2 * tc35815.c: A TOSHIBA TC35815CF PCI 10/100Mbps ethernet driver for linux.
4 * Based on skelton.c by Donald Becker.
6 * This driver is a replacement of older and less maintained version.
7 * This is a header of the older version:
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";
17 * This file is subject to the terms and conditions of the GNU General Public
18 * License. See the file "COPYING" in the main directory of this archive
21 * (C) Copyright TOSHIBA CORPORATION 2004-2005
22 * All Rights Reserved.
26 #define DRV_VERSION "1.35-NAPI"
28 #define DRV_VERSION "1.35"
30 static const char *version
= "tc35815.c:v" DRV_VERSION
"\n";
31 #define MODNAME "tc35815"
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/fcntl.h>
37 #include <linux/interrupt.h>
38 #include <linux/ioport.h>
40 #include <linux/slab.h>
41 #include <linux/string.h>
42 #include <linux/spinlock.h>
43 #include <linux/errno.h>
44 #include <linux/init.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/delay.h>
49 #include <linux/pci.h>
50 #include <linux/mii.h>
51 #include <linux/ethtool.h>
53 #include <asm/byteorder.h>
55 /* First, a few definitions that the brave might change. */
57 #define GATHER_TXINT /* On-Demand Tx Interrupt */
58 #define WORKAROUND_LOSTCAR
59 #define WORKAROUND_100HALF_PROMISC
60 /* #define TC35815_USE_PACKEDBUFFER */
68 /* indexed by board_t, above */
71 } board_info
[] __devinitdata
= {
72 { "TOSHIBA TC35815CF 10/100BaseTX" },
73 { "TOSHIBA TC35815 with Wake on LAN" },
74 { "TOSHIBA TC35815/TX4939" },
77 static const struct pci_device_id tc35815_pci_tbl
[] = {
78 {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_TC35815CF
), .driver_data
= TC35815CF
},
79 {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_TC35815_NWU
), .driver_data
= TC35815_NWU
},
80 {PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_TC35815_TX4939
), .driver_data
= TC35815_TX4939
},
83 MODULE_DEVICE_TABLE (pci
, tc35815_pci_tbl
);
85 /* see MODULE_PARM_DESC */
86 static struct tc35815_options
{
96 volatile __u32 DMA_Ctl
; /* 0x00 */
97 volatile __u32 TxFrmPtr
;
98 volatile __u32 TxThrsh
;
99 volatile __u32 TxPollCtr
;
100 volatile __u32 BLFrmPtr
;
101 volatile __u32 RxFragSize
;
102 volatile __u32 Int_En
;
103 volatile __u32 FDA_Bas
;
104 volatile __u32 FDA_Lim
; /* 0x20 */
105 volatile __u32 Int_Src
;
106 volatile __u32 unused0
[2];
107 volatile __u32 PauseCnt
;
108 volatile __u32 RemPauCnt
;
109 volatile __u32 TxCtlFrmStat
;
110 volatile __u32 unused1
;
111 volatile __u32 MAC_Ctl
; /* 0x40 */
112 volatile __u32 CAM_Ctl
;
113 volatile __u32 Tx_Ctl
;
114 volatile __u32 Tx_Stat
;
115 volatile __u32 Rx_Ctl
;
116 volatile __u32 Rx_Stat
;
117 volatile __u32 MD_Data
;
118 volatile __u32 MD_CA
;
119 volatile __u32 CAM_Adr
; /* 0x60 */
120 volatile __u32 CAM_Data
;
121 volatile __u32 CAM_Ena
;
122 volatile __u32 PROM_Ctl
;
123 volatile __u32 PROM_Data
;
124 volatile __u32 Algn_Cnt
;
125 volatile __u32 CRC_Cnt
;
126 volatile __u32 Miss_Cnt
;
132 /* DMA_Ctl bit asign ------------------------------------------------------- */
133 #define DMA_RxAlign 0x00c00000 /* 1:Reception Alignment */
134 #define DMA_RxAlign_1 0x00400000
135 #define DMA_RxAlign_2 0x00800000
136 #define DMA_RxAlign_3 0x00c00000
137 #define DMA_M66EnStat 0x00080000 /* 1:66MHz Enable State */
138 #define DMA_IntMask 0x00040000 /* 1:Interupt mask */
139 #define DMA_SWIntReq 0x00020000 /* 1:Software Interrupt request */
140 #define DMA_TxWakeUp 0x00010000 /* 1:Transmit Wake Up */
141 #define DMA_RxBigE 0x00008000 /* 1:Receive Big Endian */
142 #define DMA_TxBigE 0x00004000 /* 1:Transmit Big Endian */
143 #define DMA_TestMode 0x00002000 /* 1:Test Mode */
144 #define DMA_PowrMgmnt 0x00001000 /* 1:Power Management */
145 #define DMA_DmBurst_Mask 0x000001fc /* DMA Burst size */
147 /* RxFragSize bit asign ---------------------------------------------------- */
148 #define RxFrag_EnPack 0x00008000 /* 1:Enable Packing */
149 #define RxFrag_MinFragMask 0x00000ffc /* Minimum Fragment */
151 /* MAC_Ctl bit asign ------------------------------------------------------- */
152 #define MAC_Link10 0x00008000 /* 1:Link Status 10Mbits */
153 #define MAC_EnMissRoll 0x00002000 /* 1:Enable Missed Roll */
154 #define MAC_MissRoll 0x00000400 /* 1:Missed Roll */
155 #define MAC_Loop10 0x00000080 /* 1:Loop 10 Mbps */
156 #define MAC_Conn_Auto 0x00000000 /*00:Connection mode (Automatic) */
157 #define MAC_Conn_10M 0x00000020 /*01: (10Mbps endec)*/
158 #define MAC_Conn_Mll 0x00000040 /*10: (Mll clock) */
159 #define MAC_MacLoop 0x00000010 /* 1:MAC Loopback */
160 #define MAC_FullDup 0x00000008 /* 1:Full Duplex 0:Half Duplex */
161 #define MAC_Reset 0x00000004 /* 1:Software Reset */
162 #define MAC_HaltImm 0x00000002 /* 1:Halt Immediate */
163 #define MAC_HaltReq 0x00000001 /* 1:Halt request */
165 /* PROM_Ctl bit asign ------------------------------------------------------ */
166 #define PROM_Busy 0x00008000 /* 1:Busy (Start Operation) */
167 #define PROM_Read 0x00004000 /*10:Read operation */
168 #define PROM_Write 0x00002000 /*01:Write operation */
169 #define PROM_Erase 0x00006000 /*11:Erase operation */
170 /*00:Enable or Disable Writting, */
171 /* as specified in PROM_Addr. */
172 #define PROM_Addr_Ena 0x00000030 /*11xxxx:PROM Write enable */
175 /* CAM_Ctl bit asign ------------------------------------------------------- */
176 #define CAM_CompEn 0x00000010 /* 1:CAM Compare Enable */
177 #define CAM_NegCAM 0x00000008 /* 1:Reject packets CAM recognizes,*/
179 #define CAM_BroadAcc 0x00000004 /* 1:Broadcast assept */
180 #define CAM_GroupAcc 0x00000002 /* 1:Multicast assept */
181 #define CAM_StationAcc 0x00000001 /* 1:unicast accept */
183 /* CAM_Ena bit asign ------------------------------------------------------- */
184 #define CAM_ENTRY_MAX 21 /* CAM Data entry max count */
185 #define CAM_Ena_Mask ((1<<CAM_ENTRY_MAX)-1) /* CAM Enable bits (Max 21bits) */
186 #define CAM_Ena_Bit(index) (1<<(index))
187 #define CAM_ENTRY_DESTINATION 0
188 #define CAM_ENTRY_SOURCE 1
189 #define CAM_ENTRY_MACCTL 20
191 /* Tx_Ctl bit asign -------------------------------------------------------- */
192 #define Tx_En 0x00000001 /* 1:Transmit enable */
193 #define Tx_TxHalt 0x00000002 /* 1:Transmit Halt Request */
194 #define Tx_NoPad 0x00000004 /* 1:Suppress Padding */
195 #define Tx_NoCRC 0x00000008 /* 1:Suppress Padding */
196 #define Tx_FBack 0x00000010 /* 1:Fast Back-off */
197 #define Tx_EnUnder 0x00000100 /* 1:Enable Underrun */
198 #define Tx_EnExDefer 0x00000200 /* 1:Enable Excessive Deferral */
199 #define Tx_EnLCarr 0x00000400 /* 1:Enable Lost Carrier */
200 #define Tx_EnExColl 0x00000800 /* 1:Enable Excessive Collision */
201 #define Tx_EnLateColl 0x00001000 /* 1:Enable Late Collision */
202 #define Tx_EnTxPar 0x00002000 /* 1:Enable Transmit Parity */
203 #define Tx_EnComp 0x00004000 /* 1:Enable Completion */
205 /* Tx_Stat bit asign ------------------------------------------------------- */
206 #define Tx_TxColl_MASK 0x0000000F /* Tx Collision Count */
207 #define Tx_ExColl 0x00000010 /* Excessive Collision */
208 #define Tx_TXDefer 0x00000020 /* Transmit Defered */
209 #define Tx_Paused 0x00000040 /* Transmit Paused */
210 #define Tx_IntTx 0x00000080 /* Interrupt on Tx */
211 #define Tx_Under 0x00000100 /* Underrun */
212 #define Tx_Defer 0x00000200 /* Deferral */
213 #define Tx_NCarr 0x00000400 /* No Carrier */
214 #define Tx_10Stat 0x00000800 /* 10Mbps Status */
215 #define Tx_LateColl 0x00001000 /* Late Collision */
216 #define Tx_TxPar 0x00002000 /* Tx Parity Error */
217 #define Tx_Comp 0x00004000 /* Completion */
218 #define Tx_Halted 0x00008000 /* Tx Halted */
219 #define Tx_SQErr 0x00010000 /* Signal Quality Error(SQE) */
221 /* Rx_Ctl bit asign -------------------------------------------------------- */
222 #define Rx_EnGood 0x00004000 /* 1:Enable Good */
223 #define Rx_EnRxPar 0x00002000 /* 1:Enable Receive Parity */
224 #define Rx_EnLongErr 0x00000800 /* 1:Enable Long Error */
225 #define Rx_EnOver 0x00000400 /* 1:Enable OverFlow */
226 #define Rx_EnCRCErr 0x00000200 /* 1:Enable CRC Error */
227 #define Rx_EnAlign 0x00000100 /* 1:Enable Alignment */
228 #define Rx_IgnoreCRC 0x00000040 /* 1:Ignore CRC Value */
229 #define Rx_StripCRC 0x00000010 /* 1:Strip CRC Value */
230 #define Rx_ShortEn 0x00000008 /* 1:Short Enable */
231 #define Rx_LongEn 0x00000004 /* 1:Long Enable */
232 #define Rx_RxHalt 0x00000002 /* 1:Receive Halt Request */
233 #define Rx_RxEn 0x00000001 /* 1:Receive Intrrupt Enable */
235 /* Rx_Stat bit asign ------------------------------------------------------- */
236 #define Rx_Halted 0x00008000 /* Rx Halted */
237 #define Rx_Good 0x00004000 /* Rx Good */
238 #define Rx_RxPar 0x00002000 /* Rx Parity Error */
239 /* 0x00001000 not use */
240 #define Rx_LongErr 0x00000800 /* Rx Long Error */
241 #define Rx_Over 0x00000400 /* Rx Overflow */
242 #define Rx_CRCErr 0x00000200 /* Rx CRC Error */
243 #define Rx_Align 0x00000100 /* Rx Alignment Error */
244 #define Rx_10Stat 0x00000080 /* Rx 10Mbps Status */
245 #define Rx_IntRx 0x00000040 /* Rx Interrupt */
246 #define Rx_CtlRecd 0x00000020 /* Rx Control Receive */
248 #define Rx_Stat_Mask 0x0000EFC0 /* Rx All Status Mask */
250 /* Int_En bit asign -------------------------------------------------------- */
251 #define Int_NRAbtEn 0x00000800 /* 1:Non-recoverable Abort Enable */
252 #define Int_TxCtlCmpEn 0x00000400 /* 1:Transmit Control Complete Enable */
253 #define Int_DmParErrEn 0x00000200 /* 1:DMA Parity Error Enable */
254 #define Int_DParDEn 0x00000100 /* 1:Data Parity Error Enable */
255 #define Int_EarNotEn 0x00000080 /* 1:Early Notify Enable */
256 #define Int_DParErrEn 0x00000040 /* 1:Detected Parity Error Enable */
257 #define Int_SSysErrEn 0x00000020 /* 1:Signalled System Error Enable */
258 #define Int_RMasAbtEn 0x00000010 /* 1:Received Master Abort Enable */
259 #define Int_RTargAbtEn 0x00000008 /* 1:Received Target Abort Enable */
260 #define Int_STargAbtEn 0x00000004 /* 1:Signalled Target Abort Enable */
261 #define Int_BLExEn 0x00000002 /* 1:Buffer List Exhausted Enable */
262 #define Int_FDAExEn 0x00000001 /* 1:Free Descriptor Area */
263 /* Exhausted Enable */
265 /* Int_Src bit asign ------------------------------------------------------- */
266 #define Int_NRabt 0x00004000 /* 1:Non Recoverable error */
267 #define Int_DmParErrStat 0x00002000 /* 1:DMA Parity Error & Clear */
268 #define Int_BLEx 0x00001000 /* 1:Buffer List Empty & Clear */
269 #define Int_FDAEx 0x00000800 /* 1:FDA Empty & Clear */
270 #define Int_IntNRAbt 0x00000400 /* 1:Non Recoverable Abort */
271 #define Int_IntCmp 0x00000200 /* 1:MAC control packet complete */
272 #define Int_IntExBD 0x00000100 /* 1:Interrupt Extra BD & Clear */
273 #define Int_DmParErr 0x00000080 /* 1:DMA Parity Error & Clear */
274 #define Int_IntEarNot 0x00000040 /* 1:Receive Data write & Clear */
275 #define Int_SWInt 0x00000020 /* 1:Software request & Clear */
276 #define Int_IntBLEx 0x00000010 /* 1:Buffer List Empty & Clear */
277 #define Int_IntFDAEx 0x00000008 /* 1:FDA Empty & Clear */
278 #define Int_IntPCI 0x00000004 /* 1:PCI controller & Clear */
279 #define Int_IntMacRx 0x00000002 /* 1:Rx controller & Clear */
280 #define Int_IntMacTx 0x00000001 /* 1:Tx controller & Clear */
282 /* MD_CA bit asign --------------------------------------------------------- */
283 #define MD_CA_PreSup 0x00001000 /* 1:Preamble Supress */
284 #define MD_CA_Busy 0x00000800 /* 1:Busy (Start Operation) */
285 #define MD_CA_Wr 0x00000400 /* 1:Write 0:Read */
292 /* Frame descripter */
294 volatile __u32 FDNext
;
295 volatile __u32 FDSystem
;
296 volatile __u32 FDStat
;
297 volatile __u32 FDCtl
;
300 /* Buffer descripter */
302 volatile __u32 BuffData
;
303 volatile __u32 BDCtl
;
308 /* Frame Descripter bit asign ---------------------------------------------- */
309 #define FD_FDLength_MASK 0x0000FFFF /* Length MASK */
310 #define FD_BDCnt_MASK 0x001F0000 /* BD count MASK in FD */
311 #define FD_FrmOpt_MASK 0x7C000000 /* Frame option MASK */
312 #define FD_FrmOpt_BigEndian 0x40000000 /* Tx/Rx */
313 #define FD_FrmOpt_IntTx 0x20000000 /* Tx only */
314 #define FD_FrmOpt_NoCRC 0x10000000 /* Tx only */
315 #define FD_FrmOpt_NoPadding 0x08000000 /* Tx only */
316 #define FD_FrmOpt_Packing 0x04000000 /* Rx only */
317 #define FD_CownsFD 0x80000000 /* FD Controller owner bit */
318 #define FD_Next_EOL 0x00000001 /* FD EOL indicator */
319 #define FD_BDCnt_SHIFT 16
321 /* Buffer Descripter bit asign --------------------------------------------- */
322 #define BD_BuffLength_MASK 0x0000FFFF /* Recieve Data Size */
323 #define BD_RxBDID_MASK 0x00FF0000 /* BD ID Number MASK */
324 #define BD_RxBDSeqN_MASK 0x7F000000 /* Rx BD Sequence Number */
325 #define BD_CownsBD 0x80000000 /* BD Controller owner bit */
326 #define BD_RxBDID_SHIFT 16
327 #define BD_RxBDSeqN_SHIFT 24
330 /* Some useful constants. */
331 #undef NO_CHECK_CARRIER /* Does not check No-Carrier with TP */
333 #ifdef NO_CHECK_CARRIER
334 #define TX_CTL_CMD (Tx_EnComp | Tx_EnTxPar | Tx_EnLateColl | \
335 Tx_EnExColl | Tx_EnExDefer | Tx_EnUnder | \
336 Tx_En) /* maybe 0x7b01 */
338 #define TX_CTL_CMD (Tx_EnComp | Tx_EnTxPar | Tx_EnLateColl | \
339 Tx_EnExColl | Tx_EnLCarr | Tx_EnExDefer | Tx_EnUnder | \
340 Tx_En) /* maybe 0x7b01 */
342 #define RX_CTL_CMD (Rx_EnGood | Rx_EnRxPar | Rx_EnLongErr | Rx_EnOver \
343 | Rx_EnCRCErr | Rx_EnAlign | Rx_RxEn) /* maybe 0x6f01 */
344 #define INT_EN_CMD (Int_NRAbtEn | \
345 Int_DmParErrEn | Int_DParDEn | Int_DParErrEn | \
346 Int_SSysErrEn | Int_RMasAbtEn | Int_RTargAbtEn | \
348 Int_BLExEn | Int_FDAExEn) /* maybe 0xb7f*/
349 #define DMA_CTL_CMD DMA_BURST_SIZE
350 #define HAVE_DMA_RXALIGN(lp) likely((lp)->boardtype != TC35815CF)
352 /* Tuning parameters */
353 #define DMA_BURST_SIZE 32
354 #define TX_THRESHOLD 1024
355 #define TX_THRESHOLD_MAX 1536 /* used threshold with packet max byte for low pci transfer ability.*/
356 #define TX_THRESHOLD_KEEP_LIMIT 10 /* setting threshold max value when overrun error occured this count. */
358 /* 16 + RX_BUF_NUM * 8 + RX_FD_NUM * 16 + TX_FD_NUM * 32 <= PAGE_SIZE*FD_PAGE_NUM */
359 #ifdef TC35815_USE_PACKEDBUFFER
360 #define FD_PAGE_NUM 2
361 #define RX_BUF_NUM 8 /* >= 2 */
362 #define RX_FD_NUM 250 /* >= 32 */
363 #define TX_FD_NUM 128
364 #define RX_BUF_SIZE PAGE_SIZE
365 #else /* TC35815_USE_PACKEDBUFFER */
366 #define FD_PAGE_NUM 4
367 #define RX_BUF_NUM 128 /* < 256 */
368 #define RX_FD_NUM 256 /* >= 32 */
369 #define TX_FD_NUM 128
370 #if RX_CTL_CMD & Rx_LongEn
371 #define RX_BUF_SIZE PAGE_SIZE
372 #elif RX_CTL_CMD & Rx_StripCRC
373 #define RX_BUF_SIZE ALIGN(ETH_FRAME_LEN + 4 + 2, 32) /* +2: reserve */
375 #define RX_BUF_SIZE ALIGN(ETH_FRAME_LEN + 2, 32) /* +2: reserve */
377 #endif /* TC35815_USE_PACKEDBUFFER */
378 #define RX_FD_RESERVE (2 / 2) /* max 2 BD per RxFD */
379 #define NAPI_WEIGHT 16
389 struct BDesc bd
[0]; /* variable length */
394 struct BDesc bd
[RX_BUF_NUM
];
398 #define tc_readl(addr) readl(addr)
399 #define tc_writel(d, addr) writel(d, addr)
401 #define TC35815_TX_TIMEOUT msecs_to_jiffies(400)
403 /* Timer state engine. */
404 enum tc35815_timer_state
{
405 arbwait
= 0, /* Waiting for auto negotiation to complete. */
406 lupwait
= 1, /* Auto-neg complete, awaiting link-up status. */
407 ltrywait
= 2, /* Forcing try of all modes, from fastest to slowest. */
408 asleep
= 3, /* Time inactive. */
409 lcheck
= 4, /* Check link status. */
412 /* Information that need to be kept for each board. */
413 struct tc35815_local
{
414 struct pci_dev
*pci_dev
;
417 struct net_device_stats stats
;
425 /* Tx control lock. This protects the transmit buffer ring
426 * state along with the "tx full" state of the driver. This
427 * means all netif_queue flow control actions are protected
428 * by this lock as well.
434 unsigned short saved_lpa
;
435 struct timer_list timer
;
436 enum tc35815_timer_state timer_state
; /* State of auto-neg timer. */
437 unsigned int timer_ticks
; /* Number of clicks at each state */
440 * Transmitting: Batch Mode.
442 * Receiving: Packing Mode. (TC35815_USE_PACKEDBUFFER)
443 * 1 circular FD for Free Buffer List.
444 * RX_BUF_NUM BD in Free Buffer FD.
445 * One Free Buffer BD has PAGE_SIZE data buffer.
446 * Or Non-Packing Mode.
447 * 1 circular FD for Free Buffer List.
448 * RX_BUF_NUM BD in Free Buffer FD.
449 * One Free Buffer BD has ETH_FRAME_LEN data buffer.
451 void * fd_buf
; /* for TxFD, RxFD, FrFD */
452 dma_addr_t fd_buf_dma
;
453 struct TxFD
*tfd_base
;
454 unsigned int tfd_start
;
455 unsigned int tfd_end
;
456 struct RxFD
*rfd_base
;
457 struct RxFD
*rfd_limit
;
458 struct RxFD
*rfd_cur
;
459 struct FrFD
*fbl_ptr
;
460 #ifdef TC35815_USE_PACKEDBUFFER
461 unsigned char fbl_curid
;
462 void * data_buf
[RX_BUF_NUM
]; /* packing */
463 dma_addr_t data_buf_dma
[RX_BUF_NUM
];
467 } tx_skbs
[TX_FD_NUM
];
469 unsigned int fbl_count
;
473 } tx_skbs
[TX_FD_NUM
], rx_skbs
[RX_BUF_NUM
];
475 struct mii_if_info mii
;
476 unsigned short mii_id
[2];
481 static inline dma_addr_t
fd_virt_to_bus(struct tc35815_local
*lp
, void *virt
)
483 return lp
->fd_buf_dma
+ ((u8
*)virt
- (u8
*)lp
->fd_buf
);
486 static inline void *fd_bus_to_virt(struct tc35815_local
*lp
, dma_addr_t bus
)
488 return (void *)((u8
*)lp
->fd_buf
+ (bus
- lp
->fd_buf_dma
));
491 #ifdef TC35815_USE_PACKEDBUFFER
492 static inline void *rxbuf_bus_to_virt(struct tc35815_local
*lp
, dma_addr_t bus
)
495 for (i
= 0; i
< RX_BUF_NUM
; i
++) {
496 if (bus
>= lp
->data_buf_dma
[i
] &&
497 bus
< lp
->data_buf_dma
[i
] + PAGE_SIZE
)
498 return (void *)((u8
*)lp
->data_buf
[i
] +
499 (bus
- lp
->data_buf_dma
[i
]));
504 #define TC35815_DMA_SYNC_ONDEMAND
505 static void* alloc_rxbuf_page(struct pci_dev
*hwdev
, dma_addr_t
*dma_handle
)
507 #ifdef TC35815_DMA_SYNC_ONDEMAND
509 /* pci_map + pci_dma_sync will be more effective than
510 * pci_alloc_consistent on some archs. */
511 if ((buf
= (void *)__get_free_page(GFP_ATOMIC
)) == NULL
)
513 *dma_handle
= pci_map_single(hwdev
, buf
, PAGE_SIZE
,
515 if (pci_dma_mapping_error(*dma_handle
)) {
516 free_page((unsigned long)buf
);
521 return pci_alloc_consistent(hwdev
, PAGE_SIZE
, dma_handle
);
525 static void free_rxbuf_page(struct pci_dev
*hwdev
, void *buf
, dma_addr_t dma_handle
)
527 #ifdef TC35815_DMA_SYNC_ONDEMAND
528 pci_unmap_single(hwdev
, dma_handle
, PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
529 free_page((unsigned long)buf
);
531 pci_free_consistent(hwdev
, PAGE_SIZE
, buf
, dma_handle
);
534 #else /* TC35815_USE_PACKEDBUFFER */
535 static struct sk_buff
*alloc_rxbuf_skb(struct net_device
*dev
,
536 struct pci_dev
*hwdev
,
537 dma_addr_t
*dma_handle
)
540 skb
= dev_alloc_skb(RX_BUF_SIZE
);
543 *dma_handle
= pci_map_single(hwdev
, skb
->data
, RX_BUF_SIZE
,
545 if (pci_dma_mapping_error(*dma_handle
)) {
546 dev_kfree_skb_any(skb
);
549 skb_reserve(skb
, 2); /* make IP header 4byte aligned */
553 static void free_rxbuf_skb(struct pci_dev
*hwdev
, struct sk_buff
*skb
, dma_addr_t dma_handle
)
555 pci_unmap_single(hwdev
, dma_handle
, RX_BUF_SIZE
,
557 dev_kfree_skb_any(skb
);
559 #endif /* TC35815_USE_PACKEDBUFFER */
561 /* Index to functions, as function prototypes. */
563 static int tc35815_open(struct net_device
*dev
);
564 static int tc35815_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
565 static irqreturn_t
tc35815_interrupt(int irq
, void *dev_id
);
567 static int tc35815_rx(struct net_device
*dev
, int limit
);
568 static int tc35815_poll(struct net_device
*dev
, int *budget
);
570 static void tc35815_rx(struct net_device
*dev
);
572 static void tc35815_txdone(struct net_device
*dev
);
573 static int tc35815_close(struct net_device
*dev
);
574 static struct net_device_stats
*tc35815_get_stats(struct net_device
*dev
);
575 static void tc35815_set_multicast_list(struct net_device
*dev
);
576 static void tc35815_tx_timeout(struct net_device
*dev
);
577 static int tc35815_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
578 #ifdef CONFIG_NET_POLL_CONTROLLER
579 static void tc35815_poll_controller(struct net_device
*dev
);
581 static const struct ethtool_ops tc35815_ethtool_ops
;
583 /* Example routines you must write ;->. */
584 static void tc35815_chip_reset(struct net_device
*dev
);
585 static void tc35815_chip_init(struct net_device
*dev
);
586 static void tc35815_find_phy(struct net_device
*dev
);
587 static void tc35815_phy_chip_init(struct net_device
*dev
);
590 static void panic_queues(struct net_device
*dev
);
593 static void tc35815_timer(unsigned long data
);
594 static void tc35815_start_auto_negotiation(struct net_device
*dev
,
595 struct ethtool_cmd
*ep
);
596 static int tc_mdio_read(struct net_device
*dev
, int phy_id
, int location
);
597 static void tc_mdio_write(struct net_device
*dev
, int phy_id
, int location
,
600 static void __devinit
tc35815_init_dev_addr (struct net_device
*dev
)
602 struct tc35815_regs __iomem
*tr
=
603 (struct tc35815_regs __iomem
*)dev
->base_addr
;
606 /* dev_addr will be overwritten on NETDEV_REGISTER event */
607 while (tc_readl(&tr
->PROM_Ctl
) & PROM_Busy
)
609 for (i
= 0; i
< 6; i
+= 2) {
611 tc_writel(PROM_Busy
| PROM_Read
| (i
/ 2 + 2), &tr
->PROM_Ctl
);
612 while (tc_readl(&tr
->PROM_Ctl
) & PROM_Busy
)
614 data
= tc_readl(&tr
->PROM_Data
);
615 dev
->dev_addr
[i
] = data
& 0xff;
616 dev
->dev_addr
[i
+1] = data
>> 8;
620 static int __devinit
tc35815_init_one (struct pci_dev
*pdev
,
621 const struct pci_device_id
*ent
)
623 void __iomem
*ioaddr
= NULL
;
624 struct net_device
*dev
;
625 struct tc35815_local
*lp
;
627 unsigned long mmio_start
, mmio_end
, mmio_flags
, mmio_len
;
629 static int printed_version
;
630 if (!printed_version
++) {
632 dev_printk(KERN_DEBUG
, &pdev
->dev
,
633 "speed:%d duplex:%d doforce:%d\n",
634 options
.speed
, options
.duplex
, options
.doforce
);
638 dev_warn(&pdev
->dev
, "no IRQ assigned.\n");
642 /* dev zeroed in alloc_etherdev */
643 dev
= alloc_etherdev (sizeof (*lp
));
645 dev_err(&pdev
->dev
, "unable to alloc new ethernet\n");
648 SET_MODULE_OWNER(dev
);
649 SET_NETDEV_DEV(dev
, &pdev
->dev
);
652 /* enable device (incl. PCI PM wakeup), and bus-mastering */
653 rc
= pci_enable_device (pdev
);
657 mmio_start
= pci_resource_start (pdev
, 1);
658 mmio_end
= pci_resource_end (pdev
, 1);
659 mmio_flags
= pci_resource_flags (pdev
, 1);
660 mmio_len
= pci_resource_len (pdev
, 1);
662 /* set this immediately, we need to know before
663 * we talk to the chip directly */
665 /* make sure PCI base addr 1 is MMIO */
666 if (!(mmio_flags
& IORESOURCE_MEM
)) {
667 dev_err(&pdev
->dev
, "region #1 not an MMIO resource, aborting\n");
672 /* check for weird/broken PCI region reporting */
673 if ((mmio_len
< sizeof(struct tc35815_regs
))) {
674 dev_err(&pdev
->dev
, "Invalid PCI region size(s), aborting\n");
679 rc
= pci_request_regions (pdev
, MODNAME
);
683 pci_set_master (pdev
);
685 /* ioremap MMIO region */
686 ioaddr
= ioremap (mmio_start
, mmio_len
);
687 if (ioaddr
== NULL
) {
688 dev_err(&pdev
->dev
, "cannot remap MMIO, aborting\n");
690 goto err_out_free_res
;
693 /* Initialize the device structure. */
694 dev
->open
= tc35815_open
;
695 dev
->hard_start_xmit
= tc35815_send_packet
;
696 dev
->stop
= tc35815_close
;
697 dev
->get_stats
= tc35815_get_stats
;
698 dev
->set_multicast_list
= tc35815_set_multicast_list
;
699 dev
->do_ioctl
= tc35815_ioctl
;
700 dev
->ethtool_ops
= &tc35815_ethtool_ops
;
701 dev
->tx_timeout
= tc35815_tx_timeout
;
702 dev
->watchdog_timeo
= TC35815_TX_TIMEOUT
;
704 dev
->poll
= tc35815_poll
;
705 dev
->weight
= NAPI_WEIGHT
;
707 #ifdef CONFIG_NET_POLL_CONTROLLER
708 dev
->poll_controller
= tc35815_poll_controller
;
711 dev
->irq
= pdev
->irq
;
712 dev
->base_addr
= (unsigned long) ioaddr
;
714 /* dev->priv/lp zeroed and aligned in alloc_etherdev */
716 spin_lock_init(&lp
->lock
);
718 lp
->boardtype
= ent
->driver_data
;
720 lp
->msg_enable
= NETIF_MSG_TX_ERR
| NETIF_MSG_HW
| NETIF_MSG_DRV
| NETIF_MSG_LINK
;
721 pci_set_drvdata(pdev
, dev
);
723 /* Soft reset the chip. */
724 tc35815_chip_reset(dev
);
726 /* Retrieve the ethernet address. */
727 tc35815_init_dev_addr(dev
);
729 rc
= register_netdev (dev
);
733 memcpy(dev
->perm_addr
, dev
->dev_addr
, dev
->addr_len
);
734 printk(KERN_INFO
"%s: %s at 0x%lx, "
735 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
738 board_info
[ent
->driver_data
].name
,
740 dev
->dev_addr
[0], dev
->dev_addr
[1],
741 dev
->dev_addr
[2], dev
->dev_addr
[3],
742 dev
->dev_addr
[4], dev
->dev_addr
[5],
745 setup_timer(&lp
->timer
, tc35815_timer
, (unsigned long) dev
);
747 lp
->mii
.mdio_read
= tc_mdio_read
;
748 lp
->mii
.mdio_write
= tc_mdio_write
;
749 lp
->mii
.phy_id_mask
= 0x1f;
750 lp
->mii
.reg_num_mask
= 0x1f;
751 tc35815_find_phy(dev
);
752 lp
->mii
.phy_id
= lp
->phy_addr
;
753 lp
->mii
.full_duplex
= 0;
754 lp
->mii
.force_media
= 0;
761 pci_release_regions (pdev
);
768 static void __devexit
tc35815_remove_one (struct pci_dev
*pdev
)
770 struct net_device
*dev
= pci_get_drvdata (pdev
);
771 unsigned long mmio_addr
;
773 mmio_addr
= dev
->base_addr
;
775 unregister_netdev (dev
);
778 iounmap ((void __iomem
*)mmio_addr
);
779 pci_release_regions (pdev
);
784 pci_set_drvdata (pdev
, NULL
);
788 tc35815_init_queues(struct net_device
*dev
)
790 struct tc35815_local
*lp
= dev
->priv
;
792 unsigned long fd_addr
;
795 BUG_ON(sizeof(struct FDesc
) +
796 sizeof(struct BDesc
) * RX_BUF_NUM
+
797 sizeof(struct FDesc
) * RX_FD_NUM
+
798 sizeof(struct TxFD
) * TX_FD_NUM
>
799 PAGE_SIZE
* FD_PAGE_NUM
);
801 if ((lp
->fd_buf
= pci_alloc_consistent(lp
->pci_dev
, PAGE_SIZE
* FD_PAGE_NUM
, &lp
->fd_buf_dma
)) == 0)
803 for (i
= 0; i
< RX_BUF_NUM
; i
++) {
804 #ifdef TC35815_USE_PACKEDBUFFER
805 if ((lp
->data_buf
[i
] = alloc_rxbuf_page(lp
->pci_dev
, &lp
->data_buf_dma
[i
])) == NULL
) {
807 free_rxbuf_page(lp
->pci_dev
,
809 lp
->data_buf_dma
[i
]);
810 lp
->data_buf
[i
] = NULL
;
812 pci_free_consistent(lp
->pci_dev
,
813 PAGE_SIZE
* FD_PAGE_NUM
,
821 alloc_rxbuf_skb(dev
, lp
->pci_dev
,
822 &lp
->rx_skbs
[i
].skb_dma
);
823 if (!lp
->rx_skbs
[i
].skb
) {
825 free_rxbuf_skb(lp
->pci_dev
,
827 lp
->rx_skbs
[i
].skb_dma
);
828 lp
->rx_skbs
[i
].skb
= NULL
;
830 pci_free_consistent(lp
->pci_dev
,
831 PAGE_SIZE
* FD_PAGE_NUM
,
839 printk(KERN_DEBUG
"%s: FD buf %p DataBuf",
840 dev
->name
, lp
->fd_buf
);
841 #ifdef TC35815_USE_PACKEDBUFFER
843 for (i
= 0; i
< RX_BUF_NUM
; i
++)
844 printk(" %p", lp
->data_buf
[i
]);
848 for (i
= 0; i
< FD_PAGE_NUM
; i
++) {
849 clear_page((void *)((unsigned long)lp
->fd_buf
+ i
* PAGE_SIZE
));
852 fd_addr
= (unsigned long)lp
->fd_buf
;
854 /* Free Descriptors (for Receive) */
855 lp
->rfd_base
= (struct RxFD
*)fd_addr
;
856 fd_addr
+= sizeof(struct RxFD
) * RX_FD_NUM
;
857 for (i
= 0; i
< RX_FD_NUM
; i
++) {
858 lp
->rfd_base
[i
].fd
.FDCtl
= cpu_to_le32(FD_CownsFD
);
860 lp
->rfd_cur
= lp
->rfd_base
;
861 lp
->rfd_limit
= (struct RxFD
*)fd_addr
- (RX_FD_RESERVE
+ 1);
863 /* Transmit Descriptors */
864 lp
->tfd_base
= (struct TxFD
*)fd_addr
;
865 fd_addr
+= sizeof(struct TxFD
) * TX_FD_NUM
;
866 for (i
= 0; i
< TX_FD_NUM
; i
++) {
867 lp
->tfd_base
[i
].fd
.FDNext
= cpu_to_le32(fd_virt_to_bus(lp
, &lp
->tfd_base
[i
+1]));
868 lp
->tfd_base
[i
].fd
.FDSystem
= cpu_to_le32(0xffffffff);
869 lp
->tfd_base
[i
].fd
.FDCtl
= cpu_to_le32(0);
871 lp
->tfd_base
[TX_FD_NUM
-1].fd
.FDNext
= cpu_to_le32(fd_virt_to_bus(lp
, &lp
->tfd_base
[0]));
875 /* Buffer List (for Receive) */
876 lp
->fbl_ptr
= (struct FrFD
*)fd_addr
;
877 lp
->fbl_ptr
->fd
.FDNext
= cpu_to_le32(fd_virt_to_bus(lp
, lp
->fbl_ptr
));
878 lp
->fbl_ptr
->fd
.FDCtl
= cpu_to_le32(RX_BUF_NUM
| FD_CownsFD
);
879 #ifndef TC35815_USE_PACKEDBUFFER
881 * move all allocated skbs to head of rx_skbs[] array.
882 * fbl_count mighe not be RX_BUF_NUM if alloc_rxbuf_skb() in
883 * tc35815_rx() had failed.
886 for (i
= 0; i
< RX_BUF_NUM
; i
++) {
887 if (lp
->rx_skbs
[i
].skb
) {
888 if (i
!= lp
->fbl_count
) {
889 lp
->rx_skbs
[lp
->fbl_count
].skb
=
891 lp
->rx_skbs
[lp
->fbl_count
].skb_dma
=
892 lp
->rx_skbs
[i
].skb_dma
;
898 for (i
= 0; i
< RX_BUF_NUM
; i
++) {
899 #ifdef TC35815_USE_PACKEDBUFFER
900 lp
->fbl_ptr
->bd
[i
].BuffData
= cpu_to_le32(lp
->data_buf_dma
[i
]);
902 if (i
>= lp
->fbl_count
) {
903 lp
->fbl_ptr
->bd
[i
].BuffData
= 0;
904 lp
->fbl_ptr
->bd
[i
].BDCtl
= 0;
907 lp
->fbl_ptr
->bd
[i
].BuffData
=
908 cpu_to_le32(lp
->rx_skbs
[i
].skb_dma
);
910 /* BDID is index of FrFD.bd[] */
911 lp
->fbl_ptr
->bd
[i
].BDCtl
=
912 cpu_to_le32(BD_CownsBD
| (i
<< BD_RxBDID_SHIFT
) |
915 #ifdef TC35815_USE_PACKEDBUFFER
919 printk(KERN_DEBUG
"%s: TxFD %p RxFD %p FrFD %p\n",
920 dev
->name
, lp
->tfd_base
, lp
->rfd_base
, lp
->fbl_ptr
);
925 tc35815_clear_queues(struct net_device
*dev
)
927 struct tc35815_local
*lp
= dev
->priv
;
930 for (i
= 0; i
< TX_FD_NUM
; i
++) {
931 u32 fdsystem
= le32_to_cpu(lp
->tfd_base
[i
].fd
.FDSystem
);
932 struct sk_buff
*skb
=
933 fdsystem
!= 0xffffffff ?
934 lp
->tx_skbs
[fdsystem
].skb
: NULL
;
936 if (lp
->tx_skbs
[i
].skb
!= skb
) {
937 printk("%s: tx_skbs mismatch(%d).\n", dev
->name
, i
);
941 BUG_ON(lp
->tx_skbs
[i
].skb
!= skb
);
944 pci_unmap_single(lp
->pci_dev
, lp
->tx_skbs
[i
].skb_dma
, skb
->len
, PCI_DMA_TODEVICE
);
945 lp
->tx_skbs
[i
].skb
= NULL
;
946 lp
->tx_skbs
[i
].skb_dma
= 0;
947 dev_kfree_skb_any(skb
);
949 lp
->tfd_base
[i
].fd
.FDSystem
= cpu_to_le32(0xffffffff);
952 tc35815_init_queues(dev
);
956 tc35815_free_queues(struct net_device
*dev
)
958 struct tc35815_local
*lp
= dev
->priv
;
962 for (i
= 0; i
< TX_FD_NUM
; i
++) {
963 u32 fdsystem
= le32_to_cpu(lp
->tfd_base
[i
].fd
.FDSystem
);
964 struct sk_buff
*skb
=
965 fdsystem
!= 0xffffffff ?
966 lp
->tx_skbs
[fdsystem
].skb
: NULL
;
968 if (lp
->tx_skbs
[i
].skb
!= skb
) {
969 printk("%s: tx_skbs mismatch(%d).\n", dev
->name
, i
);
973 BUG_ON(lp
->tx_skbs
[i
].skb
!= skb
);
977 pci_unmap_single(lp
->pci_dev
, lp
->tx_skbs
[i
].skb_dma
, skb
->len
, PCI_DMA_TODEVICE
);
978 lp
->tx_skbs
[i
].skb
= NULL
;
979 lp
->tx_skbs
[i
].skb_dma
= 0;
981 lp
->tfd_base
[i
].fd
.FDSystem
= cpu_to_le32(0xffffffff);
986 lp
->rfd_limit
= NULL
;
990 for (i
= 0; i
< RX_BUF_NUM
; i
++) {
991 #ifdef TC35815_USE_PACKEDBUFFER
992 if (lp
->data_buf
[i
]) {
993 free_rxbuf_page(lp
->pci_dev
,
994 lp
->data_buf
[i
], lp
->data_buf_dma
[i
]);
995 lp
->data_buf
[i
] = NULL
;
998 if (lp
->rx_skbs
[i
].skb
) {
999 free_rxbuf_skb(lp
->pci_dev
, lp
->rx_skbs
[i
].skb
,
1000 lp
->rx_skbs
[i
].skb_dma
);
1001 lp
->rx_skbs
[i
].skb
= NULL
;
1006 pci_free_consistent(lp
->pci_dev
, PAGE_SIZE
* FD_PAGE_NUM
,
1007 lp
->fd_buf
, lp
->fd_buf_dma
);
1013 dump_txfd(struct TxFD
*fd
)
1015 printk("TxFD(%p): %08x %08x %08x %08x\n", fd
,
1016 le32_to_cpu(fd
->fd
.FDNext
),
1017 le32_to_cpu(fd
->fd
.FDSystem
),
1018 le32_to_cpu(fd
->fd
.FDStat
),
1019 le32_to_cpu(fd
->fd
.FDCtl
));
1021 printk(" %08x %08x",
1022 le32_to_cpu(fd
->bd
.BuffData
),
1023 le32_to_cpu(fd
->bd
.BDCtl
));
1028 dump_rxfd(struct RxFD
*fd
)
1030 int i
, bd_count
= (le32_to_cpu(fd
->fd
.FDCtl
) & FD_BDCnt_MASK
) >> FD_BDCnt_SHIFT
;
1033 printk("RxFD(%p): %08x %08x %08x %08x\n", fd
,
1034 le32_to_cpu(fd
->fd
.FDNext
),
1035 le32_to_cpu(fd
->fd
.FDSystem
),
1036 le32_to_cpu(fd
->fd
.FDStat
),
1037 le32_to_cpu(fd
->fd
.FDCtl
));
1038 if (le32_to_cpu(fd
->fd
.FDCtl
) & FD_CownsFD
)
1041 for (i
= 0; i
< bd_count
; i
++)
1042 printk(" %08x %08x",
1043 le32_to_cpu(fd
->bd
[i
].BuffData
),
1044 le32_to_cpu(fd
->bd
[i
].BDCtl
));
1049 #if defined(DEBUG) || defined(TC35815_USE_PACKEDBUFFER)
1051 dump_frfd(struct FrFD
*fd
)
1054 printk("FrFD(%p): %08x %08x %08x %08x\n", fd
,
1055 le32_to_cpu(fd
->fd
.FDNext
),
1056 le32_to_cpu(fd
->fd
.FDSystem
),
1057 le32_to_cpu(fd
->fd
.FDStat
),
1058 le32_to_cpu(fd
->fd
.FDCtl
));
1060 for (i
= 0; i
< RX_BUF_NUM
; i
++)
1061 printk(" %08x %08x",
1062 le32_to_cpu(fd
->bd
[i
].BuffData
),
1063 le32_to_cpu(fd
->bd
[i
].BDCtl
));
1070 panic_queues(struct net_device
*dev
)
1072 struct tc35815_local
*lp
= dev
->priv
;
1075 printk("TxFD base %p, start %u, end %u\n",
1076 lp
->tfd_base
, lp
->tfd_start
, lp
->tfd_end
);
1077 printk("RxFD base %p limit %p cur %p\n",
1078 lp
->rfd_base
, lp
->rfd_limit
, lp
->rfd_cur
);
1079 printk("FrFD %p\n", lp
->fbl_ptr
);
1080 for (i
= 0; i
< TX_FD_NUM
; i
++)
1081 dump_txfd(&lp
->tfd_base
[i
]);
1082 for (i
= 0; i
< RX_FD_NUM
; i
++) {
1083 int bd_count
= dump_rxfd(&lp
->rfd_base
[i
]);
1084 i
+= (bd_count
+ 1) / 2; /* skip BDs */
1086 dump_frfd(lp
->fbl_ptr
);
1087 panic("%s: Illegal queue state.", dev
->name
);
1091 static void print_eth(char *add
)
1095 printk("print_eth(%p)\n", add
);
1096 for (i
= 0; i
< 6; i
++)
1097 printk(" %2.2X", (unsigned char) add
[i
+ 6]);
1099 for (i
= 0; i
< 6; i
++)
1100 printk(" %2.2X", (unsigned char) add
[i
]);
1101 printk(" : %2.2X%2.2X\n", (unsigned char) add
[12], (unsigned char) add
[13]);
1104 static int tc35815_tx_full(struct net_device
*dev
)
1106 struct tc35815_local
*lp
= dev
->priv
;
1107 return ((lp
->tfd_start
+ 1) % TX_FD_NUM
== lp
->tfd_end
);
1110 static void tc35815_restart(struct net_device
*dev
)
1112 struct tc35815_local
*lp
= dev
->priv
;
1113 int pid
= lp
->phy_addr
;
1114 int do_phy_reset
= 1;
1115 del_timer(&lp
->timer
); /* Kill if running */
1117 if (lp
->mii_id
[0] == 0x0016 && (lp
->mii_id
[1] & 0xfc00) == 0xf800) {
1118 /* Resetting PHY cause problem on some chip... (SEEQ 80221) */
1123 tc_mdio_write(dev
, pid
, MII_BMCR
, BMCR_RESET
);
1126 if (!(tc_mdio_read(dev
, pid
, MII_BMCR
) & BMCR_RESET
))
1131 printk(KERN_ERR
"%s: BMCR reset failed.\n", dev
->name
);
1134 tc35815_chip_reset(dev
);
1135 tc35815_clear_queues(dev
);
1136 tc35815_chip_init(dev
);
1137 /* Reconfigure CAM again since tc35815_chip_init() initialize it. */
1138 tc35815_set_multicast_list(dev
);
1141 static void tc35815_tx_timeout(struct net_device
*dev
)
1143 struct tc35815_local
*lp
= dev
->priv
;
1144 struct tc35815_regs __iomem
*tr
=
1145 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1147 printk(KERN_WARNING
"%s: transmit timed out, status %#x\n",
1148 dev
->name
, tc_readl(&tr
->Tx_Stat
));
1150 /* Try to restart the adaptor. */
1151 spin_lock_irq(&lp
->lock
);
1152 tc35815_restart(dev
);
1153 spin_unlock_irq(&lp
->lock
);
1155 lp
->stats
.tx_errors
++;
1157 /* If we have space available to accept new transmit
1158 * requests, wake up the queueing layer. This would
1159 * be the case if the chipset_init() call above just
1160 * flushes out the tx queue and empties it.
1162 * If instead, the tx queue is retained then the
1163 * netif_wake_queue() call should be placed in the
1164 * TX completion interrupt handler of the driver instead
1167 if (!tc35815_tx_full(dev
))
1168 netif_wake_queue(dev
);
1172 * Open/initialize the board. This is called (in the current kernel)
1173 * sometime after booting when the 'ifconfig' program is run.
1175 * This routine should set everything up anew at each open, even
1176 * registers that "should" only need to be set once at boot, so that
1177 * there is non-reboot way to recover if something goes wrong.
1180 tc35815_open(struct net_device
*dev
)
1182 struct tc35815_local
*lp
= dev
->priv
;
1185 * This is used if the interrupt line can turned off (shared).
1186 * See 3c503.c for an example of selecting the IRQ at config-time.
1188 if (request_irq(dev
->irq
, &tc35815_interrupt
, IRQF_SHARED
, dev
->name
, dev
)) {
1192 del_timer(&lp
->timer
); /* Kill if running */
1193 tc35815_chip_reset(dev
);
1195 if (tc35815_init_queues(dev
) != 0) {
1196 free_irq(dev
->irq
, dev
);
1200 /* Reset the hardware here. Don't forget to set the station address. */
1201 spin_lock_irq(&lp
->lock
);
1202 tc35815_chip_init(dev
);
1203 spin_unlock_irq(&lp
->lock
);
1205 /* We are now ready to accept transmit requeusts from
1206 * the queueing layer of the networking.
1208 netif_start_queue(dev
);
1213 /* This will only be invoked if your driver is _not_ in XOFF state.
1214 * What this means is that you need not check it, and that this
1215 * invariant will hold if you make sure that the netif_*_queue()
1216 * calls are done at the proper times.
1218 static int tc35815_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1220 struct tc35815_local
*lp
= dev
->priv
;
1222 unsigned long flags
;
1224 /* If some error occurs while trying to transmit this
1225 * packet, you should return '1' from this function.
1226 * In such a case you _may not_ do anything to the
1227 * SKB, it is still owned by the network queueing
1228 * layer when an error is returned. This means you
1229 * may not modify any SKB fields, you may not free
1233 /* This is the most common case for modern hardware.
1234 * The spinlock protects this code from the TX complete
1235 * hardware interrupt handler. Queue flow control is
1236 * thus managed under this lock as well.
1238 spin_lock_irqsave(&lp
->lock
, flags
);
1240 /* failsafe... (handle txdone now if half of FDs are used) */
1241 if ((lp
->tfd_start
+ TX_FD_NUM
- lp
->tfd_end
) % TX_FD_NUM
>
1243 tc35815_txdone(dev
);
1245 if (netif_msg_pktdata(lp
))
1246 print_eth(skb
->data
);
1248 if (lp
->tx_skbs
[lp
->tfd_start
].skb
) {
1249 printk("%s: tx_skbs conflict.\n", dev
->name
);
1253 BUG_ON(lp
->tx_skbs
[lp
->tfd_start
].skb
);
1255 lp
->tx_skbs
[lp
->tfd_start
].skb
= skb
;
1256 lp
->tx_skbs
[lp
->tfd_start
].skb_dma
= pci_map_single(lp
->pci_dev
, skb
->data
, skb
->len
, PCI_DMA_TODEVICE
);
1259 txfd
= &lp
->tfd_base
[lp
->tfd_start
];
1260 txfd
->bd
.BuffData
= cpu_to_le32(lp
->tx_skbs
[lp
->tfd_start
].skb_dma
);
1261 txfd
->bd
.BDCtl
= cpu_to_le32(skb
->len
);
1262 txfd
->fd
.FDSystem
= cpu_to_le32(lp
->tfd_start
);
1263 txfd
->fd
.FDCtl
= cpu_to_le32(FD_CownsFD
| (1 << FD_BDCnt_SHIFT
));
1265 if (lp
->tfd_start
== lp
->tfd_end
) {
1266 struct tc35815_regs __iomem
*tr
=
1267 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1268 /* Start DMA Transmitter. */
1269 txfd
->fd
.FDNext
|= cpu_to_le32(FD_Next_EOL
);
1271 txfd
->fd
.FDCtl
|= cpu_to_le32(FD_FrmOpt_IntTx
);
1273 if (netif_msg_tx_queued(lp
)) {
1274 printk("%s: starting TxFD.\n", dev
->name
);
1277 tc_writel(fd_virt_to_bus(lp
, txfd
), &tr
->TxFrmPtr
);
1279 txfd
->fd
.FDNext
&= cpu_to_le32(~FD_Next_EOL
);
1280 if (netif_msg_tx_queued(lp
)) {
1281 printk("%s: queueing TxFD.\n", dev
->name
);
1285 lp
->tfd_start
= (lp
->tfd_start
+ 1) % TX_FD_NUM
;
1287 dev
->trans_start
= jiffies
;
1289 /* If we just used up the very last entry in the
1290 * TX ring on this device, tell the queueing
1291 * layer to send no more.
1293 if (tc35815_tx_full(dev
)) {
1294 if (netif_msg_tx_queued(lp
))
1295 printk(KERN_WARNING
"%s: TxFD Exhausted.\n", dev
->name
);
1296 netif_stop_queue(dev
);
1299 /* When the TX completion hw interrupt arrives, this
1300 * is when the transmit statistics are updated.
1303 spin_unlock_irqrestore(&lp
->lock
, flags
);
1307 #define FATAL_ERROR_INT \
1308 (Int_IntPCI | Int_DmParErr | Int_IntNRAbt)
1309 static void tc35815_fatal_error_interrupt(struct net_device
*dev
, u32 status
)
1312 printk(KERN_WARNING
"%s: Fatal Error Intterrupt (%#x):",
1314 if (status
& Int_IntPCI
)
1316 if (status
& Int_DmParErr
)
1317 printk(" DmParErr");
1318 if (status
& Int_IntNRAbt
)
1319 printk(" IntNRAbt");
1322 panic("%s: Too many fatal errors.", dev
->name
);
1323 printk(KERN_WARNING
"%s: Resetting ...\n", dev
->name
);
1324 /* Try to restart the adaptor. */
1325 tc35815_restart(dev
);
1329 static int tc35815_do_interrupt(struct net_device
*dev
, u32 status
, int limit
)
1331 static int tc35815_do_interrupt(struct net_device
*dev
, u32 status
)
1334 struct tc35815_local
*lp
= dev
->priv
;
1335 struct tc35815_regs __iomem
*tr
=
1336 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1339 /* Fatal errors... */
1340 if (status
& FATAL_ERROR_INT
) {
1341 tc35815_fatal_error_interrupt(dev
, status
);
1344 /* recoverable errors */
1345 if (status
& Int_IntFDAEx
) {
1346 /* disable FDAEx int. (until we make rooms...) */
1347 tc_writel(tc_readl(&tr
->Int_En
) & ~Int_FDAExEn
, &tr
->Int_En
);
1349 "%s: Free Descriptor Area Exhausted (%#x).\n",
1351 lp
->stats
.rx_dropped
++;
1354 if (status
& Int_IntBLEx
) {
1355 /* disable BLEx int. (until we make rooms...) */
1356 tc_writel(tc_readl(&tr
->Int_En
) & ~Int_BLExEn
, &tr
->Int_En
);
1358 "%s: Buffer List Exhausted (%#x).\n",
1360 lp
->stats
.rx_dropped
++;
1363 if (status
& Int_IntExBD
) {
1365 "%s: Excessive Buffer Descriptiors (%#x).\n",
1367 lp
->stats
.rx_length_errors
++;
1371 /* normal notification */
1372 if (status
& Int_IntMacRx
) {
1373 /* Got a packet(s). */
1375 ret
= tc35815_rx(dev
, limit
);
1380 lp
->lstats
.rx_ints
++;
1382 if (status
& Int_IntMacTx
) {
1383 /* Transmit complete. */
1384 lp
->lstats
.tx_ints
++;
1385 tc35815_txdone(dev
);
1386 netif_wake_queue(dev
);
1393 * The typical workload of the driver:
1394 * Handle the network interface interrupts.
1396 static irqreturn_t
tc35815_interrupt(int irq
, void *dev_id
)
1398 struct net_device
*dev
= dev_id
;
1399 struct tc35815_regs __iomem
*tr
=
1400 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1402 u32 dmactl
= tc_readl(&tr
->DMA_Ctl
);
1404 if (!(dmactl
& DMA_IntMask
)) {
1405 /* disable interrupts */
1406 tc_writel(dmactl
| DMA_IntMask
, &tr
->DMA_Ctl
);
1407 if (netif_rx_schedule_prep(dev
))
1408 __netif_rx_schedule(dev
);
1410 printk(KERN_ERR
"%s: interrupt taken in poll\n",
1414 (void)tc_readl(&tr
->Int_Src
); /* flush */
1419 struct tc35815_local
*lp
= dev
->priv
;
1423 spin_lock(&lp
->lock
);
1424 status
= tc_readl(&tr
->Int_Src
);
1425 tc_writel(status
, &tr
->Int_Src
); /* write to clear */
1426 handled
= tc35815_do_interrupt(dev
, status
);
1427 (void)tc_readl(&tr
->Int_Src
); /* flush */
1428 spin_unlock(&lp
->lock
);
1429 return IRQ_RETVAL(handled
>= 0);
1430 #endif /* TC35815_NAPI */
1433 #ifdef CONFIG_NET_POLL_CONTROLLER
1434 static void tc35815_poll_controller(struct net_device
*dev
)
1436 disable_irq(dev
->irq
);
1437 tc35815_interrupt(dev
->irq
, dev
);
1438 enable_irq(dev
->irq
);
1442 /* We have a good packet(s), get it/them out of the buffers. */
1445 tc35815_rx(struct net_device
*dev
, int limit
)
1448 tc35815_rx(struct net_device
*dev
)
1451 struct tc35815_local
*lp
= dev
->priv
;
1454 int buf_free_count
= 0;
1455 int fd_free_count
= 0;
1460 while (!((fdctl
= le32_to_cpu(lp
->rfd_cur
->fd
.FDCtl
)) & FD_CownsFD
)) {
1461 int status
= le32_to_cpu(lp
->rfd_cur
->fd
.FDStat
);
1462 int pkt_len
= fdctl
& FD_FDLength_MASK
;
1463 int bd_count
= (fdctl
& FD_BDCnt_MASK
) >> FD_BDCnt_SHIFT
;
1465 struct RxFD
*next_rfd
;
1467 #if (RX_CTL_CMD & Rx_StripCRC) == 0
1471 if (netif_msg_rx_status(lp
))
1472 dump_rxfd(lp
->rfd_cur
);
1473 if (status
& Rx_Good
) {
1474 struct sk_buff
*skb
;
1475 unsigned char *data
;
1477 #ifdef TC35815_USE_PACKEDBUFFER
1485 #ifdef TC35815_USE_PACKEDBUFFER
1486 BUG_ON(bd_count
> 2);
1487 skb
= dev_alloc_skb(pkt_len
+ 2); /* +2: for reserve */
1489 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n",
1491 lp
->stats
.rx_dropped
++;
1494 skb_reserve(skb
, 2); /* 16 bit alignment */
1496 data
= skb_put(skb
, pkt_len
);
1498 /* copy from receive buffer */
1501 while (offset
< pkt_len
&& cur_bd
< bd_count
) {
1502 int len
= le32_to_cpu(lp
->rfd_cur
->bd
[cur_bd
].BDCtl
) &
1504 dma_addr_t dma
= le32_to_cpu(lp
->rfd_cur
->bd
[cur_bd
].BuffData
);
1505 void *rxbuf
= rxbuf_bus_to_virt(lp
, dma
);
1506 if (offset
+ len
> pkt_len
)
1507 len
= pkt_len
- offset
;
1508 #ifdef TC35815_DMA_SYNC_ONDEMAND
1509 pci_dma_sync_single_for_cpu(lp
->pci_dev
,
1511 PCI_DMA_FROMDEVICE
);
1513 memcpy(data
+ offset
, rxbuf
, len
);
1514 #ifdef TC35815_DMA_SYNC_ONDEMAND
1515 pci_dma_sync_single_for_device(lp
->pci_dev
,
1517 PCI_DMA_FROMDEVICE
);
1522 #else /* TC35815_USE_PACKEDBUFFER */
1523 BUG_ON(bd_count
> 1);
1524 cur_bd
= (le32_to_cpu(lp
->rfd_cur
->bd
[0].BDCtl
)
1525 & BD_RxBDID_MASK
) >> BD_RxBDID_SHIFT
;
1527 if (cur_bd
>= RX_BUF_NUM
) {
1528 printk("%s: invalid BDID.\n", dev
->name
);
1531 BUG_ON(lp
->rx_skbs
[cur_bd
].skb_dma
!=
1532 (le32_to_cpu(lp
->rfd_cur
->bd
[0].BuffData
) & ~3));
1533 if (!lp
->rx_skbs
[cur_bd
].skb
) {
1534 printk("%s: NULL skb.\n", dev
->name
);
1538 BUG_ON(cur_bd
>= RX_BUF_NUM
);
1540 skb
= lp
->rx_skbs
[cur_bd
].skb
;
1541 prefetch(skb
->data
);
1542 lp
->rx_skbs
[cur_bd
].skb
= NULL
;
1544 pci_unmap_single(lp
->pci_dev
,
1545 lp
->rx_skbs
[cur_bd
].skb_dma
,
1546 RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
1547 if (!HAVE_DMA_RXALIGN(lp
))
1548 memmove(skb
->data
, skb
->data
- 2, pkt_len
);
1549 data
= skb_put(skb
, pkt_len
);
1550 #endif /* TC35815_USE_PACKEDBUFFER */
1551 if (netif_msg_pktdata(lp
))
1553 skb
->protocol
= eth_type_trans(skb
, dev
);
1555 netif_receive_skb(skb
);
1560 dev
->last_rx
= jiffies
;
1561 lp
->stats
.rx_packets
++;
1562 lp
->stats
.rx_bytes
+= pkt_len
;
1564 lp
->stats
.rx_errors
++;
1565 printk(KERN_DEBUG
"%s: Rx error (status %x)\n",
1566 dev
->name
, status
& Rx_Stat_Mask
);
1567 /* WORKAROUND: LongErr and CRCErr means Overflow. */
1568 if ((status
& Rx_LongErr
) && (status
& Rx_CRCErr
)) {
1569 status
&= ~(Rx_LongErr
|Rx_CRCErr
);
1572 if (status
& Rx_LongErr
) lp
->stats
.rx_length_errors
++;
1573 if (status
& Rx_Over
) lp
->stats
.rx_fifo_errors
++;
1574 if (status
& Rx_CRCErr
) lp
->stats
.rx_crc_errors
++;
1575 if (status
& Rx_Align
) lp
->stats
.rx_frame_errors
++;
1579 /* put Free Buffer back to controller */
1580 int bdctl
= le32_to_cpu(lp
->rfd_cur
->bd
[bd_count
- 1].BDCtl
);
1582 (bdctl
& BD_RxBDID_MASK
) >> BD_RxBDID_SHIFT
;
1584 if (id
>= RX_BUF_NUM
) {
1585 printk("%s: invalid BDID.\n", dev
->name
);
1589 BUG_ON(id
>= RX_BUF_NUM
);
1591 /* free old buffers */
1592 #ifdef TC35815_USE_PACKEDBUFFER
1593 while (lp
->fbl_curid
!= id
)
1595 while (lp
->fbl_count
< RX_BUF_NUM
)
1598 #ifdef TC35815_USE_PACKEDBUFFER
1599 unsigned char curid
= lp
->fbl_curid
;
1601 unsigned char curid
=
1602 (id
+ 1 + lp
->fbl_count
) % RX_BUF_NUM
;
1604 struct BDesc
*bd
= &lp
->fbl_ptr
->bd
[curid
];
1606 bdctl
= le32_to_cpu(bd
->BDCtl
);
1607 if (bdctl
& BD_CownsBD
) {
1608 printk("%s: Freeing invalid BD.\n",
1613 /* pass BD to controler */
1614 #ifndef TC35815_USE_PACKEDBUFFER
1615 if (!lp
->rx_skbs
[curid
].skb
) {
1616 lp
->rx_skbs
[curid
].skb
=
1617 alloc_rxbuf_skb(dev
,
1619 &lp
->rx_skbs
[curid
].skb_dma
);
1620 if (!lp
->rx_skbs
[curid
].skb
)
1621 break; /* try on next reception */
1622 bd
->BuffData
= cpu_to_le32(lp
->rx_skbs
[curid
].skb_dma
);
1624 #endif /* TC35815_USE_PACKEDBUFFER */
1625 /* Note: BDLength was modified by chip. */
1626 bd
->BDCtl
= cpu_to_le32(BD_CownsBD
|
1627 (curid
<< BD_RxBDID_SHIFT
) |
1629 #ifdef TC35815_USE_PACKEDBUFFER
1630 lp
->fbl_curid
= (curid
+ 1) % RX_BUF_NUM
;
1631 if (netif_msg_rx_status(lp
)) {
1632 printk("%s: Entering new FBD %d\n",
1633 dev
->name
, lp
->fbl_curid
);
1634 dump_frfd(lp
->fbl_ptr
);
1643 /* put RxFD back to controller */
1645 next_rfd
= fd_bus_to_virt(lp
,
1646 le32_to_cpu(lp
->rfd_cur
->fd
.FDNext
));
1647 if (next_rfd
< lp
->rfd_base
|| next_rfd
> lp
->rfd_limit
) {
1648 printk("%s: RxFD FDNext invalid.\n", dev
->name
);
1652 for (i
= 0; i
< (bd_count
+ 1) / 2 + 1; i
++) {
1653 /* pass FD to controler */
1655 lp
->rfd_cur
->fd
.FDNext
= cpu_to_le32(0xdeaddead);
1657 lp
->rfd_cur
->fd
.FDNext
= cpu_to_le32(FD_Next_EOL
);
1659 lp
->rfd_cur
->fd
.FDCtl
= cpu_to_le32(FD_CownsFD
);
1663 if (lp
->rfd_cur
> lp
->rfd_limit
)
1664 lp
->rfd_cur
= lp
->rfd_base
;
1666 if (lp
->rfd_cur
!= next_rfd
)
1667 printk("rfd_cur = %p, next_rfd %p\n",
1668 lp
->rfd_cur
, next_rfd
);
1672 /* re-enable BL/FDA Exhaust interrupts. */
1673 if (fd_free_count
) {
1674 struct tc35815_regs __iomem
*tr
=
1675 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1676 u32 en
, en_old
= tc_readl(&tr
->Int_En
);
1677 en
= en_old
| Int_FDAExEn
;
1681 tc_writel(en
, &tr
->Int_En
);
1690 tc35815_poll(struct net_device
*dev
, int *budget
)
1692 struct tc35815_local
*lp
= dev
->priv
;
1693 struct tc35815_regs __iomem
*tr
=
1694 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1695 int limit
= min(*budget
, dev
->quota
);
1696 int received
= 0, handled
;
1699 spin_lock(&lp
->lock
);
1700 status
= tc_readl(&tr
->Int_Src
);
1702 tc_writel(status
, &tr
->Int_Src
); /* write to clear */
1704 handled
= tc35815_do_interrupt(dev
, status
, limit
);
1706 received
+= handled
;
1711 status
= tc_readl(&tr
->Int_Src
);
1713 spin_unlock(&lp
->lock
);
1715 dev
->quota
-= received
;
1716 *budget
-= received
;
1720 netif_rx_complete(dev
);
1721 /* enable interrupts */
1722 tc_writel(tc_readl(&tr
->DMA_Ctl
) & ~DMA_IntMask
, &tr
->DMA_Ctl
);
1727 #ifdef NO_CHECK_CARRIER
1728 #define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_LateColl|Tx_TxPar|Tx_SQErr)
1730 #define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_NCarr|Tx_LateColl|Tx_TxPar|Tx_SQErr)
1734 tc35815_check_tx_stat(struct net_device
*dev
, int status
)
1736 struct tc35815_local
*lp
= dev
->priv
;
1737 const char *msg
= NULL
;
1739 /* count collisions */
1740 if (status
& Tx_ExColl
)
1741 lp
->stats
.collisions
+= 16;
1742 if (status
& Tx_TxColl_MASK
)
1743 lp
->stats
.collisions
+= status
& Tx_TxColl_MASK
;
1745 #ifndef NO_CHECK_CARRIER
1746 /* TX4939 does not have NCarr */
1747 if (lp
->boardtype
== TC35815_TX4939
)
1748 status
&= ~Tx_NCarr
;
1749 #ifdef WORKAROUND_LOSTCAR
1750 /* WORKAROUND: ignore LostCrS in full duplex operation */
1751 if ((lp
->timer_state
!= asleep
&& lp
->timer_state
!= lcheck
)
1753 status
&= ~Tx_NCarr
;
1757 if (!(status
& TX_STA_ERR
)) {
1759 lp
->stats
.tx_packets
++;
1763 lp
->stats
.tx_errors
++;
1764 if (status
& Tx_ExColl
) {
1765 lp
->stats
.tx_aborted_errors
++;
1766 msg
= "Excessive Collision.";
1768 if (status
& Tx_Under
) {
1769 lp
->stats
.tx_fifo_errors
++;
1770 msg
= "Tx FIFO Underrun.";
1771 if (lp
->lstats
.tx_underrun
< TX_THRESHOLD_KEEP_LIMIT
) {
1772 lp
->lstats
.tx_underrun
++;
1773 if (lp
->lstats
.tx_underrun
>= TX_THRESHOLD_KEEP_LIMIT
) {
1774 struct tc35815_regs __iomem
*tr
=
1775 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1776 tc_writel(TX_THRESHOLD_MAX
, &tr
->TxThrsh
);
1777 msg
= "Tx FIFO Underrun.Change Tx threshold to max.";
1781 if (status
& Tx_Defer
) {
1782 lp
->stats
.tx_fifo_errors
++;
1783 msg
= "Excessive Deferral.";
1785 #ifndef NO_CHECK_CARRIER
1786 if (status
& Tx_NCarr
) {
1787 lp
->stats
.tx_carrier_errors
++;
1788 msg
= "Lost Carrier Sense.";
1791 if (status
& Tx_LateColl
) {
1792 lp
->stats
.tx_aborted_errors
++;
1793 msg
= "Late Collision.";
1795 if (status
& Tx_TxPar
) {
1796 lp
->stats
.tx_fifo_errors
++;
1797 msg
= "Transmit Parity Error.";
1799 if (status
& Tx_SQErr
) {
1800 lp
->stats
.tx_heartbeat_errors
++;
1801 msg
= "Signal Quality Error.";
1803 if (msg
&& netif_msg_tx_err(lp
))
1804 printk(KERN_WARNING
"%s: %s (%#x)\n", dev
->name
, msg
, status
);
1807 /* This handles TX complete events posted by the device
1811 tc35815_txdone(struct net_device
*dev
)
1813 struct tc35815_local
*lp
= dev
->priv
;
1817 txfd
= &lp
->tfd_base
[lp
->tfd_end
];
1818 while (lp
->tfd_start
!= lp
->tfd_end
&&
1819 !((fdctl
= le32_to_cpu(txfd
->fd
.FDCtl
)) & FD_CownsFD
)) {
1820 int status
= le32_to_cpu(txfd
->fd
.FDStat
);
1821 struct sk_buff
*skb
;
1822 unsigned long fdnext
= le32_to_cpu(txfd
->fd
.FDNext
);
1823 u32 fdsystem
= le32_to_cpu(txfd
->fd
.FDSystem
);
1825 if (netif_msg_tx_done(lp
)) {
1826 printk("%s: complete TxFD.\n", dev
->name
);
1829 tc35815_check_tx_stat(dev
, status
);
1831 skb
= fdsystem
!= 0xffffffff ?
1832 lp
->tx_skbs
[fdsystem
].skb
: NULL
;
1834 if (lp
->tx_skbs
[lp
->tfd_end
].skb
!= skb
) {
1835 printk("%s: tx_skbs mismatch.\n", dev
->name
);
1839 BUG_ON(lp
->tx_skbs
[lp
->tfd_end
].skb
!= skb
);
1842 lp
->stats
.tx_bytes
+= skb
->len
;
1843 pci_unmap_single(lp
->pci_dev
, lp
->tx_skbs
[lp
->tfd_end
].skb_dma
, skb
->len
, PCI_DMA_TODEVICE
);
1844 lp
->tx_skbs
[lp
->tfd_end
].skb
= NULL
;
1845 lp
->tx_skbs
[lp
->tfd_end
].skb_dma
= 0;
1847 dev_kfree_skb_any(skb
);
1849 dev_kfree_skb_irq(skb
);
1852 txfd
->fd
.FDSystem
= cpu_to_le32(0xffffffff);
1854 lp
->tfd_end
= (lp
->tfd_end
+ 1) % TX_FD_NUM
;
1855 txfd
= &lp
->tfd_base
[lp
->tfd_end
];
1857 if ((fdnext
& ~FD_Next_EOL
) != fd_virt_to_bus(lp
, txfd
)) {
1858 printk("%s: TxFD FDNext invalid.\n", dev
->name
);
1862 if (fdnext
& FD_Next_EOL
) {
1863 /* DMA Transmitter has been stopping... */
1864 if (lp
->tfd_end
!= lp
->tfd_start
) {
1865 struct tc35815_regs __iomem
*tr
=
1866 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1867 int head
= (lp
->tfd_start
+ TX_FD_NUM
- 1) % TX_FD_NUM
;
1868 struct TxFD
* txhead
= &lp
->tfd_base
[head
];
1869 int qlen
= (lp
->tfd_start
+ TX_FD_NUM
1870 - lp
->tfd_end
) % TX_FD_NUM
;
1873 if (!(le32_to_cpu(txfd
->fd
.FDCtl
) & FD_CownsFD
)) {
1874 printk("%s: TxFD FDCtl invalid.\n", dev
->name
);
1878 /* log max queue length */
1879 if (lp
->lstats
.max_tx_qlen
< qlen
)
1880 lp
->lstats
.max_tx_qlen
= qlen
;
1883 /* start DMA Transmitter again */
1884 txhead
->fd
.FDNext
|= cpu_to_le32(FD_Next_EOL
);
1886 txhead
->fd
.FDCtl
|= cpu_to_le32(FD_FrmOpt_IntTx
);
1888 if (netif_msg_tx_queued(lp
)) {
1889 printk("%s: start TxFD on queue.\n",
1893 tc_writel(fd_virt_to_bus(lp
, txfd
), &tr
->TxFrmPtr
);
1899 /* If we had stopped the queue due to a "tx full"
1900 * condition, and space has now been made available,
1901 * wake up the queue.
1903 if (netif_queue_stopped(dev
) && ! tc35815_tx_full(dev
))
1904 netif_wake_queue(dev
);
1907 /* The inverse routine to tc35815_open(). */
1909 tc35815_close(struct net_device
*dev
)
1911 struct tc35815_local
*lp
= dev
->priv
;
1912 netif_stop_queue(dev
);
1914 /* Flush the Tx and disable Rx here. */
1916 del_timer(&lp
->timer
); /* Kill if running */
1917 tc35815_chip_reset(dev
);
1918 free_irq(dev
->irq
, dev
);
1920 tc35815_free_queues(dev
);
1927 * Get the current statistics.
1928 * This may be called with the card open or closed.
1930 static struct net_device_stats
*tc35815_get_stats(struct net_device
*dev
)
1932 struct tc35815_local
*lp
= dev
->priv
;
1933 struct tc35815_regs __iomem
*tr
=
1934 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1935 if (netif_running(dev
)) {
1936 /* Update the statistics from the device registers. */
1937 lp
->stats
.rx_missed_errors
= tc_readl(&tr
->Miss_Cnt
);
1943 static void tc35815_set_cam_entry(struct net_device
*dev
, int index
, unsigned char *addr
)
1945 struct tc35815_local
*lp
= dev
->priv
;
1946 struct tc35815_regs __iomem
*tr
=
1947 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1948 int cam_index
= index
* 6;
1951 saved_addr
= tc_readl(&tr
->CAM_Adr
);
1953 if (netif_msg_hw(lp
)) {
1955 printk(KERN_DEBUG
"%s: CAM %d:", dev
->name
, index
);
1956 for (i
= 0; i
< 6; i
++)
1957 printk(" %02x", addr
[i
]);
1961 /* read modify write */
1962 tc_writel(cam_index
- 2, &tr
->CAM_Adr
);
1963 cam_data
= tc_readl(&tr
->CAM_Data
) & 0xffff0000;
1964 cam_data
|= addr
[0] << 8 | addr
[1];
1965 tc_writel(cam_data
, &tr
->CAM_Data
);
1966 /* write whole word */
1967 tc_writel(cam_index
+ 2, &tr
->CAM_Adr
);
1968 cam_data
= (addr
[2] << 24) | (addr
[3] << 16) | (addr
[4] << 8) | addr
[5];
1969 tc_writel(cam_data
, &tr
->CAM_Data
);
1971 /* write whole word */
1972 tc_writel(cam_index
, &tr
->CAM_Adr
);
1973 cam_data
= (addr
[0] << 24) | (addr
[1] << 16) | (addr
[2] << 8) | addr
[3];
1974 tc_writel(cam_data
, &tr
->CAM_Data
);
1975 /* read modify write */
1976 tc_writel(cam_index
+ 4, &tr
->CAM_Adr
);
1977 cam_data
= tc_readl(&tr
->CAM_Data
) & 0x0000ffff;
1978 cam_data
|= addr
[4] << 24 | (addr
[5] << 16);
1979 tc_writel(cam_data
, &tr
->CAM_Data
);
1982 tc_writel(saved_addr
, &tr
->CAM_Adr
);
1987 * Set or clear the multicast filter for this adaptor.
1988 * num_addrs == -1 Promiscuous mode, receive all packets
1989 * num_addrs == 0 Normal mode, clear multicast list
1990 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1991 * and do best-effort filtering.
1994 tc35815_set_multicast_list(struct net_device
*dev
)
1996 struct tc35815_regs __iomem
*tr
=
1997 (struct tc35815_regs __iomem
*)dev
->base_addr
;
1999 if (dev
->flags
&IFF_PROMISC
)
2001 #ifdef WORKAROUND_100HALF_PROMISC
2002 /* With some (all?) 100MHalf HUB, controller will hang
2003 * if we enabled promiscuous mode before linkup... */
2004 struct tc35815_local
*lp
= dev
->priv
;
2005 int pid
= lp
->phy_addr
;
2006 if (!(tc_mdio_read(dev
, pid
, MII_BMSR
) & BMSR_LSTATUS
))
2009 /* Enable promiscuous mode */
2010 tc_writel(CAM_CompEn
| CAM_BroadAcc
| CAM_GroupAcc
| CAM_StationAcc
, &tr
->CAM_Ctl
);
2012 else if((dev
->flags
&IFF_ALLMULTI
) || dev
->mc_count
> CAM_ENTRY_MAX
- 3)
2014 /* CAM 0, 1, 20 are reserved. */
2015 /* Disable promiscuous mode, use normal mode. */
2016 tc_writel(CAM_CompEn
| CAM_BroadAcc
| CAM_GroupAcc
, &tr
->CAM_Ctl
);
2018 else if(dev
->mc_count
)
2020 struct dev_mc_list
* cur_addr
= dev
->mc_list
;
2022 int ena_bits
= CAM_Ena_Bit(CAM_ENTRY_SOURCE
);
2024 tc_writel(0, &tr
->CAM_Ctl
);
2025 /* Walk the address list, and load the filter */
2026 for (i
= 0; i
< dev
->mc_count
; i
++, cur_addr
= cur_addr
->next
) {
2029 /* entry 0,1 is reserved. */
2030 tc35815_set_cam_entry(dev
, i
+ 2, cur_addr
->dmi_addr
);
2031 ena_bits
|= CAM_Ena_Bit(i
+ 2);
2033 tc_writel(ena_bits
, &tr
->CAM_Ena
);
2034 tc_writel(CAM_CompEn
| CAM_BroadAcc
, &tr
->CAM_Ctl
);
2037 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE
), &tr
->CAM_Ena
);
2038 tc_writel(CAM_CompEn
| CAM_BroadAcc
, &tr
->CAM_Ctl
);
2042 static void tc35815_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
2044 struct tc35815_local
*lp
= dev
->priv
;
2045 strcpy(info
->driver
, MODNAME
);
2046 strcpy(info
->version
, DRV_VERSION
);
2047 strcpy(info
->bus_info
, pci_name(lp
->pci_dev
));
2050 static int tc35815_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2052 struct tc35815_local
*lp
= dev
->priv
;
2053 spin_lock_irq(&lp
->lock
);
2054 mii_ethtool_gset(&lp
->mii
, cmd
);
2055 spin_unlock_irq(&lp
->lock
);
2059 static int tc35815_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
2061 struct tc35815_local
*lp
= dev
->priv
;
2063 #if 1 /* use our negotiation method... */
2064 /* Verify the settings we care about. */
2065 if (cmd
->autoneg
!= AUTONEG_ENABLE
&&
2066 cmd
->autoneg
!= AUTONEG_DISABLE
)
2068 if (cmd
->autoneg
== AUTONEG_DISABLE
&&
2069 ((cmd
->speed
!= SPEED_100
&&
2070 cmd
->speed
!= SPEED_10
) ||
2071 (cmd
->duplex
!= DUPLEX_HALF
&&
2072 cmd
->duplex
!= DUPLEX_FULL
)))
2075 /* Ok, do it to it. */
2076 spin_lock_irq(&lp
->lock
);
2077 del_timer(&lp
->timer
);
2078 tc35815_start_auto_negotiation(dev
, cmd
);
2079 spin_unlock_irq(&lp
->lock
);
2082 spin_lock_irq(&lp
->lock
);
2083 rc
= mii_ethtool_sset(&lp
->mii
, cmd
);
2084 spin_unlock_irq(&lp
->lock
);
2089 static int tc35815_nway_reset(struct net_device
*dev
)
2091 struct tc35815_local
*lp
= dev
->priv
;
2093 spin_lock_irq(&lp
->lock
);
2094 rc
= mii_nway_restart(&lp
->mii
);
2095 spin_unlock_irq(&lp
->lock
);
2099 static u32
tc35815_get_link(struct net_device
*dev
)
2101 struct tc35815_local
*lp
= dev
->priv
;
2103 spin_lock_irq(&lp
->lock
);
2104 rc
= mii_link_ok(&lp
->mii
);
2105 spin_unlock_irq(&lp
->lock
);
2109 static u32
tc35815_get_msglevel(struct net_device
*dev
)
2111 struct tc35815_local
*lp
= dev
->priv
;
2112 return lp
->msg_enable
;
2115 static void tc35815_set_msglevel(struct net_device
*dev
, u32 datum
)
2117 struct tc35815_local
*lp
= dev
->priv
;
2118 lp
->msg_enable
= datum
;
2121 static int tc35815_get_stats_count(struct net_device
*dev
)
2123 struct tc35815_local
*lp
= dev
->priv
;
2124 return sizeof(lp
->lstats
) / sizeof(int);
2127 static void tc35815_get_ethtool_stats(struct net_device
*dev
, struct ethtool_stats
*stats
, u64
*data
)
2129 struct tc35815_local
*lp
= dev
->priv
;
2130 data
[0] = lp
->lstats
.max_tx_qlen
;
2131 data
[1] = lp
->lstats
.tx_ints
;
2132 data
[2] = lp
->lstats
.rx_ints
;
2133 data
[3] = lp
->lstats
.tx_underrun
;
2137 const char str
[ETH_GSTRING_LEN
];
2138 } ethtool_stats_keys
[] = {
2145 static void tc35815_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
2147 memcpy(data
, ethtool_stats_keys
, sizeof(ethtool_stats_keys
));
2150 static const struct ethtool_ops tc35815_ethtool_ops
= {
2151 .get_drvinfo
= tc35815_get_drvinfo
,
2152 .get_settings
= tc35815_get_settings
,
2153 .set_settings
= tc35815_set_settings
,
2154 .nway_reset
= tc35815_nway_reset
,
2155 .get_link
= tc35815_get_link
,
2156 .get_msglevel
= tc35815_get_msglevel
,
2157 .set_msglevel
= tc35815_set_msglevel
,
2158 .get_strings
= tc35815_get_strings
,
2159 .get_stats_count
= tc35815_get_stats_count
,
2160 .get_ethtool_stats
= tc35815_get_ethtool_stats
,
2161 .get_perm_addr
= ethtool_op_get_perm_addr
,
2164 static int tc35815_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2166 struct tc35815_local
*lp
= dev
->priv
;
2169 if (!netif_running(dev
))
2172 spin_lock_irq(&lp
->lock
);
2173 rc
= generic_mii_ioctl(&lp
->mii
, if_mii(rq
), cmd
, NULL
);
2174 spin_unlock_irq(&lp
->lock
);
2179 static int tc_mdio_read(struct net_device
*dev
, int phy_id
, int location
)
2181 struct tc35815_regs __iomem
*tr
=
2182 (struct tc35815_regs __iomem
*)dev
->base_addr
;
2184 tc_writel(MD_CA_Busy
| (phy_id
<< 5) | location
, &tr
->MD_CA
);
2185 while (tc_readl(&tr
->MD_CA
) & MD_CA_Busy
)
2187 data
= tc_readl(&tr
->MD_Data
);
2188 return data
& 0xffff;
2191 static void tc_mdio_write(struct net_device
*dev
, int phy_id
, int location
,
2194 struct tc35815_regs __iomem
*tr
=
2195 (struct tc35815_regs __iomem
*)dev
->base_addr
;
2196 tc_writel(val
, &tr
->MD_Data
);
2197 tc_writel(MD_CA_Busy
| MD_CA_Wr
| (phy_id
<< 5) | location
, &tr
->MD_CA
);
2198 while (tc_readl(&tr
->MD_CA
) & MD_CA_Busy
)
2202 /* Auto negotiation. The scheme is very simple. We have a timer routine
2203 * that keeps watching the auto negotiation process as it progresses.
2204 * The DP83840 is first told to start doing it's thing, we set up the time
2205 * and place the timer state machine in it's initial state.
2207 * Here the timer peeks at the DP83840 status registers at each click to see
2208 * if the auto negotiation has completed, we assume here that the DP83840 PHY
2209 * will time out at some point and just tell us what (didn't) happen. For
2210 * complete coverage we only allow so many of the ticks at this level to run,
2211 * when this has expired we print a warning message and try another strategy.
2212 * This "other" strategy is to force the interface into various speed/duplex
2213 * configurations and we stop when we see a link-up condition before the
2214 * maximum number of "peek" ticks have occurred.
2216 * Once a valid link status has been detected we configure the BigMAC and
2217 * the rest of the Happy Meal to speak the most efficient protocol we could
2218 * get a clean link for. The priority for link configurations, highest first
2220 * 100 Base-T Full Duplex
2221 * 100 Base-T Half Duplex
2222 * 10 Base-T Full Duplex
2223 * 10 Base-T Half Duplex
2225 * We start a new timer now, after a successful auto negotiation status has
2226 * been detected. This timer just waits for the link-up bit to get set in
2227 * the BMCR of the DP83840. When this occurs we print a kernel log message
2228 * describing the link type in use and the fact that it is up.
2230 * If a fatal error of some sort is signalled and detected in the interrupt
2231 * service routine, and the chip is reset, or the link is ifconfig'd down
2232 * and then back up, this entire process repeats itself all over again.
2234 /* Note: Above comments are come from sunhme driver. */
2236 static int tc35815_try_next_permutation(struct net_device
*dev
)
2238 struct tc35815_local
*lp
= dev
->priv
;
2239 int pid
= lp
->phy_addr
;
2240 unsigned short bmcr
;
2242 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2244 /* Downgrade from full to half duplex. Only possible via ethtool. */
2245 if (bmcr
& BMCR_FULLDPLX
) {
2246 bmcr
&= ~BMCR_FULLDPLX
;
2247 printk(KERN_DEBUG
"%s: try next permutation (BMCR %x)\n", dev
->name
, bmcr
);
2248 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2252 /* Downgrade from 100 to 10. */
2253 if (bmcr
& BMCR_SPEED100
) {
2254 bmcr
&= ~BMCR_SPEED100
;
2255 printk(KERN_DEBUG
"%s: try next permutation (BMCR %x)\n", dev
->name
, bmcr
);
2256 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2260 /* We've tried everything. */
2265 tc35815_display_link_mode(struct net_device
*dev
)
2267 struct tc35815_local
*lp
= dev
->priv
;
2268 int pid
= lp
->phy_addr
;
2269 unsigned short lpa
, bmcr
;
2270 char *speed
= "", *duplex
= "";
2272 lpa
= tc_mdio_read(dev
, pid
, MII_LPA
);
2273 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2274 if (options
.speed
? (bmcr
& BMCR_SPEED100
) : (lpa
& (LPA_100HALF
| LPA_100FULL
)))
2278 if (options
.duplex
? (bmcr
& BMCR_FULLDPLX
) : (lpa
& (LPA_100FULL
| LPA_10FULL
)))
2279 duplex
= "Full Duplex";
2281 duplex
= "Half Duplex";
2283 if (netif_msg_link(lp
))
2284 printk(KERN_INFO
"%s: Link is up at %s, %s.\n",
2285 dev
->name
, speed
, duplex
);
2286 printk(KERN_DEBUG
"%s: MII BMCR %04x BMSR %04x LPA %04x\n",
2288 bmcr
, tc_mdio_read(dev
, pid
, MII_BMSR
), lpa
);
2291 static void tc35815_display_forced_link_mode(struct net_device
*dev
)
2293 struct tc35815_local
*lp
= dev
->priv
;
2294 int pid
= lp
->phy_addr
;
2295 unsigned short bmcr
;
2296 char *speed
= "", *duplex
= "";
2298 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2299 if (bmcr
& BMCR_SPEED100
)
2303 if (bmcr
& BMCR_FULLDPLX
)
2304 duplex
= "Full Duplex.\n";
2306 duplex
= "Half Duplex.\n";
2308 if (netif_msg_link(lp
))
2309 printk(KERN_INFO
"%s: Link has been forced up at %s, %s",
2310 dev
->name
, speed
, duplex
);
2313 static void tc35815_set_link_modes(struct net_device
*dev
)
2315 struct tc35815_local
*lp
= dev
->priv
;
2316 struct tc35815_regs __iomem
*tr
=
2317 (struct tc35815_regs __iomem
*)dev
->base_addr
;
2318 int pid
= lp
->phy_addr
;
2319 unsigned short bmcr
, lpa
;
2322 if (lp
->timer_state
== arbwait
) {
2323 lpa
= tc_mdio_read(dev
, pid
, MII_LPA
);
2324 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2325 printk(KERN_DEBUG
"%s: MII BMCR %04x BMSR %04x LPA %04x\n",
2327 bmcr
, tc_mdio_read(dev
, pid
, MII_BMSR
), lpa
);
2328 if (!(lpa
& (LPA_10HALF
| LPA_10FULL
|
2329 LPA_100HALF
| LPA_100FULL
))) {
2330 /* fall back to 10HALF */
2331 printk(KERN_INFO
"%s: bad ability %04x - falling back to 10HD.\n",
2335 if (options
.duplex
? (bmcr
& BMCR_FULLDPLX
) : (lpa
& (LPA_100FULL
| LPA_10FULL
)))
2339 if (options
.speed
? (bmcr
& BMCR_SPEED100
) : (lpa
& (LPA_100HALF
| LPA_100FULL
)))
2344 /* Forcing a link mode. */
2345 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2346 if (bmcr
& BMCR_FULLDPLX
)
2350 if (bmcr
& BMCR_SPEED100
)
2356 tc_writel(tc_readl(&tr
->MAC_Ctl
) | MAC_HaltReq
, &tr
->MAC_Ctl
);
2357 if (lp
->fullduplex
) {
2358 tc_writel(tc_readl(&tr
->MAC_Ctl
) | MAC_FullDup
, &tr
->MAC_Ctl
);
2360 tc_writel(tc_readl(&tr
->MAC_Ctl
) & ~MAC_FullDup
, &tr
->MAC_Ctl
);
2362 tc_writel(tc_readl(&tr
->MAC_Ctl
) & ~MAC_HaltReq
, &tr
->MAC_Ctl
);
2364 /* TX4939 PCFG.SPEEDn bit will be changed on NETDEV_CHANGE event. */
2366 #ifndef NO_CHECK_CARRIER
2367 /* TX4939 does not have EnLCarr */
2368 if (lp
->boardtype
!= TC35815_TX4939
) {
2369 #ifdef WORKAROUND_LOSTCAR
2370 /* WORKAROUND: enable LostCrS only if half duplex operation */
2371 if (!lp
->fullduplex
&& lp
->boardtype
!= TC35815_TX4939
)
2372 tc_writel(tc_readl(&tr
->Tx_Ctl
) | Tx_EnLCarr
, &tr
->Tx_Ctl
);
2376 lp
->mii
.full_duplex
= lp
->fullduplex
;
2379 static void tc35815_timer(unsigned long data
)
2381 struct net_device
*dev
= (struct net_device
*)data
;
2382 struct tc35815_local
*lp
= dev
->priv
;
2383 int pid
= lp
->phy_addr
;
2384 unsigned short bmsr
, bmcr
, lpa
;
2385 int restart_timer
= 0;
2387 spin_lock_irq(&lp
->lock
);
2390 switch (lp
->timer_state
) {
2393 * Only allow for 5 ticks, thats 10 seconds and much too
2394 * long to wait for arbitration to complete.
2396 /* TC35815 need more times... */
2397 if (lp
->timer_ticks
>= 10) {
2398 /* Enter force mode. */
2399 if (!options
.doforce
) {
2400 printk(KERN_NOTICE
"%s: Auto-Negotiation unsuccessful,"
2401 " cable probblem?\n", dev
->name
);
2402 /* Try to restart the adaptor. */
2403 tc35815_restart(dev
);
2406 printk(KERN_NOTICE
"%s: Auto-Negotiation unsuccessful,"
2407 " trying force link mode\n", dev
->name
);
2408 printk(KERN_DEBUG
"%s: BMCR %x BMSR %x\n", dev
->name
,
2409 tc_mdio_read(dev
, pid
, MII_BMCR
),
2410 tc_mdio_read(dev
, pid
, MII_BMSR
));
2411 bmcr
= BMCR_SPEED100
;
2412 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2415 * OK, seems we need do disable the transceiver
2416 * for the first tick to make sure we get an
2417 * accurate link state at the second tick.
2420 lp
->timer_state
= ltrywait
;
2421 lp
->timer_ticks
= 0;
2424 /* Anything interesting happen? */
2425 bmsr
= tc_mdio_read(dev
, pid
, MII_BMSR
);
2426 if (bmsr
& BMSR_ANEGCOMPLETE
) {
2427 /* Just what we've been waiting for... */
2428 tc35815_set_link_modes(dev
);
2431 * Success, at least so far, advance our state
2434 lp
->timer_state
= lupwait
;
2444 * Auto negotiation was successful and we are awaiting a
2445 * link up status. I have decided to let this timer run
2446 * forever until some sort of error is signalled, reporting
2447 * a message to the user at 10 second intervals.
2449 bmsr
= tc_mdio_read(dev
, pid
, MII_BMSR
);
2450 if (bmsr
& BMSR_LSTATUS
) {
2452 * Wheee, it's up, display the link mode in use and put
2453 * the timer to sleep.
2455 tc35815_display_link_mode(dev
);
2456 netif_carrier_on(dev
);
2457 #ifdef WORKAROUND_100HALF_PROMISC
2458 /* delayed promiscuous enabling */
2459 if (dev
->flags
& IFF_PROMISC
)
2460 tc35815_set_multicast_list(dev
);
2463 lp
->saved_lpa
= tc_mdio_read(dev
, pid
, MII_LPA
);
2464 lp
->timer_state
= lcheck
;
2467 lp
->timer_state
= asleep
;
2471 if (lp
->timer_ticks
>= 10) {
2472 printk(KERN_NOTICE
"%s: Auto negotiation successful, link still "
2473 "not completely up.\n", dev
->name
);
2474 lp
->timer_ticks
= 0;
2484 * Making the timeout here too long can make it take
2485 * annoyingly long to attempt all of the link mode
2486 * permutations, but then again this is essentially
2487 * error recovery code for the most part.
2489 bmsr
= tc_mdio_read(dev
, pid
, MII_BMSR
);
2490 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2491 if (lp
->timer_ticks
== 1) {
2493 * Re-enable transceiver, we'll re-enable the
2494 * transceiver next tick, then check link state
2495 * on the following tick.
2500 if (lp
->timer_ticks
== 2) {
2504 if (bmsr
& BMSR_LSTATUS
) {
2505 /* Force mode selection success. */
2506 tc35815_display_forced_link_mode(dev
);
2507 netif_carrier_on(dev
);
2508 tc35815_set_link_modes(dev
);
2509 #ifdef WORKAROUND_100HALF_PROMISC
2510 /* delayed promiscuous enabling */
2511 if (dev
->flags
& IFF_PROMISC
)
2512 tc35815_set_multicast_list(dev
);
2515 lp
->saved_lpa
= tc_mdio_read(dev
, pid
, MII_LPA
);
2516 lp
->timer_state
= lcheck
;
2519 lp
->timer_state
= asleep
;
2523 if (lp
->timer_ticks
>= 4) { /* 6 seconds or so... */
2526 ret
= tc35815_try_next_permutation(dev
);
2529 * Aieee, tried them all, reset the
2530 * chip and try all over again.
2532 printk(KERN_NOTICE
"%s: Link down, "
2536 /* Try to restart the adaptor. */
2537 tc35815_restart(dev
);
2540 lp
->timer_ticks
= 0;
2549 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2550 lpa
= tc_mdio_read(dev
, pid
, MII_LPA
);
2551 if (bmcr
& (BMCR_PDOWN
| BMCR_ISOLATE
| BMCR_RESET
)) {
2552 printk(KERN_ERR
"%s: PHY down? (BMCR %x)\n", dev
->name
,
2554 } else if ((lp
->saved_lpa
^ lpa
) &
2555 (LPA_100FULL
|LPA_100HALF
|LPA_10FULL
|LPA_10HALF
)) {
2556 printk(KERN_NOTICE
"%s: link status changed"
2557 " (BMCR %x LPA %x->%x)\n", dev
->name
,
2558 bmcr
, lp
->saved_lpa
, lpa
);
2564 /* Try to restart the adaptor. */
2565 tc35815_restart(dev
);
2570 /* Can't happens.... */
2571 printk(KERN_ERR
"%s: Aieee, link timer is asleep but we got "
2572 "one anyways!\n", dev
->name
);
2574 lp
->timer_ticks
= 0;
2575 lp
->timer_state
= asleep
; /* foo on you */
2579 if (restart_timer
) {
2580 lp
->timer
.expires
= jiffies
+ msecs_to_jiffies(1200);
2581 add_timer(&lp
->timer
);
2584 spin_unlock_irq(&lp
->lock
);
2587 static void tc35815_start_auto_negotiation(struct net_device
*dev
,
2588 struct ethtool_cmd
*ep
)
2590 struct tc35815_local
*lp
= dev
->priv
;
2591 int pid
= lp
->phy_addr
;
2592 unsigned short bmsr
, bmcr
, advertize
;
2595 netif_carrier_off(dev
);
2596 bmsr
= tc_mdio_read(dev
, pid
, MII_BMSR
);
2597 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2598 advertize
= tc_mdio_read(dev
, pid
, MII_ADVERTISE
);
2600 if (ep
== NULL
|| ep
->autoneg
== AUTONEG_ENABLE
) {
2601 if (options
.speed
|| options
.duplex
) {
2602 /* Advertise only specified configuration. */
2603 advertize
&= ~(ADVERTISE_10HALF
|
2607 if (options
.speed
!= 10) {
2608 if (options
.duplex
!= 1)
2609 advertize
|= ADVERTISE_100FULL
;
2610 if (options
.duplex
!= 2)
2611 advertize
|= ADVERTISE_100HALF
;
2613 if (options
.speed
!= 100) {
2614 if (options
.duplex
!= 1)
2615 advertize
|= ADVERTISE_10FULL
;
2616 if (options
.duplex
!= 2)
2617 advertize
|= ADVERTISE_10HALF
;
2619 if (options
.speed
== 100)
2620 bmcr
|= BMCR_SPEED100
;
2621 else if (options
.speed
== 10)
2622 bmcr
&= ~BMCR_SPEED100
;
2623 if (options
.duplex
== 2)
2624 bmcr
|= BMCR_FULLDPLX
;
2625 else if (options
.duplex
== 1)
2626 bmcr
&= ~BMCR_FULLDPLX
;
2628 /* Advertise everything we can support. */
2629 if (bmsr
& BMSR_10HALF
)
2630 advertize
|= ADVERTISE_10HALF
;
2632 advertize
&= ~ADVERTISE_10HALF
;
2633 if (bmsr
& BMSR_10FULL
)
2634 advertize
|= ADVERTISE_10FULL
;
2636 advertize
&= ~ADVERTISE_10FULL
;
2637 if (bmsr
& BMSR_100HALF
)
2638 advertize
|= ADVERTISE_100HALF
;
2640 advertize
&= ~ADVERTISE_100HALF
;
2641 if (bmsr
& BMSR_100FULL
)
2642 advertize
|= ADVERTISE_100FULL
;
2644 advertize
&= ~ADVERTISE_100FULL
;
2647 tc_mdio_write(dev
, pid
, MII_ADVERTISE
, advertize
);
2649 /* Enable Auto-Negotiation, this is usually on already... */
2650 bmcr
|= BMCR_ANENABLE
;
2651 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2653 /* Restart it to make sure it is going. */
2654 bmcr
|= BMCR_ANRESTART
;
2655 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2656 printk(KERN_DEBUG
"%s: ADVERTISE %x BMCR %x\n", dev
->name
, advertize
, bmcr
);
2658 /* BMCR_ANRESTART self clears when the process has begun. */
2659 timeout
= 64; /* More than enough. */
2661 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2662 if (!(bmcr
& BMCR_ANRESTART
))
2663 break; /* got it. */
2667 printk(KERN_ERR
"%s: TC35815 would not start auto "
2668 "negotiation BMCR=0x%04x\n",
2670 printk(KERN_NOTICE
"%s: Performing force link "
2671 "detection.\n", dev
->name
);
2674 printk(KERN_DEBUG
"%s: auto negotiation started.\n", dev
->name
);
2675 lp
->timer_state
= arbwait
;
2679 /* Force the link up, trying first a particular mode.
2680 * Either we are here at the request of ethtool or
2681 * because the Happy Meal would not start to autoneg.
2684 /* Disable auto-negotiation in BMCR, enable the duplex and
2685 * speed setting, init the timer state machine, and fire it off.
2687 if (ep
== NULL
|| ep
->autoneg
== AUTONEG_ENABLE
) {
2688 bmcr
= BMCR_SPEED100
;
2690 if (ep
->speed
== SPEED_100
)
2691 bmcr
= BMCR_SPEED100
;
2694 if (ep
->duplex
== DUPLEX_FULL
)
2695 bmcr
|= BMCR_FULLDPLX
;
2697 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
);
2699 /* OK, seems we need do disable the transceiver for the first
2700 * tick to make sure we get an accurate link state at the
2703 lp
->timer_state
= ltrywait
;
2706 del_timer(&lp
->timer
);
2707 lp
->timer_ticks
= 0;
2708 lp
->timer
.expires
= jiffies
+ msecs_to_jiffies(1200);
2709 add_timer(&lp
->timer
);
2712 static void tc35815_find_phy(struct net_device
*dev
)
2714 struct tc35815_local
*lp
= dev
->priv
;
2715 int pid
= lp
->phy_addr
;
2719 for (pid
= 31; pid
>= 0; pid
--) {
2720 id0
= tc_mdio_read(dev
, pid
, MII_BMSR
);
2721 if (id0
!= 0xffff && id0
!= 0x0000 &&
2722 (id0
& BMSR_RESV
) != (0xffff & BMSR_RESV
) /* paranoia? */
2729 printk(KERN_ERR
"%s: No MII Phy found.\n",
2731 lp
->phy_addr
= pid
= 0;
2734 lp
->mii_id
[0] = tc_mdio_read(dev
, pid
, MII_PHYSID1
);
2735 lp
->mii_id
[1] = tc_mdio_read(dev
, pid
, MII_PHYSID2
);
2736 if (netif_msg_hw(lp
))
2737 printk(KERN_INFO
"%s: PHY(%02x) ID %04x %04x\n", dev
->name
,
2738 pid
, lp
->mii_id
[0], lp
->mii_id
[1]);
2741 static void tc35815_phy_chip_init(struct net_device
*dev
)
2743 struct tc35815_local
*lp
= dev
->priv
;
2744 int pid
= lp
->phy_addr
;
2745 unsigned short bmcr
;
2746 struct ethtool_cmd ecmd
, *ep
;
2748 /* dis-isolate if needed. */
2749 bmcr
= tc_mdio_read(dev
, pid
, MII_BMCR
);
2750 if (bmcr
& BMCR_ISOLATE
) {
2752 printk(KERN_DEBUG
"%s: unisolating...", dev
->name
);
2753 tc_mdio_write(dev
, pid
, MII_BMCR
, bmcr
& ~BMCR_ISOLATE
);
2755 if (!(tc_mdio_read(dev
, pid
, MII_BMCR
) & BMCR_ISOLATE
))
2759 printk(" %s.\n", count
? "done" : "failed");
2762 if (options
.speed
&& options
.duplex
) {
2763 ecmd
.autoneg
= AUTONEG_DISABLE
;
2764 ecmd
.speed
= options
.speed
== 10 ? SPEED_10
: SPEED_100
;
2765 ecmd
.duplex
= options
.duplex
== 1 ? DUPLEX_HALF
: DUPLEX_FULL
;
2770 tc35815_start_auto_negotiation(dev
, ep
);
2773 static void tc35815_chip_reset(struct net_device
*dev
)
2775 struct tc35815_regs __iomem
*tr
=
2776 (struct tc35815_regs __iomem
*)dev
->base_addr
;
2778 /* reset the controller */
2779 tc_writel(MAC_Reset
, &tr
->MAC_Ctl
);
2780 udelay(4); /* 3200ns */
2782 while (tc_readl(&tr
->MAC_Ctl
) & MAC_Reset
) {
2784 printk(KERN_ERR
"%s: MAC reset failed.\n", dev
->name
);
2789 tc_writel(0, &tr
->MAC_Ctl
);
2791 /* initialize registers to default value */
2792 tc_writel(0, &tr
->DMA_Ctl
);
2793 tc_writel(0, &tr
->TxThrsh
);
2794 tc_writel(0, &tr
->TxPollCtr
);
2795 tc_writel(0, &tr
->RxFragSize
);
2796 tc_writel(0, &tr
->Int_En
);
2797 tc_writel(0, &tr
->FDA_Bas
);
2798 tc_writel(0, &tr
->FDA_Lim
);
2799 tc_writel(0xffffffff, &tr
->Int_Src
); /* Write 1 to clear */
2800 tc_writel(0, &tr
->CAM_Ctl
);
2801 tc_writel(0, &tr
->Tx_Ctl
);
2802 tc_writel(0, &tr
->Rx_Ctl
);
2803 tc_writel(0, &tr
->CAM_Ena
);
2804 (void)tc_readl(&tr
->Miss_Cnt
); /* Read to clear */
2806 /* initialize internal SRAM */
2807 tc_writel(DMA_TestMode
, &tr
->DMA_Ctl
);
2808 for (i
= 0; i
< 0x1000; i
+= 4) {
2809 tc_writel(i
, &tr
->CAM_Adr
);
2810 tc_writel(0, &tr
->CAM_Data
);
2812 tc_writel(0, &tr
->DMA_Ctl
);
2815 static void tc35815_chip_init(struct net_device
*dev
)
2817 struct tc35815_local
*lp
= dev
->priv
;
2818 struct tc35815_regs __iomem
*tr
=
2819 (struct tc35815_regs __iomem
*)dev
->base_addr
;
2820 unsigned long txctl
= TX_CTL_CMD
;
2822 tc35815_phy_chip_init(dev
);
2824 /* load station address to CAM */
2825 tc35815_set_cam_entry(dev
, CAM_ENTRY_SOURCE
, dev
->dev_addr
);
2827 /* Enable CAM (broadcast and unicast) */
2828 tc_writel(CAM_Ena_Bit(CAM_ENTRY_SOURCE
), &tr
->CAM_Ena
);
2829 tc_writel(CAM_CompEn
| CAM_BroadAcc
, &tr
->CAM_Ctl
);
2831 /* Use DMA_RxAlign_2 to make IP header 4-byte aligned. */
2832 if (HAVE_DMA_RXALIGN(lp
))
2833 tc_writel(DMA_BURST_SIZE
| DMA_RxAlign_2
, &tr
->DMA_Ctl
);
2835 tc_writel(DMA_BURST_SIZE
, &tr
->DMA_Ctl
);
2836 #ifdef TC35815_USE_PACKEDBUFFER
2837 tc_writel(RxFrag_EnPack
| ETH_ZLEN
, &tr
->RxFragSize
); /* Packing */
2839 tc_writel(ETH_ZLEN
, &tr
->RxFragSize
);
2841 tc_writel(0, &tr
->TxPollCtr
); /* Batch mode */
2842 tc_writel(TX_THRESHOLD
, &tr
->TxThrsh
);
2843 tc_writel(INT_EN_CMD
, &tr
->Int_En
);
2846 tc_writel(fd_virt_to_bus(lp
, lp
->rfd_base
), &tr
->FDA_Bas
);
2847 tc_writel((unsigned long)lp
->rfd_limit
- (unsigned long)lp
->rfd_base
,
2850 * Activation method:
2851 * First, enable the MAC Transmitter and the DMA Receive circuits.
2852 * Then enable the DMA Transmitter and the MAC Receive circuits.
2854 tc_writel(fd_virt_to_bus(lp
, lp
->fbl_ptr
), &tr
->BLFrmPtr
); /* start DMA receiver */
2855 tc_writel(RX_CTL_CMD
, &tr
->Rx_Ctl
); /* start MAC receiver */
2857 /* start MAC transmitter */
2858 #ifndef NO_CHECK_CARRIER
2859 /* TX4939 does not have EnLCarr */
2860 if (lp
->boardtype
== TC35815_TX4939
)
2861 txctl
&= ~Tx_EnLCarr
;
2862 #ifdef WORKAROUND_LOSTCAR
2863 /* WORKAROUND: ignore LostCrS in full duplex operation */
2864 if ((lp
->timer_state
!= asleep
&& lp
->timer_state
!= lcheck
) ||
2866 txctl
&= ~Tx_EnLCarr
;
2868 #endif /* !NO_CHECK_CARRIER */
2870 txctl
&= ~Tx_EnComp
; /* disable global tx completion int. */
2872 tc_writel(txctl
, &tr
->Tx_Ctl
);
2876 static int tc35815_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2878 struct net_device
*dev
= pci_get_drvdata(pdev
);
2879 struct tc35815_local
*lp
= dev
->priv
;
2880 unsigned long flags
;
2882 pci_save_state(pdev
);
2883 if (!netif_running(dev
))
2885 netif_device_detach(dev
);
2886 spin_lock_irqsave(&lp
->lock
, flags
);
2887 del_timer(&lp
->timer
); /* Kill if running */
2888 tc35815_chip_reset(dev
);
2889 spin_unlock_irqrestore(&lp
->lock
, flags
);
2890 pci_set_power_state(pdev
, PCI_D3hot
);
2894 static int tc35815_resume(struct pci_dev
*pdev
)
2896 struct net_device
*dev
= pci_get_drvdata(pdev
);
2897 struct tc35815_local
*lp
= dev
->priv
;
2898 unsigned long flags
;
2900 pci_restore_state(pdev
);
2901 if (!netif_running(dev
))
2903 pci_set_power_state(pdev
, PCI_D0
);
2904 spin_lock_irqsave(&lp
->lock
, flags
);
2905 tc35815_restart(dev
);
2906 spin_unlock_irqrestore(&lp
->lock
, flags
);
2907 netif_device_attach(dev
);
2910 #endif /* CONFIG_PM */
2912 static struct pci_driver tc35815_pci_driver
= {
2914 .id_table
= tc35815_pci_tbl
,
2915 .probe
= tc35815_init_one
,
2916 .remove
= __devexit_p(tc35815_remove_one
),
2918 .suspend
= tc35815_suspend
,
2919 .resume
= tc35815_resume
,
2923 module_param_named(speed
, options
.speed
, int, 0);
2924 MODULE_PARM_DESC(speed
, "0:auto, 10:10Mbps, 100:100Mbps");
2925 module_param_named(duplex
, options
.duplex
, int, 0);
2926 MODULE_PARM_DESC(duplex
, "0:auto, 1:half, 2:full");
2927 module_param_named(doforce
, options
.doforce
, int, 0);
2928 MODULE_PARM_DESC(doforce
, "try force link mode if auto-negotiation failed");
2930 static int __init
tc35815_init_module(void)
2932 return pci_register_driver(&tc35815_pci_driver
);
2935 static void __exit
tc35815_cleanup_module(void)
2937 pci_unregister_driver(&tc35815_pci_driver
);
2940 module_init(tc35815_init_module
);
2941 module_exit(tc35815_cleanup_module
);
2943 MODULE_DESCRIPTION("TOSHIBA TC35815 PCI 10M/100M Ethernet driver");
2944 MODULE_LICENSE("GPL");