25 #define DRV_VERSION "1.39"
27 #define MODNAME "tc35815"
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/fcntl.h>
36 #include <linux/if_vlan.h>
37 #include <linux/slab.h>
38 #include <linux/string.h>
40 #include <linux/errno.h>
42 #include <linux/netdevice.h>
46 #include <linux/pci.h>
50 #include <linux/prefetch.h>
52 #include <asm/byteorder.h>
64 {
"TOSHIBA TC35815CF 10/100BaseTX" },
65 {
"TOSHIBA TC35815 with Wake on LAN" },
66 {
"TOSHIBA TC35815/TX4939" },
78 static struct tc35815_options {
124 #define DMA_RxAlign 0x00c00000
125 #define DMA_RxAlign_1 0x00400000
126 #define DMA_RxAlign_2 0x00800000
127 #define DMA_RxAlign_3 0x00c00000
128 #define DMA_M66EnStat 0x00080000
129 #define DMA_IntMask 0x00040000
130 #define DMA_SWIntReq 0x00020000
131 #define DMA_TxWakeUp 0x00010000
132 #define DMA_RxBigE 0x00008000
133 #define DMA_TxBigE 0x00004000
134 #define DMA_TestMode 0x00002000
135 #define DMA_PowrMgmnt 0x00001000
136 #define DMA_DmBurst_Mask 0x000001fc
139 #define RxFrag_EnPack 0x00008000
140 #define RxFrag_MinFragMask 0x00000ffc
143 #define MAC_Link10 0x00008000
144 #define MAC_EnMissRoll 0x00002000
145 #define MAC_MissRoll 0x00000400
146 #define MAC_Loop10 0x00000080
147 #define MAC_Conn_Auto 0x00000000
148 #define MAC_Conn_10M 0x00000020
149 #define MAC_Conn_Mll 0x00000040
150 #define MAC_MacLoop 0x00000010
151 #define MAC_FullDup 0x00000008
152 #define MAC_Reset 0x00000004
153 #define MAC_HaltImm 0x00000002
154 #define MAC_HaltReq 0x00000001
157 #define PROM_Busy 0x00008000
158 #define PROM_Read 0x00004000
159 #define PROM_Write 0x00002000
160 #define PROM_Erase 0x00006000
163 #define PROM_Addr_Ena 0x00000030
167 #define CAM_CompEn 0x00000010
168 #define CAM_NegCAM 0x00000008
170 #define CAM_BroadAcc 0x00000004
171 #define CAM_GroupAcc 0x00000002
172 #define CAM_StationAcc 0x00000001
175 #define CAM_ENTRY_MAX 21
176 #define CAM_Ena_Mask ((1<<CAM_ENTRY_MAX)-1)
177 #define CAM_Ena_Bit(index) (1 << (index))
178 #define CAM_ENTRY_DESTINATION 0
179 #define CAM_ENTRY_SOURCE 1
180 #define CAM_ENTRY_MACCTL 20
183 #define Tx_En 0x00000001
184 #define Tx_TxHalt 0x00000002
185 #define Tx_NoPad 0x00000004
186 #define Tx_NoCRC 0x00000008
187 #define Tx_FBack 0x00000010
188 #define Tx_EnUnder 0x00000100
189 #define Tx_EnExDefer 0x00000200
190 #define Tx_EnLCarr 0x00000400
191 #define Tx_EnExColl 0x00000800
192 #define Tx_EnLateColl 0x00001000
193 #define Tx_EnTxPar 0x00002000
194 #define Tx_EnComp 0x00004000
197 #define Tx_TxColl_MASK 0x0000000F
198 #define Tx_ExColl 0x00000010
199 #define Tx_TXDefer 0x00000020
200 #define Tx_Paused 0x00000040
201 #define Tx_IntTx 0x00000080
202 #define Tx_Under 0x00000100
203 #define Tx_Defer 0x00000200
204 #define Tx_NCarr 0x00000400
205 #define Tx_10Stat 0x00000800
206 #define Tx_LateColl 0x00001000
207 #define Tx_TxPar 0x00002000
208 #define Tx_Comp 0x00004000
209 #define Tx_Halted 0x00008000
210 #define Tx_SQErr 0x00010000
213 #define Rx_EnGood 0x00004000
214 #define Rx_EnRxPar 0x00002000
215 #define Rx_EnLongErr 0x00000800
216 #define Rx_EnOver 0x00000400
217 #define Rx_EnCRCErr 0x00000200
218 #define Rx_EnAlign 0x00000100
219 #define Rx_IgnoreCRC 0x00000040
220 #define Rx_StripCRC 0x00000010
221 #define Rx_ShortEn 0x00000008
222 #define Rx_LongEn 0x00000004
223 #define Rx_RxHalt 0x00000002
224 #define Rx_RxEn 0x00000001
227 #define Rx_Halted 0x00008000
228 #define Rx_Good 0x00004000
229 #define Rx_RxPar 0x00002000
230 #define Rx_TypePkt 0x00001000
231 #define Rx_LongErr 0x00000800
232 #define Rx_Over 0x00000400
233 #define Rx_CRCErr 0x00000200
234 #define Rx_Align 0x00000100
235 #define Rx_10Stat 0x00000080
236 #define Rx_IntRx 0x00000040
237 #define Rx_CtlRecd 0x00000020
238 #define Rx_InLenErr 0x00000010
240 #define Rx_Stat_Mask 0x0000FFF0
243 #define Int_NRAbtEn 0x00000800
244 #define Int_TxCtlCmpEn 0x00000400
245 #define Int_DmParErrEn 0x00000200
246 #define Int_DParDEn 0x00000100
247 #define Int_EarNotEn 0x00000080
248 #define Int_DParErrEn 0x00000040
249 #define Int_SSysErrEn 0x00000020
250 #define Int_RMasAbtEn 0x00000010
251 #define Int_RTargAbtEn 0x00000008
252 #define Int_STargAbtEn 0x00000004
253 #define Int_BLExEn 0x00000002
254 #define Int_FDAExEn 0x00000001
258 #define Int_NRabt 0x00004000
259 #define Int_DmParErrStat 0x00002000
260 #define Int_BLEx 0x00001000
261 #define Int_FDAEx 0x00000800
262 #define Int_IntNRAbt 0x00000400
263 #define Int_IntCmp 0x00000200
264 #define Int_IntExBD 0x00000100
265 #define Int_DmParErr 0x00000080
266 #define Int_IntEarNot 0x00000040
267 #define Int_SWInt 0x00000020
268 #define Int_IntBLEx 0x00000010
269 #define Int_IntFDAEx 0x00000008
270 #define Int_IntPCI 0x00000004
271 #define Int_IntMacRx 0x00000002
272 #define Int_IntMacTx 0x00000001
275 #define MD_CA_PreSup 0x00001000
276 #define MD_CA_Busy 0x00000800
277 #define MD_CA_Wr 0x00000400
301 #define FD_FDLength_MASK 0x0000FFFF
302 #define FD_BDCnt_MASK 0x001F0000
303 #define FD_FrmOpt_MASK 0x7C000000
304 #define FD_FrmOpt_BigEndian 0x40000000
305 #define FD_FrmOpt_IntTx 0x20000000
306 #define FD_FrmOpt_NoCRC 0x10000000
307 #define FD_FrmOpt_NoPadding 0x08000000
308 #define FD_FrmOpt_Packing 0x04000000
309 #define FD_CownsFD 0x80000000
310 #define FD_Next_EOL 0x00000001
311 #define FD_BDCnt_SHIFT 16
314 #define BD_BuffLength_MASK 0x0000FFFF
315 #define BD_RxBDID_MASK 0x00FF0000
316 #define BD_RxBDSeqN_MASK 0x7F000000
317 #define BD_CownsBD 0x80000000
318 #define BD_RxBDID_SHIFT 16
319 #define BD_RxBDSeqN_SHIFT 24
324 #define TX_CTL_CMD (Tx_EnTxPar | Tx_EnLateColl | \
325 Tx_EnExColl | Tx_EnLCarr | Tx_EnExDefer | Tx_EnUnder | \
328 #define RX_CTL_CMD (Rx_EnGood | Rx_EnRxPar | Rx_EnLongErr | Rx_EnOver \
329 | Rx_EnCRCErr | Rx_EnAlign | Rx_RxEn)
330 #define INT_EN_CMD (Int_NRAbtEn | \
331 Int_DmParErrEn | Int_DParDEn | Int_DParErrEn | \
332 Int_SSysErrEn | Int_RMasAbtEn | Int_RTargAbtEn | \
334 Int_BLExEn | Int_FDAExEn)
335 #define DMA_CTL_CMD DMA_BURST_SIZE
336 #define HAVE_DMA_RXALIGN(lp) likely((lp)->chiptype != TC35815CF)
339 #define DMA_BURST_SIZE 32
340 #define TX_THRESHOLD 1024
342 #define TX_THRESHOLD_MAX 1536
344 #define TX_THRESHOLD_KEEP_LIMIT 10
347 #define FD_PAGE_NUM 4
348 #define RX_BUF_NUM 128
349 #define RX_FD_NUM 256
350 #define TX_FD_NUM 128
351 #if RX_CTL_CMD & Rx_LongEn
352 #define RX_BUF_SIZE PAGE_SIZE
353 #elif RX_CTL_CMD & Rx_StripCRC
354 #define RX_BUF_SIZE \
355 L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + NET_IP_ALIGN)
357 #define RX_BUF_SIZE \
358 L1_CACHE_ALIGN(ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN + NET_IP_ALIGN)
360 #define RX_FD_RESERVE (2 / 2)
361 #define NAPI_WEIGHT 16
380 #define tc_readl(addr) ioread32(addr)
381 #define tc_writel(d, addr) iowrite32(d, addr)
383 #define TC35815_TX_TIMEOUT msecs_to_jiffies(400)
461 if (pci_dma_mapping_error(hwdev, *dma_handle)) {
478 static int tc35815_open(
struct net_device *dev);
483 static void tc35815_txdone(
struct net_device *dev);
484 static int tc35815_close(
struct net_device *dev);
486 static void tc35815_set_multicast_list(
struct net_device *dev);
487 static void tc35815_tx_timeout(
struct net_device *dev);
489 #ifdef CONFIG_NET_POLL_CONTROLLER
490 static void tc35815_poll_controller(
struct net_device *dev);
492 static const struct ethtool_ops tc35815_ethtool_ops;
495 static void tc35815_chip_reset(
struct net_device *dev);
496 static void tc35815_chip_init(
struct net_device *dev);
499 static void panic_queues(
struct net_device *dev);
504 static int tc_mdio_read(
struct mii_bus *bus,
int mii_id,
int regnum)
509 unsigned long timeout = jiffies +
HZ;
521 static int tc_mdio_write(
struct mii_bus *bus,
int mii_id,
int regnum,
u16 val)
526 unsigned long timeout = jiffies +
HZ;
540 static void tc_handle_link_change(
struct net_device *dev)
545 int status_change = 0;
588 tc35815_set_multicast_list(dev);
597 spin_unlock_irqrestore(&lp->
lock, flags);
601 pr_debug(
"%s: MII BMCR %04x BMSR %04x LPA %04x\n",
609 static int tc_mii_probe(
struct net_device *dev)
617 for (phy_addr = 0; phy_addr <
PHY_MAX_ADDR; phy_addr++) {
618 if (lp->
mii_bus->phy_map[phy_addr]) {
624 phydev = lp->
mii_bus->phy_map[phy_addr];
636 &tc_handle_link_change, 0,
639 if (IS_ERR(phydev)) {
641 return PTR_ERR(phydev);
644 "(mii_bus:phy_addr=%s, id=%x)\n",
645 dev->
name, phydev->
drv->name, dev_name(&phydev->
dev),
670 static int tc_mii_init(
struct net_device *dev)
682 lp->
mii_bus->name =
"tc35815_mii_bus";
683 lp->
mii_bus->read = tc_mdio_read;
684 lp->
mii_bus->write = tc_mdio_write;
692 goto err_out_free_mii_bus;
700 goto err_out_free_mdio_irq;
701 err = tc_mii_probe(dev);
703 goto err_out_unregister_bus;
706 err_out_unregister_bus:
708 err_out_free_mdio_irq:
710 err_out_free_mii_bus:
716 #ifdef CONFIG_CPU_TX49XX
726 unsigned int id = pci_dev->
irq;
727 return !
strcmp(plat_dev->
name,
"tc35815-mac") && plat_dev->
id ==
id;
734 lp->
pci_dev, tc35815_mac_match);
758 for (i = 0; i < 6; i += 2) {
767 if (!is_valid_ether_addr(dev->
dev_addr))
768 return tc35815_read_plat_dev_addr(dev);
773 .ndo_open = tc35815_open,
774 .ndo_stop = tc35815_close,
775 .ndo_start_xmit = tc35815_send_packet,
776 .ndo_get_stats = tc35815_get_stats,
777 .ndo_set_rx_mode = tc35815_set_multicast_list,
778 .ndo_tx_timeout = tc35815_tx_timeout,
779 .ndo_do_ioctl = tc35815_ioctl,
783 #ifdef CONFIG_NET_POLL_CONTROLLER
784 .ndo_poll_controller = tc35815_poll_controller,
796 static int printed_version;
797 if (!printed_version++) {
800 "speed:%d duplex:%d\n",
810 dev = alloc_etherdev(
sizeof(*lp));
815 lp = netdev_priv(dev);
844 pci_set_drvdata(pdev, dev);
847 tc35815_chip_reset(dev);
850 if (tc35815_init_dev_addr(dev)) {
852 eth_hw_addr_random(dev);
867 rc = tc_mii_init(dev);
869 goto err_out_unregister;
883 struct net_device *dev = pci_get_drvdata(pdev);
892 pci_set_drvdata(pdev,
NULL);
900 unsigned long fd_addr;
916 alloc_rxbuf_skb(dev, lp->
pci_dev,
1012 fdsystem != 0xffffffff ?
1015 if (lp->
tx_skbs[i].skb != skb) {
1016 printk(
"%s: tx_skbs mismatch(%d).\n", dev->
name, i);
1031 tc35815_init_queues(dev);
1044 fdsystem != 0xffffffff ?
1047 if (lp->
tx_skbs[i].skb != skb) {
1048 printk(
"%s: tx_skbs mismatch(%d).\n", dev->
name, i);
1084 dump_txfd(
struct TxFD *
fd)
1086 printk(
"TxFD(%p): %08x %08x %08x %08x\n", fd,
1099 dump_rxfd(
struct RxFD *fd)
1104 printk(
"RxFD(%p): %08x %08x %08x %08x\n", fd,
1112 for (i = 0; i < bd_count; i++)
1122 dump_frfd(
struct FrFD *fd)
1125 printk(
"FrFD(%p): %08x %08x %08x %08x\n", fd,
1144 printk(
"TxFD base %p, start %u, end %u\n",
1146 printk(
"RxFD base %p limit %p cur %p\n",
1152 int bd_count = dump_rxfd(&lp->
rfd_base[i]);
1153 i += (bd_count + 1) / 2;
1156 panic(
"%s: Illegal queue state.", dev->
name);
1160 static void print_eth(
const u8 *
add)
1164 add + 6, add, add[12], add[13]);
1167 static int tc35815_tx_full(
struct net_device *dev)
1173 static void tc35815_restart(
struct net_device *dev)
1192 spin_lock_irq(&lp->
lock);
1193 tc35815_chip_reset(dev);
1194 tc35815_clear_queues(dev);
1195 tc35815_chip_init(dev);
1197 tc35815_set_multicast_list(dev);
1198 spin_unlock_irq(&lp->
lock);
1201 netif_wake_queue(dev);
1210 tc35815_restart(dev);
1213 static void tc35815_schedule_restart(
struct net_device *dev)
1218 unsigned long flags;
1225 spin_unlock_irqrestore(&lp->
lock, flags);
1228 static void tc35815_tx_timeout(
struct net_device *dev)
1237 tc35815_schedule_restart(dev);
1238 dev->
stats.tx_errors++;
1262 tc35815_chip_reset(dev);
1264 if (tc35815_init_queues(dev) != 0) {
1269 napi_enable(&lp->
napi);
1272 spin_lock_irq(&lp->
lock);
1273 tc35815_chip_init(dev);
1274 spin_unlock_irq(&lp->
lock);
1283 netif_start_queue(dev);
1297 unsigned long flags;
1318 tc35815_txdone(dev);
1321 print_eth(skb->
data);
1324 printk(
"%s: tx_skbs conflict.\n", dev->
name);
1364 if (tc35815_tx_full(dev)) {
1367 netif_stop_queue(dev);
1374 spin_unlock_irqrestore(&lp->
lock, flags);
1378 #define FATAL_ERROR_INT \
1379 (Int_IntPCI | Int_DmParErr | Int_IntNRAbt)
1393 panic(
"%s: Too many fatal errors.", dev->
name);
1396 tc35815_schedule_restart(dev);
1406 tc35815_fatal_error_interrupt(dev, status);
1413 "Free Descriptor Area Exhausted (%#x).\n",
1415 dev->
stats.rx_dropped++;
1421 "Buffer List Exhausted (%#x).\n",
1423 dev->
stats.rx_dropped++;
1429 "Excessive Buffer Descriptiors (%#x).\n",
1431 dev->
stats.rx_length_errors++;
1438 ret = tc35815_rx(dev, limit);
1444 spin_lock_irq(&lp->
lock);
1445 tc35815_txdone(dev);
1446 spin_unlock_irq(&lp->
lock);
1468 if (napi_schedule_prep(&lp->
napi))
1481 #ifdef CONFIG_NET_POLL_CONTROLLER
1482 static void tc35815_poll_controller(
struct net_device *dev)
1485 tc35815_interrupt(dev->
irq, dev);
1492 tc35815_rx(
struct net_device *dev,
int limit)
1504 struct RxFD *next_rfd;
1506 #if (RX_CTL_CMD & Rx_StripCRC) == 0
1514 unsigned char *
data;
1523 if (cur_bd >= RX_BUF_NUM) {
1529 if (!lp->
rx_skbs[cur_bd].skb) {
1534 BUG_ON(cur_bd >= RX_BUF_NUM);
1536 skb = lp->
rx_skbs[cur_bd].skb;
1551 dev->
stats.rx_packets++;
1554 dev->
stats.rx_errors++;
1563 if (status & Rx_LongErr)
1564 dev->
stats.rx_length_errors++;
1566 dev->
stats.rx_fifo_errors++;
1567 if (status & Rx_CRCErr)
1568 dev->
stats.rx_crc_errors++;
1570 dev->
stats.rx_frame_errors++;
1579 if (
id >= RX_BUF_NUM) {
1584 BUG_ON(
id >= RX_BUF_NUM);
1590 unsigned char curid =
1596 printk(
"%s: Freeing invalid BD.\n",
1602 if (!lp->
rx_skbs[curid].skb) {
1604 alloc_rxbuf_skb(dev,
1621 next_rfd = fd_bus_to_virt(lp,
1623 if (next_rfd < lp->rfd_base || next_rfd > lp->
rfd_limit) {
1624 printk(
"%s: RxFD FDNext invalid.\n", dev->
name);
1628 for (i = 0; i < (bd_count + 1) / 2 + 1; i++) {
1642 printk(
"rfd_cur = %p, next_rfd %p\n",
1656 int received = 0, handled;
1666 handled = tc35815_do_interrupt(dev, status, budget - received);
1671 received += handled;
1672 if (received >= budget)
1679 if (received < budget) {
1687 #define TX_STA_ERR (Tx_ExColl|Tx_Under|Tx_Defer|Tx_NCarr|Tx_LateColl|Tx_TxPar|Tx_SQErr)
1690 tc35815_check_tx_stat(
struct net_device *dev,
int status)
1697 dev->
stats.collisions += 16;
1710 dev->
stats.tx_packets++;
1714 dev->
stats.tx_errors++;
1715 if (status & Tx_ExColl) {
1716 dev->
stats.tx_aborted_errors++;
1717 msg =
"Excessive Collision.";
1720 dev->
stats.tx_fifo_errors++;
1721 msg =
"Tx FIFO Underrun.";
1723 lp->
lstats.tx_underrun++;
1728 msg =
"Tx FIFO Underrun.Change Tx threshold to max.";
1733 dev->
stats.tx_fifo_errors++;
1734 msg =
"Excessive Deferral.";
1737 dev->
stats.tx_carrier_errors++;
1738 msg =
"Lost Carrier Sense.";
1741 dev->
stats.tx_aborted_errors++;
1742 msg =
"Late Collision.";
1745 dev->
stats.tx_fifo_errors++;
1746 msg =
"Transmit Parity Error.";
1749 dev->
stats.tx_heartbeat_errors++;
1750 msg =
"Signal Quality Error.";
1778 tc35815_check_tx_stat(dev, status);
1780 skb = fdsystem != 0xffffffff ?
1784 printk(
"%s: tx_skbs mismatch.\n", dev->
name);
1802 if ((fdnext & ~
FD_Next_EOL) != fd_virt_to_bus(lp, txfd)) {
1803 printk(
"%s: TxFD FDNext invalid.\n", dev->
name);
1819 printk(
"%s: TxFD FDCtl invalid.\n", dev->
name);
1824 if (lp->
lstats.max_tx_qlen < qlen)
1825 lp->
lstats.max_tx_qlen = qlen;
1832 printk(
"%s: start TxFD on queue.\n",
1846 if (netif_queue_stopped(dev) && !tc35815_tx_full(dev))
1847 netif_wake_queue(dev);
1856 netif_stop_queue(dev);
1857 napi_disable(&lp->
napi);
1863 tc35815_chip_reset(dev);
1866 tc35815_free_queues(dev);
1880 if (netif_running(dev))
1892 int cam_index = index * 6;
1900 dev->
name, index, addr);
1905 cam_data |= addr[0] << 8 | addr[1];
1909 cam_data = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) | addr[5];
1914 cam_data = (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
1919 cam_data |= addr[4] << 24 | (addr[5] << 16);
1935 tc35815_set_multicast_list(
struct net_device *dev)
1964 tc35815_set_cam_entry(dev, i + 2, ha->
addr);
2008 static void tc35815_set_msglevel(
struct net_device *dev,
u32 datum)
2014 static int tc35815_get_sset_count(
struct net_device *dev,
int sset)
2020 return sizeof(lp->
lstats) /
sizeof(
int);
2029 data[0] = lp->
lstats.max_tx_qlen;
2030 data[1] = lp->
lstats.tx_ints;
2031 data[2] = lp->
lstats.rx_ints;
2032 data[3] = lp->
lstats.tx_underrun;
2037 } ethtool_stats_keys[] = {
2044 static void tc35815_get_strings(
struct net_device *dev,
u32 stringset,
u8 *data)
2046 memcpy(data, ethtool_stats_keys,
sizeof(ethtool_stats_keys));
2049 static const struct ethtool_ops tc35815_ethtool_ops = {
2050 .get_drvinfo = tc35815_get_drvinfo,
2051 .get_settings = tc35815_get_settings,
2052 .set_settings = tc35815_set_settings,
2054 .get_msglevel = tc35815_get_msglevel,
2055 .set_msglevel = tc35815_set_msglevel,
2056 .get_strings = tc35815_get_strings,
2057 .get_sset_count = tc35815_get_sset_count,
2058 .get_ethtool_stats = tc35815_get_ethtool_stats,
2065 if (!netif_running(dev))
2072 static void tc35815_chip_reset(
struct net_device *dev)
2107 for (i = 0; i < 0x1000; i += 4) {
2114 static void tc35815_chip_init(
struct net_device *dev)
2162 struct net_device *dev = pci_get_drvdata(pdev);
2164 unsigned long flags;
2167 if (!netif_running(dev))
2173 tc35815_chip_reset(dev);
2174 spin_unlock_irqrestore(&lp->
lock, flags);
2179 static int tc35815_resume(
struct pci_dev *pdev)
2181 struct net_device *dev = pci_get_drvdata(pdev);
2185 if (!netif_running(dev))
2188 tc35815_restart(dev);
2197 static struct pci_driver tc35815_pci_driver = {
2199 .id_table = tc35815_pci_tbl,
2200 .probe = tc35815_init_one,
2203 .suspend = tc35815_suspend,
2204 .resume = tc35815_resume,
2213 static int __init tc35815_init_module(
void)
2215 return pci_register_driver(&tc35815_pci_driver);
2218 static void __exit tc35815_cleanup_module(
void)