Lines Matching +full:save +full:- +full:mac +full:- +full:address

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Aeroflex Gaisler GRETH 10/100/1G Ethernet MAC.
5 * 2005-2010 (c) Aeroflex Gaisler AB
21 #include <linux/dma-mapping.h>
54 static int greth_debug = -1; /* -1 == use GRETH_DEF_MSG_ENABLE as value */
58 /* Accept MAC address of the form macaddr=0x08,0x00,0x20,0x30,0x40,0x50 */
61 MODULE_PARM_DESC(macaddr, "GRETH Ethernet MAC address");
101 if (skb_shinfo(skb)->nr_frags == 0) in greth_print_tx_packet()
102 length = skb->len; in greth_print_tx_packet()
107 skb->data, length, true); in greth_print_tx_packet()
109 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in greth_print_tx_packet()
112 skb_frag_address(&skb_shinfo(skb)->frags[i]), in greth_print_tx_packet()
113 skb_frag_size(&skb_shinfo(skb)->frags[i]), true); in greth_print_tx_packet()
120 GRETH_REGORIN(greth->regs->control, GRETH_TXEN); in greth_enable_tx()
126 GRETH_REGORIN(greth->regs->control, GRETH_TXEN | GRETH_TXI); in greth_enable_tx_and_irq()
131 GRETH_REGANDIN(greth->regs->control, ~GRETH_TXEN); in greth_disable_tx()
137 GRETH_REGORIN(greth->regs->control, GRETH_RXEN); in greth_enable_rx()
142 GRETH_REGANDIN(greth->regs->control, ~GRETH_RXEN); in greth_disable_rx()
147 GRETH_REGORIN(greth->regs->control, GRETH_RXI | GRETH_TXI); in greth_enable_irqs()
152 GRETH_REGANDIN(greth->regs->control, ~(GRETH_RXI|GRETH_TXI)); in greth_disable_irqs()
168 struct greth_bd *rx_bdp = greth->rx_bd_base; in greth_clean_rings()
169 struct greth_bd *tx_bdp = greth->tx_bd_base; in greth_clean_rings()
171 if (greth->gbit_mac) { in greth_clean_rings()
175 if (greth->rx_skbuff[i] != NULL) { in greth_clean_rings()
176 dev_kfree_skb(greth->rx_skbuff[i]); in greth_clean_rings()
177 dma_unmap_single(greth->dev, in greth_clean_rings()
178 greth_read_bd(&rx_bdp->addr), in greth_clean_rings()
185 while (greth->tx_free < GRETH_TXBD_NUM) { in greth_clean_rings()
187 struct sk_buff *skb = greth->tx_skbuff[greth->tx_last]; in greth_clean_rings()
188 int nr_frags = skb_shinfo(skb)->nr_frags; in greth_clean_rings()
189 tx_bdp = greth->tx_bd_base + greth->tx_last; in greth_clean_rings()
190 greth->tx_last = NEXT_TX(greth->tx_last); in greth_clean_rings()
192 dma_unmap_single(greth->dev, in greth_clean_rings()
193 greth_read_bd(&tx_bdp->addr), in greth_clean_rings()
198 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in greth_clean_rings()
199 tx_bdp = greth->tx_bd_base + greth->tx_last; in greth_clean_rings()
201 dma_unmap_page(greth->dev, in greth_clean_rings()
202 greth_read_bd(&tx_bdp->addr), in greth_clean_rings()
206 greth->tx_last = NEXT_TX(greth->tx_last); in greth_clean_rings()
208 greth->tx_free += nr_frags+1; in greth_clean_rings()
213 } else { /* 10/100 Mbps MAC */ in greth_clean_rings()
216 kfree(greth->rx_bufs[i]); in greth_clean_rings()
217 dma_unmap_single(greth->dev, in greth_clean_rings()
218 greth_read_bd(&rx_bdp->addr), in greth_clean_rings()
223 kfree(greth->tx_bufs[i]); in greth_clean_rings()
224 dma_unmap_single(greth->dev, in greth_clean_rings()
225 greth_read_bd(&tx_bdp->addr), in greth_clean_rings()
239 rx_bd = greth->rx_bd_base; in greth_init_rings()
240 tx_bd = greth->tx_bd_base; in greth_init_rings()
243 if (greth->gbit_mac) { in greth_init_rings()
246 skb = netdev_alloc_skb(greth->netdev, MAX_FRAME_SIZE+NET_IP_ALIGN); in greth_init_rings()
249 dev_err(greth->dev, "Error allocating DMA ring.\n"); in greth_init_rings()
253 dma_addr = dma_map_single(greth->dev, in greth_init_rings()
254 skb->data, in greth_init_rings()
258 if (dma_mapping_error(greth->dev, dma_addr)) { in greth_init_rings()
260 dev_err(greth->dev, "Could not create initial DMA mapping\n"); in greth_init_rings()
264 greth->rx_skbuff[i] = skb; in greth_init_rings()
271 /* 10/100 MAC uses a fixed set of buffers and copy to/from SKBs */ in greth_init_rings()
274 greth->rx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL); in greth_init_rings()
276 if (greth->rx_bufs[i] == NULL) { in greth_init_rings()
278 dev_err(greth->dev, "Error allocating DMA ring.\n"); in greth_init_rings()
282 dma_addr = dma_map_single(greth->dev, in greth_init_rings()
283 greth->rx_bufs[i], in greth_init_rings()
287 if (dma_mapping_error(greth->dev, dma_addr)) { in greth_init_rings()
289 dev_err(greth->dev, "Could not create initial DMA mapping\n"); in greth_init_rings()
297 greth->tx_bufs[i] = kmalloc(MAX_FRAME_SIZE, GFP_KERNEL); in greth_init_rings()
299 if (greth->tx_bufs[i] == NULL) { in greth_init_rings()
301 dev_err(greth->dev, "Error allocating DMA ring.\n"); in greth_init_rings()
305 dma_addr = dma_map_single(greth->dev, in greth_init_rings()
306 greth->tx_bufs[i], in greth_init_rings()
310 if (dma_mapping_error(greth->dev, dma_addr)) { in greth_init_rings()
312 dev_err(greth->dev, "Could not create initial DMA mapping\n"); in greth_init_rings()
319 greth_write_bd(&rx_bd[GRETH_RXBD_NUM - 1].stat, in greth_init_rings()
320 greth_read_bd(&rx_bd[GRETH_RXBD_NUM - 1].stat) | GRETH_BD_WR); in greth_init_rings()
323 greth->rx_cur = 0; in greth_init_rings()
324 greth->tx_next = 0; in greth_init_rings()
325 greth->tx_last = 0; in greth_init_rings()
326 greth->tx_free = GRETH_TXBD_NUM; in greth_init_rings()
328 /* Initialize descriptor base address */ in greth_init_rings()
329 GRETH_REGSAVE(greth->regs->tx_desc_p, greth->tx_bd_base_phys); in greth_init_rings()
330 GRETH_REGSAVE(greth->regs->rx_desc_p, greth->rx_bd_base_phys); in greth_init_rings()
336 return -ENOMEM; in greth_init_rings()
347 dev_err(&dev->dev, "Could not allocate memory for DMA rings\n"); in greth_open()
351 err = request_irq(greth->irq, greth_interrupt, 0, "eth", (void *) dev); in greth_open()
354 dev_err(&dev->dev, "Could not allocate interrupt %d\n", dev->irq); in greth_open()
360 dev_dbg(&dev->dev, " starting queue\n"); in greth_open()
363 GRETH_REGSAVE(greth->regs->status, 0xFF); in greth_open()
365 napi_enable(&greth->napi); in greth_open()
378 napi_disable(&greth->napi); in greth_close()
386 free_irq(greth->irq, (void *) dev); in greth_close()
403 greth_clean_tx(greth->netdev); in greth_start_xmit()
405 if (unlikely(greth->tx_free <= 0)) { in greth_start_xmit()
406 spin_lock_irqsave(&greth->devlock, flags);/*save from poll/irq*/ in greth_start_xmit()
407 ctrl = GRETH_REGLOAD(greth->regs->control); in greth_start_xmit()
410 GRETH_REGSAVE(greth->regs->control, ctrl | GRETH_TXI); in greth_start_xmit()
412 spin_unlock_irqrestore(&greth->devlock, flags); in greth_start_xmit()
420 if (unlikely(skb->len > MAX_FRAME_SIZE)) { in greth_start_xmit()
421 dev->stats.tx_errors++; in greth_start_xmit()
425 bdp = greth->tx_bd_base + greth->tx_next; in greth_start_xmit()
426 dma_addr = greth_read_bd(&bdp->addr); in greth_start_xmit()
428 memcpy((unsigned char *) phys_to_virt(dma_addr), skb->data, skb->len); in greth_start_xmit()
430 dma_sync_single_for_device(greth->dev, dma_addr, skb->len, DMA_TO_DEVICE); in greth_start_xmit()
432 status = GRETH_BD_EN | GRETH_BD_IE | (skb->len & GRETH_BD_LEN); in greth_start_xmit()
433 greth->tx_bufs_length[greth->tx_next] = skb->len & GRETH_BD_LEN; in greth_start_xmit()
436 if (greth->tx_next == GRETH_TXBD_NUM_MASK) { in greth_start_xmit()
440 greth->tx_next = NEXT_TX(greth->tx_next); in greth_start_xmit()
441 greth->tx_free--; in greth_start_xmit()
444 greth_write_bd(&bdp->stat, status); in greth_start_xmit()
445 spin_lock_irqsave(&greth->devlock, flags); /*save from poll/irq*/ in greth_start_xmit()
447 spin_unlock_irqrestore(&greth->devlock, flags); in greth_start_xmit()
457 return (tx_last - tx_next) - 1; in greth_num_free_bds()
459 return GRETH_TXBD_NUM - (tx_next - tx_last) - 1; in greth_num_free_bds()
472 nr_frags = skb_shinfo(skb)->nr_frags; in greth_start_xmit_gbit()
473 tx_last = greth->tx_last; in greth_start_xmit_gbit()
476 if (greth_num_free_bds(tx_last, greth->tx_next) < nr_frags + 1) { in greth_start_xmit_gbit()
485 if (unlikely(skb->len > MAX_FRAME_SIZE)) { in greth_start_xmit_gbit()
486 dev->stats.tx_errors++; in greth_start_xmit_gbit()
490 /* Save skb pointer. */ in greth_start_xmit_gbit()
491 greth->tx_skbuff[greth->tx_next] = skb; in greth_start_xmit_gbit()
499 if (skb->ip_summed == CHECKSUM_PARTIAL) in greth_start_xmit_gbit()
502 if (greth->tx_next == GRETH_TXBD_NUM_MASK) in greth_start_xmit_gbit()
506 bdp = greth->tx_bd_base + greth->tx_next; in greth_start_xmit_gbit()
507 greth_write_bd(&bdp->stat, status); in greth_start_xmit_gbit()
508 dma_addr = dma_map_single(greth->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE); in greth_start_xmit_gbit()
510 if (unlikely(dma_mapping_error(greth->dev, dma_addr))) in greth_start_xmit_gbit()
513 greth_write_bd(&bdp->addr, dma_addr); in greth_start_xmit_gbit()
515 curr_tx = NEXT_TX(greth->tx_next); in greth_start_xmit_gbit()
519 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in greth_start_xmit_gbit()
520 greth->tx_skbuff[curr_tx] = NULL; in greth_start_xmit_gbit()
521 bdp = greth->tx_bd_base + curr_tx; in greth_start_xmit_gbit()
524 if (skb->ip_summed == CHECKSUM_PARTIAL) in greth_start_xmit_gbit()
533 if (i < nr_frags - 1) in greth_start_xmit_gbit()
538 greth_write_bd(&bdp->stat, status); in greth_start_xmit_gbit()
540 dma_addr = skb_frag_dma_map(greth->dev, frag, 0, skb_frag_size(frag), in greth_start_xmit_gbit()
543 if (unlikely(dma_mapping_error(greth->dev, dma_addr))) in greth_start_xmit_gbit()
546 greth_write_bd(&bdp->addr, dma_addr); in greth_start_xmit_gbit()
554 bdp = greth->tx_bd_base + greth->tx_next; in greth_start_xmit_gbit()
555 greth_write_bd(&bdp->stat, in greth_start_xmit_gbit()
556 greth_read_bd(&bdp->stat) | GRETH_BD_EN); in greth_start_xmit_gbit()
558 spin_lock_irqsave(&greth->devlock, flags); /*save from poll/irq*/ in greth_start_xmit_gbit()
559 greth->tx_next = curr_tx; in greth_start_xmit_gbit()
561 spin_unlock_irqrestore(&greth->devlock, flags); in greth_start_xmit_gbit()
567 for (i = 0; greth->tx_next + i != curr_tx; i++) { in greth_start_xmit_gbit()
568 bdp = greth->tx_bd_base + greth->tx_next + i; in greth_start_xmit_gbit()
569 dma_unmap_single(greth->dev, in greth_start_xmit_gbit()
570 greth_read_bd(&bdp->addr), in greth_start_xmit_gbit()
571 greth_read_bd(&bdp->stat) & GRETH_BD_LEN, in greth_start_xmit_gbit()
573 greth_write_bd(&bdp->stat, 0); in greth_start_xmit_gbit()
577 dev_warn(greth->dev, "Could not create TX DMA mapping\n"); in greth_start_xmit_gbit()
593 spin_lock(&greth->devlock); in greth_interrupt()
596 status = GRETH_REGLOAD(greth->regs->status); in greth_interrupt()
602 ctrl = GRETH_REGLOAD(greth->regs->control); in greth_interrupt()
611 napi_schedule(&greth->napi); in greth_interrupt()
614 spin_unlock(&greth->devlock); in greth_interrupt()
628 bdp = greth->tx_bd_base + greth->tx_last; in greth_clean_tx()
629 GRETH_REGSAVE(greth->regs->status, GRETH_INT_TE | GRETH_INT_TX); in greth_clean_tx()
631 stat = greth_read_bd(&bdp->stat); in greth_clean_tx()
636 if (greth->tx_free == GRETH_TXBD_NUM) in greth_clean_tx()
641 dev->stats.tx_errors++; in greth_clean_tx()
643 dev->stats.tx_aborted_errors++; in greth_clean_tx()
645 dev->stats.tx_fifo_errors++; in greth_clean_tx()
647 dev->stats.tx_packets++; in greth_clean_tx()
648 dev->stats.tx_bytes += greth->tx_bufs_length[greth->tx_last]; in greth_clean_tx()
649 greth->tx_last = NEXT_TX(greth->tx_last); in greth_clean_tx()
650 greth->tx_free++; in greth_clean_tx()
653 if (greth->tx_free > 0) { in greth_clean_tx()
662 dev->stats.tx_errors++; in greth_update_tx_stats()
664 dev->stats.tx_aborted_errors++; in greth_update_tx_stats()
666 dev->stats.tx_fifo_errors++; in greth_update_tx_stats()
668 dev->stats.tx_aborted_errors++; in greth_update_tx_stats()
670 dev->stats.tx_packets++; in greth_update_tx_stats()
683 tx_last = greth->tx_last; in greth_clean_tx_gbit()
685 while (tx_last != greth->tx_next) { in greth_clean_tx_gbit()
687 skb = greth->tx_skbuff[tx_last]; in greth_clean_tx_gbit()
689 nr_frags = skb_shinfo(skb)->nr_frags; in greth_clean_tx_gbit()
692 bdp_last_frag = greth->tx_bd_base + SKIP_TX(tx_last, nr_frags); in greth_clean_tx_gbit()
694 GRETH_REGSAVE(greth->regs->status, GRETH_INT_TE | GRETH_INT_TX); in greth_clean_tx_gbit()
696 stat = greth_read_bd(&bdp_last_frag->stat); in greth_clean_tx_gbit()
701 greth->tx_skbuff[tx_last] = NULL; in greth_clean_tx_gbit()
704 dev->stats.tx_bytes += skb->len; in greth_clean_tx_gbit()
706 bdp = greth->tx_bd_base + tx_last; in greth_clean_tx_gbit()
710 dma_unmap_single(greth->dev, in greth_clean_tx_gbit()
711 greth_read_bd(&bdp->addr), in greth_clean_tx_gbit()
716 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in greth_clean_tx_gbit()
717 bdp = greth->tx_bd_base + tx_last; in greth_clean_tx_gbit()
719 dma_unmap_page(greth->dev, in greth_clean_tx_gbit()
720 greth_read_bd(&bdp->addr), in greth_clean_tx_gbit()
730 greth->tx_last = tx_last; in greth_clean_tx_gbit()
733 (greth_num_free_bds(tx_last, greth->tx_next) > in greth_clean_tx_gbit()
753 bdp = greth->rx_bd_base + greth->rx_cur; in greth_rx()
754 GRETH_REGSAVE(greth->regs->status, GRETH_INT_RE | GRETH_INT_RX); in greth_rx()
756 status = greth_read_bd(&bdp->stat); in greth_rx()
762 dma_addr = greth_read_bd(&bdp->addr); in greth_rx()
768 dev->stats.rx_length_errors++; in greth_rx()
772 dev->stats.rx_frame_errors++; in greth_rx()
776 dev->stats.rx_crc_errors++; in greth_rx()
781 dev->stats.rx_errors++; in greth_rx()
792 dev_warn(&dev->dev, "low on memory - " "packet dropped\n"); in greth_rx()
794 dev->stats.rx_dropped++; in greth_rx()
799 dma_sync_single_for_cpu(greth->dev, in greth_rx()
810 skb->protocol = eth_type_trans(skb, dev); in greth_rx()
811 dev->stats.rx_bytes += pkt_len; in greth_rx()
812 dev->stats.rx_packets++; in greth_rx()
818 if (greth->rx_cur == GRETH_RXBD_NUM_MASK) { in greth_rx()
823 greth_write_bd(&bdp->stat, status); in greth_rx()
825 dma_sync_single_for_device(greth->dev, dma_addr, MAX_FRAME_SIZE, DMA_FROM_DEVICE); in greth_rx()
827 spin_lock_irqsave(&greth->devlock, flags); /* save from XMIT */ in greth_rx()
829 spin_unlock_irqrestore(&greth->devlock, flags); in greth_rx()
831 greth->rx_cur = NEXT_RX(greth->rx_cur); in greth_rx()
869 bdp = greth->rx_bd_base + greth->rx_cur; in greth_rx_gbit()
870 skb = greth->rx_skbuff[greth->rx_cur]; in greth_rx_gbit()
871 GRETH_REGSAVE(greth->regs->status, GRETH_INT_RE | GRETH_INT_RX); in greth_rx_gbit()
873 status = greth_read_bd(&bdp->stat); in greth_rx_gbit()
883 dev->stats.rx_length_errors++; in greth_rx_gbit()
887 dev->stats.rx_frame_errors++; in greth_rx_gbit()
890 dev->stats.rx_crc_errors++; in greth_rx_gbit()
900 dma_addr = dma_map_single(greth->dev, in greth_rx_gbit()
901 newskb->data, in greth_rx_gbit()
905 if (!dma_mapping_error(greth->dev, dma_addr)) { in greth_rx_gbit()
909 dma_unmap_single(greth->dev, in greth_rx_gbit()
910 greth_read_bd(&bdp->addr), in greth_rx_gbit()
915 greth_print_rx_packet(phys_to_virt(greth_read_bd(&bdp->addr)), pkt_len); in greth_rx_gbit()
919 if (dev->features & NETIF_F_RXCSUM && hw_checksummed(status)) in greth_rx_gbit()
920 skb->ip_summed = CHECKSUM_UNNECESSARY; in greth_rx_gbit()
924 skb->protocol = eth_type_trans(skb, dev); in greth_rx_gbit()
925 dev->stats.rx_packets++; in greth_rx_gbit()
926 dev->stats.rx_bytes += pkt_len; in greth_rx_gbit()
929 greth->rx_skbuff[greth->rx_cur] = newskb; in greth_rx_gbit()
930 greth_write_bd(&bdp->addr, dma_addr); in greth_rx_gbit()
933 dev_warn(greth->dev, "Could not create DMA mapping, dropping packet\n"); in greth_rx_gbit()
936 dev->stats.rx_dropped++; in greth_rx_gbit()
940 dev->stats.rx_dropped++; in greth_rx_gbit()
949 dev_warn(greth->dev, "Could not allocate SKB, dropping packet\n"); in greth_rx_gbit()
951 dev->stats.rx_dropped++; in greth_rx_gbit()
955 if (greth->rx_cur == GRETH_RXBD_NUM_MASK) { in greth_rx_gbit()
960 greth_write_bd(&bdp->stat, status); in greth_rx_gbit()
961 spin_lock_irqsave(&greth->devlock, flags); in greth_rx_gbit()
963 spin_unlock_irqrestore(&greth->devlock, flags); in greth_rx_gbit()
964 greth->rx_cur = NEXT_RX(greth->rx_cur); in greth_rx_gbit()
980 if (greth->gbit_mac) { in greth_poll()
981 greth_clean_tx_gbit(greth->netdev); in greth_poll()
982 work_done += greth_rx_gbit(greth->netdev, budget - work_done); in greth_poll()
984 if (netif_queue_stopped(greth->netdev)) in greth_poll()
985 greth_clean_tx(greth->netdev); in greth_poll()
986 work_done += greth_rx(greth->netdev, budget - work_done); in greth_poll()
991 spin_lock_irqsave(&greth->devlock, flags); in greth_poll()
993 ctrl = GRETH_REGLOAD(greth->regs->control); in greth_poll()
994 if ((greth->gbit_mac && (greth->tx_last != greth->tx_next)) || in greth_poll()
995 (!greth->gbit_mac && netif_queue_stopped(greth->netdev))) { in greth_poll()
996 GRETH_REGSAVE(greth->regs->control, in greth_poll()
1001 GRETH_REGSAVE(greth->regs->control, ctrl | GRETH_RXI); in greth_poll()
1005 if (GRETH_REGLOAD(greth->regs->status) & mask) { in greth_poll()
1006 GRETH_REGSAVE(greth->regs->control, ctrl); in greth_poll()
1007 spin_unlock_irqrestore(&greth->devlock, flags); in greth_poll()
1011 spin_unlock_irqrestore(&greth->devlock, flags); in greth_poll()
1025 regs = greth->regs; in greth_set_mac_add()
1027 if (!is_valid_ether_addr(addr->sa_data)) in greth_set_mac_add()
1028 return -EADDRNOTAVAIL; in greth_set_mac_add()
1030 eth_hw_addr_set(dev, addr->sa_data); in greth_set_mac_add()
1031 GRETH_REGSAVE(regs->esa_msb, dev->dev_addr[0] << 8 | dev->dev_addr[1]); in greth_set_mac_add()
1032 GRETH_REGSAVE(regs->esa_lsb, dev->dev_addr[2] << 24 | dev->dev_addr[3] << 16 | in greth_set_mac_add()
1033 dev->dev_addr[4] << 8 | dev->dev_addr[5]); in greth_set_mac_add()
1047 struct greth_regs *regs = greth->regs; in greth_set_hash_filter()
1054 bitnr = greth_hash_get_index(ha->addr); in greth_set_hash_filter()
1058 GRETH_REGSAVE(regs->hash_msb, mc_filter[1]); in greth_set_hash_filter()
1059 GRETH_REGSAVE(regs->hash_lsb, mc_filter[0]); in greth_set_hash_filter()
1066 struct greth_regs *regs = greth->regs; in greth_set_multicast_list()
1068 cfg = GRETH_REGLOAD(regs->control); in greth_set_multicast_list()
1069 if (dev->flags & IFF_PROMISC) in greth_set_multicast_list()
1074 if (greth->multicast) { in greth_set_multicast_list()
1075 if (dev->flags & IFF_ALLMULTI) { in greth_set_multicast_list()
1076 GRETH_REGSAVE(regs->hash_msb, -1); in greth_set_multicast_list()
1077 GRETH_REGSAVE(regs->hash_lsb, -1); in greth_set_multicast_list()
1079 GRETH_REGSAVE(regs->control, cfg); in greth_set_multicast_list()
1085 GRETH_REGSAVE(regs->control, cfg); in greth_set_multicast_list()
1093 GRETH_REGSAVE(regs->control, cfg); in greth_set_multicast_list()
1099 return greth->msg_enable; in greth_get_msglevel()
1105 greth->msg_enable = value; in greth_set_msglevel()
1117 strscpy(info->driver, dev_driver_string(greth->dev), in greth_get_drvinfo()
1118 sizeof(info->driver)); in greth_get_drvinfo()
1119 strscpy(info->bus_info, greth->dev->bus->name, sizeof(info->bus_info)); in greth_get_drvinfo()
1126 u32 __iomem *greth_regs = (u32 __iomem *) greth->regs; in greth_get_regs()
1155 while (GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_BUSY) { in wait_for_mdio()
1164 struct greth_private *greth = bus->priv; in greth_mdio_read()
1168 return -EBUSY; in greth_mdio_read()
1170 GRETH_REGSAVE(greth->regs->mdio, ((phy & 0x1F) << 11) | ((reg & 0x1F) << 6) | 2); in greth_mdio_read()
1173 return -EBUSY; in greth_mdio_read()
1175 if (!(GRETH_REGLOAD(greth->regs->mdio) & GRETH_MII_NVALID)) { in greth_mdio_read()
1176 data = (GRETH_REGLOAD(greth->regs->mdio) >> 16) & 0xFFFF; in greth_mdio_read()
1180 return -1; in greth_mdio_read()
1186 struct greth_private *greth = bus->priv; in greth_mdio_write()
1189 return -EBUSY; in greth_mdio_write()
1191 GRETH_REGSAVE(greth->regs->mdio, in greth_mdio_write()
1195 return -EBUSY; in greth_mdio_write()
1203 struct phy_device *phydev = dev->phydev; in greth_link_change()
1208 spin_lock_irqsave(&greth->devlock, flags); in greth_link_change()
1210 if (phydev->link) { in greth_link_change()
1212 if ((greth->speed != phydev->speed) || (greth->duplex != phydev->duplex)) { in greth_link_change()
1213 ctrl = GRETH_REGLOAD(greth->regs->control) & in greth_link_change()
1216 if (phydev->duplex) in greth_link_change()
1219 if (phydev->speed == SPEED_100) in greth_link_change()
1221 else if (phydev->speed == SPEED_1000) in greth_link_change()
1224 GRETH_REGSAVE(greth->regs->control, ctrl); in greth_link_change()
1225 greth->speed = phydev->speed; in greth_link_change()
1226 greth->duplex = phydev->duplex; in greth_link_change()
1231 if (phydev->link != greth->link) { in greth_link_change()
1232 if (!phydev->link) { in greth_link_change()
1233 greth->speed = 0; in greth_link_change()
1234 greth->duplex = -1; in greth_link_change()
1236 greth->link = phydev->link; in greth_link_change()
1241 spin_unlock_irqrestore(&greth->devlock, flags); in greth_link_change()
1244 if (phydev->link) in greth_link_change()
1246 dev->name, phydev->speed, in greth_link_change()
1247 DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); in greth_link_change()
1249 pr_debug("%s: link down\n", dev->name); in greth_link_change()
1260 phy = phy_find_first(greth->mdio); in greth_mdio_probe()
1264 dev_err(&dev->dev, "no PHY found\n"); in greth_mdio_probe()
1265 return -ENXIO; in greth_mdio_probe()
1269 greth->gbit_mac ? PHY_INTERFACE_MODE_GMII : PHY_INTERFACE_MODE_MII); in greth_mdio_probe()
1272 dev_err(&dev->dev, "could not attach to PHY\n"); in greth_mdio_probe()
1276 if (greth->gbit_mac) in greth_mdio_probe()
1281 linkmode_copy(phy->advertising, phy->supported); in greth_mdio_probe()
1283 greth->link = 0; in greth_mdio_probe()
1284 greth->speed = 0; in greth_mdio_probe()
1285 greth->duplex = -1; in greth_mdio_probe()
1294 struct net_device *ndev = greth->netdev; in greth_mdio_init()
1296 greth->mdio = mdiobus_alloc(); in greth_mdio_init()
1297 if (!greth->mdio) { in greth_mdio_init()
1298 return -ENOMEM; in greth_mdio_init()
1301 greth->mdio->name = "greth-mdio"; in greth_mdio_init()
1302 snprintf(greth->mdio->id, MII_BUS_ID_SIZE, "%s-%d", greth->mdio->name, greth->irq); in greth_mdio_init()
1303 greth->mdio->read = greth_mdio_read; in greth_mdio_init()
1304 greth->mdio->write = greth_mdio_write; in greth_mdio_init()
1305 greth->mdio->priv = greth; in greth_mdio_init()
1307 ret = mdiobus_register(greth->mdio); in greth_mdio_init()
1312 ret = greth_mdio_probe(greth->netdev); in greth_mdio_init()
1315 dev_err(&greth->netdev->dev, "failed to probe MDIO bus\n"); in greth_mdio_init()
1319 phy_start(ndev->phydev); in greth_mdio_init()
1322 if (greth->edcl && greth_edcl == 1) { in greth_mdio_init()
1323 phy_start_aneg(ndev->phydev); in greth_mdio_init()
1325 while (!phy_aneg_done(ndev->phydev) && in greth_mdio_init()
1328 phy_read_status(ndev->phydev); in greth_mdio_init()
1329 greth_link_change(greth->netdev); in greth_mdio_init()
1335 mdiobus_unregister(greth->mdio); in greth_mdio_init()
1337 mdiobus_free(greth->mdio); in greth_mdio_init()
1341 /* Initialize the GRETH MAC */
1357 return -ENOMEM; in greth_of_probe()
1360 greth->netdev = dev; in greth_of_probe()
1361 greth->dev = &ofdev->dev; in greth_of_probe()
1364 greth->msg_enable = greth_debug; in greth_of_probe()
1366 greth->msg_enable = GRETH_DEF_MSG_ENABLE; in greth_of_probe()
1368 spin_lock_init(&greth->devlock); in greth_of_probe()
1370 greth->regs = of_ioremap(&ofdev->resource[0], 0, in greth_of_probe()
1371 resource_size(&ofdev->resource[0]), in greth_of_probe()
1372 "grlib-greth regs"); in greth_of_probe()
1374 if (greth->regs == NULL) { in greth_of_probe()
1376 dev_err(greth->dev, "ioremap failure.\n"); in greth_of_probe()
1377 err = -EIO; in greth_of_probe()
1381 regs = greth->regs; in greth_of_probe()
1382 greth->irq = ofdev->archdata.irqs[0]; in greth_of_probe()
1384 dev_set_drvdata(greth->dev, dev); in greth_of_probe()
1385 SET_NETDEV_DEV(dev, greth->dev); in greth_of_probe()
1388 dev_dbg(greth->dev, "resetting controller.\n"); in greth_of_probe()
1391 GRETH_REGSAVE(regs->control, GRETH_RESET); in greth_of_probe()
1393 /* Wait for MAC to reset itself */ in greth_of_probe()
1395 while (GRETH_REGLOAD(regs->control) & GRETH_RESET) { in greth_of_probe()
1397 err = -EIO; in greth_of_probe()
1399 dev_err(greth->dev, "timeout when waiting for reset.\n"); in greth_of_probe()
1404 /* Get default PHY address */ in greth_of_probe()
1405 greth->phyaddr = (GRETH_REGLOAD(regs->mdio) >> 11) & 0x1F; in greth_of_probe()
1407 /* Check if we have GBIT capable MAC */ in greth_of_probe()
1408 tmp = GRETH_REGLOAD(regs->control); in greth_of_probe()
1409 greth->gbit_mac = (tmp >> 27) & 1; in greth_of_probe()
1412 greth->multicast = (tmp >> 25) & 1; in greth_of_probe()
1414 greth->edcl = (tmp >> 31) & 1; in greth_of_probe()
1416 /* If we have EDCL we disable the EDCL speed-duplex FSM so in greth_of_probe()
1418 if (greth->edcl != 0) in greth_of_probe()
1419 GRETH_REGORIN(regs->control, GRETH_CTRL_DISDUPLEX); in greth_of_probe()
1421 /* Check if MAC can handle MDIO interrupts */ in greth_of_probe()
1422 greth->mdio_int_en = (tmp >> 26) & 1; in greth_of_probe()
1427 dev_err(greth->dev, "failed to register MDIO bus\n"); in greth_of_probe()
1432 greth->tx_bd_base = dma_alloc_coherent(greth->dev, 1024, in greth_of_probe()
1433 &greth->tx_bd_base_phys, in greth_of_probe()
1435 if (!greth->tx_bd_base) { in greth_of_probe()
1436 err = -ENOMEM; in greth_of_probe()
1441 greth->rx_bd_base = dma_alloc_coherent(greth->dev, 1024, in greth_of_probe()
1442 &greth->rx_bd_base_phys, in greth_of_probe()
1444 if (!greth->rx_bd_base) { in greth_of_probe()
1445 err = -ENOMEM; in greth_of_probe()
1449 /* Get MAC address from: module param, OF property or ID prom */ in greth_of_probe()
1455 err = of_get_mac_address(ofdev->dev.of_node, addr); in greth_of_probe()
1462 macaddr[i] = (unsigned int) idprom->id_ethaddr[i]; in greth_of_probe()
1473 if (!is_valid_ether_addr(&dev->dev_addr[0])) { in greth_of_probe()
1475 dev_err(greth->dev, "no valid ethernet address, aborting.\n"); in greth_of_probe()
1476 err = -EINVAL; in greth_of_probe()
1480 GRETH_REGSAVE(regs->esa_msb, dev->dev_addr[0] << 8 | dev->dev_addr[1]); in greth_of_probe()
1481 GRETH_REGSAVE(regs->esa_lsb, dev->dev_addr[2] << 24 | dev->dev_addr[3] << 16 | in greth_of_probe()
1482 dev->dev_addr[4] << 8 | dev->dev_addr[5]); in greth_of_probe()
1485 GRETH_REGSAVE(regs->status, 0xFF); in greth_of_probe()
1487 if (greth->gbit_mac) { in greth_of_probe()
1488 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | in greth_of_probe()
1490 dev->features = dev->hw_features | NETIF_F_HIGHDMA; in greth_of_probe()
1494 if (greth->multicast) { in greth_of_probe()
1496 dev->flags |= IFF_MULTICAST; in greth_of_probe()
1498 dev->flags &= ~IFF_MULTICAST; in greth_of_probe()
1501 dev->netdev_ops = &greth_netdev_ops; in greth_of_probe()
1502 dev->ethtool_ops = &greth_ethtool_ops; in greth_of_probe()
1507 dev_err(greth->dev, "netdevice registration failed.\n"); in greth_of_probe()
1512 netif_napi_add(dev, &greth->napi, greth_poll); in greth_of_probe()
1517 dma_free_coherent(greth->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys); in greth_of_probe()
1519 dma_free_coherent(greth->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys); in greth_of_probe()
1521 mdiobus_unregister(greth->mdio); in greth_of_probe()
1523 of_iounmap(&ofdev->resource[0], greth->regs, resource_size(&ofdev->resource[0])); in greth_of_probe()
1535 dma_free_coherent(&of_dev->dev, 1024, greth->rx_bd_base, greth->rx_bd_base_phys); in greth_of_remove()
1537 dma_free_coherent(&of_dev->dev, 1024, greth->tx_bd_base, greth->tx_bd_base_phys); in greth_of_remove()
1539 if (ndev->phydev) in greth_of_remove()
1540 phy_stop(ndev->phydev); in greth_of_remove()
1541 mdiobus_unregister(greth->mdio); in greth_of_remove()
1545 of_iounmap(&of_dev->resource[0], greth->regs, resource_size(&of_dev->resource[0])); in greth_of_remove()
1564 .name = "grlib-greth",
1574 MODULE_DESCRIPTION("Aeroflex Gaisler Ethernet MAC driver");