Lines Matching defs:efx
42 #include "efx.h"
221 * @efx: The NIC context
288 struct efx_nic *efx;
345 void (*xmit_skb)(struct efx_nic *efx, struct sk_buff *skb);
355 static int efx_ptp_insert_unicast_filter(struct efx_nic *efx,
358 bool efx_ptp_use_mac_tx_timestamps(struct efx_nic *efx)
360 return efx_has_cap(efx, TX_MAC_TIMESTAMPING);
368 return efx_ptp_use_mac_tx_timestamps(channel->efx);
396 size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings)
398 if (!efx->ptp_data)
405 size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats)
412 if (!efx->ptp_data)
419 stats[i] = *(unsigned int *)((char *)efx->ptp_data +
429 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
520 struct efx_channel *efx_ptp_channel(struct efx_nic *efx)
522 return efx->ptp_data ? efx->ptp_data->channel : NULL;
525 void efx_ptp_update_channel(struct efx_nic *efx, struct efx_channel *channel)
527 if (efx->ptp_data)
528 efx->ptp_data->channel = channel;
531 static u32 last_sync_timestamp_major(struct efx_nic *efx)
533 struct efx_channel *channel = efx_ptp_channel(efx);
545 efx_ptp_mac_nic_to_ktime_correction(struct efx_nic *efx,
575 sync_timestamp = last_sync_timestamp_major(efx);
598 struct efx_nic *efx = tx_queue->efx;
599 struct efx_ptp_data *ptp = efx->ptp_data;
602 if (efx_ptp_use_mac_tx_timestamps(efx))
603 kt = efx_ptp_mac_nic_to_ktime_correction(efx, ptp,
616 static int efx_ptp_get_attributes(struct efx_nic *efx)
620 struct efx_ptp_data *ptp = efx->ptp_data;
631 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
638 pci_info(efx->pci_dev, "no PTP support\n");
641 efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
709 static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
723 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
726 efx->ptp_data->ts_corrections.ptp_tx = MCDI_DWORD(outbuf,
728 efx->ptp_data->ts_corrections.ptp_rx = MCDI_DWORD(outbuf,
730 efx->ptp_data->ts_corrections.pps_out = MCDI_DWORD(outbuf,
732 efx->ptp_data->ts_corrections.pps_in = MCDI_DWORD(outbuf,
736 efx->ptp_data->ts_corrections.general_tx = MCDI_DWORD(
739 efx->ptp_data->ts_corrections.general_rx = MCDI_DWORD(
743 efx->ptp_data->ts_corrections.general_tx =
744 efx->ptp_data->ts_corrections.ptp_tx;
745 efx->ptp_data->ts_corrections.general_rx =
746 efx->ptp_data->ts_corrections.ptp_rx;
749 efx->ptp_data->ts_corrections.ptp_tx = 0;
750 efx->ptp_data->ts_corrections.ptp_rx = 0;
751 efx->ptp_data->ts_corrections.pps_out = 0;
752 efx->ptp_data->ts_corrections.pps_in = 0;
753 efx->ptp_data->ts_corrections.general_tx = 0;
754 efx->ptp_data->ts_corrections.general_rx = 0;
756 efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf), outbuf,
765 static int efx_ptp_enable(struct efx_nic *efx)
774 efx->ptp_data->channel ?
775 efx->ptp_data->channel->channel : 0);
776 MCDI_SET_DWORD(inbuf, PTP_IN_ENABLE_MODE, efx->ptp_data->mode);
778 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
782 efx_mcdi_display_error(efx, MC_CMD_PTP,
793 static int efx_ptp_disable(struct efx_nic *efx)
801 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
808 pci_info(efx->pci_dev, "no PTP support\n");
810 efx_mcdi_display_error(efx, MC_CMD_PTP,
827 static void efx_ptp_handle_no_channel(struct efx_nic *efx)
829 netif_err(efx, drv, efx->net_dev,
837 static void efx_ptp_send_times(struct efx_nic *efx,
842 struct efx_ptp_data *ptp = efx->ptp_data;
867 efx->type->ptp_write_host_time(efx, host_time);
903 efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
913 struct efx_ptp_data *ptp = efx->ptp_data;
964 netif_warn(efx, drv, efx->net_dev,
979 netif_warn(efx, hw, efx->net_dev,
1006 static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
1008 struct efx_ptp_data *ptp = efx->ptp_data;
1026 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
1043 efx_ptp_send_times(efx, &last_time);
1046 rc = efx_mcdi_rpc_finish(efx, MC_CMD_PTP,
1051 rc = efx_ptp_process_times(efx, synch_buf, response_length,
1069 static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb)
1071 struct efx_ptp_data *ptp_data = efx->ptp_data;
1107 efx_ptp_insert_unicast_filter(efx, skb);
1116 static void efx_ptp_xmit_skb_mc(struct efx_nic *efx, struct sk_buff *skb)
1119 struct efx_ptp_data *ptp_data = efx->ptp_data;
1142 rc = efx_mcdi_rpc(efx, MC_CMD_PTP,
1159 efx_ptp_insert_unicast_filter(efx, skb);
1171 static void efx_ptp_process_events(struct efx_nic *efx, struct sk_buff_head *q)
1173 struct efx_ptp_data *ptp = efx->ptp_data;
1195 static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb)
1217 static void efx_ptp_remove_one_filter(struct efx_nic *efx,
1220 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1226 static void efx_ptp_remove_filters(struct efx_nic *efx,
1232 efx_ptp_remove_one_filter(efx, rxfilter);
1235 static void efx_ptp_init_filter(struct efx_nic *efx,
1238 struct efx_channel *channel = efx->ptp_data->channel;
1245 static int efx_ptp_insert_filter(struct efx_nic *efx,
1250 struct efx_ptp_data *ptp = efx->ptp_data;
1264 rc = efx_filter_insert_filter(efx, spec, true);
1285 static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx,
1292 efx_ptp_init_filter(efx, &spec);
1294 return efx_ptp_insert_filter(efx, filter_list, &spec, expiry);
1297 static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx,
1304 efx_ptp_init_filter(efx, &spec);
1306 return efx_ptp_insert_filter(efx, filter_list, &spec, expiry);
1309 static int efx_ptp_insert_eth_multicast_filter(struct efx_nic *efx)
1311 struct efx_ptp_data *ptp = efx->ptp_data;
1315 efx_ptp_init_filter(efx, &spec);
1319 return efx_ptp_insert_filter(efx, &ptp->rxfilters_mcast, &spec, 0);
1322 static int efx_ptp_insert_multicast_filters(struct efx_nic *efx)
1324 struct efx_ptp_data *ptp = efx->ptp_data;
1333 rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast,
1339 rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast,
1348 if (efx_ptp_use_mac_tx_timestamps(efx)) {
1351 rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast,
1356 rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast,
1361 rc = efx_ptp_insert_eth_multicast_filter(efx);
1371 efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast);
1391 static int efx_ptp_insert_unicast_filter(struct efx_nic *efx,
1394 struct efx_ptp_data *ptp = efx->ptp_data;
1406 rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast,
1411 rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast,
1413 } else if (efx_ptp_use_mac_tx_timestamps(efx)) {
1417 rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast,
1422 rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast,
1432 static int efx_ptp_start(struct efx_nic *efx)
1434 struct efx_ptp_data *ptp = efx->ptp_data;
1439 rc = efx_ptp_insert_multicast_filters(efx);
1443 rc = efx_ptp_enable(efx);
1453 efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast);
1457 static int efx_ptp_stop(struct efx_nic *efx)
1459 struct efx_ptp_data *ptp = efx->ptp_data;
1465 rc = efx_ptp_disable(efx);
1467 efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast);
1468 efx_ptp_remove_filters(efx, &ptp->rxfilters_ucast);
1471 efx_ptp_deliver_rx_queue(&efx->ptp_data->rxq);
1472 skb_queue_purge(&efx->ptp_data->txq);
1477 static int efx_ptp_restart(struct efx_nic *efx)
1479 if (efx->ptp_data && efx->ptp_data->enabled)
1480 return efx_ptp_start(efx);
1488 struct efx_nic *efx = ptp->efx;
1491 if (efx_ptp_synchronize(efx, PTP_SYNC_ATTEMPTS))
1503 struct efx_nic *efx = ptp_data->efx;
1508 efx_ptp_stop(efx);
1509 efx_ptp_start(efx);
1514 efx_ptp_process_events(efx, &tempq);
1517 ptp_data->xmit_skb(efx, skb);
1520 efx_ptp_process_rx(efx, skb);
1531 efx_ptp_remove_one_filter(ptp->efx, rxfilter);
1557 int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)
1562 if (efx->ptp_data) {
1563 efx->ptp_data->channel = channel;
1568 efx->ptp_data = ptp;
1569 if (!efx->ptp_data)
1572 ptp->efx = efx;
1575 rc = efx_nic_alloc_buffer(efx, &ptp->start, sizeof(int), GFP_KERNEL);
1587 if (efx_ptp_use_mac_tx_timestamps(efx)) {
1604 rc = efx_ptp_get_attributes(efx);
1609 rc = efx_ptp_get_timestamp_corrections(efx);
1613 if (efx->mcdi->fn_flags &
1617 &efx->pci_dev->dev);
1634 ptp_clock_unregister(efx->ptp_data->phc_clock);
1637 destroy_workqueue(efx->ptp_data->workwq);
1640 efx_nic_free_buffer(efx, &ptp->start);
1643 kfree(efx->ptp_data);
1644 efx->ptp_data = NULL;
1656 struct efx_nic *efx = channel->efx;
1662 rc = efx_ptp_probe(efx, channel);
1669 netif_warn(efx, drv, efx->net_dev,
1674 void efx_ptp_remove(struct efx_nic *efx)
1676 if (!efx->ptp_data)
1679 (void)efx_ptp_disable(efx);
1681 cancel_work_sync(&efx->ptp_data->work);
1682 cancel_delayed_work_sync(&efx->ptp_data->cleanup_work);
1683 if (efx->ptp_data->pps_workwq)
1684 cancel_work_sync(&efx->ptp_data->pps_work);
1686 skb_queue_purge(&efx->ptp_data->rxq);
1687 skb_queue_purge(&efx->ptp_data->txq);
1689 if (efx->ptp_data->phc_clock) {
1690 destroy_workqueue(efx->ptp_data->pps_workwq);
1691 ptp_clock_unregister(efx->ptp_data->phc_clock);
1694 destroy_workqueue(efx->ptp_data->workwq);
1696 efx_nic_free_buffer(efx, &efx->ptp_data->start);
1697 kfree(efx->ptp_data);
1698 efx->ptp_data = NULL;
1703 efx_ptp_remove(channel->efx);
1709 snprintf(buf, len, "%s-ptp", channel->efx->name);
1715 bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1717 return efx->ptp_data &&
1718 efx->ptp_data->enabled &&
1736 struct efx_nic *efx = channel->efx;
1737 struct efx_ptp_data *ptp = efx->ptp_data;
1788 int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1790 struct efx_ptp_data *ptp = efx->ptp_data;
1802 int efx_ptp_get_mode(struct efx_nic *efx)
1804 return efx->ptp_data->mode;
1807 int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
1810 if ((enable_wanted != efx->ptp_data->enabled) ||
1811 (enable_wanted && (efx->ptp_data->mode != new_mode))) {
1816 if (efx->ptp_data->enabled &&
1817 (efx->ptp_data->mode != new_mode)) {
1818 efx->ptp_data->enabled = false;
1819 rc = efx_ptp_stop(efx);
1828 efx->ptp_data->mode = new_mode;
1829 if (netif_running(efx->net_dev))
1830 rc = efx_ptp_start(efx);
1832 rc = efx_ptp_synchronize(efx,
1835 efx_ptp_stop(efx);
1838 rc = efx_ptp_stop(efx);
1844 efx->ptp_data->enabled = enable_wanted;
1850 static int efx_ptp_ts_init(struct efx_nic *efx, struct hwtstamp_config *init)
1858 rc = efx->type->ptp_set_ts_config(efx, init);
1862 efx->ptp_data->config = *init;
1866 void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info)
1868 struct efx_ptp_data *ptp = efx->ptp_data;
1869 struct efx_nic *primary = efx->primary;
1882 if (efx_ptp_use_mac_tx_timestamps(efx)) {
1883 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1894 ts_info->rx_filters = ptp->efx->type->hwtstamp_filters;
1897 int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1903 if (!efx->ptp_data)
1909 rc = efx_ptp_ts_init(efx, &config);
1917 int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1919 if (!efx->ptp_data)
1922 return copy_to_user(ifr->ifr_data, &efx->ptp_data->config,
1923 sizeof(efx->ptp_data->config)) ? -EFAULT : 0;
1926 static void ptp_event_failure(struct efx_nic *efx, int expected_frag_len)
1928 struct efx_ptp_data *ptp = efx->ptp_data;
1930 netif_err(efx, hw, efx->net_dev,
1937 static void ptp_event_fault(struct efx_nic *efx, struct efx_ptp_data *ptp)
1941 ptp_event_failure(efx, 1);
1945 netif_err(efx, hw, efx->net_dev, "PTP error %d\n", code);
1948 static void ptp_event_pps(struct efx_nic *efx, struct efx_ptp_data *ptp)
1954 void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev)
1956 struct efx_ptp_data *ptp = efx->ptp_data;
1960 if (!efx->ptp_warned) {
1961 netif_warn(efx, drv, efx->net_dev,
1963 efx->ptp_warned = true;
1974 netif_err(efx, hw, efx->net_dev,
1984 ptp_event_fault(efx, ptp);
1987 ptp_event_pps(efx, ptp);
1990 netif_err(efx, hw, efx->net_dev,
1996 netif_err(efx, hw, efx->net_dev,
2004 struct efx_nic *efx = channel->efx;
2005 struct efx_ptp_data *ptp = efx->ptp_data;
2025 static inline u32 efx_rx_buf_timestamp_minor(struct efx_nic *efx, const u8 *eh)
2028 return __le32_to_cpup((const __le32 *)(eh + efx->rx_packet_ts_offset));
2030 const u8 *data = eh + efx->rx_packet_ts_offset;
2041 struct efx_nic *efx = channel->efx;
2042 struct efx_ptp_data *ptp = efx->ptp_data;
2050 pkt_timestamp_minor = efx_rx_buf_timestamp_minor(efx, skb_mac_header(skb));
2080 netif_vdbg(efx, drv, efx->net_dev,
2101 struct efx_nic *efx = ptp_data->efx;
2121 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inadj, sizeof(inadj),
2136 struct efx_nic *efx = ptp_data->efx;
2139 efx->ptp_data->ns_to_nic_time(delta, &nic_major, &nic_minor);
2146 return efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2155 struct efx_nic *efx = ptp_data->efx;
2164 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2225 void efx_ptp_defer_probe_with_channel(struct efx_nic *efx)
2230 if (efx_ptp_disable(efx) == 0)
2231 efx->extra_channel_type[EFX_EXTRA_CHANNEL_PTP] =
2235 void efx_ptp_start_datapath(struct efx_nic *efx)
2237 if (efx_ptp_restart(efx))
2238 netif_err(efx, drv, efx->net_dev, "Failed to restart PTP.\n");
2240 if (efx->type->ptp_set_ts_sync_events)
2241 efx->type->ptp_set_ts_sync_events(efx, true, true);
2244 void efx_ptp_stop_datapath(struct efx_nic *efx)
2247 if (efx->type->ptp_set_ts_sync_events)
2248 efx->type->ptp_set_ts_sync_events(efx, false, true);
2249 efx_ptp_stop(efx);