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

ptp: add kernel API ptp_get_vclocks_index()

Add kernel API ptp_get_vclocks_index() to get all ptp
vclocks index on pclock.

This is preparation for supporting ptp vclocks info query
through ethtool.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Yangbo Lu and committed by
David S. Miller
acb288e8 44c494c8

+53 -1
+2 -1
drivers/ptp/ptp_clock.c
··· 24 24 #define PTP_PPS_EVENT PPS_CAPTUREASSERT 25 25 #define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC) 26 26 27 + struct class *ptp_class; 28 + 27 29 /* private globals */ 28 30 29 31 static dev_t ptp_devt; 30 - static struct class *ptp_class; 31 32 32 33 static DEFINE_IDA(ptp_clocks_map); 33 34
+2
drivers/ptp/ptp_private.h
··· 96 96 return in_use; 97 97 } 98 98 99 + extern struct class *ptp_class; 100 + 99 101 /* 100 102 * see ptp_chardev.c 101 103 */
+35
drivers/ptp/ptp_vclock.c
··· 148 148 ptp_clock_unregister(vclock->clock); 149 149 kfree(vclock); 150 150 } 151 + 152 + int ptp_get_vclocks_index(int pclock_index, int **vclock_index) 153 + { 154 + char name[PTP_CLOCK_NAME_LEN] = ""; 155 + struct ptp_clock *ptp; 156 + struct device *dev; 157 + int num = 0; 158 + 159 + if (pclock_index < 0) 160 + return num; 161 + 162 + snprintf(name, PTP_CLOCK_NAME_LEN, "ptp%d", pclock_index); 163 + dev = class_find_device_by_name(ptp_class, name); 164 + if (!dev) 165 + return num; 166 + 167 + ptp = dev_get_drvdata(dev); 168 + 169 + if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) { 170 + put_device(dev); 171 + return num; 172 + } 173 + 174 + *vclock_index = kzalloc(sizeof(int) * ptp->n_vclocks, GFP_KERNEL); 175 + if (!(*vclock_index)) 176 + goto out; 177 + 178 + memcpy(*vclock_index, ptp->vclock_index, sizeof(int) * ptp->n_vclocks); 179 + num = ptp->n_vclocks; 180 + out: 181 + mutex_unlock(&ptp->n_vclocks_mux); 182 + put_device(dev); 183 + return num; 184 + } 185 + EXPORT_SYMBOL(ptp_get_vclocks_index);
+14
include/linux/ptp_clock_kernel.h
··· 306 306 */ 307 307 void ptp_cancel_worker_sync(struct ptp_clock *ptp); 308 308 309 + /** 310 + * ptp_get_vclocks_index() - get all vclocks index on pclock, and 311 + * caller is responsible to free memory 312 + * of vclock_index 313 + * 314 + * @pclock_index: phc index of ptp pclock. 315 + * @vclock_index: pointer to pointer of vclock index. 316 + * 317 + * return number of vclocks. 318 + */ 319 + int ptp_get_vclocks_index(int pclock_index, int **vclock_index); 320 + 309 321 #else 310 322 static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, 311 323 struct device *parent) ··· 337 325 { return -EOPNOTSUPP; } 338 326 static inline void ptp_cancel_worker_sync(struct ptp_clock *ptp) 339 327 { } 328 + static inline int ptp_get_vclocks_index(int pclock_index, int **vclock_index) 329 + { return 0; } 340 330 341 331 #endif 342 332