33 #include <linux/mii.h>
34 #include <linux/module.h>
36 #include <linux/netdevice.h>
44 #include <linux/tcp.h>
45 #include <linux/udp.h>
50 #include <linux/slab.h>
144 #ifdef CONFIG_PPC_DCR
151 return dcr_read(lp->sdma_dcrs, reg);
157 static void temac_dma_dcr_out(
struct temac_local *lp,
int reg,
u32 value)
159 dcr_write(lp->sdma_dcrs, reg, value);
176 lp->
dma_in = temac_dma_dcr_in;
177 lp->
dma_out = temac_dma_dcr_out;
216 dev_kfree_skb(lp->
rx_skb[i]);
221 sizeof(*lp->
rx_bd_v) * RX_BD_NUM,
234 static int temac_dma_bd_init(
struct net_device *ndev)
243 "can't allocate memory for DMA RX buffer\n");
253 "unable to allocate DMA TX buffer descriptors");
257 sizeof(*lp->
rx_bd_v) * RX_BD_NUM,
261 "unable to allocate DMA RX buffer descriptors");
276 skb = netdev_alloc_skb_ip_align(ndev,
280 dev_err(&ndev->
dev,
"alloc_skb error %d\n", i);
314 temac_dma_bd_release(ndev);
329 if (!is_valid_ether_addr(ndev->
dev_addr))
330 eth_hw_addr_random(ndev);
351 static int netdev_set_mac_address(
struct net_device *ndev,
void *
p)
355 return temac_set_mac_address(ndev, addr->
sa_data);
358 static void temac_set_multicast_list(
struct net_device *ndev)
361 u32 multi_addr_msw, multi_addr_lsw,
val;
375 dev_info(&ndev->
dev,
"Promiscuous mode enabled.\n");
383 multi_addr_msw = ((ha->
addr[3] << 24) |
384 (ha->
addr[2] << 16) |
389 multi_addr_lsw = ((ha->
addr[5] << 8) |
390 (ha->
addr[4]) | (i << 16));
401 dev_info(&ndev->
dev,
"Promiscuous mode disabled.\n");
498 if (options & tp->
opt)
510 static void temac_device_reset(
struct net_device *ndev)
529 if (--timeout == 0) {
531 "temac_device_reset RX reset timeout!!\n");
541 if (--timeout == 0) {
543 "temac_device_reset TX reset timeout!!\n");
557 if (--timeout == 0) {
559 "temac_device_reset DMA reset timeout!!\n");
565 if (temac_dma_bd_init(ndev)) {
567 "temac_device_reset descriptor allocation failed\n");
579 temac_setoptions(ndev,
582 temac_set_mac_address(ndev,
NULL);
585 temac_set_multicast_list(ndev);
586 if (temac_setoptions(ndev, lp->
options))
587 dev_err(&ndev->
dev,
"Error setting TEMAC options\n");
608 switch (phy->
speed) {
622 static void temac_start_xmit_done(
struct net_device *ndev)
626 unsigned int stat = 0;
642 ndev->
stats.tx_packets++;
653 netif_wake_queue(ndev);
656 static inline int temac_check_tx_bd_space(
struct temac_local *lp,
int num_frag)
669 if (tail >= TX_BD_NUM)
674 }
while (num_frag >= 0);
685 unsigned long num_frag;
688 num_frag = skb_shinfo(skb)->nr_frags;
689 frag = &skb_shinfo(skb)->frags[0];
693 if (temac_check_tx_bd_space(lp, num_frag)) {
694 if (!netif_queue_stopped(ndev)) {
695 netif_stop_queue(ndev);
703 unsigned int csum_start_off = skb_checksum_start_offset(skb);
704 unsigned int csum_index_off = csum_start_off + skb->
csum_offset;
707 cur_p->
app1 = (csum_start_off << 16) | csum_index_off;
712 cur_p->
len = skb_headlen(skb);
717 for (ii = 0; ii < num_frag; ii++) {
724 skb_frag_address(frag),
726 cur_p->
len = skb_frag_size(frag);
737 skb_tx_timestamp(skb);
746 static void ll_temac_recv(
struct net_device *ndev)
761 bdstat = cur_p->
app0;
762 while ((bdstat & STS_CTRL_APP0_CMPLT)) {
765 length = cur_p->
app4 & 0x3FFF;
772 skb_checksum_none_assert(skb);
786 ndev->
stats.rx_packets++;
789 new_skb = netdev_alloc_skb_ip_align(ndev,
793 dev_err(&ndev->
dev,
"no memory for new sk_buff\n");
794 spin_unlock_irqrestore(&lp->
rx_lock, flags);
810 bdstat = cur_p->
app0;
814 spin_unlock_irqrestore(&lp->
rx_lock, flags);
817 static irqreturn_t ll_temac_tx_irq(
int irq,
void *_ndev)
827 temac_start_xmit_done(lp->
ndev);
829 dev_err(&ndev->
dev,
"DMA error 0x%x\n", status);
834 static irqreturn_t ll_temac_rx_irq(
int irq,
void *_ndev)
845 ll_temac_recv(lp->
ndev);
850 static int temac_open(
struct net_device *ndev)
861 dev_err(lp->
dev,
"of_phy_connect() failed\n");
868 temac_device_reset(ndev);
889 static int temac_stop(
struct net_device *ndev)
902 temac_dma_bd_release(ndev);
907 #ifdef CONFIG_NET_POLL_CONTROLLER
909 temac_poll_controller(
struct net_device *ndev)
916 ll_temac_rx_irq(lp->
tx_irq, ndev);
917 ll_temac_tx_irq(lp->
rx_irq, ndev);
928 if (!netif_running(ndev))
938 .ndo_open = temac_open,
939 .ndo_stop = temac_stop,
940 .ndo_start_xmit = temac_start_xmit,
941 .ndo_set_mac_address = netdev_set_mac_address,
943 .ndo_do_ioctl = temac_ioctl,
944 #ifdef CONFIG_NET_POLL_CONTROLLER
945 .ndo_poll_controller = temac_poll_controller,
959 for (i = 0; i < 0x11; i++)
961 (i % 8) == 7 ?
"\n" :
" ");
962 len +=
sprintf(buf + len,
"\n");
969 static struct attribute *temac_device_attrs[] = {
970 &dev_attr_llink_regs.attr,
975 .attrs = temac_device_attrs,
991 static int temac_nway_reset(
struct net_device *ndev)
997 static const struct ethtool_ops temac_ethtool_ops = {
998 .get_settings = temac_get_settings,
999 .set_settings = temac_set_settings,
1000 .nway_reset = temac_nway_reset,
1015 ndev = alloc_etherdev(
sizeof(*lp));
1036 ndev->
features |= NETIF_F_MULTI_QUEUE;
1041 lp = netdev_priv(ndev);
1051 dev_err(&op->
dev,
"could not map temac regs.\n");
1070 dev_err(&op->
dev,
"could not find DMA node\n");
1075 if (temac_dcr_setup(lp, op, np)) {
1080 lp->
dma_in = temac_dma_in32;
1081 lp->
dma_out = temac_dma_out32;
1084 dev_err(&op->
dev,
"unable to map DMA registers\n");
1096 dev_err(&op->
dev,
"could not determine irqs\n");
1104 if ((!addr) || (size != 6)) {
1105 dev_err(&op->
dev,
"could not find MAC address\n");
1109 temac_set_mac_address(ndev, (
void *)addr);
1113 dev_warn(&op->
dev,
"error registering MDIO bus\n");
1122 dev_err(lp->
dev,
"Error creating sysfs files\n");
1128 dev_err(lp->
dev,
"register_netdev() error (%i)\n", rc);
1129 goto err_register_ndev;
1167 { .compatible =
"xlnx,xps-ll-temac-1.01.b", },
1168 { .compatible =
"xlnx,xps-ll-temac-2.00.a", },
1169 { .compatible =
"xlnx,xps-ll-temac-2.02.a", },
1170 { .compatible =
"xlnx,xps-ll-temac-2.03.a", },
1176 .probe = temac_of_probe,
1180 .name =
"xilinx_temac",
1181 .of_match_table = temac_of_match,