blob: 7163a8d10dba0bb5bb30299e7de1f1dce76fafc4 [file] [log] [blame]
Atsushi Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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"
Kees Cook06324662017-05-08 15:59:05 -070026static const char version[] = "tc35815.c:v" DRV_VERSION "\n";
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +090027#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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-03-03 23:54:59 +090054 TC35815CF = 0,
55 TC35815_NWU,
56 TC35815_TX4939,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090057};
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +090058
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +090059/* indexed by tc35815_chiptype, above */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +090060static const struct {
61 const char *name;
Bill Pembertonb38d1302012-12-03 09:23:47 -050062} chip_info[] = {
Atsushi Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-03-03 23:54:59 +090075
76/* see MODULE_PARM_DESC */
77static struct tc35815_options {
78 int speed;
79 int duplex;
Atsushi Nemotoeea221ce42007-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
Colin Ian King1b283242016-06-22 17:42:21 +0100283/* Frame descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284struct FDesc {
285 volatile __u32 FDNext;
286 volatile __u32 FDSystem;
287 volatile __u32 FDStat;
288 volatile __u32 FDCtl;
289};
290
Colin Ian King1b283242016-06-22 17:42:21 +0100291/* Buffer descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292struct BDesc {
293 volatile __u32 BuffData;
294 volatile __u32 BDCtl;
295};
296
297#define FD_ALIGN 16
298
Colin Ian King1b283242016-06-22 17:42:21 +0100299/* Frame Descriptor 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
Colin Ian King1b283242016-06-22 17:42:21 +0100312/* Buffer Descriptor bit assign --------------------------------------------- */
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300313#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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-03-03 23:54:59 +0900358#endif
Atsushi Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 Nemotoeea221ce42007-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 int duplex;
409 int speed;
410 int link;
411 struct work_struct restart_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /*
414 * Transmitting: Batch Mode.
415 * 1 BD in 1 TxFD.
Atsushi Nemotoa02b7b72009-11-02 04:34:47 +0000416 * Receiving: Non-Packing Mode.
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900417 * 1 circular FD for Free Buffer List.
418 * RX_BUF_NUM BD in Free Buffer FD.
419 * One Free Buffer BD has ETH_FRAME_LEN data buffer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900421 void *fd_buf; /* for TxFD, RxFD, FrFD */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900422 dma_addr_t fd_buf_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 struct TxFD *tfd_base;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900424 unsigned int tfd_start;
425 unsigned int tfd_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 struct RxFD *rfd_base;
427 struct RxFD *rfd_limit;
428 struct RxFD *rfd_cur;
429 struct FrFD *fbl_ptr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900430 unsigned int fbl_count;
431 struct {
432 struct sk_buff *skb;
433 dma_addr_t skb_dma;
434 } tx_skbs[TX_FD_NUM], rx_skbs[RX_BUF_NUM];
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900435 u32 msg_enable;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900436 enum tc35815_chiptype chiptype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437};
438
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900439static inline dma_addr_t fd_virt_to_bus(struct tc35815_local *lp, void *virt)
440{
441 return lp->fd_buf_dma + ((u8 *)virt - (u8 *)lp->fd_buf);
442}
443#ifdef DEBUG
444static inline void *fd_bus_to_virt(struct tc35815_local *lp, dma_addr_t bus)
445{
446 return (void *)((u8 *)lp->fd_buf + (bus - lp->fd_buf_dma));
447}
448#endif
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900449static struct sk_buff *alloc_rxbuf_skb(struct net_device *dev,
450 struct pci_dev *hwdev,
451 dma_addr_t *dma_handle)
452{
453 struct sk_buff *skb;
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +0000454 skb = netdev_alloc_skb(dev, RX_BUF_SIZE);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900455 if (!skb)
456 return NULL;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900457 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE,
458 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700459 if (pci_dma_mapping_error(hwdev, *dma_handle)) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900460 dev_kfree_skb_any(skb);
461 return NULL;
462 }
463 skb_reserve(skb, 2); /* make IP header 4byte aligned */
464 return skb;
465}
466
467static void free_rxbuf_skb(struct pci_dev *hwdev, struct sk_buff *skb, dma_addr_t dma_handle)
468{
469 pci_unmap_single(hwdev, dma_handle, RX_BUF_SIZE,
470 PCI_DMA_FROMDEVICE);
471 dev_kfree_skb_any(skb);
472}
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/* Index to functions, as function prototypes. */
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476static int tc35815_open(struct net_device *dev);
477static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900478static irqreturn_t tc35815_interrupt(int irq, void *dev_id);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900479static int tc35815_rx(struct net_device *dev, int limit);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700480static int tc35815_poll(struct napi_struct *napi, int budget);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481static void tc35815_txdone(struct net_device *dev);
482static int tc35815_close(struct net_device *dev);
483static struct net_device_stats *tc35815_get_stats(struct net_device *dev);
484static void tc35815_set_multicast_list(struct net_device *dev);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900485static void tc35815_tx_timeout(struct net_device *dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900486static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
487#ifdef CONFIG_NET_POLL_CONTROLLER
488static void tc35815_poll_controller(struct net_device *dev);
489#endif
490static const struct ethtool_ops tc35815_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900492/* Example routines you must write ;->. */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900493static void tc35815_chip_reset(struct net_device *dev);
494static void tc35815_chip_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900496#ifdef DEBUG
497static void panic_queues(struct net_device *dev);
498#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900500static void tc35815_restart_work(struct work_struct *work);
501
502static int tc_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
503{
504 struct net_device *dev = bus->priv;
505 struct tc35815_regs __iomem *tr =
506 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoc60a5cf2009-08-06 04:41:47 +0000507 unsigned long timeout = jiffies + HZ;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900508
509 tc_writel(MD_CA_Busy | (mii_id << 5) | (regnum & 0x1f), &tr->MD_CA);
Atsushi Nemotoc60a5cf2009-08-06 04:41:47 +0000510 udelay(12); /* it takes 32 x 400ns at least */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900511 while (tc_readl(&tr->MD_CA) & MD_CA_Busy) {
512 if (time_after(jiffies, timeout))
513 return -EIO;
514 cpu_relax();
515 }
516 return tc_readl(&tr->MD_Data) & 0xffff;
517}
518
519static int tc_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 val)
520{
521 struct net_device *dev = bus->priv;
522 struct tc35815_regs __iomem *tr =
523 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoc60a5cf2009-08-06 04:41:47 +0000524 unsigned long timeout = jiffies + HZ;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900525
526 tc_writel(val, &tr->MD_Data);
527 tc_writel(MD_CA_Busy | MD_CA_Wr | (mii_id << 5) | (regnum & 0x1f),
528 &tr->MD_CA);
Atsushi Nemotoc60a5cf2009-08-06 04:41:47 +0000529 udelay(12); /* it takes 32 x 400ns at least */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900530 while (tc_readl(&tr->MD_CA) & MD_CA_Busy) {
531 if (time_after(jiffies, timeout))
532 return -EIO;
533 cpu_relax();
534 }
535 return 0;
536}
537
538static void tc_handle_link_change(struct net_device *dev)
539{
540 struct tc35815_local *lp = netdev_priv(dev);
Philippe Reynesa4fc5492016-07-14 15:20:46 +0200541 struct phy_device *phydev = dev->phydev;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900542 unsigned long flags;
543 int status_change = 0;
544
545 spin_lock_irqsave(&lp->lock, flags);
546 if (phydev->link &&
547 (lp->speed != phydev->speed || lp->duplex != phydev->duplex)) {
548 struct tc35815_regs __iomem *tr =
549 (struct tc35815_regs __iomem *)dev->base_addr;
550 u32 reg;
551
552 reg = tc_readl(&tr->MAC_Ctl);
553 reg |= MAC_HaltReq;
554 tc_writel(reg, &tr->MAC_Ctl);
555 if (phydev->duplex == DUPLEX_FULL)
556 reg |= MAC_FullDup;
557 else
558 reg &= ~MAC_FullDup;
559 tc_writel(reg, &tr->MAC_Ctl);
560 reg &= ~MAC_HaltReq;
561 tc_writel(reg, &tr->MAC_Ctl);
562
563 /*
564 * TX4939 PCFG.SPEEDn bit will be changed on
565 * NETDEV_CHANGE event.
566 */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900567 /*
568 * WORKAROUND: enable LostCrS only if half duplex
569 * operation.
570 * (TX4939 does not have EnLCarr)
571 */
572 if (phydev->duplex == DUPLEX_HALF &&
573 lp->chiptype != TC35815_TX4939)
574 tc_writel(tc_readl(&tr->Tx_Ctl) | Tx_EnLCarr,
575 &tr->Tx_Ctl);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900576
577 lp->speed = phydev->speed;
578 lp->duplex = phydev->duplex;
579 status_change = 1;
580 }
581
582 if (phydev->link != lp->link) {
583 if (phydev->link) {
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900584 /* delayed promiscuous enabling */
585 if (dev->flags & IFF_PROMISC)
586 tc35815_set_multicast_list(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900587 } else {
588 lp->speed = 0;
589 lp->duplex = -1;
590 }
591 lp->link = phydev->link;
592
593 status_change = 1;
594 }
595 spin_unlock_irqrestore(&lp->lock, flags);
596
597 if (status_change && netif_msg_link(lp)) {
598 phy_print_status(phydev);
Joe Perches72903832009-05-15 07:59:42 +0000599 pr_debug("%s: MII BMCR %04x BMSR %04x LPA %04x\n",
600 dev->name,
601 phy_read(phydev, MII_BMCR),
602 phy_read(phydev, MII_BMSR),
603 phy_read(phydev, MII_LPA));
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900604 }
605}
606
607static int tc_mii_probe(struct net_device *dev)
608{
609 struct tc35815_local *lp = netdev_priv(dev);
Guenter Roecka05876b2016-01-10 07:10:44 -0800610 struct phy_device *phydev;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900611 u32 dropmask;
612
Guenter Roecka05876b2016-01-10 07:10:44 -0800613 phydev = phy_find_first(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900614 if (!phydev) {
615 printk(KERN_ERR "%s: no PHY found\n", dev->name);
616 return -ENODEV;
617 }
618
619 /* attach the mac to the phy */
Andrew Lunn84eff6d2016-01-06 20:11:10 +0100620 phydev = phy_connect(dev, phydev_name(phydev),
Florian Fainellif9a8f832013-01-14 00:52:52 +0000621 &tc_handle_link_change,
622 lp->chiptype == TC35815_TX4939 ? PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900623 if (IS_ERR(phydev)) {
624 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
625 return PTR_ERR(phydev);
626 }
Andrew Lunn22209432016-01-06 20:11:13 +0100627
628 phy_attached_info(phydev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900629
630 /* mask with MAC supported features */
Andrew Lunn58056c12018-09-12 01:53:11 +0200631 phy_set_max_speed(phydev, SPEED_100);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900632 dropmask = 0;
633 if (options.speed == 10)
634 dropmask |= SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
635 else if (options.speed == 100)
636 dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full;
637 if (options.duplex == 1)
638 dropmask |= SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Full;
639 else if (options.duplex == 2)
640 dropmask |= SUPPORTED_10baseT_Half | SUPPORTED_100baseT_Half;
641 phydev->supported &= ~dropmask;
642 phydev->advertising = phydev->supported;
643
644 lp->link = 0;
645 lp->speed = 0;
646 lp->duplex = -1;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900647
648 return 0;
649}
650
651static int tc_mii_init(struct net_device *dev)
652{
653 struct tc35815_local *lp = netdev_priv(dev);
654 int err;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900655
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700656 lp->mii_bus = mdiobus_alloc();
657 if (lp->mii_bus == NULL) {
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900658 err = -ENOMEM;
659 goto err_out;
660 }
661
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700662 lp->mii_bus->name = "tc35815_mii_bus";
663 lp->mii_bus->read = tc_mdio_read;
664 lp->mii_bus->write = tc_mdio_write;
665 snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "%x",
666 (lp->pci_dev->bus->number << 8) | lp->pci_dev->devfn);
667 lp->mii_bus->priv = dev;
668 lp->mii_bus->parent = &lp->pci_dev->dev;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700669 err = mdiobus_register(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900670 if (err)
Andrew Lunne7f4dc32016-01-06 20:11:15 +0100671 goto err_out_free_mii_bus;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900672 err = tc_mii_probe(dev);
673 if (err)
674 goto err_out_unregister_bus;
675 return 0;
676
677err_out_unregister_bus:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700678 mdiobus_unregister(lp->mii_bus);
Adrian Bunk51cf7562008-10-12 21:01:53 -0700679err_out_free_mii_bus:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700680 mdiobus_free(lp->mii_bus);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900681err_out:
682 return err;
683}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900685#ifdef CONFIG_CPU_TX49XX
686/*
687 * Find a platform_device providing a MAC address. The platform code
688 * should provide a "tc35815-mac" device with a MAC address in its
689 * platform_data.
690 */
Bill Pembertonb38d1302012-12-03 09:23:47 -0500691static int tc35815_mac_match(struct device *dev, void *data)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900692{
693 struct platform_device *plat_dev = to_platform_device(dev);
694 struct pci_dev *pci_dev = data;
Atsushi Nemoto06675e62008-01-19 01:15:52 +0900695 unsigned int id = pci_dev->irq;
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900696 return !strcmp(plat_dev->name, "tc35815-mac") && plat_dev->id == id;
697}
698
Bill Pembertonb38d1302012-12-03 09:23:47 -0500699static int tc35815_read_plat_dev_addr(struct net_device *dev)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900700{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900701 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900702 struct device *pd = bus_find_device(&platform_bus_type, NULL,
703 lp->pci_dev, tc35815_mac_match);
704 if (pd) {
705 if (pd->platform_data)
706 memcpy(dev->dev_addr, pd->platform_data, ETH_ALEN);
707 put_device(pd);
708 return is_valid_ether_addr(dev->dev_addr) ? 0 : -ENODEV;
709 }
710 return -ENODEV;
711}
712#else
Bill Pembertonb38d1302012-12-03 09:23:47 -0500713static int tc35815_read_plat_dev_addr(struct net_device *dev)
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900714{
715 return -ENODEV;
716}
717#endif
718
Bill Pembertonb38d1302012-12-03 09:23:47 -0500719static int tc35815_init_dev_addr(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900721 struct tc35815_regs __iomem *tr =
722 (struct tc35815_regs __iomem *)dev->base_addr;
723 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 while (tc_readl(&tr->PROM_Ctl) & PROM_Busy)
726 ;
727 for (i = 0; i < 6; i += 2) {
728 unsigned short data;
729 tc_writel(PROM_Busy | PROM_Read | (i / 2 + 2), &tr->PROM_Ctl);
730 while (tc_readl(&tr->PROM_Ctl) & PROM_Busy)
731 ;
732 data = tc_readl(&tr->PROM_Data);
733 dev->dev_addr[i] = data & 0xff;
734 dev->dev_addr[i+1] = data >> 8;
735 }
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900736 if (!is_valid_ether_addr(dev->dev_addr))
737 return tc35815_read_plat_dev_addr(dev);
738 return 0;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900739}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000741static const struct net_device_ops tc35815_netdev_ops = {
742 .ndo_open = tc35815_open,
743 .ndo_stop = tc35815_close,
744 .ndo_start_xmit = tc35815_send_packet,
745 .ndo_get_stats = tc35815_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000746 .ndo_set_rx_mode = tc35815_set_multicast_list,
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000747 .ndo_tx_timeout = tc35815_tx_timeout,
748 .ndo_do_ioctl = tc35815_ioctl,
749 .ndo_validate_addr = eth_validate_addr,
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000750 .ndo_set_mac_address = eth_mac_addr,
751#ifdef CONFIG_NET_POLL_CONTROLLER
752 .ndo_poll_controller = tc35815_poll_controller,
753#endif
754};
755
Bill Pembertonb38d1302012-12-03 09:23:47 -0500756static int tc35815_init_one(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000757 const struct pci_device_id *ent)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900758{
759 void __iomem *ioaddr = NULL;
760 struct net_device *dev;
761 struct tc35815_local *lp;
762 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900764 static int printed_version;
765 if (!printed_version++) {
766 printk(version);
767 dev_printk(KERN_DEBUG, &pdev->dev,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900768 "speed:%d duplex:%d\n",
769 options.speed, options.duplex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900772 if (!pdev->irq) {
773 dev_warn(&pdev->dev, "no IRQ assigned.\n");
774 return -ENODEV;
775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900777 /* dev zeroed in alloc_etherdev */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900778 dev = alloc_etherdev(sizeof(*lp));
Joe Perches41de8d42012-01-29 13:47:52 +0000779 if (dev == NULL)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900780 return -ENOMEM;
Joe Perches41de8d42012-01-29 13:47:52 +0000781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 SET_NETDEV_DEV(dev, &pdev->dev);
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900783 lp = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700784 lp->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900786 /* enable device (incl. PCI PM wakeup), and bus-mastering */
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900787 rc = pcim_enable_device(pdev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900788 if (rc)
789 goto err_out;
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900790 rc = pcim_iomap_regions(pdev, 1 << 1, MODNAME);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900791 if (rc)
792 goto err_out;
Atsushi Nemoto22adf7e2008-04-11 00:24:45 +0900793 pci_set_master(pdev);
794 ioaddr = pcim_iomap_table(pdev)[1];
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900795
796 /* Initialize the device structure. */
Alexander Beregalov5a1c28b2009-04-11 07:38:54 +0000797 dev->netdev_ops = &tc35815_netdev_ops;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900798 dev->ethtool_ops = &tc35815_ethtool_ops;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900799 dev->watchdog_timeo = TC35815_TX_TIMEOUT;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700800 netif_napi_add(dev, &lp->napi, tc35815_poll, NAPI_WEIGHT);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900801
802 dev->irq = pdev->irq;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900803 dev->base_addr = (unsigned long)ioaddr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900804
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900805 INIT_WORK(&lp->restart_work, tc35815_restart_work);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900806 spin_lock_init(&lp->lock);
Atsushi Nemotodee73992010-02-24 06:00:34 +0000807 spin_lock_init(&lp->rx_lock);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900808 lp->pci_dev = pdev;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900809 lp->chiptype = ent->driver_data;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900810
811 lp->msg_enable = NETIF_MSG_TX_ERR | NETIF_MSG_HW | NETIF_MSG_DRV | NETIF_MSG_LINK;
812 pci_set_drvdata(pdev, dev);
813
814 /* Soft reset the chip. */
815 tc35815_chip_reset(dev);
816
817 /* Retrieve the ethernet address. */
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900818 if (tc35815_init_dev_addr(dev)) {
819 dev_warn(&pdev->dev, "not valid ether addr\n");
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000820 eth_hw_addr_random(dev);
Atsushi Nemotobd43da82007-06-29 22:34:53 +0900821 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900822
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900823 rc = register_netdev(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900824 if (rc)
David S. Miller1e2cfee2010-07-13 14:20:58 -0700825 goto err_out;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900826
Johannes Berge1749612008-10-27 15:59:26 -0700827 printk(KERN_INFO "%s: %s at 0x%lx, %pM, IRQ %d\n",
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900828 dev->name,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900829 chip_info[ent->driver_data].name,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900830 dev->base_addr,
Johannes Berge1749612008-10-27 15:59:26 -0700831 dev->dev_addr,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900832 dev->irq);
833
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900834 rc = tc_mii_init(dev);
835 if (rc)
836 goto err_out_unregister;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 return 0;
839
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900840err_out_unregister:
841 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842err_out:
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900843 free_netdev(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900844 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847
Bill Pembertonb38d1302012-12-03 09:23:47 -0500848static void tc35815_remove_one(struct pci_dev *pdev)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900849{
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900850 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +0900851 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900852
Philippe Reynesa4fc5492016-07-14 15:20:46 +0200853 phy_disconnect(dev->phydev);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700854 mdiobus_unregister(lp->mii_bus);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700855 mdiobus_free(lp->mii_bus);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900856 unregister_netdev(dev);
857 free_netdev(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900858}
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860static int
861tc35815_init_queues(struct net_device *dev)
862{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900863 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 int i;
865 unsigned long fd_addr;
866
867 if (!lp->fd_buf) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900868 BUG_ON(sizeof(struct FDesc) +
869 sizeof(struct BDesc) * RX_BUF_NUM +
870 sizeof(struct FDesc) * RX_FD_NUM +
871 sizeof(struct TxFD) * TX_FD_NUM >
872 PAGE_SIZE * FD_PAGE_NUM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900874 lp->fd_buf = pci_alloc_consistent(lp->pci_dev,
875 PAGE_SIZE * FD_PAGE_NUM,
876 &lp->fd_buf_dma);
877 if (!lp->fd_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 return -ENOMEM;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900879 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900880 lp->rx_skbs[i].skb =
881 alloc_rxbuf_skb(dev, lp->pci_dev,
882 &lp->rx_skbs[i].skb_dma);
883 if (!lp->rx_skbs[i].skb) {
884 while (--i >= 0) {
885 free_rxbuf_skb(lp->pci_dev,
886 lp->rx_skbs[i].skb,
887 lp->rx_skbs[i].skb_dma);
888 lp->rx_skbs[i].skb = NULL;
889 }
890 pci_free_consistent(lp->pci_dev,
891 PAGE_SIZE * FD_PAGE_NUM,
892 lp->fd_buf,
893 lp->fd_buf_dma);
894 lp->fd_buf = NULL;
895 return -ENOMEM;
896 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900898 printk(KERN_DEBUG "%s: FD buf %p DataBuf",
899 dev->name, lp->fd_buf);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900900 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 } else {
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900902 for (i = 0; i < FD_PAGE_NUM; i++)
903 clear_page((void *)((unsigned long)lp->fd_buf +
904 i * PAGE_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 fd_addr = (unsigned long)lp->fd_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /* Free Descriptors (for Receive) */
909 lp->rfd_base = (struct RxFD *)fd_addr;
910 fd_addr += sizeof(struct RxFD) * RX_FD_NUM;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +0900911 for (i = 0; i < RX_FD_NUM; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 lp->rfd_base[i].fd.FDCtl = cpu_to_le32(FD_CownsFD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 lp->rfd_cur = lp->rfd_base;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900914 lp->rfd_limit = (struct RxFD *)fd_addr - (RX_FD_RESERVE + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Transmit Descriptors */
917 lp->tfd_base = (struct TxFD *)fd_addr;
918 fd_addr += sizeof(struct TxFD) * TX_FD_NUM;
919 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900920 lp->tfd_base[i].fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, &lp->tfd_base[i+1]));
921 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 lp->tfd_base[i].fd.FDCtl = cpu_to_le32(0);
923 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900924 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 -0700925 lp->tfd_start = 0;
926 lp->tfd_end = 0;
927
928 /* Buffer List (for Receive) */
929 lp->fbl_ptr = (struct FrFD *)fd_addr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900930 lp->fbl_ptr->fd.FDNext = cpu_to_le32(fd_virt_to_bus(lp, lp->fbl_ptr));
931 lp->fbl_ptr->fd.FDCtl = cpu_to_le32(RX_BUF_NUM | FD_CownsFD);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900932 /*
933 * move all allocated skbs to head of rx_skbs[] array.
934 * fbl_count mighe not be RX_BUF_NUM if alloc_rxbuf_skb() in
935 * tc35815_rx() had failed.
936 */
937 lp->fbl_count = 0;
938 for (i = 0; i < RX_BUF_NUM; i++) {
939 if (lp->rx_skbs[i].skb) {
940 if (i != lp->fbl_count) {
941 lp->rx_skbs[lp->fbl_count].skb =
942 lp->rx_skbs[i].skb;
943 lp->rx_skbs[lp->fbl_count].skb_dma =
944 lp->rx_skbs[i].skb_dma;
945 }
946 lp->fbl_count++;
947 }
948 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900949 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900950 if (i >= lp->fbl_count) {
951 lp->fbl_ptr->bd[i].BuffData = 0;
952 lp->fbl_ptr->bd[i].BDCtl = 0;
953 continue;
954 }
955 lp->fbl_ptr->bd[i].BuffData =
956 cpu_to_le32(lp->rx_skbs[i].skb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 /* BDID is index of FrFD.bd[] */
958 lp->fbl_ptr->bd[i].BDCtl =
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900959 cpu_to_le32(BD_CownsBD | (i << BD_RxBDID_SHIFT) |
960 RX_BUF_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900963 printk(KERN_DEBUG "%s: TxFD %p RxFD %p FrFD %p\n",
964 dev->name, lp->tfd_base, lp->rfd_base, lp->fbl_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return 0;
966}
967
968static void
969tc35815_clear_queues(struct net_device *dev)
970{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +0900971 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 int i;
973
974 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900975 u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem);
976 struct sk_buff *skb =
977 fdsystem != 0xffffffff ?
978 lp->tx_skbs[fdsystem].skb : NULL;
979#ifdef DEBUG
980 if (lp->tx_skbs[i].skb != skb) {
981 printk("%s: tx_skbs mismatch(%d).\n", dev->name, i);
982 panic_queues(dev);
983 }
984#else
985 BUG_ON(lp->tx_skbs[i].skb != skb);
986#endif
987 if (skb) {
988 pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE);
989 lp->tx_skbs[i].skb = NULL;
990 lp->tx_skbs[i].skb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 dev_kfree_skb_any(skb);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +0900992 }
993 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995
996 tc35815_init_queues(dev);
997}
998
999static void
1000tc35815_free_queues(struct net_device *dev)
1001{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001002 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 int i;
1004
1005 if (lp->tfd_base) {
1006 for (i = 0; i < TX_FD_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001007 u32 fdsystem = le32_to_cpu(lp->tfd_base[i].fd.FDSystem);
1008 struct sk_buff *skb =
1009 fdsystem != 0xffffffff ?
1010 lp->tx_skbs[fdsystem].skb : NULL;
1011#ifdef DEBUG
1012 if (lp->tx_skbs[i].skb != skb) {
1013 printk("%s: tx_skbs mismatch(%d).\n", dev->name, i);
1014 panic_queues(dev);
1015 }
1016#else
1017 BUG_ON(lp->tx_skbs[i].skb != skb);
1018#endif
1019 if (skb) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001020 pci_unmap_single(lp->pci_dev, lp->tx_skbs[i].skb_dma, skb->len, PCI_DMA_TODEVICE);
Dan Carpenter11faa7b2017-04-21 13:49:37 +03001021 dev_kfree_skb(skb);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001022 lp->tx_skbs[i].skb = NULL;
1023 lp->tx_skbs[i].skb_dma = 0;
1024 }
1025 lp->tfd_base[i].fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 }
1028
1029 lp->rfd_base = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 lp->rfd_limit = NULL;
1031 lp->rfd_cur = NULL;
1032 lp->fbl_ptr = NULL;
1033
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001034 for (i = 0; i < RX_BUF_NUM; i++) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001035 if (lp->rx_skbs[i].skb) {
1036 free_rxbuf_skb(lp->pci_dev, lp->rx_skbs[i].skb,
1037 lp->rx_skbs[i].skb_dma);
1038 lp->rx_skbs[i].skb = NULL;
1039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001041 if (lp->fd_buf) {
1042 pci_free_consistent(lp->pci_dev, PAGE_SIZE * FD_PAGE_NUM,
1043 lp->fd_buf, lp->fd_buf_dma);
1044 lp->fd_buf = NULL;
1045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
1048static void
1049dump_txfd(struct TxFD *fd)
1050{
1051 printk("TxFD(%p): %08x %08x %08x %08x\n", fd,
1052 le32_to_cpu(fd->fd.FDNext),
1053 le32_to_cpu(fd->fd.FDSystem),
1054 le32_to_cpu(fd->fd.FDStat),
1055 le32_to_cpu(fd->fd.FDCtl));
1056 printk("BD: ");
1057 printk(" %08x %08x",
1058 le32_to_cpu(fd->bd.BuffData),
1059 le32_to_cpu(fd->bd.BDCtl));
1060 printk("\n");
1061}
1062
1063static int
1064dump_rxfd(struct RxFD *fd)
1065{
1066 int i, bd_count = (le32_to_cpu(fd->fd.FDCtl) & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT;
1067 if (bd_count > 8)
1068 bd_count = 8;
1069 printk("RxFD(%p): %08x %08x %08x %08x\n", fd,
1070 le32_to_cpu(fd->fd.FDNext),
1071 le32_to_cpu(fd->fd.FDSystem),
1072 le32_to_cpu(fd->fd.FDStat),
1073 le32_to_cpu(fd->fd.FDCtl));
1074 if (le32_to_cpu(fd->fd.FDCtl) & FD_CownsFD)
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001075 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 printk("BD: ");
1077 for (i = 0; i < bd_count; i++)
1078 printk(" %08x %08x",
1079 le32_to_cpu(fd->bd[i].BuffData),
1080 le32_to_cpu(fd->bd[i].BDCtl));
1081 printk("\n");
1082 return bd_count;
1083}
1084
Atsushi Nemotoa02b7b72009-11-02 04:34:47 +00001085#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086static void
1087dump_frfd(struct FrFD *fd)
1088{
1089 int i;
1090 printk("FrFD(%p): %08x %08x %08x %08x\n", fd,
1091 le32_to_cpu(fd->fd.FDNext),
1092 le32_to_cpu(fd->fd.FDSystem),
1093 le32_to_cpu(fd->fd.FDStat),
1094 le32_to_cpu(fd->fd.FDCtl));
1095 printk("BD: ");
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001096 for (i = 0; i < RX_BUF_NUM; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 printk(" %08x %08x",
1098 le32_to_cpu(fd->bd[i].BuffData),
1099 le32_to_cpu(fd->bd[i].BDCtl));
1100 printk("\n");
1101}
1102
1103static void
1104panic_queues(struct net_device *dev)
1105{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001106 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 int i;
1108
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001109 printk("TxFD base %p, start %u, end %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 lp->tfd_base, lp->tfd_start, lp->tfd_end);
1111 printk("RxFD base %p limit %p cur %p\n",
1112 lp->rfd_base, lp->rfd_limit, lp->rfd_cur);
1113 printk("FrFD %p\n", lp->fbl_ptr);
1114 for (i = 0; i < TX_FD_NUM; i++)
1115 dump_txfd(&lp->tfd_base[i]);
1116 for (i = 0; i < RX_FD_NUM; i++) {
1117 int bd_count = dump_rxfd(&lp->rfd_base[i]);
1118 i += (bd_count + 1) / 2; /* skip BDs */
1119 }
1120 dump_frfd(lp->fbl_ptr);
1121 panic("%s: Illegal queue state.", dev->name);
1122}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123#endif
1124
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001125static void print_eth(const u8 *add)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001127 printk(KERN_DEBUG "print_eth(%p)\n", add);
Johannes Berge1749612008-10-27 15:59:26 -07001128 printk(KERN_DEBUG " %pM => %pM : %02x%02x\n",
1129 add + 6, add, add[12], add[13]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001132static int tc35815_tx_full(struct net_device *dev)
1133{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001134 struct tc35815_local *lp = netdev_priv(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +00001135 return (lp->tfd_start + 1) % TX_FD_NUM == lp->tfd_end;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001136}
1137
1138static void tc35815_restart(struct net_device *dev)
1139{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001140 struct tc35815_local *lp = netdev_priv(dev);
Florian Fainelli01b01142013-12-06 13:01:37 -08001141 int ret;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001142
Philippe Reynesa4fc5492016-07-14 15:20:46 +02001143 if (dev->phydev) {
1144 ret = phy_init_hw(dev->phydev);
Florian Fainelli01b01142013-12-06 13:01:37 -08001145 if (ret)
1146 printk(KERN_ERR "%s: PHY init failed.\n", dev->name);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001147 }
1148
Atsushi Nemotodee73992010-02-24 06:00:34 +00001149 spin_lock_bh(&lp->rx_lock);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001150 spin_lock_irq(&lp->lock);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001151 tc35815_chip_reset(dev);
1152 tc35815_clear_queues(dev);
1153 tc35815_chip_init(dev);
1154 /* Reconfigure CAM again since tc35815_chip_init() initialize it. */
1155 tc35815_set_multicast_list(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001156 spin_unlock_irq(&lp->lock);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001157 spin_unlock_bh(&lp->rx_lock);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001158
1159 netif_wake_queue(dev);
1160}
1161
1162static void tc35815_restart_work(struct work_struct *work)
1163{
1164 struct tc35815_local *lp =
1165 container_of(work, struct tc35815_local, restart_work);
1166 struct net_device *dev = lp->dev;
1167
1168 tc35815_restart(dev);
1169}
1170
1171static void tc35815_schedule_restart(struct net_device *dev)
1172{
1173 struct tc35815_local *lp = netdev_priv(dev);
1174 struct tc35815_regs __iomem *tr =
1175 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotodee73992010-02-24 06:00:34 +00001176 unsigned long flags;
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001177
1178 /* disable interrupts */
Atsushi Nemotodee73992010-02-24 06:00:34 +00001179 spin_lock_irqsave(&lp->lock, flags);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001180 tc_writel(0, &tr->Int_En);
1181 tc_writel(tc_readl(&tr->DMA_Ctl) | DMA_IntMask, &tr->DMA_Ctl);
1182 schedule_work(&lp->restart_work);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001183 spin_unlock_irqrestore(&lp->lock, flags);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001184}
1185
1186static void tc35815_tx_timeout(struct net_device *dev)
1187{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001188 struct tc35815_regs __iomem *tr =
1189 (struct tc35815_regs __iomem *)dev->base_addr;
1190
1191 printk(KERN_WARNING "%s: transmit timed out, status %#x\n",
1192 dev->name, tc_readl(&tr->Tx_Stat));
1193
1194 /* Try to restart the adaptor. */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001195 tc35815_schedule_restart(dev);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001196 dev->stats.tx_errors++;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199/*
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001200 * Open/initialize the controller. This is called (in the current kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 * sometime after booting when the 'ifconfig' program is run.
1202 *
1203 * This routine should set everything up anew at each open, even
1204 * registers that "should" only need to be set once at boot, so that
1205 * there is non-reboot way to recover if something goes wrong.
1206 */
1207static int
1208tc35815_open(struct net_device *dev)
1209{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001210 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 /*
1213 * This is used if the interrupt line can turned off (shared).
1214 * See 3c503.c for an example of selecting the IRQ at config-time.
1215 */
Joe Perchesa0607fd2009-11-18 23:29:17 -08001216 if (request_irq(dev->irq, tc35815_interrupt, IRQF_SHARED,
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001217 dev->name, dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 tc35815_chip_reset(dev);
1221
1222 if (tc35815_init_queues(dev) != 0) {
1223 free_irq(dev->irq, dev);
1224 return -EAGAIN;
1225 }
1226
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001227 napi_enable(&lp->napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 /* Reset the hardware here. Don't forget to set the station address. */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001230 spin_lock_irq(&lp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 tc35815_chip_init(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001232 spin_unlock_irq(&lp->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Atsushi Nemoto59524a32008-06-25 11:41:01 +09001234 netif_carrier_off(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001235 /* schedule a link state check */
Philippe Reynesa4fc5492016-07-14 15:20:46 +02001236 phy_start(dev->phydev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001237
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001238 /* We are now ready to accept transmit requeusts from
1239 * the queueing layer of the networking.
1240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 netif_start_queue(dev);
1242
1243 return 0;
1244}
1245
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001246/* This will only be invoked if your driver is _not_ in XOFF state.
1247 * What this means is that you need not check it, and that this
1248 * invariant will hold if you make sure that the netif_*_queue()
1249 * calls are done at the proper times.
1250 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
1252{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001253 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001254 struct TxFD *txfd;
1255 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001257 /* If some error occurs while trying to transmit this
1258 * packet, you should return '1' from this function.
1259 * In such a case you _may not_ do anything to the
1260 * SKB, it is still owned by the network queueing
1261 * layer when an error is returned. This means you
1262 * may not modify any SKB fields, you may not free
1263 * the SKB, etc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001266 /* This is the most common case for modern hardware.
1267 * The spinlock protects this code from the TX complete
1268 * hardware interrupt handler. Queue flow control is
1269 * thus managed under this lock as well.
1270 */
1271 spin_lock_irqsave(&lp->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001273 /* failsafe... (handle txdone now if half of FDs are used) */
1274 if ((lp->tfd_start + TX_FD_NUM - lp->tfd_end) % TX_FD_NUM >
1275 TX_FD_NUM / 2)
1276 tc35815_txdone(dev);
1277
1278 if (netif_msg_pktdata(lp))
1279 print_eth(skb->data);
1280#ifdef DEBUG
1281 if (lp->tx_skbs[lp->tfd_start].skb) {
1282 printk("%s: tx_skbs conflict.\n", dev->name);
1283 panic_queues(dev);
1284 }
1285#else
1286 BUG_ON(lp->tx_skbs[lp->tfd_start].skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287#endif
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001288 lp->tx_skbs[lp->tfd_start].skb = skb;
1289 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 -07001290
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001291 /*add to ring */
1292 txfd = &lp->tfd_base[lp->tfd_start];
1293 txfd->bd.BuffData = cpu_to_le32(lp->tx_skbs[lp->tfd_start].skb_dma);
1294 txfd->bd.BDCtl = cpu_to_le32(skb->len);
1295 txfd->fd.FDSystem = cpu_to_le32(lp->tfd_start);
1296 txfd->fd.FDCtl = cpu_to_le32(FD_CownsFD | (1 << FD_BDCnt_SHIFT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001298 if (lp->tfd_start == lp->tfd_end) {
1299 struct tc35815_regs __iomem *tr =
1300 (struct tc35815_regs __iomem *)dev->base_addr;
1301 /* Start DMA Transmitter. */
1302 txfd->fd.FDNext |= cpu_to_le32(FD_Next_EOL);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001303 txfd->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001304 if (netif_msg_tx_queued(lp)) {
1305 printk("%s: starting TxFD.\n", dev->name);
1306 dump_txfd(txfd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001308 tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr);
1309 } else {
1310 txfd->fd.FDNext &= cpu_to_le32(~FD_Next_EOL);
1311 if (netif_msg_tx_queued(lp)) {
1312 printk("%s: queueing TxFD.\n", dev->name);
1313 dump_txfd(txfd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001315 }
1316 lp->tfd_start = (lp->tfd_start + 1) % TX_FD_NUM;
1317
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001318 /* If we just used up the very last entry in the
1319 * TX ring on this device, tell the queueing
1320 * layer to send no more.
1321 */
1322 if (tc35815_tx_full(dev)) {
1323 if (netif_msg_tx_queued(lp))
1324 printk(KERN_WARNING "%s: TxFD Exhausted.\n", dev->name);
1325 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001328 /* When the TX completion hw interrupt arrives, this
1329 * is when the transmit statistics are updated.
1330 */
1331
1332 spin_unlock_irqrestore(&lp->lock, flags);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001333 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
1336#define FATAL_ERROR_INT \
1337 (Int_IntPCI | Int_DmParErr | Int_IntNRAbt)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001338static void tc35815_fatal_error_interrupt(struct net_device *dev, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
1340 static int count;
Colin Ian Kingb103ec72017-07-27 23:15:09 +01001341 printk(KERN_WARNING "%s: Fatal Error Interrupt (%#x):",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (status & Int_IntPCI)
1344 printk(" IntPCI");
1345 if (status & Int_DmParErr)
1346 printk(" DmParErr");
1347 if (status & Int_IntNRAbt)
1348 printk(" IntNRAbt");
1349 printk("\n");
1350 if (count++ > 100)
1351 panic("%s: Too many fatal errors.", dev->name);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001352 printk(KERN_WARNING "%s: Resetting ...\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 /* Try to restart the adaptor. */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001354 tc35815_schedule_restart(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001355}
1356
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001357static int tc35815_do_interrupt(struct net_device *dev, u32 status, int limit)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001358{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001359 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001360 int ret = -1;
1361
1362 /* Fatal errors... */
1363 if (status & FATAL_ERROR_INT) {
1364 tc35815_fatal_error_interrupt(dev, status);
1365 return 0;
1366 }
1367 /* recoverable errors */
1368 if (status & Int_IntFDAEx) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001369 if (netif_msg_rx_err(lp))
1370 dev_warn(&dev->dev,
1371 "Free Descriptor Area Exhausted (%#x).\n",
1372 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001373 dev->stats.rx_dropped++;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001374 ret = 0;
1375 }
1376 if (status & Int_IntBLEx) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001377 if (netif_msg_rx_err(lp))
1378 dev_warn(&dev->dev,
1379 "Buffer List Exhausted (%#x).\n",
1380 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001381 dev->stats.rx_dropped++;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001382 ret = 0;
1383 }
1384 if (status & Int_IntExBD) {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001385 if (netif_msg_rx_err(lp))
1386 dev_warn(&dev->dev,
Colin Ian King1b283242016-06-22 17:42:21 +01001387 "Excessive Buffer Descriptors (%#x).\n",
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001388 status);
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001389 dev->stats.rx_length_errors++;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001390 ret = 0;
1391 }
1392
1393 /* normal notification */
1394 if (status & Int_IntMacRx) {
1395 /* Got a packet(s). */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001396 ret = tc35815_rx(dev, limit);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001397 lp->lstats.rx_ints++;
1398 }
1399 if (status & Int_IntMacTx) {
1400 /* Transmit complete. */
1401 lp->lstats.tx_ints++;
Atsushi Nemotodee73992010-02-24 06:00:34 +00001402 spin_lock_irq(&lp->lock);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001403 tc35815_txdone(dev);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001404 spin_unlock_irq(&lp->lock);
Atsushi Nemoto02c5c8e2009-10-26 03:46:21 +00001405 if (ret < 0)
1406 ret = 0;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001407 }
1408 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409}
1410
1411/*
1412 * The typical workload of the driver:
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001413 * Handle the network interface interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 */
David Howells7d12e782006-10-05 14:55:46 +01001415static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
1417 struct net_device *dev = dev_id;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001418 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001419 struct tc35815_regs __iomem *tr =
1420 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001421 u32 dmactl = tc_readl(&tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001423 if (!(dmactl & DMA_IntMask)) {
1424 /* disable interrupts */
1425 tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
Ben Hutchings288379f2009-01-19 16:43:59 -08001426 if (napi_schedule_prep(&lp->napi))
1427 __napi_schedule(&lp->napi);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001428 else {
1429 printk(KERN_ERR "%s: interrupt taken in poll\n",
1430 dev->name);
1431 BUG();
1432 }
1433 (void)tc_readl(&tr->Int_Src); /* flush */
1434 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001436 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001439#ifdef CONFIG_NET_POLL_CONTROLLER
1440static void tc35815_poll_controller(struct net_device *dev)
1441{
1442 disable_irq(dev->irq);
1443 tc35815_interrupt(dev->irq, dev);
1444 enable_irq(dev->irq);
1445}
1446#endif
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448/* We have a good packet(s), get it/them out of the buffers. */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001449static int
1450tc35815_rx(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001452 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 unsigned int fdctl;
1454 int i;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001455 int received = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
1457 while (!((fdctl = le32_to_cpu(lp->rfd_cur->fd.FDCtl)) & FD_CownsFD)) {
1458 int status = le32_to_cpu(lp->rfd_cur->fd.FDStat);
1459 int pkt_len = fdctl & FD_FDLength_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 int bd_count = (fdctl & FD_BDCnt_MASK) >> FD_BDCnt_SHIFT;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001461#ifdef DEBUG
1462 struct RxFD *next_rfd;
1463#endif
1464#if (RX_CTL_CMD & Rx_StripCRC) == 0
Atsushi Nemoto82a99282008-12-11 20:58:04 -08001465 pkt_len -= ETH_FCS_LEN;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001466#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001468 if (netif_msg_rx_status(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 dump_rxfd(lp->rfd_cur);
1470 if (status & Rx_Good) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 struct sk_buff *skb;
1472 unsigned char *data;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001473 int cur_bd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001475 if (--limit < 0)
1476 break;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001477 BUG_ON(bd_count > 1);
1478 cur_bd = (le32_to_cpu(lp->rfd_cur->bd[0].BDCtl)
1479 & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT;
1480#ifdef DEBUG
1481 if (cur_bd >= RX_BUF_NUM) {
1482 printk("%s: invalid BDID.\n", dev->name);
1483 panic_queues(dev);
1484 }
1485 BUG_ON(lp->rx_skbs[cur_bd].skb_dma !=
1486 (le32_to_cpu(lp->rfd_cur->bd[0].BuffData) & ~3));
1487 if (!lp->rx_skbs[cur_bd].skb) {
1488 printk("%s: NULL skb.\n", dev->name);
1489 panic_queues(dev);
1490 }
1491#else
1492 BUG_ON(cur_bd >= RX_BUF_NUM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493#endif
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001494 skb = lp->rx_skbs[cur_bd].skb;
1495 prefetch(skb->data);
1496 lp->rx_skbs[cur_bd].skb = NULL;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001497 pci_unmap_single(lp->pci_dev,
1498 lp->rx_skbs[cur_bd].skb_dma,
1499 RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Atsushi Nemoto82a99282008-12-11 20:58:04 -08001500 if (!HAVE_DMA_RXALIGN(lp) && NET_IP_ALIGN)
1501 memmove(skb->data, skb->data - NET_IP_ALIGN,
1502 pkt_len);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001503 data = skb_put(skb, pkt_len);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001504 if (netif_msg_pktdata(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 print_eth(data);
1506 skb->protocol = eth_type_trans(skb, dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001507 netif_receive_skb(skb);
1508 received++;
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001509 dev->stats.rx_packets++;
1510 dev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 } else {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001512 dev->stats.rx_errors++;
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001513 if (netif_msg_rx_err(lp))
1514 dev_info(&dev->dev, "Rx error (status %x)\n",
1515 status & Rx_Stat_Mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /* WORKAROUND: LongErr and CRCErr means Overflow. */
1517 if ((status & Rx_LongErr) && (status & Rx_CRCErr)) {
1518 status &= ~(Rx_LongErr|Rx_CRCErr);
1519 status |= Rx_Over;
1520 }
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001521 if (status & Rx_LongErr)
1522 dev->stats.rx_length_errors++;
1523 if (status & Rx_Over)
1524 dev->stats.rx_fifo_errors++;
1525 if (status & Rx_CRCErr)
1526 dev->stats.rx_crc_errors++;
1527 if (status & Rx_Align)
1528 dev->stats.rx_frame_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530
1531 if (bd_count > 0) {
1532 /* put Free Buffer back to controller */
1533 int bdctl = le32_to_cpu(lp->rfd_cur->bd[bd_count - 1].BDCtl);
1534 unsigned char id =
1535 (bdctl & BD_RxBDID_MASK) >> BD_RxBDID_SHIFT;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001536#ifdef DEBUG
1537 if (id >= RX_BUF_NUM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 printk("%s: invalid BDID.\n", dev->name);
1539 panic_queues(dev);
1540 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001541#else
1542 BUG_ON(id >= RX_BUF_NUM);
1543#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 /* free old buffers */
Atsushi Nemotoccc57aa2008-06-26 17:14:15 +09001545 lp->fbl_count--;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001546 while (lp->fbl_count < RX_BUF_NUM)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001547 {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001548 unsigned char curid =
1549 (id + 1 + lp->fbl_count) % RX_BUF_NUM;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001550 struct BDesc *bd = &lp->fbl_ptr->bd[curid];
1551#ifdef DEBUG
1552 bdctl = le32_to_cpu(bd->BDCtl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 if (bdctl & BD_CownsBD) {
1554 printk("%s: Freeing invalid BD.\n",
1555 dev->name);
1556 panic_queues(dev);
1557 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001558#endif
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +02001559 /* pass BD to controller */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001560 if (!lp->rx_skbs[curid].skb) {
1561 lp->rx_skbs[curid].skb =
1562 alloc_rxbuf_skb(dev,
1563 lp->pci_dev,
1564 &lp->rx_skbs[curid].skb_dma);
1565 if (!lp->rx_skbs[curid].skb)
1566 break; /* try on next reception */
1567 bd->BuffData = cpu_to_le32(lp->rx_skbs[curid].skb_dma);
1568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 /* Note: BDLength was modified by chip. */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001570 bd->BDCtl = cpu_to_le32(BD_CownsBD |
1571 (curid << BD_RxBDID_SHIFT) |
1572 RX_BUF_SIZE);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001573 lp->fbl_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 }
1575 }
1576
1577 /* put RxFD back to controller */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001578#ifdef DEBUG
1579 next_rfd = fd_bus_to_virt(lp,
1580 le32_to_cpu(lp->rfd_cur->fd.FDNext));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 if (next_rfd < lp->rfd_base || next_rfd > lp->rfd_limit) {
1582 printk("%s: RxFD FDNext invalid.\n", dev->name);
1583 panic_queues(dev);
1584 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 for (i = 0; i < (bd_count + 1) / 2 + 1; i++) {
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +02001587 /* pass FD to controller */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001588#ifdef DEBUG
1589 lp->rfd_cur->fd.FDNext = cpu_to_le32(0xdeaddead);
1590#else
1591 lp->rfd_cur->fd.FDNext = cpu_to_le32(FD_Next_EOL);
1592#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 lp->rfd_cur->fd.FDCtl = cpu_to_le32(FD_CownsFD);
1594 lp->rfd_cur++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001596 if (lp->rfd_cur > lp->rfd_limit)
1597 lp->rfd_cur = lp->rfd_base;
1598#ifdef DEBUG
1599 if (lp->rfd_cur != next_rfd)
1600 printk("rfd_cur = %p, next_rfd %p\n",
1601 lp->rfd_cur, next_rfd);
1602#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 }
1604
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001605 return received;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001608static int tc35815_poll(struct napi_struct *napi, int budget)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001609{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001610 struct tc35815_local *lp = container_of(napi, struct tc35815_local, napi);
1611 struct net_device *dev = lp->dev;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001612 struct tc35815_regs __iomem *tr =
1613 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001614 int received = 0, handled;
1615 u32 status;
1616
Eric W. Biederman176f7922014-03-14 18:10:14 -07001617 if (budget <= 0)
1618 return received;
1619
Atsushi Nemotodee73992010-02-24 06:00:34 +00001620 spin_lock(&lp->rx_lock);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001621 status = tc_readl(&tr->Int_Src);
1622 do {
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001623 /* BLEx, FDAEx will be cleared later */
1624 tc_writel(status & ~(Int_BLEx | Int_FDAEx),
1625 &tr->Int_Src); /* write to clear */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001626
Atsushi Nemotoa2c465d2009-04-02 01:17:36 -07001627 handled = tc35815_do_interrupt(dev, status, budget - received);
Atsushi Nemotodb30f5e2009-08-06 04:41:46 +00001628 if (status & (Int_BLEx | Int_FDAEx))
1629 tc_writel(status & (Int_BLEx | Int_FDAEx),
1630 &tr->Int_Src);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001631 if (handled >= 0) {
1632 received += handled;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001633 if (received >= budget)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001634 break;
1635 }
1636 status = tc_readl(&tr->Int_Src);
1637 } while (status);
Atsushi Nemotodee73992010-02-24 06:00:34 +00001638 spin_unlock(&lp->rx_lock);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001639
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001640 if (received < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08001641 napi_complete_done(napi, received);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001642 /* enable interrupts */
1643 tc_writel(tc_readl(&tr->DMA_Ctl) & ~DMA_IntMask, &tr->DMA_Ctl);
1644 }
1645 return received;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001646}
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648#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 -07001649
1650static void
1651tc35815_check_tx_stat(struct net_device *dev, int status)
1652{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001653 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 const char *msg = NULL;
1655
1656 /* count collisions */
1657 if (status & Tx_ExColl)
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001658 dev->stats.collisions += 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 if (status & Tx_TxColl_MASK)
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001660 dev->stats.collisions += status & Tx_TxColl_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001662 /* TX4939 does not have NCarr */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001663 if (lp->chiptype == TC35815_TX4939)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 status &= ~Tx_NCarr;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001665 /* WORKAROUND: ignore LostCrS in full duplex operation */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001666 if (!lp->link || lp->duplex == DUPLEX_FULL)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001667 status &= ~Tx_NCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 if (!(status & TX_STA_ERR)) {
1670 /* no error. */
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001671 dev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 return;
1673 }
1674
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001675 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 if (status & Tx_ExColl) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001677 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 msg = "Excessive Collision.";
1679 }
1680 if (status & Tx_Under) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001681 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 msg = "Tx FIFO Underrun.";
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001683 if (lp->lstats.tx_underrun < TX_THRESHOLD_KEEP_LIMIT) {
1684 lp->lstats.tx_underrun++;
1685 if (lp->lstats.tx_underrun >= TX_THRESHOLD_KEEP_LIMIT) {
1686 struct tc35815_regs __iomem *tr =
1687 (struct tc35815_regs __iomem *)dev->base_addr;
1688 tc_writel(TX_THRESHOLD_MAX, &tr->TxThrsh);
1689 msg = "Tx FIFO Underrun.Change Tx threshold to max.";
1690 }
1691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
1693 if (status & Tx_Defer) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001694 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 msg = "Excessive Deferral.";
1696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 if (status & Tx_NCarr) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001698 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 msg = "Lost Carrier Sense.";
1700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (status & Tx_LateColl) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001702 dev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 msg = "Late Collision.";
1704 }
1705 if (status & Tx_TxPar) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001706 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 msg = "Transmit Parity Error.";
1708 }
1709 if (status & Tx_SQErr) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001710 dev->stats.tx_heartbeat_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 msg = "Signal Quality Error.";
1712 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001713 if (msg && netif_msg_tx_err(lp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 printk(KERN_WARNING "%s: %s (%#x)\n", dev->name, msg, status);
1715}
1716
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001717/* This handles TX complete events posted by the device
1718 * via interrupts.
1719 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720static void
1721tc35815_txdone(struct net_device *dev)
1722{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001723 struct tc35815_local *lp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 struct TxFD *txfd;
1725 unsigned int fdctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 txfd = &lp->tfd_base[lp->tfd_end];
1728 while (lp->tfd_start != lp->tfd_end &&
1729 !((fdctl = le32_to_cpu(txfd->fd.FDCtl)) & FD_CownsFD)) {
1730 int status = le32_to_cpu(txfd->fd.FDStat);
1731 struct sk_buff *skb;
1732 unsigned long fdnext = le32_to_cpu(txfd->fd.FDNext);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001733 u32 fdsystem = le32_to_cpu(txfd->fd.FDSystem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001735 if (netif_msg_tx_done(lp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 printk("%s: complete TxFD.\n", dev->name);
1737 dump_txfd(txfd);
1738 }
1739 tc35815_check_tx_stat(dev, status);
1740
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001741 skb = fdsystem != 0xffffffff ?
1742 lp->tx_skbs[fdsystem].skb : NULL;
1743#ifdef DEBUG
1744 if (lp->tx_skbs[lp->tfd_end].skb != skb) {
1745 printk("%s: tx_skbs mismatch.\n", dev->name);
1746 panic_queues(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001748#else
1749 BUG_ON(lp->tx_skbs[lp->tfd_end].skb != skb);
1750#endif
1751 if (skb) {
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001752 dev->stats.tx_bytes += skb->len;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001753 pci_unmap_single(lp->pci_dev, lp->tx_skbs[lp->tfd_end].skb_dma, skb->len, PCI_DMA_TODEVICE);
1754 lp->tx_skbs[lp->tfd_end].skb = NULL;
1755 lp->tx_skbs[lp->tfd_end].skb_dma = 0;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001756 dev_kfree_skb_any(skb);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001757 }
1758 txfd->fd.FDSystem = cpu_to_le32(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 lp->tfd_end = (lp->tfd_end + 1) % TX_FD_NUM;
1761 txfd = &lp->tfd_base[lp->tfd_end];
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001762#ifdef DEBUG
1763 if ((fdnext & ~FD_Next_EOL) != fd_virt_to_bus(lp, txfd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 printk("%s: TxFD FDNext invalid.\n", dev->name);
1765 panic_queues(dev);
1766 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001767#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 if (fdnext & FD_Next_EOL) {
1769 /* DMA Transmitter has been stopping... */
1770 if (lp->tfd_end != lp->tfd_start) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001771 struct tc35815_regs __iomem *tr =
1772 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 int head = (lp->tfd_start + TX_FD_NUM - 1) % TX_FD_NUM;
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001774 struct TxFD *txhead = &lp->tfd_base[head];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 int qlen = (lp->tfd_start + TX_FD_NUM
1776 - lp->tfd_end) % TX_FD_NUM;
1777
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001778#ifdef DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 if (!(le32_to_cpu(txfd->fd.FDCtl) & FD_CownsFD)) {
1780 printk("%s: TxFD FDCtl invalid.\n", dev->name);
1781 panic_queues(dev);
1782 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001783#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 /* log max queue length */
1785 if (lp->lstats.max_tx_qlen < qlen)
1786 lp->lstats.max_tx_qlen = qlen;
1787
1788
1789 /* start DMA Transmitter again */
1790 txhead->fd.FDNext |= cpu_to_le32(FD_Next_EOL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 txhead->fd.FDCtl |= cpu_to_le32(FD_FrmOpt_IntTx);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001792 if (netif_msg_tx_queued(lp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 printk("%s: start TxFD on queue.\n",
1794 dev->name);
1795 dump_txfd(txfd);
1796 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001797 tc_writel(fd_virt_to_bus(lp, txfd), &tr->TxFrmPtr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
1799 break;
1800 }
1801 }
1802
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001803 /* If we had stopped the queue due to a "tx full"
1804 * condition, and space has now been made available,
1805 * wake up the queue.
1806 */
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001807 if (netif_queue_stopped(dev) && !tc35815_tx_full(dev))
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001808 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809}
1810
1811/* The inverse routine to tc35815_open(). */
1812static int
1813tc35815_close(struct net_device *dev)
1814{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001815 struct tc35815_local *lp = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001818 napi_disable(&lp->napi);
Philippe Reynesa4fc5492016-07-14 15:20:46 +02001819 if (dev->phydev)
1820 phy_stop(dev->phydev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001821 cancel_work_sync(&lp->restart_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 /* Flush the Tx and disable Rx here. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 tc35815_chip_reset(dev);
1825 free_irq(dev->irq, dev);
1826
1827 tc35815_free_queues(dev);
1828
1829 return 0;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831}
1832
1833/*
1834 * Get the current statistics.
1835 * This may be called with the card open or closed.
1836 */
1837static struct net_device_stats *tc35815_get_stats(struct net_device *dev)
1838{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001839 struct tc35815_regs __iomem *tr =
1840 (struct tc35815_regs __iomem *)dev->base_addr;
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001841 if (netif_running(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 /* Update the statistics from the device registers. */
Atsushi Nemoto7bb82e82009-08-06 04:41:48 +00001843 dev->stats.rx_missed_errors += tc_readl(&tr->Miss_Cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Atsushi Nemotoc201abd92008-04-11 00:24:12 +09001845 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001848static void tc35815_set_cam_entry(struct net_device *dev, int index, unsigned char *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001850 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001851 struct tc35815_regs __iomem *tr =
1852 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 int cam_index = index * 6;
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001854 u32 cam_data;
1855 u32 saved_addr;
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 saved_addr = tc_readl(&tr->CAM_Adr);
1858
Atsushi Nemoto958eb802008-04-11 00:24:24 +09001859 if (netif_msg_hw(lp))
Johannes Berge1749612008-10-27 15:59:26 -07001860 printk(KERN_DEBUG "%s: CAM %d: %pM\n",
1861 dev->name, index, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 if (index & 1) {
1863 /* read modify write */
1864 tc_writel(cam_index - 2, &tr->CAM_Adr);
1865 cam_data = tc_readl(&tr->CAM_Data) & 0xffff0000;
1866 cam_data |= addr[0] << 8 | addr[1];
1867 tc_writel(cam_data, &tr->CAM_Data);
1868 /* write whole word */
1869 tc_writel(cam_index + 2, &tr->CAM_Adr);
1870 cam_data = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) | addr[5];
1871 tc_writel(cam_data, &tr->CAM_Data);
1872 } else {
1873 /* write whole word */
1874 tc_writel(cam_index, &tr->CAM_Adr);
1875 cam_data = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
1876 tc_writel(cam_data, &tr->CAM_Data);
1877 /* read modify write */
1878 tc_writel(cam_index + 4, &tr->CAM_Adr);
1879 cam_data = tc_readl(&tr->CAM_Data) & 0x0000ffff;
1880 cam_data |= addr[4] << 24 | (addr[5] << 16);
1881 tc_writel(cam_data, &tr->CAM_Data);
1882 }
1883
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 tc_writel(saved_addr, &tr->CAM_Adr);
1885}
1886
1887
1888/*
1889 * Set or clear the multicast filter for this adaptor.
1890 * num_addrs == -1 Promiscuous mode, receive all packets
1891 * num_addrs == 0 Normal mode, clear multicast list
1892 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1893 * and do best-effort filtering.
1894 */
1895static void
1896tc35815_set_multicast_list(struct net_device *dev)
1897{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001898 struct tc35815_regs __iomem *tr =
1899 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001901 if (dev->flags & IFF_PROMISC) {
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001902 /* With some (all?) 100MHalf HUB, controller will hang
1903 * if we enabled promiscuous mode before linkup... */
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001904 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001905
1906 if (!lp->link)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001907 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 /* Enable promiscuous mode */
1909 tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc | CAM_StationAcc, &tr->CAM_Ctl);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001910 } else if ((dev->flags & IFF_ALLMULTI) ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001911 netdev_mc_count(dev) > CAM_ENTRY_MAX - 3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 /* CAM 0, 1, 20 are reserved. */
1913 /* Disable promiscuous mode, use normal mode. */
1914 tc_writel(CAM_CompEn | CAM_BroadAcc | CAM_GroupAcc, &tr->CAM_Ctl);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001915 } else if (!netdev_mc_empty(dev)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001916 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 int i;
1918 int ena_bits = CAM_Ena_Bit(CAM_ENTRY_SOURCE);
1919
1920 tc_writel(0, &tr->CAM_Ctl);
1921 /* Walk the address list, and load the filter */
Jiri Pirko567ec872010-02-23 23:17:07 +00001922 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001923 netdev_for_each_mc_addr(ha, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 /* entry 0,1 is reserved. */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001925 tc35815_set_cam_entry(dev, i + 2, ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 ena_bits |= CAM_Ena_Bit(i + 2);
Jiri Pirko567ec872010-02-23 23:17:07 +00001927 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
1929 tc_writel(ena_bits, &tr->CAM_Ena);
1930 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
Atsushi Nemoto7f225b42008-04-11 00:25:31 +09001931 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena);
1933 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
1934 }
1935}
1936
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001937static void tc35815_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001939 struct tc35815_local *lp = netdev_priv(dev);
Jiri Pirko7826d432013-01-06 00:44:26 +00001940
1941 strlcpy(info->driver, MODNAME, sizeof(info->driver));
1942 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
1943 strlcpy(info->bus_info, pci_name(lp->pci_dev), sizeof(info->bus_info));
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001944}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001945
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001946static u32 tc35815_get_msglevel(struct net_device *dev)
1947{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001948 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001949 return lp->msg_enable;
1950}
1951
1952static void tc35815_set_msglevel(struct net_device *dev, u32 datum)
1953{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001954 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001955 lp->msg_enable = datum;
1956}
1957
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001958static int tc35815_get_sset_count(struct net_device *dev, int sset)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001959{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001960 struct tc35815_local *lp = netdev_priv(dev);
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001961
1962 switch (sset) {
1963 case ETH_SS_STATS:
1964 return sizeof(lp->lstats) / sizeof(int);
1965 default:
1966 return -EOPNOTSUPP;
1967 }
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001968}
1969
1970static void tc35815_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data)
1971{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09001972 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001973 data[0] = lp->lstats.max_tx_qlen;
1974 data[1] = lp->lstats.tx_ints;
1975 data[2] = lp->lstats.rx_ints;
1976 data[3] = lp->lstats.tx_underrun;
1977}
1978
1979static struct {
1980 const char str[ETH_GSTRING_LEN];
1981} ethtool_stats_keys[] = {
1982 { "max_tx_qlen" },
1983 { "tx_ints" },
1984 { "rx_ints" },
1985 { "tx_underrun" },
1986};
1987
1988static void tc35815_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1989{
1990 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
1991}
1992
1993static const struct ethtool_ops tc35815_ethtool_ops = {
1994 .get_drvinfo = tc35815_get_drvinfo,
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09001995 .get_link = ethtool_op_get_link,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09001996 .get_msglevel = tc35815_get_msglevel,
1997 .set_msglevel = tc35815_set_msglevel,
1998 .get_strings = tc35815_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001999 .get_sset_count = tc35815_get_sset_count,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002000 .get_ethtool_stats = tc35815_get_ethtool_stats,
Philippe Reynes3a11d9e2016-07-14 15:20:47 +02002001 .get_link_ksettings = phy_ethtool_get_link_ksettings,
2002 .set_link_ksettings = phy_ethtool_set_link_ksettings,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002003};
2004
2005static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2006{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002007 if (!netif_running(dev))
2008 return -EINVAL;
Philippe Reynesa4fc5492016-07-14 15:20:46 +02002009 if (!dev->phydev)
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002010 return -ENODEV;
Philippe Reynesa4fc5492016-07-14 15:20:46 +02002011 return phy_mii_ioctl(dev->phydev, rq, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012}
2013
2014static void tc35815_chip_reset(struct net_device *dev)
2015{
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002016 struct tc35815_regs __iomem *tr =
2017 (struct tc35815_regs __iomem *)dev->base_addr;
2018 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 /* reset the controller */
2020 tc_writel(MAC_Reset, &tr->MAC_Ctl);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002021 udelay(4); /* 3200ns */
2022 i = 0;
2023 while (tc_readl(&tr->MAC_Ctl) & MAC_Reset) {
2024 if (i++ > 100) {
2025 printk(KERN_ERR "%s: MAC reset failed.\n", dev->name);
2026 break;
2027 }
2028 mdelay(1);
2029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 tc_writel(0, &tr->MAC_Ctl);
2031
2032 /* initialize registers to default value */
2033 tc_writel(0, &tr->DMA_Ctl);
2034 tc_writel(0, &tr->TxThrsh);
2035 tc_writel(0, &tr->TxPollCtr);
2036 tc_writel(0, &tr->RxFragSize);
2037 tc_writel(0, &tr->Int_En);
2038 tc_writel(0, &tr->FDA_Bas);
2039 tc_writel(0, &tr->FDA_Lim);
2040 tc_writel(0xffffffff, &tr->Int_Src); /* Write 1 to clear */
2041 tc_writel(0, &tr->CAM_Ctl);
2042 tc_writel(0, &tr->Tx_Ctl);
2043 tc_writel(0, &tr->Rx_Ctl);
2044 tc_writel(0, &tr->CAM_Ena);
2045 (void)tc_readl(&tr->Miss_Cnt); /* Read to clear */
2046
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002047 /* initialize internal SRAM */
2048 tc_writel(DMA_TestMode, &tr->DMA_Ctl);
2049 for (i = 0; i < 0x1000; i += 4) {
2050 tc_writel(i, &tr->CAM_Adr);
2051 tc_writel(0, &tr->CAM_Data);
2052 }
2053 tc_writel(0, &tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
2056static void tc35815_chip_init(struct net_device *dev)
2057{
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002058 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002059 struct tc35815_regs __iomem *tr =
2060 (struct tc35815_regs __iomem *)dev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 unsigned long txctl = TX_CTL_CMD;
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 /* load station address to CAM */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002064 tc35815_set_cam_entry(dev, CAM_ENTRY_SOURCE, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 /* Enable CAM (broadcast and unicast) */
2067 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE), &tr->CAM_Ena);
2068 tc_writel(CAM_CompEn | CAM_BroadAcc, &tr->CAM_Ctl);
2069
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002070 /* Use DMA_RxAlign_2 to make IP header 4-byte aligned. */
2071 if (HAVE_DMA_RXALIGN(lp))
2072 tc_writel(DMA_BURST_SIZE | DMA_RxAlign_2, &tr->DMA_Ctl);
2073 else
2074 tc_writel(DMA_BURST_SIZE, &tr->DMA_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 tc_writel(0, &tr->TxPollCtr); /* Batch mode */
2076 tc_writel(TX_THRESHOLD, &tr->TxThrsh);
2077 tc_writel(INT_EN_CMD, &tr->Int_En);
2078
2079 /* set queues */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002080 tc_writel(fd_virt_to_bus(lp, lp->rfd_base), &tr->FDA_Bas);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 tc_writel((unsigned long)lp->rfd_limit - (unsigned long)lp->rfd_base,
2082 &tr->FDA_Lim);
2083 /*
2084 * Activation method:
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002085 * First, enable the MAC Transmitter and the DMA Receive circuits.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 * Then enable the DMA Transmitter and the MAC Receive circuits.
2087 */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002088 tc_writel(fd_virt_to_bus(lp, lp->fbl_ptr), &tr->BLFrmPtr); /* start DMA receiver */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 tc_writel(RX_CTL_CMD, &tr->Rx_Ctl); /* start MAC receiver */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 /* start MAC transmitter */
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002092 /* TX4939 does not have EnLCarr */
Atsushi Nemotoc6686fe2008-04-12 00:47:46 +09002093 if (lp->chiptype == TC35815_TX4939)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002094 txctl &= ~Tx_EnLCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* WORKAROUND: ignore LostCrS in full duplex operation */
Philippe Reynesa4fc5492016-07-14 15:20:46 +02002096 if (!dev->phydev || !lp->link || lp->duplex == DUPLEX_FULL)
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002097 txctl &= ~Tx_EnLCarr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 tc_writel(txctl, &tr->Tx_Ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002101#ifdef CONFIG_PM
2102static int tc35815_suspend(struct pci_dev *pdev, pm_message_t state)
2103{
2104 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoee79b7f2008-04-11 00:24:36 +09002105 struct tc35815_local *lp = netdev_priv(dev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002106 unsigned long flags;
2107
2108 pci_save_state(pdev);
2109 if (!netif_running(dev))
2110 return 0;
2111 netif_device_detach(dev);
Philippe Reynesa4fc5492016-07-14 15:20:46 +02002112 if (dev->phydev)
2113 phy_stop(dev->phydev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002114 spin_lock_irqsave(&lp->lock, flags);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002115 tc35815_chip_reset(dev);
2116 spin_unlock_irqrestore(&lp->lock, flags);
2117 pci_set_power_state(pdev, PCI_D3hot);
2118 return 0;
2119}
2120
2121static int tc35815_resume(struct pci_dev *pdev)
2122{
2123 struct net_device *dev = pci_get_drvdata(pdev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002124
2125 pci_restore_state(pdev);
2126 if (!netif_running(dev))
2127 return 0;
2128 pci_set_power_state(pdev, PCI_D0);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002129 tc35815_restart(dev);
Atsushi Nemoto59524a32008-06-25 11:41:01 +09002130 netif_carrier_off(dev);
Philippe Reynesa4fc5492016-07-14 15:20:46 +02002131 if (dev->phydev)
2132 phy_start(dev->phydev);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002133 netif_device_attach(dev);
2134 return 0;
2135}
2136#endif /* CONFIG_PM */
2137
2138static struct pci_driver tc35815_pci_driver = {
2139 .name = MODNAME,
2140 .id_table = tc35815_pci_tbl,
2141 .probe = tc35815_init_one,
Bill Pembertonb38d1302012-12-03 09:23:47 -05002142 .remove = tc35815_remove_one,
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002143#ifdef CONFIG_PM
2144 .suspend = tc35815_suspend,
2145 .resume = tc35815_resume,
2146#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147};
2148
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002149module_param_named(speed, options.speed, int, 0);
2150MODULE_PARM_DESC(speed, "0:auto, 10:10Mbps, 100:100Mbps");
2151module_param_named(duplex, options.duplex, int, 0);
2152MODULE_PARM_DESC(duplex, "0:auto, 1:half, 2:full");
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002153
Peter Hüweb6f57212013-05-21 12:42:12 +00002154module_pci_driver(tc35815_pci_driver);
Atsushi Nemotoeea221ce42007-03-03 23:54:59 +09002155MODULE_DESCRIPTION("TOSHIBA TC35815 PCI 10M/100M Ethernet driver");
2156MODULE_LICENSE("GPL");