These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / net / ethernet / sfc / ptp.c
index a2e9aee..c771e0a 100644 (file)
@@ -306,7 +306,7 @@ struct efx_ptp_data {
        struct work_struct pps_work;
        struct workqueue_struct *pps_workwq;
        bool nic_ts_enabled;
-       MCDI_DECLARE_BUF(txbuf, MC_CMD_PTP_IN_TRANSMIT_LENMAX);
+       _MCDI_DECLARE_BUF(txbuf, MC_CMD_PTP_IN_TRANSMIT_LENMAX);
 
        unsigned int good_syncs;
        unsigned int fast_syncs;
@@ -389,11 +389,8 @@ size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats)
        MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
        rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
                          outbuf, sizeof(outbuf), NULL);
-       if (rc) {
-               netif_err(efx, hw, efx->net_dev,
-                         "MC_CMD_PTP_OP_STATUS failed (%d)\n", rc);
+       if (rc)
                memset(outbuf, 0, sizeof(outbuf));
-       }
        efx_nic_update_stats(efx_ptp_stat_desc, PTP_STAT_COUNT,
                             efx_ptp_stat_mask,
                             stats, _MCDI_PTR(outbuf, 0), false);
@@ -404,8 +401,8 @@ size_t efx_ptp_update_stats(struct efx_nic *efx, u64 *stats)
 /* For Siena platforms NIC time is s and ns */
 static void efx_ptp_ns_to_s_ns(s64 ns, u32 *nic_major, u32 *nic_minor)
 {
-       struct timespec ts = ns_to_timespec(ns);
-       *nic_major = ts.tv_sec;
+       struct timespec64 ts = ns_to_timespec64(ns);
+       *nic_major = (u32)ts.tv_sec;
        *nic_minor = ts.tv_nsec;
 }
 
@@ -434,8 +431,8 @@ static ktime_t efx_ptp_s_ns_to_ktime_correction(u32 nic_major, u32 nic_minor,
  */
 static void efx_ptp_ns_to_s27(s64 ns, u32 *nic_major, u32 *nic_minor)
 {
-       struct timespec ts = ns_to_timespec(ns);
-       u32 maj = ts.tv_sec;
+       struct timespec64 ts = ns_to_timespec64(ns);
+       u32 maj = (u32)ts.tv_sec;
        u32 min = (u32)(((u64)ts.tv_nsec * NS_TO_S27_MULT +
                         (1ULL << (NS_TO_S27_SHIFT - 1))) >> NS_TO_S27_SHIFT);
 
@@ -490,14 +487,20 @@ static int efx_ptp_get_attributes(struct efx_nic *efx)
         */
        MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_GET_ATTRIBUTES);
        MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
-       rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
-                         outbuf, sizeof(outbuf), &out_len);
-       if (rc == 0)
+       rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
+                               outbuf, sizeof(outbuf), &out_len);
+       if (rc == 0) {
                fmt = MCDI_DWORD(outbuf, PTP_OUT_GET_ATTRIBUTES_TIME_FORMAT);
-       else if (rc == -EINVAL)
+       } else if (rc == -EINVAL) {
                fmt = MC_CMD_PTP_OUT_GET_ATTRIBUTES_SECONDS_NANOSECONDS;
-       else
+       } else if (rc == -EPERM) {
+               netif_info(efx, probe, efx->net_dev, "no PTP support\n");
                return rc;
+       } else {
+               efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
+                                      outbuf, sizeof(outbuf), rc);
+               return rc;
+       }
 
        if (fmt == MC_CMD_PTP_OUT_GET_ATTRIBUTES_SECONDS_27FRACTION) {
                ptp->ns_to_nic_time = efx_ptp_ns_to_s27;
@@ -541,8 +544,8 @@ static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
                       MC_CMD_PTP_OP_GET_TIMESTAMP_CORRECTIONS);
        MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
 
-       rc = efx_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
-                         outbuf, sizeof(outbuf), NULL);
+       rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
+                               outbuf, sizeof(outbuf), NULL);
        if (rc == 0) {
                efx->ptp_data->ts_corrections.tx = MCDI_DWORD(outbuf,
                        PTP_OUT_GET_TIMESTAMP_CORRECTIONS_TRANSMIT);
@@ -558,6 +561,8 @@ static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
                efx->ptp_data->ts_corrections.pps_out = 0;
                efx->ptp_data->ts_corrections.pps_in = 0;
        } else {
+               efx_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf), outbuf,
+                                      sizeof(outbuf), rc);
                return rc;
        }
 
@@ -568,7 +573,7 @@ static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
 static int efx_ptp_enable(struct efx_nic *efx)
 {
        MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_ENABLE_LEN);
-       MCDI_DECLARE_BUF_OUT_OR_ERR(outbuf, 0);
+       MCDI_DECLARE_BUF_ERR(outbuf);
        int rc;
 
        MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_ENABLE);
@@ -596,7 +601,7 @@ static int efx_ptp_enable(struct efx_nic *efx)
 static int efx_ptp_disable(struct efx_nic *efx)
 {
        MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_DISABLE_LEN);
-       MCDI_DECLARE_BUF_OUT_OR_ERR(outbuf, 0);
+       MCDI_DECLARE_BUF_ERR(outbuf);
        int rc;
 
        MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_DISABLE);
@@ -604,7 +609,12 @@ static int efx_ptp_disable(struct efx_nic *efx)
        rc = efx_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
                                outbuf, sizeof(outbuf), NULL);
        rc = (rc == -EALREADY) ? 0 : rc;
-       if (rc)
+       /* If we get ENOSYS, the NIC doesn't support PTP, and thus this function
+        * should only have been called during probe.
+        */
+       if (rc == -ENOSYS || rc == -EPERM)
+               netif_info(efx, probe, efx->net_dev, "no PTP support\n");
+       else if (rc)
                efx_mcdi_display_error(efx, MC_CMD_PTP,
                                       MC_CMD_PTP_IN_DISABLE_LEN,
                                       outbuf, sizeof(outbuf), rc);
@@ -636,28 +646,28 @@ static void efx_ptp_send_times(struct efx_nic *efx,
                               struct pps_event_time *last_time)
 {
        struct pps_event_time now;
-       struct timespec limit;
+       struct timespec64 limit;
        struct efx_ptp_data *ptp = efx->ptp_data;
-       struct timespec start;
+       struct timespec64 start;
        int *mc_running = ptp->start.addr;
 
        pps_get_ts(&now);
        start = now.ts_real;
        limit = now.ts_real;
-       timespec_add_ns(&limit, SYNCHRONISE_PERIOD_NS);
+       timespec64_add_ns(&limit, SYNCHRONISE_PERIOD_NS);
 
        /* Write host time for specified period or until MC is done */
-       while ((timespec_compare(&now.ts_real, &limit) < 0) &&
+       while ((timespec64_compare(&now.ts_real, &limit) < 0) &&
               ACCESS_ONCE(*mc_running)) {
-               struct timespec update_time;
+               struct timespec64 update_time;
                unsigned int host_time;
 
                /* Don't update continuously to avoid saturating the PCIe bus */
                update_time = now.ts_real;
-               timespec_add_ns(&update_time, SYNCHRONISATION_GRANULARITY_NS);
+               timespec64_add_ns(&update_time, SYNCHRONISATION_GRANULARITY_NS);
                do {
                        pps_get_ts(&now);
-               } while ((timespec_compare(&now.ts_real, &update_time) < 0) &&
+               } while ((timespec64_compare(&now.ts_real, &update_time) < 0) &&
                         ACCESS_ONCE(*mc_running));
 
                /* Synchronise NIC with single word of time only */
@@ -713,7 +723,7 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
        struct efx_ptp_data *ptp = efx->ptp_data;
        u32 last_sec;
        u32 start_sec;
-       struct timespec delta;
+       struct timespec64 delta;
        ktime_t mc_time;
 
        if (number_readings == 0)
@@ -727,14 +737,14 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
         */
        for (i = 0; i < number_readings; i++) {
                s32 window, corrected;
-               struct timespec wait;
+               struct timespec64 wait;
 
                efx_ptp_read_timeset(
                        MCDI_ARRAY_STRUCT_PTR(synch_buf,
                                              PTP_OUT_SYNCHRONIZE_TIMESET, i),
                        &ptp->timeset[i]);
 
-               wait = ktime_to_timespec(
+               wait = ktime_to_timespec64(
                        ptp->nic_to_kernel_time(0, ptp->timeset[i].wait, 0));
                window = ptp->timeset[i].window;
                corrected = window - wait.tv_nsec;
@@ -793,7 +803,7 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
                                          ptp->timeset[last_good].minor, 0);
 
        /* Calculate delay from NIC top of second to last_time */
-       delta.tv_nsec += ktime_to_timespec(mc_time).tv_nsec;
+       delta.tv_nsec += ktime_to_timespec64(mc_time).tv_nsec;
 
        /* Set PPS timestamp to match NIC top of second */
        ptp->host_time_pps = *last_time;