32 #include <linux/kernel.h>
35 #include <linux/tcp.h>
37 #include <linux/ethtool.h>
38 #include <linux/if_ether.h>
40 #include <linux/mii.h>
42 #include <linux/if_vlan.h>
44 #include <linux/slab.h>
45 #include <linux/prefetch.h>
46 #ifdef CONFIG_STMMAC_DEBUG_FS
55 #define DBG(nlevel, klevel, fmt, args...) \
56 ((void)(netif_msg_##nlevel(priv) && \
57 printk(KERN_##klevel fmt, ## args)))
59 #define DBG(nlevel, klevel, fmt, args...) do { } while (0)
62 #undef STMMAC_RX_DEBUG
64 #ifdef STMMAC_RX_DEBUG
65 #define RX_DBG(fmt, args...) printk(fmt, ## args)
67 #define RX_DBG(fmt, args...) do { } while (0)
70 #undef STMMAC_XMIT_DEBUG
72 #ifdef STMMAC_TX_DEBUG
73 #define TX_DBG(fmt, args...) printk(fmt, ## args)
75 #define TX_DBG(fmt, args...) do { } while (0)
78 #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
79 #define JUMBO_LEN 9000
87 static int debug = -1;
95 #define DMA_TX_SIZE 256
100 #define DMA_RX_SIZE 256
113 #define TC_DEFAULT 64
121 #ifdef CONFIG_STMMAC_TIMER
122 #define DEFAULT_PERIODIC_RATE 256
123 static int tmrate = DEFAULT_PERIODIC_RATE;
128 #define DMA_BUFFER_SIZE BUF_SIZE_2KiB
137 #define STMMAC_DEFAULT_LPI_TIMER 1000
141 #define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x))
145 #ifdef CONFIG_STMMAC_DEBUG_FS
147 static void stmmac_exit_fs(
void);
155 static void stmmac_verify_args(
void)
202 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
203 static void print_pkt(
unsigned char *
buf,
int len)
206 pr_info(
"len = %d byte, buf addr: 0x%p", len, buf);
207 for (j = 0; j < len; j++) {
217 #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
227 static inline void stmmac_hw_fix_mac_speed(
struct stmmac_priv *priv)
232 priv->
plat->fix_mac_speed(priv->
plat->bsp_priv,
236 static void stmmac_enable_eee_mode(
struct stmmac_priv *priv)
241 priv->
hw->mac->set_eee_mode(priv->
ioaddr);
247 priv->
hw->mac->reset_eee_mode(priv->
ioaddr);
259 static void stmmac_eee_ctrl_timer(
unsigned long arg)
263 stmmac_enable_eee_mode(priv);
293 priv->
hw->mac->set_eee_timer(priv->
ioaddr,
297 pr_info(
"stmmac: Energy-Efficient Ethernet initialized\n");
305 static void stmmac_eee_adjust(
struct stmmac_priv *priv)
331 DBG(probe,
DEBUG,
"stmmac_adjust_link: called. address %d link %d\n",
344 ctrl &= ~priv->
hw->link.duplex;
346 ctrl |= priv->
hw->link.duplex;
356 switch (phydev->
speed) {
359 ctrl &= ~priv->
hw->link.port;
360 stmmac_hw_fix_mac_speed(priv);
364 if (priv->
plat->has_gmac) {
365 ctrl |= priv->
hw->link.port;
367 ctrl |= priv->
hw->link.speed;
369 ctrl &= ~(priv->
hw->link.speed);
372 ctrl &= ~priv->
hw->link.port;
374 stmmac_hw_fix_mac_speed(priv);
402 stmmac_eee_adjust(priv);
404 spin_unlock_irqrestore(&priv->
lock, flags);
406 DBG(probe,
DEBUG,
"stmmac_adjust_link: exiting\n");
417 static int stmmac_init_phy(
struct net_device *dev)
428 if (priv->
plat->phy_bus_name)
430 priv->
plat->phy_bus_name, priv->
plat->bus_id);
436 priv->
plat->phy_addr);
437 pr_debug(
"stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
439 phydev =
phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, 0,
442 if (IS_ERR(phydev)) {
443 pr_err(
"%s: Could not attach to PHY\n", dev->
name);
444 return PTR_ERR(phydev);
460 if (phydev->
phy_id == 0) {
464 pr_debug(
"stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
486 for (i = 0; i <
size; i++) {
487 struct tmp_s *
x = (
struct tmp_s *)(p + i);
488 pr_info(
"\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
490 (
unsigned int)(x->a), (
unsigned int)((x->a) >> 32),
496 static int stmmac_set_bfsize(
int mtu,
int bufsize)
519 static void init_dma_desc_rings(
struct net_device *dev)
528 int des3_as_data_buf = 0;
532 bfsize = priv->
hw->ring->set_16kib_bfsize(dev->
mtu);
535 des3_as_data_buf = 1;
539 #ifdef CONFIG_STMMAC_TIMER
541 if (
likely(priv->tm->enable))
545 DBG(probe,
INFO,
"stmmac: txsize %d, rxsize %d, bfsize %d\n",
546 txsize, rxsize, bfsize);
567 pr_err(
"%s:ERROR allocating the DMA Tx/Rx desc\n", __func__);
571 DBG(probe,
INFO,
"stmmac (%s) DMA desc: virt addr (Rx %p, "
572 "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
577 DBG(probe,
INFO,
"stmmac: SKB addresses:\n"
578 "skb\t\tskb data\tdma data\n");
580 for (i = 0; i < rxsize; i++) {
586 pr_err(
"%s: Rx init fails; skb is NULL\n", __func__);
596 priv->
hw->ring->init_desc3(des3_as_data_buf, p);
607 for (i = 0; i < txsize; i++) {
609 priv->dma_tx[
i].des2 = 0;
615 priv->
hw->ring->init_dma_chain(priv->dma_tx, priv->
dma_tx_phy, txsize);
621 priv->
hw->desc->init_rx_desc(priv->
dma_rx, rxsize, dis_ic);
622 priv->
hw->desc->init_tx_desc(priv->dma_tx, txsize);
625 pr_info(
"RX descriptor ring:\n");
626 display_ring(priv->
dma_rx, rxsize);
627 pr_info(
"TX descriptor ring:\n");
628 display_ring(priv->dma_tx, txsize);
632 static void dma_free_rx_skbufs(
struct stmmac_priv *priv)
646 static void dma_free_tx_skbufs(
struct stmmac_priv *priv)
655 priv->
hw->desc->get_tx_len(p),
663 static void free_dma_desc_resources(
struct stmmac_priv *priv)
666 dma_free_rx_skbufs(priv);
667 dma_free_tx_skbufs(priv);
688 static void stmmac_dma_operation_mode(
struct stmmac_priv *priv)
699 priv->
hw->dma->dma_mode(priv->
ioaddr,
724 if (priv->
hw->desc->get_tx_owner(p))
728 last = priv->
hw->desc->get_tx_ls(p);
731 priv->
hw->desc->tx_status(&priv->
dev->stats,
734 if (
likely(tx_error == 0)) {
735 priv->
dev->stats.tx_packets++;
738 priv->
dev->stats.tx_errors++;
740 TX_DBG(
"%s: curr %d, dirty %d\n", __func__,
745 priv->
hw->desc->get_tx_len(p),
747 priv->
hw->ring->clean_desc3(p);
754 priv->
hw->desc->release_tx_desc(p);
760 netif_tx_lock(priv->
dev);
761 if (netif_queue_stopped(priv->
dev) &&
763 TX_DBG(
"%s: restart transmit\n", __func__);
764 netif_wake_queue(priv->
dev);
766 netif_tx_unlock(priv->
dev);
770 stmmac_enable_eee_mode(priv);
776 static inline void stmmac_enable_irq(
struct stmmac_priv *priv)
778 #ifdef CONFIG_STMMAC_TIMER
779 if (
likely(priv->tm->enable))
780 priv->tm->timer_start(tmrate);
783 priv->
hw->dma->enable_dma_irq(priv->
ioaddr);
786 static inline void stmmac_disable_irq(
struct stmmac_priv *priv)
788 #ifdef CONFIG_STMMAC_TIMER
789 if (
likely(priv->tm->enable))
790 priv->tm->timer_stop();
793 priv->
hw->dma->disable_dma_irq(priv->
ioaddr);
796 static int stmmac_has_work(
struct stmmac_priv *priv)
798 unsigned int has_work = 0;
799 int rxret, tx_work = 0;
801 rxret = priv->
hw->desc->get_rx_owner(priv->
dma_rx +
807 if (
likely(!rxret || tx_work))
813 static inline void _stmmac_schedule(
struct stmmac_priv *priv)
815 if (
likely(stmmac_has_work(priv))) {
816 stmmac_disable_irq(priv);
817 napi_schedule(&priv->
napi);
821 #ifdef CONFIG_STMMAC_TIMER
826 priv->
xstats.sched_timer_n++;
828 _stmmac_schedule(priv);
831 static void stmmac_no_timer_started(
unsigned int x)
835 static void stmmac_no_timer_stopped(
void)
846 static void stmmac_tx_err(
struct stmmac_priv *priv)
848 netif_stop_queue(priv->
dev);
850 priv->
hw->dma->stop_tx(priv->
ioaddr);
851 dma_free_tx_skbufs(priv);
852 priv->
hw->desc->init_tx_desc(priv->dma_tx, priv->
dma_tx_size);
855 priv->
hw->dma->start_tx(priv->
ioaddr);
857 priv->
dev->stats.tx_errors++;
858 netif_wake_queue(priv->
dev);
862 static void stmmac_dma_interrupt(
struct stmmac_priv *priv)
866 status = priv->
hw->dma->dma_interrupt(priv->
ioaddr, &priv->
xstats);
868 _stmmac_schedule(priv);
881 static void stmmac_mmc_setup(
struct stmmac_priv *priv)
894 pr_info(
" No MAC Management Counters available\n");
899 u32 hwid = priv->
hw->synopsys_uid;
904 u32 uid = ((hwid & 0x0000ff00) >> 8);
905 u32 synid = (hwid & 0x000000ff);
907 pr_info(
"stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
920 static void stmmac_selec_desc_mode(
struct stmmac_priv *priv)
922 if (priv->
plat->enh_desc) {
923 pr_info(
" Enhanced/Alternate descriptors\n");
926 pr_info(
" Normal descriptors\n");
940 static int stmmac_get_hw_features(
struct stmmac_priv *priv)
944 if (priv->
hw->dma->get_hw_feature) {
945 hw_cap = priv->
hw->dma->get_hw_feature(priv->
ioaddr);
955 priv->
dma_cap.pmt_remote_wake_up =
957 priv->
dma_cap.pmt_magic_frame =
976 priv->
dma_cap.rxfifo_over_2048 =
979 priv->
dma_cap.number_rx_channel =
981 priv->
dma_cap.number_tx_channel =
992 static void stmmac_check_ether_addr(
struct stmmac_priv *priv)
996 if (!is_valid_ether_addr(priv->
dev->dev_addr)) {
997 priv->
hw->mac->get_umac_addr((
void __iomem *)
998 priv->
dev->base_addr,
999 priv->
dev->dev_addr, 0);
1000 if (!is_valid_ether_addr(priv->
dev->dev_addr))
1001 eth_hw_addr_random(priv->
dev);
1004 priv->
dev->dev_addr);
1007 static int stmmac_init_dma_engine(
struct stmmac_priv *priv)
1010 int mixed_burst = 0;
1015 if (priv->
plat->dma_cfg) {
1016 pbl = priv->
plat->dma_cfg->pbl;
1017 fixed_burst = priv->
plat->dma_cfg->fixed_burst;
1018 mixed_burst = priv->
plat->dma_cfg->mixed_burst;
1019 burst_len = priv->
plat->dma_cfg->burst_len;
1022 return priv->
hw->dma->init(priv->
ioaddr, pbl, fixed_burst, mixed_burst,
1036 static int stmmac_open(
struct net_device *dev)
1041 #ifdef CONFIG_STMMAC_TIMER
1046 priv->tm->freq = tmrate;
1051 pr_warning(
"stmmaceth: cannot attach the external timer.\n");
1053 priv->tm->timer_start = stmmac_no_timer_started;
1054 priv->tm->timer_stop = stmmac_no_timer_stopped;
1056 priv->tm->enable = 1;
1060 stmmac_check_ether_addr(priv);
1062 ret = stmmac_init_phy(dev);
1064 pr_err(
"%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
1072 init_dma_desc_rings(dev);
1075 ret = stmmac_init_dma_engine(priv);
1077 pr_err(
"%s: DMA initialization failed\n", __func__);
1085 if (priv->
plat->bus_setup)
1089 priv->
hw->mac->core_init(priv->
ioaddr);
1095 pr_err(
"%s: ERROR: allocating the IRQ %d (error: %d)\n",
1096 __func__, dev->
irq, ret);
1105 pr_err(
"%s: ERROR: allocating the ext WoL IRQ %d "
1106 "(error: %d)\n", __func__, priv->
wol_irq, ret);
1107 goto open_error_wolirq;
1116 pr_err(
"%s: ERROR: allocating the LPI IRQ %d (%d)\n",
1117 __func__, priv->
lpi_irq, ret);
1118 goto open_error_lpiirq;
1126 stmmac_dma_operation_mode(priv);
1132 stmmac_mmc_setup(priv);
1134 #ifdef CONFIG_STMMAC_DEBUG_FS
1135 ret = stmmac_init_fs(dev);
1137 pr_warning(
"%s: failed debugFS registration\n", __func__);
1140 DBG(probe,
DEBUG,
"%s: DMA RX/TX processes started...\n", dev->
name);
1141 priv->
hw->dma->start_tx(priv->
ioaddr);
1142 priv->
hw->dma->start_rx(priv->
ioaddr);
1144 #ifdef CONFIG_STMMAC_TIMER
1145 priv->tm->timer_start(tmrate);
1150 priv->
hw->mac->dump_regs(priv->
ioaddr);
1151 priv->
hw->dma->dump_regs(priv->
ioaddr);
1160 napi_enable(&priv->
napi);
1161 netif_start_queue(dev);
1173 #ifdef CONFIG_STMMAC_TIMER
1190 static int stmmac_release(
struct net_device *dev)
1204 netif_stop_queue(dev);
1206 #ifdef CONFIG_STMMAC_TIMER
1209 if (priv->tm !=
NULL)
1212 napi_disable(&priv->
napi);
1222 priv->
hw->dma->stop_tx(priv->
ioaddr);
1223 priv->
hw->dma->stop_rx(priv->
ioaddr);
1226 free_dma_desc_resources(priv);
1233 #ifdef CONFIG_STMMAC_DEBUG_FS
1252 int i, csum_insertion = 0;
1253 int nfrags = skb_shinfo(skb)->nr_frags;
1255 unsigned int nopaged_len = skb_headlen(skb);
1257 if (
unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1258 if (!netif_queue_stopped(dev)) {
1259 netif_stop_queue(dev);
1261 pr_err(
"%s: BUG! Tx Ring full when queue awake\n",
1272 entry = priv->
cur_tx % txsize;
1274 #ifdef STMMAC_XMIT_DEBUG
1277 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1278 "\tn_frags: %d - ip_summed: %d - %s gso\n",
1280 !skb_is_gso(skb) ?
"isn't" :
"is");
1285 desc = priv->dma_tx +
entry;
1288 #ifdef STMMAC_XMIT_DEBUG
1290 pr_debug(
"stmmac xmit: skb len: %d, nopaged_len: %d,\n"
1291 "\t\tn_frags: %d, ip_summed: %d\n",
1296 if (priv->
hw->ring->is_jumbo_frm(skb->
len, priv->
plat->enh_desc)) {
1297 entry = priv->
hw->ring->jumbo_frm(priv, skb, csum_insertion);
1298 desc = priv->dma_tx +
entry;
1302 priv->
hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1306 for (i = 0; i < nfrags; i++) {
1308 int len = skb_frag_size(frag);
1310 entry = (++priv->
cur_tx) % txsize;
1311 desc = priv->dma_tx +
entry;
1313 TX_DBG(
"\t[entry %d] segment len: %d\n", entry, len);
1314 desc->
des2 = skb_frag_dma_map(priv->
device, frag, 0, len,
1317 priv->
hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion);
1319 priv->
hw->desc->set_tx_owner(desc);
1324 priv->
hw->desc->close_tx_desc(desc);
1326 #ifdef CONFIG_STMMAC_TIMER
1328 if (
likely(priv->tm->enable))
1329 priv->
hw->desc->clear_tx_ic(desc);
1335 priv->
hw->desc->set_tx_owner(first);
1340 #ifdef STMMAC_XMIT_DEBUG
1342 pr_info(
"stmmac xmit: current=%d, dirty=%d, entry=%d, "
1343 "first=%p, nfrags=%d\n",
1345 entry, first, nfrags);
1346 display_ring(priv->dma_tx, txsize);
1347 pr_info(
">>> frame to be transmitted: ");
1348 print_pkt(skb->
data, skb->
len);
1352 TX_DBG(
"%s: stop transmitted packets\n", __func__);
1353 netif_stop_queue(dev);
1358 skb_tx_timestamp(skb);
1360 priv->
hw->dma->enable_dma_transmission(priv->
ioaddr);
1367 static inline void stmmac_rx_refill(
struct stmmac_priv *priv)
1374 unsigned int entry = priv->
dirty_rx % rxsize;
1378 skb = netdev_alloc_skb_ip_align(priv->
dev, bfsize);
1391 priv->
hw->ring->refill_desc3(bfsize, p + entry);
1396 priv->
hw->desc->set_rx_owner(p + entry);
1404 unsigned int entry = priv->
cur_rx % rxsize;
1405 unsigned int next_entry;
1406 unsigned int count = 0;
1410 #ifdef STMMAC_RX_DEBUG
1412 pr_debug(
">>> stmmac_rx: descriptor ring:\n");
1413 display_ring(priv->
dma_rx, rxsize);
1416 while (!priv->
hw->desc->get_rx_owner(p)) {
1424 next_entry = (++priv->
cur_rx) % rxsize;
1425 p_next = priv->
dma_rx + next_entry;
1429 status = (priv->
hw->desc->rx_status(&priv->
dev->stats,
1432 priv->
dev->stats.rx_errors++;
1437 frame_len = priv->
hw->desc->get_rx_frame_len(p,
1438 priv->
plat->rx_coe);
1443 #ifdef STMMAC_RX_DEBUG
1445 pr_debug(
"\tRX frame size %d, COE status: %d\n",
1449 pr_debug(
"\tdesc: %p [entry %d] buff=0x%x\n",
1454 pr_err(
"%s: Inconsistent Rx descriptor chain\n",
1456 priv->
dev->stats.rx_dropped++;
1466 #ifdef STMMAC_RX_DEBUG
1468 pr_info(
" frame received (%dbytes)", frame_len);
1469 print_pkt(skb->
data, frame_len);
1476 skb_checksum_none_assert(skb);
1483 priv->
dev->stats.rx_packets++;
1484 priv->
dev->stats.rx_bytes += frame_len;
1490 stmmac_rx_refill(priv);
1513 work_done = stmmac_rx(priv, budget);
1515 if (work_done < budget) {
1517 stmmac_enable_irq(priv);
1530 static void stmmac_tx_timeout(
struct net_device *dev)
1535 stmmac_tx_err(priv);
1551 if (map->
irq != dev->
irq) {
1552 pr_warning(
"%s: can't change IRQ number %d\n",
1570 static void stmmac_set_rx_mode(
struct net_device *dev)
1574 spin_lock(&priv->
lock);
1576 spin_unlock(&priv->
lock);
1590 static int stmmac_change_mtu(
struct net_device *dev,
int new_mtu)
1595 if (netif_running(dev)) {
1596 pr_err(
"%s: must be stopped to change its MTU\n", dev->
name);
1600 if (priv->
plat->enh_desc)
1605 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
1606 pr_err(
"%s: invalid MTU, max MTU is: %d\n", dev->
name, max_mtu);
1625 if (!priv->
plat->tx_coe)
1644 pr_err(
"%s: invalid dev pointer\n", __func__);
1649 if (priv->
plat->has_gmac) {
1650 int status = priv->
hw->mac->host_irq_status((
void __iomem *)
1654 priv->
xstats.mmc_tx_irq_n++;
1656 priv->
xstats.mmc_rx_irq_n++;
1658 priv->
xstats.mmc_rx_csum_offload_irq_n++;
1660 priv->
xstats.irq_receive_pmt_irq_n++;
1664 priv->
xstats.irq_tx_path_in_lpi_mode_n++;
1668 priv->
xstats.irq_tx_path_exit_lpi_mode_n++;
1672 priv->
xstats.irq_rx_path_in_lpi_mode_n++;
1674 priv->
xstats.irq_rx_path_exit_lpi_mode_n++;
1679 stmmac_dma_interrupt(priv);
1684 #ifdef CONFIG_NET_POLL_CONTROLLER
1687 static void stmmac_poll_controller(
struct net_device *dev)
1690 stmmac_interrupt(dev->
irq, dev);
1710 if (!netif_running(dev))
1721 #ifdef CONFIG_STMMAC_DEBUG_FS
1722 static struct dentry *stmmac_fs_dir;
1723 static struct dentry *stmmac_rings_status;
1724 static struct dentry *stmmac_dma_cap;
1726 static int stmmac_sysfs_ring_read(
struct seq_file *seq,
void *
v)
1737 seq_printf(seq,
"=======================\n");
1739 seq_printf(seq,
"=======================\n");
1742 struct tmp_s *x = (
struct tmp_s *)(priv->
dma_rx + i);
1743 seq_printf(seq,
"[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1744 i, (
unsigned int)(x->a),
1745 (
unsigned int)((x->a) >> 32), x->b, x->c);
1750 seq_printf(seq,
"=======================\n");
1752 seq_printf(seq,
"=======================\n");
1755 struct tmp_s *x = (
struct tmp_s *)(priv->dma_tx + i);
1756 seq_printf(seq,
"[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1757 i, (
unsigned int)(x->a),
1758 (
unsigned int)((x->a) >> 32), x->b, x->c);
1772 .open = stmmac_sysfs_ring_open,
1778 static int stmmac_sysfs_dma_cap_read(
struct seq_file *seq,
void *v)
1784 seq_printf(seq,
"DMA HW features not supported\n");
1788 seq_printf(seq,
"==============================\n");
1790 seq_printf(seq,
"==============================\n");
1793 (priv->
dma_cap.mbps_10_100) ?
"Y" :
"N");
1795 (priv->
dma_cap.mbps_1000) ?
"Y" :
"N");
1797 (priv->
dma_cap.half_duplex) ?
"Y" :
"N");
1799 (priv->
dma_cap.hash_filter) ?
"Y" :
"N");
1800 seq_printf(seq,
"\tMultiple MAC address registers: %s\n",
1801 (priv->
dma_cap.multi_addr) ?
"Y" :
"N");
1802 seq_printf(seq,
"\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
1803 (priv->
dma_cap.pcs) ?
"Y" :
"N");
1804 seq_printf(seq,
"\tSMA (MDIO) Interface: %s\n",
1805 (priv->
dma_cap.sma_mdio) ?
"Y" :
"N");
1806 seq_printf(seq,
"\tPMT Remote wake up: %s\n",
1807 (priv->
dma_cap.pmt_remote_wake_up) ?
"Y" :
"N");
1809 (priv->
dma_cap.pmt_magic_frame) ?
"Y" :
"N");
1811 (priv->
dma_cap.rmon) ?
"Y" :
"N");
1812 seq_printf(seq,
"\tIEEE 1588-2002 Time Stamp: %s\n",
1813 (priv->
dma_cap.time_stamp) ?
"Y" :
"N");
1814 seq_printf(seq,
"\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
1815 (priv->
dma_cap.atime_stamp) ?
"Y" :
"N");
1816 seq_printf(seq,
"\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
1817 (priv->
dma_cap.eee) ?
"Y" :
"N");
1819 seq_printf(seq,
"\tChecksum Offload in TX: %s\n",
1820 (priv->
dma_cap.tx_coe) ?
"Y" :
"N");
1821 seq_printf(seq,
"\tIP Checksum Offload (type1) in RX: %s\n",
1822 (priv->
dma_cap.rx_coe_type1) ?
"Y" :
"N");
1823 seq_printf(seq,
"\tIP Checksum Offload (type2) in RX: %s\n",
1824 (priv->
dma_cap.rx_coe_type2) ?
"Y" :
"N");
1825 seq_printf(seq,
"\tRXFIFO > 2048bytes: %s\n",
1826 (priv->
dma_cap.rxfifo_over_2048) ?
"Y" :
"N");
1827 seq_printf(seq,
"\tNumber of Additional RX channel: %d\n",
1828 priv->
dma_cap.number_rx_channel);
1829 seq_printf(seq,
"\tNumber of Additional TX channel: %d\n",
1830 priv->
dma_cap.number_tx_channel);
1831 seq_printf(seq,
"\tEnhanced descriptors: %s\n",
1832 (priv->
dma_cap.enh_desc) ?
"Y" :
"N");
1844 .open = stmmac_sysfs_dma_cap_open,
1850 static int stmmac_init_fs(
struct net_device *dev)
1855 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
1856 pr_err(
"ERROR %s, debugfs create directory failed\n",
1865 &stmmac_rings_status_fops);
1867 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
1868 pr_info(
"ERROR creating stmmac ring debugfs file\n");
1876 dev, &stmmac_dma_cap_fops);
1878 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
1879 pr_info(
"ERROR creating stmmac MMC debugfs file\n");
1889 static void stmmac_exit_fs(
void)
1898 .ndo_open = stmmac_open,
1899 .ndo_start_xmit = stmmac_xmit,
1900 .ndo_stop = stmmac_release,
1901 .ndo_change_mtu = stmmac_change_mtu,
1902 .ndo_fix_features = stmmac_fix_features,
1903 .ndo_set_rx_mode = stmmac_set_rx_mode,
1904 .ndo_tx_timeout = stmmac_tx_timeout,
1905 .ndo_do_ioctl = stmmac_ioctl,
1906 .ndo_set_config = stmmac_config,
1907 #ifdef CONFIG_NET_POLL_CONTROLLER
1908 .ndo_poll_controller = stmmac_poll_controller,
1922 static int stmmac_hw_init(
struct stmmac_priv *priv)
1928 if (priv->
plat->has_gmac) {
1948 pr_info(
" DMA HW capability register supported");
1956 priv->
plat->pmt = priv->
dma_cap.pmt_remote_wake_up;
1960 if (priv->
dma_cap.rx_coe_type2)
1962 else if (priv->
dma_cap.rx_coe_type1)
1966 pr_info(
" No HW DMA feature register supported");
1969 stmmac_selec_desc_mode(priv);
1973 ret = priv->
hw->mac->rx_ipc(priv->
ioaddr);
1975 pr_warning(
" RX IPC Checksum Offload not configured.\n");
1979 if (priv->
plat->rx_coe)
1980 pr_info(
" RX Checksum Offload Engine supported (type %d)\n",
1981 priv->
plat->rx_coe);
1982 if (priv->
plat->tx_coe)
1983 pr_info(
" TX Checksum insertion supported\n");
1985 if (priv->
plat->pmt) {
1986 pr_info(
" Wake-Up On Lan supported\n");
2009 ndev = alloc_etherdev(
sizeof(
struct stmmac_priv));
2015 priv = netdev_priv(ndev);
2025 priv->
dev->base_addr = (
unsigned long)addr;
2028 stmmac_verify_args();
2036 stmmac_hw_init(priv);
2044 #ifdef STMMAC_VLAN_TAG_USED
2060 pr_err(
"%s: ERROR %i registering the device\n", __func__, ret);
2061 goto error_netdev_register;
2066 pr_warning(
"%s: warning: cannot get CSR clock\n", __func__);
2076 if (!priv->
plat->clk_csr)
2077 stmmac_clk_csr_set(priv);
2084 pr_debug(
"%s: MDIO bus (id: %d) registration failed",
2085 __func__, priv->
plat->bus_id);
2086 goto error_mdio_register;
2091 error_mdio_register:
2095 error_netdev_register:
2112 pr_info(
"%s:\n\tremoving driver", __func__);
2114 priv->
hw->dma->stop_rx(priv->
ioaddr);
2115 priv->
hw->dma->stop_tx(priv->
ioaddr);
2131 unsigned long flags;
2133 if (!ndev || !netif_running(ndev))
2142 netif_stop_queue(ndev);
2144 #ifdef CONFIG_STMMAC_TIMER
2145 priv->tm->timer_stop();
2146 if (
likely(priv->tm->enable))
2149 napi_disable(&priv->
napi);
2152 priv->
hw->dma->stop_tx(priv->
ioaddr);
2153 priv->
hw->dma->stop_rx(priv->
ioaddr);
2157 priv->
hw->desc->init_tx_desc(priv->dma_tx, priv->
dma_tx_size);
2160 if (device_may_wakeup(priv->
device))
2167 spin_unlock_irqrestore(&priv->
lock, flags);
2174 unsigned long flags;
2176 if (!netif_running(ndev))
2186 if (device_may_wakeup(priv->
device))
2187 priv->
hw->mac->pmt(priv->
ioaddr, 0);
2196 priv->
hw->dma->start_tx(priv->
ioaddr);
2197 priv->
hw->dma->start_rx(priv->
ioaddr);
2199 #ifdef CONFIG_STMMAC_TIMER
2200 if (
likely(priv->tm->enable))
2201 priv->tm->timer_start(tmrate);
2203 napi_enable(&priv->
napi);
2205 netif_start_queue(ndev);
2207 spin_unlock_irqrestore(&priv->
lock, flags);
2217 if (!ndev || !netif_running(ndev))
2220 return stmmac_release(ndev);
2225 if (!ndev || !netif_running(ndev))
2228 return stmmac_open(ndev);
2235 static int __init stmmac_init(
void)
2240 err_plt = stmmac_register_platform();
2241 err_pci = stmmac_register_pci();
2243 if ((err_pci) && (err_plt)) {
2244 pr_err(
"stmmac: driver registration failed\n");
2251 static void __exit stmmac_exit(
void)
2253 stmmac_unregister_platform();
2254 stmmac_unregister_pci();
2261 static int __init stmmac_cmdline_opt(
char *
str)
2268 if (!
strncmp(opt,
"debug:", 6)) {
2271 }
else if (!
strncmp(opt,
"phyaddr:", 8)) {
2274 }
else if (!
strncmp(opt,
"dma_txsize:", 11)) {
2275 if (
kstrtoint(opt + 11, 0, &dma_txsize))
2277 }
else if (!
strncmp(opt,
"dma_rxsize:", 11)) {
2278 if (
kstrtoint(opt + 11, 0, &dma_rxsize))
2280 }
else if (!
strncmp(opt,
"buf_sz:", 7)) {
2283 }
else if (!
strncmp(opt,
"tc:", 3)) {
2286 }
else if (!
strncmp(opt,
"watchdog:", 9)) {
2289 }
else if (!
strncmp(opt,
"flow_ctrl:", 10)) {
2292 }
else if (!
strncmp(opt,
"pause:", 6)) {
2295 }
else if (!
strncmp(opt,
"eee_timer:", 6)) {
2298 #ifdef CONFIG_STMMAC_TIMER
2299 }
else if (!
strncmp(opt,
"tmrate:", 7)) {
2308 pr_err(
"%s: ERROR broken module parameter conversion", __func__);
2312 __setup(
"stmmaceth=", stmmac_cmdline_opt);