Lines Matching +full:sierra +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (C) 2003 PMC-Sierra, Inc.,
13 * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org>
15 * Copyright (C) 2004-2006 MontaVista Software, Inc.
21 * Copyright (C) 2007-2008 Marvell Semiconductor
30 #include <linux/dma-mapping.h>
44 #include <linux/phy.h>
71 * Main per-port registers. These live at offset 0x0400 for
141 * Misc per-port registers.
172 #define SKB_DMA_REALIGN ((PAGE_SIZE - NET_SKB_PAD) % SMP_CACHE_BYTES)
179 ((addr >= txq->tso_hdrs_dma) && \
180 (addr < txq->tso_hdrs_dma + txq->tx_ring_size * TSO_HEADER_SIZE))
266 * Per-port MBUS window access register value.
271 * Hardware-specific parameters.
287 /* per-port *****************************************************************/
410 * Hardware-specific parameters.
420 return readl(mp->shared->base + offset); in rdl()
425 return readl(mp->base + offset); in rdlp()
430 writel(data, mp->shared->base + offset); in wrl()
435 writel(data, mp->base + offset); in wrlp()
442 return container_of(rxq, struct mv643xx_eth_private, rxq[rxq->index]); in rxq_to_mp()
447 return container_of(txq, struct mv643xx_eth_private, txq[txq->index]); in txq_to_mp()
453 wrlp(mp, RXQ_COMMAND, 1 << rxq->index); in rxq_enable()
459 u8 mask = 1 << rxq->index; in rxq_disable()
471 addr = (u32)txq->tx_desc_dma; in txq_reset_hw_ptr()
472 addr += txq->tx_curr_desc * sizeof(struct tx_desc); in txq_reset_hw_ptr()
473 wrlp(mp, TXQ_CURRENT_DESC_PTR(txq->index), addr); in txq_reset_hw_ptr()
479 wrlp(mp, TXQ_COMMAND, 1 << txq->index); in txq_enable()
485 u8 mask = 1 << txq->index; in txq_disable()
495 struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); in txq_maybe_wake()
499 if (txq->tx_desc_count <= txq->tx_wake_threshold) in txq_maybe_wake()
508 struct net_device_stats *stats = &mp->dev->stats; in rxq_process()
512 while (rx < budget && rxq->rx_desc_count) { in rxq_process()
518 rx_desc = &rxq->rx_desc_area[rxq->rx_curr_desc]; in rxq_process()
520 cmd_sts = rx_desc->cmd_sts; in rxq_process()
525 skb = rxq->rx_skb[rxq->rx_curr_desc]; in rxq_process()
526 rxq->rx_skb[rxq->rx_curr_desc] = NULL; in rxq_process()
528 rxq->rx_curr_desc++; in rxq_process()
529 if (rxq->rx_curr_desc == rxq->rx_ring_size) in rxq_process()
530 rxq->rx_curr_desc = 0; in rxq_process()
532 dma_unmap_single(mp->dev->dev.parent, rx_desc->buf_ptr, in rxq_process()
533 rx_desc->buf_size, DMA_FROM_DEVICE); in rxq_process()
534 rxq->rx_desc_count--; in rxq_process()
537 mp->work_rx_refill |= 1 << rxq->index; in rxq_process()
539 byte_cnt = rx_desc->byte_cnt; in rxq_process()
549 stats->rx_packets++; in rxq_process()
550 stats->rx_bytes += byte_cnt - 2; in rxq_process()
562 * The -4 is for the CRC in the trailer of the in rxq_process()
565 skb_put(skb, byte_cnt - 2 - 4); in rxq_process()
568 skb->ip_summed = CHECKSUM_UNNECESSARY; in rxq_process()
569 skb->protocol = eth_type_trans(skb, mp->dev); in rxq_process()
571 napi_gro_receive(&mp->napi, skb); in rxq_process()
576 stats->rx_dropped++; in rxq_process()
581 netdev_err(mp->dev, in rxq_process()
586 stats->rx_errors++; in rxq_process()
592 mp->work_rx &= ~(1 << rxq->index); in rxq_process()
603 while (refilled < budget && rxq->rx_desc_count < rxq->rx_ring_size) { in rxq_refill()
609 skb = netdev_alloc_skb(mp->dev, mp->skb_size); in rxq_refill()
612 mp->oom = 1; in rxq_refill()
620 rxq->rx_desc_count++; in rxq_refill()
622 rx = rxq->rx_used_desc++; in rxq_refill()
623 if (rxq->rx_used_desc == rxq->rx_ring_size) in rxq_refill()
624 rxq->rx_used_desc = 0; in rxq_refill()
626 rx_desc = rxq->rx_desc_area + rx; in rxq_refill()
628 size = skb_end_pointer(skb) - skb->data; in rxq_refill()
629 rx_desc->buf_ptr = dma_map_single(mp->dev->dev.parent, in rxq_refill()
630 skb->data, size, in rxq_refill()
632 rx_desc->buf_size = size; in rxq_refill()
633 rxq->rx_skb[rx] = skb; in rxq_refill()
635 rx_desc->cmd_sts = BUFFER_OWNED_BY_DMA | RX_ENABLE_INTERRUPT; in rxq_refill()
641 * IP header ends up 16-byte aligned. in rxq_refill()
647 mp->work_rx_refill &= ~(1 << rxq->index); in rxq_refill()
659 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { in has_tiny_unaligned_frags()
660 const skb_frag_t *fragp = &skb_shinfo(skb)->frags[frag]; in has_tiny_unaligned_frags()
675 if (skb->ip_summed == CHECKSUM_PARTIAL) { in skb_tx_csum()
679 BUG_ON(skb->protocol != htons(ETH_P_IP) && in skb_tx_csum()
680 skb->protocol != htons(ETH_P_8021Q)); in skb_tx_csum()
682 hdr_len = (void *)ip_hdr(skb) - (void *)skb->data; in skb_tx_csum()
683 tag_bytes = hdr_len - ETH_HLEN; in skb_tx_csum()
685 if (length - hdr_len > mp->shared->tx_csum_limit || in skb_tx_csum()
700 ip_hdr(skb)->ihl << TX_IHL_SHIFT; in skb_tx_csum()
705 switch (ip_hdr(skb)->protocol) { in skb_tx_csum()
734 tx_index = txq->tx_curr_desc++; in txq_put_data_tso()
735 if (txq->tx_curr_desc == txq->tx_ring_size) in txq_put_data_tso()
736 txq->tx_curr_desc = 0; in txq_put_data_tso()
737 desc = &txq->tx_desc_area[tx_index]; in txq_put_data_tso()
738 txq->tx_desc_mapping[tx_index] = DESC_DMA_MAP_SINGLE; in txq_put_data_tso()
740 desc->l4i_chk = 0; in txq_put_data_tso()
741 desc->byte_cnt = length; in txq_put_data_tso()
745 memcpy(txq->tso_hdrs + tx_index * TSO_HEADER_SIZE, in txq_put_data_tso()
747 desc->buf_ptr = txq->tso_hdrs_dma in txq_put_data_tso()
751 txq->tx_desc_mapping[tx_index] = DESC_DMA_MAP_SINGLE; in txq_put_data_tso()
752 desc->buf_ptr = dma_map_single(dev->dev.parent, data, in txq_put_data_tso()
754 if (unlikely(dma_mapping_error(dev->dev.parent, in txq_put_data_tso()
755 desc->buf_ptr))) { in txq_put_data_tso()
757 return -ENOMEM; in txq_put_data_tso()
769 desc->cmd_sts = cmd_sts; in txq_put_data_tso()
786 tx_index = txq->tx_curr_desc; in txq_put_hdr_tso()
787 desc = &txq->tx_desc_area[tx_index]; in txq_put_hdr_tso()
796 desc->l4i_chk = 0; in txq_put_hdr_tso()
798 desc->byte_cnt = hdr_len; in txq_put_hdr_tso()
799 desc->buf_ptr = txq->tso_hdrs_dma + in txq_put_hdr_tso()
800 txq->tx_curr_desc * TSO_HEADER_SIZE; in txq_put_hdr_tso()
810 desc->cmd_sts = cmd_sts; in txq_put_hdr_tso()
812 txq->tx_curr_desc++; in txq_put_hdr_tso()
813 if (txq->tx_curr_desc == txq->tx_ring_size) in txq_put_hdr_tso()
814 txq->tx_curr_desc = 0; in txq_put_hdr_tso()
828 if ((txq->tx_desc_count + tso_count_descs(skb)) >= txq->tx_ring_size) { in txq_submit_tso()
830 return -EBUSY; in txq_submit_tso()
833 first_tx_desc = &txq->tx_desc_area[txq->tx_curr_desc]; in txq_submit_tso()
838 total_len = skb->len - hdr_len; in txq_submit_tso()
843 data_left = min_t(int, skb_shinfo(skb)->gso_size, total_len); in txq_submit_tso()
844 total_len -= data_left; in txq_submit_tso()
848 hdr = txq->tso_hdrs + txq->tx_curr_desc * TSO_HEADER_SIZE; in txq_submit_tso()
863 data_left -= size; in txq_submit_tso()
868 __skb_queue_tail(&txq->tx_skb, skb); in txq_submit_tso()
873 first_tx_desc->cmd_sts = first_cmd_sts; in txq_submit_tso()
876 mp->work_tx_end &= ~(1 << txq->index); in txq_submit_tso()
881 txq->tx_desc_count += desc_count; in txq_submit_tso()
885 * be DMA-unmapped. in txq_submit_tso()
893 int nr_frags = skb_shinfo(skb)->nr_frags; in txq_submit_frag_skb()
901 this_frag = &skb_shinfo(skb)->frags[frag]; in txq_submit_frag_skb()
902 tx_index = txq->tx_curr_desc++; in txq_submit_frag_skb()
903 if (txq->tx_curr_desc == txq->tx_ring_size) in txq_submit_frag_skb()
904 txq->tx_curr_desc = 0; in txq_submit_frag_skb()
905 desc = &txq->tx_desc_area[tx_index]; in txq_submit_frag_skb()
906 txq->tx_desc_mapping[tx_index] = DESC_DMA_MAP_PAGE; in txq_submit_frag_skb()
912 if (frag == nr_frags - 1) { in txq_submit_frag_skb()
913 desc->cmd_sts = BUFFER_OWNED_BY_DMA | in txq_submit_frag_skb()
917 desc->cmd_sts = BUFFER_OWNED_BY_DMA; in txq_submit_frag_skb()
920 desc->l4i_chk = 0; in txq_submit_frag_skb()
921 desc->byte_cnt = skb_frag_size(this_frag); in txq_submit_frag_skb()
922 desc->buf_ptr = skb_frag_dma_map(mp->dev->dev.parent, in txq_submit_frag_skb()
923 this_frag, 0, desc->byte_cnt, in txq_submit_frag_skb()
932 int nr_frags = skb_shinfo(skb)->nr_frags; in txq_submit_skb()
942 if (txq->tx_ring_size - txq->tx_desc_count < MAX_SKB_FRAGS + 1) { in txq_submit_skb()
945 return -EBUSY; in txq_submit_skb()
948 ret = skb_tx_csum(mp, skb, &l4i_chk, &cmd_sts, skb->len); in txq_submit_skb()
953 tx_index = txq->tx_curr_desc++; in txq_submit_skb()
954 if (txq->tx_curr_desc == txq->tx_ring_size) in txq_submit_skb()
955 txq->tx_curr_desc = 0; in txq_submit_skb()
956 desc = &txq->tx_desc_area[tx_index]; in txq_submit_skb()
957 txq->tx_desc_mapping[tx_index] = DESC_DMA_MAP_SINGLE; in txq_submit_skb()
964 length = skb->len; in txq_submit_skb()
967 desc->l4i_chk = l4i_chk; in txq_submit_skb()
968 desc->byte_cnt = length; in txq_submit_skb()
969 desc->buf_ptr = dma_map_single(mp->dev->dev.parent, skb->data, in txq_submit_skb()
972 __skb_queue_tail(&txq->tx_skb, skb); in txq_submit_skb()
978 desc->cmd_sts = cmd_sts; in txq_submit_skb()
981 mp->work_tx_end &= ~(1 << txq->index); in txq_submit_skb()
987 txq->tx_desc_count += nr_frags + 1; in txq_submit_skb()
1000 txq = mp->txq + queue; in mv643xx_eth_xmit()
1009 length = skb->len; in mv643xx_eth_xmit()
1016 txq->tx_bytes += length; in mv643xx_eth_xmit()
1017 txq->tx_packets++; in mv643xx_eth_xmit()
1019 if (txq->tx_desc_count >= txq->tx_stop_threshold) in mv643xx_eth_xmit()
1022 txq->tx_dropped++; in mv643xx_eth_xmit()
1034 struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); in txq_kick()
1040 if (rdlp(mp, TXQ_COMMAND) & (1 << txq->index)) in txq_kick()
1043 hw_desc_ptr = rdlp(mp, TXQ_CURRENT_DESC_PTR(txq->index)); in txq_kick()
1044 expected_ptr = (u32)txq->tx_desc_dma + in txq_kick()
1045 txq->tx_curr_desc * sizeof(struct tx_desc); in txq_kick()
1053 mp->work_tx_end &= ~(1 << txq->index); in txq_kick()
1059 struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index); in txq_reclaim()
1065 while (reclaimed < budget && txq->tx_desc_count > 0) { in txq_reclaim()
1071 tx_index = txq->tx_used_desc; in txq_reclaim()
1072 desc = &txq->tx_desc_area[tx_index]; in txq_reclaim()
1073 desc_dma_map = txq->tx_desc_mapping[tx_index]; in txq_reclaim()
1075 cmd_sts = desc->cmd_sts; in txq_reclaim()
1080 desc->cmd_sts = cmd_sts & ~BUFFER_OWNED_BY_DMA; in txq_reclaim()
1083 txq->tx_used_desc = tx_index + 1; in txq_reclaim()
1084 if (txq->tx_used_desc == txq->tx_ring_size) in txq_reclaim()
1085 txq->tx_used_desc = 0; in txq_reclaim()
1088 txq->tx_desc_count--; in txq_reclaim()
1090 if (!IS_TSO_HEADER(txq, desc->buf_ptr)) { in txq_reclaim()
1093 dma_unmap_page(mp->dev->dev.parent, in txq_reclaim()
1094 desc->buf_ptr, in txq_reclaim()
1095 desc->byte_cnt, in txq_reclaim()
1098 dma_unmap_single(mp->dev->dev.parent, in txq_reclaim()
1099 desc->buf_ptr, in txq_reclaim()
1100 desc->byte_cnt, in txq_reclaim()
1105 struct sk_buff *skb = __skb_dequeue(&txq->tx_skb); in txq_reclaim()
1112 netdev_info(mp->dev, "tx error\n"); in txq_reclaim()
1113 mp->dev->stats.tx_errors++; in txq_reclaim()
1121 mp->work_tx &= ~(1 << txq->index); in txq_reclaim()
1138 token_rate = ((rate / 1000) * 64) / (mp->t_clk / 1000); in tx_set_rate()
1142 mtu = (mp->dev->mtu + 255) >> 8; in tx_set_rate()
1150 switch (mp->shared->tx_bw_control) { in tx_set_rate()
1170 token_rate = ((rate / 1000) * 64) / (mp->t_clk / 1000); in txq_set_rate()
1178 wrlp(mp, TXQ_BW_TOKENS(txq->index), token_rate << 14); in txq_set_rate()
1179 wrlp(mp, TXQ_BW_CONF(txq->index), (bucket_size << 10) | token_rate); in txq_set_rate()
1192 switch (mp->shared->tx_bw_control) { in txq_set_fixed_prio_mode()
1203 val |= 1 << txq->index; in txq_set_fixed_prio_mode()
1219 if (dev->phydev->autoneg == AUTONEG_ENABLE) { in mv643xx_eth_adjust_link()
1227 if (dev->phydev->speed == SPEED_1000) { in mv643xx_eth_adjust_link()
1236 if (dev->phydev->speed == SPEED_100) in mv643xx_eth_adjust_link()
1241 if (dev->phydev->duplex == DUPLEX_FULL) in mv643xx_eth_adjust_link()
1254 struct net_device_stats *stats = &dev->stats; in mv643xx_eth_get_stats()
1260 for (i = 0; i < mp->txq_count; i++) { in mv643xx_eth_get_stats()
1261 struct tx_queue *txq = mp->txq + i; in mv643xx_eth_get_stats()
1263 tx_packets += txq->tx_packets; in mv643xx_eth_get_stats()
1264 tx_bytes += txq->tx_bytes; in mv643xx_eth_get_stats()
1265 tx_dropped += txq->tx_dropped; in mv643xx_eth_get_stats()
1268 stats->tx_packets = tx_packets; in mv643xx_eth_get_stats()
1269 stats->tx_bytes = tx_bytes; in mv643xx_eth_get_stats()
1270 stats->tx_dropped = tx_dropped; in mv643xx_eth_get_stats()
1277 return rdl(mp, MIB_COUNTERS(mp->port_num) + offset); in mib_read()
1294 struct mib_counters *p = &mp->mib_counters; in mib_counters_update()
1296 spin_lock_bh(&mp->mib_counters_lock); in mib_counters_update()
1297 p->good_octets_received += mib_read(mp, 0x00); in mib_counters_update()
1298 p->bad_octets_received += mib_read(mp, 0x08); in mib_counters_update()
1299 p->internal_mac_transmit_err += mib_read(mp, 0x0c); in mib_counters_update()
1300 p->good_frames_received += mib_read(mp, 0x10); in mib_counters_update()
1301 p->bad_frames_received += mib_read(mp, 0x14); in mib_counters_update()
1302 p->broadcast_frames_received += mib_read(mp, 0x18); in mib_counters_update()
1303 p->multicast_frames_received += mib_read(mp, 0x1c); in mib_counters_update()
1304 p->frames_64_octets += mib_read(mp, 0x20); in mib_counters_update()
1305 p->frames_65_to_127_octets += mib_read(mp, 0x24); in mib_counters_update()
1306 p->frames_128_to_255_octets += mib_read(mp, 0x28); in mib_counters_update()
1307 p->frames_256_to_511_octets += mib_read(mp, 0x2c); in mib_counters_update()
1308 p->frames_512_to_1023_octets += mib_read(mp, 0x30); in mib_counters_update()
1309 p->frames_1024_to_max_octets += mib_read(mp, 0x34); in mib_counters_update()
1310 p->good_octets_sent += mib_read(mp, 0x38); in mib_counters_update()
1311 p->good_frames_sent += mib_read(mp, 0x40); in mib_counters_update()
1312 p->excessive_collision += mib_read(mp, 0x44); in mib_counters_update()
1313 p->multicast_frames_sent += mib_read(mp, 0x48); in mib_counters_update()
1314 p->broadcast_frames_sent += mib_read(mp, 0x4c); in mib_counters_update()
1315 p->unrec_mac_control_received += mib_read(mp, 0x50); in mib_counters_update()
1316 p->fc_sent += mib_read(mp, 0x54); in mib_counters_update()
1317 p->good_fc_received += mib_read(mp, 0x58); in mib_counters_update()
1318 p->bad_fc_received += mib_read(mp, 0x5c); in mib_counters_update()
1319 p->undersize_received += mib_read(mp, 0x60); in mib_counters_update()
1320 p->fragments_received += mib_read(mp, 0x64); in mib_counters_update()
1321 p->oversize_received += mib_read(mp, 0x68); in mib_counters_update()
1322 p->jabber_received += mib_read(mp, 0x6c); in mib_counters_update()
1323 p->mac_receive_error += mib_read(mp, 0x70); in mib_counters_update()
1324 p->bad_crc_event += mib_read(mp, 0x74); in mib_counters_update()
1325 p->collision += mib_read(mp, 0x78); in mib_counters_update()
1326 p->late_collision += mib_read(mp, 0x7c); in mib_counters_update()
1328 p->rx_discard += rdlp(mp, RX_DISCARD_FRAME_CNT); in mib_counters_update()
1329 p->rx_overrun += rdlp(mp, RX_OVERRUN_FRAME_CNT); in mib_counters_update()
1330 spin_unlock_bh(&mp->mib_counters_lock); in mib_counters_update()
1337 mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ); in mib_counters_timer_wrapper()
1350 * In the ->set*() methods, we round the computed register value
1358 if (mp->shared->extended_rx_coal_limit) in get_rx_coal()
1364 temp += mp->t_clk / 2; in get_rx_coal()
1365 do_div(temp, mp->t_clk); in get_rx_coal()
1375 temp = (u64)usec * mp->t_clk; in set_rx_coal()
1380 if (mp->shared->extended_rx_coal_limit) { in set_rx_coal()
1401 temp += mp->t_clk / 2; in get_tx_coal()
1402 do_div(temp, mp->t_clk); in get_tx_coal()
1411 temp = (u64)usec * mp->t_clk; in set_tx_coal()
1432 offsetof(struct net_device, stats.m), -1 }
1436 -1, offsetof(struct mv643xx_eth_private, mib_counters.m) }
1485 struct net_device *dev = mp->dev; in mv643xx_eth_get_link_ksettings_phy()
1487 phy_ethtool_ksettings_get(dev->phydev, cmd); in mv643xx_eth_get_link_ksettings_phy()
1493 cmd->link_modes.supported); in mv643xx_eth_get_link_ksettings_phy()
1495 cmd->link_modes.advertising); in mv643xx_eth_get_link_ksettings_phy()
1513 cmd->base.speed = SPEED_10; in mv643xx_eth_get_link_ksettings_phyless()
1516 cmd->base.speed = SPEED_100; in mv643xx_eth_get_link_ksettings_phyless()
1519 cmd->base.speed = SPEED_1000; in mv643xx_eth_get_link_ksettings_phyless()
1522 cmd->base.speed = -1; in mv643xx_eth_get_link_ksettings_phyless()
1525 cmd->base.duplex = (port_status & FULL_DUPLEX) ? in mv643xx_eth_get_link_ksettings_phyless()
1527 cmd->base.port = PORT_MII; in mv643xx_eth_get_link_ksettings_phyless()
1528 cmd->base.phy_address = 0; in mv643xx_eth_get_link_ksettings_phyless()
1529 cmd->base.autoneg = AUTONEG_DISABLE; in mv643xx_eth_get_link_ksettings_phyless()
1531 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, in mv643xx_eth_get_link_ksettings_phyless()
1533 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, in mv643xx_eth_get_link_ksettings_phyless()
1542 wol->supported = 0; in mv643xx_eth_get_wol()
1543 wol->wolopts = 0; in mv643xx_eth_get_wol()
1544 if (dev->phydev) in mv643xx_eth_get_wol()
1545 phy_ethtool_get_wol(dev->phydev, wol); in mv643xx_eth_get_wol()
1553 if (!dev->phydev) in mv643xx_eth_set_wol()
1554 return -EOPNOTSUPP; in mv643xx_eth_set_wol()
1556 err = phy_ethtool_set_wol(dev->phydev, wol); in mv643xx_eth_set_wol()
1557 /* Given that mv643xx_eth works without the marvell-specific PHY driver, in mv643xx_eth_set_wol()
1560 if (err == -EOPNOTSUPP) in mv643xx_eth_set_wol()
1561 netdev_info(dev, "The PHY does not support set_wol, was CONFIG_MARVELL_PHY enabled?\n"); in mv643xx_eth_set_wol()
1571 if (dev->phydev) in mv643xx_eth_get_link_ksettings()
1585 if (!dev->phydev) in mv643xx_eth_set_link_ksettings()
1586 return -EINVAL; in mv643xx_eth_set_link_ksettings()
1597 ret = phy_ethtool_ksettings_set(dev->phydev, &c); in mv643xx_eth_set_link_ksettings()
1606 strscpy(drvinfo->driver, mv643xx_eth_driver_name, in mv643xx_eth_get_drvinfo()
1607 sizeof(drvinfo->driver)); in mv643xx_eth_get_drvinfo()
1608 strscpy(drvinfo->version, mv643xx_eth_driver_version, in mv643xx_eth_get_drvinfo()
1609 sizeof(drvinfo->version)); in mv643xx_eth_get_drvinfo()
1610 strscpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); in mv643xx_eth_get_drvinfo()
1611 strscpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info)); in mv643xx_eth_get_drvinfo()
1621 ec->rx_coalesce_usecs = get_rx_coal(mp); in mv643xx_eth_get_coalesce()
1622 ec->tx_coalesce_usecs = get_tx_coal(mp); in mv643xx_eth_get_coalesce()
1634 set_rx_coal(mp, ec->rx_coalesce_usecs); in mv643xx_eth_set_coalesce()
1635 set_tx_coal(mp, ec->tx_coalesce_usecs); in mv643xx_eth_set_coalesce()
1647 er->rx_max_pending = 4096; in mv643xx_eth_get_ringparam()
1648 er->tx_max_pending = 4096; in mv643xx_eth_get_ringparam()
1650 er->rx_pending = mp->rx_ring_size; in mv643xx_eth_get_ringparam()
1651 er->tx_pending = mp->tx_ring_size; in mv643xx_eth_get_ringparam()
1661 if (er->rx_mini_pending || er->rx_jumbo_pending) in mv643xx_eth_set_ringparam()
1662 return -EINVAL; in mv643xx_eth_set_ringparam()
1664 mp->rx_ring_size = min(er->rx_pending, 4096U); in mv643xx_eth_set_ringparam()
1665 mp->tx_ring_size = clamp_t(unsigned int, er->tx_pending, in mv643xx_eth_set_ringparam()
1667 if (mp->tx_ring_size != er->tx_pending) in mv643xx_eth_set_ringparam()
1669 mp->tx_ring_size, er->tx_pending); in mv643xx_eth_set_ringparam()
1675 "fatal error on re-opening device after ring param change\n"); in mv643xx_eth_set_ringparam()
1676 return -ENOMEM; in mv643xx_eth_set_ringparam()
1725 if (stat->netdev_off >= 0) in mv643xx_eth_get_ethtool_stats()
1726 p = ((void *)mp->dev) + stat->netdev_off; in mv643xx_eth_get_ethtool_stats()
1728 p = ((void *)mp) + stat->mp_off; in mv643xx_eth_get_ethtool_stats()
1730 data[i] = (stat->sizeof_stat == 8) ? in mv643xx_eth_get_ethtool_stats()
1740 return -EOPNOTSUPP; in mv643xx_eth_get_sset_count()
1789 if (dev->flags & IFF_PROMISC) in uc_addr_filter_mask()
1792 nibbles = 1 << (dev->dev_addr[5] & 0x0f); in uc_addr_filter_mask()
1794 if (memcmp(dev->dev_addr, ha->addr, 5)) in uc_addr_filter_mask()
1796 if ((dev->dev_addr[5] ^ ha->addr[5]) & 0xf0) in uc_addr_filter_mask()
1799 nibbles |= 1 << (ha->addr[5] & 0x0f); in uc_addr_filter_mask()
1812 uc_addr_set(mp, dev->dev_addr); in mv643xx_eth_program_unicast_filter()
1823 int off = UNICAST_TABLE(mp->port_num) + i; in mv643xx_eth_program_unicast_filter()
1852 for (j = 7; j >= 0; j--) { in addr_crc()
1869 if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) in mv643xx_eth_program_multicast_filter()
1879 u8 *a = ha->addr; in mv643xx_eth_program_multicast_filter()
1895 wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32), in mv643xx_eth_program_multicast_filter()
1897 wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32), in mv643xx_eth_program_multicast_filter()
1906 wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32), in mv643xx_eth_program_multicast_filter()
1908 wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32), in mv643xx_eth_program_multicast_filter()
1923 if (!is_valid_ether_addr(sa->sa_data)) in mv643xx_eth_set_mac_address()
1924 return -EADDRNOTAVAIL; in mv643xx_eth_set_mac_address()
1926 eth_hw_addr_set(dev, sa->sa_data); in mv643xx_eth_set_mac_address()
1939 struct rx_queue *rxq = mp->rxq + index; in rxq_init()
1944 rxq->index = index; in rxq_init()
1946 rxq->rx_ring_size = mp->rx_ring_size; in rxq_init()
1948 rxq->rx_desc_count = 0; in rxq_init()
1949 rxq->rx_curr_desc = 0; in rxq_init()
1950 rxq->rx_used_desc = 0; in rxq_init()
1952 size = rxq->rx_ring_size * sizeof(struct rx_desc); in rxq_init()
1954 if (index == 0 && size <= mp->rx_desc_sram_size) { in rxq_init()
1955 rxq->rx_desc_area = ioremap(mp->rx_desc_sram_addr, in rxq_init()
1956 mp->rx_desc_sram_size); in rxq_init()
1957 rxq->rx_desc_dma = mp->rx_desc_sram_addr; in rxq_init()
1959 rxq->rx_desc_area = dma_alloc_coherent(mp->dev->dev.parent, in rxq_init()
1960 size, &rxq->rx_desc_dma, in rxq_init()
1964 if (rxq->rx_desc_area == NULL) { in rxq_init()
1965 netdev_err(mp->dev, in rxq_init()
1969 memset(rxq->rx_desc_area, 0, size); in rxq_init()
1971 rxq->rx_desc_area_size = size; in rxq_init()
1972 rxq->rx_skb = kcalloc(rxq->rx_ring_size, sizeof(*rxq->rx_skb), in rxq_init()
1974 if (rxq->rx_skb == NULL) in rxq_init()
1977 rx_desc = rxq->rx_desc_area; in rxq_init()
1978 for (i = 0; i < rxq->rx_ring_size; i++) { in rxq_init()
1982 if (nexti == rxq->rx_ring_size) in rxq_init()
1985 rx_desc[i].next_desc_ptr = rxq->rx_desc_dma + in rxq_init()
1993 if (index == 0 && size <= mp->rx_desc_sram_size) in rxq_init()
1994 iounmap(rxq->rx_desc_area); in rxq_init()
1996 dma_free_coherent(mp->dev->dev.parent, size, in rxq_init()
1997 rxq->rx_desc_area, in rxq_init()
1998 rxq->rx_desc_dma); in rxq_init()
2001 return -ENOMEM; in rxq_init()
2011 for (i = 0; i < rxq->rx_ring_size; i++) { in rxq_deinit()
2012 if (rxq->rx_skb[i]) { in rxq_deinit()
2013 dev_consume_skb_any(rxq->rx_skb[i]); in rxq_deinit()
2014 rxq->rx_desc_count--; in rxq_deinit()
2018 if (rxq->rx_desc_count) { in rxq_deinit()
2019 netdev_err(mp->dev, "error freeing rx ring -- %d skbs stuck\n", in rxq_deinit()
2020 rxq->rx_desc_count); in rxq_deinit()
2023 if (rxq->index == 0 && in rxq_deinit()
2024 rxq->rx_desc_area_size <= mp->rx_desc_sram_size) in rxq_deinit()
2025 iounmap(rxq->rx_desc_area); in rxq_deinit()
2027 dma_free_coherent(mp->dev->dev.parent, rxq->rx_desc_area_size, in rxq_deinit()
2028 rxq->rx_desc_area, rxq->rx_desc_dma); in rxq_deinit()
2030 kfree(rxq->rx_skb); in rxq_deinit()
2035 struct tx_queue *txq = mp->txq + index; in txq_init()
2041 txq->index = index; in txq_init()
2043 txq->tx_ring_size = mp->tx_ring_size; in txq_init()
2049 txq->tx_stop_threshold = txq->tx_ring_size - MV643XX_MAX_SKB_DESCS; in txq_init()
2050 txq->tx_wake_threshold = txq->tx_stop_threshold / 2; in txq_init()
2052 txq->tx_desc_count = 0; in txq_init()
2053 txq->tx_curr_desc = 0; in txq_init()
2054 txq->tx_used_desc = 0; in txq_init()
2056 size = txq->tx_ring_size * sizeof(struct tx_desc); in txq_init()
2058 if (index == 0 && size <= mp->tx_desc_sram_size) { in txq_init()
2059 txq->tx_desc_area = ioremap(mp->tx_desc_sram_addr, in txq_init()
2060 mp->tx_desc_sram_size); in txq_init()
2061 txq->tx_desc_dma = mp->tx_desc_sram_addr; in txq_init()
2063 txq->tx_desc_area = dma_alloc_coherent(mp->dev->dev.parent, in txq_init()
2064 size, &txq->tx_desc_dma, in txq_init()
2068 if (txq->tx_desc_area == NULL) { in txq_init()
2069 netdev_err(mp->dev, in txq_init()
2071 return -ENOMEM; in txq_init()
2073 memset(txq->tx_desc_area, 0, size); in txq_init()
2075 txq->tx_desc_area_size = size; in txq_init()
2077 tx_desc = txq->tx_desc_area; in txq_init()
2078 for (i = 0; i < txq->tx_ring_size; i++) { in txq_init()
2083 if (nexti == txq->tx_ring_size) in txq_init()
2086 txd->cmd_sts = 0; in txq_init()
2087 txd->next_desc_ptr = txq->tx_desc_dma + in txq_init()
2091 txq->tx_desc_mapping = kcalloc(txq->tx_ring_size, sizeof(char), in txq_init()
2093 if (!txq->tx_desc_mapping) { in txq_init()
2094 ret = -ENOMEM; in txq_init()
2099 txq->tso_hdrs = dma_alloc_coherent(mp->dev->dev.parent, in txq_init()
2100 txq->tx_ring_size * TSO_HEADER_SIZE, in txq_init()
2101 &txq->tso_hdrs_dma, GFP_KERNEL); in txq_init()
2102 if (txq->tso_hdrs == NULL) { in txq_init()
2103 ret = -ENOMEM; in txq_init()
2106 skb_queue_head_init(&txq->tx_skb); in txq_init()
2111 kfree(txq->tx_desc_mapping); in txq_init()
2113 if (index == 0 && size <= mp->tx_desc_sram_size) in txq_init()
2114 iounmap(txq->tx_desc_area); in txq_init()
2116 dma_free_coherent(mp->dev->dev.parent, txq->tx_desc_area_size, in txq_init()
2117 txq->tx_desc_area, txq->tx_desc_dma); in txq_init()
2126 txq_reclaim(txq, txq->tx_ring_size, 1); in txq_deinit()
2128 BUG_ON(txq->tx_used_desc != txq->tx_curr_desc); in txq_deinit()
2130 if (txq->index == 0 && in txq_deinit()
2131 txq->tx_desc_area_size <= mp->tx_desc_sram_size) in txq_deinit()
2132 iounmap(txq->tx_desc_area); in txq_deinit()
2134 dma_free_coherent(mp->dev->dev.parent, txq->tx_desc_area_size, in txq_deinit()
2135 txq->tx_desc_area, txq->tx_desc_dma); in txq_deinit()
2136 kfree(txq->tx_desc_mapping); in txq_deinit()
2138 if (txq->tso_hdrs) in txq_deinit()
2139 dma_free_coherent(mp->dev->dev.parent, in txq_deinit()
2140 txq->tx_ring_size * TSO_HEADER_SIZE, in txq_deinit()
2141 txq->tso_hdrs, txq->tso_hdrs_dma); in txq_deinit()
2151 int_cause = rdlp(mp, INT_CAUSE) & mp->int_mask; in mv643xx_eth_collect_events()
2163 mp->work_tx_end |= ((int_cause & INT_TX_END) >> 19) & in mv643xx_eth_collect_events()
2165 mp->work_rx |= (int_cause & INT_RX) >> 2; in mv643xx_eth_collect_events()
2172 mp->work_link = 1; in mv643xx_eth_collect_events()
2173 mp->work_tx |= int_cause_ext & INT_EXT_TX; in mv643xx_eth_collect_events()
2188 napi_schedule(&mp->napi); in mv643xx_eth_irq()
2195 struct net_device *dev = mp->dev; in handle_link_event()
2210 for (i = 0; i < mp->txq_count; i++) { in handle_link_event()
2211 struct tx_queue *txq = mp->txq + i; in handle_link_event()
2213 txq_reclaim(txq, txq->tx_ring_size, 1); in handle_link_event()
2231 speed = -1; in handle_link_event()
2251 if (unlikely(mp->oom)) { in mv643xx_eth_poll()
2252 mp->oom = 0; in mv643xx_eth_poll()
2253 del_timer(&mp->rx_oom); in mv643xx_eth_poll()
2262 if (mp->work_link) { in mv643xx_eth_poll()
2263 mp->work_link = 0; in mv643xx_eth_poll()
2269 queue_mask = mp->work_tx | mp->work_tx_end | mp->work_rx; in mv643xx_eth_poll()
2270 if (likely(!mp->oom)) in mv643xx_eth_poll()
2271 queue_mask |= mp->work_rx_refill; in mv643xx_eth_poll()
2279 queue = fls(queue_mask) - 1; in mv643xx_eth_poll()
2282 work_tbd = budget - work_done; in mv643xx_eth_poll()
2286 if (mp->work_tx_end & queue_mask) { in mv643xx_eth_poll()
2287 txq_kick(mp->txq + queue); in mv643xx_eth_poll()
2288 } else if (mp->work_tx & queue_mask) { in mv643xx_eth_poll()
2289 work_done += txq_reclaim(mp->txq + queue, work_tbd, 0); in mv643xx_eth_poll()
2290 txq_maybe_wake(mp->txq + queue); in mv643xx_eth_poll()
2291 } else if (mp->work_rx & queue_mask) { in mv643xx_eth_poll()
2292 work_done += rxq_process(mp->rxq + queue, work_tbd); in mv643xx_eth_poll()
2293 } else if (!mp->oom && (mp->work_rx_refill & queue_mask)) { in mv643xx_eth_poll()
2294 work_done += rxq_refill(mp->rxq + queue, work_tbd); in mv643xx_eth_poll()
2301 if (mp->oom) in mv643xx_eth_poll()
2302 mod_timer(&mp->rx_oom, jiffies + (HZ / 10)); in mv643xx_eth_poll()
2304 wrlp(mp, INT_MASK, mp->int_mask); in mv643xx_eth_poll()
2314 napi_schedule(&mp->napi); in oom_timer_wrapper()
2319 struct net_device *dev = mp->dev; in port_start()
2324 * Perform PHY reset, if there is a PHY. in port_start()
2326 if (dev->phydev) { in port_start()
2330 phy_init_hw(dev->phydev); in port_start()
2333 phy_start(dev->phydev); in port_start()
2345 if (!dev->phydev) in port_start()
2353 for (i = 0; i < mp->txq_count; i++) { in port_start()
2354 struct tx_queue *txq = mp->txq + i; in port_start()
2363 * frames to RX queue #0, and include the pseudo-header when in port_start()
2366 mv643xx_eth_set_features(mp->dev, mp->dev->features); in port_start()
2376 mv643xx_eth_program_unicast_filter(mp->dev); in port_start()
2381 for (i = 0; i < mp->rxq_count; i++) { in port_start()
2382 struct rx_queue *rxq = mp->rxq + i; in port_start()
2385 addr = (u32)rxq->rx_desc_dma; in port_start()
2386 addr += rxq->rx_curr_desc * sizeof(struct rx_desc); in port_start()
2401 * 4 bytes for the trailing FCS -- 36 bytes total. in mv643xx_eth_recalc_skb_size()
2403 skb_size = mp->dev->mtu + 36; in mv643xx_eth_recalc_skb_size()
2410 mp->skb_size = (skb_size + 7) & ~7; in mv643xx_eth_recalc_skb_size()
2414 * netdev_alloc_skb() will cause skb->data to be misaligned in mv643xx_eth_recalc_skb_size()
2416 * some extra space to allow re-aligning the data area. in mv643xx_eth_recalc_skb_size()
2418 mp->skb_size += SKB_DMA_REALIGN; in mv643xx_eth_recalc_skb_size()
2431 err = request_irq(dev->irq, mv643xx_eth_irq, in mv643xx_eth_open()
2432 IRQF_SHARED, dev->name, dev); in mv643xx_eth_open()
2435 return -EAGAIN; in mv643xx_eth_open()
2440 napi_enable(&mp->napi); in mv643xx_eth_open()
2442 mp->int_mask = INT_EXT; in mv643xx_eth_open()
2444 for (i = 0; i < mp->rxq_count; i++) { in mv643xx_eth_open()
2447 while (--i >= 0) in mv643xx_eth_open()
2448 rxq_deinit(mp->rxq + i); in mv643xx_eth_open()
2452 rxq_refill(mp->rxq + i, INT_MAX); in mv643xx_eth_open()
2453 mp->int_mask |= INT_RX_0 << i; in mv643xx_eth_open()
2456 if (mp->oom) { in mv643xx_eth_open()
2457 mp->rx_oom.expires = jiffies + (HZ / 10); in mv643xx_eth_open()
2458 add_timer(&mp->rx_oom); in mv643xx_eth_open()
2461 for (i = 0; i < mp->txq_count; i++) { in mv643xx_eth_open()
2464 while (--i >= 0) in mv643xx_eth_open()
2465 txq_deinit(mp->txq + i); in mv643xx_eth_open()
2468 mp->int_mask |= INT_TX_END_0 << i; in mv643xx_eth_open()
2471 add_timer(&mp->mib_counters_timer); in mv643xx_eth_open()
2475 wrlp(mp, INT_MASK, mp->int_mask); in mv643xx_eth_open()
2481 for (i = 0; i < mp->rxq_count; i++) in mv643xx_eth_open()
2482 rxq_deinit(mp->rxq + i); in mv643xx_eth_open()
2484 napi_disable(&mp->napi); in mv643xx_eth_open()
2485 free_irq(dev->irq, dev); in mv643xx_eth_open()
2495 for (i = 0; i < mp->rxq_count; i++) in port_reset()
2496 rxq_disable(mp->rxq + i); in port_reset()
2497 for (i = 0; i < mp->txq_count; i++) in port_reset()
2498 txq_disable(mp->txq + i); in port_reset()
2525 napi_disable(&mp->napi); in mv643xx_eth_stop()
2527 del_timer_sync(&mp->rx_oom); in mv643xx_eth_stop()
2530 if (dev->phydev) in mv643xx_eth_stop()
2531 phy_stop(dev->phydev); in mv643xx_eth_stop()
2532 free_irq(dev->irq, dev); in mv643xx_eth_stop()
2537 del_timer_sync(&mp->mib_counters_timer); in mv643xx_eth_stop()
2539 for (i = 0; i < mp->rxq_count; i++) in mv643xx_eth_stop()
2540 rxq_deinit(mp->rxq + i); in mv643xx_eth_stop()
2541 for (i = 0; i < mp->txq_count; i++) in mv643xx_eth_stop()
2542 txq_deinit(mp->txq + i); in mv643xx_eth_stop()
2551 if (!dev->phydev) in mv643xx_eth_ioctl()
2552 return -ENOTSUPP; in mv643xx_eth_ioctl()
2554 ret = phy_mii_ioctl(dev->phydev, ifr, cmd); in mv643xx_eth_ioctl()
2564 dev->mtu = new_mtu; in mv643xx_eth_change_mtu()
2572 * Stop and then re-open the interface. This will allocate RX in mv643xx_eth_change_mtu()
2580 "fatal error on re-opening device after MTU change\n"); in mv643xx_eth_change_mtu()
2591 if (netif_running(mp->dev)) { in tx_timeout_task()
2592 netif_tx_stop_all_queues(mp->dev); in tx_timeout_task()
2595 netif_tx_wake_all_queues(mp->dev); in tx_timeout_task()
2605 schedule_work(&mp->tx_timeout_task); in mv643xx_eth_tx_timeout()
2616 mv643xx_eth_irq(dev->irq, dev); in mv643xx_eth_netpoll()
2618 wrlp(mp, INT_MASK, mp->int_mask); in mv643xx_eth_netpoll()
2628 void __iomem *base = msp->base; in mv643xx_eth_conf_mbus_windows()
2643 for (i = 0; i < dram->num_cs; i++) { in mv643xx_eth_conf_mbus_windows()
2644 const struct mbus_dram_window *cs = dram->cs + i; in mv643xx_eth_conf_mbus_windows()
2646 writel((cs->base & 0xffff0000) | in mv643xx_eth_conf_mbus_windows()
2647 (cs->mbus_attr << 8) | in mv643xx_eth_conf_mbus_windows()
2648 dram->mbus_dram_target_id, base + WINDOW_BASE(i)); in mv643xx_eth_conf_mbus_windows()
2649 writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); in mv643xx_eth_conf_mbus_windows()
2656 msp->win_protect = win_protect; in mv643xx_eth_conf_mbus_windows()
2662 * Check whether we have a 14-bit coal limit field in bits in infer_hw_params()
2663 * [21:8], or a 16-bit coal limit in bits [25,21:7] of the in infer_hw_params()
2666 writel(0x02000000, msp->base + 0x0400 + SDMA_CONFIG); in infer_hw_params()
2667 if (readl(msp->base + 0x0400 + SDMA_CONFIG) & 0x02000000) in infer_hw_params()
2668 msp->extended_rx_coal_limit = 1; in infer_hw_params()
2670 msp->extended_rx_coal_limit = 0; in infer_hw_params()
2677 writel(1, msp->base + 0x0400 + TX_BW_MTU_MOVED); in infer_hw_params()
2678 if (readl(msp->base + 0x0400 + TX_BW_MTU_MOVED) & 1) { in infer_hw_params()
2679 msp->tx_bw_control = TX_BW_CONTROL_NEW_LAYOUT; in infer_hw_params()
2681 writel(7, msp->base + 0x0400 + TX_BW_RATE); in infer_hw_params()
2682 if (readl(msp->base + 0x0400 + TX_BW_RATE) & 7) in infer_hw_params()
2683 msp->tx_bw_control = TX_BW_CONTROL_OLD_LAYOUT; in infer_hw_params()
2685 msp->tx_bw_control = TX_BW_CONTROL_ABSENT; in infer_hw_params()
2691 { .compatible = "marvell,orion-eth", },
2692 { .compatible = "marvell,kirkwood-eth", },
2732 dev_err(&pdev->dev, "missing interrupt on %pOFn\n", pnp); in mv643xx_eth_shared_of_add_port()
2733 return -EINVAL; in mv643xx_eth_shared_of_add_port()
2737 dev_err(&pdev->dev, "missing reg property on %pOFn\n", pnp); in mv643xx_eth_shared_of_add_port()
2738 return -EINVAL; in mv643xx_eth_shared_of_add_port()
2742 dev_err(&pdev->dev, "invalid reg property on %pOFn\n", pnp); in mv643xx_eth_shared_of_add_port()
2743 return -EINVAL; in mv643xx_eth_shared_of_add_port()
2750 dev_err(&pdev->dev, "too many ports registered\n"); in mv643xx_eth_shared_of_add_port()
2751 return -EINVAL; in mv643xx_eth_shared_of_add_port()
2755 if (ret == -EPROBE_DEFER) in mv643xx_eth_shared_of_add_port()
2758 mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size); in mv643xx_eth_shared_of_add_port()
2759 mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr); in mv643xx_eth_shared_of_add_port()
2760 mv643xx_eth_property(pnp, "tx-sram-size", ppd.tx_sram_size); in mv643xx_eth_shared_of_add_port()
2761 mv643xx_eth_property(pnp, "rx-queue-size", ppd.rx_queue_size); in mv643xx_eth_shared_of_add_port()
2762 mv643xx_eth_property(pnp, "rx-sram-addr", ppd.rx_sram_addr); in mv643xx_eth_shared_of_add_port()
2763 mv643xx_eth_property(pnp, "rx-sram-size", ppd.rx_sram_size); in mv643xx_eth_shared_of_add_port()
2765 ppd.phy_node = of_parse_phandle(pnp, "phy-handle", 0); in mv643xx_eth_shared_of_add_port()
2774 return -ENOMEM; in mv643xx_eth_shared_of_add_port()
2775 ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in mv643xx_eth_shared_of_add_port()
2776 ppdev->dev.of_node = pnp; in mv643xx_eth_shared_of_add_port()
2802 struct device_node *pnp, *np = pdev->dev.of_node; in mv643xx_eth_shared_of_probe()
2809 pd = devm_kzalloc(&pdev->dev, sizeof(*pd), GFP_KERNEL); in mv643xx_eth_shared_of_probe()
2811 return -ENOMEM; in mv643xx_eth_shared_of_probe()
2812 pdev->dev.platform_data = pd; in mv643xx_eth_shared_of_probe()
2814 mv643xx_eth_property(np, "tx-checksum-limit", pd->tx_csum_limit); in mv643xx_eth_shared_of_probe()
2848 pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n", in mv643xx_eth_shared_probe()
2853 return -EINVAL; in mv643xx_eth_shared_probe()
2855 msp = devm_kzalloc(&pdev->dev, sizeof(*msp), GFP_KERNEL); in mv643xx_eth_shared_probe()
2857 return -ENOMEM; in mv643xx_eth_shared_probe()
2860 msp->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); in mv643xx_eth_shared_probe()
2861 if (msp->base == NULL) in mv643xx_eth_shared_probe()
2862 return -ENOMEM; in mv643xx_eth_shared_probe()
2864 msp->clk = devm_clk_get(&pdev->dev, NULL); in mv643xx_eth_shared_probe()
2865 if (!IS_ERR(msp->clk)) in mv643xx_eth_shared_probe()
2866 clk_prepare_enable(msp->clk); in mv643xx_eth_shared_probe()
2869 * (Re-)program MBUS remapping windows if we are asked to. in mv643xx_eth_shared_probe()
2878 pd = dev_get_platdata(&pdev->dev); in mv643xx_eth_shared_probe()
2880 msp->tx_csum_limit = (pd != NULL && pd->tx_csum_limit) ? in mv643xx_eth_shared_probe()
2881 pd->tx_csum_limit : 9 * 1024; in mv643xx_eth_shared_probe()
2887 if (!IS_ERR(msp->clk)) in mv643xx_eth_shared_probe()
2888 clk_disable_unprepare(msp->clk); in mv643xx_eth_shared_probe()
2897 if (!IS_ERR(msp->clk)) in mv643xx_eth_shared_remove()
2898 clk_disable_unprepare(msp->clk); in mv643xx_eth_shared_remove()
2913 int addr_shift = 5 * mp->port_num; in phy_addr_set()
2928 return (data >> (5 * mp->port_num)) & 0x1f; in phy_addr_get()
2934 struct net_device *dev = mp->dev; in set_params()
2937 if (is_valid_ether_addr(pd->mac_addr)) { in set_params()
2938 eth_hw_addr_set(dev, pd->mac_addr); in set_params()
2946 mp->rx_ring_size = DEFAULT_RX_QUEUE_SIZE; in set_params()
2947 if (pd->rx_queue_size) in set_params()
2948 mp->rx_ring_size = pd->rx_queue_size; in set_params()
2949 mp->rx_desc_sram_addr = pd->rx_sram_addr; in set_params()
2950 mp->rx_desc_sram_size = pd->rx_sram_size; in set_params()
2952 mp->rxq_count = pd->rx_queue_count ? : 1; in set_params()
2955 if (pd->tx_queue_size) in set_params()
2956 tx_ring_size = pd->tx_queue_size; in set_params()
2958 mp->tx_ring_size = clamp_t(unsigned int, tx_ring_size, in set_params()
2960 if (mp->tx_ring_size != tx_ring_size) in set_params()
2962 mp->tx_ring_size, tx_ring_size); in set_params()
2964 mp->tx_desc_sram_addr = pd->tx_sram_addr; in set_params()
2965 mp->tx_desc_sram_size = pd->tx_sram_size; in set_params()
2967 mp->txq_count = pd->tx_queue_count ? : 1; in set_params()
2972 struct device *dev = mp->dev->dev.parent; in get_phy_mode()
2976 if (dev->of_node) in get_phy_mode()
2977 err = of_get_phy_mode(dev->of_node, &iface); in get_phy_mode()
2982 if (!dev->of_node || err) in get_phy_mode()
3004 /* Attempt to connect to the PHY using orion-mdio */ in phy_scan()
3005 phydev = ERR_PTR(-ENODEV); in phy_scan()
3010 "orion-mdio-mii", addr); in phy_scan()
3012 phydev = phy_connect(mp->dev, phy_id, mv643xx_eth_adjust_link, in phy_scan()
3025 struct net_device *dev = mp->dev; in phy_init()
3026 struct phy_device *phy = dev->phydev; in phy_init() local
3029 phy->autoneg = AUTONEG_ENABLE; in phy_init()
3030 phy->speed = 0; in phy_init()
3031 phy->duplex = 0; in phy_init()
3032 linkmode_copy(phy->advertising, phy->supported); in phy_init()
3034 phy->advertising); in phy_init()
3036 phy->autoneg = AUTONEG_DISABLE; in phy_init()
3037 linkmode_zero(phy->advertising); in phy_init()
3038 phy->speed = speed; in phy_init()
3039 phy->duplex = duplex; in phy_init()
3041 phy_start_aneg(phy); in phy_init()
3046 struct net_device *dev = mp->dev; in init_pscr()
3056 if (!dev->phydev) { in init_pscr()
3098 pd = dev_get_platdata(&pdev->dev); in mv643xx_eth_probe()
3100 dev_err(&pdev->dev, "no mv643xx_eth_platform_data\n"); in mv643xx_eth_probe()
3101 return -ENODEV; in mv643xx_eth_probe()
3104 if (pd->shared == NULL) { in mv643xx_eth_probe()
3105 dev_err(&pdev->dev, "no mv643xx_eth_platform_data->shared\n"); in mv643xx_eth_probe()
3106 return -ENODEV; in mv643xx_eth_probe()
3111 return -ENOMEM; in mv643xx_eth_probe()
3113 SET_NETDEV_DEV(dev, &pdev->dev); in mv643xx_eth_probe()
3117 mp->shared = platform_get_drvdata(pd->shared); in mv643xx_eth_probe()
3118 mp->base = mp->shared->base + 0x0400 + (pd->port_number << 10); in mv643xx_eth_probe()
3119 mp->port_num = pd->port_number; in mv643xx_eth_probe()
3121 mp->dev = dev; in mv643xx_eth_probe()
3127 if (of_device_is_compatible(pdev->dev.of_node, in mv643xx_eth_probe()
3128 "marvell,kirkwood-eth-port")) in mv643xx_eth_probe()
3136 mp->t_clk = 133000000; in mv643xx_eth_probe()
3137 mp->clk = devm_clk_get(&pdev->dev, NULL); in mv643xx_eth_probe()
3138 if (!IS_ERR(mp->clk)) { in mv643xx_eth_probe()
3139 clk_prepare_enable(mp->clk); in mv643xx_eth_probe()
3140 mp->t_clk = clk_get_rate(mp->clk); in mv643xx_eth_probe()
3141 } else if (!IS_ERR(mp->shared->clk)) { in mv643xx_eth_probe()
3142 mp->t_clk = clk_get_rate(mp->shared->clk); in mv643xx_eth_probe()
3146 netif_set_real_num_tx_queues(dev, mp->txq_count); in mv643xx_eth_probe()
3147 netif_set_real_num_rx_queues(dev, mp->rxq_count); in mv643xx_eth_probe()
3150 if (pd->phy_node) { in mv643xx_eth_probe()
3151 phydev = of_phy_connect(mp->dev, pd->phy_node, in mv643xx_eth_probe()
3155 err = -ENODEV; in mv643xx_eth_probe()
3157 phy_addr_set(mp, phydev->mdio.addr); in mv643xx_eth_probe()
3158 } else if (pd->phy_addr != MV643XX_ETH_PHY_NONE) { in mv643xx_eth_probe()
3159 phydev = phy_scan(mp, pd->phy_addr); in mv643xx_eth_probe()
3164 phy_init(mp, pd->speed, pd->duplex); in mv643xx_eth_probe()
3166 if (err == -ENODEV) { in mv643xx_eth_probe()
3167 err = -EPROBE_DEFER; in mv643xx_eth_probe()
3173 dev->ethtool_ops = &mv643xx_eth_ethtool_ops; in mv643xx_eth_probe()
3175 init_pscr(mp, pd->speed, pd->duplex); in mv643xx_eth_probe()
3180 timer_setup(&mp->mib_counters_timer, mib_counters_timer_wrapper, 0); in mv643xx_eth_probe()
3181 mp->mib_counters_timer.expires = jiffies + 30 * HZ; in mv643xx_eth_probe()
3183 spin_lock_init(&mp->mib_counters_lock); in mv643xx_eth_probe()
3185 INIT_WORK(&mp->tx_timeout_task, tx_timeout_task); in mv643xx_eth_probe()
3187 netif_napi_add(dev, &mp->napi, mv643xx_eth_poll); in mv643xx_eth_probe()
3189 timer_setup(&mp->rx_oom, oom_timer_wrapper, 0); in mv643xx_eth_probe()
3197 dev->irq = irq; in mv643xx_eth_probe()
3199 dev->netdev_ops = &mv643xx_eth_netdev_ops; in mv643xx_eth_probe()
3201 dev->watchdog_timeo = 2 * HZ; in mv643xx_eth_probe()
3202 dev->base_addr = 0; in mv643xx_eth_probe()
3204 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; in mv643xx_eth_probe()
3205 dev->vlan_features = dev->features; in mv643xx_eth_probe()
3207 dev->features |= NETIF_F_RXCSUM; in mv643xx_eth_probe()
3208 dev->hw_features = dev->features; in mv643xx_eth_probe()
3210 dev->priv_flags |= IFF_UNICAST_FLT; in mv643xx_eth_probe()
3213 /* MTU range: 64 - 9500 */ in mv643xx_eth_probe()
3214 dev->min_mtu = 64; in mv643xx_eth_probe()
3215 dev->max_mtu = 9500; in mv643xx_eth_probe()
3217 if (mp->shared->win_protect) in mv643xx_eth_probe()
3218 wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect); in mv643xx_eth_probe()
3232 mp->port_num, dev->dev_addr); in mv643xx_eth_probe()
3234 if (mp->tx_desc_sram_size > 0) in mv643xx_eth_probe()
3240 if (!IS_ERR(mp->clk)) in mv643xx_eth_probe()
3241 clk_disable_unprepare(mp->clk); in mv643xx_eth_probe()
3250 struct net_device *dev = mp->dev; in mv643xx_eth_remove()
3252 unregister_netdev(mp->dev); in mv643xx_eth_remove()
3253 if (dev->phydev) in mv643xx_eth_remove()
3254 phy_disconnect(dev->phydev); in mv643xx_eth_remove()
3255 cancel_work_sync(&mp->tx_timeout_task); in mv643xx_eth_remove()
3257 if (!IS_ERR(mp->clk)) in mv643xx_eth_remove()
3258 clk_disable_unprepare(mp->clk); in mv643xx_eth_remove()
3260 free_netdev(mp->dev); in mv643xx_eth_remove()
3273 if (netif_running(mp->dev)) in mv643xx_eth_shutdown()