33 #include <linux/module.h>
34 #include <linux/types.h>
37 #include <linux/net.h>
38 #include <linux/netdevice.h>
40 #include <linux/ethtool.h>
45 #include <linux/mii.h>
46 #include <linux/device.h>
47 #include <linux/pci.h>
48 #include <linux/rtnetlink.h>
58 #define MII_READ_DELAY 10000
60 #define TSI108_RXRING_LEN 256
66 #define TSI108_RXBUF_SIZE 1536
68 #define TSI108_TXRING_LEN 256
70 #define TSI108_TX_INT_FREQ 64
73 #define CHECK_PHY_INTERVAL (HZ/2)
161 .probe = tsi108_init_one,
162 .remove = tsi108_ether_remove,
164 .name =
"tsi-ethernet",
169 static void tsi108_timed_checker(
unsigned long dev_ptr);
176 printk(
"intstat %x intmask %x phy_ok %d"
177 " link %d speed %d duplex %d\n",
182 printk(
"TX: head %d, tail %d, free %d, stat %x, estat %x, err %x\n",
188 printk(
"RX: head %d, tail %d, free %d, stat %x,"
189 " estat %x, err %x, pending %d\n\n",
212 for (i = 0; i < 100; i++) {
241 static int tsi108_mdio_read(
struct net_device *dev,
int addr,
int reg)
244 return tsi108_read_mii(data, reg);
247 static void tsi108_mdio_write(
struct net_device *dev,
int addr,
int reg,
int val)
250 tsi108_write_mii(data, reg, val);
271 int advert, lpa,
val, media;
284 media = mii_nway_result(advert & lpa);
294 static void tsi108_check_phy(
struct net_device *dev)
297 u32 mac_cfg2_reg, portctrl_reg;
310 if (netif_carrier_ok(dev)) {
312 speed = mii_speed(&data->
mii_if);
314 if ((speed != data->
speed) || duplex) {
331 if (data->
mii_if.full_duplex) {
353 netif_wake_queue(dev);
356 spin_unlock(&data->
txlock);
360 netif_stop_queue(dev);
370 spin_unlock_irqrestore(&phy_lock, flags);
374 tsi108_stat_carry_one(
int carry,
int carry_bit,
int carry_shift,
375 unsigned long *upper)
377 if (carry & carry_bit)
378 *upper += carry_shift;
381 static void tsi108_stat_carry(
struct net_device *dev)
399 &data->
stats.rx_packets);
406 &data->
stats.multicast);
410 &data->
stats.rx_frame_errors);
414 &data->
stats.rx_length_errors);
430 &data->
stats.rx_missed_errors);
437 &data->
stats.tx_packets);
441 &data->
stats.tx_aborted_errors);
448 &data->
stats.collisions);
460 static inline unsigned long
461 tsi108_read_stat(
struct tsi108_prv_data * data,
int reg,
int carry_bit,
462 int carry_shift,
unsigned long *upper)
481 *upper += carry_shift;
537 &data->
stats.rx_length_errors);
553 &data->
stats.rx_frame_errors);
569 &data->
stats.rx_missed_errors);
579 &data->
stats.tx_aborted_errors);
587 data->
tmpstats.tx_aborted_errors += excol;
620 static void tsi108_complete_tx(
struct net_device *dev)
636 printk(
"%s: bad tx packet, misc %x\n",
650 netif_wake_queue(dev);
657 int frags = skb_shinfo(skb)->nr_frags + 1;
666 netif_stop_queue(dev);
671 netif_stop_queue(dev);
680 netif_stop_queue(dev);
683 spin_lock_irq(&data->
txlock);
685 for (i = 0; i < frags; i++) {
725 printk(
"%s: Tx Frame contents (%d)\n", dev->
name,
727 for (i = 0; i < skb->
len; i++)
737 tsi108_complete_tx(dev);
744 tsi108_restart_tx(data);
746 spin_unlock_irq(&data->
txlock);
755 while (data->
rxfree && done != budget) {
771 data->
stats.rx_crc_errors++;
773 data->
stats.rx_fifo_errors++;
782 printk(
"%s: Rx Frame contents (%d)\n",
784 for (i = 0; i < data->
rxring[
rx].len; i++)
797 static int tsi108_refill_rx(
struct net_device *dev,
int budget)
830 tsi108_restart_rx(data, dev);
841 int num_received = 0, num_filled = 0;
850 num_received = tsi108_complete_rx(dev, budget);
865 num_filled = tsi108_refill_rx(dev, budget * 2);
877 TSI108_EC_RXSTAT_QUEUE0))
878 tsi108_restart_rx(data, dev);
884 data->
stats.rx_fifo_errors++;
888 if (num_received < budget) {
896 TSI108_INT_RXOVERRUN |
906 static void tsi108_rx_int(
struct net_device *dev)
921 if (napi_schedule_prep(&data->
napi)) {
930 TSI108_INT_RXOVERRUN | TSI108_INT_RXERROR |
934 if (!netif_running(dev)) {
956 TSI108_INT_RXOVERRUN |
970 static void tsi108_check_rxring(
struct net_device *dev)
983 static void tsi108_tx_int(
struct net_device *dev)
1000 spin_lock(&data->
txlock);
1001 tsi108_complete_tx(dev);
1002 spin_unlock(&data->
txlock);
1023 TSI108_INT_RXERROR))
1033 tsi108_stat_carry(dev);
1040 static void tsi108_stop_ethernet(
struct net_device *dev)
1097 static int tsi108_get_mac(
struct net_device *dev)
1106 if (word2 == 0 && word1 == 0) {
1112 if (0x8 == data->
phy)
1125 dev->
dev_addr[0] = (word2 >> 16) & 0xff;
1126 dev->
dev_addr[1] = (word2 >> 24) & 0xff;
1127 dev->
dev_addr[2] = (word1 >> 0) & 0xff;
1128 dev->
dev_addr[3] = (word1 >> 8) & 0xff;
1129 dev->
dev_addr[4] = (word1 >> 16) & 0xff;
1130 dev->
dev_addr[5] = (word1 >> 24) & 0xff;
1133 if (!is_valid_ether_addr(dev->
dev_addr)) {
1135 "%s: Invalid MAC address. word1: %08x, word2: %08x\n",
1136 dev->
name, word1, word2);
1149 if (!is_valid_ether_addr(addr))
1152 for (i = 0; i < 6; i++)
1154 dev->
dev_addr[i] = ((
unsigned char *)addr)[i + 2];
1164 spin_lock(&data->
txlock);
1167 netif_wake_queue(dev);
1169 spin_unlock(&data->
txlock);
1175 static void tsi108_set_rx_mode(
struct net_device *dev)
1207 for (i = 0; i < 16; i++) {
1221 static void tsi108_init_phy(
struct net_device *dev)
1226 unsigned long flags;
1240 tsi108_write_mii(data, 0x09, 0x0300);
1241 tsi108_write_mii(data, 0x10, 0x1020);
1242 tsi108_write_mii(data, 0x1c, 0x8c00);
1245 tsi108_write_mii(data,
1256 tsi108_write_tbi(data, 0x11, 0x30);
1264 while (!((phyval = tsi108_read_mii(data,
MII_BMSR)) &
1269 spin_unlock_irqrestore(&phy_lock, flags);
1278 spin_unlock_irqrestore(&phy_lock, flags);
1281 static void tsi108_kill_phy(
struct net_device *dev)
1284 unsigned long flags;
1289 spin_unlock_irqrestore(&phy_lock, flags);
1292 static int tsi108_open(
struct net_device *dev)
1307 "tsi108_open : Port %d Assigned IRQ %d to %s\n",
1316 "TSI108_ETH: failed to allocate memory for rxring!\n");
1327 "TSI108_ETH: failed to allocate memory for txring!\n");
1340 data->
rxring[TSI108_RXRING_LEN - 1].next0 = data->
rxdma;
1355 "%s: Could only allocate %d receive skb(s).\n",
1374 data->
txring[TSI108_TXRING_LEN - 1].next0 = data->
txdma;
1379 tsi108_init_phy(dev);
1381 napi_enable(&data->
napi);
1386 tsi108_restart_rx(data, dev);
1398 netif_start_queue(dev);
1402 static int tsi108_close(
struct net_device *dev)
1406 netif_stop_queue(dev);
1407 napi_disable(&data->
napi);
1411 tsi108_stop_ethernet(dev);
1412 tsi108_kill_phy(dev);
1442 TSI108_RXRING_LEN *
sizeof(
rx_desc),
1445 TSI108_TXRING_LEN *
sizeof(
tx_desc),
1451 static void tsi108_init_mac(
struct net_device *dev)
1515 unsigned long flags;
1520 spin_unlock_irqrestore(&data->
txlock, flags);
1528 unsigned long flags;
1533 spin_unlock_irqrestore(&data->
txlock, flags);
1541 if (!netif_running(dev))
1546 static const struct ethtool_ops tsi108_ethtool_ops = {
1548 .get_settings = tsi108_get_settings,
1549 .set_settings = tsi108_set_settings,
1553 .ndo_open = tsi108_open,
1554 .ndo_stop = tsi108_close,
1555 .ndo_start_xmit = tsi108_send_packet,
1556 .ndo_set_rx_mode = tsi108_set_rx_mode,
1557 .ndo_get_stats = tsi108_get_stats,
1558 .ndo_do_ioctl = tsi108_do_ioctl,
1559 .ndo_set_mac_address = tsi108_set_mac,
1572 einfo = pdev->
dev.platform_data;
1574 if (
NULL == einfo) {
1586 printk(
"tsi108_eth%d: probe...\n", pdev->
id);
1587 data = netdev_priv(dev);
1590 pr_debug(
"tsi108_eth%d:regs:phyresgs:phy:irq_num=0x%x:0x%x:0x%x:0x%x\n",
1607 data->
mii_if.mdio_read = tsi108_mdio_read;
1608 data->
mii_if.mdio_write = tsi108_mdio_write;
1610 data->
mii_if.phy_id_mask = 0x1f;
1611 data->
mii_if.reg_num_mask = 0x1f;
1616 data->
id = pdev->
id;
1634 tsi108_reset_ether(data);
1635 tsi108_kill_phy(dev);
1637 if ((err = tsi108_get_mac(dev)) != 0) {
1643 tsi108_init_mac(dev);
1651 platform_set_drvdata(pdev, dev);
1679 static void tsi108_timed_checker(
unsigned long dev_ptr)
1684 tsi108_check_phy(dev);
1685 tsi108_check_rxring(dev);
1691 struct net_device *dev = platform_get_drvdata(pdev);
1695 tsi108_stop_ethernet(dev);
1696 platform_set_drvdata(pdev,
NULL);