fm10k/base: fix ieee1588 adjustment direction
[dpdk.git] / drivers / net / fm10k / base / fm10k_pf.c
index cc85adb..6e6d71e 100644 (file)
@@ -1189,19 +1189,6 @@ STATIC void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
        fm10k_update_hw_stats_q(hw, q, idx, qpp);
 }
 
-STATIC s32 fm10k_iov_report_timestamp_pf(struct fm10k_hw *hw,
-                                        struct fm10k_vf_info *vf_info,
-                                        u64 timestamp)
-{
-       u32 msg[4];
-
-       /* generate port state response to notify VF it is not ready */
-       fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_1588);
-       fm10k_tlv_attr_put_u64(msg, FM10K_1588_MSG_TIMESTAMP, timestamp);
-
-       return vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
-}
-
 /**
  *  fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF
  *  @hw: Pointer to hardware structure
@@ -1857,57 +1844,81 @@ s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
        return FM10K_SUCCESS;
 }
 
+/* currently there is no shared 1588 timestamp handler */
+
 const struct fm10k_tlv_attr fm10k_1588_timestamp_msg_attr[] = {
        FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_TIMESTAMP,
                                 sizeof(struct fm10k_swapi_1588_timestamp)),
        FM10K_TLV_ATTR_LAST
 };
 
-const struct fm10k_tlv_attr fm10k_tx_timestamp_mode_attr[] = {
-       FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_TIMESTAMP_MODE_RESP,
-                                sizeof(struct fm10k_swapi_tx_timestamp_mode)),
+const struct fm10k_tlv_attr fm10k_1588_clock_owner_attr[] = {
+       FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_CLOCK_OWNER,
+                                sizeof(struct fm10k_swapi_1588_clock_owner)),
        FM10K_TLV_ATTR_LAST
 };
 
-/* currently there is no shared 1588 timestamp handler */
+const struct fm10k_tlv_attr fm10k_master_clk_offset_attr[] = {
+       FM10K_TLV_ATTR_U64(FM10K_PF_ATTR_ID_MASTER_CLK_OFFSET),
+       FM10K_TLV_ATTR_LAST
+};
 
 /**
- *  fm10k_request_tx_timestamp_mode_pf - Request a specific Tx timestamping mode
+ *  fm10k_iov_notify_offset_pf - Notify VF of change in PTP offset
  *  @hw: pointer to hardware structure
- *  @glort: base resource tag for this request
- *  @mode: integer value indicating the requested mode
+ *  @vf_info: pointer to the vf info structure
+ *  @offset: 64bit unsigned offset from hardware SYSTIME
  *
- *  This function will attempt to request a specific timestamp mode for the
- *  port so that it can receive Tx timestamp messages.
+ *  This function sends a message to a given VF to notify it of PTP offset
+ *  changes.
  **/
-STATIC s32 fm10k_request_tx_timestamp_mode_pf(struct fm10k_hw *hw,
-                                             u16 glort,
-                                             u8 mode)
+STATIC void fm10k_iov_notify_offset_pf(struct fm10k_hw *hw,
+                                      struct fm10k_vf_info *vf_info,
+                                      u64 offset)
 {
-       struct fm10k_mbx_info *mbx = &hw->mbx;
-       u32 msg[3], timestamp_mode;
+       u32 msg[4];
 
-       DEBUGFUNC("fm10k_request_timestamp_mode_pf");
+       fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_1588);
+       fm10k_tlv_attr_put_u64(msg, FM10K_1588_MSG_CLK_OFFSET, offset);
 
-       if (mode > FM10K_TIMESTAMP_MODE_PEP_TO_ANY)
-               return FM10K_ERR_PARAM;
+       if (vf_info->mbx.ops.enqueue_tx)
+               vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
+}
 
-       /* if glort is not valid return error */
-       if (!fm10k_glort_valid_pf(hw, glort))
-               return FM10K_ERR_PARAM;
+/**
+ *  fm10k_msg_1588_clock_owner_pf - Message handler for clock ownership from SM
+ *  @hw: pointer to hardware structure
+ *  @results: pointer to array containing parsed data,
+ *  @mbx: Pointer to mailbox information structure
+ *
+ *  This handler configures the FM10K_HW_FLAG_CLOCK_OWNER field for the PF
+ */
+s32 fm10k_msg_1588_clock_owner_pf(struct fm10k_hw *hw, u32 **results,
+                                 struct fm10k_mbx_info *mbx)
+{
+       struct fm10k_swapi_1588_clock_owner msg;
+       u16 glort;
+       s32 err;
 
-       /* write timestamp mode as a single u32 value,
-        * lower 16 bits: glort
-        * upper 16 bits: mode
-        */
-       timestamp_mode = ((u32)mode << 16) | glort;
+       UNREFERENCED_1PARAMETER(mbx);
+       DEBUGFUNC("fm10k_msg_1588_clock_owner");
 
-       /* generate message requesting change to xcast mode */
-       fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_TX_TIMESTAMP_MODE);
-       fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_TIMESTAMP_MODE_REQ, timestamp_mode);
+       err = fm10k_tlv_attr_get_le_struct(
+               results[FM10K_PF_ATTR_ID_1588_CLOCK_OWNER],
+               &msg, sizeof(msg));
+       if (err)
+               return err;
 
-       /* load onto outgoing mailbox */
-       return mbx->ops.enqueue_tx(hw, mbx, msg);
+       /* We own the clock iff the glort matches us and the enabled field is
+        * true. Otherwise, the clock must belong to some other port.
+        */
+       glort = le16_to_cpu(msg.glort);
+       if (fm10k_glort_valid_pf(hw, glort) && msg.enabled)
+               hw->flags |= FM10K_HW_FLAG_CLOCK_OWNER;
+       else
+               hw->flags &= ~FM10K_HW_FLAG_CLOCK_OWNER;
+
+       return FM10K_SUCCESS;
 }
 
 /**
@@ -1929,6 +1940,10 @@ STATIC s32 fm10k_adjust_systime_pf(struct fm10k_hw *hw, s32 ppb)
 
        DEBUGFUNC("fm10k_adjust_systime_pf");
 
+       /* ensure that we control the clock */
+       if (!(hw->flags & FM10K_HW_FLAG_CLOCK_OWNER))
+               return FM10K_ERR_DEVICE_NOT_SUPPORTED;
+
        /* if sw_addr is not set we don't have switch register access */
        if (!hw->sw_addr)
                return ppb ? FM10K_ERR_PARAM : FM10K_SUCCESS;
@@ -1954,14 +1969,41 @@ STATIC s32 fm10k_adjust_systime_pf(struct fm10k_hw *hw, s32 ppb)
        if (systime_adjust > FM10K_SW_SYSTIME_ADJUST_MASK)
                return FM10K_ERR_PARAM;
 
-       if (ppb < 0)
-               systime_adjust |= FM10K_SW_SYSTIME_ADJUST_DIR_NEGATIVE;
+       if (ppb > 0)
+               systime_adjust |= FM10K_SW_SYSTIME_ADJUST_DIR_POSITIVE;
 
        FM10K_WRITE_SW_REG(hw, FM10K_SW_SYSTIME_ADJUST, (u32)systime_adjust);
 
        return FM10K_SUCCESS;
 }
 
+/**
+ *  fm10k_notify_offset_pf - Notify switch of change in PTP offset
+ *  @hw: pointer to hardware structure
+ *  @offset: 64bit unsigned offset of SYSTIME
+ *
+ *  This function sends a message to the switch to indicate a change in the
+ *  offset of the hardware SYSTIME registers. The switch manager is
+ *  responsible for transmitting this message to other hosts.
+ */
+STATIC s32 fm10k_notify_offset_pf(struct fm10k_hw *hw, u64 offset)
+{
+       struct fm10k_mbx_info *mbx = &hw->mbx;
+       u32 msg[4];
+
+       DEBUGFUNC("fm10k_notify_offset_pf");
+
+       /* ensure that we control the clock */
+       if (!(hw->flags & FM10K_HW_FLAG_CLOCK_OWNER))
+               return FM10K_ERR_DEVICE_NOT_SUPPORTED;
+
+       fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_MASTER_CLK_OFFSET);
+       fm10k_tlv_attr_put_u64(msg, FM10K_PF_ATTR_ID_MASTER_CLK_OFFSET, offset);
+
+       /* load onto outgoing mailbox */
+       return mbx->ops.enqueue_tx(hw, mbx, msg);
+}
+
 /**
  *  fm10k_read_systime_pf - Reads value of systime registers
  *  @hw: pointer to the hardware structure
@@ -1994,6 +2036,7 @@ static const struct fm10k_msg_data fm10k_msg_data_pf[] = {
        FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
        FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
        FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
+       FM10K_PF_MSG_1588_CLOCK_OWNER_HANDLER(fm10k_msg_1588_clock_owner_pf),
        FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
 };
 
@@ -2032,8 +2075,8 @@ s32 fm10k_init_ops_pf(struct fm10k_hw *hw)
        mac->ops.get_fault = &fm10k_get_fault_pf;
        mac->ops.get_host_state = &fm10k_get_host_state_pf;
        mac->ops.adjust_systime = &fm10k_adjust_systime_pf;
+       mac->ops.notify_offset = &fm10k_notify_offset_pf;
        mac->ops.read_systime = &fm10k_read_systime_pf;
-       mac->ops.request_tx_timestamp_mode = &fm10k_request_tx_timestamp_mode_pf;
 
        mac->max_msix_vectors = fm10k_get_pcie_msix_count_generic(hw);
 
@@ -2045,7 +2088,7 @@ s32 fm10k_init_ops_pf(struct fm10k_hw *hw)
        iov->ops.set_lport = &fm10k_iov_set_lport_pf;
        iov->ops.reset_lport = &fm10k_iov_reset_lport_pf;
        iov->ops.update_stats = &fm10k_iov_update_stats_pf;
-       iov->ops.report_timestamp = &fm10k_iov_report_timestamp_pf;
+       iov->ops.notify_offset = &fm10k_iov_notify_offset_pf;
 
        return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf);
 }