blob: 71efe0092bec25a7efadec2db1af9ec2e5f1a60a [file] [log] [blame]
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001/*
2 * tc35815.c: A TOSHIBA TC35815CF PCI 10/100Mbps ethernet driver for linux.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Based on skelton.c by Donald Becker.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09006 * 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 Torvalds1da177e2005-04-16 15:20:36 -070016 *
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090017 * 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 Torvalds1da177e2005-04-16 15:20:36 -070020 *
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090021 * (C) Copyright TOSHIBA CORPORATION 2004-2005
22 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Atsushi Nemotoc6a2dbb2009-11-02 04:34:46 +000025#define DRV_VERSION "1.39"
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090026static const char *version = "tc35815.c:v" DRV_VERSION "\n";
27#define MODNAME "tc35815"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
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 Nemoto82a99282008-12-11 20:58:04 -080036#include <linux/if_vlan.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/slab.h>
38#include <linux/string.h>
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090039#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/skbuff.h>
44#include <linux/delay.h>
45#include <linux/pci.h>
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090046#include <linux/phy.h>
47#include <linux/workqueue.h>
Atsushi Nemotobd43da82007-06-29 22:34:53 +090048#include <linux/platform_device.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040049#include <linux/prefetch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/byteorder.h>
52
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090053enum tc35815_chiptype {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090054 TC35815CF = 0,
55 TC35815_NWU,
56 TC35815_TX4939,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090057};
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090058
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090059/* indexed by tc35815_chiptype, above */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090060static const struct {
61 const char *name;
Bill Pembertonb38d1302012-12-03 09:23:47 -050062} chip_info[] = {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090063 { "TOSHIBA TC35815CF 10/100BaseTX" },
64 { "TOSHIBA TC35815 with Wake on LAN" },
65 { "TOSHIBA TC35815/TX4939" },
66};
67
Benoit Taine9baa3c32014-08-08 15:56:03 +020068static const struct pci_device_id tc35815_pci_tbl[] = {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090069 {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 Nemoto7f225b42008-04-11 00:25:31 +090074MODULE_DEVICE_TABLE(pci, tc35815_pci_tbl);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090075
76/* see MODULE_PARM_DESC */
77static struct tc35815_options {
78 int speed;
79 int duplex;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +090080} options;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * Registers
84 */
85struct tc35815_regs {
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +090086 __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 Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
119/*
120 * Bit assignments
121 */
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300122/* DMA_Ctl bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900123#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 */
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300128#define DMA_IntMask 0x00040000 /* 1:Interrupt mask */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900129#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 Torvalds1da177e2005-04-16 15:20:36 -0700136
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300137/* RxFragSize bit assign ---------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900138#define RxFrag_EnPack 0x00008000 /* 1:Enable Packing */
139#define RxFrag_MinFragMask 0x00000ffc /* Minimum Fragment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300141/* MAC_Ctl bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900142#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 Torvalds1da177e2005-04-16 15:20:36 -0700154
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300155/* PROM_Ctl bit assign ------------------------------------------------------ */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900156#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 Torvalds1da177e2005-04-16 15:20:36 -0700164
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300165/* CAM_Ctl bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900166#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 Torvalds1da177e2005-04-16 15:20:36 -0700172
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300173/* CAM_Ena bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900174#define CAM_ENTRY_MAX 21 /* CAM Data entry max count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#define CAM_Ena_Mask ((1<<CAM_ENTRY_MAX)-1) /* CAM Enable bits (Max 21bits) */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900176#define CAM_Ena_Bit(index) (1 << (index))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define CAM_ENTRY_DESTINATION 0
178#define CAM_ENTRY_SOURCE 1
179#define CAM_ENTRY_MACCTL 20
180
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300181/* Tx_Ctl bit assign -------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900182#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 Torvalds1da177e2005-04-16 15:20:36 -0700194
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300195/* Tx_Stat bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900196#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 Torvalds1da177e2005-04-16 15:20:36 -0700210
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300211/* Rx_Ctl bit assign -------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900212#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 Torvalds1da177e2005-04-16 15:20:36 -0700224
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300225/* Rx_Stat bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900226#define Rx_Halted 0x00008000 /* Rx Halted */
227#define Rx_Good 0x00004000 /* Rx Good */
228#define Rx_RxPar 0x00002000 /* Rx Parity Error */
Atsushi Nemoto842e08b2008-10-28 22:30:23 +0900229#define Rx_TypePkt 0x00001000 /* Rx Type Packet */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900230#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 Nemoto842e08b2008-10-28 22:30:23 +0900237#define Rx_InLenErr 0x00000010 /* Rx In Range Frame Length Error */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Atsushi Nemoto842e08b2008-10-28 22:30:23 +0900239#define Rx_Stat_Mask 0x0000FFF0 /* Rx All Status Mask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300241/* Int_En bit assign -------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900242#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 Torvalds1da177e2005-04-16 15:20:36 -0700255
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300256/* Int_Src bit assign ------------------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900257#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 Torvalds1da177e2005-04-16 15:20:36 -0700272
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300273/* MD_CA bit assign --------------------------------------------------------- */
274#define MD_CA_PreSup 0x00001000 /* 1:Preamble Suppress */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900275#define MD_CA_Busy 0x00000800 /* 1:Busy (Start Operation) */
276#define MD_CA_Wr 0x00000400 /* 1:Write 0:Read */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279/*
280 * Descriptors
281 */
282
283/* Frame descripter */
284struct FDesc {
285 volatile __u32 FDNext;
286 volatile __u32 FDSystem;
287 volatile __u32 FDStat;
288 volatile __u32 FDCtl;
289};
290
291/* Buffer descripter */
292struct BDesc {
293 volatile __u32 BuffData;
294 volatile __u32 BDCtl;
295};
296
297#define FD_ALIGN 16
298
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300299/* Frame Descripter bit assign ---------------------------------------------- */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900300#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 Torvalds1da177e2005-04-16 15:20:36 -0700303#define FD_FrmOpt_BigEndian 0x40000000 /* Tx/Rx */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900304#define FD_FrmOpt_IntTx 0x20000000 /* Tx only */
305#define FD_FrmOpt_NoCRC 0x10000000 /* Tx only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306#define FD_FrmOpt_NoPadding 0x08000000 /* Tx only */
307#define FD_FrmOpt_Packing 0x04000000 /* Rx only */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900308#define FD_CownsFD 0x80000000 /* FD Controller owner bit */
309#define FD_Next_EOL 0x00000001 /* FD EOL indicator */
310#define FD_BDCnt_SHIFT 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300312/* Buffer Descripter bit assign --------------------------------------------- */
313#define BD_BuffLength_MASK 0x0000FFFF /* Receive Data Size */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900314#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 Torvalds1da177e2005-04-16 15:20:36 -0700318#define BD_RxBDSeqN_SHIFT 24
319
320
321/* Some useful constants. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Atsushi Nemotoa02b7b72009-11-02 04:34:47 +0000323#define TX_CTL_CMD (Tx_EnTxPar | Tx_EnLateColl | \
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900324 Tx_EnExColl | Tx_EnLCarr | Tx_EnExDefer | Tx_EnUnder | \
325 Tx_En) /* maybe 0x7b01 */
Atsushi Nemoto297713d2009-08-06 04:41:45 +0000326/* Do not use Rx_StripCRC -- it causes trouble on BLEx/FDAEx condition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define RX_CTL_CMD (Rx_EnGood | Rx_EnRxPar | Rx_EnLongErr | Rx_EnOver \
Atsushi Nemoto297713d2009-08-06 04:41:45 +0000328 | Rx_EnCRCErr | Rx_EnAlign | Rx_RxEn) /* maybe 0x6f01 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#define INT_EN_CMD (Int_NRAbtEn | \
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900330 Int_DmParErrEn | Int_DParDEn | Int_DParErrEn | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 Int_SSysErrEn | Int_RMasAbtEn | Int_RTargAbtEn | \
332 Int_STargAbtEn | \
333 Int_BLExEn | Int_FDAExEn) /* maybe 0xb7f*/
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900334#define DMA_CTL_CMD DMA_BURST_SIZE
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900335#define HAVE_DMA_RXALIGN(lp) likely((lp)->chiptype != TC35815CF)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337/* Tuning parameters */
338#define DMA_BURST_SIZE 32
339#define TX_THRESHOLD 1024
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900340/* used threshold with packet max byte for low pci transfer ability.*/
341#define TX_THRESHOLD_MAX 1536
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300342/* setting threshold max value when overrun error occurred this count. */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900343#define TX_THRESHOLD_KEEP_LIMIT 10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900345/* 16 + RX_BUF_NUM * 8 + RX_FD_NUM * 16 + TX_FD_NUM * 32 <= PAGE_SIZE*FD_PAGE_NUM */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900346#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 Nemoto82a99282008-12-11 20:58:04 -0800353#define RX_BUF_SIZE \
354 L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + NET_IP_ALIGN)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900355#else
Atsushi Nemoto82a99282008-12-11 20:58:04 -0800356#define RX_BUF_SIZE \
357 L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN + NET_IP_ALIGN)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900358#endif
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900359#define RX_FD_RESERVE (2 / 2) /* max 2 BD per RxFD */
360#define NAPI_WEIGHT 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362struct TxFD {
363 struct FDesc fd;
364 struct BDesc bd;
365 struct BDesc unused;
366};
367
368struct RxFD {
369 struct FDesc fd;
370 struct BDesc bd[0]; /* variable length */
371};
372
373struct FrFD {
374 struct FDesc fd;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900375 struct BDesc bd[RX_BUF_NUM];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376};
377
378
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900379#define tc_readl(addr) ioread32(addr)
380#define tc_writel(d, addr) iowrite32(d, addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900382#define TC35815_TX_TIMEOUT msecs_to_jiffies(400)
383
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900384/* Information that need to be kept for each controller. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385struct tc35815_local {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900386 struct pci_dev *pci_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700388 struct net_device *dev;
389 struct napi_struct napi;
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 struct {
393 int max_tx_qlen;
394 int tx_ints;
395 int rx_ints;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900396 int tx_underrun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 } lstats;
398
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900399 /* 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 Nemotodee73992010-02-24 06:00:34 +0000405 spinlock_t rx_lock;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900406
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700407 struct mii_bus *mii_bus;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900408 struct phy_device *phy_dev;
409 int duplex;
410 int speed;
411 int link;
412 struct work_struct restart_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 /*
415 * Transmitting: Batch Mode.
416 * 1 BD in 1 TxFD.
Atsushi Nemotoa02b7b72009-11-02 04:34:47 +0000417 * Receiving: Non-Packing Mode.
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900418 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700421 */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900422 void *fd_buf; /* for TxFD, RxFD, FrFD */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900423 dma_addr_t fd_buf_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 struct TxFD *tfd_base;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900425 unsigned int tfd_start;
426 unsigned int tfd_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 struct RxFD *rfd_base;
428 struct RxFD *rfd_limit;
429 struct RxFD *rfd_cur;
430 struct FrFD *fbl_ptr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900431 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 Nemotoeea221c2007-03-03 23:54:59 +0900436 u32 msg_enable;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900437 enum tc35815_chiptype chiptype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438};
439
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900440static 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
445static 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 Nemotoeea221c2007-03-03 23:54:59 +0900450static 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;
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +0000455 skb = netdev_alloc_skb(dev, RX_BUF_SIZE);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900456 if (!skb)
457 return NULL;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900458 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE,
459 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700460 if (pci_dma_mapping_error(hwdev, *dma_handle)) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900461 dev_kfree_skb_any(skb);
462 return NULL;
463 }
464 skb_reserve(skb, 2); /* make IP header 4byte aligned */
465 return skb;
466}
467
468static 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 Nemotoeea221c2007-03-03 23:54:59 +0900474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475/* Index to functions, as function prototypes. */
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477static int tc35815_open(struct net_device *dev);
478static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900479static irqreturn_t tc35815_interrupt(int irq, void *dev_id);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900480static int tc35815_rx(struct net_device *dev, int limit);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700481static int tc35815_poll(struct napi_struct *napi, int budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482static void tc35815_txdone(struct net_device *dev);
483static int tc35815_close(struct net_device *dev);
484static struct net_device_stats *tc35815_get_stats(struct net_device *dev);
485static void tc35815_set_multicast_list(struct net_device *dev);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900486static void tc35815_tx_timeout(struct net_device *dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900487static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
488#ifdef CONFIG_NET_POLL_CONTROLLER
489static void tc35815_poll_controller(struct net_device *dev);
490#endif
491static const struct ethtool_ops tc35815_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900493/* Example routines you must write ;->. */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900494static void tc35815_chip_reset(struct net_device *dev);
495static void tc35815_chip_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900497#ifdef DEBUG
498static void panic_queues(struct net_device *dev);
499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900501static void tc35815_restart_work(struct work_struct *work);
502
503static 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 Nemotoc60a5cf2009-08-06 04:41:47 +0000508 unsigned long timeout = jiffies + HZ;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900509
510 tc_writel(MD_CA_Busy | (mii_id << 5) | (regnum & 0x1f), &tr->MD_CA);
Atsushi Nemotoc60a5cf2009-08-06 04:41:47 +0000511 udelay(12); /* it takes 32 x 400ns at least */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900512 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
520static 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 Nemotoc60a5cf2009-08-06 04:41:47 +0000525 unsigned long timeout = jiffies + HZ;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900526
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 Nemotoc60a5cf2009-08-06 04:41:47 +0000530 udelay(12); /* it takes 32 x 400ns at least */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900531 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
539static 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 Nemotoc6686fe2008-04-12 00:47:46 +0900568 /*
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 Nemotoc6686fe2008-04-12 00:47:46 +0900577
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 Nemotoc6686fe2008-04-12 00:47:46 +0900585 /* delayed promiscuous enabling */
586 if (dev->flags & IFF_PROMISC)
587 tc35815_set_multicast_list(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900588 } 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 Perches72903832009-05-15 07:59:42 +0000600 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 Nemotoc6686fe2008-04-12 00:47:46 +0900605 }
606}
607
608static int tc_mii_probe(struct net_device *dev)
609{
610 struct tc35815_local *lp = netdev_priv(dev);
Guenter Roecka05876b2016-01-10 07:10:44 -0800611 struct phy_device *phydev;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900612 u32 dropmask;
613
Guenter Roecka05876b2016-01-10 07:10:44 -0800614 phydev = phy_find_first(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900615 if (!phydev) {
616 printk(KERN_ERR "%s: no PHY found\n", dev->name);
617 return -ENODEV;
618 }
619
620 /* attach the mac to the phy */
Andrew Lunn84eff6d2016-01-06 20:11:10 +0100621 phydev = phy_connect(dev, phydev_name(phydev),
Florian Fainellif9a8f832013-01-14 00:52:52 +0000622 &tc_handle_link_change,
623 lp->chiptype == TC35815_TX4939 ? PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900624 if (IS_ERR(phydev)) {
625 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
626 return PTR_ERR(phydev);
627 }
Andrew Lunn22209432016-01-06 20:11:13 +0100628
629 phy_attached_info(phydev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900630
631 /* mask with MAC supported features */
632 phydev->supported &= PHY_BASIC_FEATURES;
633 dropmask = 0;
634 if (options.speed == 10)
635 dropmask |= SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
636 else if (options.speed == 100)
637 dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full;
638 if (options.duplex == 1)
639 dropmask |= SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Full;
640 else if (options.duplex == 2)
641 dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_100baseT_Half;
642 phydev->supported &= ~dropmask;
643 phydev->advertising = phydev->supported;
644
645 lp->link = 0;
646 lp->speed = 0;
647 lp->duplex = -1;
648 lp->phy_dev = phydev;
649
650 return 0;
651}
652
653static int tc_mii_init(struct net_device *dev)
654{
655 struct tc35815_local *lp = netdev_priv(dev);
656 int err;
657 int i;
658
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700659 lp->mii_bus = mdiobus_alloc();
660 if (lp->mii_bus == NULL) {
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900661 err = -ENOMEM;
662 goto err_out;
663 }
664
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700665 lp->mii_bus->name = "tc35815_mii_bus";
666 lp->mii_bus->read = tc_mdio_read;
667 lp->mii_bus->write = tc_mdio_write;
668 snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "%x",
669 (lp->pci_dev->bus->number << 8) | lp->pci_dev->devfn);
670 lp->mii_bus->priv = dev;
671 lp->mii_bus->parent = &lp->pci_dev->dev;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700672 err = mdiobus_register(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900673 if (err)
Andrew Lunne7f4dc32016-01-06 20:11:15 +0100674 goto err_out_free_mii_bus;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900675 err = tc_mii_probe(dev);
676 if (err)
677 goto err_out_unregister_bus;
678 return 0;
679
680err_out_unregister_bus:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700681 mdiobus_unregister(lp->mii_bus);
Adrian Bunk51cf7562008-10-12 21:01:53 -0700682err_out_free_mii_bus:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700683 mdiobus_free(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900684err_out:
685 return err;
686}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900688#ifdef CONFIG_CPU_TX49XX
689/*
690 * Find a platform_device providing a MAC address. The platform code
691 * should provide a "tc35815-mac" device with a MAC address in its
692 * platform_data.
693 */
Bill Pembertonb38d1302012-12-03 09:23:47 -0500694static int tc35815_mac_match(struct device *dev, void *data)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900695{
696 struct platform_device *plat_dev = to_platform_device(dev);
697 struct pci_dev *pci_dev = data;
Atsushi Nemoto06675e62008-01-19 01:15:52 +0900698 unsigned int id = pci_dev->irq;
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900699 return !strcmp(plat_dev->name, "tc35815-mac") && plat_dev->id == id;
700}
701
Bill Pembertonb38d1302012-12-03 09:23:47 -0500702static int tc35815_read_plat_dev_addr(struct net_device *dev)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900703{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900704 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900705 struct device *pd = bus_find_device(&platform_bus_type, NULL,
706 lp->pci_dev, tc35815_mac_match);
707 if (pd) {
708 if (pd->platform_data)
709 memcpy(dev->dev_addr, pd->platform_data, ETH_ALEN);
710 put_device(pd);
711 return is_valid_ether_addr(dev->dev_addr) ? 0 : -ENODEV;
712 }
713 return -ENODEV;
714}
715#else
Bill Pembertonb38d1302012-12-03 09:23:47 -0500716static int tc35815_read_plat_dev_addr(struct net_device *dev)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900717{
718 return -ENODEV;
719}
720#endif
721
Bill Pembertonb38d1302012-12-03 09:23:47 -0500722static int tc35815_init_dev_addr(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900724 struct tc35815_regs __iomem *tr =
725 (struct tc35815_regs __iomem *)dev->base_addr;
726 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 while (tc_readl(&tr->PROM_Ctl) & PROM_Busy)
729 ;
730 for (i = 0; i < 6; i += 2) {
731 unsigned short data;
732 tc_writel(PROM_Busy | PROM_Read | (i / 2 + 2), &tr->PROM_Ctl);
733 while (tc_readl(&tr->PROM_Ctl) & PROM_Busy)
734 ;
735 data = tc_readl(&tr->PROM_Data);
736 dev->dev_addr[i] = data & 0xff;
737 dev->dev_addr[i+1] = data >> 8;
738 }
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900739 if (!is_valid_ether_addr(dev->dev_addr))
740 return tc35815_read_plat_dev_addr(dev);
741 return 0;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900742}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000744static const struct net_device_ops tc35815_netdev_ops = {
745 .ndo_open = tc35815_open,
746 .ndo_stop = tc35815_close,
747 .ndo_start_xmit = tc35815_send_packet,
748 .ndo_get_stats = tc35815_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000749 .ndo_set_rx_mode = tc35815_set_multicast_list,
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000750 .ndo_tx_timeout = tc35815_tx_timeout,
751 .ndo_do_ioctl = tc35815_ioctl,
752 .ndo_validate_addr = eth_validate_addr,
753 .ndo_change_mtu = eth_change_mtu,
754 .ndo_set_mac_address = eth_mac_addr,
755#ifdef CONFIG_NET_POLL_CONTROLLER
756 .ndo_poll_controller = tc35815_poll_controller,
757#endif
758};
759
Bill Pembertonb38d1302012-12-03 09:23:47 -0500760static int tc35815_init_one(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000761 const struct pci_device_id *ent)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900762{
763 void __iomem *ioaddr = NULL;
764 struct net_device *dev;
765 struct tc35815_local *lp;
766 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900768 static int printed_version;
769 if (!printed_version++) {
770 printk(version);
771 dev_printk(KERN_DEBUG, &pdev->dev,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900772 "speed:%d duplex:%d\n",
773 options.speed, options.duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900776 if (!pdev->irq) {
777 dev_warn(&pdev->dev, "no IRQ assigned.\n");
778 return -ENODEV;
779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900781 /* dev zeroed in alloc_etherdev */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900782 dev = alloc_etherdev(sizeof(*lp));
Joe Perches41de8d42012-01-29 13:47:52 +0000783 if (dev == NULL)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900784 return -ENOMEM;
Joe Perches41de8d42012-01-29 13:47:52 +0000785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 SET_NETDEV_DEV(dev, &pdev->dev);
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900787 lp = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700788 lp->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900790 /* enable device (incl. PCI PM wakeup), and bus-mastering */
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900791 rc = pcim_enable_device(pdev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900792 if (rc)
793 goto err_out;
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900794 rc = pcim_iomap_regions(pdev, 1 << 1, MODNAME);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900795 if (rc)
796 goto err_out;
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900797 pci_set_master(pdev);
798 ioaddr = pcim_iomap_table(pdev)[1];
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900799
800 /* Initialize the device structure. */
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000801 dev->netdev_ops = &tc35815_netdev_ops;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900802 dev->ethtool_ops = &tc35815_ethtool_ops;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900803 dev->watchdog_timeo = TC35815_TX_TIMEOUT;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700804 netif_napi_add(dev, &lp->napi, tc35815_poll, NAPI_WEIGHT);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900805
806 dev->irq = pdev->irq;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900807 dev->base_addr = (unsigned long)ioaddr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900808
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900809 INIT_WORK(&lp->restart_work, tc35815_restart_work);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900810 spin_lock_init(&lp->lock);
Atsushi Nemotodee73992010-02-24 06:00:34 +0000811 spin_lock_init(&lp->rx_lock);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900812 lp->pci_dev = pdev;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900813 lp->chiptype = ent->driver_data;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900814
815 lp->msg_enable = NETIF_MSG_TX_ERR | NETIF_MSG_HW | NETIF_MSG_DRV | NETIF_MSG_LINK;
816 pci_set_drvdata(pdev, dev);
817
818 /* Soft reset the chip. */
819 tc35815_chip_reset(dev);
820
821 /* Retrieve the ethernet address. */
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900822 if (tc35815_init_dev_addr(dev)) {
823 dev_warn(&pdev->dev, "not valid ether addr\n");
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000824 eth_hw_addr_random(dev);
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900825 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900826
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900827 rc = register_netdev(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900828 if (rc)
David S. Miller1e2cfee2010-07-13 14:20:58 -0700829 goto err_out;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900830
Johannes Berge1749612008-10-27 15:59:26 -0700831 printk(KERN_INFO "%s: %s at 0x%lx, %pM, IRQ %d\n",
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900832 dev->name,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900833 chip_info[ent->driver_data].name,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900834 dev->base_addr,
Johannes Berge1749612008-10-27 15:59:26 -0700835 dev->dev_addr,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900836 dev->irq);
837
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900838 rc = tc_mii_init(dev);
839 if (rc)
840 goto err_out_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 return 0;
843
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900844err_out_unregister:
845 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846err_out:
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900847 free_netdev(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900848 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
851
Bill Pembertonb38d1302012-12-03 09:23:47 -0500852static void tc35815_remove_one(struct pci_dev *pdev)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900853{
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900854 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900855 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900856
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900857 phy_disconnect(lp->phy_dev);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700858 mdiobus_unregister(lp->mii_bus);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700859 mdiobus_free(lp->mii_bus);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900860 unregister_netdev(dev);
861 free_netdev(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900862}
863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864static int
865tc35815_init_queues(struct net_device *dev)
866{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900867 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 int i;
869 unsigned long fd_addr;
870
871 if (!lp->fd_buf) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900872 BUG_ON(sizeof(struct FDesc) +
873 sizeof(struct BDesc) * RX_BUF_NUM +
874 sizeof(struct FDesc) * RX_FD_NUM +
875 sizeof(struct TxFD) * TX_FD_NUM >
876 PAGE_SIZE * FD_PAGE_NUM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900878 lp->fd_buf = pci_alloc_consistent(lp->pci_dev,
879 PAGE_SIZE * FD_PAGE_NUM,
880 &lp->fd_buf_dma);
881 if (!lp->fd_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return -ENOMEM;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900883 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900884 lp->rx_skbs[i].skb =
885 alloc_rxbuf_skb(dev, lp->pci_dev,
886 &lp->rx_skbs[i].skb_dma);
887 if (!lp->rx_skbs[i].skb) {
888 while (--i >= 0) {
889 free_rxbuf_skb(lp->pci_dev,
890 lp->rx_skbs[i].skb,
891 lp->rx_skbs[i].skb_dma);
892 lp->rx_skbs[i].skb = NULL;
893 }
894 pci_free_consistent(lp->pci_dev,
895 PAGE_SIZE * FD_PAGE_NUM,
896 lp->fd_buf,
897 lp->fd_buf_dma);
898 lp->fd_buf = NULL;
899 return -ENOMEM;
900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900902 printk(KERN_DEBUG "%s: FD buf %p DataBuf",
903 dev->name, lp->fd_buf);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900904 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 } else {
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900906 for (i = 0; i < FD_PAGE_NUM; i++)
907 clear_page((void *)((unsigned long)lp->fd_buf +
908 i * PAGE_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 fd_addr = (unsigned long)lp->fd_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 /* Free Descriptors (for Receive) */
913 lp->rfd_base = (struct RxFD *)fd_addr;
914 fd_addr += sizeof(struct RxFD) * RX_FD_NUM;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900915 for (i = 0; i < RX_FD_NUM; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 lp->rfd_base[i].fd.FDCtl = cpu_to_le32(FD_CownsFD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 lp->rfd_cur = lp->rfd_base;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900918 lp->rfd_limit = (struct RxFD *)fd_addr - (RX_FD_RESERVE + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920 /* Transmit Descriptors */
921 lp->tfd_base = (struct TxFD *)fd_addr;
922 fd_addr += sizeof(struct TxFD) * TX_FD_NUM;
923 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900924 lp->tfd_base[i].fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, &lp->tfd_base[i+1]));
925 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 lp->tfd_base[i].fd.FDCtl = cpu_to_le32(0);
927 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900928 lp->tfd_base[TX_FD_NUM-1].fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, &lp->tfd_base[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 lp->tfd_start = 0;
930 lp->tfd_end = 0;
931
932 /* Buffer List (for Receive) */
933 lp->fbl_ptr = (struct FrFD *)fd_addr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900934 lp->fbl_ptr->fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, lp->fbl_ptr));
935 lp->fbl_ptr->fd.FDCtl = cpu_to_le32(RX_BUF_NUM | FD_CownsFD);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900936 /*
937 * move all allocated skbs to head of rx_skbs[] array.
938 * fbl_count mighe not be RX_BUF_NUM if alloc_rxbuf_skb() in
939 * tc35815_rx() had failed.
940 */
941 lp->fbl_count = 0;
942 for (i = 0; i < RX_BUF_NUM; i++) {
943 if (lp->rx_skbs[i].skb) {
944 if (i != lp->fbl_count) {
945 lp->rx_skbs[lp->fbl_count].skb =
946 lp->rx_skbs[i].skb;
947 lp->rx_skbs[lp->fbl_count].skb_dma =
948 lp->rx_skbs[i].skb_dma;
949 }
950 lp->fbl_count++;
951 }
952 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900953 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900954 if (i >= lp->fbl_count) {
955 lp->fbl_ptr->bd[i].BuffData = 0;
956 lp->fbl_ptr->bd[i].BDCtl = 0;
957 continue;
958 }
959 lp->fbl_ptr->bd[i].BuffData =
960 cpu_to_le32(lp->rx_skbs[i].skb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 /* BDID is index of FrFD.bd[] */
962 lp->fbl_ptr->bd[i].BDCtl =
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900963 cpu_to_le32(BD_CownsBD | (i << BD_RxBDID_SHIFT) |
964 RX_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900967 printk(KERN_DEBUG "%s: TxFD %p RxFD %p FrFD %p\n",
968 dev->name, lp->tfd_base, lp->rfd_base, lp->fbl_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return 0;
970}
971
972static void
973tc35815_clear_queues(struct net_device *dev)
974{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900975 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 int i;
977
978 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900979 u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem);
980 struct sk_buff *skb =
981 fdsystem != 0xffffffff ?
982 lp->tx_skbs[fdsystem].skb : NULL;
983#ifdef DEBUG
984 if (lp->tx_skbs[i].skb != skb) {
985 printk("%s: tx_skbs mismatch(%d).\n", dev->name, i);
986 panic_queues(dev);
987 }
988#else
989 BUG_ON(lp->tx_skbs[i].skb != skb);
990#endif
991 if (skb) {
992 pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE);
993 lp->tx_skbs[i].skb = NULL;
994 lp->tx_skbs[i].skb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 dev_kfree_skb_any(skb);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +0900996 }
997 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
999
1000 tc35815_init_queues(dev);
1001}
1002
1003static void
1004tc35815_free_queues(struct net_device *dev)
1005{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001006 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 int i;
1008
1009 if (lp->tfd_base) {
1010 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001011 u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem);
1012 struct sk_buff *skb =
1013 fdsystem != 0xffffffff ?
1014 lp->tx_skbs[fdsystem].skb : NULL;
1015#ifdef DEBUG
1016 if (lp->tx_skbs[i].skb != skb) {
1017 printk("%s: tx_skbs mismatch(%d).\n", dev->name, i);
1018 panic_queues(dev);
1019 }
1020#else
1021 BUG_ON(lp->tx_skbs[i].skb != skb);
1022#endif
1023 if (skb) {
1024 dev_kfree_skb(skb);
1025 pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE);
1026 lp->tx_skbs[i].skb = NULL;
1027 lp->tx_skbs[i].skb_dma = 0;
1028 }
1029 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 }
1032
1033 lp->rfd_base = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 lp->rfd_limit = NULL;
1035 lp->rfd_cur = NULL;
1036 lp->fbl_ptr = NULL;
1037
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001038 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001039 if (lp->rx_skbs[i].skb) {
1040 free_rxbuf_skb(lp->pci_dev, lp->rx_skbs[i].skb,
1041 lp->rx_skbs[i].skb_dma);
1042 lp->rx_skbs[i].skb = NULL;
1043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001045 if (lp->fd_buf) {
1046 pci_free_consistent(lp->pci_dev, PAGE_SIZE * FD_PAGE_NUM,
1047 lp->fd_buf, lp->fd_buf_dma);
1048 lp->fd_buf = NULL;
1049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
1052static void
1053dump_txfd(struct TxFD *fd)
1054{
1055 printk("TxFD(%p): %08x %08x %08x %08x\n", fd,
1056 le32_to_cpu(fd->fd.FDNext),
1057 le32_to_cpu(fd->fd.FDSystem),
1058 le32_to_cpu(fd->fd.FDStat),
1059 le32_to_cpu(fd->fd.FDCtl));
1060 printk("BD: ");
1061 printk(" %08x %08x",
1062 le32_to_cpu(fd->bd.BuffData),
1063 le32_to_cpu(fd->bd.BDCtl));
1064 printk("\n");
1065}
1066
1067static int
1068dump_rxfd(struct RxFD *fd)
1069{
1070 int i, bd_count = (le32_to_cpu(fd->fd.FDCtl) & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT;
1071 if (bd_count > 8)
1072 bd_count = 8;
1073 printk("RxFD(%p): %08x %08x %08x %08x\n", fd,
1074 le32_to_cpu(fd->fd.FDNext),
1075 le32_to_cpu(fd->fd.FDSystem),
1076 le32_to_cpu(fd->fd.FDStat),
1077 le32_to_cpu(fd->fd.FDCtl));
1078 if (le32_to_cpu(fd->fd.FDCtl) & FD_CownsFD)
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001079 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 printk("BD: ");
1081 for (i = 0; i < bd_count; i++)
1082 printk(" %08x %08x",
1083 le32_to_cpu(fd->bd[i].BuffData),
1084 le32_to_cpu(fd->bd[i].BDCtl));
1085 printk("\n");
1086 return bd_count;
1087}
1088
Atsushi Nemotoa02b7b72009-11-02 04:34:47 +00001089#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090static void
1091dump_frfd(struct FrFD *fd)
1092{
1093 int i;
1094 printk("FrFD(%p): %08x %08x %08x %08x\n", fd,
1095 le32_to_cpu(fd->fd.FDNext),
1096 le32_to_cpu(fd->fd.FDSystem),
1097 le32_to_cpu(fd->fd.FDStat),
1098 le32_to_cpu(fd->fd.FDCtl));
1099 printk("BD: ");
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001100 for (i = 0; i < RX_BUF_NUM; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 printk(" %08x %08x",
1102 le32_to_cpu(fd->bd[i].BuffData),
1103 le32_to_cpu(fd->bd[i].BDCtl));
1104 printk("\n");
1105}
1106
1107static void
1108panic_queues(struct net_device *dev)
1109{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001110 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 int i;
1112
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001113 printk("TxFD base %p, start %u, end %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 lp->tfd_base, lp->tfd_start, lp->tfd_end);
1115 printk("RxFD base %p limit %p cur %p\n",
1116 lp->rfd_base, lp->rfd_limit, lp->rfd_cur);
1117 printk("FrFD %p\n", lp->fbl_ptr);
1118 for (i = 0; i < TX_FD_NUM; i++)
1119 dump_txfd(&lp->tfd_base[i]);
1120 for (i = 0; i < RX_FD_NUM; i++) {
1121 int bd_count = dump_rxfd(&lp->rfd_base[i]);
1122 i += (bd_count + 1) / 2; /* skip BDs */
1123 }
1124 dump_frfd(lp->fbl_ptr);
1125 panic("%s: Illegal queue state.", dev->name);
1126}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127#endif
1128
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001129static void print_eth(const u8 *add)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001131 printk(KERN_DEBUG "print_eth(%p)\n", add);
Johannes Berge1749612008-10-27 15:59:26 -07001132 printk(KERN_DEBUG " %pM => %pM : %02x%02x\n",
1133 add + 6, add, add[12], add[13]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001136static int tc35815_tx_full(struct net_device *dev)
1137{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001138 struct tc35815_local *lp = netdev_priv(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +00001139 return (lp->tfd_start + 1) % TX_FD_NUM == lp->tfd_end;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001140}
1141
1142static void tc35815_restart(struct net_device *dev)
1143{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001144 struct tc35815_local *lp = netdev_priv(dev);
Florian Fainelli01b01142013-12-06 13:01:37 -08001145 int ret;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001146
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001147 if (lp->phy_dev) {
Florian Fainelli01b01142013-12-06 13:01:37 -08001148 ret = phy_init_hw(lp->phy_dev);
1149 if (ret)
1150 printk(KERN_ERR "%s: PHY init failed.\n", dev->name);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001151 }
1152
Atsushi Nemotodee73992010-02-24 06:00:34 +00001153 spin_lock_bh(&lp->rx_lock);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001154 spin_lock_irq(&lp->lock);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001155 tc35815_chip_reset(dev);
1156 tc35815_clear_queues(dev);
1157 tc35815_chip_init(dev);
1158 /* Reconfigure CAM again since tc35815_chip_init() initialize it. */
1159 tc35815_set_multicast_list(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001160 spin_unlock_irq(&lp->lock);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001161 spin_unlock_bh(&lp->rx_lock);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001162
1163 netif_wake_queue(dev);
1164}
1165
1166static void tc35815_restart_work(struct work_struct *work)
1167{
1168 struct tc35815_local *lp =
1169 container_of(work, struct tc35815_local, restart_work);
1170 struct net_device *dev = lp->dev;
1171
1172 tc35815_restart(dev);
1173}
1174
1175static void tc35815_schedule_restart(struct net_device *dev)
1176{
1177 struct tc35815_local *lp = netdev_priv(dev);
1178 struct tc35815_regs __iomem *tr =
1179 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotodee73992010-02-24 06:00:34 +00001180 unsigned long flags;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001181
1182 /* disable interrupts */
Atsushi Nemotodee73992010-02-24 06:00:34 +00001183 spin_lock_irqsave(&lp->lock, flags);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001184 tc_writel(0, &tr->Int_En);
1185 tc_writel(tc_readl(&tr->DMA_Ctl) | DMA_IntMask, &tr->DMA_Ctl);
1186 schedule_work(&lp->restart_work);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001187 spin_unlock_irqrestore(&lp->lock, flags);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001188}
1189
1190static void tc35815_tx_timeout(struct net_device *dev)
1191{
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001192 struct tc35815_regs __iomem *tr =
1193 (struct tc35815_regs __iomem *)dev->base_addr;
1194
1195 printk(KERN_WARNING "%s: transmit timed out, status %#x\n",
1196 dev->name, tc_readl(&tr->Tx_Stat));
1197
1198 /* Try to restart the adaptor. */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001199 tc35815_schedule_restart(dev);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001200 dev->stats.tx_errors++;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001201}
1202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203/*
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001204 * Open/initialize the controller. This is called (in the current kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 * sometime after booting when the 'ifconfig' program is run.
1206 *
1207 * This routine should set everything up anew at each open, even
1208 * registers that "should" only need to be set once at boot, so that
1209 * there is non-reboot way to recover if something goes wrong.
1210 */
1211static int
1212tc35815_open(struct net_device *dev)
1213{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001214 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 /*
1217 * This is used if the interrupt line can turned off (shared).
1218 * See 3c503.c for an example of selecting the IRQ at config-time.
1219 */
Joe Perchesa0607fd2009-11-18 23:29:17 -08001220 if (request_irq(dev->irq, tc35815_interrupt, IRQF_SHARED,
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001221 dev->name, dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
1224 tc35815_chip_reset(dev);
1225
1226 if (tc35815_init_queues(dev) != 0) {
1227 free_irq(dev->irq, dev);
1228 return -EAGAIN;
1229 }
1230
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001231 napi_enable(&lp->napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 /* Reset the hardware here. Don't forget to set the station address. */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001234 spin_lock_irq(&lp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 tc35815_chip_init(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001236 spin_unlock_irq(&lp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Atsushi Nemoto59524a32008-06-25 11:41:01 +09001238 netif_carrier_off(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001239 /* schedule a link state check */
1240 phy_start(lp->phy_dev);
1241
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001242 /* We are now ready to accept transmit requeusts from
1243 * the queueing layer of the networking.
1244 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 netif_start_queue(dev);
1246
1247 return 0;
1248}
1249
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001250/* This will only be invoked if your driver is _not_ in XOFF state.
1251 * What this means is that you need not check it, and that this
1252 * invariant will hold if you make sure that the netif_*_queue()
1253 * calls are done at the proper times.
1254 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
1256{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001257 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001258 struct TxFD *txfd;
1259 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001261 /* If some error occurs while trying to transmit this
1262 * packet, you should return '1' from this function.
1263 * In such a case you _may not_ do anything to the
1264 * SKB, it is still owned by the network queueing
1265 * layer when an error is returned. This means you
1266 * may not modify any SKB fields, you may not free
1267 * the SKB, etc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001270 /* This is the most common case for modern hardware.
1271 * The spinlock protects this code from the TX complete
1272 * hardware interrupt handler. Queue flow control is
1273 * thus managed under this lock as well.
1274 */
1275 spin_lock_irqsave(&lp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001277 /* failsafe... (handle txdone now if half of FDs are used) */
1278 if ((lp->tfd_start + TX_FD_NUM - lp->tfd_end) % TX_FD_NUM >
1279 TX_FD_NUM / 2)
1280 tc35815_txdone(dev);
1281
1282 if (netif_msg_pktdata(lp))
1283 print_eth(skb->data);
1284#ifdef DEBUG
1285 if (lp->tx_skbs[lp->tfd_start].skb) {
1286 printk("%s: tx_skbs conflict.\n", dev->name);
1287 panic_queues(dev);
1288 }
1289#else
1290 BUG_ON(lp->tx_skbs[lp->tfd_start].skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291#endif
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001292 lp->tx_skbs[lp->tfd_start].skb = skb;
1293 lp->tx_skbs[lp->tfd_start].skb_dma = pci_map_single(lp->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001295 /*add to ring */
1296 txfd = &lp->tfd_base[lp->tfd_start];
1297 txfd->bd.BuffData = cpu_to_le32(lp->tx_skbs[lp->tfd_start].skb_dma);
1298 txfd->bd.BDCtl = cpu_to_le32(skb->len);
1299 txfd->fd.FDSystem = cpu_to_le32(lp->tfd_start);
1300 txfd->fd.FDCtl = cpu_to_le32(FD_CownsFD | (1 << FD_BDCnt_SHIFT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001302 if (lp->tfd_start == lp->tfd_end) {
1303 struct tc35815_regs __iomem *tr =
1304 (struct tc35815_regs __iomem *)dev->base_addr;
1305 /* Start DMA Transmitter. */
1306 txfd->fd.FDNext |= cpu_to_le32(FD_Next_EOL);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001307 txfd->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001308 if (netif_msg_tx_queued(lp)) {
1309 printk("%s: starting TxFD.\n", dev->name);
1310 dump_txfd(txfd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001312 tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr);
1313 } else {
1314 txfd->fd.FDNext &= cpu_to_le32(~FD_Next_EOL);
1315 if (netif_msg_tx_queued(lp)) {
1316 printk("%s: queueing TxFD.\n", dev->name);
1317 dump_txfd(txfd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001319 }
1320 lp->tfd_start = (lp->tfd_start + 1) % TX_FD_NUM;
1321
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001322 /* If we just used up the very last entry in the
1323 * TX ring on this device, tell the queueing
1324 * layer to send no more.
1325 */
1326 if (tc35815_tx_full(dev)) {
1327 if (netif_msg_tx_queued(lp))
1328 printk(KERN_WARNING "%s: TxFD Exhausted.\n", dev->name);
1329 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001332 /* When the TX completion hw interrupt arrives, this
1333 * is when the transmit statistics are updated.
1334 */
1335
1336 spin_unlock_irqrestore(&lp->lock, flags);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001337 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
1340#define FATAL_ERROR_INT \
1341 (Int_IntPCI | Int_DmParErr | Int_IntNRAbt)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001342static void tc35815_fatal_error_interrupt(struct net_device *dev, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
1344 static int count;
1345 printk(KERN_WARNING "%s: Fatal Error Intterrupt (%#x):",
1346 dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 if (status & Int_IntPCI)
1348 printk(" IntPCI");
1349 if (status & Int_DmParErr)
1350 printk(" DmParErr");
1351 if (status & Int_IntNRAbt)
1352 printk(" IntNRAbt");
1353 printk("\n");
1354 if (count++ > 100)
1355 panic("%s: Too many fatal errors.", dev->name);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001356 printk(KERN_WARNING "%s: Resetting ...\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 /* Try to restart the adaptor. */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001358 tc35815_schedule_restart(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001359}
1360
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001361static int tc35815_do_interrupt(struct net_device *dev, u32 status, int limit)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001362{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001363 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001364 int ret = -1;
1365
1366 /* Fatal errors... */
1367 if (status & FATAL_ERROR_INT) {
1368 tc35815_fatal_error_interrupt(dev, status);
1369 return 0;
1370 }
1371 /* recoverable errors */
1372 if (status & Int_IntFDAEx) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001373 if (netif_msg_rx_err(lp))
1374 dev_warn(&dev->dev,
1375 "Free Descriptor Area Exhausted (%#x).\n",
1376 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001377 dev->stats.rx_dropped++;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001378 ret = 0;
1379 }
1380 if (status & Int_IntBLEx) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001381 if (netif_msg_rx_err(lp))
1382 dev_warn(&dev->dev,
1383 "Buffer List Exhausted (%#x).\n",
1384 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001385 dev->stats.rx_dropped++;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001386 ret = 0;
1387 }
1388 if (status & Int_IntExBD) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001389 if (netif_msg_rx_err(lp))
1390 dev_warn(&dev->dev,
1391 "Excessive Buffer Descriptiors (%#x).\n",
1392 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001393 dev->stats.rx_length_errors++;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001394 ret = 0;
1395 }
1396
1397 /* normal notification */
1398 if (status & Int_IntMacRx) {
1399 /* Got a packet(s). */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001400 ret = tc35815_rx(dev, limit);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001401 lp->lstats.rx_ints++;
1402 }
1403 if (status & Int_IntMacTx) {
1404 /* Transmit complete. */
1405 lp->lstats.tx_ints++;
Atsushi Nemotodee73992010-02-24 06:00:34 +00001406 spin_lock_irq(&lp->lock);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001407 tc35815_txdone(dev);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001408 spin_unlock_irq(&lp->lock);
Atsushi Nemoto02c5c8e2009-10-26 03:46:21 +00001409 if (ret < 0)
1410 ret = 0;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001411 }
1412 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
1415/*
1416 * The typical workload of the driver:
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001417 * Handle the network interface interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 */
David Howells7d12e782006-10-05 14:55:46 +01001419static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
1421 struct net_device *dev = dev_id;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001422 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001423 struct tc35815_regs __iomem *tr =
1424 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001425 u32 dmactl = tc_readl(&tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001427 if (!(dmactl & DMA_IntMask)) {
1428 /* disable interrupts */
1429 tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
Ben Hutchings288379f2009-01-19 16:43:59 -08001430 if (napi_schedule_prep(&lp->napi))
1431 __napi_schedule(&lp->napi);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001432 else {
1433 printk(KERN_ERR "%s: interrupt taken in poll\n",
1434 dev->name);
1435 BUG();
1436 }
1437 (void)tc_readl(&tr->Int_Src); /* flush */
1438 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001440 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001443#ifdef CONFIG_NET_POLL_CONTROLLER
1444static void tc35815_poll_controller(struct net_device *dev)
1445{
1446 disable_irq(dev->irq);
1447 tc35815_interrupt(dev->irq, dev);
1448 enable_irq(dev->irq);
1449}
1450#endif
1451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452/* We have a good packet(s), get it/them out of the buffers. */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001453static int
1454tc35815_rx(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001456 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 unsigned int fdctl;
1458 int i;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001459 int received = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 while (!((fdctl = le32_to_cpu(lp->rfd_cur->fd.FDCtl)) & FD_CownsFD)) {
1462 int status = le32_to_cpu(lp->rfd_cur->fd.FDStat);
1463 int pkt_len = fdctl & FD_FDLength_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 int bd_count = (fdctl & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001465#ifdef DEBUG
1466 struct RxFD *next_rfd;
1467#endif
1468#if (RX_CTL_CMD & Rx_StripCRC) == 0
Atsushi Nemoto82a99282008-12-11 20:58:04 -08001469 pkt_len -= ETH_FCS_LEN;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001470#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001472 if (netif_msg_rx_status(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 dump_rxfd(lp->rfd_cur);
1474 if (status & Rx_Good) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 struct sk_buff *skb;
1476 unsigned char *data;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001477 int cur_bd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001479 if (--limit < 0)
1480 break;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001481 BUG_ON(bd_count > 1);
1482 cur_bd = (le32_to_cpu(lp->rfd_cur->bd[0].BDCtl)
1483 & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT;
1484#ifdef DEBUG
1485 if (cur_bd >= RX_BUF_NUM) {
1486 printk("%s: invalid BDID.\n", dev->name);
1487 panic_queues(dev);
1488 }
1489 BUG_ON(lp->rx_skbs[cur_bd].skb_dma !=
1490 (le32_to_cpu(lp->rfd_cur->bd[0].BuffData) & ~3));
1491 if (!lp->rx_skbs[cur_bd].skb) {
1492 printk("%s: NULL skb.\n", dev->name);
1493 panic_queues(dev);
1494 }
1495#else
1496 BUG_ON(cur_bd >= RX_BUF_NUM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497#endif
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001498 skb = lp->rx_skbs[cur_bd].skb;
1499 prefetch(skb->data);
1500 lp->rx_skbs[cur_bd].skb = NULL;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001501 pci_unmap_single(lp->pci_dev,
1502 lp->rx_skbs[cur_bd].skb_dma,
1503 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Atsushi Nemoto82a99282008-12-11 20:58:04 -08001504 if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN)
1505 memmove(skb->data, skb->data - NET_IP_ALIGN,
1506 pkt_len);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001507 data = skb_put(skb, pkt_len);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001508 if (netif_msg_pktdata(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 print_eth(data);
1510 skb->protocol = eth_type_trans(skb, dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001511 netif_receive_skb(skb);
1512 received++;
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001513 dev->stats.rx_packets++;
1514 dev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 } else {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001516 dev->stats.rx_errors++;
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001517 if (netif_msg_rx_err(lp))
1518 dev_info(&dev->dev, "Rx error (status %x)\n",
1519 status & Rx_Stat_Mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 /* WORKAROUND: LongErr and CRCErr means Overflow. */
1521 if ((status & Rx_LongErr) && (status & Rx_CRCErr)) {
1522 status &= ~(Rx_LongErr|Rx_CRCErr);
1523 status |= Rx_Over;
1524 }
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001525 if (status & Rx_LongErr)
1526 dev->stats.rx_length_errors++;
1527 if (status & Rx_Over)
1528 dev->stats.rx_fifo_errors++;
1529 if (status & Rx_CRCErr)
1530 dev->stats.rx_crc_errors++;
1531 if (status & Rx_Align)
1532 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
1534
1535 if (bd_count > 0) {
1536 /* put Free Buffer back to controller */
1537 int bdctl = le32_to_cpu(lp->rfd_cur->bd[bd_count - 1].BDCtl);
1538 unsigned char id =
1539 (bdctl & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001540#ifdef DEBUG
1541 if (id >= RX_BUF_NUM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 printk("%s: invalid BDID.\n", dev->name);
1543 panic_queues(dev);
1544 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001545#else
1546 BUG_ON(id >= RX_BUF_NUM);
1547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 /* free old buffers */
Atsushi Nemotoccc57aa2008-06-26 17:14:15 +09001549 lp->fbl_count--;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001550 while (lp->fbl_count < RX_BUF_NUM)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001551 {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001552 unsigned char curid =
1553 (id + 1 + lp->fbl_count) % RX_BUF_NUM;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001554 struct BDesc *bd = &lp->fbl_ptr->bd[curid];
1555#ifdef DEBUG
1556 bdctl = le32_to_cpu(bd->BDCtl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 if (bdctl & BD_CownsBD) {
1558 printk("%s: Freeing invalid BD.\n",
1559 dev->name);
1560 panic_queues(dev);
1561 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001562#endif
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +02001563 /* pass BD to controller */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001564 if (!lp->rx_skbs[curid].skb) {
1565 lp->rx_skbs[curid].skb =
1566 alloc_rxbuf_skb(dev,
1567 lp->pci_dev,
1568 &lp->rx_skbs[curid].skb_dma);
1569 if (!lp->rx_skbs[curid].skb)
1570 break; /* try on next reception */
1571 bd->BuffData = cpu_to_le32(lp->rx_skbs[curid].skb_dma);
1572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 /* Note: BDLength was modified by chip. */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001574 bd->BDCtl = cpu_to_le32(BD_CownsBD |
1575 (curid << BD_RxBDID_SHIFT) |
1576 RX_BUF_SIZE);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001577 lp->fbl_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 }
1579 }
1580
1581 /* put RxFD back to controller */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001582#ifdef DEBUG
1583 next_rfd = fd_bus_to_virt(lp,
1584 le32_to_cpu(lp->rfd_cur->fd.FDNext));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 if (next_rfd < lp->rfd_base || next_rfd > lp->rfd_limit) {
1586 printk("%s: RxFD FDNext invalid.\n", dev->name);
1587 panic_queues(dev);
1588 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 for (i = 0; i < (bd_count + 1) / 2 + 1; i++) {
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +02001591 /* pass FD to controller */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001592#ifdef DEBUG
1593 lp->rfd_cur->fd.FDNext = cpu_to_le32(0xdeaddead);
1594#else
1595 lp->rfd_cur->fd.FDNext = cpu_to_le32(FD_Next_EOL);
1596#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 lp->rfd_cur->fd.FDCtl = cpu_to_le32(FD_CownsFD);
1598 lp->rfd_cur++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001600 if (lp->rfd_cur > lp->rfd_limit)
1601 lp->rfd_cur = lp->rfd_base;
1602#ifdef DEBUG
1603 if (lp->rfd_cur != next_rfd)
1604 printk("rfd_cur = %p, next_rfd %p\n",
1605 lp->rfd_cur, next_rfd);
1606#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
1608
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001609 return received;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001612static int tc35815_poll(struct napi_struct *napi, int budget)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001613{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001614 struct tc35815_local *lp = container_of(napi, struct tc35815_local, napi);
1615 struct net_device *dev = lp->dev;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001616 struct tc35815_regs __iomem *tr =
1617 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001618 int received = 0, handled;
1619 u32 status;
1620
Eric W. Biederman176f7922014-03-14 18:10:14 -07001621 if (budget <= 0)
1622 return received;
1623
Atsushi Nemotodee73992010-02-24 06:00:34 +00001624 spin_lock(&lp->rx_lock);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001625 status = tc_readl(&tr->Int_Src);
1626 do {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001627 /* BLEx, FDAEx will be cleared later */
1628 tc_writel(status & ~(Int_BLEx | Int_FDAEx),
1629 &tr->Int_Src); /* write to clear */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001630
Atsushi Nemotoa2c465d2009-04-02 01:17:36 -07001631 handled = tc35815_do_interrupt(dev, status, budget - received);
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001632 if (status & (Int_BLEx | Int_FDAEx))
1633 tc_writel(status & (Int_BLEx | Int_FDAEx),
1634 &tr->Int_Src);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001635 if (handled >= 0) {
1636 received += handled;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001637 if (received >= budget)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001638 break;
1639 }
1640 status = tc_readl(&tr->Int_Src);
1641 } while (status);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001642 spin_unlock(&lp->rx_lock);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001643
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001644 if (received < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001645 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001646 /* enable interrupts */
1647 tc_writel(tc_readl(&tr->DMA_Ctl) & ~DMA_IntMask, &tr->DMA_Ctl);
1648 }
1649 return received;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001650}
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652#define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_NCarr|Tx_LateColl|Tx_TxPar|Tx_SQErr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654static void
1655tc35815_check_tx_stat(struct net_device *dev, int status)
1656{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001657 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 const char *msg = NULL;
1659
1660 /* count collisions */
1661 if (status & Tx_ExColl)
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001662 dev->stats.collisions += 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (status & Tx_TxColl_MASK)
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001664 dev->stats.collisions += status & Tx_TxColl_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001666 /* TX4939 does not have NCarr */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001667 if (lp->chiptype == TC35815_TX4939)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 status &= ~Tx_NCarr;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001669 /* WORKAROUND: ignore LostCrS in full duplex operation */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001670 if (!lp->link || lp->duplex == DUPLEX_FULL)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001671 status &= ~Tx_NCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 if (!(status & TX_STA_ERR)) {
1674 /* no error. */
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001675 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 return;
1677 }
1678
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001679 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 if (status & Tx_ExColl) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001681 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 msg = "Excessive Collision.";
1683 }
1684 if (status & Tx_Under) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001685 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 msg = "Tx FIFO Underrun.";
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001687 if (lp->lstats.tx_underrun < TX_THRESHOLD_KEEP_LIMIT) {
1688 lp->lstats.tx_underrun++;
1689 if (lp->lstats.tx_underrun >= TX_THRESHOLD_KEEP_LIMIT) {
1690 struct tc35815_regs __iomem *tr =
1691 (struct tc35815_regs __iomem *)dev->base_addr;
1692 tc_writel(TX_THRESHOLD_MAX, &tr->TxThrsh);
1693 msg = "Tx FIFO Underrun.Change Tx threshold to max.";
1694 }
1695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 }
1697 if (status & Tx_Defer) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001698 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 msg = "Excessive Deferral.";
1700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (status & Tx_NCarr) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001702 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 msg = "Lost Carrier Sense.";
1704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 if (status & Tx_LateColl) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001706 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 msg = "Late Collision.";
1708 }
1709 if (status & Tx_TxPar) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001710 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 msg = "Transmit Parity Error.";
1712 }
1713 if (status & Tx_SQErr) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001714 dev->stats.tx_heartbeat_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 msg = "Signal Quality Error.";
1716 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001717 if (msg && netif_msg_tx_err(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 printk(KERN_WARNING "%s: %s (%#x)\n", dev->name, msg, status);
1719}
1720
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001721/* This handles TX complete events posted by the device
1722 * via interrupts.
1723 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724static void
1725tc35815_txdone(struct net_device *dev)
1726{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001727 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 struct TxFD *txfd;
1729 unsigned int fdctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
1731 txfd = &lp->tfd_base[lp->tfd_end];
1732 while (lp->tfd_start != lp->tfd_end &&
1733 !((fdctl = le32_to_cpu(txfd->fd.FDCtl)) & FD_CownsFD)) {
1734 int status = le32_to_cpu(txfd->fd.FDStat);
1735 struct sk_buff *skb;
1736 unsigned long fdnext = le32_to_cpu(txfd->fd.FDNext);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001737 u32 fdsystem = le32_to_cpu(txfd->fd.FDSystem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001739 if (netif_msg_tx_done(lp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 printk("%s: complete TxFD.\n", dev->name);
1741 dump_txfd(txfd);
1742 }
1743 tc35815_check_tx_stat(dev, status);
1744
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001745 skb = fdsystem != 0xffffffff ?
1746 lp->tx_skbs[fdsystem].skb : NULL;
1747#ifdef DEBUG
1748 if (lp->tx_skbs[lp->tfd_end].skb != skb) {
1749 printk("%s: tx_skbs mismatch.\n", dev->name);
1750 panic_queues(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001752#else
1753 BUG_ON(lp->tx_skbs[lp->tfd_end].skb != skb);
1754#endif
1755 if (skb) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001756 dev->stats.tx_bytes += skb->len;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001757 pci_unmap_single(lp->pci_dev, lp->tx_skbs[lp->tfd_end].skb_dma, skb->len, PCI_DMA_TODEVICE);
1758 lp->tx_skbs[lp->tfd_end].skb = NULL;
1759 lp->tx_skbs[lp->tfd_end].skb_dma = 0;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001760 dev_kfree_skb_any(skb);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001761 }
1762 txfd->fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 lp->tfd_end = (lp->tfd_end + 1) % TX_FD_NUM;
1765 txfd = &lp->tfd_base[lp->tfd_end];
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001766#ifdef DEBUG
1767 if ((fdnext & ~FD_Next_EOL) != fd_virt_to_bus(lp, txfd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 printk("%s: TxFD FDNext invalid.\n", dev->name);
1769 panic_queues(dev);
1770 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001771#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 if (fdnext & FD_Next_EOL) {
1773 /* DMA Transmitter has been stopping... */
1774 if (lp->tfd_end != lp->tfd_start) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001775 struct tc35815_regs __iomem *tr =
1776 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 int head = (lp->tfd_start + TX_FD_NUM - 1) % TX_FD_NUM;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001778 struct TxFD *txhead = &lp->tfd_base[head];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 int qlen = (lp->tfd_start + TX_FD_NUM
1780 - lp->tfd_end) % TX_FD_NUM;
1781
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001782#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 if (!(le32_to_cpu(txfd->fd.FDCtl) & FD_CownsFD)) {
1784 printk("%s: TxFD FDCtl invalid.\n", dev->name);
1785 panic_queues(dev);
1786 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001787#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 /* log max queue length */
1789 if (lp->lstats.max_tx_qlen < qlen)
1790 lp->lstats.max_tx_qlen = qlen;
1791
1792
1793 /* start DMA Transmitter again */
1794 txhead->fd.FDNext |= cpu_to_le32(FD_Next_EOL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 txhead->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001796 if (netif_msg_tx_queued(lp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 printk("%s: start TxFD on queue.\n",
1798 dev->name);
1799 dump_txfd(txfd);
1800 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001801 tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
1803 break;
1804 }
1805 }
1806
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001807 /* If we had stopped the queue due to a "tx full"
1808 * condition, and space has now been made available,
1809 * wake up the queue.
1810 */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001811 if (netif_queue_stopped(dev) && !tc35815_tx_full(dev))
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001812 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813}
1814
1815/* The inverse routine to tc35815_open(). */
1816static int
1817tc35815_close(struct net_device *dev)
1818{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001819 struct tc35815_local *lp = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001822 napi_disable(&lp->napi);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001823 if (lp->phy_dev)
1824 phy_stop(lp->phy_dev);
1825 cancel_work_sync(&lp->restart_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 /* Flush the Tx and disable Rx here. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 tc35815_chip_reset(dev);
1829 free_irq(dev->irq, dev);
1830
1831 tc35815_free_queues(dev);
1832
1833 return 0;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
1836
1837/*
1838 * Get the current statistics.
1839 * This may be called with the card open or closed.
1840 */
1841static struct net_device_stats *tc35815_get_stats(struct net_device *dev)
1842{
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001843 struct tc35815_regs __iomem *tr =
1844 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001845 if (netif_running(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 /* Update the statistics from the device registers. */
Atsushi Nemoto7bb82e82009-08-06 04:41:48 +00001847 dev->stats.rx_missed_errors += tc_readl(&tr->Miss_Cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001849 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850}
1851
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001852static void tc35815_set_cam_entry(struct net_device *dev, int index, unsigned char *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001854 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001855 struct tc35815_regs __iomem *tr =
1856 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 int cam_index = index * 6;
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001858 u32 cam_data;
1859 u32 saved_addr;
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001860
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 saved_addr = tc_readl(&tr->CAM_Adr);
1862
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001863 if (netif_msg_hw(lp))
Johannes Berge1749612008-10-27 15:59:26 -07001864 printk(KERN_DEBUG "%s: CAM %d: %pM\n",
1865 dev->name, index, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 if (index & 1) {
1867 /* read modify write */
1868 tc_writel(cam_index - 2, &tr->CAM_Adr);
1869 cam_data = tc_readl(&tr->CAM_Data) & 0xffff0000;
1870 cam_data |= addr[0] << 8 | addr[1];
1871 tc_writel(cam_data, &tr->CAM_Data);
1872 /* write whole word */
1873 tc_writel(cam_index + 2, &tr->CAM_Adr);
1874 cam_data = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) | addr[5];
1875 tc_writel(cam_data, &tr->CAM_Data);
1876 } else {
1877 /* write whole word */
1878 tc_writel(cam_index, &tr->CAM_Adr);
1879 cam_data = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
1880 tc_writel(cam_data, &tr->CAM_Data);
1881 /* read modify write */
1882 tc_writel(cam_index + 4, &tr->CAM_Adr);
1883 cam_data = tc_readl(&tr->CAM_Data) & 0x0000ffff;
1884 cam_data |= addr[4] << 24 | (addr[5] << 16);
1885 tc_writel(cam_data, &tr->CAM_Data);
1886 }
1887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 tc_writel(saved_addr, &tr->CAM_Adr);
1889}
1890
1891
1892/*
1893 * Set or clear the multicast filter for this adaptor.
1894 * num_addrs == -1 Promiscuous mode, receive all packets
1895 * num_addrs == 0 Normal mode, clear multicast list
1896 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1897 * and do best-effort filtering.
1898 */
1899static void
1900tc35815_set_multicast_list(struct net_device *dev)
1901{
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001902 struct tc35815_regs __iomem *tr =
1903 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001905 if (dev->flags & IFF_PROMISC) {
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001906 /* With some (all?) 100MHalf HUB, controller will hang
1907 * if we enabled promiscuous mode before linkup... */
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001908 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001909
1910 if (!lp->link)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001911 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 /* Enable promiscuous mode */
1913 tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc | CAM_StationAcc, &tr->CAM_Ctl);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001914 } else if ((dev->flags & IFF_ALLMULTI) ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001915 netdev_mc_count(dev) > CAM_ENTRY_MAX - 3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 /* CAM 0, 1, 20 are reserved. */
1917 /* Disable promiscuous mode, use normal mode. */
1918 tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc, &tr->CAM_Ctl);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001919 } else if (!netdev_mc_empty(dev)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001920 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 int i;
1922 int ena_bits = CAM_Ena_Bit(CAM_ENTRY_SOURCE);
1923
1924 tc_writel(0, &tr->CAM_Ctl);
1925 /* Walk the address list, and load the filter */
Jiri Pirko567ec872010-02-23 23:17:07 +00001926 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001927 netdev_for_each_mc_addr(ha, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 /* entry 0,1 is reserved. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001929 tc35815_set_cam_entry(dev, i + 2, ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 ena_bits |= CAM_Ena_Bit(i + 2);
Jiri Pirko567ec872010-02-23 23:17:07 +00001931 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 }
1933 tc_writel(ena_bits, &tr->CAM_Ena);
1934 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001935 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena);
1937 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
1938 }
1939}
1940
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001941static void tc35815_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001943 struct tc35815_local *lp = netdev_priv(dev);
Jiri Pirko7826d432013-01-06 00:44:26 +00001944
1945 strlcpy(info->driver, MODNAME, sizeof(info->driver));
1946 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
1947 strlcpy(info->bus_info, pci_name(lp->pci_dev), sizeof(info->bus_info));
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001948}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001949
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001950static int tc35815_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1951{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001952 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001953
1954 if (!lp->phy_dev)
1955 return -ENODEV;
1956 return phy_ethtool_gset(lp->phy_dev, cmd);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001957}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001959static int tc35815_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1960{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001961 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001962
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001963 if (!lp->phy_dev)
1964 return -ENODEV;
1965 return phy_ethtool_sset(lp->phy_dev, cmd);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001966}
1967
1968static u32 tc35815_get_msglevel(struct net_device *dev)
1969{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001970 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001971 return lp->msg_enable;
1972}
1973
1974static void tc35815_set_msglevel(struct net_device *dev, u32 datum)
1975{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001976 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001977 lp->msg_enable = datum;
1978}
1979
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001980static int tc35815_get_sset_count(struct net_device *dev, int sset)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001981{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001982 struct tc35815_local *lp = netdev_priv(dev);
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001983
1984 switch (sset) {
1985 case ETH_SS_STATS:
1986 return sizeof(lp->lstats) / sizeof(int);
1987 default:
1988 return -EOPNOTSUPP;
1989 }
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001990}
1991
1992static void tc35815_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data)
1993{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001994 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09001995 data[0] = lp->lstats.max_tx_qlen;
1996 data[1] = lp->lstats.tx_ints;
1997 data[2] = lp->lstats.rx_ints;
1998 data[3] = lp->lstats.tx_underrun;
1999}
2000
2001static struct {
2002 const char str[ETH_GSTRING_LEN];
2003} ethtool_stats_keys[] = {
2004 { "max_tx_qlen" },
2005 { "tx_ints" },
2006 { "rx_ints" },
2007 { "tx_underrun" },
2008};
2009
2010static void tc35815_get_strings(struct net_device *dev, u32 stringset, u8 *data)
2011{
2012 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
2013}
2014
2015static const struct ethtool_ops tc35815_ethtool_ops = {
2016 .get_drvinfo = tc35815_get_drvinfo,
2017 .get_settings = tc35815_get_settings,
2018 .set_settings = tc35815_set_settings,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002019 .get_link = ethtool_op_get_link,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002020 .get_msglevel = tc35815_get_msglevel,
2021 .set_msglevel = tc35815_set_msglevel,
2022 .get_strings = tc35815_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002023 .get_sset_count = tc35815_get_sset_count,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002024 .get_ethtool_stats = tc35815_get_ethtool_stats,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002025};
2026
2027static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2028{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002029 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002030
2031 if (!netif_running(dev))
2032 return -EINVAL;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002033 if (!lp->phy_dev)
2034 return -ENODEV;
Richard Cochran28b04112010-07-17 08:48:55 +00002035 return phy_mii_ioctl(lp->phy_dev, rq, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036}
2037
2038static void tc35815_chip_reset(struct net_device *dev)
2039{
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002040 struct tc35815_regs __iomem *tr =
2041 (struct tc35815_regs __iomem *)dev->base_addr;
2042 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 /* reset the controller */
2044 tc_writel(MAC_Reset, &tr->MAC_Ctl);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002045 udelay(4); /* 3200ns */
2046 i = 0;
2047 while (tc_readl(&tr->MAC_Ctl) & MAC_Reset) {
2048 if (i++ > 100) {
2049 printk(KERN_ERR "%s: MAC reset failed.\n", dev->name);
2050 break;
2051 }
2052 mdelay(1);
2053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 tc_writel(0, &tr->MAC_Ctl);
2055
2056 /* initialize registers to default value */
2057 tc_writel(0, &tr->DMA_Ctl);
2058 tc_writel(0, &tr->TxThrsh);
2059 tc_writel(0, &tr->TxPollCtr);
2060 tc_writel(0, &tr->RxFragSize);
2061 tc_writel(0, &tr->Int_En);
2062 tc_writel(0, &tr->FDA_Bas);
2063 tc_writel(0, &tr->FDA_Lim);
2064 tc_writel(0xffffffff, &tr->Int_Src); /* Write 1 to clear */
2065 tc_writel(0, &tr->CAM_Ctl);
2066 tc_writel(0, &tr->Tx_Ctl);
2067 tc_writel(0, &tr->Rx_Ctl);
2068 tc_writel(0, &tr->CAM_Ena);
2069 (void)tc_readl(&tr->Miss_Cnt); /* Read to clear */
2070
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002071 /* initialize internal SRAM */
2072 tc_writel(DMA_TestMode, &tr->DMA_Ctl);
2073 for (i = 0; i < 0x1000; i += 4) {
2074 tc_writel(i, &tr->CAM_Adr);
2075 tc_writel(0, &tr->CAM_Data);
2076 }
2077 tc_writel(0, &tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
2080static void tc35815_chip_init(struct net_device *dev)
2081{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002082 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002083 struct tc35815_regs __iomem *tr =
2084 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 unsigned long txctl = TX_CTL_CMD;
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 /* load station address to CAM */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002088 tc35815_set_cam_entry(dev, CAM_ENTRY_SOURCE, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 /* Enable CAM (broadcast and unicast) */
2091 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena);
2092 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
2093
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002094 /* Use DMA_RxAlign_2 to make IP header 4-byte aligned. */
2095 if (HAVE_DMA_RXALIGN(lp))
2096 tc_writel(DMA_BURST_SIZE | DMA_RxAlign_2, &tr->DMA_Ctl);
2097 else
2098 tc_writel(DMA_BURST_SIZE, &tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 tc_writel(0, &tr->TxPollCtr); /* Batch mode */
2100 tc_writel(TX_THRESHOLD, &tr->TxThrsh);
2101 tc_writel(INT_EN_CMD, &tr->Int_En);
2102
2103 /* set queues */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002104 tc_writel(fd_virt_to_bus(lp, lp->rfd_base), &tr->FDA_Bas);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 tc_writel((unsigned long)lp->rfd_limit - (unsigned long)lp->rfd_base,
2106 &tr->FDA_Lim);
2107 /*
2108 * Activation method:
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002109 * First, enable the MAC Transmitter and the DMA Receive circuits.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 * Then enable the DMA Transmitter and the MAC Receive circuits.
2111 */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002112 tc_writel(fd_virt_to_bus(lp, lp->fbl_ptr), &tr->BLFrmPtr); /* start DMA receiver */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 tc_writel(RX_CTL_CMD, &tr->Rx_Ctl); /* start MAC receiver */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002114
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 /* start MAC transmitter */
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002116 /* TX4939 does not have EnLCarr */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002117 if (lp->chiptype == TC35815_TX4939)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002118 txctl &= ~Tx_EnLCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 /* WORKAROUND: ignore LostCrS in full duplex operation */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002120 if (!lp->phy_dev || !lp->link || lp->duplex == DUPLEX_FULL)
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002121 txctl &= ~Tx_EnLCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 tc_writel(txctl, &tr->Tx_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002125#ifdef CONFIG_PM
2126static int tc35815_suspend(struct pci_dev *pdev, pm_message_t state)
2127{
2128 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002129 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002130 unsigned long flags;
2131
2132 pci_save_state(pdev);
2133 if (!netif_running(dev))
2134 return 0;
2135 netif_device_detach(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002136 if (lp->phy_dev)
2137 phy_stop(lp->phy_dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002138 spin_lock_irqsave(&lp->lock, flags);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002139 tc35815_chip_reset(dev);
2140 spin_unlock_irqrestore(&lp->lock, flags);
2141 pci_set_power_state(pdev, PCI_D3hot);
2142 return 0;
2143}
2144
2145static int tc35815_resume(struct pci_dev *pdev)
2146{
2147 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002148 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002149
2150 pci_restore_state(pdev);
2151 if (!netif_running(dev))
2152 return 0;
2153 pci_set_power_state(pdev, PCI_D0);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002154 tc35815_restart(dev);
Atsushi Nemoto59524a32008-06-25 11:41:01 +09002155 netif_carrier_off(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002156 if (lp->phy_dev)
2157 phy_start(lp->phy_dev);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002158 netif_device_attach(dev);
2159 return 0;
2160}
2161#endif /* CONFIG_PM */
2162
2163static struct pci_driver tc35815_pci_driver = {
2164 .name = MODNAME,
2165 .id_table = tc35815_pci_tbl,
2166 .probe = tc35815_init_one,
Bill Pembertonb38d1302012-12-03 09:23:47 -05002167 .remove = tc35815_remove_one,
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002168#ifdef CONFIG_PM
2169 .suspend = tc35815_suspend,
2170 .resume = tc35815_resume,
2171#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172};
2173
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002174module_param_named(speed, options.speed, int, 0);
2175MODULE_PARM_DESC(speed, "0:auto, 10:10Mbps, 100:100Mbps");
2176module_param_named(duplex, options.duplex, int, 0);
2177MODULE_PARM_DESC(duplex, "0:auto, 1:half, 2:full");
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002178
Peter Hüweb6f57212013-05-21 12:42:12 +00002179module_pci_driver(tc35815_pci_driver);
Atsushi Nemotoeea221c2007-03-03 23:54:59 +09002180MODULE_DESCRIPTION("TOSHIBA TC35815 PCI 10M/100M Ethernet driver");
2181MODULE_LICENSE("GPL");