Lines Matching defs:efx

41 #include "efx.h"
213 * @efx: The NIC context
286 struct efx_nic *efx;
348 void (*xmit_skb)(struct efx_nic *efx, struct sk_buff *skb);
359 bool efx_ptp_use_mac_tx_timestamps(struct efx_nic *efx)
361 return efx_has_cap(efx, TX_MAC_TIMESTAMPING);
369 return efx_ptp_use_mac_tx_timestamps(channel->efx);
397 size_t efx_ptp_describe_stats(struct efx_nic *efx, u8 *strings)
399 if (!efx->ptp_data)
406 size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats)
413 if (!efx->ptp_data)
420 stats[i] = *(unsigned int *)((char *)efx->ptp_data +
430 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
540 struct efx_channel *efx_ptp_channel(struct efx_nic *efx)
542 return efx->ptp_data ? efx->ptp_data->channel : NULL;
545 void efx_ptp_update_channel(struct efx_nic *efx, struct efx_channel *channel)
547 if (efx->ptp_data)
548 efx->ptp_data->channel = channel;
551 static u32 last_sync_timestamp_major(struct efx_nic *efx)
553 struct efx_channel *channel = efx_ptp_channel(efx);
565 efx_ptp_mac_nic_to_ktime_correction(struct efx_nic *efx,
595 sync_timestamp = last_sync_timestamp_major(efx);
618 struct efx_nic *efx = tx_queue->efx;
619 struct efx_ptp_data *ptp = efx->ptp_data;
622 if (efx_ptp_use_mac_tx_timestamps(efx))
623 kt = efx_ptp_mac_nic_to_ktime_correction(efx, ptp,
636 static int efx_ptp_get_attributes(struct efx_nic *efx)
640 struct efx_ptp_data *ptp = efx->ptp_data;
651 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
658 pci_info(efx->pci_dev, "no PTP support\n");
661 efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
735 static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
749 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
752 efx->ptp_data->ts_corrections.ptp_tx = MCDI_DWORD(outbuf,
754 efx->ptp_data->ts_corrections.ptp_rx = MCDI_DWORD(outbuf,
756 efx->ptp_data->ts_corrections.pps_out = MCDI_DWORD(outbuf,
758 efx->ptp_data->ts_corrections.pps_in = MCDI_DWORD(outbuf,
762 efx->ptp_data->ts_corrections.general_tx = MCDI_DWORD(
765 efx->ptp_data->ts_corrections.general_rx = MCDI_DWORD(
769 efx->ptp_data->ts_corrections.general_tx =
770 efx->ptp_data->ts_corrections.ptp_tx;
771 efx->ptp_data->ts_corrections.general_rx =
772 efx->ptp_data->ts_corrections.ptp_rx;
775 efx->ptp_data->ts_corrections.ptp_tx = 0;
776 efx->ptp_data->ts_corrections.ptp_rx = 0;
777 efx->ptp_data->ts_corrections.pps_out = 0;
778 efx->ptp_data->ts_corrections.pps_in = 0;
779 efx->ptp_data->ts_corrections.general_tx = 0;
780 efx->ptp_data->ts_corrections.general_rx = 0;
782 efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf), outbuf,
791 static int efx_ptp_enable(struct efx_nic *efx)
800 efx->ptp_data->channel ?
801 efx->ptp_data->channel->channel : 0);
802 MCDI_SET_DWORD(inbuf, PTP_IN_ENABLE_MODE, efx->ptp_data->mode);
804 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
808 efx_mcdi_display_error(efx, MC_CMD_PTP,
819 static int efx_ptp_disable(struct efx_nic *efx)
827 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
834 pci_info(efx->pci_dev, "no PTP support\n");
836 efx_mcdi_display_error(efx, MC_CMD_PTP,
853 static void efx_ptp_handle_no_channel(struct efx_nic *efx)
855 netif_err(efx, drv, efx->net_dev,
863 static void efx_ptp_send_times(struct efx_nic *efx,
868 struct efx_ptp_data *ptp = efx->ptp_data;
893 efx->type->ptp_write_host_time(efx, host_time);
929 efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
939 struct efx_ptp_data *ptp = efx->ptp_data;
990 netif_warn(efx, drv, efx->net_dev,
1005 netif_warn(efx, hw, efx->net_dev,
1032 static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
1034 struct efx_ptp_data *ptp = efx->ptp_data;
1052 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
1069 efx_ptp_send_times(efx, &last_time);
1072 rc = efx_mcdi_rpc_finish(efx, MC_CMD_PTP,
1077 rc = efx_ptp_process_times(efx, synch_buf, response_length,
1095 static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb)
1097 struct efx_ptp_data *ptp_data = efx->ptp_data;
1133 static void efx_ptp_xmit_skb_mc(struct efx_nic *efx, struct sk_buff *skb)
1135 struct efx_ptp_data *ptp_data = efx->ptp_data;
1159 rc = efx_mcdi_rpc(efx, MC_CMD_PTP,
1181 static void efx_ptp_drop_time_expired_events(struct efx_nic *efx)
1183 struct efx_ptp_data *ptp = efx->ptp_data;
1199 netif_warn(efx, hw, efx->net_dev,
1206 static enum ptp_packet_state efx_ptp_match_rx(struct efx_nic *efx,
1209 struct efx_ptp_data *ptp = efx->ptp_data;
1255 static void efx_ptp_process_events(struct efx_nic *efx, struct sk_buff_head *q)
1257 struct efx_ptp_data *ptp = efx->ptp_data;
1266 } else if (efx_ptp_match_rx(efx, skb) ==
1282 static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb)
1289 static void efx_ptp_remove_multicast_filters(struct efx_nic *efx)
1291 struct efx_ptp_data *ptp = efx->ptp_data;
1294 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1296 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1302 static int efx_ptp_insert_multicast_filters(struct efx_nic *efx)
1304 struct efx_ptp_data *ptp = efx->ptp_data;
1323 rc = efx_filter_insert_filter(efx, &rxfilter, true);
1337 rc = efx_filter_insert_filter(efx, &rxfilter, true);
1346 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1351 static int efx_ptp_start(struct efx_nic *efx)
1353 struct efx_ptp_data *ptp = efx->ptp_data;
1358 rc = efx_ptp_insert_multicast_filters(efx);
1362 rc = efx_ptp_enable(efx);
1372 efx_ptp_remove_multicast_filters(efx);
1376 static int efx_ptp_stop(struct efx_nic *efx)
1378 struct efx_ptp_data *ptp = efx->ptp_data;
1386 rc = efx_ptp_disable(efx);
1388 efx_ptp_remove_multicast_filters(efx);
1391 efx_ptp_deliver_rx_queue(&efx->ptp_data->rxq);
1392 skb_queue_purge(&efx->ptp_data->txq);
1395 spin_lock_bh(&efx->ptp_data->evt_lock);
1396 list_for_each_safe(cursor, next, &efx->ptp_data->evt_list) {
1397 list_move(cursor, &efx->ptp_data->evt_free_list);
1399 spin_unlock_bh(&efx->ptp_data->evt_lock);
1404 static int efx_ptp_restart(struct efx_nic *efx)
1406 if (efx->ptp_data && efx->ptp_data->enabled)
1407 return efx_ptp_start(efx);
1415 struct efx_nic *efx = ptp->efx;
1418 if (efx_ptp_synchronize(efx, PTP_SYNC_ATTEMPTS))
1430 struct efx_nic *efx = ptp_data->efx;
1435 efx_ptp_stop(efx);
1436 efx_ptp_start(efx);
1440 efx_ptp_drop_time_expired_events(efx);
1443 efx_ptp_process_events(efx, &tempq);
1446 ptp_data->xmit_skb(efx, skb);
1449 efx_ptp_process_rx(efx, skb);
1469 int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)
1475 if (efx->ptp_data) {
1476 efx->ptp_data->channel = channel;
1481 efx->ptp_data = ptp;
1482 if (!efx->ptp_data)
1485 ptp->efx = efx;
1487 ptp->rx_ts_inline = efx_nic_rev(efx) >= EFX_REV_HUNT_A0;
1489 rc = efx_nic_alloc_buffer(efx, &ptp->start, sizeof(int), GFP_KERNEL);
1501 if (efx_ptp_use_mac_tx_timestamps(efx)) {
1520 rc = efx_ptp_get_attributes(efx);
1525 rc = efx_ptp_get_timestamp_corrections(efx);
1529 if (efx->mcdi->fn_flags &
1533 &efx->pci_dev->dev);
1550 ptp_clock_unregister(efx->ptp_data->phc_clock);
1553 destroy_workqueue(efx->ptp_data->workwq);
1556 efx_nic_free_buffer(efx, &ptp->start);
1559 kfree(efx->ptp_data);
1560 efx->ptp_data = NULL;
1572 struct efx_nic *efx = channel->efx;
1578 rc = efx_ptp_probe(efx, channel);
1585 netif_warn(efx, drv, efx->net_dev,
1590 void efx_ptp_remove(struct efx_nic *efx)
1592 if (!efx->ptp_data)
1595 (void)efx_ptp_disable(efx);
1597 cancel_work_sync(&efx->ptp_data->work);
1598 if (efx->ptp_data->pps_workwq)
1599 cancel_work_sync(&efx->ptp_data->pps_work);
1601 skb_queue_purge(&efx->ptp_data->rxq);
1602 skb_queue_purge(&efx->ptp_data->txq);
1604 if (efx->ptp_data->phc_clock) {
1605 destroy_workqueue(efx->ptp_data->pps_workwq);
1606 ptp_clock_unregister(efx->ptp_data->phc_clock);
1609 destroy_workqueue(efx->ptp_data->workwq);
1611 efx_nic_free_buffer(efx, &efx->ptp_data->start);
1612 kfree(efx->ptp_data);
1613 efx->ptp_data = NULL;
1618 efx_ptp_remove(channel->efx);
1624 snprintf(buf, len, "%s-ptp", channel->efx->name);
1630 bool efx_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1632 return efx->ptp_data &&
1633 efx->ptp_data->enabled &&
1651 struct efx_nic *efx = channel->efx;
1652 struct efx_ptp_data *ptp = efx->ptp_data;
1736 int efx_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1738 struct efx_ptp_data *ptp = efx->ptp_data;
1750 int efx_ptp_get_mode(struct efx_nic *efx)
1752 return efx->ptp_data->mode;
1755 int efx_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
1758 if ((enable_wanted != efx->ptp_data->enabled) ||
1759 (enable_wanted && (efx->ptp_data->mode != new_mode))) {
1764 if (efx->ptp_data->enabled &&
1765 (efx->ptp_data->mode != new_mode)) {
1766 efx->ptp_data->enabled = false;
1767 rc = efx_ptp_stop(efx);
1776 efx->ptp_data->mode = new_mode;
1777 if (netif_running(efx->net_dev))
1778 rc = efx_ptp_start(efx);
1780 rc = efx_ptp_synchronize(efx,
1783 efx_ptp_stop(efx);
1786 rc = efx_ptp_stop(efx);
1792 efx->ptp_data->enabled = enable_wanted;
1798 static int efx_ptp_ts_init(struct efx_nic *efx, struct hwtstamp_config *init)
1809 rc = efx->type->ptp_set_ts_config(efx, init);
1813 efx->ptp_data->config = *init;
1817 void efx_ptp_get_ts_info(struct efx_nic *efx, struct ethtool_ts_info *ts_info)
1819 struct efx_ptp_data *ptp = efx->ptp_data;
1820 struct efx_nic *primary = efx->primary;
1833 if (efx_ptp_use_mac_tx_timestamps(efx)) {
1834 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1845 ts_info->rx_filters = ptp->efx->type->hwtstamp_filters;
1848 int efx_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1854 if (!efx->ptp_data)
1860 rc = efx_ptp_ts_init(efx, &config);
1868 int efx_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1870 if (!efx->ptp_data)
1873 return copy_to_user(ifr->ifr_data, &efx->ptp_data->config,
1874 sizeof(efx->ptp_data->config)) ? -EFAULT : 0;
1877 static void ptp_event_failure(struct efx_nic *efx, int expected_frag_len)
1879 struct efx_ptp_data *ptp = efx->ptp_data;
1881 netif_err(efx, hw, efx->net_dev,
1892 static void ptp_event_rx(struct efx_nic *efx, struct efx_ptp_data *ptp)
1900 ptp_event_failure(efx, 3);
1917 evt->hwtimestamp = efx->ptp_data->nic_to_kernel_time(
1927 netif_err(efx, rx_err, efx->net_dev, "PTP event queue overflow\n");
1932 static void ptp_event_fault(struct efx_nic *efx, struct efx_ptp_data *ptp)
1936 ptp_event_failure(efx, 1);
1940 netif_err(efx, hw, efx->net_dev, "PTP error %d\n", code);
1943 static void ptp_event_pps(struct efx_nic *efx, struct efx_ptp_data *ptp)
1949 void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev)
1951 struct efx_ptp_data *ptp = efx->ptp_data;
1955 if (!efx->ptp_warned) {
1956 netif_warn(efx, drv, efx->net_dev,
1958 efx->ptp_warned = true;
1969 netif_err(efx, hw, efx->net_dev,
1979 ptp_event_rx(efx, ptp);
1982 ptp_event_fault(efx, ptp);
1985 ptp_event_pps(efx, ptp);
1988 netif_err(efx, hw, efx->net_dev,
1994 netif_err(efx, hw, efx->net_dev,
2002 struct efx_nic *efx = channel->efx;
2003 struct efx_ptp_data *ptp = efx->ptp_data;
2023 static inline u32 efx_rx_buf_timestamp_minor(struct efx_nic *efx, const u8 *eh)
2026 return __le32_to_cpup((const __le32 *)(eh + efx->rx_packet_ts_offset));
2028 const u8 *data = eh + efx->rx_packet_ts_offset;
2039 struct efx_nic *efx = channel->efx;
2040 struct efx_ptp_data *ptp = efx->ptp_data;
2048 pkt_timestamp_minor = efx_rx_buf_timestamp_minor(efx, skb_mac_header(skb));
2078 netif_vdbg(efx, drv, efx->net_dev,
2098 struct efx_nic *efx = ptp_data->efx;
2118 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inadj, sizeof(inadj),
2133 struct efx_nic *efx = ptp_data->efx;
2136 efx->ptp_data->ns_to_nic_time(delta, &nic_major, &nic_minor);
2143 return efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2152 struct efx_nic *efx = ptp_data->efx;
2161 rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2222 void efx_ptp_defer_probe_with_channel(struct efx_nic *efx)
2227 if (efx_ptp_disable(efx) == 0)
2228 efx->extra_channel_type[EFX_EXTRA_CHANNEL_PTP] =
2232 void efx_ptp_start_datapath(struct efx_nic *efx)
2234 if (efx_ptp_restart(efx))
2235 netif_err(efx, drv, efx->net_dev, "Failed to restart PTP.\n");
2237 if (efx->type->ptp_set_ts_sync_events)
2238 efx->type->ptp_set_ts_sync_events(efx, true, true);
2241 void efx_ptp_stop_datapath(struct efx_nic *efx)
2244 if (efx->type->ptp_set_ts_sync_events)
2245 efx->type->ptp_set_ts_sync_events(efx, false, true);
2246 efx_ptp_stop(efx);