Lines Matching +full:mac +full:- +full:address
1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/nvmem-consumer.h>
27 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_open() local
28 struct spl2sw_common *comm = mac->comm; in spl2sw_ethernet_open()
31 netdev_dbg(ndev, "Open port = %x\n", mac->lan_port); in spl2sw_ethernet_open()
33 comm->enable |= mac->lan_port; in spl2sw_ethernet_open()
38 mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); in spl2sw_ethernet_open()
40 writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0); in spl2sw_ethernet_open()
42 phy_start(ndev->phydev); in spl2sw_ethernet_open()
51 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_stop() local
52 struct spl2sw_common *comm = mac->comm; in spl2sw_ethernet_stop()
56 comm->enable &= ~mac->lan_port; in spl2sw_ethernet_stop()
58 phy_stop(ndev->phydev); in spl2sw_ethernet_stop()
68 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_start_xmit() local
69 struct spl2sw_common *comm = mac->comm; in spl2sw_ethernet_start_xmit()
78 if (unlikely(comm->tx_desc_full == 1)) { in spl2sw_ethernet_start_xmit()
85 if (unlikely(skb->len < ETH_ZLEN)) { in spl2sw_ethernet_start_xmit()
89 skb_put(skb, ETH_ZLEN - skb->len); in spl2sw_ethernet_start_xmit()
92 mapping = dma_map_single(&comm->pdev->dev, skb->data, in spl2sw_ethernet_start_xmit()
93 skb->len, DMA_TO_DEVICE); in spl2sw_ethernet_start_xmit()
94 if (dma_mapping_error(&comm->pdev->dev, mapping)) { in spl2sw_ethernet_start_xmit()
95 ndev->stats.tx_errors++; in spl2sw_ethernet_start_xmit()
100 spin_lock_irqsave(&comm->tx_lock, flags); in spl2sw_ethernet_start_xmit()
102 tx_pos = comm->tx_pos; in spl2sw_ethernet_start_xmit()
103 txdesc = &comm->tx_desc[tx_pos]; in spl2sw_ethernet_start_xmit()
104 skbinfo = &comm->tx_temp_skb_info[tx_pos]; in spl2sw_ethernet_start_xmit()
105 skbinfo->mapping = mapping; in spl2sw_ethernet_start_xmit()
106 skbinfo->len = skb->len; in spl2sw_ethernet_start_xmit()
107 skbinfo->skb = skb; in spl2sw_ethernet_start_xmit()
110 cmd1 = TXD_OWN | TXD_SOP | TXD_EOP | (mac->to_vlan << 12) | in spl2sw_ethernet_start_xmit()
111 (skb->len & TXD_PKT_LEN); in spl2sw_ethernet_start_xmit()
112 cmd2 = skb->len & TXD_BUF_LEN1; in spl2sw_ethernet_start_xmit()
114 if (tx_pos == (TX_DESC_NUM - 1)) in spl2sw_ethernet_start_xmit()
117 txdesc->addr1 = skbinfo->mapping; in spl2sw_ethernet_start_xmit()
118 txdesc->cmd2 = cmd2; in spl2sw_ethernet_start_xmit()
120 txdesc->cmd1 = cmd1; in spl2sw_ethernet_start_xmit()
125 if (unlikely(tx_pos == comm->tx_done_pos)) { in spl2sw_ethernet_start_xmit()
127 comm->tx_desc_full = 1; in spl2sw_ethernet_start_xmit()
129 comm->tx_pos = tx_pos; in spl2sw_ethernet_start_xmit()
132 /* Trigger mac to transmit */ in spl2sw_ethernet_start_xmit()
133 writel(MAC_TRIG_L_SOC0, comm->l2sw_reg_base + L2SW_CPU_TX_TRIG); in spl2sw_ethernet_start_xmit()
135 spin_unlock_irqrestore(&comm->tx_lock, flags); in spl2sw_ethernet_start_xmit()
141 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_set_rx_mode() local
143 spl2sw_mac_rx_mode_set(mac); in spl2sw_ethernet_set_rx_mode()
148 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_set_mac_address() local
155 /* Delete the old MAC address */ in spl2sw_ethernet_set_mac_address()
156 netdev_dbg(ndev, "Old Ethernet (MAC) address = %pM\n", mac->mac_addr); in spl2sw_ethernet_set_mac_address()
157 if (is_valid_ether_addr(mac->mac_addr)) { in spl2sw_ethernet_set_mac_address()
158 err = spl2sw_mac_addr_del(mac); in spl2sw_ethernet_set_mac_address()
163 /* Set the MAC address */ in spl2sw_ethernet_set_mac_address()
164 ether_addr_copy(mac->mac_addr, ndev->dev_addr); in spl2sw_ethernet_set_mac_address()
165 return spl2sw_mac_addr_add(mac); in spl2sw_ethernet_set_mac_address()
170 struct spl2sw_mac *mac = netdev_priv(ndev); in spl2sw_ethernet_tx_timeout() local
171 struct spl2sw_common *comm = mac->comm; in spl2sw_ethernet_tx_timeout()
176 ndev->stats.tx_errors++; in spl2sw_ethernet_tx_timeout()
178 spin_lock_irqsave(&comm->tx_lock, flags); in spl2sw_ethernet_tx_timeout()
181 if (comm->ndev[i]) in spl2sw_ethernet_tx_timeout()
182 netif_stop_queue(comm->ndev[i]); in spl2sw_ethernet_tx_timeout()
188 if (comm->ndev[i]) { in spl2sw_ethernet_tx_timeout()
189 netif_trans_update(comm->ndev[i]); in spl2sw_ethernet_tx_timeout()
190 netif_wake_queue(comm->ndev[i]); in spl2sw_ethernet_tx_timeout()
193 spin_unlock_irqrestore(&comm->tx_lock, flags); in spl2sw_ethernet_tx_timeout()
208 /* Byte order of MAC address of some samples are reversed. in spl2sw_check_mac_vendor_id_and_convert()
226 u8 *mac; in spl2sw_nvmem_get_mac_address() local
228 /* Get nvmem cell of mac-address from dts. */ in spl2sw_nvmem_get_mac_address()
229 cell = of_nvmem_cell_get(np, "mac-address"); in spl2sw_nvmem_get_mac_address()
233 /* Read mac address from nvmem cell. */ in spl2sw_nvmem_get_mac_address()
234 mac = nvmem_cell_read(cell, &len); in spl2sw_nvmem_get_mac_address()
236 if (IS_ERR(mac)) in spl2sw_nvmem_get_mac_address()
237 return PTR_ERR(mac); in spl2sw_nvmem_get_mac_address()
240 kfree(mac); in spl2sw_nvmem_get_mac_address()
241 dev_info(dev, "Invalid length of mac address in nvmem!\n"); in spl2sw_nvmem_get_mac_address()
242 return -EINVAL; in spl2sw_nvmem_get_mac_address()
248 spl2sw_check_mac_vendor_id_and_convert(mac); in spl2sw_nvmem_get_mac_address()
250 /* Check if mac address is valid */ in spl2sw_nvmem_get_mac_address()
251 if (!is_valid_ether_addr(mac)) { in spl2sw_nvmem_get_mac_address()
252 dev_info(dev, "Invalid mac address in nvmem (%pM)!\n", mac); in spl2sw_nvmem_get_mac_address()
253 kfree(mac); in spl2sw_nvmem_get_mac_address()
254 return -EINVAL; in spl2sw_nvmem_get_mac_address()
257 ether_addr_copy(addrbuf, mac); in spl2sw_nvmem_get_mac_address()
258 kfree(mac); in spl2sw_nvmem_get_mac_address()
266 struct spl2sw_mac *mac; in spl2sw_init_netdev() local
272 ndev = devm_alloc_etherdev(&pdev->dev, sizeof(*mac)); in spl2sw_init_netdev()
275 return -ENOMEM; in spl2sw_init_netdev()
277 SET_NETDEV_DEV(ndev, &pdev->dev); in spl2sw_init_netdev()
278 ndev->netdev_ops = &netdev_ops; in spl2sw_init_netdev()
279 mac = netdev_priv(ndev); in spl2sw_init_netdev()
280 mac->ndev = ndev; in spl2sw_init_netdev()
281 ether_addr_copy(mac->mac_addr, mac_addr); in spl2sw_init_netdev()
284 dev_info(&pdev->dev, "Ethernet (MAC) address = %pM\n", mac_addr); in spl2sw_init_netdev()
288 dev_err(&pdev->dev, "Failed to register net device \"%s\"!\n", in spl2sw_init_netdev()
289 ndev->name); in spl2sw_init_netdev()
293 netdev_dbg(ndev, "Registered net device \"%s\" successfully.\n", ndev->name); in spl2sw_init_netdev()
306 if (strcmp(port_np->name, "port")) in spl2sw_get_eth_child_node()
328 struct spl2sw_mac *mac; in spl2sw_probe() local
333 return -ENODEV; in spl2sw_probe()
336 comm = devm_kzalloc(&pdev->dev, sizeof(*comm), GFP_KERNEL); in spl2sw_probe()
338 return -ENOMEM; in spl2sw_probe()
340 comm->pdev = pdev; in spl2sw_probe()
343 spin_lock_init(&comm->tx_lock); in spl2sw_probe()
344 spin_lock_init(&comm->mdio_lock); in spl2sw_probe()
345 spin_lock_init(&comm->int_mask_lock); in spl2sw_probe()
348 comm->l2sw_reg_base = devm_platform_ioremap_resource(pdev, 0); in spl2sw_probe()
349 if (IS_ERR(comm->l2sw_reg_base)) in spl2sw_probe()
350 return PTR_ERR(comm->l2sw_reg_base); in spl2sw_probe()
359 comm->clk = devm_clk_get(&pdev->dev, NULL); in spl2sw_probe()
360 if (IS_ERR(comm->clk)) { in spl2sw_probe()
361 dev_err_probe(&pdev->dev, PTR_ERR(comm->clk), in spl2sw_probe()
363 return PTR_ERR(comm->clk); in spl2sw_probe()
367 comm->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in spl2sw_probe()
368 if (IS_ERR(comm->rstc)) { in spl2sw_probe()
369 dev_err_probe(&pdev->dev, PTR_ERR(comm->rstc), in spl2sw_probe()
371 return PTR_ERR(comm->rstc); in spl2sw_probe()
375 ret = clk_prepare_enable(comm->clk); in spl2sw_probe()
380 /* Reset MAC */ in spl2sw_probe()
381 reset_control_assert(comm->rstc); in spl2sw_probe()
383 reset_control_deassert(comm->rstc); in spl2sw_probe()
387 ret = devm_request_irq(&pdev->dev, irq, spl2sw_ethernet_interrupt, 0, in spl2sw_probe()
388 dev_name(&pdev->dev), comm); in spl2sw_probe()
390 dev_err(&pdev->dev, "Failed to request irq #%d!\n", irq); in spl2sw_probe()
397 dev_err(&pdev->dev, "Fail to initialize mac descriptors!\n"); in spl2sw_probe()
402 /* Initialize MAC. */ in spl2sw_probe()
408 dev_err(&pdev->dev, "Failed to initialize mdio bus!\n"); in spl2sw_probe()
412 /* Get child node ethernet-ports. */ in spl2sw_probe()
413 eth_ports_np = of_get_child_by_name(pdev->dev.of_node, "ethernet-ports"); in spl2sw_probe()
415 dev_err(&pdev->dev, "No ethernet-ports child node found!\n"); in spl2sw_probe()
416 ret = -ENODEV; in spl2sw_probe()
421 /* Get port@i of node ethernet-ports. */ in spl2sw_probe()
426 /* Get phy-mode. */ in spl2sw_probe()
428 dev_err(&pdev->dev, "Failed to get phy-mode property of port@%d!\n", in spl2sw_probe()
433 /* Get phy-handle. */ in spl2sw_probe()
434 phy_np = of_parse_phandle(port_np, "phy-handle", 0); in spl2sw_probe()
436 dev_err(&pdev->dev, "Failed to get phy-handle property of port@%d!\n", in spl2sw_probe()
441 /* Get mac-address from nvmem. */ in spl2sw_probe()
442 ret = spl2sw_nvmem_get_mac_address(&pdev->dev, port_np, mac_addr); in spl2sw_probe()
443 if (ret == -EPROBE_DEFER) { in spl2sw_probe()
446 dev_info(&pdev->dev, "Generate a random mac address!\n"); in spl2sw_probe()
455 ndev->irq = irq; in spl2sw_probe()
456 comm->ndev[i] = ndev; in spl2sw_probe()
457 mac = netdev_priv(ndev); in spl2sw_probe()
458 mac->phy_node = phy_np; in spl2sw_probe()
459 mac->phy_mode = phy_mode; in spl2sw_probe()
460 mac->comm = comm; in spl2sw_probe()
462 mac->lan_port = 0x1 << i; /* forward to port i */ in spl2sw_probe()
463 mac->to_vlan = 0x1 << i; /* vlan group: i */ in spl2sw_probe()
464 mac->vlan_id = i; /* vlan group: i */ in spl2sw_probe()
466 /* Set MAC address */ in spl2sw_probe()
467 ret = spl2sw_mac_addr_add(mac); in spl2sw_probe()
471 spl2sw_mac_rx_mode_set(mac); in spl2sw_probe()
476 if (comm->ndev[i]) in spl2sw_probe()
480 dev_err(&pdev->dev, "No valid ethernet port!\n"); in spl2sw_probe()
481 ret = -ENODEV; in spl2sw_probe()
486 ndev = comm->ndev[i]; in spl2sw_probe()
495 netif_napi_add(ndev, &comm->rx_napi, spl2sw_rx_poll); in spl2sw_probe()
496 napi_enable(&comm->rx_napi); in spl2sw_probe()
497 netif_napi_add_tx(ndev, &comm->tx_napi, spl2sw_tx_poll); in spl2sw_probe()
498 napi_enable(&comm->tx_napi); in spl2sw_probe()
503 if (comm->ndev[i]) in spl2sw_probe()
504 unregister_netdev(comm->ndev[i]); in spl2sw_probe()
510 clk_disable_unprepare(comm->clk); in spl2sw_probe()
525 if (comm->ndev[i]) in spl2sw_remove()
526 unregister_netdev(comm->ndev[i]); in spl2sw_remove()
528 comm->enable = 0; in spl2sw_remove()
533 napi_disable(&comm->rx_napi); in spl2sw_remove()
534 netif_napi_del(&comm->rx_napi); in spl2sw_remove()
535 napi_disable(&comm->tx_napi); in spl2sw_remove()
536 netif_napi_del(&comm->tx_napi); in spl2sw_remove()
540 clk_disable_unprepare(comm->clk); in spl2sw_remove()
544 {.compatible = "sunplus,sp7021-emac"},