Lines Matching refs:greth
45 #include "greth.h"
120 static inline void greth_enable_tx(struct greth_private *greth)
123 GRETH_REGORIN(greth->regs->control, GRETH_TXEN);
126 static inline void greth_disable_tx(struct greth_private *greth)
128 GRETH_REGANDIN(greth->regs->control, ~GRETH_TXEN);
131 static inline void greth_enable_rx(struct greth_private *greth)
134 GRETH_REGORIN(greth->regs->control, GRETH_RXEN);
137 static inline void greth_disable_rx(struct greth_private *greth)
139 GRETH_REGANDIN(greth->regs->control, ~GRETH_RXEN);
142 static inline void greth_enable_irqs(struct greth_private *greth)
144 GRETH_REGORIN(greth->regs->control, GRETH_RXI | GRETH_TXI);
147 static inline void greth_disable_irqs(struct greth_private *greth)
149 GRETH_REGANDIN(greth->regs->control, ~(GRETH_RXI|GRETH_TXI));
162 static void greth_clean_rings(struct greth_private *greth)
165 struct greth_bd *rx_bdp = greth->rx_bd_base;
166 struct greth_bd *tx_bdp = greth->tx_bd_base;
168 if (greth->gbit_mac) {
172 if (greth->rx_skbuff[i] != NULL) {
173 dev_kfree_skb(greth->rx_skbuff[i]);
174 dma_unmap_single(greth->dev,
182 while (greth->tx_free < GRETH_TXBD_NUM) {
184 struct sk_buff *skb = greth->tx_skbuff[greth->tx_last];
186 tx_bdp = greth->tx_bd_base + greth->tx_last;
187 greth->tx_last = NEXT_TX(greth->tx_last);
189 dma_unmap_single(greth->dev,
196 tx_bdp = greth->tx_bd_base + greth->tx_last;
198 dma_unmap_page(greth->dev,
203 greth->tx_last = NEXT_TX(greth->tx_last);
205 greth->tx_free += nr_frags+1;
213 kfree(greth->rx_bufs[i]);
214 dma_unmap_single(greth->dev,
220 kfree(greth->tx_bufs[i]);
221 dma_unmap_single(greth->dev,
229 static int greth_init_rings(struct greth_private *greth)
236 rx_bd = greth->rx_bd_base;
237 tx_bd = greth->tx_bd_base;
240 if (greth->gbit_mac) {
243 skb = netdev_alloc_skb(greth->netdev, MAX_FRAME_SIZE+NET_IP_ALIGN);
245 if (netif_msg_ifup(greth))
246 dev_err(greth->dev, "Error allocating DMA ring.\n");
250 dma_addr = dma_map_single(greth->dev,
255 if (dma_mapping_error(greth->dev, dma_addr)) {
256 if (netif_msg_ifup(greth))
257 dev_err(greth->dev, "Could not create initial DMA mapping\n");
260 greth->rx_skbuff[i] = skb;
270 greth->rx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL);
272 if (greth->rx_bufs[i] == NULL) {
273 if (netif_msg_ifup(greth))
274 dev_err(greth->dev, "Error allocating DMA ring.\n");
278 dma_addr = dma_map_single(greth->dev,
279 greth->rx_bufs[i],
283 if (dma_mapping_error(greth->dev, dma_addr)) {
284 if (netif_msg_ifup(greth))
285 dev_err(greth->dev, "Could not create initial DMA mapping\n");
293 greth->tx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL);
295 if (greth->tx_bufs[i] == NULL) {
296 if (netif_msg_ifup(greth))
297 dev_err(greth->dev, "Error allocating DMA ring.\n");
301 dma_addr = dma_map_single(greth->dev,
302 greth->tx_bufs[i],
306 if (dma_mapping_error(greth->dev, dma_addr)) {
307 if (netif_msg_ifup(greth))
308 dev_err(greth->dev, "Could not create initial DMA mapping\n");
319 greth->rx_cur = 0;
320 greth->tx_next = 0;
321 greth->tx_last = 0;
322 greth->tx_free = GRETH_TXBD_NUM;
325 GRETH_REGSAVE(greth->regs->tx_desc_p, greth->tx_bd_base_phys);
326 GRETH_REGSAVE(greth->regs->rx_desc_p, greth->rx_bd_base_phys);
331 greth_clean_rings(greth);
337 struct greth_private *greth = netdev_priv(dev);
340 err = greth_init_rings(greth);
342 if (netif_msg_ifup(greth))
347 err = request_irq(greth->irq, greth_interrupt, 0, "eth", (void *) dev);
349 if (netif_msg_ifup(greth))
351 greth_clean_rings(greth);
355 if (netif_msg_ifup(greth))
359 napi_enable(&greth->napi);
361 greth_enable_irqs(greth);
362 greth_enable_tx(greth);
363 greth_enable_rx(greth);
370 struct greth_private *greth = netdev_priv(dev);
372 napi_disable(&greth->napi);
374 greth_disable_tx(greth);
378 free_irq(greth->irq, (void *) dev);
380 greth_clean_rings(greth);
388 struct greth_private *greth = netdev_priv(dev);
393 bdp = greth->tx_bd_base + greth->tx_next;
395 if (unlikely(greth->tx_free <= 0)) {
400 if (netif_msg_pktdata(greth))
413 dma_sync_single_for_device(greth->dev, dma_addr, skb->len, DMA_TO_DEVICE);
418 if (greth->tx_next == GRETH_TXBD_NUM_MASK) {
422 greth->tx_next = NEXT_TX(greth->tx_next);
423 greth->tx_free--;
426 if (unlikely(greth->tx_free == 0)) {
432 if (unlikely(greth->tx_free == 0)) {
440 greth_enable_tx(greth);
451 struct greth_private *greth = netdev_priv(dev);
458 if (greth->tx_free < nr_frags + 1) {
464 if (netif_msg_pktdata(greth))
473 greth->tx_skbuff[greth->tx_next] = skb;
481 if (greth->tx_next == GRETH_TXBD_NUM_MASK)
485 bdp = greth->tx_bd_base + greth->tx_next;
487 dma_addr = dma_map_single(greth->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
489 if (unlikely(dma_mapping_error(greth->dev, dma_addr)))
494 curr_tx = NEXT_TX(greth->tx_next);
499 greth->tx_skbuff[curr_tx] = NULL;
500 bdp = greth->tx_bd_base + curr_tx;
514 else if (greth->tx_free - nr_frags - 1 < (MAX_SKB_FRAGS + 1)) {
523 dma_addr = dma_map_page(greth->dev,
529 if (unlikely(dma_mapping_error(greth->dev, dma_addr)))
541 bdp = greth->tx_bd_base + greth->tx_next;
543 greth->tx_next = NEXT_TX(greth->tx_next);
544 greth->tx_free--;
547 greth_enable_tx(greth);
553 for (i = 0; greth->tx_next + i != curr_tx; i++) {
554 bdp = greth->tx_bd_base + greth->tx_next + i;
555 dma_unmap_single(greth->dev,
562 dev_warn(greth->dev, "Could not create TX DMA mapping\n");
572 struct greth_private *greth;
576 greth = netdev_priv(dev);
578 spin_lock(&greth->devlock);
581 status = GRETH_REGLOAD(greth->regs->status);
587 GRETH_REGORIN(greth->regs->status,
593 greth_disable_irqs(greth);
594 napi_schedule(&greth->napi);
598 spin_unlock(&greth->devlock);
605 struct greth_private *greth;
609 greth = netdev_priv(dev);
612 bdp = greth->tx_bd_base + greth->tx_last;
618 if (greth->tx_free == GRETH_TXBD_NUM)
630 greth->tx_last = NEXT_TX(greth->tx_last);
631 greth->tx_free++;
634 if (greth->tx_free > 0) {
657 struct greth_private *greth;
663 greth = netdev_priv(dev);
665 while (greth->tx_free < GRETH_TXBD_NUM) {
667 skb = greth->tx_skbuff[greth->tx_last];
672 bdp_last_frag = greth->tx_bd_base + SKIP_TX(greth->tx_last, nr_frags);
678 greth->tx_skbuff[greth->tx_last] = NULL;
682 bdp = greth->tx_bd_base + greth->tx_last;
684 greth->tx_last = NEXT_TX(greth->tx_last);
686 dma_unmap_single(greth->dev,
693 bdp = greth->tx_bd_base + greth->tx_last;
695 dma_unmap_page(greth->dev,
700 greth->tx_last = NEXT_TX(greth->tx_last);
702 greth->tx_free += nr_frags+1;
705 if (greth->tx_free > (MAX_SKB_FRAGS + 1)) {
710 static int greth_pending_packets(struct greth_private *greth)
714 bdp = greth->rx_bd_base + greth->rx_cur;
724 struct greth_private *greth;
731 greth = netdev_priv(dev);
735 bdp = greth->rx_bd_base + greth->rx_cur;
779 dma_sync_single_for_cpu(greth->dev,
784 if (netif_msg_pktdata(greth))
796 if (greth->rx_cur == GRETH_RXBD_NUM_MASK) {
803 dma_sync_single_for_device(greth->dev, dma_addr, MAX_FRAME_SIZE, DMA_FROM_DEVICE);
805 greth_enable_rx(greth);
807 greth->rx_cur = NEXT_RX(greth->rx_cur);
833 struct greth_private *greth;
840 greth = netdev_priv(dev);
844 bdp = greth->rx_bd_base + greth->rx_cur;
845 skb = greth->rx_skbuff[greth->rx_cur];
874 dma_addr = dma_map_single(greth->dev,
879 if (!dma_mapping_error(greth->dev, dma_addr)) {
883 dma_unmap_single(greth->dev,
888 if (netif_msg_pktdata(greth))
893 if (greth->flags & GRETH_FLAG_RX_CSUM && hw_checksummed(status))
902 greth->rx_skbuff[greth->rx_cur] = newskb;
906 dev_warn(greth->dev, "Could not create DMA mapping, dropping packet\n");
912 dev_warn(greth->dev, "Could not allocate SKB, dropping packet\n");
917 if (greth->rx_cur == GRETH_RXBD_NUM_MASK) {
923 greth_enable_rx(greth);
924 greth->rx_cur = NEXT_RX(greth->rx_cur);
933 struct greth_private *greth;
935 greth = container_of(napi, struct greth_private, napi);
937 if (greth->gbit_mac) {
938 greth_clean_tx_gbit(greth->netdev);
940 greth_clean_tx(greth->netdev);
944 if (greth->gbit_mac) {
945 work_done += greth_rx_gbit(greth->netdev, budget - work_done);
947 work_done += greth_rx(greth->netdev, budget - work_done);
954 if (greth_pending_packets(greth)) {
960 greth_enable_irqs(greth);
967 struct greth_private *greth;
970 greth = netdev_priv(dev);
971 regs = (struct greth_regs *) greth->regs;
993 struct greth_private *greth = netdev_priv(dev);
994 struct greth_regs *regs = (struct greth_regs *) greth->regs;
1012 struct greth_private *greth = netdev_priv(dev);
1013 struct greth_regs *regs = (struct greth_regs *) greth->regs;
1021 if (greth->multicast) {
1045 struct greth_private *greth = netdev_priv(dev);
1046 return greth->msg_enable;
1051 struct greth_private *greth = netdev_priv(dev);
1052 greth->msg_enable = value;
1056 struct greth_private *greth = netdev_priv(dev);
1057 struct phy_device *phy = greth->phy;
1067 struct greth_private *greth = netdev_priv(dev);
1068 struct phy_device *phy = greth->phy;
1083 struct greth_private *greth = netdev_priv(dev);
1085 strncpy(info->driver, dev_driver_string(greth->dev), 32);
1087 strncpy(info->bus_info, greth->dev->bus->name, 32);
1096 struct greth_private *greth = netdev_priv(dev);
1097 u32 __iomem *greth_regs = (u32 __iomem *) greth->regs;
1106 struct greth_private *greth = netdev_priv(dev);
1107 return (greth->flags & GRETH_FLAG_RX_CSUM) != 0;
1112 struct greth_private *greth = netdev_priv(dev);
1114 spin_lock_bh(&greth->devlock);
1117 greth->flags |= GRETH_FLAG_RX_CSUM;
1119 greth->flags &= ~GRETH_FLAG_RX_CSUM;
1121 spin_unlock_bh(&greth->devlock);
1162 static inline int wait_for_mdio(struct greth_private *greth)
1165 while (GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_BUSY) {
1174 struct greth_private *greth = bus->priv;
1177 if (!wait_for_mdio(greth))
1180 GRETH_REGSAVE(greth->regs->mdio, ((phy & 0x1F) << 11) | ((reg & 0x1F) << 6) | 2);
1182 if (!wait_for_mdio(greth))
1185 if (!(GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_NVALID)) {
1186 data = (GRETH_REGLOAD(greth->regs->mdio) >> 16) & 0xFFFF;
1196 struct greth_private *greth = bus->priv;
1198 if (!wait_for_mdio(greth))
1201 GRETH_REGSAVE(greth->regs->mdio,
1204 if (!wait_for_mdio(greth))
1217 struct greth_private *greth = netdev_priv(dev);
1218 struct phy_device *phydev = greth->phy;
1223 spin_lock_irqsave(&greth->devlock, flags);
1227 if ((greth->speed != phydev->speed) || (greth->duplex != phydev->duplex)) {
1229 GRETH_REGANDIN(greth->regs->control,
1233 GRETH_REGORIN(greth->regs->control, GRETH_CTRL_FD);
1237 GRETH_REGORIN(greth->regs->control, GRETH_CTRL_SP);
1241 GRETH_REGORIN(greth->regs->control, GRETH_CTRL_GB);
1243 greth->speed = phydev->speed;
1244 greth->duplex = phydev->duplex;
1249 if (phydev->link != greth->link) {
1251 greth->speed = 0;
1252 greth->duplex = -1;
1254 greth->link = phydev->link;
1259 spin_unlock_irqrestore(&greth->devlock, flags);
1273 struct greth_private *greth = netdev_priv(dev);
1278 phy = phy_find_first(greth->mdio);
1281 if (netif_msg_probe(greth))
1287 0, greth->gbit_mac ?
1291 if (netif_msg_ifup(greth))
1296 if (greth->gbit_mac)
1303 greth->link = 0;
1304 greth->speed = 0;
1305 greth->duplex = -1;
1306 greth->phy = phy;
1320 static int greth_mdio_init(struct greth_private *greth)
1325 greth->mdio = mdiobus_alloc();
1326 if (!greth->mdio) {
1330 greth->mdio->name = "greth-mdio";
1331 snprintf(greth->mdio->id, MII_BUS_ID_SIZE, "%s-%d", greth->mdio->name, greth->irq);
1332 greth->mdio->read = greth_mdio_read;
1333 greth->mdio->write = greth_mdio_write;
1334 greth->mdio->reset = greth_mdio_reset;
1335 greth->mdio->priv = greth;
1337 greth->mdio->irq = greth->mdio_irqs;
1340 greth->mdio->irq[phy] = PHY_POLL;
1342 ret = mdiobus_register(greth->mdio);
1347 ret = greth_mdio_probe(greth->netdev);
1349 if (netif_msg_probe(greth))
1350 dev_err(&greth->netdev->dev, "failed to probe MDIO bus\n");
1354 phy_start(greth->phy);
1357 if (greth->edcl && greth_edcl == 1) {
1358 phy_start_aneg(greth->phy);
1360 while (!phy_aneg_done(greth->phy) && time_before(jiffies, timeout)) {
1362 genphy_read_status(greth->phy);
1363 greth_link_change(greth->netdev);
1369 mdiobus_unregister(greth->mdio);
1371 mdiobus_free(greth->mdio);
1379 struct greth_private *greth;
1392 greth = netdev_priv(dev);
1393 greth->netdev = dev;
1394 greth->dev = &ofdev->dev;
1397 greth->msg_enable = greth_debug;
1399 greth->msg_enable = GRETH_DEF_MSG_ENABLE;
1401 spin_lock_init(&greth->devlock);
1403 greth->regs = of_ioremap(&ofdev->resource[0], 0,
1405 "grlib-greth regs");
1407 if (greth->regs == NULL) {
1408 if (netif_msg_probe(greth))
1409 dev_err(greth->dev, "ioremap failure.\n");
1414 regs = (struct greth_regs *) greth->regs;
1415 greth->irq = ofdev->archdata.irqs[0];
1417 dev_set_drvdata(greth->dev, dev);
1418 SET_NETDEV_DEV(dev, greth->dev);
1420 if (netif_msg_probe(greth))
1421 dev_dbg(greth->dev, "reseting controller.\n");
1431 if (netif_msg_probe(greth))
1432 dev_err(greth->dev, "timeout when waiting for reset.\n");
1438 greth->phyaddr = (GRETH_REGLOAD(regs->mdio) >> 11) & 0x1F;
1442 greth->gbit_mac = (tmp >> 27) & 1;
1445 greth->multicast = (tmp >> 25) & 1;
1447 greth->edcl = (tmp >> 31) & 1;
1451 if (greth->edcl != 0)
1455 greth->mdio_int_en = (tmp >> 26) & 1;
1457 err = greth_mdio_init(greth);
1459 if (netif_msg_probe(greth))
1460 dev_err(greth->dev, "failed to register MDIO bus\n");
1465 greth->tx_bd_base = (struct greth_bd *) dma_alloc_coherent(greth->dev,
1467 &greth->tx_bd_base_phys,
1470 if (!greth->tx_bd_base) {
1471 if (netif_msg_probe(greth))
1477 memset(greth->tx_bd_base, 0, 1024);
1480 greth->rx_bd_base = (struct greth_bd *) dma_alloc_coherent(greth->dev,
1482 &greth->rx_bd_base_phys,
1485 if (!greth->rx_bd_base) {
1486 if (netif_msg_probe(greth))
1487 dev_err(greth->dev, "could not allocate descriptor memory.\n");
1492 memset(greth->rx_bd_base, 0, 1024);
1521 if (netif_msg_probe(greth))
1522 dev_err(greth->dev, "no valid ethernet address, aborting.\n");
1534 if (greth->gbit_mac) {
1537 greth->flags = GRETH_FLAG_RX_CSUM;
1540 if (greth->multicast) {
1551 if (netif_msg_probe(greth))
1552 dev_err(greth->dev, "netdevice registration failed.\n");
1558 netif_napi_add(dev, &greth->napi, greth_poll, 64);
1563 dma_free_coherent(greth->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys);
1565 dma_free_coherent(greth->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys);
1567 mdiobus_unregister(greth->mdio);
1569 of_iounmap(&ofdev->resource[0], greth->regs, resource_size(&ofdev->resource[0]));
1578 struct greth_private *greth = netdev_priv(ndev);
1581 dma_free_coherent(&of_dev->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys);
1583 dma_free_coherent(&of_dev->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys);
1587 if (greth->phy)
1588 phy_stop(greth->phy);
1589 mdiobus_unregister(greth->mdio);
1594 of_iounmap(&of_dev->resource[0], greth->regs, resource_size(&of_dev->resource[0]));
1610 .name = "grlib-greth",