26 #include <linux/module.h>
27 #include <linux/netdevice.h>
34 #include <linux/mii.h>
35 #include <linux/ethtool.h>
44 #define DRIVER_NAME "xaxienet"
45 #define DRIVER_DESCRIPTION "Xilinx Axi Ethernet driver"
46 #define DRIVER_VERSION "1.00a"
48 #define AXIENET_REGS_N 32
52 { .compatible =
"xlnx,axi-ethernet-1.00.a", },
53 { .compatible =
"xlnx,axi-ethernet-1.01.a", },
54 { .compatible =
"xlnx,axi-ethernet-2.01.a", },
160 dev_kfree_skb((
struct sk_buff *)
161 (lp->
rx_bd_v[i].sw_id_offset));
166 sizeof(*lp->
rx_bd_v) * RX_BD_NUM,
189 static int axienet_dma_bd_init(
struct net_device *ndev)
209 dev_err(&ndev->
dev,
"unable to allocate DMA Tx buffer "
215 sizeof(*lp->
rx_bd_v) * RX_BD_NUM,
219 dev_err(&ndev->
dev,
"unable to allocate DMA Rx buffer "
237 skb = netdev_alloc_skb_ip_align(ndev, lp->
max_frm_size);
239 dev_err(&ndev->
dev,
"alloc_skb error %d\n", i);
284 (
sizeof(*lp->
rx_bd_v) * (RX_BD_NUM - 1)));
296 axienet_dma_bd_release(ndev);
314 if (!is_valid_ether_addr(ndev->
dev_addr))
341 static int netdev_set_mac_address(
struct net_device *ndev,
void *
p)
344 axienet_set_mac_address(ndev, addr->
sa_data);
359 static void axienet_set_multicast_list(
struct net_device *ndev)
374 dev_info(&ndev->
dev,
"Promiscuous mode enabled.\n");
383 af0reg = (ha->
addr[0]);
384 af0reg |= (ha->
addr[1] << 8);
385 af0reg |= (ha->
addr[2] << 16);
386 af0reg |= (ha->
addr[3] << 24);
388 af1reg = (ha->
addr[4]);
389 af1reg |= (ha->
addr[5] << 8);
414 dev_info(&ndev->
dev,
"Promiscuous mode disabled.\n");
436 reg = ((axienet_ior(lp, tp->
reg)) & ~(tp->
m_or));
437 if (options & tp->
opt)
439 axienet_iow(lp, tp->
reg, reg);
458 if (--timeout == 0) {
459 dev_err(dev,
"axienet_device_reset DMA "
477 static void axienet_device_reset(
struct net_device *ndev)
496 if (axienet_dma_bd_init(ndev)) {
497 dev_err(&ndev->
dev,
"axienet_device_reset descriptor "
498 "allocation failed\n");
513 axienet_setoptions(ndev, lp->
options &
515 axienet_set_mac_address(ndev,
NULL);
516 axienet_set_multicast_list(ndev);
517 axienet_setoptions(ndev, lp->
options);
530 static void axienet_adjust_link(
struct net_device *ndev)
553 switch (phy->
speed) {
564 dev_err(&ndev->
dev,
"Speed other than 10, 100 "
565 "or 1Gbps is not supported\n");
573 dev_err(&ndev->
dev,
"Error setting Axi Ethernet "
590 static void axienet_start_xmit_done(
struct net_device *ndev)
623 netif_wake_queue(ndev);
639 static inline int axienet_check_tx_bd_space(
struct axienet_local *lp,
673 num_frag = skb_shinfo(skb)->nr_frags;
676 if (axienet_check_tx_bd_space(lp, num_frag)) {
677 if (!netif_queue_stopped(ndev))
678 netif_stop_queue(ndev);
687 csum_start_off = skb_transport_offset(skb);
688 csum_index_off = csum_start_off + skb->
csum_offset;
691 cur_p->
app1 = (csum_start_off << 16) | csum_index_off;
701 for (ii = 0; ii < num_frag; ii++) {
704 frag = &skb_shinfo(skb)->frags[ii];
706 skb_frag_address(frag),
709 cur_p->
cntrl = skb_frag_size(frag);
732 static void axienet_recv(
struct net_device *ndev)
746 while ((cur_p->
status & XAXIDMA_BD_STS_COMPLETE_MASK)) {
748 length = cur_p->
app4 & 0x0000FFFF;
761 csumstatus = (cur_p->
app2 &
779 new_skb = netdev_alloc_skb_ip_align(ndev, lp->
max_frm_size);
781 dev_err(&ndev->
dev,
"no memory for new sk_buff\n");
811 static irqreturn_t axienet_tx_irq(
int irq,
void *_ndev)
820 axienet_start_xmit_done(lp->
ndev);
824 dev_err(&ndev->
dev,
"No interrupts asserted in Tx path");
826 dev_err(&ndev->
dev,
"DMA Tx error 0x%x\n", status);
827 dev_err(&ndev->
dev,
"Current BD is at: 0x%x\n",
832 cr &= (~XAXIDMA_IRQ_ALL_MASK);
838 cr &= (~XAXIDMA_IRQ_ALL_MASK);
859 static irqreturn_t axienet_rx_irq(
int irq,
void *_ndev)
868 axienet_recv(lp->
ndev);
871 if (!(status & XAXIDMA_IRQ_ALL_MASK))
872 dev_err(&ndev->
dev,
"No interrupts asserted in Rx path");
874 dev_err(&ndev->
dev,
"DMA Rx error 0x%x\n", status);
875 dev_err(&ndev->
dev,
"Current BD is at: 0x%x\n",
880 cr &= (~XAXIDMA_IRQ_ALL_MASK);
886 cr &= (~XAXIDMA_IRQ_ALL_MASK);
897 static void axienet_dma_err_handler(
unsigned long data);
912 static int axienet_open(
struct net_device *ndev)
929 axienet_device_reset(ndev);
938 axienet_adjust_link, 0,
941 dev_err(lp->
dev,
"of_phy_connect() failed\n");
983 static int axienet_stop(
struct net_device *ndev)
996 axienet_setoptions(ndev, lp->
options &
1008 axienet_dma_bd_release(ndev);
1023 static int axienet_change_mtu(
struct net_device *ndev,
int new_mtu)
1027 if (netif_running(ndev))
1032 ndev->
mtu = new_mtu;
1034 if ((new_mtu >
XAE_MTU) || (new_mtu < 64))
1036 ndev->
mtu = new_mtu;
1042 #ifdef CONFIG_NET_POLL_CONTROLLER
1050 static void axienet_poll_controller(
struct net_device *ndev)
1055 axienet_rx_irq(lp->
tx_irq, ndev);
1056 axienet_tx_irq(lp->
rx_irq, ndev);
1063 .ndo_open = axienet_open,
1064 .ndo_stop = axienet_stop,
1065 .ndo_start_xmit = axienet_start_xmit,
1066 .ndo_change_mtu = axienet_change_mtu,
1067 .ndo_set_mac_address = netdev_set_mac_address,
1069 .ndo_set_rx_mode = axienet_set_multicast_list,
1070 #ifdef CONFIG_NET_POLL_CONTROLLER
1071 .ndo_poll_controller = axienet_poll_controller,
1085 static int axienet_ethtools_get_settings(
struct net_device *ndev,
1106 static int axienet_ethtools_set_settings(
struct net_device *ndev,
1124 static void axienet_ethtools_get_drvinfo(
struct net_device *ndev,
1141 static int axienet_ethtools_get_regs_len(
struct net_device *ndev)
1156 static void axienet_ethtools_get_regs(
struct net_device *ndev,
1211 axienet_ethtools_get_pauseparam(
struct net_device *ndev,
1233 axienet_ethtools_set_pauseparam(
struct net_device *ndev,
1239 if (netif_running(ndev)) {
1241 "configruation\n", ndev->
name);
1268 static int axienet_ethtools_get_coalesce(
struct net_device *ndev,
1291 static int axienet_ethtools_set_coalesce(
struct net_device *ndev,
1296 if (netif_running(ndev)) {
1298 "configruation\n", ndev->
name);
1332 .get_settings = axienet_ethtools_get_settings,
1333 .set_settings = axienet_ethtools_set_settings,
1334 .get_drvinfo = axienet_ethtools_get_drvinfo,
1335 .get_regs_len = axienet_ethtools_get_regs_len,
1336 .get_regs = axienet_ethtools_get_regs,
1338 .get_pauseparam = axienet_ethtools_get_pauseparam,
1339 .set_pauseparam = axienet_ethtools_set_pauseparam,
1340 .get_coalesce = axienet_ethtools_get_coalesce,
1341 .set_coalesce = axienet_ethtools_set_coalesce,
1351 static void axienet_dma_err_handler(
unsigned long data)
1360 axienet_setoptions(ndev, lp->
options &
1444 (
sizeof(*lp->
rx_bd_v) * (RX_BD_NUM - 1)));
1465 axienet_setoptions(ndev, lp->
options &
1467 axienet_set_mac_address(ndev,
NULL);
1468 axienet_set_multicast_list(ndev);
1469 axienet_setoptions(ndev, lp->
options);
1494 ndev = alloc_etherdev(
sizeof(*lp));
1507 lp = netdev_priv(ndev);
1514 dev_err(&op->
dev,
"could not map Axi Ethernet regs.\n");
1580 dev_err(&op->
dev,
"could not find DMA node\n");
1587 dev_err(&op->
dev,
"unable to map DMA registers\n");
1594 dev_err(&op->
dev,
"could not determine irqs\n");
1601 if ((!addr) || (size != 6)) {
1602 dev_err(&op->
dev,
"could not find MAC address\n");
1606 axienet_set_mac_address(ndev, (
void *) addr);
1614 dev_warn(&op->
dev,
"error registering MDIO bus\n");
1618 dev_err(lp->
dev,
"register_netdev() error (%i)\n", ret);
1658 .probe = axienet_of_probe,
1662 .name =
"xilinx_axienet",
1663 .of_match_table = axienet_of_match,