Create common DPLL/clock configuration API
Subsystems (11)
v6 cover Create common DPLL/clock configuration API
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation in ptp_ocp is back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments to dpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- move dpll_type to uapi header
- rename DPLLA_DUMP_FILTER to DPLLA_FILTER
- rename dpll_pin_state to dpll_pin_mode
- rename DPLL_MODE_FORCED to DPLL_MODE_MANUAL
- remove DPLL_CHANGE_PIN_TYPE enum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s - dev_name(parent) of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally in dpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Remove ptp_ocp driver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
* ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing list
Arkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cgu
Vadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL ops
Documentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-) create mode 100644 Documentation/netlink/specs/dpll.yaml create mode 100644 Documentation/networking/dpll.rst create mode 100644 drivers/dpll/Kconfig create mode 100644 drivers/dpll/Makefile create mode 100644 drivers/dpll/dpll_core.c create mode 100644 drivers/dpll/dpll_core.h create mode 100644 drivers/dpll/dpll_netlink.c create mode 100644 drivers/dpll/dpll_netlink.h create mode 100644 drivers/dpll/dpll_nl.c create mode 100644 drivers/dpll/dpll_nl.h create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h create mode 100644 include/linux/dpll.h create mode 100644 include/uapi/linux/dpll.h
Signature · 1 line
2.34.1
RFC PATCH v6 1/6 dpll: spec: Add Netlink spec in YAML
From: Arkadiusz Kubalewski <[email protected]>
Add a protocol spec for DPLL.
Add code generated from the spec.
--- Documentation/netlink/specs/dpll.yaml | 514 ++++++++++++++++++++++++++ drivers/dpll/dpll_nl.c | 126 +++++++ drivers/dpll/dpll_nl.h | 42 +++ include/uapi/linux/dpll.h | 196 ++++++++++ 4 files changed, 878 insertions(+) create mode 100644 Documentation/netlink/specs/dpll.yaml create mode 100644 drivers/dpll/dpll_nl.c create mode 100644 drivers/dpll/dpll_nl.h create mode 100644 include/uapi/linux/dpll.h
Documentation/netlink/specs/dpll.yaml new file +514 -0
@@ -0,0 +1,514 @@ +name: dpll + +doc: DPLL subsystem. + +definitions: + - + type: const + name: temp-divider + value: 10 + - + type: const + name: pin-freq-1-hz + value: 1 + - + type: const + name: pin-freq-10-mhz + value: 10000000 + - + type: enum + name: lock-status + doc: | + Provides information of dpll device lock status, valid values for + DPLL_A_LOCK_STATUS attribute + entries: + - + name: unspec + doc: unspecified value + - + name: unlocked + doc: | + dpll was not yet locked to any valid (or is in one of modes: + DPLL_MODE_FREERUN, DPLL_MODE_NCO) + - + name: calibrating + doc: dpll is trying to lock to a valid signal + - + name: locked + doc: dpll is locked + - + name: holdover + doc: | + dpll is in holdover state - lost a valid lock or was forced by + selecting DPLL_MODE_HOLDOVER mode + render-max: true + - + type: enum + name: pin-type + doc: Enumerates types of a pin, valid values for DPLL_A_PIN_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: mux + doc: aggregates another layer of selectable pins + - + name: ext + doc: external source + - + name: synce-eth-port + doc: ethernet port PHY's recovered clock + - + name: int-oscillator + doc: device internal oscillator + - + name: gnss + doc: GNSS recovered clock + render-max: true + - + type: enum + name: pin-state + doc: available pin modes + entries: + - + name: unspec + doc: unspecified value + - + name: connected + doc: pin connected + - + name: disconnected + doc: pin disconnected + render-max: true + - + type: enum + name: pin-direction + doc: available pin direction + entries: + - + name: unspec + doc: unspecified value + - + name: source + doc: pin used as a source of a signal + - + name: output + doc: pin used to output the signal + render-max: true + - + type: enum + name: mode + doc: | + working-modes a dpll can support, differentiate if and how dpll selects + one of its sources to syntonize with it + entries: + - + name: unspec + doc: unspecified value + - + name: manual + doc: source can be only selected by sending a request to dpll + - + name: automatic + doc: highest prio, valid source, auto selected by dpll + - + name: holdover + doc: dpll forced into holdover mode + - + name: freerun + doc: dpll driven on system clk, no holdover available + - + name: nco + doc: dpll driven by Numerically Controlled Oscillator + render-max: true + - + type: enum + name: type + doc: type of dpll, valid values for DPLL_A_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: pps + doc: dpll produces Pulse-Per-Second signal + - + name: eec + doc: dpll drives the Ethernet Equipment Clock + render-max: true + - + type: enum + name: event + doc: events of dpll generic netlink family + entries: + - + name: unspec + doc: invalid event type + - + name: device-create + doc: dpll device created + - + name: device-delete + doc: dpll device deleted + - + name: device-change + doc: | + attribute of dpll device or pin changed, reason is to be found with + an attribute type (DPLL_A_*) received with the event + - + type: flags + name: pin-caps + doc: define capabilities of a pin + entries: + - + name: direction-can-change + - + name: priority-can-change + - + name: state-can-change + + +attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: id + type: u32 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + multi-attr: true + nested-attributes: pin + value: 12 + - + name: pin-idx + type: u32 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + - + name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23 + - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pin + - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26 + - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + - + name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32 + - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-state + type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: string + + +operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dpll device + attribute-set: dpll + flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump: + pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes: + - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll + flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - mode + + - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pins in the system + - dump request with target dpll - list all the pins registered with a given dpll device + - do request with target dpll and target pin - single pin attributes + attribute-set: dpll + flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + reply: + attributes: + - pin + + dump: + pre: dpll-pin-pre-dumpit + post: dpll-pin-post-dumpit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - pin + + - + name: pin-set + doc: Set attributes of a target pin + attribute-set: dpll + flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + - pin-frequency + - pin-direction + - pin-prio + - pin-parent-idx + - pin-state + +mcast-groups: + list: + - + name: monitor
drivers/dpll/dpll_nl.c new file +126 -0
126 lines not on this page · raw message
drivers/dpll/dpll_nl.h new file +42 -0
42 lines not on this page · raw message
include/uapi/linux/dpll.h new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 117 lines · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
Add a protocol spec for DPLL.
Add code generated from the spec.Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Michal Michalik <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Vadim Fedorenko <[email protected]>---
Documentation/netlink/specs/dpll.yaml | 514 ++++++++++++++++++++++++++ drivers/dpll/dpll_nl.c | 126 +++++++ drivers/dpll/dpll_nl.h | 42 +++ include/uapi/linux/dpll.h | 196 ++++++++++ 4 files changed, 878 insertions(+)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644drivers/dpll/dpll_nl.ccreate mode 100644drivers/dpll/dpll_nl.hcreate mode 100644include/uapi/linux/dpll.hDocumentation/netlink/specs/dpll.yaml new file +91
-0@@ -0,0 +1,514 @@ +name: dpll + +doc: DPLL subsystem. + +definitions: + - + type: const + name: temp-divider + value: 10 + - + type: const + name: pin-freq-1-hz + value: 1 + - + type: const + name: pin-freq-10-mhz + value: 10000000 + - + type: enum + name: lock-status + doc: | + Provides information of dpll device lock status, valid values for + DPLL_A_LOCK_STATUS attribute + entries: + - + name: unspec + doc: unspecified value + - + name: unlocked + doc: | + dpll was not yet locked to any valid (or is in one of modes: + DPLL_MODE_FREERUN, DPLL_MODE_NCO) + - + name: calibrating + doc: dpll is trying to lock to a valid signal + - + name: locked + doc: dpll is locked + - + name: holdover + doc: | + dpll is in holdover state - lost a valid lock or was forced by + selecting DPLL_MODE_HOLDOVER mode + render-max: true + - + type: enum + name: pin-type + doc: Enumerates types of a pin, valid values for DPLL_A_PIN_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: mux + doc: aggregates another layer of selectable pins + - + name: ext + doc: external source + - + name: synce-eth-port + doc: ethernet port PHY's recovered clock + - + name: int-oscillator + doc: device internal oscillator + - + name: gnss + doc: GNSS recovered clock + render-max: true + - + type: enum + name: pin-state + doc: available pin modes + entries: + - + name: unspec + doc: unspecified value + - + name: connected + doc: pin connected + - + name: disconnected + doc: pin disconnected + render-max: true + - + type: enum + name: pin-direction + doc: available pin direction + entries: + - + name: unspec + doc: unspecified value
Documentation/netlink/specs/dpll.yaml line 101
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: source + doc: pin used as a source of a signal + - + name: output + doc: pin used to output the signal + render-max: true + - + type: enum + name: mode
Could you please sort the enums so they are in the same order as the attribute which carries them? That would also put the device and pin enums together.
Quoted 71 lines
Documentation/netlink/specs/dpll.yaml new file +71
-0+ doc: | + working-modes a dpll can support, differentiate if and how dpll selects + one of its sources to syntonize with it + entries: + - + name: unspec + doc: unspecified value + - + name: manual + doc: source can be only selected by sending a request to dpll + - + name: automatic + doc: highest prio, valid source, auto selected by dpll + - + name: holdover + doc: dpll forced into holdover mode + - + name: freerun + doc: dpll driven on system clk, no holdover available + - + name: nco + doc: dpll driven by Numerically Controlled Oscillator + render-max: true + - + type: enum + name: type + doc: type of dpll, valid values for DPLL_A_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: pps + doc: dpll produces Pulse-Per-Second signal + - + name: eec + doc: dpll drives the Ethernet Equipment Clock + render-max: true + - + type: enum + name: event + doc: events of dpll generic netlink family + entries: + - + name: unspec + doc: invalid event type + - + name: device-create + doc: dpll device created + - + name: device-delete + doc: dpll device deleted + - + name: device-change + doc: | + attribute of dpll device or pin changed, reason is to be found with + an attribute type (DPLL_A_*) received with the event + - + type: flags + name: pin-caps + doc: define capabilities of a pin + entries: + - + name: direction-can-change + - + name: priority-can-change + - + name: state-can-change + + +attribute-sets:
Documentation/netlink/specs/dpll.yaml line 182
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
Quoted 17 lines
Documentation/netlink/specs/dpll.yaml new file +17
-0+ - + name: id + type: u32 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode
Documentation/netlink/specs/dpll.yaml line 209
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp
Could you put some comment regarding the divider here?
Quoted 31 lines
Documentation/netlink/specs/dpll.yaml new file +31
-0+ type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + multi-attr: true + nested-attributes: pin + value: 12 + - + name: pin-idx + type: u32 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32
Documentation/netlink/specs/dpll.yaml line 250
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32
These 2 attrs somehow overlap with pin-frequency-supported, which is a bit confusing, I think that pin-frequency-supported should carry all supported frequencies. How about to have something like:
name: pin-frequency-supported
type: nest
multi-attr: true
nested-attributes: pin-frequency-range
and then:
name: pin-frequency-range
subset-of: dpll
attributes:
-
name: pin-frequency-min
type: u32
-
name: pin-frequency-max
type: u32
doc: should be put only to specify range when value differs
from pin-frequency-minThat could carry list of frequencies and ranges, in this case multiple ones if possibly needed.
Documentation/netlink/specs/dpll.yaml line 263
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +13
-0+ - + name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?
Quoted 45 lines
Documentation/netlink/specs/dpll.yaml new file +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64
Documentation/netlink/specs/dpll.yaml line 318
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pin
This does not belong here.
Documentation/netlink/specs/dpll.yaml line 330
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26
All these 3 do not belong here are well.
Quoted 39 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -
Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true
Multiple parents? How is that supposed to work?
Documentation/netlink/specs/dpll.yaml line 388
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32
Missing "enum: "
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-state
Documentation/netlink/specs/dpll.yaml line 404
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: string
Yeah, as I wrote in the other email, this really smells to have like a simple string like this. What is it supposed to be?
Documentation/netlink/specs/dpll.yaml line 417
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +13
-0+ + +operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dpll device + attribute-set: dpll
Shouldn't this be "device"?
Quoted 15 lines
Documentation/netlink/specs/dpll.yaml new file +15
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump:
Documentation/netlink/specs/dpll.yaml line 442
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes: + - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll
"device" here as well?
Documentation/netlink/specs/dpll.yaml line 453
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - mode
Hmm, shouldn't source-pin-index be here as well?
Documentation/netlink/specs/dpll.yaml line 462
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ + - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pins in the system + - dump request with target dpll - list all the pins registered with a given dpll device + - do request with target dpll and target pin - single pin attributes + attribute-set: dpll
"pin"?
Quoted 21 lines
Documentation/netlink/specs/dpll.yaml new file +21
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + reply: + attributes: + - pin + + dump: + pre: dpll-pin-pre-dumpit + post: dpll-pin-post-dumpit + request: + attributes: + - id
Documentation/netlink/specs/dpll.yaml line 493
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - bus-name + - dev-name + reply: + attributes: + - pin + + - + name: pin-set + doc: Set attributes of a target pin + attribute-set: dpll
"pin"?
Quoted 42 lines
Documentation/netlink/specs/dpll.yaml new file +21
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + - pin-frequency + - pin-direction + - pin-prio + - pin-parent-idx + - pin-state + +mcast-groups: + list: + - + name: monitordrivers/dpll/dpll_nl.c new file +15
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel source */ + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include "dpll_nl.h" + +#include <linux/dpll.h> + +/* DPLL_CMD_DEVICE_GET - do */ +static const struct nla_policy dpll_device_get_nl_policy[DPLL_A_BUS_NAME +1 ] = { + [DPLL_A_ID ] = { .type =NLA_U32 , },
drivers/dpll/dpll_nl.c line 25
Quoted 10 lines
drivers/dpll/dpll_nl.c new file +10
-0+ [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, +}; + +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1 ] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_DEV_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_MODE ] =NLA_POLICY_MAX (NLA_U8 ,5 ),
Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 14 lines
drivers/dpll/dpll_nl.c new file +14
-0+}; + +/* DPLL_CMD_PIN_GET - do */ +static const struct nla_policy dpll_pin_get_do_nl_policy[DPLL_A_PIN_IDX +1 ] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_DEV_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_PIN_IDX ] = { .type =NLA_U32 , }, +}; + +/* DPLL_CMD_PIN_GET - dump */ +static const struct nla_policy dpll_pin_get_dump_nl_policy[DPLL_A_BUS_NAME +1 ] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , },
drivers/dpll/dpll_nl.c line 49
Quoted 10 lines
drivers/dpll/dpll_nl.c new file +10
-0+ [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, +}; + +/* DPLL_CMD_PIN_SET - do */ +static const struct nla_policy dpll_pin_set_nl_policy[DPLL_A_PIN_PARENT_IDX +1 ] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_DEV_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_PIN_IDX ] = { .type =NLA_U32 , }, + [DPLL_A_PIN_FREQUENCY ] = { .type =NLA_U32 , },
4.3GHz would be the limit, isn't it future proof to make this rather u64?
drivers/dpll/dpll_nl.c line 52
Quoted 3 lines
drivers/dpll/dpll_nl.c new file +3
-0+ [DPLL_A_PIN_DIRECTION] = NLA_POLICY_MAX(NLA_U8, 2), + [DPLL_A_PIN_PRIO] = { .type = NLA_U32, }, + [DPLL_A_PIN_PARENT_IDX] = { .type = NLA_U32, },
This is a bit odd. The size is DPLL_A_PIN_PARENT_IDX + 1, yet PIN_STATE is last. I found that the order is not according to the enum in the yaml operation definition. Perhaps the generator can sort this?
Quoted 130 lines
drivers/dpll/dpll_nl.c new file +74
-0+ [DPLL_A_PIN_STATE] = NLA_POLICY_MAX(NLA_U8, 2), +}; + +/* Ops table for dpll */ +static const struct genl_split_ops dpll_nl_ops[6 ] = { + { + .cmd =DPLL_CMD_DEVICE_GET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_get_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_get_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_DEVICE_GET , + .start = dpll_pre_dumpit, + .dumpit = dpll_nl_device_get_dumpit, + .done = dpll_post_dumpit, + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_DEVICE_SET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_set_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_set_nl_policy, + .maxattr =DPLL_A_MODE , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_get_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_get_do_nl_policy, + .maxattr =DPLL_A_PIN_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .start = dpll_pin_pre_dumpit, + .dumpit = dpll_nl_pin_get_dumpit, + .done = dpll_pin_post_dumpit, + .policy = dpll_pin_get_dump_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_PIN_SET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_set_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_set_nl_policy, + .maxattr =DPLL_A_PIN_PARENT_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, +}; + +static const struct genl_multicast_group dpll_nl_mcgrps[] = { + [DPLL_NLGRP_MONITOR ] = {"monitor" , }, +}; + +struct genl_family dpll_nl_family__ro_after_init = { + .name =DPLL_FAMILY_NAME , + .version =DPLL_FAMILY_VERSION , + .netnsok = true, + .parallel_ops = true, + .module =THIS_MODULE , + .split_ops = dpll_nl_ops, + .n_split_ops =ARRAY_SIZE (dpll_nl_ops), + .mcgrps = dpll_nl_mcgrps, + .n_mcgrps =ARRAY_SIZE (dpll_nl_mcgrps), +};drivers/dpll/dpll_nl.h new file +42
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_DPLL_GEN_H +#define _LINUX_DPLL_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/dpll.h> + +int dpll_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pin_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +void +dpll_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +void +dpll_pin_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pre_dumpit (struct netlink_callback *cb); +int dpll_pin_pre_dumpit (struct netlink_callback *cb); +int dpll_post_dumpit (struct netlink_callback *cb); +int dpll_pin_post_dumpit (struct netlink_callback *cb); + +int dpll_nl_device_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_device_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int dpll_nl_device_set_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int dpll_nl_pin_set_doit (struct sk_buff *skb,struct genl_info *info); + +enum { +DPLL_NLGRP_MONITOR , +}; + +extern struct genl_family dpll_nl_family; + +#endif /* _LINUX_DPLL_GEN_H */ include/uapi/linux/dpll.h new file +2
-0@@ -0,0 +1,196 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Do not edit directly, auto-generated from: */
include/uapi/linux/dpll.h line 12
Quoted 10 lines
include/uapi/linux/dpll.h new file +10
-0+/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_DPLL_H +#define _UAPI_LINUX_DPLL_H + +#define DPLL_FAMILY_NAME "dpll" +#define DPLL_FAMILY_VERSION 1 + +#define DPLL_TEMP_DIVIDER 10
Some comment to this define would be nice.
include/uapi/linux/dpll.h line 14
Quoted 2 lines
include/uapi/linux/dpll.h new file +2
-0+#define DPLL_PIN_FREQ_1_HZ 1 +#define DPLL_PIN_FREQ_10_MHZ 10000000
Have this as enum. Spell out "frequency" to be consistent with the related attribute name.
include/uapi/linux/dpll.h line 20
Quoted 6 lines
include/uapi/linux/dpll.h new file +6
-0+ +/** +* enum dpll_lock_status - Provides information of dpll device lock status, +* valid values for DPLL_A_LOCK_STATUS attribute +* @DPLL_LOCK_STATUS_UNSPEC: unspecified value +* @DPLL_LOCK_STATUS_UNLOCKED: dpll was not yet locked to any valid (or is in
"any valid source" perhaps?
Quoted 31 lines
include/uapi/linux/dpll.h new file +31
-0+* one of modes: DPLL_MODE_FREERUN, DPLL_MODE_NCO) +* @DPLL_LOCK_STATUS_CALIBRATING: dpll is trying to lock to a valid signal +* @DPLL_LOCK_STATUS_LOCKED: dpll is locked +* @DPLL_LOCK_STATUS_HOLDOVER: dpll is in holdover state - lost a valid lock or +* was forced by selecting DPLL_MODE_HOLDOVER mode +*/ +enum dpll_lock_status { +DPLL_LOCK_STATUS_UNSPEC , +DPLL_LOCK_STATUS_UNLOCKED , +DPLL_LOCK_STATUS_CALIBRATING , +DPLL_LOCK_STATUS_LOCKED , +DPLL_LOCK_STATUS_HOLDOVER , + + __DPLL_LOCK_STATUS_MAX, +DPLL_LOCK_STATUS_MAX = (__DPLL_LOCK_STATUS_MAX -1 ) +}; + +/** +* enum dpll_pin_type - Enumerates types of a pin, valid values for +* DPLL_A_PIN_TYPE attribute +* @DPLL_PIN_TYPE_UNSPEC: unspecified value +* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins +* @DPLL_PIN_TYPE_EXT: external source +* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock +* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator +* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock +*/ +enum dpll_pin_type { +DPLL_PIN_TYPE_UNSPEC , +DPLL_PIN_TYPE_MUX , +DPLL_PIN_TYPE_EXT ,
include/uapi/linux/dpll.h line 61
Quoted 10 lines
include/uapi/linux/dpll.h new file +10
-0+DPLL_PIN_TYPE_SYNCE_ETH_PORT , +DPLL_PIN_TYPE_INT_OSCILLATOR , +DPLL_PIN_TYPE_GNSS , + + __DPLL_PIN_TYPE_MAX, + DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1) +}; + +/** +* enum dpll_pin_state - available pin modes
For some of the enums, you say for what attribute it serves as a value set, for some you don't. Please unify the approach. I think it is valuable to say that for every enum.
Quoted 94 lines
include/uapi/linux/dpll.h new file +94
-0+* @DPLL_PIN_STATE_UNSPEC: unspecified value +* @DPLL_PIN_STATE_CONNECTED: pin connected +* @DPLL_PIN_STATE_DISCONNECTED: pin disconnected +*/ +enum dpll_pin_state { +DPLL_PIN_STATE_UNSPEC , +DPLL_PIN_STATE_CONNECTED , +DPLL_PIN_STATE_DISCONNECTED , + + __DPLL_PIN_STATE_MAX, +DPLL_PIN_STATE_MAX = (__DPLL_PIN_STATE_MAX -1 ) +}; + +/** +* enum dpll_pin_direction - available pin direction +* @DPLL_PIN_DIRECTION_UNSPEC: unspecified value +* @DPLL_PIN_DIRECTION_SOURCE: pin used as a source of a signal +* @DPLL_PIN_DIRECTION_OUTPUT: pin used to output the signal +*/ +enum dpll_pin_direction { +DPLL_PIN_DIRECTION_UNSPEC , +DPLL_PIN_DIRECTION_SOURCE , +DPLL_PIN_DIRECTION_OUTPUT , + + __DPLL_PIN_DIRECTION_MAX, +DPLL_PIN_DIRECTION_MAX = (__DPLL_PIN_DIRECTION_MAX -1 ) +}; + +/** +* enum dpll_mode - working-modes a dpll can support, differentiate if and how +* dpll selects one of its sources to syntonize with it +* @DPLL_MODE_UNSPEC: unspecified value +* @DPLL_MODE_MANUAL: source can be only selected by sending a request to dpll +* @DPLL_MODE_AUTOMATIC: highest prio, valid source, auto selected by dpll +* @DPLL_MODE_HOLDOVER: dpll forced into holdover mode +* @DPLL_MODE_FREERUN: dpll driven on system clk, no holdover available +* @DPLL_MODE_NCO: dpll driven by Numerically Controlled Oscillator +*/ +enum dpll_mode { +DPLL_MODE_UNSPEC , +DPLL_MODE_MANUAL , +DPLL_MODE_AUTOMATIC , +DPLL_MODE_HOLDOVER , +DPLL_MODE_FREERUN , +DPLL_MODE_NCO , + + __DPLL_MODE_MAX, +DPLL_MODE_MAX = (__DPLL_MODE_MAX -1 ) +}; + +/** +* enum dpll_type - type of dpll, valid values for DPLL_A_TYPE attribute +* @DPLL_TYPE_UNSPEC: unspecified value +* @DPLL_TYPE_PPS: dpll produces Pulse-Per-Second signal +* @DPLL_TYPE_EEC: dpll drives the Ethernet Equipment Clock +*/ +enum dpll_type { +DPLL_TYPE_UNSPEC , +DPLL_TYPE_PPS , +DPLL_TYPE_EEC , + + __DPLL_TYPE_MAX, +DPLL_TYPE_MAX = (__DPLL_TYPE_MAX -1 ) +}; + +/** +* enum dpll_event - events of dpll generic netlink family +* @DPLL_EVENT_UNSPEC: invalid event type +* @DPLL_EVENT_DEVICE_CREATE: dpll device created +* @DPLL_EVENT_DEVICE_DELETE: dpll device deleted +* @DPLL_EVENT_DEVICE_CHANGE: attribute of dpll device or pin changed, reason +* is to be found with an attribute type (DPLL_A_*) received with the event +*/ +enum dpll_event { +DPLL_EVENT_UNSPEC , +DPLL_EVENT_DEVICE_CREATE , +DPLL_EVENT_DEVICE_DELETE , +DPLL_EVENT_DEVICE_CHANGE , +}; + +/** +* enum dpll_pin_caps - define capabilities of a pin +*/ +enum dpll_pin_caps { +DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE =1 , +DPLL_PIN_CAPS_PRIORITY_CAN_CHANGE =2 , +DPLL_PIN_CAPS_STATE_CAN_CHANGE =4 , +}; + +enum dplla { +DPLL_A_DEVICE =1 , +DPLL_A_ID , +DPLL_A_DEV_NAME , +DPLL_A_BUS_NAME ,
include/uapi/linux/dpll.h line 165
Quoted 10 lines
include/uapi/linux/dpll.h new file +10
-0+DPLL_A_MODE , +DPLL_A_MODE_SUPPORTED , +DPLL_A_SOURCE_PIN_IDX , +DPLL_A_LOCK_STATUS , +DPLL_A_TEMP , +DPLL_A_CLOCK_ID , +DPLL_A_TYPE , +DPLL_A_PIN , +DPLL_A_PIN_IDX , + DPLL_A_PIN_DESCRIPTION,
I commented this name in the other email. This does not describe anything. It is a label on a connector, isn't it? Why don't to call it "label"?
include/uapi/linux/dpll.h line 171
Quoted 6 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_TYPE , +DPLL_A_PIN_DIRECTION , +DPLL_A_PIN_FREQUENCY , +DPLL_A_PIN_FREQUENCY_SUPPORTED , +DPLL_A_PIN_ANY_FREQUENCY_MIN , + DPLL_A_PIN_ANY_FREQUENCY_MAX,
Drop "any". Not good for anything.
include/uapi/linux/dpll.h line 177
Quoted 6 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,
Just DPLL_A_PIN_CAPS is enough, that would be also consistent with the enum name.
Quoted 22 lines
include/uapi/linux/dpll.h new file +19
-0+ + __DPLL_A_MAX, +DPLL_A_MAX = (__DPLL_A_MAX -1 ) +}; + +enum { +DPLL_CMD_UNSPEC , +DPLL_CMD_DEVICE_GET , +DPLL_CMD_DEVICE_SET , +DPLL_CMD_PIN_GET , +DPLL_CMD_PIN_SET , + + __DPLL_CMD_MAX, +DPLL_CMD_MAX = (__DPLL_CMD_MAX -1 ) +}; + +#define DPLL_MCGRP_MONITOR "monitor" + +#endif /* _UAPI_LINUX_DPLL_H */ Signature · 1 line
2.34.1
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 129 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 3:44 PMQuoted 125 lines · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
Add a protocol spec for DPLL.
Add code generated from the spec.Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Michal Michalik <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Vadim Fedorenko <[email protected]>---
Documentation/netlink/specs/dpll.yaml | 514 ++++++++++++++++++++++++++ drivers/dpll/dpll_nl.c | 126 +++++++ drivers/dpll/dpll_nl.h | 42 +++ include/uapi/linux/dpll.h | 196 ++++++++++ 4 files changed, 878 insertions(+)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644drivers/dpll/dpll_nl.ccreate mode 100644drivers/dpll/dpll_nl.hcreate mode 100644include/uapi/linux/dpll.hDocumentation/netlink/specs/dpll.yaml new file +48
-0@@ -0,0 +1,514 @@ +name: dpll + +doc: DPLL subsystem. + +definitions: + - + type: const + name: temp-divider + value: 10 + - + type: const + name: pin-freq-1-hz + value: 1 + - + type: const + name: pin-freq-10-mhz + value: 10000000 + - + type: enum + name: lock-status + doc: | + Provides information of dpll device lock status, valid values for + DPLL_A_LOCK_STATUS attribute + entries: + - + name: unspec + doc: unspecified value + - + name: unlocked + doc: | + dpll was not yet locked to any valid (or is in one of modes: + DPLL_MODE_FREERUN, DPLL_MODE_NCO) + - + name: calibrating + doc: dpll is trying to lock to a valid signal + - + name: locked + doc: dpll is locked + - + name: holdover + doc: | + dpll is in holdover state - lost a valid lock or was forced by + selecting DPLL_MODE_HOLDOVER mode + render-max: true + - + type: enum + name: pin-type + doc: Enumerates types of a pin, valid values for DPLL_A_PIN_TYPEattribute
Documentation/netlink/specs/dpll.yaml new file +49
-0+ entries: + - + name: unspec + doc: unspecified value + - + name: mux + doc: aggregates another layer of selectable pins + - + name: ext + doc: external source + - + name: synce-eth-port + doc: ethernet port PHY's recovered clock + - + name: int-oscillator + doc: device internal oscillator + - + name: gnss + doc: GNSS recovered clock + render-max: true + - + type: enum + name: pin-state + doc: available pin modes + entries: + - + name: unspec + doc: unspecified value + - + name: connected + doc: pin connected + - + name: disconnected + doc: pin disconnected + render-max: true + - + type: enum + name: pin-direction + doc: available pin direction + entries: + - + name: unspec + doc: unspecified value + - + name: source + doc: pin used as a source of a signal + - + name: output + doc: pin used to output the signal
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 101
Quoted 4 lines
Documentation/netlink/specs/dpll.yaml new file +4
-0+ render-max: true + - + type: enum + name: modeCould you please sort the enums so they are in the same order as the attribute which carries them? That would also put the device and pin enums together.
Fixed.
Quoted 79 lines
Quoted 79 lines
Documentation/netlink/specs/dpll.yaml new file +2
-0+ doc: | + working-modes a dpll can support, differentiate if and how dpllselects
Documentation/netlink/specs/dpll.yaml new file +54
-0+ one of its sources to syntonize with it + entries: + - + name: unspec + doc: unspecified value + - + name: manual + doc: source can be only selected by sending a request to dpll + - + name: automatic + doc: highest prio, valid source, auto selected by dpll + - + name: holdover + doc: dpll forced into holdover mode + - + name: freerun + doc: dpll driven on system clk, no holdover available + - + name: nco + doc: dpll driven by Numerically Controlled Oscillator + render-max: true + - + type: enum + name: type + doc: type of dpll, valid values for DPLL_A_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: pps + doc: dpll produces Pulse-Per-Second signal + - + name: eec + doc: dpll drives the Ethernet Equipment Clock + render-max: true + - + type: enum + name: event + doc: events of dpll generic netlink family + entries: + - + name: unspec + doc: invalid event type + - + name: device-create + doc: dpll device created + - + name: device-delete + doc: dpll device deleted + - + name: device-change + doc: | + attribute of dpll device or pin changed, reason is to be foundwith
Documentation/netlink/specs/dpll.yaml new file +20
-0+ an attribute type (DPLL_A_*) received with the event + - + type: flags + name: pin-caps + doc: define capabilities of a pin + entries: + - + name: direction-can-change + - + name: priority-can-change + - + name: state-can-change + + +attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + -
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 5 lines
Documentation/netlink/specs/dpll.yaml new file +5
-0+ name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceWhat is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},
{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}]}]- do/dump of pin-get, in case of shared pins, each pin contains number of dpll handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci',
'dev-name': '0000:21:00.0_0',
'id': 0,
'pin-prio': 6,
'pin-state': {'doc': 'pin connected',
'name': 'connected'}},
{'bus-name': 'pci',
'dev-name': '0000:21:00.0_1',
'id': 1,
'pin-prio': 8,
'pin-state': {'doc': 'pin connected',
'name': 'connected'}}],
'pin-direction': {'doc': 'pin used as a source of a signal',
'name': 'source'},
'pin-frequency': 1,
'pin-frequency-supported': [1, 10000000],
'pin-idx': 0,
...Quoted 29 lines
Quoted 18 lines
Documentation/netlink/specs/dpll.yaml new file +17
-0+ - + name: id + type: u32 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: modeDocumentation/netlink/specs/dpll.yaml line 209
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp
Quoted 2 lines
Could you put some comment regarding the divider here?
Sure, fixed.
Quoted 65 lines
Quoted 32 lines
Documentation/netlink/specs/dpll.yaml new file +31
-0+ type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + multi-attr: true + nested-attributes: pin + value: 12 + - + name: pin-idx + type: u32 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32Documentation/netlink/specs/dpll.yaml line 250
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32These 2 attrs somehow overlap with pin-frequency-supported, which is a bit confusing, I think that pin-frequency-supported should carry all supported frequencies. How about to have something like:
name: pin-frequency-supported
type: nest
multi-attr: true
nested-attributes: pin-frequency-rangeand then:
name: pin-frequency-range subset-of: dpll attributes: - name: pin-frequency-min type: u32 - name: pin-frequency-max type: u32 doc: should be put only to specify range when value differs from pin-frequency-min
Quoted 3 lines
That could carry list of frequencies and ranges, in this case multiple ones if possibly needed.
Sure
Quoted 16 lines
Quoted 5 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ - + name: pin-prio + type: u32Documentation/netlink/specs/dpll.yaml line 263
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23
Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because of cli.py parser issue, maybe Kuba knows a better way to prevent the issue?
Basically, without those values, cli.py brakes on parsing responses, after every "jump" to nested attribute list it is assigning first attribute there with value=0, thus there is a need to assign a proper value, same as it is on 'main' attribute list.
Quoted 57 lines
Quoted 46 lines
Documentation/netlink/specs/dpll.yaml new file +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64Documentation/netlink/specs/dpll.yaml line 318
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pin
Quoted 2 lines
This does not belong here.
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.
This is required by parser to work.
Quoted 14 lines
Documentation/netlink/specs/dpll.yaml line 330
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Quoted 52 lines
Quoted 41 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true
Quoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-get --json '{"id": 0, "pin-idx":13}' {'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},
{'bus-name': 'pci',
'dev-name': '0000:21:00.0_1',
'id': 1}],
'pin-description': '0000:21:00.0',
'pin-direction': {'doc': 'pin used as a source of a signal',
'name': 'source'},
'pin-idx': 13,
'pin-parent': [{'pin-parent-idx': 2,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}},
{'pin-parent-idx': 3,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}}],
'pin-rclk-device': '0000:21:00.0',
'pin-type': {'doc': "ethernet port PHY's recovered clock",
'name': 'synce-eth-port'}}]}Quoted 11 lines
Documentation/netlink/specs/dpll.yaml line 388
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32
Quoted 2 lines
Missing "enum: "
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Quoted 18 lines
Quoted 7 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-stateDocumentation/netlink/specs/dpll.yaml line 404
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: string
Quoted 3 lines
Yeah, as I wrote in the other email, this really smells to have like a simple string like this. What is it supposed to be?
Yes, let's discuss there.
Quoted 14 lines
Documentation/netlink/specs/dpll.yaml
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ + +operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dplldevice
Quoted 4 lines
Quoted 1 line
+ attribute-set: dpll
Shouldn't this be "device"?
It would brake the parser, again I hope Jakub Kicinski could take a look on this.
Quoted 20 lines
Quoted 20 lines
Documentation/netlink/specs/dpll.yaml new file +19
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump: + pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes:
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 442
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll"device" here as well?
Same as above.
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - mode
Quoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.
source-pin-index is read only, returns active source.
Quoted 7 lines
Documentation/netlink/specs/dpll.yaml
Quoted 7 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ + - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pins
Quoted 9 lines
in the system
Quoted 1 line
+ - dump request with target dpll - list all the pins registered
with a given dpll device
Quoted 1 line
+ - do request with target dpll and target pin - single pin
attributes
Quoted 1 line
+ attribute-set: dpll
"pin"?
Same case as with dpll/device above.
Quoted 26 lines
Quoted 26 lines
Documentation/netlink/specs/dpll.yaml new file +25
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + reply: + attributes: + - pin + + dump: + pre: dpll-pin-pre-dumpit + post: dpll-pin-post-dumpit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes:
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 493
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - pin + + - + name: pin-set + doc: Set attributes of a target pin + attribute-set: dpll"pin"?
Same case as with dpll/device above.
Quoted 50 lines
Quoted 50 lines
Documentation/netlink/specs/dpll.yaml new file +21
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + - pin-frequency + - pin-direction + - pin-prio + - pin-parent-idx + - pin-state + +mcast-groups: + list: + - + name: monitordrivers/dpll/dpll_nl.c new file +22
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel source */ + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include "dpll_nl.h" + +#include <linux/dpll.h> + +/* DPLL_CMD_DEVICE_GET - do */ +static const struct nla_policy dpll_device_get_nl_policy[DPLL_A_BUS_NAME + 1] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_DEV_NAME ] = { .type =NLA_NUL_STRING , }, +}; + +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1 ]
Quoted 9 lines
drivers/dpll/dpll_nl.c line 25
Quoted 5 lines
= {
drivers/dpll/dpll_nl.c new file +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Not really, it probably needs a fix for this.
Quoted 22 lines
Quoted 22 lines
drivers/dpll/dpll_nl.c new file +4
-0+}; + +/* DPLL_CMD_PIN_GET - do */ +static const struct nla_policy dpll_pin_get_do_nl_policy[DPLL_A_PIN_IDX +1] = {
drivers/dpll/dpll_nl.c new file +8
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_PIN_IDX] = { .type = NLA_U32, }, +}; + +/* DPLL_CMD_PIN_GET - dump */ +static const struct nla_policydpll_pin_get_dump_nl_policy[DPLL_A_BUS_NAME + 1] = {
drivers/dpll/dpll_nl.c new file +7
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, +}; + +/* DPLL_CMD_PIN_SET - do */ +static const struct nla_policy
Quoted 9 lines
drivers/dpll/dpll_nl.c line 49
Quoted 6 lines
dpll_pin_set_nl_policy[DPLL_A_PIN_PARENT_IDX + 1] = {
drivers/dpll/dpll_nl.c new file +5
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_PIN_IDX] = { .type = NLA_U32, }, + [DPLL_A_PIN_FREQUENCY] = { .type = NLA_U32, },4.3GHz would be the limit, isn't it future proof to make this rather u64?
Sure, fixed.
Quoted 9 lines
drivers/dpll/dpll_nl.c line 52
Quoted 4 lines
drivers/dpll/dpll_nl.c new file +3
-0+ [DPLL_A_PIN_DIRECTION] = NLA_POLICY_MAX(NLA_U8, 2), + [DPLL_A_PIN_PRIO] = { .type = NLA_U32, }, + [DPLL_A_PIN_PARENT_IDX] = { .type = NLA_U32, },This is a bit odd. The size is
DPLL_A_PIN_PARENT_IDX+ 1, yetPIN_STATEis last. I found that the order is not according to the enum in the yaml operation definition. Perhaps the generator can sort this?
Fixed. This related to the order on list of attributes expected on ops definition.
Quoted 138 lines
Quoted 87 lines
drivers/dpll/dpll_nl.c new file +74
-0+ [DPLL_A_PIN_STATE] = NLA_POLICY_MAX(NLA_U8, 2), +}; + +/* Ops table for dpll */ +static const struct genl_split_ops dpll_nl_ops[6 ] = { + { + .cmd =DPLL_CMD_DEVICE_GET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_get_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_get_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_DEVICE_GET , + .start = dpll_pre_dumpit, + .dumpit = dpll_nl_device_get_dumpit, + .done = dpll_post_dumpit, + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_DEVICE_SET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_set_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_set_nl_policy, + .maxattr =DPLL_A_MODE , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_get_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_get_do_nl_policy, + .maxattr =DPLL_A_PIN_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .start = dpll_pin_pre_dumpit, + .dumpit = dpll_nl_pin_get_dumpit, + .done = dpll_pin_post_dumpit, + .policy = dpll_pin_get_dump_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_PIN_SET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_set_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_set_nl_policy, + .maxattr =DPLL_A_PIN_PARENT_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, +}; + +static const struct genl_multicast_group dpll_nl_mcgrps[] = { + [DPLL_NLGRP_MONITOR ] = {"monitor" , }, +}; + +struct genl_family dpll_nl_family__ro_after_init = { + .name =DPLL_FAMILY_NAME , + .version =DPLL_FAMILY_VERSION , + .netnsok = true, + .parallel_ops = true, + .module =THIS_MODULE , + .split_ops = dpll_nl_ops, + .n_split_ops =ARRAY_SIZE (dpll_nl_ops), + .mcgrps = dpll_nl_mcgrps, + .n_mcgrps =ARRAY_SIZE (dpll_nl_mcgrps), +};drivers/dpll/dpll_nl.h new file +6
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_DPLL_GEN_Hdrivers/dpll/dpll_nl.h line 16
Quoted 10 lines
drivers/dpll/dpll_nl.h new file +10
-0+#define _LINUX_DPLL_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/dpll.h> + +int dpll_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff*skb,
Quoted 4 lines
drivers/dpll/dpll_nl.h new file +4
-0+ struct genl_info *info); +void +dpll_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info);drivers/dpll/dpll_nl.h
Quoted 10 lines
drivers/dpll/dpll_nl.h new file +10
-0+void +dpll_pin_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pre_dumpit (struct netlink_callback *cb); +int dpll_pin_pre_dumpit (struct netlink_callback *cb); +int dpll_post_dumpit (struct netlink_callback *cb); +int dpll_pin_post_dumpit (struct netlink_callback *cb); + +int dpll_nl_device_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_device_get_dumpit(struct sk_buff *skb, struct
netlink_callback*cb);drivers/dpll/dpll_nl.h
Quoted 3 lines
drivers/dpll/dpll_nl.h new file +3
-0+int dpll_nl_device_set_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback*cb);
Quoted 21 lines
drivers/dpll/dpll_nl.h new file +9
-0+int dpll_nl_pin_set_doit (struct sk_buff *skb,struct genl_info *info); + +enum { +DPLL_NLGRP_MONITOR , +}; + +extern struct genl_family dpll_nl_family; + +#endif /* _LINUX_DPLL_GEN_H */ include/uapi/linux/dpll.h new file +6
-0@@ -0,0 +1,196 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_DPLL_H
Quoted 9 lines
include/uapi/linux/dpll.h line 12
Quoted 6 lines
include/uapi/linux/dpll.h new file +6
-0+#define _UAPI_LINUX_DPLL_H + +#define DPLL_FAMILY_NAME "dpll" +#define DPLL_FAMILY_VERSION 1 + +#define DPLL_TEMP_DIVIDER 10Some comment to this define would be nice.
I added to the spec, but it is not generated by the regen script.
Quoted 7 lines
include/uapi/linux/dpll.h line 14
Quoted 3 lines
include/uapi/linux/dpll.h new file +2
-0+#define DPLL_PIN_FREQ_1_HZ 1 +#define DPLL_PIN_FREQ_10_MHZ 10000000Have this as enum. Spell out "frequency" to be consistent with the related attribute name.
Sure, fixed.
Quoted 10 lines
Quoted 8 lines
include/uapi/linux/dpll.h new file +3
-0+ +/** +* enum dpll_lock_status - Provides information of dpll device lock status,
+ * valid values forDPLL_A_LOCK_STATUSattribute
+ * @DPLL_LOCK_STATUS_UNSPEC: unspecified value
+ * @DPLL_LOCK_STATUS_UNLOCKED: dpll was not yet locked to any valid (oris in
Quoted 2 lines
"any valid source" perhaps?
Yes, fixed.
Quoted 40 lines
Quoted 40 lines
+ * one of modes:
DPLL_MODE_FREERUN,DPLL_MODE_NCO)
+ * @DPLL_LOCK_STATUS_CALIBRATING: dpll is trying to lock to a valid signal
+ * @DPLL_LOCK_STATUS_LOCKED: dpll is locked
+ * @DPLL_LOCK_STATUS_HOLDOVER: dpll is in holdover state - lost a valid lock or
+ * was forced by selectingDPLL_MODE_HOLDOVERmode
+ */include/uapi/linux/dpll.h new file +31
-0+enum dpll_lock_status { +DPLL_LOCK_STATUS_UNSPEC , +DPLL_LOCK_STATUS_UNLOCKED , +DPLL_LOCK_STATUS_CALIBRATING , +DPLL_LOCK_STATUS_LOCKED , +DPLL_LOCK_STATUS_HOLDOVER , + + __DPLL_LOCK_STATUS_MAX, +DPLL_LOCK_STATUS_MAX = (__DPLL_LOCK_STATUS_MAX -1 ) +}; + +/** +* enum dpll_pin_type - Enumerates types of a pin, valid values for +* DPLL_A_PIN_TYPE attribute +* @DPLL_PIN_TYPE_UNSPEC: unspecified value +* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins +* @DPLL_PIN_TYPE_EXT: external source +* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock +* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator +* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock +*/ +enum dpll_pin_type { +DPLL_PIN_TYPE_UNSPEC , +DPLL_PIN_TYPE_MUX , +DPLL_PIN_TYPE_EXT , +DPLL_PIN_TYPE_SYNCE_ETH_PORT , +DPLL_PIN_TYPE_INT_OSCILLATOR , +DPLL_PIN_TYPE_GNSS , + + __DPLL_PIN_TYPE_MAX, +DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX -1 )
Quoted 9 lines
include/uapi/linux/dpll.h line 61
Quoted 4 lines
include/uapi/linux/dpll.h new file +4
-0+}; + +/** +* enum dpll_pin_state - available pin modes For some of the enums, you say for what attribute it serves as a value set, for some you don't. Please unify the approach. I think it is valuable to say that for every enum.
Sure, fixed.
Quoted 106 lines
Quoted 106 lines
+ * @DPLL_PIN_STATE_UNSPEC: unspecified value
+ * @DPLL_PIN_STATE_CONNECTED: pin connected
+ * @DPLL_PIN_STATE_DISCONNECTED: pin disconnected
+ */include/uapi/linux/dpll.h new file +26
-0+enum dpll_pin_state { +DPLL_PIN_STATE_UNSPEC , +DPLL_PIN_STATE_CONNECTED , +DPLL_PIN_STATE_DISCONNECTED , + + __DPLL_PIN_STATE_MAX, +DPLL_PIN_STATE_MAX = (__DPLL_PIN_STATE_MAX -1 ) +}; + +/** +* enum dpll_pin_direction - available pin direction +* @DPLL_PIN_DIRECTION_UNSPEC: unspecified value +* @DPLL_PIN_DIRECTION_SOURCE: pin used as a source of a signal +* @DPLL_PIN_DIRECTION_OUTPUT: pin used to output the signal +*/ +enum dpll_pin_direction { +DPLL_PIN_DIRECTION_UNSPEC , +DPLL_PIN_DIRECTION_SOURCE , +DPLL_PIN_DIRECTION_OUTPUT , + + __DPLL_PIN_DIRECTION_MAX, +DPLL_PIN_DIRECTION_MAX = (__DPLL_PIN_DIRECTION_MAX -1 ) +}; + +/** +* enum dpll_mode - working-modes a dpll can support, differentiate if and how
+ * dpll selects one of its sources to syntonize with it
+ * @DPLL_MODE_UNSPEC: unspecified value
+ * @DPLL_MODE_MANUAL: source can be only selected by sending a request to dpll
+ * @DPLL_MODE_AUTOMATIC: highest prio, valid source, auto selected by dpll
+ * @DPLL_MODE_HOLDOVER: dpll forced into holdover mode
+ * @DPLL_MODE_FREERUN: dpll driven on system clk, no holdover available
+ * @DPLL_MODE_NCO: dpll driven by Numerically Controlled Oscillator
+ */include/uapi/linux/dpll.h new file +33
-0+enum dpll_mode { +DPLL_MODE_UNSPEC , +DPLL_MODE_MANUAL , +DPLL_MODE_AUTOMATIC , +DPLL_MODE_HOLDOVER , +DPLL_MODE_FREERUN , +DPLL_MODE_NCO , + + __DPLL_MODE_MAX, +DPLL_MODE_MAX = (__DPLL_MODE_MAX -1 ) +}; + +/** +* enum dpll_type - type of dpll, valid values for DPLL_A_TYPE attribute +* @DPLL_TYPE_UNSPEC: unspecified value +* @DPLL_TYPE_PPS: dpll produces Pulse-Per-Second signal +* @DPLL_TYPE_EEC: dpll drives the Ethernet Equipment Clock +*/ +enum dpll_type { +DPLL_TYPE_UNSPEC , +DPLL_TYPE_PPS , +DPLL_TYPE_EEC , + + __DPLL_TYPE_MAX, +DPLL_TYPE_MAX = (__DPLL_TYPE_MAX -1 ) +}; + +/** +* enum dpll_event - events of dpll generic netlink family +* @DPLL_EVENT_UNSPEC: invalid event type +* @DPLL_EVENT_DEVICE_CREATE: dpll device created +* @DPLL_EVENT_DEVICE_DELETE: dpll device deleted +* @DPLL_EVENT_DEVICE_CHANGE: attribute of dpll device or pin changed, reason
+ * is to be found with an attribute type (DPLL_A_*) received with the
event
+ */include/uapi/linux/dpll.h new file +27
-0+enum dpll_event { +DPLL_EVENT_UNSPEC , +DPLL_EVENT_DEVICE_CREATE , +DPLL_EVENT_DEVICE_DELETE , +DPLL_EVENT_DEVICE_CHANGE , +}; + +/** +* enum dpll_pin_caps - define capabilities of a pin +*/ +enum dpll_pin_caps { +DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE =1 , +DPLL_PIN_CAPS_PRIORITY_CAN_CHANGE =2 , +DPLL_PIN_CAPS_STATE_CAN_CHANGE =4 , +}; + +enum dplla { +DPLL_A_DEVICE =1 , +DPLL_A_ID , +DPLL_A_DEV_NAME , +DPLL_A_BUS_NAME , +DPLL_A_MODE , +DPLL_A_MODE_SUPPORTED , +DPLL_A_SOURCE_PIN_IDX , +DPLL_A_LOCK_STATUS , +DPLL_A_TEMP , +DPLL_A_CLOCK_ID ,
Quoted 9 lines
include/uapi/linux/dpll.h line 165
Quoted 4 lines
include/uapi/linux/dpll.h new file +4
-0+DPLL_A_TYPE , +DPLL_A_PIN , +DPLL_A_PIN_IDX , + DPLL_A_PIN_DESCRIPTION,I commented this name in the other email. This does not describe anything. It is a label on a connector, isn't it? Why don't to call it "label"?
Sure, fixed.
Quoted 10 lines
include/uapi/linux/dpll.h line 171
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_TYPE , +DPLL_A_PIN_DIRECTION , +DPLL_A_PIN_FREQUENCY , +DPLL_A_PIN_FREQUENCY_SUPPORTED , +DPLL_A_PIN_ANY_FREQUENCY_MIN , + DPLL_A_PIN_ANY_FREQUENCY_MAX,Drop "any". Not good for anything.
Sure, fixed.
Quoted 10 lines
include/uapi/linux/dpll.h line 177
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.
Sure, fixed.
Quoted 23 lines
Quoted 23 lines
include/uapi/linux/dpll.h new file +19
-1+ + __DPLL_A_MAX, +DPLL_A_MAX = (__DPLL_A_MAX -1 ) +}; + +enum { +DPLL_CMD_UNSPEC , +DPLL_CMD_DEVICE_GET , +DPLL_CMD_DEVICE_SET , +DPLL_CMD_PIN_GET , +DPLL_CMD_PIN_SET , + + __DPLL_CMD_MAX, +DPLL_CMD_MAX = (__DPLL_CMD_MAX -1 ) +}; + +#define DPLL_MCGRP_MONITOR "monitor" + +#endif /* _UAPI_LINUX_DPLL_H */ --2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 230 lines · Thu, Mar 16, 2023 at 02:15:59PM CET, [email protected] wrote:
Quoted 129 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 3:44 PMQuoted 125 lines · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
Add a protocol spec for DPLL.
Add code generated from the spec.Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Michal Michalik <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Vadim Fedorenko <[email protected]>---
Documentation/netlink/specs/dpll.yaml | 514 ++++++++++++++++++++++++++ drivers/dpll/dpll_nl.c | 126 +++++++ drivers/dpll/dpll_nl.h | 42 +++ include/uapi/linux/dpll.h | 196 ++++++++++ 4 files changed, 878 insertions(+)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644drivers/dpll/dpll_nl.ccreate mode 100644drivers/dpll/dpll_nl.hcreate mode 100644include/uapi/linux/dpll.hDocumentation/netlink/specs/dpll.yaml new file +48
-0@@ -0,0 +1,514 @@ +name: dpll + +doc: DPLL subsystem. + +definitions: + - + type: const + name: temp-divider + value: 10 + - + type: const + name: pin-freq-1-hz + value: 1 + - + type: const + name: pin-freq-10-mhz + value: 10000000 + - + type: enum + name: lock-status + doc: | + Provides information of dpll device lock status, valid values for + DPLL_A_LOCK_STATUS attribute + entries: + - + name: unspec + doc: unspecified value + - + name: unlocked + doc: | + dpll was not yet locked to any valid (or is in one of modes: + DPLL_MODE_FREERUN, DPLL_MODE_NCO) + - + name: calibrating + doc: dpll is trying to lock to a valid signal + - + name: locked + doc: dpll is locked + - + name: holdover + doc: | + dpll is in holdover state - lost a valid lock or was forced by + selecting DPLL_MODE_HOLDOVER mode + render-max: true + - + type: enum + name: pin-type + doc: Enumerates types of a pin, valid values for DPLL_A_PIN_TYPEattribute
Documentation/netlink/specs/dpll.yaml new file +49
-0+ entries: + - + name: unspec + doc: unspecified value + - + name: mux + doc: aggregates another layer of selectable pins + - + name: ext + doc: external source + - + name: synce-eth-port + doc: ethernet port PHY's recovered clock + - + name: int-oscillator + doc: device internal oscillator + - + name: gnss + doc: GNSS recovered clock + render-max: true + - + type: enum + name: pin-state + doc: available pin modes + entries: + - + name: unspec + doc: unspecified value + - + name: connected + doc: pin connected + - + name: disconnected + doc: pin disconnected + render-max: true + - + type: enum + name: pin-direction + doc: available pin direction + entries: + - + name: unspec + doc: unspecified value + - + name: source + doc: pin used as a source of a signal + - + name: output + doc: pin used to output the signalQuoted 9 lines
Documentation/netlink/specs/dpll.yaml line 101
Quoted 4 lines
Documentation/netlink/specs/dpll.yaml new file +4
-0+ render-max: true + - + type: enum + name: modeCould you please sort the enums so they are in the same order as the attribute which carries them? That would also put the device and pin enums together.
Fixed.
Quoted 79 lines
Quoted 79 lines
Documentation/netlink/specs/dpll.yaml new file +2
-0+ doc: | + working-modes a dpll can support, differentiate if and how dpllselects
Documentation/netlink/specs/dpll.yaml new file +54
-0+ one of its sources to syntonize with it + entries: + - + name: unspec + doc: unspecified value + - + name: manual + doc: source can be only selected by sending a request to dpll + - + name: automatic + doc: highest prio, valid source, auto selected by dpll + - + name: holdover + doc: dpll forced into holdover mode + - + name: freerun + doc: dpll driven on system clk, no holdover available + - + name: nco + doc: dpll driven by Numerically Controlled Oscillator + render-max: true + - + type: enum + name: type + doc: type of dpll, valid values for DPLL_A_TYPE attribute + entries: + - + name: unspec + doc: unspecified value + - + name: pps + doc: dpll produces Pulse-Per-Second signal + - + name: eec + doc: dpll drives the Ethernet Equipment Clock + render-max: true + - + type: enum + name: event + doc: events of dpll generic netlink family + entries: + - + name: unspec + doc: invalid event type + - + name: device-create + doc: dpll device created + - + name: device-delete + doc: dpll device deleted + - + name: device-change + doc: | + attribute of dpll device or pin changed, reason is to be foundwith
Documentation/netlink/specs/dpll.yaml new file +20
-0+ an attribute type (DPLL_A_*) received with the event + - + type: flags + name: pin-caps + doc: define capabilities of a pin + entries: + - + name: direction-can-change + - + name: priority-can-change + - + name: state-can-change + + +attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + -Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 5 lines
Documentation/netlink/specs/dpll.yaml new file +5
-0+ name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceWhat is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
Quoted 7 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}]}]
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Device nest should not be there for DEVICE_GET, does not make sense.
Quoted 4 lines
- do/dump of pin-get, in case of shared pins, each pin contains number of dpll handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci',
Quoted 11 lines
'dev-name': '0000:21:00.0_0',
'id': 0,
'pin-prio': 6,
'pin-state': {'doc': 'pin connected',
'name': 'connected'}},
{'bus-name': 'pci',
'dev-name': '0000:21:00.0_1',
'id': 1,
'pin-prio': 8,
'pin-state': {'doc': 'pin connected',
'name': 'connected'}}],Okay, here I understand it contains device specific pin items. Makes sense!
Quoted 133 lines
'pin-direction': {'doc': 'pin used as a source of a signal', 'name': 'source'}, 'pin-frequency': 1, 'pin-frequency-supported': [1, 10000000], 'pin-idx': 0, ...Quoted 29 lines
Quoted 18 lines
Documentation/netlink/specs/dpll.yaml new file +17
-0+ - + name: id + type: u32 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: modeDocumentation/netlink/specs/dpll.yaml line 209
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: tempQuoted 2 lines
Could you put some comment regarding the divider here?
Sure, fixed.
Quoted 65 lines
Quoted 32 lines
Documentation/netlink/specs/dpll.yaml new file +31
-0+ type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + multi-attr: true + nested-attributes: pin + value: 12 + - + name: pin-idx + type: u32 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32Documentation/netlink/specs/dpll.yaml line 250
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32These 2 attrs somehow overlap with pin-frequency-supported, which is a bit confusing, I think that pin-frequency-supported should carry all supported frequencies. How about to have something like:
name: pin-frequency-supported
type: nest
multi-attr: true
nested-attributes: pin-frequency-rangeand then:
name: pin-frequency-range subset-of: dpll attributes: - name: pin-frequency-min type: u32 - name: pin-frequency-max type: u32 doc: should be put only to specify range when value differs from pin-frequency-minQuoted 3 lines
That could carry list of frequencies and ranges, in this case multiple ones if possibly needed.
Sure
Quoted 16 lines
Quoted 5 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ - + name: pin-prio + type: u32Documentation/netlink/specs/dpll.yaml line 263
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?
Quoted 9 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better way to prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attribute there with value=0, thus there is a need to assign a proper value, same as it is on 'main' attribute list.
That's weird. Looks like a bug then?
Quoted 58 lines
Quoted 58 lines
Quoted 57 lines
Documentation/netlink/specs/dpll.yaml new file +55
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64 + - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pin
Quoted 6 lines
Quoted 2 lines
This does not belong here.
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.
No, wait a sec. You have 2 object types: device and pin. Each have separate netlink CMDs to get and dump individual objects. Don't mix those together like this. I thought it became clear in the past. :/
Quoted 16 lines
This is required by parser to work.
Quoted 14 lines
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26
Quoted 4 lines
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Same as above reply.
Quoted 60 lines
Quoted 53 lines
Quoted 42 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: trueQuoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":13}' {'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},
Quoted 16 lines
{'bus-name': 'pci',
'dev-name': '0000:21:00.0_1',
'id': 1}],
'pin-description': '0000:21:00.0',
'pin-direction': {'doc': 'pin used as a source of a signal',
'name': 'source'},
'pin-idx': 13,
'pin-parent': [{'pin-parent-idx': 2,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}},
{'pin-parent-idx': 3,
'pin-state': {'doc': 'pin disconnected',
'name': 'disconnected'}}],
'pin-rclk-device': '0000:21:00.0',
'pin-type': {'doc': "ethernet port PHY's recovered clock",
'name': 'synce-eth-port'}}]}Got it, it is still a bit hard to me to follow this. Could you perhaps extend the Documentation to describe in more details with examples? Would help a lot for slower people like me to understand what's what.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32
Quoted 5 lines
Quoted 2 lines
Missing "enum: "
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Ah! Got it. Perhaps a docs note with the enum pointer then?
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Documentation/netlink/specs/dpll.yaml new file +16
-0+ - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-state + type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: string
Quoted 5 lines
Quoted 3 lines
Yeah, as I wrote in the other email, this really smells to have like a simple string like this. What is it supposed to be?
Yes, let's discuss there.
Yep.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Documentation/netlink/specs/dpll.yaml new file +2
-0+ +Documentation/netlink/specs/dpll.yaml
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dplldevice
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ attribute-set: dpll
Shouldn't this be "device"?
It would brake the parser, again I hope Jakub Kicinski could take a look on this.
Odd.
Quoted 46 lines
Quoted 21 lines
Quoted 21 lines
Documentation/netlink/specs/dpll.yaml new file +19
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump: + pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes:Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 442
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll"device" here as well?
Same as above.
Quoted 13 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - mode
Quoted 7 lines
Quoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 118 lines
Quoted 8 lines
Documentation/netlink/specs/dpll.yaml
Quoted 8 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ + - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pinsQuoted 9 lines
in the system
Quoted 1 line
+ - dump request with target dpll - list all the pins registered
with a given dpll device
Quoted 1 line
+ - do request with target dpll and target pin - single pin
attributes
Quoted 1 line
+ attribute-set: dpll
"pin"?
Same case as with dpll/device above.
Quoted 26 lines
Quoted 26 lines
Documentation/netlink/specs/dpll.yaml new file +25
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + reply: + attributes: + - pin + + dump: + pre: dpll-pin-pre-dumpit + post: dpll-pin-post-dumpit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes:Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 493
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - pin + + - + name: pin-set + doc: Set attributes of a target pin + attribute-set: dpll"pin"?
Same case as with dpll/device above.
Quoted 50 lines
Quoted 50 lines
Documentation/netlink/specs/dpll.yaml new file +21
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pin-pre-doit + post: dpll-pin-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - pin-idx + - pin-frequency + - pin-direction + - pin-prio + - pin-parent-idx + - pin-state + +mcast-groups: + list: + - + name: monitordrivers/dpll/dpll_nl.c new file +22
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel source */ + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include "dpll_nl.h" + +#include <linux/dpll.h> + +/* DPLL_CMD_DEVICE_GET - do */ +static const struct nla_policy dpll_device_get_nl_policy[DPLL_A_BUS_NAME + 1] = { + [DPLL_A_ID ] = { .type =NLA_U32 , }, + [DPLL_A_BUS_NAME ] = { .type =NLA_NUL_STRING , }, + [DPLL_A_DEV_NAME ] = { .type =NLA_NUL_STRING , }, +}; + +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1 ]Quoted 9 lines
drivers/dpll/dpll_nl.c line 25
Quoted 5 lines
= {
drivers/dpll/dpll_nl.c new file +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Quoted 45 lines
Quoted 23 lines
Quoted 23 lines
drivers/dpll/dpll_nl.c new file +4
-0+}; + +/* DPLL_CMD_PIN_GET - do */ +static const struct nla_policy dpll_pin_get_do_nl_policy[DPLL_A_PIN_IDX +1] = {
drivers/dpll/dpll_nl.c new file +8
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_PIN_IDX] = { .type = NLA_U32, }, +}; + +/* DPLL_CMD_PIN_GET - dump */ +static const struct nla_policydpll_pin_get_dump_nl_policy[DPLL_A_BUS_NAME + 1] = {
drivers/dpll/dpll_nl.c new file +7
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, +}; + +/* DPLL_CMD_PIN_SET - do */ +static const struct nla_policyQuoted 9 lines
drivers/dpll/dpll_nl.c line 49
Quoted 6 lines
dpll_pin_set_nl_policy[DPLL_A_PIN_PARENT_IDX + 1] = {
drivers/dpll/dpll_nl.c new file +5
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_PIN_IDX] = { .type = NLA_U32, }, + [DPLL_A_PIN_FREQUENCY] = { .type = NLA_U32, },4.3GHz would be the limit, isn't it future proof to make this rather u64?
Sure, fixed.
Quoted 9 lines
drivers/dpll/dpll_nl.c line 52
Quoted 4 lines
drivers/dpll/dpll_nl.c new file +3
-0+ [DPLL_A_PIN_DIRECTION] = NLA_POLICY_MAX(NLA_U8, 2), + [DPLL_A_PIN_PRIO] = { .type = NLA_U32, }, + [DPLL_A_PIN_PARENT_IDX] = { .type = NLA_U32, },This is a bit odd. The size is
DPLL_A_PIN_PARENT_IDX+ 1, yetPIN_STATEis last. I found that the order is not according to the enum in the yaml operation definition. Perhaps the generator can sort this?
Quoted 2 lines
Fixed. This related to the order on list of attributes expected on ops definition.
Yep.
Quoted 370 lines
Quoted 139 lines
Quoted 88 lines
drivers/dpll/dpll_nl.c new file +74
-0+ [DPLL_A_PIN_STATE] = NLA_POLICY_MAX(NLA_U8, 2), +}; + +/* Ops table for dpll */ +static const struct genl_split_ops dpll_nl_ops[6 ] = { + { + .cmd =DPLL_CMD_DEVICE_GET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_get_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_get_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_DEVICE_GET , + .start = dpll_pre_dumpit, + .dumpit = dpll_nl_device_get_dumpit, + .done = dpll_post_dumpit, + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_DEVICE_SET , + .pre_doit = dpll_pre_doit, + .doit = dpll_nl_device_set_doit, + .post_doit = dpll_post_doit, + .policy = dpll_device_set_nl_policy, + .maxattr =DPLL_A_MODE , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_get_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_get_do_nl_policy, + .maxattr =DPLL_A_PIN_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, + { + .cmd =DPLL_CMD_PIN_GET , + .start = dpll_pin_pre_dumpit, + .dumpit = dpll_nl_pin_get_dumpit, + .done = dpll_pin_post_dumpit, + .policy = dpll_pin_get_dump_nl_policy, + .maxattr =DPLL_A_BUS_NAME , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =DPLL_CMD_PIN_SET , + .pre_doit = dpll_pin_pre_doit, + .doit = dpll_nl_pin_set_doit, + .post_doit = dpll_pin_post_doit, + .policy = dpll_pin_set_nl_policy, + .maxattr =DPLL_A_PIN_PARENT_IDX , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, +}; + +static const struct genl_multicast_group dpll_nl_mcgrps[] = { + [DPLL_NLGRP_MONITOR ] = {"monitor" , }, +}; + +struct genl_family dpll_nl_family__ro_after_init = { + .name =DPLL_FAMILY_NAME , + .version =DPLL_FAMILY_VERSION , + .netnsok = true, + .parallel_ops = true, + .module =THIS_MODULE , + .split_ops = dpll_nl_ops, + .n_split_ops =ARRAY_SIZE (dpll_nl_ops), + .mcgrps = dpll_nl_mcgrps, + .n_mcgrps =ARRAY_SIZE (dpll_nl_mcgrps), +};drivers/dpll/dpll_nl.h new file +6
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_DPLL_GEN_Hdrivers/dpll/dpll_nl.h line 16
Quoted 10 lines
drivers/dpll/dpll_nl.h new file +10
-0+#define _LINUX_DPLL_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/dpll.h> + +int dpll_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff*skb,
Quoted 4 lines
drivers/dpll/dpll_nl.h new file +4
-0+ struct genl_info *info); +void +dpll_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info);drivers/dpll/dpll_nl.h
Quoted 10 lines
drivers/dpll/dpll_nl.h new file +10
-0+void +dpll_pin_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +int dpll_pre_dumpit (struct netlink_callback *cb); +int dpll_pin_pre_dumpit (struct netlink_callback *cb); +int dpll_post_dumpit (struct netlink_callback *cb); +int dpll_pin_post_dumpit (struct netlink_callback *cb); + +int dpll_nl_device_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_device_get_dumpit(struct sk_buff *skb, struct
netlink_callback*cb);drivers/dpll/dpll_nl.h
Quoted 3 lines
drivers/dpll/dpll_nl.h new file +3
-0+int dpll_nl_device_set_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_doit (struct sk_buff *skb,struct genl_info *info); +int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback*cb);
Quoted 21 lines
drivers/dpll/dpll_nl.h new file +9
-0+int dpll_nl_pin_set_doit (struct sk_buff *skb,struct genl_info *info); + +enum { +DPLL_NLGRP_MONITOR , +}; + +extern struct genl_family dpll_nl_family; + +#endif /* _LINUX_DPLL_GEN_H */ include/uapi/linux/dpll.h new file +6
-0@@ -0,0 +1,196 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/dpll.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_DPLL_HQuoted 9 lines
include/uapi/linux/dpll.h line 12
Quoted 6 lines
include/uapi/linux/dpll.h new file +6
-0+#define _UAPI_LINUX_DPLL_H + +#define DPLL_FAMILY_NAME "dpll" +#define DPLL_FAMILY_VERSION 1 + +#define DPLL_TEMP_DIVIDER 10Some comment to this define would be nice.
I added to the spec, but it is not generated by the regen script.
Quoted 7 lines
include/uapi/linux/dpll.h line 14
Quoted 3 lines
include/uapi/linux/dpll.h new file +2
-0+#define DPLL_PIN_FREQ_1_HZ 1 +#define DPLL_PIN_FREQ_10_MHZ 10000000Have this as enum. Spell out "frequency" to be consistent with the related attribute name.
Sure, fixed.
Quoted 10 lines
Quoted 8 lines
include/uapi/linux/dpll.h new file +3
-0+ +/** +* enum dpll_lock_status - Provides information of dpll device lock status,
+ * valid values forDPLL_A_LOCK_STATUSattribute
+ * @DPLL_LOCK_STATUS_UNSPEC: unspecified value
+ * @DPLL_LOCK_STATUS_UNLOCKED: dpll was not yet locked to any valid (oris in
Quoted 2 lines
"any valid source" perhaps?
Yes, fixed.
Quoted 40 lines
Quoted 40 lines
+ * one of modes:
DPLL_MODE_FREERUN,DPLL_MODE_NCO)
+ * @DPLL_LOCK_STATUS_CALIBRATING: dpll is trying to lock to a valid signal
+ * @DPLL_LOCK_STATUS_LOCKED: dpll is locked
+ * @DPLL_LOCK_STATUS_HOLDOVER: dpll is in holdover state - lost a valid lock or
+ * was forced by selectingDPLL_MODE_HOLDOVERmode
+ */include/uapi/linux/dpll.h new file +31
-0+enum dpll_lock_status { +DPLL_LOCK_STATUS_UNSPEC , +DPLL_LOCK_STATUS_UNLOCKED , +DPLL_LOCK_STATUS_CALIBRATING , +DPLL_LOCK_STATUS_LOCKED , +DPLL_LOCK_STATUS_HOLDOVER , + + __DPLL_LOCK_STATUS_MAX, +DPLL_LOCK_STATUS_MAX = (__DPLL_LOCK_STATUS_MAX -1 ) +}; + +/** +* enum dpll_pin_type - Enumerates types of a pin, valid values for +* DPLL_A_PIN_TYPE attribute +* @DPLL_PIN_TYPE_UNSPEC: unspecified value +* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins +* @DPLL_PIN_TYPE_EXT: external source +* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock +* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator +* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock +*/ +enum dpll_pin_type { +DPLL_PIN_TYPE_UNSPEC , +DPLL_PIN_TYPE_MUX , +DPLL_PIN_TYPE_EXT , +DPLL_PIN_TYPE_SYNCE_ETH_PORT , +DPLL_PIN_TYPE_INT_OSCILLATOR , +DPLL_PIN_TYPE_GNSS , + + __DPLL_PIN_TYPE_MAX, +DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX -1 )Quoted 9 lines
include/uapi/linux/dpll.h line 61
Quoted 4 lines
include/uapi/linux/dpll.h new file +4
-0+}; + +/** +* enum dpll_pin_state - available pin modes For some of the enums, you say for what attribute it serves as a value set, for some you don't. Please unify the approach. I think it is valuable to say that for every enum.
Sure, fixed.
Quoted 106 lines
Quoted 106 lines
+ * @DPLL_PIN_STATE_UNSPEC: unspecified value
+ * @DPLL_PIN_STATE_CONNECTED: pin connected
+ * @DPLL_PIN_STATE_DISCONNECTED: pin disconnected
+ */include/uapi/linux/dpll.h new file +26
-0+enum dpll_pin_state { +DPLL_PIN_STATE_UNSPEC , +DPLL_PIN_STATE_CONNECTED , +DPLL_PIN_STATE_DISCONNECTED , + + __DPLL_PIN_STATE_MAX, +DPLL_PIN_STATE_MAX = (__DPLL_PIN_STATE_MAX -1 ) +}; + +/** +* enum dpll_pin_direction - available pin direction +* @DPLL_PIN_DIRECTION_UNSPEC: unspecified value +* @DPLL_PIN_DIRECTION_SOURCE: pin used as a source of a signal +* @DPLL_PIN_DIRECTION_OUTPUT: pin used to output the signal +*/ +enum dpll_pin_direction { +DPLL_PIN_DIRECTION_UNSPEC , +DPLL_PIN_DIRECTION_SOURCE , +DPLL_PIN_DIRECTION_OUTPUT , + + __DPLL_PIN_DIRECTION_MAX, +DPLL_PIN_DIRECTION_MAX = (__DPLL_PIN_DIRECTION_MAX -1 ) +}; + +/** +* enum dpll_mode - working-modes a dpll can support, differentiate if and how
+ * dpll selects one of its sources to syntonize with it
+ * @DPLL_MODE_UNSPEC: unspecified value
+ * @DPLL_MODE_MANUAL: source can be only selected by sending a request to dpll
+ * @DPLL_MODE_AUTOMATIC: highest prio, valid source, auto selected by dpll
+ * @DPLL_MODE_HOLDOVER: dpll forced into holdover mode
+ * @DPLL_MODE_FREERUN: dpll driven on system clk, no holdover available
+ * @DPLL_MODE_NCO: dpll driven by Numerically Controlled Oscillator
+ */include/uapi/linux/dpll.h new file +33
-0+enum dpll_mode { +DPLL_MODE_UNSPEC , +DPLL_MODE_MANUAL , +DPLL_MODE_AUTOMATIC , +DPLL_MODE_HOLDOVER , +DPLL_MODE_FREERUN , +DPLL_MODE_NCO , + + __DPLL_MODE_MAX, +DPLL_MODE_MAX = (__DPLL_MODE_MAX -1 ) +}; + +/** +* enum dpll_type - type of dpll, valid values for DPLL_A_TYPE attribute +* @DPLL_TYPE_UNSPEC: unspecified value +* @DPLL_TYPE_PPS: dpll produces Pulse-Per-Second signal +* @DPLL_TYPE_EEC: dpll drives the Ethernet Equipment Clock +*/ +enum dpll_type { +DPLL_TYPE_UNSPEC , +DPLL_TYPE_PPS , +DPLL_TYPE_EEC , + + __DPLL_TYPE_MAX, +DPLL_TYPE_MAX = (__DPLL_TYPE_MAX -1 ) +}; + +/** +* enum dpll_event - events of dpll generic netlink family +* @DPLL_EVENT_UNSPEC: invalid event type +* @DPLL_EVENT_DEVICE_CREATE: dpll device created +* @DPLL_EVENT_DEVICE_DELETE: dpll device deleted +* @DPLL_EVENT_DEVICE_CHANGE: attribute of dpll device or pin changed, reason
+ * is to be found with an attribute type (DPLL_A_*) received with the
event
+ */include/uapi/linux/dpll.h new file +27
-0+enum dpll_event { +DPLL_EVENT_UNSPEC , +DPLL_EVENT_DEVICE_CREATE , +DPLL_EVENT_DEVICE_DELETE , +DPLL_EVENT_DEVICE_CHANGE , +}; + +/** +* enum dpll_pin_caps - define capabilities of a pin +*/ +enum dpll_pin_caps { +DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE =1 , +DPLL_PIN_CAPS_PRIORITY_CAN_CHANGE =2 , +DPLL_PIN_CAPS_STATE_CAN_CHANGE =4 , +}; + +enum dplla { +DPLL_A_DEVICE =1 , +DPLL_A_ID , +DPLL_A_DEV_NAME , +DPLL_A_BUS_NAME , +DPLL_A_MODE , +DPLL_A_MODE_SUPPORTED , +DPLL_A_SOURCE_PIN_IDX , +DPLL_A_LOCK_STATUS , +DPLL_A_TEMP , +DPLL_A_CLOCK_ID ,Quoted 9 lines
include/uapi/linux/dpll.h line 165
Quoted 4 lines
include/uapi/linux/dpll.h new file +4
-0+DPLL_A_TYPE , +DPLL_A_PIN , +DPLL_A_PIN_IDX , + DPLL_A_PIN_DESCRIPTION,I commented this name in the other email. This does not describe anything. It is a label on a connector, isn't it? Why don't to call it "label"?
Sure, fixed.
Quoted 10 lines
include/uapi/linux/dpll.h line 171
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_TYPE , +DPLL_A_PIN_DIRECTION , +DPLL_A_PIN_FREQUENCY , +DPLL_A_PIN_FREQUENCY_SUPPORTED , +DPLL_A_PIN_ANY_FREQUENCY_MIN , + DPLL_A_PIN_ANY_FREQUENCY_MAX,Drop "any". Not good for anything.
Sure, fixed.
Quoted 10 lines
include/uapi/linux/dpll.h line 177
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 1 line · Thu, Mar 16, 2023 at 02:45:10PM CET, [email protected] wrote:
Thu, Mar 16, 2023 at 02:15:59PM CET, [email protected] wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - modeQuoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.
Quoted 7 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Actually, for mlx5 implementation, would be non-trivial to implement this, as each of the pin/port is instantiated and controlled by separate pci backend.
Could you please remove, it is not needed and has potential and real issues.
[...]
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 35 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 4:20 PMQuoted 1 line · Thu, Mar 16, 2023 at 02:45:10PM CET, [email protected] wrote:
Thu, Mar 16, 2023 at 02:15:59PM CET, [email protected] wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - modeQuoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.Quoted 7 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 8 lines
Actually, for mlx5 implementation, would be non-trivial to implement this, as each of the pin/port is instantiated and controlled by separate pci backend.
Could you please remove, it is not needed and has potential and real issues.
[...]
Sorry I cannot, for priority based automatic selection mode multiple sources are enabled at any time - selection is done automatically by the chip. Thus for that case, this attribute is only way of getting an active source. Although, maybe we could allow driver to not implement it, would this help for your case? As it seems only required for automatic mode selection.
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 42 lines · Fri, Mar 17, 2023 at 01:53:49AM CET, [email protected] wrote:
Quoted 42 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 4:20 PMQuoted 1 line · Thu, Mar 16, 2023 at 02:45:10PM CET, [email protected] wrote:
Thu, Mar 16, 2023 at 02:15:59PM CET, [email protected] wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - modeQuoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.Quoted 7 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Actually, for mlx5 implementation, would be non-trivial to implement this, as each of the pin/port is instantiated and controlled by separate pci backend.
Could you please remove, it is not needed and has potential and real issues.
Quoted 7 lines
Quoted 1 line
[...]
Sorry I cannot, for priority based automatic selection mode multiple sources are enabled at any time - selection is done automatically by the chip. Thus for that case, this attribute is only way of getting an active source. Although, maybe we could allow driver to not implement it, would this help for your case? As it seems only required for automatic mode selection.
Please see the other reply for this patch where I describe what I think is wrong about this approach and suggesting a solution.
Quoted 3 lines
Thank you,
Arkadiusz
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Jiri PirkoQuoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM
[...]
Quoted 24 lines
Quoted 16 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 3 lines
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
Quoted 7 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}]}]
Quoted 5 lines
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Device nest should not be there for
DEVICE_GET, does not make sense.
This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-get
Please note this relates to 'dump' request , it is rather expected that there are multiple dplls returned, thus we need a nest attribute for each one.
Quoted 18 lines
Quoted 3 lines
- do/dump of pin-get, in case of shared pins, each pin contains number of
dpll
Quoted 13 lines
handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci','dev-name': '0000:21:00.0_0', 'id': 0, 'pin-prio': 6, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}, {'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1, 'pin-prio': 8, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}],
Quoted 3 lines
Okay, here I understand it contains device specific pin items. Makes sense!
Good.
[...]
Quoted 30 lines
Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ - + name: pin-prio + type: u32Documentation/netlink/specs/dpll.yaml line 263
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?Quoted 4 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better wayto
Quoted 3 lines
prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attribute
Quoted 7 lines
there
Quoted 1 line
with value=0, thus there is a need to assign a proper value, same as it is
on
Quoted 1 line
'main' attribute list.
That's weird. Looks like a bug then?
Guess we could call it a bug, I haven't investigated the parser that much, AFAIR, other specs are doing the same way.
Quoted 62 lines
Quoted 62 lines
Quoted 61 lines
Quoted 48 lines
Documentation/netlink/specs/dpll.yaml new file +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64Documentation/netlink/specs/dpll.yaml line 318
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pinThis does not belong here.
Quoted 9 lines
Quoted 3 lines
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.No, wait a sec. You have 2 object types: device and pin. Each have separate netlink CMDs to get and dump individual objects. Don't mix those together like this. I thought it became clear in the past. :/
For pins we must, as pins without a handle to a dpll are pointless. Same as a dpll without pins, right?
'do' of DEVICE_GET could just dump it's own status, without the list of pins, but it feels easier for handling it's state on userspace counterpart if that command also returns currently registered pins. Don't you think so?
Quoted 104 lines
Quoted 17 lines
This is required by parser to work.
Quoted 14 lines
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26Quoted 4 lines
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Same as above reply.
Quoted 62 lines
Quoted 53 lines
Quoted 42 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: trueQuoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":13}'
{'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},Quoted 16 lines
{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}], 'pin-description': '0000:21:00.0', 'pin-direction': {'doc': 'pin used as a source of a signal', 'name': 'source'}, 'pin-idx': 13, 'pin-parent': [{'pin-parent-idx': 2, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}, {'pin-parent-idx': 3, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}], 'pin-rclk-device': '0000:21:00.0', 'pin-type': {'doc': "ethernet port PHY's recovered clock", 'name': 'synce-eth-port'}}]}
Quoted 5 lines
Got it, it is still a bit hard to me to follow this. Could you perhaps extend the Documentation to describe in more details with examples? Would help a lot for slower people like me to understand what's what.
Actually this is already explained in "MUX-type pins" paragraph of Documentation/networking/dpll.rst.
Do we want to duplicate this explanation here?
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Missing "enum: "
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Ah! Got it. Perhaps a docs note with the enum pointer then?
Same as above, explained in Documentation/networking/dpll.rst, do wan't to duplicate?
Quoted 45 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Documentation/netlink/specs/dpll.yaml new file +16
-0+ - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-state + type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: stringQuoted 5 lines
Quoted 3 lines
Yeah, as I wrote in the other email, this really smells to have like a simple string like this. What is it supposed to be?
Yes, let's discuss there.
Yep.
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
Documentation/netlink/specs/dpll.yaml new file +2
-0+ +Documentation/netlink/specs/dpll.yaml
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dplldevice
Quoted 1 line
+ attribute-set: dpll
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Shouldn't this be "device"?
It would brake the parser, again I hope Jakub Kicinski could take a look on this.
Odd.
Yes, seems a bit odd.
Quoted 52 lines
Quoted 52 lines
Quoted 21 lines
Quoted 21 lines
Documentation/netlink/specs/dpll.yaml new file +19
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump: + pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes:Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 442
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll"device" here as well?
Same as above.
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - modeQuoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.
Quoted 8 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
drivers/dpll/dpll_nl.c line 25
Quoted 9 lines
drivers/dpll/dpll_nl.c new file +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1]
= {drivers/dpll/dpll_nl.c new file +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
include/uapi/linux/dpll.h line 177
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 36 lines · Fri, Mar 17, 2023 at 01:52:44AM CET, [email protected] wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 24 lines
Quoted 16 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 3 lines
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
Quoted 7 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}]}]Quoted 5 lines
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Device nest should not be there for
DEVICE_GET, does not make sense.
Quoted 6 lines
This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-getPlease note this relates to 'dump' request , it is rather expected that there are multiple dplls returned, thus we need a nest attribute for each one.
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
See how that is done in devlink for example: devlink_nl_fill() This functions fills up one object in the dump. No nesting. I'm not aware of such nesting approach anywhere in kernel dumps, does not make sense at all.
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
- do/dump of pin-get, in case of shared pins, each pin contains number of
dpll
Quoted 13 lines
handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci','dev-name': '0000:21:00.0_0', 'id': 0, 'pin-prio': 6, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}, {'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1, 'pin-prio': 8, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}],
Quoted 5 lines
Quoted 3 lines
Okay, here I understand it contains device specific pin items. Makes sense!
Good.
Make sure you don't nest the pin objects for dump (DPLL_A_PIN). Same reason as above.
I don't see a need for DPLL_A_PIN attr existence, please remove it.
Quoted 110 lines
[...]
Quoted 30 lines
Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ - + name: pin-prio + type: u32Documentation/netlink/specs/dpll.yaml line 263
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?Quoted 4 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better wayto
Quoted 3 lines
prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attributeQuoted 7 lines
there
Quoted 1 line
with value=0, thus there is a need to assign a proper value, same as it is
on
Quoted 1 line
'main' attribute list.
That's weird. Looks like a bug then?
Guess we could call it a bug, I haven't investigated the parser that much, AFAIR, other specs are doing the same way.
Quoted 66 lines
Quoted 65 lines
Quoted 59 lines
Quoted 48 lines
Documentation/netlink/specs/dpll.yaml new file +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64Documentation/netlink/specs/dpll.yaml line 318
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pinQuoted 2 lines
This does not belong here.
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.
Quoted 7 lines
Quoted 5 lines
No, wait a sec. You have 2 object types: device and pin. Each have separate netlink CMDs to get and dump individual objects. Don't mix those together like this. I thought it became clear in the past. :/
For pins we must, as pins without a handle to a dpll are pointless.
I'm not talking about per device specific items for pins (state and prio). That is something else, it's a pin-device tuple. Completely fine.
Quoted 3 lines
Same as a dpll without pins, right?
'do' of
DEVICE_GETcould just dump it's own status, without the list of pins,
Yes please.
Quoted 2 lines
but it feels easier for handling it's state on userspace counterpart if that command also returns currently registered pins. Don't you think so?
No, definitelly not. Please make the object separation clear. Device and pins are different objects, they have different commands to work with. Don't mix them together.
Quoted 111 lines
Quoted 105 lines
Quoted 18 lines
This is required by parser to work.
Quoted 14 lines
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26Quoted 4 lines
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Same as above reply.
Quoted 62 lines
Quoted 53 lines
Quoted 42 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: trueQuoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":13}'
{'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},Quoted 16 lines
{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}], 'pin-description': '0000:21:00.0', 'pin-direction': {'doc': 'pin used as a source of a signal', 'name': 'source'}, 'pin-idx': 13, 'pin-parent': [{'pin-parent-idx': 2, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}, {'pin-parent-idx': 3, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}], 'pin-rclk-device': '0000:21:00.0', 'pin-type': {'doc': "ethernet port PHY's recovered clock", 'name': 'synce-eth-port'}}]}Quoted 5 lines
Got it, it is still a bit hard to me to follow this. Could you perhaps extend the Documentation to describe in more details with examples? Would help a lot for slower people like me to understand what's what.
Quoted 3 lines
Actually this is already explained in "MUX-type pins" paragraph of
Documentation/networking/dpll.rst.
Do we want to duplicate this explanation here?
No, please extend the docs. As I wrote above, could you add some examples, like the one you pasted above. Examples always help to undestand things much better.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml line 388
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32Missing "enum: "
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Ah! Got it. Perhaps a docs note with the enum pointer then?
Same as above, explained in
Documentation/networking/dpll.rst, do wan't to duplicate?
For this, yes. Some small doc note here would be quite convenient.
Also, I almost forgot: Please don't use NLA_U32 for caps flags. Please use NLA_BITFIELD32 which was introduced for exactly this purpose. Allows to do nicer validation as well.
Quoted 118 lines
Quoted 46 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Documentation/netlink/specs/dpll.yaml new file +16
-0+ - + name: pin-parent + subset-of: dpll + attributes: + - + name: pin-state + type: u8 + value: 22 + enum: pin-state + - + name: pin-parent-idx + type: u32 + value: 24 + - + name: pin-rclk-device + type: stringQuoted 5 lines
Quoted 3 lines
Yeah, as I wrote in the other email, this really smells to have like a simple string like this. What is it supposed to be?
Yes, let's discuss there.
Yep.
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
Documentation/netlink/specs/dpll.yaml new file +2
-0+ +Documentation/netlink/specs/dpll.yaml
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+operations: + list: + - + name: unspec + doc: unused + + - + name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dplldevice
Quoted 1 line
+ attribute-set: dpll
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Shouldn't this be "device"?
It would brake the parser, again I hope Jakub Kicinski could take a look on this.
Odd.
Yes, seems a bit odd.
Quoted 52 lines
Quoted 52 lines
Quoted 21 lines
Quoted 21 lines
Documentation/netlink/specs/dpll.yaml new file +19
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + reply: + attributes: + - device + + dump: + pre: dpll-pre-dumpit + post: dpll-post-dumpit + reply: + attributes:Quoted 9 lines
Documentation/netlink/specs/dpll.yaml line 442
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ - device + + - + name: device-set + doc: Set attributes for a DPLL device + attribute-set: dpll"device" here as well?
Same as above.
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml line 453
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+ flags: [ admin-perm ] + + do: + pre: dpll-pre-doit + post: dpll-post-doit + request: + attributes: + - id + - bus-name + - dev-name + - modeQuoted 1 line
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.Quoted 8 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 2 lines
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
Okay, this is confusing and I believe wrong.
You have dual meaning for pin state attribute with states STATE_CONNECTED/DISCONNECTED:
1) Manual mode, MUX pins (both share the same model):
There is only one pin with STATE_CONNECTED. The others are in STATE_DISCONNECTED
User changes a state of a pin to make the selection.
Example:
$ dplltool pin dump
pin 1 state connected
pin 2 state disconnected
$ dplltool pin 2 set state connected
$ dplltool pin dump
pin 1 state disconnected
pin 2 state connected2) Automatic mode:
The user by setting "state" decides it the pin should be considered by the device for auto selection.
Example:
$ dplltool pin dump:
pin 1 state connected prio 10
pin 2 state connected prio 15
$ dplltool dpll x get:
dpll x source-pin-index 1So in manual mode, STATE_CONNECTED means the dpll is connected to this source pin. However, in automatic mode it means something else. It means the user allows this pin to be considered for auto selection. The fact the pin is selected source is exposed over source-pin-index.
Instead of this, I believe that the semantics of STATE_CONNECTED/DISCONNECTED should be the same for automatic mode as well. Unlike the manual mode/mux, where the state is written by user, in automatic mode the state should be only written by the driver. User attemts to set the state should fail with graceful explanation (DPLL netlink/core code should handle that, w/o driver interaction)
Suggested automatic mode example:
$ dplltool pin dump:
pin 1 state connected prio 10 connectable true
pin 2 state disconnected prio 15 connectable true
$ dplltool pin 1 set connectable false
$ dplltool pin dump:
pin 1 state disconnected prio 10 connectable false
pin 2 state connected prio 15 connectable true
$ dplltool pin 1 set state connected
-EOPNOTSUPPNote there is no "source-pin-index" at all. Replaced by pin state here. There is a new attribute called "connectable", the user uses this attribute to tell the device, if this source pin could be considered for auto selection or not.
Could be called perhaps "selectable", does not matter. The point is, the meaning of the "state" attribute is consistent for automatic mode, manual mode and mux pin.
Makes sense?
Quoted 39 lines
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
drivers/dpll/dpll_nl.c line 25
Quoted 9 lines
drivers/dpll/dpll_nl.c new file +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1]
= {drivers/dpll/dpll_nl.c new file +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
include/uapi/linux/dpll.h line 177
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Glad to help.
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 41 lines · Fri, Mar 17, 2023 at 11:05:26AM CET, [email protected] wrote:
Quoted 40 lines · Fri, Mar 17, 2023 at 01:52:44AM CET, [email protected] wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 24 lines
Quoted 16 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 3 lines
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
Quoted 7 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}]}]Quoted 5 lines
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Device nest should not be there for
DEVICE_GET, does not make sense.This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-get
Quoted 5 lines
Quoted 2 lines
Please note this relates to 'dump' request , it is rather expected that there are multiple dplls returned, thus we need a nest attribute for each one.
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
Another example:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump dev-get
[{'ifindex': 1, 'xdp-features': set()},
{'ifindex': 2, 'xdp-features': {'basic', 'rx-sg', 'redirect'}},
{'ifindex': 3, 'xdp-features': {'basic', 'rx-sg', 'redirect'}},
{'ifindex': 4, 'xdp-features': set()},
{'ifindex': 5, 'xdp-features': {'basic', 'rx-sg', 'xsk-zerocopy', 'redirect'}},
{'ifindex': 6, 'xdp-features': {'basic', 'rx-sg', 'xsk-zerocopy', 'redirect'}}][...]
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Jiri PirkoQuoted 51 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 11:05 AMQuoted 35 lines · Fri, Mar 17, 2023 at 01:52:44AM CET, [email protected] wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 29 lines
Quoted 19 lines
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml line 182
Quoted 11 lines
Documentation/netlink/specs/dpll.yaml new file +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 3 lines
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
No, it is nested attribute type, used when multiple devices are returned with netlink:
Quoted 6 lines
- dump of device-get command where all devices are returned, each one nested
inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id':1}]}]
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Quoted 8 lines
Quoted 2 lines
Device nest should not be there for
DEVICE_GET, does not make sense.This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-getPlease note this relates to 'dump' request , it is rather expected that
there
Quoted 1 line
are multiple dplls returned, thus we need a nest attribute for each one.
Quoted 8 lines
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
See how that is done in devlink for example:
devlink_nl_fill()This functions fills up one object in the dump. No nesting. I'm not aware of such nesting approach anywhere in kernel dumps, does not make sense at all.
Yeah it make sense to have same output on do and dump, but this is also achievable with nest DPLL_A_DEVICE, still don't need put extra header for it. The difference would be that on dump multiple DPLL_A_DEVICE are provided, on do only one.
Will try to fix it.
Although could you please explain why it make sense to put extra header (exactly the same header) multiple times in one netlink response message?
Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
- do/dump of pin-get, in case of shared pins, each pin contains number
of
Quoted 19 lines
Quoted 18 lines
dpll
Quoted 13 lines
handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci','dev-name': '0000:21:00.0_0', 'id': 0, 'pin-prio': 6, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}, {'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1, 'pin-prio': 8, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}],Okay, here I understand it contains device specific pin items. Makes sense!
Quoted 7 lines
Quoted 1 line
Good.
Make sure you don't nest the pin objects for dump (
DPLL_A_PIN). Same reason as above.
I don't see a need forDPLL_A_PINattr existence, please remove it.
Sure, will try.
Quoted 133 lines
Quoted 112 lines
[...]
Quoted 30 lines
Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ - + name: pin-prio + type: u32Documentation/netlink/specs/dpll.yaml line 263
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?Quoted 4 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better wayto
Quoted 3 lines
prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attributeQuoted 7 lines
there
Quoted 1 line
with value=0, thus there is a need to assign a proper value, same as it is
on
Quoted 1 line
'main' attribute list.
That's weird. Looks like a bug then?
Guess we could call it a bug, I haven't investigated the parser that much, AFAIR, other specs are doing the same way.
Quoted 66 lines
Quoted 65 lines
Quoted 59 lines
Quoted 48 lines
Documentation/netlink/specs/dpll.yaml new file +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64Documentation/netlink/specs/dpll.yaml line 318
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pinQuoted 2 lines
This does not belong here.
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.Quoted 7 lines
Quoted 5 lines
No, wait a sec. You have 2 object types: device and pin. Each have separate netlink CMDs to get and dump individual objects. Don't mix those together like this. I thought it became clear in the past. :/
For pins we must, as pins without a handle to a dpll are pointless.
I'm not talking about per device specific items for pins (state and prio). That is something else, it's a pin-device tuple. Completely fine.
Quoted 3 lines
Same as a dpll without pins, right?
'do' of
DEVICE_GETcould just dump it's own status, without the list ofpins,
Yes please.
Quoted 7 lines
Quoted 2 lines
but it feels easier for handling it's state on userspace counterpart if that command also returns currently registered pins. Don't you think so?
No, definitelly not. Please make the object separation clear. Device and pins are different objects, they have different commands to work with. Don't mix them together.
It does, since the user app wouldn't have to dump/get pins continuously. But yeah, as object separation argument makes sense will try to fix it.
Quoted 112 lines
Quoted 112 lines
Quoted 111 lines
Quoted 19 lines
This is required by parser to work.
Quoted 14 lines
Quoted 13 lines
Documentation/netlink/specs/dpll.yaml new file +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26Quoted 4 lines
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Same as above reply.
Quoted 62 lines
Quoted 53 lines
Quoted 42 lines
Documentation/netlink/specs/dpll.yaml new file +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Documentation/netlink/specs/dpll.yaml line 379
Quoted 10 lines
Documentation/netlink/specs/dpll.yaml new file +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: trueQuoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":13}'
{'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},Quoted 16 lines
{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}], 'pin-description': '0000:21:00.0', 'pin-direction': {'doc': 'pin used as a source of a signal', 'name': 'source'}, 'pin-idx': 13, 'pin-parent': [{'pin-parent-idx': 2, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}, {'pin-parent-idx': 3, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}], 'pin-rclk-device': '0000:21:00.0', 'pin-type': {'doc': "ethernet port PHY's recovered clock", 'name': 'synce-eth-port'}}]}Got it, it is still a bit hard to me to follow this. Could you perhaps extend the Documentation to describe in more details with examples? Would help a lot for slower people like me to understand what's what.
Quoted 8 lines
Quoted 3 lines
Actually this is already explained in "MUX-type pins" paragraph of
Documentation/networking/dpll.rst.
Do we want to duplicate this explanation here?No, please extend the docs. As I wrote above, could you add some examples, like the one you pasted above. Examples always help to undestand things much better.
Sure, fixed.
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32Quoted 5 lines
Quoted 2 lines
Missing "enum: "
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Ah! Got it. Perhaps a docs note with the enum pointer then?
Quoted 9 lines
Quoted 2 lines
Same as above, explained in
Documentation/networking/dpll.rst, do wan't to duplicate?For this, yes. Some small doc note here would be quite convenient.
Also, I almost forgot: Please don't use
NLA_U32for caps flags. Please useNLA_BITFIELD32which was introduced for exactly this purpose. Allows to do nicer validation as well.
Actually BITFIELD32 is to much for this case, the bit itself would be enough as we don't need validity bit.
But yeah, as there is no BITMASK yet, will try to change to BITFIELD32.
[...]
Quoted 76 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.Quoted 8 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 2 lines
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
Okay, this is confusing and I believe wrong.
You have dual meaning for pin state attribute with states STATE_CONNECTED/DISCONNECTED:1) Manual mode, MUX pins (both share the same model):
There is only one pin withSTATE_CONNECTED. The others are inSTATE_DISCONNECTED
User changes a state of a pin to make the selection.Example:
$ dplltool pin dump pin 1 state connected pin 2 state disconnected $ dplltool pin 2 set state connected $ dplltool pin dump pin 1 state disconnected pin 2 state connected2) Automatic mode:
The user by setting "state" decides it the pin should be considered by the device for auto selection.Example:
$ dplltool pin dump: pin 1 state connected prio 10 pin 2 state connected prio 15 $ dplltool dpll x get: dpll x source-pin-index 1So in manual mode,
STATE_CONNECTEDmeans the dpll is connected to this source pin. However, in automatic mode it means something else. It means the user allows this pin to be considered for auto selection. The fact the pin is selected source is exposed over source-pin-index.Instead of this, I believe that the semantics of STATE_CONNECTED/DISCONNECTED should be the same for automatic mode as well. Unlike the manual mode/mux, where the state is written by user, in automatic mode the state should be only written by the driver. User attemts to set the state should fail with graceful explanation (DPLL netlink/core code should handle that, w/o driver interaction)
Suggested automatic mode example:
$ dplltool pin dump: pin 1 state connected prio 10 connectable true pin 2 state disconnected prio 15 connectable true $ dplltool pin 1 set connectable false $ dplltool pin dump: pin 1 state disconnected prio 10 connectable false pin 2 state connected prio 15 connectable true $ dplltool pin 1 set state connected -EOPNOTSUPPNote there is no "source-pin-index" at all. Replaced by pin state here. There is a new attribute called "connectable", the user uses this attribute to tell the device, if this source pin could be considered for auto selection or not.
Quoted 6 lines
Could be called perhaps "selectable", does not matter. The point is, the meaning of the "state" attribute is consistent for automatic mode, manual mode and mux pin.
Makes sense?
Great idea!
I will add third enum for pin-state: DPLL_PIN_STATE_SELECTABLE. In the end we will have this:
+--------------------------------+
| valid DPLL_A_PIN_STATE values |
+---------------+----------------+
+------------+| requested: | returned: |
|DPLL_A_MODE:|| | |
|------------++--------------------------------|
|AUTOMATIC ||- SELECTABLE | - SELECTABLE |
| ||- DISCONNECTED | - DISCONNECTED |
| || | - CONNECTED |
|------------++--------------------------------|
|MANUAL ||- CONNECTED | - CONNECTED |
| ||- DISCONNECTED | - DISCONNECTED |
+------------++---------------+----------------+Thank you,
Arkadiusz
Quoted 48 lines
Quoted 40 lines
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
drivers/dpll/dpll_nl.c line 25
Quoted 9 lines
drivers/dpll/dpll_nl.c new file +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1]
= {drivers/dpll/dpll_nl.c new file +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
include/uapi/linux/dpll.h line 177
Quoted 7 lines
include/uapi/linux/dpll.h new file +6
-0+DPLL_A_PIN_PRIO , +DPLL_A_PIN_STATE , +DPLL_A_PIN_PARENT , +DPLL_A_PIN_PARENT_IDX , +DPLL_A_PIN_RCLK_DEVICE , + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Glad to help.
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 60 lines · Fri, Mar 17, 2023 at 04:14:45PM CET, [email protected] wrote:
Quoted 51 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 11:05 AMQuoted 35 lines · Fri, Mar 17, 2023 at 01:52:44AM CET, [email protected] wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 29 lines
Quoted 19 lines
Quoted 12 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 3 lines
What is this "device" and what is it good for? Smells like some leftover and with the nested scheme looks quite odd.
No, it is nested attribute type, used when multiple devices are returned with netlink:
Quoted 6 lines
- dump of device-get command where all devices are returned, each one nested
inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id':1}]}]
Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Quoted 8 lines
Quoted 2 lines
Device nest should not be there for
DEVICE_GET, does not make sense.This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-getPlease note this relates to 'dump' request , it is rather expected that
there
Quoted 1 line
are multiple dplls returned, thus we need a nest attribute for each one.
Quoted 8 lines
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
See how that is done in devlink for example:
devlink_nl_fill()This functions fills up one object in the dump. No nesting. I'm not aware of such nesting approach anywhere in kernel dumps, does not make sense at all.
Quoted 4 lines
Yeah it make sense to have same output on
doanddump, but this is also achievable with nestDPLL_A_DEVICE, still don't need put extra header for it. The difference would be that ondumpmultipleDPLL_A_DEVICEare provided, ondoonly one.
Please don't. This root nesting is not correct.
Quoted 4 lines
Will try to fix it.
Although could you please explain why it make sense to put extra header (exactly the same header) multiple times in one netlink response message?
This is how it's done for all netlink dumps as far as I know. The reason might be that the userspace is parsing exactly the same message as if it would be DOIT message.
Quoted 28 lines
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
- do/dump of pin-get, in case of shared pins, each pin contains number
of
Quoted 20 lines
Quoted 15 lines
dpll
Quoted 13 lines
handles it connects with:
[{'pin': [{'device': [{'bus-name': 'pci','dev-name': '0000:21:00.0_0', 'id': 0, 'pin-prio': 6, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}, {'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1, 'pin-prio': 8, 'pin-state': {'doc': 'pin connected', 'name': 'connected'}}],Quoted 3 lines
Okay, here I understand it contains device specific pin items. Makes sense!
Good.
Quoted 7 lines
Quoted 5 lines
Make sure you don't nest the pin objects for dump (
DPLL_A_PIN). Same reason as above.
I don't see a need forDPLL_A_PINattr existence, please remove it.Sure, will try.
Cool.
Quoted 137 lines
Quoted 137 lines
Quoted 113 lines
[...]
Quoted 30 lines
Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
(quoted diff) +3
-0+ - + name: pin-prio + type: u32Review
Quoted 10 lines
(quoted diff) +10
-0+ - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: true + nested-attributes: pin + value: 23Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?Quoted 4 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better wayto
Quoted 3 lines
prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attributeQuoted 7 lines
there
Quoted 1 line
with value=0, thus there is a need to assign a proper value, same as it is
on
Quoted 1 line
'main' attribute list.
That's weird. Looks like a bug then?
Guess we could call it a bug, I haven't investigated the parser that much, AFAIR, other specs are doing the same way.
Quoted 66 lines
Quoted 65 lines
Quoted 59 lines
Quoted 48 lines
(quoted diff) +45
-0+ - + name: pin-parent-idx + type: u32 + - + name: pin-rclk-device + type: string + - + name: pin-dpll-caps + type: u32 + - + name: device + subset-of: dpll + attributes: + - + name: id + type: u32 + value: 2 + - + name: dev-name + type: string + - + name: bus-name + type: string + - + name: mode + type: u8 + enum: mode + - + name: mode-supported + type: u8 + enum: mode + multi-attr: true + - + name: source-pin-idx + type: u32 + - + name: lock-status + type: u8 + enum: lock-status + - + name: temp + type: s32 + - + name: clock-id + type: u64Review
Quoted 10 lines
(quoted diff) +10
-0+ - + name: type + type: u8 + enum: type + - + name: pin + type: nest + value: 12 + multi-attr: true + nested-attributes: pinQuoted 2 lines
This does not belong here.
What do you mean?
With device-get 'do' request the list of pins connected to the dpll is returned, each pin is nested in this attribute.Quoted 7 lines
Quoted 5 lines
No, wait a sec. You have 2 object types: device and pin. Each have separate netlink CMDs to get and dump individual objects. Don't mix those together like this. I thought it became clear in the past. :/
For pins we must, as pins without a handle to a dpll are pointless.
I'm not talking about per device specific items for pins (state and prio). That is something else, it's a pin-device tuple. Completely fine.
Quoted 3 lines
Same as a dpll without pins, right?
'do' of
DEVICE_GETcould just dump it's own status, without the list ofpins,
Yes please.
Quoted 2 lines
but it feels easier for handling it's state on userspace counterpart if that command also returns currently registered pins. Don't you think so?
Quoted 6 lines
Quoted 4 lines
No, definitelly not. Please make the object separation clear. Device and pins are different objects, they have different commands to work with. Don't mix them together.
It does, since the user app wouldn't have to dump/get pins continuously.
I don't follow. For every pin change there is going to be pin object dumped over monitoring netlink.
Quoted 1 line
But yeah, as object separation argument makes sense will try to fix it.
Awesome.
Quoted 252 lines
Quoted 113 lines
Quoted 113 lines
Quoted 112 lines
Quoted 20 lines
This is required by parser to work.
Quoted 14 lines
Quoted 13 lines
(quoted diff) +12
-0+ - + name: pin-prio + type: u32 + value: 21 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-dpll-caps + type: u32 + value: 26Quoted 4 lines
Quoted 2 lines
All these 3 do not belong here are well.
Same as above explanation.
Same as above reply.
Quoted 62 lines
Quoted 53 lines
Quoted 42 lines
(quoted diff) +39
-0+ - + name: pin + subset-of: dpll + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: device + - + name: pin-idx + type: u32 + value: 13 + - + name: pin-description + type: string + - + name: pin-type + type: u8 + enum: pin-type + - + name: pin-direction + type: u8 + enum: pin-direction + - + name: pin-frequency + type: u32 + - + name: pin-frequency-supported + type: u32 + multi-attr: true + - + name: pin-any-frequency-min + type: u32 + - + name: pin-any-frequency-max + type: u32 + -Review
Quoted 10 lines
(quoted diff) +10
-0+ name: pin-prio + type: u32 + - + name: pin-state + type: u8 + enum: pin-state + - + name: pin-parent + type: nest + multi-attr: trueQuoted 2 lines
Multiple parents? How is that supposed to work?
As we have agreed, MUXed pins can have multiple parents.
In our case:
/tools/net/ynl/cli.py --specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":13}'
{'pin': [{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id': 0},Quoted 16 lines
{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id': 1}], 'pin-description': '0000:21:00.0', 'pin-direction': {'doc': 'pin used as a source of a signal', 'name': 'source'}, 'pin-idx': 13, 'pin-parent': [{'pin-parent-idx': 2, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}, {'pin-parent-idx': 3, 'pin-state': {'doc': 'pin disconnected', 'name': 'disconnected'}}], 'pin-rclk-device': '0000:21:00.0', 'pin-type': {'doc': "ethernet port PHY's recovered clock", 'name': 'synce-eth-port'}}]}Got it, it is still a bit hard to me to follow this. Could you perhaps extend the Documentation to describe in more details with examples? Would help a lot for slower people like me to understand what's what.
Quoted 8 lines
Quoted 3 lines
Actually this is already explained in "MUX-type pins" paragraph of
Documentation/networking/dpll.rst.
Do we want to duplicate this explanation here?No, please extend the docs. As I wrote above, could you add some examples, like the one you pasted above. Examples always help to undestand things much better.
Sure, fixed.
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
(quoted diff) +9
-0+ nested-attributes: pin-parent + value: 23 + - + name: pin-rclk-device + type: string + value: 25 + - + name: pin-dpll-caps + type: u32Quoted 5 lines
Quoted 2 lines
Missing "enum: "
It is actually a bitmask, this is why didn't set as enum, with enum type parser won't parse it.
Ah! Got it. Perhaps a docs note with the enum pointer then?
Quoted 9 lines
Quoted 2 lines
Same as above, explained in
Documentation/networking/dpll.rst, do wan't to duplicate?For this, yes. Some small doc note here would be quite convenient.
Also, I almost forgot: Please don't use
NLA_U32for caps flags. Please useNLA_BITFIELD32which was introduced for exactly this purpose. Allows to do nicer validation as well.Actually BITFIELD32 is to much for this case, the bit itself would be enough as we don't need validity bit.
But yeah, as there is no BITMASK yet, will try to change to BITFIELD32.[...]
Quoted 76 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on the one he needs to recover signal from.Quoted 8 lines
Quoted 1 line
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 2 lines
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
Okay, this is confusing and I believe wrong.
You have dual meaning for pin state attribute with states STATE_CONNECTED/DISCONNECTED:1) Manual mode, MUX pins (both share the same model):
There is only one pin withSTATE_CONNECTED. The others are inSTATE_DISCONNECTED
User changes a state of a pin to make the selection.Example:
$ dplltool pin dump pin 1 state connected pin 2 state disconnected $ dplltool pin 2 set state connected $ dplltool pin dump pin 1 state disconnected pin 2 state connected2) Automatic mode:
The user by setting "state" decides it the pin should be considered by the device for auto selection.Example:
$ dplltool pin dump: pin 1 state connected prio 10 pin 2 state connected prio 15 $ dplltool dpll x get: dpll x source-pin-index 1So in manual mode,
STATE_CONNECTEDmeans the dpll is connected to this source pin. However, in automatic mode it means something else. It means the user allows this pin to be considered for auto selection. The fact the pin is selected source is exposed over source-pin-index.Instead of this, I believe that the semantics of STATE_CONNECTED/DISCONNECTED should be the same for automatic mode as well. Unlike the manual mode/mux, where the state is written by user, in automatic mode the state should be only written by the driver. User attemts to set the state should fail with graceful explanation (DPLL netlink/core code should handle that, w/o driver interaction)
Suggested automatic mode example:
$ dplltool pin dump: pin 1 state connected prio 10 connectable true pin 2 state disconnected prio 15 connectable true $ dplltool pin 1 set connectable false $ dplltool pin dump: pin 1 state disconnected prio 10 connectable false pin 2 state connected prio 15 connectable true $ dplltool pin 1 set state connected -EOPNOTSUPPNote there is no "source-pin-index" at all. Replaced by pin state here. There is a new attribute called "connectable", the user uses this attribute to tell the device, if this source pin could be considered for auto selection or not.
Quoted 6 lines
Could be called perhaps "selectable", does not matter. The point is, the meaning of the "state" attribute is consistent for automatic mode, manual mode and mux pin.
Makes sense?
Great idea!
I will add third enum for pin-state:DPLL_PIN_STATE_SELECTABLE. In the end we will have this:
Quoted 9 lines
+--------------------------------+
| valid DPLL_A_PIN_STATE values |
+---------------+----------------+
+------------+| requested: | returned: |
|DPLL_A_MODE:|| | |
|------------++--------------------------------|
|AUTOMATIC ||- SELECTABLE | - SELECTABLE |
| ||- DISCONNECTED | - DISCONNECTED |
| || | - CONNECTED |"selectable" is something the user sets. "connected"/"disconnected" is in case of auto mode something that driver sets.
Looks a bit odd to mix them together. That is why I suggested to have sepectable as a separate attr. But up to you. Please make sure you sanitize the user/driver set of this attr in dpll code.
Quoted 56 lines
|------------++--------------------------------| |MANUAL ||- CONNECTED | - CONNECTED | | ||- DISCONNECTED | - DISCONNECTED | +------------++---------------+----------------+Thank you,
ArkadiuszQuoted 48 lines
Quoted 40 lines
[...]
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Review
Quoted 9 lines
(quoted diff) +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policy dpll_device_set_nl_policy[DPLL_A_MODE +1]
= {(quoted diff) +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+ DPLL_A_PIN_PRIO, + DPLL_A_PIN_STATE, + DPLL_A_PIN_PARENT, + DPLL_A_PIN_PARENT_IDX, + DPLL_A_PIN_RCLK_DEVICE, + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Glad to help.
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 74 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 5:21 PMQuoted 61 lines · Fri, Mar 17, 2023 at 04:14:45PM CET, [email protected] wrote:
Quoted 52 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 11:05 AMFri, Mar 17, 2023 at 01:52:44AM CET, [email protected]
Quoted 35 lines · wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 29 lines
Quoted 17 lines
Quoted 12 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 4 lines
What is this "device" and what is it good for? Smells like some leftover
and with the nested scheme looks quite odd.Quoted 8 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested
inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id':0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id':1}]}]Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Quoted 8 lines
Quoted 2 lines
Device nest should not be there for
DEVICE_GET, does not make sense.This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-getPlease note this relates to 'dump' request , it is rather expected that
there
Quoted 1 line
are multiple dplls returned, thus we need a nest attribute for each one.
Quoted 8 lines
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
See how that is done in devlink for example:
devlink_nl_fill()This functions fills up one object in the dump. No nesting. I'm not aware of such nesting approach anywhere in kernel dumps, does not make sense at all.Quoted 4 lines
Yeah it make sense to have same output on
doanddump, but this is also achievable with nestDPLL_A_DEVICE, still don't need put extra header for it. The difference would be that ondumpmultipleDPLL_A_DEVICEare provided, ondoonly one.Please don't. This root nesting is not correct.
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Will try to fix it.
Although could you please explain why it make sense to put extra header (exactly the same header) multiple times in one netlink response message?This is how it's done for all netlink dumps as far as I know.
So we just following something but we cannot explain why?
Quoted 3 lines
The reason might be that the userspace is parsing exactly the same message as if it would be DOIT message.
This argument is achievable on both approaches.
[...]
Quoted 97 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on theone
Quoted 81 lines
Quoted 71 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
he needs to recover signal from.
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 2 lines
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
Okay, this is confusing and I believe wrong.
You have dual meaning for pin state attribute with states STATE_CONNECTED/DISCONNECTED:1) Manual mode, MUX pins (both share the same model):
There is only one pin withSTATE_CONNECTED. The others are inSTATE_DISCONNECTED
User changes a state of a pin to make the selection.Example:
$ dplltool pin dump pin 1 state connected pin 2 state disconnected $ dplltool pin 2 set state connected $ dplltool pin dump pin 1 state disconnected pin 2 state connected2) Automatic mode:
The user by setting "state" decides it the pin should be considered by the device for auto selection.Example:
$ dplltool pin dump: pin 1 state connected prio 10 pin 2 state connected prio 15 $ dplltool dpll x get: dpll x source-pin-index 1So in manual mode,
STATE_CONNECTEDmeans the dpll is connected to this source pin. However, in automatic mode it means something else. It means the user allows this pin to be considered for auto selection. The fact the pin is selected source is exposed over source-pin-index.Instead of this, I believe that the semantics of STATE_CONNECTED/DISCONNECTED should be the same for automatic mode as well. Unlike the manual mode/mux, where the state is written by user, in automatic mode the state should be only written by the driver. User attemts to set the state should fail with graceful explanation (DPLL netlink/core code should handle that, w/o driver interaction)
Suggested automatic mode example:
$ dplltool pin dump: pin 1 state connected prio 10 connectable true pin 2 state disconnected prio 15 connectable true $ dplltool pin 1 set connectable false $ dplltool pin dump: pin 1 state disconnected prio 10 connectable false pin 2 state connected prio 15 connectable true $ dplltool pin 1 set state connected -EOPNOTSUPPNote there is no "source-pin-index" at all. Replaced by pin state here. There is a new attribute called "connectable", the user uses this attribute to tell the device, if this source pin could be considered for auto selection or not.
Quoted 6 lines
Could be called perhaps "selectable", does not matter. The point is, the meaning of the "state" attribute is consistent for automatic mode, manual mode and mux pin.
Makes sense?
Great idea!
I will add third enum for pin-state:DPLL_PIN_STATE_SELECTABLE. In the end we will have this:Quoted 9 lines
+--------------------------------+ | valid DPLL_A_PIN_STATE values | +---------------+----------------+ +------------+| requested: | returned: | |DPLL_A_MODE:|| | | |------------++--------------------------------| |AUTOMATIC ||- SELECTABLE | - SELECTABLE | | ||- DISCONNECTED | - DISCONNECTED | | || | - CONNECTED |
Quoted 1 line
"selectable" is something the user sets.
Yes.
Quoted 3 lines
"connected"/"disconnected" is in case of auto mode something that driver sets.
No. Not really.
"CONNECTED" is only set by driver once a pin is choosen. "SELECTABLE" is set by the user if he needs to enable a pin for selection, it is also default state of a pin if it was not selected ("CONNECTED") "DISCONNECTED" is set by the user if he needs to disable a pin from selection.
Quoted 4 lines
Looks a bit odd to mix them together. That is why I suggested to have sepectable as a separate attr. But up to you. Please make sure you sanitize the user/driver set of this attr in dpll code.
What is odd?
What do you mean by "sanitize the user/driver set of this attr in dpll code"?
Thank you,
Arkadiusz
Quoted 58 lines
Quoted 11 lines
|------------++--------------------------------| |MANUAL ||- CONNECTED | - CONNECTED | | ||- DISCONNECTED | - DISCONNECTED | +------------++---------------+----------------+Thank you,
ArkadiuszQuoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
[...]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policydpll_device_set_nl_policy[DPLL_A_MODE +
Quoted 41 lines
Quoted 41 lines
Quoted 33 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines
1]
= {(quoted diff) +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+ DPLL_A_PIN_PRIO, + DPLL_A_PIN_STATE, + DPLL_A_PIN_PARENT, + DPLL_A_PIN_PARENT_IDX, + DPLL_A_PIN_RCLK_DEVICE, + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Glad to help.
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 74 lines · Fri, Mar 17, 2023 at 07:22:46PM CET, [email protected] wrote:
Quoted 74 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 5:21 PMQuoted 61 lines · Fri, Mar 17, 2023 at 04:14:45PM CET, [email protected] wrote:
Quoted 52 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 11:05 AMFri, Mar 17, 2023 at 01:52:44AM CET, [email protected]
Quoted 35 lines · wrote:
Quoted 3 lines
From: Jiri Pirko <[email protected]>
Sent: Thursday, March 16, 2023 2:45 PM[...]
Quoted 29 lines
Quoted 17 lines
Quoted 12 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+attribute-sets: + - + name: dpll + enum-name: dplla + attributes: + - + name: device + type: nest + value: 1 + multi-attr: true + nested-attributes: deviceQuoted 4 lines
What is this "device" and what is it good for? Smells like some leftover
and with the nested scheme looks quite odd.Quoted 8 lines
No, it is nested attribute type, used when multiple devices are returned with netlink:
- dump of device-get command where all devices are returned, each one nested
inside it:
[{'device': [{'bus-name': 'pci', 'dev-name': '0000:21:00.0_0', 'id':0},{'bus-name': 'pci', 'dev-name': '0000:21:00.0_1', 'id':1}]}]Okay, why is it nested here? The is one netlink msg per dpll device instance. Is this the real output of you made that up?
Quoted 8 lines
Quoted 2 lines
Device nest should not be there for
DEVICE_GET, does not make sense.This was returned by CLI parser on ice with cmd:
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml / --dump device-getPlease note this relates to 'dump' request , it is rather expected that
there
Quoted 1 line
are multiple dplls returned, thus we need a nest attribute for each one.
Quoted 8 lines
No, you definitelly don't need to nest them. Dump format and get format should be exactly the same. Please remove the nest.
See how that is done in devlink for example:
devlink_nl_fill()This functions fills up one object in the dump. No nesting. I'm not aware of such nesting approach anywhere in kernel dumps, does not make sense at all.Quoted 4 lines
Yeah it make sense to have same output on
doanddump, but this is also achievable with nestDPLL_A_DEVICE, still don't need put extra header for it. The difference would be that ondumpmultipleDPLL_A_DEVICEare provided, ondoonly one.Please don't. This root nesting is not correct.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Will try to fix it.
Although could you please explain why it make sense to put extra header (exactly the same header) multiple times in one netlink response message?This is how it's done for all netlink dumps as far as I know.
So we just following something but we cannot explain why?
I thought it is obvious. With what you suggest, each generic netlink user would have to have all commands that implement both do and dump with message format of a root nest. Not only that, for the sake of consistency, all the rest of the commands would have to implement same root nesting format. Both ways, to and from kernel.
So no matter what, all the messages would look like:
CMD_X MSG:
SUBSYS_ATTR_ROOT
SUBSYS_ATTR_1
SUBSYS_ATTR_2
***
SUBSYS_ATTR_NWhat I say, this extra level of nesting is not needed and in fact it is not good for anything. Remove it and just have:
CMD_X MSG:
SUBSYS_ATTR_1
SUBSYS_ATTR_2
***
SUBSYS_ATTR_N
Clear and simple. For dump, you repeat the header, I don't see why that is problem. All implementations are doing that, all userspace apps are used to it. It is simple and consistent even if you consider multiple skbs used for dump. I'm lacking to understand your need to reinvent the wheel here.
Quoted 115 lines
Quoted 4 lines
The reason might be that the userspace is parsing exactly the same message as if it would be DOIT message.
This argument is achievable on both approaches.
[...]
Quoted 97 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Hmm, shouldn't source-pin-index be here as well?
No, there is no set for this.
For manual mode user selects the pin by setting enabled state on theone
Quoted 81 lines
Quoted 71 lines
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
he needs to recover signal from.
source-pin-index is read only, returns active source.
Okay, got it. Then why do we have this assymetric approach? Just have the enabled state to serve the user to see which one is selected, no? This would help to avoid confusion (like mine) and allow not to create inconsistencies (like no pin enabled yet driver to return some source pin index)
Quoted 2 lines
This is due to automatic mode were multiple pins are enabled, but actual selection is done on hardware level with priorities.
Okay, this is confusing and I believe wrong.
You have dual meaning for pin state attribute with states STATE_CONNECTED/DISCONNECTED:1) Manual mode, MUX pins (both share the same model):
There is only one pin withSTATE_CONNECTED. The others are inSTATE_DISCONNECTED
User changes a state of a pin to make the selection.Example:
$ dplltool pin dump pin 1 state connected pin 2 state disconnected $ dplltool pin 2 set state connected $ dplltool pin dump pin 1 state disconnected pin 2 state connected2) Automatic mode:
The user by setting "state" decides it the pin should be considered by the device for auto selection.Example:
$ dplltool pin dump: pin 1 state connected prio 10 pin 2 state connected prio 15 $ dplltool dpll x get: dpll x source-pin-index 1So in manual mode,
STATE_CONNECTEDmeans the dpll is connected to this source pin. However, in automatic mode it means something else. It means the user allows this pin to be considered for auto selection. The fact the pin is selected source is exposed over source-pin-index.Instead of this, I believe that the semantics of STATE_CONNECTED/DISCONNECTED should be the same for automatic mode as well. Unlike the manual mode/mux, where the state is written by user, in automatic mode the state should be only written by the driver. User attemts to set the state should fail with graceful explanation (DPLL netlink/core code should handle that, w/o driver interaction)
Suggested automatic mode example:
$ dplltool pin dump: pin 1 state connected prio 10 connectable true pin 2 state disconnected prio 15 connectable true $ dplltool pin 1 set connectable false $ dplltool pin dump: pin 1 state disconnected prio 10 connectable false pin 2 state connected prio 15 connectable true $ dplltool pin 1 set state connected -EOPNOTSUPPNote there is no "source-pin-index" at all. Replaced by pin state here. There is a new attribute called "connectable", the user uses this attribute to tell the device, if this source pin could be considered for auto selection or not.
Quoted 6 lines
Could be called perhaps "selectable", does not matter. The point is, the meaning of the "state" attribute is consistent for automatic mode, manual mode and mux pin.
Makes sense?
Great idea!
I will add third enum for pin-state:DPLL_PIN_STATE_SELECTABLE. In the end we will have this:Quoted 9 lines
+--------------------------------+ | valid DPLL_A_PIN_STATE values | +---------------+----------------+ +------------+| requested: | returned: | |DPLL_A_MODE:|| | | |------------++--------------------------------| |AUTOMATIC ||- SELECTABLE | - SELECTABLE | | ||- DISCONNECTED | - DISCONNECTED | | || | - CONNECTED |Quoted 1 line
"selectable" is something the user sets.
Yes.
Quoted 3 lines
"connected"/"disconnected" is in case of auto mode something that driver sets.
Quoted 5 lines
No. Not really.
"CONNECTED" is only set by driver once a pin is choosen. "SELECTABLE" is set by the user if he needs to enable a pin for selection, it is also default state of a pin if it was not selected ("CONNECTED") "DISCONNECTED" is set by the user if he needs to disable a pin from selection.
Sure.
Quoted 7 lines
Quoted 5 lines
Looks a bit odd to mix them together. That is why I suggested to have sepectable as a separate attr. But up to you. Please make sure you sanitize the user/driver set of this attr in dpll code.
What is odd?
To mix them together in a single attr. But I'm fine with that.
Quoted 1 line
What do you mean by "sanitize the user/driver set of this attr in dpll code"?
What I mean is that in each mode there has to be clearly documented which entity changes state, how and under which circumstance. This behaviour needs to be enforced in the dpll code.
Quoted 63 lines
Thank you,
ArkadiuszQuoted 58 lines
Quoted 11 lines
|------------++--------------------------------| |MANUAL ||- CONNECTED | - CONNECTED | | ||- DISCONNECTED | - DISCONNECTED | +------------++---------------+----------------+Thank you,
ArkadiuszQuoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
[...]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ +/* DPLL_CMD_DEVICE_SET - do */ +static const struct nla_policydpll_device_set_nl_policy[DPLL_A_MODE +
Quoted 41 lines
Quoted 41 lines
Quoted 33 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines
1]
= {(quoted diff) +4
-0+ [DPLL_A_ID] = { .type = NLA_U32, }, + [DPLL_A_BUS_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_DEV_NAME] = { .type = NLA_NUL_STRING, }, + [DPLL_A_MODE] = NLA_POLICY_MAX(NLA_U8, 5),Hmm, any idea why the generator does not put define name here instead of "5"?
Quoted 4 lines
Quoted 1 line
Not really, it probably needs a fix for this.
Yeah.
Well, once we done with review maybe we could also fix those, or ask Jakub if he could help :)
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+ DPLL_A_PIN_PRIO, + DPLL_A_PIN_STATE, + DPLL_A_PIN_PARENT, + DPLL_A_PIN_PARENT_IDX, + DPLL_A_PIN_RCLK_DEVICE, + DPLL_A_PIN_DPLL_CAPS,Just
DPLL_A_PIN_CAPSis enough, that would be also consistent with the enum name.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sure, fixed.
Thanks for all your work on this!
Thanks for a great review! :)
Glad to help.
Jakub Kicinski
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Kubalewski, ArkadiuszQuoted 5 lines · Arkadiusz
Quoted 4 lines
Value 23? What's this?
You have it specified for some attrs all over the place. What is the reason for it?
Quoted 9 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better way to prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attribute there with value=0, thus there is a need to assign a proper value, same as it is on 'main' attribute list.
Are you saying the parser gets confused after returning from nested parsing? Can you still repro this problem? I don't see any global state in _decode()..
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jakub Kicinski
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 10 lines · On Mon, 20 Mar 2023 21:05:49 -0700 Jakub Kicinski wrote:
Quoted 9 lines
Actually this particular one is not needed (also value: 12 on pin above), I will remove those.
But the others you are refering to (the ones in nested attribute list), are required because ofcli.pyparser issue, maybe Kuba knows a better way to prevent the issue?
Basically, without those values,cli.pybrakes on parsing responses, after every "jump" to nested attribute list it is assigning first attribute there with value=0, thus there is a need to assign a proper value, same as it is on 'main' attribute list.
Quoted 3 lines
Are you saying the parser gets confused after returning from nested parsing? Can you still repro this problem? I don't see any global state in
_decode()..
Oh, I grokked the attr structure. This should be fixed now. Commit 7cf93538e087 ("tools: ynl: fully inherit attrs in subsets")
The entire attr structure is a bit off (/ inspired by devlink?) Why create one huge attribute space with all attributes in it? Try to find something in the devlink attrs, it's pages long with little to no reuse :| Can't pins and devices have their own spaces?
If one has to carry a link to the other you should create a subset so there is no circular dependency. That's the only potentially tricky thing I can think of...
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jakub Kicinski
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 3 lines · On Mon, 20 Mar 2023 21:13:54 -0700 Jakub Kicinski wrote:
If one has to carry a link to the other you should create a subset so there is no circular dependency. That's the only potentially tricky thing I can think of...
Another option is to take a page from ethtool's book and factor out identifiers to a nested attr from the start.
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Vadim FedorenkoQuoted 1 line · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
[...]
drivers/dpll/dpll_nl.c line 57
Quoted 2 lines
drivers/dpll/dpll_nl.c new file +2
-0+/* Ops table for dpll */ +static const struct genl_split_ops dpll_nl_ops[6 ] = {
It's odd to see 6 here. Should by just []
But it's an issue of Jakub's generator.
[...]
Jakub Kicinski
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 5 lines · On Fri, 17 Mar 2023 17:23:33 +0100 Jiri Pirko wrote:
drivers/dpll/dpll_nl.c line 57
Quoted 2 lines
drivers/dpll/dpll_nl.c new file +2
-0+/* Ops table for dpll */ +static const struct genl_split_ops dpll_nl_ops[6 ] = {It's odd to see 6 here. Should by just []
But it's an issue of Jakub's generator.
In some modes of generation the array is visible outside the source file i.e. there's a forward declaration in the header. So I had to get the counting right, anyway. But sure, I'll send a "fix"..
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Vadim FedorenkoQuoted 2 lines · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
[...]
Quoted 6 lines
Documentation/netlink/specs/dpll.yaml new file +6
-0+ name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dpll device + attribute-set: dpll + flags: [ admin-perm ] +
[...]
Documentation/netlink/specs/dpll.yaml line 463
Quoted 9 lines
Documentation/netlink/specs/dpll.yaml new file +9
-0+ - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pins in the system + - dump request with target dpll - list all the pins registered with a given dpll device + - do request with target dpll and target pin - single pin attributes + attribute-set: dpll + flags: [ admin-perm ]
Any particular reason to have admin cap required for get operations? If not, please remove.
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
Quoted 34 lines
From: Jiri Pirko <[email protected]>
Sent: Friday, March 17, 2023 5:54 PMQuoted 2 lines · Sun, Mar 12, 2023 at 03:28:02AM CET, [email protected] wrote:
From: Arkadiusz Kubalewski <[email protected]>
[...]
Quoted 7 lines
Documentation/netlink/specs/dpll.yaml new file +3
-0+ name: device-get + doc: | + Get list of DPLL devices (dump) or attributes of a single dplldevice
Documentation/netlink/specs/dpll.yaml new file +3
-0+ attribute-set: dpll + flags: [ admin-perm ] +[...]
Review
Quoted 12 lines
Documentation/netlink/specs/dpll.yaml new file +5
-0+ - + name: pin-get + doc: | + Get list of pins and its attributes. + - dump request without any attributes given - list all the pinsin the system
+ - dump request with target dpll - list all the pins registered
with a given dpll device
+ - do request with target dpll and target pin - single pin
attributes(quoted diff) +2
-0+ attribute-set: dpll + flags: [ admin-perm ]
Quoted 2 lines
Any particular reason to have admin cap required for get operations? If not, please remove.
Yes, security reasons, we don't want regular users to spam-query the driver ops. Also explained in docs:
All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent any spamming/D.o.S. from unauthorized userspace applications.
Thank you,
Arkadiusz
RFC PATCH v6 2/6 dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoDPLL framework is used to represent and configure DPLL devices in systems. Each device that has DPLL and can configure sources and outputs can use this framework. Netlink interface is used to provide configuration data and to receive notification messages about changes in the configuration or status of DPLL device. Inputs and outputs of the DPLL device are represented as special objects which could be dynamically added to and removed from DPLL device.
Changes:
dpll: adapt changes after introduction of dpll yaml spec
dpll: redesign after review comments, fix minor issues
dpll: add get pin command
dpll: _get/_put approach for creating and realesing pin or dpll objects
dpll: lock access to dplls with global lock
dpll: lock access to pins with global lock
dpll: replace cookie with clock id
dpll: add clock class
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
dpll: follow one naming schema in dpll subsys
dpll: fix dpll device naming scheme
Fix dpll device naming scheme by use of new pattern. "dpll_%s_%d_%d", where:
- %s - dev_name(parent) of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
dpll: remove description length parameter
dpll: fix muxed/shared pin registration
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in dpll_core, simplifing a dpll API.
dpll: move function comments to dpll_core.c, fix exports
dpll: remove single-use helper functions
dpll: merge device register with alloc
dpll: lock and unlock mutex on dpll device release
dpll: move dpll_type to uapi header
dpll: rename DPLLA_DUMP_FILTER to DPLLA_FILTER
dpll: rename dpll_pin_state to dpll_pin_mode
dpll: rename DPLL_MODE_FORCED to DPLL_MODE_MANUAL
dpll: remove DPLL_CHANGE_PIN_TYPE enum value
--- MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 +++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 99 ++++ drivers/dpll/dpll_netlink.c | 1065 +++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_netlink.h | 30 + include/linux/dpll.h | 284 ++++++++++ 10 files changed, 2342 insertions(+) create mode 100644 drivers/dpll/Kconfig create mode 100644 drivers/dpll/Makefile create mode 100644 drivers/dpll/dpll_core.c create mode 100644 drivers/dpll/dpll_core.h create mode 100644 drivers/dpll/dpll_netlink.c create mode 100644 drivers/dpll/dpll_netlink.h create mode 100644 include/linux/dpll.h
MAINTAINERS +9 -0
@@ -6289,6 +6289,15 @@ F: Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-drive F: drivers/net/ethernet/freescale/dpaa2/dpaa2-switch* F: drivers/net/ethernet/freescale/dpaa2/dpsw* +DPLL CLOCK SUBSYSTEM +M: Vadim Fedorenko <[email protected]> +M: Arkadiusz Kubalewski <[email protected]> +L: [email protected] +S: Maintained +F: drivers/dpll/* +F: include/net/dpll.h +F: include/uapi/linux/dpll.h + DRBD DRIVER M: Philipp Reisner <[email protected]> M: Lars Ellenberg <[email protected]>
drivers/Kconfig +2 -0
@@ -241,4 +241,6 @@ source "drivers/peci/Kconfig" source "drivers/hte/Kconfig" +source "drivers/dpll/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -194,3 +194,4 @@ obj-$(CONFIG_MOST) += most/ obj-$(CONFIG_PECI) += peci/ obj-$(CONFIG_HTE) += hte/ obj-$(CONFIG_DRM_ACCEL) += accel/ +obj-$(CONFIG_DPLL) += dpll/
drivers/dpll/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Generic DPLL drivers configuration +# + +config DPLL + bool
drivers/dpll/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.o +dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +
drivers/dpll/dpll_core.c new file +835 -0
835 lines not on this page · raw message
drivers/dpll/dpll_core.h new file +99 -0
99 lines not on this page · raw message
drivers/dpll/dpll_netlink.c new file +1065 -0
1,065 lines not on this page · raw message
drivers/dpll/dpll_netlink.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +*/ + +/** +* dpll_notify_device_create - notify that the device has been created +* @dpll: registered dpll pointer +* +* Return: 0 if succeeds, error code otherwise. +*/ +int dpll_notify_device_create (struct dpll_device *dpll); + + +/** +* dpll_notify_device_delete - notify that the device has been deleted +* @dpll: registered dpll pointer +* +* Return: 0 if succeeds, error code otherwise. +*/ +int dpll_notify_device_delete (struct dpll_device *dpll); + +int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, +enum dplla attr); + +int dpll_pin_parent_notify (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin *parent,enum dplla attr); + +int __init dpll_netlink_init (void ); +void dpll_netlink_finish (void );
include/linux/dpll.h new file +284 -0
284 lines not on this page · raw message
Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 17 lines · Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
DPLL framework is used to represent and configure DPLL devices in systems. Each device that has DPLL and can configure sources and outputs can use this framework. Netlink interface is used to provide configuration data and to receive notification messages about changes in the configuration or status of DPLL device. Inputs and outputs of the DPLL device are represented as special objects which could be dynamically added to and removed from DPLL device.
Changes:
dpll: adapt changes after introduction of dpll yaml spec
dpll: redesign after review comments, fix minor issues
dpll: add get pin command
dpll: _get/_put approach for creating and realesing pin or dpll objects
dpll: lock access to dplls with global lock
dpll: lock access to pins with global lock
Quoted 2 lines
dpll: replace cookie with clock id
dpll: add clock class
Looks like some leftover in patch description.
Quoted 24 lines
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.dpll: follow one naming schema in dpll subsys
dpll: fix dpll device naming scheme
Fix dpll device naming scheme by use of new pattern. "dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.dpll: remove description length parameter
dpll: fix muxed/shared pin registration
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in
dpll_core, simplifing a dpll API.
Quoted 9 lines
dpll: move function comments to
dpll_core.c, fix exports
dpll: remove single-use helper functions
dpll: merge device register with alloc
dpll: lock and unlock mutex on dpll device release
dpll: movedpll_typeto uapi header
dpll: renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
dpll: renamedpll_pin_statetodpll_pin_mode
dpll: renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
dpll: removeDPLL_CHANGE_PIN_TYPEenum value
I'm confused, some messed-up squash?
Quoted 87 lines
Co-developed-by Milena Olech <[email protected]>Signed-off-by Milena Olech <[email protected]>Co-developed-by Michal Michalik <[email protected]>Signed-off-by Michal Michalik <[email protected]>Co-developed-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Vadim Fedorenko <[email protected]>---
MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 +++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 99 ++++ drivers/dpll/dpll_netlink.c | 1065 +++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_netlink.h | 30 + include/linux/dpll.h | 284 ++++++++++ 10 files changed, 2342 insertions(+)create mode 100644
drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.c
create mode 100644drivers/dpll/dpll_netlink.h
create mode 100644include/linux/dpll.hMAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F: Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-driveF:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*MAINTAINERS +9
-0+DPLL CLOCK SUBSYSTEM +M: Vadim Fedorenko <[email protected]> +M: Arkadiusz Kubalewski <[email protected]> +L: [email protected] +S: Maintained +F: drivers/dpll/* +F: include/net/dpll.h +F: include/uapi/linux/dpll.h +DRBD DRIVER
M: Philipp Reisner <[email protected]>
M: Lars Ellenberg <[email protected]>drivers/Kconfig +0
-0@@ -241,4 +241,6 @@ source "drivers/peci/Kconfig"source "
drivers/hte/Kconfig"drivers/Kconfig +2
-0+source "drivers/dpll/Kconfig" +endmenu
drivers/Makefile +0
-0@@ -194,3 +194,4 @@ obj-$(CONFIG_MOST) += most/obj-$(CONFIG_PECI) += peci/
obj-$(CONFIG_HTE) += hte/
obj-$(CONFIG_DRM_ACCEL) += accel/drivers/Makefile +1
-0+obj-$(CONFIG_DPLL) += dpll/drivers/dpll/Kconfig new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Generic DPLL drivers configuration +# + +config DPLL + booldrivers/dpll/Makefile new file +0
-0
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.o
What's "sys" and why is it here?
Quoted 10 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +drivers/dpll/dpll_core.c new file +0
-0
drivers/dpll/dpll_core.c line 5
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. +* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates
IIUC, there's a lot of Intel work behind this, I think some credits should go here as well.
Also, it is 2023, you live in the past :)
Quoted 30 lines
drivers/dpll/dpll_core.c new file +30
-0+*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/device.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/string.h> + +#include "dpll_core.h" + +DEFINE_MUTEX (dpll_device_xa_lock); +DEFINE_MUTEX (dpll_pin_xa_lock); + +DEFINE_XARRAY_FLAGS (dpll_device_xa,XA_FLAGS_ALLOC ); +DEFINE_XARRAY_FLAGS (dpll_pin_xa,XA_FLAGS_ALLOC ); + +#define ASSERT_DPLL_REGISTERED (d) \ + WARN_ON_ONCE(!xa_get_mark(&dpll_device_xa, (d)->id, DPLL_REGISTERED)) +#define ASSERT_DPLL_NOT_REGISTERED (d) \ + WARN_ON_ONCE(xa_get_mark(&dpll_device_xa, (d)->id, DPLL_REGISTERED)) + +static struct class dpll_class = { + .name ="dpll" , +}; + +/** +* dpll_device_get_by_id - find dpll device by it's id +* @id: id of searched dpll +*
drivers/dpll/dpll_core.c line 45
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* Return: +* * dpll_device struct if found +* * NULL otherwise +*/ +struct dpll_device *dpll_device_get_by_id (int id) +{ +struct dpll_device *dpll =NULL ; + +if (xa_get_mark (&dpll_device_xa, id,DPLL_REGISTERED )) + dpll =xa_load (&dpll_device_xa, id);
return xa_load
drivers/dpll/dpll_core.c line 46
Quoted 1 line
drivers/dpll/dpll_core.c new file +1
-0+
return NULL
drivers/dpll/dpll_core.c line 47
Quoted 1 line
drivers/dpll/dpll_core.c new file +1
-0+return dpll;
Anyway, I believe this fuction should go away, see below.
Quoted 38 lines
drivers/dpll/dpll_core.c new file +38
-0+} + +/** +* dpll_device_get_by_name - find dpll device by it's id +* @bus_name: bus name of searched dpll +* @dev_name: dev name of searched dpll +* +* Return: +* * dpll_device struct if found +* * NULL otherwise +*/ +struct dpll_device * +dpll_device_get_by_name (const char *bus_name,const char *device_name) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index; + +xa_for_each_marked (&dpll_device_xa, index, dpll,DPLL_REGISTERED ) { +if (!strcmp (dev_bus_name (&dpll->dev), bus_name) && + !strcmp (dev_name (&dpll->dev), device_name)) { + ret = dpll; +break ; + } + } + +return ret; +} + +/** +* dpll_xa_ref_pin_add - add pin reference to a given xarray +* @xa_pins: dpll_pin_ref xarray holding pins +* @pin: pin being added +* @ops: ops for a pin +* @priv: pointer to private data of owner +* +* Allocate and create reference of a pin or increase refcount on existing pin +* reference on given xarray. +*
drivers/dpll/dpll_core.c line 95
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* Return: +* * 0 on success +* * -ENOMEM on failed allocation +*/ +static int +dpll_xa_ref_pin_add (struct xarray *xa_pins,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv) +{ +struct dpll_pin_ref *ref; +unsigned long i;
In previous function you use "index" name for the same variable. Be consistent. I think "i" is actually better.
Quoted 180 lines
drivers/dpll/dpll_core.c new file +180
-0+u32 idx; +int ret; + +xa_for_each (xa_pins, i, ref) { +if (ref->pin == pin) { +refcount_inc (&ref->refcount); +return 0 ; + } + } + + ref =kzalloc (sizeof (*ref),GFP_KERNEL ); +if (!ref) +return -ENOMEM ; + ref->pin = pin; + ref->ops = ops; + ref->priv = priv; + ret =xa_alloc (xa_pins, &idx, ref, xa_limit_16b,GFP_KERNEL ); +if (!ret) +refcount_set (&ref->refcount,1 ); +else +kfree (ref); + +return ret; +} + +/** +* dpll_xa_ref_pin_del - remove reference of a pin from xarray +* @xa_pins: dpll_pin_ref xarray holding pins +* @pin: pointer to a pin +* +* Decrement refcount of existing pin reference on given xarray. +* If all references are dropped, delete the reference and free its memory. +* +* Return: +* * 0 on success +* * -EINVAL if reference to a pin was not found +*/ +static int dpll_xa_ref_pin_del (struct xarray *xa_pins,struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_pins, i, ref) { +if (ref->pin == pin) { +if (refcount_dec_and_test (&ref->refcount)) { +xa_erase (xa_pins, i); +kfree (ref); + } +return 0 ; + } + } + +return -EINVAL ; +} + +/** +* dpll_xa_ref_pin_find - find pin reference on xarray +* @xa_pins: dpll_pin_ref xarray holding pins +* @pin: pointer to a pin +* +* Search for pin reference struct of a given pin on given xarray. +* +* Return: +* * pin reference struct pointer on success +* * NULL - reference to a pin was not found +*/ +struct dpll_pin_ref * +dpll_xa_ref_pin_find (struct xarray *xa_pins,const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_pins, i, ref) { +if (ref->pin == pin) +return ref; + } + +return NULL ; +} + +/** +* dpll_xa_ref_dpll_add - add dpll reference to a given xarray +* @xa_dplls: dpll_pin_ref xarray holding dplls +* @dpll: dpll being added +* @ops: pin-reference ops for a dpll +* @priv: pointer to private data of owner +* +* Allocate and create reference of a dpll-pin ops or increase refcount +* on existing dpll reference on given xarray. +* +* Return: +* * 0 on success +* * -ENOMEM on failed allocation +*/ +static int +dpll_xa_ref_dpll_add (struct xarray *xa_dplls,struct dpll_device *dpll, +struct dpll_pin_ops *ops,void *priv) +{ +struct dpll_pin_ref *ref; +unsigned long i; +u32 idx; +int ret; + +xa_for_each (xa_dplls, i, ref) { +if (ref->dpll == dpll) { +refcount_inc (&ref->refcount); +return 0 ; + } + } + ref =kzalloc (sizeof (*ref),GFP_KERNEL ); +if (!ref) +return -ENOMEM ; + ref->dpll = dpll; + ref->ops = ops; + ref->priv = priv; + ret =xa_alloc (xa_dplls, &idx, ref, xa_limit_16b,GFP_KERNEL ); +if (!ret) +refcount_set (&ref->refcount,1 ); +else +kfree (ref); + +return ret; +} + +/** +* dpll_xa_ref_dpll_del - remove reference of a dpll from xarray +* @xa_dplls: dpll_pin_ref xarray holding dplls +* @dpll: pointer to a dpll to remove +* +* Decrement refcount of existing dpll reference on given xarray. +* If all references are dropped, delete the reference and free its memory. +*/ +static void +dpll_xa_ref_dpll_del (struct xarray *xa_dplls,struct dpll_device *dpll) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_dplls, i, ref) { +if (ref->dpll == dpll) { +if (refcount_dec_and_test (&ref->refcount)) { +xa_erase (xa_dplls, i); +kfree (ref); + } +break ; + } + } +} + +/** +* dpll_xa_ref_dpll_find - find dpll reference on xarray +* @xa_dplls: dpll_pin_ref xarray holding dplls +* @dpll: pointer to a dpll +* +* Search for dpll-pin ops reference struct of a given dpll on given xarray. +* +* Return: +* * pin reference struct pointer on success +* * NULL - reference to a pin was not found +*/ +struct dpll_pin_ref * +dpll_xa_ref_dpll_find (struct xarray *xa_refs,const struct dpll_device *dpll) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +xa_for_each (xa_refs, i, ref) { +if (ref->dpll == dpll) +return ref; + } + +return NULL ; +} + + +/** +* dpll_device_alloc - allocate the memory for dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module
drivers/dpll/dpll_core.c line 285
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Allocates memory and initialize dpll device, hold its reference on global +* xarray. +* +* Return: +* * dpll_device struct pointer if succeeded +* * ERR_PTR(X) - failed allocation +*/ +struct dpll_device * +dpll_device_alloc (const u64 clock_id,u32 dev_driver_id,struct module *module)
This should be static. Didn't you get warn?
Quoted 36 lines
drivers/dpll/dpll_core.c new file +36
-0+{ +struct dpll_device *dpll; +int ret; + + dpll =kzalloc (sizeof (*dpll),GFP_KERNEL ); +if (!dpll) +return ERR_PTR (-ENOMEM ); +refcount_set (&dpll->refcount,1 ); + dpll->dev.class = &dpll_class; + dpll->dev_driver_id = dev_driver_id; + dpll->clock_id = clock_id; + dpll->module = module; + ret =xa_alloc (&dpll_device_xa, &dpll->id, dpll, + xa_limit_16b,GFP_KERNEL ); +if (ret) { +kfree (dpll); +return ERR_PTR (ret); + } +xa_init_flags (&dpll->pin_refs,XA_FLAGS_ALLOC ); + +return dpll; +} + +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/
drivers/dpll/dpll_core.c line 331
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&
Why you need "dev_driver_id"? clock_id is here for the purpose of identification, isn't that enough for you.
Plus, the name is odd. "dev_driver" should certainly be avoided.
Quoted 15 lines
drivers/dpll/dpll_core.c new file +15
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/**
drivers/dpll/dpll_core.c line 356
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete +* dpll device object. +*/ +void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;
Remove this check. The driver should not call this with NULL.
drivers/dpll/dpll_core.c line 359
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);
drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);
This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2
I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename dev_name() with anything.
Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56
If you really need the "dev_driver_id" (as I believe clock_id should be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master".
Quoted 26 lines
drivers/dpll/dpll_core.c new file +26
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); +
drivers/dpll/dpll_core.c line 436
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Return: +* * valid allocated dpll_pin struct pointer if succeeded +* * ERR_PTR of an error
Extra "*"'s
drivers/dpll/dpll_core.c line 439
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+*/ +struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
Odd whitespace.
Also, func should be static.
drivers/dpll/dpll_core.c line 448
Quoted 9 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;
Name inconsistency: driver/drv
you have it on multiple places
Quoted 12 lines
drivers/dpll/dpll_core.c new file +12
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + }
drivers/dpll/dpll_core.c line 470
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + } + pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;
Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 20 lines
drivers/dpll/dpll_core.c new file +20
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator
drivers/dpll/dpll_core.c line 500
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new +* if doesn't exist yet. +* +* Return: +* * valid allocated dpll_pin struct pointer if succeeded +* * ERR_PTR of an error
This is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
drivers/dpll/dpll_core.c line 503
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+*/ +struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,
Again, why do you need this device_drv_id? Clock id should be enough.
drivers/dpll/dpll_core.c line 513
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {
Compare prop as well.
Can't the driver_id (pin index) be something const as well? I think it should. And therefore it could be easily put inside.
Quoted 73 lines
drivers/dpll/dpll_core.c new file +73
-0+ ret = pos; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_pin_alloc (clock_id, device_drv_id, module, prop); +mutex_unlock (&dpll_pin_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_get); + +/** +* dpll_pin_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a pin, if all references are gone, delete pin object. +*/ +void dpll_pin_put (struct dpll_pin *pin) +{ +if (!pin) +return ; +mutex_lock (&dpll_pin_xa_lock); +if (refcount_dec_and_test (&pin->refcount)) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +xa_erase (&dpll_pin_xa, pin->idx); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); + } +mutex_unlock (&dpll_pin_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_pin_put); + +static int +__dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +const char *rclk_device_name) +{ +int ret; + +if (rclk_device_name && !pin->rclk_dev_name) { + pin->rclk_dev_name =kstrdup (rclk_device_name,GFP_KERNEL ); +if (!pin->rclk_dev_name) +return -ENOMEM ; + } + ret =dpll_xa_ref_pin_add (&dpll->pin_refs, pin, ops, priv); +if (ret) + goto rclk_free; + ret =dpll_xa_ref_dpll_add (&pin->dpll_refs, dpll, ops, priv); +if (ret) + goto ref_pin_del; +else +dpll_pin_notify (dpll, pin,DPLL_A_PIN_IDX ); + +return ret; + +ref_pin_del: +dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +rclk_free: +kfree (pin->rclk_dev_name); +return ret; +} + +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device
drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)
Wait a second, what is this "struct device *"? Looks very odd.
drivers/dpll/dpll_core.c line 598
Quoted 2 lines
drivers/dpll/dpll_core.c new file +2
-0+{ +const char *rclk_name = rclk_device ?dev_name (rclk_device) :NULL ;
If you need to store something here, store the pointer to the device directly. But this rclk_device seems odd to me.Dev_name is in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
drivers/dpll/dpll_core.c line 604
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+int ret; + +if (WARN_ON (!dpll)) +return -EINVAL ; +if (WARN_ON (!pin)) +return -EINVAL ;
Remove these checks and other similar checks in the code. It should rely on basic driver sanity.
Quoted 60 lines
drivers/dpll/dpll_core.c new file +60
-0+ +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); + ret =__dpll_pin_register (dpll, pin, ops, priv, rclk_name); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_register); + +static void +__dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +{ +dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +dpll_xa_ref_dpll_del (&pin->dpll_refs, dpll); +} + +/** +* dpll_pin_unregister - deregister dpll pin from dpll device +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +{ +if (WARN_ON (xa_empty (&dpll->pin_refs))) +return -ENOENT ; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +__dpll_pin_unregister (dpll, pin); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_pin_unregister); + +/** +* dpll_pin_on_pin_register - register a pin with a parent pin +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* @ops: ops for a dpll pin +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device +* +* Register a pin with a parent pin, create references between them and +* between newly registered pin and dplls connected with a parent pin. +* +* Return: +* * 0 on success +* * -EINVAL missing pin or parent +* * -ENOMEM failed allocation +* * -EPERM if parent is not allowed +*/ +int +dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv,
drivers/dpll/dpll_core.c line 674
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ struct device *rclk_device) +{ +struct dpll_pin_ref *ref; +unsigned long i, stop; +int ret; + +if (WARN_ON (!pin || !parent)) +return -EINVAL ; +if (WARN_ON (parent->prop.type !=DPLL_PIN_TYPE_MUX )) +return -EPERM ;
I don't think that EPERM is suitable for this. Just use EINVAL. The driver is buggy in this case anyway.
Quoted 71 lines
drivers/dpll/dpll_core.c new file +71
-0+mutex_lock (&dpll_pin_xa_lock); + ret =dpll_xa_ref_pin_add (&pin->parent_refs, parent, ops, priv); +if (ret) + goto unlock; +refcount_inc (&pin->refcount); +xa_for_each (&parent->dpll_refs, i, ref) { +mutex_lock (&dpll_device_xa_lock); + ret =__dpll_pin_register (ref->dpll, pin, ops, priv, + rclk_device ? +dev_name (rclk_device) :NULL ); +mutex_unlock (&dpll_device_xa_lock); +if (ret) { + stop = i; + goto dpll_unregister; + } +dpll_pin_parent_notify (ref->dpll, pin, parent,DPLL_A_PIN_IDX ); + } +mutex_unlock (&dpll_pin_xa_lock); + +return ret; + +dpll_unregister: +xa_for_each (&parent->dpll_refs, i, ref) { +if (i < stop) { +mutex_lock (&dpll_device_xa_lock); +__dpll_pin_unregister (ref->dpll, pin); +mutex_unlock (&dpll_device_xa_lock); + } + } +refcount_dec (&pin->refcount); +dpll_xa_ref_pin_del (&pin->parent_refs, parent); +unlock: +mutex_unlock (&dpll_pin_xa_lock); +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_register); + +/** +* dpll_pin_on_pin_unregister - deregister dpll pin from a parent pin +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +dpll_xa_ref_pin_del (&pin->parent_refs, parent); +refcount_dec (&pin->refcount); +xa_for_each (&pin->dpll_refs, i, ref) { +__dpll_pin_unregister (ref->dpll, pin); +dpll_pin_parent_notify (ref->dpll, pin, parent, +DPLL_A_PIN_IDX ); + } +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_unregister); + +/** +* dpll_pin_get_by_idx - find a pin ref on dpll by pin index +* @dpll: dpll device pointer +* @idx: index of pin +* +* Find a reference to a pin registered with given dpll and return its pointer. +* +* Return:
drivers/dpll/dpll_core.c line 755
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* * valid pointer if pin was found +* * NULL if not found +*/ +struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)
How exactly pos->pin could be NULL?
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 16 lines
drivers/dpll/dpll_core.c new file +16
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +}
drivers/dpll/dpll_core.c line 781
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Return: pointer to the data +*/ +void *dpll_pin_on_dpll_priv(const struct dpll_device *dpll,
IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
drivers/dpll/dpll_core.c line 786
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);
Why cast is needed here? You have this on multiple places.
Quoted 26 lines
drivers/dpll/dpll_core.c new file +26
-0+if (!ref) +return NULL ; + +return ref->priv; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_dpll_priv); + +/** +* dpll_pin_on_pin_priv - get the dpll pin private owner data +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* +* Return: pointer to the data +*/ +void *dpll_pin_on_pin_priv (const struct dpll_pin *parent, +const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&pin->parent_refs, parent); +if (!ref) +return NULL ; + +return ref->priv; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_priv);
drivers/dpll/dpll_core.c line 822
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ +static int __init dpll_init (void ) +{ +int ret; + + ret =dpll_netlink_init (); +if (ret) + goto error; + + ret =class_register (&dpll_class);
Why exactly do you need this? I asked to remove this previously, IIRC you said you would check if this needed. Why?
Quoted 71 lines
drivers/dpll/dpll_core.c new file +13
-0+if (ret) + goto unregister_netlink; + +return 0 ; + +unregister_netlink: +dpll_netlink_finish (); +error: +mutex_destroy (&dpll_device_xa_lock); +mutex_destroy (&dpll_pin_xa_lock); +return ret; +} +subsys_initcall (dpll_init);drivers/dpll/dpll_core.h new file +52
-0@@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +*/ + +#ifndef __DPLL_CORE_H__ +#define __DPLL_CORE_H__ + +#include <linux/dpll.h> +#include <linux/refcount.h> +#include "dpll_netlink.h" + +#define DPLL_REGISTERED XA_MARK_1 + +/** +* struct dpll_device - structure for a DPLL device +* @id: unique id number for each device +* @dev_driver_id: id given by dev driver +* @dev: struct device for this dpll device +* @parent: parent device +* @module: module of creator +* @ops: operations this &dpll_device supports +* @lock: mutex to serialize operations +* @type: type of a dpll +* @priv: pointer to private information of owner +* @pins: list of pointers to pins registered with this dpll +* @clock_id: unique identifier (clock_id) of a dpll +* @mode_supported_mask: mask of supported modes +* @refcount: refcount +**/ +struct dpll_device { +u32 id; +u32 dev_driver_id; +struct device dev; +struct device *parent; +struct module *module; +struct dpll_device_ops *ops; +enum dpll_type type; +void *priv; +struct xarray pin_refs; +u64 clock_id; +unsigned long mode_supported_mask; +refcount_t refcount; +}; + +/** +* struct dpll_pin - structure for a dpll pin +* @idx: unique idx given by alloc on global pin's XA +* @dev_driver_id: id given by dev driver +* @clock_id: clock_id of creator +* @module: module of creator +* @dpll_refs: hold referencees to dplls that pin is registered with
drivers/dpll/dpll_core.h line 62
Quoted 10 lines
drivers/dpll/dpll_core.h new file +10
-0+* @pin_refs: hold references to pins that pin is registered with +* @prop: properties given by registerer +* @rclk_dev_name: holds name of device when pin can recover clock from it +* @refcount: refcount +**/ +struct dpll_pin { +u32 idx; +u32 dev_driver_id; +u64 clock_id; +struct module *module;
Have the ordering of common fields, like clock_id and module consistent with struct dpll_device
Quoted 56 lines
drivers/dpll/dpll_core.h new file +37
-0+struct xarray dpll_refs; +struct xarray parent_refs; +struct dpll_pin_properties prop; +char *rclk_dev_name; +refcount_t refcount; +}; + +/** +* struct dpll_pin_ref - structure for referencing either dpll or pins +* @dpll: pointer to a dpll +* @pin: pointer to a pin +* @ops: ops for a dpll pin +* @priv: pointer to private information of owner +**/ +struct dpll_pin_ref { +union { +struct dpll_device *dpll; +struct dpll_pin *pin; + }; +struct dpll_pin_ops *ops; +void *priv; +refcount_t refcount; +}; + +struct dpll_device *dpll_device_get_by_id (int id); +struct dpll_device *dpll_device_get_by_name (const char *bus_name, +const char *dev_name); +struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx); +struct dpll_pin_ref * +dpll_xa_ref_pin_find (struct xarray *xa_refs,const struct dpll_pin *pin); +struct dpll_pin_ref * +dpll_xa_ref_dpll_find (struct xarray *xa_refs,const struct dpll_device *dpll); +extern struct xarray dpll_device_xa; +extern struct xarray dpll_pin_xa; +extern struct mutex dpll_device_xa_lock; +extern struct mutex dpll_pin_xa_lock; +#endif drivers/dpll/dpll_netlink.c new file +13
-0@@ -0,0 +1,1065 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Generic netlink for DPLL management framework +* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +* +*/ +#include <linux/module.h> +#include <linux/kernel.h> +#include <net/genetlink.h> +#include "dpll_core.h" +#include "dpll_nl.h" +#include <uapi/linux/dpll.h>
drivers/dpll/dpll_netlink.c line 23
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ +static u32 dpll_pin_freq_value[] = { + [DPLL_PIN_FREQ_SUPP_1_HZ ] =DPLL_PIN_FREQ_1_HZ , + [DPLL_PIN_FREQ_SUPP_10_MHZ ] =DPLL_PIN_FREQ_10_MHZ , +}; + +static int +dpll_msg_add_dev_handle (struct sk_buff *msg,const struct dpll_device *dpll) +{ +if (nla_put_u32 (msg,DPLL_A_ID , dpll->id))
1,407 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 18 lines · Jiri Pirko
Quoted 17 lines · Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
DPLL framework is used to represent and configure DPLL devices in systems. Each device that has DPLL and can configure sources and outputs can use this framework. Netlink interface is used to provide configuration data and to receive notification messages about changes in the configuration or status of DPLL device. Inputs and outputs of the DPLL device are represented as special objects which could be dynamically added to and removed from DPLL device.
Changes:
dpll: adapt changes after introduction of dpll yaml spec
dpll: redesign after review comments, fix minor issues
dpll: add get pin command
dpll: _get/_put approach for creating and realesing pin or dpll objects
dpll: lock access to dplls with global lock
dpll: lock access to pins with global lock
Quoted 4 lines
Quoted 2 lines
dpll: replace cookie with clock id
dpll: add clock classLooks like some leftover in patch description.
Yeah, it's a changelog from the previous iteration.
Quoted 34 lines
Quoted 24 lines
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.dpll: follow one naming schema in dpll subsys
dpll: fix dpll device naming scheme
Fix dpll device naming scheme by use of new pattern. "dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.dpll: remove description length parameter
dpll: fix muxed/shared pin registration
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in
dpll_core, simplifing a dpll API.Quoted 9 lines
dpll: move function comments to
dpll_core.c, fix exports
dpll: remove single-use helper functions
dpll: merge device register with alloc
dpll: lock and unlock mutex on dpll device release
dpll: movedpll_typeto uapi header
dpll: renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
dpll: renamedpll_pin_statetodpll_pin_mode
dpll: renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
dpll: removeDPLL_CHANGE_PIN_TYPEenum value
Quoted 1 line
I'm confused, some messed-up squash?
Yep, from previous iteration. I'll remove it next time.
Quoted 86 lines
Quoted 86 lines
Co-developed-by Milena Olech <[email protected]>Signed-off-by Milena Olech <[email protected]>Co-developed-by Michal Michalik <[email protected]>Signed-off-by Michal Michalik <[email protected]>Co-developed-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>Signed-off-by Vadim Fedorenko <[email protected]>---
MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 +++++++++++++++++++++++++++ drivers/dpll/dpll_core.h | 99 ++++ drivers/dpll/dpll_netlink.c | 1065 +++++++++++++++++++++++++++++++++++ drivers/dpll/dpll_netlink.h | 30 + include/linux/dpll.h | 284 ++++++++++ 10 files changed, 2342 insertions(+)create mode 100644
drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.c
create mode 100644drivers/dpll/dpll_netlink.h
create mode 100644include/linux/dpll.hMAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F: Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-driveF:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*MAINTAINERS +9
-0+DPLL CLOCK SUBSYSTEM +M: Vadim Fedorenko <[email protected]> +M: Arkadiusz Kubalewski <[email protected]> +L: [email protected] +S: Maintained +F: drivers/dpll/* +F: include/net/dpll.h +F: include/uapi/linux/dpll.h +DRBD DRIVER
M: Philipp Reisner <[email protected]>
M: Lars Ellenberg <[email protected]>drivers/Kconfig +0
-0@@ -241,4 +241,6 @@ source "drivers/peci/Kconfig"source "
drivers/hte/Kconfig"drivers/Kconfig +2
-0+source "drivers/dpll/Kconfig" +endmenu
drivers/Makefile +0
-0@@ -194,3 +194,4 @@ obj-$(CONFIG_MOST) += most/obj-$(CONFIG_PECI) += peci/
obj-$(CONFIG_HTE) += hte/
obj-$(CONFIG_DRM_ACCEL) += accel/drivers/Makefile +1
-0+obj-$(CONFIG_DPLL) += dpll/drivers/dpll/Kconfig new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Generic DPLL drivers configuration +# + +config DPLL + booldrivers/dpll/Makefile new file +0
-0@@ -0,0 +1,10 @@
Quoted 8 lines
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.oWhat's "sys" and why is it here?
It's an object file for the subsystem. Could be useful if we will have drivers for DPLL-only devices.
Quoted 19 lines
Quoted 10 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +drivers/dpll/dpll_core.c new file +0
-0drivers/dpll/dpll_core.c line 5
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. +* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates IIUC, there's a lot of Intel work behind this, I think some credits should go here as well.
Quoted 1 line
Also, it is 2023, you live in the past :)
Yeah, that's true. Have to improve it. As well as in other files.
Quoted 42 lines
Quoted 30 lines
drivers/dpll/dpll_core.c new file +30
-0+*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/device.h> +#include <linux/err.h> +#include <linux/slab.h> +#include <linux/string.h> + +#include "dpll_core.h" + +DEFINE_MUTEX (dpll_device_xa_lock); +DEFINE_MUTEX (dpll_pin_xa_lock); + +DEFINE_XARRAY_FLAGS (dpll_device_xa,XA_FLAGS_ALLOC ); +DEFINE_XARRAY_FLAGS (dpll_pin_xa,XA_FLAGS_ALLOC ); + +#define ASSERT_DPLL_REGISTERED (d) \ + WARN_ON_ONCE(!xa_get_mark(&dpll_device_xa, (d)->id, DPLL_REGISTERED)) +#define ASSERT_DPLL_NOT_REGISTERED (d) \ + WARN_ON_ONCE(xa_get_mark(&dpll_device_xa, (d)->id, DPLL_REGISTERED)) + +static struct class dpll_class = { + .name ="dpll" , +}; + +/** +* dpll_device_get_by_id - find dpll device by it's id +* @id: id of searched dpll +* drivers/dpll/dpll_core.c line 45
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* Return: +* * dpll_device struct if found +* * NULL otherwise +*/ +struct dpll_device *dpll_device_get_by_id (int id) +{ +struct dpll_device *dpll =NULL ; + +if (xa_get_mark (&dpll_device_xa, id,DPLL_REGISTERED )) + dpll =xa_load (&dpll_device_xa, id);return
xa_load
Quoted 6 lines
drivers/dpll/dpll_core.c line 46
Quoted 1 line
drivers/dpll/dpll_core.c new file +1
-0+return NULL
drivers/dpll/dpll_core.c line 47
Quoted 1 line
drivers/dpll/dpll_core.c new file +1
-0+return dpll;Anyway, I believe this fuction should go away, see below.
Don't think it matters, but happy to remove the function.
Quoted 43 lines
Quoted 43 lines
drivers/dpll/dpll_core.c new file +43
-0+} + +/** +* dpll_device_get_by_name - find dpll device by it's id +* @bus_name: bus name of searched dpll +* @dev_name: dev name of searched dpll +* +* Return: +* * dpll_device struct if found +* * NULL otherwise +*/ +struct dpll_device * +dpll_device_get_by_name (const char *bus_name,const char *device_name) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index; + +xa_for_each_marked (&dpll_device_xa, index, dpll,DPLL_REGISTERED ) { +if (!strcmp (dev_bus_name (&dpll->dev), bus_name) && + !strcmp (dev_name (&dpll->dev), device_name)) { + ret = dpll; +break ; + } + } + +return ret; +} + +/** +* dpll_xa_ref_pin_add - add pin reference to a given xarray +* @xa_pins: dpll_pin_ref xarray holding pins +* @pin: pin being added +* @ops: ops for a pin +* @priv: pointer to private data of owner +* +* Allocate and create reference of a pin or increase refcount on existing pin +* reference on given xarray. +* +* Return: +* * 0 on success +* * -ENOMEM on failed allocation +*/ +static int
Quoted 9 lines
drivers/dpll/dpll_core.c line 95
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+dpll_xa_ref_pin_add(struct xarray *xa_pins, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv) +{ + struct dpll_pin_ref *ref; +unsigned long i;In previous function you use "index" name for the same variable. Be consistent. I think "i" is actually better.
Yep, agree.
Quoted 38 lines
Quoted 38 lines
drivers/dpll/dpll_core.c new file +37
-0+u32 idx; +int ret; + +xa_for_each (xa_pins, i, ref) { +if (ref->pin == pin) { +refcount_inc (&ref->refcount); +return 0 ; + } + } + + ref =kzalloc (sizeof (*ref),GFP_KERNEL ); +if (!ref) +return -ENOMEM ; + ref->pin = pin; + ref->ops = ops; + ref->priv = priv; + ret =xa_alloc (xa_pins, &idx, ref, xa_limit_16b,GFP_KERNEL ); +if (!ret) +refcount_set (&ref->refcount,1 ); +else +kfree (ref); + +return ret; +} + +/** +* dpll_xa_ref_pin_del - remove reference of a pin from xarray +* @xa_pins: dpll_pin_ref xarray holding pins +* @pin: pointer to a pin +* +* Decrement refcount of existing pin reference on given xarray. +* If all references are dropped, delete the reference and free its memory. +* +* Return: +* * 0 on success +* * -EINVAL if reference to a pin was not found +*/
[...]
Quoted 9 lines
Quoted 9 lines
+/**
+ *dpll_device_alloc- allocate the memory for dpll device
+ * @clock_id:clock_idof creator
+ * @dev_driver_id: id given by dev driver
+ * @module: reference to registering module
+ *
+ * Allocates memory and initialize dpll device, hold its reference on global
+ * xarray.
+ *
Quoted 8 lines
drivers/dpll/dpll_core.c line 285
Quoted 6 lines
+ * Return:
+ * *dpll_devicestruct pointer if succeeded
+ * *ERR_PTR(X)- failed allocation
+ */drivers/dpll/dpll_core.c new file +2
-0+struct dpll_device * +dpll_device_alloc (const u64 clock_id,u32 dev_driver_id,struct module *module)This should be static. Didn't you get warn?
I did get an email from kernel test robot. I'll make it static. As well as dpll_pin_alloc()
Quoted 41 lines
Quoted 41 lines
drivers/dpll/dpll_core.c new file +41
-0+{ +struct dpll_device *dpll; +int ret; + + dpll =kzalloc (sizeof (*dpll),GFP_KERNEL ); +if (!dpll) +return ERR_PTR (-ENOMEM ); +refcount_set (&dpll->refcount,1 ); + dpll->dev.class = &dpll_class; + dpll->dev_driver_id = dev_driver_id; + dpll->clock_id = clock_id; + dpll->module = module; + ret =xa_alloc (&dpll_device_xa, &dpll->id, dpll, + xa_limit_16b,GFP_KERNEL ); +if (ret) { +kfree (dpll); +return ERR_PTR (ret); + } +xa_init_flags (&dpll->pin_refs,XA_FLAGS_ALLOC ); + +return dpll; +} + +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/ +struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index;
Quoted 8 lines
drivers/dpll/dpll_core.c line 331
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.
dev_driver_id is needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to recover from Sync-E. I believe there is only one clock, that's why clock id is the same for both of them. But Arkadiusz can tell more about it.
Quoted 2 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.
Simply id doesn't tell anything either. dpll_dev_id?
Quoted 19 lines
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/** +* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete
Quoted 8 lines
drivers/dpll/dpll_core.c line 356
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/dpll_core.c new file +4
-0+void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;Remove this check. The driver should not call this with NULL.
Well, netdev_put() has this kind of check. As well as spi_dev_put() or i2c_put_adapter() at least. Not sure I would like to avoid a bit of safety.
Quoted 5 lines
drivers/dpll/dpll_core.c line 359
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);
Good point!
Quoted 58 lines
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2
Looks good, will change it
Quoted 32 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
Quoted 30 lines
drivers/dpll/dpll_core.c new file +30
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); + +/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver
Quoted 8 lines
Quoted 6 lines
+ * @module: reference to registering module
+ * @prop: dpll pin properties
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorExtra "*"'s
Ok, I can re-format the comments across the files.
Quoted 8 lines
drivers/dpll/dpll_core.c line 439
Quoted 3 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,Odd whitespace.
Also, func should be static.
Fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 448
Quoted 10 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;Name inconsistency: driver/drv
you have it on multiple places
Changed it every where, thanks for spotting.
Quoted 18 lines
Quoted 18 lines
drivers/dpll/dpll_core.c new file +17
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + }
Quoted 9 lines
drivers/dpll/dpll_core.c line 470
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
What's the difference? For ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case. Not sure if the pointer way is much better...
Quoted 27 lines
Quoted 27 lines
drivers/dpll/dpll_core.c new file +26
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new +* if doesn't exist yet.
Quoted 9 lines
Quoted 4 lines
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorThis is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
Yep, will clear .h files.
Quoted 7 lines
drivers/dpll/dpll_core.c line 503
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,Again, why do you need this
device_drv_id? Clock id should be enough.
I explained the reason earlier, but the naming is fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 513
Quoted 11 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.
I think clock_id + dev_driver_id + module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?
Quoted 88 lines
Quoted 74 lines
drivers/dpll/dpll_core.c new file +73
-0+ ret = pos; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_pin_alloc (clock_id, device_drv_id, module, prop); +mutex_unlock (&dpll_pin_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_get); + +/** +* dpll_pin_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a pin, if all references are gone, delete pin object. +*/ +void dpll_pin_put (struct dpll_pin *pin) +{ +if (!pin) +return ; +mutex_lock (&dpll_pin_xa_lock); +if (refcount_dec_and_test (&pin->refcount)) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +xa_erase (&dpll_pin_xa, pin->idx); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); + } +mutex_unlock (&dpll_pin_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_pin_put); + +static int +__dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +const char *rclk_device_name) +{ +int ret; + +if (rclk_device_name && !pin->rclk_dev_name) { + pin->rclk_dev_name =kstrdup (rclk_device_name,GFP_KERNEL ); +if (!pin->rclk_dev_name) +return -ENOMEM ; + } + ret =dpll_xa_ref_pin_add (&dpll->pin_refs, pin, ops, priv); +if (ret) + goto rclk_free; + ret =dpll_xa_ref_dpll_add (&pin->dpll_refs, dpll, ops, priv); +if (ret) + goto ref_pin_del; +else +dpll_pin_notify (dpll, pin,DPLL_A_PIN_IDX ); + +return ret; + +ref_pin_del: +dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +rclk_free: +kfree (pin->rclk_dev_name); +return ret; +} + +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 2 lines
drivers/dpll/dpll_core.c new file +2
-0+{ +const char *rclk_name = rclk_device ?dev_name (rclk_device) :NULL ;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Well, these questions go to Arkadiusz...
Quoted 12 lines
drivers/dpll/dpll_core.c line 604
Quoted 8 lines
drivers/dpll/dpll_core.c new file +6
-0+int ret; + +if (WARN_ON (!dpll)) +return -EINVAL ; +if (WARN_ON (!pin)) +return -EINVAL ;Remove these checks and other similar checks in the code. It should rely on basic driver sanity.
Ok...
Quoted 66 lines
Quoted 66 lines
drivers/dpll/dpll_core.c new file +65
-0+ +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); + ret =__dpll_pin_register (dpll, pin, ops, priv, rclk_name); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_register); + +static void +__dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +{ +dpll_xa_ref_pin_del (&dpll->pin_refs, pin); +dpll_xa_ref_dpll_del (&pin->dpll_refs, dpll); +} + +/** +* dpll_pin_unregister - deregister dpll pin from dpll device +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin) +{ +if (WARN_ON (xa_empty (&dpll->pin_refs))) +return -ENOENT ; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +__dpll_pin_unregister (dpll, pin); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_pin_unregister); + +/** +* dpll_pin_on_pin_register - register a pin with a parent pin +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* @ops: ops for a dpll pin +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device +* +* Register a pin with a parent pin, create references between them and +* between newly registered pin and dplls connected with a parent pin. +* +* Return: +* * 0 on success +* * -EINVAL missing pin or parent +* * -ENOMEM failed allocation +* * -EPERM if parent is not allowed +*/ +int +dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device) +{ +struct dpll_pin_ref *ref; +unsigned long i, stop; +int ret;
Quoted 9 lines
drivers/dpll/dpll_core.c line 674
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +if (WARN_ON (!pin || !parent)) +return -EINVAL ; +if (WARN_ON (parent->prop.type !=DPLL_PIN_TYPE_MUX )) +return -EPERM ;I don't think that EPERM is suitable for this. Just use EINVAL. The driver is buggy in this case anyway.
Ok.
Quoted 29 lines
Quoted 29 lines
drivers/dpll/dpll_core.c new file +28
-0+mutex_lock (&dpll_pin_xa_lock); + ret =dpll_xa_ref_pin_add (&pin->parent_refs, parent, ops, priv); +if (ret) + goto unlock; +refcount_inc (&pin->refcount); +xa_for_each (&parent->dpll_refs, i, ref) { +mutex_lock (&dpll_device_xa_lock); + ret =__dpll_pin_register (ref->dpll, pin, ops, priv, + rclk_device ? +dev_name (rclk_device) :NULL ); +mutex_unlock (&dpll_device_xa_lock); +if (ret) { + stop = i; + goto dpll_unregister; + } +dpll_pin_parent_notify (ref->dpll, pin, parent,DPLL_A_PIN_IDX ); + } +mutex_unlock (&dpll_pin_xa_lock); + +return ret; + +dpll_unregister: +xa_for_each (&parent->dpll_refs, i, ref) { +if (i < stop) { +mutex_lock (&dpll_device_xa_lock); +__dpll_pin_unregister (ref->dpll, pin); +mutex_unlock (&dpll_device_xa_lock); + }
Quoted 8 lines
drivers/dpll/dpll_core.c line 710
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ } +refcount_dec (&pin->refcount); +dpll_xa_ref_pin_del (&pin->parent_refs, parent); +unlock: +mutex_unlock (&dpll_pin_xa_lock); +return ret; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_register);
Now I realised that this function can bring us to ABBA deadlock with mutexes..
Quoted 48 lines
Quoted 35 lines
drivers/dpll/dpll_core.c new file +35
-0+ +/** +* dpll_pin_on_pin_unregister - deregister dpll pin from a parent pin +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; +unsigned long i; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +dpll_xa_ref_pin_del (&pin->parent_refs, parent); +refcount_dec (&pin->refcount); +xa_for_each (&pin->dpll_refs, i, ref) { +__dpll_pin_unregister (ref->dpll, pin); +dpll_pin_parent_notify (ref->dpll, pin, parent, +DPLL_A_PIN_IDX ); + } +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_unregister); + +/** +* dpll_pin_get_by_idx - find a pin ref on dpll by pin index +* @dpll: dpll device pointer +* @idx: index of pin +* +* Find a reference to a pin registered with given dpll and return its pointer. +* +* Return: drivers/dpll/dpll_core.c line 755
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* * valid pointer if pin was found +* * NULL if not found +*/ +struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
Quoted 4 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
Quoted 73 lines
Quoted 17 lines
drivers/dpll/dpll_core.c new file +16
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +}drivers/dpll/dpll_core.c line 781
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Return: pointer to the data +*/ +void *dpll_pin_on_dpll_priv(const struct dpll_device *dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
drivers/dpll/dpll_core.c line 786
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+if (!ref) +return NULL ; + +return ref->priv; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_dpll_priv); + +/** +* dpll_pin_on_pin_priv - get the dpll pin private owner data +* @parent: pointer to a parent pin +* @pin: pointer to a pin +* +* Return: pointer to the data +*/ +void *dpll_pin_on_pin_priv (const struct dpll_pin *parent, +const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&pin->parent_refs, parent); +if (!ref) +return NULL ; + +return ref->priv; +} +EXPORT_SYMBOL_GPL (dpll_pin_on_pin_priv); + +static int __init dpll_init (void ) +{ +int ret; +
Quoted 9 lines
drivers/dpll/dpll_core.c line 822
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ ret =dpll_netlink_init (); +if (ret) + goto error; + + ret =class_register (&dpll_class);Why exactly do you need this? I asked to remove this previously, IIRC you said you would check if this needed. Why?
Ah, sorry. Removed it now.
Quoted 77 lines
Quoted 77 lines
drivers/dpll/dpll_core.c new file +13
-0+if (ret) + goto unregister_netlink; + +return 0 ; + +unregister_netlink: +dpll_netlink_finish (); +error: +mutex_destroy (&dpll_device_xa_lock); +mutex_destroy (&dpll_pin_xa_lock); +return ret; +} +subsys_initcall (dpll_init);drivers/dpll/dpll_core.h new file +57
-0@@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +*/ + +#ifndef __DPLL_CORE_H__ +#define __DPLL_CORE_H__ + +#include <linux/dpll.h> +#include <linux/refcount.h> +#include "dpll_netlink.h" + +#define DPLL_REGISTERED XA_MARK_1 + +/** +* struct dpll_device - structure for a DPLL device +* @id: unique id number for each device +* @dev_driver_id: id given by dev driver +* @dev: struct device for this dpll device +* @parent: parent device +* @module: module of creator +* @ops: operations this &dpll_device supports +* @lock: mutex to serialize operations +* @type: type of a dpll +* @priv: pointer to private information of owner +* @pins: list of pointers to pins registered with this dpll +* @clock_id: unique identifier (clock_id) of a dpll +* @mode_supported_mask: mask of supported modes +* @refcount: refcount +**/ +struct dpll_device { +u32 id; +u32 dev_driver_id; +struct device dev; +struct device *parent; +struct module *module; +struct dpll_device_ops *ops; +enum dpll_type type; +void *priv; +struct xarray pin_refs; +u64 clock_id; +unsigned long mode_supported_mask; +refcount_t refcount; +}; + +/** +* struct dpll_pin - structure for a dpll pin +* @idx: unique idx given by alloc on global pin's XA +* @dev_driver_id: id given by dev driver +* @clock_id: clock_id of creator +* @module: module of creator +* @dpll_refs: hold referencees to dplls that pin is registered with +* @pin_refs: hold references to pins that pin is registered with +* @prop: properties given by registerer +* @rclk_dev_name: holds name of device when pin can recover clock from it +* @refcount: refcount +**/
Quoted 9 lines
drivers/dpll/dpll_core.h line 62
Quoted 5 lines
drivers/dpll/dpll_core.h new file +5
-0+struct dpll_pin { +u32 idx; +u32 dev_driver_id; +u64 clock_id; +struct module *module;Have the ordering of common fields, like
clock_idand module consistent with structdpll_device
Re-arranged it a bit.
Quoted 63 lines
Quoted 63 lines
drivers/dpll/dpll_core.h new file +37
-0+struct xarray dpll_refs; +struct xarray parent_refs; +struct dpll_pin_properties prop; +char *rclk_dev_name; +refcount_t refcount; +}; + +/** +* struct dpll_pin_ref - structure for referencing either dpll or pins +* @dpll: pointer to a dpll +* @pin: pointer to a pin +* @ops: ops for a dpll pin +* @priv: pointer to private information of owner +**/ +struct dpll_pin_ref { +union { +struct dpll_device *dpll; +struct dpll_pin *pin; + }; +struct dpll_pin_ops *ops; +void *priv; +refcount_t refcount; +}; + +struct dpll_device *dpll_device_get_by_id (int id); +struct dpll_device *dpll_device_get_by_name (const char *bus_name, +const char *dev_name); +struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx); +struct dpll_pin_ref * +dpll_xa_ref_pin_find (struct xarray *xa_refs,const struct dpll_pin *pin); +struct dpll_pin_ref * +dpll_xa_ref_dpll_find (struct xarray *xa_refs,const struct dpll_device *dpll); +extern struct xarray dpll_device_xa; +extern struct xarray dpll_pin_xa; +extern struct mutex dpll_device_xa_lock; +extern struct mutex dpll_pin_xa_lock; +#endif drivers/dpll/dpll_netlink.c new file +19
-0@@ -0,0 +1,1065 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Generic netlink for DPLL management framework +* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +* +*/ +#include <linux/module.h> +#include <linux/kernel.h> +#include <net/genetlink.h> +#include "dpll_core.h" +#include "dpll_nl.h" +#include <uapi/linux/dpll.h> + +static u32 dpll_pin_freq_value[] = { + [DPLL_PIN_FREQ_SUPP_1_HZ ] =DPLL_PIN_FREQ_1_HZ , + [DPLL_PIN_FREQ_SUPP_10_MHZ ] =DPLL_PIN_FREQ_10_MHZ , +}; +
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 23
Quoted 4 lines
drivers/dpll/dpll_netlink.c new file +4
-0+static int +dpll_msg_add_dev_handle (struct sk_buff *msg,const struct dpll_device *dpll) +{ +if (nla_put_u32 (msg,DPLL_A_ID , dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Quoted 9 lines
Quoted 9 lines
drivers/dpll/dpll_netlink.c new file +8
-0+return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_BUS_NAME ,dev_bus_name (&dpll->dev))) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_DEV_NAME ,dev_name (&dpll->dev))) +return -EMSGSIZE ; + +return 0 ; +}
[...]
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 241
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+ +static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+enum dpll_pin_state state; +struct nlattr *nest; +unsigned long index; +int ret; + +xa_for_each (&pin->parent_refs, index, ref) { +if (WARN_ON (!ref->ops->state_on_pin_get)) +return -EFAULT ; + ret = ref->ops->state_on_pin_get (pin, ref->pin, &state, + extack); +if (ret) +return -EFAULT ; + nest =nla_nest_start (msg,DPLL_A_PIN_PARENT ); +if (!nest) +return -EMSGSIZE ; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/dpll_netlink.c line 267
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +if (nla_put_u8 (msg,DPLL_A_PIN_STATE , state)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +nla_nest_end (msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
Quoted 45 lines
Quoted 45 lines
drivers/dpll/dpll_netlink.c new file +44
-0+ +return 0 ; + +nest_cancel: +nla_nest_cancel (msg, nest); +return ret; +} + +static int +dpll_msg_add_pin_dplls (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct nlattr *attr; +unsigned long index; +int ret; + +xa_for_each (&pin->dpll_refs, index, ref) { + attr =nla_nest_start (msg,DPLL_A_DEVICE ); +if (!attr) +return -EMSGSIZE ; + ret =dpll_msg_add_dev_handle (msg, ref->dpll); +if (ret) + goto nest_cancel; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; +nla_nest_end (msg, attr); + } + +return 0 ; + +nest_cancel: +nla_nest_end (msg, attr); +return ret; +} + +static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack)
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 316
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
I believe it's INDEX which is provided by the driver. I'll think about renaming, but suggestions are welcome.
Quoted 57 lines
Quoted 57 lines
drivers/dpll/dpll_netlink.c new file +57
-0+return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name) +if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} + +static int +__dpll_cmd_pin_dump_one (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_dpll) +{ +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pins_on_pin (msg, pin, extack); +if (ret) +return ret; +if (!xa_empty (&pin->dpll_refs) && dump_dpll) { + ret =dpll_msg_add_pin_dplls (msg, pin, extack); +if (ret)
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 345
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+return ret; + } +if (pin->rclk_dev_name) +if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ;Lots of code duplication with the previous functions, please unify.
Agree, have done it.
Quoted 5 lines
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +4
-0+ +return 0 ; +} +
[...]
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 563
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+static int +dpll_pin_set_from_nlattr (struct dpll_device *dpll, +struct dpll_pin *pin,struct genl_info *info) +{ +enum dpll_pin_state state =DPLL_PIN_STATE_UNSPEC ; +u32 parent_idx =PIN_IDX_INVALID ;You just need this
PIN_IDX_INVALIDdefine internally in this function, change the flow to avoid a need for it.
I'll re-think it, thanks.
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 568
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +5
-0+int rem, ret = -EINVAL ; +struct nlattr *a; + +nla_for_each_attr (a,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
I had some unknown crashes when I was using such access. I might have lost some checks, will try it again.
Quoted 30 lines
Quoted 18 lines
drivers/dpll/dpll_netlink.c new file +17
-0+switch (nla_type (a)) { +case DPLL_A_PIN_FREQUENCY : + ret =dpll_pin_freq_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_DIRECTION : + ret =dpll_pin_direction_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PRIO : + ret =dpll_pin_prio_set (dpll, pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PARENT_IDX :drivers/dpll/dpll_netlink.c line 595
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ parent_idx =nla_get_u32 (a); +break ; +case DPLL_A_PIN_STATE : + state =nla_get_u8 (a); +break ; +default : +break ; + } + } +if (state !=DPLL_PIN_STATE_UNSPEC ) {Again, change the flow to:
Quoted 4 lines
if (attrs[DPLL_A_PIN_STATE]) {and avoid need for this value set/check.
Yep, will try.
Quoted 17 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+if (parent_idx ==PIN_IDX_INVALID ) { + ret =dpll_pin_state_set (dpll, pin, state, + info->extack); +if (ret) +return ret; + }else { + ret =dpll_pin_on_pin_state_set (dpll, pin, parent_idx, + state, info->extack); +if (ret) +return ret; + } + } + +return ret; +} +
[...]
Quoted 51 lines
Quoted 51 lines
drivers/dpll/dpll_netlink.c new file +51
-0+int dpll_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_device_xa_lock); + +return 0 ; +} + +int dpll_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_device_xa_lock); + +return 0 ; +} + +int dpll_pin_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info) +{ +int ret =dpll_pre_doit (ops, skb, info); +struct dpll_device *dpll; +struct dpll_pin *pin; + +if (ret) +return ret; + dpll = info->user_ptr[0 ]; +if (!info->attrs[DPLL_A_PIN_IDX ]) { + ret = -EINVAL ; + goto unlock_dev; + } +mutex_lock (&dpll_pin_xa_lock); + pin =dpll_pin_get_by_idx (dpll, +nla_get_u32 (info->attrs[DPLL_A_PIN_IDX ])); +if (!pin) { + ret = -ENODEV ; + goto unlock_pin; + } + info->user_ptr[1 ] = pin; + +return 0 ; + +unlock_pin: +mutex_unlock (&dpll_pin_xa_lock); +unlock_dev: +mutex_unlock (&dpll_device_xa_lock); +return ret; +} + +void dpll_pin_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info) +{ +mutex_unlock (&dpll_pin_xa_lock); +dpll_post_doit (ops, skb, info);
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 878
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+} + +int dpll_pin_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Now I see an ABBA deadlock here, as well as in function before. Not sure how to solve it here. Any thoughts?
Quoted 36 lines
Quoted 15 lines
drivers/dpll/dpll_netlink.c new file +14
-0+ +return dpll_pre_dumpit (cb); +} + +int dpll_pin_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_pin_xa_lock); + +return dpll_post_dumpit (cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/dpll_netlink.c line 902
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about
what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and compare all attributes to figure out changes and that's might not be great idea.
Quoted 96 lines
Quoted 96 lines
drivers/dpll/dpll_netlink.c new file +95
-0+ +switch (attr) { +case DPLL_A_MODE : + ret =dpll_msg_add_mode (msg, dpll,NULL ); +break ; +case DPLL_A_SOURCE_PIN_IDX : + ret =dpll_msg_add_source_pin_idx (msg, dpll,NULL ); +break ; +case DPLL_A_LOCK_STATUS : + ret =dpll_msg_add_lock_status (msg, dpll,NULL ); +break ; +case DPLL_A_TEMP : + ret =dpll_msg_add_temp (msg, dpll,NULL ); +break ; +case DPLL_A_PIN_FREQUENCY : + ret =dpll_msg_add_pin_freq (msg, pin,NULL , false); +break ; +case DPLL_A_PIN_PRIO : + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref,NULL ); +break ; +case DPLL_A_PIN_STATE : +if (parent) { + ref =dpll_xa_ref_pin_find (&pin->parent_refs, parent); +if (!ref) +return -EFAULT ; +if (!ref->ops || !ref->ops->state_on_pin_get) +return -EOPNOTSUPP ; + ret = ref->ops->state_on_pin_get (pin, parent, &state, +NULL ); +if (ret) +return ret; +if (nla_put_u32 (msg,DPLL_A_PIN_PARENT_IDX , + parent->dev_driver_id)) +return -EMSGSIZE ; + }else { + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref) +return -EFAULT ; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, +NULL ); +if (ret) +return ret; + } +break ; +default : +break ; + } + +return ret; +} + +static int +dpll_send_event_create (enum dpll_event event,struct dpll_device *dpll) +{ +struct sk_buff *msg; +int ret = -EMSGSIZE ; +void *hdr; + + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg,0 ,0 , &dpll_nl_family,0 , event); +if (!hdr) + goto out_free_msg; + + ret =dpll_msg_add_dev_handle (msg, dpll); +if (ret) + goto out_cancel_msg; +genlmsg_end (msg, hdr); +genlmsg_multicast (&dpll_nl_family, msg,0 ,0 ,GFP_KERNEL ); + +return 0 ; + +out_cancel_msg: +genlmsg_cancel (msg, hdr); +out_free_msg: +nlmsg_free (msg); + +return ret; +} + +static int +dpll_send_event_change (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin *parent,enum dplla attr) +{ +struct sk_buff *msg; +int ret = -EMSGSIZE ; +void *hdr; + + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL ); +if (!msg)
Quoted 8 lines
drivers/dpll/dpll_netlink.c line 1001
Quoted 4 lines
drivers/dpll/dpll_netlink.c new file +4
-0+return -ENOMEM ; + + hdr =genlmsg_put (msg,0 ,0 , &dpll_nl_family,0 , +DPLL_EVENT_DEVICE_CHANGE );I don't really get it. Why exactly you keep having this *EVENT* cmds? Why per-object NEW/GET/DEL cmds shared with get genl op are not enough? I have to be missing something.
Changes might come from other places, but will affect the DPLL device and we have to notify users in this case.
Quoted 295 lines
Quoted 281 lines
drivers/dpll/dpll_netlink.c new file +64
-0+if (!hdr) + goto out_free_msg; + + ret =dpll_event_device_change (msg, dpll, pin, parent, attr); +if (ret) + goto out_cancel_msg; +genlmsg_end (msg, hdr); +genlmsg_multicast (&dpll_nl_family, msg,0 ,0 ,GFP_KERNEL ); + +return 0 ; + +out_cancel_msg: +genlmsg_cancel (msg, hdr); +out_free_msg: +nlmsg_free (msg); + +return ret; +} + +int dpll_notify_device_create (struct dpll_device *dpll) +{ +return dpll_send_event_create (DPLL_EVENT_DEVICE_CREATE , dpll); +} + +int dpll_notify_device_delete (struct dpll_device *dpll) +{ +return dpll_send_event_create (DPLL_EVENT_DEVICE_DELETE , dpll); +} + +int dpll_device_notify (struct dpll_device *dpll,enum dplla attr) +{ +if (WARN_ON (!dpll)) +return -EINVAL ; + +return dpll_send_event_change (dpll,NULL ,NULL , attr); +} +EXPORT_SYMBOL_GPL (dpll_device_notify); + +int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, +enum dplla attr) +{ +return dpll_send_event_change (dpll, pin,NULL , attr); +} + +int dpll_pin_parent_notify (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin *parent,enum dplla attr) +{ +return dpll_send_event_change (dpll, pin, parent, attr); +} + +int __init dpll_netlink_init (void ) +{ +return genl_register_family (&dpll_nl_family); +} + +void dpll_netlink_finish (void ) +{ +genl_unregister_family (&dpll_nl_family); +} + +void __exit dpll_netlink_fini(void) +{ +dpll_netlink_finish (); +}drivers/dpll/dpll_netlink.h new file +30
-0@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +*/ + +/** +* dpll_notify_device_create - notify that the device has been created +* @dpll: registered dpll pointer +* +* Return: 0 if succeeds, error code otherwise. +*/ +int dpll_notify_device_create (struct dpll_device *dpll); + + +/** +* dpll_notify_device_delete - notify that the device has been deleted +* @dpll: registered dpll pointer +* +* Return: 0 if succeeds, error code otherwise. +*/ +int dpll_notify_device_delete (struct dpll_device *dpll); + +int dpll_pin_notify (struct dpll_device *dpll,struct dpll_pin *pin, +enum dplla attr); + +int dpll_pin_parent_notify (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin *parent,enum dplla attr); + +int __init dpll_netlink_init (void ); +void dpll_netlink_finish (void );include/linux/dpll.h new file +173
-0@@ -0,0 +1,284 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Meta Platforms, Inc. and affiliates +*/ + +#ifndef __DPLL_H__ +#define __DPLL_H__ + +#include <uapi/linux/dpll.h> +#include <linux/device.h> +#include <linux/netlink.h> + +struct dpll_device ; +struct dpll_pin ; + +#define PIN_IDX_INVALID ((u32)ULONG_MAX) + +struct dpll_device_ops { +int (*mode_get)(const struct dpll_device *dpll,enum dpll_mode *mode, +struct netlink_ext_ack *extack); +int (*mode_set)(const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack); +bool (*mode_supported)(const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack); +int (*source_pin_idx_get)(const struct dpll_device *dpll, +u32 *pin_idx, +struct netlink_ext_ack *extack); +int (*lock_status_get)(const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack); +int (*temp_get)(const struct dpll_device *dpll,s32 *temp, +struct netlink_ext_ack *extack); +}; + +struct dpll_pin_ops { +int (*frequency_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const u32 frequency, +struct netlink_ext_ack *extack); +int (*frequency_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency,struct netlink_ext_ack *extack); +int (*direction_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const enum dpll_pin_direction direction, +struct netlink_ext_ack *extack); +int (*direction_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack); +int (*state_on_pin_get)(const struct dpll_pin *pin, +const struct dpll_pin *parent_pin, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack); +int (*state_on_dpll_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack); +int (*state_on_pin_set)(const struct dpll_pin *pin, +const struct dpll_pin *parent_pin, +const enum dpll_pin_state state, +struct netlink_ext_ack *extack); +int (*state_on_dpll_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const enum dpll_pin_state state, +struct netlink_ext_ack *extack); +int (*prio_get)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *prio,struct netlink_ext_ack *extack); +int (*prio_set)(const struct dpll_pin *pin, +const struct dpll_device *dpll, +const u32 prio,struct netlink_ext_ack *extack); +}; + +struct dpll_pin_properties { +const char *description; +enum dpll_pin_type type; +unsigned long freq_supported; +u32 any_freq_min; +u32 any_freq_max; +unsigned long capabilities; +}; + +enum dpll_pin_freq_supp { +DPLL_PIN_FREQ_SUPP_UNSPEC =0 , +DPLL_PIN_FREQ_SUPP_1_HZ , +DPLL_PIN_FREQ_SUPP_10_MHZ , + + __DPLL_PIN_FREQ_SUPP_MAX, +DPLL_PIN_FREQ_SUPP_MAX = (__DPLL_PIN_FREQ_SUPP_MAX -1 ) +}; + +/** +* dpll_device_get - find or create dpll_device object +* @clock_id: a system unique number for a device +* @dev_driver_idx: index of dpll device on parent device +* @module: register module +* +* Returns: +* * pointer to initialized dpll - success +* * NULL - memory allocation fail +*/ +struct dpll_device +*dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module); + +/** +* dpll_device_put - caller drops reference to the device, free resources +* @dpll: dpll device pointer +* +* If all dpll_device_get callers drops their reference, the dpll device +* resources are freed. +*/ +void dpll_device_put (struct dpll_device *dpll); + +/** +* dpll_device_register - register device, make it visible in the subsystem. +* @dpll: reference previously allocated with dpll_device_get +* @type: type of dpll +* @ops: callbacks +* @priv: private data of registerer +* @owner: device struct of the owner +* +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner); + +/** +* dpll_device_unregister - deregister registered dpll +* @dpll: pointer to dpll +* +* Unregister the dpll from the subsystem, make it unavailable for netlink +* API users. +*/ +void dpll_device_unregister (struct dpll_device *dpll); + +/** +* dpll_priv - get dpll private data +* @dpll: pointer to dpll +* +* Obtain private data pointer passed to dpll subsystem when allocating +* device with ``dpll_device_alloc(..)`` +*/ +void *dpll_priv (const struct dpll_device *dpll); + +/** +* dpll_pin_on_pin_priv - get pin on pin pair private data +* @parent: pointer to a parent pin +* @pin: pointer to a dpll_pin +* +* Obtain private pin data pointer passed to dpll subsystem when pin +* was registered with parent pin. +*/ +void *dpll_pin_on_pin_priv (const struct dpll_pin *parent,const struct dpll_pin *pin); + +/** +* dpll_pin_on_dpll_priv - get pin on dpll pair private data +* @dpll: pointer to dpll +* @pin: pointer to a dpll_pin +* +* Obtain private pin-dpll pair data pointer passed to dpll subsystem when pin +* was registered with a dpll. +*/ +void *dpll_pin_on_dpll_priv (const struct dpll_device *dpll,const struct dpll_pin *pin); + +/** +* dpll_pin_get - get reference or create new pin object +* @clock_id: a system unique number of a device +* @dev_driver_idx: index of dpll device on parent device +* @module: register module +* @pin_prop: constant properities of a pin include/linux/dpll.h line 183
Quoted 10 lines
include/linux/dpll.h new file +10
-0+* +* find existing pin with given clock_id, dev_driver_idx and module, or create new +* and returen its reference. +* +* Returns: +* * pointer to initialized pin - success +* * NULL - memory allocation fail +*/ +struct dpll_pin +*dpll_pin_get(u64 clock_id, u32 dev_driver_id, struct module *module,Name inconsistency: dev_driver_id/idx in comment
Quoted 4 lines
include/linux/dpll.h line 184
Quoted 1 line
include/linux/dpll.h new file +1
-0+ const struct dpll_pin_properties *pin_prop);In .c you call this "prop", be consistent.
Fixed both.
Quoted 104 lines
Quoted 104 lines
include/linux/dpll.h new file +100
-0+ +/** +* dpll_pin_register - register pin with a dpll device +* @dpll: pointer to dpll object to register pin with +* @pin: pointer to allocated pin object being registered with dpll +* @ops: struct with pin ops callbacks +* @priv: private data pointer passed when calling callback ops +* @rclk_device: pointer to device struct if pin is used for recovery of a clock +* from that device +* +* Register previously allocated pin object with a dpll device. +* +* Return: +* * 0 - if pin was registered with a parent pin, +* * -ENOMEM - failed to allocate memory, +* * -EEXIST - pin already registered with this dpll, +* * -EBUSY - couldn't allocate id for a pin. +*/ +int dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device); + +/** +* dpll_pin_unregister - deregister pin from a dpll device +* @dpll: pointer to dpll object to deregister pin from +* @pin: pointer to allocated pin object being deregistered from dpll +* +* Deregister previously registered pin object from a dpll device. +* +* Return: +* * 0 - pin was successfully deregistered from this dpll device, +* * -ENXIO - given pin was not registered with this dpll device, +* * -EINVAL - pin pointer is not valid. +*/ +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin); + +/** +* dpll_pin_put - drop reference to a pin acquired with dpll_pin_get +* @pin: pointer to allocated pin +* +* Pins shall be deregistered from all dpll devices before putting them, +* otherwise the memory won't be freed. +*/ +void dpll_pin_put (struct dpll_pin *pin); + +/** +* dpll_pin_on_pin_register - register a pin to a muxed-type pin +* @parent: parent pin pointer +* @pin: pointer to allocated pin object being registered with a parent pin +* @ops: struct with pin ops callbacks +* @priv: private data pointer passed when calling callback ops +* @rclk_device: pointer to device struct if pin is used for recovery of a clock +* from that device +* +* In case of multiplexed pins, allows registring them under a single +* parent pin. +* +* Return: +* * 0 - if pin was registered with a parent pin, +* * -ENOMEM - failed to allocate memory, +* * -EEXIST - pin already registered with this parent pin, +*/ +int dpll_pin_on_pin_register (struct dpll_pin *parent,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device); + +/** +* dpll_pin_on_pin_register - register a pin to a muxed-type pin +* @parent: parent pin pointer +* @pin: pointer to allocated pin object being registered with a parent pin +* @ops: struct with pin ops callbacks +* @priv: private data pointer passed when calling callback ops +* @rclk_device: pointer to device struct if pin is used for recovery of a clock +* from that device +* +* In case of multiplexed pins, allows registring them under a single +* parent pin. +* +* Return: +* * 0 - if pin was registered with a parent pin, +* * -ENOMEM - failed to allocate memory, +* * -EEXIST - pin already registered with this parent pin, +*/ +void dpll_pin_on_pin_unregister (struct dpll_pin *parent,struct dpll_pin *pin); + +/** +* dpll_device_notify - notify on dpll device change +* @dpll: dpll device pointer +* @attr: changed attribute +* +* Broadcast event to the netlink multicast registered listeners. +* +* Return: +* * 0 - success +* * negative - error +*/ +int dpll_device_notify (struct dpll_device *dpll,enum dplla attr); + + +#endif Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +0
-0@@ -0,0 +1,10 @@Quoted 8 lines
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.oWhat's "sys" and why is it here?
Quoted 2 lines
It's an object file for the subsystem. Could be useful if we will have drivers for DPLL-only devices.
Yeah, but why "sys"? I don't get what "sys" means here. Can't this be just "dpll.o"?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +
[...]
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+struct dpll_device * +dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module) +{ + struct dpll_device *dpll, *ret = NULL; + unsigned long index;Quoted 8 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ + mutex_lock(&dpll_device_xa_lock); + xa_for_each(&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.
Quoted 4 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver implementation there are 2 different DPLLs - to recover from PPS input and to recover from Sync-E. I believe there is only one clock, that's why clock id is the same for both of them. But Arkadiusz can tell more about it.
Okay, I see. Clock_id is the same. Could we have index for pin, could this be index too:
dpll_device_get(u64 clock_id, u32 device_index, struct module *module); dpll_pin_get(u64 clock_id, u32 pin_index, struct module *module,
const struct dpll_pin_properties *prop);
This way it is consistent, driver provides custom index for both dpll device and dpll pin.
Makes sense?
Quoted 4 lines
Quoted 2 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?
Yeah, see above.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/Makefile new file +19
-0+ dpll->module == module) { + ret = dpll; + refcount_inc(&ret->refcount); + break; + } + } + if (!ret) + ret = dpll_device_alloc(clock_id, dev_driver_id, module); + mutex_unlock(&dpll_device_xa_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(dpll_device_get); + +/** + * dpll_device_put - decrease the refcount and free memory if possible + * @dpll: dpll_device struct pointer + * + * Drop reference for a dpll device, if all references are gone, deleteQuoted 8 lines
drivers/dpll/Makefile
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/Makefile new file +4
-0+void dpll_device_put(struct dpll_device *dpll) +{ + if (!dpll) + return;Remove this check. The driver should not call this with NULL.
Quoted 2 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.
IDK, maybe for historical reasons. My point is, id driver is callin this with NULL, there is something odd in the driver flow. Lets not allow that for new code.
Quoted 67 lines
Quoted 6 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +3
-0+ mutex_lock(&dpll_device_xa_lock); + if (refcount_dec_and_test(&dpll->refcount)) { + WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Quoted 58 lines
Quoted 31 lines
drivers/dpll/Makefile new file +31
-0+ xa_destroy(&dpll->pin_refs); + xa_erase(&dpll_device_xa, dpll->id); + kfree(dpll); + } + mutex_unlock(&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL(dpll_device_put); + +/** + * dpll_device_register - register the dpll device in the subsystem + * @dpll: pointer to a dpll + * @type: type of a dpll + * @ops: ops for a dpll device + * @priv: pointer to private information of owner + * @owner: pointer to owner device + * + * Make dpll device available for user space. + * + * Return: + * * 0 on success + * * -EINVAL on failure + */ +int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, + struct dpll_device_ops *ops, void *priv, + struct device *owner) +{ + if (WARN_ON(!ops || !owner)) + return -EINVAL; + if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX)) + return -EINVAL; + mutex_lock(&dpll_device_xa_lock);drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ if (ASSERT_DPLL_NOT_REGISTERED(dpll)) { + mutex_unlock(&dpll_device_xa_lock); + return -EEXIST; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; + dev_set_name(&dpll->dev, "%s_%d", dev_name(owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56
Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Great.
Quoted 3 lines
Quoted 3 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
[...]
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ pin->prop.description = kstrdup(prop->description, GFP_KERNEL); + if (!pin->prop.description) { + ret = -ENOMEM; + goto release; + } + if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC || + prop->type > DPLL_PIN_TYPE_MAX)) { + ret = -EINVAL; + goto release; + }Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 4 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case. Not sure if the pointer way is much better...
For things like this it is common to have static const array in the driver, like:
static const struct dpll_pin_properties dpll_pin_props[] = {
{
.description = "SMA0",
.freq_supported = DPLL_PIN_FREQ_SUPP_MAX,
.type = DPLL_PIN_TYPE_EXT,
.any_freq_max = 10000000,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
},
{
.description = "SMA1",
.freq_supported = DPLL_PIN_FREQ_SUPP_MAX,
.type = DPLL_PIN_TYPE_EXT,
.any_freq_max = 10000000,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
},
{
.description = "SMA2",
.freq_supported = DPLL_PIN_FREQ_SUPP_MAX,
.type = DPLL_PIN_TYPE_EXT,
.any_freq_max = 10000000,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
},
{
.description = "SMA3",
.freq_supported = DPLL_PIN_FREQ_SUPP_MAX,
.type = DPLL_PIN_TYPE_EXT,
.any_freq_max = 10000000,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
},
};Here you have very nice list of pins, the reader knows right away what is happening.
Thinking about "description" name, I think would be more appropriate to name this "label" as it represents user-facing label on the connector, isn't it? Does not describe anything.
Quoted 2 lines
Quoted 2 lines
[...]
Quoted 15 lines
Quoted 15 lines
drivers/dpll/Makefile
Quoted 12 lines
drivers/dpll/Makefile new file +10
-0+ const struct dpll_pin_properties *prop) +{ + struct dpll_pin *pos, *ret = NULL; + unsigned long index; + + mutex_lock(&dpll_pin_xa_lock); + xa_for_each(&dpll_pin_xa, index, pos) { + if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 7 lines
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.I think
clock_id+dev_driver_id+ module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?
IDK, no strong opinion on this. I just thought it may help to identify the pin and avoid potential driver bugs. (Like registering 2 pins with the same properties).
[...]
Quoted 30 lines
Quoted 21 lines
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+/** + * dpll_pin_register - register the dpll pin in the subsystem + * @dpll: pointer to a dpll + * @pin: pointer to a dpll pin + * @ops: ops for a dpll pin ops + * @priv: pointer to private information of owner + * @rclk_device: pointer to recovered clock devicedrivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ * + * Return: + * * 0 on success + * * -EINVAL - missing dpll or pin + * * -ENOMEM - failed to allocate memory + */ +int +dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv, + struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
drivers/dpll/Makefile
Quoted 2 lines
drivers/dpll/Makefile new file +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) : NULL;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Quoted 1 line
Well, these questions go to Arkadiusz...
Okay.
[...]
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
+ *
dpll_pin_get_by_idx- find a pin ref on dpll by pin index
+ * @dpll: dpll device pointer
+ * @idx: index of pin
+ *
+ * Find a reference to a pin registered with given dpll and return its pointer.
+ *
+ * Return:
+ * * valid pointer if pin was found
+ * * NULL if not found
+ */drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx) +{ + struct dpll_pin_ref *pos; + unsigned long i; + + xa_for_each(&dpll->pin_refs, i, pos) { + if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
Quoted 6 lines
Quoted 4 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
No, driver can provide indexing which is completely up to his decision. You should use xa_insert() to insert the entry at specific index. See devl_port_register for inspiration where it is done exactly like this.
And this should be done in exactly the same way for both pin and device.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/dpll/Makefile new file +22
-0+ return pos->pin; + } + + return NULL; +} + +/** + * dpll_priv - get the dpll device private owner data + * @dpll: registered dpll pointer + * + * Return: pointer to the data + */ +void *dpll_priv(const struct dpll_device *dpll) +{ + return dpll->priv; +} +EXPORT_SYMBOL_GPL(dpll_priv); + +/** + * dpll_pin_on_dpll_priv - get the dpll device private owner data + * @dpll: registered dpll pointer + * @pin: pointer to a pin
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
+ *
+ * Return: pointer to the data
+ */
+void *dpll_pin_on_dpll_priv(const structdpll_device*dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
Did you miss this?
Quoted 9 lines
Quoted 9 lines
drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +5
-0+ const struct dpll_pin *pin) +{ + struct dpll_pin_ref *ref; + + ref = dpll_xa_ref_pin_find((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
Did you miss this?
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
drivers/dpll/Makefile new file +31
-0+ if (!ref) + return NULL; + + return ref->priv; +} +EXPORT_SYMBOL_GPL(dpll_pin_on_dpll_priv); + +/** + * dpll_pin_on_pin_priv - get the dpll pin private owner data + * @parent: pointer to a parent pin + * @pin: pointer to a pin + * + * Return: pointer to the data + */ +void *dpll_pin_on_pin_priv(const struct dpll_pin *parent, + const struct dpll_pin *pin) +{ + struct dpll_pin_ref *ref; + + ref = dpll_xa_ref_pin_find((struct xarray *)&pin->parent_refs, parent); + if (!ref) + return NULL; + + return ref->priv; +} +EXPORT_SYMBOL_GPL(dpll_pin_on_pin_priv); + +static int __init dpll_init(void) +{ + int ret; +Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ ret = dpll_netlink_init(); + if (ret) + goto error; + + ret = class_register(&dpll_class);Why exactly do you need this? I asked to remove this previously, IIRC you said you would check if this needed. Why?
Quoted 1 line
Ah, sorry. Removed it now.
Np, good.
[...]
Quoted 9 lines
Quoted 9 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +4
-0+static int +dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device *dpll) +{ + if (nla_put_u32(msg, DPLL_A_ID, dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.
Quoted 3 lines
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Wait, I don't get it. Could you please explain a bit more?
My point is, there should be not such ID exposed over netlink You don't need to expose it to userspace. The user has well defined handle as you agreed with above. For example:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2
This is shown in dpll device GET/DUMP outputs.
Also user passes it during SET operation:
$ dplltool set ice/c92d02a7129f4747/1 mode auto
Isn't that enough stable and nice?
Quoted 57 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile new file +8
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_BUS_NAME, dev_bus_name(&dpll->dev))) + return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_DEV_NAME, dev_name(&dpll->dev))) + return -EMSGSIZE; + + return 0; +}[...]
Quoted 9 lines
drivers/dpll/Makefile
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+ +static int +dpll_msg_add_pins_on_pin(struct sk_buff *msg, struct dpll_pin *pin, + struct netlink_ext_ack *extack) +{ + struct dpll_pin_ref *ref = NULL;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/Makefile new file +16
-0+ enum dpll_pin_state state; + struct nlattr *nest; + unsigned long index; + int ret; + + xa_for_each(&pin->parent_refs, index, ref) { + if (WARN_ON(!ref->ops->state_on_pin_get)) + return -EFAULT; + ret = ref->ops->state_on_pin_get(pin, ref->pin, &state, + extack); + if (ret) + return -EFAULT; + nest = nla_nest_start(msg, DPLL_A_PIN_PARENT); + if (!nest) + return -EMSGSIZE; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + if (nla_put_u8(msg, DPLL_A_PIN_STATE, state)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + nla_nest_end(msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/
Quoted 6 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
Okay, Arkadiuzs?
Quoted 56 lines
Quoted 46 lines
Quoted 46 lines
drivers/dpll/Makefile new file +44
-0+ + return 0; + +nest_cancel: + nla_nest_cancel(msg, nest); + return ret; +} + +static int +dpll_msg_add_pin_dplls(struct sk_buff *msg, struct dpll_pin *pin, + struct netlink_ext_ack *extack) +{ + struct dpll_pin_ref *ref; + struct nlattr *attr; + unsigned long index; + int ret; + + xa_for_each(&pin->dpll_refs, index, ref) { + attr = nla_nest_start(msg, DPLL_A_DEVICE); + if (!attr) + return -EMSGSIZE; + ret = dpll_msg_add_dev_handle(msg, ref->dpll); + if (ret) + goto nest_cancel; + ret = dpll_msg_add_pin_on_dpll_state(msg, pin, ref, extack); + if (ret && ret != -EOPNOTSUPP) + goto nest_cancel; + ret = dpll_msg_add_pin_prio(msg, pin, ref, extack); + if (ret && ret != -EOPNOTSUPP) + goto nest_cancel; + nla_nest_end(msg, attr); + } + + return 0; + +nest_cancel: + nla_nest_end(msg, attr); + return ret; +} + +static int +dpll_cmd_pin_on_dpll_get(struct sk_buff *msg, struct dpll_pin *pin, + struct dpll_device *dpll, + struct netlink_ext_ack *extack)Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+{ + struct dpll_pin_ref *ref; + int ret; + + if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 2 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming, but suggestions are welcome.
Let's use "index" and "INDEX" internalla and in Netlink attr names as well then.
[...]
Quoted 12 lines
Quoted 11 lines
drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +5
-0+ int rem, ret = -EINVAL; + struct nlattr *a; + + nla_for_each_attr(a, genlmsg_data(info->genlhdr), + genlmsg_len(info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
Quoted 2 lines
I had some unknown crashes when I was using such access. I might have lost some checks, will try it again.
Odd, yet definitelly debuggable though :)
[...]
Quoted 10 lines
Quoted 7 lines
drivers/dpll/Makefile
Quoted 3 lines
drivers/dpll/Makefile new file +3
-0+int dpll_pin_pre_dumpit(struct netlink_callback *cb) +{ + mutex_lock(&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.Now I see an ABBA deadlock here, as well as in function before. Not sure how to solve it here. Any thoughts?
Well, here you can just call dpll_pre_dumpit() before mutex_lock(&dpll_pin_xa_lock) to take the locks in the same order.
Quoted 37 lines
Quoted 37 lines
Quoted 16 lines
drivers/dpll/Makefile new file +14
-0+ + return dpll_pre_dumpit(cb); +} + +int dpll_pin_post_dumpit(struct netlink_callback *cb) +{ + mutex_unlock(&dpll_pin_xa_lock); + + return dpll_post_dumpit(cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ enum dplla attr) +{ + int ret = dpll_msg_add_dev_handle(msg, dpll); + struct dpll_pin_ref *ref = NULL; + enum dpll_pin_state state; + + if (ret) + return ret; + if (pin && nla_put_u32(msg, DPLL_A_PIN_IDX, pin->dev_driver_id)) + return -EMSGSIZE;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.
Quoted 7 lines
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
Wait, are you saying that the app is stateless? Could you provide example use cases?
From what I see, the app managing dpll knows the state of the device and pins, it monitors for the changes and saves new state with appropriate reaction (might be some action or maybe just log entry).
Quoted 106 lines
Quoted 97 lines
Quoted 97 lines
drivers/dpll/Makefile new file +95
-0+ + switch (attr) { + case DPLL_A_MODE: + ret = dpll_msg_add_mode(msg, dpll, NULL); + break; + case DPLL_A_SOURCE_PIN_IDX: + ret = dpll_msg_add_source_pin_idx(msg, dpll, NULL); + break; + case DPLL_A_LOCK_STATUS: + ret = dpll_msg_add_lock_status(msg, dpll, NULL); + break; + case DPLL_A_TEMP: + ret = dpll_msg_add_temp(msg, dpll, NULL); + break; + case DPLL_A_PIN_FREQUENCY: + ret = dpll_msg_add_pin_freq(msg, pin, NULL, false); + break; + case DPLL_A_PIN_PRIO: + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_prio(msg, pin, ref, NULL); + break; + case DPLL_A_PIN_STATE: + if (parent) { + ref = dpll_xa_ref_pin_find(&pin->parent_refs, parent); + if (!ref) + return -EFAULT; + if (!ref->ops || !ref->ops->state_on_pin_get) + return -EOPNOTSUPP; + ret = ref->ops->state_on_pin_get(pin, parent, &state, + NULL); + if (ret) + return ret; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX, + parent->dev_driver_id)) + return -EMSGSIZE; + } else { + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_on_dpll_state(msg, pin, ref, + NULL); + if (ret) + return ret; + } + break; + default: + break; + } + + return ret; +} + +static int +dpll_send_event_create(enum dpll_event event, struct dpll_device *dpll) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, event); + if (!hdr) + goto out_free_msg; + + ret = dpll_msg_add_dev_handle(msg, dpll); + if (ret) + goto out_cancel_msg; + genlmsg_end(msg, hdr); + genlmsg_multicast(&dpll_nl_family, msg, 0, 0, GFP_KERNEL); + + return 0; + +out_cancel_msg: + genlmsg_cancel(msg, hdr); +out_free_msg: + nlmsg_free(msg); + + return ret; +} + +static int +dpll_send_event_change(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin *parent, enum dplla attr) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg)Quoted 8 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +4
-0+ return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, + DPLL_EVENT_DEVICE_CHANGE);I don't really get it. Why exactly you keep having this *EVENT* cmds? Why per-object NEW/GET/DEL cmds shared with get genl op are not enough? I have to be missing something.
Quoted 2 lines
Changes might come from other places, but will affect the DPLL device and we have to notify users in this case.
I'm not sure I follow. There are 2 scenarios for change:
1) user originated - user issues set of something
2) driver originated - something changes in HW, driver propagates that
With what I suggest, both scenarios work of course. My point is, user knows very well the objects: device and pin, he knows the format or messages that are related to GET/DUMP/SET operations of both. The notification should have the same format, that is all I say.
Btw, you can see devlink code for example how the notifications like this are implemented and work.
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 67 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 10:22 AMQuoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +0
-0@@ -0,0 +1,10 @@Quoted 8 lines
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.oWhat's "sys" and why is it here?
Quoted 3 lines
It's an object file for the subsystem. Could be useful if we will have drivers
for DPLL-only devices.Yeah, but why "sys"? I don't get what "sys" means here. Can't this be just "dpll.o"?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +2
-0+struct dpll_device * +dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module*module)
drivers/dpll/Makefile new file +3
-0+{ + struct dpll_device *dpll, *ret = NULL; + unsigned long index;Quoted 8 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ + mutex_lock(&dpll_device_xa_lock); + xa_for_each(&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.Quoted 6 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is the same for both of them. But Arkadiusz can tell more about it.Okay, I see.
Clock_idis the same. Could we have index for pin, could this be index too:
Quoted 9 lines
dpll_device_get(u64 clock_id, u32 device_index, struct module *module); dpll_pin_get(u64clock_id, u32pin_index, struct module *module,const struct dpll_pin_properties *prop);This way it is consistent, driver provides custom index for both dpll device and dpll pin.
Makes sense?
IMHO, Yes this better shows the intentions.
Quoted 191 lines
Quoted 5 lines
Quoted 3 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?Yeah, see above.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/Makefile new file +19
-0+ dpll->module == module) { + ret = dpll; + refcount_inc(&ret->refcount); + break; + } + } + if (!ret) + ret = dpll_device_alloc(clock_id, dev_driver_id, module); + mutex_unlock(&dpll_device_xa_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(dpll_device_get); + +/** + * dpll_device_put - decrease the refcount and free memory if possible + * @dpll: dpll_device struct pointer + * + * Drop reference for a dpll device, if all references are gone, deleteQuoted 8 lines
drivers/dpll/Makefile
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/Makefile new file +4
-0+void dpll_device_put(struct dpll_device *dpll) +{ + if (!dpll) + return;Remove this check. The driver should not call this with NULL.
Quoted 2 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.IDK, maybe for historical reasons. My point is, id driver is callin this with NULL, there is something odd in the driver flow. Lets not allow that for new code.
Quoted 67 lines
Quoted 6 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +3
-0+ mutex_lock(&dpll_device_xa_lock); + if (refcount_dec_and_test(&dpll->refcount)) { + WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Quoted 58 lines
Quoted 31 lines
drivers/dpll/Makefile new file +31
-0+ xa_destroy(&dpll->pin_refs); + xa_erase(&dpll_device_xa, dpll->id); + kfree(dpll); + } + mutex_unlock(&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL(dpll_device_put); + +/** + * dpll_device_register - register the dpll device in the subsystem + * @dpll: pointer to a dpll + * @type: type of a dpll + * @ops: ops for a dpll device + * @priv: pointer to private information of owner + * @owner: pointer to owner device + * + * Make dpll device available for user space. + * + * Return: + * * 0 on success + * * -EINVAL on failure + */ +int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, + struct dpll_device_ops *ops, void *priv, + struct device *owner) +{ + if (WARN_ON(!ops || !owner)) + return -EINVAL; + if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX)) + return -EINVAL; + mutex_lock(&dpll_device_xa_lock);drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ if (ASSERT_DPLL_NOT_REGISTERED(dpll)) { + mutex_unlock(&dpll_device_xa_lock); + return -EEXIST; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; + dev_set_name(&dpll->dev, "%s_%d", dev_name(owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Great.
Quoted 3 lines
Quoted 3 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
[...]
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ pin->prop.description = kstrdup(prop->description, GFP_KERNEL); + if (!pin->prop.description) { + ret = -ENOMEM; + goto release; + } + if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC || + prop->type > DPLL_PIN_TYPE_MAX)) { + ret = -EINVAL; + goto release; + }Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 3 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in thiscase.
Quoted 1 line
Not sure if the pointer way is much better...
For things like this it is common to have static const array in the driver, like:
static const struct dpll_pin_properties dpll_pin_props[] = { { .description = "SMA0", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA1", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA2", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA3", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, };
Quoted 7 lines
Here you have very nice list of pins, the reader knows right away what is happening.
Thinking about "description" name, I think would be more appropriate to name this "label" as it represents user-facing label on the connector, isn't it? Does not describe anything.
"label" seems good.
Quoted 26 lines
Quoted 3 lines
Quoted 3 lines
[...]
Quoted 19 lines
Quoted 18 lines
drivers/dpll/Makefile
Quoted 12 lines
drivers/dpll/Makefile new file +10
-0+ const struct dpll_pin_properties *prop) +{ + struct dpll_pin *pos, *ret = NULL; + unsigned long index; + + mutex_lock(&dpll_pin_xa_lock); + xa_for_each(&dpll_pin_xa, index, pos) { + if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.
Quoted 8 lines
Quoted 3 lines
I think
clock_id+dev_driver_id+ module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?IDK, no strong opinion on this. I just thought it may help to identify the pin and avoid potential driver bugs. (Like registering 2 pins with the same properties).
It would make most sense if pin_index would be a part of *prop.
Quoted 34 lines
[...]
Quoted 31 lines
Quoted 30 lines
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+/** + * dpll_pin_register - register the dpll pin in the subsystem + * @dpll: pointer to a dpll + * @pin: pointer to a dpll pin + * @ops: ops for a dpll pin ops + * @priv: pointer to private information of owner + * @rclk_device: pointer to recovered clock devicedrivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ * + * Return: + * * 0 on success + * * -EINVAL - missing dpll or pin + * * -ENOMEM - failed to allocate memory + */ +int +dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv, + struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 3 lines
drivers/dpll/Makefile new file +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) :NULL;
If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Quoted 2 lines
Quoted 1 line
Well, these questions go to Arkadiusz...
[ copy paste my answer from previous response ]
If pin is able to recover signal from some device this shall convey that device struct pointer.
Name of that device is later passed to the user with DPLL_A_PIN_RCLK_DEVICE attribute.
Sure we can have pointer to device and use dev_name (each do/dump) on netlink part. But isn't it better to have the name ready to use there?
It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
Quoted 30 lines
Okay.
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
+ *
dpll_pin_get_by_idx- find a pin ref on dpll by pin index
+ * @dpll: dpll device pointer
+ * @idx: index of pin
+ *
+ * Find a reference to a pin registered with given dpll and return its pointer.
+ *
+ * Return:
+ * * valid pointer if pin was found
+ * * NULL if not found
+ */drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx) +{ + struct dpll_pin_ref *pos; + unsigned long i; + + xa_for_each(&dpll->pin_refs, i, pos) { + if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 9 lines
Quoted 2 lines
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
No, driver can provide indexing which is completely up to his decision. You should use
xa_insert()to insert the entry at specific index. Seedevl_port_registerfor inspiration where it is done exactly like this.And this should be done in exactly the same way for both pin and device.
Yes, I agree seems doable and better then it is now.
[...]
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +2
-0+static int +dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device*dpll)
drivers/dpll/Makefile new file +2
-0+{ + if (nla_put_u32(msg, DPLL_A_ID, dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.Quoted 3 lines
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Wait, I don't get it. Could you please explain a bit more?
My point is, there should be not such ID exposed over netlink You don't need to expose it to userspace. The user has well defined handle as you agreed with above. For example:
Quoted 9 lines
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2This is shown in dpll device GET/DUMP outputs.
Also user passes it during SET operation:$ dplltool set ice/c92d02a7129f4747/1 mode autoIsn't that enough stable and nice?
I agree with Vadim, this is rather to be used by a daemon tools, which would get the index once, then could use it as long as device is there.
Quoted 59 lines
Quoted 59 lines
Quoted 12 lines
Quoted 12 lines
drivers/dpll/Makefile new file +2
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_BUS_NAME, dev_bus_name(&dpll-dev)))
drivers/dpll/Makefile new file +6
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_DEV_NAME, dev_name(&dpll->dev))) + return -EMSGSIZE; + + return 0; +}[...]
Quoted 9 lines
drivers/dpll/Makefile
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+ +static int +dpll_msg_add_pins_on_pin(struct sk_buff *msg, struct dpll_pin *pin, + struct netlink_ext_ack *extack) +{ + struct dpll_pin_ref *ref = NULL;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/Makefile new file +16
-0+ enum dpll_pin_state state; + struct nlattr *nest; + unsigned long index; + int ret; + + xa_for_each(&pin->parent_refs, index, ref) { + if (WARN_ON(!ref->ops->state_on_pin_get)) + return -EFAULT; + ret = ref->ops->state_on_pin_get(pin, ref->pin, &state, + extack); + if (ret) + return -EFAULT; + nest = nla_nest_start(msg, DPLL_A_PIN_PARENT); + if (!nest) + return -EMSGSIZE; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + if (nla_put_u8(msg, DPLL_A_PIN_STATE, state)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + nla_nest_end(msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
[ copy paste my answer from previous response ]
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 7 lines
Quoted 3 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.Let's use "index" and "INDEX" internalla and in Netlink attr names as well then.
For me makes sense to have a common name instead of origin-based one.
Quoted 31 lines
[...]
Quoted 12 lines
Quoted 11 lines
drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +5
-0+ int rem, ret = -EINVAL; + struct nlattr *a; + + nla_for_each_attr(a, genlmsg_data(info->genlhdr), + genlmsg_len(info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
Quoted 2 lines
I had some unknown crashes when I was using such access. I might have lost some checks, will try it again.
Odd, yet definitelly debuggable though :)
[...]
Quoted 8 lines
Quoted 7 lines
drivers/dpll/Makefile
Quoted 3 lines
drivers/dpll/Makefile new file +3
-0+int dpll_pin_pre_dumpit(struct netlink_callback *cb) +{ + mutex_lock(&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Quoted 8 lines
Quoted 3 lines
Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?Well, here you can just call
dpll_pre_dumpit()beforemutex_lock(&dpll_pin_xa_lock)
to take the locks in the same order.
This double lock doesn't really improve anything.
Any objections on having single mutex/lock for access the dpll subsystem?
Quoted 49 lines
Quoted 40 lines
Quoted 40 lines
Quoted 28 lines
drivers/dpll/Makefile new file +13
-0+ + return dpll_pre_dumpit(cb); +} + +int dpll_pin_post_dumpit(struct netlink_callback *cb) +{ + mutex_unlock(&dpll_pin_xa_lock); + + return dpll_post_dumpit(cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device*dpll,
drivers/dpll/Makefile new file +10
-0+ struct dpll_pin *pin, struct dpll_pin *parent, + enum dplla attr) +{ + int ret = dpll_msg_add_dev_handle(msg, dpll); + struct dpll_pin_ref *ref = NULL; + enum dpll_pin_state state; + + if (ret) + return ret; + if (pin && nla_put_u32(msg, DPLL_A_PIN_IDX, pin-
dev_driver_id))drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ return -EMSGSIZE;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 8 lines
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
Quoted 7 lines
Wait, are you saying that the app is stateless? Could you provide example use cases?
From what I see, the app managing dpll knows the state of the device and pins, it monitors for the changes and saves new state with appropriate reaction (might be some action or maybe just log entry).
It depends on the use case, right? App developer having those information knows what has changed, thus can react in a way it thinks is most suitable. IMHO from user perspective it is good to have a notification which actually shows it's reason, so proper flow could be assigned to handle the reaction.
Quoted 114 lines
Quoted 107 lines
Quoted 98 lines
Quoted 98 lines
drivers/dpll/Makefile new file +95
-0+ + switch (attr) { + case DPLL_A_MODE: + ret = dpll_msg_add_mode(msg, dpll, NULL); + break; + case DPLL_A_SOURCE_PIN_IDX: + ret = dpll_msg_add_source_pin_idx(msg, dpll, NULL); + break; + case DPLL_A_LOCK_STATUS: + ret = dpll_msg_add_lock_status(msg, dpll, NULL); + break; + case DPLL_A_TEMP: + ret = dpll_msg_add_temp(msg, dpll, NULL); + break; + case DPLL_A_PIN_FREQUENCY: + ret = dpll_msg_add_pin_freq(msg, pin, NULL, false); + break; + case DPLL_A_PIN_PRIO: + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_prio(msg, pin, ref, NULL); + break; + case DPLL_A_PIN_STATE: + if (parent) { + ref = dpll_xa_ref_pin_find(&pin->parent_refs, parent); + if (!ref) + return -EFAULT; + if (!ref->ops || !ref->ops->state_on_pin_get) + return -EOPNOTSUPP; + ret = ref->ops->state_on_pin_get(pin, parent, &state, + NULL); + if (ret) + return ret; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX, + parent->dev_driver_id)) + return -EMSGSIZE; + } else { + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_on_dpll_state(msg, pin, ref, + NULL); + if (ret) + return ret; + } + break; + default: + break; + } + + return ret; +} + +static int +dpll_send_event_create(enum dpll_event event, struct dpll_device *dpll) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, event); + if (!hdr) + goto out_free_msg; + + ret = dpll_msg_add_dev_handle(msg, dpll); + if (ret) + goto out_cancel_msg; + genlmsg_end(msg, hdr); + genlmsg_multicast(&dpll_nl_family, msg, 0, 0, GFP_KERNEL); + + return 0; + +out_cancel_msg: + genlmsg_cancel(msg, hdr); +out_free_msg: + nlmsg_free(msg); + + return ret; +} + +static int +dpll_send_event_change(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin *parent, enum dplla attr) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg)Quoted 8 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +4
-0+ return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, + DPLL_EVENT_DEVICE_CHANGE);I don't really get it. Why exactly you keep having this *EVENT* cmds? Why per-object NEW/GET/DEL cmds shared with get genl op are not enough? I have to be missing something.
Quoted 2 lines
Changes might come from other places, but will affect the DPLL device and we have to notify users in this case.
I'm not sure I follow. There are 2 scenarios for change:
1) user originated - user issues set of something
2) driver originated - something changes in HW, driver propagates that
Quoted 8 lines
With what I suggest, both scenarios work of course. My point is, user knows very well the objects: device and pin, he knows the format or messages that are related to GET/DUMP/SET operations of both. The notification should have the same format, that is all I say.
Btw, you can see devlink code for example how the notifications like this are implemented and work.
Devlink packs all the info into a netlink message and notifies with it, isn't it that it has all the info "buffered" in its structures?
A dpll subsystem keeps only some of the info in its internal structures, but for most of it it has to question the driver. It would do it multiple times i.e. if there would be a change on a pin connected to multiple dpll devices.
With current approach the notifications are pretty light to the subsystem as well as for the registered clients, and as you suggested with having info of what actually changed the userspace could implement a stateless daemon right away.
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 71 lines · Tue, Mar 14, 2023 at 06:50:57PM CET, [email protected] wrote:
Quoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 10:22 AMQuoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +0
-0@@ -0,0 +1,10 @@Quoted 8 lines
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.oWhat's "sys" and why is it here?
Quoted 3 lines
It's an object file for the subsystem. Could be useful if we will have drivers
for DPLL-only devices.Yeah, but why "sys"? I don't get what "sys" means here. Can't this be just "dpll.o"?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +2
-0+struct dpll_device * +dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module*module)
drivers/dpll/Makefile new file +3
-0+{ + struct dpll_device *dpll, *ret = NULL; + unsigned long index;Quoted 8 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ + mutex_lock(&dpll_device_xa_lock); + xa_for_each(&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.Quoted 6 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is the same for both of them. But Arkadiusz can tell more about it.Okay, I see.
Clock_idis the same. Could we have index for pin, could this be index too:
dpll_device_get(u64 clock_id, u32 device_index, struct module *module); dpll_pin_get(u64clock_id, u32pin_index, struct module *module,const struct dpll_pin_properties *prop);
Quoted 7 lines
Quoted 5 lines
This way it is consistent, driver provides custom index for both dpll device and dpll pin.
Makes sense?
IMHO, Yes this better shows the intentions.
Ok.
Quoted 195 lines
Quoted 195 lines
Quoted 6 lines
Quoted 4 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?Yeah, see above.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/Makefile new file +19
-0+ dpll->module == module) { + ret = dpll; + refcount_inc(&ret->refcount); + break; + } + } + if (!ret) + ret = dpll_device_alloc(clock_id, dev_driver_id, module); + mutex_unlock(&dpll_device_xa_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(dpll_device_get); + +/** + * dpll_device_put - decrease the refcount and free memory if possible + * @dpll: dpll_device struct pointer + * + * Drop reference for a dpll device, if all references are gone, deleteQuoted 8 lines
drivers/dpll/Makefile
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/Makefile new file +4
-0+void dpll_device_put(struct dpll_device *dpll) +{ + if (!dpll) + return;Remove this check. The driver should not call this with NULL.
Quoted 2 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.IDK, maybe for historical reasons. My point is, id driver is callin this with NULL, there is something odd in the driver flow. Lets not allow that for new code.
Quoted 67 lines
Quoted 6 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +3
-0+ mutex_lock(&dpll_device_xa_lock); + if (refcount_dec_and_test(&dpll->refcount)) { + WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Quoted 58 lines
Quoted 31 lines
drivers/dpll/Makefile new file +31
-0+ xa_destroy(&dpll->pin_refs); + xa_erase(&dpll_device_xa, dpll->id); + kfree(dpll); + } + mutex_unlock(&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL(dpll_device_put); + +/** + * dpll_device_register - register the dpll device in the subsystem + * @dpll: pointer to a dpll + * @type: type of a dpll + * @ops: ops for a dpll device + * @priv: pointer to private information of owner + * @owner: pointer to owner device + * + * Make dpll device available for user space. + * + * Return: + * * 0 on success + * * -EINVAL on failure + */ +int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, + struct dpll_device_ops *ops, void *priv, + struct device *owner) +{ + if (WARN_ON(!ops || !owner)) + return -EINVAL; + if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX)) + return -EINVAL; + mutex_lock(&dpll_device_xa_lock);drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ if (ASSERT_DPLL_NOT_REGISTERED(dpll)) { + mutex_unlock(&dpll_device_xa_lock); + return -EEXIST; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; + dev_set_name(&dpll->dev, "%s_%d", dev_name(owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Great.
Quoted 3 lines
Quoted 3 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
[...]
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ pin->prop.description = kstrdup(prop->description, GFP_KERNEL); + if (!pin->prop.description) { + ret = -ENOMEM; + goto release; + } + if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC || + prop->type > DPLL_PIN_TYPE_MAX)) { + ret = -EINVAL; + goto release; + }Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 3 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in thiscase.
Quoted 1 line
Not sure if the pointer way is much better...
For things like this it is common to have static const array in the driver, like:
static const struct dpll_pin_properties dpll_pin_props[] = { { .description = "SMA0", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA1", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA2", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA3", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, };Here you have very nice list of pins, the reader knows right away what is happening.
Quoted 6 lines
Quoted 4 lines
Thinking about "description" name, I think would be more appropriate to name this "label" as it represents user-facing label on the connector, isn't it? Does not describe anything.
"label" seems good.
Ok.
Quoted 31 lines
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
[...]
Quoted 22 lines
Quoted 15 lines
drivers/dpll/Makefile
Quoted 12 lines
drivers/dpll/Makefile new file +10
-0+ const struct dpll_pin_properties *prop) +{ + struct dpll_pin *pos, *ret = NULL; + unsigned long index; + + mutex_lock(&dpll_pin_xa_lock); + xa_for_each(&dpll_pin_xa, index, pos) { + if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.I think
clock_id+dev_driver_id+ module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?
Quoted 6 lines
Quoted 4 lines
IDK, no strong opinion on this. I just thought it may help to identify the pin and avoid potential driver bugs. (Like registering 2 pins with the same properties).
It would make most sense if
pin_indexwould be a part of *prop.
Hmm. I see one example where it would not be suitable:
NIC with N physical ports. You, as a driver, register one pin per physical port. You have one static const prop and pass the pointer to if for every registration call of N pins, each time with different pin_index.
So from what I see, the prop describes a flavour of pin in the driver. In the exaple above, it is still the same SyncE pin, with the same ops. Only multiple instances of that distinguished by pin_index and priv.
Makes sense?
Quoted 35 lines
Quoted 35 lines
[...]
Quoted 31 lines
Quoted 30 lines
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+/** + * dpll_pin_register - register the dpll pin in the subsystem + * @dpll: pointer to a dpll + * @pin: pointer to a dpll pin + * @ops: ops for a dpll pin ops + * @priv: pointer to private information of owner + * @rclk_device: pointer to recovered clock devicedrivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ * + * Return: + * * 0 on success + * * -EINVAL - missing dpll or pin + * * -ENOMEM - failed to allocate memory + */ +int +dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv, + struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 3 lines
drivers/dpll/Makefile new file +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) :NULL;
If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Well, these questions go to Arkadiusz...
[ copy paste my answer from previous response ]
Does not help, see below.
Quoted 2 lines
If pin is able to recover signal from some device this shall convey that device struct pointer.
But one device (struct device instance) could easily have multiple netdev instances attached and therefore mutiple sources of recovered signal.
mlxsw driver is one of the examples of this 1:N mapping between device and netdev.
Quoted 7 lines
Name of that device is later passed to the user with
DPLL_A_PIN_RCLK_DEVICEattribute.
Sure we can have pointer to device and usedev_name(each do/dump) on netlink part. But isn't it better to have the name ready to use there?It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Very easily, auxiliary_bus. That is actually the case already for mlx5.
Quoted 4 lines
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
What is the motivation exactly? Is it only SyncE? In case it is, the link to the pin should be added from the other side, carried over RTNetlink msg of a netdev associated with pin. I will add a patch for this.
Do you need to expose any other recovered clock device source?
Quoted 72 lines
Quoted 31 lines
Okay.
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
+ *
dpll_pin_get_by_idx- find a pin ref on dpll by pin index
+ * @dpll: dpll device pointer
+ * @idx: index of pin
+ *
+ * Find a reference to a pin registered with given dpll and return its pointer.
+ *
+ * Return:
+ * * valid pointer if pin was found
+ * * NULL if not found
+ */drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx) +{ + struct dpll_pin_ref *pos; + unsigned long i; + + xa_for_each(&dpll->pin_refs, i, pos) { + if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 9 lines
Quoted 2 lines
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
No, driver can provide indexing which is completely up to his decision. You should use
xa_insert()to insert the entry at specific index. Seedevl_port_registerfor inspiration where it is done exactly like this.And this should be done in exactly the same way for both pin and device.
Yes, I agree seems doable and better then it is now.
[...]
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +2
-0+static int +dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device*dpll)
drivers/dpll/Makefile new file +2
-0+{ + if (nla_put_u32(msg, DPLL_A_ID, dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.Quoted 3 lines
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Wait, I don't get it. Could you please explain a bit more?
My point is, there should be not such ID exposed over netlink You don't need to expose it to userspace. The user has well defined handle as you agreed with above. For example:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2This is shown in dpll device GET/DUMP outputs.
Also user passes it during SET operation:$ dplltool set ice/c92d02a7129f4747/1 mode auto
Quoted 5 lines
Quoted 2 lines
Isn't that enough stable and nice?
I agree with Vadim, this is rather to be used by a daemon tools, which would get the index once, then could use it as long as device is there.
So basically you say, you can have 2 approaches in app:
1)
id = dpll_device_get_id("ice/c92d02a7129f4747/1") dpll_device_set(id, something); dpll_device_set(id, something); dpll_device_set(id, something);
2):dpll_device_set("ice/c92d02a7129f4747/1, something); dpll_device_set("ice/c92d02a7129f4747/1, something); dpll_device_set("ice/c92d02a7129f4747/1, something);
What is exactly benefit of the first one? Why to have 2 handles? Devlink is a nice example of 2) approach, no problem there.
Perhaps I'm missing something, but looks like you want the id for no good reason and this dual-handle scheme just makes things more complicated with 0 added value.
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
Quoted 13 lines
Quoted 13 lines
drivers/dpll/Makefile new file +2
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_BUS_NAME, dev_bus_name(&dpll-dev)))
drivers/dpll/Makefile new file +6
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_DEV_NAME, dev_name(&dpll->dev))) + return -EMSGSIZE; + + return 0; +}[...]
Quoted 9 lines
drivers/dpll/Makefile
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+ +static int +dpll_msg_add_pins_on_pin(struct sk_buff *msg, struct dpll_pin *pin, + struct netlink_ext_ack *extack) +{ + struct dpll_pin_ref *ref = NULL;Why this needs to be initialized?
No need, fixed.
Quoted 35 lines
Quoted 17 lines
drivers/dpll/Makefile new file +16
-0+ enum dpll_pin_state state; + struct nlattr *nest; + unsigned long index; + int ret; + + xa_for_each(&pin->parent_refs, index, ref) { + if (WARN_ON(!ref->ops->state_on_pin_get)) + return -EFAULT; + ret = ref->ops->state_on_pin_get(pin, ref->pin, &state, + extack); + if (ret) + return -EFAULT; + nest = nla_nest_start(msg, DPLL_A_PIN_PARENT); + if (!nest) + return -EMSGSIZE; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + if (nla_put_u8(msg, DPLL_A_PIN_STATE, state)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + nla_nest_end(msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/Did you get lost here as well? If yes, this needs some serious think through :)
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
[ copy paste my answer from previous response ]
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
Hmm, ok. I'm still lost a bit with all the referencing and cross referencing, I wonder if it could be made a bit simpler and/or easier to read and follow.
Quoted 13 lines
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.
Quoted 5 lines
Quoted 3 lines
Let's use "index" and "INDEX" internalla and in Netlink attr names as well then.
For me makes sense to have a common name instead of origin-based one.
What do you mean by this?
Quoted 36 lines
Quoted 36 lines
[...]
Quoted 12 lines
Quoted 11 lines
drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +5
-0+ int rem, ret = -EINVAL; + struct nlattr *a; + + nla_for_each_attr(a, genlmsg_data(info->genlhdr), + genlmsg_len(info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
Quoted 2 lines
I had some unknown crashes when I was using such access. I might have lost some checks, will try it again.
Odd, yet definitelly debuggable though :)
[...]
Quoted 11 lines
Quoted 7 lines
drivers/dpll/Makefile
Quoted 3 lines
drivers/dpll/Makefile new file +3
-0+int dpll_pin_pre_dumpit(struct netlink_callback *cb) +{ + mutex_lock(&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?
Quoted 7 lines
Quoted 4 lines
Well, here you can just call
dpll_pre_dumpit()beforemutex_lock(&dpll_pin_xa_lock)
to take the locks in the same order.This double lock doesn't really improve anything.
Any objections on having single mutex/lock for access the dpll subsystem?
Yeah, we had it in devlink and then we spent a lot of a time to get rid of it. Now we have per-instance locking. Here, it would be per-dpll-device locking.
No strong opinion, perhaps on case of dpll one master lock is enough. Perhaps Jakub would have some opinion on this.
Quoted 58 lines
Quoted 50 lines
Quoted 41 lines
Quoted 41 lines
Quoted 29 lines
drivers/dpll/Makefile new file +13
-0+ + return dpll_pre_dumpit(cb); +} + +int dpll_pin_post_dumpit(struct netlink_callback *cb) +{ + mutex_unlock(&dpll_pin_xa_lock); + + return dpll_post_dumpit(cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device*dpll,
drivers/dpll/Makefile new file +10
-0+ struct dpll_pin *pin, struct dpll_pin *parent, + enum dplla attr) +{ + int ret = dpll_msg_add_dev_handle(msg, dpll); + struct dpll_pin_ref *ref = NULL; + enum dpll_pin_state state; + + if (ret) + return ret; + if (pin && nla_put_u32(msg, DPLL_A_PIN_IDX, pin-
dev_driver_id))drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ return -EMSGSIZE;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 8 lines
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.Quoted 7 lines
Wait, are you saying that the app is stateless? Could you provide example use cases?
From what I see, the app managing dpll knows the state of the device and pins, it monitors for the changes and saves new state with appropriate reaction (might be some action or maybe just log entry).
Quoted 4 lines
It depends on the use case, right? App developer having those information knows what has changed, thus can react in a way it thinks is most suitable. IMHO from user perspective it is good to have a notification which actually shows it's reason, so proper flow could be assigned to handle the reaction.
Again, could you provide me specific example in which this is needed? I may be missing something, but I don't see how it can bring and benefit. It just makes the live of the app harder because it has to treat the get and notify messages differently.
It is quite common for app to:
init:
1) get object state
2) store it
3) apply configuration
runtime:
1) listen to object state change
2) store it
3) apply configuration
Same code for both.
Quoted 120 lines
Quoted 120 lines
Quoted 108 lines
Quoted 99 lines
Quoted 99 lines
drivers/dpll/Makefile new file +95
-0+ + switch (attr) { + case DPLL_A_MODE: + ret = dpll_msg_add_mode(msg, dpll, NULL); + break; + case DPLL_A_SOURCE_PIN_IDX: + ret = dpll_msg_add_source_pin_idx(msg, dpll, NULL); + break; + case DPLL_A_LOCK_STATUS: + ret = dpll_msg_add_lock_status(msg, dpll, NULL); + break; + case DPLL_A_TEMP: + ret = dpll_msg_add_temp(msg, dpll, NULL); + break; + case DPLL_A_PIN_FREQUENCY: + ret = dpll_msg_add_pin_freq(msg, pin, NULL, false); + break; + case DPLL_A_PIN_PRIO: + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_prio(msg, pin, ref, NULL); + break; + case DPLL_A_PIN_STATE: + if (parent) { + ref = dpll_xa_ref_pin_find(&pin->parent_refs, parent); + if (!ref) + return -EFAULT; + if (!ref->ops || !ref->ops->state_on_pin_get) + return -EOPNOTSUPP; + ret = ref->ops->state_on_pin_get(pin, parent, &state, + NULL); + if (ret) + return ret; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX, + parent->dev_driver_id)) + return -EMSGSIZE; + } else { + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_on_dpll_state(msg, pin, ref, + NULL); + if (ret) + return ret; + } + break; + default: + break; + } + + return ret; +} + +static int +dpll_send_event_create(enum dpll_event event, struct dpll_device *dpll) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, event); + if (!hdr) + goto out_free_msg; + + ret = dpll_msg_add_dev_handle(msg, dpll); + if (ret) + goto out_cancel_msg; + genlmsg_end(msg, hdr); + genlmsg_multicast(&dpll_nl_family, msg, 0, 0, GFP_KERNEL); + + return 0; + +out_cancel_msg: + genlmsg_cancel(msg, hdr); +out_free_msg: + nlmsg_free(msg); + + return ret; +} + +static int +dpll_send_event_change(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin *parent, enum dplla attr) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg)Quoted 8 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +4
-0+ return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, + DPLL_EVENT_DEVICE_CHANGE);I don't really get it. Why exactly you keep having this *EVENT* cmds? Why per-object NEW/GET/DEL cmds shared with get genl op are not enough? I have to be missing something.
Quoted 2 lines
Changes might come from other places, but will affect the DPLL device and we have to notify users in this case.
I'm not sure I follow. There are 2 scenarios for change:
1) user originated - user issues set of something
2) driver originated - something changes in HW, driver propagates thatWith what I suggest, both scenarios work of course. My point is, user knows very well the objects: device and pin, he knows the format or messages that are related to GET/DUMP/SET operations of both. The notification should have the same format, that is all I say.
Quoted 6 lines
Quoted 3 lines
Btw, you can see devlink code for example how the notifications like this are implemented and work.
Devlink packs all the info into a netlink message and notifies with it, isn't it that it has all the info "buffered" in its structures?
Not really. Ops are there as well.
Quoted 8 lines
A dpll subsystem keeps only some of the info in its internal structures, but for most of it it has to question the driver. It would do it multiple times i.e. if there would be a change on a pin connected to multiple dpll devices.
With current approach the notifications are pretty light to the subsystem as well as for the registered clients, and as you suggested with having info of what actually changed the userspace could implement a stateless daemon right away.
Okay, examples? I really can't see how this stateless deamon could be implemented, but perhaps I lack better imagination :/
Quoted 3 lines
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 7 lines · Wed, Mar 15, 2023 at 10:22:33AM CET, [email protected] wrote:
Quoted 6 lines · Tue, Mar 14, 2023 at 06:50:57PM CET, [email protected] wrote:
Quoted 6 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 10:22 AMQuoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
drivers/dpll/dpll_core.c line 513
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
I think
clock_id+dev_driver_id+ module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?IDK, no strong opinion on this. I just thought it may help to identify the pin and avoid potential driver bugs. (Like registering 2 pins with
Was thinking about this some more, I think that it would be good to store and check properties in case of pin_get() call. If the driver does call for the second time pin_get() for the same pin (clockid,pin_index) with different prop, it is buggy and WARN_ON should be triggered. WARN_ON check should compare the actual struct, not just pointer.
[...]
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 507 lines · Jiri Pirko
Quoted 71 lines · Tue, Mar 14, 2023 at 06:50:57PM CET, [email protected] wrote:
Quoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 10:22 AMQuoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +0
-0@@ -0,0 +1,10 @@Quoted 8 lines
drivers/dpll/Makefile line 6
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for DPLL drivers. +# + +obj-$(CONFIG_DPLL) += dpll_sys.oWhat's "sys" and why is it here?
Quoted 3 lines
It's an object file for the subsystem. Could be useful if we will have drivers
for DPLL-only devices.Yeah, but why "sys"? I don't get what "sys" means here. Can't this be just "dpll.o"?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/dpll/Makefile new file +4
-0+dpll_sys-y += dpll_core.o +dpll_sys-y += dpll_netlink.o +dpll_sys-y += dpll_nl.o +[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/dpll/Makefile new file +2
-0+struct dpll_device * +dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module*module)
drivers/dpll/Makefile new file +3
-0+{ + struct dpll_device *dpll, *ret = NULL; + unsigned long index;Quoted 8 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ + mutex_lock(&dpll_device_xa_lock); + xa_for_each(&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.Quoted 6 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is the same for both of them. But Arkadiusz can tell more about it.Okay, I see.
Clock_idis the same. Could we have index for pin, could this be index too:
dpll_device_get(u64 clock_id, u32 device_index, struct module *module); dpll_pin_get(u64clock_id, u32pin_index, struct module *module,const struct dpll_pin_properties *prop);Quoted 7 lines
Quoted 5 lines
This way it is consistent, driver provides custom index for both dpll device and dpll pin.
Makes sense?
IMHO, Yes this better shows the intentions.
Ok.
Quoted 195 lines
Quoted 195 lines
Quoted 6 lines
Quoted 4 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?Yeah, see above.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/Makefile new file +19
-0+ dpll->module == module) { + ret = dpll; + refcount_inc(&ret->refcount); + break; + } + } + if (!ret) + ret = dpll_device_alloc(clock_id, dev_driver_id, module); + mutex_unlock(&dpll_device_xa_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(dpll_device_get); + +/** + * dpll_device_put - decrease the refcount and free memory if possible + * @dpll: dpll_device struct pointer + * + * Drop reference for a dpll device, if all references are gone, deleteQuoted 8 lines
drivers/dpll/Makefile
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/Makefile new file +4
-0+void dpll_device_put(struct dpll_device *dpll) +{ + if (!dpll) + return;Remove this check. The driver should not call this with NULL.
Quoted 2 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.IDK, maybe for historical reasons. My point is, id driver is callin this with NULL, there is something odd in the driver flow. Lets not allow that for new code.
Quoted 67 lines
Quoted 6 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +3
-0+ mutex_lock(&dpll_device_xa_lock); + if (refcount_dec_and_test(&dpll->refcount)) { + WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Quoted 58 lines
Quoted 31 lines
drivers/dpll/Makefile new file +31
-0+ xa_destroy(&dpll->pin_refs); + xa_erase(&dpll_device_xa, dpll->id); + kfree(dpll); + } + mutex_unlock(&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL(dpll_device_put); + +/** + * dpll_device_register - register the dpll device in the subsystem + * @dpll: pointer to a dpll + * @type: type of a dpll + * @ops: ops for a dpll device + * @priv: pointer to private information of owner + * @owner: pointer to owner device + * + * Make dpll device available for user space. + * + * Return: + * * 0 on success + * * -EINVAL on failure + */ +int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, + struct dpll_device_ops *ops, void *priv, + struct device *owner) +{ + if (WARN_ON(!ops || !owner)) + return -EINVAL; + if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX)) + return -EINVAL; + mutex_lock(&dpll_device_xa_lock);drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ if (ASSERT_DPLL_NOT_REGISTERED(dpll)) { + mutex_unlock(&dpll_device_xa_lock); + return -EEXIST; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; + dev_set_name(&dpll->dev, "%s_%d", dev_name(owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Great.
Quoted 3 lines
Quoted 3 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
[...]
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ pin->prop.description = kstrdup(prop->description, GFP_KERNEL); + if (!pin->prop.description) { + ret = -ENOMEM; + goto release; + } + if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC || + prop->type > DPLL_PIN_TYPE_MAX)) { + ret = -EINVAL; + goto release; + }Quoted 9 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 3 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in thiscase.
Quoted 1 line
Not sure if the pointer way is much better...
For things like this it is common to have static const array in the driver, like:
static const struct dpll_pin_properties dpll_pin_props[] = { { .description = "SMA0", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA1", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA2", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, { .description = "SMA3", .freq_supported = DPLL_PIN_FREQ_SUPP_MAX, .type = DPLL_PIN_TYPE_EXT, .any_freq_max = 10000000, .capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE, }, };Here you have very nice list of pins, the reader knows right away what is happening.
Quoted 6 lines
Quoted 4 lines
Thinking about "description" name, I think would be more appropriate to name this "label" as it represents user-facing label on the connector, isn't it? Does not describe anything.
"label" seems good.
Ok.
Quoted 31 lines
Quoted 31 lines
Quoted 4 lines
Quoted 4 lines
[...]
Quoted 22 lines
Quoted 15 lines
drivers/dpll/Makefile
Quoted 12 lines
drivers/dpll/Makefile new file +10
-0+ const struct dpll_pin_properties *prop) +{ + struct dpll_pin *pos, *ret = NULL; + unsigned long index; + + mutex_lock(&dpll_pin_xa_lock); + xa_for_each(&dpll_pin_xa, index, pos) { + if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.I think
clock_id+dev_driver_id+ module should identify the pin exactly. And now I think that *prop is not needed here at all. Arkadiusz, any thoughts?Quoted 6 lines
Quoted 4 lines
IDK, no strong opinion on this. I just thought it may help to identify the pin and avoid potential driver bugs. (Like registering 2 pins with the same properties).
It would make most sense if
pin_indexwould be a part of *prop.Hmm. I see one example where it would not be suitable:
NIC with N physical ports. You, as a driver, register one pin per physical port. You have one static const prop and pass the pointer to if for every registration call of N pins, each time with differentpin_index.So from what I see, the prop describes a flavour of pin in the driver. In the exaple above, it is still the same SyncE pin, with the same ops. Only multiple instances of that distinguished by
pin_indexand priv.Makes sense?
Quoted 35 lines
Quoted 35 lines
[...]
Quoted 31 lines
Quoted 30 lines
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+/** + * dpll_pin_register - register the dpll pin in the subsystem + * @dpll: pointer to a dpll + * @pin: pointer to a dpll pin + * @ops: ops for a dpll pin ops + * @priv: pointer to private information of owner + * @rclk_device: pointer to recovered clock devicedrivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ * + * Return: + * * 0 on success + * * -EINVAL - missing dpll or pin + * * -ENOMEM - failed to allocate memory + */ +int +dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin_ops *ops, void *priv, + struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 3 lines
drivers/dpll/Makefile new file +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) :NULL;
If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Well, these questions go to Arkadiusz...
[ copy paste my answer from previous response ]
Does not help, see below.
Quoted 2 lines
If pin is able to recover signal from some device this shall convey that device struct pointer.
But one device (struct device instance) could easily have multiple netdev instances attached and therefore mutiple sources of recovered signal.
mlxsw driver is one of the examples of this 1:N mapping between device and netdev.
Quoted 7 lines
Name of that device is later passed to the user with
DPLL_A_PIN_RCLK_DEVICEattribute.
Sure we can have pointer to device and usedev_name(each do/dump) on netlink part. But isn't it better to have the name ready to use there?It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Very easily,
auxiliary_bus. That is actually the case already for mlx5.Quoted 4 lines
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
What is the motivation exactly? Is it only SyncE? In case it is, the link to the pin should be added from the other side, carried over RTNetlink msg of a netdev associated with pin. I will add a patch for this.
Do you need to expose any other recovered clock device source?
Quoted 72 lines
Quoted 31 lines
Okay.
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
+ *
dpll_pin_get_by_idx- find a pin ref on dpll by pin index
+ * @dpll: dpll device pointer
+ * @idx: index of pin
+ *
+ * Find a reference to a pin registered with given dpll and return its pointer.
+ *
+ * Return:
+ * * valid pointer if pin was found
+ * * NULL if not found
+ */drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx(struct dpll_device *dpll, u32 idx) +{ + struct dpll_pin_ref *pos; + unsigned long i; + + xa_for_each(&dpll->pin_refs, i, pos) { + if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 9 lines
Quoted 2 lines
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
No, driver can provide indexing which is completely up to his decision. You should use
xa_insert()to insert the entry at specific index. Seedevl_port_registerfor inspiration where it is done exactly like this.And this should be done in exactly the same way for both pin and device.
Yes, I agree seems doable and better then it is now.
[...]
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/Makefile
Quoted 5 lines
drivers/dpll/Makefile new file +2
-0+static int +dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device*dpll)
drivers/dpll/Makefile new file +2
-0+{ + if (nla_put_u32(msg, DPLL_A_ID, dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.Quoted 3 lines
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Wait, I don't get it. Could you please explain a bit more?
My point is, there should be not such ID exposed over netlink You don't need to expose it to userspace. The user has well defined handle as you agreed with above. For example:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2This is shown in dpll device GET/DUMP outputs.
Also user passes it during SET operation:$ dplltool set ice/c92d02a7129f4747/1 mode autoQuoted 5 lines
Quoted 2 lines
Isn't that enough stable and nice?
I agree with Vadim, this is rather to be used by a daemon tools, which would get the index once, then could use it as long as device is there.
So basically you say, you can have 2 approaches in app:
1)
id =dpll_device_get_id("ice/c92d02a7129f4747/1")dpll_device_set(id, something);dpll_device_set(id, something);dpll_device_set(id, something);
2):dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);
Quoted 6 lines
What is exactly benefit of the first one? Why to have 2 handles? Devlink is a nice example of 2) approach, no problem there.
Perhaps I'm missing something, but looks like you want the id for no good reason and this dual-handle scheme just makes things more complicated with 0 added value.
I would like to avoid any extra memory copies or memory checks when it's possible to compare single u32/u64 index value. I might be invisible on a single host setup, but running monitoring at scale which will parse and compare string on every get/event can burn a bit of compute capacity.
Quoted 231 lines
Quoted 66 lines
Quoted 66 lines
Quoted 66 lines
Quoted 15 lines
Quoted 15 lines
drivers/dpll/Makefile new file +2
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_BUS_NAME, dev_bus_name(&dpll-dev)))
drivers/dpll/Makefile new file +6
-0+ return -EMSGSIZE; + if (nla_put_string(msg, DPLL_A_DEV_NAME, dev_name(&dpll->dev))) + return -EMSGSIZE; + + return 0; +}[...]
Quoted 9 lines
drivers/dpll/Makefile
Quoted 6 lines
drivers/dpll/Makefile new file +6
-0+ +static int +dpll_msg_add_pins_on_pin(struct sk_buff *msg, struct dpll_pin *pin, + struct netlink_ext_ack *extack) +{ + struct dpll_pin_ref *ref = NULL;Why this needs to be initialized?
No need, fixed.
Quoted 35 lines
Quoted 17 lines
drivers/dpll/Makefile new file +16
-0+ enum dpll_pin_state state; + struct nlattr *nest; + unsigned long index; + int ret; + + xa_for_each(&pin->parent_refs, index, ref) { + if (WARN_ON(!ref->ops->state_on_pin_get)) + return -EFAULT; + ret = ref->ops->state_on_pin_get(pin, ref->pin, &state, + extack); + if (ret) + return -EFAULT; + nest = nla_nest_start(msg, DPLL_A_PIN_PARENT); + if (!nest) + return -EMSGSIZE; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/Makefile
Quoted 10 lines
drivers/dpll/Makefile new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + if (nla_put_u8(msg, DPLL_A_PIN_STATE, state)) { + ret = -EMSGSIZE; + goto nest_cancel; + } + nla_nest_end(msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/Did you get lost here as well? If yes, this needs some serious think through :)
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
[ copy paste my answer from previous response ]
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!Hmm, ok. I'm still lost a bit with all the referencing and cross referencing, I wonder if it could be made a bit simpler and/or easier to read and follow.
Quoted 13 lines
[...]
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.Quoted 5 lines
Quoted 3 lines
Let's use "index" and "INDEX" internalla and in Netlink attr names as well then.
For me makes sense to have a common name instead of origin-based one.
What do you mean by this?
Quoted 36 lines
Quoted 36 lines
[...]
Quoted 12 lines
Quoted 11 lines
drivers/dpll/Makefile
Quoted 7 lines
drivers/dpll/Makefile new file +5
-0+ int rem, ret = -EINVAL; + struct nlattr *a; + + nla_for_each_attr(a, genlmsg_data(info->genlhdr), + genlmsg_len(info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
Quoted 2 lines
I had some unknown crashes when I was using such access. I might have lost some checks, will try it again.
Odd, yet definitelly debuggable though :)
[...]
Quoted 11 lines
Quoted 7 lines
drivers/dpll/Makefile
Quoted 3 lines
drivers/dpll/Makefile new file +3
-0+int dpll_pin_pre_dumpit(struct netlink_callback *cb) +{ + mutex_lock(&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?Quoted 7 lines
Quoted 4 lines
Well, here you can just call
dpll_pre_dumpit()beforemutex_lock(&dpll_pin_xa_lock)
to take the locks in the same order.This double lock doesn't really improve anything.
Any objections on having single mutex/lock for access the dpll subsystem?Yeah, we had it in devlink and then we spent a lot of a time to get rid of it. Now we have per-instance locking. Here, it would be per-dpll-device locking.
No strong opinion, perhaps on case of dpll one master lock is enough. Perhaps Jakub would have some opinion on this.
Quoted 58 lines
Quoted 50 lines
Quoted 41 lines
Quoted 41 lines
Quoted 29 lines
drivers/dpll/Makefile new file +13
-0+ + return dpll_pre_dumpit(cb); +} + +int dpll_pin_post_dumpit(struct netlink_callback *cb) +{ + mutex_unlock(&dpll_pin_xa_lock); + + return dpll_post_dumpit(cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device*dpll,
drivers/dpll/Makefile new file +10
-0+ struct dpll_pin *pin, struct dpll_pin *parent, + enum dplla attr) +{ + int ret = dpll_msg_add_dev_handle(msg, dpll); + struct dpll_pin_ref *ref = NULL; + enum dpll_pin_state state; + + if (ret) + return ret; + if (pin && nla_put_u32(msg, DPLL_A_PIN_IDX, pin-
dev_driver_id))drivers/dpll/Makefile
Quoted 1 line
drivers/dpll/Makefile new file +1
-0+ return -EMSGSIZE;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 8 lines
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.Quoted 7 lines
Wait, are you saying that the app is stateless? Could you provide example use cases?
From what I see, the app managing dpll knows the state of the device and pins, it monitors for the changes and saves new state with appropriate reaction (might be some action or maybe just log entry).
Quoted 4 lines
It depends on the use case, right? App developer having those information knows what has changed, thus can react in a way it thinks is most suitable. IMHO from user perspective it is good to have a notification which actually shows it's reason, so proper flow could be assigned to handle the reaction.
Again, could you provide me specific example in which this is needed? I may be missing something, but I don't see how it can bring and benefit. It just makes the live of the app harder because it has to treat the get and notify messages differently.
It is quite common for app to:
init:
1) get object state
2) store it
3) apply configuration
runtime:
1) listen to object state change
2) store it
3) apply configuration
Quoted 1 line
Same code for both.
Well, I'm thinking about simple monitoring app which will wait for the events and create an alert if the changes coming from the event differ from the "allowed configs". In this case no real reason to store whole object state, but the changes in events are very useful.
Quoted 138 lines
Quoted 124 lines
Quoted 124 lines
Quoted 112 lines
Quoted 103 lines
Quoted 103 lines
drivers/dpll/Makefile new file +95
-0+ + switch (attr) { + case DPLL_A_MODE: + ret = dpll_msg_add_mode(msg, dpll, NULL); + break; + case DPLL_A_SOURCE_PIN_IDX: + ret = dpll_msg_add_source_pin_idx(msg, dpll, NULL); + break; + case DPLL_A_LOCK_STATUS: + ret = dpll_msg_add_lock_status(msg, dpll, NULL); + break; + case DPLL_A_TEMP: + ret = dpll_msg_add_temp(msg, dpll, NULL); + break; + case DPLL_A_PIN_FREQUENCY: + ret = dpll_msg_add_pin_freq(msg, pin, NULL, false); + break; + case DPLL_A_PIN_PRIO: + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_prio(msg, pin, ref, NULL); + break; + case DPLL_A_PIN_STATE: + if (parent) { + ref = dpll_xa_ref_pin_find(&pin->parent_refs, parent); + if (!ref) + return -EFAULT; + if (!ref->ops || !ref->ops->state_on_pin_get) + return -EOPNOTSUPP; + ret = ref->ops->state_on_pin_get(pin, parent, &state, + NULL); + if (ret) + return ret; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX, + parent->dev_driver_id)) + return -EMSGSIZE; + } else { + ref = dpll_xa_ref_dpll_find(&pin->dpll_refs, dpll); + if (!ref) + return -EFAULT; + ret = dpll_msg_add_pin_on_dpll_state(msg, pin, ref, + NULL); + if (ret) + return ret; + } + break; + default: + break; + } + + return ret; +} + +static int +dpll_send_event_create(enum dpll_event event, struct dpll_device *dpll) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, event); + if (!hdr) + goto out_free_msg; + + ret = dpll_msg_add_dev_handle(msg, dpll); + if (ret) + goto out_cancel_msg; + genlmsg_end(msg, hdr); + genlmsg_multicast(&dpll_nl_family, msg, 0, 0, GFP_KERNEL); + + return 0; + +out_cancel_msg: + genlmsg_cancel(msg, hdr); +out_free_msg: + nlmsg_free(msg); + + return ret; +} + +static int +dpll_send_event_change(struct dpll_device *dpll, struct dpll_pin *pin, + struct dpll_pin *parent, enum dplla attr) +{ + struct sk_buff *msg; + int ret = -EMSGSIZE; + void *hdr; + + msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); + if (!msg)Quoted 8 lines
drivers/dpll/Makefile
Quoted 4 lines
drivers/dpll/Makefile new file +4
-0+ return -ENOMEM; + + hdr = genlmsg_put(msg, 0, 0, &dpll_nl_family, 0, + DPLL_EVENT_DEVICE_CHANGE);I don't really get it. Why exactly you keep having this *EVENT* cmds? Why per-object NEW/GET/DEL cmds shared with get genl op are not enough? I have to be missing something.
Quoted 2 lines
Changes might come from other places, but will affect the DPLL device and we have to notify users in this case.
I'm not sure I follow. There are 2 scenarios for change:
1) user originated - user issues set of something
2) driver originated - something changes in HW, driver propagates thatWith what I suggest, both scenarios work of course. My point is, user knows very well the objects: device and pin, he knows the format or messages that are related to GET/DUMP/SET operations of both. The notification should have the same format, that is all I say.
Quoted 6 lines
Quoted 3 lines
Btw, you can see devlink code for example how the notifications like this are implemented and work.
Devlink packs all the info into a netlink message and notifies with it, isn't it that it has all the info "buffered" in its structures?
Not really. Ops are there as well.
Quoted 4 lines
A dpll subsystem keeps only some of the info in its internal structures, but for most of it it has to question the driver. It would do it multiple times i.e. if there would be a change on a pin connected to multiple dpll devices.
Quoted 12 lines
Quoted 4 lines
With current approach the notifications are pretty light to the subsystem as well as for the registered clients, and as you suggested with having info of what actually changed the userspace could implement a stateless daemon right away.
Okay, examples? I really can't see how this stateless deamon could be implemented, but perhaps I lack better imagination :/
Quoted 3 lines
Thank you,
Arkadiusz
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 8 lines · Tue, Mar 28, 2023 at 05:22:04PM CEST, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 6 lines · Tue, Mar 14, 2023 at 06:50:57PM CET, [email protected] wrote:
Quoted 6 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 10:22 AMQuoted 2 lines · Mon, Mar 13, 2023 at 11:59:32PM CET, [email protected] wrote:
Quoted 1 line · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 47 lines
Quoted 47 lines
Quoted 27 lines
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+static int +dpll_msg_add_dev_handle(struct sk_buff *msg, const struct dpll_device*dpll)
(quoted diff) +2
-0+{ + if (nla_put_u32(msg, DPLL_A_ID, dpll->id))Why exactly do we need this dua--handle scheme? Why do you need unpredictable
DPLL_A_IDto be exposed to userspace? It's just confusing.Quoted 3 lines
To be able to work with DPLL per integer after iterator on the list deducts which DPLL device is needed. It can reduce the amount of memory copies and simplify comparisons. Not sure why it's confusing.
Wait, I don't get it. Could you please explain a bit more?
My point is, there should be not such ID exposed over netlink You don't need to expose it to userspace. The user has well defined handle as you agreed with above. For example:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2This is shown in dpll device GET/DUMP outputs.
Also user passes it during SET operation:$ dplltool set ice/c92d02a7129f4747/1 mode autoQuoted 5 lines
Quoted 2 lines
Isn't that enough stable and nice?
I agree with Vadim, this is rather to be used by a daemon tools, which would get the index once, then could use it as long as device is there.
So basically you say, you can have 2 approaches in app:
1)
id =dpll_device_get_id("ice/c92d02a7129f4747/1")dpll_device_set(id, something);dpll_device_set(id, something);dpll_device_set(id, something);
2):dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);What is exactly benefit of the first one? Why to have 2 handles? Devlink is a nice example of 2) approach, no problem there.
Quoted 8 lines
Quoted 3 lines
Perhaps I'm missing something, but looks like you want the id for no good reason and this dual-handle scheme just makes things more complicated with 0 added value.
I would like to avoid any extra memory copies or memory checks when it's possible to compare single u32/u64 index value. I might be invisible on a single host setup, but running monitoring at scale which will parse and compare string on every get/event can burn a bit of compute capacity.
Wait, that does not make any sense what so ever.
Show me numbers and real usecase. A sane app gets once at start, then processes notifications. You have a flow where string compare on a netlink command makes difference to int compare? Like tens of thousands of netlink cmds per second? I doubt that. If yes, it is a misuse. Btw, the string compare would be your last problem comparing the overhead of Netlink processing with ioctl for example.
Your dual handle scheme just adds complexicity, confusion with 0 added value. Please drop it. I really don't understand the need to defend this odd approach :/
[...]
Quoted 74 lines
Quoted 74 lines
Quoted 54 lines
Quoted 46 lines
Quoted 37 lines
Quoted 37 lines
Quoted 25 lines
(quoted diff) +13
-0+ + return dpll_pre_dumpit(cb); +} + +int dpll_pin_post_dumpit(struct netlink_callback *cb) +{ + mutex_unlock(&dpll_pin_xa_lock); + + return dpll_post_dumpit(cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device*dpll,
(quoted diff) +10
-0+ struct dpll_pin *pin, struct dpll_pin *parent, + enum dplla attr) +{ + int ret = dpll_msg_add_dev_handle(msg, dpll); + struct dpll_pin_ref *ref = NULL; + enum dpll_pin_state state; + + if (ret) + return ret; + if (pin && nla_put_u32(msg, DPLL_A_PIN_IDX, pin-
dev_driver_id))Review
Quoted 1 line
(quoted diff) +1
-0+ return -EMSGSIZE;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 8 lines
Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
But with full object-snapshot user space app will lose the information about what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.Quoted 7 lines
Wait, are you saying that the app is stateless? Could you provide example use cases?
From what I see, the app managing dpll knows the state of the device and pins, it monitors for the changes and saves new state with appropriate reaction (might be some action or maybe just log entry).
Quoted 4 lines
It depends on the use case, right? App developer having those information knows what has changed, thus can react in a way it thinks is most suitable. IMHO from user perspective it is good to have a notification which actually shows it's reason, so proper flow could be assigned to handle the reaction.
Again, could you provide me specific example in which this is needed? I may be missing something, but I don't see how it can bring and benefit. It just makes the live of the app harder because it has to treat the get and notify messages differently.
It is quite common for app to:
init:
1) get object state
2) store it
3) apply configuration
runtime:
1) listen to object state change
2) store it
3) apply configuration
Quoted 6 lines
Quoted 1 line
Same code for both.
Well, I'm thinking about simple monitoring app which will wait for the events and create an alert if the changes coming from the event differ from the "allowed configs". In this case no real reason to store whole object state, but the changes in events are very useful.
No problem. But as I wrote elsewhere in this thread, make sure that msg format of a change message is the same as the format of get cmd message. Basically think of it as a get cmd message filtered to have only attrs which changed. Same nesting and everything. Makes it simple for the app to have same parsing code for get/dump/notification messages.
[...]
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 11 lines · On Wed, 15 Mar 2023 10:22:33 +0100 Jiri Pirko wrote:
So basically you say, you can have 2 approaches in app:
1)
id =dpll_device_get_id("ice/c92d02a7129f4747/1")dpll_device_set(id, something);dpll_device_set(id, something);dpll_device_set(id, something);
2):dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);
Quoted 2 lines
What is exactly benefit of the first one? Why to have 2 handles? Devlink is a nice example of 2) approach, no problem there.
IMHO for devlink the neatness of using the name came from the fact that the device name was meaningful.
With the advent of auxbus that's no longer the case.
In fact it seems more than likely that changing the name to auxbus will break FW update scripts. Maybe nobody has complained yet only because prod adoption of these APIs is generally lacking :(
I agree that supporting both name and ID is pointless, user space can translate between the two trivially all by itself. But I'd lean towards deleting the name support not the ID support :(
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 20 lines · Mon, Apr 03, 2023 at 08:18:12PM CEST, [email protected] wrote:
Quoted 11 lines · On Wed, 15 Mar 2023 10:22:33 +0100 Jiri Pirko wrote:
So basically you say, you can have 2 approaches in app:
1)
id =dpll_device_get_id("ice/c92d02a7129f4747/1")dpll_device_set(id, something);dpll_device_set(id, something);dpll_device_set(id, something);
2):dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);dpll_device_set("ice/c92d02a7129f4747/1, something);Quoted 2 lines
What is exactly benefit of the first one? Why to have 2 handles? Devlink is a nice example of 2) approach, no problem there.
IMHO for devlink the neatness of using the name came from the fact that the device name was meaningful.
With the advent of auxbus that's no longer the case.
Quoted 7 lines
In fact it seems more than likely that changing the name to auxbus will break FW update scripts. Maybe nobody has complained yet only because prod adoption of these APIs is generally lacking :(
I agree that supporting both name and ID is pointless, user space can translate between the two trivially all by itself. But I'd lean towards deleting the name support not the ID support :(
Wait, not sure you get the format of the "name". It does not contain any bus address, so the auxdev issue you pointed out is not applicable. It is driver/clock_id/index.
All 3 are stable and user can rely on them. Do you see any issue in that?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 9 lines · Tue, Apr 11, 2023 at 12:31:49AM CEST, [email protected] wrote:
Quoted 5 lines · On Sun, 9 Apr 2023 09:51:48 +0200 Jiri Pirko wrote:
Wait, not sure you get the format of the "name". It does not contain any bus address, so the auxdev issue you pointed out is not applicable. It is driver/clock_id/index.
All 3 are stable and user can rely on them. Do you see any issue in that?What is index? I thought you don't want an index and yet there is one, just scoped by random attributes :(
Index internal within a single instance. Like Intel guys, they have 1 clock wired up with multiple DPLLs. The driver gives every DPLL index. This is internal, totally up to the driver decision. Similar concept to devlink port index.
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 8 lines · Jiri Pirko
Quoted 7 lines · Tue, Apr 11, 2023 at 12:31:49AM CEST, [email protected] wrote:
Quoted 5 lines · On Sun, 9 Apr 2023 09:51:48 +0200 Jiri Pirko wrote:
Wait, not sure you get the format of the "name". It does not contain any bus address, so the auxdev issue you pointed out is not applicable. It is driver/clock_id/index.
All 3 are stable and user can rely on them. Do you see any issue in that?
Quoted 7 lines
Quoted 2 lines
What is index? I thought you don't want an index and yet there is one, just scoped by random attributes :(
Index internal within a single instance. Like Intel guys, they have 1 clock wired up with multiple DPLLs. The driver gives every DPLL index. This is internal, totally up to the driver decision. Similar concept to devlink port index.
It feels like a dead-lock in conversation here. We have to agree on something because for now it's the only blocker to post the next version with all the comments from the previous one addressed in the code. My position here is that I'm ok to have any of the properties being an identifier as well as keep both of them, the code already has all the lines to support any decision. I just to want to go back to this part again in the next iteration.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Paolo Abeni
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Hi,
Quoted 11 lines · Jakub Kicinski
[resend with fixed CC list]
Quoted 7 lines · On Sun, 16 Apr 2023 18:23:15 +0200 Jiri Pirko wrote:
Quoted 2 lines
What is index? I thought you don't want an index and yet there is one, just scoped by random attributes :(
Index internal within a single instance. Like Intel guys, they have 1 clock wired up with multiple DPLLs. The driver gives every DPLL index. This is internal, totally up to the driver decision. Similar concept to devlink port index.
Quoted 4 lines
devlink port index ended up as a pretty odd beast with drivers encoding various information into it, using locally grown schemes.
Hard no on doing that in dpll, it should not be exposed to the user.
I'm replying here just in case the even the above reply was lost.
I guess the last remark resolved this specific discussion.
@Vadim, @Arkadiusz, even if net-next is currently closed, there are no restrictions for RFC patches: feel free to share v7 when it fits you better!
Thanks,
Paolo
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 19 lines · Paolo Abeni
Hi,
Quoted 11 lines · Jakub Kicinski
[resend with fixed CC list]
Quoted 7 lines · On Sun, 16 Apr 2023 18:23:15 +0200 Jiri Pirko wrote:
Quoted 2 lines
What is index? I thought you don't want an index and yet there is one, just scoped by random attributes :(
Index internal within a single instance. Like Intel guys, they have 1 clock wired up with multiple DPLLs. The driver gives every DPLL index. This is internal, totally up to the driver decision. Similar concept to devlink port index.
Quoted 4 lines
devlink port index ended up as a pretty odd beast with drivers encoding various information into it, using locally grown schemes.
Hard no on doing that in dpll, it should not be exposed to the user.
Quoted 7 lines
I'm replying here just in case the even the above reply was lost.
I guess the last remark resolved this specific discussion.
@Vadim, @Arkadiusz, even if net-next is currently closed, there are no restrictions for RFC patches: feel free to share v7 when it fits you better!
Hi Paolo!
Thanks for reminder, the new version is almost ready, I was a bit distracted by other burning issues. Hopefully I'll publish it till the end of the week.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
A message that is not in the archive (sent off-list or not yet received): ZFDPaXlJainSOqmV@nanopsycho
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Adding back the cclist stripped due to Claws bug.
Quoted 9 lines · Tue, May 02, 2023 at 05:32:44PM CEST, [email protected] wrote:
Quoted 8 lines · On Tue, 2 May 2023 10:52:57 +0200 Jiri Pirko wrote:
Quoted 8 lines
Quoted 4 lines
Index internal within a single instance. Like Intel guys, they have 1 clock wired up with multiple DPLLs. The driver gives every DPLL index. This is internal, totally up to the driver decision. Similar concept to devlink port index.
devlink port index ended up as a pretty odd beast with drivers encoding various information into it, using locally grown schemes.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Hard no on doing that in dpll, it should not be exposed to the user.
So you say to have ID fully dynamic and non deterministic? I'm lost a bit.
Yup, non-deterministic, just a cyclic ID allocated by the core starting from 1. Finding the right device / pin needs to be done via informational attributes not making assumptions about the ID.
Okay.
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tuple
The first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)
Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
What am I missing here?
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 4 lines · On Wed, 3 May 2023 09:56:57 +0200 Jiri Pirko wrote:
Quoted 3 lines
Yup, non-deterministic, just a cyclic ID allocated by the core starting from 1. Finding the right device / pin needs to be done via informational attributes not making assumptions about the ID.
Quoted 8 lines
Okay.
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
No scoped idx.
Quoted 10 lines
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tupleThe first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
Sure, we don't _have_ to have an ID, but it seems go against normal data normalization rules. And I don't see any harm in it.
But you're asking for per-device "idx" and that's a no-go for me, given already cited experience.
The user space can look up the ID based on identifying information it has. IMO it's better to support multiple different intelligible elements than single integer index into which drivers will start encoding all sort of info, using locally invented schemes.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 7 lines · Thu, May 04, 2023 at 04:16:43AM CEST, [email protected] wrote:
Quoted 6 lines · On Wed, 3 May 2023 09:56:57 +0200 Jiri Pirko wrote:
Quoted 3 lines
Yup, non-deterministic, just a cyclic ID allocated by the core starting from 1. Finding the right device / pin needs to be done via informational attributes not making assumptions about the ID.
Okay.
Quoted 8 lines
Quoted 6 lines
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
No scoped idx.
That means, no index defined by a driver if I undestand you correctly, right?
Quoted 12 lines
Quoted 11 lines
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tupleThe first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
Quoted 8 lines
Sure, we don't _have_ to have an ID, but it seems go against normal data normalization rules. And I don't see any harm in it.
But you're asking for per-device "idx" and that's a no-go for me, given already cited experience.
The user space can look up the ID based on identifying information it has. IMO it's better to support multiple different intelligible elements
Do you mean fixed tuple or variable tuple?
CMD_GET_ID
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_ID
CMD_GET_PIN_ID
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_PIN_ID
Quoted 2 lines
than single integer index into which drivers will start encoding all sort of info, using locally invented schemes.
There could be multiple DPLL and pin instances for a single module/clock_id tuple we have to distinguish somehow. If the driver can't pass "index" of DPLL or a pin, how we distinguish them?
Plus is is possible that 2 driver instances share the same dpll instance, then to get the dpll pointer reference, they do:
INSTANCE A:dpll_0 = dpll_device_get(clock_id, 0, THIS_MODULE); dpll_1 = dpll_device_get(clock_id, 1, THIS_MODULE);
INSTANCE B:dpll_0 = dpll_device_get(clock_id, 0, THIS_MODULE); dpll_1 = dpll_device_get(clock_id, 1, THIS_MODULE);
My point is, event if we don't expose the index to the userspace, we need to have it internally.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 39 lines · Thu, May 04, 2023 at 01:00:42PM CEST, [email protected] wrote:
Quoted 7 lines · Thu, May 04, 2023 at 04:16:43AM CEST, [email protected] wrote:
Quoted 6 lines · On Wed, 3 May 2023 09:56:57 +0200 Jiri Pirko wrote:
Quoted 3 lines
Yup, non-deterministic, just a cyclic ID allocated by the core starting from 1. Finding the right device / pin needs to be done via informational attributes not making assumptions about the ID.
Okay.
Quoted 8 lines
Quoted 6 lines
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
No scoped idx.
That means, no index defined by a driver if I undestand you correctly, right?
Quoted 18 lines
Quoted 11 lines
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tupleThe first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
Sure, we don't _have_ to have an ID, but it seems go against normal data normalization rules. And I don't see any harm in it.
But you're asking for per-device "idx" and that's a no-go for me, given already cited experience.
Quoted 8 lines
Quoted 2 lines
The user space can look up the ID based on identifying information it has. IMO it's better to support multiple different intelligible elements
Do you mean fixed tuple or variable tuple?
CMD_GET_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
Sorry, I hit the send button by a mistake.
I ment to add a question here:
What is the next intelligible element to identify DPLL device here?
Quoted 5 lines
<-
DPLL_A_ID
CMD_GET_PIN_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
What is the next intelligible element to identify a pin here?
Quoted 24 lines
<-
DPLL_A_PIN_IDQuoted 2 lines
than single integer index into which drivers will start encoding all sort of info, using locally invented schemes.
There could be multiple DPLL and pin instances for a single module/clock_id tuple we have to distinguish somehow. If the driver can't pass "index" of DPLL or a pin, how we distinguish them?
Plus is is possible that 2 driver instances share the same dpll instance, then to get the dpll pointer reference, they do:
INSTANCE A:dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);INSTANCE B:
dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);My point is, event if we don't expose the index to the userspace, we need to have it internally.
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 7 lines · On Thu, 4 May 2023 13:00:42 +0200 Jiri Pirko wrote:
Quoted 6 lines · Thu, May 04, 2023 at 04:16:43AM CEST, [email protected] wrote:
Quoted 5 lines · On Wed, 3 May 2023 09:56:57 +0200 Jiri Pirko wrote:
Okay.
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
No scoped idx.
That means, no index defined by a driver if I undestand you correctly, right?
Yes, my suggestion did not include a scoped index with no globally defined semantics.
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tupleThe first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
Quoted 8 lines
Sure, we don't _have_ to have an ID, but it seems go against normal data normalization rules. And I don't see any harm in it.
But you're asking for per-device "idx" and that's a no-go for me, given already cited experience.
The user space can look up the ID based on identifying information it has. IMO it's better to support multiple different intelligible elements
Quoted 7 lines
Do you mean fixed tuple or variable tuple?
CMD_GET_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_IDWhat is the next intelligible element to identify DPLL device here?
I don't know. We can always add more as needed.
We presuppose that the devices are identifiable, so whatever info is used to identify them goes here.
Quoted 7 lines
<-
DPLL_A_ID
CMD_GET_PIN_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_IDWhat is the next intelligible element to identify a pin here?
Same answer. Could be a name of the pin according to ASIC docs. Could be the ball name for a BGA package. Anything that's meaningful.
My point is that we don't want a field simply called "index". Because then for one vendor it will mean Ethernet port, for another SMA connector number and for the third pin of the package. Those are different attributes.
Quoted 15 lines
<-
DPLL_A_PIN_IDQuoted 2 lines
than single integer index into which drivers will start encoding all sort of info, using locally invented schemes.
There could be multiple DPLL and pin instances for a single module/clock_id tuple we have to distinguish somehow. If the driver can't pass "index" of DPLL or a pin, how we distinguish them?
Plus is is possible that 2 driver instances share the same dpll instance, then to get the dpll pointer reference, they do:
INSTANCE A:dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);
Quoted 6 lines
INSTANCE B:
dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);My point is, event if we don't expose the index to the userspace, we need to have it internally.
That's fine, I guess. I'd prefer driver matching to be the same as user space matching to force driver authors to have the same perspective as the user. But a "driver coookie" not visible to user space it probably fine.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 12 lines · Thu, May 04, 2023 at 06:04:01PM CEST, [email protected] wrote:
Quoted 11 lines · On Thu, 4 May 2023 13:00:42 +0200 Jiri Pirko wrote:
Quoted 10 lines · Thu, May 04, 2023 at 04:16:43AM CEST, [email protected] wrote:
Quoted 8 lines · On Wed, 3 May 2023 09:56:57 +0200 Jiri Pirko wrote:
Okay.
When netdev will have pin ID in the RT netlink message (as it is done in RFCv7), it is easy to get the pin/dpll for netdev. No problem there.
However, for non-SyncE usecase, how do you imagine scripts to work? I mean, the script have to obtain dpll/pin ID by deterministic module_name/clock_id/idx tuple.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
No scoped idx.
That means, no index defined by a driver if I undestand you correctly, right?
Yes, my suggestion did not include a scoped index with no globally defined semantics.
Okay, makes sense. Devlink port index didn't end up well :/
Quoted 27 lines
Quoted 26 lines
Quoted 12 lines
Quoted 11 lines
There are 2 options to do that:
1) dump all dplls/pins and do lookup in userspace
2) get a dpll/pin according to given module_name/clock_id/idx tupleThe first approach is not very nice.
The currently pushed RFCv7 of the patchset does not support 2)Now if we add support for 2), we basically use module_name/clock_id/idx as a handle for "get cmd". My point is, why can't we use it for "set cmd" as well and avoid the ID entirely?
Quoted 8 lines
Sure, we don't _have_ to have an ID, but it seems go against normal data normalization rules. And I don't see any harm in it.
But you're asking for per-device "idx" and that's a no-go for me, given already cited experience.
The user space can look up the ID based on identifying information it has. IMO it's better to support multiple different intelligible elements
Do you mean fixed tuple or variable tuple?
CMD_GET_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
Quoted 5 lines
Quoted 1 line
What is the next intelligible element to identify DPLL device here?
I don't know. We can always add more as needed.
We presuppose that the devices are identifiable, so whatever info is used to identify them goes here.
Allright. So in case of ptp_ocp and mlx5, module_name and clock_id are enough. In case of ice, DPLL_A_TYPE, attr is the one to make distinction between the 2 dpll instances there
So for now, we can have:
CMD_GET_ID
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<- DPLL_A_ID
if user passes a subset which would not provide a single match, we error out with -EINVAL and proper exack message. Makes sense?
Quoted 11 lines
Quoted 8 lines
<-
DPLL_A_ID
CMD_GET_PIN_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_IDWhat is the next intelligible element to identify a pin here?
Same answer. Could be a name of the pin according to ASIC docs. Could be the ball name for a BGA package. Anything that's meaningful.
Okay, for pin, the type and label would probably do:
CMD_GET_PIN_ID
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_LABEL
<- DPLL_A_PIN_ID
Again, if user passes a subset which would not provide a single match, we error out with -EINVAL and proper exack message.
If there is only one pin for example, user query of DPLL_A_MODULE_NAME and DPLL_A_CLOCK_ID would do return a single match. No need to pass anything else.
I think this could work with both ice and ptp_ocp, correct guys?
For mlx5, I will have 2 or more pins with same module name, clock id and type. For these SyncE pins the label does not really make sense. But I don't have to query, because the PIN_ID is going to be exposed for netdev over RT netlink. Clicks.
Makes sense?
Quoted 5 lines
My point is that we don't want a field simply called "index". Because then for one vendor it will mean Ethernet port, for another SMA connector number and for the third pin of the package. Those are different attributes.
Got you and agree.
Quoted 20 lines
Quoted 20 lines
<-
DPLL_A_PIN_IDQuoted 2 lines
than single integer index into which drivers will start encoding all sort of info, using locally invented schemes.
There could be multiple DPLL and pin instances for a single module/clock_id tuple we have to distinguish somehow. If the driver can't pass "index" of DPLL or a pin, how we distinguish them?
Plus is is possible that 2 driver instances share the same dpll instance, then to get the dpll pointer reference, they do:
INSTANCE A:dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);INSTANCE B:
dpll_0=dpll_device_get(clock_id, 0, THIS_MODULE);dpll_1=dpll_device_get(clock_id, 1, THIS_MODULE);
Quoted 7 lines
Quoted 2 lines
My point is, event if we don't expose the index to the userspace, we need to have it internally.
That's fine, I guess. I'd prefer driver matching to be the same as user space matching to force driver authors to have the same perspective as the user. But a "driver coookie" not visible to user space it probably fine.
Allright, lets leave them for now. As internal kernel API, could be changed in the future if needed.
Arkadiusz, Vadim, are you following this?
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 18 lines · On Thu, 4 May 2023 19:51:38 +0200 Jiri Pirko wrote:
Quoted 5 lines
Quoted 1 line
What is the next intelligible element to identify DPLL device here?
I don't know. We can always add more as needed.
We presuppose that the devices are identifiable, so whatever info is used to identify them goes here.Allright. So in case of
ptp_ocpand mlx5,module_nameandclock_idare enough. In case of ice,DPLL_A_TYPE, attr is the one to make distinction between the 2 dpll instances thereSo for now, we can have:
CMD_GET_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<-DPLL_A_ID
Quoted 2 lines
if user passes a subset which would not provide a single match, we error out with
-EINVALand proper exack message. Makes sense?
Yup, that sounds good to me.
Quoted 9 lines
Quoted 2 lines
Same answer. Could be a name of the pin according to ASIC docs. Could be the ball name for a BGA package. Anything that's meaningful.
Okay, for pin, the type and label would probably do:
CMD_GET_PIN_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_LABEL
Label sounds dangerously open ended, too. Would that be the SMA connector label (i.e. front panel label)? Or also applicable to internal pins? It'd be easier to talk details if we had the user facing documentation that ships with these products.
Quoted 17 lines
<- DPLL_A_PIN_IDAgain, if user passes a subset which would not provide a single match, we error out with
-EINVALand proper exack message.If there is only one pin for example, user query of
DPLL_A_MODULE_NAMEandDPLL_A_CLOCK_IDwould do return a single match. No need to pass anything else.I think this could work with both ice and
ptp_ocp, correct guys?For mlx5, I will have 2 or more pins with same module name, clock id and type. For these SyncE pins the label does not really make sense. But I don't have to query, because the
PIN_IDis going to be exposed for netdev over RT netlink. Clicks.Makes sense?
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 27 lines · Thu, May 04, 2023 at 08:44:21PM CEST, [email protected] wrote:
Quoted 18 lines · On Thu, 4 May 2023 19:51:38 +0200 Jiri Pirko wrote:
Quoted 5 lines
Quoted 1 line
What is the next intelligible element to identify DPLL device here?
I don't know. We can always add more as needed.
We presuppose that the devices are identifiable, so whatever info is used to identify them goes here.Allright. So in case of
ptp_ocpand mlx5,module_nameandclock_idare enough. In case of ice,DPLL_A_TYPE, attr is the one to make distinction between the 2 dpll instances thereSo for now, we can have:
CMD_GET_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<-DPLL_A_IDQuoted 2 lines
if user passes a subset which would not provide a single match, we error out with
-EINVALand proper exack message. Makes sense?Yup, that sounds good to me.
Quoted 3 lines
Quoted 2 lines
Same answer. Could be a name of the pin according to ASIC docs. Could be the ball name for a BGA package. Anything that's meaningful.
Quoted 8 lines
Quoted 6 lines
Okay, for pin, the type and label would probably do:
CMD_GET_PIN_ID
->DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_LABELLabel sounds dangerously open ended, too. Would that be the SMA
Well, every string is. And past RFCs of this patchset demonstrated guys did serialize a lot of stuff in strings.
Quoted 3 lines
connector label (i.e. front panel label)? Or also applicable to internal pins? It'd be easier to talk details if we had the user facing documentation that ships with these products.
I think is is use case specific. Some of the pins face the user over physical port, they it is a front panel label. Others are internal names. I have no clue how to define and mainly enforce rules here.
But as an example, if you have 2 pins of the same type, only difference is they are connected to front panel connector "A" and "B", this is the label you have to pass to the ID query. Do you see any other way?
Quoted 18 lines
Quoted 18 lines
<- DPLL_A_PIN_IDAgain, if user passes a subset which would not provide a single match, we error out with
-EINVALand proper exack message.If there is only one pin for example, user query of
DPLL_A_MODULE_NAMEandDPLL_A_CLOCK_IDwould do return a single match. No need to pass anything else.I think this could work with both ice and
ptp_ocp, correct guys?For mlx5, I will have 2 or more pins with same module name, clock id and type. For these SyncE pins the label does not really make sense. But I don't have to query, because the
PIN_IDis going to be exposed for netdev over RT netlink. Clicks.Makes sense?
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 7 lines · On Fri, 5 May 2023 12:41:11 +0200 Jiri Pirko wrote:
Quoted 3 lines
connector label (i.e. front panel label)? Or also applicable to internal pins? It'd be easier to talk details if we had the user facing documentation that ships with these products.
I think is is use case specific. Some of the pins face the user over physical port, they it is a front panel label. Others are internal names. I have no clue how to define and mainly enforce rules here.
It should be pretty easy to judge if we see the user-facing documentation vendors have.
Quoted 3 lines
But as an example, if you have 2 pins of the same type, only difference is they are connected to front panel connector "A" and "B", this is the label you have to pass to the ID query. Do you see any other way?
Sound perfectly fine, if it's a front panel label, let's call the attribute DPLL_A_PIN_FRONT_PANEL_LABEL. If the pin is not brought out to the front panel it will not have this attr. For other type of labels we should have different attributes.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 11 lines · Fri, May 05, 2023 at 05:35:31PM CEST, [email protected] wrote:
Quoted 7 lines · On Fri, 5 May 2023 12:41:11 +0200 Jiri Pirko wrote:
Quoted 3 lines
connector label (i.e. front panel label)? Or also applicable to internal pins? It'd be easier to talk details if we had the user facing documentation that ships with these products.
I think is is use case specific. Some of the pins face the user over physical port, they it is a front panel label. Others are internal names. I have no clue how to define and mainly enforce rules here.
It should be pretty easy to judge if we see the user-facing documentation vendors have.
Intel, Vadim, do you have such documentation?
As I wrote, for mlx5 the label is not really applicable as the link netdev->pin is defining what the pin is.
Quoted 9 lines
Quoted 4 lines
But as an example, if you have 2 pins of the same type, only difference is they are connected to front panel connector "A" and "B", this is the label you have to pass to the ID query. Do you see any other way?
Sound perfectly fine, if it's a front panel label, let's call the attribute
DPLL_A_PIN_FRONT_PANEL_LABEL. If the pin is not brought out to the front panel it will not have this attr. For other type of labels we should have different attributes.
Hmm, that would kind of embed the pin type into attr which feels wrong. We already have the pin type exposed:
enum dpll_pin_type {
DPLL_PIN_TYPE_UNSPEC,
DPLL_PIN_TYPE_MUX,
DPLL_PIN_TYPE_EXT,
DPLL_PIN_TYPE_SYNCE_ETH_PORT,
DPLL_PIN_TYPE_INT_OSCILLATOR,
DPLL_PIN_TYPE_GNSS,
__DPLL_PIN_TYPE_MAX,
DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1)
};It case of front panel pin label, the type is "EXT" as for external pin.
Paolo Abeni
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 9 lines · Jiri Pirko
Quoted 6 lines · Fri, May 05, 2023 at 05:35:31PM CEST, [email protected] wrote:
Quoted 1 line · On Fri, 5 May 2023 12:41:11 +0200 Jiri Pirko wrote:
Sound perfectly fine, if it's a front panel label, let's call the attribute
DPLL_A_PIN_FRONT_PANEL_LABEL. If the pin is not brought out to the front panel it will not have this attr. For other type of labels we should have different attributes.Hmm, that would kind of embed the pin type into attr which feels wrong.
Looking at the above from a different angle, the DPLL_A_PIN_FRONT_PANEL_LABEL attribute will be available only for DPLL_PIN_TYPE_EXT type pins, which looks legit to me - possibly renaming DPLL_A_PIN_FRONT_PANEL_LABEL as DPLL_A_PIN_EXT_LABEL.
Cheer,
Paolo
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 9 lines · Mon, May 08, 2023 at 08:50:09AM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
Quoted 6 lines · Fri, May 05, 2023 at 05:35:31PM CEST, [email protected] wrote:
Quoted 1 line · On Fri, 5 May 2023 12:41:11 +0200 Jiri Pirko wrote:
Sound perfectly fine, if it's a front panel label, let's call the attribute
DPLL_A_PIN_FRONT_PANEL_LABEL. If the pin is not brought out to the front panel it will not have this attr. For other type of labels we should have different attributes.
Quoted 6 lines
Quoted 1 line
Hmm, that would kind of embed the pin type into attr which feels wrong.
Looking at the above from a different angle, the
DPLL_A_PIN_FRONT_PANEL_LABELattribute will be available only forDPLL_PIN_TYPE_EXTtype pins, which looks legit to me - possibly renamingDPLL_A_PIN_FRONT_PANEL_LABELasDPLL_A_PIN_EXT_LABEL.
Well sure, in case there is no "label" attr for the rest of the types. Which I believe it is, for the ice implementation in this patchset. Otherwise, there is no way to distinguish between the pins. To have multiple attrs for label for multiple pin types does not make any sense to me, that was my point.
Quoted 5 lines
Cheer,
Paolo
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 1 line · On Mon, 8 May 2023 14:17:30 +0200 Jiri Pirko wrote:
Quoted 1 line
Quoted 1 line
Hmm, that would kind of embed the pin type into attr which feels wrong.
An attribute which changes meaning based on a value of another attribute feels even more wrong.
Quoted 4 lines
Quoted 4 lines
Looking at the above from a different angle, the
DPLL_A_PIN_FRONT_PANEL_LABELattribute will be available only forDPLL_PIN_TYPE_EXTtype pins, which looks legit to me - possibly renamingDPLL_A_PIN_FRONT_PANEL_LABELasDPLL_A_PIN_EXT_LABEL.
Yup. Even renaming EXT to something that's less.. relative :(
Quoted 5 lines
Well sure, in case there is no "label" attr for the rest of the types. Which I believe it is, for the ice implementation in this patchset. Otherwise, there is no way to distinguish between the pins. To have multiple attrs for label for multiple pin types does not make any sense to me, that was my point.
Come on, am I really this bad at explaining this?
If we make a generic "label" attribute driver authors will pack everything they want to expose to the user into it, and then some.
So we need attributes which will feel *obviously* *wrong* to abuse.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 5 lines · Mon, May 08, 2023 at 09:42:50PM CEST, [email protected] wrote:
Quoted 1 line · On Mon, 8 May 2023 14:17:30 +0200 Jiri Pirko wrote:
Quoted 1 line
Quoted 1 line
Hmm, that would kind of embed the pin type into attr which feels wrong.
An attribute which changes meaning based on a value of another attribute feels even more wrong.
It wouldn't change meaning, it would be still "a label". Either on a back of a PCI card or internal pin in a board scheme. Still the same meaning (for mux type for example).
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Looking at the above from a different angle, the
DPLL_A_PIN_FRONT_PANEL_LABELattribute will be available only forDPLL_PIN_TYPE_EXTtype pins, which looks legit to me - possibly renamingDPLL_A_PIN_FRONT_PANEL_LABELasDPLL_A_PIN_EXT_LABEL.Yup. Even renaming EXT to something that's less.. relative :(
Suggestion?
Quoted 8 lines
Quoted 6 lines
Well sure, in case there is no "label" attr for the rest of the types. Which I believe it is, for the ice implementation in this patchset. Otherwise, there is no way to distinguish between the pins. To have multiple attrs for label for multiple pin types does not make any sense to me, that was my point.
Come on, am I really this bad at explaining this?
Or perhaps I'm just slow.
Quoted 3 lines
If we make a generic "label" attribute driver authors will pack everything they want to expose to the user into it, and then some.
What's difference in generic label string attr and type specific label string attr. What is stopping driver developers to pack crap in either of these 2. Perhaps I'm missing something. Could you draw examples?
Quoted 2 lines
So we need attributes which will feel *obviously* *wrong* to abuse.
Sure, I get what you say and agree. I'm just trying to find out the actual attributes :)
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 3 lines · On Tue, 9 May 2023 09:53:07 +0200 Jiri Pirko wrote:
Quoted 1 line
Yup. Even renaming EXT to something that's less.. relative :(
Suggestion?
Well, is an SMT socket on the board an EXT pin?
Which is why I prefer PANEL.
Quoted 13 lines
Quoted 7 lines
Quoted 5 lines
Well sure, in case there is no "label" attr for the rest of the types. Which I believe it is, for the ice implementation in this patchset. Otherwise, there is no way to distinguish between the pins. To have multiple attrs for label for multiple pin types does not make any sense to me, that was my point.
Come on, am I really this bad at explaining this?
Or perhaps I'm just slow.
Quoted 2 lines
If we make a generic "label" attribute driver authors will pack everything they want to expose to the user into it, and then some.
Quoted 8 lines
What's difference in generic label string attr and type specific label string attr. What is stopping driver developers to pack crap in either of these 2. Perhaps I'm missing something. Could you draw examples?
Quoted 1 line
So we need attributes which will feel *obviously* *wrong* to abuse.
Sure, I get what you say and agree. I'm just trying to find out the actual attributes :)
PANEL label must match the name on the panel. User can take the card into their hand, look at the front, and there should be a label/sticker/ /engraving which matches exactly what the kernel reports.
If the label is printed on the board it's a BOARD_LABEL, if it's the name of a trace in board docs it's a BOARD_TRACE, if it's a pin of the ASIC it's a PACKAGE_PIN.
If it's none of those, or user does not have access to the detailed board / pinout - don't use the label.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 7 lines · Tue, May 09, 2023 at 04:52:47PM CEST, [email protected] wrote:
Quoted 3 lines · On Tue, 9 May 2023 09:53:07 +0200 Jiri Pirko wrote:
Quoted 1 line
Yup. Even renaming EXT to something that's less.. relative :(
Suggestion?
Well, is an SMT socket on the board an EXT pin?
Which is why I prefer PANEL.
Makes sense.
To speak code, we'll have:
/**
* enum dpll_pin_type - defines possible types of a pin, valid values for
* DPLL_A_PIN_TYPE attribute
* @DPLL_PIN_TYPE_UNSPEC: unspecified value
* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins
* @DPLL_PIN_TYPE_PANEL: physically facing user, for example on a front panel
* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock
* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator
* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock
*/
enum dpll_pin_type {
DPLL_PIN_TYPE_UNSPEC,
DPLL_PIN_TYPE_MUX,
DPLL_PIN_TYPE_PANEL,
DPLL_PIN_TYPE_SYNCE_ETH_PORT,
DPLL_PIN_TYPE_INT_OSCILLATOR,
DPLL_PIN_TYPE_GNSS,
__DPLL_PIN_TYPE_MAX,
DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1)
};Quoted 27 lines
Quoted 14 lines
Quoted 8 lines
Quoted 6 lines
Well sure, in case there is no "label" attr for the rest of the types. Which I believe it is, for the ice implementation in this patchset. Otherwise, there is no way to distinguish between the pins. To have multiple attrs for label for multiple pin types does not make any sense to me, that was my point.
Come on, am I really this bad at explaining this?
Or perhaps I'm just slow.
Quoted 2 lines
If we make a generic "label" attribute driver authors will pack everything they want to expose to the user into it, and then some.
Quoted 8 lines
What's difference in generic label string attr and type specific label string attr. What is stopping driver developers to pack crap in either of these 2. Perhaps I'm missing something. Could you draw examples?
Quoted 1 line
So we need attributes which will feel *obviously* *wrong* to abuse.
Sure, I get what you say and agree. I'm just trying to find out the actual attributes :)
PANEL label must match the name on the panel. User can take the card into their hand, look at the front, and there should be a label/sticker/ /engraving which matches exactly what the kernel reports.
Quoted 6 lines
If the label is printed on the board it's a
BOARD_LABEL, if it's the name of a trace in board docs it's aBOARD_TRACE, if it's a pin of the ASIC it's aPACKAGE_PIN.If it's none of those, or user does not have access to the detailed board / pinout - don't use the label.
To speak code, we'll have:DPLL_A_PIN_PANEL_LABEL (string)
available always when attr[DPLL_A_PIN_TYPE] == DPLL_PIN_TYPE_PANELDPLL_A_PIN_BOARD_LABEL (string)
may be available for any type, optionalDPLL_A_PIN_BOARD_TRACE (string)
may be available for any type, optionalDPLL_A_PIN_PACKAGE_PIN (string)
may be available for any type, optional
Makes sense?
But this does not prevent driver developer to pack random crap in the string anyway :/
Jakub Kicinski
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
Quoted 22 lines · On Tue, 9 May 2023 17:21:42 +0200 Jiri Pirko wrote:
Quoted 7 lines · Tue, May 09, 2023 at 04:52:47PM CEST, [email protected] wrote:
Quoted 3 lines · On Tue, 9 May 2023 09:53:07 +0200 Jiri Pirko wrote:
Quoted 1 line
Yup. Even renaming EXT to something that's less.. relative :(
Suggestion?
Well, is an SMT socket on the board an EXT pin?
Which is why I prefer PANEL.Makes sense.
To speak code, we'll have:/**
* enumdpll_pin_type- defines possible types of a pin, valid values for
*DPLL_A_PIN_TYPEattribute
* @DPLL_PIN_TYPE_UNSPEC: unspecified value
* @DPLL_PIN_TYPE_MUX: aggregates another layer of selectable pins
* @DPLL_PIN_TYPE_PANEL: physically facing user, for example on a front panel
* @DPLL_PIN_TYPE_SYNCE_ETH_PORT: ethernet port PHY's recovered clock
* @DPLL_PIN_TYPE_INT_OSCILLATOR: device internal oscillator
* @DPLL_PIN_TYPE_GNSS: GNSS recovered clock
*/
Quoted 11 lines
enum dpll_pin_type {
DPLL_PIN_TYPE_UNSPEC,
DPLL_PIN_TYPE_MUX,
DPLL_PIN_TYPE_PANEL,
DPLL_PIN_TYPE_SYNCE_ETH_PORT,
DPLL_PIN_TYPE_INT_OSCILLATOR,
DPLL_PIN_TYPE_GNSS,
__DPLL_PIN_TYPE_MAX,
DPLL_PIN_TYPE_MAX = (__DPLL_PIN_TYPE_MAX - 1)
};Maybe we can keep the EXT here, just not in the label itself. Don't think we care to add pin type for PANEL vs SMT vs jumper?
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Sure, I get what you say and agree. I'm just trying to find out the actual attributes :)
PANEL label must match the name on the panel. User can take the card into their hand, look at the front, and there should be a label/sticker/ /engraving which matches exactly what the kernel reports.
If the label is printed on the board it's a
BOARD_LABEL, if it's the name of a trace in board docs it's aBOARD_TRACE, if it's a pin of the ASIC it's aPACKAGE_PIN.
Quoted 6 lines
Quoted 2 lines
If it's none of those, or user does not have access to the detailed board / pinout - don't use the label.
To speak code, we'll have:
DPLL_A_PIN_PANEL_LABEL(string)
available always when attr[DPLL_A_PIN_TYPE] ==DPLL_PIN_TYPE_PANEL
Not sure about always, if there's only one maybe there's no need to provide the label?
Quoted 8 lines
DPLL_A_PIN_BOARD_LABEL(string)
may be available for any type, optionalDPLL_A_PIN_BOARD_TRACE(string)
may be available for any type, optionalDPLL_A_PIN_PACKAGE_PIN(string)
may be available for any type, optionalMakes sense?
yup (obviously we need to document the semantics)
Quoted 2 lines
But this does not prevent driver developer to pack random crap in the string anyway :/
It doesn't but it hopefully makes it much more likely that (1) reviewer will notice that something is off if the driver printfs random crap; and (2) that the user reading the documentation will complain that e.g.BOARD_LABEL is used but does not match the label on they see...