Create common DPLL/clock configuration API
Subsystems (11)
RFC PATCH v6 3/6 dpll: documentation on DPLL subsystem interface
In reply to Vadim FedorenkoAdd documentation explaining common netlink interface to configure DPLL devices and monitoring events. Common way to implement DPLL device in a driver is also covered.
--- Documentation/networking/dpll.rst | 347 +++++++++++++++++++++++++++++ Documentation/networking/index.rst | 1 + 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/dpll.rst
Documentation/networking/dpll.rst new file +347 -0
@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +The Linux kernel DPLL subsystem +=============================== + + +The main purpose of DPLL subsystem is to provide general interface +to configure devices that use any kind of Digital PLL and could use +different sources of signal to synchronize to as well as different +types of outputs. +The main interface is NETLINK_GENERIC based protocol with an event +monitoring multicast group defined. + + +Dpll object +=========== +Single dpll device object means single Digital PLL circuit and bunch of +pins connected with it. +It provides its capablities and current status to the user in response +to the `do` request of netlink command ``DPLL_CMD_DEVICE_GET`` and list +of dplls registered in the subsystem with `dump` netlink request of same +command. +Requesting configuration of dpll device is done with `do` request of +netlink ``DPLL_CMD_DEVICE_SET`` command. + + +Pin object +========== +A pin is amorphic object which represents either input or output, it +could be internal component of the device, as well as externaly +connected. +The number of pins per dpll vary, but usually multiple pins shall be +provided for a single dpll device. +Pin's properities and capabilities are provided to the user in response +to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. +It is also possible to list all the pins that were registered either +with dpll or different pin with `dump` request of ``DPLL_CMD_PIN_GET`` +command. +Configuration of a pin can be changed by `do` request of netlink +``DPLL_CMD_PIN_SET`` command. + + +Shared pins +=========== +Pin can be shared by multiple dpll devices. Where configuration on one +pin can alter multiple dplls (i.e. PIN_FREQUENCY, PIN_DIRECTION), +or configure just one pin-dpll pair (i.e. PIN_PRIO, PIN_STATE). + + +MUX-type pins +============= +A pin can be MUX-type, which aggregates child pins and serves as pin +multiplexer. One or more pins are attached to MUX-type instead of being +directly connected to a dpll device. +Pins registered with a MUX-type provides user with additional nested +attribute ``DPLL_A_PIN_PARENT`` for each parrent they were registered +with. +Only one child pin can provide it's signal to the parent MUX-type pin at +a time, the selection is done with requesting change of child pin state +to ``DPLL_PIN_STATE_CONNECTED`` and providing a target MUX-type pin +index value in ``DPLL_A_PARENT_PIN_IDX`` + + +Pin priority +============ +Some devices might offer a capability of automatic pin selection mode. +Usually such automatic selection is offloaded to the hardware, +which means only pins directly connected to the dpll are capable of +automatic source pin selection. +In automatic selection mode, the user cannot manually select a source +pin for the device, instead the user shall provide all directly +connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would +pick a highest priority valid signal and connect with it. +Child pin of MUX-type are not capable of automatic source pin selection, +in order to configure a source of a MUX-type pin the user still needs +to request desired pin state. + + +Configuration commands group +============================ + +Configuration commands are used to get or dump information about +registered DPLL devices (and pins), as well as set configuration of +device or pins. As DPLL device could not be abstract and reflects real +hardware, there is no way to add new DPLL device via netlink from user +space and each device should be registered by it's driver. + +All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent +any spamming/D.o.S. from unauthorized userspace applications. + +List of command with possible attributes +======================================== + +All constants identifying command types use ``DPLL_CMD_`` prefix and +suffix according to command purpose. All attributes use ``DPLL_A_`` +prefix and suffix according to attribute purpose: + + ============================ ======================================= + ``DEVICE_GET`` command to get device info or dump list + of available devices + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``MODE`` attr selection mode + ``MODE_SUPPORTED`` attr available selection modes + ``SOURCE_PIN_IDX`` attr index of currently selected source + ``LOCK_STATUS`` attr internal frequency-lock status + ``TEMP`` attr device temperature information + ``CLOCK_ID`` attr Unique Clock Identifier (EUI-64), + as defined by the IEEE 1588 standard + ``TYPE`` attr type or purpose of dpll device + ``DEVICE_SET`` command to set dpll device configuration + ``ID`` attr internal dpll device index + ``NAME`` attr dpll device name (not required if + dpll device index was provided) + ``MODE`` attr selection mode to configure + ``PIN_GET`` command to get pin info or dump list of + available pins + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_PRIO`` attr priority of pin on the dpll device + ``PIN_STATE`` attr state of pin on the dpll device + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DESCRIPTION`` attr description provided by driver + ``PIN_TYPE`` attr type of a pin + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency in case + pin/dpll supports any frequency + ``PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency in case + pin/dpll supports any frequency + ``PIN_PARENT`` nest attr for each MUX-type parent, that + pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DPLL_CAPS`` attr bitmask of pin-dpll capabilities + + ``PIN_SET`` command to set pins configuration + ``ID`` attr internal dpll device index + ``BUS_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``DEV_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DIRECTION`` attr direction to be set + ``PIN_FREQUENCY`` attr frequency to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_STATE`` attr pin state to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_PARENT_IDX`` attr if provided state is to be set with + parent pin instead of with dpll device + +Netlink dump requests +===================== + +The ``DEVICE_GET`` and ``PIN_GET`` commands are capable of dump type +netlink requests. Possible response message attributes for netlink dump +requests: + + ============================== ======================================= + ``PIN_GET`` command to dump pins + ``PIN`` attr nested type contains single pin + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_IDX`` attr index of dumped pin (on dplls) + ``PIN_DESCRIPTION`` description of a pin provided by driver + ``PIN_TYPE`` attr value of pin type + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_PARENT`` nest attr for each MUX-type parent, + that pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + + ``DEVICE_GET`` command to dump dplls + ``DEVICE`` attr nested type contatin a single + dpll device + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + + +Dpll device level configuration pre-defined enums +================================================= + +For all below enum names used for configuration of dpll device use +the ``DPLL_`` prefix. + +Values for ``DPLL_A_LOCK_STATUS`` attribute: + + ============================= ====================================== + ``LOCK_STATUS_UNLOCKED`` DPLL is in freerun, not locked to any + source pin + ``LOCK_STATUS_CALIBRATING`` DPLL device calibrates to lock to the + source pin signal + ``LOCK_STATUS_LOCKED`` DPLL device is locked to the source + pin frequency + ``LOCK_STATUS_HOLDOVER`` DPLL device lost a lock, using its + frequency holdover capabilities + +Values for ``DPLL_A_MODE`` attribute: + + =================== ================================================ + ``MODE_FORCED`` source pin is force-selected by setting pin + state to ``DPLL_PIN_STATE_CONNECTED`` on a dpll + ``MODE_AUTOMATIC`` source pin is auto selected according to + configured pin priorities and source signal + validity + ``MODE_HOLDOVER`` force holdover mode of DPLL + ``MODE_FREERUN`` DPLL is driven by supplied system clock without + holdover capabilities + ``MODE_NCO`` similar to FREERUN, with possibility to + numerically control frequency offset + +Values for ``DPLL_A_TYPE`` attribute: + + ============= ================================================ + ``TYPE_PPS`` DPLL used to provide pulse-per-second output + ``TYPE_EEC`` DPLL used to drive ethernet equipment clock + + + +Pin level configuration pre-defined enums +========================================= + +For all below enum names used for configuration of pin use the +``DPLL_PIN`` prefix. + +Values for ``DPLL_A_PIN_STATE`` attribute: + + ======================= ======================================== + ``STATE_CONNECTED`` Pin connected to a dpll or parent pin + ``STATE_DISCONNECTED`` Pin disconnected from dpll or parent pin + +Values for ``DPLL_A_PIN_DIRECTION`` attribute: + + ======================= ============================== + ``DIRECTION_SOURCE`` Pin used as a source of signal + ``DIRECTION_OUTPUT`` Pin used to output signal + +Values for ``DPLL_A_PIN_TYPE`` attributes: + + ======================== ======================================== + ``TYPE_MUX`` MUX type pin, connected pins shall have + their own types + ``TYPE_EXT`` External pin + ``TYPE_SYNCE_ETH_PORT`` SyncE on Ethernet port + ``TYPE_INT_OSCILLATOR`` Internal Oscillator (i.e. Holdover with + Atomic Clock as a Source) + ``TYPE_GNSS`` GNSS 1PPS source + +Values for ``DPLL_A_PIN_DPLL_CAPS`` attributes: + + ============================= ================================ + ``CAPS_DIRECTION_CAN_CHANGE`` Bit present if direction can change + ``CAPS_PRIORITY_CAN_CHANGE`` Bit present if priority can change + ``CAPS_STATE_CAN_CHANGE`` Bit present if state can change + + +Notifications +============= + +DPLL device can provide notifications regarding status changes of the +device, i.e. lock status changes, source/output type changes or alarms. +This is the multicast group that is used to notify user-space apps via +netlink socket: ``DPLL_MCGRP_MONITOR`` + +Notifications messages (attrbiutes use ``DPLL_A`` prefix): + + ========================= ========================================== + ``EVENT_DEVICE_CREATE`` event value new DPLL device was created + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``EVENT_DEVICE_DELETE`` event value DPLL device was deleted + ``ID`` attr dpll device index + ``EVENT_DEVICE_CHANGE`` event value DPLL device attribute has + changed + ``ID`` attr modified dpll device ID + ``PIN_IDX`` attr the modified pin index + +Device change event shall consiste of the attribute and the value that +has changed. + + +Device driver implementation +============================ + +Device is allocated by ``dpll_device_get`` call. Second call with the +same arguments doesn't create new object but provides pointer to +previously created device for given arguments, it also increase refcount +of that object. +Device is deallocated by ``dpll_device_put`` call, which first decreases +the refcount, once refcount is cleared the object is destroyed. + +Device should implement set of operations and register device via +``dpll_device_register`` at which point it becomes available to the +users. Only one driver can register a dpll device within dpll subsytem. +Multiple driver instances can obtain reference to it with +``dpll_device_get``. + +The pins are allocated separately with ``dpll_pin_get``, it works +similarly to ``dpll_device_get``. Creates object and the for each call +with the same arguments the object refcount increases. + +Once DPLL device is created, allocated pin can be registered with it +with 2 different methods, always providing implemented pin callbacks, +and private data pointer for calling them: +``dpll_pin_register`` - simple registration with a dpll device. +``dpll_pin_on_pin_register`` - register pin with another MUX type pin. + +For different instances of a device driver requiring to find already +registered DPLL (i.e. to connect its pins to id) use ``dpll_device_get`` +to obtain proper dpll device pointer. + +The name od DPLL device is generated based on registerer provided device +struct pointer and dev_driver_id value. +Name is in format: ``%s_%u`` witch arguments: +``dev_name(struct device *)`` - syscall on parent device struct +``dev_driver_idx`` - registerer given id + +Notifications of adding or removing DPLL devices are created within +subsystem itself. +Notifications about registering/deregistering pins are also invoked by +the subsystem. +Notifications about dpll status changes shall be requested by device +driver with ``dpll_device_notify`` corresponding attribute as a reason. + +There is no strict requirement to implement all the operations for +each device, every operation handler is checked for existence and +ENOTSUPP is returned in case of absence of specific handler. +
Documentation/networking/index.rst +1 -0
@@ -17,6 +17,7 @@ Contents: dsa/index devlink/index caif/index + dpll ethtool-netlink ieee802154 j1939
Signature · 1 line
2.34.1
RFC PATCH v6 1/6 dpll: spec: Add Netlink spec in YAML
In reply to Vadim FedorenkoFrom: 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
RFC PATCH v6 6/6 ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoImplement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.
--- drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 209 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 200 insertions(+), 10 deletions(-)
drivers/ptp/Kconfig +1 -0
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.
drivers/ptp/ptp_ocp.c +199 -10
265 lines not on this page · raw message
Signature · 1 line
2.34.1
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
RFC PATCH v6 5/6 ice: implement dpll interface to control cgu
In reply to Vadim FedorenkoFrom: Arkadiusz Kubalewski <[email protected]>
Control over clock generation unit is required for further development of Synchronous Ethernet feature. Interface provides ability to obtain current state of a dpll, its sources and outputs which are pins, and allows their configuration.
--- drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 4 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 ++ drivers/net/ethernet/intel/ice/ice_main.c | 7 + 6 files changed, 1955 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -301,6 +301,7 @@ config ICE select DIMLIB select NET_DEVLINK select PLDMFW + select DPLL help This driver supports Intel(R) Ethernet Connection E800 Series of devices. For more information on how to identify your adapter, go
drivers/net/ethernet/intel/ice/Makefile +2 -1
@@ -33,7 +33,8 @@ ice-y := ice_main.o \ ice_lag.o \ ice_ethtool.o \ ice_repr.o \ - ice_tc_lib.o + ice_tc_lib.o \ + ice_dpll.o ice-$(CONFIG_PCI_IOV) += \ ice_sriov.o \ ice_virtchnl.o \
drivers/net/ethernet/intel/ice/ice.h +4 -0
@@ -75,6 +75,7 @@#include "ice_lag.h" #include "ice_vsi_vlan_ops.h" #include "ice_gnss.h" +#include "ice_dpll.h" #define ICE_BAR0 0#define ICE_REQ_DESC_MULTIPLE 32
@@ -202,6 +203,7 @@enum ice_feature {ICE_F_DSCP ,ICE_F_PTP_EXTTS , +ICE_F_PHY_RCLK ,ICE_F_SMA_CTRL ,ICE_F_CGU ,ICE_F_GNSS ,
@@ -512,6 +514,7 @@ enum ice_pf_flags {ICE_FLAG_PLUG_AUX_DEV ,ICE_FLAG_MTU_CHANGED ,ICE_FLAG_GNSS ,/* GNSS successfully initialized */ +ICE_FLAG_DPLL ,/* SyncE/PTP dplls initialized */ ICE_PF_FLAGS_NBITS /* must be last */ };
@@ -635,6 +638,7 @@ struct ice_pf {#define ICE_VF_AGG_NODE_ID_START 65#define ICE_MAX_VF_AGG_NODES 32struct ice_agg_node vf_agg_node[ICE_MAX_VF_AGG_NODES ]; +struct ice_dplls dplls; };struct ice_netdev_priv {
drivers/net/ethernet/intel/ice/ice_dpll.c new file +1845 -0
1,845 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_dpll.h new file +96 -0
96 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_main.c +7 -0
@@ -4810,6 +4810,10 @@ static void ice_init_features(struct ice_pf *pf)if (ice_is_feature_supported (pf,ICE_F_GNSS ))ice_gnss_init (pf); +if (ice_is_feature_supported (pf,ICE_F_CGU ) || +ice_is_feature_supported (pf,ICE_F_PHY_RCLK )) +ice_dpll_init (pf); +/* Note: Flow director init failure is non-fatal to load */ if (ice_init_fdir (pf))dev_err (dev,"could not initialize flow director\n" );
@@ -4836,6 +4840,9 @@ static void ice_deinit_features(struct ice_pf *pf)ice_gnss_exit (pf);if (test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags))ice_ptp_release (pf); +if (ice_is_feature_supported (pf,ICE_F_PHY_RCLK ) || +ice_is_feature_supported (pf,ICE_F_CGU )) +ice_dpll_release (pf); }static void ice_init_wakeup (struct ice_pf *pf)
Signature · 1 line
2.34.1
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 4/6 ice: add admin commands to access cgu configuration
From: Arkadiusz Kubalewski <[email protected]>
Add firmware admin command to access clock generation unit configuration, it is required to enable Extended PTP and SyncE features in the driver.
Add definitions of possible hardware variations of input and output pins related to clock generation unit and functions to access the data.
--- drivers/net/ethernet/intel/ice/ice.h | 1 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++++++++- drivers/net/ethernet/intel/ice/ice_common.c | 467 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 ++ drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 +++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + 8 files changed, 1415 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +1 -0
@@ -203,6 +203,7 @@ enum ice_feature {ICE_F_DSCP ,ICE_F_PTP_EXTTS ,ICE_F_SMA_CTRL , +ICE_F_CGU ,ICE_F_GNSS , ICE_F_MAX };
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +239 -1
288 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_common.c +467 -0
479 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_common.h +43 -0
55 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_lib.c +13 -4
@@ -4322,13 +4322,22 @@ void ice_init_feature_support(struct ice_pf *pf)case ICE_DEV_ID_E810C_BACKPLANE :case ICE_DEV_ID_E810C_QSFP :case ICE_DEV_ID_E810C_SFP : +case ICE_DEV_ID_E810_XXV_BACKPLANE : +case ICE_DEV_ID_E810_XXV_QSFP : +case ICE_DEV_ID_E810_XXV_SFP :ice_set_feature_support (pf,ICE_F_DSCP );ice_set_feature_support (pf,ICE_F_PTP_EXTTS ); -if (ice_is_e810t (&pf->hw)) { +if (ice_is_phy_rclk_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_PHY_RCLK ); +/* If we don't own the timer - don't enable other caps */ +if (!pf->hw.func_caps.ts_func_info.src_tmr_owned) +break ; +if (ice_is_cgu_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_CGU ); +if (ice_is_clock_mux_present_e810t (&pf->hw))ice_set_feature_support (pf,ICE_F_SMA_CTRL ); -if (ice_gnss_is_gps_present (&pf->hw)) -ice_set_feature_support (pf,ICE_F_GNSS ); - } +if (ice_gnss_is_gps_present (&pf->hw)) +ice_set_feature_support (pf,ICE_F_GNSS );break ;default :break ;
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +411 -0
420 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +240 -0
258 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
@@ -962,6 +962,7 @@ struct ice_hw {DECLARE_BITMAP (hw_ptype,ICE_FLOW_PTYPE_MAX );u8 dvm_ena;u16 io_expander_handle; +u8 cgu_part_number; };/* Statistics collected by each port, VSI, VEB, and S-channel */
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim Fedorenko[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-7-vadfed%40meta.com patch subject: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops config: x86_64-randconfig-a005 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/fe16623a48f3c6592be80872758c19822b70ae62
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout fe16623a48f3c6592be80872758c19822b70ae62
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/dpll/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/dpll/dpll_core.c:285:1: warning: no previous prototype for function 'dpll_device_alloc' [-Wmissing-prototypes] dpll_device_alloc(const u64 clock_id, u32 dev_driver_id, struct module *module) ^ drivers/dpll/dpll_core.c:284:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct dpll_device * ^ static >> drivers/dpll/dpll_core.c:439:1: warning: no previous prototype for function 'dpll_pin_alloc' [-Wmissing-prototypes]
dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
^
drivers/dpll/dpll_core.c:438:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct dpll_pin *
^
static
2 warnings generated.
--
>> drivers/dpll/dpll_netlink.c:1062:13: warning: no previous prototype for function 'dpll_netlink_fini' [-Wmissing-prototypes]
void __exit dpll_netlink_fini(void)
^ drivers/dpll/dpll_netlink.c:1062:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __exit dpll_netlink_fini(void)
^
static
1 warning generated.
vim +/dpll_device_alloc +285 drivers/dpll/dpll_core.c
55b810a5137d33 Vadim Fedorenko 2023-03-11 269
55b810a5137d33 Vadim Fedorenko 2023-03-11 270
55b810a5137d33 Vadim Fedorenko 2023-03-11 271 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 272 * dpll_device_alloc - allocate the memory for dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 273 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 274 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 275 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 276 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 277 * Allocates memory and initialize dpll device, hold its reference on global
55b810a5137d33 Vadim Fedorenko 2023-03-11 278 * xarray.
55b810a5137d33 Vadim Fedorenko 2023-03-11 279 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 280 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 281 * * dpll_device struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 282 * * ERR_PTR(X) - failed allocation
55b810a5137d33 Vadim Fedorenko 2023-03-11 283 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 284 struct dpll_device *
55b810a5137d33 Vadim Fedorenko 2023-03-11 @285 dpll_device_alloc(const u64 clock_id, u32 dev_driver_id, struct module *module)
55b810a5137d33 Vadim Fedorenko 2023-03-11 286 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 287 struct dpll_device *dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 288 int ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 289
55b810a5137d33 Vadim Fedorenko 2023-03-11 290 dpll = kzalloc(sizeof(*dpll), GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 291 if (!dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 292 return ERR_PTR(-ENOMEM);
55b810a5137d33 Vadim Fedorenko 2023-03-11 293 refcount_set(&dpll->refcount, 1);
55b810a5137d33 Vadim Fedorenko 2023-03-11 294 dpll->dev.class = &dpll_class;
55b810a5137d33 Vadim Fedorenko 2023-03-11 295 dpll->dev_driver_id = dev_driver_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 296 dpll->clock_id = clock_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 297 dpll->module = module;
55b810a5137d33 Vadim Fedorenko 2023-03-11 298 ret = xa_alloc(&dpll_device_xa, &dpll->id, dpll,
55b810a5137d33 Vadim Fedorenko 2023-03-11 299 xa_limit_16b, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 300 if (ret) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 301 kfree(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 302 return ERR_PTR(ret);
55b810a5137d33 Vadim Fedorenko 2023-03-11 303 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 304 xa_init_flags(&dpll->pin_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 305
55b810a5137d33 Vadim Fedorenko 2023-03-11 306 return dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 307 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 308
55b810a5137d33 Vadim Fedorenko 2023-03-11 309 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 310 * dpll_device_get - find existing or create new dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 311 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 312 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 313 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 314 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 315 * Get existing object of a dpll device, unique for given arguments.
55b810a5137d33 Vadim Fedorenko 2023-03-11 316 * Create new if doesn't exist yet.
55b810a5137d33 Vadim Fedorenko 2023-03-11 317 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 318 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 319 * * valid dpll_device struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 320 * * ERR_PTR of an error
55b810a5137d33 Vadim Fedorenko 2023-03-11 321 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 322 struct dpll_device *
55b810a5137d33 Vadim Fedorenko 2023-03-11 323 dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module)
55b810a5137d33 Vadim Fedorenko 2023-03-11 324 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 325 struct dpll_device *dpll, *ret = NULL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 326 unsigned long index;
55b810a5137d33 Vadim Fedorenko 2023-03-11 327
55b810a5137d33 Vadim Fedorenko 2023-03-11 328 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 329 xa_for_each(&dpll_device_xa, index, dpll) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 330 if (dpll->clock_id == clock_id &&
55b810a5137d33 Vadim Fedorenko 2023-03-11 331 dpll->dev_driver_id == dev_driver_id &&
55b810a5137d33 Vadim Fedorenko 2023-03-11 332 dpll->module == module) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 333 ret = dpll;
55b810a5137d33 Vadim Fedorenko 2023-03-11 334 refcount_inc(&ret->refcount);
55b810a5137d33 Vadim Fedorenko 2023-03-11 335 break;
55b810a5137d33 Vadim Fedorenko 2023-03-11 336 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 337 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 338 if (!ret)
55b810a5137d33 Vadim Fedorenko 2023-03-11 339 ret = dpll_device_alloc(clock_id, dev_driver_id, module);
55b810a5137d33 Vadim Fedorenko 2023-03-11 340 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 341
55b810a5137d33 Vadim Fedorenko 2023-03-11 342 return ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 343 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 344 EXPORT_SYMBOL_GPL(dpll_device_get);
55b810a5137d33 Vadim Fedorenko 2023-03-11 345
55b810a5137d33 Vadim Fedorenko 2023-03-11 346 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 347 * dpll_device_put - decrease the refcount and free memory if possible
55b810a5137d33 Vadim Fedorenko 2023-03-11 348 * @dpll: dpll_device struct pointer
55b810a5137d33 Vadim Fedorenko 2023-03-11 349 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 350 * Drop reference for a dpll device, if all references are gone, delete
55b810a5137d33 Vadim Fedorenko 2023-03-11 351 * dpll device object.
55b810a5137d33 Vadim Fedorenko 2023-03-11 352 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 353 void dpll_device_put(struct dpll_device *dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 354 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 355 if (!dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 356 return;
55b810a5137d33 Vadim Fedorenko 2023-03-11 357 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 358 if (refcount_dec_and_test(&dpll->refcount)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 359 WARN_ON_ONCE(!xa_empty(&dpll->pin_refs));
55b810a5137d33 Vadim Fedorenko 2023-03-11 360 xa_destroy(&dpll->pin_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 361 xa_erase(&dpll_device_xa, dpll->id);
55b810a5137d33 Vadim Fedorenko 2023-03-11 362 kfree(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 363 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 364 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 365 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 366 EXPORT_SYMBOL_GPL(dpll_device_put);
55b810a5137d33 Vadim Fedorenko 2023-03-11 367
55b810a5137d33 Vadim Fedorenko 2023-03-11 368 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 369 * dpll_device_register - register the dpll device in the subsystem
55b810a5137d33 Vadim Fedorenko 2023-03-11 370 * @dpll: pointer to a dpll
55b810a5137d33 Vadim Fedorenko 2023-03-11 371 * @type: type of a dpll
55b810a5137d33 Vadim Fedorenko 2023-03-11 372 * @ops: ops for a dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 373 * @priv: pointer to private information of owner
55b810a5137d33 Vadim Fedorenko 2023-03-11 374 * @owner: pointer to owner device
55b810a5137d33 Vadim Fedorenko 2023-03-11 375 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 376 * Make dpll device available for user space.
55b810a5137d33 Vadim Fedorenko 2023-03-11 377 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 378 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 379 * * 0 on success
55b810a5137d33 Vadim Fedorenko 2023-03-11 380 * * -EINVAL on failure
55b810a5137d33 Vadim Fedorenko 2023-03-11 381 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 382 int dpll_device_register(struct dpll_device *dpll, enum dpll_type type,
55b810a5137d33 Vadim Fedorenko 2023-03-11 383 struct dpll_device_ops *ops, void *priv,
55b810a5137d33 Vadim Fedorenko 2023-03-11 384 struct device *owner)
55b810a5137d33 Vadim Fedorenko 2023-03-11 385 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 386 if (WARN_ON(!ops || !owner))
55b810a5137d33 Vadim Fedorenko 2023-03-11 387 return -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 388 if (WARN_ON(type <= DPLL_TYPE_UNSPEC || type > DPLL_TYPE_MAX))
55b810a5137d33 Vadim Fedorenko 2023-03-11 389 return -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 390 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 391 if (ASSERT_DPLL_NOT_REGISTERED(dpll)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 392 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 393 return -EEXIST;
55b810a5137d33 Vadim Fedorenko 2023-03-11 394 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 395 dpll->dev.bus = owner->bus;
55b810a5137d33 Vadim Fedorenko 2023-03-11 396 dpll->parent = owner;
55b810a5137d33 Vadim Fedorenko 2023-03-11 397 dpll->type = type;
55b810a5137d33 Vadim Fedorenko 2023-03-11 398 dpll->ops = ops;
55b810a5137d33 Vadim Fedorenko 2023-03-11 399 dev_set_name(&dpll->dev, "%s_%d", dev_name(owner),
55b810a5137d33 Vadim Fedorenko 2023-03-11 400 dpll->dev_driver_id);
55b810a5137d33 Vadim Fedorenko 2023-03-11 401 dpll->priv = priv;
55b810a5137d33 Vadim Fedorenko 2023-03-11 402 xa_set_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED);
55b810a5137d33 Vadim Fedorenko 2023-03-11 403 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 404 dpll_notify_device_create(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 405
55b810a5137d33 Vadim Fedorenko 2023-03-11 406 return 0;
55b810a5137d33 Vadim Fedorenko 2023-03-11 407 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 408 EXPORT_SYMBOL_GPL(dpll_device_register);
55b810a5137d33 Vadim Fedorenko 2023-03-11 409
55b810a5137d33 Vadim Fedorenko 2023-03-11 410 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 411 * dpll_device_unregister - deregister dpll device
55b810a5137d33 Vadim Fedorenko 2023-03-11 412 * @dpll: registered dpll pointer
55b810a5137d33 Vadim Fedorenko 2023-03-11 413 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 414 * Deregister device, make it unavailable for userspace.
55b810a5137d33 Vadim Fedorenko 2023-03-11 415 * Note: It does not free the memory
55b810a5137d33 Vadim Fedorenko 2023-03-11 416 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 417 void dpll_device_unregister(struct dpll_device *dpll)
55b810a5137d33 Vadim Fedorenko 2023-03-11 418 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 419 mutex_lock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 420 ASSERT_DPLL_REGISTERED(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 421 xa_clear_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED);
55b810a5137d33 Vadim Fedorenko 2023-03-11 422 mutex_unlock(&dpll_device_xa_lock);
55b810a5137d33 Vadim Fedorenko 2023-03-11 423 dpll_notify_device_delete(dpll);
55b810a5137d33 Vadim Fedorenko 2023-03-11 424 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 425 EXPORT_SYMBOL_GPL(dpll_device_unregister);
55b810a5137d33 Vadim Fedorenko 2023-03-11 426
55b810a5137d33 Vadim Fedorenko 2023-03-11 427 /**
55b810a5137d33 Vadim Fedorenko 2023-03-11 428 * dpll_pin_alloc - allocate the memory for dpll pin
55b810a5137d33 Vadim Fedorenko 2023-03-11 429 * @clock_id: clock_id of creator
55b810a5137d33 Vadim Fedorenko 2023-03-11 430 * @dev_driver_id: id given by dev driver
55b810a5137d33 Vadim Fedorenko 2023-03-11 431 * @module: reference to registering module
55b810a5137d33 Vadim Fedorenko 2023-03-11 432 * @prop: dpll pin properties
55b810a5137d33 Vadim Fedorenko 2023-03-11 433 *
55b810a5137d33 Vadim Fedorenko 2023-03-11 434 * Return:
55b810a5137d33 Vadim Fedorenko 2023-03-11 435 * * valid allocated dpll_pin struct pointer if succeeded
55b810a5137d33 Vadim Fedorenko 2023-03-11 436 * * ERR_PTR of an error
55b810a5137d33 Vadim Fedorenko 2023-03-11 437 */
55b810a5137d33 Vadim Fedorenko 2023-03-11 438 struct dpll_pin *
55b810a5137d33 Vadim Fedorenko 2023-03-11 @439 dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module *module,
55b810a5137d33 Vadim Fedorenko 2023-03-11 440 const struct dpll_pin_properties *prop)
55b810a5137d33 Vadim Fedorenko 2023-03-11 441 {
55b810a5137d33 Vadim Fedorenko 2023-03-11 442 struct dpll_pin *pin;
55b810a5137d33 Vadim Fedorenko 2023-03-11 443 int ret;
55b810a5137d33 Vadim Fedorenko 2023-03-11 444
55b810a5137d33 Vadim Fedorenko 2023-03-11 445 pin = kzalloc(sizeof(*pin), GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 446 if (!pin)
55b810a5137d33 Vadim Fedorenko 2023-03-11 447 return ERR_PTR(-ENOMEM);
55b810a5137d33 Vadim Fedorenko 2023-03-11 448 pin->dev_driver_id = device_drv_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 449 pin->clock_id = clock_id;
55b810a5137d33 Vadim Fedorenko 2023-03-11 450 pin->module = module;
55b810a5137d33 Vadim Fedorenko 2023-03-11 451 refcount_set(&pin->refcount, 1);
55b810a5137d33 Vadim Fedorenko 2023-03-11 452 if (WARN_ON(!prop->description)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 453 ret = -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 454 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 455 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 456 pin->prop.description = kstrdup(prop->description, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 457 if (!pin->prop.description) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 458 ret = -ENOMEM;
55b810a5137d33 Vadim Fedorenko 2023-03-11 459 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 460 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 461 if (WARN_ON(prop->type <= DPLL_PIN_TYPE_UNSPEC ||
55b810a5137d33 Vadim Fedorenko 2023-03-11 462 prop->type > DPLL_PIN_TYPE_MAX)) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 463 ret = -EINVAL;
55b810a5137d33 Vadim Fedorenko 2023-03-11 464 goto release;
55b810a5137d33 Vadim Fedorenko 2023-03-11 465 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 466 pin->prop.type = prop->type;
55b810a5137d33 Vadim Fedorenko 2023-03-11 467 pin->prop.capabilities = prop->capabilities;
55b810a5137d33 Vadim Fedorenko 2023-03-11 468 pin->prop.freq_supported = prop->freq_supported;
55b810a5137d33 Vadim Fedorenko 2023-03-11 469 pin->prop.any_freq_min = prop->any_freq_min;
55b810a5137d33 Vadim Fedorenko 2023-03-11 470 pin->prop.any_freq_max = prop->any_freq_max;
55b810a5137d33 Vadim Fedorenko 2023-03-11 471 xa_init_flags(&pin->dpll_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 472 xa_init_flags(&pin->parent_refs, XA_FLAGS_ALLOC);
55b810a5137d33 Vadim Fedorenko 2023-03-11 473 ret = xa_alloc(&dpll_pin_xa, &pin->idx, pin,
55b810a5137d33 Vadim Fedorenko 2023-03-11 474 xa_limit_16b, GFP_KERNEL);
55b810a5137d33 Vadim Fedorenko 2023-03-11 475 release:
55b810a5137d33 Vadim Fedorenko 2023-03-11 476 if (ret) {
55b810a5137d33 Vadim Fedorenko 2023-03-11 477 xa_destroy(&pin->dpll_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 478 xa_destroy(&pin->parent_refs);
55b810a5137d33 Vadim Fedorenko 2023-03-11 479 kfree(pin->prop.description);
55b810a5137d33 Vadim Fedorenko 2023-03-11 480 kfree(pin->rclk_dev_name);
55b810a5137d33 Vadim Fedorenko 2023-03-11 481 kfree(pin);
55b810a5137d33 Vadim Fedorenko 2023-03-11 482 return ERR_PTR(ret);
55b810a5137d33 Vadim Fedorenko 2023-03-11 483 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 484
55b810a5137d33 Vadim Fedorenko 2023-03-11 485 return pin;
55b810a5137d33 Vadim Fedorenko 2023-03-11 486 }
55b810a5137d33 Vadim Fedorenko 2023-03-11 487 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH RFC v6 5/6] ice: implement dpll interface to control cgu
In reply to Vadim Fedorenko[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-6-vadfed%40meta.com patch subject: [PATCH RFC v6 5/6] ice: implement dpll interface to control cgu config: i386-randconfig-a013 (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c4acb622eb0fd3120fc9cdcaf33fddfa7da04a50
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout c4acb622eb0fd3120fc9cdcaf33fddfa7da04a50
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/net/ethernet/intel/ice/ice_dpll.c:155:7: warning: variable 'pin_num' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (pin == pf->dplls.rclk.pin)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:161:18: note: uninitialized use occurs here
for (i = 0; i < pin_num; i++)
^~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:155:3: note: remove the 'if' if its condition is always true
if (pin == pf->dplls.rclk.pin)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:143:13: note: initialize the variable 'pin_num' to silence this warning
int pin_num, i;
^
= 0
>> drivers/net/ethernet/intel/ice/ice_dpll.c:412:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:416:6: note: uninitialized use occurs here
if (ret)
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:412:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:407:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
drivers/net/ethernet/intel/ice/ice_dpll.c:449:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:453:6: note: uninitialized use occurs here
if (ret)
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:449:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:444:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
>> drivers/net/ethernet/intel/ice/ice_dpll.c:478:1: warning: no previous prototype for function 'ice_dpll_pin_state_update' [-Wmissing-prototypes]
ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
^
drivers/net/ethernet/intel/ice/ice_dpll.c:477:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int
^
static
drivers/net/ethernet/intel/ice/ice_dpll.c:499:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:519:9: note: uninitialized use occurs here
return ret;
^~~
drivers/net/ethernet/intel/ice/ice_dpll.c:499:9: note: remove the 'if' if its condition is always true
} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_dpll.c:481:9: note: initialize the variable 'ret' to silence this warning
int ret;
^
= 0
5 warnings generated.
--
ERROR: modpost: "__divdi3" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_phy_rclk_present" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_cgu_present" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_is_clock_mux_present_e810t" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_get_cgu_rclk_pin_info" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_get_cgu_state" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_name" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_type" [drivers/net/ethernet/intel/ice/ice.ko] undefined!
>> ERROR: modpost: "ice_cgu_get_pin_freq_mask" [drivers/net/ethernet/intel/ice/ice.ko] undefined!Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH RFC v6 4/6] ice: add admin commands to access cgu configuration
In reply to Vadim Fedorenko[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in…
Hi Vadim,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v6.3-rc1 next-20230310]
[cannot apply to tnguy-next-queue/dev-queue]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 patch link: https://lore.kernel.org/r/20230312022807.278528-5-vadfed%40meta.com patch subject: [PATCH RFC v6 4/6] ice: add admin commands to access cgu configuration config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230312/[email protected]/config) compiler: alpha-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/0b8a02c116e829e4a4f8dd4a3d584b47688fed76
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230312-103056 git checkout 0b8a02c116e829e4a4f8dd4a3d584b47688fed76
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=alpha olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/intel/ice/ice_lib.c: In function 'ice_init_feature_support':
>> drivers/net/ethernet/intel/ice/ice_lib.c:4334:53: error: 'ICE_F_PHY_RCLK' undeclared (first use in this function)
4334 | ice_set_feature_support(pf, ICE_F_PHY_RCLK);
| ^~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_lib.c:4334:53: note: each undeclared identifier is reported only once for each function it appears in
In file included from drivers/net/ethernet/intel/ice/ice_ptp.h:10,
from drivers/net/ethernet/intel/ice/ice.h:69,
from drivers/net/ethernet/intel/ice/ice_lib.c:4:
drivers/net/ethernet/intel/ice/ice_ptp_hw.h: At top level:
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:325:38: warning: 'ice_e823_zl_cgu_outputs' defined but not used [-Wunused-const-variable=]
325 | static const struct ice_cgu_pin_desc ice_e823_zl_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:306:38: warning: 'ice_e823_zl_cgu_inputs' defined but not used [-Wunused-const-variable=]
306 | static const struct ice_cgu_pin_desc ice_e823_zl_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:295:38: warning: 'ice_e823_si_cgu_outputs' defined but not used [-Wunused-const-variable=]
295 | static const struct ice_cgu_pin_desc ice_e823_si_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:279:38: warning: 'ice_e823_si_cgu_inputs' defined but not used [-Wunused-const-variable=]
279 | static const struct ice_cgu_pin_desc ice_e823_si_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:262:38: warning: 'ice_e810t_qsfp_cgu_outputs' defined but not used [-Wunused-const-variable=]
262 | static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:247:38: warning: 'ice_e810t_sfp_cgu_outputs' defined but not used [-Wunused-const-variable=]
247 | static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_outputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:224:38: warning: 'ice_e810t_qsfp_cgu_inputs' defined but not used [-Wunused-const-variable=]
224 | static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/ice/ice_ptp_hw.h:205:38: warning: 'ice_e810t_sfp_cgu_inputs' defined but not used [-Wunused-const-variable=]
205 | static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_inputs[] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~vim +/ICE_F_PHY_RCLK +4334 drivers/net/ethernet/intel/ice/ice_lib.c
4315
4316 /**
4317 * ice_init_feature_support
4318 * @pf: pointer to the struct ice_pf instance
4319 *
4320 * called during init to setup supported feature
4321 */
4322 void ice_init_feature_support(struct ice_pf *pf)
4323 {
4324 switch (pf->hw.device_id) {
4325 case ICE_DEV_ID_E810C_BACKPLANE:
4326 case ICE_DEV_ID_E810C_QSFP:
4327 case ICE_DEV_ID_E810C_SFP:
4328 case ICE_DEV_ID_E810_XXV_BACKPLANE:
4329 case ICE_DEV_ID_E810_XXV_QSFP:
4330 case ICE_DEV_ID_E810_XXV_SFP:
4331 ice_set_feature_support(pf, ICE_F_DSCP);
4332 ice_set_feature_support(pf, ICE_F_PTP_EXTTS);
4333 if (ice_is_phy_rclk_present(&pf->hw))
> 4334 ice_set_feature_support(pf, ICE_F_PHY_RCLK);
4335 /* If we don't own the timer - don't enable other caps */
4336 if (!pf->hw.func_caps.ts_func_info.src_tmr_owned)
4337 break;
4338 if (ice_is_cgu_present(&pf->hw))
4339 ice_set_feature_support(pf, ICE_F_CGU);
4340 if (ice_is_clock_mux_present_e810t(&pf->hw))
4341 ice_set_feature_support(pf, ICE_F_SMA_CTRL);
4342 if (ice_gnss_is_gps_present(&pf->hw))
4343 ice_set_feature_support(pf, ICE_F_GNSS);
4344 break;
4345 default:
4346 break;
4347 }
4348 }
4349
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Jiri Pirko
maintainerQuoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
Quoted 110 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Vadim Fedorenko
maintainerQuoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --dump device-get./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do device-get --json '{"id": 0}' ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --dump pin-get./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-get --json '{"id": 0, "pin-idx":1}' ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Quoted 111 lines
Quoted 111 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoQuoted 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.
1,594 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Jiri Pirko
maintainerQuoted 13 lines · Mon, Mar 13, 2023 at 04:33:13PM CET, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
Quoted 10 lines
./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump device-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump pin-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":1}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Yep, that is exactly what I was asking for. Thanks.
Please try to extend it a bit and add to the cover letter. Gives people better understanding of how this works.
Quoted 113 lines
Quoted 112 lines
Quoted 112 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Vadim Fedorenko
maintainerQuoted 25 lines · Jiri Pirko
Quoted 13 lines · Mon, Mar 13, 2023 at 04:33:13PM CET, [email protected] wrote:
Quoted 7 lines · Jiri Pirko
Quoted 4 lines · Sun, Mar 12, 2023 at 03:28:01AM CET, [email protected] wrote:
Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.
Could you please put here some command line examples to work with this?
We don't have open-source tools ready right now for specific hardware, but with YAML spec published you can use in-kernel tool to manipulate the values, i.e.:
Quoted 10 lines
./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump device-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do device-get --json '{"id": 0}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--dump pin-get./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-get --json '{"id": 0, "pin-idx":1}'./tools/net/ynl/cli.py--specDocumentation/netlink/specs/dpll.yaml--do pin-set --json '{"id":0, "pin-idx":1, "pin-frequency":1}'
Quoted 3 lines
Yep, that is exactly what I was asking for. Thanks.
Please try to extend it a bit and add to the cover letter. Gives people better understanding of how this works.
Sure, will extend the cover letter in the next version, thanks!
Quoted 114 lines
Quoted 114 lines
Quoted 113 lines
Quoted 113 lines
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation inptp_ocpis back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments todpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- movedpll_typeto uapi header
- renameDPLLA_DUMP_FILTERtoDPLLA_FILTER
- renamedpll_pin_statetodpll_pin_mode
- renameDPLL_MODE_FORCEDtoDPLL_MODE_MANUAL
- removeDPLL_CHANGE_PIN_TYPEenum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s -dev_name(parent)of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding
it or its parent. Instead use a parent/shared pin description to find correct pin internally indpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Removeptp_ocpdriver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
*ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing listArkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cguVadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL opsDocumentation/netlink/specs/dpll.yaml | 514 +++++ Documentation/networking/dpll.rst | 347 ++++ Documentation/networking/index.rst | 1 + MAINTAINERS | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/dpll/Kconfig | 7 + drivers/dpll/Makefile | 10 + drivers/dpll/dpll_core.c | 835 ++++++++ drivers/dpll/dpll_core.h | 99 + drivers/dpll/dpll_netlink.c | 1065 ++++++++++ drivers/dpll/dpll_netlink.h | 30 + drivers/dpll/dpll_nl.c | 126 ++ drivers/dpll/dpll_nl.h | 42 + drivers/net/ethernet/intel/Kconfig | 1 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 5 + .../net/ethernet/intel/ice/ice_adminq_cmd.h | 240 ++- drivers/net/ethernet/intel/ice/ice_common.c | 467 +++++ drivers/net/ethernet/intel/ice/ice_common.h | 43 + drivers/net/ethernet/intel/ice/ice_dpll.c | 1845 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_dpll.h | 96 + drivers/net/ethernet/intel/ice/ice_lib.c | 17 +- drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 240 +++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + drivers/ptp/Kconfig | 1 + drivers/ptp/ptp_ocp.c | 206 +- include/linux/dpll.h | 284 +++ include/uapi/linux/dpll.h | 196 ++ 31 files changed, 7135 insertions(+), 16 deletions(-)create mode 100644
Documentation/netlink/specs/dpll.yamlcreate mode 100644Documentation/networking/dpll.rstcreate mode 100644drivers/dpll/Kconfig
create mode 100644drivers/dpll/Makefile
create mode 100644drivers/dpll/dpll_core.c
create mode 100644drivers/dpll/dpll_core.h
create mode 100644drivers/dpll/dpll_netlink.ccreate mode 100644drivers/dpll/dpll_netlink.hcreate mode 100644drivers/dpll/dpll_nl.c
create mode 100644drivers/dpll/dpll_nl.h
create mode 100644drivers/net/ethernet/intel/ice/ice_dpll.ccreate mode 100644drivers/net/ethernet/intel/ice/ice_dpll.hcreate mode 100644include/linux/dpll.h
create mode 100644include/uapi/linux/dpll.hSignature · 1 line
2.34.1
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 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.
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 36 lines
drivers/dpll/dpll_core.c new file +36
-0+struct dpll_pin * +dpll_pin_alloc (u64 clock_id,u8 device_drv_id,struct module *module, +const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id; + pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + } + pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max; +xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret = xa_alloc(&dpll_pin_xa, &pin->idx, pin,
drivers/dpll/dpll_core.c line 483
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+ xa_limit_16b, GFP_KERNEL); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + }
This is odd flow. Just return 0 before "release" and have the goto-label dedicated to error path only.
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+ +return pin; +}
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoQuoted 26 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c line 27
Quoted 5 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h>
Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Quoted 12 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };struct ocp_attr_group {
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 2 lines
drivers/ptp/ptp_ocp.c +0
-0@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];
It is quite customary to use defines for const numbers like this. Why don't you do that in ptp_ocp?
Quoted 46 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 10 lines
drivers/ptp/ptp_ocp.c +7
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); } +static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;
Just pass &bp->sma[i] as a priv to dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use of sma_nr at all.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 9 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);
No need to cast (void *), remove it.
Quoted 15 lines
drivers/ptp/ptp_ocp.c +15
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1);
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+return 0 ; + } +return -EINVAL ; +} + +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +
No need for empty line, I believe.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;
Just:
return mode == DPLL_MODE_AUTOMATIC;
Quoted 27 lines
drivers/ptp/ptp_ocp.c +27
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; +
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ; +return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,
Why you need const for u32?
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;
This is weird. I believe you should handle unsupported frequencies gracefully.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +
Avoid double empty lines.
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;
I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
and leave the frequency constant.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 4 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {
const
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,
Should be called "source_pin_get" and return (struct dpll_pin *) On the driver api level, no reason to pass indexes. Work with objects.
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {
const
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 12 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;
Won't fit. Just use:
char *sma = "SMA0"
to be safe
Quoted 23 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +10
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out;
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+ + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ; + prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;
Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {
How it could be NULL?
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 1 line
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;
This would not be needed if the error path iterates over indexes which were successul.
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)
You don't do unregister of pin here.
Quoted 18 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +2
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp); +dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Vadim FedorenkoQuoted 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
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 9 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F: Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-driveF:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support.
Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))
drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))
This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
You can have a macro to help driver to assemble array of supported frequencies and ranges.
Quoted 15 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +
[...]
Quoted 14 lines
drivers/dpll/dpll_core.c new file +14
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ;
drivers/dpll/dpll_core.c
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret; + ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)
How exactly this can happen? Looks to me like only in case of a bug. WARN_ON() perhaps (put directly into dpll_xa_ref_dpll_find()?
drivers/dpll/dpll_core.c
Quoted 11 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)
Use && and single if
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +
[...]
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref;
drivers/dpll/dpll_core.c
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq)) +return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;
return what the op returns: ret
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +
[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))
ret = ..
if (ret)
return ret;
Please use this pattern in other ops call code as well.
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;
[...]
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jiri Pirko
maintainerRe: [PATCH RFC v6 3/6] dpll: documentation on DPLL subsystem interface
In reply to Vadim FedorenkoQuoted 24 lines · Sun, Mar 12, 2023 at 03:28:04AM CET, [email protected] wrote:
Add documentation explaining common netlink interface to configure DPLL devices and monitoring events. Common way to implement DPLL device in a driver is also covered.
Signed-off-by Vadim Fedorenko <[email protected]>Signed-off-by Arkadiusz Kubalewski <[email protected]>---
Documentation/networking/dpll.rst| 347 +++++++++++++++++++++++++++++Documentation/networking/index.rst| 1 +2 files changed, 348 insertions(+)create mode 100644
Documentation/networking/dpll.rstDocumentation/networking/dpll.rst new file +6
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +The Linux kernel DPLL subsystem +=============================== +
Documentation/networking/dpll.rst line 16
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ +The main purpose of DPLL subsystem is to provide general interface +to configure devices that use any kind of Digital PLL and could use +different sources of signal to synchronize to as well as different +types of outputs. +The main interface is NETLINK_GENERIC based protocol with an event +monitoring multicast group defined. + + +Dpll object
rather perhaps "Device object"?
Documentation/networking/dpll.rst line 20
Quoted 4 lines
Documentation/networking/dpll.rst new file +4
-0+=========== +Single dpll device object means single Digital PLL circuit and bunch of +pins connected with it. +It provides its capablities and current status to the user in response
Which capabilities you have in mind. There is CAPs for pins, but I see none for device.
Documentation/networking/dpll.rst line 30
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+to the `do` request of netlink command ``DPLL_CMD_DEVICE_GET`` and list +of dplls registered in the subsystem with `dump` netlink request of same +command. +Requesting configuration of dpll device is done with `do` request of +netlink ``DPLL_CMD_DEVICE_SET`` command. + + +Pin object +========== +A pin is amorphic object which represents either input or output, it
In the code and UAPI you use terms "source" and "output". Please align to that.
Documentation/networking/dpll.rst line 35
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+could be internal component of the device, as well as externaly +connected. +The number of pins per dpll vary, but usually multiple pins shall be +provided for a single dpll device. +Pin's properities and capabilities are provided to the user in response
s/properities/properties/
There is more provided, like "status" for example.
Documentation/networking/dpll.rst line 38
Quoted 3 lines
Documentation/networking/dpll.rst new file +3
-0+to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. +It is also possible to list all the pins that were registered either +with dpll or different pin with `dump` request of ``DPLL_CMD_PIN_GET``
I don't follow. Dump of DPLL_CMD_PIN_GET just dumps always all the pins in the system. Am I missing something?
Documentation/networking/dpll.rst line 48
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+command. +Configuration of a pin can be changed by `do` request of netlink +``DPLL_CMD_PIN_SET`` command. + + +Shared pins +=========== +Pin can be shared by multiple dpll devices. Where configuration on one +pin can alter multiple dplls (i.e. PIN_FREQUENCY, PIN_DIRECTION), +or configure just one pin-dpll pair (i.e. PIN_PRIO, PIN_STATE).
Perhaps this can be extended to something like this:
A single pin object can be registered to multiple dpll devices. Then there are two groups of configuration knobs:
1) Set on a pin - the configuration affects all dpll devices pin is registered to. (i.e. PIN_FREQUENCY, PIN_DIRECTION),
2) Set on a pin-dpll tuple - the configuration affects only selected dpll device. (i.e. PIN_PRIO, PIN_STATE).
Documentation/networking/dpll.rst line 55
Quoted 7 lines
Documentation/networking/dpll.rst new file +7
-0+ + +MUX-type pins +============= +A pin can be MUX-type, which aggregates child pins and serves as pin +multiplexer. One or more pins are attached to MUX-type instead of being +directly connected to a dpll device.
Perhaps you can say "registered" in stead of "connected" and "attached" so this is aligned with the function names?
Documentation/networking/dpll.rst line 56
Quoted 1 line
Documentation/networking/dpll.rst new file +1
-0+Pins registered with a MUX-type provides user with additional nested
s/provides/provide/
Documentation/networking/dpll.rst line 57
Quoted 1 line
Documentation/networking/dpll.rst new file +1
-0+attribute ``DPLL_A_PIN_PARENT`` for each parrent they were registered
s/parrent/parent/
I'm confused. Can one pin be registered to multiple parents? How is that supposed to be working?
Documentation/networking/dpll.rst line 67
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+with. +Only one child pin can provide it's signal to the parent MUX-type pin at +a time, the selection is done with requesting change of child pin state +to ``DPLL_PIN_STATE_CONNECTED`` and providing a target MUX-type pin +index value in ``DPLL_A_PARENT_PIN_IDX`` + + +Pin priority +============ +Some devices might offer a capability of automatic pin selection mode.
Tell the enum value.
Documentation/networking/dpll.rst line 75
Quoted 8 lines
Documentation/networking/dpll.rst new file +8
-0+Usually such automatic selection is offloaded to the hardware, +which means only pins directly connected to the dpll are capable of +automatic source pin selection. +In automatic selection mode, the user cannot manually select a source +pin for the device, instead the user shall provide all directly +connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would +pick a highest priority valid signal and connect with it. +Child pin of MUX-type are not capable of automatic source pin selection,
s/are not/is not/
Documentation/networking/dpll.rst line 77
Quoted 2 lines
Documentation/networking/dpll.rst new file +2
-0+in order to configure a source of a MUX-type pin the user still needs +to request desired pin state.
Perhaps emphasize that this is the state of the child?
Quoted 34 lines
Documentation/networking/dpll.rst new file +34
-0+ + +Configuration commands group +============================ + +Configuration commands are used to get or dump information about +registered DPLL devices (and pins), as well as set configuration of +device or pins. As DPLL device could not be abstract and reflects real +hardware, there is no way to add new DPLL device via netlink from user +space and each device should be registered by it's driver. + +All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent +any spamming/D.o.S. from unauthorized userspace applications. + +List of command with possible attributes +======================================== + +All constants identifying command types use ``DPLL_CMD_`` prefix and +suffix according to command purpose. All attributes use ``DPLL_A_`` +prefix and suffix according to attribute purpose: + + ============================ ======================================= + ``DEVICE_GET`` command to get device info or dump list + of available devices + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``MODE`` attr selection mode + ``MODE_SUPPORTED`` attr available selection modes + ``SOURCE_PIN_IDX`` attr index of currently selected source + ``LOCK_STATUS`` attr internal frequency-lock status + ``TEMP`` attr device temperature information + ``CLOCK_ID`` attr Unique Clock Identifier (EUI-64), + as defined by the IEEE 1588 standard
Documentation/networking/dpll.rst line 121
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``TYPE`` attr type or purpose of dpll device + ``DEVICE_SET`` command to set dpll device configuration + ``ID`` attr internal dpll device index + ``NAME`` attr dpll device name (not required if + dpll device index was provided) + ``MODE`` attr selection mode to configure + ``PIN_GET`` command to get pin info or dump list of + available pins + ``DEVICE`` nest attr for each dpll device pin is + connected with
Ah, now I understand what this is about. Didn't occur to me from the netlink UAPI :/
Quoted 26 lines
Documentation/networking/dpll.rst new file +26
-0+ ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_PRIO`` attr priority of pin on the dpll device + ``PIN_STATE`` attr state of pin on the dpll device + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DESCRIPTION`` attr description provided by driver + ``PIN_TYPE`` attr type of a pin + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency in case + pin/dpll supports any frequency + ``PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency in case + pin/dpll supports any frequency + ``PIN_PARENT`` nest attr for each MUX-type parent, that + pin is connected with + ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DPLL_CAPS`` attr bitmask of pin-dpll capabilities + + ``PIN_SET`` command to set pins configuration + ``ID`` attr internal dpll device index
Documentation/networking/dpll.rst line 157
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``BUS_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``DEV_NAME`` attr dpll device name (not required if + dpll device ID was provided) + ``PIN_IDX`` attr index of a pin on the dpll device + ``PIN_DIRECTION`` attr direction to be set + ``PIN_FREQUENCY`` attr frequency to be set + ``PIN_PRIO`` attr pin priority to be set + ``PIN_STATE`` attr pin state to be set + ``PIN_PRIO`` attr pin priority to be set
I think it would be good to emhasize which attribute is valid in which combination, meaning alone, dpll needs to be specified, parent pin needs to be specified
Documentation/networking/dpll.rst line 169
Quoted 12 lines
Documentation/networking/dpll.rst new file +12
-0+ ``PIN_PARENT_IDX`` attr if provided state is to be set with + parent pin instead of with dpll device + +Netlink dump requests +===================== + +The ``DEVICE_GET`` and ``PIN_GET`` commands are capable of dump type +netlink requests. Possible response message attributes for netlink dump +requests: + + ============================== ======================================= + ``PIN_GET`` command to dump pins
Maintain the order and start with DEVICE_GET
Quoted 16 lines
Documentation/networking/dpll.rst new file +16
-0+ ``PIN`` attr nested type contains single pin + ``DEVICE`` nest attr for each dpll device pin is + connected with + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``PIN_IDX`` attr index of dumped pin (on dplls) + ``PIN_DESCRIPTION`` description of a pin provided by driver + ``PIN_TYPE`` attr value of pin type + ``PIN_FREQUENCY`` attr current frequency of a pin + ``PIN_FREQUENCY_SUPPORTED`` attr provides supported frequencies + ``PIN_RCLK_DEVICE`` attr name of a device, where pin + recovers clock signal from + ``PIN_DIRECTION`` attr direction of a pin + ``PIN_PARENT`` nest attr for each MUX-type parent, + that pin is connected with
Documentation/networking/dpll.rst line 195
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+ ``PIN_PARENT_IDX`` attr index of a parent pin on the dpll + device + ``PIN_STATE`` attr state of a pin on parent pin + + ``DEVICE_GET`` command to dump dplls + ``DEVICE`` attr nested type contatin a single + dpll device + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name
Hmm, why you need to repeat this for dump? Just say the message format is the same as for DO and you are done with it.
Quoted 108 lines
Documentation/networking/dpll.rst new file +108
-0+ + +Dpll device level configuration pre-defined enums +================================================= + +For all below enum names used for configuration of dpll device use +the ``DPLL_`` prefix. + +Values for ``DPLL_A_LOCK_STATUS`` attribute: + + ============================= ====================================== + ``LOCK_STATUS_UNLOCKED`` DPLL is in freerun, not locked to any + source pin + ``LOCK_STATUS_CALIBRATING`` DPLL device calibrates to lock to the + source pin signal + ``LOCK_STATUS_LOCKED`` DPLL device is locked to the source + pin frequency + ``LOCK_STATUS_HOLDOVER`` DPLL device lost a lock, using its + frequency holdover capabilities + +Values for ``DPLL_A_MODE`` attribute: + + =================== ================================================ + ``MODE_FORCED`` source pin is force-selected by setting pin + state to ``DPLL_PIN_STATE_CONNECTED`` on a dpll + ``MODE_AUTOMATIC`` source pin is auto selected according to + configured pin priorities and source signal + validity + ``MODE_HOLDOVER`` force holdover mode of DPLL + ``MODE_FREERUN`` DPLL is driven by supplied system clock without + holdover capabilities + ``MODE_NCO`` similar to FREERUN, with possibility to + numerically control frequency offset + +Values for ``DPLL_A_TYPE`` attribute: + + ============= ================================================ + ``TYPE_PPS`` DPLL used to provide pulse-per-second output + ``TYPE_EEC`` DPLL used to drive ethernet equipment clock + + + +Pin level configuration pre-defined enums +========================================= + +For all below enum names used for configuration of pin use the +``DPLL_PIN`` prefix. + +Values for ``DPLL_A_PIN_STATE`` attribute: + + ======================= ======================================== + ``STATE_CONNECTED`` Pin connected to a dpll or parent pin + ``STATE_DISCONNECTED`` Pin disconnected from dpll or parent pin + +Values for ``DPLL_A_PIN_DIRECTION`` attribute: + + ======================= ============================== + ``DIRECTION_SOURCE`` Pin used as a source of signal + ``DIRECTION_OUTPUT`` Pin used to output signal + +Values for ``DPLL_A_PIN_TYPE`` attributes: + + ======================== ======================================== + ``TYPE_MUX`` MUX type pin, connected pins shall have + their own types + ``TYPE_EXT`` External pin + ``TYPE_SYNCE_ETH_PORT`` SyncE on Ethernet port + ``TYPE_INT_OSCILLATOR`` Internal Oscillator (i.e. Holdover with + Atomic Clock as a Source) + ``TYPE_GNSS`` GNSS 1PPS source + +Values for ``DPLL_A_PIN_DPLL_CAPS`` attributes: + + ============================= ================================ + ``CAPS_DIRECTION_CAN_CHANGE`` Bit present if direction can change + ``CAPS_PRIORITY_CAN_CHANGE`` Bit present if priority can change + ``CAPS_STATE_CAN_CHANGE`` Bit present if state can change + + +Notifications +============= + +DPLL device can provide notifications regarding status changes of the +device, i.e. lock status changes, source/output type changes or alarms. +This is the multicast group that is used to notify user-space apps via +netlink socket: ``DPLL_MCGRP_MONITOR`` + +Notifications messages (attrbiutes use ``DPLL_A`` prefix): + + ========================= ========================================== + ``EVENT_DEVICE_CREATE`` event value new DPLL device was created + ``ID`` attr internal dpll device ID + ``DEV_NAME`` attr dpll device name + ``BUS_NAME`` attr dpll device bus name + ``EVENT_DEVICE_DELETE`` event value DPLL device was deleted + ``ID`` attr dpll device index + ``EVENT_DEVICE_CHANGE`` event value DPLL device attribute has + changed + ``ID`` attr modified dpll device ID + ``PIN_IDX`` attr the modified pin index + +Device change event shall consiste of the attribute and the value that +has changed. + + +Device driver implementation +============================ +
Documentation/networking/dpll.rst line 313
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+Device is allocated by ``dpll_device_get`` call. Second call with the +same arguments doesn't create new object but provides pointer to +previously created device for given arguments, it also increase refcount +of that object. +Device is deallocated by ``dpll_device_put`` call, which first decreases +the refcount, once refcount is cleared the object is destroyed. + +Device should implement set of operations and register device via +``dpll_device_register`` at which point it becomes available to the +users. Only one driver can register a dpll device within dpll subsytem.
"Driver instance". Btw, I need to change it for mlx5. I will try to implement it in coming days.
Documentation/networking/dpll.rst line 321
Quoted 8 lines
Documentation/networking/dpll.rst new file +8
-0+Multiple driver instances can obtain reference to it with +``dpll_device_get``. + +The pins are allocated separately with ``dpll_pin_get``, it works +similarly to ``dpll_device_get``. Creates object and the for each call +with the same arguments the object refcount increases. + +Once DPLL device is created, allocated pin can be registered with it
In this text, you use "dpll", "Dpll", "DPLL". Could you unify?
Documentation/networking/dpll.rst line 328
Quoted 7 lines
Documentation/networking/dpll.rst new file +7
-0+with 2 different methods, always providing implemented pin callbacks, +and private data pointer for calling them: +``dpll_pin_register`` - simple registration with a dpll device. +``dpll_pin_on_pin_register`` - register pin with another MUX type pin. + +For different instances of a device driver requiring to find already +registered DPLL (i.e. to connect its pins to id) use ``dpll_device_get``
s/to id/to it/
Documentation/networking/dpll.rst line 331
Quoted 3 lines
Documentation/networking/dpll.rst new file +3
-0+to obtain proper dpll device pointer. + +The name od DPLL device is generated based on registerer provided device
s/name od/name of/
Quoted 5 lines
Documentation/networking/dpll.rst new file +5
-0+struct pointer and dev_driver_id value. +Name is in format: ``%s_%u`` witch arguments: +``dev_name(struct device *)`` - syscall on parent device struct +``dev_driver_idx`` - registerer given id +
Documentation/networking/dpll.rst line 346
Quoted 10 lines
Documentation/networking/dpll.rst new file +10
-0+Notifications of adding or removing DPLL devices are created within +subsystem itself. +Notifications about registering/deregistering pins are also invoked by +the subsystem. +Notifications about dpll status changes shall be requested by device +driver with ``dpll_device_notify`` corresponding attribute as a reason. + +There is no strict requirement to implement all the operations for +each device, every operation handler is checked for existence and +ENOTSUPP is returned in case of absence of specific handler.
Not sure internal implementation details are necessary. Just say that driver is free to implement a set of ops it supports, leave the rest not implemented.
Quoted 16 lines
Documentation/networking/dpll.rst new file +1
-0+Documentation/networking/index.rst +1
-0@@ -17,6 +17,7 @@ Contents: dsa/index devlink/index caif/index + dpll ethtool-netlink ieee802154 j1939Signature · 1 line
2.34.1
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoQuoted 3 lines
From: Vadim Fedorenko <[email protected]>
Sent: Tuesday, March 14, 2023 12:00 AM
[...]
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+ +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/ +struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index;Quoted 8 lines
drivers/dpll/dpll_core.c line 331
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.
Quoted 7 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is
the same for both of them. But Arkadiusz can tell more about it.
Yes, exactly.
One driver can have multiple dplls with the same clock id. Actually dev_driver_id makes dpll objects unique.
Quoted 4 lines
Quoted 2 lines
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?
Looks good to me.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/dpll/dpll_core.c new file +19
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/** +* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete Quoted 8 lines
drivers/dpll/dpll_core.c line 356
Quoted 6 lines
+ * dpll device object.
+ */drivers/dpll/dpll_core.c new file +4
-0+void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;Remove this check. The driver should not call this with NULL.
Quoted 3 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.
I agree, IMHO it is better to have safety checks :)
Quoted 8 lines
Quoted 5 lines
drivers/dpll/dpll_core.c line 359
Quoted 3 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Yes, great point!
Quoted 58 lines
Quoted 58 lines
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56
Quoted 7 lines
Quoted 5 lines
If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2Looks good, will change it
Makes sense to me.
Quoted 42 lines
Quoted 33 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
Quoted 30 lines
drivers/dpll/dpll_core.c new file +30
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); + +/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver Quoted 8 lines
Quoted 6 lines
+ * @module: reference to registering module
+ * @prop: dpll pin properties
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorExtra "*"'s
Quoted 1 line
Ok, I can re-format the comments across the files.
This is expected on enumerating return values in kernel-docs:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#Return%20values
Quoted 58 lines
Quoted 4 lines
Review
Quoted 4 lines
+ */
(quoted diff) +2
-0+struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module*module,
Quoted 5 lines
Odd whitespace.
Also, func should be static.
Fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 448
Quoted 10 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;Name inconsistency: driver/drv
you have it on multiple placesChanged it every where, thanks for spotting.
Quoted 18 lines
Quoted 18 lines
drivers/dpll/dpll_core.c new file +17
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + }Quoted 9 lines
drivers/dpll/dpll_core.c line 470
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 6 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case.
Not sure if the pointer way is much better...
I also don't feel it.
Dpll subsystem directly using memory of different driver doesn't look like a great design.
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
drivers/dpll/dpll_core.c new file +25
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new
+ * if doesn't exist yet.Quoted 9 lines
Quoted 4 lines
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorThis is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
Quoted 2 lines
Yep, will clear .h files.
There might be some issues, and certainly makes sense to have them in one place.
Quoted 8 lines
Quoted 7 lines
drivers/dpll/dpll_core.c line 503
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,Again, why do you need this
device_drv_id? Clock id should be enough.I explained the reason earlier, but the naming is fixed.
Yes, this device_drv_id is id of a pin not a dpll device id. Maybe worth to rename it to make it more clear.
Quoted 15 lines
Quoted 15 lines
drivers/dpll/dpll_core.c line 513
Quoted 12 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Quoted 5 lines
Quoted 3 lines
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.I think
clock_id+dev_driver_id+ module should identify the pin exactly.
Yes, they should be unique for a single pin object, and enough for getting pin reference.
Basically if driver would call twice this with different props, it would be broken.
We could have props compared here as well.
Quoted 2 lines
And
now I think that *prop is not needed here at all. Arkadiusz, any thoughts?
As dpll_pin_alloc is having them assigned to a pin object, thus had to put it here. Not sure how to solve it differently.
Jiri's suggestion to put dev_driver_id inside of pin props would also work AFAIU.
[...]
Quoted 31 lines
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) : NULL;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?
Quoted 2 lines
Well, these questions go to Arkadiusz...
If pin is able to recover signal from some device this shall convey that device struct pointer.
Name of that device is later passed to the user with DPLL_A_PIN_RCLK_DEVICE attribute.
Sure we can have pointer to device and use dev_name (each do/dump) on netlink part. But isn't it better to have the name ready to use there?
It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
[...]
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 755
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
I believe if proper synchronization in place it shall not be NULL, I left it after fixing some issue with access to the pin that was already removed..
Quoted 7 lines
Quoted 4 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
After quick thinking, it might be doable, storing pin being registered on dpll->pin_refs under given by driver pin's dev_driver_idx or whatever it would be named.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
drivers/dpll/dpll_core.c new file +23
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +} +EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +*
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
+ * Return: pointer to the data
+ */
+void *dpll_pin_on_dpll_priv(const structdpll_device*dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
No strong opinion, probably doable.
Quoted 9 lines
Quoted 9 lines
drivers/dpll/dpll_core.c line 786
Quoted 6 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
const of struct dpll_pin *pin makes a warning/error there, there is something broken on xarray implementation of for_each I believe.
[...]
Quoted 44 lines
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 241
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+ +static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+enum dpll_pin_state state; +struct nlattr *nest; +unsigned long index; +int ret; + +xa_for_each (&pin->parent_refs, index, ref) { +if (WARN_ON (!ref->ops->state_on_pin_get)) +return -EFAULT ; + ret = ref->ops->state_on_pin_get (pin, ref->pin, &state, + extack); +if (ret) +return -EFAULT ; + nest =nla_nest_start (msg,DPLL_A_PIN_PARENT ); +if (!nest) +return -EMSGSIZE ; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/dpll_netlink.c line 267
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +if (nla_put_u8 (msg,DPLL_A_PIN_STATE , state)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +nla_nest_end (msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/
Quoted 7 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
Quoted 55 lines
Quoted 45 lines
Quoted 45 lines
drivers/dpll/dpll_netlink.c new file +44
-0+ +return 0 ; + +nest_cancel: +nla_nest_cancel (msg, nest); +return ret; +} + +static int +dpll_msg_add_pin_dplls (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct nlattr *attr; +unsigned long index; +int ret; + +xa_for_each (&pin->dpll_refs, index, ref) { + attr =nla_nest_start (msg,DPLL_A_DEVICE ); +if (!attr) +return -EMSGSIZE ; + ret =dpll_msg_add_dev_handle (msg, ref->dpll); +if (ret) + goto nest_cancel; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; +nla_nest_end (msg, attr); + } + +return 0 ; + +nest_cancel: +nla_nest_end (msg, attr); +return ret; +} + +static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack)Quoted 9 lines
drivers/dpll/dpll_netlink.c line 316
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 3 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.
Yes, confusing a bit, I agree we need a fix of this.
Isn't it that dpll has an INDEX assigned by dpll subsystem on its allocation and pin have ID given by the driver?
[...]
Quoted 60 lines
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 563
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+static int +dpll_pin_set_from_nlattr (struct dpll_device *dpll, +struct dpll_pin *pin,struct genl_info *info) +{ +enum dpll_pin_state state =DPLL_PIN_STATE_UNSPEC ; +u32 parent_idx =PIN_IDX_INVALID ;You just need this
PIN_IDX_INVALIDdefine internally in this function, change the flow to avoid a need for it.I'll re-think it, thanks.
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 568
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +5
-0+int rem, ret = -EINVAL ; +struct nlattr *a; + +nla_for_each_attr (a,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
I had some unknown crashes when I was using such access. I might have lost some
checks, will try it again.Quoted 32 lines
Quoted 18 lines
drivers/dpll/dpll_netlink.c new file +17
-0+switch (nla_type (a)) { +case DPLL_A_PIN_FREQUENCY : + ret =dpll_pin_freq_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_DIRECTION : + ret =dpll_pin_direction_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PRIO : + ret =dpll_pin_prio_set (dpll, pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PARENT_IDX :drivers/dpll/dpll_netlink.c line 595
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ parent_idx =nla_get_u32 (a); +break ; +case DPLL_A_PIN_STATE : + state =nla_get_u8 (a); +break ; +default : +break ; + } + } +if (state !=DPLL_PIN_STATE_UNSPEC ) {Again, change the flow to:
if (attrs[DPLL_A_PIN_STATE]) {
Quoted 4 lines
Quoted 2 lines
and avoid need for this value set/check.
Yep, will try.
Yes, this shall work now, as long as there are no multiple nested attributes coming from userspace.
[...]
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
+void dpll_pin_post_doit(const struct
genl_split_ops*ops, structsk_buff*skb,drivers/dpll/dpll_netlink.c new file +4
-0+ struct genl_info *info) +{ +mutex_unlock (&dpll_pin_xa_lock); +dpll_post_doit (ops, skb, info);Quoted 9 lines
drivers/dpll/dpll_netlink.c line 878
Quoted 5 lines
drivers/dpll/dpll_netlink.c new file +5
-0+} + +int dpll_pin_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Quoted 4 lines
Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?
Not really, this is why it is there :(
A single global lock for whole dpll subsystem?
Quoted 38 lines
Quoted 36 lines
Quoted 15 lines
drivers/dpll/dpll_netlink.c new file +14
-0+ +return dpll_pre_dumpit (cb); +} + +int dpll_pin_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_pin_xa_lock); + +return dpll_post_dumpit (cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/dpll_netlink.c line 902
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
Quoted 8 lines
But with full object-snapshot user space app will lose the information about
what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
I agree that from functional perspective it is better to have on userspace a reason of the notification.
[...]
Thank you,
Arkadiusz
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 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
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 4:45 PM[...]
MAINTAINERS F:
Quoted 5 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F:
Documentation/networking/device_drivers/ethernet/freescale/dpaa2/swit
ch-driveQuoted 4 lines
F:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
Quoted 3 lines
You can have a macro to help driver to assemble array of supported frequencies and ranges.
I understand suggestion on yaml, but here I am confused.
How do they relate to the supported frequency passed between driver and dpll subsystem?
This bitfield is not visible to the userspace, and sure probably adding macro can be useful.
Quoted 39 lines
Quoted 16 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +[...]
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret;
Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)How exactly this can happen? Looks to me like only in case of a bug.
WARN_ON()perhaps (put directly intodpll_xa_ref_dpll_find()?
Yes, makes sense.
Quoted 16 lines
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)Use && and single if
Make sense to me.
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +[...]
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref; +unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq))
Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;return what the op returns: ret
Why would we return here a driver return code, userspace can have this info from extack. IMHO return values of dpll subsystem shall be not dependent on what is returned from the driver.
Quoted 28 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))ret = ..
if (ret)
Quoted 4 lines
return ret;Please use this pattern in other ops call code as well.
This is the same as above (return code by driver) explanation.
Quoted 8 lines
Quoted 6 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;[...]
Thanks,
Arkadiusz
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Jiri PirkoQuoted 22 lines · Jiri Pirko
Quoted 21 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.
Quoted 13 lines
drivers/ptp/ptp_ocp.c line 27
Quoted 10 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h> Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Ah, yeah, you've mentioned it for ice driver last time, but I forgot to check it here. Removed.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };
Quoted 7 lines
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0struct ocp_attr_group {@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];It is quite customary to use defines for const numbers like this. Why don't you do that in
ptp_ocp?
Historical reasons. Jonathan might answer this question. I will add it to my TODO list for the driver.
Quoted 49 lines
Quoted 49 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)drivers/ptp/ptp_ocp.c +0
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); }
Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.
I'm still thinking about the change that you proposed to remove these _priv() helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);No need to cast (void *), remove it.
Fixed everywhere in the code, thanks.
Quoted 20 lines
Quoted 20 lines
drivers/ptp/ptp_ocp.c +19
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1); +return 0 ; + } +return -EINVAL ; +}
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+ +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +No need for empty line, I believe.
Ok.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;Just:
Quoted 2 lines
return mode == DPLL_MODE_AUTOMATIC;
Done, thanks!
Quoted 31 lines
Quoted 31 lines
drivers/ptp/ptp_ocp.c +31
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; + +if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ;
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,Why you need const for u32?
No need, true, removed.
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;This is weird. I believe you should handle unsupported frequencies gracefully.
Currently hardware supports fixed frequencies only. That's why I have to do this kind of "dance". Hopefully we will improve it to support variable frequency.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +Avoid double empty lines.
Yep.
Quoted 27 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
Quoted 1 line
and leave the frequency constant.
It's actually a mistake. It should be 1 which means 1Hz, PPS. The value returned by sma_op->get is actually the type of the signal where 0 is 1PPS, 1 is 10Mhz and so on.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 6 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {const
Will change it together with API part. Otherwise it doesn't compile.
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,Should be called "
source_pin_get" and return (structdpll_pin*) On the driver api level, no reason to pass indexes. Work with objects.
Good point, will improve it.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {const
Yep.
Quoted 18 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 13 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;Won't fit. Just use:
char *sma = "SMA0"
to be safe
Got it.
Quoted 29 lines
Quoted 29 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +15
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out; + + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ;
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
well, yes. but at the same time Arkadiusz raised a good question about accessing driver's memory from the subsystem code - doesn't look clean.
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {How it could be NULL?
Allocation fail?
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 2 lines
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;This would not be needed if the error path iterates over indexes which were successul.
Yeah, I'll make it the same way it's done in ice.
Quoted 15 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 12 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)You don't do unregister of pin here.
Yeah, actually error path and unload path should be re-implemented.
Quoted 19 lines
Quoted 19 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +2
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp); +dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Kubalewski, ArkadiuszQuoted 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
In reply to Kubalewski, ArkadiuszQuoted 47 lines · Tue, Mar 14, 2023 at 05:43:18PM CET, [email protected] wrote:
Quoted 3 lines
From: Vadim Fedorenko <[email protected]>
Sent: Tuesday, March 14, 2023 12:00 AM[...]
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+ +/** +* dpll_device_get - find existing or create new dpll device +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* +* Get existing object of a dpll device, unique for given arguments. +* Create new if doesn't exist yet. +* +* Return: +* * valid dpll_device struct pointer if succeeded +* * ERR_PTR of an error +*/ +struct dpll_device * +dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module) +{ +struct dpll_device *dpll, *ret =NULL ; +unsigned long index;Quoted 8 lines
drivers/dpll/dpll_core.c line 331
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ +mutex_lock (&dpll_device_xa_lock); +xa_for_each (&dpll_device_xa, index, dpll) { + if (dpll->clock_id == clock_id && + dpll->dev_driver_id == dev_driver_id &&Why you need "
dev_driver_id"?clock_idis here for the purpose of identification, isn't that enough for you.Quoted 7 lines
dev_driver_idis needed to provide several DPLLs from one device. In ice driver
implementation there are 2 different DPLLs - to recover from PPS input and to
recover from Sync-E. I believe there is only one clock, that's why clock id is
the same for both of them. But Arkadiusz can tell more about it.Yes, exactly.
One driver can have multiple dplls with the same clock id. Actuallydev_driver_idmakes dpll objects unique.Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Plus, the name is odd. "
dev_driver" should certainly be avoided.Simply id doesn't tell anything either.
dpll_dev_id?Looks good to me.
Let's call this "device_index" and "pin_index" for the pin getter as I suggested in the other email.
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 17 lines
drivers/dpll/dpll_core.c new file +15
-0+ dpll->module == module) { + ret = dpll; +refcount_inc (&ret->refcount); +break ; + } + } +if (!ret) + ret =dpll_device_alloc (clock_id, dev_driver_id, module); +mutex_unlock (&dpll_device_xa_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (dpll_device_get); + +/** drivers/dpll/dpll_core.c line 356
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* dpll_device_put - decrease the refcount and free memory if possible +* @dpll: dpll_device struct pointer +* +* Drop reference for a dpll device, if all references are gone, delete +* dpll device object. +*/ +void dpll_device_put (struct dpll_device *dpll) +{ +if (!dpll) +return ;Remove this check. The driver should not call this with NULL.
Quoted 5 lines
Quoted 3 lines
Well,
netdev_put()has this kind of check. As well asspi_dev_put()ori2c_put_adapter()at least. Not sure I would like to avoid a bit of safety.I agree, IMHO it is better to have safety checks :)
IDK, we should rely on basic driver sanity. Let least put a WARN_ON() to these checks. But try to reduce them at least.
Quoted 76 lines
Quoted 9 lines
Quoted 6 lines
drivers/dpll/dpll_core.c line 359
Quoted 4 lines
drivers/dpll/dpll_core.c new file +3
-0+mutex_lock (&dpll_device_xa_lock); +if (refcount_dec_and_test (&dpll->refcount)) { +WARN_ON_ONCE (!xa_empty (&dpll->pin_refs));
ASSERT_DPLL_NOT_REGISTERED(dpll);Good point!
Yes, great point!
Quoted 64 lines
Quoted 63 lines
Quoted 31 lines
drivers/dpll/dpll_core.c new file +31
-0+xa_destroy (&dpll->pin_refs); +xa_erase (&dpll_device_xa, dpll->id); +kfree (dpll); + } +mutex_unlock (&dpll_device_xa_lock); +} +EXPORT_SYMBOL_GPL (dpll_device_put); + +/** +* dpll_device_register - register the dpll device in the subsystem +* @dpll: pointer to a dpll +* @type: type of a dpll +* @ops: ops for a dpll device +* @priv: pointer to private information of owner +* @owner: pointer to owner device +* +* Make dpll device available for user space. +* +* Return: +* * 0 on success +* * -EINVAL on failure +*/ +int dpll_device_register (struct dpll_device *dpll,enum dpll_type type, +struct dpll_device_ops *ops,void *priv, +struct device *owner) +{ +if (WARN_ON (!ops || !owner)) +return -EINVAL ; +if (WARN_ON (type <=DPLL_TYPE_UNSPEC || type >DPLL_TYPE_MAX )) +return -EINVAL ; +mutex_lock (&dpll_device_xa_lock);drivers/dpll/dpll_core.c line 400
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+if (ASSERT_DPLL_NOT_REGISTERED (dpll)) { +mutex_unlock (&dpll_device_xa_lock); +return -EEXIST ; + } + dpll->dev.bus = owner->bus; + dpll->parent = owner; + dpll->type = type; + dpll->ops = ops; +dev_set_name (&dpll->dev,"%s_%d" ,dev_name (owner), + dpll->dev_driver_id);This is really odd. As a result, the user would see something like:
pci/0000:01:00.0_1
pci/0000:01:00.0_2I have to say it is confusing. In devlink, is bus/name and the user could use this info to look trough sysfs. Here, 0000:01:00.0_1 is not there. Also, "_" might have some meaning on some bus. Should not concatename
dev_name()with anything.Thinking about this some more, the module/clock_id tuple should be uniqueue and stable. It is used for
dpll_device_get(), it could be used as the user handle, can't it?
Example:
ice/c92d02a7129f4747
mlx5/90265d8bf6e6df56If you really need the "
dev_driver_id" (as I believeclock_idshould be enough), you can put it here as well:
ice/c92d02a7129f4747/1
ice/c92d02a7129f4747/2
Quoted 3 lines
Quoted 1 line
Looks good, will change it
Makes sense to me.
Good. Fits the mlx5 model nicely.
Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
This would also be beneficial for mlx5, as mlx5 with 2 PFs would like to share instance of DPLL equally, there is no "one clock master". >
Quoted 26 lines
drivers/dpll/dpll_core.c new file +26
-0+ dpll->priv = priv; +xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_create (dpll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_device_register); + +/** +* dpll_device_unregister - deregister dpll device +* @dpll: registered dpll pointer +* +* Deregister device, make it unavailable for userspace. +* Note: It does not free the memory +*/ +void dpll_device_unregister (struct dpll_device *dpll) +{ +mutex_lock (&dpll_device_xa_lock); +ASSERT_DPLL_REGISTERED (dpll); +xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); +mutex_unlock (&dpll_device_xa_lock); +dpll_notify_device_delete (dpll); +} +EXPORT_SYMBOL_GPL (dpll_device_unregister); +drivers/dpll/dpll_core.c line 436
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+/** +* dpll_pin_alloc - allocate the memory for dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Return: +* * valid allocated dpll_pin struct pointer if succeeded +* * ERR_PTR of an error Extra "*"'s
Quoted 4 lines
Quoted 1 line
Ok, I can re-format the comments across the files.
This is expected on enumerating return values in kernel-docs:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#Return%20values
Ah, okay. I missed that. Sorry.
Quoted 66 lines
Quoted 59 lines
Quoted 5 lines
Review
Quoted 5 lines
+ */
(quoted diff) +2
-0+struct dpll_pin * +dpll_pin_alloc(u64 clock_id, u8 device_drv_id, struct module*module,
Quoted 5 lines
Odd whitespace.
Also, func should be static.
Fixed.
Quoted 14 lines
drivers/dpll/dpll_core.c line 448
Quoted 10 lines
drivers/dpll/dpll_core.c new file +9
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin; +int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id;Name inconsistency: driver/drv
you have it on multiple placesChanged it every where, thanks for spotting.
Quoted 18 lines
Quoted 18 lines
drivers/dpll/dpll_core.c new file +17
-0+ pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) { + ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + } +if (WARN_ON (prop->type <=DPLL_PIN_TYPE_UNSPEC || + prop->type >DPLL_PIN_TYPE_MAX )) { + ret = -EINVAL ; + goto release; + }Quoted 9 lines
drivers/dpll/dpll_core.c line 470
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ pin->prop.type = prop->type; + pin->prop.capabilities = prop->capabilities; + pin->prop.freq_supported = prop->freq_supported; + pin->prop.any_freq_min = prop->any_freq_min; + pin->prop.any_freq_max = prop->any_freq_max;Make sure that the driver maintains prop (static const) and just save the pointer. Prop does not need to be something driver needs to change.
Quoted 6 lines
What's the difference? For
ptp_ocp, we have the same configuration for all ext pins and the allocator only changes the name of the pin. Properties of the DPLL pins are stored within the pin object, not the driver, in this case.
Not sure if the pointer way is much better...
Quoted 3 lines
I also don't feel it.
Dpll subsystem directly using memory of different driver doesn't look like a great design.
Wait. This is done all the time in kernel. Almost every ops for example. Lots of other examples like that as well:
git grep "static const struct" drivers/net/
Quoted 52 lines
Quoted 39 lines
Quoted 29 lines
Quoted 29 lines
drivers/dpll/dpll_core.c new file +25
-0+xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC ); +xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC ); + ret =xa_alloc (&dpll_pin_xa, &pin->idx, pin, + xa_limit_16b,GFP_KERNEL ); +release: +if (ret) { +xa_destroy (&pin->dpll_refs); +xa_destroy (&pin->parent_refs); +kfree (pin->prop.description); +kfree (pin->rclk_dev_name); +kfree (pin); +return ERR_PTR (ret); + } + +return pin; +} + +/** +* dpll_pin_get - find existing or create new dpll pin +* @clock_id: clock_id of creator +* @dev_driver_id: id given by dev driver +* @module: reference to registering module +* @prop: dpll pin properties +* +* Get existing object of a pin (unique for given arguments) or create new
+ * if doesn't exist yet.Quoted 9 lines
Quoted 4 lines
+ *
+ * Return:
+ * * valid allocateddpll_pinstruct pointer if succeeded
+ * *ERR_PTRof an errorThis is one example, I'm pretty sure that there are others, when you have text inconsistencies in func doc for the same function in .c and .h Have it please only on one place. .c is the usual place.
Quoted 2 lines
Yep, will clear .h files.
There might be some issues, and certainly makes sense to have them in one place.
Quoted 7 lines
Quoted 7 lines
drivers/dpll/dpll_core.c line 503
Quoted 4 lines
+ */
drivers/dpll/dpll_core.c new file +2
-0+struct dpll_pin * +dpll_pin_get(u64 clock_id, u32 device_drv_id, struct module *module,Again, why do you need this
device_drv_id? Clock id should be enough.
Quoted 4 lines
Quoted 1 line
I explained the reason earlier, but the naming is fixed.
Yes, this
device_drv_idis id of a pin not a dpll device id. Maybe worth to rename it to make it more clear.
Yeah, device_index and pin_index
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
drivers/dpll/dpll_core.c line 513
Quoted 13 lines
drivers/dpll/dpll_core.c new file +10
-0+ const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pos, *ret =NULL ; +unsigned long index; + +mutex_lock (&dpll_pin_xa_lock); +xa_for_each (&dpll_pin_xa, index, pos) { +if (pos->clock_id == clock_id && + pos->dev_driver_id == device_drv_id && + pos->module == module) {Compare prop as well.
Can't the
driver_id(pin index) be something const as well? I think it should. And therefore it could be easily put inside.
Quoted 7 lines
Quoted 1 line
I think
clock_id+dev_driver_id+ module should identify the pin exactly.Yes, they should be unique for a single pin object, and enough for getting pin reference.
Basically if driver would call twice this with different props, it would be broken.
We could have props compared here as well.
Let's leave it as it is for now, it's ok.
Quoted 8 lines
Quoted 3 lines
And
now I think that *prop is not needed here at all. Arkadiusz, any thoughts?As
dpll_pin_allocis having them assigned to a pin object, thus had to put it here. Not sure how to solve it differently.
Jiri's suggestion to putdev_driver_idinside of pin props would also work AFAIU.
Let's have it as device_get()/pin_get() args as you have it right now. Makes more sense as the prop could be static const as I described in the other email.
Quoted 44 lines
[...]
Quoted 31 lines
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ +/** +* dpll_pin_register - register the dpll pin in the subsystem +* @dpll: pointer to a dpll +* @pin: pointer to a dpll pin +* @ops: ops for a dpll pin ops +* @priv: pointer to private information of owner +* @rclk_device: pointer to recovered clock device drivers/dpll/dpll_core.c line 596
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+* +* Return: +* * 0 on success +* * -EINVAL - missing dpll or pin +* * -ENOMEM - failed to allocate memory +*/ +int +dpll_pin_register (struct dpll_device *dpll,struct dpll_pin *pin, +struct dpll_pin_ops *ops,void *priv, +struct device *rclk_device)Wait a second, what is this "struct device *"? Looks very odd.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + const char *rclk_name = rclk_device ? dev_name(rclk_device) : NULL;If you need to store something here, store the pointer to the device directly. But this
rclk_deviceseems odd to me.Dev_nameis in case of PCI device for example 0000:01:00.0? That alone is incomplete. What should it server for?Quoted 2 lines
Well, these questions go to Arkadiusz...
If pin is able to recover signal from some device this shall convey that device struct pointer.
Name of that device is later passed to the user withDPLL_A_PIN_RCLK_DEVICEattribute.
Sure we can have pointer to device and usedev_name(each do/dump) on netlink part. But isn't it better to have the name ready to use there?
Quoted 2 lines
It might be incomplete only if one device would have some kind of access to a different bus? I don't think it is valid use case.
Very valid as I explained in the other email.
Quoted 18 lines
Basically the driver will refer only to the devices handled by that driver, which means if dpll is on some bus, also all the pins are there, didn't notice the need to have bus here as well.
[...]
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 755
Quoted 7 lines
drivers/dpll/dpll_core.c new file +7
-0+struct dpll_pin *dpll_pin_get_by_idx (struct dpll_device *dpll,u32 idx) +{ +struct dpll_pin_ref *pos; +unsigned long i; + +xa_for_each (&dpll->pin_refs, i, pos) { +if (pos && pos->pin && pos->pin->dev_driver_id == idx)How exactly
pos->pincould be NULL?
Quoted 2 lines
I believe if proper synchronization in place it shall not be NULL, I left it after fixing some issue with access to the pin that was already removed..
Then don't check it here.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Also, you are degrading the xarray to a mere list here with lookup like this. Why can't you use the pin index coming from driver and insert/lookup based on this index?
Quoted 7 lines
Quoted 3 lines
Good point. We just have to be sure, that drivers provide 0-based indexes for their pins. I'll re-think it.
After quick thinking, it might be doable, storing pin being registered on
dpll->pin_refsunder given by driver pin'sdev_driver_idxor whatever it would be named.
Yep.
Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/dpll/dpll_core.c new file +23
-0+return pos->pin; + } + +return NULL ; +} + +/** +* dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* +* Return: pointer to the data +*/ +void *dpll_priv (const struct dpll_device *dpll) +{ +return dpll->priv; +} +EXPORT_SYMBOL_GPL (dpll_priv); + +/** +* dpll_pin_on_dpll_priv - get the dpll device private owner data +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
+ * Return: pointer to the data
+ */
+void *dpll_pin_on_dpll_priv(const structdpll_device*dpll,IIUC, you use this helper from dpll ops in drivers to get per dpll priv. Just pass the priv directly to the op and avoid need for this helper, no? Same goes to the rest of the priv helpers.
Quoted 1 line
No strong opinion, probably doable.
It is better for the driver writer to actually see right away that there is a priv so he can use it and not need to get the priv from some place else (using pin index * lookup). Very nice example where this would work is the last patch of this set, where Vadim does not use priv at all.
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
drivers/dpll/dpll_core.c line 786
Quoted 7 lines
drivers/dpll/dpll_core.c new file +5
-0+ const struct dpll_pin *pin) +{ +struct dpll_pin_ref *ref; + + ref =dpll_xa_ref_pin_find ((struct xarray *)&dpll->pin_refs, pin);Why cast is needed here? You have this on multiple places.
Quoted 2 lines
constof structdpll_pin*pin makes a warning/error there, there is something broken on xarray implementation offor_eachI believe.
Either fix it or avoid using const arg. Cast's like this always smell and should be avoided.
Quoted 113 lines
[...]
Quoted 44 lines
Quoted 9 lines
drivers/dpll/dpll_netlink.c line 241
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+ +static int +dpll_msg_add_pins_on_pin (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref =NULL ;Why this needs to be initialized?
No need, fixed.
Quoted 32 lines
Quoted 17 lines
drivers/dpll/dpll_netlink.c new file +16
-0+enum dpll_pin_state state; +struct nlattr *nest; +unsigned long index; +int ret; + +xa_for_each (&pin->parent_refs, index, ref) { +if (WARN_ON (!ref->ops->state_on_pin_get)) +return -EFAULT ; + ret = ref->ops->state_on_pin_get (pin, ref->pin, &state, + extack); +if (ret) +return -EFAULT ; + nest =nla_nest_start (msg,DPLL_A_PIN_PARENT ); +if (!nest) +return -EMSGSIZE ; + if (nla_put_u32(msg, DPLL_A_PIN_PARENT_IDX,drivers/dpll/dpll_netlink.c line 267
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ ref->pin->dev_driver_id)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +if (nla_put_u8 (msg,DPLL_A_PIN_STATE , state)) { + ret = -EMSGSIZE ; + goto nest_cancel; + } +nla_nest_end (msg, nest); + }How is this function different to
dpll_msg_add_pin_parents()? Am I lost? To be honest, this x_on_pin/dpll, parent, refs dance is quite hard to follow for me :/Quoted 7 lines
Quoted 3 lines
Did you get lost here as well? If yes, this needs some serious think through :)
Let's re-think it again. Arkadiuzs, do you have clear explanation of the relationship between these things?
No, it is just leftover I didn't catch, we can leave one function and use it in both cases. Sorry about that, great catch!
Quoted 55 lines
Quoted 54 lines
Quoted 40 lines
drivers/dpll/dpll_netlink.c new file +39
-0+ +return 0 ; + +nest_cancel: +nla_nest_cancel (msg, nest); +return ret; +} + +static int +dpll_msg_add_pin_dplls (struct sk_buff *msg,struct dpll_pin *pin, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +struct nlattr *attr; +unsigned long index; +int ret; + +xa_for_each (&pin->dpll_refs, index, ref) { + attr =nla_nest_start (msg,DPLL_A_DEVICE ); +if (!attr) +return -EMSGSIZE ; + ret =dpll_msg_add_dev_handle (msg, ref->dpll); +if (ret) + goto nest_cancel; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) + goto nest_cancel; +nla_nest_end (msg, attr); + } + +return 0 ; + +nest_cancel: +nla_nest_end (msg, attr); +return ret; +}drivers/dpll/dpll_netlink.c line 316
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ +static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id))Is it "ID" or "INDEX" (IDX). Please make this consistent in the whole code.
Quoted 7 lines
Quoted 3 lines
I believe it's INDEX which is provided by the driver. I'll think about renaming,
but suggestions are welcome.Yes, confusing a bit, I agree we need a fix of this.
Isn't it that dpll has an INDEX assigned by dpll subsystem on its allocation and pin have ID given by the driver?
Driver should provice the device_index and pin_index in appropriate _get() functions. I think it is better to spell out "index". "idx" looks a bit odd. Either way, please unify the name all along the code, netlink included.
ID is your odd dual-handle construct, which I don't see a need for and only adds confusions. Better to remove it.
Quoted 89 lines
[...]
Quoted 60 lines
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 563
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +6
-0+static int +dpll_pin_set_from_nlattr (struct dpll_device *dpll, +struct dpll_pin *pin,struct genl_info *info) +{ +enum dpll_pin_state state =DPLL_PIN_STATE_UNSPEC ; +u32 parent_idx =PIN_IDX_INVALID ;You just need this
PIN_IDX_INVALIDdefine internally in this function, change the flow to avoid a need for it.I'll re-think it, thanks.
Quoted 10 lines
drivers/dpll/dpll_netlink.c line 568
Quoted 6 lines
drivers/dpll/dpll_netlink.c new file +5
-0+int rem, ret = -EINVAL ; +struct nlattr *a; + +nla_for_each_attr (a,genlmsg_data (info->genlhdr), +genlmsg_len (info->genlhdr), rem) {This is odd. Why you iterace over attrs? Why don't you just access them directly, like attrs[DPLL_A_PIN_FREQUENCY] for example?
I had some unknown crashes when I was using such access. I might have lost some
checks, will try it again.Quoted 32 lines
Quoted 18 lines
drivers/dpll/dpll_netlink.c new file +17
-0+switch (nla_type (a)) { +case DPLL_A_PIN_FREQUENCY : + ret =dpll_pin_freq_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_DIRECTION : + ret =dpll_pin_direction_set (pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PRIO : + ret =dpll_pin_prio_set (dpll, pin, a, info->extack); +if (ret) +return ret; +break ; +case DPLL_A_PIN_PARENT_IDX :drivers/dpll/dpll_netlink.c line 595
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ parent_idx =nla_get_u32 (a); +break ; +case DPLL_A_PIN_STATE : + state =nla_get_u8 (a); +break ; +default : +break ; + } + } +if (state !=DPLL_PIN_STATE_UNSPEC ) {Again, change the flow to:
if (attrs[DPLL_A_PIN_STATE]) {Quoted 4 lines
Quoted 2 lines
and avoid need for this value set/check.
Yep, will try.
Yes, this shall work now, as long as there are no multiple nested attributes coming from userspace.
[...]
Quoted 16 lines
Quoted 15 lines
drivers/dpll/dpll_netlink.c line 878
Quoted 11 lines
+void dpll_pin_post_doit(const struct
genl_split_ops*ops, structsk_buff*skb,drivers/dpll/dpll_netlink.c new file +9
-0+ struct genl_info *info) +{ +mutex_unlock (&dpll_pin_xa_lock); +dpll_post_doit (ops, skb, info); +} + +int dpll_pin_pre_dumpit (struct netlink_callback *cb) +{ +mutex_lock (&dpll_pin_xa_lock);ABBA deadlock here, see
dpll_pin_register()for example where the lock taking order is opposite.
Quoted 7 lines
Quoted 4 lines
Now I see an ABBA deadlock here, as well as in function before. Not sure how to
solve it here. Any thoughts?Not really, this is why it is there :(
A single global lock for whole dpll subsystem?
Either that or per-instance/device lock.
Quoted 48 lines
Quoted 39 lines
Quoted 37 lines
Quoted 16 lines
drivers/dpll/dpll_netlink.c new file +14
-0+ +return dpll_pre_dumpit (cb); +} + +int dpll_pin_post_dumpit (struct netlink_callback *cb) +{ +mutex_unlock (&dpll_pin_xa_lock); + +return dpll_post_dumpit (cb); +} + +static int +dpll_event_device_change(struct sk_buff *msg, struct dpll_device *dpll, + struct dpll_pin *pin, struct dpll_pin *parent,drivers/dpll/dpll_netlink.c line 902
Quoted 10 lines
drivers/dpll/dpll_netlink.c new file +10
-0+ enum dplla attr) +{ +int ret =dpll_msg_add_dev_handle (msg, dpll); +struct dpll_pin_ref *ref =NULL ; +enum dpll_pin_state state; + +if (ret) +return ret; +if (pin &&nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ;I don't really understand why you are trying figure something new and interesting with the change notifications. This object mix and random attrs fillup is something very wrong and makes userspace completely fuzzy about what it is getting. And yet it is so simple:
You have 2 objects, dpll and pin, please just have:dpll_notify()dpll_pin_notify()
and share the attrs fillup code withpin_get()anddpll_get()callbacks. No need for any smartness. Have this dumb and simple.Quoted 1 line
Think about it more as about "object-state-snapshot" than "atomic-change"
Quoted 8 lines
But with full object-snapshot user space app will lose the information about
what exactly has changed. The reason to have this event is to provide the attributes which have changed. Otherwise, the app should have full snapshot and
compare all attributes to figure out changes and that's might not be great idea.
Quoted 2 lines
I agree that from functional perspective it is better to have on userspace a reason of the notification.
I would like to understand why exactly is it better.
But anyway, I was thinking about it a bit more and it might make sense only the added/changed/deleted attribute to safe some msg space and getting/parsing cycles. However, it is questionable how much does it actually save. But you apparently strongly want it, so lets have it
But, the format of the message should be exactly the same as for GET. Meaning, if some nested attr changes/is added/is removed, the msg should contain the proper nest same as for the same attr in GET msg. Think of it as if you assemble the whole GET msg for an object and filter out things that did not change.
Also need to emphasize strict objects separation, same as for GET.
Also, you have to distinguish between attr being added/removed or the whole object being added/removed. The userspace has to understand difference.
So you would have events like:DEVICE_ADDEDDEVICE_REMOVEDDEVICE_ATTRS_ADDEDDEVICE_ATTRS_CHANGEDDEVICE_ATTRS_REMOVEDPIN_ADDEDPIN_REMOVEDPIN_ATTRS_ADDEDPIN_ATTRS_CHANGEDPIN_ATTRS_REMOVED
This scenario I can imagine working in a sane way.
Makes sense?
Btw, with the whole object snapshot scenario you just have:DEVICE_NEW (sent for creation and change)DEVICE_DELPIN_NEW (sent for creation and change)PIN_DEL
And you are fine with it. This is how it's usually done in Netlink. In fact, do you have examples in kernel code of what you are suggesting?
Quoted 6 lines
[...]
Thank you,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoQuoted 123 lines · Wed, Mar 15, 2023 at 01:10:33AM CET, [email protected] wrote:
Quoted 22 lines · Jiri Pirko
Quoted 21 lines · Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
Implement basic DPLL operations in
ptp_ocpdriver as the simplest example of using new subsystem.Signed-off-by Vadim Fedorenko <[email protected]>---
drivers/ptp/Kconfig| 1 +drivers/ptp/ptp_ocp.c| 209 ++++++++++++++++++++++++++++++++++++++++--2 files changed, 200 insertions(+), 10 deletions(-)drivers/ptp/Kconfig +1
-0@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP depends on COMMON_CLK select NET_DEVLINK select CRC16 + select DPLL help This driver adds support for an OpenCompute time card.Quoted 13 lines
drivers/ptp/ptp_ocp.c line 27
Quoted 10 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -23,6 +23,8 @@#include <linux/mtd/mtd.h> #include <linux/nvmem-consumer.h> #include <linux/crc16.h> +#include <linux/dpll.h> +#include <uapi/linux/dpll.h> Don't include UAPI directly. I'm pretty sure I had this comment earlier.
Ah, yeah, you've mentioned it for ice driver last time, but I forgot to check it here. Removed.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +1
-0#define PCI_VENDOR_ID_FACEBOOK 0x1d9b#define PCI_DEVICE_ID_FACEBOOK_TIMECARD 0x0400@@ -267,6 +269,7 @@ struct ptp_ocp_sma_connector {bool fixed_dir;bool disabled;u8 default_fcn; +struct dpll_pin *dpll_pin; };Quoted 7 lines
drivers/ptp/ptp_ocp.c struct ptp_ocp { · line 357
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0struct ocp_attr_group {@@ -353,6 +356,7 @@ struct ptp_ocp {struct ptp_ocp_signal signal[4 ];struct ptp_ocp_sma_connector sma[4 ];It is quite customary to use defines for const numbers like this. Why don't you do that in
ptp_ocp?Historical reasons. Jonathan might answer this question. I will add it to my TODO list for the driver.
Quoted 49 lines
Quoted 49 lines
drivers/ptp/ptp_ocp.c +1
-0const struct ocp_sma_op *sma_op; +struct dpll_device *dpll; };#define OCP_REQ_TIMESTAMP BIT(0)@@ -2689,16 +2693,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf) }static int
drivers/ptp/ptp_ocp.c +1
-1-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr) +ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr){ struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];drivers/ptp/ptp_ocp.c +0
-7-enum ptp_ocp_sma_mode mode; -int val; - - mode = sma->mode; - val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); -if (val <0 ) -return val;if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE)) return -EOPNOTSUPP;drivers/ptp/ptp_ocp.c +15
-0@@ -2733,6 +2730,21 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)return val; } +static int +ptp_ocp_sma_store (struct ptp_ocp *bp,const char *buf,int sma_nr) +{ +struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr -1 ]; +enum ptp_ocp_sma_mode mode; +int val; + + mode = sma->mode; + val =sma_parse_inputs (bp->sma_op->tbl, buf, &mode); +if (val <0 ) +return val; + +return ptp_ocp_sma_store_val (bp, val, mode, sma_nr); +} +static
ssize_t
sma1_store(struct device *dev, structdevice_attribute*attr,
const char *buf,size_tcount)drivers/ptp/ptp_ocp.c +0
-0@@ -4171,12 +4183,151 @@ ptp_ocp_detach(struct ptp_ocp *bp)device_unregister (&bp->dev); }Quoted 11 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4192
Quoted 7 lines
drivers/ptp/ptp_ocp.c +7
-0+static int ptp_ocp_dpll_pin_to_sma (const struct ptp_ocp *bp,const struct dpll_pin *pin) +{ +int i; + +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin == pin) +return i;Just pass &bp->sma[i] as a priv to
dpll_pin_register().
and get that pointer directly in pin ops. No need for lookup and use ofsma_nrat all.
Quoted 3 lines
I'm still thinking about the change that you proposed to remove these
_priv()helpers. I have to look into ice code to be sure we won't break any assumptions in it with moving to additional (void *) parameter.
There are basically 2 ways:someop(struct subsystemobj *x, void *priv)
{
struct *mine = priv;
}
or:
someop(struct subsystemobj *x)
{
struct *mine = subsystem_get_priv(x);
}Both are more or less equal. The first has benefit that the caller most usually has direct access to the priv, so it can just easily pass it on. Also, you as the driver write see right away there is a priv arg and makes you want to use it and not figure out odd lookups to get to the same priv.
Quoted 161 lines
Quoted 14 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4201
Quoted 11 lines
drivers/ptp/ptp_ocp.c +9
-0+ } +return -1 ; +} + +static int ptp_ocp_dpll_lock_status_get (const struct dpll_device *dpll, +enum dpll_lock_status *status, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll);No need to cast (void *), remove it.
Fixed everywhere in the code, thanks.
Quoted 20 lines
Quoted 20 lines
drivers/ptp/ptp_ocp.c +19
-0+int sync; + + sync =ioread32 (&bp->reg->status) &OCP_STATUS_IN_SYNC ; + *status = sync ?DPLL_LOCK_STATUS_LOCKED :DPLL_LOCK_STATUS_UNLOCKED ; + +return 0 ; +} + +static int ptp_ocp_dpll_source_idx_get (const struct dpll_device *dpll, +u32 *idx,struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); + +if (bp->pps_select) { + *idx =ioread32 (&bp->pps_select->gpio1); +return 0 ; + } +return -EINVAL ; +}Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4226
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+ +static int ptp_ocp_dpll_mode_get (const struct dpll_device *dpll, +u32 *mode,struct netlink_ext_ack *extack) +{ + *mode =DPLL_MODE_AUTOMATIC ; +No need for empty line, I believe.
Ok.
Quoted 13 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4237
Quoted 11 lines
drivers/ptp/ptp_ocp.c +11
-0+return 0 ; +} + +static bool ptp_ocp_dpll_mode_supported (const struct dpll_device *dpll, +const enum dpll_mode mode, +struct netlink_ext_ack *extack) +{ +if (mode ==DPLL_MODE_AUTOMATIC ) +return true; + +return false;Just:
Quoted 2 lines
return mode == DPLL_MODE_AUTOMATIC;Done, thanks!
Quoted 31 lines
Quoted 31 lines
drivers/ptp/ptp_ocp.c +31
-0+} + +static int ptp_ocp_dpll_direction_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); + +if (sma_nr <0 ) +return -EINVAL ; + + *direction = bp->sma[sma_nr].mode ==SMA_MODE_IN ?DPLL_PIN_DIRECTION_SOURCE : +DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static int ptp_ocp_dpll_direction_set (const struct dpll_pin *pin, +const struct dpll_device *dpll, +enum dpll_pin_direction direction, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +enum ptp_ocp_sma_mode mode; + +if (sma_nr <0 ) +return -EINVAL ; + + mode = direction ==DPLL_PIN_DIRECTION_SOURCE ?SMA_MODE_IN :SMA_MODE_OUT ;Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4274
Quoted 6 lines
drivers/ptp/ptp_ocp.c +6
-0+return ptp_ocp_sma_store_val (bp,0 , mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, + const struct dpll_device *dpll, + const u32 frequency,Why you need const for u32?
No need, true, removed.
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4279
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin); +int val = frequency ==10000000 ?0 :1 ;This is weird. I believe you should handle unsupported frequencies gracefully.
Currently hardware supports fixed frequencies only. That's why I have to do this kind of "dance". Hopefully we will improve it to support variable frequency.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4255
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ +if (sma_nr <0 ) +return -EINVAL ; + +Avoid double empty lines.
Yep.
Quoted 27 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +10
-0+return ptp_ocp_sma_store_val (bp, val, bp->sma[sma_nr].mode, sma_nr); +} + +static int ptp_ocp_dpll_frequency_get (const struct dpll_pin *pin, +const struct dpll_device *dpll, +u32 *frequency, +struct netlink_ext_ack *extack) +{ +struct ptp_ocp *bp = (struct ptp_ocp *)dpll_priv (dpll); +int sma_nr =ptp_ocp_dpll_pin_to_sma (bp, pin);drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4304
Quoted 10 lines
drivers/ptp/ptp_ocp.c +10
-0+u32 val; + +if (sma_nr <0 ) +return -EINVAL ; + + val = bp->sma_op->get (bp, sma_nr); +if (!val) + *frequency =1000000 ; +else + *frequency =0 ;I don't follow. How the frequency could be 0? Does that mean that the pin is disabled? If yes, you should rather implement .state_on_dpll_get
.state_on_dpll_set
Quoted 5 lines
Quoted 1 line
and leave the frequency constant.
It's actually a mistake. It should be 1 which means 1Hz, PPS. The value returned by
sma_op->getis actually the type of the signal where 0 is 1PPS, 1 is 10Mhz and so on.
So you support freq change? In the comment above you wrote "Currently hardware supports fixed frequencies only". I'm confused.
The point is:
1) if you support freq change, you should sanitize the input properly in frequency_set() and return correct actual value in frequency_get()
2) if you don't support freq change, avoid filling-up these ops entirely.
Quoted 93 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4308
Quoted 7 lines
drivers/ptp/ptp_ocp.c +4
-0+return 0 ; +} + +static struct dpll_device_ops dpll_ops = {const
Will change it together with API part. Otherwise it doesn't compile.
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4310
Quoted 3 lines
drivers/ptp/ptp_ocp.c +2
-0+ .lock_status_get = ptp_ocp_dpll_lock_status_get, + .source_pin_idx_get = ptp_ocp_dpll_source_idx_get,Should be called "
source_pin_get" and return (structdpll_pin*) On the driver api level, no reason to pass indexes. Work with objects.Good point, will improve it.
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4315
Quoted 6 lines
drivers/ptp/ptp_ocp.c +5
-0+ .mode_get = ptp_ocp_dpll_mode_get, + .mode_supported = ptp_ocp_dpll_mode_supported, +}; + +static struct dpll_pin_ops dpll_pins_ops = {const
Yep.
Quoted 18 lines
drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4327
Quoted 13 lines
drivers/ptp/ptp_ocp.c +6
-0+ .frequency_get = ptp_ocp_dpll_frequency_get, + .frequency_set = ptp_ocp_dpll_frequency_set, + .direction_get = ptp_ocp_dpll_direction_get, + .direction_set = ptp_ocp_dpll_direction_set, +}; +static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id){drivers/ptp/ptp_ocp.c +1
-0+struct dpll_pin_properties prop;struct devlink *devlink;drivers/ptp/ptp_ocp.c +1
-0+char sma[4 ] ="SMA0" ;Won't fit. Just use:
char *sma = "SMA0"
to be safeGot it.
Quoted 29 lines
Quoted 29 lines
struct ptp_ocp *bp;drivers/ptp/ptp_ocp.c +2
-1-int err; +int err, i; +u64 clkid;devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev); if (!devlink) {drivers/ptp/ptp_ocp.c +15
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) { +dev_err (&pdev->dev,"dpll_device_alloc failed\n" ); + goto out; + } + + err =dpll_device_register (bp->dpll,DPLL_TYPE_PPS , &dpll_ops, bp, &pdev->dev); +if (err) + goto out; + + prop.description = &sma[0 ]; + prop.freq_supported =DPLL_PIN_FREQ_SUPP_MAX ; + prop.type =DPLL_PIN_TYPE_EXT ; + prop.any_freq_max =10000000 ;Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4400
Quoted 5 lines
drivers/ptp/ptp_ocp.c +5
-0+ prop.any_freq_min =0 ; + prop.capabilities =DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE ; + +for (i =0 ; i <4 ; i++) { + sma[3 ] =0x31 + i;Ugh. Just use the static const array as I suggested in the dpll patch reply. Helps you avoid this sort of "magic".
Quoted 2 lines
well, yes. but at the same time Arkadiusz raised a good question about accessing driver's memory from the subsystem code - doesn't look clean.
It is completely clean and we do it everywhere in the kernel. No problem what so ever.
Quoted 9 lines
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4402
Quoted 4 lines
drivers/ptp/ptp_ocp.c +2
-0+ bp->sma[i].dpll_pin =dpll_pin_get (clkid, i,THIS_MODULE , &prop); +if (IS_ERR_OR_NULL (bp->sma[i].dpll_pin)) {How it could be NULL?
Allocation fail?
No? I mean, I don't see such possibility of return value of dpll_pin_get() Do you see it or are you just guessing? :)
Quoted 39 lines
Quoted 7 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4403
Quoted 3 lines
drivers/ptp/ptp_ocp.c +1
-0+ bp->sma[i].dpll_pin =NULL ;This would not be needed if the error path iterates over indexes which were successul.
Yeah, I'll make it the same way it's done in ice.
Quoted 15 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4414
Quoted 12 lines
drivers/ptp/ptp_ocp.c +11
-0+ goto out_dpll; + } + err =dpll_pin_register (bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp,NULL ); +if (err) + goto out_dpll; + } + +return 0 ; +out_dpll: +for (i =0 ; i <4 ; i++) { +if (bp->sma[i].dpll_pin)You don't do unregister of pin here.
Yeah, actually error path and unload path should be re-implemented.
Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +3
-0+dpll_pin_put (bp->sma[i].dpll_pin); + } +dpll_device_put (bp->dpll);out:
ptp_ocp_detach(bp);
out_disable:drivers/ptp/ptp_ocp.c +0
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp);
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/ptp/ptp_ocp.c +2
-0+dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Kubalewski, ArkadiuszQuoted 75 lines · Tue, Mar 14, 2023 at 07:35:55PM CET, [email protected] wrote:
Quoted 71 lines
From: Jiri Pirko <[email protected]>
Sent: Tuesday, March 14, 2023 4:45 PM[...]
MAINTAINERS F:
Quoted 5 lines
MAINTAINERS +0
-0@@ -6289,6 +6289,15 @@ F:
Documentation/networking/device_drivers/ethernet/freescale/dpaa2/swit
ch-driveQuoted 4 lines
F:
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
F:drivers/net/ethernet/freescale/dpaa2/dpsw*+DPLL CLOCK SUBSYSTEM
Why "clock"? You don't mention "clock" anywhere else.
[...]
drivers/dpll/dpll_core.c line 3
Quoted 9 lines
drivers/dpll/dpll_core.c new file +3
-0@@ -0,0 +1,835 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* dpll_core.c - Generic DPLL Management class support. Why "class" ?
[...]
Quoted 18 lines
drivers/dpll/dpll_core.c new file +18
-0+static int +dpll_msg_add_pin_freq (struct sk_buff *msg,const struct dpll_pin *pin, +struct netlink_ext_ack *extack,bool dump_any_freq) +{ +enum dpll_pin_freq_supp fs; +struct dpll_pin_ref *ref; +unsigned long i; +u32 freq; + +xa_for_each ((struct xarray *)&pin->dpll_refs, i, ref) { +if (ref && ref->ops && ref->dpll) +break ; + } +if (!ref || !ref->ops || !ref->dpll) +return -ENODEV ; +if (!ref->ops->frequency_get) +return -EOPNOTSUPP ; +if (ref->ops->frequency_get (pin, ref->dpll, &freq, extack))drivers/dpll/dpll_core.c line 31
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+return -EFAULT ; +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY , freq)) +return -EMSGSIZE ; +if (!dump_any_freq) +return 0 ; +for (fs =DPLL_PIN_FREQ_SUPP_UNSPEC +1 ; + fs <=DPLL_PIN_FREQ_SUPP_MAX ; fs++) { +if (test_bit (fs, &pin->prop.freq_supported)) { +if (nla_put_u32 (msg,DPLL_A_PIN_FREQUENCY_SUPPORTED , + dpll_pin_freq_value[fs]))This is odd. As I suggested in the yaml patch, better to treat all supported frequencies the same, no matter if it is range or not. The you don't need this weird bitfield.
Quoted 3 lines
You can have a macro to help driver to assemble array of supported frequencies and ranges.
Quoted 5 lines
I understand suggestion on yaml, but here I am confused.
How do they relate to the supported frequency passed between driver and dpll subsystem?
This bitfield is not visible to the userspace, and sure probably adding macro can be useful.
My point is to avoid the bitfield and to treat supported frequencies and ranges in the same way. It can look similar to this:
in dpll.h:
struct struct dpll_pin_frequency {
u64 min;
u64 max;
};#define DPLL_PIN_FREQUENCY_RANGE(_min, _mac) \
{ \
.min = _min, \
.max = _max, \
}#define DPLL_PIN_FREQUENCY(_val) DPLL_PIN_FREQUENCY_RANGE(_val, _val) #define DPLL_PIN_FREQUENCY_1PPS DPLL_PIN_FREQUENCY(1) #define DPLL_PIN_FREQUENCY_10MHZ DPLL_PIN_FREQUENCY(1000000)
Then in driver you have:
static const struct dpll_pin_frequency pcp_dpll_pin_freqs[] = {
DPLL_PIN_FREQUENCY_1PPS,
DPLL_PIN_FREQUENCY_10MHZ,
DPLL_PIN_FREQUENCY(4000000),
DPLL_PIN_FREQUENCY_RANGE(500, 1000),
DPLL_PIN_FREQUENCY_RANGE(9000, 10000),
};static const struct dpll_pin_properties pcp_dpll_pin_props = {
.label = "SMA",
.frequencies_supported = pcp_dpll_pin_freqs, .frequencies_supported_count = ARRAY_SIZE(pcp_dpll_pin_freqs), .type = DPLL_PIN_TYPE_EXT,
.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
};
Then the dpll core could very easily iterate over .frequencies_supported array and dump the supported values and ranges to user in uniform way.
Quoted 101 lines
Quoted 40 lines
Quoted 17 lines
drivers/dpll/dpll_core.c new file +15
-0+return -EMSGSIZE ; + } + } +if (pin->prop.any_freq_min && pin->prop.any_freq_max) { +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MIN , + pin->prop.any_freq_min)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_ANY_FREQUENCY_MAX , + pin->prop.any_freq_max)) +return -EMSGSIZE ; + } + +return 0 ; +} +[...]
Quoted 19 lines
drivers/dpll/dpll_core.c new file +19
-0+static int +dpll_cmd_pin_on_dpll_get (struct sk_buff *msg,struct dpll_pin *pin, +struct dpll_device *dpll, +struct netlink_ext_ack *extack) +{ +struct dpll_pin_ref *ref; +int ret; + +if (nla_put_u32 (msg,DPLL_A_PIN_IDX , pin->dev_driver_id)) +return -EMSGSIZE ; +if (nla_put_string (msg,DPLL_A_PIN_DESCRIPTION , pin->prop.description)) +return -EMSGSIZE ; +if (nla_put_u8 (msg,DPLL_A_PIN_TYPE , pin->prop.type)) +return -EMSGSIZE ; +if (nla_put_u32 (msg,DPLL_A_PIN_DPLL_CAPS , pin->prop.capabilities)) +return -EMSGSIZE ; + ret =dpll_msg_add_pin_direction (msg, pin, extack); +if (ret) +return ret;Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+ ret =dpll_msg_add_pin_freq (msg, pin, extack, true); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ref =dpll_xa_ref_dpll_find (&pin->dpll_refs, dpll); +if (!ref)How exactly this can happen? Looks to me like only in case of a bug.
WARN_ON()perhaps (put directly intodpll_xa_ref_dpll_find()?Yes, makes sense.
Quoted 16 lines
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +11
-0+return -EFAULT ; + ret =dpll_msg_add_pin_prio (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_on_dpll_state (msg, pin, ref, extack); +if (ret && ret != -EOPNOTSUPP ) +return ret; + ret =dpll_msg_add_pin_parents (msg, pin, extack); +if (ret) +return ret; +if (pin->rclk_dev_name)Use && and single if
Make sense to me.
Quoted 22 lines
Quoted 8 lines
drivers/dpll/dpll_core.c new file +7
-0+if (nla_put_string (msg,DPLL_A_PIN_RCLK_DEVICE , + pin->rclk_dev_name)) +return -EMSGSIZE ; + +return 0 ; +} +[...]
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+static int +dpll_pin_freq_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +u32 freq =nla_get_u32 (a); +struct dpll_pin_ref *ref; +unsigned long i; +int ret; + +if (!dpll_pin_is_freq_supported (pin, freq))Quoted 8 lines
drivers/dpll/dpll_core.c
Quoted 6 lines
drivers/dpll/dpll_core.c new file +6
-0+return -EINVAL ; + +xa_for_each (&pin->dpll_refs, i, ref) { + ret = ref->ops->frequency_set (pin, ref->dpll, freq, extack); +if (ret) +return -EFAULT ;return what the op returns: ret
Quoted 3 lines
Why would we return here a driver return code, userspace can have this info from extack. IMHO return values of dpll subsystem shall be not dependent on what is returned from the driver.
Why not to return it? The driver had some problem, errno suggests what that was. It is completely desired to pass that along and actually, it's been done like this in the rest of the netlink ops I can think of. Why would you want to hide it? Extack carries string message, not related to this directly.
Quoted 31 lines
Quoted 31 lines
Quoted 9 lines
drivers/dpll/dpll_core.c new file +6
-0+dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_FREQUENCY ); + } + +return 0 ; +} +[...]
drivers/dpll/dpll_core.c
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+static int +dpll_pin_direction_set (struct dpll_pin *pin,struct nlattr *a, +struct netlink_ext_ack *extack) +{ +enum dpll_pin_direction direction =nla_get_u8 (a); +struct dpll_pin_ref *ref; +unsigned long i; + +if (!(DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE & pin->prop.capabilities)) +return -EOPNOTSUPP ; + +xa_for_each (&pin->dpll_refs, i, ref) { +if (ref->ops->direction_set (pin, ref->dpll, direction, extack))ret = ..
if (ret)return ret;
Quoted 4 lines
Quoted 2 lines
Please use this pattern in other ops call code as well.
This is the same as above (return code by driver) explanation.
Same reply as above.
Quoted 12 lines
Quoted 9 lines
Quoted 7 lines
drivers/dpll/dpll_core.c new file +5
-0+return -EFAULT ; +dpll_pin_notify (ref->dpll, pin,DPLL_A_PIN_DIRECTION ); + } + +return 0 ;[...]
Thanks,
Arkadiusz
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 2 lines
include/linux/dpll.h new file +2
-0+struct dpll_device +*dpll_device_get (u64 clock_id,u32 dev_driver_id,struct module *module);
[...]
include/linux/dpll.h line 184
Quoted 3 lines
include/linux/dpll.h new file +3
-0+struct dpll_pin +*dpll_pin_get (u64 clock_id,u32 dev_driver_id,struct module *module, +const struct dpll_pin_properties *pin_prop);
Small tweak, please use the same trick as shown for example here:
/* pci_register_driver() must be a macro so KBUILD_MODNAME can be expanded */
#define pci_register_driver(driver) \
__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
The driver calls header helper which fills up the "THIS_MODULE" for it.
Thanks!
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4383
Quoted 9 lines
drivers/ptp/ptp_ocp.c +3
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ; + clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) {
You have to use IS_ERR() here. Same problem in ice.
[...]
Vadim Fedorenko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
Quoted 10 lines · Jiri Pirko
Sun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
Quoted 6 lines
drivers/ptp/ptp_ocp.c +0
-1@@ -4226,8 +4377,44 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)ptp_ocp_info (bp);devlink_register (devlink); -return 0 ;
Quoted 6 lines
drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4383
Quoted 3 lines
drivers/ptp/ptp_ocp.c +3
-0+ clkid =pci_get_dsn (pdev); + bp->dpll =dpll_device_get (clkid,0 ,THIS_MODULE ); +if (!bp->dpll) {You have to use
IS_ERR()here. Same problem in ice.
Yep, fixed, thanks!
Jiri Pirko
maintainerRe: [PATCH RFC v6 6/6] ptp_ocp: implement DPLL ops
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:07AM CET, [email protected] wrote:
[...]
drivers/ptp/ptp_ocp.c ptp_ocp_remove(struct pci_dev *pdev) · line 4432
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0@@ -4243,6 +4430,8 @@ ptp_ocp_remove(struct pci_dev *pdev)struct ptp_ocp *bp =pci_get_drvdata (pdev);struct devlink *devlink =priv_to_devlink (bp);
You are missing pins unregister and put here.
Btw, It would be probably good to add a WARN_ON into dpll_device_unregister() to catch bugs like this one.
Quoted 8 lines
drivers/ptp/ptp_ocp.c +2
-0+dpll_device_unregister (bp->dpll); +dpll_device_put (bp->dpll);devlink_unregister (devlink);ptp_ocp_detach (bp);pci_disable_device (pdev);Signature · 1 line
2.34.1
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
drivers/dpll/dpll_core.c line 630
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+/** +* dpll_pin_unregister - deregister dpll pin from dpll device +* @dpll: registered dpll pointer +* @pin: pointer to a pin +* +* Note: It does not free the memory +*/ +int dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin)
Make this return void. Function does not report anything useful, non-0 is only in case of WARN_ON. Nobody is going to check that ever anyway.
Quoted 13 lines
drivers/dpll/dpll_core.c new file +13
-0+{ +if (WARN_ON (xa_empty (&dpll->pin_refs))) +return -ENOENT ; + +mutex_lock (&dpll_device_xa_lock); +mutex_lock (&dpll_pin_xa_lock); +__dpll_pin_unregister (dpll, pin); +mutex_unlock (&dpll_pin_xa_lock); +mutex_unlock (&dpll_device_xa_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (dpll_pin_unregister);
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Jiri PirkoQuoted 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.
[...]
Jiri Pirko
maintainerRe: [PATCH RFC v6 2/6] dpll: Add DPLL framework base functions
In reply to Vadim FedorenkoSun, Mar 12, 2023 at 03:28:03AM CET, [email protected] wrote:
[...]
Quoted 5 lines
drivers/dpll/dpll_core.c new file +5
-0+struct dpll_pin * +dpll_pin_alloc (u64 clock_id,u8 device_drv_id,struct module *module, +const struct dpll_pin_properties *prop) +{ +struct dpll_pin *pin;
drivers/dpll/dpll_core.c line 452
Quoted 10 lines
drivers/dpll/dpll_core.c new file +10
-0+int ret; + + pin =kzalloc (sizeof (*pin),GFP_KERNEL ); +if (!pin) +return ERR_PTR (-ENOMEM ); + pin->dev_driver_id = device_drv_id; + pin->clock_id = clock_id; + pin->module = module; +refcount_set (&pin->refcount,1 ); +if (WARN_ON (!prop->description)) {
Why is this mandatory? I'm now working on mlx5 implementation, don't really know what to put here for SyncE. The type of the pin SyncE tells all I need. I would like to avoid description fill-up.
Quoted 8 lines
drivers/dpll/dpll_core.c new file +8
-0+ ret = -EINVAL ; + goto release; + } + pin->prop.description =kstrdup (prop->description,GFP_KERNEL ); +if (!pin->prop.description) { + ret = -ENOMEM ; + goto release; + }
[...]
Kubalewski, Arkadiusz
maintainerRE: [PATCH RFC v6 1/6] dpll: spec: Add Netlink spec in YAML
In reply to Jiri PirkoQuoted 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