20 #include <linux/module.h>
22 #include <linux/netdevice.h>
29 #include <linux/mii.h>
30 #include <linux/ethtool.h>
35 #include <linux/slab.h>
42 #include <mach/regs-irq.h>
46 #define MODULENAME "ks8695_ether"
47 #define MODULEVERSION "1.02"
99 #define MAX_TX_DESC_MASK 0x7
100 #define MAX_RX_DESC 16
101 #define MAX_RX_DESC_MASK 0xf
104 #define NAPI_WEIGHT 64
106 #define MAX_RXBUF_SIZE 0x700
108 #define TX_RING_DMA_SIZE (sizeof(struct tx_ring_desc) * MAX_TX_DESC)
109 #define RX_RING_DMA_SIZE (sizeof(struct rx_ring_desc) * MAX_RX_DESC)
110 #define RING_DMA_SIZE (TX_RING_DMA_SIZE + RX_RING_DMA_SIZE)
229 switch (ksp->
dtype) {
319 #define KS8695_NR_ADDRESSES 16
332 ks8695_init_partial_multicast(
struct ks8695_priv *ksp,
344 low = (ha->
addr[2] << 24) | (ha->
addr[3] << 16) |
346 high = (ha->
addr[0] << 8) | (ha->
addr[1]);
372 ks8695_tx_irq(
int irq,
void *
dev_id)
384 ndev->
stats.tx_packets++;
388 ksp->
tx_ring[buff_n].data_ptr = 0;
401 netif_wake_queue(ndev);
420 static inline u32 ks8695_get_rx_enable_bit(
struct ks8695_priv *ksp)
434 ks8695_rx_irq(
int irq,
void *dev_id)
441 if (napi_schedule_prep(&ksp->
napi)) {
443 unsigned long mask_bit = 1 << ks8695_get_rx_enable_bit(ksp);
469 while (received < budget
471 && (!(ksp->
rx_ring[buff_n].status &
491 ndev->
stats.rx_errors++;
493 ndev->
stats.rx_length_errors++;
495 ndev->
stats.rx_length_errors++;
497 ndev->
stats.rx_crc_errors++;
499 ndev->
stats.rx_missed_errors++;
512 ksp->
rx_ring[buff_n].data_ptr = 0;
526 ndev->
stats.rx_packets++;
545 ks8695_refill_rxbuffers(ksp);
565 unsigned long work_done;
568 unsigned long mask_bit = 1 << ks8695_get_rx_enable_bit(ksp);
570 work_done = ks8695_rx(ksp, budget);
572 if (work_done < budget) {
578 spin_unlock_irqrestore(&ksp->
rx_lock, flags);
592 ks8695_link_irq(
int irq,
void *dev_id)
603 "%s: Link is now up (10%sMbps/%s-duplex)\n",
606 (ctrl &
WMC_WDS) ?
"Full" :
"Half");
633 while (reset_timeout--) {
639 if (reset_timeout < 0) {
641 "Timeout waiting for DMA engines to reset\n");
688 ksp->
tx_ring[buff_n].owner = 0;
689 ksp->
tx_ring[buff_n].status = 0;
690 ksp->
tx_ring[buff_n].data_ptr = 0;
706 ksp->
rx_ring[buff_n].status = 0;
707 ksp->
rx_ring[buff_n].data_ptr = 0;
731 ks8695_setup_irq(
int irq,
const char *irq_name,
739 dev_err(&ndev->
dev,
"failure to request IRQ %d\n", irq);
760 ks8695_refill_rxbuffers(ksp);
768 ks8695_rx_irq, ksp->
ndev);
772 ks8695_tx_irq, ksp->
ndev);
777 ks8695_link_irq, ksp->
ndev);
896 ethtool_cmd_speed_set(cmd,
945 ctrl &= ~(WMC_WAND | WMC_WANA100F | WMC_WANA100H |
989 if ((ctrl & WMC_WAND) == 0)
1038 static const struct ethtool_ops ks8695_ethtool_ops = {
1039 .get_msglevel = ks8695_get_msglevel,
1040 .set_msglevel = ks8695_set_msglevel,
1041 .get_drvinfo = ks8695_get_drvinfo,
1044 static const struct ethtool_ops ks8695_wan_ethtool_ops = {
1045 .get_msglevel = ks8695_get_msglevel,
1046 .set_msglevel = ks8695_set_msglevel,
1047 .get_settings = ks8695_wan_get_settings,
1048 .set_settings = ks8695_wan_set_settings,
1049 .nway_reset = ks8695_wan_nwayreset,
1051 .get_pauseparam = ks8695_wan_get_pause,
1052 .get_drvinfo = ks8695_get_drvinfo,
1068 if (!is_valid_ether_addr(address->
sa_data))
1073 ks8695_update_mac(ksp);
1075 dev_dbg(ksp->
dev,
"%s: Updated MAC address to %pM\n",
1089 ks8695_set_multicast(
struct net_device *ndev)
1115 ks8695_init_partial_multicast(ksp, ndev);
1132 netif_stop_queue(ndev);
1133 ks8695_shutdown(ksp);
1137 ks8695_update_mac(ksp);
1142 ks8695_init_net(ksp);
1145 ks8695_set_multicast(ndev);
1148 netif_start_queue(ndev);
1183 dev_dbg(ksp->
dev,
"%s: Could not map DMA memory for "\
1184 "transmission, trying later\n", ndev->
name);
1194 ksp->
tx_ring[buff_n].data_ptr =
1206 netif_stop_queue(ndev);
1230 netif_stop_queue(ndev);
1231 napi_disable(&ksp->
napi);
1233 ks8695_shutdown(ksp);
1252 if (!is_valid_ether_addr(ndev->
dev_addr))
1257 ks8695_update_mac(ksp);
1259 ret = ks8695_init_net(ksp);
1261 ks8695_shutdown(ksp);
1265 napi_enable(&ksp->
napi);
1266 netif_start_queue(ndev);
1314 ctrl = (WMC_WANAP | WMC_WANA100F | WMC_WANA100H |
1330 .ndo_open = ks8695_open,
1331 .ndo_stop = ks8695_stop,
1332 .ndo_start_xmit = ks8695_start_xmit,
1333 .ndo_tx_timeout = ks8695_timeout,
1334 .ndo_set_mac_address = ks8695_set_mac,
1336 .ndo_set_rx_mode = ks8695_set_multicast,
1357 struct resource *regs_res, *phyiface_res;
1358 struct resource *rxirq_res, *txirq_res, *linkirq_res;
1361 u32 machigh, maclow;
1364 ndev = alloc_etherdev(
sizeof(
struct ks8695_priv));
1370 dev_dbg(&pdev->
dev,
"ks8695_probe() called\n");
1373 ksp = netdev_priv(ndev);
1387 if (!(regs_res && rxirq_res && txirq_res)) {
1388 dev_err(ksp->
dev,
"insufficient resources\n");
1394 resource_size(regs_res),
1398 dev_err(ksp->
dev,
"cannot claim register space\n");
1406 dev_err(ksp->
dev,
"failed to ioremap registers\n");
1414 resource_size(phyiface_res),
1415 phyiface_res->
name);
1419 "cannot claim switch register space\n");
1425 resource_size(phyiface_res));
1429 "failed to ioremap switch registers\n");
1441 linkirq_res->
name :
"Ethernet Link";
1455 ndev->
dev_addr[0] = (machigh >> 8) & 0xFF;
1456 ndev->
dev_addr[1] = machigh & 0xFF;
1457 ndev->
dev_addr[2] = (maclow >> 24) & 0xFF;
1458 ndev->
dev_addr[3] = (maclow >> 16) & 0xFF;
1459 ndev->
dev_addr[4] = (maclow >> 8) & 0xFF;
1462 if (!is_valid_ether_addr(ndev->
dev_addr))
1463 dev_warn(ksp->
dev,
"%s: Invalid ethernet MAC address. Please "
1464 "set using ifconfig\n", ndev->
name);
1493 for (buff_n = 0; buff_n <
MAX_TX_DESC; ++buff_n) {
1494 ksp->
tx_ring[buff_n].next_desc =
1500 for (buff_n = 0; buff_n <
MAX_RX_DESC; ++buff_n) {
1501 ksp->
rx_ring[buff_n].next_desc =
1509 ks8695_init_switch(ksp);
1513 ks8695_init_wan_phy(ksp);
1523 platform_set_drvdata(pdev, ndev);
1527 dev_info(ksp->
dev,
"ks8695 ethernet (%s) MAC: %pM\n",
1528 ks8695_port_type(ksp), ndev->
dev_addr);
1531 dev_err(ksp->
dev,
"ks8695net: failed to register netdev.\n");
1540 ks8695_release_device(ksp);
1556 struct net_device *ndev = platform_get_drvdata(pdev);
1561 if (netif_running(ndev)) {
1563 ks8695_shutdown(ksp);
1579 struct net_device *ndev = platform_get_drvdata(pdev);
1582 if (netif_running(ndev)) {
1584 ks8695_init_net(ksp);
1585 ks8695_set_multicast(ndev);
1603 struct net_device *ndev = platform_get_drvdata(pdev);
1606 platform_set_drvdata(pdev,
NULL);
1610 ks8695_release_device(ksp);
1613 dev_dbg(&pdev->
dev,
"released and freed device\n");
1622 .probe = ks8695_probe,
1624 .suspend = ks8695_drv_suspend,
1625 .resume = ks8695_drv_resume,
1640 ks8695_cleanup(
void)