35 #include <linux/module.h>
36 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/ctype.h>
40 #include <linux/types.h>
45 #include <linux/slab.h>
46 #include <linux/string.h>
48 #include <linux/netdevice.h>
51 #include <linux/errno.h>
53 #include <linux/mii.h>
54 #include <linux/ethtool.h>
57 #include <asm/bootinfo.h>
58 #include <asm/bitops.h>
59 #include <asm/pgtable.h>
68 #define DRV_NAME "korina"
69 #define DRV_VERSION "0.10"
70 #define DRV_RELDATE "04Mar2008"
72 #define STATION_ADDRESS_HIGH(dev) (((dev)->dev_addr[0] << 8) | \
74 #define STATION_ADDRESS_LOW(dev) (((dev)->dev_addr[2] << 24) | \
75 ((dev)->dev_addr[3] << 16) | \
76 ((dev)->dev_addr[4] << 8) | \
79 #define MII_CLOCK 1250000
82 #define KORINA_NUM_RDS 64
83 #define KORINA_NUM_TDS 64
88 #define KORINA_RBSIZE 1536
89 #define KORINA_RDS_MASK (KORINA_NUM_RDS - 1)
90 #define KORINA_TDS_MASK (KORINA_NUM_TDS - 1)
91 #define RD_RING_SIZE (KORINA_NUM_RDS * sizeof(struct dma_desc))
92 #define TD_RING_SIZE (KORINA_NUM_TDS * sizeof(struct dma_desc))
94 #define TX_TIMEOUT (6000 * HZ / 1000)
97 #define IS_DMA_FINISHED(X) (((X) & (DMA_DESC_FINI)) != 0)
98 #define IS_DMA_DONE(X) (((X) & (DMA_DESC_DONE)) != 0)
99 #define RCVPKT_LENGTH(X) (((X) & ETH_RX_LEN) >> ETH_RX_LEN_BIT)
170 static void korina_abort_tx(
struct net_device *dev)
177 static void korina_abort_rx(
struct net_device *dev)
202 u32 chain_prev, chain_next;
214 netif_stop_queue(dev);
216 dev->
stats.tx_dropped++;
218 spin_unlock_irqrestore(&lp->
lock, flags);
254 lp->
td_ring[chain_prev].control &=
279 lp->
td_ring[chain_prev].control &=
288 spin_unlock_irqrestore(&lp->
lock, flags);
293 static int mdio_read(
struct net_device *dev,
int mii_id,
int reg)
298 mii_id = ((lp->
rx_irq == 0x2c ? 1 : 0) << 8);
309 static void mdio_write(
struct net_device *dev,
int mii_id,
int reg,
int val)
313 mii_id = ((lp->
rx_irq == 0x2c ? 1 : 0) << 8);
337 napi_schedule(&lp->
napi);
360 for (count = 0; count <
limit; count++) {
371 dev->
stats.rx_crc_errors++;
373 dev->
stats.rx_length_errors++;
375 dev->
stats.rx_length_errors++;
377 dev->
stats.rx_fifo_errors++;
379 dev->
stats.rx_frame_errors++;
381 dev->
stats.rx_length_errors++;
383 dev->
stats.multicast++;
389 dev->
stats.rx_errors++;
390 dev->
stats.rx_dropped++;
412 dev->
stats.rx_packets++;
416 if (devcs & ETH_RX_MP)
417 dev->
stats.multicast++;
453 korina_chain_rx(lp, rd);
466 work_done = korina_rx(dev, budget);
467 if (work_done < budget) {
480 static void korina_multicast_list(
struct net_device *dev)
501 for (i = 0; i < 4; i++)
507 hash_table[crc >> 4] |= 1 << (15 - (crc & 0xf));
513 writel((
u32)(hash_table[1] << 16 | hash_table[0]),
515 writel((
u32)(hash_table[3] << 16 | hash_table[2]),
521 spin_unlock_irqrestore(&lp->
lock, flags);
531 spin_lock(&lp->
lock);
536 netif_wake_queue(dev);
543 dev->
stats.tx_errors++;
544 dev->
stats.tx_dropped++;
550 dev->
stats.tx_packets++;
551 dev->
stats.tx_bytes +=
554 dev->
stats.tx_errors++;
555 dev->
stats.tx_dropped++;
559 dev->
stats.tx_fifo_errors++;
563 dev->
stats.tx_aborted_errors++;
567 dev->
stats.tx_carrier_errors++;
571 dev->
stats.collisions++;
575 dev->
stats.tx_window_errors++;
604 spin_unlock(&lp->
lock);
608 korina_tx_dma_interrupt(
int irq,
void *dev_id)
643 static void korina_check_media(
struct net_device *dev,
unsigned int init_media)
649 if (lp->
mii_if.full_duplex)
657 static void korina_poll_media(
unsigned long data)
662 korina_check_media(dev, 0);
666 static void korina_set_carrier(
struct mii_if_info *mii)
670 if (!netif_carrier_ok(mii->
dev))
673 korina_check_media(mii->
dev, 0);
682 if (!netif_running(dev))
684 spin_lock_irq(&lp->
lock);
686 spin_unlock_irq(&lp->
lock);
687 korina_set_carrier(&lp->
mii_if);
693 static void netdev_get_drvinfo(
struct net_device *dev,
708 spin_lock_irq(&lp->
lock);
710 spin_unlock_irq(&lp->
lock);
720 spin_lock_irq(&lp->
lock);
722 spin_unlock_irq(&lp->
lock);
723 korina_set_carrier(&lp->
mii_if);
735 static const struct ethtool_ops netdev_ethtool_ops = {
736 .get_drvinfo = netdev_get_drvinfo,
737 .get_settings = netdev_get_settings,
738 .set_settings = netdev_set_settings,
739 .get_link = netdev_get_link,
742 static int korina_alloc_ring(
struct net_device *dev)
785 static void korina_free_ring(
struct net_device *dev)
808 static int korina_init(
struct net_device *dev)
813 korina_abort_tx(dev);
814 korina_abort_rx(dev);
825 if (korina_alloc_ring(dev)) {
827 korina_free_ring(dev);
833 korina_start_rx(lp, &lp->
rd_ring[0]);
878 napi_enable(&lp->
napi);
879 netif_start_queue(dev);
908 korina_free_ring(dev);
910 napi_disable(&lp->
napi);
912 if (korina_init(dev) < 0) {
916 korina_multicast_list(dev);
928 netif_stop_queue(dev);
934 static irqreturn_t korina_und_interrupt(
int irq,
void *dev_id)
940 spin_lock(&lp->
lock);
945 korina_clear_and_restart(dev, und & ~ETH_INT_FC_UND);
947 spin_unlock(&lp->
lock);
952 static void korina_tx_timeout(
struct net_device *dev)
961 korina_ovr_interrupt(
int irq,
void *dev_id)
967 spin_lock(&lp->
lock);
971 korina_clear_and_restart(dev, ovr & ~ETH_INT_FC_OVR);
973 spin_unlock(&lp->
lock);
978 #ifdef CONFIG_NET_POLL_CONTROLLER
979 static void korina_poll_controller(
struct net_device *dev)
982 korina_tx_dma_interrupt(dev->
irq, dev);
987 static int korina_open(
struct net_device *dev)
993 ret = korina_init(dev);
1014 goto err_free_rx_irq;
1023 goto err_free_tx_irq;
1032 goto err_free_ovr_irq;
1045 korina_free_ring(dev);
1049 static int korina_close(
struct net_device *dev)
1062 korina_abort_tx(dev);
1067 korina_abort_rx(dev);
1072 korina_free_ring(dev);
1074 napi_disable(&lp->
napi);
1087 .ndo_open = korina_open,
1088 .ndo_stop = korina_close,
1089 .ndo_start_xmit = korina_send_packet,
1090 .ndo_set_rx_mode = korina_multicast_list,
1091 .ndo_tx_timeout = korina_tx_timeout,
1092 .ndo_do_ioctl = korina_ioctl,
1096 #ifdef CONFIG_NET_POLL_CONTROLLER
1097 .ndo_poll_controller = korina_poll_controller,
1114 lp = netdev_priv(dev);
1138 goto probe_err_dma_rx;
1146 goto probe_err_dma_tx;
1152 goto probe_err_td_ring;
1174 lp->
mii_if.mdio_read = mdio_read;
1175 lp->
mii_if.mdio_write = mdio_write;
1177 lp->
mii_if.phy_id_mask = 0x1f;
1178 lp->
mii_if.reg_num_mask = 0x1f;
1183 ": cannot register net device: %d\n", rc);
1184 goto probe_err_register;
1217 platform_set_drvdata(pdev,
NULL);
1225 .driver.name =
"korina",
1226 .probe = korina_probe,
1227 .remove = korina_remove,