dpll: single-owner pins, board wiring as pin links
Subsystems (6)
Ivan Vecera
reviewercover dpll: single-owner pins, board wiring as pin links
Sorry for the size, I know 19 patches is over the netdev limit of 15. For the RFC I kept each step in its own patch, so all the changes are easy to see one by one. The final series will squash some of them.
In the thread on "dpll: do not serialize driver callbacks under global dpll_lock" [1], Jakub was not convinced: relations between DPLL objects are hard to follow, objects of one driver plug into objects of another, and the driver API should be much more "dummy-proof" [2]. Vadim agreed and asked to step back, because the subsystem was shaped to model one NIC family and is getting more complex for its next generation [3]. Jiri agreed with Vadim [4]. This RFC removes the sharing of pin objects between drivers instead of picking a lock scheme for it.
Problems in DPLL today
Model:
- One pin, two owners: on E825, ice registers zl3073x output pins with its DPLLs (c191b319f208) and hangs its recovered clock pins under zl3073x inputs, so one request runs callbacks of two drivers.
- Per-registration needs on one object: a state change bypass for firmware node pins (521b6d5de08d), zl3073x inputs typed MUX although the mux is in the NIC, one pin that is both an output and an input.
Driver API:
- ice waits for the zl3073x pins on a notifier chain (2be467588d6b) and holds references to them, so probe order and lifetime are its job.
- Core code exists only for that: the owner check exception, the notifier source id (0bf47f722fa9), the owner ref selection (2c1bd78dc8e2, 84e85c325e5e) and a cached module name.
- Callbacks run under dpll_lock and must use __dpll_*_change_ntf(), notifications go out without driver locks. Only comments say so.
Locking:
- dpll_lock serializes every callback of every driver. With a dual NAC E825 and a ZL80132B, ice DPLL requests during zl3073x ToD writes took a median of 1448 ms, at most 3.9 s (idle 0.1 ms). zl3073x is narrowing its waits, but callbacks that wait for hardware stay (planned zl3073x resync, up to 1 s; mlx5 commands, 60 s timeout).
- No lock scheme fits pins shared between drivers. Options A-E from the thread each cost something, from callbacks invisible to lockdep (A) to one domain for everything connected, the global lock again (D).
Fragility: 13 fixes in a year in the (un)register, on-pin and notification paths, e.g. 32239d600236, df0ba51ccf87, 1a2292101c0d.
All of these come from one dpll_pin being both a pad of a chip and a wire on the board, so two drivers end up sharing one object.
Proposal
- I1: a pin is registered only with DPLLs and parent pins of its owner, the module and clock_id it was created with. The core enforces it.
- I2: so a request about an object runs only its owner's callbacks.
- I3: a wire between pins of two devices is a link. The driver of one end adds it to its own pin with dpll_pin_link_add() and names the other end by its firmware node, so no driver holds a pin of another.
- I4: a link is only a wire, with no state and no callbacks. pin-get reports DPLL_A_PIN_LINK with the peer id for both pins while both are registered, the peer is notified when one of them comes or goes.
On E825 this covers the TX reference (zl3073x output to the ice TXC DPLL), the time reference (zl3073x output to the ice TSPLL) and the recovered clock crossbar: two ice mux devices, one per CGU output, with the port pins as inputs and outputs linked with zl3073x inputs.
This removes the model and driver API problems and options A-E. The code of one fix is gone, the cross-owner cases behind other fixes cannot happen. The stall and unenforced rules stay, per-owner locks become possible. Not addressed: a netdev names only its recovered clock pin.
For a driver
TX reference and recovered clock, before and after (the first PF of the adapter creates the muxes):
pin = fwnode_dpll_pin_find(fwnode, &tracker); /* or wait for it */ dpll_pin_register(txc_dpll, pin, &txclk_ops, priv); dpll_pin_on_pin_register(zl_input, rclk_pin, &rclk_ops, priv); pin = dpll_pin_get(txc_clock_id, idx, THIS_MODULE, &prop, &tracker); dpll_pin_link_add(pin, fwnode); dpll_pin_register(txc_dpll, pin, &txclk_ops, priv); dpll_device_register(mux, DPLL_TYPE_GENERIC, &mux_ops, adapter_mux); dpll_pin_link_add(mux_out, rclk_fwnode); dpll_pin_register(mux, mux_out, &out_ops, adapter_mux); dpll_pin_register(mux, rclk_pin, &rclk_ops, priv);
For user space (ids from the GNR-D below)
The zl3073x output OUT3 (id 36) no longer lists the ice TXC DPLLs as parents; it is linked with the EXT_SYNCE pins of the eight PFs, which are inputs of their TXC DPLLs:
{'id': 36, 'module-name': 'zl3073x', 'package-label': 'OUT3',
'parent-device': [{'parent-id': 11, 'direction': 'output', ...}], 'link': [{'id': 4}, {'id': 8}, ..., {'id': 26}]}
{'id': 4, 'module-name': 'ice', 'board-label': 'EXT_SYNCE',
'parent-device': [{'parent-id': 1, 'direction': 'input', ...}], 'link': [{'id': 36}]}
The port pin of eno1np0 (id 2) had the zl3073x inputs as parent pins. It is now an input of the muxes 2 and 3, and RCLK0 (id 0) is linked with REF1P (id 29):
{'id': 2, 'module-name': 'ice', 'type': 'synce-eth-port',
'parent-device': [{'parent-id': 2, 'state': 'connected', ...},
{'parent-id': 3, 'state': 'disconnected', ...}]}{'id': 0, 'board-label': 'RCLK0', 'link': [{'id': 29}], ...}
pin-set {"id": 2, "parent-device": {"parent-id": 2, "state":
"connected"}} routes the port and disconnects the one routed before. The clock-id of the port pin is the adapter index instead of the DSN. The E825 pins exist without zl3073x too.
What it removes
Core: everything under driver API above, cross-owner on-pin registration is rejected. ice: the notifier work, the firmware node parent pins and the foreign pin references. The tolerance for a DPLL without registrations (33f016b23a21) stays: on E810 the recovered clock pins of the PFs without the CGU stay registered with the DPLLs of the PF with the CGU when that PF goes first.
core (dpll_core, dpll_netlink, dpll.h) +224/-173 ice +727/-503 KUnit tests and build +563 docs, spec, uapi +69
exported symbols 21 -> 20 (+2 for KUnit only), ops unchanged
ice grows, as the PFs of an ASIC share the muxes and the adapter records the routing. An E825 with N ports had N+1 DPLL devices (TXC per port, TSPLL) and 2N ice pins, now N+3 devices and 3N+3 ice pins. A mux is not a DPLL, but the generic type is for devices outside the EEC and PPS classes, and two driver-local devices replace two core mechanisms:
cross-owner on-pin registration and a MUX parent of another driver.
Locking series: v3 is on hold until the direction is agreed. On top of this the rule for drivers becomes "your callbacks run under your lock", and options A-E are not needed.
Status: W=1 build at every patch, full build, sparse, kernel-doc, ynl-regen, htmldocs, KUnit (12 tests, UML, lockdep). Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B: links, routing of all eight ports with notifications, the recovered clock at the zl3073x inputs, PF reset, CORER, GLOBR, PF unbind and bind, zl3073x reload and the TX reference; the test script and its results are in [5]. Not
tested: EMPR, and the recovered clock of the second NAC, whose ports had no link. Prepared with the help of an AI coding assistant.
Questions
1. The E825 TX reference and recovered clock views change. Fine, or should netlink translate the old view?
2. Is a mux fine as a generic DPLL device that reports locked while it routes a port, and are N+3 DPLL devices for N ports fine?
3. The two muxes share module, clock-id and type, so device-id-get finds neither. Is finding them through their output pins enough?
4. The firmware still types the zl3073x inputs as MUX. Leave it?
5. The ice pin does not know the frequency on the wire. Omit it, as now, or read it from a firmware node property?
6. Should the locking series be rebased on top of this?
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/[email protected]/
[4] https://lore.kernel.org/netdev/awMP9Gj3Xhia0ZeI@FV6GYCPJ69/
[5] https://gist.github.com/ivecera/b31f67adac6deac318719bbe0f282707
Ivan Vecera (19):
dpll: add pin links
dpll: report pin links
dpll: notify linked pins when a pin is registered or unregistered
dpll: add KUnit tests for pin links
ice: dpll: use own pins for the TX and time references
ice: dpll: drop the filter of notifications from own registrations
dpll: register pins only with a DPLL of their owner
dpll: drop the state change exception for pins with a firmware node
dpll: drop the source clock id from pin notifications
dpll: drop device events from the in-kernel notifier
dpll: drop the cached module name of a pin
ice: dpll: track the E825 recovered clock routing in the adapter
ice: dpll: register the E825 recovered clock muxes as DPLL devices
ice: dpll: route the E825 recovered clock through the mux devices
dpll: register pins only with a parent pin of their owner
dpll: drop the in-kernel notifier chain
dpll: require a registered DPLL for pin registration
dpll: drop the owner reference selection of pins
dpll: add KUnit tests for the pin owner checks
Documentation/driver-api/dpll.rst | 53 + Documentation/netlink/specs/dpll.yaml | 15 + drivers/dpll/.kunitconfig | 5 + drivers/dpll/Kconfig | 18 + drivers/dpll/Makefile | 2 + drivers/dpll/dpll_core.c | 253 ++-- drivers/dpll/dpll_core.h | 20 +- drivers/dpll/dpll_netlink.c | 82 +- drivers/dpll/dpll_netlink.h | 10 +- drivers/dpll/tests/dpll_kunit.c | 538 ++++++++ drivers/net/ethernet/intel/ice/ice_adapter.c | 3 +- drivers/net/ethernet/intel/ice/ice_adapter.h | 33 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1175 ++++++++++-------- drivers/net/ethernet/intel/ice/ice_dpll.h | 11 +- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 8 - include/linux/dpll.h | 32 +- include/uapi/linux/dpll.h | 1 + 17 files changed, 1583 insertions(+), 676 deletions(-) create mode 100644 drivers/dpll/.kunitconfig create mode 100644 drivers/dpll/tests/dpll_kunit.c
base-commit: 2388bb763e323442f4dd8189238ac0c5f334c4a0
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 1/19 dpll: add pin links
A pin is a pad of the chip whose driver registers it. When a board wires a pad of one chip to a pad of another, for example an output of an external DPLL to the TX reference input of a network controller, a driver now registers the pin of the other driver with its own DPLL. The pin then has two owners and a request about it runs callbacks of both drivers.
Add a link that describes such a wire instead. A driver adds it to its own pin with dpll_pin_link_add() and names the pin at the other end by its firmware node, which the driver of that pin sets with dpll_pin_fwnode_set(). The link holds only the firmware node, so the driver needs no pointer to a pin of another driver and that pin does not have to exist yet.
Links are added before the pin is registered and are released together with the pin. Adding an existing link returns -EEXIST, also on a registered pin, so each user of a shared pin can add the same link. The next patch reports links to user space.
--- drivers/dpll/dpll_core.c | 71 ++++++++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 12 +++++++ include/linux/dpll.h | 2 ++ 3 files changed, 85 insertions(+)
drivers/dpll/dpll_core.c +71 -0
@@ -147,6 +147,16 @@ static void __dpll_pin_hold(struct dpll_pin *pin, dpll_tracker *tracker)static void dpll_pin_idx_free (u32 pin_idx);static void dpll_pin_prop_free (struct dpll_pin_properties *prop); +static void dpll_pin_links_free (struct dpll_pin *pin) +{ +struct dpll_pin_link *link, *tmp; + +list_for_each_entry_safe (link, tmp, &pin->links, list) { +fwnode_handle_put (link->peer); +kfree (link); + } +} +static void __dpll_pin_put (struct dpll_pin *pin,dpll_tracker *tracker) {dpll_pin_tracker_free (pin, tracker);
@@ -155,6 +165,7 @@ static void __dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker)xa_destroy (&pin->dpll_refs);xa_destroy (&pin->parent_refs);xa_destroy (&pin->ref_sync_pins); +dpll_pin_links_free (pin);dpll_pin_prop_free (&pin->prop);fwnode_handle_put (pin->fwnode);dpll_pin_idx_free (pin->pin_idx);
@@ -665,6 +676,7 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module,if (ret) goto err_pin_prop;refcount_set (&pin->refcount,1 ); +INIT_LIST_HEAD (&pin->links);xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC );xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC );xa_init_flags (&pin->ref_sync_pins,XA_FLAGS_ALLOC );
@@ -838,6 +850,65 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode, }EXPORT_SYMBOL_GPL (fwnode_dpll_pin_find); +static bool dpll_pin_has_link (const struct dpll_pin *pin, +const struct fwnode_handle *peer) +{ +struct dpll_pin_link *link; + +list_for_each_entry (link, &pin->links, list) +if (link->peer == peer) +return true; + +return false; +} + +/** +* dpll_pin_link_add - add a link from a pin to another pin +* @pin: pointer to a dpll pin +* @peer: firmware node of the pin at the other end +* +* Describe a fixed board connection between @pin and the pin of another +* device that its driver associates with @peer by dpll_pin_fwnode_set(). +* The other pin does not need to exist yet. The link is kept until @pin is +* released. An existing link is reported also when @pin is registered, so +* each user of a shared pin can add the same link. +* +* Context: Acquires a lock (dpll_lock). Must be called before @pin is +* registered. +* Return: +* * 0 on success +* * -EEXIST if @pin already has a link to @peer +* * -EBUSY if @pin is already registered +* * -ENOMEM if the link cannot be allocated +*/ +int dpll_pin_link_add (struct dpll_pin *pin,struct fwnode_handle *peer) +{ +struct dpll_pin_link *link; +int ret =0 ; + +mutex_lock (&dpll_lock); +if (dpll_pin_has_link (pin, peer)) { + ret = -EEXIST ; + goto unlock; + } +if (WARN_ON (xa_get_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED ))) { + ret = -EBUSY ; + goto unlock; + } + link =kzalloc_obj (*link); +if (!link) { + ret = -ENOMEM ; + goto unlock; + } + link->peer =fwnode_handle_get (peer); +list_add_tail (&link->list, &pin->links); +unlock: +mutex_unlock (&dpll_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_link_add); +static int __dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin,const struct dpll_pin_ops *ops,void *priv,void *cookie)
drivers/dpll/dpll_core.h +12 -0
@@ -47,6 +47,7 @@ struct dpll_device {* @module: module of creator * @module_name: module name of creator * @fwnode: optional reference to firmware node +* @links: links to other pins (struct dpll_pin_link) * @dpll_refs: hold referencees to dplls pin was registered with * @parent_refs: hold references to parent pins pin was registered with * @ref_sync_pins: hold references to pins for Reference SYNC feature
@@ -62,6 +63,7 @@ struct dpll_pin {struct module *module;char module_name[MODULE_NAME_LEN ];struct fwnode_handle *fwnode; +struct list_head links;struct xarray dpll_refs;struct xarray parent_refs;struct xarray ref_sync_pins;
@@ -71,6 +73,16 @@ struct dpll_pin {struct rcu_head rcu; }; +/** +* struct dpll_pin_link - wire between a pin and another pin +* @list: entry in the links list of the pin +* @peer: firmware node of the pin at the other end +**/ +struct dpll_pin_link { +struct list_head list; +struct fwnode_handle *peer; +}; +/** * struct dpll_pin_ref - structure for referencing either dpll or pins * @dpll: pointer to a dpll
include/linux/dpll.h +2 -0
@@ -301,6 +301,8 @@ void dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker);void dpll_pin_fwnode_set (struct dpll_pin *pin,struct fwnode_handle *fwnode); +int dpll_pin_link_add (struct dpll_pin *pin,struct fwnode_handle *peer); +int dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin,const struct dpll_pin_ops *ops,void *priv);
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 2/19 dpll: report pin links
In reply to Ivan VeceraReport the links of a pin in pin-get with a new multi-attr nest DPLL_A_PIN_LINK, which carries the id of the pin at the other end. The link is reported for both pins, the one that has it and the one whose firmware node it names, and only while both of them are registered.
DPLL_A_PIN_LINK is a nest rather than a repeated u32, so that attributes of a link, for example the delay of the board trace, can be added later. The message layout is uAPI, so a flat u32 could not be extended.
Links name a pin by its firmware node, so dpll_pin_fwnode_set() now refuses to change the node of a registered pin, which would change the reported links without a notification. Setting the same node again, as zl3073x does for each of its DPLLs, still works.
Pins with no links and no firmware node are not affected.
--- Documentation/driver-api/dpll.rst | 38 +++++++++++++++++++++++++++ Documentation/netlink/specs/dpll.yaml | 15 +++++++++++ drivers/dpll/dpll_core.c | 26 +++++++++++++++--- drivers/dpll/dpll_core.h | 1 + drivers/dpll/dpll_netlink.c | 30 ++++++++++++++++++++- include/uapi/linux/dpll.h | 1 + 6 files changed, 107 insertions(+), 4 deletions(-)
Documentation/driver-api/dpll.rst +38 -0
@@ -350,6 +350,41 @@ bound to only one other pin at any given time. ``DPLL_A_PIN_STATE`` state of Reference SYNC connection ============================== ========================================== +Pin links +========= + +A pin represents a pad of the device whose driver registers it. When the +board connects a pad of one device to a pad of another one, for example an +output of a DPLL chip to a reference clock input of a network controller, +the driver of one of them describes the connection with +dpll_pin_link_add() on its own pin. The link names the pin at the other +end by its firmware node, which the driver of that pin sets with +dpll_pin_fwnode_set(). Each driver registers only its own pins and the +drivers may probe in any order. + +While both pins are registered, ``DPLL_CMD_PIN_GET`` reports the link for +each of them with the id of the pin at the other end: + + ============================== ========================================== + ``DPLL_A_PIN_LINK`` nested attribute for each linked pin + ``DPLL_A_PIN_ID`` id of the pin at the other end + ============================== ========================================== + +For example, an output of a DPLL chip wired to an input of a network +controller:: + + 'pin': [{ + 'id': 7, + 'module-name': 'zl3073x', + 'parent-device': [{'parent-id': 0, 'direction': 'output', ...}], + 'link': [{'id': 21}] + }, { + 'id': 21, + 'module-name': 'ice', + 'parent-device': [{'parent-id': 5, 'direction': 'input', ...}], + 'link': [{'id': 7}] + }] + Configuration commands group ============================
@@ -467,6 +502,9 @@ according to attribute purpose. ``DPLL_A_PIN_CAPABILITIES`` attr bitmask of pin capabilities ``DPLL_A_PIN_MEASURED_FREQUENCY`` attr measured frequency of an input pin in mHz + ``DPLL_A_PIN_LINK`` nested attr for each pin linked + with the pin + ``DPLL_A_PIN_ID`` attr id of the linked pin ==================================== ================================== ==================================== =================================
Documentation/netlink/specs/dpll.yaml +15 -0
@@ -542,6 +542,14 @@ attribute-sets: Operational state of the pin with respect to its parent DPLL device. Unlike state (which reflects the administrative intent), operstate reflects the actual hardware status. + - + name: link + type: nest + multi-attr: true + nested-attributes: pin-link + doc: | + A pin connected with this pin on the board, usually a pin of + another device. Reported while both pins are registered. - name: pin-parent-device
@@ -591,6 +599,12 @@ attribute-sets: name: id - name: state + - + name: pin-link + subset-of: pin + attributes: + - + name: id operations: enum-name: dpll_cmd
@@ -741,6 +755,7 @@ operations: - esync-pulse - reference-sync - measured-frequency + - link dump: reply: *pin-attrs
drivers/dpll/dpll_core.c +23 -3
@@ -806,13 +806,19 @@ EXPORT_SYMBOL_GPL(dpll_pin_put);* @pin: pointer to a dpll pin * @fwnode: firmware node handle * -* Set firmware node handle for the given dpll pin. +* Set firmware node handle for the given dpll pin. Links name pins by their +* firmware node, so the node of a registered pin must not change. +* +* Context: Acquires a lock (dpll_lock) */ void dpll_pin_fwnode_set (struct dpll_pin *pin,struct fwnode_handle *fwnode) {mutex_lock (&dpll_lock); -fwnode_handle_put (pin->fwnode);/* Drop fwnode previously set */ - pin->fwnode =fwnode_handle_get (fwnode); +if (pin->fwnode != fwnode && + !WARN_ON (xa_get_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED ))) { +fwnode_handle_put (pin->fwnode);/* Drop fwnode previously set */ + pin->fwnode =fwnode_handle_get (fwnode); + }mutex_unlock (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_pin_fwnode_set);
@@ -862,6 +868,20 @@ static bool dpll_pin_has_link(const struct dpll_pin *pin,return false; } +/** +* dpll_pins_linked - check if two pins are linked +* @a: pointer to a dpll pin +* @b: pointer to another dpll pin +* +* Context: Caller must hold dpll_lock. +* Return: true if either pin has a link to the firmware node of the other +*/ +bool dpll_pins_linked (const struct dpll_pin *a,const struct dpll_pin *b) +{ +return (b->fwnode &&dpll_pin_has_link (a, b->fwnode)) || + (a->fwnode &&dpll_pin_has_link (b, a->fwnode)); +} +/** * dpll_pin_link_add - add a link from a pin to another pin * @pin: pointer to a dpll pin
drivers/dpll/dpll_core.h +1 -0
@@ -108,6 +108,7 @@ struct dpll_device *dpll_device_get_by_id(int id);struct dpll_pin_ref *dpll_pin_own_dpll_ref_first (struct dpll_pin *pin);const struct dpll_pin_ops *dpll_pin_ops (struct dpll_pin_ref *ref);struct dpll_pin_ref *dpll_xa_ref_dpll_first (struct xarray *xa_refs); +bool dpll_pins_linked (const struct dpll_pin *a,const struct dpll_pin *b);extern struct xarray dpll_device_xa;extern struct xarray dpll_pin_xa;extern struct mutex dpll_lock;
drivers/dpll/dpll_netlink.c +29 -1
@@ -709,6 +709,32 @@ dpll_msg_add_pin_dplls(struct sk_buff *msg, struct dpll_pin *pin,return ret; } +static int dpll_msg_add_pin_links (struct sk_buff *msg,struct dpll_pin *pin) +{ +struct dpll_pin *pos; +struct nlattr *nest; +unsigned long i; + +/* Only a pin with links or with a firmware node can be linked */ +if (list_empty (&pin->links) && !pin->fwnode) +return 0 ; +xa_for_each_marked (&dpll_pin_xa, i, pos,DPLL_REGISTERED ) { +if (pos == pin || !dpll_pins_linked (pin, pos) || + !dpll_pin_available (pos)) +continue ; + nest =nla_nest_start (msg,DPLL_A_PIN_LINK ); +if (!nest) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ID , pos->id)) { +nla_nest_cancel (msg, nest); +return -EMSGSIZE ; + } +nla_nest_end (msg, nest); + } + +return 0 ; +} +static int dpll_cmd_pin_get_one (struct sk_buff *msg,struct dpll_pin *pin,struct netlink_ext_ack *extack)
@@ -780,8 +806,10 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin, ret =dpll_msg_add_pin_dplls (msg, pin, extack); else ret =dpll_msg_add_pin_parents (msg, pin, ref, extack); +if (ret) +return ret; -return ret; +return dpll_msg_add_pin_links (msg, pin); } static int
include/uapi/linux/dpll.h +1 -0
@@ -289,6 +289,7 @@ enum dpll_a_pin {DPLL_A_PIN_FRACTIONAL_FREQUENCY_OFFSET_PPT ,DPLL_A_PIN_MEASURED_FREQUENCY ,DPLL_A_PIN_OPERSTATE , +DPLL_A_PIN_LINK , __DPLL_A_PIN_MAX,DPLL_A_PIN_MAX = (__DPLL_A_PIN_MAX -1 )
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 3/19 dpll: notify linked pins when a pin is registered or unregistered
In reply to Ivan VeceraA link is reported only while the pins at both ends are registered. When a pin gets its first registration or loses its last one, send a change notification for every registered pin linked with it, so user space sees the link appear and disappear at both ends.
The notifications follow the registration of the pin. A link also disappears from the report when the last registered dpll device of the pin goes away, so a pin with a link or a firmware node has to be unregistered before its dpll devices, as zl3073x and ice do. The documentation says so.
The notifications are sent from one helper, under dpll_lock like the other notifications. The message about a linked pin is built with the callbacks of its owner, also when another driver registers the pin at the other end.
--- Documentation/driver-api/dpll.rst | 6 ++++++ drivers/dpll/dpll_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
Documentation/driver-api/dpll.rst +6 -0
@@ -370,6 +370,12 @@ each of them with the id of the pin at the other end: ``DPLL_A_PIN_ID`` id of the pin at the other end ============================== ========================================== +When a pin gets its first registration or loses its last one, the +subsystem sends ``DPLL_CMD_PIN_CHANGE_NTF`` for the registered pins +linked with it. A pin with a link or a firmware node has to be +unregistered before the dpll devices it is registered with, otherwise +its links disappear without a notification. + For example, an output of a DPLL chip wired to an input of a network controller::
drivers/dpll/dpll_core.c +24 -0
@@ -929,10 +929,30 @@ int dpll_pin_link_add(struct dpll_pin *pin, struct fwnode_handle *peer) }EXPORT_SYMBOL_GPL (dpll_pin_link_add); +/** +* dpll_pin_links_ntf - notify the pins linked with a pin +* @pin: pin that was registered or unregistered +* +* A link is reported only while the pins at both ends are registered, so +* send a change notification for every registered pin linked with @pin. +*/ +static void dpll_pin_links_ntf (struct dpll_pin *pin) +{ +struct dpll_pin *pos; +unsigned long i; + +if (list_empty (&pin->links) && !pin->fwnode) +return ; +xa_for_each_marked (&dpll_pin_xa, i, pos,DPLL_REGISTERED ) +if (pos != pin &&dpll_pins_linked (pin, pos)) +__dpll_pin_change_ntf (pos); +} +static int __dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin,const struct dpll_pin_ops *ops,void *priv,void *cookie) { +bool registered;int ret; ret =dpll_xa_ref_pin_add (&dpll->pin_refs, pin, ops, priv, cookie);
@@ -941,8 +961,11 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, ret =dpll_xa_ref_dpll_add (&pin->dpll_refs, dpll, ops, priv, cookie);if (ret) goto ref_pin_del; + registered =xa_get_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED );xa_set_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED );dpll_pin_create_ntf (pin, dpll->clock_id); +if (!registered) +dpll_pin_links_ntf (pin);return ret;
@@ -1035,6 +1058,7 @@ __dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin,if (xa_empty (&pin->dpll_refs)) {dpll_pin_ref_sync_pair_del (pin->id);xa_clear_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED ); +dpll_pin_links_ntf (pin); } }
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 4/19 dpll: add KUnit tests for pin links
In reply to Ivan VeceraAdd a KUnit suite with a mock driver of two owners that differ inclock_id: a pin of one owner with a firmware node and a pin of the other owner with a link to it. The tests check that:
- the link is reported for both pins only while both are registered, whichever of them is registered first
- the pin at the other end gets a change notification whenever the link appears or disappears
- a pin keeps its link when it is unregistered and registered again
- for a pin registered with two DPLLs of its owner, only the first registration and the last unregistration change the link
- a pin with neither a link nor a firmware node is not linked or notified
- a duplicate link is rejected, also on a registered pin, and a new link cannot be added to a registered pin
The tests build the pin message with dpll_cmd_pin_get_one() under dpll_lock, so both are exported for KUnit.
Run them with:
tools/testing/kunit/kunit.py run --kunitconfig=drivers/dpll
--- drivers/dpll/.kunitconfig | 5 + drivers/dpll/Kconfig | 16 ++ drivers/dpll/Makefile | 2 + drivers/dpll/dpll_core.c | 2 + drivers/dpll/dpll_netlink.c | 4 +- drivers/dpll/dpll_netlink.h | 6 + drivers/dpll/tests/dpll_kunit.c | 419 ++++++++++++++++++++++++++++++++ 7 files changed, 453 insertions(+), 1 deletion(-) create mode 100644 drivers/dpll/.kunitconfig create mode 100644 drivers/dpll/tests/dpll_kunit.c
drivers/dpll/.kunitconfig new file +5 -0
@@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_NET=y +CONFIG_DPLL_KUNIT_TEST=y +CONFIG_DEBUG_KERNEL=y +CONFIG_PROVE_LOCKING=y
drivers/dpll/Kconfig +16 -0
@@ -23,6 +23,22 @@ config DPLL_REFCNT_TRACKER If unsure, say N. +config DPLL_KUNIT_TEST + tristate "KUnit tests for DPLL core" if !KUNIT_ALL_TESTS + depends on KUNIT && NET + select DPLL + default KUNIT_ALL_TESTS + help + KUnit tests for the DPLL core. They use a mock driver to check + that links between pins of two devices are reported and notified + while the pins at both ends are registered. + + The mock devices and pins are registered with the DPLL subsystem, + so user space sees them and their notifications while the tests + run. + + If unsure, say N. + source "drivers/dpll/zl3073x/Kconfig" endmenu
drivers/dpll/Makefile +2 -0
@@ -8,4 +8,6 @@ dpll-y += dpll_core.o dpll-y += dpll_netlink.o dpll-y += dpll_nl.o +obj-$(CONFIG_DPLL_KUNIT_TEST) += tests/dpll_kunit.o + obj-$(CONFIG_ZL3073X) += zl3073x/
drivers/dpll/dpll_core.c +2 -0
@@ -8,6 +8,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <kunit/visibility.h> #include <linux/device.h> #include <linux/err.h> #include <linux/idr.h>
@@ -21,6 +22,7 @@/* Mutex lock to protect DPLL subsystem devices and pins */ DEFINE_MUTEX (dpll_lock); +EXPORT_SYMBOL_IF_KUNIT (dpll_lock);DEFINE_XARRAY_FLAGS (dpll_device_xa,XA_FLAGS_ALLOC );DEFINE_XARRAY_FLAGS (dpll_pin_xa,XA_FLAGS_ALLOC );
drivers/dpll/dpll_netlink.c +3 -1
@@ -6,6 +6,7 @@* Copyright (c) 2023 Intel and affiliates * */ +#include <kunit/visibility.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/netdevice.h>
@@ -735,7 +736,7 @@ static int dpll_msg_add_pin_links(struct sk_buff *msg, struct dpll_pin *pin)return 0 ; } -static int +VISIBLE_IF_KUNIT intdpll_cmd_pin_get_one (struct sk_buff *msg,struct dpll_pin *pin,struct netlink_ext_ack *extack) {
@@ -811,6 +812,7 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,return dpll_msg_add_pin_links (msg, pin); } +EXPORT_SYMBOL_IF_KUNIT (dpll_cmd_pin_get_one); static int dpll_device_get_one(struct dpll_device *dpll, struct sk_buff *msg,
drivers/dpll/dpll_netlink.h +6 -0
@@ -11,3 +11,9 @@ int dpll_device_delete_ntf(struct dpll_device *dpll);int dpll_pin_create_ntf (struct dpll_pin *pin,u64 src_clock_id);int dpll_pin_delete_ntf (struct dpll_pin *pin,u64 src_clock_id); + +#if IS_ENABLED (CONFIG_KUNIT ) +/* For KUnit tests, call with dpll_lock held for a registered pin */ +int dpll_cmd_pin_get_one (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack); +#endif
drivers/dpll/tests/dpll_kunit.c new file +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 5/19 ice: dpll: use own pins for the TX and time references
In reply to Ivan VeceraOn E825 the TXC DPLL of each PF uses the zl3073x output pin wired to its SyncE TX reference input, and the TSPLL DPLL of the PF that owns the source timer uses the zl3073x output pin wired to its time reference input. The driver finds these pins by firmware node, registers them with its own DPLLs and uses the DPLL notifier to wait for them and to follow their removal.
Register own pins instead, EXT_SYNCE next to EXT_EREF0 with the TXC DPLL and TIME_REF with the TSPLL DPLL, and link each of them with the zl3073x pin through the same firmware node. The pins keep the callbacks they had, so the hardware is programmed as before. The notifier now serves the recovered clock pin only.
The pins and EXT_EREF0 get dynamic pin indices. Without a valid MAC address the TXC and TSPLL DPLLs fall back to the clock_id of the PF, and fixed indices would make TIME_REF the EXT_EREF0 pin and EXT_SYNCE a pin shared by the PFs of a NAC.
What user space sees on E825 changes:
- the zl3073x pins list only zl3073x DPLLs as parent devices and report a link to EXT_SYNCE of each PF or to TIME_REF
- the SyncE TX reference is selected by the state of EXT_SYNCE on the TXC DPLL and the time reference by the state of TIME_REF on the TSPLL DPLL, instead of the state of the zl3073x pins on those DPLLs
- EXT_SYNCE and TIME_REF report no frequency
- both pins exist also when the zl3073x driver is not loaded
Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL: the EXT_SYNCE pins of the eight PFs and the TIME_REF pin report their links to the zl3073x outputs and stay without them while zl3073x is unloaded, and connecting EXT_SYNCE on the TXC DPLL of a PF locks the DPLL.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 276 ++++++++++------------ drivers/net/ethernet/intel/ice/ice_dpll.h | 2 +- 2 files changed, 121 insertions(+), 157 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +120 -156
@@ -85,6 +85,8 @@ static const char * const pin_type_name[] = {static const char *const ice_dpll_sw_pin_sma[] = {"SMA1" ,"SMA2" };static const char *const ice_dpll_sw_pin_ufl[] = {"U.FL1" ,"U.FL2" };static const char *const ice_dpll_ext_eref_pin ="EXT_EREF0" ; +static const char *const ice_dpll_ext_synce_pin ="EXT_SYNCE" ; +static const char *const ice_dpll_time_ref_pin ="TIME_REF" ;static const char *const ice_dpll_fwnode_ext_synce ="clk_ref_synce" ;static const char *const ice_dpll_fwnode_time_ref ="time_ref" ;
@@ -3792,8 +3794,6 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) struct ice_dpll_pin_work, work);struct ice_dpll_pin *pin, *parent = w->pin; -bool is_tx_synce_parent = false; -bool is_tspll_time_ref = false;struct ice_pf *pf = parent->pf;bool is_rclk_parent = false;int ret;
@@ -3811,14 +3811,7 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) } } - is_tx_synce_parent = -ice_dpll_fwnode_eq (parent->fwnode, - pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX ].fwnode); - - is_tspll_time_ref = -ice_dpll_fwnode_eq (parent->fwnode, pf->dplls.tspll_in.fwnode); - -if (!is_rclk_parent && !is_tx_synce_parent && !is_tspll_time_ref) +if (!is_rclk_parent) goto out;switch (w->action) {
@@ -3837,40 +3830,15 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) goto out; } -if (is_rclk_parent) { -/* Register rclk pin via on-pin relationship */ - pin = &pf->dplls.rclk; - ret =dpll_pin_on_pin_register (parent->pin, pin->pin, - &ice_dpll_rclk_ops, pin); -if (ret) { -dev_err (ice_pf_to_dev (pf), -"RCLK pin register failed: %pe\n" , -ERR_PTR (ret)); - goto drop_parent_ref; - } - }else if (is_tx_synce_parent) { -/* Register TX-CLK SYNCE pin directly to TXC DPLL */ - pin = &pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX ]; - ret =dpll_pin_register (pf->dplls.txc.dpll, pin->pin, - &ice_dpll_txclk_ops, pin); -if (ret) { -dev_err (ice_pf_to_dev (pf), -"TX SYNCE pin register failed: %pe\n" , -ERR_PTR (ret)); - goto drop_parent_ref; - } - }else if (is_tspll_time_ref) { -/* Register TIME_REF pin directly to TSPLL DPLL */ - ret =dpll_pin_register (pf->dplls.tspll.dpll, - parent->pin, - &ice_dpll_tspll_in_ops, - parent); -if (ret) { -dev_err (ice_pf_to_dev (pf), -"TSPLL TIME_REF pin register failed: %pe\n" , -ERR_PTR (ret)); - goto drop_parent_ref; - } +/* Register rclk pin via on-pin relationship */ + pin = &pf->dplls.rclk; + ret =dpll_pin_on_pin_register (parent->pin, pin->pin, + &ice_dpll_rclk_ops, pin); +if (ret) { +dev_err (ice_pf_to_dev (pf), +"RCLK pin register failed: %pe\n" , +ERR_PTR (ret)); + goto drop_parent_ref; }break ;case DPLL_PIN_DELETED :
@@ -3879,22 +3847,10 @@ static void ice_dpll_pin_notify_work(struct work_struct *work) goto out; } -if (is_rclk_parent) { -/* Unregister rclk pin */ - pin = &pf->dplls.rclk; -dpll_pin_on_pin_unregister (parent->pin, pin->pin, - &ice_dpll_rclk_ops, pin); - }else if (is_tx_synce_parent) { -/* Unregister TX-CLK SYNCE pin from TXC DPLL */ - pin = &pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX ]; -dpll_pin_unregister (pf->dplls.txc.dpll, pin->pin, - &ice_dpll_txclk_ops, pin); - }else if (is_tspll_time_ref) { -/* Unregister TIME_REF pin from TSPLL DPLL */ -dpll_pin_unregister (pf->dplls.tspll.dpll, - parent->pin, - &ice_dpll_tspll_in_ops, parent); - } +/* Unregister rclk pin */ + pin = &pf->dplls.rclk; +dpll_pin_on_pin_unregister (parent->pin, pin->pin, + &ice_dpll_rclk_ops, pin); drop_parent_ref:/* Drop fwnode pin reference */ dpll_pin_put (parent->pin, &parent->tracker);
@@ -4067,43 +4023,36 @@ ice_dpll_deinit_fwnode_pins(struct ice_pf *pf, struct ice_dpll_pin *pins,destroy_workqueue (pf->dplls.wq); } -static int ice_dpll_deinit_txclk_pins (struct ice_pf *pf,bool flush) +static void ice_dpll_deinit_txclk_pins (struct ice_pf *pf) { -struct ice_dpll_pin *synce_pin = &pf->dplls.txclks[E825_EXT_SYNCE_PIN_IDX ]; -struct ice_dpll *dt = &pf->dplls.txc; +struct ice_dplls *d = &pf->dplls; +int i; -ice_dpll_stop_fwnode_pin_activity (synce_pin, flush); -ice_dpll_unregister_pins (dt->dpll, pf->dplls.txclks, - &ice_dpll_txclk_ops, -ARRAY_SIZE (pf->dplls.txclks)); -ice_dpll_release_pins (&pf->dplls.txclks[E825_EXT_EREF_PIN_IDX ],1 ); -/* ice_dpll_release_pins() puts the pin but does not clear the slot, -* unlike ice_dpll_release_fwnode_pin() used for SYNCE below. NULL it -* so a late ice_txclk_get_pin() returns NULL rather than a dangling -* pointer. +ice_dpll_unregister_pins (d->txc.dpll, d->txclks, &ice_dpll_txclk_ops, +ARRAY_SIZE (d->txclks)); +ice_dpll_release_pins (d->txclks,ARRAY_SIZE (d->txclks)); +/* ice_dpll_release_pins() puts the pins but does not clear the slots. +* Clear them so a late ice_txclk_get_pin() returns NULL rather than a +* dangling pointer. */ - pf->dplls.txclks[E825_EXT_EREF_PIN_IDX ].pin =NULL ; -ice_dpll_release_fwnode_pin (synce_pin); -return 0 ; +for (i =0 ; i <ARRAY_SIZE (d->txclks); i++) + d->txclks[i].pin =NULL ; }/** -* ice_dpll_deinit_tspll_pins - deinitialize TSPLL fwnode pin +* ice_dpll_deinit_tspll_pins - deinitialize TSPLL pin * @pf: board private structure * -* Stop notifier activity and release the TIME_REF fwnode pin, unregistering -* it from the TSPLL DPLL if it was registered. +* Unregister the TIME_REF pin from the TSPLL DPLL and release it. */ static void ice_dpll_deinit_tspll_pins (struct ice_pf *pf) {struct ice_dpll_pin *time_ref = &pf->dplls.tspll_in; -struct ice_dpll *tp = &pf->dplls.tspll; -ice_dpll_stop_fwnode_pin_activity (time_ref, true); -if (!IS_ERR_OR_NULL (time_ref->pin)) -dpll_pin_unregister (tp->dpll, time_ref->pin, - &ice_dpll_tspll_in_ops, time_ref); -ice_dpll_release_fwnode_pin (time_ref); +ice_dpll_unregister_pins (pf->dplls.tspll.dpll, time_ref, + &ice_dpll_tspll_in_ops,1 ); +ice_dpll_release_pins (time_ref,1 ); + time_ref->pin =NULL ; }/**
@@ -4129,7 +4078,7 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu)if (ice_pf_src_tmr_owned (pf) &&test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags))ice_dpll_deinit_tspll_pins (pf); -ice_dpll_deinit_txclk_pins (pf, true); +ice_dpll_deinit_txclk_pins (pf);ice_dpll_deinit_fwnode_pins (pf, pf->dplls.inputs,0 ); }if (cgu) {
@@ -4173,6 +4122,34 @@ ice_dpll_pin_node_get(struct ice_pf *pf, const char *name)return fwnode_find_reference (fwnode,"dpll-pins" , index); } +/** +* ice_dpll_pin_link_add - link a pin with the pin wired to it +* @pf: board private structure +* @pin: pin of the driver +* @name: name of the firmware node of the pin at the other end +* +* Return: +* * 0 - success +* * negative - failure reason +*/ +static int ice_dpll_pin_link_add (struct ice_pf *pf,struct dpll_pin *pin, +const char *name) +{ +struct fwnode_handle *fwnode; +int ret; + + fwnode =ice_dpll_pin_node_get (pf, name); +if (IS_ERR (fwnode)) { +dev_err (ice_pf_to_dev (pf), +"Failed to find %s firmware node: %pe\n" , name, fwnode); +return -ENODEV ; + } + ret =dpll_pin_link_add (pin, fwnode); +fwnode_handle_put (fwnode); + +return ret; +} +static int ice_dpll_init_fwnode_pin (struct ice_dpll_pin *pin,const char *name) {
@@ -4266,77 +4243,58 @@ ice_dpll_init_fwnode_pins(struct ice_pf *pf, struct ice_dpll_pin *pins,return ret; } -static int ice_dpll_init_txclk_pins (struct ice_pf *pf,int start_idx) +/** +* ice_dpll_init_txclk_pins - init and register TX reference clock pins +* @pf: board private structure +* +* Get the EXT_EREF0 and EXT_SYNCE pins, link EXT_SYNCE with the pin wired to +* it and register both pins with the TXC DPLL. +* +* Return: +* * 0 - success +* * negative - initialization failure reason +*/ +static int ice_dpll_init_txclk_pins (struct ice_pf *pf) { -struct ice_dpll_pin *ref_pin = pf->dplls.txclks; +struct ice_dpll_pin *pins = pf->dplls.txclks;struct ice_dpll *txc = &pf->dplls.txc;u64 clock_id; -int ret; +int ret, i; -/* EXT_EREF0 is a non-fwnode pin; its clock_id must match the TX-CLK -* DPLL device clock_id (see dpll_pin_register()). +/* The clock_id of the pins must match the TXC DPLL device clock_id +* (see dpll_pin_register()). Without a valid MAC address it is the +* clock_id of the other DPLLs of the NIC, so the pin indices are +* dynamic to keep the pins distinct. */ clock_id =ice_generate_dpll_clock_id (pf, txc,DPLL_TYPE_GENERIC ); - -/* Configure EXT_EREF0 pin */ - ret =ice_dpll_get_pins (pf, ref_pin, start_idx,1 , clock_id); + ret =ice_dpll_get_pins (pf, pins,DPLL_PIN_IDX_UNSPEC , +ICE_DPLL_TXCLK_NUM_MAX , clock_id);if (ret)return ret; - ret =dpll_pin_register (txc->dpll, ref_pin->pin, &ice_dpll_txclk_ops, - ref_pin); + ret =ice_dpll_pin_link_add (pf, pins[E825_EXT_SYNCE_PIN_IDX ].pin, + ice_dpll_fwnode_ext_synce);if (ret) - goto err_release_ext_eref; - -/* -* Configure EXT_SYNCE pin (fwnode-backed). -* The pin may not yet be available; in that case registration -* will be deferred via the notifier path. -*/ - ref_pin++; - ret =ice_dpll_init_fwnode_pin (ref_pin, ice_dpll_fwnode_ext_synce); -if (ret) - goto err_unregister_ext_eref; - -if (IS_ERR_OR_NULL (ref_pin->pin)) { -dev_dbg (ice_pf_to_dev (pf), -"Tx-clk SYNCE pin not registered yet\n" ); -return 0 ; - } - - ret =dpll_pin_register (txc->dpll, ref_pin->pin, &ice_dpll_txclk_ops, - ref_pin); + goto release_pins; + ret =ice_dpll_register_pins (txc->dpll, pins, &ice_dpll_txclk_ops, +ICE_DPLL_TXCLK_NUM_MAX );if (ret) - goto err_deinit_synce; + goto release_pins;return 0 ; -err_deinit_synce: -/* -* Avoid deadlock against notifier workers blocked on dpll_init. -* The outer init error path will complete dpll_init and flush the -* shared workqueue before destroying it. -*/ -ice_dpll_stop_fwnode_pin_activity (ref_pin, false); -ice_dpll_release_fwnode_pin (ref_pin); -err_unregister_ext_eref: -dpll_pin_unregister (txc->dpll, - pf->dplls.txclks[E825_EXT_EREF_PIN_IDX ].pin, - &ice_dpll_txclk_ops, - &pf->dplls.txclks[E825_EXT_EREF_PIN_IDX ]); - -err_release_ext_eref: -ice_dpll_release_pins (&pf->dplls.txclks[E825_EXT_EREF_PIN_IDX ],1 ); - +release_pins: +ice_dpll_release_pins (pins,ICE_DPLL_TXCLK_NUM_MAX ); +for (i =0 ; i <ICE_DPLL_TXCLK_NUM_MAX ; i++) + pins[i].pin =NULL ;return ret; }/** -* ice_dpll_init_tspll_pins - init and register TSPLL TIME_REF fwnode pin +* ice_dpll_init_tspll_pins - init and register TSPLL TIME_REF pin * @pf: board private structure * -* Initialize the fwnode-based TIME_REF input pin for the TSPLL DPLL on E825. -* If the pin is not yet available in the dpll subsystem, registration will -* be deferred via the notifier path. +* Get the TIME_REF input pin of the TSPLL DPLL on E825, link it with the pin +* wired to it and register it with the TSPLL DPLL. * * Return: * * 0 - success
@@ -4346,26 +4304,36 @@ static int ice_dpll_init_tspll_pins(struct ice_pf *pf) {struct ice_dpll_pin *time_ref = &pf->dplls.tspll_in;struct ice_dpll *tp = &pf->dplls.tspll; +u64 clock_id;int ret; time_ref->pf = pf; - ret =ice_dpll_init_fwnode_pin (time_ref, ice_dpll_fwnode_time_ref); + time_ref->prop.type =DPLL_PIN_TYPE_EXT ; + time_ref->prop.capabilities =DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; + time_ref->prop.board_label = ice_dpll_time_ref_pin; + +/* The clock_id of the pin must match the TSPLL DPLL device clock_id +* (see dpll_pin_register()), the pin index is dynamic as for the TX +* reference pins. +*/ + clock_id =ice_generate_dpll_clock_id (pf, tp,DPLL_TYPE_GENERIC ); + ret =ice_dpll_get_pins (pf, time_ref,DPLL_PIN_IDX_UNSPEC ,1 , clock_id);if (ret)return ret; - -if (IS_ERR_OR_NULL (time_ref->pin)) { -dev_dbg (ice_pf_to_dev (pf), -"TSPLL TIME_REF pin not registered yet\n" ); -return 0 ; - } - + ret =ice_dpll_pin_link_add (pf, time_ref->pin, + ice_dpll_fwnode_time_ref); +if (ret) + goto release_pin; ret =dpll_pin_register (tp->dpll, time_ref->pin, &ice_dpll_tspll_in_ops, time_ref); -if (ret) { -ice_dpll_stop_fwnode_pin_activity (time_ref, false); -ice_dpll_release_fwnode_pin (time_ref); - } +if (ret) + goto release_pin; + +return 0 ; +release_pin: +ice_dpll_release_pins (time_ref,1 ); + time_ref->pin =NULL ;return ret; }
@@ -4394,7 +4362,7 @@ static int ice_dpll_init_pins_e825(struct ice_pf *pf)if (ret) goto unregister_pins; - ret =ice_dpll_init_txclk_pins (pf,0 ); + ret =ice_dpll_init_txclk_pins (pf);if (ret) {ice_dpll_deinit_rclk_pin (pf); goto unregister_pins;
@@ -4404,12 +4372,7 @@ static int ice_dpll_init_pins_e825(struct ice_pf *pf) test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) { ret =ice_dpll_init_tspll_pins (pf);if (ret) { -/* Avoid flushing pf->dplls.wq here: notifier work -* items block on pf->dplls.dpll_init which is -* completed by the unregister_pins path below. -* destroy_workqueue() there drains queued items. -*/ -ice_dpll_deinit_txclk_pins (pf, false); +ice_dpll_deinit_txclk_pins (pf);ice_dpll_deinit_rclk_pin (pf); } }
@@ -4964,6 +4927,7 @@ static int ice_dpll_init_info_txclk_pins_e825c(struct ice_pf *pf) tx_pin->prop.board_label = ice_dpll_ext_eref_pin; tx_pin->tx_ref_src =ICE_REF_CLK_EREF0 ; }else if (i ==E825_EXT_SYNCE_PIN_IDX ) { + tx_pin->prop.board_label = ice_dpll_ext_synce_pin; tx_pin->tx_ref_src =ICE_REF_CLK_SYNCE ; } }
drivers/net/ethernet/intel/ice/ice_dpll.h +1 -1
@@ -138,7 +138,7 @@ struct ice_dpll {* @outputs: output pins pointer * @rclk: recovered pins pointer * @txclks: TX clock reference pins pointer -* @tspll_in: TSPLL TIME_REF fwnode input pin (E825 only) +* @tspll_in: TSPLL TIME_REF input pin (E825 only) * @num_inputs: number of input pins available on dpll * @num_outputs: number of output pins available on dpll * @cgu_state_acq_err_num: number of errors returned during periodic work
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 6/19 ice: dpll: drop the filter of notifications from own registrations
In reply to Ivan Veceraice_dpll_pin_notify() ignored the pin notifications that the driver itself caused when it registered the zl3073x pins with its TXC and TSPLL DPLLs. The driver does not do that any more, and the recovered clock pin that it registers under a zl3073x pin has no firmware node, so no notification caused by the driver matches a watched firmware node. Remove the filter.
Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL, with the rest of the series.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 34 ----------------------- 1 file changed, 34 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +0 -34
@@ -3098,32 +3098,6 @@ static u64 ice_generate_dpll_clock_id(struct ice_pf *pf, struct ice_dpll *d,return pf->dplls.clock_id; } -/** -* ice_dpll_is_own_dpll_clock_id - check if clock_id belongs to this pf's DPLLs -* @pf: board private structure -* @clock_id: clock_id from a DPLL notification -* -* Match info->src_clock_id from a DPLL pin notification against any DPLL -* device this PF has registered. Used to suppress self-notifications -* generated as a side effect of our own dpll_pin_register() and -* dpll_pin_unregister() calls on the fwnode-backed SYNCE and TIME_REF pins, -* whose DPLLs (TXC and TSPLL) use MAC-derived clock_ids on E825. -* -* Return: true if clock_id matches one of this PF's registered DPLL devices. -*/ -static bool ice_dpll_is_own_dpll_clock_id (struct ice_pf *pf,u64 clock_id) -{ -if (clock_id == pf->dplls.clock_id) -return true; -if (pf->hw.mac_type !=ICE_MAC_GENERIC_3K_E825 ) -return false; -if (clock_id ==ice_generate_dpll_clock_id (pf, &pf->dplls.txc, -DPLL_TYPE_GENERIC )) -return true; -return clock_id ==ice_generate_dpll_clock_id (pf, &pf->dplls.tspll, -DPLL_TYPE_GENERIC ); -} -/** * ice_dpll_pin_ntf - notify pin change including any SW pin wrappers * @dplls: pointer to dplls struct
@@ -3877,14 +3851,6 @@ static int ice_dpll_pin_notify(struct notifier_block *nb, unsigned long action,if (pin->fwnode != info->fwnode)return NOTIFY_DONE ;/* Not this pin */ -/* Ignore notifications that are a side effect of internal pin -* registration/unregistration calls. E825 uses per-device -* MAC-derived clock_ids for the TXC and TSPLL generic DPLLs, so -* info->src_clock_id may not equal pf->dplls.clock_id. -*/ -if (ice_dpll_is_own_dpll_clock_id (pin->pf, info->src_clock_id)) -return NOTIFY_DONE ; - work =kzalloc_obj (*work);if (!work)return NOTIFY_DONE ;
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 7/19 dpll: register pins only with a DPLL of their owner
In reply to Ivan VeceraCommit c191b319f208 ("dpll: allow registering FW-identified pin with a different DPLL") allowed a pin with a firmware node to be registered with a DPLL of another owner. Its only user was ice on E825, which now links its own pins with the zl3073x pins instead.
Require the same owner for every pin again and document the rule.
--- Documentation/driver-api/dpll.rst | 8 ++++++-- drivers/dpll/dpll_core.c | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-)
Documentation/driver-api/dpll.rst +6 -2
@@ -350,8 +350,12 @@ bound to only one other pin at any given time. ``DPLL_A_PIN_STATE`` state of Reference SYNC connection ============================== ========================================== -Pin links -========= +Pin ownership and links +======================= + +The owner of a dpll device or a pin is identified by the module and the +clock_id passed to dpll_device_get() or dpll_pin_get(). dpll_pin_register() +accepts only a dpll device of the same owner as the pin. A pin represents a pad of the device whose driver registers it. When the board connects a pad of one device to a pad of another one, for example an
drivers/dpll/dpll_core.c +6 -6
@@ -983,6 +983,9 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* @ops: ops for a dpll pin ops * @priv: pointer to private information of owner * +* The @dpll and the @pin must have the same owner, they must be created with +* the same module and clock_id. +* * Context: Acquires a lock (dpll_lock) * Return: * * 0 on success
@@ -1015,13 +1018,10 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, goto out_unlock; } -/* -* For pins identified via firmware (pin->fwnode), allow registration -* even if the pin's (module, clock_id) differs from the target DPLL. -* For non-fwnode pins, require a strict (module, clock_id) match. +/* A pin of another owner is connected by a link, see +* dpll_pin_link_add(). */ -if (!pin->fwnode && -WARN_ON_ONCE (dpll->module != pin->module || +if (WARN_ON_ONCE (dpll->module != pin->module || dpll->clock_id != pin->clock_id)) { ret = -EINVAL ; goto out_unlock;
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 8/19 dpll: drop the state change exception for pins with a firmware node
In reply to Ivan VeceraCommit 521b6d5de08d ("dpll: allow fwnode pins to attempt state change without capability bit") let user space try to set the state of a pin with a firmware node also without DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE. It was needed for the zl3073x output pins that ice registered with its TXC and TSPLL DPLLs. ice now uses its own pins, which have the capability, and zl3073x, the only driver that sets a firmware node, gives it to every pin whose state can be set.
Check the capability for all pins again.
--- drivers/dpll/dpll_netlink.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/dpll/dpll_netlink.c +2 -8
@@ -1328,11 +1328,8 @@ dpll_pin_on_pin_state_set(struct dpll_pin *pin, u32 parent_idx,unsigned long i;int ret; -/* fwnode pins may not set the capability bit upfront; let the ops -* layer return -EOPNOTSUPP if the operation is unsupported. -*/ if (!(DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE & - pin->prop.capabilities) && !pin->fwnode) { + pin->prop.capabilities)) {NL_SET_ERR_MSG (extack,"state changing is not allowed" );return -EOPNOTSUPP ; }
@@ -1367,11 +1364,8 @@ dpll_pin_state_set(struct dpll_device *dpll, struct dpll_pin *pin,struct dpll_pin_ref *ref;int ret; -/* fwnode pins may not set the capability bit upfront; let the ops -* layer return -EOPNOTSUPP if the operation is unsupported. -*/ if (!(DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE & - pin->prop.capabilities) && !pin->fwnode) { + pin->prop.capabilities)) {NL_SET_ERR_MSG (extack,"state changing is not allowed" );return -EOPNOTSUPP ; }
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 9/19 dpll: drop the source clock id from pin notifications
In reply to Ivan VeceraCommit 0bf47f722fa9 ("dpll: extend pin notifier with notification source ID") added src_clock_id to the pin notifier info, so that ice could ignore the notifications caused by its own registrations of the zl3073x pins with its TXC and TSPLL DPLLs. ice does not register those pins any more and no other notifier user reads the field. Remove it.
The notifications are sent as before, only without the field.
--- drivers/dpll/dpll_core.c | 14 ++++++-------- drivers/dpll/dpll_core.h | 3 +-- drivers/dpll/dpll_netlink.c | 10 +++++----- drivers/dpll/dpll_netlink.h | 4 ++-- include/linux/dpll.h | 1 - 5 files changed, 14 insertions(+), 18 deletions(-)
drivers/dpll/dpll_core.c +6 -8
@@ -74,8 +74,7 @@ void dpll_device_notify(struct dpll_device *dpll, unsigned long action)call_dpll_notifiers (action, &info); } -void dpll_pin_notify (struct dpll_pin *pin,u64 src_clock_id, -unsigned long action) +void dpll_pin_notify (struct dpll_pin *pin,unsigned long action) {struct dpll_pin_notifier_info info = { .pin = pin,
@@ -84,7 +83,6 @@ void dpll_pin_notify(struct dpll_pin *pin, u64 src_clock_id, .clock_id = pin->clock_id, .fwnode = pin->fwnode, .prop = &pin->prop, - .src_clock_id = src_clock_id, };call_dpll_notifiers (action, &info);
@@ -965,7 +963,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, goto ref_pin_del; registered =xa_get_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED );xa_set_mark (&dpll_pin_xa, pin->id,DPLL_REGISTERED ); -dpll_pin_create_ntf (pin, dpll->clock_id); +dpll_pin_create_ntf (pin);if (!registered)dpll_pin_links_ntf (pin);
@@ -1054,7 +1052,7 @@ __dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv, void *cookie) {ASSERT_DPLL_PIN_REGISTERED (pin ); -dpll_pin_delete_ntf (pin, dpll->clock_id); +dpll_pin_delete_ntf (pin);dpll_xa_ref_pin_del (&dpll->pin_refs, pin, ops, priv, cookie);dpll_xa_ref_dpll_del (&pin->dpll_refs, dpll, ops, priv, cookie);if (xa_empty (&pin->dpll_refs)) {
@@ -1128,7 +1126,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, stop = i; goto dpll_unregister; } -dpll_pin_create_ntf (pin, parent->clock_id); +dpll_pin_create_ntf (pin); }mutex_unlock (&dpll_lock);
@@ -1137,7 +1135,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, dpll_unregister:xa_for_each (&parent->dpll_refs, i, ref)if (i < stop) { -dpll_pin_delete_ntf (pin, parent->clock_id); +dpll_pin_delete_ntf (pin);__dpll_pin_unregister (ref->dpll, pin, ops, priv, parent); }
@@ -1170,7 +1168,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin, reg =dpll_pin_registration_find (ref, ops, priv, parent);if (!reg)continue ; -dpll_pin_delete_ntf (pin, parent->clock_id); +dpll_pin_delete_ntf (pin);__dpll_pin_unregister (ref->dpll, pin, ops, priv, parent); }dpll_xa_ref_pin_del (&pin->parent_refs, parent, ops, priv, pin);
drivers/dpll/dpll_core.h +1 -2
@@ -114,7 +114,6 @@ extern struct xarray dpll_pin_xa;extern struct mutex dpll_lock;void dpll_device_notify (struct dpll_device *dpll,unsigned long action); -void dpll_pin_notify (struct dpll_pin *pin,u64 src_clock_id, -unsigned long action); +void dpll_pin_notify (struct dpll_pin *pin,unsigned long action);#endif
drivers/dpll/dpll_netlink.c +5 -5
@@ -969,15 +969,15 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin)return ret; } -int dpll_pin_create_ntf (struct dpll_pin *pin,u64 src_clock_id) +int dpll_pin_create_ntf (struct dpll_pin *pin) { -dpll_pin_notify (pin, src_clock_id,DPLL_PIN_CREATED ); +dpll_pin_notify (pin,DPLL_PIN_CREATED );return dpll_pin_event_send (DPLL_CMD_PIN_CREATE_NTF , pin); } -int dpll_pin_delete_ntf (struct dpll_pin *pin,u64 src_clock_id) +int dpll_pin_delete_ntf (struct dpll_pin *pin) { -dpll_pin_notify (pin, src_clock_id,DPLL_PIN_DELETED ); +dpll_pin_notify (pin,DPLL_PIN_DELETED );return dpll_pin_event_send (DPLL_CMD_PIN_DELETE_NTF , pin); }
@@ -992,7 +992,7 @@ int dpll_pin_delete_ntf(struct dpll_pin *pin, u64 src_clock_id)int __dpll_pin_change_ntf (struct dpll_pin *pin) {lockdep_assert_held (&dpll_lock); -dpll_pin_notify (pin, pin->clock_id,DPLL_PIN_CHANGED ); +dpll_pin_notify (pin,DPLL_PIN_CHANGED );return dpll_pin_event_send (DPLL_CMD_PIN_CHANGE_NTF , pin); }EXPORT_SYMBOL_GPL (__dpll_pin_change_ntf);
drivers/dpll/dpll_netlink.h +2 -2
@@ -8,9 +8,9 @@ int dpll_device_create_ntf(struct dpll_device *dpll);int dpll_device_delete_ntf (struct dpll_device *dpll); -int dpll_pin_create_ntf (struct dpll_pin *pin,u64 src_clock_id); +int dpll_pin_create_ntf (struct dpll_pin *pin); -int dpll_pin_delete_ntf (struct dpll_pin *pin,u64 src_clock_id); +int dpll_pin_delete_ntf (struct dpll_pin *pin);#if IS_ENABLED (CONFIG_KUNIT )/* For KUnit tests, call with dpll_lock held for a registered pin */
include/linux/dpll.h +0 -1
@@ -233,7 +233,6 @@ struct dpll_pin_notifier_info {u64 clock_id;const struct fwnode_handle *fwnode;const struct dpll_pin_properties *prop; -u64 src_clock_id; };#if IS_ENABLED (CONFIG_DPLL )
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 10/19 dpll: drop device events from the in-kernel notifier
In reply to Ivan VeceraCommit 2be467588d6b ("dpll: Add notifier chain for dpll events") sends device created, deleted and changed events to the in-kernel notifier chain, but no driver ever handled them. The only driver that uses the notifier, ice, waits for pins with a firmware node and ignores everything else.
Keep the pin events and remove the device ones.
--- drivers/dpll/dpll_core.c | 13 ------------- drivers/dpll/dpll_core.h | 1 - drivers/dpll/dpll_netlink.c | 3 --- include/linux/dpll.h | 11 ----------- 4 files changed, 28 deletions(-)
drivers/dpll/dpll_core.c +0 -13
@@ -61,19 +61,6 @@ static int call_dpll_notifiers(unsigned long action, void *info)return raw_notifier_call_chain (&dpll_notifier_chain, action, info); } -void dpll_device_notify (struct dpll_device *dpll,unsigned long action) -{ -struct dpll_device_notifier_info info = { - .dpll = dpll, - .id = dpll->id, - .idx = dpll->device_idx, - .clock_id = dpll->clock_id, - .type = dpll->type, - }; - -call_dpll_notifiers (action, &info); -} -void dpll_pin_notify (struct dpll_pin *pin,unsigned long action) {struct dpll_pin_notifier_info info = {
drivers/dpll/dpll_core.h +0 -1
@@ -113,7 +113,6 @@ extern struct xarray dpll_device_xa;extern struct xarray dpll_pin_xa;extern struct mutex dpll_lock; -void dpll_device_notify (struct dpll_device *dpll,unsigned long action);void dpll_pin_notify (struct dpll_pin *pin,unsigned long action);#endif
drivers/dpll/dpll_netlink.c +0 -3
@@ -891,13 +891,11 @@ dpll_device_event_send(enum dpll_cmd event, struct dpll_device *dpll)int dpll_device_create_ntf (struct dpll_device *dpll) { -dpll_device_notify (dpll,DPLL_DEVICE_CREATED );return dpll_device_event_send (DPLL_CMD_DEVICE_CREATE_NTF , dpll); }int dpll_device_delete_ntf (struct dpll_device *dpll) { -dpll_device_notify (dpll,DPLL_DEVICE_DELETED );return dpll_device_event_send (DPLL_CMD_DEVICE_DELETE_NTF , dpll); }
@@ -912,7 +910,6 @@ int dpll_device_delete_ntf(struct dpll_device *dpll)int __dpll_device_change_ntf (struct dpll_device *dpll) {lockdep_assert_held (&dpll_lock); -dpll_device_notify (dpll,DPLL_DEVICE_CHANGED );return dpll_device_event_send (DPLL_CMD_DEVICE_CHANGE_NTF , dpll); }EXPORT_SYMBOL_GPL (__dpll_device_change_ntf);
include/linux/dpll.h +0 -11
@@ -211,21 +211,10 @@ typedef struct ref_tracker *dpll_tracker;typedef struct {}dpll_tracker ;#endif -#define DPLL_DEVICE_CREATED 1 -#define DPLL_DEVICE_DELETED 2 -#define DPLL_DEVICE_CHANGED 3#define DPLL_PIN_CREATED 4#define DPLL_PIN_DELETED 5#define DPLL_PIN_CHANGED 6 -struct dpll_device_notifier_info { -struct dpll_device *dpll; -u32 id; -u32 idx; -u64 clock_id; -enum dpll_type type; -}; -struct dpll_pin_notifier_info {struct dpll_pin *pin;u32 id;
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 11/19 dpll: drop the cached module name of a pin
In reply to Ivan VeceraCommit c191b319f208 ("dpll: allow registering FW-identified pin with a different DPLL") cached the module name in the pin, because a pin that another driver registered with its DPLL could stay registered after the module that created the pin was removed. Every pin is now registered by the driver that created it, with its DPLLs or under a parent pin, and a driver unregisters its pins before its module goes away.
Read the module name from the module again.
--- drivers/dpll/dpll_core.c | 1 - drivers/dpll/dpll_core.h | 2 -- drivers/dpll/dpll_netlink.c | 6 +++--- 3 files changed, 3 insertions(+), 6 deletions(-)
drivers/dpll/dpll_core.c +0 -1
@@ -653,7 +653,6 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module, pin->pin_idx = pin_idx; pin->clock_id = clock_id; pin->module = module; -strscpy (pin->module_name,module_name (module));if (WARN_ON (prop->type <DPLL_PIN_TYPE_MUX || prop->type >DPLL_PIN_TYPE_MAX )) { ret = -EINVAL ;
drivers/dpll/dpll_core.h +0 -2
@@ -45,7 +45,6 @@ struct dpll_device {* @pin_idx: index of a pin given by dev driver * @clock_id: clock_id of creator * @module: module of creator -* @module_name: module name of creator * @fwnode: optional reference to firmware node * @links: links to other pins (struct dpll_pin_link) * @dpll_refs: hold referencees to dplls pin was registered with
@@ -61,7 +60,6 @@ struct dpll_pin {u32 pin_idx;u64 clock_id;struct module *module; -char module_name[MODULE_NAME_LEN ];struct fwnode_handle *fwnode;struct list_head links;struct xarray dpll_refs;
drivers/dpll/dpll_netlink.c +3 -3
@@ -754,7 +754,7 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,if (ret)return ret;if (nla_put_string (msg,DPLL_A_PIN_MODULE_NAME , - pin->module_name)) +module_name (pin->module)))return -EMSGSIZE ;if (nla_put_64bit (msg,DPLL_A_PIN_CLOCK_ID ,sizeof (pin->clock_id), &pin->clock_id,DPLL_A_PIN_PAD ))
@@ -1630,9 +1630,9 @@ dpll_pin_find(u64 clock_id, struct nlattr *mod_name_attr,xa_for_each_marked (&dpll_pin_xa, i, pin,DPLL_REGISTERED ) { prop = &pin->prop; cid_match = clock_id ? pin->clock_id == clock_id : true; - mod_match = mod_name_attr && pin->module_name[0 ] ? + mod_match = mod_name_attr &&module_name (pin->module) ? !nla_strcmp (mod_name_attr, - pin->module_name) : true; +module_name (pin->module)) : true; type_match = type ? prop->type == type : true; board_match = board_label ? (prop->board_label ? !nla_strcmp(board_label, prop->board_label) : false) :
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 12/19 ice: dpll: track the E825 recovered clock routing in the adapter
In reply to Ivan VeceraOn E825 the CGU has two muxes, each routing the recovered clock of one port of the adapter to a SyncE output. All PFs of the adapter reach the muxes, but the driver tracks the routing only per PF, as the state of the recovered clock pin of the PF on each mux.
Record in the adapter which recovered clock pin each mux routes. A PF records its pin when it creates the pin and the mux routes its port, and when it routes its port. The record is cleared when a PF disables the mux and when the routed PF removes its pin. A failed configuration may leave the mux registers changed, for example the R11 selection of SyncE output 1 is written before R10, so the record is then read back from them, or set to no port if that read fails too, as the routing is then unknown. Writers hold cgu_synce_lock, which already serializes the writes of the mux registers.
Nothing reads the record yet. Creating the pin adds one read of the mux registers R10 and R11, the same reads as for getting the pin state, and a failed configuration adds a read of the register that selects the port.
Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL: the record follows the routing of each of the eight ports, and the mux registers keep the routing over a PF reset, a CORER and a GLOBR, so the record stays valid. EMPR was not tested.
--- drivers/net/ethernet/intel/ice/ice_adapter.h | 15 ++ drivers/net/ethernet/intel/ice/ice_dpll.c | 154 ++++++++++++++++--- 2 files changed, 150 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/ice/ice_adapter.h +15 -0
@@ -13,6 +13,7 @@#include "ice_type.h" +struct dpll_pin ;struct pci_dev ;struct ice_pf ;
@@ -34,6 +35,18 @@ struct ice_port_list {struct srcu_struct srcu; }; +/** +* struct ice_dpll_rclk_mux - recovered clock mux of the E825C CGU +* @src: recovered clock pin of the port that the mux routes to its output, +* NULL when it routes no port of a bound PF or the routing is unknown +* +* The CGU routes the recovered clock of one port of the adapter to each of +* its two SyncE outputs. Writers of @src hold cgu_synce_lock of the adapter. +*/ +struct ice_dpll_rclk_mux { +struct dpll_pin *src; +}; +/** * struct ice_adapter - PCI adapter resources shared across PFs * @devlink: ice adapter's devlink (whole dev devlink)
@@ -44,6 +57,7 @@ struct ice_port_list {* Index 0 = PHY0, index 1 = PHY1. Used on E825C devices. * @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11, * which all PFs reach. Used on E825C devices. +* @rclk_mux: Recovered clock muxes of the CGU. Used on E825C devices. * @ctrl_pf: Control PF of the adapter * @ports: Ports list */
@@ -58,6 +72,7 @@ struct ice_adapter {struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS ];/* Serialize changes of the SyncE CGU registers (E825C only) */ struct mutex cgu_synce_lock; +struct ice_dpll_rclk_mux rclk_mux[ICE_SYNCE_CLK_NUM ];struct ice_pf *ctrl_pf;struct ice_port_list ports;
drivers/net/ethernet/intel/ice/ice_dpll.c +135 -19
207 lines not on this page · raw message
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 13/19 ice: dpll: register the E825 recovered clock muxes as DPLL devices
In reply to Ivan VeceraEach of the two recovered clock muxes of the E825 CGU feeds a SyncE output, which the board wires to an input of the platform DPLL. Describe each mux with a DPLL device of type generic with one output pin, RCLK0 or RCLK1. The output pin is linked with the pin at the other end of the wire through the firmware node rclk0 or rclk1, the same nodes the recovered clock pins use to find their parent pins.
The devices and the output pins belong to the adapter. Their clock ID is the adapter index, which all PFs of the adapter share, both NACs of E825 included. The device index is the SyncE output. The first PF registers the devices and the pins and the last one unregisters them, under the instance lock of the adapter devlink. The callers already hold the instance lock of the PF devlink, which is nested in the adapter devlink, so the two locks are taken in the order the devlink rules require.
A mux reports a locked status, and its output pin the connected state, while the mux routes the port of a bound PF, as recorded in the adapter. The callbacks of the devices and of the output pins do not access the hardware. A change of the routing, also by a failed write, notifies the device, its output pin and the recovered clock pins whose state on the mux changed, the pin of the port routed before included, which is read together with the write under cgu_synce_lock. When a PF finds at probe that the registers differ from the record, it notifies only the device and its output pin, because the pin routed before belongs to another PF, which can go away meanwhile, and the state of a recovered clock pin is read from the hardware. The recovered clock pins do not use the muxes yet.
Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL: the mux devices and RCLK0/1 stay while any PF of the adapter is bound and go with the last one, and RCLK0 and RCLK1 report their links to the zl3073x inputs REF1P and REF1N.
--- drivers/net/ethernet/intel/ice/ice_adapter.c | 3 +- drivers/net/ethernet/intel/ice/ice_adapter.h | 22 +- drivers/net/ethernet/intel/ice/ice_dpll.c | 323 ++++++++++++++++++- 3 files changed, 335 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/ice/ice_adapter.c +2 -1
@@ -43,6 +43,7 @@ static int ice_adapter_init(void *priv, void *init_param) devlink =shd_priv_to_devlink (adapter); adapter->devlink = devlink; + adapter->index = *(u64 *)init_param;spin_lock_init (&adapter->ptp_gltsyn_time_lock);spin_lock_init (&adapter->txq_ctx_lock);
@@ -96,7 +97,7 @@ struct ice_adapter *ice_adapter_get(struct pci_dev *pdev) index =ice_adapter_index (pdev);snprintf (devlink_id,sizeof (devlink_id),"ice:%llx" , index); devlink =devlink_shd_get (devlink_id, &ice_adapter_devlink_ops, -sizeof (*adapter),NULL , pdev->dev.driver); +sizeof (*adapter), &index, pdev->dev.driver);if (IS_ERR (devlink))return ERR_CAST (devlink);
drivers/net/ethernet/intel/ice/ice_adapter.h +20 -2
@@ -5,6 +5,7 @@#define _ICE_ADAPTER_H_#include <linux/types.h> +#include <linux/dpll.h> #include <linux/mutex.h> #include <linux/srcu.h> #include <linux/spinlock_types.h>
@@ -13,7 +14,6 @@#include "ice_type.h" -struct dpll_pin ;struct pci_dev ;struct ice_pf ;
@@ -37,19 +37,33 @@ struct ice_port_list {/** * struct ice_dpll_rclk_mux - recovered clock mux of the E825C CGU +* @dpll: DPLL device of the mux +* @tracker: reference tracker of @dpll +* @out: output pin of the mux +* @out_tracker: reference tracker of @out * @src: recovered clock pin of the port that the mux routes to its output, * NULL when it routes no port of a bound PF or the routing is unknown +* @idx: SyncE output of the CGU fed by the mux * * The CGU routes the recovered clock of one port of the adapter to each of -* its two SyncE outputs. Writers of @src hold cgu_synce_lock of the adapter. +* its two SyncE outputs. The PFs of the adapter share the muxes: the first +* PF registers @dpll and @out, the last one unregisters them, under the +* instance lock of the adapter devlink. Writers of @src hold cgu_synce_lock +* of the adapter. */ struct ice_dpll_rclk_mux { +struct dpll_device *dpll; +dpll_tracker tracker; +struct dpll_pin *out; +dpll_tracker out_tracker;struct dpll_pin *src; +enum ice_synce_clk idx; };/** * struct ice_adapter - PCI adapter resources shared across PFs * @devlink: ice adapter's devlink (whole dev devlink) +* @index: Index of the adapter, also the clock ID of its recovered clock muxes * @ptp_gltsyn_time_lock: Spinlock protecting access to the GLTSYN_TIME * register of the PTP clock. * @txq_ctx_lock: Spinlock protecting access to the GLCOMM_QTX_CNTX_CTL register
@@ -58,11 +72,14 @@ struct ice_dpll_rclk_mux {* @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11, * which all PFs reach. Used on E825C devices. * @rclk_mux: Recovered clock muxes of the CGU. Used on E825C devices. +* @rclk_mux_users: Number of PFs that use @rclk_mux, protected by the +* instance lock of @devlink * @ctrl_pf: Control PF of the adapter * @ports: Ports list */ struct ice_adapter {struct devlink *devlink; +u64 index;/* For access to the GLTSYN_TIME register */ spinlock_t ptp_gltsyn_time_lock;
@@ -73,6 +90,7 @@ struct ice_adapter {/* Serialize changes of the SyncE CGU registers (E825C only) */ struct mutex cgu_synce_lock;struct ice_dpll_rclk_mux rclk_mux[ICE_SYNCE_CLK_NUM ]; +unsigned int rclk_mux_users;struct ice_pf *ctrl_pf;struct ice_port_list ports;
drivers/net/ethernet/intel/ice/ice_dpll.c +313 -10
445 lines not on this page · raw message
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 14/19 ice: dpll: route the E825 recovered clock through the mux devices
In reply to Ivan VeceraOn E825 the driver registers the recovered clock pin of each PF as a child of the zl3073x pins rclk0 and rclk1 with dpll_pin_on_pin_register(). It finds them by firmware node, holds references to them and uses the DPLL notifier to wait for them and to follow their removal.
Register the recovered clock pin as an input of both mux devices instead, with the clock ID of the muxes. The state of the pin on a mux selects the port for the output of the mux. Connecting a port disconnects the port the mux routed before, which gets a change notification. Setting and reading the state accesses the same CGU registers as before.
Drop the notifier work, the firmware node pins and the dpll_init completion, which served only this path, and the E825 case of ice_get_cgu_rclk_pin_info().
What user space sees on E825 changes:
- the recovered clock pin lists the two mux devices as parent devices instead of the zl3073x pins as parent pins, so a port is routed by setting the state of its pin on a mux device
- the clock ID of the recovered clock pin is the adapter index instead of the DSN; neither tells the PFs apart, as all PFs of a complex have the same DSN
- the zl3073x pins have no child pins; the firmware still describes them as MUX pins, which they no longer need to be
- the recovered clock pin exists also when the zl3073x driver is not loaded
Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL:
routing each port to RCLK0 or RCLK1 updates the pin states, the lock status of the mux and the output pin, and notifies the port routed before. With a 25 Gb/s port routed, the zl3073x input measures 78.125 MHz and qualifies; a 1 Gb/s port gives 62.5 MHz, as set by the divider. A PF bound again finds its port still routed.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 522 +++++++------------- drivers/net/ethernet/intel/ice/ice_dpll.h | 9 - drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 8 - 3 files changed, 190 insertions(+), 349 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +190 -332
@@ -613,9 +613,6 @@ static int ice_dpll_rclk_update_e825c(struct ice_pf *pf,int err, i;u8 sel; -if (pf->dplls.rclk.num_parents >ICE_SYNCE_CLK_NUM ) -return -EINVAL ; -for (i =0 ; i <ICE_SYNCE_CLK_NUM ; i++) { err =ice_dpll_rclk_mux_sel_get (&pf->hw, i, &sel);if (err)
@@ -2701,9 +2698,7 @@ ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv, struct netlink_ext_ack *extack) {bool enable = state ==DPLL_PIN_STATE_CONNECTED ; -struct ice_dpll_rclk_mux *mux =NULL ;struct ice_dpll_pin *p = pin_priv; -struct dpll_pin *prev =NULL ;struct ice_pf *pf = p->pf;struct ice_hw *hw;int ret = -EINVAL ;
@@ -2731,15 +2726,7 @@ ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv, goto unlock; } -if (hw->mac_type ==ICE_MAC_GENERIC_3K_E825 ) { - mux = &pf->adapter->rclk_mux[hw_idx]; - ret =ice_dpll_synce_update_e825c (hw, enable, - pf->ptp.port.port_num, - (enum ice_synce_clk )hw_idx, - &prev); - }else { - ret =ice_aq_set_phy_rec_clk_out (hw, hw_idx, enable, &p->freq); - } + ret =ice_aq_set_phy_rec_clk_out (hw, hw_idx, enable, &p->freq);if (ret) NL_SET_ERR_MSG_FMT(extack, "err:%d %s failed to set pin state:%u for pin:%u on parent:%u",
@@ -2749,9 +2736,6 @@ ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv, ice_dpll_pin_get_parent_num(p, parent_pin)); unlock:mutex_unlock (&pf->dplls.lock); -/* The core notifies this pin on success */ -if (mux) -__ice_dpll_rclk_mux_ntf (mux, prev, ret ?NULL : p->pin);return ret; }
@@ -2856,6 +2840,108 @@ static int ice_dpll_rclk_mux_mode_get(const struct dpll_device *dpll,return 0 ; } +/** +* ice_dpll_rclk_state_on_dpll_set - set a state of rclk pin on a mux +* @pin: pointer to a pin +* @pin_priv: private data pointer passed on pin registration +* @dpll: registered dpll pointer +* @dpll_priv: private data pointer passed on dpll registration +* @state: state to be set on pin +* @extack: error reporting +* +* Dpll subsystem callback. Route the recovered clock of the port to the +* output of a recovered clock mux, or stop routing it. +* +* Context: Acquires pf->dplls.lock +* Return: +* * 0 - success +* * negative - failure +*/ +static int +ice_dpll_rclk_state_on_dpll_set (const struct dpll_pin *pin,void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{ +bool enable = state ==DPLL_PIN_STATE_CONNECTED ; +struct ice_dpll_rclk_mux *mux = dpll_priv; +struct ice_dpll_pin *p = pin_priv; +struct ice_pf *pf = p->pf; +struct dpll_pin *prev; +int ret = -EINVAL ; + +if (ice_dpll_is_reset (pf, extack)) +return -EBUSY ; + +/* Read again with the write of the mux, under cgu_synce_lock */ + prev =READ_ONCE (mux->src); +mutex_lock (&pf->dplls.lock); +if ((enable && p->state[mux->idx] ==DPLL_PIN_STATE_CONNECTED ) || + (!enable && p->state[mux->idx] ==DPLL_PIN_STATE_DISCONNECTED )) { +NL_SET_ERR_MSG_FMT (extack, +"pin:%u state:%u on dpll:%u already set" , + p->idx, state, mux->idx); + goto unlock; + } + + ret =ice_dpll_synce_update_e825c (&pf->hw, enable, + pf->ptp.port.port_num, mux->idx, + &prev); +if (ret) +NL_SET_ERR_MSG_FMT (extack, +"err:%d %s failed to set pin state:%u for pin:%u on dpll:%u" , + ret, +libie_aq_str (pf->hw.adminq.sq_last_status), + state, p->idx, mux->idx); +unlock: +mutex_unlock (&pf->dplls.lock); +/* The core notifies this pin on success */ +__ice_dpll_rclk_mux_ntf (mux, prev, ret ?NULL : p->pin); + +return ret; +} + +/** +* ice_dpll_rclk_state_on_dpll_get - get a state of rclk pin on a mux +* @pin: pointer to a pin +* @pin_priv: private data pointer passed on pin registration +* @dpll: registered dpll pointer +* @dpll_priv: private data pointer passed on dpll registration +* @state: on success holds pin state on the mux +* @extack: error reporting +* +* Dpll subsystem callback. Get the state of the recovered clock pin on a +* recovered clock mux. +* +* Context: Acquires pf->dplls.lock +* Return: +* * 0 - success +* * negative - failure +*/ +static int +ice_dpll_rclk_state_on_dpll_get (const struct dpll_pin *pin,void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,enum dpll_pin_state *state, +struct netlink_ext_ack *extack) +{ +struct ice_dpll_rclk_mux *mux = dpll_priv; +struct ice_dpll_pin *p = pin_priv; +struct ice_pf *pf = p->pf; +int ret; + +if (ice_dpll_is_reset (pf, extack)) +return -EBUSY ; + +mutex_lock (&pf->dplls.lock); + ret =ice_dpll_pin_state_update (pf, p,ICE_DPLL_PIN_TYPE_RCLK_INPUT , + extack); +if (!ret) + *state = p->state[mux->idx]; +mutex_unlock (&pf->dplls.lock); + +return ret; +} +/** * ice_dpll_rclk_out_state_get - get a state of a recovered clock mux output * @pin: pointer to a pin
@@ -3078,6 +3164,12 @@ static const struct dpll_pin_ops ice_dpll_rclk_ops = { .direction_get = ice_dpll_input_direction, }; +static const struct dpll_pin_ops ice_dpll_rclk_in_ops = { + .state_on_dpll_set = ice_dpll_rclk_state_on_dpll_set, + .state_on_dpll_get = ice_dpll_rclk_state_on_dpll_get, + .direction_get = ice_dpll_input_direction, +}; +static const struct dpll_pin_ops ice_dpll_rclk_out_ops = { .state_on_dpll_get = ice_dpll_rclk_out_state_get, .direction_get = ice_dpll_output_direction,
@@ -4019,125 +4111,34 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf)dpll_pin_on_pin_unregister (parent->pin, rclk->pin, &ice_dpll_rclk_ops, rclk); } -if (pf->hw.mac_type ==ICE_MAC_GENERIC_3K_E825 ) -ice_dpll_rclk_src_fini (pf);if (WARN_ON_ONCE (!vsi || !vsi->netdev))return ;dpll_netdev_pin_clear (vsi->netdev);dpll_pin_put (rclk->pin, &rclk->tracker); } -static bool ice_dpll_is_fwnode_pin (struct ice_dpll_pin *pin) -{ -return !IS_ERR_OR_NULL (pin->fwnode); -} - -static bool ice_dpll_fwnode_eq (const struct fwnode_handle *a, -const struct fwnode_handle *b) -{ -return a && a == b; -} - -static void ice_dpll_pin_notify_work (struct work_struct *work) -{ -struct ice_dpll_pin_work *w =container_of (work, - struct ice_dpll_pin_work, - work); -struct ice_dpll_pin *pin, *parent = w->pin; -struct ice_pf *pf = parent->pf; -bool is_rclk_parent = false; -int ret; - -wait_for_completion (&pf->dplls.dpll_init); -if (!test_bit (ICE_FLAG_DPLL , pf->flags)) - goto out;/* DPLL initialization failed */ - -/* Decide which parent we are handling, defensively checking FWNs */ -for (int i =0 ; i < pf->dplls.rclk.num_parents; i++) { -if (ice_dpll_fwnode_eq (parent->fwnode, - pf->dplls.inputs[i].fwnode)) { - is_rclk_parent = true; -break ; - } - } - -if (!is_rclk_parent) - goto out; - -switch (w->action) { -case DPLL_PIN_CREATED : -if (!IS_ERR_OR_NULL (parent->pin)) { -/* We have already our pin registered */ - goto out; - } - -/* Grab reference on fwnode pin */ - parent->pin =fwnode_dpll_pin_find (parent->fwnode, - &parent->tracker); -if (IS_ERR_OR_NULL (parent->pin)) { -dev_err (ice_pf_to_dev (pf), -"Cannot get fwnode pin reference\n" ); - goto out; - } - -/* Register rclk pin via on-pin relationship */ - pin = &pf->dplls.rclk; - ret =dpll_pin_on_pin_register (parent->pin, pin->pin, - &ice_dpll_rclk_ops, pin); -if (ret) { -dev_err (ice_pf_to_dev (pf), -"RCLK pin register failed: %pe\n" , -ERR_PTR (ret)); - goto drop_parent_ref; - } -break ; -case DPLL_PIN_DELETED : -if (IS_ERR_OR_NULL (parent->pin)) { -/* We have already our pin unregistered */ - goto out; - } - -/* Unregister rclk pin */ - pin = &pf->dplls.rclk; -dpll_pin_on_pin_unregister (parent->pin, pin->pin, - &ice_dpll_rclk_ops, pin); -drop_parent_ref: -/* Drop fwnode pin reference */ -dpll_pin_put (parent->pin, &parent->tracker); - parent->pin =NULL ; -break ; -default : -break ; - } -out: -kfree (w); -} - -static int ice_dpll_pin_notify (struct notifier_block *nb,unsigned long action, -void *data) +/** +* ice_dpll_deinit_rclk_pin_e825c - release rclk pin resources on E825 +* @pf: board private structure +* +* Unregister the rclk pin from the recovered clock muxes and release it. +*/ +static void ice_dpll_deinit_rclk_pin_e825c (struct ice_pf *pf) { - struct ice_dpll_pin *pin = container_of(nb, struct ice_dpll_pin, nb); -struct dpll_pin_notifier_info *info = data; -struct ice_dpll_pin_work *work; - -if (action !=DPLL_PIN_CREATED && action !=DPLL_PIN_DELETED ) -return NOTIFY_DONE ; - -/* Check if the reported pin is this one */ -if (pin->fwnode != info->fwnode) -return NOTIFY_DONE ;/* Not this pin */ - - work =kzalloc_obj (*work); -if (!work) -return NOTIFY_DONE ; - -INIT_WORK (&work->work, ice_dpll_pin_notify_work); - work->action = action; - work->pin = pin; - -queue_work (pin->pf->dplls.wq, &work->work); +struct ice_dpll_rclk_mux *muxes = pf->adapter->rclk_mux; +struct ice_dpll_pin *rclk = &pf->dplls.rclk; +struct ice_vsi *vsi =ice_get_main_vsi (pf); +int i; -return NOTIFY_OK ; +for (i =0 ; i <ICE_SYNCE_CLK_NUM ; i++) +dpll_pin_unregister (muxes[i].dpll, rclk->pin, + &ice_dpll_rclk_in_ops, rclk); +/* No callback of the pin runs any more and can route the port again */ +ice_dpll_rclk_src_fini (pf); +if (WARN_ON_ONCE (!vsi || !vsi->netdev)) +return ; +dpll_netdev_pin_clear (vsi->netdev); +dpll_pin_put (rclk->pin, &rclk->tracker); }/**
@@ -4168,17 +4169,8 @@ ice_dpll_init_pin_common(struct ice_pf *pf, struct ice_dpll_pin *pin,for (i =0 ; i < pin->num_parents; i++) { parent = &pf->dplls.inputs[pin->parent_idx[i]];if (IS_ERR_OR_NULL (parent->pin)) { -if (!ice_dpll_is_fwnode_pin (parent)) { - ret = -ENODEV ; - goto unregister_pins; - } - parent->pin =fwnode_dpll_pin_find (parent->fwnode, - &parent->tracker); -if (IS_ERR_OR_NULL (parent->pin)) { -dev_info (ice_pf_to_dev (pf), -"Mux pin not registered yet\n" ); -continue ; - } + ret = -ENODEV ; + goto unregister_pins; } ret =dpll_pin_on_pin_register (parent->pin, pin->pin, ops, pin);if (ret)
@@ -4228,43 +4220,6 @@ ice_dpll_init_rclk_pin(struct ice_pf *pf, int start_idx,return 0 ; } -static void -ice_dpll_stop_fwnode_pin_activity (struct ice_dpll_pin *pin,bool flush) -{ -unregister_dpll_notifier (&pin->nb); -if (flush) -flush_workqueue (pin->pf->dplls.wq); -} - -static void -ice_dpll_release_fwnode_pin (struct ice_dpll_pin *pin) -{ -if (!IS_ERR_OR_NULL (pin->pin)) { -dpll_pin_put (pin->pin, &pin->tracker); - pin->pin =NULL ; - } -fwnode_handle_put (pin->fwnode); - pin->fwnode =NULL ; -} - -static void -ice_dpll_deinit_fwnode_pin (struct ice_dpll_pin *pin) -{ -ice_dpll_stop_fwnode_pin_activity (pin, true); -ice_dpll_release_fwnode_pin (pin); -} - -static void -ice_dpll_deinit_fwnode_pins (struct ice_pf *pf,struct ice_dpll_pin *pins, -int start_idx) -{ -int i; - -for (i =0 ; i < pf->dplls.rclk.num_parents; i++) -ice_dpll_deinit_fwnode_pin (&pins[start_idx + i]); -destroy_workqueue (pf->dplls.wq); -} -static void ice_dpll_deinit_txclk_pins (struct ice_pf *pf) {struct ice_dplls *d = &pf->dplls;
@@ -4349,14 +4304,16 @@ static void ice_dpll_deinit_pins(struct ice_pf *pf, bool cgu)struct ice_dpll *de = &d->eec;struct ice_dpll *dp = &d->pps; -ice_dpll_deinit_rclk_pin (pf);if (pf->hw.mac_type ==ICE_MAC_GENERIC_3K_E825 ) {if (ice_pf_src_tmr_owned (pf) &&test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags))ice_dpll_deinit_tspll_pins (pf);ice_dpll_deinit_txclk_pins (pf); -ice_dpll_deinit_fwnode_pins (pf, pf->dplls.inputs,0 ); +ice_dpll_deinit_rclk_pin_e825c (pf);ice_dpll_rclk_muxes_put (pf); +destroy_workqueue (pf->dplls.wq); + }else { +ice_dpll_deinit_rclk_pin (pf); }if (cgu) { ice_dpll_unregister_pins(dp->dpll, inputs, &ice_dpll_input_ops,
@@ -4522,96 +4479,50 @@ static int ice_dpll_rclk_muxes_get(struct ice_pf *pf)return ret; } -static int -ice_dpll_init_fwnode_pin (struct ice_dpll_pin *pin,const char *name) -{ -struct ice_pf *pf = pin->pf; -int ret; - - pin->fwnode =ice_dpll_pin_node_get (pf, name); -if (IS_ERR (pin->fwnode)) { -dev_err (ice_pf_to_dev (pf), -"Failed to find %s firmware node: %pe\n" , name, - pin->fwnode); - pin->fwnode =NULL ; -return -ENODEV ; - } - -dev_dbg (ice_pf_to_dev (pf),"Found fwnode node for %s\n" , name); - - pin->pin =fwnode_dpll_pin_find (pin->fwnode, &pin->tracker); -if (IS_ERR_OR_NULL (pin->pin)) { -dev_info (ice_pf_to_dev (pf), -"DPLL pin for %pfwp not registered yet\n" , - pin->fwnode); - pin->pin =NULL ; - } - - pin->nb.notifier_call = ice_dpll_pin_notify; - ret =register_dpll_notifier (&pin->nb); -if (ret) { -dev_err (ice_pf_to_dev (pf), -"Failed to subscribe for DPLL notifications\n" ); - -if (!IS_ERR_OR_NULL (pin->pin)) { -dpll_pin_put (pin->pin, &pin->tracker); - pin->pin =NULL ; - } -fwnode_handle_put (pin->fwnode); - pin->fwnode =NULL ; - -return ret; - } - -return ret; -} -/** -* ice_dpll_init_fwnode_pins - initialize pins from device tree +* ice_dpll_init_rclk_pin_e825c - initialize recovered clock pin on E825 * @pf: board private structure -* @pins: pointer to pins array -* @start_idx: starting index for pins * -* Initialize input pins for E825 RCLK support. The parent pins (rclk0, rclk1) -* are expected to be defined by the system firmware (ACPI). This function -* allocates them in the dpll subsystem and stores their indices for later -* registration with the rclk pin. +* Get the recovered clock pin of the PF, register it with both recovered +* clock muxes and record the muxes that route its port. The clock ID of the +* pin is the clock ID of the muxes, so the pins of all PFs of the adapter +* share it. A clock ID based on the DSN would not tell the PFs apart either, +* as all PFs of a complex have the same DSN. * * Return: * * 0 - success -* * negative - initialization failure reason +* * negative - registration failure reason */ -static int -ice_dpll_init_fwnode_pins (struct ice_pf *pf,struct ice_dpll_pin *pins, -int start_idx) +static int ice_dpll_init_rclk_pin_e825c (struct ice_pf *pf) { -char pin_name[16 ]; -int i, ret; - - pf->dplls.wq =create_singlethread_workqueue ("ice_dpll_wq" ); -if (!pf->dplls.wq) -return -ENOMEM ; +struct ice_dpll_rclk_mux *muxes = pf->adapter->rclk_mux; +struct ice_dpll_pin *rclk = &pf->dplls.rclk; +struct ice_vsi *vsi =ice_get_main_vsi (pf); +int ret, i; -for (i =0 ; i < pf->dplls.rclk.num_parents; i++) { - pins[start_idx + i].pf = pf; -snprintf (pin_name,sizeof (pin_name),"rclk%u" , i); - ret =ice_dpll_init_fwnode_pin (&pins[start_idx + i], pin_name); + ret =ice_dpll_get_pins (pf, rclk,DPLL_PIN_IDX_UNSPEC ,1 , + pf->adapter->index); +if (ret) +return ret; +for (i =0 ; i <ICE_SYNCE_CLK_NUM ; i++) { + ret =dpll_pin_register (muxes[i].dpll, rclk->pin, + &ice_dpll_rclk_in_ops, rclk);if (ret) - goto error; + goto unregister_pin; } + ret =ice_dpll_rclk_src_init (pf); +if (ret) + goto unregister_pin; +dpll_netdev_pin_set (vsi->netdev, rclk->pin);return 0 ; -error: -/* -* A notifier worker may already be queued and blocked on dpll_init; -* release it so the per-pin flush below does not deadlock. -*/ -complete_all (&pf->dplls.dpll_init); -while (i--) -ice_dpll_deinit_fwnode_pin (&pins[start_idx + i]); - -destroy_workqueue (pf->dplls.wq); +unregister_pin: +while (i--) +dpll_pin_unregister (muxes[i].dpll, rclk->pin, + &ice_dpll_rclk_in_ops, rclk); +ice_dpll_rclk_src_fini (pf); +ice_dpll_release_pins (rclk,1 );return ret; }
@@ -4724,52 +4635,36 @@ static int ice_dpll_init_pins_e825(struct ice_pf *pf) {int ret; + pf->dplls.wq =create_singlethread_workqueue ("ice_dpll_wq" ); +if (!pf->dplls.wq) +return -ENOMEM ; + ret =ice_dpll_rclk_muxes_get (pf);if (ret) -return ret; - - ret =ice_dpll_init_fwnode_pins (pf, pf->dplls.inputs,0 ); + goto destroy_wq; + ret =ice_dpll_init_rclk_pin_e825c (pf);if (ret) goto put_muxes; - - ret =ice_dpll_init_rclk_pin (pf,DPLL_PIN_IDX_UNSPEC , - &ice_dpll_rclk_ops); - -if (ret) - goto unregister_pins; - - ret =ice_dpll_rclk_src_init (pf); -if (ret) { -ice_dpll_deinit_rclk_pin (pf); - goto unregister_pins; - } - ret =ice_dpll_init_txclk_pins (pf); -if (ret) { -ice_dpll_deinit_rclk_pin (pf); - goto unregister_pins; - } - +if (ret) + goto deinit_rclk_pin;if (ice_pf_src_tmr_owned (pf) &&test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags)) { ret =ice_dpll_init_tspll_pins (pf); -if (ret) { -ice_dpll_deinit_txclk_pins (pf); -ice_dpll_deinit_rclk_pin (pf); - } +if (ret) + goto deinit_txclk_pins; } -unregister_pins: -if (ret) { -/* Inform DPLL notifier works that DPLL init was finished -* unsuccessfully (ICE_DPLL_FLAG not set). -*/ -complete_all (&pf->dplls.dpll_init); -ice_dpll_deinit_fwnode_pins (pf, pf->dplls.inputs,0 ); - } +return 0 ; + +deinit_txclk_pins: +ice_dpll_deinit_txclk_pins (pf); +deinit_rclk_pin: +ice_dpll_deinit_rclk_pin_e825c (pf); put_muxes: -if (ret) -ice_dpll_rclk_muxes_put (pf); +ice_dpll_rclk_muxes_put (pf); +destroy_wq: +destroy_workqueue (pf->dplls.wq);return ret; }
@@ -5146,7 +5041,7 @@ ice_dpll_init_info_direct_pins(struct ice_pf *pf, }/** -* ice_dpll_init_info_pin_on_pin_e825c - initializes rclk pin information +* ice_dpll_init_info_rclk_pin_e825c - initializes rclk pin information * @pf: board private structure * * Init information for rclk pin, cache them in pf->dplls.rclk.
@@ -5154,7 +5049,7 @@ ice_dpll_init_info_direct_pins(struct ice_pf *pf,* Return: * * 0 - success */ -static int ice_dpll_init_info_pin_on_pin_e825c (struct ice_pf *pf) +static int ice_dpll_init_info_rclk_pin_e825c (struct ice_pf *pf) {struct ice_dpll_pin *rclk_pin = &pf->dplls.rclk;
@@ -5340,7 +5235,7 @@ ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)return ice_dpll_init_info_direct_pins (pf, pin_type);case ICE_DPLL_PIN_TYPE_RCLK_INPUT :if (pf->hw.mac_type ==ICE_MAC_GENERIC_3K_E825 ) -return ice_dpll_init_info_pin_on_pin_e825c (pf); +return ice_dpll_init_info_rclk_pin_e825c (pf);else return ice_dpll_init_info_rclk_pin (pf);case ICE_DPLL_PIN_TYPE_SOFTWARE :
@@ -5387,11 +5282,9 @@ static int ice_dpll_init_info_e825c(struct ice_pf *pf)struct ice_dplls *d = &pf->dplls;struct ice_dpll *tp = &d->tspll;struct ice_dpll *dt = &d->txc; -int ret =0 ; -int i; +int ret; d->clock_id =ice_generate_clock_id (pf); - d->num_inputs =ICE_SYNCE_CLK_NUM ; dt->dpll_state =ice_txclk_lock_status (pf->ptp.port.tx_clk); dt->mode =DPLL_MODE_MANUAL ; dt->dpll_idx =E825_DPLL_TXCLK_BASE_IDX + pf->ptp.port.port_num;
@@ -5400,33 +5293,11 @@ static int ice_dpll_init_info_e825c(struct ice_pf *pf) tp->mode =DPLL_MODE_MANUAL ; tp->dpll_idx =E825_DPLL_TSPLL_BASE_IDX ; - d->inputs =kzalloc_objs (*d->inputs, d->num_inputs); -if (!d->inputs) -return -ENOMEM ; - - ret =ice_get_cgu_rclk_pin_info (&pf->hw, &d->base_rclk_idx, - &pf->dplls.rclk.num_parents); -if (ret) - goto deinit_info; - -for (i =0 ; i < pf->dplls.rclk.num_parents; i++) - pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i; - ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_RCLK_INPUT );if (ret) - goto deinit_info; - - ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_TXCLK ); -if (ret) - goto deinit_info; +return ret; -dev_dbg (ice_pf_to_dev (pf), -"%s - success, inputs: %u, outputs: %u, rclk-parents: %u\n" , - __func__, d->num_inputs, d->num_outputs, d->rclk.num_parents); -return 0 ; -deinit_info: -ice_dpll_deinit_info (pf); -return ret; +return ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_TXCLK ); }/**
@@ -5615,7 +5486,6 @@ static void ice_dpll_init_e825(struct ice_pf *pf)*/ INIT_WORK (&d->txclk_work, ice_dpll_txclk_work);init_rwsem (&d->txclk_notify_rwsem); -init_completion (&d->dpll_init); err =ice_dpll_init_info_e825c (pf);if (err)
@@ -5626,17 +5496,6 @@ static void ice_dpll_init_e825(struct ice_pf *pf) DPLL_TYPE_GENERIC);if (err) goto deinit_info; -/* Start the periodic worker before registering fwnode pins. The -* fwnode notifier path (ice_dpll_pin_notify_work()) blocks on -* pf->dplls.dpll_init, which is only signalled on the success -* return below. Starting the worker before any fwnode notifier -* is registered means a subsequent init failure cannot leave -* notifier work items queued on pf->dplls.wq, so the deinit -* flush_workqueue() paths in ice_dpll_deinit_pins() cannot -* deadlock. The E825 periodic worker only touches -* pf->dplls.tspll (already registered above) and pf->ptp state, -* so it is safe to run before pins. -*/ err =ice_dpll_init_worker (pf);if (err) goto deinit_tspll;
@@ -5648,7 +5507,6 @@ static void ice_dpll_init_e825(struct ice_pf *pf)if (err) goto deinit_txclk;set_bit (ICE_FLAG_DPLL , pf->flags); -complete_all (&d->dpll_init);return ;
drivers/net/ethernet/intel/ice/ice_dpll.h +0 -9
@@ -39,12 +39,6 @@ enum ice_dpll_pin_sw { ICE_DPLL_PIN_SW_NUM }; -struct ice_dpll_pin_work { -struct work_struct work; -unsigned long action; -struct ice_dpll_pin *pin; -}; -/** ice_dpll_pin - store info about pins * @pin: dpll pin structure * @pf: pointer to pf, which has registered the dpll_pin
@@ -64,8 +58,6 @@ struct ice_dpll_pin {struct dpll_pin *pin;struct ice_pf *pf;dpll_tracker tracker; -struct fwnode_handle *fwnode; -struct notifier_block nb;u8 idx;u8 num_parents;u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX ];
@@ -179,7 +171,6 @@ struct ice_dplls {struct kthread_delayed_work work;struct workqueue_struct *wq;struct mutex lock; -struct completion dpll_init;struct ice_dpll eec;struct ice_dpll pps;struct ice_dpll txc;
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +0 -8
@@ -6220,14 +6220,6 @@ int ice_get_cgu_rclk_pin_info(struct ice_hw *hw, u8 *base_idx, u8 *pin_num)else ret = -ENODEV ;break ; -case ICE_DEV_ID_E825C_BACKPLANE : -case ICE_DEV_ID_E825C_QSFP : -case ICE_DEV_ID_E825C_SFP : -case ICE_DEV_ID_E825C_SGMII : - *pin_num =ICE_SYNCE_CLK_NUM ; - *base_idx =0 ; - ret =0 ; -break ;default : ret = -ENODEV ;break ;
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 15/19 dpll: register pins only with a parent pin of their owner
In reply to Ivan Veceradpll_pin_on_pin_register() accepts a parent pin of another owner and then registers the pin with the DPLLs of that owner. Its only user was ice on E825, which now describes its recovered clock muxes with its own DPLL devices linked with the zl3073x pins.
Require the same owner for the parent pin, as dpll_pin_register() does for the DPLL, and document how to describe a mux in front of an input of another device.
--- Documentation/driver-api/dpll.rst | 7 +++++-- drivers/dpll/dpll_core.c | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/driver-api/dpll.rst +5 -2
@@ -355,7 +355,8 @@ Pin ownership and links The owner of a dpll device or a pin is identified by the module and the clock_id passed to dpll_device_get() or dpll_pin_get(). dpll_pin_register() -accepts only a dpll device of the same owner as the pin. +accepts only a dpll device and dpll_pin_on_pin_register() only a parent pin +of the same owner as the pin. A pin represents a pad of the device whose driver registers it. When the board connects a pad of one device to a pad of another one, for example an
@@ -364,7 +365,9 @@ the driver of one of them describes the connection with dpll_pin_link_add() on its own pin. The link names the pin at the other end by its firmware node, which the driver of that pin sets with dpll_pin_fwnode_set(). Each driver registers only its own pins and the -drivers may probe in any order. +drivers may probe in any order. A mux of one device that feeds an input of +another device is a dpll device of its own driver, with the selectable +signals as input pins and an output pin linked with that input. While both pins are registered, ``DPLL_CMD_PIN_GET`` reports the link for each of them with the id of the pin at the other end:
drivers/dpll/dpll_core.c +9 -0
@@ -1081,6 +1081,8 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister);* * Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. +* The @parent and the @pin must have the same owner, they must be created +* with the same module and clock_id. * * Context: Acquires a lock (dpll_lock) * Return:
@@ -1097,6 +1099,13 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,if (WARN_ON (parent->prop.type !=DPLL_PIN_TYPE_MUX ))return -EINVAL ; +/* A pin of another owner is connected by a link, see +* dpll_pin_link_add(). +*/ +if (WARN_ON_ONCE (parent->module != pin->module || + parent->clock_id != pin->clock_id)) +return -EINVAL ; +if (WARN_ON (!ops) ||WARN_ON (!ops->state_on_pin_get) ||WARN_ON (!ops->direction_get))
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 16/19 dpll: drop the in-kernel notifier chain
In reply to Ivan VeceraThe only user of the notifier chain from commit 2be467588d6b ("dpll: Add notifier chain for dpll events") was ice on E825. The driver waited there for the zl3073x pins it registered its own pins with. It now links its own pins with them instead.
Drop the chain. The KUnit tests counted the change notifications of linked pins through it. Count them with a static stub of __dpll_pin_change_ntf() instead.
--- drivers/dpll/Kconfig | 4 +-- drivers/dpll/dpll_core.c | 43 --------------------------------- drivers/dpll/dpll_core.h | 2 -- drivers/dpll/dpll_netlink.c | 5 ++-- drivers/dpll/tests/dpll_kunit.c | 31 +++++++++--------------- include/linux/dpll.h | 18 -------------- 6 files changed, 15 insertions(+), 88 deletions(-)
drivers/dpll/Kconfig +2 -2
@@ -34,8 +34,8 @@ config DPLL_KUNIT_TEST while the pins at both ends are registered. The mock devices and pins are registered with the DPLL subsystem, - so user space sees them and their notifications while the tests - run. + so user space sees them and their create and delete notifications + while the tests run. If unsure, say N.
drivers/dpll/dpll_core.c +0 -43
61 lines not on this page · raw message
drivers/dpll/dpll_core.h +0 -2
@@ -111,6 +111,4 @@ extern struct xarray dpll_device_xa;extern struct xarray dpll_pin_xa;extern struct mutex dpll_lock; -void dpll_pin_notify (struct dpll_pin *pin,unsigned long action); -#endif
drivers/dpll/dpll_netlink.c +2 -3
@@ -6,6 +6,7 @@* Copyright (c) 2023 Intel and affiliates * */ +#include <kunit/static_stub.h> #include <kunit/visibility.h> #include <linux/module.h> #include <linux/kernel.h>
@@ -968,13 +969,11 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin)int dpll_pin_create_ntf (struct dpll_pin *pin) { -dpll_pin_notify (pin,DPLL_PIN_CREATED );return dpll_pin_event_send (DPLL_CMD_PIN_CREATE_NTF , pin); }int dpll_pin_delete_ntf (struct dpll_pin *pin) { -dpll_pin_notify (pin,DPLL_PIN_DELETED );return dpll_pin_event_send (DPLL_CMD_PIN_DELETE_NTF , pin); }
@@ -988,8 +987,8 @@ int dpll_pin_delete_ntf(struct dpll_pin *pin)*/ int __dpll_pin_change_ntf (struct dpll_pin *pin) { +KUNIT_STATIC_STUB_REDIRECT (__dpll_pin_change_ntf, pin);lockdep_assert_held (&dpll_lock); -dpll_pin_notify (pin,DPLL_PIN_CHANGED );return dpll_pin_event_send (DPLL_CMD_PIN_CHANGE_NTF , pin); }EXPORT_SYMBOL_GPL (__dpll_pin_change_ntf);
drivers/dpll/tests/dpll_kunit.c +11 -20
@@ -12,9 +12,9 @@*/ #include <kunit/fwnode.h> +#include <kunit/static_stub.h> #include <kunit/test.h> #include <linux/dpll.h> -#include <linux/notifier.h> #include <net/netlink.h> #include "../dpll_core.h"
@@ -35,15 +35,13 @@ struct dt_dev {struct dt_pin {struct dpll_pin *pin;dpll_tracker tracker; -int changes;/* DPLL_PIN_CHANGED notifications */ +int changes;/* change notifications */ };struct dt_ctx {struct dt_dev a0, a1, b0;struct dt_pin p, u, c;struct fwnode_handle *fwnode; -struct notifier_block nb; -bool nb_registered;bool p_a0, p_a1, u_a0, c_b0;/* registrations */ };
@@ -95,22 +93,19 @@ static const struct dpll_pin_properties dt_pin_prop = { .type = DPLL_PIN_TYPE_EXT, }; -static int dt_notify (struct notifier_block *nb,unsigned long action, -void *data) +/* Stub of __dpll_pin_change_ntf() that counts the notifications */ +static int dt_pin_change_ntf (struct dpll_pin *pin) { - struct dt_ctx *ctx = container_of(nb, struct dt_ctx, nb); -struct dpll_pin_notifier_info *info = data; +struct dt_ctx *ctx =kunit_get_current_test ()->priv; -if (action !=DPLL_PIN_CHANGED ) -return NOTIFY_DONE ; -if (info->pin == ctx->p.pin) +if (pin == ctx->p.pin) ctx->p.changes++; -else if (info->pin == ctx->u.pin) +else if (pin == ctx->u.pin) ctx->u.changes++; -else if (info->pin == ctx->c.pin) +else if (pin == ctx->c.pin) ctx->c.changes++; -return NOTIFY_OK ; +return 0 ; } static void dt_dev_init(struct kunit *test, struct dt_dev *dev, u64 clock_id,
@@ -235,10 +230,8 @@ static int dt_init(struct kunit *test) ret =dpll_pin_link_add (ctx->c.pin, ctx->fwnode);KUNIT_ASSERT_EQ (test, ret,0 ); - ctx->nb.notifier_call = dt_notify; - ret =register_dpll_notifier (&ctx->nb); -KUNIT_ASSERT_EQ (test, ret,0 ); - ctx->nb_registered = true; +kunit_activate_static_stub (test, __dpll_pin_change_ntf, + dt_pin_change_ntf);return 0 ; }
@@ -249,8 +242,6 @@ static void dt_exit(struct kunit *test)if (!ctx)return ; -if (ctx->nb_registered) -unregister_dpll_notifier (&ctx->nb);dt_unreg (&ctx->a0, &ctx->p, &ctx->p_a0);dt_unreg (&ctx->a1, &ctx->p, &ctx->p_a1);dt_unreg (&ctx->a0, &ctx->u, &ctx->u_a0);
include/linux/dpll.h +0 -18
@@ -11,7 +11,6 @@#include <linux/device.h> #include <linux/netlink.h> #include <linux/netdevice.h> -#include <linux/notifier.h> #include <linux/rtnetlink.h> #include <net/netlink.h>
@@ -211,19 +210,6 @@ typedef struct ref_tracker *dpll_tracker;typedef struct {}dpll_tracker ;#endif -#define DPLL_PIN_CREATED 4 -#define DPLL_PIN_DELETED 5 -#define DPLL_PIN_CHANGED 6 - -struct dpll_pin_notifier_info { -struct dpll_pin *pin; -u32 id; -u32 idx; -u64 clock_id; -const struct fwnode_handle *fwnode; -const struct dpll_pin_properties *prop; -}; -#if IS_ENABLED (CONFIG_DPLL )void dpll_netdev_pin_set (struct net_device *dev,struct dpll_pin *dpll_pin);void dpll_netdev_pin_clear (struct net_device *dev);
@@ -306,8 +292,4 @@ int dpll_device_change_ntf(struct dpll_device *dpll);int __dpll_pin_change_ntf (struct dpll_pin *pin);int dpll_pin_change_ntf (struct dpll_pin *pin); -int register_dpll_notifier (struct notifier_block *nb); - -int unregister_dpll_notifier (struct notifier_block *nb); -#endif
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 17/19 dpll: require a registered DPLL for pin registration
In reply to Ivan VeceraSince commit 33f016b23a21 ("dpll: fix NULL deref in dpll_device_ops() during teardown race"), dpll_pin_register() accepts a DPLL without registrations unless the pin has measured_freq_get, and dpll_pin_on_pin_register() registers a pin with the DPLLs of the parent pin without a check.
The drivers register a DPLL before its pins. Reject a DPLL that is not registered in dpll_pin_register() before its ops are requested, and a parent pin with such a DPLL in dpll_pin_on_pin_register(), and document the order.
The pin paths keep the tolerance for a DPLL without registrations from that commit. On E810, ice registers the recovered clock pin of a PF without the CGU under the input pins of the PF with the CGU, and so with its DPLLs. The pin stays registered with them when that PF goes first.
--- Documentation/driver-api/dpll.rst | 2 ++ drivers/dpll/dpll_core.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-)
Documentation/driver-api/dpll.rst +2 -0
@@ -634,6 +634,8 @@ of pin callbacks, and private data pointer for calling them: - dpll_pin_register() - register pin with a dpll device, - dpll_pin_on_pin_register() - register pin with another MUX type pin. +A dpll device is registered before its pins. + Notifications of adding or removing dpll devices are created within subsystem itself. Notifications about registering/deregistering pins are also invoked by
drivers/dpll/dpll_core.c +13 -4
@@ -925,7 +925,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* @priv: pointer to private information of owner * * The @dpll and the @pin must have the same owner, they must be created with -* the same module and clock_id. +* the same module and clock_id. The @dpll must be registered. * * Context: Acquires a lock (dpll_lock) * Return:
@@ -951,9 +951,13 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,mutex_lock (&dpll_lock); +if (ASSERT_DPLL_REGISTERED (dpll)) { + ret = -EINVAL ; + goto out_unlock; + } dev_ops =dpll_device_ops (dpll);if (WARN_ON (ops->measured_freq_get && - (!dev_ops || !dev_ops->freq_monitor_get || + (!dev_ops->freq_monitor_get || !dev_ops->freq_monitor_set))) { ret = -EINVAL ; goto out_unlock;
@@ -1039,7 +1043,8 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister);* Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * The @parent and the @pin must have the same owner, they must be created -* with the same module and clock_id. +* with the same module and clock_id. The dpll devices of the @parent must +* be registered. * * Context: Acquires a lock (dpll_lock) * Return:
@@ -1073,7 +1078,11 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,if (ret) goto unlock;xa_for_each (&parent->dpll_refs, i, ref) { - ret =__dpll_pin_register (ref->dpll, pin, ops, priv, parent); +if (ASSERT_DPLL_REGISTERED (ref->dpll)) + ret = -EINVAL ; +else + ret =__dpll_pin_register (ref->dpll, pin, ops, priv, + parent);if (ret) { stop = i; goto dpll_unregister;
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 18/19 dpll: drop the owner reference selection of pins
In reply to Ivan VeceraCommit 2c1bd78dc8e2 ("dpll: use pin owner's dpll ref for pin-level attribute reporting") and commit 84e85c325e5e ("dpll: use pin owner's dpll ref for pin-level attribute setting") made the pin-level paths look for the reference of a DPLL of the pin's owner, because a pin could also be registered with DPLLs of other owners.
Every DPLL a pin is registered with now has the owner of the pin. Use the first reference of a registered DPLL and drop dpll_pin_own_dpll_ref_first().
--- drivers/dpll/dpll_core.c | 27 --------------------------- drivers/dpll/dpll_core.h | 1 - drivers/dpll/dpll_netlink.c | 20 +++++++++----------- 3 files changed, 9 insertions(+), 39 deletions(-)
drivers/dpll/dpll_core.c +0 -27
@@ -1229,33 +1229,6 @@ void *dpll_pin_on_pin_priv(struct dpll_pin *parent,return reg->priv; } -/** -* dpll_pin_own_dpll_ref_first - find the first owner dpll ref of a pin -* @pin: pointer to a dpll pin -* -* Search pin's dpll_refs for a ref whose dpll matches the pin's -* (module, clock_id) tuple, i.e. the dpll registered by the driver -* that created the pin. This ensures pin-level attributes are -* reported and modified using the owner's ops even when the pin is -* also registered with dplls from other drivers. -* -* Return: pointer to the owner's dpll_pin_ref, or NULL if no -* owner ref is found. -*/ -struct dpll_pin_ref *dpll_pin_own_dpll_ref_first (struct dpll_pin *pin) -{ -struct dpll_pin_ref *ref; -unsigned long i; - -xa_for_each (&pin->dpll_refs, i, ref) { -if (ref->dpll->module == pin->module && - ref->dpll->clock_id == pin->clock_id) -return ref; - } - -return NULL ; -} -const struct dpll_pin_ops *dpll_pin_ops (struct dpll_pin_ref *ref) {struct dpll_pin_registration *reg;
drivers/dpll/dpll_core.h +0 -1
@@ -103,7 +103,6 @@ void *dpll_pin_on_pin_priv(struct dpll_pin *parent, struct dpll_pin *pin);const struct dpll_device_ops *dpll_device_ops (struct dpll_device *dpll);struct dpll_device *dpll_device_get_by_id (int id); -struct dpll_pin_ref *dpll_pin_own_dpll_ref_first (struct dpll_pin *pin);const struct dpll_pin_ops *dpll_pin_ops (struct dpll_pin_ref *ref);struct dpll_pin_ref *dpll_xa_ref_dpll_first (struct xarray *xa_refs);bool dpll_pins_linked (const struct dpll_pin *a,const struct dpll_pin *b);
drivers/dpll/dpll_netlink.c +9 -11
@@ -745,9 +745,7 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,struct dpll_pin_ref *ref;int ret; - ref =dpll_pin_own_dpll_ref_first (pin); -if (!ref || !dpll_device_registered (ref->dpll)) - ref =dpll_pin_first_registered_ref (pin); + ref =dpll_pin_first_registered_ref (pin);if (!ref)return -ENODEV ;
@@ -1134,8 +1132,8 @@ dpll_pin_freq_set(struct dpll_pin *pin, struct nlattr *a,return -EINVAL ; } - ref =dpll_pin_own_dpll_ref_first (pin); -if (!ref || !dpll_device_registered (ref->dpll)) { + ref =dpll_pin_first_registered_ref (pin); +if (!ref) {NL_SET_ERR_MSG (extack,"pin owner dpll not found" );return -ENODEV ; }
@@ -1180,8 +1178,8 @@ dpll_pin_esync_set(struct dpll_pin *pin, struct nlattr *a,bool supported = false;int ret, i; - ref =dpll_pin_own_dpll_ref_first (pin); -if (!ref || !dpll_device_registered (ref->dpll)) { + ref =dpll_pin_first_registered_ref (pin); +if (!ref) {NL_SET_ERR_MSG (extack,"pin owner dpll not found" );return -ENODEV ; }
@@ -1245,8 +1243,8 @@ dpll_pin_ref_sync_state_set(struct dpll_pin *pin,NL_SET_ERR_MSG (extack,"reference sync pin not available" );return -EINVAL ; } - ref =dpll_pin_own_dpll_ref_first (pin); -if (!ref || !dpll_device_registered (ref->dpll)) { + ref =dpll_pin_first_registered_ref (pin); +if (!ref) {NL_SET_ERR_MSG (extack,"pin owner dpll not found" );return -ENODEV ; }
@@ -1458,8 +1456,8 @@ dpll_pin_phase_adj_set(struct dpll_pin *pin, struct nlattr *phase_adj_attr,return -EINVAL ; } - ref =dpll_pin_own_dpll_ref_first (pin); -if (!ref || !dpll_device_registered (ref->dpll)) { + ref =dpll_pin_first_registered_ref (pin); +if (!ref) {NL_SET_ERR_MSG (extack,"pin owner dpll not found" );return -ENODEV ; }
Signature · 1 line
2.56.1
Ivan Vecera
reviewerRFC PATCH 19/19 dpll: add KUnit tests for the pin owner checks
In reply to Ivan VeceraCheck that dpll_pin_register() rejects a DPLL of another owner and a DPLL that is not registered, that dpll_pin_on_pin_register() rejects a parent pin of another owner and a parent pin registered with a DPLL that is not registered any more, and that a pin of the owner is still shared by its DPLLs and registered under its parent pin.
The checks are WARN_ON_ONCE(), so the tests suppress the warning without counting it. A registration that is not rejected is undone, so the next case does not get the registered pin and the failure stays in its case.
--- drivers/dpll/Kconfig | 4 +- drivers/dpll/tests/dpll_kunit.c | 150 +++++++++++++++++++++++++++++--- 2 files changed, 142 insertions(+), 12 deletions(-)
drivers/dpll/Kconfig +3 -1
@@ -31,7 +31,9 @@ config DPLL_KUNIT_TEST help KUnit tests for the DPLL core. They use a mock driver to check that links between pins of two devices are reported and notified - while the pins at both ends are registered. + while the pins at both ends are registered, and that a pin is + registered only with the registered devices and the parent pins + of its owner. The mock devices and pins are registered with the DPLL subsystem, so user space sees them and their create and delete notifications
drivers/dpll/tests/dpll_kunit.c +139 -11
205 lines not on this page · raw message
Signature · 1 line
2.56.1