Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'ptp-adjfreq-copnvert'

Jacob Keller says:

====================
ptp: convert remaining users of .adjfreq

A handful of drivers remain which still use the .adjfreq interface instead
of the newer .adjfine interface. The new interface is preferred as it has a
more precise adjustment using scaled parts per million.

A handful of the remaining drivers are implemented with a common pattern
that can be refactored to use the adjust_by_scaled_ppm and
diff_by_scaled_ppm helper functions. These include the ptp_phc, ptp_ixp64x,
tg3, hclge, stmac, cpts and bnxt drivers. These are each refactored in a
separate change.

The remaining drivers, bnx2x, liquidio, cxgb4, fec, and qede implement
.adjfreq in a way different from the normal pattern expected by
adjust_by_scaled_ppm. Fixing these drivers to properly use .adjfine requires
specific knowledge of the hardware implementation. Instead I simply refactor
them to use .adjfine and convert scaled_ppm into ppb using the
scaled_ppm_to_ppb function.

Finally, the .adjfreq implementation interface is removed entirely. This
simplifies the interface and ensures that new drivers must implement the new
interface as they no longer have an alternative.

This still leaves parts per billion used as part of the max_adj interface,
and the core PTP stack still converts scaled_ppm to ppb to check this. I
plan to investigate fixing this in the future.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+88 -154
+5 -4
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
··· 13671 13671 return bnx2x_func_state_change(bp, &func_params); 13672 13672 } 13673 13673 13674 - static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 13674 + static int bnx2x_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 13675 13675 { 13676 13676 struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info); 13677 13677 int rc; 13678 13678 int drift_dir = 1; 13679 13679 int val, period, period1, period2, dif, dif1, dif2; 13680 13680 int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0; 13681 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 13681 13682 13682 - DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb); 13683 + DP(BNX2X_MSG_PTP, "PTP adjfine called, ppb = %d\n", ppb); 13683 13684 13684 13685 if (!netif_running(bp->dev)) { 13685 13686 DP(BNX2X_MSG_PTP, 13686 - "PTP adjfreq called while the interface is down\n"); 13687 + "PTP adjfine called while the interface is down\n"); 13687 13688 return -ENETDOWN; 13688 13689 } 13689 13690 ··· 13819 13818 bp->ptp_clock_info.n_ext_ts = 0; 13820 13819 bp->ptp_clock_info.n_per_out = 0; 13821 13820 bp->ptp_clock_info.pps = 0; 13822 - bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq; 13821 + bp->ptp_clock_info.adjfine = bnx2x_ptp_adjfine; 13823 13822 bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime; 13824 13823 bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime; 13825 13824 bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
+6 -16
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
··· 205 205 return 0; 206 206 } 207 207 208 - static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb) 208 + static int bnxt_ptp_adjfine(struct ptp_clock_info *ptp_info, long scaled_ppm) 209 209 { 210 210 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, 211 211 ptp_info); ··· 214 214 int rc = 0; 215 215 216 216 if (!(ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)) { 217 - int neg_adj = 0; 218 - u32 diff; 219 - u64 adj; 220 - 221 - if (ppb < 0) { 222 - neg_adj = 1; 223 - ppb = -ppb; 224 - } 225 - adj = ptp->cmult; 226 - adj *= ppb; 227 - diff = div_u64(adj, 1000000000ULL); 228 - 229 217 spin_lock_bh(&ptp->ptp_lock); 230 218 timecounter_read(&ptp->tc); 231 - ptp->cc.mult = neg_adj ? ptp->cmult - diff : ptp->cmult + diff; 219 + ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm); 232 220 spin_unlock_bh(&ptp->ptp_lock); 233 221 } else { 222 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 223 + 234 224 rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG); 235 225 if (rc) 236 226 return rc; ··· 230 240 rc = hwrm_req_send(ptp->bp, req); 231 241 if (rc) 232 242 netdev_err(ptp->bp->dev, 233 - "ptp adjfreq failed. rc = %d\n", rc); 243 + "ptp adjfine failed. rc = %d\n", rc); 234 244 } 235 245 return rc; 236 246 } ··· 759 769 .n_per_out = 0, 760 770 .n_pins = 0, 761 771 .pps = 0, 762 - .adjfreq = bnxt_ptp_adjfreq, 772 + .adjfine = bnxt_ptp_adjfine, 763 773 .adjtime = bnxt_ptp_adjtime, 764 774 .do_aux_work = bnxt_ptp_ts_aux_work, 765 775 .gettimex64 = bnxt_ptp_gettimex,
+7 -15
drivers/net/ethernet/broadcom/tg3.c
··· 6179 6179 return 0; 6180 6180 } 6181 6181 6182 - static int tg3_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 6182 + static int tg3_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 6183 6183 { 6184 6184 struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); 6185 - bool neg_adj = false; 6186 - u32 correction = 0; 6187 - 6188 - if (ppb < 0) { 6189 - neg_adj = true; 6190 - ppb = -ppb; 6191 - } 6185 + u64 correction; 6186 + bool neg_adj; 6192 6187 6193 6188 /* Frequency adjustment is performed using hardware with a 24 bit 6194 6189 * accumulator and a programmable correction value. On each clk, the 6195 6190 * correction value gets added to the accumulator and when it 6196 6191 * overflows, the time counter is incremented/decremented. 6197 - * 6198 - * So conversion from ppb to correction value is 6199 - * ppb * (1 << 24) / 1000000000 6200 6192 */ 6201 - correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & 6202 - TG3_EAV_REF_CLK_CORRECT_MASK; 6193 + neg_adj = diff_by_scaled_ppm(1 << 24, scaled_ppm, &correction); 6203 6194 6204 6195 tg3_full_lock(tp, 0); 6205 6196 6206 6197 if (correction) 6207 6198 tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 6208 6199 TG3_EAV_REF_CLK_CORRECT_EN | 6209 - (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); 6200 + (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | 6201 + ((u32)correction & TG3_EAV_REF_CLK_CORRECT_MASK)); 6210 6202 else 6211 6203 tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); 6212 6204 ··· 6322 6330 .n_per_out = 1, 6323 6331 .n_pins = 0, 6324 6332 .pps = 0, 6325 - .adjfreq = tg3_ptp_adjfreq, 6333 + .adjfine = tg3_ptp_adjfine, 6326 6334 .adjtime = tg3_ptp_adjtime, 6327 6335 .gettimex64 = tg3_ptp_gettimex, 6328 6336 .settime64 = tg3_ptp_settime,
+7 -4
drivers/net/ethernet/cavium/liquidio/lio_main.c
··· 1512 1512 } 1513 1513 1514 1514 /** 1515 - * liquidio_ptp_adjfreq - Adjust ptp frequency 1515 + * liquidio_ptp_adjfine - Adjust ptp frequency 1516 1516 * @ptp: PTP clock info 1517 - * @ppb: how much to adjust by, in parts-per-billion 1517 + * @scaled_ppm: how much to adjust by, in scaled parts-per-million 1518 + * 1519 + * Scaled parts per million is ppm with a 16-bit binary fractional field. 1518 1520 */ 1519 - static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 1521 + static int liquidio_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 1520 1522 { 1521 1523 struct lio *lio = container_of(ptp, struct lio, ptp_info); 1522 1524 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; 1525 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 1523 1526 u64 comp, delta; 1524 1527 unsigned long flags; 1525 1528 bool neg_adj = false; ··· 1646 1643 lio->ptp_info.n_ext_ts = 0; 1647 1644 lio->ptp_info.n_per_out = 0; 1648 1645 lio->ptp_info.pps = 0; 1649 - lio->ptp_info.adjfreq = liquidio_ptp_adjfreq; 1646 + lio->ptp_info.adjfine = liquidio_ptp_adjfine; 1650 1647 lio->ptp_info.adjtime = liquidio_ptp_adjtime; 1651 1648 lio->ptp_info.gettime64 = liquidio_ptp_gettime; 1652 1649 lio->ptp_info.settime64 = liquidio_ptp_settime;
+8 -5
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
··· 194 194 } 195 195 196 196 /** 197 - * cxgb4_ptp_adjfreq - Adjust frequency of PHC cycle counter 197 + * cxgb4_ptp_adjfine - Adjust frequency of PHC cycle counter 198 198 * @ptp: ptp clock structure 199 - * @ppb: Desired frequency change in parts per billion 199 + * @scaled_ppm: Desired frequency in scaled parts per billion 200 200 * 201 - * Adjust the frequency of the PHC cycle counter by the indicated ppb from 201 + * Adjust the frequency of the PHC cycle counter by the indicated amount from 202 202 * the base frequency. 203 + * 204 + * Scaled parts per million is ppm with a 16-bit binary fractional field. 203 205 */ 204 - static int cxgb4_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 206 + static int cxgb4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 205 207 { 206 208 struct adapter *adapter = (struct adapter *)container_of(ptp, 207 209 struct adapter, ptp_clock_info); 210 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 208 211 struct fw_ptp_cmd c; 209 212 int err; 210 213 ··· 407 404 .n_ext_ts = 0, 408 405 .n_per_out = 0, 409 406 .pps = 0, 410 - .adjfreq = cxgb4_ptp_adjfreq, 407 + .adjfine = cxgb4_ptp_adjfine, 411 408 .adjtime = cxgb4_ptp_adjtime, 412 409 .gettime64 = cxgb4_ptp_gettime, 413 410 .settime64 = cxgb4_ptp_settime,
+8 -5
drivers/net/ethernet/freescale/fec_ptp.c
··· 338 338 } 339 339 340 340 /** 341 - * fec_ptp_adjfreq - adjust ptp cycle frequency 341 + * fec_ptp_adjfine - adjust ptp cycle frequency 342 342 * @ptp: the ptp clock structure 343 - * @ppb: parts per billion adjustment from base 343 + * @scaled_ppm: scaled parts per million adjustment from base 344 344 * 345 345 * Adjust the frequency of the ptp cycle counter by the 346 - * indicated ppb from the base frequency. 346 + * indicated amount from the base frequency. 347 + * 348 + * Scaled parts per million is ppm with a 16-bit binary fractional field. 347 349 * 348 350 * Because ENET hardware frequency adjust is complex, 349 351 * using software method to do that. 350 352 */ 351 - static int fec_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 353 + static int fec_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 352 354 { 355 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 353 356 unsigned long flags; 354 357 int neg_adj = 0; 355 358 u32 i, tmp; ··· 745 742 fep->ptp_caps.n_per_out = 1; 746 743 fep->ptp_caps.n_pins = 0; 747 744 fep->ptp_caps.pps = 1; 748 - fep->ptp_caps.adjfreq = fec_ptp_adjfreq; 745 + fep->ptp_caps.adjfine = fec_ptp_adjfine; 749 746 fep->ptp_caps.adjtime = fec_ptp_adjtime; 750 747 fep->ptp_caps.gettime64 = fec_ptp_gettime; 751 748 fep->ptp_caps.settime64 = fec_ptp_settime;
+5 -17
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
··· 22 22 return 0; 23 23 } 24 24 25 - static int hclge_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 25 + static int hclge_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 26 26 { 27 27 struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp); 28 28 struct hclge_ptp_cycle *cycle = &hdev->ptp->cycle; 29 - u64 adj_val, adj_base, diff; 29 + u64 adj_val, adj_base; 30 30 unsigned long flags; 31 - bool is_neg = false; 32 31 u32 quo, numerator; 33 32 34 - if (ppb < 0) { 35 - ppb = -ppb; 36 - is_neg = true; 37 - } 38 - 39 33 adj_base = (u64)cycle->quo * (u64)cycle->den + (u64)cycle->numer; 40 - adj_val = adj_base * ppb; 41 - diff = div_u64(adj_val, 1000000000ULL); 42 - 43 - if (is_neg) 44 - adj_val = adj_base - diff; 45 - else 46 - adj_val = adj_base + diff; 34 + adj_val = adjust_by_scaled_ppm(adj_base, scaled_ppm); 47 35 48 36 /* This clock cycle is defined by three part: quotient, numerator 49 37 * and denominator. For example, 2.5ns, the quotient is 2, ··· 434 446 ptp->info.max_adj = HCLGE_PTP_CYCLE_ADJ_MAX; 435 447 ptp->info.n_ext_ts = 0; 436 448 ptp->info.pps = 0; 437 - ptp->info.adjfreq = hclge_ptp_adjfreq; 449 + ptp->info.adjfine = hclge_ptp_adjfine; 438 450 ptp->info.adjtime = hclge_ptp_adjtime; 439 451 ptp->info.gettimex64 = hclge_ptp_gettimex; 440 452 ptp->info.settime64 = hclge_ptp_settime; ··· 492 504 goto out; 493 505 494 506 set_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags); 495 - ret = hclge_ptp_adjfreq(&hdev->ptp->info, 0); 507 + ret = hclge_ptp_adjfine(&hdev->ptp->info, 0); 496 508 if (ret) { 497 509 dev_err(&hdev->pdev->dev, 498 510 "failed to init freq, ret = %d\n", ret);
+8 -5
drivers/net/ethernet/qlogic/qede/qede_ptp.c
··· 28 28 }; 29 29 30 30 /** 31 - * qede_ptp_adjfreq() - Adjust the frequency of the PTP cycle counter. 31 + * qede_ptp_adjfine() - Adjust the frequency of the PTP cycle counter. 32 32 * 33 33 * @info: The PTP clock info structure. 34 - * @ppb: Parts per billion adjustment from base. 34 + * @scaled_ppm: Scaled parts per million adjustment from base. 35 + * 36 + * Scaled parts per million is ppm with a 16-bit binary fractional field. 35 37 * 36 38 * Return: Zero on success, negative errno otherwise. 37 39 */ 38 - static int qede_ptp_adjfreq(struct ptp_clock_info *info, s32 ppb) 40 + static int qede_ptp_adjfine(struct ptp_clock_info *info, long scaled_ppm) 39 41 { 40 42 struct qede_ptp *ptp = container_of(info, struct qede_ptp, clock_info); 43 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 41 44 struct qede_dev *edev = ptp->edev; 42 45 int rc; 43 46 ··· 50 47 rc = ptp->ops->adjfreq(edev->cdev, ppb); 51 48 spin_unlock_bh(&ptp->lock); 52 49 } else { 53 - DP_ERR(edev, "PTP adjfreq called while interface is down\n"); 50 + DP_ERR(edev, "PTP adjfine called while interface is down\n"); 54 51 rc = -EFAULT; 55 52 } 56 53 __qede_unlock(edev); ··· 465 462 ptp->clock_info.n_ext_ts = 0; 466 463 ptp->clock_info.n_per_out = 0; 467 464 ptp->clock_info.pps = 0; 468 - ptp->clock_info.adjfreq = qede_ptp_adjfreq; 465 + ptp->clock_info.adjfine = qede_ptp_adjfine; 469 466 ptp->clock_info.adjtime = qede_ptp_adjtime; 470 467 ptp->clock_info.gettime64 = qede_ptp_gettime; 471 468 ptp->clock_info.settime64 = qede_ptp_settime;
+4 -3
drivers/net/ethernet/sfc/ptp.c
··· 351 351 void (*xmit_skb)(struct efx_nic *efx, struct sk_buff *skb); 352 352 }; 353 353 354 - static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta); 354 + static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm); 355 355 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta); 356 356 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts); 357 357 static int efx_phc_settime(struct ptp_clock_info *ptp, ··· 1508 1508 .n_per_out = 0, 1509 1509 .n_pins = 0, 1510 1510 .pps = 1, 1511 - .adjfreq = efx_phc_adjfreq, 1511 + .adjfine = efx_phc_adjfine, 1512 1512 .adjtime = efx_phc_adjtime, 1513 1513 .gettime64 = efx_phc_gettime, 1514 1514 .settime64 = efx_phc_settime, ··· 2137 2137 ptp->ts_corrections.general_rx); 2138 2138 } 2139 2139 2140 - static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta) 2140 + static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 2141 2141 { 2142 2142 struct efx_ptp_data *ptp_data = container_of(ptp, 2143 2143 struct efx_ptp_data, 2144 2144 phc_clock_info); 2145 + s32 delta = scaled_ppm_to_ppb(scaled_ppm); 2145 2146 struct efx_nic *efx = ptp_data->efx; 2146 2147 MCDI_DECLARE_BUF(inadj, MC_CMD_PTP_IN_ADJUST_LEN); 2147 2148 s64 adjustment_ns;
+4 -3
drivers/net/ethernet/sfc/siena/ptp.c
··· 347 347 void (*xmit_skb)(struct efx_nic *efx, struct sk_buff *skb); 348 348 }; 349 349 350 - static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta); 350 + static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm); 351 351 static int efx_phc_adjtime(struct ptp_clock_info *ptp, s64 delta); 352 352 static int efx_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts); 353 353 static int efx_phc_settime(struct ptp_clock_info *ptp, ··· 1429 1429 .n_per_out = 0, 1430 1430 .n_pins = 0, 1431 1431 .pps = 1, 1432 - .adjfreq = efx_phc_adjfreq, 1432 + .adjfine = efx_phc_adjfine, 1433 1433 .adjtime = efx_phc_adjtime, 1434 1434 .gettime64 = efx_phc_gettime, 1435 1435 .settime64 = efx_phc_settime, ··· 2044 2044 ptp->ts_corrections.general_rx); 2045 2045 } 2046 2046 2047 - static int efx_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta) 2047 + static int efx_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 2048 2048 { 2049 2049 struct efx_ptp_data *ptp_data = container_of(ptp, 2050 2050 struct efx_ptp_data, 2051 2051 phc_clock_info); 2052 + s32 delta = scaled_ppm_to_ppb(scaled_ppm); 2052 2053 struct efx_nic *efx = ptp_data->efx; 2053 2054 MCDI_DECLARE_BUF(inadj, MC_CMD_PTP_IN_ADJUST_LEN); 2054 2055 s64 adjustment_ns;
+7 -16
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
··· 15 15 * stmmac_adjust_freq 16 16 * 17 17 * @ptp: pointer to ptp_clock_info structure 18 - * @ppb: desired period change in parts ber billion 18 + * @scaled_ppm: desired period change in scaled parts per million 19 19 * 20 20 * Description: this function will adjust the frequency of hardware clock. 21 + * 22 + * Scaled parts per million is ppm with a 16-bit binary fractional field. 21 23 */ 22 - static int stmmac_adjust_freq(struct ptp_clock_info *ptp, s32 ppb) 24 + static int stmmac_adjust_freq(struct ptp_clock_info *ptp, long scaled_ppm) 23 25 { 24 26 struct stmmac_priv *priv = 25 27 container_of(ptp, struct stmmac_priv, ptp_clock_ops); 26 28 unsigned long flags; 27 - u32 diff, addend; 28 - int neg_adj = 0; 29 - u64 adj; 29 + u32 addend; 30 30 31 - if (ppb < 0) { 32 - neg_adj = 1; 33 - ppb = -ppb; 34 - } 35 - 36 - addend = priv->default_addend; 37 - adj = addend; 38 - adj *= ppb; 39 - diff = div_u64(adj, 1000000000ULL); 40 - addend = neg_adj ? (addend - diff) : (addend + diff); 31 + addend = adjust_by_scaled_ppm(priv->default_addend, scaled_ppm); 41 32 42 33 write_lock_irqsave(&priv->ptp_lock, flags); 43 34 stmmac_config_addend(priv, priv->ptpaddr, addend); ··· 260 269 .n_per_out = 0, /* will be overwritten in stmmac_ptp_register */ 261 270 .n_pins = 0, 262 271 .pps = 0, 263 - .adjfreq = stmmac_adjust_freq, 272 + .adjfine = stmmac_adjust_freq, 264 273 .adjtime = stmmac_adjust_time, 265 274 .gettime64 = stmmac_get_time, 266 275 .settime64 = stmmac_set_time,
+3 -2
drivers/net/ethernet/ti/am65-cpts.c
··· 391 391 } 392 392 393 393 /* PTP clock operations */ 394 - static int am65_cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 394 + static int am65_cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 395 395 { 396 396 struct am65_cpts *cpts = container_of(ptp, struct am65_cpts, ptp_info); 397 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 397 398 int neg_adj = 0; 398 399 u64 adj_period; 399 400 u32 val; ··· 626 625 static struct ptp_clock_info am65_ptp_info = { 627 626 .owner = THIS_MODULE, 628 627 .name = "CTPS timer", 629 - .adjfreq = am65_cpts_ptp_adjfreq, 628 + .adjfine = am65_cpts_ptp_adjfine, 630 629 .adjtime = am65_cpts_ptp_adjtime, 631 630 .gettimex64 = am65_cpts_ptp_gettimex, 632 631 .settime64 = am65_cpts_ptp_settime,
+4 -16
drivers/net/ethernet/ti/cpts.c
··· 213 213 214 214 /* PTP clock operations */ 215 215 216 - static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 216 + static int cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 217 217 { 218 218 struct cpts *cpts = container_of(ptp, struct cpts, info); 219 - int neg_adj = 0; 220 - u32 diff, mult; 221 - u64 adj; 222 - 223 - if (ppb < 0) { 224 - neg_adj = 1; 225 - ppb = -ppb; 226 - } 227 - mult = cpts->cc_mult; 228 - adj = mult; 229 - adj *= ppb; 230 - diff = div_u64(adj, 1000000000ULL); 231 219 232 220 mutex_lock(&cpts->ptp_clk_mutex); 233 221 234 - cpts->mult_new = neg_adj ? mult - diff : mult + diff; 222 + cpts->mult_new = adjust_by_scaled_ppm(cpts->cc_mult, scaled_ppm); 235 223 236 224 cpts_update_cur_time(cpts, CPTS_EV_PUSH, NULL); 237 225 ··· 423 435 .n_ext_ts = 0, 424 436 .n_pins = 0, 425 437 .pps = 0, 426 - .adjfreq = cpts_ptp_adjfreq, 438 + .adjfine = cpts_ptp_adjfine, 427 439 .adjtime = cpts_ptp_adjtime, 428 440 .gettimex64 = cpts_ptp_gettimeex, 429 441 .settime64 = cpts_ptp_settime, ··· 782 794 783 795 cpts_calc_mult_shift(cpts); 784 796 /* save cc.mult original value as it can be modified 785 - * by cpts_ptp_adjfreq(). 797 + * by cpts_ptp_adjfine(). 786 798 */ 787 799 cpts->cc_mult = cpts->cc.mult; 788 800
+4 -15
drivers/net/ethernet/xscale/ptp_ixp46x.c
··· 120 120 * PTP clock operations 121 121 */ 122 122 123 - static int ptp_ixp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 123 + static int ptp_ixp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 124 124 { 125 - u64 adj; 126 - u32 diff, addend; 127 - int neg_adj = 0; 125 + u32 addend; 128 126 struct ixp_clock *ixp_clock = container_of(ptp, struct ixp_clock, caps); 129 127 struct ixp46x_ts_regs *regs = ixp_clock->regs; 130 128 131 - if (ppb < 0) { 132 - neg_adj = 1; 133 - ppb = -ppb; 134 - } 135 - addend = DEFAULT_ADDEND; 136 - adj = addend; 137 - adj *= ppb; 138 - diff = div_u64(adj, 1000000000ULL); 139 - 140 - addend = neg_adj ? addend - diff : addend + diff; 129 + addend = adjust_by_scaled_ppm(DEFAULT_ADDEND, scaled_ppm); 141 130 142 131 __raw_writel(addend, &regs->addend); 143 132 ··· 219 230 .n_ext_ts = N_EXT_TS, 220 231 .n_pins = 0, 221 232 .pps = 0, 222 - .adjfreq = ptp_ixp_adjfreq, 233 + .adjfine = ptp_ixp_adjfine, 223 234 .adjtime = ptp_ixp_adjtime, 224 235 .gettime64 = ptp_ixp_gettime, 225 236 .settime64 = ptp_ixp_settime,
+1 -4
drivers/ptp/ptp_clock.c
··· 131 131 long ppb = scaled_ppm_to_ppb(tx->freq); 132 132 if (ppb > ops->max_adj || ppb < -ops->max_adj) 133 133 return -ERANGE; 134 - if (ops->adjfine) 135 - err = ops->adjfine(ops, tx->freq); 136 - else 137 - err = ops->adjfreq(ops, ppb); 134 + err = ops->adjfine(ops, tx->freq); 138 135 ptp->dialed_frequency = tx->freq; 139 136 } else if (tx->modes & ADJ_OFFSET) { 140 137 if (ops->adjphase) {
+3 -2
drivers/ptp/ptp_dte.c
··· 134 134 return ns; 135 135 } 136 136 137 - static int ptp_dte_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 137 + static int ptp_dte_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 138 138 { 139 + s32 ppb = scaled_ppm_to_ppb(scaled_ppm); 139 140 u32 nco_incr; 140 141 unsigned long flags; 141 142 struct ptp_dte *ptp_dte = container_of(ptp, struct ptp_dte, caps); ··· 220 219 .n_ext_ts = 0, 221 220 .n_pins = 0, 222 221 .pps = 0, 223 - .adjfreq = ptp_dte_adjfreq, 222 + .adjfine = ptp_dte_adjfine, 224 223 .adjtime = ptp_dte_adjtime, 225 224 .gettime64 = ptp_dte_gettime, 226 225 .settime64 = ptp_dte_settime,
+4 -15
drivers/ptp/ptp_pch.c
··· 336 336 * PTP clock operations 337 337 */ 338 338 339 - static int ptp_pch_adjfreq(struct ptp_clock_info *ptp, s32 ppb) 339 + static int ptp_pch_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) 340 340 { 341 - u64 adj; 342 - u32 diff, addend; 343 - int neg_adj = 0; 341 + u32 addend; 344 342 struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps); 345 343 struct pch_ts_regs __iomem *regs = pch_dev->regs; 346 344 347 - if (ppb < 0) { 348 - neg_adj = 1; 349 - ppb = -ppb; 350 - } 351 - addend = DEFAULT_ADDEND; 352 - adj = addend; 353 - adj *= ppb; 354 - diff = div_u64(adj, 1000000000ULL); 355 - 356 - addend = neg_adj ? addend - diff : addend + diff; 345 + addend = adjust_by_scaled_ppm(DEFAULT_ADDEND, scaled_ppm); 357 346 358 347 iowrite32(addend, &regs->addend); 359 348 ··· 429 440 .n_ext_ts = N_EXT_TS, 430 441 .n_pins = 0, 431 442 .pps = 0, 432 - .adjfreq = ptp_pch_adjfreq, 443 + .adjfine = ptp_pch_adjfine, 433 444 .adjtime = ptp_pch_adjtime, 434 445 .gettime64 = ptp_pch_gettime, 435 446 .settime64 = ptp_pch_settime,
-7
include/linux/ptp_clock_kernel.h
··· 77 77 * nominal frequency in parts per million, but with a 78 78 * 16 bit binary fractional field. 79 79 * 80 - * @adjfreq: Adjusts the frequency of the hardware clock. 81 - * This method is deprecated. New drivers should implement 82 - * the @adjfine method instead. 83 - * parameter delta: Desired frequency offset from nominal frequency 84 - * in parts per billion 85 - * 86 80 * @adjphase: Adjusts the phase offset of the hardware clock. 87 81 * parameter delta: Desired change in nanoseconds. 88 82 * ··· 168 174 int pps; 169 175 struct ptp_pin_desc *pin_config; 170 176 int (*adjfine)(struct ptp_clock_info *ptp, long scaled_ppm); 171 - int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta); 172 177 int (*adjphase)(struct ptp_clock_info *ptp, s32 phase); 173 178 int (*adjtime)(struct ptp_clock_info *ptp, s64 delta); 174 179 int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);