Skip to contentSkip to conversation

Radio device framework

PATCH Superseded [email protected] 7 participants 21 messages Jun 17, 2013 – Jul 5, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Radio device framework

From: Akhil Goyal <[email protected]>

RF signal path is integral part of any system that transmits/receives RF (radio frequency) signals. In these systems Data is processed/converted to IQ samples (digital representation a RF signal) and passed to a RFIC (RF PHY) which converts the digital RF signal (IQ samples) to analog and transmits over antenna.

Typically The signal path consists of multiple components:

Antenna controller <-> vector signal processors <-> RFIC <-> Antenna

Each of these components have specific functionalities:

1. Antenna controller: Framing of digital IQ data into protocol specific frames.
2. vector signal processors: For conditioning of signal.
3. RFIC : converts digital IQ data to analog signal which is transmitted/received on/from Air.

Also it is desirable to control the complete signal path, for example:
bringing the complete signal path up/down etc.

The radio device framework introduces a way to accommodate the RF signal paths. One signal path is represented as a RF device (rf0, rf1 etc), and it can contain multiple components which have their individual vendor specific drivers. The framework provides mechanism by which individual components can register with RF framework, and the framework will handle the binding of individual component devices to a RF device. RF device exports the control interfaces to user space, and this user space interface is independent of component (vendor specific) drivers.

This patch set include
1. RF Interface: Independent of phy or antenna controller.
2. AIC driver: Antenna interface Controller(AIC) of Hetrogenous SOC's like BSC9131, BSC9132
3. AD9361 driver: RF Phy driver for Analog Devices(ADI) chip(AD9361)
4. Device tree bindings for AIC and ADI nodes.
5. Device tree changes for BSC9131

Akhil Goyal (5):
drivers/misc: Support for RF interface device framework drivers/misc/rf: AIC: Freescale Antenna Interface controller driver drivers/misc: rf/ad9361: AD9361 device driver for Radio phy
binding: Add device tree bindings for freescale AIC and AD phy BSC9131rdb/dts: Add nodes for supporting AIC and AD PHY

 .../devicetree/bindings/rf/ad9361-phy.txt          |   53 +
 Documentation/devicetree/bindings/rf/fsl-aic.txt   |   47 +
 Documentation/misc-devices/rf_framework            |  110 ++
 arch/powerpc/boot/dts/bsc9131rdb.dts               |    4 +
 arch/powerpc/boot/dts/bsc9131rdb.dtsi              |   38 +
 arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi      |   53 +-
 arch/powerpc/boot/dts/fsl/pq3-espi-0.dtsi          |    1 +
 arch/powerpc/boot/dts/fsl/pq3-espi-1.dtsi          |   42 +
 arch/powerpc/boot/dts/fsl/pq3-gpio-0.dtsi          |    1 +
 arch/powerpc/boot/dts/fsl/pq3-gpio-1.dtsi          |   42 +
 drivers/misc/Kconfig                               |    1 +
 drivers/misc/Makefile                              |    1 +
 drivers/misc/rf/Kconfig                            |   37 +
 drivers/misc/rf/Makefile                           |    7 +
 drivers/misc/rf/controllers/Makefile               |    1 +
 drivers/misc/rf/controllers/fsl_aic.c              | 1560 ++++++++++++++++
 drivers/misc/rf/controllers/fsl_aic.h              |  450 +++++
 drivers/misc/rf/core/Makefile                      |    2 +
 drivers/misc/rf/core/rf_channel.c                  |  207 +++
 drivers/misc/rf/core/rfdev.c                       | 1263 +++++++++++++
 drivers/misc/rf/phy/Makefile                       |    2 +
 drivers/misc/rf/phy/ad9361.c                       | 1918 ++++++++++++++++++++
 drivers/misc/rf/phy/ad9361.h                       |  353 ++++
 include/linux/rf_channel.h                         |   26 +
 include/linux/rfdev.h                              |  250 +++
 include/uapi/linux/rfdev.h                         |  392 ++++
 26 files changed, 6858 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rf/ad9361-phy.txt
 create mode 100644 Documentation/devicetree/bindings/rf/fsl-aic.txt
 create mode 100644 Documentation/misc-devices/rf_framework
 create mode 100644 arch/powerpc/boot/dts/fsl/pq3-espi-1.dtsi
 create mode 100644 arch/powerpc/boot/dts/fsl/pq3-gpio-1.dtsi
 create mode 100644 drivers/misc/rf/Kconfig
 create mode 100644 drivers/misc/rf/Makefile
 create mode 100644 drivers/misc/rf/controllers/Makefile
 create mode 100644 drivers/misc/rf/controllers/fsl_aic.c
 create mode 100644 drivers/misc/rf/controllers/fsl_aic.h
 create mode 100644 drivers/misc/rf/core/Makefile
 create mode 100644 drivers/misc/rf/core/rf_channel.c
 create mode 100644 drivers/misc/rf/core/rfdev.c
 create mode 100644 drivers/misc/rf/phy/Makefile
 create mode 100644 drivers/misc/rf/phy/ad9361.c
 create mode 100644 drivers/misc/rf/phy/ad9361.h
 create mode 100644 include/linux/rf_channel.h
 create mode 100644 include/linux/rfdev.h
 create mode 100644 include/uapi/linux/rfdev.h
#1 lore raw

PATCH 1/5 drivers/misc: Support for RF interface device framework

From: Akhil Goyal <[email protected]>

The radio device framework introduces a way to accommodate the RF(radio frequency) signal paths. One signal path is represented as a RF device (rf0, rf1 etc), and it can contain multiple components which have their individual vendor specific drivers. The framework provides mechanism by which individual components can register with RF framework, and the framework will handle the binding of individual component devices to a RF device. RF device exports the control interfaces to user space, and this user space interface is independent of component (vendor specific) drivers.

In a multimode system there can be multiple rfdev devices, depending on number of radios connected.

In this patch, the rf controller(AIC) and RFIC(AD9361) drivers register their respective devices with this framework. This framework does binding of RFIC device with RF controller device and exposes the combination as a logical rfdev to user space.

---
 Documentation/misc-devices/rf_framework |  110 +++
 drivers/misc/Kconfig                    |    1 +
 drivers/misc/Makefile                   |    1 +
 drivers/misc/rf/Kconfig                 |   37 +
 drivers/misc/rf/Makefile                |    5 +
 drivers/misc/rf/core/Makefile           |    2 +
 drivers/misc/rf/core/rf_channel.c       |  207 +++++
 drivers/misc/rf/core/rfdev.c            | 1263 +++++++++++++++++++++++++++++++
 include/linux/rf_channel.h              |   26 +
 include/linux/rfdev.h                   |  250 ++++++
 include/uapi/linux/rfdev.h              |  392 ++++++++++
 11 files changed, 2294 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/misc-devices/rf_framework
 create mode 100644 drivers/misc/rf/Kconfig
 create mode 100644 drivers/misc/rf/Makefile
 create mode 100644 drivers/misc/rf/core/Makefile
 create mode 100644 drivers/misc/rf/core/rf_channel.c
 create mode 100644 drivers/misc/rf/core/rfdev.c
 create mode 100644 include/linux/rf_channel.h
 create mode 100644 include/linux/rfdev.h
 create mode 100644 include/uapi/linux/rfdev.h
Documentation/misc-devices/rf_framework new file +110 -0
new file mode 100644
index 0000000..b65b575
@@ -0,0 +1,110 @@
+		Kernel Framework for Radio devices
+
+This document explains the Framework for radio devices along with the APIs
+provided for Phy and controller drivers and the interface for user space.
+
+1. Introduction:
+
+RF signal path is integral part of any system that transmits/receives RF
+(radio frequency) signals. In these systems Data is processed/converted
+to IQ samples (digital representation a RF signal) and passed to a RFIC
+(RF PHY) which converts the digital RF signal (IQ samples) to analog and
+transmits over antenna.
+
+Typically The signal path consists of multiple components:
+
+Antenna controller <-> vector signal processors <-> RFIC <-> Antenna
+
+Each of these components have specific functionalities:
+
+1. Antenna controller: Framing of digital IQ data into protocol specific frames.
+2. vector signal processors: For conditioning of signal.
+3. RFIC : converts digital IQ data to analog signal which is
+	transmitted/received on/from Air.
+
+Also it is desirable to control the complete signal path, for example:
+bringing the complete signal path up/down etc.
+
+The radio device framework introduces a way to accommodate the RF signal
+paths.  One signal path is represented as a RF device (rf0, rf1 etc), and
+it can contain multiple components which have their individual vendor
+specific drivers. The framework provides mechanism by which individual
+components can register with RF framework, and the framework will handle the
+binding of individual component devices to a RF device. RF device exports the
+control interfaces to user space, and this user space interface is independent
+of component (vendor specific) drivers.
+
+RF framework provide APIs for PHY and Controller drivers to register themselves
+and exposes the radio device as a character device for configuration from user
+space.
+
+1. PHY and Controller APIs
+	a) Allocate/free controller and phy device structures
+		The RF framework provide APIs for allocation and deallocation
+		of controller and phy devices.
+
+		struct rf_ctrl_dev *allocate_rf_ctrl_dev(size_t priv_size,
+							unsigned long flags);
+		int free_rf_ctrl_dev(struct rf_ctrl_dev *rf_dev);
+		struct rf_phy_dev *allocate_rf_phy_dev(size_t priv_size,
+							unsigned long flags);
+		int free_rf_phy_dev(struct rf_phy_dev *phy)
+
+	b) Register/Unregister controller and phy devices
+		register_rf_ctrl_dev is used to register the controller
+		with the rf framework. Similarly, register_rf_phy_dev is for
+		registering phy with the framework. Controller and Phy drivers
+		shall populate their structures with phy_id which is used by
+		the framework to bind controller to PHY. Controller and phy
+		can populate this information from device tree or any other
+		mechanism. RF framework will internally maintain a state
+		machine for RF device. User space and controller/phy drivers
+		shall use these states to allow/disallow certain control
+		operations.
+
+		int register_rf_ctrl_dev(struct rf_ctrl_dev *rf_dev);
+		int unregister_rf_ctrl_dev(struct rf_ctrl_dev *rf_dev);
+		int register_rf_phy_dev(struct rf_phy_dev *phy);
+		int unregister_rf_phy_dev(struct rf_phy_dev *phy);
+
+2. User space file_operations
+	a) open rf node
+		User space can make open() calls to open a file descriptor for
+		RF device.
+
+		static int rf_open(struct inode *inode, struct file *filep);
+
+	b) release rf node
+		For releasing the file descriptor of rf device
+
+		static int rf_release(struct inode *inode, struct file *filep);
+
+	c) read from a file descriptor
+		User space can make read() calls to get notification for every
+		Transmit time Interval(TTI) which is an integral part of a
+		communication network.
+
+		static ssize_t rf_read(struct file *filep, char __user *buf,
+					size_t size, loff_t *offset);
+
+	d) ioctl interface
+		User space can interact with the RF framework and the
+		phy/controller drivers using various IOCTLs. Various IOCTL
+		numbers are defined in include/uapi/linux/rfdev.h.
+		User space application can include this file to interact with
+		the kernel controller/phy drivers.
+		The ioctls exposed here are independant of vendor specific
+		controller/phy drivers.
+
+		static long rf_ioctl(struct file *, unsigned int cmd,
+					unsigned long arg);
+
+	e) event handling
+		User space can register event handler to get notified of some
+		events which are triggered from the hardware and user space can
+		perform certain actions on receiving those events.
+
+		int rf_register_event_handler(struct rf_ctrl_dev *rf_dev,
+				struct rf_event_listener *listener);
+		int rf_unregister_event_handler(struct rf_ctrl_dev *rf_dev,
+				enum rf_evt_del flag);
drivers/misc/Kconfig +1 -0
index c002d86..c5ddc28 100644
@@ -536,4 +536,5 @@ source "drivers/misc/carma/Kconfig"
 source "drivers/misc/altera-stapl/Kconfig"
 source "drivers/misc/mei/Kconfig"
 source "drivers/misc/vmw_vmci/Kconfig"
+source "drivers/misc/rf/Kconfig"
 endmenu
drivers/misc/Makefile +1 -0
index c235d5b..62769ab 100644
@@ -53,3 +53,4 @@ obj-$(CONFIG_INTEL_MEI)		+= mei/
 obj-$(CONFIG_VMWARE_VMCI)	+= vmw_vmci/
 obj-$(CONFIG_LATTICE_ECP3_CONFIG)	+= lattice-ecp3-config.o
 obj-$(CONFIG_SRAM)		+= sram.o
+obj-$(CONFIG_RFDEVICES)		+= rf/
drivers/misc/rf/Kconfig new file +37 -0
new file mode 100644
index 0000000..ae4ff36
@@ -0,0 +1,37 @@
+
+# RF (radio frequency) device configuration
+#
+
+menuconfig RFDEVICES
+	default n
+	bool "RF interface device support"
+	---help---
+	Support for RF interface devices.
+	In a baseband system, different radios (RF PHYs) are
+	connected depending on required radio technology. Higher layer
+	stacks need to configure the radio according to required network mode.
+	Adding this support will export different radios connected in system
+	(in case of multi mode system)as RF interface deivces 'rf0', 'rf1' etc.
+	Higher layer stacks (running in user space)can use rfX device to
+	talk to a specific radio.
+
+	radio interface controller driver (Antenna controller) and RF PHY driver
+	connected to system must also be chosen.
+
+if RFDEVICES
+
+config FSL_AIC
+	default y
+	bool "Freescale Antenna Interface Controller (AIC)"
+	---help---
+	Freescale AIC controller (Antenna Interface Controller) is found
+	in bsc913x family of SOCs. AIC has six RF lanes and maximum four
+	RF PHYs can be connected and operated simultaneously.
+
+config ADI9361
+	default y
+	bool "ADI 9361 RF PHY"
+	---help---
+	ADI9361 RF phy driver.
+
+endif
drivers/misc/rf/Makefile new file +5 -0
new file mode 100644
index 0000000..566585e
@@ -0,0 +1,5 @@
+#
+# Makefile for the RF interface drivers.
+#
+
+obj-$(CONFIG_RFDEVICES)		+= core/
drivers/misc/rf/core/Makefile new file +2 -0
new file mode 100644
index 0000000..f8ab6e8
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_RFDEVICES)		+= rfdev.o rf_channel.o
drivers/misc/rf/core/rf_channel.c new file +207 -0

207 lines not on this page · raw message

drivers/misc/rf/core/rfdev.c new file +1263 -0

1,263 lines not on this page · raw message

include/linux/rf_channel.h new file +26 -0
new file mode 100644
index 0000000..408aabf
@@ -0,0 +1,26 @@
+/*
+ * RF device Data channels
+ *
+ * Author: pankaj chauhan <[email protected]>
+ *
+ * Copyright 2011-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+struct rf_frame {
+	int ant;
+	union {
+		void *buffer;
+		u32 buffer_idx;
+	} buf;
+};
+
+int rf_channel_open(struct rf_ctrl_dev *rf_dev,
+	struct rf_channel_params *chan_params);
+int rf_channel_close(struct rf_ctrl_dev *rf_dev, int ant);
+int rf_rx_frame(struct rf_ctrl_dev *rf_dev, struct rf_frame *frame);
+int rf_sniff_done(struct rf_ctrl_dev *rf_dev, int ant);
include/linux/rfdev.h new file +250 -0

250 lines not on this page · raw message

include/uapi/linux/rfdev.h new file +392 -0

392 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#2 lore raw

PATCH 2/5 drivers/misc/rf: AIC: Freescale Antenna Interface controller driver

From: Akhil Goyal <[email protected]>

AIC is the antenna interface controller found in heterogenous SOCs- BSC9131 and BSC9132. It supports NCDMA, WCDMA-FDD, LTE-FDD, LTE-TDD and SNIFF network modes.
AIC has 6 data lanes in BSC9131 and 4 in BSC9132 on which RFICs can be connected. AIC supports at max 4 RFICs working simultaneously.

The address mapping of AIC is a part of DSP side of SOC. But according to the architecture of the system, configuration of this driver shall be done from PA side.

This patch support LTE-FDD, LTE-TDD and WCDMA configurations for AIC. The data from RFIC through AIC goes directly to a hardware accelerator from where it is taken out by DSP core in bsc913x.

This patch also support sniffing of LTE-FDD networks and it can also handle the data path of the sniffing data.

---
 drivers/misc/rf/Makefile              |    1 +
 drivers/misc/rf/controllers/Makefile  |    1 +
 drivers/misc/rf/controllers/fsl_aic.c | 1560 +++++++++++++++++++++++++++++++++
 drivers/misc/rf/controllers/fsl_aic.h |  450 ++++++++++
 4 files changed, 2012 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/rf/controllers/Makefile
 create mode 100644 drivers/misc/rf/controllers/fsl_aic.c
 create mode 100644 drivers/misc/rf/controllers/fsl_aic.h
drivers/misc/rf/Makefile +1 -0
index 566585e..37dc442 100644
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_RFDEVICES)		+= core/
+obj-$(CONFIG_RFDEVICES)		+= controllers/
drivers/misc/rf/controllers/Makefile new file +1 -0
new file mode 100644
index 0000000..6578c3c
@@ -0,0 +1 @@
+obj-$(CONFIG_FSL_AIC)	+= fsl_aic.o
drivers/misc/rf/controllers/fsl_aic.c new file +1560 -0

1,560 lines not on this page · raw message

drivers/misc/rf/controllers/fsl_aic.h new file +450 -0

450 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#3 lore raw

PATCH 3/5 drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

---
 drivers/misc/rf/Makefile     |    1 +
 drivers/misc/rf/phy/Makefile |    2 +
 drivers/misc/rf/phy/ad9361.c | 1918 ++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rf/phy/ad9361.h |  353 ++++++++
 4 files changed, 2274 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/rf/phy/Makefile
 create mode 100644 drivers/misc/rf/phy/ad9361.c
 create mode 100644 drivers/misc/rf/phy/ad9361.h
drivers/misc/rf/Makefile +1 -0
index 37dc442..61a0e7c 100644
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_RFDEVICES)		+= core/
 obj-$(CONFIG_RFDEVICES)		+= controllers/
+obj-$(CONFIG_RFDEVICES)		+= phy/
drivers/misc/rf/phy/Makefile new file +2 -0
new file mode 100644
index 0000000..4b1b54b
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_ADI9361)		+= ad9361.o
drivers/misc/rf/phy/ad9361.c new file +1918 -0

1,918 lines not on this page · raw message

drivers/misc/rf/phy/ad9361.h new file +353 -0

353 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#4 lore raw

PATCH 4/5 binding: Add device tree bindings for freescale AIC and AD phy

From: Akhil Goyal <[email protected]>

For platforms like BSC9131 and BSC9132, a Radio framework for supporting various network modes comprise of an Antenna interface controller driver and a phy driver(AD9361 in this case).
A combination of AIC lane and AD phy is called a rf device which can be used to operate on a particular network mode.

This patch explain various device tree properties required for AIC and AD9361 drivers.

---
 .../devicetree/bindings/rf/ad9361-phy.txt          |   53 ++++++++++++++++++++
 Documentation/devicetree/bindings/rf/fsl-aic.txt   |   47 +++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rf/ad9361-phy.txt
 create mode 100644 Documentation/devicetree/bindings/rf/fsl-aic.txt
Documentation/devicetree/bindings/rf/ad9361-phy.txt new file +53 -0
new file mode 100644
index 0000000..9dbf736
@@ -0,0 +1,53 @@
+* AD9361-phy
+
+Required Properties:
+- compatible : should be "adi,ad9361"
+- reg : chipselect of the spi controller
+- spi-max-frequency :  maximum spi bus frequency for this device (Hz).
+- spi-cpha : (optional) Empty property indicating device requires
+		shifted clock phase (CPHA) mode
+- fsl,ad9361-gpios : Specifies GPIOs being used for AD9361
+		This sequence shall be maintained.
+		Here, <&gpio1 2 1> denotes reset gpio
+		<&gpio0 18 1> denotes pa_en gpio
+		<&gpio0 17 1> denotes lna_en gpio
+- fsl,ad9361-band-grpX : denotes group of LTE/WCDMA bands available for a
+  particular combination of values of pa_en and lna_en gpios.
+  where X can be 1,2,3,4
+	- fsl,ad9361-bands : denotes LTE/WCDMA band numbers for normal DL/UL
+	- fsl,ad9361-sniff-bands : denotes LTE/WCDMA band numbers for sniffing
+	- fsl,ad9361-lna : if present in the node then, lna_en gpio is enabled
+	- fsl,ad9361-pa : if present in the node then, pa_en gpio is enabled
+
+For Example:
+
+rfphy0: ad9361-phy@0{
+	compatible = "adi,ad9361";
+	reg = <0>;
+	spi-max-frequency = <20000000>;
+	spi-cpha;
+	fsl,ad9361-gpios = <&gpio1 2 1 &gpio0 18 1 &gpio0 17 1>;
+	fsl,ad9361-band-grp1 {
+		fsl,ad9361-bands = <1 7>;
+		fsl,ad9361-sniff-bands = <>;
+	};
+	fsl,ad9361-band-grp2 {
+		fsl,ad9361-lna;
+		fsl,ad9361-bands= <41>;
+		fsl,ad9361-sniff-bands = <13>;
+	};
+	fsl,ad9361-band-grp3 {
+		fsl,ad9361-pa;
+		fsl,ad9361-bands = <>;
+		fsl,ad9361-sniff-bands = <1 7>;
+	};
+	fsl,ad9361-band-grp4 {
+		fsl,ad9361-pa;
+		fsl,ad9361-lna;
+		fsl,ad9361-bands = <13 40>;
+		fsl,ad9361-sniff-bands = <>;
+	};
+};
+
+
+
Documentation/devicetree/bindings/rf/fsl-aic.txt new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#5 lore raw

PATCH 5/5 BSC9131rdb/dts: Add nodes for supporting AIC and AD PHY

From: Akhil Goyal <[email protected]>

BSC9131 is a hetrogenous system where Antenna interface controller (AIC) is a part of DSP subsystem. But its configuration is done from PA side. So a DSP node is added with appropriate CCSR address visible to PA and hence the address space for AIC will be visible to PA.

BSC9131 support 3 AIC lanes for ADI interface and 3 for MAXIM type of interface. This patch support only ADI lanes.

This patch also provide node for rfphy which includes control gpios for RFIC and various SPI parameters required for accessing the ADI phy registers. ADI chip is connected to espi-1 and control gpios are controlled by gpio-0 and gpio-1

Currently on BSC9131, the DTS support only one rfphy and it is attached to AIC lane 3 for LTE and WCDMA networks.

---
 arch/powerpc/boot/dts/bsc9131rdb.dts          |    4 ++
 arch/powerpc/boot/dts/bsc9131rdb.dtsi         |   38 ++++++++++++++++++
 arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi |   53 +++++++++++++++++++++++-
 arch/powerpc/boot/dts/fsl/pq3-espi-0.dtsi     |    1 +
 arch/powerpc/boot/dts/fsl/pq3-espi-1.dtsi     |   42 +++++++++++++++++++
 arch/powerpc/boot/dts/fsl/pq3-gpio-0.dtsi     |    1 +
 arch/powerpc/boot/dts/fsl/pq3-gpio-1.dtsi     |   42 +++++++++++++++++++
 7 files changed, 178 insertions(+), 3 deletions(-)
 create mode 100644 arch/powerpc/boot/dts/fsl/pq3-espi-1.dtsi
 create mode 100644 arch/powerpc/boot/dts/fsl/pq3-gpio-1.dtsi
arch/powerpc/boot/dts/bsc9131rdb.dts +4 -0
index e13d2d4..c134de7 100644
@@ -28,6 +28,10 @@
 	board_soc: soc: soc@ff700000 {
 		ranges = <0x0 0x0 0xff700000 0x100000>;
 	};
+
+	dsp_soc: sc3850@ff600000 {
+		ranges = <0x0 0x0 0xff600000 0x100000>;
+	};
 };
 
 /include/ "bsc9131rdb.dtsi"
arch/powerpc/boot/dts/bsc9131rdb.dtsi +38 -0
index 9e6c013..dcf5d85 100644
@@ -110,6 +110,36 @@
 		};
 	};
 
+	spi@6000 {
+		rfphy0: ad9361-phy@0{
+			compatible = "adi,ad9361";
+			reg = <0>;
+			spi-max-frequency = <20000000>;
+			spi-cpha;
+			fsl,ad9361-gpios = <&gpio1 2 1 &gpio0 18 1 &gpio0 17 1>;
+			fsl,ad9361-band-grp1 {
+				fsl,ad9361-bands = <1 7>;
+				fsl,ad9361-sniff-bands = <>;
+			};
+			fsl,ad9361-band-grp2 {
+				fsl,ad9361-lna;
+				fsl,ad9361-bands= <41>;
+				fsl,ad9361-sniff-bands = <13>;
+			};
+			fsl,ad9361-band-grp3 {
+				fsl,ad9361-pa;
+				fsl,ad9361-bands = <>;
+				fsl,ad9361-sniff-bands = <1 7>;
+			};
+			fsl,ad9361-band-grp4 {
+				fsl,ad9361-pa;
+				fsl,ad9361-lna;
+				fsl,ad9361-bands = <13 40>;
+				fsl,ad9361-sniff-bands = <>;
+			};
+		};
+	};
+
 	usb@22000 {
 		phy_type = "ulpi";
 	};
@@ -140,3 +170,11 @@
 		phy-connection-type = "rgmii-id";
 	};
 };
+
+&dsp_soc {
+	aic@50000 {
+		lane2: aiclane@600 {
+		rfphy-handle = <&rfphy0>;
+		};
+	};
+};
arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi +50 -3

71 lines not on this page · raw message

arch/powerpc/boot/dts/fsl/pq3-espi-0.dtsi +1 -0
index 75854b2..e0cf954 100644
@@ -33,6 +33,7 @@
  */
 
 spi@7000 {
+	cell-index = <0>;
 	#address-cells = <1>;
 	#size-cells = <0>;
 	compatible = "fsl,mpc8536-espi";
arch/powerpc/boot/dts/fsl/pq3-espi-1.dtsi new file +42 -0

42 lines not on this page · raw message

arch/powerpc/boot/dts/fsl/pq3-gpio-0.dtsi +1 -0
index 72a3ef5..363e401 100644
@@ -33,6 +33,7 @@
  */
 
 gpio-controller@f000 {
+	cell-index = <0>;
 	#gpio-cells = <2>;
 	compatible = "fsl,pq3-gpio";
 	reg = <0xf000 0x100>;
arch/powerpc/boot/dts/fsl/pq3-gpio-1.dtsi new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#6 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

In reply to [email protected]
Quoted 14 lines · On 06/17/2013 10:09 AM, [email protected] wrote:

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Hi,

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

You seem to have made the kernel layer as thin as possible and provide a IOCTL which allows userspace to directly modify the registers of the hardware. So this sentence from the documentation "user space interface is independent of component (vendor specific) drivers" is not exactly true. If you write a userspace application it will still only work with one specific RF-frontend. There is only a common interface on how to talk to the frontend. Your documentation on this is also a bit sparse, e.g. there is no explanation of the individual IOCTLs.

Since it is probably not such a good idea to have two different drivers for the same device in different subsystems we should probably try to figure something out that will work for us both.

I'd also be interested in learning more about how the userspace side looks like.

- Lars

maintainer
#7 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

Quoted 24 lines · Lars-Peter Clausen
Quoted 14 lines · On 06/17/2013 10:09 AM, [email protected] wrote:

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Quoted 7 lines

Hi,

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

That's the "proper" api for this, not a bunch of chip-custom ioctls that aren't documented anywhere.

thanks,

greg k-h

maintainer
#8 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

Quoted 11 lines · Greg KH
Quoted 7 lines · Lars-Peter Clausen

On 06/17/2013 10:09 AM, [email protected] wrote:

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

That's the "proper" api for this, not a bunch of chip-custom ioctls that aren't documented anywhere.

Depending on what functions there are in the device, it might actually be better to make the chip itself an MFD device, and have sub-functions handled by drivers/iio, drivers/clk, drivers/pwm etc. For the bigger picture I definitely agree: it should use the existing subsystems whereever possible. It may well be that a single IIO device is the right answer in this case, but a new subsystem that covers the entire chip and adds a custom user interface is almost certainly not.

Arnd

#9 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

In reply to Lars-Peter Clausen
Quoted 24 lines · Lars-Peter Clausen
Quoted 14 lines · On 06/17/2013 10:09 AM, [email protected] wrote:

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Quoted 8 lines

Hi,

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

Yes i agree AD9361 is more of a multifunction device and it can fit in IIO framework. This patch (ad9361: AD9361 device driver for Radio phy) implements:

1. Programming of AD9361 :

Most of initialization is done by parsing Low level script generated by ADI tool, and sending the SPIwrite/read/wait calibration commands to the driver. This is more of a raw write interface to device.

2. Adding utility function APIs for higher layers:

We have LTE/WCDMA stacks running in user space. They have requirement of monitoring RSSI, changing Attenuation, reading/changing Rx gain, disable/enable of tx/rx antennas, changing LO frequency etc. This patch exposes APIs which can be accessed through RF device layer user space interface (explained later in the email).

3. Control of Radio card (which has AD9361): We have radio card which contains AD9361 and there are different set of PA/LNAs (Power amplifier/Low Noise Amplifier). Each set caters a set of frequency bands. This patch also exports functions to enable/disable a Tx/Rx path (PA/LNAs) which are external to AD9361.

May be we can spit this driver in two parts :

1. AD9361 driver: which covers #1 and #2 as mentioned as above. And this can be merged with the driver you have in IIO framework.

2. Radio card driver: which covers #3 and uses AD9361 driver's exported APIs to program AD9361 OR may be we can program AD9361 from user space using IIO interface.

pls let me know what do you think is best approach.

Quoted 9 lines

You seem to have made the kernel layer as thin as possible and provide a IOCTL which allows userspace to directly modify the registers of the hardware. So this sentence from the documentation "user space interface is independent of component (vendor specific) drivers" is not exactly true. If you write a userspace application it will still only work with one specific RF-frontend. There is only a common interface on how to talk to the frontend. Your documentation on this is also a bit sparse, e.g. there is no explanation of the individual IOCTLs.

Yes modifying registers from user space is part of the patch set and register read/write interface is aimed only for two purposes:

1. Debugging : taking register dumps etc.
2. Initializing AD9361 using Low level script generated by ADI GUI tool.

I'll try to explain what we meant by 'independent of vendor specific drivers' and the framework itself.

Following is the overview of hardware on which are running these drivers:

1. Antenna controller : This is part of SOC. The controller has multiple IQ data lanes. On the application core of SOC we run Linux. LTE/WCDMA stacks run in user space, and they interact with antenna controller and RFPHY.
2. Radio card: This contains one or more RF PHYS (AD9361). Each AD9361 is connected to Antenna controller IQ lane over JESD207 bus.

With this patch set we aim to abstract combination of a IQ data lane and RF PHY as a 'radio device'. So this patch set is divided in three parts:

1. RF device layer :
- Exposes IOCTLS to user space for device configuration.
- Exposes registration APIs so that antenna controllers and PHYs so that they can register their control operations. antenna controller and RF PHYs don't interact with user space directly.
- Maintains state of overall RF device. For example IQ data transfer starts only when both the controller and PHY are configured and ready.

2. Antenna controller driver: This configures the Antenna controller hardware. It registers its control functions as a ops structure (containing function pointers) with RF device layer.

3. RF PHY driver: This is AD9361 driver (in this patch set). This also registers with it ops structure with RF device layer. One of the operation is raw register read/write as you pointed out.

The RF device layer exposes the two (or more than two) devices (i.e antenna controller and RF PHY) as a RF device 'rf0' to user space. It is similar to Ethernet, which has two drivers (Ethernet MAC controller driver, and the Ethernet PHY driver) under eth0/eth1 interface.

The exposed IOCTLs from RF device layer are generic or protocol specific (except raw register read/write interface), for example:

1. Setting network mode of device to LTE, WCDMA etc
2. Configuring device in TDD or FDD mode.
3. Setting bandwidth to 10 Mhz, 15 Mhz, or 20 Mz.
4. Changing Downlink/Uplink LO frequency to 'X' Mhz.
5. Capturing IQ data from controller.
6. Changing RF settings: attenuation, rx gain etc.
7. Raw register read/write: so that PHYS with programming model similar to AD9361 (using script containing SPI commands) can be supported.

Generally LTE/WCDMA stacks run in user space and they have to interact with the antenna controller and the RF PHY (AD9361) for initialization, control, IQ capture etc.

If we don't have RF device layer then these stacks have to write vendor drivers (antenna controller and RF PHY) specific code for interaction with underlying controller and PHY drivers.

The RF device layer solves this problem by exposing an interface which is protocol/functionality specific, so that the user space stack do not change if underlying antenna controller or RF phy changes.

In user space we have a library called 'rflib' which interacts with RF device layer through exposed IOCTLs. User space LTE/WCDMA stacks interact only with 'rflib' and they are immune to underlying vendor specific drivers. This is the reason for calling 'vendor independent interface'. And if user space wants to fine tune the RF PHY then raw register read/write interface is also exposed.

We are not aware of any other subsystem which meets above mentioned requirements, and exposes interface for LTE/WCDMA stacks for controlling radio hardware. That's why we introduced RF device layer between user space interface and controller specific drivers.

pls suggest what is best possible way/subsystem for hardware and software requirements that i explained above.

Quoted 4 lines

Since it is probably not such a good idea to have two different drivers for the same device in different subsystems we should probably try to figure something out that will work for us both.

I agree, for AD9361 should have one driver, we'll figure out way how requirements for both of us can be met by single driver.

Quoted 2 lines

I'd also be interested in learning more about how the userspace side looks like.

The user space (rflib) is not on a public repository yet, i'll try to figure out how rflib can be

Quoted 2 lines

- Lars

sorry for long reply, we'll cover the details of API/framework in documentation in next version of patch.

thanks,
pankaj

#10 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

Quoted 62 lines · pankaj chauhan
Quoted 26 lines · Lars-Peter Clausen
Quoted 14 lines · On 06/17/2013 10:09 AM, [email protected] wrote:

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Hi,

Quoted 9 lines

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework
though, since the AD9361 is more or less a multifunction device implementing
different functions already covered by the IIO framework, like ADCs, DACs,
clock chips and so on.

Yes i agree AD9361 is more of a multifunction device and it can fit in IIO framework. This patch (ad9361: AD9361 device driver for Radio phy) implements:

1. Programming of AD9361 :

Most of initialization is done by parsing Low level script generated by ADI tool, and sending the SPIwrite/read/wait calibration commands to the driver. This is more of a raw write interface to device.

2. Adding utility function APIs for higher layers:

We have LTE/WCDMA stacks running in user space. They have requirement of monitoring RSSI, changing Attenuation, reading/changing Rx gain, disable/enable of tx/rx antennas, changing LO frequency etc. This patch exposes APIs which can be accessed through RF device layer user space interface (explained later in the email).

3. Control of Radio card (which has AD9361): We have radio card which contains AD9361 and there are different set of PA/LNAs (Power amplifier/Low Noise Amplifier). Each set caters a set of frequency bands. This patch also exports functions to enable/disable a Tx/Rx path (PA/LNAs) which are external to AD9361.

May be we can spit this driver in two parts :

Quoted 8 lines

1. AD9361 driver: which covers #1 and #2 as mentioned as above. And this can be merged with the driver you have in IIO framework.

2. Radio card driver: which covers #3 and uses AD9361 driver's exported APIs to program AD9361 OR may be we can program AD9361 from user space using IIO interface.

pls let me know what do you think is best approach.

Lars pls suggest whether this split will work for both of us.

Quoted 91 lines
Quoted 14 lines

You seem to have made the kernel layer as thin as possible and provide a IOCTL which allows userspace to directly modify the registers of the hardware. So this sentence from the documentation "user space interface is
independent of component (vendor specific) drivers" is not exactly true. If
you write a userspace application it will still only work with one specific
RF-frontend. There is only a common interface on how to talk to the frontend. Your documentation on this is also a bit sparse, e.g. there is no
explanation of the individual IOCTLs.

Yes modifying registers from user space is part of the patch set and register read/write interface is aimed only for two purposes:

1. Debugging : taking register dumps etc.
2. Initializing AD9361 using Low level script generated by ADI GUI tool.

I'll try to explain what we meant by 'independent of vendor specific drivers' and the framework itself.

Following is the overview of hardware on which are running these drivers:

1. Antenna controller : This is part of SOC. The controller has multiple IQ data lanes. On the application core of SOC we run Linux. LTE/WCDMA stacks run in user space, and they interact with antenna controller and RFPHY.
2. Radio card: This contains one or more RF PHYS (AD9361). Each AD9361 is connected to Antenna controller IQ lane over JESD207 bus.

With this patch set we aim to abstract combination of a IQ data lane and RF PHY as a 'radio device'. So this patch set is divided in three parts:

1. RF device layer :
- Exposes IOCTLS to user space for device configuration.
- Exposes registration APIs so that antenna controllers and PHYs so that they can register their control operations. antenna controller and RF PHYs don't interact with user space directly.
- Maintains state of overall RF device. For example IQ data transfer starts only when both the controller and PHY are configured and ready.

2. Antenna controller driver: This configures the Antenna controller hardware. It registers its control functions as a ops structure (containing function pointers) with RF device layer.

3. RF PHY driver: This is AD9361 driver (in this patch set). This also registers with it ops structure with RF device layer. One of the operation is raw register read/write as you pointed out.

The RF device layer exposes the two (or more than two) devices (i.e antenna controller and RF PHY) as a RF device 'rf0' to user space. It is similar to Ethernet, which has two drivers (Ethernet MAC controller driver, and the Ethernet PHY driver) under eth0/eth1 interface.

The exposed IOCTLs from RF device layer are generic or protocol specific (except raw register read/write interface), for example:

1. Setting network mode of device to LTE, WCDMA etc
2. Configuring device in TDD or FDD mode.
3. Setting bandwidth to 10 Mhz, 15 Mhz, or 20 Mz.
4. Changing Downlink/Uplink LO frequency to 'X' Mhz.
5. Capturing IQ data from controller.
6. Changing RF settings: attenuation, rx gain etc.
7. Raw register read/write: so that PHYS with programming model similar to AD9361 (using script containing SPI commands) can be supported.

Generally LTE/WCDMA stacks run in user space and they have to interact with the antenna controller and the RF PHY (AD9361) for initialization, control, IQ capture etc.

If we don't have RF device layer then these stacks have to write vendor drivers (antenna controller and RF PHY) specific code for interaction with underlying controller and PHY drivers.

The RF device layer solves this problem by exposing an interface which is protocol/functionality specific, so that the user space stack do not change if underlying antenna controller or RF phy changes.

In user space we have a library called 'rflib' which interacts with RF device layer through exposed IOCTLs. User space LTE/WCDMA stacks interact only with 'rflib' and they are immune to underlying vendor specific drivers. This is the reason for calling 'vendor independent interface'. And if user space wants to fine tune the RF PHY then raw register read/write interface is also exposed.

Quoted 8 lines

We are not aware of any other subsystem which meets above mentioned requirements, and exposes interface for LTE/WCDMA stacks for controlling radio hardware. That's why we introduced RF device layer between user space interface and controller specific drivers.

pls suggest what is best possible way/subsystem for hardware and software requirements that i explained above.

I've tried to capture the need of a framework for drivers dealing with IQ data which interact with LTE/WCDMA stacks. Pls suggest the way forward.

Quoted 24 lines
Quoted 5 lines

Since it is probably not such a good idea to have two different drivers for
the same device in different subsystems we should probably try to figure something out that will work for us both.

I agree, for AD9361 should have one driver, we'll figure out way how requirements for both of us can be met by single driver.

Quoted 3 lines

I'd also be interested in learning more about how the userspace side looks like.

The user space (rflib) is not on a public repository yet, i'll try to figure out how rflib can be

Quoted 2 lines

- Lars

sorry for long reply, we'll cover the details of API/framework in documentation in next version of patch.

thanks,
pankaj

#11 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

In reply to pankaj chauhan

On Thu 20 Jun 2013 06:35, pankaj chauhan pondered:

Quoted 11 lines · Lars-Peter Clausen
Quoted 10 lines · On 06/17/2013 10:09 AM, [email protected] wrote:
Quoted 9 lines

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

The AD9361 datasheet still hasn't been posted for public consumption yet (as of today), but for those interested, here is something similar - just not exactly - but it gets the idea across.

http://www.analog.com/static/imported-files/data_sheets/AD9357.pdf

Quoted 25 lines
Quoted 13 lines
Quoted 4 lines

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Quoted 7 lines

Hi,

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

Yes i agree AD9361 is more of a multifunction device and it can fit in IIO framework. This patch (ad9361: AD9361 device driver for Radio phy) implements:

Quoted 5 lines

1. Programming of AD9361 :

Most of initialization is done by parsing Low level script generated by ADI tool, and sending the SPIwrite/read/wait calibration commands to the driver. This is more of a raw write interface to device.

The "ADI GUI tool", is a proprietary, closed source, Windows only application. I think that for a Linux driver - we would want to be completely independent of that, and that the driver should be (a) standalone, or (b) useable with Linux based tools.

Quoted 7 lines

2. Adding utility function APIs for higher layers:

We have LTE/WCDMA stacks running in user space. They have requirement of monitoring RSSI, changing Attenuation, reading/changing Rx gain, disable/enable of tx/rx antennas, changing LO frequency etc. This patch exposes APIs which can be accessed through RF device layer user space interface (explained later in the email).

Wow - LTE in userspace?

What's your requirements for real-timeness of the system? Bandwidth? Are you running a stock kernel for this? If you are monitoring RSSI, and changing attenuation (an AGC loop) - how quickly does this loop need to run? What speed are you running the ADC/DACs into userspace?

Quoted 5 lines

3. Control of Radio card (which has AD9361): We have radio card which contains AD9361 and there are different set of PA/LNAs (Power amplifier/Low Noise Amplifier). Each set caters a set of frequency bands. This patch also exports functions to enable/disable a Tx/Rx path (PA/LNAs) which are external to AD9361.

Isn't this just normal GPIO control? (like Arnd suggested - if you need GPIO - make things a MFD - and use the existing GPIO infrastructure - at least that is how I thought the GPO would be handled, and maybe even the CNTRL IN/OUT).

Quoted 10 lines

May be we can spit this driver in two parts :

1. AD9361 driver: which covers #1 and #2 as mentioned as above. And this can be merged with the driver you have in IIO framework.

2. Radio card driver: which covers #3 and uses AD9361 driver's exported APIs to program AD9361 OR may be we can program AD9361 from user space using IIO interface.

pls let me know what do you think is best approach.

I don't know if we have all the answers yet either. We aren't running LTE - so having a real world userspace consumer might help direct us down a workable path for everyone.

It sounds like all the internal filters (which require floating point to calculate the coefficients) - you are letting the GUI tool handle all this? This is part of the issue we have been looking at - how to split things, so no floating point in the driver...

Quoted 114 lines
Quoted 8 lines

You seem to have made the kernel layer as thin as possible and provide a IOCTL which allows userspace to directly modify the registers of the hardware. So this sentence from the documentation "user space interface is independent of component (vendor specific) drivers" is not exactly true. If you write a userspace application it will still only work with one specific RF-frontend. There is only a common interface on how to talk to the frontend. Your documentation on this is also a bit sparse, e.g. there is no explanation of the individual IOCTLs.

Yes modifying registers from user space is part of the patch set and register read/write interface is aimed only for two purposes:

1. Debugging : taking register dumps etc.
2. Initializing AD9361 using Low level script generated by ADI GUI tool.

I'll try to explain what we meant by 'independent of vendor specific drivers' and the framework itself.

Following is the overview of hardware on which are running these drivers:

1. Antenna controller : This is part of SOC. The controller has multiple IQ data lanes. On the application core of SOC we run Linux. LTE/WCDMA stacks run in user space, and they interact with antenna controller and RFPHY.
2. Radio card: This contains one or more RF PHYS (AD9361). Each AD9361 is connected to Antenna controller IQ lane over JESD207 bus.

With this patch set we aim to abstract combination of a IQ data lane and RF PHY as a 'radio device'. So this patch set is divided in three parts:

1. RF device layer :
- Exposes IOCTLS to user space for device configuration.
- Exposes registration APIs so that antenna controllers and PHYs so that they can register their control operations. antenna controller and RF PHYs don't interact with user space directly.
- Maintains state of overall RF device. For example IQ data transfer starts only when both the controller and PHY are configured and ready.

2. Antenna controller driver: This configures the Antenna controller hardware. It registers its control functions as a ops structure (containing function pointers) with RF device layer.

3. RF PHY driver: This is AD9361 driver (in this patch set). This also registers with it ops structure with RF device layer. One of the operation is raw register read/write as you pointed out.

The RF device layer exposes the two (or more than two) devices (i.e antenna controller and RF PHY) as a RF device 'rf0' to user space. It is similar to Ethernet, which has two drivers (Ethernet MAC controller driver, and the Ethernet PHY driver) under eth0/eth1 interface.

The exposed IOCTLs from RF device layer are generic or protocol specific (except raw register read/write interface), for example:

1. Setting network mode of device to LTE, WCDMA etc
2. Configuring device in TDD or FDD mode.
3. Setting bandwidth to 10 Mhz, 15 Mhz, or 20 Mz.
4. Changing Downlink/Uplink LO frequency to 'X' Mhz.
5. Capturing IQ data from controller.
6. Changing RF settings: attenuation, rx gain etc.
7. Raw register read/write: so that PHYS with programming model similar to AD9361 (using script containing SPI commands) can be supported.

Generally LTE/WCDMA stacks run in user space and they have to interact with the antenna controller and the RF PHY (AD9361) for initialization, control, IQ capture etc.

If we don't have RF device layer then these stacks have to write vendor drivers (antenna controller and RF PHY) specific code for interaction with underlying controller and PHY drivers.

The RF device layer solves this problem by exposing an interface which is protocol/functionality specific, so that the user space stack do not change if underlying antenna controller or RF phy changes.

In user space we have a library called 'rflib' which interacts with RF device layer through exposed IOCTLs. User space LTE/WCDMA stacks interact only with 'rflib' and they are immune to underlying vendor specific drivers. This is the reason for calling 'vendor independent interface'. And if user space wants to fine tune the RF PHY then raw register read/write interface is also exposed.

We are not aware of any other subsystem which meets above mentioned requirements, and exposes interface for LTE/WCDMA stacks for controlling radio hardware. That's why we introduced RF device layer between user space interface and controller specific drivers.

pls suggest what is best possible way/subsystem for hardware and software requirements that i explained above.

Quoted 3 lines

Since it is probably not such a good idea to have two different drivers for the same device in different subsystems we should probably try to figure something out that will work for us both.

I agree, for AD9361 should have one driver, we'll figure out way how requirements for both of us can be met by single driver.

Quoted 2 lines

I'd also be interested in learning more about how the userspace side looks like.

The user space (rflib) is not on a public repository yet, i'll try to figure out how rflib can be

Quoted 1 line

- Lars

sorry for long reply, we'll cover the details of API/framework in documentation in next version of patch.

thanks,
pankaj

#12 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

Quoted 46 lines · Robin

On Thu 20 Jun 2013 06:35, pankaj chauhan pondered:

Quoted 11 lines · Lars-Peter Clausen
Quoted 10 lines · On 06/17/2013 10:09 AM, [email protected] wrote:
Quoted 9 lines

From: Akhil Goyal <[email protected]>

AD9361 is a radio phy(RFIC) for radio networks. This phy can support LTE-FDD/LTE-TDD and WCDMA networks. The RFIC can convert the analog radio signals from air to digital IQ samples.

AD9361 is controlled via an SPI bus and all the register read/ write can be performed via SPI transactions.

The AD9361 datasheet still hasn't been posted for public consumption yet (as of today), but for those interested, here is something similar - just not exactly - but it gets the idea across.

http://www.analog.com/static/imported-files/data_sheets/AD9357.pdf

Quoted 27 lines
Quoted 13 lines
Quoted 4 lines

Driver provides various operations for configuring and controlling the AD PHY. These can be controlled from the user space via the rfdev framework.

Quoted 8 lines

Driver also binds itself to one of AIC lane using RF framework. The combination of AIC lane and PHY connected to it works as one RF device.

Quoted 7 lines

Hi,

This is interesting. We at Analog Devices are currently also working on a driver for this part. We are using the Linux Industrial IO (IIO) framework though, since the AD9361 is more or less a multifunction device implementing different functions already covered by the IIO framework, like ADCs, DACs, clock chips and so on.

Yes i agree AD9361 is more of a multifunction device and it can fit in IIO framework. This patch (ad9361: AD9361 device driver for Radio phy) implements:

1. Programming of AD9361 :

Quoted 9 lines
Quoted 3 lines

Most of initialization is done by parsing Low level script generated by ADI tool, and sending the SPIwrite/read/wait calibration commands to the driver. This is more of a raw write interface to device.

The "ADI GUI tool", is a proprietary, closed source, Windows only application. I think that for a Linux driver - we would want to be completely independent of that, and that the driver should be (a) standalone, or (b) useable with Linux based tools.

Agreed. We also would like to integrate with standalone driver instead of a driver which is dependent on 'ADI GUI tool'. since we had limited access to internals AD9361, we choose script generated by ADI tool as our configuration path for AD9361.

One your standalone driver is available we can discard AD9361 driver in this patch set and integrate our antenna controller driver with the standalone driver.

Quoted 10 lines
Quoted 7 lines

2. Adding utility function APIs for higher layers:

We have LTE/WCDMA stacks running in user space. They have requirement of monitoring RSSI, changing Attenuation, reading/changing Rx gain, disable/enable of tx/rx antennas, changing LO frequency etc. This patch exposes APIs which can be accessed through RF device layer user space interface (explained later in the email).

Wow - LTE in userspace?

Yes we run both LTE and WCDMA stacks in user space. Reason is that most of commercial LTE/WCDMA stack vendors implement their stacks in user space.

Here is how it works:

1. Layer1 stack runs on a DSP core running non Linux RTOS.
2. Layer2/3 stacks run in Linux user space on a application core.
3. Both cores use hardware based communication mechanisms for communication between L1 <-> L2/L3.

Quoted 5 lines

What's your requirements for real-timeness of the system? Bandwidth? Are you running a stock kernel for this? If you are monitoring RSSI, and changing attenuation (an AGC loop) - how quickly does this loop need to run? What speed are you running the ADC/DACs into userspace?

Since L2/L3 stacks are in user space, we can not run it on stock kernel. We run it on sock kernel + PREEMT_RT patch. The Real time requirement varies from protocol to protocol, for example for LTE we have to perform 'few operations' in a TTI (1 milli second, with error margin of 30 micro seconds). 'Few operations' again depends on use case and data path which we are running on system, some examples are:

1. Reading RSSI values.
2. Updating gain.
3. Reading IQ data of last subframe (1 ms), radio frame (10 ms), or multiple radio frames (N * 10ms).

updating attenuation isn't currently in real time path.

We are running at maximum of 30.72 MSPS (million samples per second, with 16 bit samples). but Speed of IQ transfer wont' matter much for Linux drivers because IQ data doesn't pass through Linux drivers (except for sniffing).

Quoted 11 lines
Quoted 6 lines

3. Control of Radio card (which has AD9361): We have radio card which contains AD9361 and there are different set of PA/LNAs (Power amplifier/Low Noise Amplifier). Each set caters a set of frequency bands. This patch also exports functions to enable/disable a Tx/Rx path (PA/LNAs) which are external to AD9361.

Isn't this just normal GPIO control? (like Arnd suggested - if you need GPIO - make things a MFD - and use the existing GPIO infrastructure - at least that is how I thought the GPO would be handled, and maybe even the CNTRL IN/OUT).

Agreed on this. so radio card part of driver can very well be in MFD.

Quoted 10 lines
Quoted 10 lines

May be we can spit this driver in two parts :

1. AD9361 driver: which covers #1 and #2 as mentioned as above. And this can be merged with the driver you have in IIO framework.

2. Radio card driver: which covers #3 and uses AD9361 driver's exported APIs to program AD9361 OR may be we can program AD9361 from user space using IIO interface.

Quoted 6 lines
Quoted 1 line

pls let me know what do you think is best approach.

I don't know if we have all the answers yet either. We aren't running LTE - so having a real world userspace consumer might help direct us down a workable path for everyone.

We are using AD9361 for LTE and WCDMA, so we are real world users :) only problem is that the vendors for L2/L3 stacks are in user space (and their stacks are not open source). I can document the user space interface that we have, and then we can discuss on the interface for additions/deletions/modifications.

Quoted 5 lines

It sounds like all the internal filters (which require floating point to calculate the coefficients) - you are letting the GUI tool handle all this? This is part of the issue we have been looking at - how to split things, so no floating point in the driver...

Yes, what we are doing is that we generate script for a particular bandwidth/Lo frequency combination and initialize AD9361 with this script. Later if we have to change LO frequency, gain tables, synthesizer tables we do floating point in user space and pass fixed point data in driver. This makes programming interface of AD9361 much simpler for us to use.

We can adopt the full fledged standalone driver that you are developing and integrate with our controller drivers as long as our requirements (functionality for function pointers in phy_ops structure) are met.

Quoted 1 line
#13 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

In reply to pankaj chauhan
Quoted 4 lines · pankaj chauhan

Yes modifying registers from user space is part of the patch set and register read/write interface is aimed only for two purposes:

1. Debugging : taking register dumps etc.

Use regmap, it should have the infrastructure you need here.

Quoted 1 line

2. Initializing AD9361 using Low level script generated by ADI GUI tool.

This sounds like generating a firmmware blob that the driver can load. You may have to cook the GUI output to be more amenable to loading in the kernel (or persuade the GUI guys to generate something useful here).

#14 lore raw

Re: [PATCH 3/5] drivers/misc: rf/ad9361: AD9361 device driver for Radio phy

Quoted 9 lines · Mark Brown
Quoted 4 lines · pankaj chauhan

Yes modifying registers from user space is part of the patch set and register read/write interface is aimed only for two purposes:

1. Debugging : taking register dumps etc.

Use regmap, it should have the infrastructure you need here.

Thanks! I looked into regmap, and it is exactly what we want. We'll remove reg read/write from our patch and use regmap.

Quoted 6 lines
Quoted 1 line

2. Initializing AD9361 using Low level script generated by ADI GUI tool.

This sounds like generating a firmmware blob that the driver can load. You may have to cook the GUI output to be more amenable to loading in the kernel (or persuade the GUI guys to generate something useful here).

Yes it is kind of generating firmware blob from GUI tool. They reason why we choose to initialize AD9361 using script generated by GUI tool was lack of our insight in AD9361, and script is the quickest way to bring-up AD9361. This GUI is developed by analog devices, so we don't have much control on it. Lars and Robin are developing full fledged driver for Ad9661, We intend to use that driver only, that's why in next version of patch we'll remove AD9361 driver from our patchset, and integrate with Lars' driver once it is available.

maintainer
#15 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

In reply to [email protected]
Quoted 6 lines · On Monday 17 June 2013, [email protected] wrote:
drivers/misc/rf/Kconfig new file +6 -0
+
+menuconfig RFDEVICES
+	default n
+	bool "RF interface device support"
+	---help---
+	Support for RF interface devices.

drivers/misc/rf/Kconfig line 19

Quoted 10 lines
drivers/misc/rf/Kconfig new file +10 -0
+	In a baseband system, different radios (RF PHYs) are
+	connected depending on required radio technology. Higher layer
+	stacks need to configure the radio according to required network mode.
+	Adding this support will export different radios connected in system
+	(in case of multi mode system)as RF interface deivces 'rf0', 'rf1' etc.
+	Higher layer stacks (running in user space)can use rfX device to
+	talk to a specific radio.
+
+	radio interface controller driver (Antenna controller) and RF PHY driver
+	connected to system must also be chosen.

You should spell out "RF" at least once here, not everybody is familiar with the term.

Quoted 7 lines
drivers/misc/rf/Kconfig new file +7 -0
+if RFDEVICES
+
+config FSL_AIC
+	default y
+	bool "Freescale Antenna Interface Controller (AIC)"
+	---help---
+	Freescale AIC controller (Antenna Interface Controller) is found

drivers/misc/rf/Kconfig line 37

Quoted 10 lines
drivers/misc/rf/Kconfig new file +10 -0
+	in bsc913x family of SOCs. AIC has six RF lanes and maximum four
+	RF PHYs can be connected and operated simultaneously.
+
+config ADI9361
+	default y
+	bool "ADI 9361 RF PHY"
+	---help---
+	ADI9361 RF phy driver.
+
+endif

This should probably be part of a later patch.

drivers/misc/rf/core/rfdev.c line 52

Quoted 8 lines
drivers/misc/rf/core/rfdev.c new file +8 -0
+
+static struct rf_priv *rf_priv;
+static int rf_change_state(struct rf_ctrl_dev *rf_dev, unsigned int state);
+static int rf_attach_phy(struct rf_ctrl_dev *rf_dev, struct rf_phy_dev *phy);
+static int rf_open(struct inode *inode, struct file *filep);
+static int rf_release(struct inode *inode, struct file *filep);
+static ssize_t rf_read(struct file *, char __user *, size_t, loff_t *);
+static long rf_ioctl(struct file *, unsigned int, unsigned long);

Please reorganize the file so that you don't need forward declarations for functions.

Quoted 14 lines
drivers/misc/rf/core/rfdev.c new file +14 -0
+struct rf_ctrl_dev *allocate_rf_ctrl_dev(size_t priv_size,
+		unsigned long flags)
+{
+	struct rf_ctrl_dev *rf_dev;
+	size_t size;
+
+	size = sizeof(struct rf_ctrl_dev) + priv_size;
+	rf_dev = kzalloc(size, flags);
+
+	if (!rf_dev)
+		return rf_dev;
+
+	atomic_set(&rf_dev->ref, 1);
+	mutex_init(&rf_dev->lock);

drivers/misc/rf/core/rfdev.c line 84

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+	init_waitqueue_head(&rf_dev->wait_q);
+	INIT_LIST_HEAD(&rf_dev->event_handler_list);
+	spin_lock_init(&rf_dev->event_handler_lock);
+	raw_spin_lock_init(&rf_dev->wait_q_lock);
+	rf_dev->priv = (unsigned char *) rf_dev + sizeof(struct rf_ctrl_dev);
+	rf_dev->dev_idx = INVAL_DEV_IDX;
+
+	return rf_dev;
+}
+EXPORT_SYMBOL(allocate_rf_ctrl_dev);

Normally I would expect to see EXPORT_SYMBOL_GPL.

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+	/*
+	 * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+	 * i.e they can sleep. This fact is problem for us because
+	 * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+	 * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+	 * called from rf_notify_dl_tti (which is called in interrupt context).
+	 * As a workaround, wait_q_lock is used for protecting the wait_q and
+	 * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+	 * are used.
+	 */

drivers/misc/rf/core/rfdev.c line 428

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__add_wait_queue_tail_exclusive(&rf_dev->wait_q, &wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+	set_current_state(TASK_INTERRUPTIBLE);
+	/*Now wait here, tti notificaion will wake us up*/
+	schedule();
+	set_current_state(TASK_RUNNING);
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__remove_wait_queue(&rf_dev->wait_q, &wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

Quoted 12 lines
drivers/misc/rf/core/rfdev.c new file +12 -0
+static long rf_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
+{
+	struct rf_ctrl_dev *rf_dev;
+	struct rf_phy_dev *phy;
+	struct rf_init_params init_params;
+	struct rif_phy_cmd_set cmd_set;
+	struct rif_reg_buf reg_buf;
+	struct rif_write_reg_buf write_reg_buf;
+	struct rif_dac_params dac_params;
+	struct rif_dac_buf dac_buff;
+	struct rf_dev_info dev_info;
+	struct rf_tx_buf tx_buf;

drivers/misc/rf/core/rfdev.c line 652

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+	struct rf_tx_en_dis tx_en_dis;
+	struct rf_rssi rssi;
+	struct rf_rx_gain rx_gain;
+	struct rf_gain_ctrl gain_ctrl;
+	struct rf_sniff_params sniff_params;
+	struct rf_synth_table synth_table;
+	struct rf_channel_params chan_params;
+	struct rf_event_listener listener;
+	unsigned long long (*params_buf)[NUM_SYNTH_PARAMS];
+	u8 (*reg_vals_buf)[NUM_SYNTH_REGS];

Are you sure you don't run out of stack space here?
It may also be beter for style reasons to split this function into a set of functions, one for each case.

drivers/misc/rf/core/rfdev.c line 661

Quoted 9 lines
drivers/misc/rf/core/rfdev.c new file +9 -0
+	u32	*buf;
+	u32 u32arg;
+	int rc = -ENOSYS, size;
+
+	rf_dev = filep->private_data;
+	phy = rf_dev->phy;
+
+	rc = mutex_lock_interruptible(&rf_dev->lock);
+	switch (cmd) {

If mutex_lock_interruptible() fails, you should not enter the function because you don't actually hold the mutex.

include/uapi/linux/rfdev.h line 239

Quoted 11 lines
include/uapi/linux/rfdev.h new file +11 -0
+struct rif_phy_cmd {
+	__u32	param1;
+	__u32	param2;
+	__u32	param3;
+	__u8	cmd;
+};
+
+struct rif_phy_cmd_set {
+	struct rif_phy_cmd *cmds;
+	__u32 count;
+};

Please try to avoid ioctl structures with pointers in them, they are harder to parse from anything that needs to intercept the ioctl in user space, and they break 64 bit compatibility mode.

You should also add padding in the first structure to ensure that the size is a multiple of the largest member. Otherwise you break e.g. ARM OABI support or anything else that has unconventional rules on the ABI.

include/uapi/linux/rfdev.h line 260

Quoted 9 lines
include/uapi/linux/rfdev.h new file +9 -0
+struct time_sync_1588_cnt {
+	__u32 high;
+	__u32 low;
+};
+
+struct time_info {
+	struct time_sync_1588_cnt time_cnt;
+	__u8 event;
+};

Here too.

include/uapi/linux/rfdev.h line 276

Quoted 8 lines
include/uapi/linux/rfdev.h new file +8 -0
+struct time_sync_data {
+	struct time_info time_info;
+	__u32 lte_delay;
+	__u32 ioctl_cmd;
+	__u32 black_out_duration;
+	__u8 correction_mode;
+	__u8 sync_source;
+};

It definitely sounds like a bug to have a member named "ioctl_cmd" in a structure that is passed in an ioctl command.

include/uapi/linux/rfdev.h line 286

Quoted 4 lines
include/uapi/linux/rfdev.h new file +4 -0
+struct rif_dac_buf {
+	__u32 correction_type;
+	__u32 *buf;
+};

A pointer again.

Quoted 16 lines
include/uapi/linux/rfdev.h new file +16 -0
+#define RF_MAGIC 0xEE
+#define RIF_DEV_INIT		_IOWR(RF_MAGIC, 1, struct rf_init_params)
+#define RIF_SET_TIMER_SOURCE	_IOW(RF_MAGIC, 2, unsigned int)
+#define RIF_GET_STATE		_IOR(RF_MAGIC, 3, unsigned int)
+#define RIF_SET_TIMER_CORRECTION _IOW(RF_MAGIC, 4, struct rif_dac_params)
+#define	RIF_RUN_PHY_CMDS	_IOW(RF_MAGIC, 5, struct rif_phy_cmd_set)
+#define RIF_READ_RSSI		_IOWR(RF_MAGIC, 6, struct rf_rssi)
+#define RIF_READ_PHY_REGS	_IOR(RF_MAGIC, 7, struct rif_reg_buf)
+#define RIF_READ_CTRL_REGS	_IOR(RF_MAGIC, 8, struct rif_reg_buf)
+#define RIF_START		_IO(RF_MAGIC, 9)
+#define RIF_STOP		_IO(RF_MAGIC, 10)
+#define RIF_GET_DEV_INFO	_IOWR(RF_MAGIC, 11, struct rf_dev_info)
+#define RIF_WRITE_PHY_REGS _IOR(RF_MAGIC, 12, struct rif_write_reg_buf)
+#define RIF_GET_DAC_VALUE	_IOR(RF_MAGIC, 13, struct rif_dac_buf)
+#define RIF_SET_TX_ATTEN	_IOW(RF_MAGIC, 14, struct rf_tx_buf)
+#define RIF_EN_DIS_TX		_IOW(RF_MAGIC, 15, struct rf_tx_en_dis)

include/uapi/linux/rfdev.h line 390

Quoted 10 lines
include/uapi/linux/rfdev.h new file +10 -0
+#define RIF_WRITE_CTRL_REGS 	_IOW(RF_MAGIC, 16, struct rif_write_reg_buf)
+#define RIF_READ_RX_GAIN 	_IOWR(RF_MAGIC, 17, struct rf_rx_gain)
+#define RIF_CONFIG_SNIFF 	_IOWR(RF_MAGIC, 18, struct rf_sniff_params)
+#define RIF_WRITE_RX_GAIN 	_IOW(RF_MAGIC, 19, struct rf_rx_gain)
+#define RIF_SET_GAIN_CTRL_MODE 	_IOW(RF_MAGIC, 20, struct rf_gain_ctrl)
+#define RIF_INIT_SYNTH_TABLE	_IOW(RF_MAGIC, 21, struct rf_synth_table)
+#define RIF_CHANNEL_OPEN	_IOW(RF_MAGIC, 22, struct rf_channel_params)
+#define RIF_CHANNEL_CLOSE	_IOW(RF_MAGIC, 23, unsigned int)
+#define RIF_REGISTER_EVENT	_IOW(RF_MAGIC, 24, struct rf_event_listener)
+#define RIF_UNREGISTER_EVENT	_IO(RF_MAGIC, 25)

On the whole, the ioctl API looks very complex to me. It may well be that the complexity is necessary, but I cannot tell because I don't understand the subsystem. Can you find someone from another company that has hardware which would use the same subsystem, and have them do a review of the API to ensure it works for them as well?

Arnd

#16 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

Quoted 12 lines · Arnd Bergmann
Quoted 11 lines · On Monday 17 June 2013, [email protected] wrote:
drivers/misc/rf/Kconfig new file +11 -0
+
+menuconfig RFDEVICES
+	default n
+	bool "RF interface device support"
+	---help---
+	Support for RF interface devices.
+	In a baseband system, different radios (RF PHYs) are
+	connected depending on required radio technology. Higher layer
+	stacks need to configure the radio according to required network mode.
+	Adding this support will export different radios connected in system
+	(in case of multi mode system)as RF interface deivces 'rf0', 'rf1' etc.
Quoted 8 lines

drivers/misc/rf/Kconfig line 19

Quoted 5 lines
drivers/misc/rf/Kconfig new file +5 -0
+	Higher layer stacks (running in user space)can use rfX device to
+	talk to a specific radio.
+
+	radio interface controller driver (Antenna controller) and RF PHY driver
+	connected to system must also be chosen.

You should spell out "RF" at least once here, not everybody is familiar with the term.

Ok I will do that

Quoted 12 lines
Quoted 12 lines
drivers/misc/rf/Kconfig new file +11 -0
+if RFDEVICES
+
+config FSL_AIC
+	default y
+	bool "Freescale Antenna Interface Controller (AIC)"
+	---help---
+	Freescale AIC controller (Antenna Interface Controller) is found
+	in bsc913x family of SOCs. AIC has six RF lanes and maximum four
+	RF PHYs can be connected and operated simultaneously.
+
+config ADI9361
Quoted 8 lines

drivers/misc/rf/Kconfig line 37

Quoted 6 lines
drivers/misc/rf/Kconfig new file +6 -0
+	default y
+	bool "ADI 9361 RF PHY"
+	---help---
+	ADI9361 RF phy driver.
+
+endif

This should probably be part of a later patch.

Ok I will do that

Quoted 12 lines

drivers/misc/rf/core/rfdev.c line 52

Quoted 8 lines
drivers/misc/rf/core/rfdev.c new file +8 -0
+
+static struct rf_priv *rf_priv;
+static int rf_change_state(struct rf_ctrl_dev *rf_dev, unsigned int state);
+static int rf_attach_phy(struct rf_ctrl_dev *rf_dev, struct rf_phy_dev *phy);
+static int rf_open(struct inode *inode, struct file *filep);
+static int rf_release(struct inode *inode, struct file *filep);
+static ssize_t rf_read(struct file *, char __user *, size_t, loff_t *);
+static long rf_ioctl(struct file *, unsigned int, unsigned long);

Please reorganize the file so that you don't need forward declarations for functions.

ok I will do that.

Quoted 18 lines
Quoted 18 lines
drivers/misc/rf/core/rfdev.c new file +18 -0
+struct rf_ctrl_dev *allocate_rf_ctrl_dev(size_t priv_size,
+		unsigned long flags)
+{
+	struct rf_ctrl_dev *rf_dev;
+	size_t size;
+
+	size = sizeof(struct rf_ctrl_dev) + priv_size;
+	rf_dev = kzalloc(size, flags);
+
+	if (!rf_dev)
+		return rf_dev;
+
+	atomic_set(&rf_dev->ref, 1);
+	mutex_init(&rf_dev->lock);
+	init_waitqueue_head(&rf_dev->wait_q);
+	INIT_LIST_HEAD(&rf_dev->event_handler_list);
+	spin_lock_init(&rf_dev->event_handler_lock);
+	raw_spin_lock_init(&rf_dev->wait_q_lock);
Quoted 8 lines

drivers/misc/rf/core/rfdev.c line 84

Quoted 6 lines
drivers/misc/rf/core/rfdev.c new file +6 -0
+	rf_dev->priv = (unsigned char *) rf_dev + sizeof(struct rf_ctrl_dev);
+	rf_dev->dev_idx = INVAL_DEV_IDX;
+
+	return rf_dev;
+}
+EXPORT_SYMBOL(allocate_rf_ctrl_dev);

Normally I would expect to see EXPORT_SYMBOL_GPL.

ok i will correct this

Quoted 17 lines
Quoted 17 lines
drivers/misc/rf/core/rfdev.c new file +15 -0
+	/*
+	 * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+	 * i.e they can sleep. This fact is problem for us because
+	 * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+	 * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+	 * called from rf_notify_dl_tti (which is called in interrupt context).
+	 * As a workaround, wait_q_lock is used for protecting the wait_q and
+	 * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+	 * are used.
+	 */
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__add_wait_queue_tail_exclusive(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+	set_current_state(TASK_INTERRUPTIBLE);
+	/*Now wait here, tti notificaion will wake us up*/
Quoted 8 lines

drivers/misc/rf/core/rfdev.c line 428

Quoted 5 lines
drivers/misc/rf/core/rfdev.c new file +5 -0
+	schedule();
+	set_current_state(TASK_RUNNING);
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__remove_wait_queue(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

wait_event() is internally calling spin_lock_irqsave() and this function will be called in hard IRQ context with PREEMPT_RT enabled(IRQF_NODELAY set). So wait_event cannot be used. This problem can be solved if we can get the following patch applied on the tree.
https://patchwork.kernel.org/patch/2161261/

Quoted 3 lines

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

The interrupt handler has real time requirement and thus running in HARDIRQ context with flag IRQF_NODELAY. We get this interrupt in every millisecond.

Quoted 19 lines
Quoted 19 lines
drivers/misc/rf/core/rfdev.c new file +18 -0
+static long rf_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
+{
+	struct rf_ctrl_dev *rf_dev;
+	struct rf_phy_dev *phy;
+	struct rf_init_params init_params;
+	struct rif_phy_cmd_set cmd_set;
+	struct rif_reg_buf reg_buf;
+	struct rif_write_reg_buf write_reg_buf;
+	struct rif_dac_params dac_params;
+	struct rif_dac_buf dac_buff;
+	struct rf_dev_info dev_info;
+	struct rf_tx_buf tx_buf;
+	struct rf_tx_en_dis tx_en_dis;
+	struct rf_rssi rssi;
+	struct rf_rx_gain rx_gain;
+	struct rf_gain_ctrl gain_ctrl;
+	struct rf_sniff_params sniff_params;
+	struct rf_synth_table synth_table;
Quoted 8 lines

drivers/misc/rf/core/rfdev.c line 652

Quoted 4 lines
drivers/misc/rf/core/rfdev.c new file +4 -0
+	struct rf_channel_params chan_params;
+	struct rf_event_listener listener;
+	unsigned long long (*params_buf)[NUM_SYNTH_PARAMS];
+	u8 (*reg_vals_buf)[NUM_SYNTH_REGS];

Are you sure you don't run out of stack space here?
It may also be beter for style reasons to split this function into a set of functions, one for each case.

ok I will split this function.

Quoted 13 lines

drivers/misc/rf/core/rfdev.c line 661

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +9 -0
+	u32	*buf;
+	u32 u32arg;
+	int rc = -ENOSYS, size;
+
+	rf_dev = filep->private_data;
+	phy = rf_dev->phy;
+
+	rc = mutex_lock_interruptible(&rf_dev->lock);
+	switch (cmd) {

If mutex_lock_interruptible() fails, you should not enter the function because you don't actually hold the mutex.

ok I will do that

Quoted 16 lines

include/uapi/linux/rfdev.h line 239

Quoted 12 lines
include/uapi/linux/rfdev.h new file +11 -0
+struct rif_phy_cmd {
+	__u32	param1;
+	__u32	param2;
+	__u32	param3;
+	__u8	cmd;
+};
+
+struct rif_phy_cmd_set {
+	struct rif_phy_cmd *cmds;
+	__u32 count;
+};

Please try to avoid ioctl structures with pointers in them, they are harder to parse from anything that needs to intercept the ioctl in user space, and they break 64 bit compatibility mode.

ok I will do that

Quoted 4 lines

You should also add padding in the first structure to ensure that the size is a multiple of the largest member. Otherwise you break e.g. ARM OABI support or anything else that has unconventional rules on the ABI.

ok i will do that

Quoted 13 lines

include/uapi/linux/rfdev.h line 260

Quoted 10 lines
include/uapi/linux/rfdev.h new file +9 -0
+struct time_sync_1588_cnt {
+	__u32 high;
+	__u32 low;
+};
+
+struct time_info {
+	struct time_sync_1588_cnt time_cnt;
+	__u8 event;
+};

Here too.

Quoted 11 lines

include/uapi/linux/rfdev.h line 276

Quoted 8 lines
include/uapi/linux/rfdev.h new file +8 -0
+struct time_sync_data {
+	struct time_info time_info;
+	__u32 lte_delay;
+	__u32 ioctl_cmd;
+	__u32 black_out_duration;
+	__u8 correction_mode;
+	__u8 sync_source;
+};

It definitely sounds like a bug to have a member named "ioctl_cmd" in a structure that is passed in an ioctl command.

Ok I will correct it.

Quoted 7 lines

include/uapi/linux/rfdev.h line 286

Quoted 5 lines
include/uapi/linux/rfdev.h new file +4 -0
+struct rif_dac_buf {
+	__u32 correction_type;
+	__u32 *buf;
+};

A pointer again.

ok i will correct it.

Quoted 25 lines
Quoted 25 lines
include/uapi/linux/rfdev.h new file +24 -0
+#define RF_MAGIC 0xEE
+#define RIF_DEV_INIT		_IOWR(RF_MAGIC, 1, struct rf_init_params)
+#define RIF_SET_TIMER_SOURCE	_IOW(RF_MAGIC, 2, unsigned int)
+#define RIF_GET_STATE		_IOR(RF_MAGIC, 3, unsigned int)
+#define RIF_SET_TIMER_CORRECTION _IOW(RF_MAGIC, 4, struct rif_dac_params)
+#define	RIF_RUN_PHY_CMDS	_IOW(RF_MAGIC, 5, struct rif_phy_cmd_set)
+#define RIF_READ_RSSI		_IOWR(RF_MAGIC, 6, struct rf_rssi)
+#define RIF_READ_PHY_REGS	_IOR(RF_MAGIC, 7, struct rif_reg_buf)
+#define RIF_READ_CTRL_REGS	_IOR(RF_MAGIC, 8, struct rif_reg_buf)
+#define RIF_START		_IO(RF_MAGIC, 9)
+#define RIF_STOP		_IO(RF_MAGIC, 10)
+#define RIF_GET_DEV_INFO	_IOWR(RF_MAGIC, 11, struct rf_dev_info)
+#define RIF_WRITE_PHY_REGS _IOR(RF_MAGIC, 12, struct rif_write_reg_buf)
+#define RIF_GET_DAC_VALUE	_IOR(RF_MAGIC, 13, struct rif_dac_buf)
+#define RIF_SET_TX_ATTEN	_IOW(RF_MAGIC, 14, struct rf_tx_buf)
+#define RIF_EN_DIS_TX		_IOW(RF_MAGIC, 15, struct rf_tx_en_dis)
+#define RIF_WRITE_CTRL_REGS 	_IOW(RF_MAGIC, 16, struct rif_write_reg_buf)
+#define RIF_READ_RX_GAIN 	_IOWR(RF_MAGIC, 17, struct rf_rx_gain)
+#define RIF_CONFIG_SNIFF 	_IOWR(RF_MAGIC, 18, struct rf_sniff_params)
+#define RIF_WRITE_RX_GAIN 	_IOW(RF_MAGIC, 19, struct rf_rx_gain)
+#define RIF_SET_GAIN_CTRL_MODE 	_IOW(RF_MAGIC, 20, struct rf_gain_ctrl)
+#define RIF_INIT_SYNTH_TABLE	_IOW(RF_MAGIC, 21, struct rf_synth_table)
+#define RIF_CHANNEL_OPEN	_IOW(RF_MAGIC, 22, struct rf_channel_params)
+#define RIF_CHANNEL_CLOSE	_IOW(RF_MAGIC, 23, unsigned int)
Quoted 9 lines

include/uapi/linux/rfdev.h line 390

Quoted 2 lines
include/uapi/linux/rfdev.h new file +2 -0
+#define RIF_REGISTER_EVENT	_IOW(RF_MAGIC, 24, struct rf_event_listener)
+#define RIF_UNREGISTER_EVENT	_IO(RF_MAGIC, 25)

On the whole, the ioctl API looks very complex to me. It may well be that the complexity is necessary, but I cannot tell because I don't understand the subsystem. Can you find someone from another company that has hardware which would use the same subsystem, and have them do a review of the API to ensure it works for them as well?

Antenna controller is a Freescale designed hardware block in the BSC9131 SOC. I am not aware of any other company which has similar kind of controller. I could not find any existing Antenna Controller Driver in kernel.

AD9361 RF PHY is being used by other companies also but again there is no open source driver for that.

This framework binds the Radio PHY and the Antenna Controller and expose the complete rf device(phy + controller) to the user space. Since I am not aware of other companies using similar hardware, I was hoping to get feedback about framework and APIs on the list itself.

Also I will try to explain more on the IOCTL APIs in the Documentation file that I have added in this patch.

-Akhil

maintainer
#17 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

Quoted 24 lines · Akhil Goyal
Quoted 15 lines · Arnd Bergmann
Quoted 15 lines
drivers/misc/rf/core/rfdev.c new file +15 -0
+	/*
+	 * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+	 * i.e they can sleep. This fact is problem for us because
+	 * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+	 * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+	 * called from rf_notify_dl_tti (which is called in interrupt context).
+	 * As a workaround, wait_q_lock is used for protecting the wait_q and
+	 * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+	 * are used.
+	 */
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__add_wait_queue_tail_exclusive(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+	set_current_state(TASK_INTERRUPTIBLE);
+	/*Now wait here, tti notificaion will wake us up*/
Quoted 8 lines

drivers/misc/rf/core/rfdev.c line 428

Quoted 5 lines
drivers/misc/rf/core/rfdev.c new file +5 -0
+	schedule();
+	set_current_state(TASK_RUNNING);
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__remove_wait_queue(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

Quoted 6 lines

wait_event() is internally calling spin_lock_irqsave() and this function will be called in hard IRQ context with PREEMPT_RT enabled(IRQF_NODELAY set). So wait_event cannot be used.
This problem can be solved if we can get the following patch applied on the tree.
https://patchwork.kernel.org/patch/2161261/

I see. How about using wait_event here then and adding a comment about the RT kernel?

Quoted 5 lines
Quoted 2 lines

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

The interrupt handler has real time requirement and thus running in HARDIRQ context with flag IRQF_NODELAY. We get this interrupt in every millisecond.

Ok. So there would be no problem without the RT patch set.

IRQF_NODELAY is specific to the RT kernel, so you can change the wait_event function to something else in the same patch that adds this flag.

Quoted 38 lines
Quoted 24 lines
Quoted 24 lines
include/uapi/linux/rfdev.h new file +24 -0
+#define RF_MAGIC 0xEE
+#define RIF_DEV_INIT		_IOWR(RF_MAGIC, 1, struct rf_init_params)
+#define RIF_SET_TIMER_SOURCE	_IOW(RF_MAGIC, 2, unsigned int)
+#define RIF_GET_STATE		_IOR(RF_MAGIC, 3, unsigned int)
+#define RIF_SET_TIMER_CORRECTION _IOW(RF_MAGIC, 4, struct rif_dac_params)
+#define	RIF_RUN_PHY_CMDS	_IOW(RF_MAGIC, 5, struct rif_phy_cmd_set)
+#define RIF_READ_RSSI		_IOWR(RF_MAGIC, 6, struct rf_rssi)
+#define RIF_READ_PHY_REGS	_IOR(RF_MAGIC, 7, struct rif_reg_buf)
+#define RIF_READ_CTRL_REGS	_IOR(RF_MAGIC, 8, struct rif_reg_buf)
+#define RIF_START		_IO(RF_MAGIC, 9)
+#define RIF_STOP		_IO(RF_MAGIC, 10)
+#define RIF_GET_DEV_INFO	_IOWR(RF_MAGIC, 11, struct rf_dev_info)
+#define RIF_WRITE_PHY_REGS _IOR(RF_MAGIC, 12, struct rif_write_reg_buf)
+#define RIF_GET_DAC_VALUE	_IOR(RF_MAGIC, 13, struct rif_dac_buf)
+#define RIF_SET_TX_ATTEN	_IOW(RF_MAGIC, 14, struct rf_tx_buf)
+#define RIF_EN_DIS_TX		_IOW(RF_MAGIC, 15, struct rf_tx_en_dis)
+#define RIF_WRITE_CTRL_REGS 	_IOW(RF_MAGIC, 16, struct rif_write_reg_buf)
+#define RIF_READ_RX_GAIN 	_IOWR(RF_MAGIC, 17, struct rf_rx_gain)
+#define RIF_CONFIG_SNIFF 	_IOWR(RF_MAGIC, 18, struct rf_sniff_params)
+#define RIF_WRITE_RX_GAIN 	_IOW(RF_MAGIC, 19, struct rf_rx_gain)
+#define RIF_SET_GAIN_CTRL_MODE 	_IOW(RF_MAGIC, 20, struct rf_gain_ctrl)
+#define RIF_INIT_SYNTH_TABLE	_IOW(RF_MAGIC, 21, struct rf_synth_table)
+#define RIF_CHANNEL_OPEN	_IOW(RF_MAGIC, 22, struct rf_channel_params)
+#define RIF_CHANNEL_CLOSE	_IOW(RF_MAGIC, 23, unsigned int)
Quoted 9 lines

include/uapi/linux/rfdev.h line 390

Quoted 2 lines
include/uapi/linux/rfdev.h new file +2 -0
+#define RIF_REGISTER_EVENT	_IOW(RF_MAGIC, 24, struct rf_event_listener)
+#define RIF_UNREGISTER_EVENT	_IO(RF_MAGIC, 25)

On the whole, the ioctl API looks very complex to me. It may well be that the complexity is necessary, but I cannot tell because I don't understand the subsystem. Can you find someone from another company that has hardware which would use the same subsystem, and have them do a review of the API to ensure it works for them as well?

Antenna controller is a Freescale designed hardware block in the BSC9131 SOC. I am not aware of any other company which has similar kind of controller. I could not find any existing Antenna Controller Driver in kernel.

Quoted 7 lines

AD9361 RF PHY is being used by other companies also but again there is no open source driver for that.

This framework binds the Radio PHY and the Antenna Controller and expose the complete rf device(phy + controller) to the user space. Since I am not aware of other companies using similar hardware, I was hoping to get feedback about framework and APIs on the list itself.

Ok. I hope you can find someone else to provide a review of the API.

Quoted 2 lines

Also I will try to explain more on the IOCTL APIs in the Documentation file that I have added in this patch.

Yes, that would be good.

Arnd

#18 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

Quoted 32 lines · Arnd Bergmann
Quoted 24 lines · Akhil Goyal
Quoted 15 lines · Arnd Bergmann
Quoted 15 lines
drivers/misc/rf/core/rfdev.c new file +15 -0
+	/*
+	 * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+	 * i.e they can sleep. This fact is problem for us because
+	 * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+	 * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+	 * called from rf_notify_dl_tti (which is called in interrupt context).
+	 * As a workaround, wait_q_lock is used for protecting the wait_q and
+	 * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+	 * are used.
+	 */
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__add_wait_queue_tail_exclusive(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+	set_current_state(TASK_INTERRUPTIBLE);
+	/*Now wait here, tti notificaion will wake us up*/
Quoted 8 lines

drivers/misc/rf/core/rfdev.c line 428

Quoted 5 lines
drivers/misc/rf/core/rfdev.c new file +5 -0
+	schedule();
+	set_current_state(TASK_RUNNING);
+	raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+	__remove_wait_queue(&rf_dev->wait_q,&wait);
+	raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

Quoted 6 lines

wait_event() is internally calling spin_lock_irqsave() and this function will be called in hard IRQ context with PREEMPT_RT enabled(IRQF_NODELAY set). So wait_event cannot be used.
This problem can be solved if we can get the following patch applied on the tree.
https://patchwork.kernel.org/patch/2161261/

Quoted 2 lines

I see. How about using wait_event here then and adding a comment about the RT kernel?

We can change it to wait_event but the problem is that, the ISR in Antenna Controller driver will always run in HARDIRQ context because of its latency requirements. In that case we will always get warning for "Trying to sleep in interrupt context".

Since we always require PREEMPT_RT patch while working with Antenna Controller Driver and there is no use case for running it in non-RT kernel. May be we can add dependency on CONFIG_PREEMPT_RT in the Kconfig of this framework/driver.

If the patch "Simple waitqueue implementation" from Steven Rostedt <[email protected]> gets mainlined then we can use simple wait queues to make a clean up here.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

The interrupt handler has real time requirement and thus running in HARDIRQ context with flag IRQF_NODELAY. We get this interrupt in every millisecond.

Ok. So there would be no problem without the RT patch set.

This driver always require PREEMPT_RT enabled. As mentioned above I can add dependency on CONFIG_PREEMPT_RT.

Quoted 3 lines

IRQF_NODELAY is specific to the RT kernel, so you can change the wait_event function to something else in the same patch that adds this flag.

#19 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

In reply to Akhil Goyal

On 06/18/2013 09:44 AM, Akhil Goyal wrote:
[...]

Quoted 31 lines
Quoted 21 lines
Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+    /*
+     * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+     * i.e they can sleep. This fact is problem for us because
+     * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+     * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+     * called from rf_notify_dl_tti (which is called in interrupt context).
+     * As a workaround, wait_q_lock is used for protecting the wait_q and
+     * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+     * are used.
+     */

drivers/misc/rf/core/rfdev.c line 428

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+    raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+    __add_wait_queue_tail_exclusive(&rf_dev->wait_q,&wait);
+    raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+    set_current_state(TASK_INTERRUPTIBLE);
+    /*Now wait here, tti notificaion will wake us up*/
+    schedule();
+    set_current_state(TASK_RUNNING);
+    raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+    __remove_wait_queue(&rf_dev->wait_q,&wait);
+    raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
Quoted 2 lines

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

wait_event() is internally calling spin_lock_irqsave() and this function will be called in hard IRQ context with PREEMPT_RT enabled(IRQF_NODELAY set). So wait_event cannot be used.
This problem can be solved if we can get the following patch applied on the tree.
https://patchwork.kernel.org/patch/2161261/

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

The interrupt handler has real time requirement and thus running in HARDIRQ context with flag IRQF_NODELAY. We get this interrupt in every millisecond.

But if you are running in HARDIRQ context the whole sequence doesn't make much sense at all, since you won't be able to sleep and wait for the event.

- Lars

#20 lore raw

Re: [PATCH 1/5] drivers/misc: Support for RF interface device framework

Quoted 33 lines · Lars-Peter Clausen

On 06/18/2013 09:44 AM, Akhil Goyal wrote:
[...]

Quoted 31 lines
Quoted 21 lines
Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+    /*
+     * Spin_locks are changed to mutexes if PREEMPT_RT is enabled,
+     * i.e they can sleep. This fact is problem for us because
+     * add_wait_queue()/wake_up_all() takes wait queue spin lock.
+     * Since spin lock can sleep with PREEMPT_RT, wake_up_all() can not be
+     * called from rf_notify_dl_tti (which is called in interrupt context).
+     * As a workaround, wait_q_lock is used for protecting the wait_q and
+     * add_wait_queue_locked()/ wake_up_locked() functions of wait queues
+     * are used.
+     */

drivers/misc/rf/core/rfdev.c line 428

Quoted 10 lines
drivers/misc/rf/core/rfdev.c new file +10 -0
+    raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+    __add_wait_queue_tail_exclusive(&rf_dev->wait_q,&wait);
+    raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
+    set_current_state(TASK_INTERRUPTIBLE);
+    /*Now wait here, tti notificaion will wake us up*/
+    schedule();
+    set_current_state(TASK_RUNNING);
+    raw_spin_lock_irqsave(&rf_dev->wait_q_lock, flags);
+    __remove_wait_queue(&rf_dev->wait_q,&wait);
+    raw_spin_unlock_irqrestore(&rf_dev->wait_q_lock, flags);
Quoted 2 lines

This is not a proper method of waiting for an event. Why can't you use wait_event() here?

wait_event() is internally calling spin_lock_irqsave() and this function will be called in hard IRQ context with PREEMPT_RT enabled(IRQF_NODELAY set). So wait_event cannot be used.
This problem can be solved if we can get the following patch applied on the tree.
https://patchwork.kernel.org/patch/2161261/

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The explanation about the interrupt handler seems incorrect, since PREEMPT_RT also turns interrupt handlers into threads.

The interrupt handler has real time requirement and thus running in HARDIRQ context with flag IRQF_NODELAY. We get this interrupt in every millisecond.

But if you are running in HARDIRQ context the whole sequence doesn't make much sense at all, since you won't be able to sleep and wait for the event.

This function for adding process to rf_dev->wait_q runs in process context, but the function (dl_notify_tti())which wakes process up from this queue runs in HARDIRQ context, that's why we could not use wait_event() or spin_lock() here.

thanks,
pankaj