Create common DPLL/clock configuration API
Subsystems (11)
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jakub KicinskiQuoted 31 lines · Tue, May 09, 2023 at 07:53:02PM CEST, [email protected] wrote:
Quoted 30 lines · On Tue, 9 May 2023 17:21:42 +0200 Jiri Pirko wrote:
Quoted 7 lines · Tue, May 09, 2023 at 04:52:47PM CEST, [email protected] wrote:
Quoted 3 lines · On Tue, 9 May 2023 09:53:07 +0200 Jiri Pirko wrote:
Quoted 1 line
Yup. Even renaming EXT to something that's less.. relative :(
Suggestion?
Well, is an SMT socket on the board an EXT pin?
Which is why I prefer PANEL.Makes sense.
To speak code, we'll have:/**
* enumdpll_pin_type- defines possible types of a pin, valid values for
*DPLL_A_PIN_TYPEattribute
* @DPLL_PIN_TYPE_UNSPEC: unspecified value
* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins
* @DPLL_PIN_TYPE_PANEL: physically facing user, for example on a front panel
* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock
* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator
* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock
*/
enumdpll_pin_type{
DPLL_PIN_TYPE_UNSPEC,
DPLL_PIN_TYPE_MUX,
DPLL_PIN_TYPE_PANEL,
DPLL_PIN_TYPE_SYNCE_ETH_PORT,DPLL_PIN_TYPE_INT_OSCILLATOR,
DPLL_PIN_TYPE_GNSS,
Quoted 6 lines
Quoted 3 lines
__DPLL_PIN_TYPE_MAX, DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1) };Maybe we can keep the EXT here, just not in the label itself. Don't think we care to add pin type for PANEL vs SMT vs jumper?
Okay:
enum dpll_pin_type {
DPLL_PIN_TYPE_UNSPEC,
DPLL_PIN_TYPE_MUX,
DPLL_PIN_TYPE_EXT,
DPLL_PIN_TYPE_SYNCE_ETH_PORT,
DPLL_PIN_TYPE_INT_OSCILLATOR,
DPLL_PIN_TYPE_GNSS,
__DPLL_PIN_TYPE_MAX,
DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1)
};Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 3 lines
Sure, I get what you say and agree. I'm just trying to find out the actual attributes :)
PANEL label must match the name on the panel. User can take the card into their hand, look at the front, and there should be a label/sticker/ /engraving which matches exactly what the kernel reports.
If the label is printed on the board it's a
BOARD_LABEL, if it's the name of a trace in board docs it's aBOARD_TRACE, if it's a pin of the ASIC it's aPACKAGE_PIN.If it's none of those, or user does not have access to the detailed board / pinout - don't use the label.
Quoted 6 lines
Quoted 3 lines
To speak code, we'll have:
DPLL_A_PIN_PANEL_LABEL(string)
available always when attr[DPLL_A_PIN_TYPE] ==DPLL_PIN_TYPE_PANELNot sure about always, if there's only one maybe there's no need to provide the label?
Well, I would like to have check in pin_register() for this. That would be non-trivial if this would be required only in case pin_count>1. However I can imagine a card with one connector without any label on it. IDK.
Quoted 11 lines
Quoted 9 lines
DPLL_A_PIN_BOARD_LABEL(string)
may be available for any type, optionalDPLL_A_PIN_BOARD_TRACE(string)
may be available for any type, optionalDPLL_A_PIN_PACKAGE_PIN(string)
may be available for any type, optionalMakes sense?
yup (obviously we need to document the semantics)
Agreed.
Quoted 8 lines
Quoted 3 lines
But this does not prevent driver developer to pack random crap in the string anyway :/
It doesn't but it hopefully makes it much more likely that (1) reviewer will notice that something is off if the driver printfs random crap; and (2) that the user reading the documentation will complain that e.g.BOARD_LABEL is used but does not match the label on they see...
Fair.
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoQuoted 3 lines
From: Vadim Fedorenko <[email protected]>
Sent: Tuesday, March 14, 2023 12:00 AM
[...]
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+ +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/ +struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index;Quoted 8 lines
drivers/dpll/dpll_core.c line 331
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.
Quoted 7 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is
the same for both of them. But Arkadiusz can tell more about it.
Yes, exactly.
One driver can have multiple dplls with the same clock id. Actually dev_driver_id makes dpll objects unique.
Quoted 4 lines
Quoted 2 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?
Looks good to me.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/dpll_core.c new file +19
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/** +* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete Quoted 8 lines
drivers/dpll/dpll_core.c line 356
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/dpll_core.c new file +4
-0+void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;Remove this check. The driver should not call this with NULL.
Quoted 3 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.
I agree, IMHO it is better to have safety checks :)
Quoted 8 lines
Quoted 5 lines
drivers/dpll/dpll_core.c line 359
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Yes, great point!
Quoted 58 lines
Quoted 58 lines
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56
Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Makes sense to me.
Quoted 42 lines
Quoted 33 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
Quoted 30 lines
drivers/dpll/dpll_core.c new file +30
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); + +/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver Quoted 8 lines
Quoted 6 lines
+ * @module: reference to registering module
+ * @prop: dpll pin properties
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorExtra "*"'s
Quoted 1 line
Ok, I can re-format the comments across the files.
This is expected on enumerating return values in kernel-docs:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#Return%20values
Quoted 58 lines
Quoted 4 lines
Review
Quoted 4 lines
+ */
(quoted diff) +2
-0+struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module*module,
Quoted 5 lines
Odd whitespace.
Also, func should be static.
Fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 448
Quoted 10 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;Name inconsistency: driver/drv
you have it on multiple placesChanged it every where, thanks for spotting.
Quoted 18 lines
Quoted 18 lines
drivers/dpll/dpll_core.c new file +17
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + }Quoted 9 lines
drivers/dpll/dpll_core.c line 470
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 6 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case.
Not sure if the pointer way is much better...
I also don't feel it.
Dpll subsystem directly using memory of different driver doesn't look like a great design.
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
drivers/dpll/dpll_core.c new file +25
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new
+ * if doesn't exist yet.Quoted 9 lines
Quoted 4 lines
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorThis is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
Quoted 2 lines
Yep, will clear .h files.
There might be some issues, and certainly makes sense to have them in one place.
Quoted 8 lines
Quoted 7 lines
drivers/dpll/dpll_core.c line 503
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,Again, why do you need this
device_drv_id? Clock id should be enough.I explained the reason earlier, but the naming is fixed.
Yes, this device_drv_id is id of a pin not a dpll device id. Maybe worth to rename it to make it more clear.
Quoted 15 lines
Quoted 15 lines
drivers/dpll/dpll_core.c line 513
Quoted 12 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 5 lines
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.I think
clock_id+dev_driver_id+ module should identify the pin exactly.
Yes, they should be unique for a single pin object, and enough for getting pin reference.
Basically if driver would call twice this with different props, it would be broken.
We could have props compared here as well.
Quoted 2 lines
And
now I think that *prop is not needed here at all. Arkadiusz, any thoughts?
As dpll_pin_alloc is having them assigned to a pin object, thus had to put it here. Not sure how to solve it differently.
Jiri's suggestion to put dev_driver_id inside of pin props would also work AFAIU.
[...]
Quoted 31 lines
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) : NULL;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Quoted 2 lines
Well, these questions go to Arkadiusz...
If pin is able to recover signal from some device this shall convey that device struct pointer.
Name of that device is later passed to the user with DPLL_A_PIN_RCLK_DEVICE attribute.
Sure we can have pointer to device and use dev_name (each do/dump) on netlink part. But isn't it better to have the name ready to use there?
It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
[...]
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 755
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
I believe if proper synchronization in place it shall not be NULL, I left it after fixing some issue with access to the pin that was already removed..
Quoted 7 lines
Quoted 4 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
After quick thinking, it might be doable, storing pin being registered on dpll->pin_refs under given by driver pin's dev_driver_idx or whatever it would be named.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/dpll/dpll_core.c new file +23
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +} +EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +*
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
+ * Return: pointer to the data
+ */
+void *dpll_pin_on_dpll_priv(const structdpll_device*dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
No strong opinion, probably doable.
Quoted 9 lines
Quoted 9 lines
drivers/dpll/dpll_core.c line 786
Quoted 6 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
const of struct dpll_pin *pin makes a warning/error there, there is something broken on xarray implementation of for_each I believe.
[...]
Quoted 44 lines
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 241
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+ +static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+enum dpll_pin_state state; +struct nlattr *nest; +unsigned long index; +int ret; + +xa_for_each (&pin->parent_refs, index, ref) { +if (WARN_ON (!ref->ops->state_on_pin_get)) +return -EFAULT ; + ret = ref->ops->state_on_pin_get (pin, ref->pin, &state, + extack); +if (ret) +return -EFAULT ; + nest =nla_nest_start (msg,DPLL_A_PIN_PARENT ); +if (!nest) +return -EMSGSIZE ; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/dpll_netlink.c line 267
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +if (nla_put_u8 (msg,DPLL_A_PIN_STATE , state)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +nla_nest_end (msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/
Quoted 7 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
Quoted 55 lines
Quoted 45 lines
Quoted 45 lines
drivers/dpll/dpll_netlink.c new file +44
-0+ +return 0 ; + +nest_cancel: +nla_nest_cancel (msg, nest); +return ret; +} + +static int +dpll_msg_add_pin_dplls (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct nlattr *attr; +unsigned long index; +int ret; + +xa_for_each (&pin->dpll_refs, index, ref) { + attr =nla_nest_start (msg,DPLL_A_DEVICE ); +if (!attr) +return -EMSGSIZE ; + ret =dpll_msg_add_dev_handle (msg, ref->dpll); +if (ret) + goto nest_cancel; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; +nla_nest_end (msg, attr); + } + +return 0 ; + +nest_cancel: +nla_nest_end (msg, attr); +return ret; +} + +static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack)Quoted 9 lines
drivers/dpll/dpll_netlink.c line 316
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 3 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.
Yes, confusing a bit, I agree we need a fix of this.
Isn't it that dpll has an INDEX assigned by dpll subsystem on its allocation and pin have ID given by the driver?
[...]
Quoted 60 lines
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 563
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+static int +dpll_pin_set_from_nlattr (struct dpll_device *dpll, +struct dpll_pin *pin,struct genl_info *info) +{ +enum dpll_pin_state state =DPLL_PIN_STATE_UNSPEC ; +u32 parent_idx =PIN_IDX_INVALID ;You just need this
PIN_IDX_INVALIDdefine internally in this function, change the flow to avoid a need for it.I'll re-think it, thanks.
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 568
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +5
-0+int rem, ret = -EINVAL ; +struct nlattr *a; + +nla_for_each_attr (a,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
I had some unknown crashes when I was using such access. I might have lost some
checks, will try it again.Quoted 32 lines
Quoted 18 lines
drivers/dpll/dpll_netlink.c new file +17
-0+switch (nla_type (a)) { +case DPLL_A_PIN_FREQUENCY : + ret =dpll_pin_freq_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_DIRECTION : + ret =dpll_pin_direction_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PRIO : + ret =dpll_pin_prio_set (dpll, pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PARENT_IDX :drivers/dpll/dpll_netlink.c line 595
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ parent_idx =nla_get_u32 (a); +break ; +case DPLL_A_PIN_STATE : + state =nla_get_u8 (a); +break ; +default : +break ; + } + } +if (state !=DPLL_PIN_STATE_UNSPEC ) {Again, change the flow to:
if (attrs[DPLL_A_PIN_STATE]) {
Quoted 4 lines
Quoted 2 lines
and avoid need for this value set/check.
Yep, will try.
Yes, this shall work now, as long as there are no multiple nested attributes coming from userspace.
[...]
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
+void dpll_pin_post_doit(const struct
genl_split_ops*ops, structsk_buff*skb,drivers/dpll/dpll_netlink.c new file +4
-0+ struct genl_info *info) +{ +mutex_unlock (&dpll_pin_xa_lock); +dpll_post_doit (ops, skb, info);Quoted 9 lines
drivers/dpll/dpll_netlink.c line 878
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+} + +int dpll_pin_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Quoted 4 lines
Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?
Not really, this is why it is there :(
A single global lock for whole dpll subsystem?
Quoted 38 lines
Quoted 36 lines
Quoted 15 lines
drivers/dpll/dpll_netlink.c new file +14
-0+ +return dpll_pre_dumpit (cb); +} + +int dpll_pin_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_pin_xa_lock); + +return dpll_post_dumpit (cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/dpll_netlink.c line 902
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
Quoted 8 lines
But with full object-snapshot user space app will lose the information about
what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
I agree that from functional perspective it is better to have on userspace a reason of the notification.
[...]
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 47 lines · Tue, Mar 14, 2023 at 05:43:18PM CET, [email protected] wrote:
Quoted 3 lines
From: Vadim Fedorenko <[email protected]>
Sent: Tuesday, March 14, 2023 12:00 AM[...]
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+ +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/ +struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index;Quoted 8 lines
drivers/dpll/dpll_core.c line 331
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.Quoted 7 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is
the same for both of them. But Arkadiusz can tell more about it.Yes, exactly.
One driver can have multiple dplls with the same clock id. Actuallydev_driver_idmakes dpll objects unique.Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?Looks good to me.
Let's call this "device_index" and "pin_index" for the pin getter as I suggested in the other email.
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 17 lines
drivers/dpll/dpll_core.c new file +15
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/** drivers/dpll/dpll_core.c line 356
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete +* dpll device object. +*/ +void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;Remove this check. The driver should not call this with NULL.
Quoted 5 lines
Quoted 3 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.I agree, IMHO it is better to have safety checks :)
IDK, we should rely on basic driver sanity. Let least put a WARN_ON() to these checks. But try to reduce them at least.
Quoted 76 lines
Quoted 9 lines
Quoted 6 lines
drivers/dpll/dpll_core.c line 359
Quoted 4 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Yes, great point!
Quoted 64 lines
Quoted 63 lines
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2
Quoted 3 lines
Quoted 1 line
Looks good, will change it
Makes sense to me.
Good. Fits the mlx5 model nicely.
Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
Quoted 26 lines
drivers/dpll/dpll_core.c new file +26
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); +drivers/dpll/dpll_core.c line 436
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Return: +* * valid allocated dpll_pin struct pointer if succeeded +* * ERR_PTR of an error Extra "*"'s
Quoted 4 lines
Quoted 1 line
Ok, I can re-format the comments across the files.
This is expected on enumerating return values in kernel-docs:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#Return%20values
Ah, okay. I missed that. Sorry.
Quoted 66 lines
Quoted 59 lines
Quoted 5 lines
Review
Quoted 5 lines
+ */
(quoted diff) +2
-0+struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module*module,
Quoted 5 lines
Odd whitespace.
Also, func should be static.
Fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 448
Quoted 10 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;Name inconsistency: driver/drv
you have it on multiple placesChanged it every where, thanks for spotting.
Quoted 18 lines
Quoted 18 lines
drivers/dpll/dpll_core.c new file +17
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + }Quoted 9 lines
drivers/dpll/dpll_core.c line 470
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 6 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case.
Not sure if the pointer way is much better...
Quoted 3 lines
I also don't feel it.
Dpll subsystem directly using memory of different driver doesn't look like a great design.
Wait. This is done all the time in kernel. Almost every ops for example. Lots of other examples like that as well:
git grep "static const struct" drivers/net/
Quoted 52 lines
Quoted 39 lines
Quoted 29 lines
Quoted 29 lines
drivers/dpll/dpll_core.c new file +25
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new
+ * if doesn't exist yet.Quoted 9 lines
Quoted 4 lines
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorThis is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
Quoted 2 lines
Yep, will clear .h files.
There might be some issues, and certainly makes sense to have them in one place.
Quoted 7 lines
Quoted 7 lines
drivers/dpll/dpll_core.c line 503
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,Again, why do you need this
device_drv_id? Clock id should be enough.
Quoted 4 lines
Quoted 1 line
I explained the reason earlier, but the naming is fixed.
Yes, this
device_drv_idis id of a pin not a dpll device id. Maybe worth to rename it to make it more clear.
Yeah, device_index and pin_index
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
drivers/dpll/dpll_core.c line 513
Quoted 13 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.
Quoted 7 lines
Quoted 1 line
I think
clock_id+dev_driver_id+ module should identify the pin exactly.Yes, they should be unique for a single pin object, and enough for getting pin reference.
Basically if driver would call twice this with different props, it would be broken.
We could have props compared here as well.
Let's leave it as it is for now, it's ok.
Quoted 8 lines
Quoted 3 lines
And
now I think that *prop is not needed here at all. Arkadiusz, any thoughts?As
dpll_pin_allocis having them assigned to a pin object, thus had to put it here. Not sure how to solve it differently.
Jiri's suggestion to putdev_driver_idinside of pin props would also work AFAIU.
Let's have it as device_get()/pin_get() args as you have it right now. Makes more sense as the prop could be static const as I described in the other email.
Quoted 44 lines
[...]
Quoted 31 lines
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) : NULL;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?Quoted 2 lines
Well, these questions go to Arkadiusz...
If pin is able to recover signal from some device this shall convey that device struct pointer.
Name of that device is later passed to the user withDPLL_A_PIN_RCLK_DEVICEattribute.
Sure we can have pointer to device and usedev_name(each do/dump) on netlink part. But isn't it better to have the name ready to use there?
Quoted 2 lines
It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Very valid as I explained in the other email.
Quoted 18 lines
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
[...]
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 755
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
Quoted 2 lines
I believe if proper synchronization in place it shall not be NULL, I left it after fixing some issue with access to the pin that was already removed..
Then don't check it here.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 7 lines
Quoted 3 lines
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
After quick thinking, it might be doable, storing pin being registered on
dpll->pin_refsunder given by driver pin'sdev_driver_idxor whatever it would be named.
Yep.
Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/dpll/dpll_core.c new file +23
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +} +EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
+ * Return: pointer to the data
+ */
+void *dpll_pin_on_dpll_priv(const structdpll_device*dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
Quoted 1 line
No strong opinion, probably doable.
It is better for the driver writer to actually see right away that there is a priv so he can use it and not need to get the priv from some place else (using pin index * lookup). Very nice example where this would work is the last patch of this set, where Vadim does not use priv at all.
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 786
Quoted 7 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
Quoted 2 lines
constof structdpll_pin*pin makes a warning/error there, there is something broken on xarray implementation offor_eachI believe.
Either fix it or avoid using const arg. Cast's like this always smell and should be avoided.
Quoted 113 lines
[...]
Quoted 44 lines
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 241
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+ +static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+enum dpll_pin_state state; +struct nlattr *nest; +unsigned long index; +int ret; + +xa_for_each (&pin->parent_refs, index, ref) { +if (WARN_ON (!ref->ops->state_on_pin_get)) +return -EFAULT ; + ret = ref->ops->state_on_pin_get (pin, ref->pin, &state, + extack); +if (ret) +return -EFAULT ; + nest =nla_nest_start (msg,DPLL_A_PIN_PARENT ); +if (!nest) +return -EMSGSIZE ; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/dpll_netlink.c line 267
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +if (nla_put_u8 (msg,DPLL_A_PIN_STATE , state)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +nla_nest_end (msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/Quoted 7 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
Quoted 55 lines
Quoted 54 lines
Quoted 40 lines
drivers/dpll/dpll_netlink.c new file +39
-0+ +return 0 ; + +nest_cancel: +nla_nest_cancel (msg, nest); +return ret; +} + +static int +dpll_msg_add_pin_dplls (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct nlattr *attr; +unsigned long index; +int ret; + +xa_for_each (&pin->dpll_refs, index, ref) { + attr =nla_nest_start (msg,DPLL_A_DEVICE ); +if (!attr) +return -EMSGSIZE ; + ret =dpll_msg_add_dev_handle (msg, ref->dpll); +if (ret) + goto nest_cancel; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; +nla_nest_end (msg, attr); + } + +return 0 ; + +nest_cancel: +nla_nest_end (msg, attr); +return ret; +}drivers/dpll/dpll_netlink.c line 316
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ +static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 7 lines
Quoted 3 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.Yes, confusing a bit, I agree we need a fix of this.
Isn't it that dpll has an INDEX assigned by dpll subsystem on its allocation and pin have ID given by the driver?
Driver should provice the device_index and pin_index in appropriate _get() functions. I think it is better to spell out "index". "idx" looks a bit odd. Either way, please unify the name all along the code, netlink included.
ID is your odd dual-handle construct, which I don't see a need for and only adds confusions. Better to remove it.
Quoted 89 lines
[...]
Quoted 60 lines
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 563
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+static int +dpll_pin_set_from_nlattr (struct dpll_device *dpll, +struct dpll_pin *pin,struct genl_info *info) +{ +enum dpll_pin_state state =DPLL_PIN_STATE_UNSPEC ; +u32 parent_idx =PIN_IDX_INVALID ;You just need this
PIN_IDX_INVALIDdefine internally in this function, change the flow to avoid a need for it.I'll re-think it, thanks.
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 568
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +5
-0+int rem, ret = -EINVAL ; +struct nlattr *a; + +nla_for_each_attr (a,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
I had some unknown crashes when I was using such access. I might have lost some
checks, will try it again.Quoted 32 lines
Quoted 18 lines
drivers/dpll/dpll_netlink.c new file +17
-0+switch (nla_type (a)) { +case DPLL_A_PIN_FREQUENCY : + ret =dpll_pin_freq_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_DIRECTION : + ret =dpll_pin_direction_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PRIO : + ret =dpll_pin_prio_set (dpll, pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PARENT_IDX :drivers/dpll/dpll_netlink.c line 595
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ parent_idx =nla_get_u32 (a); +break ; +case DPLL_A_PIN_STATE : + state =nla_get_u8 (a); +break ; +default : +break ; + } + } +if (state !=DPLL_PIN_STATE_UNSPEC ) {Again, change the flow to:
if (attrs[DPLL_A_PIN_STATE]) {Quoted 4 lines
Quoted 2 lines
and avoid need for this value set/check.
Yep, will try.
Yes, this shall work now, as long as there are no multiple nested attributes coming from userspace.
[...]
Quoted 16 lines
Quoted 15 lines
drivers/dpll/dpll_netlink.c line 878
Quoted 11 lines
+void dpll_pin_post_doit(const struct
genl_split_ops*ops, structsk_buff*skb,drivers/dpll/dpll_netlink.c new file +9
-0+ struct genl_info *info) +{ +mutex_unlock (&dpll_pin_xa_lock); +dpll_post_doit (ops, skb, info); +} + +int dpll_pin_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Quoted 7 lines
Quoted 4 lines
Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?Not really, this is why it is there :(
A single global lock for whole dpll subsystem?
Either that or per-instance/device lock.
Quoted 48 lines
Quoted 39 lines
Quoted 37 lines
Quoted 16 lines
drivers/dpll/dpll_netlink.c new file +14
-0+ +return dpll_pre_dumpit (cb); +} + +int dpll_pin_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_pin_xa_lock); + +return dpll_post_dumpit (cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/dpll_netlink.c line 902
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
Quoted 8 lines
But with full object-snapshot user space app will lose the information about
what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
Quoted 2 lines
I agree that from functional perspective it is better to have on userspace a reason of the notification.
I would like to understand why exactly is it better.
But anyway, I was thinking about it a bit more and it might make sense only the added/changed/deleted attribute to safe some msg space and getting/parsing cycles. However, it is questionable how much does it actually save. But you apparently strongly want it, so lets have it
But, the format of the message should be exactly the same as for GET. Meaning, if some nested attr changes/is added/is removed, the msg should contain the proper nest same as for the same attr in GET msg. Think of it as if you assemble the whole GET msg for an object and filter out things that did not change.
Also need to emphasize strict objects separation, same as for GET.
Also, you have to distinguish between attr being added/removed or the whole object being added/removed. The userspace has to understand difference.
So you would have events like:DEVICE_ADDEDDEVICE_REMOVEDDEVICE_ATTRS_ADDEDDEVICE_ATTRS_CHANGEDDEVICE_ATTRS_REMOVEDPIN_ADDEDPIN_REMOVEDPIN_ATTRS_ADDEDPIN_ATTRS_CHANGEDPIN_ATTRS_REMOVED
This scenario I can imagine working in a sane way.
Makes sense?
Btw, with the whole object snapshot scenario you just have:DEVICE_NEW (sent for creation and change)DEVICE_DELPIN_NEW (sent for creation and change)PIN_DEL
And you are fine with it. This is how it's usually done in Netlink. In fact, do you have examples in kernel code of what you are suggesting?
Quoted 6 lines
[...]
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 36 lines
drivers/dpll/dpll_core.c new file +36
-0+struct dpll_pin * +dpll_pin_alloc (u64 clock_id,u8 device_drv_id,struct module *module, +const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id; + pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + } + pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max; +xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret = xa_alloc(&dpll_pin_xa, &pin->idx, pin,
drivers/dpll/dpll_core.c line 483
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ xa_limit_16b, GFP_KERNEL); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + }
This is odd flow. Just return 0 before "release" and have the goto-label dedicated to error path only.
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+ +return pin; +}
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 9 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F: Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-driveF:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support.
Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))
drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))
This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
You can have a macro to help driver to assemble array of supported frequencies and ranges.
Quoted 15 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +
[...]
Quoted 14 lines
drivers/dpll/dpll_core.c new file +14
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ;
drivers/dpll/dpll_core.c
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)
How exactly this can happen? Looks to me like only in case of a bug. WARN_ON() perhaps (put directly into dpll_xa_ref_dpll_find()?
drivers/dpll/dpll_core.c
Quoted 11 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)
Use && and single if
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +
[...]
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref;
drivers/dpll/dpll_core.c
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq)) +return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;
return what the op returns: ret
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +
[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))
ret = ..
if (ret)
return ret;
Please use this pattern in other ops call code as well.
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;
[...]
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 4:45 PM[...]
MAINTAINERS F:
Quoted 5 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F:
Documentation/networking/device_drivers/ethernet/freescale/dpaa2/swit
ch-driveQuoted 4 lines
F:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
Quoted 3 lines
You can have a macro to help driver to assemble array of supported frequencies and ranges.
I understand suggestion on yaml, but here I am confused.
How do they relate to the supported frequency passed between driver and dpll subsystem?
This bitfield is not visible to the userspace, and sure probably adding macro can be useful.
Quoted 39 lines
Quoted 16 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +[...]
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret;
Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)How exactly this can happen? Looks to me like only in case of a bug.
WARN_ON()perhaps (put directly intodpll_xa_ref_dpll_find()?
Yes, makes sense.
Quoted 16 lines
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)Use && and single if
Make sense to me.
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +[...]
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref; +unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq))
Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;return what the op returns: ret
Why would we return here a driver return code, userspace can have this info from extack. IMHO return values of dpll subsystem shall be not dependent on what is returned from the driver.
Quoted 28 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))ret = ..
if (ret)
Quoted 4 lines
return ret;Please use this pattern in other ops call code as well.
This is the same as above (return code by driver) explanation.
Quoted 8 lines
Quoted 6 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;[...]
Thanks,
Arkadiusz
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 75 lines · Tue, Mar 14, 2023 at 07:35:55PM CET, [email protected] wrote:
Quoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 4:45 PM[...]
MAINTAINERS F:
Quoted 5 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F:
Documentation/networking/device_drivers/ethernet/freescale/dpaa2/swit
ch-driveQuoted 4 lines
F:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
Quoted 3 lines
You can have a macro to help driver to assemble array of supported frequencies and ranges.
Quoted 5 lines
I understand suggestion on yaml, but here I am confused.
How do they relate to the supported frequency passed between driver and dpll subsystem?
This bitfield is not visible to the userspace, and sure probably adding macro can be useful.
My point is to avoid the bitfield and to treat supported frequencies and ranges in the same way. It can look similar to this:
in dpll.h:
struct struct dpll_pin_frequency {
u64 min;
u64 max;
};#define DPLL_PIN_FREQUENCY_RANGE(_min, _mac) \
{ \
.min = _min, \
.max = _max, \
}#define DPLL_PIN_FREQUENCY(_val) DPLL_PIN_FREQUENCY_RANGE(_val, _val) #define DPLL_PIN_FREQUENCY_1PPS DPLL_PIN_FREQUENCY(1) #define DPLL_PIN_FREQUENCY_10MHZ DPLL_PIN_FREQUENCY(1000000)
Then in driver you have:
static const struct dpll_pin_frequency pcp_dpll_pin_freqs[] = {
DPLL_PIN_FREQUENCY_1PPS,
DPLL_PIN_FREQUENCY_10MHZ,
DPLL_PIN_FREQUENCY(4000000),
DPLL_PIN_FREQUENCY_RANGE(500, 1000),
DPLL_PIN_FREQUENCY_RANGE(9000, 10000),
};static const struct dpll_pin_properties pcp_dpll_pin_props = {
.label = "SMA",
.frequencies_supported = pcp_dpll_pin_freqs, .frequencies_supported_count = ARRAY_SIZE(pcp_dpll_pin_freqs), .type = DPLL_PIN_TYPE_EXT,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
};
Then the dpll core could very easily iterate over .frequencies_supported array and dump the supported values and ranges to user in uniform way.
Quoted 101 lines
Quoted 40 lines
Quoted 17 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +[...]
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret;Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)How exactly this can happen? Looks to me like only in case of a bug.
WARN_ON()perhaps (put directly intodpll_xa_ref_dpll_find()?Yes, makes sense.
Quoted 16 lines
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)Use && and single if
Make sense to me.
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +[...]
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref; +unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq))Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;return what the op returns: ret
Quoted 3 lines
Why would we return here a driver return code, userspace can have this info from extack. IMHO return values of dpll subsystem shall be not dependent on what is returned from the driver.
Why not to return it? The driver had some problem, errno suggests what that was. It is completely desired to pass that along and actually, it's been done like this in the rest of the netlink ops I can think of. Why would you want to hide it? Extack carries string message, not related to this directly.
Quoted 31 lines
Quoted 31 lines
Quoted 9 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))ret = ..
if (ret)return ret;
Quoted 4 lines
Quoted 2 lines
Please use this pattern in other ops call code as well.
This is the same as above (return code by driver) explanation.
Same reply as above.
Quoted 12 lines
Quoted 9 lines
Quoted 7 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;[...]
Thanks,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 2 lines
include/linux/dpll.h new file +2
-0+struct dpll_device +*dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module);
[...]
include/linux/dpll.h line 184
Quoted 3 lines
include/linux/dpll.h new file +3
-0+struct dpll_pin +*dpll_pin_get (u64 clock_id,u32 dev_driver_id,struct module *module, +const struct dpll_pin_properties *pin_prop);
Small tweak, please use the same trick as shown for example here:
/* pci_register_driver() must be a macro so KBUILD_MODNAME can be expanded */
#define pci_register_driver(driver) \
__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
The driver calls header helper which fills up the "THIS_MODULE" for it.
Thanks!
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
drivers/dpll/dpll_core.c line 630
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+/** +* dpll_pin_unregister - deregister dpll pin from dpll device +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin)
Make this return void. Function does not report anything useful, non-0 is only in case of WARN_ON. Nobody is going to check that ever anyway.
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+{ +if (WARN_ON (xa_empty (&dpll->pin_refs))) +return -ENOENT ; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +__dpll_pin_unregister (dpll, pin); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_pin_unregister);
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+struct dpll_pin * +dpll_pin_alloc (u64 clock_id,u8 device_drv_id,struct module *module, +const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin;
drivers/dpll/dpll_core.c line 452
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id; + pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) {
Why is this mandatory? I'm now working on mlx5 implementation, don't really know what to put here for SyncE. The type of the pin SyncE tells all I need. I would like to avoid description fill-up.
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + }
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
include/linux/dpll.h line 60
Quoted 8 lines
include/linux/dpll.h new file +8
-0+int (*state_on_pin_get)(const struct dpll_pin *pin, +const struct dpll_pin *parent_pin, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack); +int (*state_on_dpll_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack);
Could this be rather called "state_on_device_get" or perhaps even better just "state_get" (in sync with "prio_set/get") ?
This "od dpll" is a bit confusing, there is no such object. We have "device" and "pin".
Quoted 8 lines
include/linux/dpll.h new file +8
-0+int (*state_on_pin_set)(const struct dpll_pin *pin, +const struct dpll_pin *parent_pin, +const enum dpll_pin_state state, +struct netlink_ext_ack *extack); +int (*state_on_dpll_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const enum dpll_pin_state state, +struct netlink_ext_ack *extack);
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, + struct dpll_device_ops *ops, void *priv,
ops should be const
Quoted 1 line
drivers/dpll/dpll_core.c new file +1
-0+ struct device *owner)
[...]
drivers/dpll/dpll_core.c line 552
Quoted 4 lines
drivers/dpll/dpll_core.c new file +4
-0+ +static int +__dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv,
ops should be const
Quoted 2 lines
(quoted diff) +2
-0+ const char *rclk_device_name) +{
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 9 lines
drivers/dpll/dpll_netlink.c new file +9
-0+int dpll_nl_device_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb) +{ +struct nlattr *hdr, *nest; +struct dpll_device *dpll; +unsigned long i; +int ret; + + hdr =genlmsg_put (skb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq, + &dpll_nl_family,0 ,DPLL_CMD_DEVICE_GET );
drivers/dpll/dpll_netlink.c line 765
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+if (!hdr) +return -EMSGSIZE ; + +xa_for_each_marked (&dpll_device_xa, i, dpll,DPLL_REGISTERED ) { + nest =nla_nest_start (skb,DPLL_A_DEVICE ); + ret =dpll_msg_add_dev_handle (skb, dpll); +if (ret) { +nla_nest_cancel (skb, nest); +break ; + }
Please fillup the attrs for the object. The format should be exactly the same as for doit.
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+nla_nest_end (skb, nest); + } +if (ret) +genlmsg_cancel (skb, hdr); +else +genlmsg_end (skb, hdr); + +return ret; +} +
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
drivers/dpll/dpll_netlink.c line 241
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;
Pointless init.
[...]
drivers/dpll/dpll_netlink.c line 896
Quoted 7 lines
drivers/dpll/dpll_netlink.c new file +7
-0+static int +dpll_event_device_change (struct sk_buff *msg,struct dpll_device *dpll, +struct dpll_pin *pin,struct dpll_pin *parent, +enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ;
Pointless init.
[...]
Quoted 6 lines
include/linux/dpll.h new file +6
-0+struct dpll_pin_ops { +int (*frequency_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const u32 frequency, +struct netlink_ext_ack *extack); + int (*frequency_get)(const struct dpll_pin *pin,
include/linux/dpll.h line 52
Quoted 10 lines
include/linux/dpll.h new file +10
-0+const struct dpll_device *dpll, + u32 *frequency, struct netlink_ext_ack *extack); +int (*direction_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const enum dpll_pin_direction direction, +struct netlink_ext_ack *extack); +int (*direction_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack);
For frequency and direction, why exactly do you need to pass dpll pointer? For set I can understand you need it to set the same frequency/direction for all dplls the pin is connected to, but why for get()?
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 13 lines
drivers/dpll/dpll_netlink.c new file +13
-0+static int +dpll_event_device_change (struct sk_buff *msg,struct dpll_device *dpll, +struct dpll_pin *pin,struct dpll_pin *parent, +enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;
drivers/dpll/dpll_netlink.c line 912
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ +switch (attr) { +case DPLL_A_MODE : + ret =dpll_msg_add_mode (msg, dpll,NULL ); +break ; +case DPLL_A_SOURCE_PIN_IDX : + ret =dpll_msg_add_source_pin_idx (msg, dpll,NULL ); +break ; +case DPLL_A_LOCK_STATUS : + ret =dpll_msg_add_lock_status (msg, dpll,NULL );
On top of what I wrote about the notifications, I found another two issues:
1) You don't take any lock calling this from drivers. You need to hold the xarray locks you have now.
I have to repear, I think that we definitelly need to convert the overall locking scheme to have this per-instance, in a similar way we did that for devlink. I noted this in another email, but wanted to say that again.
2) You have possible race condition:
1) -> driver gets a state change event
2) -> driver calls into this function
3) -> this code does call the driver op to get the state, driver queries the state again
Between 1) and 3) state can easily change, multiple times. That might lead to oddities observed by the user (like getting a notification of change with the original values)
I see only 1 solutions to this:
Pass the value of changed item from the driver here and just pass it on over netlink without doing calling into driver again.
Quoted 104 lines
drivers/dpll/dpll_netlink.c new file +104
-0+break ; +case DPLL_A_TEMP : + ret =dpll_msg_add_temp (msg, dpll,NULL ); +break ; +case DPLL_A_PIN_FREQUENCY : + ret =dpll_msg_add_pin_freq (msg, pin,NULL , false); +break ; +case DPLL_A_PIN_PRIO : + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref,NULL ); +break ; +case DPLL_A_PIN_STATE : +if (parent) { + ref =dpll_xa_ref_pin_find (&pin->parent_refs, parent); +if (!ref) +return -EFAULT ; +if (!ref->ops || !ref->ops->state_on_pin_get) +return -EOPNOTSUPP ; + ret = ref->ops->state_on_pin_get (pin, parent, &state, +NULL ); +if (ret) +return ret; +if (nla_put_u32 (msg,DPLL_A_PIN_PARENT_IDX , + parent->dev_driver_id)) +return -EMSGSIZE ; + }else { + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, +NULL ); +if (ret) +return ret; + } +break ; +default : +break ; + } + +return ret; +} + +static int +dpll_send_event_create (enum dpll_event event,struct dpll_device *dpll) +{ +struct sk_buff *msg; +int ret = -EMSGSIZE ; +void *hdr; + + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg,0 ,0 , &dpll_nl_family,0 , event); +if (!hdr) + goto out_free_msg; + + ret =dpll_msg_add_dev_handle (msg, dpll); +if (ret) + goto out_cancel_msg; +genlmsg_end (msg, hdr); +genlmsg_multicast (&dpll_nl_family, msg,0 ,0 ,GFP_KERNEL ); + +return 0 ; + +out_cancel_msg: +genlmsg_cancel (msg, hdr); +out_free_msg: +nlmsg_free (msg); + +return ret; +} + +static int +dpll_send_event_change (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin *parent,enum dplla attr) +{ +struct sk_buff *msg; +int ret = -EMSGSIZE ; +void *hdr; + + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg,0 ,0 , &dpll_nl_family,0 , +DPLL_EVENT_DEVICE_CHANGE ); +if (!hdr) + goto out_free_msg; + + ret =dpll_event_device_change (msg, dpll, pin, parent, attr); +if (ret) + goto out_cancel_msg; +genlmsg_end (msg, hdr); +genlmsg_multicast (&dpll_nl_family, msg,0 ,0 ,GFP_KERNEL ); + +return 0 ; + +out_cancel_msg: +genlmsg_cancel (msg, hdr); +out_free_msg: +nlmsg_free (msg);
drivers/dpll/dpll_netlink.c line 1026
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ +return ret; +} + +int dpll_notify_device_create (struct dpll_device *dpll) +{ +return dpll_send_event_create (DPLL_EVENT_DEVICE_CREATE , dpll); +} + +int dpll_notify_device_delete (struct dpll_device *dpll)
Please change the function names to "register/unregister" to be consistent with the rest of the code.
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+{ +return dpll_send_event_create (DPLL_EVENT_DEVICE_DELETE , dpll); +} + +int dpll_device_notify (struct dpll_device *dpll,enum dplla attr)
drivers/dpll/dpll_netlink.c line 1041
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+{ +if (WARN_ON (!dpll)) +return -EINVAL ; + +return dpll_send_event_change (dpll,NULL ,NULL , attr); +} +EXPORT_SYMBOL_GPL (dpll_device_notify); + +int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, +enum dplla attr)
The driver should be aware of netlink attributes. Should be abstracted out.
just have per-item notification like:dpll_pin_state_notify()dpll_pin_prio_notify()
...
Then you can easily pass changed value that would allow solution to the issue 2) I described above.
Quoted 4 lines
drivers/dpll/dpll_netlink.c new file +4
-0+{ +return dpll_send_event_change (dpll, pin,NULL , attr); +} +
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 8 lines
+/**
+ *dpll_xa_ref_pin_del- remove reference of a pin from xarray
+ * @xa_pins:dpll_pin_refxarray holding pins
+ * @pin: pointer to a pin
+ *
+ * Decrement refcount of existing pin reference on given xarray.
+ * If all references are dropped, delete the reference and free its memory.
+ *
Hmm, came to think about this, why do you do func docs even for static function? It is customary to do that for exported function. For static ones, not really needed.
Quoted 5 lines
+ * Return:
+ * * 0 on success
+ * *-EINVALif reference to a pin was not found
+ */
+static intdpll_xa_ref_pin_del(struct xarray *xa_pins, struct dpll_pin *pin)
Have this to return void, you don't check the return value anywhere.
Quoted 16 lines
drivers/dpll/dpll_core.c new file +16
-0+{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_pins, i, ref) { +if (ref->pin == pin) { +if (refcount_dec_and_test (&ref->refcount)) { +xa_erase (xa_pins, i); +kfree (ref); + } +return 0 ; + } + } + +return -EINVAL ; +}
[...]
drivers/dpll/dpll_core.c line 257
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+/** +* dpll_xa_ref_dpll_find - find dpll reference on xarray +* @xa_dplls: dpll_pin_ref xarray holding dplls +* @dpll: pointer to a dpll +* +* Search for dpll-pin ops reference struct of a given dpll on given xarray. +* +* Return: +* * pin reference struct pointer on success +* * NULL - reference to a pin was not found +*/ +struct dpll_pin_ref * +dpll_xa_ref_dpll_find (struct xarray *xa_refs,const struct dpll_device *dpll)
Every caller of this function does fill the first arg by:&pin->dpll_refs
Could you please change it to "struct dpll_pin *pin" and get the xarray pointer in this function?
The same applies to other functions passing xarray pointer, like:dpll_xa_ref_dpll_adddpll_xa_ref_dpll_deldpll_xa_ref_pin_find
The point is, always better and easier to read to pass "struct dpll_device *" and "struct dpll_pin *" as function args. Passing "struct xarray *" makes the reader uncertain about what is going on.
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_refs, i, ref) { +if (ref->dpll == dpll) +return ref; + } + +return NULL ; +} + +
[...]
Quoted 5 lines
+/**
+ *dpll_device_register- register the dpll device in the subsystem
+ * @dpll: pointer to a dpll
+ * @type: type of a dpll
+ * @ops: ops for a dpll device
Quoted 8 lines
+ * @priv: pointer to private information of owner
+ * @owner: pointer to owner device
+ *
+ * Make dpll device available for user space.
+ *
+ * Return:
+ * * 0 on success
+ * *-EINVALon failure
You return more than that. Do you really need to list the error possiblities in the func docs?
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +3
-0+int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner)
[...]
drivers/dpll/dpll_core.c line 561
Quoted 12 lines
drivers/dpll/dpll_core.c new file +12
-0+static int +__dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +const char *rclk_device_name) +{ +int ret; + +if (rclk_device_name && !pin->rclk_dev_name) { + pin->rclk_dev_name =kstrdup (rclk_device_name,GFP_KERNEL ); +if (!pin->rclk_dev_name) +return -ENOMEM ; + }
Somewhere here, please add a check:dpll->module == pin->module dpll->clock_id && pin->clock_id For sanity sake.
drivers/dpll/dpll_core.c line 569
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ ret =dpll_xa_ref_pin_add (&dpll->pin_refs, pin, ops, priv); +if (ret) + goto rclk_free; + ret =dpll_xa_ref_dpll_add (&pin->dpll_refs, dpll, ops, priv); +if (ret) + goto ref_pin_del; +else +dpll_pin_notify (dpll, pin,DPLL_A_PIN_IDX );
Pointless else.
Quoted 9 lines
drivers/dpll/dpll_core.c new file +9
-0+ +return ret; + +ref_pin_del: +dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +rclk_free: +kfree (pin->rclk_dev_name); +return ret; +}
[...]
Quoted 11 lines
drivers/dpll/dpll_core.c new file +11
-0+int +dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device) +{ +struct dpll_pin_ref *ref; +unsigned long i, stop; +int ret; + +if (WARN_ON (!pin || !parent)) +return -EINVAL ;
drivers/dpll/dpll_core.c line 682
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (WARN_ON (parent->prop.type !=DPLL_PIN_TYPE_MUX )) +return -EPERM ; +mutex_lock (&dpll_pin_xa_lock); + ret =dpll_xa_ref_pin_add (&pin->parent_refs, parent, ops, priv); +if (ret) + goto unlock; +refcount_inc (&pin->refcount); +xa_for_each (&parent->dpll_refs, i, ref) { +mutex_lock (&dpll_device_xa_lock); + ret = __dpll_pin_register(ref->dpll, pin, ops, priv,
Why exactly do you need to register the pin over to the dpll of a parent? Isn't it enough to have the pin registered on a parent? I mean, there is no direct connection between pin and dpll, the parent is in the middle. So prio setup, and other things does not make sense to configure on this child pin, isn't it?
Btw, what is stopping the driver from:
dpll register
pin1 register on dpll
pin2 register on pin1
pin1 unregister
?
The you would have pin2 registered to dpll incorrectly.
Quoted 27 lines
drivers/dpll/dpll_core.c new file +27
-0+ rclk_device ? + dev_name(rclk_device) : NULL); +mutex_unlock (&dpll_device_xa_lock); +if (ret) { + stop = i; + goto dpll_unregister; + } +dpll_pin_parent_notify (ref->dpll, pin, parent,DPLL_A_PIN_IDX ); + } +mutex_unlock (&dpll_pin_xa_lock); + +return ret; + +dpll_unregister: +xa_for_each (&parent->dpll_refs, i, ref) { +if (i < stop) { +mutex_lock (&dpll_device_xa_lock); +__dpll_pin_unregister (ref->dpll, pin); +mutex_unlock (&dpll_device_xa_lock); + } + } +refcount_dec (&pin->refcount); +dpll_xa_ref_pin_del (&pin->parent_refs, parent); +unlock: +mutex_unlock (&dpll_pin_xa_lock); +return ret; +}
[...]
drivers/dpll/dpll_netlink.c line 479
Quoted 9 lines
drivers/dpll/dpll_netlink.c new file +9
-0+static int +dpll_pin_on_pin_state_set (struct dpll_device *dpll,struct dpll_pin *pin, +u32 parent_idx,enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct dpll_pin *parent; + +if (!(DPLL_PIN_CAPS_STATE_CAN_CHANGE & pin->prop.capabilities))
Hmm, why is this capabilities are any good for internal purposes? I understand the need to expose it to the user, but internally in kernel, if the driver implements some _set() op, it is good enough indication of a support of a certain setter. You can check if the relevant _set() is not null and expose the appropriate capability to the user.
drivers/dpll/dpll_netlink.c line 481
Quoted 2 lines
drivers/dpll/dpll_netlink.c new file +2
-0+return -EOPNOTSUPP ; + parent =dpll_pin_get_by_idx (dpll, parent_idx);
I don't follow. Why do you need dpll pointer to get the parent pin? The same handle as pin should be used, you have clock_id and driver name (in next patchsets implementation) that should be enough. Pin is a separate entity, attached 0:N dplls.
Please remove dpll pointer from here. Also, please remove dpll->pins_ref, as you are using this array only for this lookup (here and in dpll_pin_pre_doit())
Quoted 34 lines
drivers/dpll/dpll_netlink.c new file +34
-0+if (!parent) +return -EINVAL ; + ref =dpll_xa_ref_pin_find (&pin->parent_refs, parent); +if (!ref) +return -EINVAL ; +if (!ref->ops || !ref->ops->state_on_pin_set) +return -EOPNOTSUPP ; +if (ref->ops->state_on_pin_set (pin, parent, state, extack)) +return -EFAULT ; +dpll_pin_parent_notify (dpll, pin, parent,DPLL_A_PIN_STATE ); + +return 0 ; +} + +static int +dpll_pin_state_set (struct dpll_device *dpll,struct dpll_pin *pin, +enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; + +if (!(DPLL_PIN_CAPS_STATE_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; +if (!ref->ops || !ref->ops->state_on_dpll_set) +return -EOPNOTSUPP ; +if (ref->ops->state_on_dpll_set (pin, ref->dpll, state, extack)) +return -EINVAL ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_STATE ); + +return 0 ; +}
[...]
Quoted 4 lines
drivers/dpll/dpll_netlink.c new file +4
-0+static int +dpll_set_from_nlattr (struct dpll_device *dpll,struct genl_info *info) +{ +struct nlattr *attr;
drivers/dpll/dpll_netlink.c line 699
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+enum dpll_mode mode; +int rem, ret =0 ; + +nla_for_each_attr (attr,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) { +switch (nla_type (attr)) { +case DPLL_A_MODE : + mode =nla_get_u8 (attr); + +if (!dpll->ops || !dpll->ops->mode_set)
Remove the pointless check of ops. This cannot happen (checked in dpll_device_register())
Quoted 13 lines
drivers/dpll/dpll_netlink.c new file +13
-0+return -EOPNOTSUPP ; + ret = dpll->ops->mode_set (dpll, mode, info->extack); +if (ret) +return ret; +break ; +default : +break ; + } + } + +return ret; +} +
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 25 lines
drivers/dpll/dpll_netlink.c new file +25
-0+static int +dpll_msg_add_pin_direction (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction; +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->direction_get) +return -EOPNOTSUPP ; +if (ref->ops->direction_get (pin, ref->dpll, &direction, extack)) +return -EFAULT ; +if (nla_put_u8 (msg,DPLL_A_PIN_DIRECTION , direction)) +return -EMSGSIZE ; + +return 0 ; +} + +static int
drivers/dpll/dpll_netlink.c line 165
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+dpll_msg_add_pin_freq(struct sk_buff *msg, const struct dpll_pin *pin, + struct netlink_ext_ack *extack, bool dump_any_freq) +{ + enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll)
Checking for "ref" is nonsense here, as xa_for_each fills it up for every iteration.
ref->dpll is always filled. Also pointless check.
Does it make sense to register with ops==NULL? I think we should forbid it and make this just xa_find(0) to get the first item in the xarray.
I'm doing this in my patch, as it is dependency on some other patch I do in this area.
Quoted 32 lines
drivers/dpll/dpll_netlink.c new file +32
-0+break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack)) +return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs])) +return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +
[...]
Quoted 8 lines
drivers/dpll/dpll_netlink.c new file +8
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; +
drivers/dpll/dpll_netlink.c line 325
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret)
Why -EOPNOTSUPP here is not ok, as for the others below?
drivers/dpll/dpll_netlink.c line 331
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)
How this can happen? I don't think it could.
Quoted 30 lines
drivers/dpll/dpll_netlink.c new file +30
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name) +if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} + +static int +__dpll_cmd_pin_dump_one (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_dpll) +{ +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ;
drivers/dpll/dpll_netlink.c line 371
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pins_on_pin (msg, pin, extack); +if (ret) +return ret; +if (!xa_empty (&pin->dpll_refs) && dump_dpll) {
How dpll refs could be empty? I don't think it is possible.
Overall, whole the code has very odd habit of checking for conditions that are obviously impossible to happen. Only confuses reader as he naturally expects that the check is there for a reason.
Quoted 12 lines
drivers/dpll/dpll_netlink.c new file +12
-0+ ret =dpll_msg_add_pin_dplls (msg, pin, extack); +if (ret) +return ret; + } +if (pin->rclk_dev_name) +if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +
RFC PATCH v6 3/6 dpll: documentation on DPLL subsystem interface
In reply to Vadim FedorenkoAdd documentation explaining common netlink interface to configure DPLL devices and monitoring events. Common way to implement DPLL device in a driver is also covered.
--- Documentation/networking/dpll.rst | 347 +++++++++++++++++++++++++++++ Documentation/networking/index.rst | 1 + 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/dpll.rst
Documentation/networking/dpll.rst new file +347 -0
@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +The Linux kernel DPLL subsystem +=============================== + + +The main purpose of DPLL subsystem is to provide general interface +to configure devices that use any kind of Digital PLL and could use +different sources of signal to synchronize to as well as different +types of outputs. +The main interface is NETLINK_GENERIC based protocol with an event +monitoring multicast group defined. + + +Dpll object +=========== +Single dpll device object means single Digital PLL circuit and bunch of +pins connected with it. +It provides its capablities and current status to the user in response +to the `do` request of netlink command ``DPLL_CMD_DEVICE_GET`` and list +of dplls registered in the subsystem with `dump` netlink request of same +command. +Requesting configuration of dpll device is done with `do` request of +netlink ``DPLL_CMD_DEVICE_SET`` command. + + +Pin object +========== +A pin is amorphic object which represents either input or output, it +could be internal component of the device, as well as externaly +connected. +The number of pins per dpll vary, but usually multiple pins shall be +provided for a single dpll device. +Pin's properities and capabilities are provided to the user in response +to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. +It is also possible to list all the pins that were registered either +with dpll or different pin with `dump` request of ``DPLL_CMD_PIN_GET`` +command. +Configuration of a pin can be changed by `do` request of netlink +``DPLL_CMD_PIN_SET`` command. + + +Shared pins +=========== +Pin can be shared by multiple dpll devices. Where configuration on one +pin can alter multiple dplls (i.e. PIN_FREQUENCY, PIN_DIRECTION), +or configure just one pin-dpll pair (i.e. PIN_PRIO, PIN_STATE). + + +MUX-type pins +============= +A pin can be MUX-type, which aggregates child pins and serves as pin +multiplexer. One or more pins are attached to MUX-type instead of being +directly connected to a dpll device. +Pins registered with a MUX-type provides user with additional nested +attribute ``DPLL_A_PIN_PARENT`` for each parrent they were registered +with. +Only one child pin can provide it's signal to the parent MUX-type pin at +a time, the selection is done with requesting change of child pin state +to ``DPLL_PIN_STATE_CONNECTED`` and providing a target MUX-type pin +index value in ``DPLL_A_PARENT_PIN_IDX`` + + +Pin priority +============ +Some devices might offer a capability of automatic pin selection mode. +Usually such automatic selection is offloaded to the hardware, +which means only pins directly connected to the dpll are capable of +automatic source pin selection. +In automatic selection mode, the user cannot manually select a source +pin for the device, instead the user shall provide all directly +connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would +pick a highest priority valid signal and connect with it. +Child pin of MUX-type are not capable of automatic source pin selection, +in order to configure a source of a MUX-type pin the user still needs +to request desired pin state. + + +Configuration commands group +============================ + +Configuration commands are used to get or dump information about +registered DPLL devices (and pins), as well as set configuration of +device or pins. As DPLL device could not be abstract and reflects real +hardware, there is no way to add new DPLL device via netlink from user +space and each device should be registered by it's driver. + +All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent +any spamming/D.o.S. from unauthorized userspace applications. + +List of command with possible attributes +======================================== + +All constants identifying command types use ``DPLL_CMD_`` prefix and +suffix according to command purpose. All attributes use ``DPLL_A_`` +prefix and suffix according to attribute purpose: + + ============================ ======================================= + ``DEVICE_GET`` command to get device info or dump list + of available devices + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``MODE`` attr selection mode + ``MODE_SUPPORTED`` attr available selection modes + ``SOURCE_PIN_IDX`` attr index of currently selected source + ``LOCK_STATUS`` attr internal frequency-lock status + ``TEMP`` attr device temperature information + ``CLOCK_ID`` attr Unique Clock Identifier (EUI-64), + as defined by the IEEE 1588 standard + ``TYPE`` attr type or purpose of dpll device + ``DEVICE_SET`` command to set dpll device configuration + ``ID`` attr internal dpll device index + ``NAME`` attr dpll device name (not required if + dpll device index was provided) + ``MODE`` attr selection mode to configure + ``PIN_GET`` command to get pin info or dump list of + available pins + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_PRIO`` attr priority of pin on the dpll device + ``PIN_STATE`` attr state of pin on the dpll device + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DESCRIPTION`` attr description provided by driver + ``PIN_TYPE`` attr type of a pin + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency in case + pin/dpll supports any frequency + ``PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency in case + pin/dpll supports any frequency + ``PIN_PARENT`` nest attr for each MUX-type parent, that + pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DPLL_CAPS`` attr bitmask of pin-dpll capabilities + + ``PIN_SET`` command to set pins configuration + ``ID`` attr internal dpll device index + ``BUS_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``DEV_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DIRECTION`` attr direction to be set + ``PIN_FREQUENCY`` attr frequency to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_STATE`` attr pin state to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_PARENT_IDX`` attr if provided state is to be set with + parent pin instead of with dpll device + +Netlink dump requests +===================== + +The ``DEVICE_GET`` and ``PIN_GET`` commands are capable of dump type +netlink requests. Possible response message attributes for netlink dump +requests: + + ============================== ======================================= + ``PIN_GET`` command to dump pins + ``PIN`` attr nested type contains single pin + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_IDX`` attr index of dumped pin (on dplls) + ``PIN_DESCRIPTION`` description of a pin provided by driver + ``PIN_TYPE`` attr value of pin type + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_PARENT`` nest attr for each MUX-type parent, + that pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + + ``DEVICE_GET`` command to dump dplls + ``DEVICE`` attr nested type contatin a single + dpll device + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + + +Dpll device level configuration pre-defined enums +================================================= + +For all below enum names used for configuration of dpll device use +the ``DPLL_`` prefix. + +Values for ``DPLL_A_LOCK_STATUS`` attribute: + + ============================= ====================================== + ``LOCK_STATUS_UNLOCKED`` DPLL is in freerun, not locked to any + source pin + ``LOCK_STATUS_CALIBRATING`` DPLL device calibrates to lock to the + source pin signal + ``LOCK_STATUS_LOCKED`` DPLL device is locked to the source + pin frequency + ``LOCK_STATUS_HOLDOVER`` DPLL device lost a lock, using its + frequency holdover capabilities + +Values for ``DPLL_A_MODE`` attribute: + + =================== ================================================ + ``MODE_FORCED`` source pin is force-selected by setting pin + state to ``DPLL_PIN_STATE_CONNECTED`` on a dpll + ``MODE_AUTOMATIC`` source pin is auto selected according to + configured pin priorities and source signal + validity + ``MODE_HOLDOVER`` force holdover mode of DPLL + ``MODE_FREERUN`` DPLL is driven by supplied system clock without + holdover capabilities + ``MODE_NCO`` similar to FREERUN, with possibility to + numerically control frequency offset + +Values for ``DPLL_A_TYPE`` attribute: + + ============= ================================================ + ``TYPE_PPS`` DPLL used to provide pulse-per-second output + ``TYPE_EEC`` DPLL used to drive ethernet equipment clock + + + +Pin level configuration pre-defined enums +========================================= + +For all below enum names used for configuration of pin use the +``DPLL_PIN`` prefix. + +Values for ``DPLL_A_PIN_STATE`` attribute: + + ======================= ======================================== + ``STATE_CONNECTED`` Pin connected to a dpll or parent pin + ``STATE_DISCONNECTED`` Pin disconnected from dpll or parent pin + +Values for ``DPLL_A_PIN_DIRECTION`` attribute: + + ======================= ============================== + ``DIRECTION_SOURCE`` Pin used as a source of signal + ``DIRECTION_OUTPUT`` Pin used to output signal + +Values for ``DPLL_A_PIN_TYPE`` attributes: + + ======================== ======================================== + ``TYPE_MUX`` MUX type pin, connected pins shall have + their own types + ``TYPE_EXT`` External pin + ``TYPE_SYNCE_ETH_PORT`` SyncE on Ethernet port + ``TYPE_INT_OSCILLATOR`` Internal Oscillator (i.e. Holdover with + Atomic Clock as a Source) + ``TYPE_GNSS`` GNSS 1PPS source + +Values for ``DPLL_A_PIN_DPLL_CAPS`` attributes: + + ============================= ================================ + ``CAPS_DIRECTION_CAN_CHANGE`` Bit present if direction can change + ``CAPS_PRIORITY_CAN_CHANGE`` Bit present if priority can change + ``CAPS_STATE_CAN_CHANGE`` Bit present if state can change + + +Notifications +============= + +DPLL device can provide notifications regarding status changes of the +device, i.e. lock status changes, source/output type changes or alarms. +This is the multicast group that is used to notify user-space apps via +netlink socket: ``DPLL_MCGRP_MONITOR`` + +Notifications messages (attrbiutes use ``DPLL_A`` prefix): + + ========================= ========================================== + ``EVENT_DEVICE_CREATE`` event value new DPLL device was created + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``EVENT_DEVICE_DELETE`` event value DPLL device was deleted + ``ID`` attr dpll device index + ``EVENT_DEVICE_CHANGE`` event value DPLL device attribute has + changed + ``ID`` attr modified dpll device ID + ``PIN_IDX`` attr the modified pin index + +Device change event shall consiste of the attribute and the value that +has changed. + + +Device driver implementation +============================ + +Device is allocated by ``dpll_device_get`` call. Second call with the +same arguments doesn't create new object but provides pointer to +previously created device for given arguments, it also increase refcount +of that object. +Device is deallocated by ``dpll_device_put`` call, which first decreases +the refcount, once refcount is cleared the object is destroyed. + +Device should implement set of operations and register device via +``dpll_device_register`` at which point it becomes available to the +users. Only one driver can register a dpll device within dpll subsytem. +Multiple driver instances can obtain reference to it with +``dpll_device_get``. + +The pins are allocated separately with ``dpll_pin_get``, it works +similarly to ``dpll_device_get``. Creates object and the for each call +with the same arguments the object refcount increases. + +Once DPLL device is created, allocated pin can be registered with it +with 2 different methods, always providing implemented pin callbacks, +and private data pointer for calling them: +``dpll_pin_register`` - simple registration with a dpll device. +``dpll_pin_on_pin_register`` - register pin with another MUX type pin. + +For different instances of a device driver requiring to find already +registered DPLL (i.e. to connect its pins to id) use ``dpll_device_get`` +to obtain proper dpll device pointer. + +The name od DPLL device is generated based on registerer provided device +struct pointer and dev_driver_id value. +Name is in format: ``%s_%u`` witch arguments: +``dev_name(struct device *)`` - syscall on parent device struct +``dev_driver_idx`` - registerer given id + +Notifications of adding or removing DPLL devices are created within +subsystem itself. +Notifications about registering/deregistering pins are also invoked by +the subsystem. +Notifications about dpll status changes shall be requested by device +driver with ``dpll_device_notify`` corresponding attribute as a reason. + +There is no strict requirement to implement all the operations for +each device, every operation handler is checked for existence and +ENOTSUPP is returned in case of absence of specific handler. +
Documentation/networking/index.rst +1 -0
@@ -17,6 +17,7 @@ Contents: dsa/index devlink/index caif/index + dpll ethtool-netlink ieee802154 j1939
Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 3/6] dpll: documentation on DPLL subsystem interface
Quoted 24 lines · Sun, Mar 12, 2023 at 03:28:04AM CET, [email protected] wrote:
Add documentation explaining common netlink interface to configure DPLL devices and monitoring events. Common way to implement DPLL device in a driver is also covered.
Signed-off-by Vadim Fedorenko <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>---
Documentation/networking/dpll.rst| 347 +++++++++++++++++++++++++++++Documentation/networking/index.rst| 1 +2 files changed, 348 insertions(+)create mode 100644
Documentation/networking/dpll.rstDocumentation/networking/dpll.rst new file +6
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +The Linux kernel DPLL subsystem +=============================== +
Documentation/networking/dpll.rst line 16
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ +The main purpose of DPLL subsystem is to provide general interface +to configure devices that use any kind of Digital PLL and could use +different sources of signal to synchronize to as well as different +types of outputs. +The main interface is NETLINK_GENERIC based protocol with an event +monitoring multicast group defined. + + +Dpll object
rather perhaps "Device object"?
Documentation/networking/dpll.rst line 20
Quoted 4 lines
Documentation/networking/dpll.rst new file +4
-0+=========== +Single dpll device object means single Digital PLL circuit and bunch of +pins connected with it. +It provides its capablities and current status to the user in response
Which capabilities you have in mind. There is CAPs for pins, but I see none for device.
Documentation/networking/dpll.rst line 30
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+to the `do` request of netlink command ``DPLL_CMD_DEVICE_GET`` and list +of dplls registered in the subsystem with `dump` netlink request of same +command. +Requesting configuration of dpll device is done with `do` request of +netlink ``DPLL_CMD_DEVICE_SET`` command. + + +Pin object +========== +A pin is amorphic object which represents either input or output, it
In the code and UAPI you use terms "source" and "output". Please align to that.
Documentation/networking/dpll.rst line 35
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+could be internal component of the device, as well as externaly +connected. +The number of pins per dpll vary, but usually multiple pins shall be +provided for a single dpll device. +Pin's properities and capabilities are provided to the user in response
s/properities/properties/
There is more provided, like "status" for example.
Documentation/networking/dpll.rst line 38
Quoted 3 lines
Documentation/networking/dpll.rst new file +3
-0+to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. +It is also possible to list all the pins that were registered either +with dpll or different pin with `dump` request of ``DPLL_CMD_PIN_GET``
I don't follow. Dump of DPLL_CMD_PIN_GET just dumps always all the pins in the system. Am I missing something?
Documentation/networking/dpll.rst line 48
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+command. +Configuration of a pin can be changed by `do` request of netlink +``DPLL_CMD_PIN_SET`` command. + + +Shared pins +=========== +Pin can be shared by multiple dpll devices. Where configuration on one +pin can alter multiple dplls (i.e. PIN_FREQUENCY, PIN_DIRECTION), +or configure just one pin-dpll pair (i.e. PIN_PRIO, PIN_STATE).
Perhaps this can be extended to something like this:
A single pin object can be registered to multiple dpll devices. Then there are two groups of configuration knobs:
1) Set on a pin - the configuration affects all dpll devices pin is registered to. (i.e. PIN_FREQUENCY, PIN_DIRECTION),
2) Set on a pin-dpll tuple - the configuration affects only selected dpll device. (i.e. PIN_PRIO, PIN_STATE).
Documentation/networking/dpll.rst line 55
Quoted 7 lines
Documentation/networking/dpll.rst new file +7
-0+ + +MUX-type pins +============= +A pin can be MUX-type, which aggregates child pins and serves as pin +multiplexer. One or more pins are attached to MUX-type instead of being +directly connected to a dpll device.
Perhaps you can say "registered" in stead of "connected" and "attached" so this is aligned with the function names?
Documentation/networking/dpll.rst line 56
Quoted 1 line
Documentation/networking/dpll.rst new file +1
-0+Pins registered with a MUX-type provides user with additional nested
s/provides/provide/
Documentation/networking/dpll.rst line 57
Quoted 1 line
Documentation/networking/dpll.rst new file +1
-0+attribute ``DPLL_A_PIN_PARENT`` for each parrent they were registered
s/parrent/parent/
I'm confused. Can one pin be registered to multiple parents? How is that supposed to be working?
Documentation/networking/dpll.rst line 67
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+with. +Only one child pin can provide it's signal to the parent MUX-type pin at +a time, the selection is done with requesting change of child pin state +to ``DPLL_PIN_STATE_CONNECTED`` and providing a target MUX-type pin +index value in ``DPLL_A_PARENT_PIN_IDX`` + + +Pin priority +============ +Some devices might offer a capability of automatic pin selection mode.
Tell the enum value.
Documentation/networking/dpll.rst line 75
Quoted 8 lines
Documentation/networking/dpll.rst new file +8
-0+Usually such automatic selection is offloaded to the hardware, +which means only pins directly connected to the dpll are capable of +automatic source pin selection. +In automatic selection mode, the user cannot manually select a source +pin for the device, instead the user shall provide all directly +connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would +pick a highest priority valid signal and connect with it. +Child pin of MUX-type are not capable of automatic source pin selection,
s/are not/is not/
Documentation/networking/dpll.rst line 77
Quoted 2 lines
Documentation/networking/dpll.rst new file +2
-0+in order to configure a source of a MUX-type pin the user still needs +to request desired pin state.
Perhaps emphasize that this is the state of the child?
Quoted 34 lines
Documentation/networking/dpll.rst new file +34
-0+ + +Configuration commands group +============================ + +Configuration commands are used to get or dump information about +registered DPLL devices (and pins), as well as set configuration of +device or pins. As DPLL device could not be abstract and reflects real +hardware, there is no way to add new DPLL device via netlink from user +space and each device should be registered by it's driver. + +All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent +any spamming/D.o.S. from unauthorized userspace applications. + +List of command with possible attributes +======================================== + +All constants identifying command types use ``DPLL_CMD_`` prefix and +suffix according to command purpose. All attributes use ``DPLL_A_`` +prefix and suffix according to attribute purpose: + + ============================ ======================================= + ``DEVICE_GET`` command to get device info or dump list + of available devices + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``MODE`` attr selection mode + ``MODE_SUPPORTED`` attr available selection modes + ``SOURCE_PIN_IDX`` attr index of currently selected source + ``LOCK_STATUS`` attr internal frequency-lock status + ``TEMP`` attr device temperature information + ``CLOCK_ID`` attr Unique Clock Identifier (EUI-64), + as defined by the IEEE 1588 standard
Documentation/networking/dpll.rst line 121
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``TYPE`` attr type or purpose of dpll device + ``DEVICE_SET`` command to set dpll device configuration + ``ID`` attr internal dpll device index + ``NAME`` attr dpll device name (not required if + dpll device index was provided) + ``MODE`` attr selection mode to configure + ``PIN_GET`` command to get pin info or dump list of + available pins + ``DEVICE`` nest attr for each dpll device pin is + connected with
Ah, now I understand what this is about. Didn't occur to me from the netlink UAPI :/
Quoted 26 lines
Documentation/networking/dpll.rst new file +26
-0+ ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_PRIO`` attr priority of pin on the dpll device + ``PIN_STATE`` attr state of pin on the dpll device + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DESCRIPTION`` attr description provided by driver + ``PIN_TYPE`` attr type of a pin + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency in case + pin/dpll supports any frequency + ``PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency in case + pin/dpll supports any frequency + ``PIN_PARENT`` nest attr for each MUX-type parent, that + pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DPLL_CAPS`` attr bitmask of pin-dpll capabilities + + ``PIN_SET`` command to set pins configuration + ``ID`` attr internal dpll device index
Documentation/networking/dpll.rst line 157
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``BUS_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``DEV_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DIRECTION`` attr direction to be set + ``PIN_FREQUENCY`` attr frequency to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_STATE`` attr pin state to be set + ``PIN_PRIO`` attr pin priority to be set
I think it would be good to emhasize which attribute is valid in which combination, meaning alone, dpll needs to be specified, parent pin needs to be specified
Documentation/networking/dpll.rst line 169
Quoted 12 lines
Documentation/networking/dpll.rst new file +12
-0+ ``PIN_PARENT_IDX`` attr if provided state is to be set with + parent pin instead of with dpll device + +Netlink dump requests +===================== + +The ``DEVICE_GET`` and ``PIN_GET`` commands are capable of dump type +netlink requests. Possible response message attributes for netlink dump +requests: + + ============================== ======================================= + ``PIN_GET`` command to dump pins
Maintain the order and start with DEVICE_GET
Quoted 16 lines
Documentation/networking/dpll.rst new file +16
-0+ ``PIN`` attr nested type contains single pin + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_IDX`` attr index of dumped pin (on dplls) + ``PIN_DESCRIPTION`` description of a pin provided by driver + ``PIN_TYPE`` attr value of pin type + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_PARENT`` nest attr for each MUX-type parent, + that pin is connected with
Documentation/networking/dpll.rst line 195
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + + ``DEVICE_GET`` command to dump dplls + ``DEVICE`` attr nested type contatin a single + dpll device + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name
Hmm, why you need to repeat this for dump? Just say the message format is the same as for DO and you are done with it.
Quoted 108 lines
Documentation/networking/dpll.rst new file +108
-0+ + +Dpll device level configuration pre-defined enums +================================================= + +For all below enum names used for configuration of dpll device use +the ``DPLL_`` prefix. + +Values for ``DPLL_A_LOCK_STATUS`` attribute: + + ============================= ====================================== + ``LOCK_STATUS_UNLOCKED`` DPLL is in freerun, not locked to any + source pin + ``LOCK_STATUS_CALIBRATING`` DPLL device calibrates to lock to the + source pin signal + ``LOCK_STATUS_LOCKED`` DPLL device is locked to the source + pin frequency + ``LOCK_STATUS_HOLDOVER`` DPLL device lost a lock, using its + frequency holdover capabilities + +Values for ``DPLL_A_MODE`` attribute: + + =================== ================================================ + ``MODE_FORCED`` source pin is force-selected by setting pin + state to ``DPLL_PIN_STATE_CONNECTED`` on a dpll + ``MODE_AUTOMATIC`` source pin is auto selected according to + configured pin priorities and source signal + validity + ``MODE_HOLDOVER`` force holdover mode of DPLL + ``MODE_FREERUN`` DPLL is driven by supplied system clock without + holdover capabilities + ``MODE_NCO`` similar to FREERUN, with possibility to + numerically control frequency offset + +Values for ``DPLL_A_TYPE`` attribute: + + ============= ================================================ + ``TYPE_PPS`` DPLL used to provide pulse-per-second output + ``TYPE_EEC`` DPLL used to drive ethernet equipment clock + + + +Pin level configuration pre-defined enums +========================================= + +For all below enum names used for configuration of pin use the +``DPLL_PIN`` prefix. + +Values for ``DPLL_A_PIN_STATE`` attribute: + + ======================= ======================================== + ``STATE_CONNECTED`` Pin connected to a dpll or parent pin + ``STATE_DISCONNECTED`` Pin disconnected from dpll or parent pin + +Values for ``DPLL_A_PIN_DIRECTION`` attribute: + + ======================= ============================== + ``DIRECTION_SOURCE`` Pin used as a source of signal + ``DIRECTION_OUTPUT`` Pin used to output signal + +Values for ``DPLL_A_PIN_TYPE`` attributes: + + ======================== ======================================== + ``TYPE_MUX`` MUX type pin, connected pins shall have + their own types + ``TYPE_EXT`` External pin + ``TYPE_SYNCE_ETH_PORT`` SyncE on Ethernet port + ``TYPE_INT_OSCILLATOR`` Internal Oscillator (i.e. Holdover with + Atomic Clock as a Source) + ``TYPE_GNSS`` GNSS 1PPS source + +Values for ``DPLL_A_PIN_DPLL_CAPS`` attributes: + + ============================= ================================ + ``CAPS_DIRECTION_CAN_CHANGE`` Bit present if direction can change + ``CAPS_PRIORITY_CAN_CHANGE`` Bit present if priority can change + ``CAPS_STATE_CAN_CHANGE`` Bit present if state can change + + +Notifications +============= + +DPLL device can provide notifications regarding status changes of the +device, i.e. lock status changes, source/output type changes or alarms. +This is the multicast group that is used to notify user-space apps via +netlink socket: ``DPLL_MCGRP_MONITOR`` + +Notifications messages (attrbiutes use ``DPLL_A`` prefix): + + ========================= ========================================== + ``EVENT_DEVICE_CREATE`` event value new DPLL device was created + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``EVENT_DEVICE_DELETE`` event value DPLL device was deleted + ``ID`` attr dpll device index + ``EVENT_DEVICE_CHANGE`` event value DPLL device attribute has + changed + ``ID`` attr modified dpll device ID + ``PIN_IDX`` attr the modified pin index + +Device change event shall consiste of the attribute and the value that +has changed. + + +Device driver implementation +============================ +
Documentation/networking/dpll.rst line 313
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+Device is allocated by ``dpll_device_get`` call. Second call with the +same arguments doesn't create new object but provides pointer to +previously created device for given arguments, it also increase refcount +of that object. +Device is deallocated by ``dpll_device_put`` call, which first decreases +the refcount, once refcount is cleared the object is destroyed. + +Device should implement set of operations and register device via +``dpll_device_register`` at which point it becomes available to the +users. Only one driver can register a dpll device within dpll subsytem.
"Driver instance". Btw, I need to change it for mlx5. I will try to implement it in coming days.
Documentation/networking/dpll.rst line 321
Quoted 8 lines
Documentation/networking/dpll.rst new file +8
-0+Multiple driver instances can obtain reference to it with +``dpll_device_get``. + +The pins are allocated separately with ``dpll_pin_get``, it works +similarly to ``dpll_device_get``. Creates object and the for each call +with the same arguments the object refcount increases. + +Once DPLL device is created, allocated pin can be registered with it
In this text, you use "dpll", "Dpll", "DPLL". Could you unify?
Documentation/networking/dpll.rst line 328
Quoted 7 lines
Documentation/networking/dpll.rst new file +7
-0+with 2 different methods, always providing implemented pin callbacks, +and private data pointer for calling them: +``dpll_pin_register`` - simple registration with a dpll device. +``dpll_pin_on_pin_register`` - register pin with another MUX type pin. + +For different instances of a device driver requiring to find already +registered DPLL (i.e. to connect its pins to id) use ``dpll_device_get``
s/to id/to it/
Documentation/networking/dpll.rst line 331
Quoted 3 lines
Documentation/networking/dpll.rst new file +3
-0+to obtain proper dpll device pointer. + +The name od DPLL device is generated based on registerer provided device
s/name od/name of/
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+struct pointer and dev_driver_id value. +Name is in format: ``%s_%u`` witch arguments: +``dev_name(struct device *)`` - syscall on parent device struct +``dev_driver_idx`` - registerer given id +
Documentation/networking/dpll.rst line 346
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+Notifications of adding or removing DPLL devices are created within +subsystem itself. +Notifications about registering/deregistering pins are also invoked by +the subsystem. +Notifications about dpll status changes shall be requested by device +driver with ``dpll_device_notify`` corresponding attribute as a reason. + +There is no strict requirement to implement all the operations for +each device, every operation handler is checked for existence and +ENOTSUPP is returned in case of absence of specific handler.
Not sure internal implementation details are necessary. Just say that driver is free to implement a set of ops it supports, leave the rest not implemented.
Quoted 16 lines
Documentation/networking/dpll.rst new file +1
-0+Documentation/networking/index.rst +1
-0@@ -17,6 +17,7 @@ Contents: dsa/index devlink/index caif/index + dpll ethtool-netlink ieee802154 j1939Signature · 1 line
2.34.1
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 3/6] dpll: documentation on DPLL subsystem interface
Quoted 33 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 5:15 PMQuoted 29 lines · Sun, Mar 12, 2023 at 03:28:04AM CET, [email protected] wrote:
Add documentation explaining common netlink interface to configure DPLL devices and monitoring events. Common way to implement DPLL device in a driver is also covered.
Signed-off-by Vadim Fedorenko <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>---
Documentation/networking/dpll.rst| 347 +++++++++++++++++++++++++++++Documentation/networking/index.rst| 1 +2 files changed, 348 insertions(+)create mode 100644
Documentation/networking/dpll.rstDocumentation/networking/dpll.rst new file +10
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +The Linux kernel DPLL subsystem +=============================== + + +The main purpose of DPLL subsystem is to provide general interface +to configure devices that use any kind of Digital PLL and could use +different sources of signal to synchronize to as well as different
Quoted 9 lines
Documentation/networking/dpll.rst line 16
Quoted 6 lines
Documentation/networking/dpll.rst new file +6
-0+types of outputs. +The main interface is NETLINK_GENERIC based protocol with an event +monitoring multicast group defined. + + +Dpll objectrather perhaps "Device object"?
Sure, fixed.
Quoted 9 lines
Documentation/networking/dpll.rst line 20
Quoted 5 lines
Documentation/networking/dpll.rst new file +4
-0+=========== +Single dpll device object means single Digital PLL circuit and bunch of +pins connected with it. +It provides its capablities and current status to the user in responseWhich capabilities you have in mind. There is CAPs for pins, but I see none for device.
Ok, changed "capabilities" to "supported working modes".
Quoted 15 lines
Documentation/networking/dpll.rst line 30
Quoted 11 lines
Documentation/networking/dpll.rst new file +10
-0+to the `do` request of netlink command ``DPLL_CMD_DEVICE_GET`` and list +of dplls registered in the subsystem with `dump` netlink request of same +command. +Requesting configuration of dpll device is done with `do` request of +netlink ``DPLL_CMD_DEVICE_SET`` command. + + +Pin object +========== +A pin is amorphic object which represents either input or output, itIn the code and UAPI you use terms "source" and "output". Please align to that.
Sure, fixed.
Quoted 9 lines
Documentation/networking/dpll.rst line 35
Quoted 6 lines
Documentation/networking/dpll.rst new file +5
-0+could be internal component of the device, as well as externaly +connected. +The number of pins per dpll vary, but usually multiple pins shall be +provided for a single dpll device. +Pin's properities and capabilities are provided to the user in responses/properities/properties/
Thanks, fixed.
Quoted 2 lines
There is more provided, like "status" for example.
Makes sense, fixed.
Quoted 8 lines
Documentation/networking/dpll.rst line 38
Quoted 4 lines
Documentation/networking/dpll.rst new file +3
-0+to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. +It is also possible to list all the pins that were registered either +with dpll or different pin with `dump` request of ``DPLL_CMD_PIN_GET``I don't follow. Dump of
DPLL_CMD_PIN_GETjust dumps always all the pins in the system. Am I missing something?
Yes you are right, rephrased to make it clearer.
Quoted 14 lines
Documentation/networking/dpll.rst line 48
Quoted 11 lines
Documentation/networking/dpll.rst new file +10
-0+command. +Configuration of a pin can be changed by `do` request of netlink +``DPLL_CMD_PIN_SET`` command. + + +Shared pins +=========== +Pin can be shared by multiple dpll devices. Where configuration on one +pin can alter multiple dplls (i.e. PIN_FREQUENCY, PIN_DIRECTION), +or configure just one pin-dpll pair (i.e. PIN_PRIO, PIN_STATE).Perhaps this can be extended to something like this:
Quoted 8 lines
A single pin object can be registered to multiple dpll devices. Then there are two groups of configuration knobs:
1) Set on a pin - the configuration affects all dpll devices pin is registered to. (i.e.PIN_FREQUENCY,PIN_DIRECTION),
2) Set on a pin-dpll tuple - the configuration affects only selected dpll device. (i.e.PIN_PRIO,PIN_STATE).
Makes sense, fixed.
Quoted 11 lines
Documentation/networking/dpll.rst line 55
Quoted 7 lines
Documentation/networking/dpll.rst new file +7
-0+ + +MUX-type pins +============= +A pin can be MUX-type, which aggregates child pins and serves as pin +multiplexer. One or more pins are attached to MUX-type instead of being +directly connected to a dpll device.Perhaps you can say "registered" in stead of "connected" and "attached" so this is aligned with the function names?
Makes sense, fixed.
Quoted 5 lines
Documentation/networking/dpll.rst line 56
Quoted 2 lines
Documentation/networking/dpll.rst new file +1
-0+Pins registered with a MUX-type provides user with additional nesteds/provides/provide/
Sure, fixed.
Quoted 8 lines
Documentation/networking/dpll.rst line 57
Quoted 2 lines
Documentation/networking/dpll.rst new file +1
-0+attribute ``DPLL_A_PIN_PARENT`` for each parrent they were registereds/parrent/parent/
I'm confused. Can one pin be registered to multiple parents? How is that supposed to be working?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-get --json '{"id": 0, "pin-idx":13}'
{'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},
{'bus-name': 'pci',
'dev-name': '0000:21:00.0_1',
'id': 1}],
'pin-description': '0000:21:00.0',
'pin-direction': {'doc': 'pin used as a source of a signal',
'name': 'source'},
'pin-idx': 13,
'pin-parent': [{'pin-parent-idx': 2,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}},
{'pin-parent-idx': 3,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}}],
'pin-rclk-device': '0000:21:00.0',
'pin-type': {'doc': "ethernet port PHY's recovered clock",
'name': 'synce-eth-port'}}]}I will add some more information and the example.
Quoted 14 lines
Documentation/networking/dpll.rst line 67
Quoted 11 lines
Documentation/networking/dpll.rst new file +10
-0+with. +Only one child pin can provide it's signal to the parent MUX-type pin at +a time, the selection is done with requesting change of child pin state +to ``DPLL_PIN_STATE_CONNECTED`` and providing a target MUX-type pin +index value in ``DPLL_A_PARENT_PIN_IDX`` + + +Pin priority +============ +Some devices might offer a capability of automatic pin selection mode.Tell the enum value.
Sure, fixed.
Quoted 12 lines
Documentation/networking/dpll.rst line 75
Quoted 9 lines
Documentation/networking/dpll.rst new file +8
-0+Usually such automatic selection is offloaded to the hardware, +which means only pins directly connected to the dpll are capable of +automatic source pin selection. +In automatic selection mode, the user cannot manually select a source +pin for the device, instead the user shall provide all directly +connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would +pick a highest priority valid signal and connect with it. +Child pin of MUX-type are not capable of automatic source pin selection,s/are not/is not/
Thanks, fixed.
Quoted 6 lines
Documentation/networking/dpll.rst line 77
Quoted 3 lines
Documentation/networking/dpll.rst new file +2
-0+in order to configure a source of a MUX-type pin the user still needs +to request desired pin state.Perhaps emphasize that this is the state of the child?
Makes sense, fixed.
Quoted 40 lines
Quoted 40 lines
Documentation/networking/dpll.rst new file +39
-0+ + +Configuration commands group +============================ + +Configuration commands are used to get or dump information about +registered DPLL devices (and pins), as well as set configuration of +device or pins. As DPLL device could not be abstract and reflects real +hardware, there is no way to add new DPLL device via netlink from user +space and each device should be registered by it's driver. + +All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent +any spamming/D.o.S. from unauthorized userspace applications. + +List of command with possible attributes +======================================== + +All constants identifying command types use ``DPLL_CMD_`` prefix and +suffix according to command purpose. All attributes use ``DPLL_A_`` +prefix and suffix according to attribute purpose: + + ============================ ======================================= + ``DEVICE_GET`` command to get device info or dump list + of available devices + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``MODE`` attr selection mode + ``MODE_SUPPORTED`` attr available selection modes + ``SOURCE_PIN_IDX`` attr index of currently selected source + ``LOCK_STATUS`` attr internal frequency-lock status + ``TEMP`` attr device temperature information + ``CLOCK_ID`` attr Unique Clock Identifier (EUI-64), + as defined by the IEEE 1588 standard + ``TYPE`` attr type or purpose of dpll device + ``DEVICE_SET`` command to set dpll device configuration + ``ID`` attr internal dpll device index + ``NAME`` attr dpll device name (not required if + dpll device index was provided)
Quoted 9 lines
Documentation/networking/dpll.rst line 121
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+ ``MODE`` attr selection mode to configure + ``PIN_GET`` command to get pin info or dump list of + available pins + ``DEVICE`` nest attr for each dpll device pin is + connected withAh, now I understand what this is about. Didn't occur to me from the netlink UAPI :/
It's like assembling furniture without the manual :)
Quoted 38 lines
Quoted 27 lines
Documentation/networking/dpll.rst new file +26
-0+ ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_PRIO`` attr priority of pin on the dpll device + ``PIN_STATE`` attr state of pin on the dpll device + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DESCRIPTION`` attr description provided by driver + ``PIN_TYPE`` attr type of a pin + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency in case + pin/dpll supports any frequency + ``PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency in case + pin/dpll supports any frequency + ``PIN_PARENT`` nest attr for each MUX-type parent, that + pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DPLL_CAPS`` attr bitmask of pin-dpll capabilities + + ``PIN_SET`` command to set pins configuration + ``ID`` attr internal dpll device indexDocumentation/networking/dpll.rst line 157
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``BUS_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``DEV_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DIRECTION`` attr direction to be set + ``PIN_FREQUENCY`` attr frequency to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_STATE`` attr pin state to be set + ``PIN_PRIO`` attr pin priority to be set
Quoted 4 lines
I think it would be good to emhasize which attribute is valid in which combination, meaning alone, dpll needs to be specified, parent pin needs to be specified
I agree, we need to do something like it.
Quoted 16 lines
Documentation/networking/dpll.rst line 169
Quoted 13 lines
Documentation/networking/dpll.rst new file +12
-0+ ``PIN_PARENT_IDX`` attr if provided state is to be set with + parent pin instead of with dpll device + +Netlink dump requests +===================== + +The ``DEVICE_GET`` and ``PIN_GET`` commands are capable of dump type +netlink requests. Possible response message attributes for netlink dump +requests: + + ============================== ======================================= + ``PIN_GET`` command to dump pinsMaintain the order and start with
DEVICE_GET
Sure, fixed.
Quoted 29 lines
Quoted 18 lines
Documentation/networking/dpll.rst new file +16
-0+ ``PIN`` attr nested type contains single pin + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_IDX`` attr index of dumped pin (on dplls) + ``PIN_DESCRIPTION`` description of a pin provided by driver + ``PIN_TYPE`` attr value of pin type + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_PARENT`` nest attr for each MUX-type parent, + that pin is connected withDocumentation/networking/dpll.rst line 195
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + + ``DEVICE_GET`` command to dump dplls + ``DEVICE`` attr nested type contatin a single + dpll device + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name
Quoted 3 lines
Hmm, why you need to repeat this for dump? Just say the message format is the same as for DO and you are done with it.
Yeah. Fixed.
Quoted 114 lines
Quoted 114 lines
Documentation/networking/dpll.rst new file +113
-0+ + +Dpll device level configuration pre-defined enums +================================================= + +For all below enum names used for configuration of dpll device use +the ``DPLL_`` prefix. + +Values for ``DPLL_A_LOCK_STATUS`` attribute: + + ============================= ====================================== + ``LOCK_STATUS_UNLOCKED`` DPLL is in freerun, not locked to any + source pin + ``LOCK_STATUS_CALIBRATING`` DPLL device calibrates to lock to the + source pin signal + ``LOCK_STATUS_LOCKED`` DPLL device is locked to the source + pin frequency + ``LOCK_STATUS_HOLDOVER`` DPLL device lost a lock, using its + frequency holdover capabilities + +Values for ``DPLL_A_MODE`` attribute: + + =================== ================================================ + ``MODE_FORCED`` source pin is force-selected by setting pin + state to ``DPLL_PIN_STATE_CONNECTED`` on a dpll + ``MODE_AUTOMATIC`` source pin is auto selected according to + configured pin priorities and source signal + validity + ``MODE_HOLDOVER`` force holdover mode of DPLL + ``MODE_FREERUN`` DPLL is driven by supplied system clock without + holdover capabilities + ``MODE_NCO`` similar to FREERUN, with possibility to + numerically control frequency offset + +Values for ``DPLL_A_TYPE`` attribute: + + ============= ================================================ + ``TYPE_PPS`` DPLL used to provide pulse-per-second output + ``TYPE_EEC`` DPLL used to drive ethernet equipment clock + + + +Pin level configuration pre-defined enums +========================================= + +For all below enum names used for configuration of pin use the +``DPLL_PIN`` prefix. + +Values for ``DPLL_A_PIN_STATE`` attribute: + + ======================= ======================================== + ``STATE_CONNECTED`` Pin connected to a dpll or parent pin + ``STATE_DISCONNECTED`` Pin disconnected from dpll or parent pin + +Values for ``DPLL_A_PIN_DIRECTION`` attribute: + + ======================= ============================== + ``DIRECTION_SOURCE`` Pin used as a source of signal + ``DIRECTION_OUTPUT`` Pin used to output signal + +Values for ``DPLL_A_PIN_TYPE`` attributes: + + ======================== ======================================== + ``TYPE_MUX`` MUX type pin, connected pins shall have + their own types + ``TYPE_EXT`` External pin + ``TYPE_SYNCE_ETH_PORT`` SyncE on Ethernet port + ``TYPE_INT_OSCILLATOR`` Internal Oscillator (i.e. Holdover with + Atomic Clock as a Source) + ``TYPE_GNSS`` GNSS 1PPS source + +Values for ``DPLL_A_PIN_DPLL_CAPS`` attributes: + + ============================= ================================ + ``CAPS_DIRECTION_CAN_CHANGE`` Bit present if direction can change + ``CAPS_PRIORITY_CAN_CHANGE`` Bit present if priority can change + ``CAPS_STATE_CAN_CHANGE`` Bit present if state can change + + +Notifications +============= + +DPLL device can provide notifications regarding status changes of the +device, i.e. lock status changes, source/output type changes or alarms. +This is the multicast group that is used to notify user-space apps via +netlink socket: ``DPLL_MCGRP_MONITOR`` + +Notifications messages (attrbiutes use ``DPLL_A`` prefix): + + ========================= ========================================== + ``EVENT_DEVICE_CREATE`` event value new DPLL device was created + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``EVENT_DEVICE_DELETE`` event value DPLL device was deleted + ``ID`` attr dpll device index + ``EVENT_DEVICE_CHANGE`` event value DPLL device attribute has + changed + ``ID`` attr modified dpll device ID + ``PIN_IDX`` attr the modified pin index + +Device change event shall consiste of the attribute and the value that +has changed. + + +Device driver implementation +============================ + +Device is allocated by ``dpll_device_get`` call. Second call with the +same arguments doesn't create new object but provides pointer to +previously created device for given arguments, it also increase refcount +of that object. +Device is deallocated by ``dpll_device_put`` call, which first decreases
Quoted 9 lines
Documentation/networking/dpll.rst line 313
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+the refcount, once refcount is cleared the object is destroyed. + +Device should implement set of operations and register device via +``dpll_device_register`` at which point it becomes available to the +users. Only one driver can register a dpll device within dpll subsytem."Driver instance". Btw, I need to change it for mlx5. I will try to implement it in coming days.
Sure, fixed.
Quoted 12 lines
Documentation/networking/dpll.rst line 321
Quoted 9 lines
Documentation/networking/dpll.rst new file +8
-0+Multiple driver instances can obtain reference to it with +``dpll_device_get``. + +The pins are allocated separately with ``dpll_pin_get``, it works +similarly to ``dpll_device_get``. Creates object and the for each call +with the same arguments the object refcount increases. + +Once DPLL device is created, allocated pin can be registered with itIn this text, you use "dpll", "Dpll", "DPLL". Could you unify?
Sure, fixed.
Quoted 12 lines
Documentation/networking/dpll.rst line 328
Quoted 9 lines
Documentation/networking/dpll.rst new file +7
-0+with 2 different methods, always providing implemented pin callbacks, +and private data pointer for calling them: +``dpll_pin_register`` - simple registration with a dpll device. +``dpll_pin_on_pin_register`` - register pin with another MUX type pin. + +For different instances of a device driver requiring to find already +registered DPLL (i.e. to connect its pins to id) use ``dpll_device_get``s/to id/to it/
Thanks, fixed.
Quoted 6 lines
Documentation/networking/dpll.rst line 331
Quoted 4 lines
Documentation/networking/dpll.rst new file +3
-0+to obtain proper dpll device pointer. + +The name od DPLL device is generated based on registerer provided devices/name od/name of/
Thanks, fixed.
Quoted 13 lines
Quoted 13 lines
Documentation/networking/dpll.rst new file +11
-0+struct pointer and dev_driver_id value. +Name is in format: ``%s_%u`` witch arguments: +``dev_name(struct device *)`` - syscall on parent device struct +``dev_driver_idx`` - registerer given id + +Notifications of adding or removing DPLL devices are created within +subsystem itself. +Notifications about registering/deregistering pins are also invoked by +the subsystem. +Notifications about dpll status changes shall be requested by device +driver with ``dpll_device_notify`` corresponding attribute as a reason.
Quoted 9 lines
Documentation/networking/dpll.rst line 346
Quoted 4 lines
Documentation/networking/dpll.rst new file +4
-0+ +There is no strict requirement to implement all the operations for +each device, every operation handler is checked for existence and +ENOTSUPP is returned in case of absence of specific handler.Not sure internal implementation details are necessary. Just say that driver is free to implement a set of ops it supports, leave the rest not implemented.
Hmm, actually this sentence is not true.
Some commands are required - as we WARN about them... I will list them there.
Thank you,
Arkadiusz
Quoted 18 lines
Review
Quoted 3 lines
Documentation/networking/dpll.rst new file +1
-0+(quoted diff) +0
-0
b/Documentation/networking/index.rstQuoted 14 lines
index
4ddcae33c336..6eb83a47cc2d100644Documentation/networking/index.rst +1
-1@@ -17,6 +17,7 @@ Contents: dsa/index devlink/index caif/index + dpll ethtool-netlink ieee802154 j1939 --2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 3/6] dpll: documentation on DPLL subsystem interface
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:04AM CET, [email protected] wrote:
[...]
Quoted 1 line
Documentation/networking/dpll.rst| 347 +++++++++++++++++++++++++++++
Why this is under networking? It is not networking. Please move, probably directly under "Documentation"
[...]
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 3/6] dpll: documentation on DPLL subsystem interface
Quoted 8 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:46 PMSun, Mar 12, 2023 at 03:28:04AM CET, [email protected] wrote:
[...]
Quoted 6 lines
Quoted 1 line
Documentation/networking/dpll.rst| 347 +++++++++++++++++++++++++++++Why this is under networking? It is not networking. Please move, probably directly under "Documentation"
[...]
Fixed, now in Documentation/dpll.rst
Thank you,
Arkadiusz
RFC PATCH v6 4/6 ice: add admin commands to access cgu configuration
In reply to Vadim FedorenkoFrom: Arkadiusz Kubalewski <[email protected]>
Add firmware admin command to access clock generation unit configuration, it is required to enable Extended PTP and SyncE features in the driver.
Add definitions of possible hardware variations of input and output pins related to clock generation unit and functions to access the data.
--- drivers/net/ethernet/intel/ice/ice.h | 1 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++++++++- drivers/net/ethernet/intel/ice/ice_common.c | 467 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 ++ drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 +++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + 8 files changed, 1415 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +1 -0
@@ -203,6 +203,7 @@ enum ice_feature {ICE_F_DSCP ,ICE_F_PTP_EXTTS ,ICE_F_SMA_CTRL , +ICE_F_CGU ,ICE_F_GNSS , ICE_F_MAX };
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +239 -1
288 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_common.c +467 -0
479 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_common.h +43 -0
55 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_lib.c +13 -4
@@ -4322,13 +4322,22 @@ void ice_init_feature_support(struct ice_pf *pf)case ICE_DEV_ID_E810C_BACKPLANE :case ICE_DEV_ID_E810C_QSFP :case ICE_DEV_ID_E810C_SFP : +case ICE_DEV_ID_E810_XXV_BACKPLANE : +case ICE_DEV_ID_E810_XXV_QSFP : +case ICE_DEV_ID_E810_XXV_SFP :ice_set_feature_support (pf,ICE_F_DSCP );ice_set_feature_support (pf,ICE_F_PTP_EXTTS ); -if (ice_is_e810t (&pf->hw)) { +if (ice_is_phy_rclk_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_PHY_RCLK ); +/* If we don't own the timer - don't enable other caps */ +if (!pf->hw.func_caps.ts_func_info.src_tmr_owned) +break ; +if (ice_is_cgu_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_CGU ); +if (ice_is_clock_mux_present_e810t (&pf->hw))ice_set_feature_support (pf,ICE_F_SMA_CTRL ); -if (ice_gnss_is_gps_present (&pf->hw)) -ice_set_feature_support (pf,ICE_F_GNSS ); - } +if (ice_gnss_is_gps_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_GNSS );break ;default :break ;
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +411 -0
420 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +240 -0
258 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
@@ -962,6 +962,7 @@ struct ice_hw {DECLARE_BITMAP (hw_ptype,ICE_FLOW_PTYPE_MAX );u8 dvm_ena;u16 io_expander_handle; +u8 cgu_part_number; };/* Statistics collected by each port, VSI, VEB, and S-channel */
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH RFC v6 4/6] ice: add admin commands to access cgu configuration
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-5-vadfed%40meta.com patch subject: [PATCH RFC v6 4/6] ice: add admin commands to access cgu configuration config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/0b8a02c116e829e4a4f8dd4a3d584b47688fed76
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout 0b8a02c116e829e4a4f8dd4a3d584b47688fed76
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=alpha olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/intel/ice/ice_lib.c: In function 'ice_init_feature_support':
>> drivers/net/ethernet/intel/ice/ice_lib.c:4334:53: error: 'ICE_F_PHY_RCLK' undeclared (first use in this function)
4334 | ice_set_feature_support(pf, ICE_F_PHY_RCLK);
| ^~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_lib.c:4334:53: note: each undeclared identifier is reported only once for each function it appears in
In file included from drivers/net/ethernet/intel/ice/ice_ptp.h:10,
from drivers/net/ethernet/intel/ice/ice.h:69,
from drivers/net/ethernet/intel/ice/ice_lib.c:4:
drivers/net/ethernet/intel/ice/ice_ptp_hw.h: At top level:
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:325:38: warning: 'ice_e823_zl_cgu_outputs' defined but not used [-Wunused-const-variable=]
325 | static const struct ice_cgu_pin_desc ice_e823_zl_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:306:38: warning: 'ice_e823_zl_cgu_inputs' defined but not used [-Wunused-const-variable=]
306 | static const struct ice_cgu_pin_desc ice_e823_zl_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:295:38: warning: 'ice_e823_si_cgu_outputs' defined but not used [-Wunused-const-variable=]
295 | static const struct ice_cgu_pin_desc ice_e823_si_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:279:38: warning: 'ice_e823_si_cgu_inputs' defined but not used [-Wunused-const-variable=]
279 | static const struct ice_cgu_pin_desc ice_e823_si_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:262:38: warning: 'ice_e810t_qsfp_cgu_outputs' defined but not used [-Wunused-const-variable=]
262 | static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:247:38: warning: 'ice_e810t_sfp_cgu_outputs' defined but not used [-Wunused-const-variable=]
247 | static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:224:38: warning: 'ice_e810t_qsfp_cgu_inputs' defined but not used [-Wunused-const-variable=]
224 | static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:205:38: warning: 'ice_e810t_sfp_cgu_inputs' defined but not used [-Wunused-const-variable=]
205 | static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~vim +/ICE_F_PHY_RCLK +4334 drivers/net/ethernet/intel/ice/ice_lib.c
4315
4316 /**
4317 * ice_init_feature_support
4318 * @pf: pointer to the struct ice_pf instance
4319 *
4320 * called during init to setup supported feature
4321 */
4322 void ice_init_feature_support(struct ice_pf *pf)
4323 {
4324 switch (pf->hw.device_id) {
4325 case ICE_DEV_ID_E810C_BACKPLANE:
4326 case ICE_DEV_ID_E810C_QSFP:
4327 case ICE_DEV_ID_E810C_SFP:
4328 case ICE_DEV_ID_E810_XXV_BACKPLANE:
4329 case ICE_DEV_ID_E810_XXV_QSFP:
4330 case ICE_DEV_ID_E810_XXV_SFP:
4331 ice_set_feature_support(pf, ICE_F_DSCP);
4332 ice_set_feature_support(pf, ICE_F_PTP_EXTTS);
4333 if (ice_is_phy_rclk_present(&pf->hw))
> 4334 ice_set_feature_support(pf, ICE_F_PHY_RCLK);
4335 /* If we don't own the timer - don't enable other caps */
4336 if (!pf->hw.func_caps.ts_func_info.src_tmr_owned)
4337 break;
4338 if (ice_is_cgu_present(&pf->hw))
4339 ice_set_feature_support(pf, ICE_F_CGU);
4340 if (ice_is_clock_mux_present_e810t(&pf->hw))
4341 ice_set_feature_support(pf, ICE_F_SMA_CTRL);
4342 if (ice_gnss_is_gps_present(&pf->hw))
4343 ice_set_feature_support(pf, ICE_F_GNSS);
4344 break;
4345 default:
4346 break;
4347 }
4348 }
4349
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
RFC PATCH v6 5/6 ice: implement dpll interface to control cgu
In reply to Vadim FedorenkoFrom: Arkadiusz Kubalewski <[email protected]>
Control over clock generation unit is required for further development of Synchronous Ethernet feature. Interface provides ability to obtain current state of a dpll, its sources and outputs which are pins, and allows their configuration.
--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 4 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 ++ drivers/net/ethernet/intel/ice/ice_main.c | 7 + 6 files changed, 1955 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -301,6 +301,7 @@ config ICE select DIMLIB select NET_DEVLINK select PLDMFW + select DPLL help This driver supports Intel(R) Ethernet Connection E800 Series of devices. For more information on how to identify your adapter, go
drivers/net/ethernet/intel/ice/Makefile +2 -1
@@ -33,7 +33,8 @@ ice-y := ice_main.o \ ice_lag.o \ ice_ethtool.o \ ice_repr.o \ - ice_tc_lib.o + ice_tc_lib.o \ + ice_dpll.o ice-$(CONFIG_PCI_IOV) += \ ice_sriov.o \ ice_virtchnl.o \
drivers/net/ethernet/intel/ice/ice.h +4 -0
@@ -75,6 +75,7 @@#include "ice_lag.h" #include "ice_vsi_vlan_ops.h" #include "ice_gnss.h" +#include "ice_dpll.h" #define ICE_BAR0 0#define ICE_REQ_DESC_MULTIPLE 32
@@ -202,6 +203,7 @@enum ice_feature {ICE_F_DSCP ,ICE_F_PTP_EXTTS , +ICE_F_PHY_RCLK ,ICE_F_SMA_CTRL ,ICE_F_CGU ,ICE_F_GNSS ,
@@ -512,6 +514,7 @@ enum ice_pf_flags {ICE_FLAG_PLUG_AUX_DEV ,ICE_FLAG_MTU_CHANGED ,ICE_FLAG_GNSS ,/* GNSS successfully initialized */ +ICE_FLAG_DPLL ,/* SyncE/PTP dplls initialized */ ICE_PF_FLAGS_NBITS /* must be last */ };
@@ -635,6 +638,7 @@ struct ice_pf {#define ICE_VF_AGG_NODE_ID_START 65#define ICE_MAX_VF_AGG_NODES 32struct ice_agg_node vf_agg_node[ICE_MAX_VF_AGG_NODES ]; +struct ice_dplls dplls; };struct ice_netdev_priv {
drivers/net/ethernet/intel/ice/ice_dpll.c new file +1845 -0
1,845 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_dpll.h new file +96 -0
96 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_main.c +7 -0
@@ -4810,6 +4810,10 @@ static void ice_init_features(struct ice_pf *pf)if (ice_is_feature_supported (pf,ICE_F_GNSS ))ice_gnss_init (pf); +if (ice_is_feature_supported (pf,ICE_F_CGU ) || +ice_is_feature_supported (pf,ICE_F_PHY_RCLK )) +ice_dpll_init (pf); +/* Note: Flow director init failure is non-fatal to load */ if (ice_init_fdir (pf))dev_err (dev,"could not initialize flow director\n" );
@@ -4836,6 +4840,9 @@ static void ice_deinit_features(struct ice_pf *pf)ice_gnss_exit (pf);if (test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags))ice_ptp_release (pf); +if (ice_is_feature_supported (pf,ICE_F_PHY_RCLK ) || +ice_is_feature_supported (pf,ICE_F_CGU )) +ice_dpll_release (pf); }static void ice_init_wakeup (struct ice_pf *pf)
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH RFC v6 5/6] ice: implement dpll interface to control cgu
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-6-vadfed%40meta.com patch subject: [PATCH RFC v6 5/6] ice: implement dpll interface to control cgu config: i386-randconfig-a013 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c4acb622eb0fd3120fc9cdcaf33fddfa7da04a50
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout c4acb622eb0fd3120fc9cdcaf33fddfa7da04a50
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/net/ethernet/intel/ice/ice_dpll.c:155:7: warning: variable 'pin_num' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (pin == pf->dplls.rclk.pin)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:161:18: note: uninitialized use occurs here
for (i = 0; i < pin_num; i++)
^~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:155:3: note: remove the 'if' if its condition is always true
if (pin == pf->dplls.rclk.pin)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:143:13: note: initialize the variable 'pin_num' to silence this warning
int pin_num, i;
^
= 0
>> drivers/net/ethernet/intel/ice/ice_dpll.c:412:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:416:6: note: uninitialized use occurs here
if (ret)
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:412:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:407:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
drivers/net/ethernet/intel/ice/ice_dpll.c:449:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:453:6: note: uninitialized use occurs here
if (ret)
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:449:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:444:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
>> drivers/net/ethernet/intel/ice/ice_dpll.c:478:1: warning: no previous prototype for function 'ice_dpll_pin_state_update' [-Wmissing-prototypes]
ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
^
drivers/net/ethernet/intel/ice/ice_dpll.c:477:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int
^
static
drivers/net/ethernet/intel/ice/ice_dpll.c:499:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:519:9: note: uninitialized use occurs here
return ret;
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:499:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:481:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
5 warnings generated.
--
ERROR: modpost: "__divdi3" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_phy_rclk_present" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_cgu_present" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_clock_mux_present_e810t" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_get_cgu_rclk_pin_info" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_get_cgu_state" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_name" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_type" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_freq_mask" [drivers/net/ethernet/intel/ice/ice.ko] undefined!Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
RFC PATCH v6 6/6 ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoImplement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.
--- drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 209 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 200 insertions(+), 10 deletions(-)
drivers/ptp/Kconfig +1 -0
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.
drivers/ptp/ptp_ocp.c +199 -10
265 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-7-vadfed%40meta.com patch subject: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops config: x86_64-randconfig-a005 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/fe16623a48f3c6592be80872758c19822b70ae62
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout fe16623a48f3c6592be80872758c19822b70ae62
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/dpll/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/dpll/dpll_core.c:285:1: warning: no previous prototype for function 'dpll_device_alloc' [-Wmissing-prototypes] dpll_device_alloc(const u64 clock_id, u32 dev_driver_id, struct module *module) ^ drivers/dpll/dpll_core.c:284:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct dpll_device * ^ static >> drivers/dpll/dpll_core.c:439:1: warning: no previous prototype for function 'dpll_pin_alloc' [-Wmissing-prototypes]
dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
^
drivers/dpll/dpll_core.c:438:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct dpll_pin *
^
static
2 warnings generated.
--
>> drivers/dpll/dpll_netlink.c:1062:13: warning: no previous prototype for function 'dpll_netlink_fini' [-Wmissing-prototypes]
void __exit dpll_netlink_fini(void)
^ drivers/dpll/dpll_netlink.c:1062:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __exit dpll_netlink_fini(void)
^
static
1 warning generated.
vim +/dpll_device_alloc +285 drivers/dpll/dpll_core.c
55b810a5137d33 Vadim Fedorenko 2023-03-11 269
55b810a5137d33 Vadim Fedorenko 2023-03-11 270
55b810a5137d33 Vadim Fedorenko 2023-03-11 271 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 272 * dpll_device_alloc - allocate the memory for dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 273 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 274 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 275 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 276 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 277 * Allocates memory and initialize dpll device, hold its reference on global
55b810a5137d33 Vadim Fedorenko 2023-03-11 278 * xarray.
55b810a5137d33 Vadim Fedorenko 2023-03-11 279 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 280 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 281 * * dpll_device struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 282 * * ERR_PTR(X) - failed allocation
55b810a5137d33 Vadim Fedorenko 2023-03-11 283 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 284 struct dpll_device *
55b810a5137d33 Vadim Fedorenko 2023-03-11 @285 dpll_device_alloc(const u64 clock_id, u32 dev_driver_id, struct module *module)
55b810a5137d33 Vadim Fedorenko 2023-03-11 286 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 287 struct dpll_device *dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 288 int ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 289
55b810a5137d33 Vadim Fedorenko 2023-03-11 290 dpll = kzalloc(sizeof(*dpll), GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 291 if (!dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 292 return ERR_PTR(-ENOMEM);
55b810a5137d33 Vadim Fedorenko 2023-03-11 293 refcount_set(&dpll->refcount, 1);
55b810a5137d33 Vadim Fedorenko 2023-03-11 294 dpll->dev.class = &dpll_class;
55b810a5137d33 Vadim Fedorenko 2023-03-11 295 dpll->dev_driver_id = dev_driver_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 296 dpll->clock_id = clock_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 297 dpll->module = module;
55b810a5137d33 Vadim Fedorenko 2023-03-11 298 ret = xa_alloc(&dpll_device_xa, &dpll->id, dpll,
55b810a5137d33 Vadim Fedorenko 2023-03-11 299 xa_limit_16b, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 300 if (ret) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 301 kfree(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 302 return ERR_PTR(ret);
55b810a5137d33 Vadim Fedorenko 2023-03-11 303 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 304 xa_init_flags(&dpll->pin_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 305
55b810a5137d33 Vadim Fedorenko 2023-03-11 306 return dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 307 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 308
55b810a5137d33 Vadim Fedorenko 2023-03-11 309 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 310 * dpll_device_get - find existing or create new dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 311 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 312 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 313 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 314 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 315 * Get existing object of a dpll device, unique for given arguments.
55b810a5137d33 Vadim Fedorenko 2023-03-11 316 * Create new if doesn't exist yet.
55b810a5137d33 Vadim Fedorenko 2023-03-11 317 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 318 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 319 * * valid dpll_device struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 320 * * ERR_PTR of an error
55b810a5137d33 Vadim Fedorenko 2023-03-11 321 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 322 struct dpll_device *
55b810a5137d33 Vadim Fedorenko 2023-03-11 323 dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module)
55b810a5137d33 Vadim Fedorenko 2023-03-11 324 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 325 struct dpll_device *dpll, *ret = NULL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 326 unsigned long index;
55b810a5137d33 Vadim Fedorenko 2023-03-11 327
55b810a5137d33 Vadim Fedorenko 2023-03-11 328 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 329 xa_for_each(&dpll_device_xa, index, dpll) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 330 if (dpll->clock_id == clock_id &&
55b810a5137d33 Vadim Fedorenko 2023-03-11 331 dpll->dev_driver_id == dev_driver_id &&
55b810a5137d33 Vadim Fedorenko 2023-03-11 332 dpll->module == module) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 333 ret = dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 334 refcount_inc(&ret->refcount);
55b810a5137d33 Vadim Fedorenko 2023-03-11 335 break;
55b810a5137d33 Vadim Fedorenko 2023-03-11 336 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 337 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 338 if (!ret)
55b810a5137d33 Vadim Fedorenko 2023-03-11 339 ret = dpll_device_alloc(clock_id, dev_driver_id, module);
55b810a5137d33 Vadim Fedorenko 2023-03-11 340 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 341
55b810a5137d33 Vadim Fedorenko 2023-03-11 342 return ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 343 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 344 EXPORT_SYMBOL_GPL(dpll_device_get);
55b810a5137d33 Vadim Fedorenko 2023-03-11 345
55b810a5137d33 Vadim Fedorenko 2023-03-11 346 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 347 * dpll_device_put - decrease the refcount and free memory if possible
55b810a5137d33 Vadim Fedorenko 2023-03-11 348 * @dpll: dpll_device struct pointer
55b810a5137d33 Vadim Fedorenko 2023-03-11 349 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 350 * Drop reference for a dpll device, if all references are gone, delete
55b810a5137d33 Vadim Fedorenko 2023-03-11 351 * dpll device object.
55b810a5137d33 Vadim Fedorenko 2023-03-11 352 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 353 void dpll_device_put(struct dpll_device *dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 354 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 355 if (!dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 356 return;
55b810a5137d33 Vadim Fedorenko 2023-03-11 357 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 358 if (refcount_dec_and_test(&dpll->refcount)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 359 WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
55b810a5137d33 Vadim Fedorenko 2023-03-11 360 xa_destroy(&dpll->pin_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 361 xa_erase(&dpll_device_xa, dpll->id);
55b810a5137d33 Vadim Fedorenko 2023-03-11 362 kfree(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 363 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 364 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 365 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 366 EXPORT_SYMBOL_GPL(dpll_device_put);
55b810a5137d33 Vadim Fedorenko 2023-03-11 367
55b810a5137d33 Vadim Fedorenko 2023-03-11 368 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 369 * dpll_device_register - register the dpll device in the subsystem
55b810a5137d33 Vadim Fedorenko 2023-03-11 370 * @dpll: pointer to a dpll
55b810a5137d33 Vadim Fedorenko 2023-03-11 371 * @type: type of a dpll
55b810a5137d33 Vadim Fedorenko 2023-03-11 372 * @ops: ops for a dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 373 * @priv: pointer to private information of owner
55b810a5137d33 Vadim Fedorenko 2023-03-11 374 * @owner: pointer to owner device
55b810a5137d33 Vadim Fedorenko 2023-03-11 375 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 376 * Make dpll device available for user space.
55b810a5137d33 Vadim Fedorenko 2023-03-11 377 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 378 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 379 * * 0 on success
55b810a5137d33 Vadim Fedorenko 2023-03-11 380 * * -EINVAL on failure
55b810a5137d33 Vadim Fedorenko 2023-03-11 381 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 382 int dpll_device_register(struct dpll_device *dpll, enum dpll_type type,
55b810a5137d33 Vadim Fedorenko 2023-03-11 383 struct dpll_device_ops *ops, void *priv,
55b810a5137d33 Vadim Fedorenko 2023-03-11 384 struct device *owner)
55b810a5137d33 Vadim Fedorenko 2023-03-11 385 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 386 if (WARN_ON(!ops || !owner))
55b810a5137d33 Vadim Fedorenko 2023-03-11 387 return -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 388 if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX))
55b810a5137d33 Vadim Fedorenko 2023-03-11 389 return -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 390 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 391 if (ASSERT_DPLL_NOT_REGISTERED(dpll)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 392 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 393 return -EEXIST;
55b810a5137d33 Vadim Fedorenko 2023-03-11 394 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 395 dpll->dev.bus = owner->bus;
55b810a5137d33 Vadim Fedorenko 2023-03-11 396 dpll->parent = owner;
55b810a5137d33 Vadim Fedorenko 2023-03-11 397 dpll->type = type;
55b810a5137d33 Vadim Fedorenko 2023-03-11 398 dpll->ops = ops;
55b810a5137d33 Vadim Fedorenko 2023-03-11 399 dev_set_name(&dpll->dev, "%s_%d", dev_name(owner),
55b810a5137d33 Vadim Fedorenko 2023-03-11 400 dpll->dev_driver_id);
55b810a5137d33 Vadim Fedorenko 2023-03-11 401 dpll->priv = priv;
55b810a5137d33 Vadim Fedorenko 2023-03-11 402 xa_set_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED);
55b810a5137d33 Vadim Fedorenko 2023-03-11 403 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 404 dpll_notify_device_create(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 405
55b810a5137d33 Vadim Fedorenko 2023-03-11 406 return 0;
55b810a5137d33 Vadim Fedorenko 2023-03-11 407 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 408 EXPORT_SYMBOL_GPL(dpll_device_register);
55b810a5137d33 Vadim Fedorenko 2023-03-11 409
55b810a5137d33 Vadim Fedorenko 2023-03-11 410 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 411 * dpll_device_unregister - deregister dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 412 * @dpll: registered dpll pointer
55b810a5137d33 Vadim Fedorenko 2023-03-11 413 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 414 * Deregister device, make it unavailable for userspace.
55b810a5137d33 Vadim Fedorenko 2023-03-11 415 * Note: It does not free the memory
55b810a5137d33 Vadim Fedorenko 2023-03-11 416 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 417 void dpll_device_unregister(struct dpll_device *dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 418 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 419 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 420 ASSERT_DPLL_REGISTERED(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 421 xa_clear_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED);
55b810a5137d33 Vadim Fedorenko 2023-03-11 422 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 423 dpll_notify_device_delete(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 424 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 425 EXPORT_SYMBOL_GPL(dpll_device_unregister);
55b810a5137d33 Vadim Fedorenko 2023-03-11 426
55b810a5137d33 Vadim Fedorenko 2023-03-11 427 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 428 * dpll_pin_alloc - allocate the memory for dpll pin
55b810a5137d33 Vadim Fedorenko 2023-03-11 429 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 430 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 431 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 432 * @prop: dpll pin properties
55b810a5137d33 Vadim Fedorenko 2023-03-11 433 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 434 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 435 * * valid allocated dpll_pin struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 436 * * ERR_PTR of an error
55b810a5137d33 Vadim Fedorenko 2023-03-11 437 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 438 struct dpll_pin *
55b810a5137d33 Vadim Fedorenko 2023-03-11 @439 dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
55b810a5137d33 Vadim Fedorenko 2023-03-11 440 const struct dpll_pin_properties *prop)
55b810a5137d33 Vadim Fedorenko 2023-03-11 441 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 442 struct dpll_pin *pin;
55b810a5137d33 Vadim Fedorenko 2023-03-11 443 int ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 444
55b810a5137d33 Vadim Fedorenko 2023-03-11 445 pin = kzalloc(sizeof(*pin), GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 446 if (!pin)
55b810a5137d33 Vadim Fedorenko 2023-03-11 447 return ERR_PTR(-ENOMEM);
55b810a5137d33 Vadim Fedorenko 2023-03-11 448 pin->dev_driver_id = device_drv_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 449 pin->clock_id = clock_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 450 pin->module = module;
55b810a5137d33 Vadim Fedorenko 2023-03-11 451 refcount_set(&pin->refcount, 1);
55b810a5137d33 Vadim Fedorenko 2023-03-11 452 if (WARN_ON(!prop->description)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 453 ret = -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 454 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 455 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 456 pin->prop.description = kstrdup(prop->description, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 457 if (!pin->prop.description) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 458 ret = -ENOMEM;
55b810a5137d33 Vadim Fedorenko 2023-03-11 459 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 460 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 461 if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC ||
55b810a5137d33 Vadim Fedorenko 2023-03-11 462 prop->type > DPLL_PIN_TYPE_MAX)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 463 ret = -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 464 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 465 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 466 pin->prop.type = prop->type;
55b810a5137d33 Vadim Fedorenko 2023-03-11 467 pin->prop.capabilities = prop->capabilities;
55b810a5137d33 Vadim Fedorenko 2023-03-11 468 pin->prop.freq_supported = prop->freq_supported;
55b810a5137d33 Vadim Fedorenko 2023-03-11 469 pin->prop.any_freq_min = prop->any_freq_min;
55b810a5137d33 Vadim Fedorenko 2023-03-11 470 pin->prop.any_freq_max = prop->any_freq_max;
55b810a5137d33 Vadim Fedorenko 2023-03-11 471 xa_init_flags(&pin->dpll_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 472 xa_init_flags(&pin->parent_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 473 ret = xa_alloc(&dpll_pin_xa, &pin->idx, pin,
55b810a5137d33 Vadim Fedorenko 2023-03-11 474 xa_limit_16b, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 475 release:
55b810a5137d33 Vadim Fedorenko 2023-03-11 476 if (ret) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 477 xa_destroy(&pin->dpll_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 478 xa_destroy(&pin->parent_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 479 kfree(pin->prop.description);
55b810a5137d33 Vadim Fedorenko 2023-03-11 480 kfree(pin->rclk_dev_name);
55b810a5137d33 Vadim Fedorenko 2023-03-11 481 kfree(pin);
55b810a5137d33 Vadim Fedorenko 2023-03-11 482 return ERR_PTR(ret);
55b810a5137d33 Vadim Fedorenko 2023-03-11 483 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 484
55b810a5137d33 Vadim Fedorenko 2023-03-11 485 return pin;
55b810a5137d33 Vadim Fedorenko 2023-03-11 486 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 487 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoQuoted 26 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c line 27
Quoted 5 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h>
Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Quoted 12 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };struct ocp_attr_group {
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 2 lines
drivers/ptp/ptp_ocp.c +0
-0@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];
It is quite customary to use defines for const numbers like this. Why don't you do that in ptp_ocp?
Quoted 46 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 10 lines
drivers/ptp/ptp_ocp.c +7
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); } +static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;
Just pass &bp->sma[i] as a priv to dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use of sma_nr at all.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 9 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);
No need to cast (void *), remove it.
Quoted 15 lines
drivers/ptp/ptp_ocp.c +15
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1);
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+return 0 ; + } +return -EINVAL ; +} + +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +
No need for empty line, I believe.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;
Just:
return mode == DPLL_MODE_AUTOMATIC;
Quoted 27 lines
drivers/ptp/ptp_ocp.c +27
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; +
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ; +return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,
Why you need const for u32?
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;
This is weird. I believe you should handle unsupported frequencies gracefully.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +
Avoid double empty lines.
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;
I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
and leave the frequency constant.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 4 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {
const
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,
Should be called "source_pin_get" and return (struct dpll_pin *) On the driver api level, no reason to pass indexes. Work with objects.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {
const
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 12 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;
Won't fit. Just use:
char *sma = "SMA0"
to be safe
Quoted 23 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +10
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out;
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+ + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ; + prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;
Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {
How it could be NULL?
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 1 line
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;
This would not be needed if the error path iterates over indexes which were successul.
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)
You don't do unregister of pin here.
Quoted 18 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +2
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp); +dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.
Quoted 13 lines
drivers/ptp/ptp_ocp.c line 27
Quoted 10 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h> Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Ah, yeah, you've mentioned it for ice driver last time, but I forgot to check it here. Removed.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };
Quoted 7 lines
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0struct ocp_attr_group {@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];It is quite customary to use defines for const numbers like this. Why don't you do that in
ptp_ocp?
Historical reasons. Jonathan might answer this question. I will add it to my TODO list for the driver.
Quoted 49 lines
Quoted 49 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)drivers/ptp/ptp_ocp.c +0
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); }
Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.
I'm still thinking about the change that you proposed to remove these _priv() helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);No need to cast (void *), remove it.
Fixed everywhere in the code, thanks.
Quoted 20 lines
Quoted 20 lines
drivers/ptp/ptp_ocp.c +19
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1); +return 0 ; + } +return -EINVAL ; +}
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+ +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +No need for empty line, I believe.
Ok.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;Just:
Quoted 2 lines
return mode == DPLL_MODE_AUTOMATIC;
Done, thanks!
Quoted 31 lines
Quoted 31 lines
drivers/ptp/ptp_ocp.c +31
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; + +if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ;
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,Why you need const for u32?
No need, true, removed.
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;This is weird. I believe you should handle unsupported frequencies gracefully.
Currently hardware supports fixed frequencies only. That's why I have to do this kind of "dance". Hopefully we will improve it to support variable frequency.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +Avoid double empty lines.
Yep.
Quoted 27 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
Quoted 1 line
and leave the frequency constant.
It's actually a mistake. It should be 1 which means 1Hz, PPS. The value returned by sma_op->get is actually the type of the signal where 0 is 1PPS, 1 is 10Mhz and so on.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 6 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {const
Will change it together with API part. Otherwise it doesn't compile.
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,Should be called "
source_pin_get" and return (structdpll_pin*) On the driver api level, no reason to pass indexes. Work with objects.
Good point, will improve it.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {const
Yep.
Quoted 18 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 13 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;Won't fit. Just use:
char *sma = "SMA0"
to be safe
Got it.
Quoted 29 lines
Quoted 29 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +15
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out; + + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ;
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
well, yes. but at the same time Arkadiusz raised a good question about accessing driver's memory from the subsystem code - doesn't look clean.
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {How it could be NULL?
Allocation fail?
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 2 lines
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;This would not be needed if the error path iterates over indexes which were successul.
Yeah, I'll make it the same way it's done in ice.
Quoted 15 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 12 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)You don't do unregister of pin here.
Yeah, actually error path and unload path should be re-implemented.
Quoted 19 lines
Quoted 19 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +2
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp); +dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 123 lines · Wed, Mar 15, 2023 at 01:10:33AM CET, [email protected] wrote:
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.Quoted 13 lines
drivers/ptp/ptp_ocp.c line 27
Quoted 10 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h> Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Ah, yeah, you've mentioned it for ice driver last time, but I forgot to check it here. Removed.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };Quoted 7 lines
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0struct ocp_attr_group {@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];It is quite customary to use defines for const numbers like this. Why don't you do that in
ptp_ocp?Historical reasons. Jonathan might answer this question. I will add it to my TODO list for the driver.
Quoted 49 lines
Quoted 49 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)drivers/ptp/ptp_ocp.c +0
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); }Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.
Quoted 3 lines
I'm still thinking about the change that you proposed to remove these
_priv()helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.
There are basically 2 ways:someop(struct subsystemobj *x, void *priv)
{
struct *mine = priv;
}
or:
someop(struct subsystemobj *x)
{
struct *mine = subsystem_get_priv(x);
}Both are more or less equal. The first has benefit that the caller most usually has direct access to the priv, so it can just easily pass it on. Also, you as the driver write see right away there is a priv arg and makes you want to use it and not figure out odd lookups to get to the same priv.
Quoted 161 lines
Quoted 14 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 11 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);No need to cast (void *), remove it.
Fixed everywhere in the code, thanks.
Quoted 20 lines
Quoted 20 lines
drivers/ptp/ptp_ocp.c +19
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1); +return 0 ; + } +return -EINVAL ; +}Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+ +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +No need for empty line, I believe.
Ok.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;Just:
Quoted 2 lines
return mode == DPLL_MODE_AUTOMATIC;Done, thanks!
Quoted 31 lines
Quoted 31 lines
drivers/ptp/ptp_ocp.c +31
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; + +if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ;Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,Why you need const for u32?
No need, true, removed.
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;This is weird. I believe you should handle unsupported frequencies gracefully.
Currently hardware supports fixed frequencies only. That's why I have to do this kind of "dance". Hopefully we will improve it to support variable frequency.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +Avoid double empty lines.
Yep.
Quoted 27 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
Quoted 5 lines
Quoted 1 line
and leave the frequency constant.
It's actually a mistake. It should be 1 which means 1Hz, PPS. The value returned by
sma_op->getis actually the type of the signal where 0 is 1PPS, 1 is 10Mhz and so on.
So you support freq change? In the comment above you wrote "Currently hardware supports fixed frequencies only". I'm confused.
The point is:
1) if you support freq change, you should sanitize the input properly in frequency_set() and return correct actual value in frequency_get()
2) if you don't support freq change, avoid filling-up these ops entirely.
Quoted 93 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 7 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {const
Will change it together with API part. Otherwise it doesn't compile.
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,Should be called "
source_pin_get" and return (structdpll_pin*) On the driver api level, no reason to pass indexes. Work with objects.Good point, will improve it.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {const
Yep.
Quoted 18 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 13 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;Won't fit. Just use:
char *sma = "SMA0"
to be safeGot it.
Quoted 29 lines
Quoted 29 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +15
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out; + + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ;Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
Quoted 2 lines
well, yes. but at the same time Arkadiusz raised a good question about accessing driver's memory from the subsystem code - doesn't look clean.
It is completely clean and we do it everywhere in the kernel. No problem what so ever.
Quoted 9 lines
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 4 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {How it could be NULL?
Allocation fail?
No? I mean, I don't see such possibility of return value of dpll_pin_get() Do you see it or are you just guessing? :)
Quoted 39 lines
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 3 lines
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;This would not be needed if the error path iterates over indexes which were successul.
Yeah, I'll make it the same way it's done in ice.
Quoted 15 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 12 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)You don't do unregister of pin here.
Yeah, actually error path and unload path should be re-implemented.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +0
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp);
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/ptp/ptp_ocp.c +2
-0+dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 60 lines · Jiri Pirko
Quoted 59 lines · Wed, Mar 15, 2023 at 01:10:33AM CET, [email protected] wrote:
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.Quoted 13 lines
drivers/ptp/ptp_ocp.c line 27
Quoted 10 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h> Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Ah, yeah, you've mentioned it for ice driver last time, but I forgot to check it here. Removed.
Quoted 18 lines
Quoted 13 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };struct ocp_attr_group {drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 2 lines
drivers/ptp/ptp_ocp.c +0
-0@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];It is quite customary to use defines for const numbers like this. Why don't you do that in
ptp_ocp?
Quoted 3 lines
Quoted 3 lines
Historical reasons. Jonathan might answer this question. I will add it to my TODO list for the driver.
Added macros for SMAs for now.
Quoted 76 lines
Quoted 61 lines
Quoted 49 lines
Quoted 49 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)drivers/ptp/ptp_ocp.c +0
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); }Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.Quoted 3 lines
I'm still thinking about the change that you proposed to remove these
_priv()helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.There are basically 2 ways:
someop(struct subsystemobj *x, void *priv){ struct *mine = priv; } or: someop(struct subsystemobj *x) { struct *mine = subsystem_get_priv(x); }
Quoted 5 lines
Both are more or less equal. The first has benefit that the caller most usually has direct access to the priv, so it can just easily pass it on. Also, you as the driver write see right away there is a priv arg and makes you want to use it and not figure out odd lookups to get to the same priv.
Thinking about this part. We have tons of parameters for some ops already. Adding void *priv to every one of them (and actually two for pins) makes them even more ugly. Let's stay with helpers if you don't have strong opinion against.
Quoted 29 lines
Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_setQuoted 5 lines
Quoted 1 line
and leave the frequency constant.
It's actually a mistake. It should be 1 which means 1Hz, PPS. The value returned by
sma_op->getis actually the type of the signal where 0 is 1PPS, 1 is 10Mhz and so on.
Quoted 7 lines
So you support freq change? In the comment above you wrote "Currently hardware supports fixed frequencies only". I'm confused.
The point is:
1) if you support freq change, you should sanitize the input properly infrequency_set()and return correct actual value infrequency_get()
2) if you don't support freq change, avoid filling-up these ops entirely.
Improved this part completely.
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 23 lines
drivers/ptp/ptp_ocp.c +12
-2struct ptp_ocp *bp; -int err; +int err, i; +u64 clkid; devlink =devlink_alloc (&ptp_ocp_devlink_ops,sizeof (*bp), &pdev->dev);if (!devlink) {@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out;drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+ + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ; + prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
Quoted 6 lines
Quoted 2 lines
well, yes. but at the same time Arkadiusz raised a good question about accessing driver's memory from the subsystem code - doesn't look clean.
It is completely clean and we do it everywhere in the kernel. No problem what so ever.
Did it this way.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 5 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {How it could be NULL?
Quoted 5 lines
Quoted 1 line
Allocation fail?
No? I mean, I don't see such possibility of return value of
dpll_pin_get()Do you see it or are you just guessing? :)
Fixed this part.
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 4 lines · Sat, Apr 01, 2023 at 01:28:29AM CEST, [email protected] wrote:
Quoted 3 lines · Jiri Pirko
Quoted 2 lines · Wed, Mar 15, 2023 at 01:10:33AM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
Quoted 33 lines
Quoted 27 lines
Quoted 12 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.Quoted 3 lines
I'm still thinking about the change that you proposed to remove these
_priv()helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.There are basically 2 ways:
someop(struct subsystemobj *x, void *priv){ struct *mine = priv; } or: someop(struct subsystemobj *x) { struct *mine = subsystem_get_priv(x); }Quoted 5 lines
Both are more or less equal. The first has benefit that the caller most usually has direct access to the priv, so it can just easily pass it on. Also, you as the driver write see right away there is a priv arg and makes you want to use it and not figure out odd lookups to get to the same priv.
Quoted 4 lines
Thinking about this part. We have tons of parameters for some ops already. Adding void *priv to every one of them (and actually two for pins) makes them even more ugly. Let's stay with helpers if you don't have strong opinion against.
Well, with the patches I sent when 1 device/pin can be registered multiple times with multiple privs, I believe it is much more feasable to just pass the priv along in the arg list, because otherwise you would have to do some odd lookup.
Please pass priv, would be nicer and easier and more simple for the driver to implement. The arg list can handle that easily.
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4383
Quoted 9 lines
drivers/ptp/ptp_ocp.c +3
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) {
You have to use IS_ERR() here. Same problem in ice.
[...]
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 10 lines · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
Quoted 6 lines
drivers/ptp/ptp_ocp.c +0
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ;
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4383
Quoted 3 lines
drivers/ptp/ptp_ocp.c +3
-0+ clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) {You have to use
IS_ERR()here. Same problem in ice.
Yep, fixed, thanks!
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
drivers/ptp/ptp_ocp.c ptp_ocp_remove(struct pci_dev *pdev) · line 4432
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp);
You are missing pins unregister and put here.
Btw, It would be probably good to add a WARN_ON into dpll_device_unregister() to catch bugs like this one.
Quoted 8 lines
drivers/ptp/ptp_ocp.c +2
-0+dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Jiri Pirko
maintainerQuoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
Quoted 110 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Vadim Fedorenko
maintainerQuoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --dump device-get./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do device-get --json '{"id": 0}' ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --dump pin-get./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-get --json '{"id": 0, "pin-idx":1}' ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Quoted 111 lines
Quoted 111 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Jiri Pirko
maintainerQuoted 13 lines · Mon, Mar 13, 2023 at 04:33:13PM CET, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
Quoted 10 lines
./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump device-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump pin-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":1}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Yep, that is exactly what I was asking for. Thanks.
Please try to extend it a bit and add to the cover letter. Gives people better understanding of how this works.
Quoted 113 lines
Quoted 112 lines
Quoted 112 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Vadim Fedorenko
maintainerQuoted 25 lines · Jiri Pirko
Quoted 13 lines · Mon, Mar 13, 2023 at 04:33:13PM CET, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
Quoted 10 lines
./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump device-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump pin-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":1}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Quoted 3 lines
Yep, that is exactly what I was asking for. Thanks.
Please try to extend it a bit and add to the cover letter. Gives people better understanding of how this works.
Sure, will extend the cover letter in the next version, thanks!
Quoted 114 lines
Quoted 114 lines
Quoted 113 lines
Quoted 113 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Jiri Pirko
maintainerQuoted 13 lines · Mon, Mar 13, 2023 at 04:33:13PM CET, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
Quoted 10 lines
./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump device-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump pin-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":1}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Interesting, is this working for you?
I'm experiencing some issue with cmd value. Example:./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do device-get --json '{"id": 0}' this should send DPLL_CMD_DEVICE_GET which is 1.
In kernel genl_family_rcv_msg() the hdr->cmd is 2
Any idea what might be wrong?
Jakub Kicinski
maintainerQuoted 6 lines · On Fri, 17 Mar 2023 17:10:04 +0100 Jiri Pirko wrote:
Interesting, is this working for you?
I'm experiencing some issue with cmd value. Example:./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}' this should sendDPLL_CMD_DEVICE_GETwhich is 1.
In kernelgenl_family_rcv_msg()thehdr->cmdis 2
Any idea what might be wrong?
I changed the default value for the first element of an attribute set from 0 to 1 to avoid having to add all those (pointless?)
+ -
+ name: unspec
+ doc: unspecified value
at the start. So delete those or explicitly set them to value: 0.
See commit ad4fafcde5bc ("tools: ynl: use 1 as the default for first entry in attrs/ops").
Jiri Pirko
maintainerQuoted 9 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
Vadim, Arkadiusz.
I have couple of patches on top of this one and mlx5 implementation. I would like to send it to you until Sunday. Could you include those to the next rfc?
I will not review this version more now. Lets do the changes, I will continue with the review on the next version of rfc.
Thanks!
Vadim Fedorenko
maintainerQuoted 14 lines · Jiri Pirko
Quoted 9 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back againVadim, Arkadiusz.
Quoted 8 lines
I have couple of patches on top of this one and mlx5 implementation. I would like to send it to you until Sunday. Could you include those to the next rfc?
I will not review this version more now. Lets do the changes, I will continue with the review on the next version of rfc.
Thanks!
Hi Jiri!
I'm going to spend Friday and weekend polishing the series to address as much comments as I can and publish v7 next week. You can send your patches prepared on top of github version, that would be the best way to have them ready for the next round.
Thanks,
Vadim
Jiri Pirko
maintainercover dpll: initial patchset extension by mlx5 implementation
In reply to Vadim FedorenkoFrom: Jiri Pirko <[email protected]>
Hi.
This is extending your patchset. Basically, I do this on top of the changes I pointed out during review. For example patch #6 is exposing pin handle which is going to change, etc (there, I put a note).
First 5 patches are just needed dependencies and you can squash them into your patch/patches. Last two patches should go in separatelly.
Please note that the patch #6 is replacing the need to pass the rclk device during pin registration by putting a link between netdev and dpll pin.
Please merge this into your dpll patchset and include it in the next RFC. Thanks!
Jiri Pirko (7):
dpll: make ops function args const
dpll: allow to call device register multiple times
dpll: introduce a helper to get first dpll ref and use it
dpll: allow to call pin register multiple times
dpll: export dpll_pin_notify()
netdev: expose DPLL pin handle for netdevice
mlx5: Implement SyncE support using DPLL infrastructure
drivers/dpll/dpll_core.c | 334 ++++++++++---- drivers/dpll/dpll_core.h | 25 +- drivers/dpll/dpll_netlink.c | 161 ++++--- drivers/dpll/dpll_netlink.h | 3 - drivers/net/ethernet/intel/ice/ice_dpll.c | 22 +- .../net/ethernet/mellanox/mlx5/core/Kconfig | 8 + .../net/ethernet/mellanox/mlx5/core/Makefile | 3 + drivers/net/ethernet/mellanox/mlx5/core/dev.c | 17 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 429 ++++++++++++++++++ drivers/ptp/ptp_ocp.c | 2 +- include/linux/dpll.h | 46 +- include/linux/mlx5/driver.h | 2 + include/linux/mlx5/mlx5_ifc.h | 59 ++- include/linux/netdevice.h | 7 + include/uapi/linux/if_link.h | 2 + net/core/dev.c | 20 + net/core/rtnetlink.c | 38 ++ 17 files changed, 1008 insertions(+), 170 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/dpll.c
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 1/7 dpll: make ops function args const
From: Jiri Pirko <[email protected]>
Make ops args passed over *_register() functions const.
--- drivers/dpll/dpll_core.c | 25 ++++++++++++------------- include/linux/dpll.h | 9 +++++---- 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/dpll/dpll_core.c +12 -13
@@ -89,7 +89,7 @@ dpll_device_get_by_name(const char *bus_name, const char *device_name)*/ static int dpll_xa_ref_pin_add (struct xarray *xa_pins,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv) +const struct dpll_pin_ops *ops,void *priv) {struct dpll_pin_ref *ref;unsigned long i;
@@ -189,7 +189,7 @@ dpll_xa_ref_pin_find(struct xarray *xa_pins, const struct dpll_pin *pin)*/ static int dpll_xa_ref_dpll_add (struct xarray *xa_dplls,struct dpll_device *dpll, -struct dpll_pin_ops *ops,void *priv) +const struct dpll_pin_ops *ops,void *priv) {struct dpll_pin_ref *ref;unsigned long i;
@@ -385,8 +385,9 @@ EXPORT_SYMBOL_GPL(dpll_device_put);* * 0 on success * * -EINVAL on failure */ -int dpll_device_register (struct dpll_device *dpll,struct dpll_device_ops *ops, -void *priv,struct device *owner) +int dpll_device_register (struct dpll_device *dpll, +const struct dpll_device_ops *ops,void *priv, +struct device *owner) {if (WARN_ON (!ops || !owner))return -EINVAL ;
@@ -551,7 +552,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_put);static int __dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv, +const struct dpll_pin_ops *ops,void *priv,const char *rclk_device_name) {int ret;
@@ -592,10 +593,9 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* * -EINVAL - missing dpll or pin * * -ENOMEM - failed to allocate memory */ -int -dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv, -struct device *rclk_device) +int dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device) {const char *rclk_name = rclk_device ?dev_name (rclk_device) :NULL ;int ret;
@@ -661,10 +661,9 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister);* * -ENOMEM failed allocation * * -EPERM if parent is not allowed */ -int -dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv, -struct device *rclk_device) +int dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device) {struct dpll_pin_ref *ref;unsigned long i, stop;
include/linux/dpll.h +5 -4
@@ -123,8 +123,9 @@ void dpll_device_put(struct dpll_device *dpll);* @owner: device struct of the owner * */ -int dpll_device_register (struct dpll_device *dpll,struct dpll_device_ops *ops, -void *priv,struct device *owner); +int dpll_device_register (struct dpll_device *dpll, +const struct dpll_device_ops *ops,void *priv, +struct device *owner);/** * dpll_device_unregister - deregister registered dpll
@@ -200,7 +201,7 @@ struct dpll_pin* * -EBUSY - couldn't allocate id for a pin. */ int dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv, +const struct dpll_pin_ops *ops,void *priv,struct device *rclk_device);/**
@@ -244,7 +245,7 @@ void dpll_pin_put(struct dpll_pin *pin);* * -EEXIST - pin already registered with this parent pin, */ int dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, -struct dpll_pin_ops *ops,void *priv, +const struct dpll_pin_ops *ops,void *priv,struct device *rclk_device);/**
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 2/7 dpll: allow to call device register multiple times
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Some devices allow to control a single dpll instance over multiple channels. In case of mlx5 for example, one dpll could be controlled over multiple PFs that reside on a single ASIC. These are equal. Allow each to register/unregister dpll device. Use the first ops and priv always as the is no difference in between those and the rest.
--- drivers/dpll/dpll_core.c | 85 +++++++++++++++++++++-- drivers/dpll/dpll_core.h | 11 ++- drivers/dpll/dpll_netlink.c | 29 ++++---- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 +- drivers/ptp/ptp_ocp.c | 2 +- include/linux/dpll.h | 5 +- 6 files changed, 113 insertions(+), 23 deletions(-)
drivers/dpll/dpll_core.c +80 -5
@@ -293,6 +293,7 @@ dpll_device_alloc(const u64 clock_id, u32 dev_driver_id,if (!dpll)return ERR_PTR (-ENOMEM );refcount_set (&dpll->refcount,1 ); +INIT_LIST_HEAD (&dpll->registration_list); dpll->dev.class = &dpll_class; dpll->dev_driver_id = dev_driver_id; dpll->clock_id = clock_id;
@@ -366,12 +367,26 @@ void dpll_device_put(struct dpll_device *dpll)WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));xa_destroy (&dpll->pin_refs);xa_erase (&dpll_device_xa, dpll->id); +WARN_ON (!list_empty (&dpll->registration_list));kfree (dpll); }mutex_unlock (&dpll_device_xa_lock); }EXPORT_SYMBOL_GPL (dpll_device_put); +static struct dpll_device_registration * +dpll_device_registration_find (struct dpll_device *dpll, +const struct dpll_device_ops *ops,void *priv) +{ +struct dpll_device_registration *reg; + +list_for_each_entry (reg, &dpll->registration_list, list) { +if (reg->ops == ops && reg->priv == priv) +return reg; + } +return NULL ; +} +/** * dpll_device_register - register the dpll device in the subsystem * @dpll: pointer to a dpll
@@ -389,19 +404,39 @@ int dpll_device_register(struct dpll_device *dpll, const struct dpll_device_ops *ops, void *priv, struct device *owner) { + struct dpll_device_registration *reg; +bool first_registration = false; +if (WARN_ON (!ops || !owner))return -EINVAL ; +mutex_lock (&dpll_device_xa_lock); -if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { + reg =dpll_device_registration_find (dpll, ops, priv); +if (reg) {mutex_unlock (&dpll_device_xa_lock);return -EEXIST ; } + + reg =kzalloc (sizeof (*reg),GFP_KERNEL ); +if (!reg) { +mutex_unlock (&dpll_device_xa_lock); +return -ENOMEM ; + } + reg->ops = ops; + reg->priv = priv; + dpll->dev.bus = owner->bus; dpll->parent = owner; - dpll->ops = ops;dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), dpll->dev_driver_id); - dpll->priv = priv; + + first_registration =list_empty (&dpll->registration_list); +list_add_tail (®->list, &dpll->registration_list); +if (!first_registration) { +mutex_unlock (&dpll_device_xa_lock); +return 0 ; + } +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED );mutex_unlock (&dpll_device_xa_lock);dpll_notify_device_create (dpll);
@@ -413,14 +448,32 @@ EXPORT_SYMBOL_GPL(dpll_device_register);/** * dpll_device_unregister - deregister dpll device * @dpll: registered dpll pointer +* @ops: ops for a dpll device +* @priv: pointer to private information of owner * * Deregister device, make it unavailable for userspace. * Note: It does not free the memory */ -void dpll_device_unregister (struct dpll_device *dpll) +void dpll_device_unregister (struct dpll_device *dpll, +const struct dpll_device_ops *ops,void *priv) { +struct dpll_device_registration *reg; +mutex_lock (&dpll_device_xa_lock);ASSERT_DPLL_REGISTERED (dpll); + + reg =dpll_device_registration_find (dpll, ops, priv); +if (WARN_ON (!reg)) { +mutex_unlock (&dpll_device_xa_lock); +return ; + } +list_del (®->list); +kfree (reg); + +if (!list_empty (&dpll->registration_list)) { +mutex_unlock (&dpll_device_xa_lock); +return ; + }xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED );mutex_unlock (&dpll_device_xa_lock);dpll_notify_device_delete (dpll);
@@ -760,6 +813,17 @@ struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx)return NULL ; } +static struct dpll_device_registration * +dpll_device_registration_first (struct dpll_device *dpll) +{ +struct dpll_device_registration *reg; + + reg =list_first_entry_or_null ((struct list_head *) &dpll->registration_list, + struct dpll_device_registration, list); +WARN_ON (!reg); +return reg; +} +/** * dpll_priv - get the dpll device private owner data * @dpll: registered dpll pointer
@@ -768,10 +832,21 @@ struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx)*/ void *dpll_priv (const struct dpll_device *dpll) { -return dpll->priv; +struct dpll_device_registration *reg; + + reg =dpll_device_registration_first ((struct dpll_device *) dpll); +return reg->priv; }EXPORT_SYMBOL_GPL (dpll_priv); +const struct dpll_device_ops *dpll_device_ops (struct dpll_device *dpll) +{ +struct dpll_device_registration *reg; + + reg =dpll_device_registration_first (dpll); +return reg->ops; +} +/** * dpll_pin_on_dpll_priv - get the dpll device private owner data * @dpll: registered dpll pointer
drivers/dpll/dpll_core.h +9 -2
@@ -7,11 +7,18 @@#define __DPLL_CORE_H__#include <linux/dpll.h> +#include <linux/list.h> #include <linux/refcount.h> #include "dpll_netlink.h" #define DPLL_REGISTERED XA_MARK_1 +struct dpll_device_registration { +struct list_head list; +const struct dpll_device_ops *ops; +void *priv; +}; +/** * struct dpll_device - structure for a DPLL device * @id: unique id number for each device
@@ -34,9 +41,8 @@ struct dpll_device {struct device dev;struct device *parent;struct module *module; -struct dpll_device_ops *ops;enum dpll_type type; -void *priv; +struct list_head registration_list;struct xarray pin_refs;u64 clock_id;unsigned long mode_supported_mask;
@@ -84,6 +90,7 @@ struct dpll_pin_ref {refcount_t refcount; }; +const struct dpll_device_ops *dpll_device_ops (struct dpll_device *dpll);struct dpll_device *dpll_device_get_by_id (int id);struct dpll_device *dpll_device_get_by_name (const char *bus_name,const char *dev_name);
drivers/dpll/dpll_netlink.c +17 -12
@@ -18,7 +18,7 @@ static u32 dpll_pin_freq_value[] = { };static int -dpll_msg_add_dev_handle (struct sk_buff *msg,const struct dpll_device *dpll) +dpll_msg_add_dev_handle (struct sk_buff *msg,struct dpll_device *dpll) {if (nla_put_u32 (msg,DPLL_A_ID , dpll->id))return -EMSGSIZE ;
@@ -31,14 +31,15 @@ dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device *dpll) }static int -dpll_msg_add_mode (struct sk_buff *msg,const struct dpll_device *dpll, +dpll_msg_add_mode (struct sk_buff *msg,struct dpll_device *dpll,struct netlink_ext_ack *extack) { +const struct dpll_device_ops *ops =dpll_device_ops (dpll);enum dpll_mode mode; -if (WARN_ON (!dpll->ops->mode_get)) +if (WARN_ON (!ops->mode_get))return -EOPNOTSUPP ; -if (dpll->ops->mode_get (dpll, &mode, extack)) +if (ops->mode_get (dpll, &mode, extack))return -EFAULT ;if (nla_put_u8 (msg,DPLL_A_MODE , mode))return -EMSGSIZE ;
@@ -50,11 +51,12 @@ static int dpll_msg_add_source_pin_idx(struct sk_buff *msg, struct dpll_device *dpll, struct netlink_ext_ack *extack) { + const struct dpll_device_ops *ops = dpll_device_ops(dpll);u32 source_pin_idx; -if (!dpll->ops->source_pin_idx_get) +if (!ops->source_pin_idx_get)return 0 ; -if (dpll->ops->source_pin_idx_get (dpll, &source_pin_idx, extack)) +if (ops->source_pin_idx_get (dpll, &source_pin_idx, extack))return -EFAULT ;if (nla_put_u32 (msg,DPLL_A_SOURCE_PIN_IDX , source_pin_idx))return -EMSGSIZE ;
@@ -66,11 +68,12 @@ static int dpll_msg_add_lock_status(struct sk_buff *msg, struct dpll_device *dpll, struct netlink_ext_ack *extack) { + const struct dpll_device_ops *ops = dpll_device_ops(dpll);enum dpll_lock_status status; -if (WARN_ON (!dpll->ops->lock_status_get)) +if (WARN_ON (!ops->lock_status_get))return -EOPNOTSUPP ; -if (dpll->ops->lock_status_get (dpll, &status, extack)) +if (ops->lock_status_get (dpll, &status, extack))return -EFAULT ;if (nla_put_u8 (msg,DPLL_A_LOCK_STATUS , status))return -EMSGSIZE ;
@@ -82,11 +85,12 @@ static int dpll_msg_add_temp(struct sk_buff *msg, struct dpll_device *dpll, struct netlink_ext_ack *extack) { + const struct dpll_device_ops *ops = dpll_device_ops(dpll);s32 temp; -if (!dpll->ops->temp_get) +if (!ops->temp_get)return -EOPNOTSUPP ; -if (dpll->ops->temp_get (dpll, &temp, extack)) +if (ops->temp_get (dpll, &temp, extack))return -EFAULT ;if (nla_put_s32 (msg,DPLL_A_TEMP , temp))return -EMSGSIZE ;
@@ -686,6 +690,7 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)static int dpll_set_from_nlattr (struct dpll_device *dpll,struct genl_info *info) { +const struct dpll_device_ops *ops =dpll_device_ops (dpll);struct nlattr *attr;enum dpll_mode mode;int rem, ret =0 ;
@@ -696,9 +701,9 @@ dpll_set_from_nlattr(struct dpll_device *dpll, struct genl_info *info)case DPLL_A_MODE : mode =nla_get_u8 (attr); -if (!dpll->ops || !dpll->ops->mode_set) +if (!ops->mode_set)return -EOPNOTSUPP ; - ret = dpll->ops->mode_set (dpll, mode, info->extack); + ret = ops->mode_set (dpll, mode, info->extack);if (ret)return ret;break ;
drivers/net/ethernet/intel/ice/ice_dpll.c +2 -2
@@ -1551,7 +1551,7 @@ static void ice_dpll_release_all(struct ice_pf *pf, bool cgu)if (dp->dpll) {mutex_lock (&pf->dplls.lock);if (cgu) -dpll_device_unregister (dp->dpll); +dpll_device_unregister (dp->dpll, &ice_dpll_ops, pf);dpll_device_put (dp->dpll);mutex_unlock (&pf->dplls.lock);dev_dbg (ice_pf_to_dev (pf),"PPS dpll removed\n" );
@@ -1560,7 +1560,7 @@ static void ice_dpll_release_all(struct ice_pf *pf, bool cgu)if (de->dpll) {mutex_lock (&pf->dplls.lock);if (cgu) -dpll_device_unregister (de->dpll); +dpll_device_unregister (de->dpll, &ice_dpll_ops, pf);dpll_device_put (de->dpll);mutex_unlock (&pf->dplls.lock);dev_dbg (ice_pf_to_dev (pf),"EEC dpll removed\n" );
drivers/ptp/ptp_ocp.c +1 -1
@@ -4431,7 +4431,7 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp); -dpll_device_unregister (bp->dpll); +dpll_device_unregister (bp->dpll, &dpll_ops, bp);dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);
include/linux/dpll.h +4 -1
@@ -130,11 +130,14 @@ int dpll_device_register(struct dpll_device *dpll,/** * dpll_device_unregister - deregister registered dpll * @dpll: pointer to dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner * * Unregister the dpll from the subsystem, make it unavailable for netlink * API users. */ -void dpll_device_unregister (struct dpll_device *dpll); +void dpll_device_unregister (struct dpll_device *dpll, +const struct dpll_device_ops *ops,void *priv);/** * dpll_priv - get dpll private data
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 3/7 dpll: introduce a helper to get first dpll ref and use it
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
No need to iterate xaarray in dpll_msg_add_pin_direction() and dpll_msg_add_pin_freq(). Just introduce a helper to get the first dpll reference and use that.
Add a check for ops not being null in pin_register() function, not only for sake of this change, but also for the sake of existing code relying on it.
--- drivers/dpll/dpll_core.c | 12 ++++++++++++ drivers/dpll/dpll_core.h | 1 + drivers/dpll/dpll_netlink.c | 34 ++++++++++++---------------------- 3 files changed, 25 insertions(+), 22 deletions(-)
drivers/dpll/dpll_core.c +12 -0
@@ -267,6 +267,15 @@ dpll_xa_ref_dpll_find(struct xarray *xa_refs, const struct dpll_device *dpll)return NULL ; } +struct dpll_pin_ref *dpll_xa_ref_dpll_first (struct xarray *xa_refs) +{ +struct dpll_pin_ref *ref; +unsigned long i =0 ; + + ref =xa_find (xa_refs, &i,ULONG_MAX ,XA_PRESENT ); +WARN_ON (!ref); +return ref; +}/** * dpll_device_alloc - allocate the memory for dpll device
@@ -610,6 +619,9 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, {int ret; +if (WARN_ON (!ops)) +return -EINVAL ; +if (rclk_device_name && !pin->rclk_dev_name) { pin->rclk_dev_name =kstrdup (rclk_device_name,GFP_KERNEL );if (!pin->rclk_dev_name)
drivers/dpll/dpll_core.h +1 -0
@@ -99,6 +99,7 @@ struct dpll_pin_ref * dpll_xa_ref_pin_find(struct xarray *xa_refs, const struct dpll_pin *pin);struct dpll_pin_ref *dpll_xa_ref_dpll_find (struct xarray *xa_refs,const struct dpll_device *dpll); +struct dpll_pin_ref *dpll_xa_ref_dpll_first (struct xarray *xa_refs);extern struct xarray dpll_device_xa;extern struct xarray dpll_pin_xa;extern struct mutex dpll_device_xa_lock;
drivers/dpll/dpll_netlink.c +12 -22
@@ -134,18 +134,11 @@ dpll_msg_add_pin_on_dpll_state(struct sk_buff *msg, const struct dpll_pin *pin,static int dpll_msg_add_pin_direction (struct sk_buff *msg,const struct dpll_pin *pin, +struct dpll_pin_ref *ref,struct netlink_ext_ack *extack) {enum dpll_pin_direction direction; -struct dpll_pin_ref *ref; -unsigned long i; -xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { -if (ref && ref->ops && ref->dpll) -break ; - } -if (!ref || !ref->ops || !ref->dpll) -return -ENODEV ;if (!ref->ops->direction_get)return -EOPNOTSUPP ;if (ref->ops->direction_get (pin, ref->dpll, &direction, extack))
@@ -158,19 +151,12 @@ dpll_msg_add_pin_direction(struct sk_buff *msg, const struct dpll_pin *pin,static int dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, -struct netlink_ext_ack *extack,bool dump_any_freq) +struct dpll_pin_ref *ref,struct netlink_ext_ack *extack, +bool dump_any_freq) {enum dpll_pin_freq_supp fs; -struct dpll_pin_ref *ref; -unsigned long i;u32 freq; -xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { -if (ref && ref->ops && ref->dpll) -break ; - } -if (!ref || !ref->ops || !ref->dpll) -return -ENODEV ;if (!ref->ops->frequency_get)return -EOPNOTSUPP ;if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))
@@ -325,10 +311,11 @@ dpll_cmd_pin_on_dpll_get(struct sk_buff *msg, struct dpll_pin *pin,return -EMSGSIZE ;if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities))return -EMSGSIZE ; - ret =dpll_msg_add_pin_direction (msg, pin, extack); + ref =dpll_xa_ref_dpll_first (&pin->dpll_refs); + ret =dpll_msg_add_pin_direction (msg, pin, ref, extack);if (ret)return ret; - ret =dpll_msg_add_pin_freq (msg, pin, extack, true); + ret =dpll_msg_add_pin_freq (msg, pin, ref, extack, true);if (ret && ret != -EOPNOTSUPP )return ret; ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll);
@@ -355,6 +342,7 @@ static int __dpll_cmd_pin_dump_one(struct sk_buff *msg, struct dpll_pin *pin, struct netlink_ext_ack *extack, bool dump_dpll) { + struct dpll_pin_ref *ref;int ret;if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))
@@ -363,10 +351,11 @@ __dpll_cmd_pin_dump_one(struct sk_buff *msg, struct dpll_pin *pin,return -EMSGSIZE ;if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type))return -EMSGSIZE ; - ret =dpll_msg_add_pin_direction (msg, pin, extack); + ref =dpll_xa_ref_dpll_first (&pin->dpll_refs); + ret =dpll_msg_add_pin_direction (msg, pin, ref, extack);if (ret)return ret; - ret =dpll_msg_add_pin_freq (msg, pin, extack, true); + ret =dpll_msg_add_pin_freq (msg, pin, ref, extack, true);if (ret && ret != -EOPNOTSUPP )return ret; ret =dpll_msg_add_pins_on_pin (msg, pin, extack);
@@ -920,7 +909,8 @@ dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, ret =dpll_msg_add_temp (msg, dpll,NULL );break ;case DPLL_A_PIN_FREQUENCY : - ret =dpll_msg_add_pin_freq (msg, pin,NULL , false); + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); + ret =dpll_msg_add_pin_freq (msg, pin, ref,NULL , false);break ;case DPLL_A_PIN_PRIO : ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll);
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 4/7 dpll: allow to call pin register multiple times
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Some devices allow to control a single dpll pin instance over multiple channels. In case of mlx5 for example, one dpll pin could be controlled over multiple PFs that reside on a single ASIC. These are equal. Allow each to register/unregister dpll pin. Use the first ops and priv always as the is no difference in between those and the rest. Replace the existing reference counting by the list of registrations as they serve the same purpose.
--- drivers/dpll/dpll_core.c | 212 +++++++++++++++------- drivers/dpll/dpll_core.h | 13 +- drivers/dpll/dpll_netlink.c | 69 ++++--- drivers/net/ethernet/intel/ice/ice_dpll.c | 18 +- include/linux/dpll.h | 8 +- 5 files changed, 220 insertions(+), 100 deletions(-)
drivers/dpll/dpll_core.c +150 -62
@@ -73,6 +73,19 @@ dpll_device_get_by_name(const char *bus_name, const char *device_name)return ret; } +static struct dpll_pin_registration * +dpll_pin_registration_find (struct dpll_pin_ref *ref, +const struct dpll_pin_ops *ops,void *priv) +{ +struct dpll_pin_registration *reg; + +list_for_each_entry (reg, &ref->registration_list, list) { +if (reg->ops == ops && reg->priv == priv) +return reg; + } +return NULL ; +} +/** * dpll_xa_ref_pin_add - add pin reference to a given xarray * @xa_pins: dpll_pin_ref xarray holding pins
@@ -80,8 +93,8 @@ dpll_device_get_by_name(const char *bus_name, const char *device_name)* @ops: ops for a pin * @priv: pointer to private data of owner * -* Allocate and create reference of a pin or increase refcount on existing pin -* reference on given xarray. +* Allocate and create reference of a pin and enlist a registration +* structure storing ops and priv pointers of a caller registant. * * Return: * * 0 on success
@@ -91,31 +104,48 @@ static int dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv) { + struct dpll_pin_registration *reg;struct dpll_pin_ref *ref; +bool ref_exists = false;unsigned long i;u32 idx;int ret;xa_for_each (xa_pins, i, ref) { -if (ref->pin == pin) { -refcount_inc (&ref->refcount); -return 0 ; +if (ref->pin != pin) +continue ; + reg =dpll_pin_registration_find (ref, ops, priv); +if (reg) +return -EEXIST ; + ref_exists = true; +break ; + } + +if (!ref_exists) { + ref =kzalloc (sizeof (*ref),GFP_KERNEL ); +if (!ref) +return -ENOMEM ; + ref->pin = pin; +INIT_LIST_HEAD (&ref->registration_list); + ret =xa_alloc (xa_pins, &idx, ref, xa_limit_16b,GFP_KERNEL ); +if (ret) { +kfree (ref); +return ret; } } - ref =kzalloc (sizeof (*ref),GFP_KERNEL ); -if (!ref) + reg =kzalloc (sizeof (*reg),GFP_KERNEL ); +if (!reg) { +if (!ref_exists) +kfree (ref);return -ENOMEM ; - ref->pin = pin; - ref->ops = ops; - ref->priv = priv; - ret =xa_alloc (xa_pins, &idx, ref, xa_limit_16b,GFP_KERNEL ); -if (!ret) -refcount_set (&ref->refcount,1 ); -else -kfree (ref); + } + reg->ops = ops; + reg->priv = priv; -return ret; +list_add_tail (®->list, &ref->registration_list); + +return 0 ; }/**
@@ -124,25 +154,31 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin,* @pin: pointer to a pin * * Decrement refcount of existing pin reference on given xarray. -* If all references are dropped, delete the reference and free its memory. +* If all registrations are lifted delete the reference and free its memory. * * Return: * * 0 on success * * -EINVAL if reference to a pin was not found */ -static int dpll_xa_ref_pin_del (struct xarray *xa_pins,struct dpll_pin *pin) +static int dpll_xa_ref_pin_del (struct xarray *xa_pins,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv) { +struct dpll_pin_registration *reg;struct dpll_pin_ref *ref;unsigned long i;xa_for_each (xa_pins, i, ref) { -if (ref->pin == pin) { -if (refcount_dec_and_test (&ref->refcount)) { -xa_erase (xa_pins, i); -kfree (ref); - } -return 0 ; - } +if (ref->pin != pin) +continue ; + reg =dpll_pin_registration_find (ref, ops, priv); +if (WARN_ON (!reg)) +return -EINVAL ; +list_del (®->list); +kfree (reg); +xa_erase (xa_pins, i); +WARN_ON (!list_empty (&ref->registration_list)); +kfree (ref); +return 0 ; }return -EINVAL ;
@@ -191,30 +227,48 @@ static int dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct dpll_device *dpll, const struct dpll_pin_ops *ops, void *priv) { + struct dpll_pin_registration *reg;struct dpll_pin_ref *ref; +bool ref_exists = false;unsigned long i;u32 idx;int ret;xa_for_each (xa_dplls, i, ref) { -if (ref->dpll == dpll) { -refcount_inc (&ref->refcount); -return 0 ; +if (ref->dpll != dpll) +continue ; + reg =dpll_pin_registration_find (ref, ops, priv); +if (reg) +return -EEXIST ; + ref_exists = true; +break ; + } + +if (!ref_exists) { + ref =kzalloc (sizeof (*ref),GFP_KERNEL ); +if (!ref) +return -ENOMEM ; + ref->dpll = dpll; +INIT_LIST_HEAD (&ref->registration_list); + ret =xa_alloc (xa_dplls, &idx, ref, xa_limit_16b,GFP_KERNEL ); +if (ret) { +kfree (ref); +return ret; } } - ref =kzalloc (sizeof (*ref),GFP_KERNEL ); -if (!ref) + + reg =kzalloc (sizeof (*reg),GFP_KERNEL ); +if (!reg) { +if (!ref_exists) +kfree (ref);return -ENOMEM ; - ref->dpll = dpll; - ref->ops = ops; - ref->priv = priv; - ret =xa_alloc (xa_dplls, &idx, ref, xa_limit_16b,GFP_KERNEL ); -if (!ret) -refcount_set (&ref->refcount,1 ); -else -kfree (ref); + } + reg->ops = ops; + reg->priv = priv; -return ret; +list_add_tail (®->list, &ref->registration_list); + +return 0 ; }/**
@@ -226,19 +280,25 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct dpll_device *dpll,* If all references are dropped, delete the reference and free its memory. */ static void -dpll_xa_ref_dpll_del (struct xarray *xa_dplls,struct dpll_device *dpll) +dpll_xa_ref_dpll_del (struct xarray *xa_dplls,struct dpll_device *dpll, +const struct dpll_pin_ops *ops,void *priv) { +struct dpll_pin_registration *reg;struct dpll_pin_ref *ref;unsigned long i;xa_for_each (xa_dplls, i, ref) { -if (ref->dpll == dpll) { -if (refcount_dec_and_test (&ref->refcount)) { -xa_erase (xa_dplls, i); -kfree (ref); - } -break ; - } +if (ref->dpll != dpll) +continue ; + reg =dpll_pin_registration_find (ref, ops, priv); +if (WARN_ON (!reg)) +return ; +list_del (®->list); +kfree (reg); +xa_erase (xa_dplls, i); +WARN_ON (!list_empty (&ref->registration_list)); +kfree (ref); +return ; } }
@@ -639,7 +699,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,return ret; ref_pin_del: -dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +dpll_xa_ref_pin_del (&dpll->pin_refs, pin, ops, priv); rclk_free:kfree (pin->rclk_dev_name);return ret;
@@ -681,27 +741,31 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,EXPORT_SYMBOL_GPL (dpll_pin_register);static void -__dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +__dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv) { -dpll_xa_ref_pin_del (&dpll->pin_refs, pin); -dpll_xa_ref_dpll_del (&pin->dpll_refs, dpll); +dpll_xa_ref_pin_del (&dpll->pin_refs, pin, ops, priv); +dpll_xa_ref_dpll_del (&pin->dpll_refs, dpll, ops, priv); }/** * dpll_pin_unregister - deregister dpll pin from dpll device * @dpll: registered dpll pointer * @pin: pointer to a pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner * * Note: It does not free the memory */ -int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv) {if (WARN_ON (xa_empty (&dpll->pin_refs)))return -ENOENT ;mutex_lock (&dpll_device_xa_lock);mutex_lock (&dpll_pin_xa_lock); -__dpll_pin_unregister (dpll, pin); +__dpll_pin_unregister (dpll, pin, ops, priv);mutex_unlock (&dpll_pin_xa_lock);mutex_unlock (&dpll_device_xa_lock);
@@ -763,12 +827,12 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,xa_for_each (&parent->dpll_refs, i, ref) {if (i < stop) {mutex_lock (&dpll_device_xa_lock); -__dpll_pin_unregister (ref->dpll, pin); +__dpll_pin_unregister (ref->dpll, pin, ops, priv);mutex_unlock (&dpll_device_xa_lock); } }refcount_dec (&pin->refcount); -dpll_xa_ref_pin_del (&pin->parent_refs, parent); +dpll_xa_ref_pin_del (&pin->parent_refs, parent, ops, priv); unlock:mutex_unlock (&dpll_pin_xa_lock);return ret;
@@ -779,20 +843,23 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_register);* dpll_pin_on_pin_unregister - deregister dpll pin from a parent pin * @parent: pointer to a parent pin * @pin: pointer to a pin +* @ops: ops for a dpll pin +* @priv: pointer to private information of owner * * Note: It does not free the memory */ -void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin) +void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv) {struct dpll_pin_ref *ref;unsigned long i;mutex_lock (&dpll_device_xa_lock);mutex_lock (&dpll_pin_xa_lock); -dpll_xa_ref_pin_del (&pin->parent_refs, parent); +dpll_xa_ref_pin_del (&pin->parent_refs, parent, ops, priv);refcount_dec (&pin->refcount);xa_for_each (&pin->dpll_refs, i, ref) { -__dpll_pin_unregister (ref->dpll, pin); +__dpll_pin_unregister (ref->dpll, pin, ops, priv);dpll_pin_parent_notify (ref->dpll, pin, parent,DPLL_A_PIN_IDX ); }
@@ -859,6 +926,17 @@ const struct dpll_device_ops *dpll_device_ops(struct dpll_device *dpll)return reg->ops; } +static struct dpll_pin_registration * +dpll_pin_registration_first (struct dpll_pin_ref *ref) +{ +struct dpll_pin_registration *reg; + + reg =list_first_entry_or_null (&ref->registration_list, + struct dpll_pin_registration, list); +WARN_ON (!reg); +return reg; +} +/** * dpll_pin_on_dpll_priv - get the dpll device private owner data * @dpll: registered dpll pointer
@@ -869,13 +947,14 @@ const struct dpll_device_ops *dpll_device_ops(struct dpll_device *dpll)void *dpll_pin_on_dpll_priv (const struct dpll_device *dpll,const struct dpll_pin *pin) { +struct dpll_pin_registration *reg;struct dpll_pin_ref *ref; ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);if (!ref)return NULL ; - -return ref->priv; + reg =dpll_pin_registration_first (ref); +return reg->priv; }EXPORT_SYMBOL_GPL (dpll_pin_on_dpll_priv);
@@ -889,16 +968,25 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_dpll_priv);void *dpll_pin_on_pin_priv (const struct dpll_pin *parent,const struct dpll_pin *pin) { +struct dpll_pin_registration *reg;struct dpll_pin_ref *ref; ref =dpll_xa_ref_pin_find ((struct xarray *)&pin->parent_refs, parent);if (!ref)return NULL ; - -return ref->priv; + reg =dpll_pin_registration_first (ref); +return reg->priv; }EXPORT_SYMBOL_GPL (dpll_pin_on_pin_priv); +const struct dpll_pin_ops *dpll_pin_ops (struct dpll_pin_ref *ref) +{ +struct dpll_pin_registration *reg; + + reg =dpll_pin_registration_first (ref); +return reg->ops; +} +static int __init dpll_init (void ) {int ret;
drivers/dpll/dpll_core.h +8 -5
@@ -73,27 +73,30 @@ struct dpll_pin {refcount_t refcount; }; +struct dpll_pin_registration { +struct list_head list; +const struct dpll_pin_ops *ops; +void *priv; +}; +/** * struct dpll_pin_ref - structure for referencing either dpll or pins * @dpll: pointer to a dpll * @pin: pointer to a pin -* @ops: ops for a dpll pin -* @priv: pointer to private information of owner **/ struct dpll_pin_ref {union {struct dpll_device *dpll;struct dpll_pin *pin; }; -struct dpll_pin_ops *ops; -void *priv; -refcount_t refcount; +struct list_head registration_list; };const struct dpll_device_ops *dpll_device_ops (struct dpll_device *dpll);struct dpll_device *dpll_device_get_by_id (int id);struct dpll_device *dpll_device_get_by_name (const char *bus_name,const char *dev_name); +const struct dpll_pin_ops *dpll_pin_ops (struct dpll_pin_ref *ref);struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx);struct dpll_pin_ref *dpll_xa_ref_pin_find (struct xarray *xa_refs,const struct dpll_pin *pin);
drivers/dpll/dpll_netlink.c +44 -25
181 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_dpll.c +12 -6
@@ -1194,7 +1194,8 @@ ice_dpll_release_rclk_pin(struct ice_pf *pf) parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;if (!parent)continue ; -dpll_pin_on_pin_unregister (parent, rclk->pin); +dpll_pin_on_pin_unregister (parent, rclk->pin, + &ice_dpll_rclk_ops, pf); }dpll_pin_put (rclk->pin); rclk->pin =NULL ;
@@ -1202,6 +1203,7 @@ ice_dpll_release_rclk_pin(struct ice_pf *pf)/** * ice_dpll_release_pins - release pin's from dplls registered in subsystem +* @pf: board private structure * @dpll_eec: dpll_eec dpll pointer * @dpll_pps: dpll_pps dpll pointer * @pins: pointer to pins array
@@ -1215,7 +1217,7 @@ ice_dpll_release_rclk_pin(struct ice_pf *pf)* * positive - number of errors encounterd on pin's deregistration. */ static int -ice_dpll_release_pins (struct dpll_device *dpll_eec, +ice_dpll_release_pins (struct ice_pf *pf,struct dpll_device *dpll_eec,struct dpll_device *dpll_pps,struct ice_dpll_pin *pins,int count,bool cgu) {
@@ -1226,12 +1228,16 @@ ice_dpll_release_pins(struct dpll_device *dpll_eec,if (p && !IS_ERR_OR_NULL (p->pin)) {if (cgu && dpll_eec) { - ret =dpll_pin_unregister (dpll_eec, p->pin); + ret =dpll_pin_unregister (dpll_eec, p->pin, + &ice_dpll_source_ops, + pf);if (ret) err++; }if (cgu && dpll_pps) { - ret =dpll_pin_unregister (dpll_pps, p->pin); + ret =dpll_pin_unregister (dpll_pps, p->pin, + &ice_dpll_source_ops, + pf);if (ret) err++; }
@@ -1532,7 +1538,7 @@ static void ice_dpll_release_all(struct ice_pf *pf, bool cgu)mutex_lock (&pf->dplls.lock);ice_dpll_release_rclk_pin (pf); - ret =ice_dpll_release_pins (de->dpll, dp->dpll, d->inputs, + ret =ice_dpll_release_pins (pf, de->dpll, dp->dpll, d->inputs, d->num_inputs, cgu);mutex_unlock (&pf->dplls.lock);if (ret)
@@ -1540,7 +1546,7 @@ static void ice_dpll_release_all(struct ice_pf *pf, bool cgu) "source pins release dplls err=%d\n", ret);if (cgu) {mutex_lock (&pf->dplls.lock); - ret =ice_dpll_release_pins (de->dpll, dp->dpll, d->outputs, + ret =ice_dpll_release_pins (pf, de->dpll, dp->dpll, d->outputs, d->num_outputs, cgu);mutex_unlock (&pf->dplls.lock);if (ret)
include/linux/dpll.h +6 -2
@@ -211,6 +211,8 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* dpll_pin_unregister - deregister pin from a dpll device * @dpll: pointer to dpll object to deregister pin from * @pin: pointer to allocated pin object being deregistered from dpll +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner * * Deregister previously registered pin object from a dpll device. *
@@ -219,7 +221,8 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* * -ENXIO - given pin was not registered with this dpll device, * * -EINVAL - pin pointer is not valid. */ -int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin); +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv);/** * dpll_pin_put - drop reference to a pin acquired with dpll_pin_get
@@ -268,7 +271,8 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,* * -ENOMEM - failed to allocate memory, * * -EEXIST - pin already registered with this parent pin, */ -void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin); +void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin, +const struct dpll_pin_ops *ops,void *priv);/** * dpll_device_notify - notify on dpll device change
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 5/7 dpll: export dpll_pin_notify()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Export dpll_pin_notify() as it is needed to be called from drivers.
--- drivers/dpll/dpll_netlink.c | 1 + drivers/dpll/dpll_netlink.h | 3 --- include/linux/dpll.h | 4 ++++ 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/dpll/dpll_netlink.c +1 -0
@@ -1056,6 +1056,7 @@ int dpll_pin_notify(struct dpll_device *dpll, struct dpll_pin *pin, {return dpll_send_event_change (dpll, pin,NULL , attr); } +EXPORT_SYMBOL_GPL (dpll_pin_notify);int dpll_pin_parent_notify (struct dpll_device *dpll,struct dpll_pin *pin,struct dpll_pin *parent,enum dplla attr)
drivers/dpll/dpll_netlink.h +0 -3
@@ -20,9 +20,6 @@ int dpll_notify_device_create(struct dpll_device *dpll);*/ int dpll_notify_device_delete (struct dpll_device *dpll); -int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, -enum dplla attr); -int dpll_pin_parent_notify (struct dpll_device *dpll,struct dpll_pin *pin,struct dpll_pin *parent,enum dplla attr);
include/linux/dpll.h +4 -0
@@ -287,5 +287,9 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,*/ int dpll_device_notify (struct dpll_device *dpll,enum dplla attr); +int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, +enum dplla attr); + +#endif
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 6/7 netdev: expose DPLL pin handle for netdevice
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In case netdevice represents a SyncE port, the user needs to understand the connection between netdevice and associated DPLL pin. There might me multiple netdevices pointing to the same pin, in case of VF/SF implementation.
Add a IFLA Netlink attribute to nest the DPLL pin handle, similar to how is is implemented for devlink port. Add a struct dpll_pin pointer to netdev and protect access to it by RTNL. Expose netdev_dpll_pin_set() and netdev_dpll_pin_clear() helpers to the drivers so they can set/clear the DPLL pin relationship to netdev.
Note that during the lifetime of struct dpll_pin the handle fields do not change. Therefore it is save to access them lockless. It is drivers responsibility to call netdev_dpll_pin_clear() before dpll_pin_put().
--- drivers/dpll/dpll_netlink.c | 28 ++++++++++++++++++++++---- include/linux/dpll.h | 20 +++++++++++++++++++ include/linux/netdevice.h | 7 +++++++ include/uapi/linux/if_link.h | 2 ++ net/core/dev.c | 20 +++++++++++++++++++ net/core/rtnetlink.c | 38 ++++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 4 deletions(-)
drivers/dpll/dpll_netlink.c +24 -4
@@ -302,6 +302,24 @@ dpll_msg_add_pin_dplls(struct sk_buff *msg, struct dpll_pin *pin,return ret; } +size_t dpll_msg_pin_handle_size (struct dpll_pin *pin) +{ +// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX +// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION +return nla_total_size (4 );/* DPLL_A_PIN_IDX */ +} +EXPORT_SYMBOL_GPL (dpll_msg_pin_handle_size); + +int dpll_msg_add_pin_handle (struct sk_buff *msg,struct dpll_pin *pin) +{ +// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX +// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_msg_add_pin_handle); + static int dpll_cmd_pin_on_dpll_get(struct sk_buff *msg, struct dpll_pin *pin, struct dpll_device *dpll,
@@ -310,8 +328,9 @@ dpll_cmd_pin_on_dpll_get(struct sk_buff *msg, struct dpll_pin *pin,struct dpll_pin_ref *ref;int ret; -if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) -return -EMSGSIZE ; + ret =dpll_msg_add_pin_handle (msg, pin); +if (ret) +return ret;if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description))return -EMSGSIZE ;if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type))
@@ -352,8 +371,9 @@ __dpll_cmd_pin_dump_one(struct sk_buff *msg, struct dpll_pin *pin,struct dpll_pin_ref *ref;int ret; -if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) -return -EMSGSIZE ; + ret =dpll_msg_add_pin_handle (msg, pin); +if (ret) +return ret;if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description))return -EMSGSIZE ;if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type))
include/linux/dpll.h +20 -0
@@ -92,6 +92,26 @@ enum dpll_pin_freq_supp { DPLL_PIN_FREQ_SUPP_MAX = (__DPLL_PIN_FREQ_SUPP_MAX - 1) }; +#if IS_ENABLED (CONFIG_DPLL ) + +size_t dpll_msg_pin_handle_size (struct dpll_pin *pin); + +int dpll_msg_add_pin_handle (struct sk_buff *msg,struct dpll_pin *pin); + +#else + +static inline size_t dpll_msg_pin_handle_size (struct dpll_pin *pin) +{ +return 0 ; +} + +static inline int dpll_msg_add_pin_handle (struct sk_buff *msg,struct dpll_pin *pin) +{ +return 0 ; +} + +#endif +/** * dpll_device_get - find or create dpll_device object * @clock_id: a system unique number for a device
include/linux/netdevice.h +7 -0
@@ -34,6 +34,7 @@#include <linux/rculist.h> #include <linux/workqueue.h> #include <linux/dynamic_queue_limits.h> +#include <linux/dpll.h> #include <net/net_namespace.h> #ifdef CONFIG_DCB
@@ -2403,6 +2404,10 @@ struct net_device {struct rtnl_hw_stats64 *offload_xstats_l3;struct devlink_port *devlink_port; + +#if IS_ENABLED (CONFIG_DPLL ) +struct dpll_pin *dpll_pin; +#endif };#define to_net_dev (d) container_of(d, struct net_device, dev)
@@ -3939,6 +3944,8 @@ int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);int dev_get_port_parent_id (struct net_device *dev,struct netdev_phys_item_id *ppid,bool recurse);bool netdev_port_same_parent_id (struct net_device *a,struct net_device *b); +void netdev_dpll_pin_set (struct net_device *dev,struct dpll_pin *dpll_pin); +void netdev_dpll_pin_clear (struct net_device *dev);struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev,bool *again);struct sk_buff *dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev,struct netdev_queue *txq,int *ret);
include/uapi/linux/if_link.h +2 -0
@@ -377,6 +377,8 @@ enum {IFLA_GSO_IPV4_MAX_SIZE ,IFLA_GRO_IPV4_MAX_SIZE , +IFLA_DPLL_PIN , + __IFLA_MAX };
net/core/dev.c +20 -0
@@ -8949,6 +8949,26 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b) }EXPORT_SYMBOL (netdev_port_same_parent_id); +static void netdev_dpll_pin_assign (struct net_device *dev,struct dpll_pin *dpll_pin) +{ +rtnl_lock (); + dev->dpll_pin = dpll_pin; +rtnl_unlock (); +} + +void netdev_dpll_pin_set (struct net_device *dev,struct dpll_pin *dpll_pin) +{ +WARN_ON (!dpll_pin); +netdev_dpll_pin_assign (dev, dpll_pin); +} +EXPORT_SYMBOL (netdev_dpll_pin_set); + +void netdev_dpll_pin_clear (struct net_device *dev) +{ +netdev_dpll_pin_assign (dev,NULL ); +} +EXPORT_SYMBOL (netdev_dpll_pin_clear); +/** * dev_change_proto_down - set carrier according to proto_down. *
net/core/rtnetlink.c +38 -0
@@ -1052,6 +1052,16 @@ static size_t rtnl_devlink_port_size(const struct net_device *dev)return size; } +static size_t rtnl_dpll_pin_size (const struct net_device *dev) +{ +size_t size =nla_total_size (0 );/* nest IFLA_DPLL_PIN */ + +if (dev->dpll_pin) + size +=dpll_msg_pin_handle_size (dev->dpll_pin); + +return size; +} + static noinline size_t if_nlmsg_size(const struct net_device *dev,u32 ext_filter_mask) {
@@ -1108,6 +1118,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +rtnl_prop_list_size (dev) +nla_total_size (MAX_ADDR_LEN )/* IFLA_PERM_ADDRESS */ +rtnl_devlink_port_size (dev) + +rtnl_dpll_pin_size (dev) +0 ; }
@@ -1769,6 +1780,30 @@ static int rtnl_fill_devlink_port(struct sk_buff *skb,return ret; } +static int rtnl_fill_dpll_pin (struct sk_buff *skb, +const struct net_device *dev) +{ +struct nlattr *dpll_pin_nest; +int ret; + + dpll_pin_nest =nla_nest_start (skb,IFLA_DPLL_PIN ); +if (!dpll_pin_nest) +return -EMSGSIZE ; + +if (dev->dpll_pin) { + ret =dpll_msg_add_pin_handle (skb, dev->dpll_pin); +if (ret <0 ) + goto nest_cancel; + } + +nla_nest_end (skb, dpll_pin_nest); +return 0 ; + +nest_cancel: +nla_nest_cancel (skb, dpll_pin_nest); +return ret; +} + static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, struct net *src_net, int type, u32 pid, u32 seq, u32 change,
@@ -1911,6 +1946,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,if (rtnl_fill_devlink_port (skb, dev)) goto nla_put_failure; +if (rtnl_fill_dpll_pin (skb, dev)) + goto nla_put_failure; +nlmsg_end (skb, nlh);return 0 ;
Signature · 1 line
2.39.0
Jiri Pirko
maintainerPATCH 7/7 mlx5: Implement SyncE support using DPLL infrastructure
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Implement SyncE support using newly introduced DPLL support. Make sure that each PFs/VFs/SFs probed with appropriate capability will spawn a dpll auxiliary device and register appropriate dpll device and pin instances.
--- .../net/ethernet/mellanox/mlx5/core/Kconfig | 8 + .../net/ethernet/mellanox/mlx5/core/Makefile | 3 + drivers/net/ethernet/mellanox/mlx5/core/dev.c | 17 + .../net/ethernet/mellanox/mlx5/core/dpll.c | 429 ++++++++++++++++++ include/linux/mlx5/driver.h | 2 + include/linux/mlx5/mlx5_ifc.h | 59 ++- 6 files changed, 517 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/dpll.c
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +8 -0
@@ -188,3 +188,11 @@ config MLX5_SF_MANAGER port is managed through devlink. A subfunction supports RDMA, netdevice and vdpa device. It is similar to a SRIOV VF but it doesn't require SRIOV support. + +config MLX5_DPLL + tristate "Mellanox 5th generation network adapters (ConnectX series) DPLL support" + depends on NETDEVICES && ETHERNET && PCI && MLX5_CORE + select DPLL + help + DPLL support in Mellanox Technologies ConnectX NICs. +
drivers/net/ethernet/mellanox/mlx5/core/Makefile +3 -0
@@ -123,3 +123,6 @@ mlx5_core-$(CONFIG_MLX5_SF) += sf/vhca_event.o sf/dev/dev.o sf/dev/driver.o irq_ # SF manager # mlx5_core-$(CONFIG_MLX5_SF_MANAGER) += sf/cmd.o sf/hw_table.o sf/devlink.o + +obj-$(CONFIG_MLX5_DPLL) += mlx5_dpll.o +mlx5_dpll-y := dpll.o
drivers/net/ethernet/mellanox/mlx5/core/dev.c +17 -0
@@ -227,6 +227,19 @@ static bool is_ib_enabled(struct mlx5_core_dev *dev)return err ? false : val.vbool; } +static bool is_dpll_supported (struct mlx5_core_dev *dev) +{ +if (!IS_ENABLED (CONFIG_MLX5_DPLL )) +return false; + +if (!MLX5_CAP_MCAM_REG2 (dev, synce_registers)) { +mlx5_core_warn (dev,"Missing SyncE capability\n" ); +return false; + } + +return true; +} +enum {MLX5_INTERFACE_PROTOCOL_ETH ,MLX5_INTERFACE_PROTOCOL_ETH_REP ,
@@ -236,6 +249,8 @@ enum {MLX5_INTERFACE_PROTOCOL_MPIB ,MLX5_INTERFACE_PROTOCOL_VNET , + + MLX5_INTERFACE_PROTOCOL_DPLL, }; static const struct mlx5_adev_device {
@@ -258,6 +273,8 @@ static const struct mlx5_adev_device { .is_supported = &is_ib_rep_supported }, [MLX5_INTERFACE_PROTOCOL_MPIB] = { .suffix = "multiport", .is_supported = &is_mp_supported }, + [MLX5_INTERFACE_PROTOCOL_DPLL] = { .suffix = "dpll", + .is_supported = &is_dpll_supported }, };int mlx5_adev_idx_alloc (void )
drivers/net/ethernet/mellanox/mlx5/core/dpll.c new file +429 -0
429 lines not on this page · raw message
include/linux/mlx5/driver.h +2 -0
@@ -154,6 +154,8 @@ enum {MLX5_REG_MCC =0x9062 ,MLX5_REG_MCDA =0x9063 ,MLX5_REG_MCAM =0x907f , +MLX5_REG_MSECQ =0x9155 , +MLX5_REG_MSEES =0x9156 ,MLX5_REG_MIRC =0x9162 ,MLX5_REG_SBCAM =0xB01F , MLX5_REG_RESOURCE_DUMP = 0xC000,
include/linux/mlx5/mlx5_ifc.h +58 -1
69 lines not on this page · raw message
Signature · 1 line
2.39.0
Vadim Fedorenko
maintainerRe: [patch dpll-rfc 0/7] dpll: initial patchset extension by mlx5 implementation
In reply to Jiri PirkoQuoted 11 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Hi.
This is extending your patchset. Basically, I do this on top of the changes I pointed out during review. For example patch #6 is exposing pin handle which is going to change, etc (there, I put a note).
First 5 patches are just needed dependencies and you can squash them into your patch/patches. Last two patches should go in separatelly.
Quoted 7 lines
Please note that the patch #6 is replacing the need to pass the rclk device during pin registration by putting a link between netdev and dpll pin.
Please merge this into your dpll patchset and include it in the next RFC. Thanks!
Hi Jiri!
Thanks for the patch set. It looks like it covers some changes that I have also done to address the comments. I'll try to combine everything in a couple of days and will re-spin series and we restart review process. I think that there are open question still in the conversation which were not answered.
Best,
Vadim
Jiri Pirko
maintainerRe: [patch dpll-rfc 0/7] dpll: initial patchset extension by mlx5 implementation
Quoted 20 lines · Tue, Mar 28, 2023 at 06:36:13PM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
Hi.
This is extending your patchset. Basically, I do this on top of the changes I pointed out during review. For example patch #6 is exposing pin handle which is going to change, etc (there, I put a note).
First 5 patches are just needed dependencies and you can squash them into your patch/patches. Last two patches should go in separatelly.
Quoted 7 lines
Please note that the patch #6 is replacing the need to pass the rclk device during pin registration by putting a link between netdev and dpll pin.
Please merge this into your dpll patchset and include it in the next RFC. Thanks!
Quoted 6 lines
Hi Jiri!
Thanks for the patch set. It looks like it covers some changes that I have also done to address the comments. I'll try to combine everything in a couple of days and will re-spin series and we restart review process. I think that there are open question still in the conversation which were not answered.
I hope I didn't miss anything. I believe I replied to every comment. Please tell me if not.
Thanks!
Quoted 3 lines
Best,
Vadim