Lines Matching +full:tx +full:- +full:rx

1 /* SPDX-License-Identifier: GPL-2.0+ */
41 netif_err(adapter, drv, adapter->netdev, in pci11x1x_strap_get_status()
54 adapter->is_sgmii_en = true; in pci11x1x_strap_get_status()
56 adapter->is_sgmii_en = false; in pci11x1x_strap_get_status()
61 adapter->is_sgmii_en = true; in pci11x1x_strap_get_status()
63 adapter->is_sgmii_en = false; in pci11x1x_strap_get_status()
65 adapter->is_sgmii_en = false; in pci11x1x_strap_get_status()
68 netif_dbg(adapter, drv, adapter->netdev, in pci11x1x_strap_get_status()
69 "SGMII I/F %sable\n", adapter->is_sgmii_en ? "En" : "Dis"); in pci11x1x_strap_get_status()
74 struct lan743x_csr *csr = &adapter->csr; in is_pci11x1x_chip()
75 u32 id_rev = csr->id_rev; in is_pci11x1x_chip()
86 pci_release_selected_regions(adapter->pdev, in lan743x_pci_cleanup()
87 pci_select_bars(adapter->pdev, in lan743x_pci_cleanup()
89 pci_disable_device(adapter->pdev); in lan743x_pci_cleanup()
98 adapter->pdev = pdev; in lan743x_pci_init()
103 netif_info(adapter, probe, adapter->netdev, in lan743x_pci_init()
105 pdev->vendor, pdev->device); in lan743x_pci_init()
118 pci_disable_device(adapter->pdev); in lan743x_pci_init()
126 return ioread32(&adapter->csr.csr_address[offset]); in lan743x_csr_read()
132 iowrite32(data, &adapter->csr.csr_address[offset]); in lan743x_csr_write()
175 struct lan743x_csr *csr = &adapter->csr; in lan743x_csr_init()
178 bar_start = pci_resource_start(adapter->pdev, 0); in lan743x_csr_init()
179 bar_length = pci_resource_len(adapter->pdev, 0); in lan743x_csr_init()
180 csr->csr_address = devm_ioremap(&adapter->pdev->dev, in lan743x_csr_init()
182 if (!csr->csr_address) in lan743x_csr_init()
183 return -ENOMEM; in lan743x_csr_init()
185 csr->id_rev = lan743x_csr_read(adapter, ID_REV); in lan743x_csr_init()
186 csr->fpga_rev = lan743x_csr_read(adapter, FPGA_REV); in lan743x_csr_init()
187 netif_info(adapter, probe, adapter->netdev, in lan743x_csr_init()
189 csr->id_rev, FPGA_REV_GET_MAJOR_(csr->fpga_rev), in lan743x_csr_init()
190 FPGA_REV_GET_MINOR_(csr->fpga_rev)); in lan743x_csr_init()
191 if (!ID_REV_IS_VALID_CHIP_ID_(csr->id_rev)) in lan743x_csr_init()
192 return -ENODEV; in lan743x_csr_init()
194 csr->flags = LAN743X_CSR_FLAG_SUPPORTS_INTR_AUTO_SET_CLR; in lan743x_csr_init()
195 switch (csr->id_rev & ID_REV_CHIP_REV_MASK_) { in lan743x_csr_init()
197 csr->flags |= LAN743X_CSR_FLAG_IS_A0; in lan743x_csr_init()
198 csr->flags &= ~LAN743X_CSR_FLAG_SUPPORTS_INTR_AUTO_SET_CLR; in lan743x_csr_init()
201 csr->flags |= LAN743X_CSR_FLAG_IS_B0; in lan743x_csr_init()
210 struct lan743x_intr *intr = &adapter->intr; in lan743x_intr_software_isr()
212 /* disable the interrupt to prevent repeated re-triggering */ in lan743x_intr_software_isr()
214 intr->software_isr_flag = true; in lan743x_intr_software_isr()
215 wake_up(&intr->software_isr_wq); in lan743x_intr_software_isr()
220 struct lan743x_tx *tx = context; in lan743x_tx_isr() local
221 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_isr()
227 INT_BIT_DMA_TX_(tx->channel_number)); in lan743x_tx_isr()
230 if (int_sts & INT_BIT_DMA_TX_(tx->channel_number)) { in lan743x_tx_isr()
231 u32 ioc_bit = DMAC_INT_BIT_TX_IOC_(tx->channel_number); in lan743x_tx_isr()
248 napi_schedule(&tx->napi); in lan743x_tx_isr()
256 INT_BIT_DMA_TX_(tx->channel_number)); in lan743x_tx_isr()
261 struct lan743x_rx *rx = context; in lan743x_rx_isr() local
262 struct lan743x_adapter *adapter = rx->adapter; in lan743x_rx_isr()
267 INT_BIT_DMA_RX_(rx->channel_number)); in lan743x_rx_isr()
270 if (int_sts & INT_BIT_DMA_RX_(rx->channel_number)) { in lan743x_rx_isr()
271 u32 rx_frame_bit = DMAC_INT_BIT_RXFRM_(rx->channel_number); in lan743x_rx_isr()
288 napi_schedule(&rx->napi); in lan743x_rx_isr()
296 INT_BIT_DMA_RX_(rx->channel_number)); in lan743x_rx_isr()
311 lan743x_rx_isr(&adapter->rx[channel], in lan743x_intr_shared_isr()
318 for (channel = 0; channel < adapter->used_tx_channels; in lan743x_intr_shared_isr()
323 lan743x_tx_isr(&adapter->tx[channel], in lan743x_intr_shared_isr()
346 struct lan743x_adapter *adapter = vector->adapter; in lan743x_intr_entry_isr()
351 if (vector->flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_READ) { in lan743x_intr_entry_isr()
353 } else if (vector->flags & in lan743x_intr_entry_isr()
359 int_sts = vector->int_mask | INT_BIT_MAS_; in lan743x_intr_entry_isr()
365 if (vector->flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_ISR_CLEAR) in lan743x_intr_entry_isr()
369 INT_VEC_EN_(vector->vector_index)); in lan743x_intr_entry_isr()
371 if (vector->flags & LAN743X_VECTOR_FLAG_MASTER_ENABLE_CLEAR) in lan743x_intr_entry_isr()
375 if (vector->flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_CHECK) { in lan743x_intr_entry_isr()
379 int_enables = vector->int_mask; in lan743x_intr_entry_isr()
383 int_sts &= vector->int_mask; in lan743x_intr_entry_isr()
385 if (vector->handler) { in lan743x_intr_entry_isr()
386 vector->handler(vector->context, in lan743x_intr_entry_isr()
387 int_sts, vector->flags); in lan743x_intr_entry_isr()
391 vector->int_mask); in lan743x_intr_entry_isr()
396 if (vector->flags & LAN743X_VECTOR_FLAG_MASTER_ENABLE_SET) in lan743x_intr_entry_isr()
400 if (vector->flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_ISR_SET) in lan743x_intr_entry_isr()
404 INT_VEC_EN_(vector->vector_index)); in lan743x_intr_entry_isr()
411 struct lan743x_intr *intr = &adapter->intr; in lan743x_intr_test_isr()
414 intr->software_isr_flag = false; in lan743x_intr_test_isr()
420 ret = wait_event_timeout(intr->software_isr_wq, in lan743x_intr_test_isr()
421 intr->software_isr_flag, in lan743x_intr_test_isr()
427 return ret > 0 ? 0 : -ENODEV; in lan743x_intr_test_isr()
436 struct lan743x_vector *vector = &adapter->intr.vector_list in lan743x_intr_register_isr()
440 vector->adapter = adapter; in lan743x_intr_register_isr()
441 vector->flags = flags; in lan743x_intr_register_isr()
442 vector->vector_index = vector_index; in lan743x_intr_register_isr()
443 vector->int_mask = int_mask; in lan743x_intr_register_isr()
444 vector->handler = handler; in lan743x_intr_register_isr()
445 vector->context = context; in lan743x_intr_register_isr()
447 ret = request_irq(vector->irq, in lan743x_intr_register_isr()
452 vector->handler = NULL; in lan743x_intr_register_isr()
453 vector->context = NULL; in lan743x_intr_register_isr()
454 vector->int_mask = 0; in lan743x_intr_register_isr()
455 vector->flags = 0; in lan743x_intr_register_isr()
463 struct lan743x_vector *vector = &adapter->intr.vector_list in lan743x_intr_unregister_isr()
466 free_irq(vector->irq, vector); in lan743x_intr_unregister_isr()
467 vector->handler = NULL; in lan743x_intr_unregister_isr()
468 vector->context = NULL; in lan743x_intr_unregister_isr()
469 vector->int_mask = 0; in lan743x_intr_unregister_isr()
470 vector->flags = 0; in lan743x_intr_unregister_isr()
478 for (index = 0; index < adapter->max_vector_count; index++) { in lan743x_intr_get_vector_flags()
479 if (adapter->intr.vector_list[index].int_mask & int_mask) in lan743x_intr_get_vector_flags()
480 return adapter->intr.vector_list[index].flags; in lan743x_intr_get_vector_flags()
487 struct lan743x_intr *intr = &adapter->intr; in lan743x_intr_close()
491 if (adapter->is_pci11x1x) in lan743x_intr_close()
496 for (index = 0; index < intr->number_of_vectors; index++) { in lan743x_intr_close()
497 if (intr->flags & INTR_FLAG_IRQ_REQUESTED(index)) { in lan743x_intr_close()
499 intr->flags &= ~INTR_FLAG_IRQ_REQUESTED(index); in lan743x_intr_close()
503 if (intr->flags & INTR_FLAG_MSI_ENABLED) { in lan743x_intr_close()
504 pci_disable_msi(adapter->pdev); in lan743x_intr_close()
505 intr->flags &= ~INTR_FLAG_MSI_ENABLED; in lan743x_intr_close()
508 if (intr->flags & INTR_FLAG_MSIX_ENABLED) { in lan743x_intr_close()
509 pci_disable_msix(adapter->pdev); in lan743x_intr_close()
510 intr->flags &= ~INTR_FLAG_MSIX_ENABLED; in lan743x_intr_close()
517 struct lan743x_intr *intr = &adapter->intr; in lan743x_intr_open()
523 int ret = -ENODEV; in lan743x_intr_open()
527 intr->number_of_vectors = 0; in lan743x_intr_open()
530 max_vector_count = adapter->max_vector_count; in lan743x_intr_open()
535 used_tx_channels = adapter->used_tx_channels; in lan743x_intr_open()
536 ret = pci_enable_msix_range(adapter->pdev, in lan743x_intr_open()
542 intr->flags |= INTR_FLAG_MSIX_ENABLED; in lan743x_intr_open()
543 intr->number_of_vectors = ret; in lan743x_intr_open()
544 intr->using_vectors = true; in lan743x_intr_open()
545 for (index = 0; index < intr->number_of_vectors; index++) in lan743x_intr_open()
546 intr->vector_list[index].irq = msix_entries in lan743x_intr_open()
548 netif_info(adapter, ifup, adapter->netdev, in lan743x_intr_open()
550 intr->number_of_vectors); in lan743x_intr_open()
554 if (!intr->number_of_vectors) { in lan743x_intr_open()
555 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { in lan743x_intr_open()
556 if (!pci_enable_msi(adapter->pdev)) { in lan743x_intr_open()
557 intr->flags |= INTR_FLAG_MSI_ENABLED; in lan743x_intr_open()
558 intr->number_of_vectors = 1; in lan743x_intr_open()
559 intr->using_vectors = true; in lan743x_intr_open()
560 intr->vector_list[0].irq = in lan743x_intr_open()
561 adapter->pdev->irq; in lan743x_intr_open()
562 netif_info(adapter, ifup, adapter->netdev, in lan743x_intr_open()
564 intr->number_of_vectors); in lan743x_intr_open()
570 if (!intr->number_of_vectors) { in lan743x_intr_open()
571 intr->number_of_vectors = 1; in lan743x_intr_open()
572 intr->using_vectors = false; in lan743x_intr_open()
573 intr->vector_list[0].irq = intr->irq; in lan743x_intr_open()
574 netif_info(adapter, ifup, adapter->netdev, in lan743x_intr_open()
590 if (intr->using_vectors) { in lan743x_intr_open()
599 if (adapter->csr.flags & LAN743X_CSR_FLAG_SUPPORTS_INTR_AUTO_SET_CLR) { in lan743x_intr_open()
608 init_waitqueue_head(&intr->software_isr_wq); in lan743x_intr_open()
616 intr->flags |= INTR_FLAG_IRQ_REQUESTED(0); in lan743x_intr_open()
618 if (intr->using_vectors) in lan743x_intr_open()
622 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { in lan743x_intr_open()
631 if (adapter->is_pci11x1x) { in lan743x_intr_open()
649 if (intr->number_of_vectors > 1) { in lan743x_intr_open()
650 int number_of_tx_vectors = intr->number_of_vectors - 1; in lan743x_intr_open()
661 if (adapter->csr.flags & in lan743x_intr_open()
673 /* map TX interrupt to vector */ in lan743x_intr_open()
677 /* Remove TX interrupt from shared mask */ in lan743x_intr_open()
678 intr->vector_list[0].int_mask &= ~int_bit; in lan743x_intr_open()
681 &adapter->tx[index]); in lan743x_intr_open()
684 intr->flags |= INTR_FLAG_IRQ_REQUESTED(vector); in lan743x_intr_open()
691 if ((intr->number_of_vectors - used_tx_channels) > 1) { in lan743x_intr_open()
692 int number_of_rx_vectors = intr->number_of_vectors - in lan743x_intr_open()
693 used_tx_channels - 1; in lan743x_intr_open()
705 if (adapter->csr.flags & in lan743x_intr_open()
717 /* map RX interrupt to vector */ in lan743x_intr_open()
727 /* Remove RX interrupt from shared mask */ in lan743x_intr_open()
728 intr->vector_list[0].int_mask &= ~int_bit; in lan743x_intr_open()
731 &adapter->rx[index]); in lan743x_intr_open()
734 intr->flags |= INTR_FLAG_IRQ_REQUESTED(vector); in lan743x_intr_open()
755 return -EIO; in lan743x_dp_write()
768 return -EIO; in lan743x_dp_write()
802 struct lan743x_adapter *adapter = bus->priv; in lan743x_mdiobus_read_c22()
825 struct lan743x_adapter *adapter = bus->priv; in lan743x_mdiobus_write_c22()
867 struct lan743x_adapter *adapter = bus->priv; in lan743x_mdiobus_read_c45()
900 struct lan743x_adapter *adapter = bus->priv; in lan743x_mdiobus_write_c45()
935 netif_err(adapter, drv, adapter->netdev, in lan743x_sgmii_wait_till_not_busy()
948 netif_err(adapter, probe, adapter->netdev, in lan743x_sgmii_read()
950 return -EINVAL; in lan743x_sgmii_read()
953 mutex_lock(&adapter->sgmii_rw_lock); in lan743x_sgmii_read()
966 mutex_unlock(&adapter->sgmii_rw_lock); in lan743x_sgmii_read()
978 netif_err(adapter, probe, adapter->netdev, in lan743x_sgmii_write()
980 return -EINVAL; in lan743x_sgmii_write()
982 mutex_lock(&adapter->sgmii_rw_lock); in lan743x_sgmii_write()
990 mutex_unlock(&adapter->sgmii_rw_lock); in lan743x_sgmii_write()
1065 enum lan743x_sgmii_lsd lsd = adapter->sgmii_lsd; in lan743x_sgmii_aneg_update()
1099 /* In order for Auto-Negotiation to operate properly at in lan743x_sgmii_aneg_update()
1145 return -ETIMEDOUT; in lan743x_pcs_seq_state()
1152 struct net_device *netdev = adapter->netdev; in lan743x_sgmii_config()
1153 struct phy_device *phydev = netdev->phydev; in lan743x_sgmii_config()
1159 switch (phydev->speed) { in lan743x_sgmii_config()
1161 if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER) in lan743x_sgmii_config()
1167 if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER) in lan743x_sgmii_config()
1173 if (phydev->duplex) in lan743x_sgmii_config()
1179 if (phydev->duplex) in lan743x_sgmii_config()
1185 netif_err(adapter, drv, adapter->netdev, in lan743x_sgmii_config()
1186 "Invalid speed %d\n", phydev->speed); in lan743x_sgmii_config()
1187 return -EINVAL; in lan743x_sgmii_config()
1190 adapter->sgmii_lsd = lsd; in lan743x_sgmii_config()
1193 netif_err(adapter, drv, adapter->netdev, in lan743x_sgmii_config()
1200 netif_err(adapter, drv, adapter->netdev, in lan743x_sgmii_config()
1206 netif_dbg(adapter, drv, adapter->netdev, in lan743x_sgmii_config()
1209 netif_dbg(adapter, drv, adapter->netdev, in lan743x_sgmii_config()
1212 /* SGMII/1000/2500BASE-X PCS power down */ in lan743x_sgmii_config()
1226 /* SGMII/1000/2500BASE-X PCS power up */ in lan743x_sgmii_config()
1253 ether_addr_copy(adapter->mac_address, addr); in lan743x_mac_set_address()
1254 netif_info(adapter, drv, adapter->netdev, in lan743x_mac_set_address()
1266 netdev = adapter->netdev; in lan743x_mac_init()
1274 if (!is_valid_ether_addr(adapter->mac_address)) { in lan743x_mac_init()
1277 adapter->mac_address[0] = mac_addr_lo & 0xFF; in lan743x_mac_init()
1278 adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF; in lan743x_mac_init()
1279 adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF; in lan743x_mac_init()
1280 adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF; in lan743x_mac_init()
1281 adapter->mac_address[4] = mac_addr_hi & 0xFF; in lan743x_mac_init()
1282 adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF; in lan743x_mac_init()
1287 } else if (!is_valid_ether_addr(adapter->mac_address)) { in lan743x_mac_init()
1292 eth_random_addr(adapter->mac_address); in lan743x_mac_init()
1294 lan743x_mac_set_address(adapter, adapter->mac_address); in lan743x_mac_init()
1295 eth_hw_addr_set(netdev, adapter->mac_address); in lan743x_mac_init()
1395 struct lan743x_phy *phy = &adapter->phy; in lan743x_phy_update_flowcontrol()
1398 if (phy->fc_autoneg) in lan743x_phy_update_flowcontrol()
1401 cap = phy->fc_request_control; in lan743x_phy_update_flowcontrol()
1416 struct phy_device *phydev = netdev->phydev; in lan743x_phy_link_status_change()
1420 if (phydev->state == PHY_RUNNING) { in lan743x_phy_link_status_change()
1427 if (phydev->duplex) in lan743x_phy_link_status_change()
1433 switch (phydev->speed) { in lan743x_phy_link_status_change()
1454 linkmode_adv_to_mii_adv_t(phydev->advertising); in lan743x_phy_link_status_change()
1456 linkmode_adv_to_mii_adv_t(phydev->lp_advertising); in lan743x_phy_link_status_change()
1460 lan743x_ptp_update_latency(adapter, phydev->speed); in lan743x_phy_link_status_change()
1461 if (phydev->interface == PHY_INTERFACE_MODE_SGMII || in lan743x_phy_link_status_change()
1462 phydev->interface == PHY_INTERFACE_MODE_1000BASEX || in lan743x_phy_link_status_change()
1463 phydev->interface == PHY_INTERFACE_MODE_2500BASEX) in lan743x_phy_link_status_change()
1470 struct net_device *netdev = adapter->netdev; in lan743x_phy_close()
1472 phy_stop(netdev->phydev); in lan743x_phy_close()
1473 phy_disconnect(netdev->phydev); in lan743x_phy_close()
1482 id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_; in lan743x_phy_interface_select()
1484 if (adapter->is_pci11x1x && adapter->is_sgmii_en) in lan743x_phy_interface_select()
1485 adapter->phy_interface = PHY_INTERFACE_MODE_SGMII; in lan743x_phy_interface_select()
1487 adapter->phy_interface = PHY_INTERFACE_MODE_GMII; in lan743x_phy_interface_select()
1489 adapter->phy_interface = PHY_INTERFACE_MODE_MII; in lan743x_phy_interface_select()
1491 adapter->phy_interface = PHY_INTERFACE_MODE_RGMII; in lan743x_phy_interface_select()
1496 struct net_device *netdev = adapter->netdev; in lan743x_phy_open()
1497 struct lan743x_phy *phy = &adapter->phy; in lan743x_phy_open()
1504 int ret = -EIO; in lan743x_phy_open()
1507 phydev = of_phy_get_and_connect(netdev, adapter->pdev->dev.of_node, in lan743x_phy_open()
1512 phydev = phy_find_first(adapter->mdiobus); in lan743x_phy_open()
1514 if ((adapter->csr.id_rev & ID_REV_ID_MASK_) == in lan743x_phy_open()
1531 adapter->phy_interface); in lan743x_phy_open()
1541 phy->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX); in lan743x_phy_open()
1542 phy->fc_autoneg = phydev->autoneg; in lan743x_phy_open()
1578 mac_addr = adapter->mac_address; in lan743x_rfe_update_mac_address()
1593 struct net_device *netdev = adapter->netdev; in lan743x_rfe_set_multicast()
1602 if (netdev->flags & IFF_PROMISC) { in lan743x_rfe_set_multicast()
1605 if (netdev->flags & IFF_ALLMULTI) in lan743x_rfe_set_multicast()
1609 if (netdev->features & NETIF_F_RXCSUM) in lan743x_rfe_set_multicast()
1624 data = ha->addr[3]; in lan743x_rfe_set_multicast()
1625 data = ha->addr[2] | (data << 8); in lan743x_rfe_set_multicast()
1626 data = ha->addr[1] | (data << 8); in lan743x_rfe_set_multicast()
1627 data = ha->addr[0] | (data << 8); in lan743x_rfe_set_multicast()
1630 data = ha->addr[5]; in lan743x_rfe_set_multicast()
1631 data = ha->addr[4] | (data << 8); in lan743x_rfe_set_multicast()
1636 u32 bitnum = (ether_crc(ETH_ALEN, ha->addr) >> in lan743x_rfe_set_multicast()
1672 return -EPERM; in lan743x_dmac_init()
1674 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) in lan743x_dmac_init()
1715 timeout--; in lan743x_dmac_tx_wait_till_stopped()
1718 result = -ENODEV; in lan743x_dmac_tx_wait_till_stopped()
1744 timeout--; in lan743x_dmac_rx_wait_till_stopped()
1747 result = -ENODEV; in lan743x_dmac_rx_wait_till_stopped()
1751 static void lan743x_tx_release_desc(struct lan743x_tx *tx, in lan743x_tx_release_desc() argument
1759 descriptor = &tx->ring_cpu_ptr[descriptor_index]; in lan743x_tx_release_desc()
1760 buffer_info = &tx->buffer_info[descriptor_index]; in lan743x_tx_release_desc()
1761 if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_ACTIVE)) in lan743x_tx_release_desc()
1764 descriptor_type = le32_to_cpu(descriptor->data0) & in lan743x_tx_release_desc()
1772 if (buffer_info->dma_ptr) { in lan743x_tx_release_desc()
1773 if (buffer_info->flags & in lan743x_tx_release_desc()
1775 dma_unmap_page(&tx->adapter->pdev->dev, in lan743x_tx_release_desc()
1776 buffer_info->dma_ptr, in lan743x_tx_release_desc()
1777 buffer_info->buffer_length, in lan743x_tx_release_desc()
1780 dma_unmap_single(&tx->adapter->pdev->dev, in lan743x_tx_release_desc()
1781 buffer_info->dma_ptr, in lan743x_tx_release_desc()
1782 buffer_info->buffer_length, in lan743x_tx_release_desc()
1785 buffer_info->dma_ptr = 0; in lan743x_tx_release_desc()
1786 buffer_info->buffer_length = 0; in lan743x_tx_release_desc()
1788 if (!buffer_info->skb) in lan743x_tx_release_desc()
1791 if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED)) { in lan743x_tx_release_desc()
1792 dev_kfree_skb_any(buffer_info->skb); in lan743x_tx_release_desc()
1797 lan743x_ptp_unrequest_tx_timestamp(tx->adapter); in lan743x_tx_release_desc()
1798 dev_kfree_skb_any(buffer_info->skb); in lan743x_tx_release_desc()
1800 ignore_sync = (buffer_info->flags & in lan743x_tx_release_desc()
1802 lan743x_ptp_tx_timestamp_skb(tx->adapter, in lan743x_tx_release_desc()
1803 buffer_info->skb, ignore_sync); in lan743x_tx_release_desc()
1807 buffer_info->skb = NULL; in lan743x_tx_release_desc()
1810 buffer_info->flags &= ~TX_BUFFER_INFO_FLAG_ACTIVE; in lan743x_tx_release_desc()
1817 static int lan743x_tx_next_index(struct lan743x_tx *tx, int index) in lan743x_tx_next_index() argument
1819 return ((++index) % tx->ring_size); in lan743x_tx_next_index()
1822 static void lan743x_tx_release_completed_descriptors(struct lan743x_tx *tx) in lan743x_tx_release_completed_descriptors() argument
1824 while (le32_to_cpu(*tx->head_cpu_ptr) != (tx->last_head)) { in lan743x_tx_release_completed_descriptors()
1825 lan743x_tx_release_desc(tx, tx->last_head, false); in lan743x_tx_release_completed_descriptors()
1826 tx->last_head = lan743x_tx_next_index(tx, tx->last_head); in lan743x_tx_release_completed_descriptors()
1830 static void lan743x_tx_release_all_descriptors(struct lan743x_tx *tx) in lan743x_tx_release_all_descriptors() argument
1834 original_head = tx->last_head; in lan743x_tx_release_all_descriptors()
1836 lan743x_tx_release_desc(tx, tx->last_head, true); in lan743x_tx_release_all_descriptors()
1837 tx->last_head = lan743x_tx_next_index(tx, tx->last_head); in lan743x_tx_release_all_descriptors()
1838 } while (tx->last_head != original_head); in lan743x_tx_release_all_descriptors()
1839 memset(tx->ring_cpu_ptr, 0, in lan743x_tx_release_all_descriptors()
1840 sizeof(*tx->ring_cpu_ptr) * (tx->ring_size)); in lan743x_tx_release_all_descriptors()
1841 memset(tx->buffer_info, 0, in lan743x_tx_release_all_descriptors()
1842 sizeof(*tx->buffer_info) * (tx->ring_size)); in lan743x_tx_release_all_descriptors()
1845 static int lan743x_tx_get_desc_cnt(struct lan743x_tx *tx, in lan743x_tx_get_desc_cnt() argument
1853 nr_frags = skb_shinfo(skb)->nr_frags; in lan743x_tx_get_desc_cnt()
1858 static int lan743x_tx_get_avail_desc(struct lan743x_tx *tx) in lan743x_tx_get_avail_desc() argument
1860 int last_head = tx->last_head; in lan743x_tx_get_avail_desc()
1861 int last_tail = tx->last_tail; in lan743x_tx_get_avail_desc()
1864 return tx->ring_size - last_tail + last_head - 1; in lan743x_tx_get_avail_desc()
1866 return last_head - last_tail - 1; in lan743x_tx_get_avail_desc()
1869 void lan743x_tx_set_timestamping_mode(struct lan743x_tx *tx, in lan743x_tx_set_timestamping_mode() argument
1874 tx->ts_flags |= TX_TS_FLAG_TIMESTAMPING_ENABLED; in lan743x_tx_set_timestamping_mode()
1876 tx->ts_flags &= ~TX_TS_FLAG_TIMESTAMPING_ENABLED; in lan743x_tx_set_timestamping_mode()
1878 tx->ts_flags |= TX_TS_FLAG_ONE_STEP_SYNC; in lan743x_tx_set_timestamping_mode()
1880 tx->ts_flags &= ~TX_TS_FLAG_ONE_STEP_SYNC; in lan743x_tx_set_timestamping_mode()
1883 static int lan743x_tx_frame_start(struct lan743x_tx *tx, in lan743x_tx_frame_start() argument
1891 * assuming tx->ring_lock has already been acquired. in lan743x_tx_frame_start()
1895 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_frame_start()
1896 struct device *dev = &adapter->pdev->dev; in lan743x_tx_frame_start()
1899 tx->frame_flags |= TX_FRAME_FLAG_IN_PROGRESS; in lan743x_tx_frame_start()
1900 tx->frame_first = tx->last_tail; in lan743x_tx_frame_start()
1901 tx->frame_tail = tx->frame_first; in lan743x_tx_frame_start()
1903 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_start()
1904 buffer_info = &tx->buffer_info[tx->frame_tail]; in lan743x_tx_frame_start()
1908 return -ENOMEM; in lan743x_tx_frame_start()
1910 tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr)); in lan743x_tx_frame_start()
1911 tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr)); in lan743x_tx_frame_start()
1912 tx_descriptor->data3 = cpu_to_le32((frame_length << 16) & in lan743x_tx_frame_start()
1915 buffer_info->skb = NULL; in lan743x_tx_frame_start()
1916 buffer_info->dma_ptr = dma_ptr; in lan743x_tx_frame_start()
1917 buffer_info->buffer_length = first_buffer_length; in lan743x_tx_frame_start()
1918 buffer_info->flags |= TX_BUFFER_INFO_FLAG_ACTIVE; in lan743x_tx_frame_start()
1920 tx->frame_data0 = (first_buffer_length & in lan743x_tx_frame_start()
1926 tx->frame_data0 |= TX_DESC_DATA0_TSE_; in lan743x_tx_frame_start()
1929 tx->frame_data0 |= TX_DESC_DATA0_ICE_ | in lan743x_tx_frame_start()
1937 static void lan743x_tx_frame_add_lso(struct lan743x_tx *tx, in lan743x_tx_frame_add_lso() argument
1942 * assuming tx->ring_lock has already been acquired. in lan743x_tx_frame_add_lso()
1948 tx->frame_data0 |= TX_DESC_DATA0_EXT_; in lan743x_tx_frame_add_lso()
1950 tx->frame_data0 |= TX_DESC_DATA0_LS_; in lan743x_tx_frame_add_lso()
1951 tx->frame_data0 |= TX_DESC_DATA0_IOC_; in lan743x_tx_frame_add_lso()
1953 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_add_lso()
1954 tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); in lan743x_tx_frame_add_lso()
1957 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); in lan743x_tx_frame_add_lso()
1958 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_add_lso()
1959 buffer_info = &tx->buffer_info[tx->frame_tail]; in lan743x_tx_frame_add_lso()
1962 tx_descriptor->data1 = 0; in lan743x_tx_frame_add_lso()
1963 tx_descriptor->data2 = 0; in lan743x_tx_frame_add_lso()
1964 tx_descriptor->data3 = 0; in lan743x_tx_frame_add_lso()
1966 buffer_info->skb = NULL; in lan743x_tx_frame_add_lso()
1967 buffer_info->dma_ptr = 0; in lan743x_tx_frame_add_lso()
1968 buffer_info->buffer_length = 0; in lan743x_tx_frame_add_lso()
1969 buffer_info->flags |= TX_BUFFER_INFO_FLAG_ACTIVE; in lan743x_tx_frame_add_lso()
1971 tx->frame_data0 = (frame_length & TX_DESC_DATA0_EXT_PAY_LENGTH_MASK_) | in lan743x_tx_frame_add_lso()
1978 static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx, in lan743x_tx_frame_add_fragment() argument
1983 * assuming tx->ring_lock has already been acquired in lan743x_tx_frame_add_fragment()
1987 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_frame_add_fragment()
1988 struct device *dev = &adapter->pdev->dev; in lan743x_tx_frame_add_fragment()
1997 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_add_fragment()
1998 tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); in lan743x_tx_frame_add_fragment()
2001 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); in lan743x_tx_frame_add_fragment()
2002 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_add_fragment()
2003 buffer_info = &tx->buffer_info[tx->frame_tail]; in lan743x_tx_frame_add_fragment()
2011 desc_index = tx->frame_first; in lan743x_tx_frame_add_fragment()
2012 while (desc_index != tx->frame_tail) { in lan743x_tx_frame_add_fragment()
2013 lan743x_tx_release_desc(tx, desc_index, true); in lan743x_tx_frame_add_fragment()
2014 desc_index = lan743x_tx_next_index(tx, desc_index); in lan743x_tx_frame_add_fragment()
2017 tx->frame_flags &= ~TX_FRAME_FLAG_IN_PROGRESS; in lan743x_tx_frame_add_fragment()
2018 tx->frame_first = 0; in lan743x_tx_frame_add_fragment()
2019 tx->frame_data0 = 0; in lan743x_tx_frame_add_fragment()
2020 tx->frame_tail = 0; in lan743x_tx_frame_add_fragment()
2021 return -ENOMEM; in lan743x_tx_frame_add_fragment()
2024 tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr)); in lan743x_tx_frame_add_fragment()
2025 tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr)); in lan743x_tx_frame_add_fragment()
2026 tx_descriptor->data3 = cpu_to_le32((frame_length << 16) & in lan743x_tx_frame_add_fragment()
2029 buffer_info->skb = NULL; in lan743x_tx_frame_add_fragment()
2030 buffer_info->dma_ptr = dma_ptr; in lan743x_tx_frame_add_fragment()
2031 buffer_info->buffer_length = fragment_length; in lan743x_tx_frame_add_fragment()
2032 buffer_info->flags |= TX_BUFFER_INFO_FLAG_ACTIVE; in lan743x_tx_frame_add_fragment()
2033 buffer_info->flags |= TX_BUFFER_INFO_FLAG_SKB_FRAGMENT; in lan743x_tx_frame_add_fragment()
2035 tx->frame_data0 = (fragment_length & TX_DESC_DATA0_BUF_LENGTH_MASK_) | in lan743x_tx_frame_add_fragment()
2043 static void lan743x_tx_frame_end(struct lan743x_tx *tx, in lan743x_tx_frame_end() argument
2049 * assuming tx->ring_lock has already been acquired in lan743x_tx_frame_end()
2053 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_frame_end()
2057 if ((tx->frame_data0 & TX_DESC_DATA0_DTYPE_MASK_) == in lan743x_tx_frame_end()
2059 tx->frame_data0 |= TX_DESC_DATA0_LS_; in lan743x_tx_frame_end()
2060 tx->frame_data0 |= TX_DESC_DATA0_IOC_; in lan743x_tx_frame_end()
2063 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; in lan743x_tx_frame_end()
2064 buffer_info = &tx->buffer_info[tx->frame_tail]; in lan743x_tx_frame_end()
2065 buffer_info->skb = skb; in lan743x_tx_frame_end()
2067 buffer_info->flags |= TX_BUFFER_INFO_FLAG_TIMESTAMP_REQUESTED; in lan743x_tx_frame_end()
2069 buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC; in lan743x_tx_frame_end()
2071 tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); in lan743x_tx_frame_end()
2072 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); in lan743x_tx_frame_end()
2073 tx->last_tail = tx->frame_tail; in lan743x_tx_frame_end()
2077 if (tx->vector_flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET) in lan743x_tx_frame_end()
2079 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET) in lan743x_tx_frame_end()
2083 lan743x_csr_write(adapter, TX_TAIL(tx->channel_number), in lan743x_tx_frame_end()
2084 tx_tail_flags | tx->frame_tail); in lan743x_tx_frame_end()
2085 tx->frame_flags &= ~TX_FRAME_FLAG_IN_PROGRESS; in lan743x_tx_frame_end()
2088 static netdev_tx_t lan743x_tx_xmit_frame(struct lan743x_tx *tx, in lan743x_tx_xmit_frame() argument
2104 required_number_of_descriptors = lan743x_tx_get_desc_cnt(tx, skb); in lan743x_tx_xmit_frame()
2106 spin_lock_irqsave(&tx->ring_lock, irq_flags); in lan743x_tx_xmit_frame()
2108 lan743x_tx_get_avail_desc(tx)) { in lan743x_tx_xmit_frame()
2109 if (required_number_of_descriptors > (tx->ring_size - 1)) { in lan743x_tx_xmit_frame()
2113 tx->rqd_descriptors = required_number_of_descriptors; in lan743x_tx_xmit_frame()
2115 txq = netdev_get_tx_queue(tx->adapter->netdev, in lan743x_tx_xmit_frame()
2116 tx->channel_number); in lan743x_tx_xmit_frame()
2123 if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && in lan743x_tx_xmit_frame()
2124 (tx->ts_flags & TX_TS_FLAG_TIMESTAMPING_ENABLED) && in lan743x_tx_xmit_frame()
2125 (lan743x_ptp_request_tx_timestamp(tx->adapter))) { in lan743x_tx_xmit_frame()
2126 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in lan743x_tx_xmit_frame()
2128 if (tx->ts_flags & TX_TS_FLAG_ONE_STEP_SYNC) in lan743x_tx_xmit_frame()
2133 nr_frags = skb_shinfo(skb)->nr_frags; in lan743x_tx_xmit_frame()
2137 start_frame_length = max(skb_shinfo(skb)->gso_size, in lan743x_tx_xmit_frame()
2141 if (lan743x_tx_frame_start(tx, in lan743x_tx_xmit_frame()
2142 skb->data, head_length, in lan743x_tx_xmit_frame()
2145 skb->ip_summed == CHECKSUM_PARTIAL)) { in lan743x_tx_xmit_frame()
2149 tx->frame_count++; in lan743x_tx_xmit_frame()
2152 lan743x_tx_frame_add_lso(tx, frame_length, nr_frags); in lan743x_tx_xmit_frame()
2158 const skb_frag_t *frag = &(skb_shinfo(skb)->frags[j]); in lan743x_tx_xmit_frame()
2160 if (lan743x_tx_frame_add_fragment(tx, frag, frame_length)) { in lan743x_tx_xmit_frame()
2172 lan743x_tx_frame_end(tx, skb, do_timestamp, ignore_sync); in lan743x_tx_xmit_frame()
2175 spin_unlock_irqrestore(&tx->ring_lock, irq_flags); in lan743x_tx_xmit_frame()
2181 struct lan743x_tx *tx = container_of(napi, struct lan743x_tx, napi); in lan743x_tx_napi_poll() local
2182 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_napi_poll()
2187 ioc_bit = DMAC_INT_BIT_TX_IOC_(tx->channel_number); in lan743x_tx_napi_poll()
2189 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_W2C) in lan743x_tx_napi_poll()
2191 spin_lock_irqsave(&tx->ring_lock, irq_flags); in lan743x_tx_napi_poll()
2193 /* clean up tx ring */ in lan743x_tx_napi_poll()
2194 lan743x_tx_release_completed_descriptors(tx); in lan743x_tx_napi_poll()
2195 txq = netdev_get_tx_queue(adapter->netdev, tx->channel_number); in lan743x_tx_napi_poll()
2197 if (tx->rqd_descriptors) { in lan743x_tx_napi_poll()
2198 if (tx->rqd_descriptors <= in lan743x_tx_napi_poll()
2199 lan743x_tx_get_avail_desc(tx)) { in lan743x_tx_napi_poll()
2200 tx->rqd_descriptors = 0; in lan743x_tx_napi_poll()
2207 spin_unlock_irqrestore(&tx->ring_lock, irq_flags); in lan743x_tx_napi_poll()
2214 INT_BIT_DMA_TX_(tx->channel_number)); in lan743x_tx_napi_poll()
2221 static void lan743x_tx_ring_cleanup(struct lan743x_tx *tx) in lan743x_tx_ring_cleanup() argument
2223 if (tx->head_cpu_ptr) { in lan743x_tx_ring_cleanup()
2224 dma_free_coherent(&tx->adapter->pdev->dev, in lan743x_tx_ring_cleanup()
2225 sizeof(*tx->head_cpu_ptr), tx->head_cpu_ptr, in lan743x_tx_ring_cleanup()
2226 tx->head_dma_ptr); in lan743x_tx_ring_cleanup()
2227 tx->head_cpu_ptr = NULL; in lan743x_tx_ring_cleanup()
2228 tx->head_dma_ptr = 0; in lan743x_tx_ring_cleanup()
2230 kfree(tx->buffer_info); in lan743x_tx_ring_cleanup()
2231 tx->buffer_info = NULL; in lan743x_tx_ring_cleanup()
2233 if (tx->ring_cpu_ptr) { in lan743x_tx_ring_cleanup()
2234 dma_free_coherent(&tx->adapter->pdev->dev, in lan743x_tx_ring_cleanup()
2235 tx->ring_allocation_size, tx->ring_cpu_ptr, in lan743x_tx_ring_cleanup()
2236 tx->ring_dma_ptr); in lan743x_tx_ring_cleanup()
2237 tx->ring_allocation_size = 0; in lan743x_tx_ring_cleanup()
2238 tx->ring_cpu_ptr = NULL; in lan743x_tx_ring_cleanup()
2239 tx->ring_dma_ptr = 0; in lan743x_tx_ring_cleanup()
2241 tx->ring_size = 0; in lan743x_tx_ring_cleanup()
2244 static int lan743x_tx_ring_init(struct lan743x_tx *tx) in lan743x_tx_ring_init() argument
2249 int ret = -ENOMEM; in lan743x_tx_ring_init()
2251 tx->ring_size = LAN743X_TX_RING_SIZE; in lan743x_tx_ring_init()
2252 if (tx->ring_size & ~TX_CFG_B_TX_RING_LEN_MASK_) { in lan743x_tx_ring_init()
2253 ret = -EINVAL; in lan743x_tx_ring_init()
2256 if (dma_set_mask_and_coherent(&tx->adapter->pdev->dev, in lan743x_tx_ring_init()
2258 dev_warn(&tx->adapter->pdev->dev, in lan743x_tx_ring_init()
2260 ret = -ENOMEM; in lan743x_tx_ring_init()
2263 ring_allocation_size = ALIGN(tx->ring_size * in lan743x_tx_ring_init()
2267 cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev, in lan743x_tx_ring_init()
2270 ret = -ENOMEM; in lan743x_tx_ring_init()
2274 tx->ring_allocation_size = ring_allocation_size; in lan743x_tx_ring_init()
2275 tx->ring_cpu_ptr = (struct lan743x_tx_descriptor *)cpu_ptr; in lan743x_tx_ring_init()
2276 tx->ring_dma_ptr = dma_ptr; in lan743x_tx_ring_init()
2278 cpu_ptr = kcalloc(tx->ring_size, sizeof(*tx->buffer_info), GFP_KERNEL); in lan743x_tx_ring_init()
2280 ret = -ENOMEM; in lan743x_tx_ring_init()
2283 tx->buffer_info = (struct lan743x_tx_buffer_info *)cpu_ptr; in lan743x_tx_ring_init()
2285 cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev, in lan743x_tx_ring_init()
2286 sizeof(*tx->head_cpu_ptr), &dma_ptr, in lan743x_tx_ring_init()
2289 ret = -ENOMEM; in lan743x_tx_ring_init()
2293 tx->head_cpu_ptr = cpu_ptr; in lan743x_tx_ring_init()
2294 tx->head_dma_ptr = dma_ptr; in lan743x_tx_ring_init()
2295 if (tx->head_dma_ptr & 0x3) { in lan743x_tx_ring_init()
2296 ret = -ENOMEM; in lan743x_tx_ring_init()
2303 lan743x_tx_ring_cleanup(tx); in lan743x_tx_ring_init()
2307 static void lan743x_tx_close(struct lan743x_tx *tx) in lan743x_tx_close() argument
2309 struct lan743x_adapter *adapter = tx->adapter; in lan743x_tx_close()
2313 DMAC_CMD_STOP_T_(tx->channel_number)); in lan743x_tx_close()
2314 lan743x_dmac_tx_wait_till_stopped(adapter, tx->channel_number); in lan743x_tx_close()
2318 DMAC_INT_BIT_TX_IOC_(tx->channel_number)); in lan743x_tx_close()
2320 INT_BIT_DMA_TX_(tx->channel_number)); in lan743x_tx_close()
2321 napi_disable(&tx->napi); in lan743x_tx_close()
2322 netif_napi_del(&tx->napi); in lan743x_tx_close()
2325 FCT_TX_CTL_DIS_(tx->channel_number)); in lan743x_tx_close()
2327 FCT_TX_CTL_EN_(tx->channel_number), in lan743x_tx_close()
2330 lan743x_tx_release_all_descriptors(tx); in lan743x_tx_close()
2332 tx->rqd_descriptors = 0; in lan743x_tx_close()
2334 lan743x_tx_ring_cleanup(tx); in lan743x_tx_close()
2337 static int lan743x_tx_open(struct lan743x_tx *tx) in lan743x_tx_open() argument
2343 adapter = tx->adapter; in lan743x_tx_open()
2344 ret = lan743x_tx_ring_init(tx); in lan743x_tx_open()
2350 FCT_TX_CTL_RESET_(tx->channel_number)); in lan743x_tx_open()
2352 FCT_TX_CTL_RESET_(tx->channel_number), in lan743x_tx_open()
2357 FCT_TX_CTL_EN_(tx->channel_number)); in lan743x_tx_open()
2359 /* reset tx channel */ in lan743x_tx_open()
2361 DMAC_CMD_TX_SWR_(tx->channel_number)); in lan743x_tx_open()
2363 DMAC_CMD_TX_SWR_(tx->channel_number), in lan743x_tx_open()
2368 TX_BASE_ADDRH(tx->channel_number), in lan743x_tx_open()
2369 DMA_ADDR_HIGH32(tx->ring_dma_ptr)); in lan743x_tx_open()
2371 TX_BASE_ADDRL(tx->channel_number), in lan743x_tx_open()
2372 DMA_ADDR_LOW32(tx->ring_dma_ptr)); in lan743x_tx_open()
2375 data = lan743x_csr_read(adapter, TX_CFG_B(tx->channel_number)); in lan743x_tx_open()
2377 data |= ((tx->ring_size) & TX_CFG_B_TX_RING_LEN_MASK_); in lan743x_tx_open()
2378 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) in lan743x_tx_open()
2380 lan743x_csr_write(adapter, TX_CFG_B(tx->channel_number), data); in lan743x_tx_open()
2384 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { in lan743x_tx_open()
2390 lan743x_csr_write(adapter, TX_CFG_A(tx->channel_number), data); in lan743x_tx_open()
2394 TX_HEAD_WRITEBACK_ADDRH(tx->channel_number), in lan743x_tx_open()
2395 DMA_ADDR_HIGH32(tx->head_dma_ptr)); in lan743x_tx_open()
2397 TX_HEAD_WRITEBACK_ADDRL(tx->channel_number), in lan743x_tx_open()
2398 DMA_ADDR_LOW32(tx->head_dma_ptr)); in lan743x_tx_open()
2401 tx->last_head = lan743x_csr_read(adapter, TX_HEAD(tx->channel_number)); in lan743x_tx_open()
2404 tx->last_tail = 0; in lan743x_tx_open()
2405 lan743x_csr_write(adapter, TX_TAIL(tx->channel_number), in lan743x_tx_open()
2406 (u32)(tx->last_tail)); in lan743x_tx_open()
2407 tx->vector_flags = lan743x_intr_get_vector_flags(adapter, in lan743x_tx_open()
2409 (tx->channel_number)); in lan743x_tx_open()
2410 netif_napi_add_tx_weight(adapter->netdev, in lan743x_tx_open()
2411 &tx->napi, lan743x_tx_napi_poll, in lan743x_tx_open()
2413 napi_enable(&tx->napi); in lan743x_tx_open()
2416 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_CLEAR) in lan743x_tx_open()
2418 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_AUTO_CLEAR) in lan743x_tx_open()
2420 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_R2C) in lan743x_tx_open()
2422 if (tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C) in lan743x_tx_open()
2424 lan743x_csr_write(adapter, TX_CFG_C(tx->channel_number), data); in lan743x_tx_open()
2426 if (!(tx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET)) in lan743x_tx_open()
2428 INT_BIT_DMA_TX_(tx->channel_number)); in lan743x_tx_open()
2430 DMAC_INT_BIT_TX_IOC_(tx->channel_number)); in lan743x_tx_open()
2434 DMAC_CMD_START_T_(tx->channel_number)); in lan743x_tx_open()
2438 static int lan743x_rx_next_index(struct lan743x_rx *rx, int index) in lan743x_rx_next_index() argument
2440 return ((++index) % rx->ring_size); in lan743x_rx_next_index()
2443 static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) in lan743x_rx_update_tail() argument
2447 lan743x_csr_write(rx->adapter, RX_TAIL(rx->channel_number), in lan743x_rx_update_tail()
2451 static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, in lan743x_rx_init_ring_element() argument
2454 struct net_device *netdev = rx->adapter->netdev; in lan743x_rx_init_ring_element()
2455 struct device *dev = &rx->adapter->pdev->dev; in lan743x_rx_init_ring_element()
2462 buffer_length = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + RX_HEAD_PADDING; in lan743x_rx_init_ring_element()
2464 descriptor = &rx->ring_cpu_ptr[index]; in lan743x_rx_init_ring_element()
2465 buffer_info = &rx->buffer_info[index]; in lan743x_rx_init_ring_element()
2468 return -ENOMEM; in lan743x_rx_init_ring_element()
2469 dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE); in lan743x_rx_init_ring_element()
2472 return -ENOMEM; in lan743x_rx_init_ring_element()
2474 if (buffer_info->dma_ptr) { in lan743x_rx_init_ring_element()
2476 if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) in lan743x_rx_init_ring_element()
2482 (le32_to_cpu(descriptor->data0)), in lan743x_rx_init_ring_element()
2483 buffer_info->buffer_length); in lan743x_rx_init_ring_element()
2485 used_length = buffer_info->buffer_length; in lan743x_rx_init_ring_element()
2486 dma_sync_single_for_cpu(dev, buffer_info->dma_ptr, in lan743x_rx_init_ring_element()
2489 dma_unmap_single_attrs(dev, buffer_info->dma_ptr, in lan743x_rx_init_ring_element()
2490 buffer_info->buffer_length, in lan743x_rx_init_ring_element()
2495 buffer_info->skb = skb; in lan743x_rx_init_ring_element()
2496 buffer_info->dma_ptr = dma_ptr; in lan743x_rx_init_ring_element()
2497 buffer_info->buffer_length = buffer_length; in lan743x_rx_init_ring_element()
2498 descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); in lan743x_rx_init_ring_element()
2499 descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); in lan743x_rx_init_ring_element()
2500 descriptor->data3 = 0; in lan743x_rx_init_ring_element()
2501 descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | in lan743x_rx_init_ring_element()
2503 lan743x_rx_update_tail(rx, index); in lan743x_rx_init_ring_element()
2508 static void lan743x_rx_reuse_ring_element(struct lan743x_rx *rx, int index) in lan743x_rx_reuse_ring_element() argument
2513 descriptor = &rx->ring_cpu_ptr[index]; in lan743x_rx_reuse_ring_element()
2514 buffer_info = &rx->buffer_info[index]; in lan743x_rx_reuse_ring_element()
2516 descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); in lan743x_rx_reuse_ring_element()
2517 descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); in lan743x_rx_reuse_ring_element()
2518 descriptor->data3 = 0; in lan743x_rx_reuse_ring_element()
2519 descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | in lan743x_rx_reuse_ring_element()
2520 ((buffer_info->buffer_length) & in lan743x_rx_reuse_ring_element()
2522 lan743x_rx_update_tail(rx, index); in lan743x_rx_reuse_ring_element()
2525 static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index) in lan743x_rx_release_ring_element() argument
2530 descriptor = &rx->ring_cpu_ptr[index]; in lan743x_rx_release_ring_element()
2531 buffer_info = &rx->buffer_info[index]; in lan743x_rx_release_ring_element()
2535 if (buffer_info->dma_ptr) { in lan743x_rx_release_ring_element()
2536 dma_unmap_single(&rx->adapter->pdev->dev, in lan743x_rx_release_ring_element()
2537 buffer_info->dma_ptr, in lan743x_rx_release_ring_element()
2538 buffer_info->buffer_length, in lan743x_rx_release_ring_element()
2540 buffer_info->dma_ptr = 0; in lan743x_rx_release_ring_element()
2543 if (buffer_info->skb) { in lan743x_rx_release_ring_element()
2544 dev_kfree_skb(buffer_info->skb); in lan743x_rx_release_ring_element()
2545 buffer_info->skb = NULL; in lan743x_rx_release_ring_element()
2558 frame_length = max_t(int, 0, frame_length - ETH_FCS_LEN); in lan743x_rx_trim_skb()
2559 if (skb->len > frame_length) { in lan743x_rx_trim_skb()
2560 skb->tail -= skb->len - frame_length; in lan743x_rx_trim_skb()
2561 skb->len = frame_length; in lan743x_rx_trim_skb()
2566 static int lan743x_rx_process_buffer(struct lan743x_rx *rx) in lan743x_rx_process_buffer() argument
2568 int current_head_index = le32_to_cpu(*rx->head_cpu_ptr); in lan743x_rx_process_buffer()
2570 struct net_device *netdev = rx->adapter->netdev; in lan743x_rx_process_buffer()
2575 int extension_index = -1; in lan743x_rx_process_buffer()
2579 if (current_head_index < 0 || current_head_index >= rx->ring_size) in lan743x_rx_process_buffer()
2582 if (rx->last_head < 0 || rx->last_head >= rx->ring_size) in lan743x_rx_process_buffer()
2585 if (rx->last_head == current_head_index) in lan743x_rx_process_buffer()
2588 descriptor = &rx->ring_cpu_ptr[rx->last_head]; in lan743x_rx_process_buffer()
2589 if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) in lan743x_rx_process_buffer()
2591 buffer_info = &rx->buffer_info[rx->last_head]; in lan743x_rx_process_buffer()
2593 is_last = le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_; in lan743x_rx_process_buffer()
2594 is_first = le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_; in lan743x_rx_process_buffer()
2596 if (is_last && le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_EXT_) { in lan743x_rx_process_buffer()
2598 int index = lan743x_rx_next_index(rx, rx->last_head); in lan743x_rx_process_buffer()
2603 desc_ext = &rx->ring_cpu_ptr[index]; in lan743x_rx_process_buffer()
2604 if (le32_to_cpu(desc_ext->data0) & RX_DESC_DATA0_OWN_) in lan743x_rx_process_buffer()
2607 if (!(le32_to_cpu(desc_ext->data0) & RX_DESC_DATA0_EXT_)) in lan743x_rx_process_buffer()
2612 /* Only the last buffer in a multi-buffer frame contains the total frame in lan743x_rx_process_buffer()
2619 RX_DESC_DATA0_FRAME_LENGTH_GET_(le32_to_cpu(descriptor->data0)); in lan743x_rx_process_buffer()
2620 buffer_length = buffer_info->buffer_length; in lan743x_rx_process_buffer()
2621 is_ice = le32_to_cpu(descriptor->data1) & RX_DESC_DATA1_STATUS_ICE_; in lan743x_rx_process_buffer()
2622 is_tce = le32_to_cpu(descriptor->data1) & RX_DESC_DATA1_STATUS_TCE_; in lan743x_rx_process_buffer()
2623 is_icsm = le32_to_cpu(descriptor->data1) & RX_DESC_DATA1_STATUS_ICSM_; in lan743x_rx_process_buffer()
2631 skb = buffer_info->skb; in lan743x_rx_process_buffer()
2632 if (lan743x_rx_init_ring_element(rx, rx->last_head, in lan743x_rx_process_buffer()
2638 lan743x_rx_reuse_ring_element(rx, rx->last_head); in lan743x_rx_process_buffer()
2640 dev_kfree_skb_irq(rx->skb_head); in lan743x_rx_process_buffer()
2641 rx->skb_head = NULL; in lan743x_rx_process_buffer()
2645 /* add buffers to skb via skb->frag_list */ in lan743x_rx_process_buffer()
2648 skb_put(skb, buffer_length - RX_HEAD_PADDING); in lan743x_rx_process_buffer()
2649 if (rx->skb_head) in lan743x_rx_process_buffer()
2650 dev_kfree_skb_irq(rx->skb_head); in lan743x_rx_process_buffer()
2651 rx->skb_head = skb; in lan743x_rx_process_buffer()
2652 } else if (rx->skb_head) { in lan743x_rx_process_buffer()
2654 if (skb_shinfo(rx->skb_head)->frag_list) in lan743x_rx_process_buffer()
2655 rx->skb_tail->next = skb; in lan743x_rx_process_buffer()
2657 skb_shinfo(rx->skb_head)->frag_list = skb; in lan743x_rx_process_buffer()
2658 rx->skb_tail = skb; in lan743x_rx_process_buffer()
2659 rx->skb_head->len += skb->len; in lan743x_rx_process_buffer()
2660 rx->skb_head->data_len += skb->len; in lan743x_rx_process_buffer()
2661 rx->skb_head->truesize += skb->truesize; in lan743x_rx_process_buffer()
2675 ts_sec = le32_to_cpu(desc_ext->data1); in lan743x_rx_process_buffer()
2676 ts_nsec = (le32_to_cpu(desc_ext->data2) & in lan743x_rx_process_buffer()
2678 if (rx->skb_head) in lan743x_rx_process_buffer()
2679 skb_hwtstamps(rx->skb_head)->hwtstamp = in lan743x_rx_process_buffer()
2681 lan743x_rx_reuse_ring_element(rx, extension_index); in lan743x_rx_process_buffer()
2682 rx->last_head = extension_index; in lan743x_rx_process_buffer()
2686 if (is_last && rx->skb_head) in lan743x_rx_process_buffer()
2687 rx->skb_head = lan743x_rx_trim_skb(rx->skb_head, frame_length); in lan743x_rx_process_buffer()
2689 if (is_last && rx->skb_head) { in lan743x_rx_process_buffer()
2690 rx->skb_head->protocol = eth_type_trans(rx->skb_head, in lan743x_rx_process_buffer()
2691 rx->adapter->netdev); in lan743x_rx_process_buffer()
2692 if (rx->adapter->netdev->features & NETIF_F_RXCSUM) { in lan743x_rx_process_buffer()
2694 skb->ip_summed = CHECKSUM_UNNECESSARY; in lan743x_rx_process_buffer()
2697 rx->skb_head->len); in lan743x_rx_process_buffer()
2698 napi_gro_receive(&rx->napi, rx->skb_head); in lan743x_rx_process_buffer()
2699 rx->skb_head = NULL; in lan743x_rx_process_buffer()
2704 rx->last_tail = rx->last_head; in lan743x_rx_process_buffer()
2705 rx->last_head = lan743x_rx_next_index(rx, rx->last_head); in lan743x_rx_process_buffer()
2713 struct lan743x_rx *rx = container_of(napi, struct lan743x_rx, napi); in lan743x_rx_napi_poll() local
2714 struct lan743x_adapter *adapter = rx->adapter; in lan743x_rx_napi_poll()
2719 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_W2C) { in lan743x_rx_napi_poll()
2722 DMAC_INT_BIT_RXFRM_(rx->channel_number)); in lan743x_rx_napi_poll()
2725 result = lan743x_rx_process_buffer(rx); in lan743x_rx_napi_poll()
2729 rx->frame_count += count; in lan743x_rx_napi_poll()
2736 /* re-arm interrupts, must write to rx tail on some chip variants */ in lan743x_rx_napi_poll()
2737 if (rx->vector_flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET) in lan743x_rx_napi_poll()
2739 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET) { in lan743x_rx_napi_poll()
2743 INT_BIT_DMA_RX_(rx->channel_number)); in lan743x_rx_napi_poll()
2747 lan743x_csr_write(adapter, RX_TAIL(rx->channel_number), in lan743x_rx_napi_poll()
2748 rx_tail_flags | rx->last_tail); in lan743x_rx_napi_poll()
2753 static void lan743x_rx_ring_cleanup(struct lan743x_rx *rx) in lan743x_rx_ring_cleanup() argument
2755 if (rx->buffer_info && rx->ring_cpu_ptr) { in lan743x_rx_ring_cleanup()
2758 for (index = 0; index < rx->ring_size; index++) in lan743x_rx_ring_cleanup()
2759 lan743x_rx_release_ring_element(rx, index); in lan743x_rx_ring_cleanup()
2762 if (rx->head_cpu_ptr) { in lan743x_rx_ring_cleanup()
2763 dma_free_coherent(&rx->adapter->pdev->dev, in lan743x_rx_ring_cleanup()
2764 sizeof(*rx->head_cpu_ptr), rx->head_cpu_ptr, in lan743x_rx_ring_cleanup()
2765 rx->head_dma_ptr); in lan743x_rx_ring_cleanup()
2766 rx->head_cpu_ptr = NULL; in lan743x_rx_ring_cleanup()
2767 rx->head_dma_ptr = 0; in lan743x_rx_ring_cleanup()
2770 kfree(rx->buffer_info); in lan743x_rx_ring_cleanup()
2771 rx->buffer_info = NULL; in lan743x_rx_ring_cleanup()
2773 if (rx->ring_cpu_ptr) { in lan743x_rx_ring_cleanup()
2774 dma_free_coherent(&rx->adapter->pdev->dev, in lan743x_rx_ring_cleanup()
2775 rx->ring_allocation_size, rx->ring_cpu_ptr, in lan743x_rx_ring_cleanup()
2776 rx->ring_dma_ptr); in lan743x_rx_ring_cleanup()
2777 rx->ring_allocation_size = 0; in lan743x_rx_ring_cleanup()
2778 rx->ring_cpu_ptr = NULL; in lan743x_rx_ring_cleanup()
2779 rx->ring_dma_ptr = 0; in lan743x_rx_ring_cleanup()
2782 rx->ring_size = 0; in lan743x_rx_ring_cleanup()
2783 rx->last_head = 0; in lan743x_rx_ring_cleanup()
2786 static int lan743x_rx_ring_init(struct lan743x_rx *rx) in lan743x_rx_ring_init() argument
2791 int ret = -ENOMEM; in lan743x_rx_ring_init()
2794 rx->ring_size = LAN743X_RX_RING_SIZE; in lan743x_rx_ring_init()
2795 if (rx->ring_size <= 1) { in lan743x_rx_ring_init()
2796 ret = -EINVAL; in lan743x_rx_ring_init()
2799 if (rx->ring_size & ~RX_CFG_B_RX_RING_LEN_MASK_) { in lan743x_rx_ring_init()
2800 ret = -EINVAL; in lan743x_rx_ring_init()
2803 if (dma_set_mask_and_coherent(&rx->adapter->pdev->dev, in lan743x_rx_ring_init()
2805 dev_warn(&rx->adapter->pdev->dev, in lan743x_rx_ring_init()
2807 ret = -ENOMEM; in lan743x_rx_ring_init()
2810 ring_allocation_size = ALIGN(rx->ring_size * in lan743x_rx_ring_init()
2814 cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev, in lan743x_rx_ring_init()
2817 ret = -ENOMEM; in lan743x_rx_ring_init()
2820 rx->ring_allocation_size = ring_allocation_size; in lan743x_rx_ring_init()
2821 rx->ring_cpu_ptr = (struct lan743x_rx_descriptor *)cpu_ptr; in lan743x_rx_ring_init()
2822 rx->ring_dma_ptr = dma_ptr; in lan743x_rx_ring_init()
2824 cpu_ptr = kcalloc(rx->ring_size, sizeof(*rx->buffer_info), in lan743x_rx_ring_init()
2827 ret = -ENOMEM; in lan743x_rx_ring_init()
2830 rx->buffer_info = (struct lan743x_rx_buffer_info *)cpu_ptr; in lan743x_rx_ring_init()
2832 cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev, in lan743x_rx_ring_init()
2833 sizeof(*rx->head_cpu_ptr), &dma_ptr, in lan743x_rx_ring_init()
2836 ret = -ENOMEM; in lan743x_rx_ring_init()
2840 rx->head_cpu_ptr = cpu_ptr; in lan743x_rx_ring_init()
2841 rx->head_dma_ptr = dma_ptr; in lan743x_rx_ring_init()
2842 if (rx->head_dma_ptr & 0x3) { in lan743x_rx_ring_init()
2843 ret = -ENOMEM; in lan743x_rx_ring_init()
2847 rx->last_head = 0; in lan743x_rx_ring_init()
2848 for (index = 0; index < rx->ring_size; index++) { in lan743x_rx_ring_init()
2849 ret = lan743x_rx_init_ring_element(rx, index, GFP_KERNEL); in lan743x_rx_ring_init()
2856 netif_warn(rx->adapter, ifup, rx->adapter->netdev, in lan743x_rx_ring_init()
2859 lan743x_rx_ring_cleanup(rx); in lan743x_rx_ring_init()
2863 static void lan743x_rx_close(struct lan743x_rx *rx) in lan743x_rx_close() argument
2865 struct lan743x_adapter *adapter = rx->adapter; in lan743x_rx_close()
2868 FCT_RX_CTL_DIS_(rx->channel_number)); in lan743x_rx_close()
2870 FCT_RX_CTL_EN_(rx->channel_number), in lan743x_rx_close()
2874 DMAC_CMD_STOP_R_(rx->channel_number)); in lan743x_rx_close()
2875 lan743x_dmac_rx_wait_till_stopped(adapter, rx->channel_number); in lan743x_rx_close()
2878 DMAC_INT_BIT_RXFRM_(rx->channel_number)); in lan743x_rx_close()
2880 INT_BIT_DMA_RX_(rx->channel_number)); in lan743x_rx_close()
2881 napi_disable(&rx->napi); in lan743x_rx_close()
2883 netif_napi_del(&rx->napi); in lan743x_rx_close()
2885 lan743x_rx_ring_cleanup(rx); in lan743x_rx_close()
2888 static int lan743x_rx_open(struct lan743x_rx *rx) in lan743x_rx_open() argument
2890 struct lan743x_adapter *adapter = rx->adapter; in lan743x_rx_open()
2894 rx->frame_count = 0; in lan743x_rx_open()
2895 ret = lan743x_rx_ring_init(rx); in lan743x_rx_open()
2899 netif_napi_add(adapter->netdev, &rx->napi, lan743x_rx_napi_poll); in lan743x_rx_open()
2902 DMAC_CMD_RX_SWR_(rx->channel_number)); in lan743x_rx_open()
2904 DMAC_CMD_RX_SWR_(rx->channel_number), in lan743x_rx_open()
2909 RX_BASE_ADDRH(rx->channel_number), in lan743x_rx_open()
2910 DMA_ADDR_HIGH32(rx->ring_dma_ptr)); in lan743x_rx_open()
2912 RX_BASE_ADDRL(rx->channel_number), in lan743x_rx_open()
2913 DMA_ADDR_LOW32(rx->ring_dma_ptr)); in lan743x_rx_open()
2915 /* set rx write back address */ in lan743x_rx_open()
2917 RX_HEAD_WRITEBACK_ADDRH(rx->channel_number), in lan743x_rx_open()
2918 DMA_ADDR_HIGH32(rx->head_dma_ptr)); in lan743x_rx_open()
2920 RX_HEAD_WRITEBACK_ADDRL(rx->channel_number), in lan743x_rx_open()
2921 DMA_ADDR_LOW32(rx->head_dma_ptr)); in lan743x_rx_open()
2923 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) { in lan743x_rx_open()
2932 RX_CFG_A(rx->channel_number), data); in lan743x_rx_open()
2935 data = lan743x_csr_read(adapter, RX_CFG_B(rx->channel_number)); in lan743x_rx_open()
2942 data |= ((rx->ring_size) & RX_CFG_B_RX_RING_LEN_MASK_); in lan743x_rx_open()
2944 if (!(adapter->csr.flags & LAN743X_CSR_FLAG_IS_A0)) in lan743x_rx_open()
2947 lan743x_csr_write(adapter, RX_CFG_B(rx->channel_number), data); in lan743x_rx_open()
2948 rx->vector_flags = lan743x_intr_get_vector_flags(adapter, in lan743x_rx_open()
2950 (rx->channel_number)); in lan743x_rx_open()
2954 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_CLEAR) in lan743x_rx_open()
2956 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_AUTO_CLEAR) in lan743x_rx_open()
2958 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_STATUS_R2C) in lan743x_rx_open()
2960 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_R2C) in lan743x_rx_open()
2962 lan743x_csr_write(adapter, RX_CFG_C(rx->channel_number), data); in lan743x_rx_open()
2964 rx->last_tail = ((u32)(rx->ring_size - 1)); in lan743x_rx_open()
2965 lan743x_csr_write(adapter, RX_TAIL(rx->channel_number), in lan743x_rx_open()
2966 rx->last_tail); in lan743x_rx_open()
2967 rx->last_head = lan743x_csr_read(adapter, RX_HEAD(rx->channel_number)); in lan743x_rx_open()
2968 if (rx->last_head) { in lan743x_rx_open()
2969 ret = -EIO; in lan743x_rx_open()
2973 napi_enable(&rx->napi); in lan743x_rx_open()
2976 INT_BIT_DMA_RX_(rx->channel_number)); in lan743x_rx_open()
2978 DMAC_INT_BIT_RXFRM_(rx->channel_number)); in lan743x_rx_open()
2980 DMAC_INT_BIT_RXFRM_(rx->channel_number)); in lan743x_rx_open()
2982 DMAC_CMD_START_R_(rx->channel_number)); in lan743x_rx_open()
2986 FCT_RX_CTL_RESET_(rx->channel_number)); in lan743x_rx_open()
2988 FCT_RX_CTL_RESET_(rx->channel_number), in lan743x_rx_open()
2990 lan743x_csr_write(adapter, FCT_FLOW(rx->channel_number), in lan743x_rx_open()
2997 FCT_RX_CTL_EN_(rx->channel_number)); in lan743x_rx_open()
3001 netif_napi_del(&rx->napi); in lan743x_rx_open()
3002 lan743x_rx_ring_cleanup(rx); in lan743x_rx_open()
3013 for (index = 0; index < adapter->used_tx_channels; index++) in lan743x_netdev_close()
3014 lan743x_tx_close(&adapter->tx[index]); in lan743x_netdev_close()
3017 lan743x_rx_close(&adapter->rx[index]); in lan743x_netdev_close()
3055 ret = lan743x_rx_open(&adapter->rx[index]); in lan743x_netdev_open()
3060 for (index = 0; index < adapter->used_tx_channels; index++) { in lan743x_netdev_open()
3061 ret = lan743x_tx_open(&adapter->tx[index]); in lan743x_netdev_open()
3067 if (adapter->netdev->phydev) { in lan743x_netdev_open()
3070 phy_ethtool_get_wol(netdev->phydev, &wol); in lan743x_netdev_open()
3071 adapter->phy_wol_supported = wol.supported; in lan743x_netdev_open()
3072 adapter->phy_wolopts = wol.wolopts; in lan743x_netdev_open()
3079 for (index = 0; index < adapter->used_tx_channels; index++) { in lan743x_netdev_open()
3080 if (adapter->tx[index].ring_cpu_ptr) in lan743x_netdev_open()
3081 lan743x_tx_close(&adapter->tx[index]); in lan743x_netdev_open()
3086 if (adapter->rx[index].ring_cpu_ptr) in lan743x_netdev_open()
3087 lan743x_rx_close(&adapter->rx[index]); in lan743x_netdev_open()
3101 netif_warn(adapter, ifup, adapter->netdev, in lan743x_netdev_open()
3112 if (adapter->is_pci11x1x) in lan743x_netdev_xmit_frame()
3113 ch = skb->queue_mapping % PCI11X1X_USED_TX_CHANNELS; in lan743x_netdev_xmit_frame()
3115 return lan743x_tx_xmit_frame(&adapter->tx[ch], skb); in lan743x_netdev_xmit_frame()
3122 return -EINVAL; in lan743x_netdev_ioctl()
3125 return phy_mii_ioctl(netdev->phydev, ifr, cmd); in lan743x_netdev_ioctl()
3142 netdev->mtu = new_mtu; in lan743x_netdev_change_mtu()
3151 stats->rx_packets = lan743x_csr_read(adapter, STAT_RX_TOTAL_FRAMES); in lan743x_netdev_get_stats64()
3152 stats->tx_packets = lan743x_csr_read(adapter, STAT_TX_TOTAL_FRAMES); in lan743x_netdev_get_stats64()
3153 stats->rx_bytes = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3159 stats->tx_bytes = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3165 stats->rx_errors = lan743x_csr_read(adapter, STAT_RX_FCS_ERRORS) + in lan743x_netdev_get_stats64()
3173 stats->tx_errors = lan743x_csr_read(adapter, STAT_TX_FCS_ERRORS) + in lan743x_netdev_get_stats64()
3177 stats->rx_dropped = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3179 stats->tx_dropped = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3181 stats->multicast = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3185 stats->collisions = lan743x_csr_read(adapter, in lan743x_netdev_get_stats64()
3203 eth_hw_addr_set(netdev, sock_addr->sa_data); in lan743x_netdev_set_mac_address()
3204 lan743x_mac_set_address(adapter, sock_addr->sa_data); in lan743x_netdev_set_mac_address()
3227 mdiobus_unregister(adapter->mdiobus); in lan743x_mdiobus_cleanup()
3232 unregister_netdev(adapter->netdev); in lan743x_full_cleanup()
3241 u16 rev = adapter->csr.id_rev & ID_REV_CHIP_REV_MASK_; in pci11x1x_set_rfe_rd_fifo_threshold()
3257 struct lan743x_tx *tx; in lan743x_hardware_init() local
3261 adapter->is_pci11x1x = is_pci11x1x_chip(adapter); in lan743x_hardware_init()
3262 if (adapter->is_pci11x1x) { in lan743x_hardware_init()
3263 adapter->max_tx_channels = PCI11X1X_MAX_TX_CHANNELS; in lan743x_hardware_init()
3264 adapter->used_tx_channels = PCI11X1X_USED_TX_CHANNELS; in lan743x_hardware_init()
3265 adapter->max_vector_count = PCI11X1X_MAX_VECTOR_COUNT; in lan743x_hardware_init()
3267 spin_lock_init(&adapter->eth_syslock_spinlock); in lan743x_hardware_init()
3268 mutex_init(&adapter->sgmii_rw_lock); in lan743x_hardware_init()
3271 adapter->max_tx_channels = LAN743X_MAX_TX_CHANNELS; in lan743x_hardware_init()
3272 adapter->used_tx_channels = LAN743X_USED_TX_CHANNELS; in lan743x_hardware_init()
3273 adapter->max_vector_count = LAN743X_MAX_VECTOR_COUNT; in lan743x_hardware_init()
3276 adapter->intr.irq = adapter->pdev->irq; in lan743x_hardware_init()
3302 adapter->rx[index].adapter = adapter; in lan743x_hardware_init()
3303 adapter->rx[index].channel_number = index; in lan743x_hardware_init()
3306 for (index = 0; index < adapter->used_tx_channels; index++) { in lan743x_hardware_init()
3307 tx = &adapter->tx[index]; in lan743x_hardware_init()
3308 tx->adapter = adapter; in lan743x_hardware_init()
3309 tx->channel_number = index; in lan743x_hardware_init()
3310 spin_lock_init(&tx->ring_lock); in lan743x_hardware_init()
3321 adapter->mdiobus = devm_mdiobus_alloc(&adapter->pdev->dev); in lan743x_mdiobus_init()
3322 if (!(adapter->mdiobus)) { in lan743x_mdiobus_init()
3323 ret = -ENOMEM; in lan743x_mdiobus_init()
3327 adapter->mdiobus->priv = (void *)adapter; in lan743x_mdiobus_init()
3328 if (adapter->is_pci11x1x) { in lan743x_mdiobus_init()
3329 if (adapter->is_sgmii_en) { in lan743x_mdiobus_init()
3334 netif_dbg(adapter, drv, adapter->netdev, in lan743x_mdiobus_init()
3336 adapter->mdiobus->read = lan743x_mdiobus_read_c22; in lan743x_mdiobus_init()
3337 adapter->mdiobus->write = lan743x_mdiobus_write_c22; in lan743x_mdiobus_init()
3338 adapter->mdiobus->read_c45 = lan743x_mdiobus_read_c45; in lan743x_mdiobus_init()
3339 adapter->mdiobus->write_c45 = lan743x_mdiobus_write_c45; in lan743x_mdiobus_init()
3340 adapter->mdiobus->name = "lan743x-mdiobus-c45"; in lan743x_mdiobus_init()
3341 netif_dbg(adapter, drv, adapter->netdev, in lan743x_mdiobus_init()
3342 "lan743x-mdiobus-c45\n"); in lan743x_mdiobus_init()
3348 netif_dbg(adapter, drv, adapter->netdev, in lan743x_mdiobus_init()
3351 adapter->mdiobus->read = lan743x_mdiobus_read_c22; in lan743x_mdiobus_init()
3352 adapter->mdiobus->write = lan743x_mdiobus_write_c22; in lan743x_mdiobus_init()
3353 adapter->mdiobus->name = "lan743x-mdiobus"; in lan743x_mdiobus_init()
3354 netif_dbg(adapter, drv, adapter->netdev, in lan743x_mdiobus_init()
3355 "lan743x-mdiobus\n"); in lan743x_mdiobus_init()
3358 adapter->mdiobus->read = lan743x_mdiobus_read_c22; in lan743x_mdiobus_init()
3359 adapter->mdiobus->write = lan743x_mdiobus_write_c22; in lan743x_mdiobus_init()
3360 adapter->mdiobus->name = "lan743x-mdiobus"; in lan743x_mdiobus_init()
3361 netif_dbg(adapter, drv, adapter->netdev, "lan743x-mdiobus\n"); in lan743x_mdiobus_init()
3364 snprintf(adapter->mdiobus->id, MII_BUS_ID_SIZE, in lan743x_mdiobus_init()
3365 "pci-%s", pci_name(adapter->pdev)); in lan743x_mdiobus_init()
3367 if ((adapter->csr.id_rev & ID_REV_ID_MASK_) == ID_REV_ID_LAN7430_) in lan743x_mdiobus_init()
3369 adapter->mdiobus->phy_mask = ~(u32)BIT(1); in lan743x_mdiobus_init()
3372 ret = mdiobus_register(adapter->mdiobus); in lan743x_mdiobus_init()
3381 /* lan743x_pcidev_probe - Device Initialization Routine
3396 int ret = -ENODEV; in lan743x_pcidev_probe()
3398 if (id->device == PCI_DEVICE_ID_SMSC_A011 || in lan743x_pcidev_probe()
3399 id->device == PCI_DEVICE_ID_SMSC_A041) { in lan743x_pcidev_probe()
3400 netdev = devm_alloc_etherdev_mqs(&pdev->dev, in lan743x_pcidev_probe()
3405 netdev = devm_alloc_etherdev_mqs(&pdev->dev, in lan743x_pcidev_probe()
3414 SET_NETDEV_DEV(netdev, &pdev->dev); in lan743x_pcidev_probe()
3417 adapter->netdev = netdev; in lan743x_pcidev_probe()
3418 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE | in lan743x_pcidev_probe()
3421 netdev->max_mtu = LAN743X_MAX_FRAME_SIZE; in lan743x_pcidev_probe()
3423 of_get_mac_address(pdev->dev.of_node, adapter->mac_address); in lan743x_pcidev_probe()
3441 adapter->netdev->netdev_ops = &lan743x_netdev_ops; in lan743x_pcidev_probe()
3442 adapter->netdev->ethtool_ops = &lan743x_ethtool_ops; in lan743x_pcidev_probe()
3443 adapter->netdev->features = NETIF_F_SG | NETIF_F_TSO | in lan743x_pcidev_probe()
3445 adapter->netdev->hw_features = adapter->netdev->features; in lan743x_pcidev_probe()
3450 ret = register_netdev(adapter->netdev); in lan743x_pcidev_probe()
3470 * lan743x_pcidev_remove - Device Removal Routine
3475 * Hot-Plug event, or because the driver is going to be removed from
3495 * For instance, it is true when system goes to sleep by pm-suspend in lan743x_pcidev_shutdown()
3545 if (adapter->phy_wolopts) in lan743x_pm_set_wol()
3548 if (adapter->wolopts & WAKE_MAGIC) { in lan743x_pm_set_wol()
3553 if (adapter->wolopts & WAKE_UCAST) { in lan743x_pm_set_wol()
3559 if (adapter->wolopts & WAKE_BCAST) { in lan743x_pm_set_wol()
3565 if (adapter->wolopts & WAKE_MCAST) { in lan743x_pm_set_wol()
3595 if (adapter->wolopts & WAKE_ARP) { in lan743x_pm_set_wol()
3616 if (adapter->wolopts & WAKE_MAGICSECURE) { in lan743x_pm_set_wol()
3617 sopass = *(u32 *)adapter->sopass; in lan743x_pm_set_wol()
3619 sopass = *(u16 *)&adapter->sopass[4]; in lan743x_pm_set_wol()
3643 if (adapter->wolopts || adapter->phy_wolopts) in lan743x_pm_suspend()
3646 if (adapter->is_pci11x1x) { in lan743x_pm_suspend()
3649 adapter->hw_cfg = data; in lan743x_pm_suspend()
3675 if (adapter->is_pci11x1x) in lan743x_pm_resume()
3676 lan743x_csr_write(adapter, HW_CFG, adapter->hw_cfg); in lan743x_pm_resume()
3680 netif_err(adapter, probe, adapter->netdev, in lan743x_pm_resume()
3687 netif_dbg(adapter, drv, adapter->netdev, in lan743x_pm_resume()
3711 * For instance, it is true when system wakesup after pm-suspend in lan743x_pm_resume()