Skip to contentSkip to conversation

dt-bindings: Add vendor prefix for Silvaco

PATCH Superseded Miquel Raynal 3 participants 10 messages Aug 12, 2020 – Dec 28, 2020

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Miquel Raynal

author maintainer
#0 lore raw

PATCH v2 1/4 dt-bindings: Add vendor prefix for Silvaco

Silvaco, Inc. is an EDA provider of software tools used for process and device development and for analog/mixed-signal, power IC and memory design [1].

[1] https://www.silvaco.com/company/profile/profile.html

---

Changes in v2:
* Change the prefix 'svc,' -> 'silvaco,'.

 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index f3d847832fdc..df780a2a5b78 100644
@@ -1014,6 +1014,8 @@ patternProperties:
     description: Shenzhen Sunchip Technology Co., Ltd
   "^SUNW,.*":
     description: Sun Microsystems, Inc
+  "^silvaco,.*":
+    description: Silvaco, Inc.
   "^swir,.*":
     description: Sierra Wireless
   "^syna,.*":
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH v2 2/4 dt-bindings: i3c: Describe Silvaco master binding

Silvaco provide a dual-role I3C master.

Description is rather simple: it needs a register mapping, three clocks and an interrupt.

---

Changes in v2:
* Updated Rob's tool and fixed the mistake reported.
* Updated the vendor prefix.

 .../bindings/i3c/silvaco,i3c-master.yaml      | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +59 -0
new file mode 100644
index 000000000000..63731e8a9068
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i3c/silvaco,i3c-master.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Silvaco I3C master
+
+maintainers:
+  - Conor Culhane <[email protected]>
+
+properties:
+  compatible:
+    const: silvaco,i3c-master
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    description: |
+      There are three clocks:
+        pclk:     System clock
+        fast_clk: Fast clock (for the bus)
+        slow_clk: Slow clock (for other events)
+
+    items:
+      - const: pclk
+      - const: fast_clk
+      - const: slow_clk
+
+  clocks:
+    minItems: 3
+    maxItems: 3
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+
+examples:
+  - |
+    i3c-master@a0000000 {
+        compatible = "silvaco,i3c-master";
+        clocks = <&zynqmp_clk 71>, <&fclk>, <&sclk>;
+        clock-names = "pclk", "fast_clk", "slow_clk";
+        interrupt-parent = <&gic>;
+        interrupts = <0 89 4>;
+        reg = <0xa0000000 0x1000>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+    };
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH v2 2/4] dt-bindings: i3c: Describe Silvaco master binding

Quoted 39 lines · Miquel Raynal

Silvaco provide a dual-role I3C master.

Description is rather simple: it needs a register mapping, three clocks and an interrupt.

---

Changes in v2:
* Updated Rob's tool and fixed the mistake reported.
* Updated the vendor prefix.

 .../bindings/i3c/silvaco,i3c-master.yaml      | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +17 -0
new file mode 100644
index 000000000000..63731e8a9068
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i3c/silvaco,i3c-master.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Silvaco I3C master
+
+maintainers:
+  - Conor Culhane <[email protected]>
+
+properties:
+  compatible:
+    const: silvaco,i3c-master
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml line 27

Quoted 10 lines
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +10 -0
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    description: |
+      There are three clocks:
+        pclk:     System clock
+        fast_clk: Fast clock (for the bus)
+        slow_clk: Slow clock (for other events)

You basically say this in the schema... If you want some description, do it in 'clocks':

clocks:
items:
- description: ...
- description: ...
- description: ...

Quoted 9 lines
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +9 -0
+
+    items:
+      - const: pclk
+      - const: fast_clk
+      - const: slow_clk
+
+  clocks:
+    minItems: 3
+    maxItems: 3

Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml line 46

Quoted 10 lines
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +10 -0
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks

additionalProperties: false

And that will point out some errors in the example.

Quoted 16 lines
Documentation/devicetree/bindings/i3c/silvaco,i3c-master.yaml new file +13 -0
+
+examples:
+  - |
+    i3c-master@a0000000 {
+        compatible = "silvaco,i3c-master";
+        clocks = <&zynqmp_clk 71>, <&fclk>, <&sclk>;
+        clock-names = "pclk", "fast_clk", "slow_clk";
+        interrupt-parent = <&gic>;
+        interrupts = <0 89 4>;
+        reg = <0xa0000000 0x1000>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+    };
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH v2 3/4 i3c: master: svc: Add Silvaco I3C master driver

In reply to Miquel Raynal

Add support for Silvaco I3C dual-role IP. The master role is supported in SDR mode only. I2C transfers have not been tested but are shared because they are so close to the I3C transfers in terms of registers configuration.

---

Changes in v2:
* Declared all the functions static (2 were missing).
* Catched errors reported by i3c_master_get_free_addr().
* Reworked the IBI handling to avoid sleeping.
* Updated the vendor prefix in the compatible and also use "silvaco" instead of "svc" in the driver's name.

 drivers/i3c/master/Kconfig          |    8 +
 drivers/i3c/master/Makefile         |    1 +
 drivers/i3c/master/svc-i3c-master.c | 1349 +++++++++++++++++++++++++++
 3 files changed, 1358 insertions(+)
 create mode 100644 drivers/i3c/master/svc-i3c-master.c
drivers/i3c/master/Kconfig +8 -0
index 4e80a1fcbf91..032b4de14277 100644
@@ -21,3 +21,11 @@ config DW_I3C_MASTER
 
 	  This driver can also be built as a module.  If so, the module
 	  will be called dw-i3c-master.
+
+config SVC_I3C_MASTER
+	tristate "Silvaco I3C Dual-Role Master driver"
+	depends on I3C
+	depends on HAS_IOMEM
+	depends on !(ALPHA || PARISC)
+	help
+	  Support for Silvaco I3C Dual-Role Master Controller.
drivers/i3c/master/Makefile +1 -0
index 7eea9e086144..69e5f5479df9 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_CDNS_I3C_MASTER)		+= i3c-master-cdns.o
 obj-$(CONFIG_DW_I3C_MASTER)		+= dw-i3c-master.o
+obj-$(CONFIG_SVC_I3C_MASTER)		+= svc-i3c-master.o
drivers/i3c/master/svc-i3c-master.c new file +1349 -0

1,349 lines not on this page · raw message

Signature · 1 line
2.20.1
author maintainer
#4 lore raw

Re: [PATCH v2 3/4] i3c: master: svc: Add Silvaco I3C master driver

Hi Conor, Rajeev,

Quoted 14 lines
drivers/i3c/master/svc-i3c-master.c new file +14 -0
+static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
+				     struct i3c_dev_desc *dev)
+{
+	struct svc_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
+	struct i3c_ibi_slot *slot;
+	unsigned int count;
+	u32 mdatactrl;
+	int ret = 0;
+	u8 *buf;
+
+	spin_lock(&master->ibi.lock);
+
+	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
+	if (!slot) {

drivers/i3c/master/svc-i3c-master.c line 265

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+		ret = -ENOSPC;
+		goto unlock;
+	}
+
+	slot->len = 0;
+	buf = slot->data;
+	while (readl(master->regs + SVC_I3C_MSTATUS) & SVC_I3C_MINT_RXPEND) {
+		mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);
+		count = SVC_I3C_MDATACTRL_RXCOUNT(mdatactrl);
+		readsl(master->regs + SVC_I3C_MRDATAB, buf, count);

After discussing with Boris, I have a question about the design: is there a way to differentiate, from a software point of view, from the data coming as "IBI" and "regular data"?

Let's say the master initiates a read.
The moment after, an IBI is triggered.
The hanlde_ibi() helper is called to read the IBI payload. While the IBI interrupted the read operation, it also interrupted the master dequeuing process of the bytes already in the FIFO. From a software perspective, we might end up reading a "regular byte" from the handle_ibi() helper expecting an "IBI byte".

Is there some kind of double queue feature which I missed? Or perhaps a way to discriminate the origin of the data?

Quoted 99 lines
drivers/i3c/master/svc-i3c-master.c new file +99 -0
+		slot->len += count;
+		buf += count;
+	}
+
+	i3c_master_queue_ibi(dev, slot);
+
+unlock:
+	spin_unlock(&master->ibi.lock);
+	svc_i3c_master_emit_stop(master);
+	svc_i3c_master_flush_fifo(master);
+
+	return ret;
+}
+
+static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+				   bool mandatory_byte)
+{
+	unsigned int ibi_ack_nack;
+
+	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
+	if (mandatory_byte)
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITH_BYTE;
+	else
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
+
+	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+}
+
+static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
+{
+	writel(SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK |
+	       SVC_I3C_MCTRL_IBIRESP_NACK,
+	       master->regs + SVC_I3C_MCTRL);
+}
+
+static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 active = readl(master->regs + SVC_I3C_MINTMASKED);
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);
+	unsigned int ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;
+	bool rdata;
+
+	if (active & SVC_I3C_MINT_SLVSTART) {
+		writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS);
+		writel(SVC_I3C_MCTRL_REQUEST_AUTO_IBI |
+		       SVC_I3C_MCTRL_IBIRESP_MANUAL,
+		       master->regs + SVC_I3C_MCTRL);
+		return IRQ_HANDLED;
+	}
+
+	if (!(active & SVC_I3C_MINT_IBIWON))
+		return IRQ_NONE;
+
+	writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+
+	switch (ibitype) {
+	case SVC_I3C_MSTATUS_IBITYPE_IBI:
+		dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+		if (WARN_ON(!dev)) {
+			svc_i3c_master_nack_ibi(master);
+			break;
+		}
+
+		rdata = dev->info.bcr & I3C_BCR_IBI_PAYLOAD;
+		svc_i3c_master_ack_ibi(master, rdata);
+		if (rdata) {
+			svc_i3c_master_disable_interrupts(master);
+			return IRQ_WAKE_THREAD;
+		}
+
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
+		svc_i3c_master_nack_ibi(master);
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
+		svc_i3c_master_ack_ibi(master, false);
+		queue_work(master->base.wq, &master->hj_work);
+		break;
+	default:
+		return IRQ_NONE;
+	}
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t svc_i3c_master_threaded_handler(int irq, void *dev_id)
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;
+
+	dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+	if (WARN_ON(!dev)) {
+		svc_i3c_master_emit_stop(master);
+		svc_i3c_master_flush_fifo(master);

drivers/i3c/master/svc-i3c-master.c line 374

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+		return IRQ_HANDLED;
+	}
+
+	svc_i3c_master_handle_ibi(master, dev);
+	svc_i3c_master_enable_interrupts(master,
+					 SVC_I3C_MINT_SLVSTART |
+					 SVC_I3C_MINT_IBIWON);
+
+	return IRQ_HANDLED;
+}

Thanks,
Miquèl

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#5 lore raw

Re: [PATCH v2 3/4] i3c: master: svc: Add Silvaco I3C master driver

In reply to Miquel Raynal
Quoted 153 lines · On Wed, 12 Aug 2020 16:13:11 +0200 Miquel Raynal <[email protected]>…
drivers/i3c/master/svc-i3c-master.c new file +153 -0
+
+#define SVC_I3C_MAX_DEVS 32
+
+struct svc_i3c_cmd {
+	u8 addr;
+	bool rnw;
+	u8 *in;
+	const void *out;
+	unsigned int len;
+	unsigned int read_len;
+	bool continued;
+};
+
+struct svc_i3c_xfer {
+	struct list_head node;
+	struct completion comp;
+	int ret;
+	unsigned int type;
+	unsigned int ncmds;
+	struct svc_i3c_cmd cmds[];
+};
+
+/**
+ * struct svc_i3c_master - Silvaco I3C Master structure
+ * @base: I3C master controller
+ * @dev: Corresponding device
+ * @regs: Memory mapping
+ * @free_slots: Bit array of available slots
+ * @addrs: Array containing the dynamic addresses of each attached device
+ * @descs: Array of descriptors, one per attached device
+ * @hj_work: Hot-join work
+ * @irq: Main interrupt
+ * @pclk: System clock
+ * @fclk: Fast clock (bus)
+ * @sclk: Slow clock (other events)
+ * @xferqueue: Transfer queue structure
+ * @xferqueue.list: List member
+ * @xferqueue.cur: Current ongoing transfer
+ * @xferqueue.lock: Queue lock
+ * @ibi: IBI structure
+ * @ibi.num_slots: Number of slots available in @ibi.slots
+ * @ibi.slots: Available IBI slots
+ * @ibi.lock: IBI lock
+ * @bus_lock: Bus lock
+ */
+struct svc_i3c_master {
+	struct i3c_master_controller base;
+	struct device *dev;
+	void __iomem *regs;
+	u32 free_slots;
+	u8 addrs[SVC_I3C_MAX_DEVS];
+	struct i3c_dev_desc *descs[SVC_I3C_MAX_DEVS];
+	struct work_struct hj_work;
+	int irq;
+	struct clk *pclk;
+	struct clk *fclk;
+	struct clk *sclk;
+	struct {
+		struct list_head list;
+		struct svc_i3c_xfer *cur;
+		/* Prevent races between transfers */
+		spinlock_t lock;
+	} xferqueue;
+	struct {
+		unsigned int num_slots;
+		struct i3c_dev_desc **slots;
+		/* Prevent races within IBI handlers */
+		spinlock_t lock;
+	} ibi;
+};
+
+/**
+ * struct svc_i3c_i3c_dev_data - Device specific data
+ * @index: Index in the master tables corresponding to this device
+ * @ibi: IBI slot index in the master structure
+ * @ibi_pool: IBI pool associated to this device
+ */
+struct svc_i3c_i2c_dev_data {
+	u8 index;
+	int ibi;
+	struct i3c_generic_ibi_pool *ibi_pool;
+};
+
+static void svc_i3c_master_enable_interrupts(struct svc_i3c_master *master, u32 mask)
+{
+	writel(mask, master->regs + SVC_I3C_MINTSET);
+}
+
+static void svc_i3c_master_disable_interrupts(struct svc_i3c_master *master)
+{
+	u32 mask = readl(master->regs + SVC_I3C_MINTSET);
+
+	writel(mask, master->regs + SVC_I3C_MINTCLR);
+}
+
+static inline struct svc_i3c_master *
+to_svc_i3c_master(struct i3c_master_controller *master)
+{
+	return container_of(master, struct svc_i3c_master, base);
+}
+
+static void svc_i3c_master_hj(struct work_struct *work)
+{
+	struct svc_i3c_master *master;
+
+	master = container_of(work, struct svc_i3c_master, hj_work);
+	i3c_master_do_daa(&master->base);
+}
+
+static void svc_i3c_master_flush_fifo(struct svc_i3c_master *master)
+{
+	writel(SVC_I3C_MDATACTRL_FLUSHTB | SVC_I3C_MDATACTRL_FLUSHRB,
+	       master->regs + SVC_I3C_MDATACTRL);
+}
+
+static struct i3c_dev_desc *
+svc_i3c_master_dev_from_addr(struct svc_i3c_master *master,
+			     unsigned int ibiaddr)
+{
+	int i;
+
+	for (i = 0; i < SVC_I3C_MAX_DEVS; i++)
+		if (master->addrs[i] == ibiaddr)
+			break;
+
+	if (i == SVC_I3C_MAX_DEVS)
+		return NULL;
+
+	return master->descs[i];
+}
+
+static void svc_i3c_master_emit_stop(struct svc_i3c_master *master)
+{
+	writel(SVC_I3C_MCTRL_REQUEST_STOP, master->regs + SVC_I3C_MCTRL);
+}
+
+static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
+				     struct i3c_dev_desc *dev)
+{
+	struct svc_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
+	struct i3c_ibi_slot *slot;
+	unsigned int count;
+	u32 mdatactrl;
+	int ret = 0;
+	u8 *buf;
+
+	spin_lock(&master->ibi.lock);
+
+	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
+	if (!slot) {
+		ret = -ENOSPC;
+		goto unlock;
+	}

drivers/i3c/master/svc-i3c-master.c line 268

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+
+	slot->len = 0;
+	buf = slot->data;
+	while (readl(master->regs + SVC_I3C_MSTATUS) & SVC_I3C_MINT_RXPEND) {
+		mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);
+		count = SVC_I3C_MDATACTRL_RXCOUNT(mdatactrl);
+		readsl(master->regs + SVC_I3C_MRDATAB, buf, count);
+		slot->len += count;
+		buf += count;
+	}

I don't think the while loop and i3c_generic_ibi_get_free_slot() call have to be protected by the ibi lock (having an unbounded while loop in a critical section makes me nervous).

We also discussed the race you have because IBIs and regular transfers share the same RX FIFO, which you mentioned in your previous reply already.

drivers/i3c/master/svc-i3c-master.c line 275

Quoted 7 lines
drivers/i3c/master/svc-i3c-master.c new file +7 -0
+
+	i3c_master_queue_ibi(dev, slot);
+
+unlock:
+	spin_unlock(&master->ibi.lock);
+	svc_i3c_master_emit_stop(master);
+	svc_i3c_master_flush_fifo(master);

Flush FIFOs? Does it flush all remaining bytes present in the RX/TX FIFOs? Are you sure that's appropriate?

drivers/i3c/master/svc-i3c-master.c line 287

Quoted 12 lines
drivers/i3c/master/svc-i3c-master.c new file +12 -0
+
+	return ret;
+}
+
+static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+				   bool mandatory_byte)
+{
+	unsigned int ibi_ack_nack;
+
+	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
+	if (mandatory_byte)
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITH_BYTE;

IIRC, some devices send more than one byte, does that mean you don't support those?

Quoted 18 lines
drivers/i3c/master/svc-i3c-master.c new file +18 -0
+	else
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
+
+	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+}
+
+static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
+{
+	writel(SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK |
+	       SVC_I3C_MCTRL_IBIRESP_NACK,
+	       master->regs + SVC_I3C_MCTRL);
+}
+
+static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 active = readl(master->regs + SVC_I3C_MINTMASKED);
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);

drivers/i3c/master/svc-i3c-master.c line 315

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+	unsigned int ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;
+	bool rdata;
+
+	if (active & SVC_I3C_MINT_SLVSTART) {
+		writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS);
+		writel(SVC_I3C_MCTRL_REQUEST_AUTO_IBI |
+		       SVC_I3C_MCTRL_IBIRESP_MANUAL,
+		       master->regs + SVC_I3C_MCTRL);

I would expect some kind of auto-ack/nack mechanism. Not sure what happens when you do it manually, but if that blocks the bus waiting for the interrupt handler to tell the I3C master what to do with IBI, that's far from ideal.

drivers/i3c/master/svc-i3c-master.c line 327

Quoted 12 lines
drivers/i3c/master/svc-i3c-master.c new file +12 -0
+		return IRQ_HANDLED;
+	}
+
+	if (!(active & SVC_I3C_MINT_IBIWON))
+		return IRQ_NONE;
+
+	writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+
+	switch (ibitype) {
+	case SVC_I3C_MSTATUS_IBITYPE_IBI:
+		dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+		if (WARN_ON(!dev)) {

I wouldn't WARN_ON() that. I wouldn't be surprised if some slaves send IBIs without being allowed, and you're in an interrupt context. This being said, you should probably trigger a DISEC on this device when that happens.

Quoted 22 lines
drivers/i3c/master/svc-i3c-master.c new file +22 -0
+			svc_i3c_master_nack_ibi(master);
+			break;
+		}
+
+		rdata = dev->info.bcr & I3C_BCR_IBI_PAYLOAD;
+		svc_i3c_master_ack_ibi(master, rdata);
+		if (rdata) {
+			svc_i3c_master_disable_interrupts(master);
+			return IRQ_WAKE_THREAD;
+		}
+
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
+		svc_i3c_master_nack_ibi(master);
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
+		svc_i3c_master_ack_ibi(master, false);
+		queue_work(master->base.wq, &master->hj_work);
+		break;
+	default:
+		return IRQ_NONE;
+	}

drivers/i3c/master/svc-i3c-master.c line 359

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t svc_i3c_master_threaded_handler(int irq, void *dev_id)
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;

Do you really need a threaded irq? We already have a workqueue per master, maybe you can use it to schedule the IBI dequeuing?

Quoted 121 lines
drivers/i3c/master/svc-i3c-master.c new file +119 -0
+
+	dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+	if (WARN_ON(!dev)) {
+		svc_i3c_master_emit_stop(master);
+		svc_i3c_master_flush_fifo(master);
+		return IRQ_HANDLED;
+	}
+
+	svc_i3c_master_handle_ibi(master, dev);
+	svc_i3c_master_enable_interrupts(master,
+					 SVC_I3C_MINT_SLVSTART |
+					 SVC_I3C_MINT_IBIWON);
+
+	return IRQ_HANDLED;
+}
+
 
 
+
+static int svc_i3c_master_attach_i3c_dev(struct i3c_dev_desc *dev)
+{
+	struct i3c_master_controller *m = i3c_dev_get_master(dev);
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+	struct svc_i3c_i2c_dev_data *data;
+	int slot;
+
+	slot = svc_i3c_master_reserve_slot(master);
+	if (slot < 0)
+		return slot;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		svc_i3c_master_release_slot(master, slot);
+		return -ENOMEM;
+	}
+
+	data->ibi = -1;
+	data->index = slot;
+	master->addrs[slot] = dev->info.dyn_addr ? dev->info.dyn_addr :
+						   dev->info.static_addr;
+	master->descs[slot] = dev;
+
+	i3c_dev_set_master_data(dev, data);
+
+	return 0;
+}
+
+static int svc_i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,
+					   u8 old_dyn_addr)
+{
+	struct i3c_master_controller *m = i3c_dev_get_master(dev);
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+	struct svc_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
+
+	master->addrs[data->index] = dev->info.dyn_addr ? dev->info.dyn_addr :
+							  dev->info.static_addr;
+
+	return 0;
+}
+
+static void svc_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev)
+{
+	struct svc_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
+	struct i3c_master_controller *m = i3c_dev_get_master(dev);
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+
+	svc_i3c_master_release_slot(master, data->index);
+
+	kfree(data);
+}
+
+static int svc_i3c_master_attach_i2c_dev(struct i2c_dev_desc *dev)
+{
+	struct i3c_master_controller *m = i2c_dev_get_master(dev);
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+	struct svc_i3c_i2c_dev_data *data;
+	int slot;
+
+	slot = svc_i3c_master_reserve_slot(master);
+	if (slot < 0)
+		return slot;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		svc_i3c_master_release_slot(master, slot);
+		return -ENOMEM;
+	}
+
+	data->index = slot;
+	master->addrs[slot] = dev->addr;
+
+	i2c_dev_set_master_data(dev, data);
+
+	return 0;
+}
+
+static void svc_i3c_master_detach_i2c_dev(struct i2c_dev_desc *dev)
+{
+	struct svc_i3c_i2c_dev_data *data = i2c_dev_get_master_data(dev);
+	struct i3c_master_controller *m = i2c_dev_get_master(dev);
+	struct svc_i3c_master *master = to_svc_i3c_master(m);
+
+	svc_i3c_master_release_slot(master, data->index);
+
+	kfree(data);
+}
+
+static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
+					u8 *addrs, unsigned int *count)
+{
+	u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0;
+	unsigned int dev_nb = 0, last_addr = 0;
+	u32 reg;
+	int ret, i;
+
+	while (true) {
+		/* Enter/proceed with DAA */
+		writel(SVC_I3C_MCTRL_REQUEST_PROC_DAA |
+		       SVC_I3C_MCTRL_TYPE_I3C |
+		       SVC_I3C_MCTRL_IBIRESP_MANUAL |
+		       SVC_I3C_MCTRL_DIR(SVC_I3C_MCTRL_DIR_WRITE),

drivers/i3c/master/svc-i3c-master.c line 607

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+		       master->regs + SVC_I3C_MCTRL);
+
+		/*
+		 * Either one slave will send its ID, or the assignment process
+		 * is done.
+		 */
+		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
+					 reg & (SVC_I3C_MINT_RXPEND |
+						SVC_I3C_MINT_MCTRLDONE),
+					 1, 1000);

No interrupt for the DAA? I'm also curious about the RX FIFO size. Looks like PIDs/BCRs/DCRs of attached devices go there. What happens if it exceeds the size of the FIFO and you're not dequeuing things fast enough?

Quoted 11 lines
drivers/i3c/master/svc-i3c-master.c new file +11 -0
+		if (ret)
+			return ret;
+
+		if (reg & SVC_I3C_MINT_RXPEND) {
+			u8 datab;
+
+			/*
+			 * We only care about the 48-bit provisional ID yet to
+			 * be sure a device does not nack an address twice.
+			 * Otherwise, we would just need to flush the RX FIFO.
+			 */

drivers/i3c/master/svc-i3c-master.c line 628

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+			for (i = 0; i < 6; i++) {
+				ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS,
+							 reg,
+							 reg & SVC_I3C_MINT_RXPEND,
+							 0, 1000);
+				if (ret)
+					return ret;
+
+				datab = readl(master->regs + SVC_I3C_MRDATAB);
+				prov_id[dev_nb] |= (u64)(datab) << (8 * (5 - i));

This calls for an svc_i3c_read_bytes() helper.

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c new file +4 -0
+			}
+
+			/* We do not care about the BCR and DCR yet */
+			for (i = 0; i < 2; i++) {

drivers/i3c/master/svc-i3c-master.c line 642

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+				ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS,
+							 reg,
+							 reg & SVC_I3C_MINT_RXPEND,
+							 0, 1000);
+				if (ret)
+					return ret;
+
+				reg = readl(master->regs + SVC_I3C_MRDATAB);
+			}
+		} else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) {

Can't you have both SVC_I3C_MSTATUS_MCTRLDONE and SVC_I3C_MINT_RXPEND? BTW, can we make the bit definitions consistent. You sometimes have:

#define FOO(x) FIELD_GET(BIT(n), (x))

and sometimes

#define BAR BIT(n)

which leads to inconsistencies in how you test presence of those bits:

'if (FOO(reg))' vs 'if (reg & BAR)'.

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c new file +6 -0
+			if (SVC_I3C_MSTATUS_STATE_IDLE(reg) &&
+			    SVC_I3C_MSTATUS_COMPLETE(reg)) {
+				/*
+				 * All devices received and acked they dynamic
+				 * address, this is the natural end of the DAA
+				 * procedure.

drivers/i3c/master/svc-i3c-master.c line 658

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+				 */
+				break;
+			} else if (SVC_I3C_MSTATUS_NACKED(reg)) {
+				/*
+				 * A slave device nacked the address, this is
+				 * allowed only once, DAA will be stopped and
+				 * then resumed. The same device is supposed to
+				 * answer again immediately and shall ack the
+				 * address this time.
+				 */

I couldn't find where this is described in v1 of the spec. All I see is:

"
The Arbitration-winning Device shall acknowledge the assigned Dynamic Address
"

Quoted 37 lines
drivers/i3c/master/svc-i3c-master.c new file +37 -0
+				if (prov_id[dev_nb] == nacking_prov_id)
+					return -EIO;
+
+				dev_nb--;
+				nacking_prov_id = prov_id[dev_nb];
+				svc_i3c_master_emit_stop(master);
+
+				continue;
+			} else {
+				return -EIO;
+			}
+		}
+
+		/* Wait for the slave to be ready to receive its address */
+		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
+					 SVC_I3C_MSTATUS_MCTRLDONE(reg) &&
+					 SVC_I3C_MSTATUS_STATE_DAA(reg) &&
+					 SVC_I3C_MSTATUS_BETWEEN(reg),
+					 0, 1000);
+		if (ret)
+			return ret;
+
+		/* Give the slave device a suitable dynamic address */
+		ret = i3c_master_get_free_addr(&master->base, last_addr + 1);
+		if (ret < 0)
+			return ret;
+
+		addrs[dev_nb] = ret;
+
+		writel(addrs[dev_nb], master->regs + SVC_I3C_MWDATAB);
+		last_addr = addrs[dev_nb++];
+	}
+
+	*count = dev_nb;
+
+	return 0;
+}
author maintainer
#6 lore raw

Re: [PATCH v2 3/4] i3c: master: svc: Add Silvaco I3C master driver

Hi Boris,

It's been quite some time since you made this review, but now that I am ready to send a new version, I think it is useful to answer your questions and remarks below which I pretty much all addressed with significant changes.

Also adding Alexandre so he can smoothly get into this driver :)

Quoted 23 lines
Quoted 23 lines
drivers/i3c/master/svc-i3c-master.c new file +23 -0
+static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
+				     struct i3c_dev_desc *dev)
+{
+	struct svc_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
+	struct i3c_ibi_slot *slot;
+	unsigned int count;
+	u32 mdatactrl;
+	int ret = 0;
+	u8 *buf;
+
+	spin_lock(&master->ibi.lock);
+
+	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
+	if (!slot) {
+		ret = -ENOSPC;
+		goto unlock;
+	}
+
+	slot->len = 0;
+	buf = slot->data;
+	while (readl(master->regs + SVC_I3C_MSTATUS) & SVC_I3C_MINT_RXPEND) {
+		mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);
+		count = SVC_I3C_MDATACTRL_RXCOUNT(mdatactrl);
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 268

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c new file +4 -0
+		readsl(master->regs + SVC_I3C_MRDATAB, buf, count);
+		slot->len += count;
+		buf += count;
+	}  

I don't think the while loop and i3c_generic_ibi_get_free_slot() call have to be protected by the ibi lock (having an unbounded while loop in a critical section makes me nervous).

Dropped indeed, I don't think it is needed as well.

Quoted 3 lines

We also discussed the race you have because IBIs and regular transfers share the same RX FIFO, which you mentioned in your previous reply already.

I addressed this issue by automatically nacking IBIs happening during transfers (hardware feature).

Quoted 10 lines

drivers/i3c/master/svc-i3c-master.c line 275

Quoted 7 lines
drivers/i3c/master/svc-i3c-master.c new file +7 -0
+
+	i3c_master_queue_ibi(dev, slot);
+
+unlock:
+	spin_unlock(&master->ibi.lock);
+	svc_i3c_master_emit_stop(master);
+	svc_i3c_master_flush_fifo(master);  

Flush FIFOs? Does it flush all remaining bytes present in the RX/TX FIFOs? Are you sure that's appropriate?

Indeed this is not appropriate and has been dropped.

Quoted 8 lines
Quoted 8 lines
drivers/i3c/master/svc-i3c-master.c new file +8 -0
+
+	return ret;
+}
+
+static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+				   bool mandatory_byte)
+{
+	unsigned int ibi_ack_nack;
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 287

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c new file +4 -0
+
+	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
+	if (mandatory_byte)
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITH_BYTE;  

IIRC, some devices send more than one byte, does that mean you don't support those?

The dequeuing mechanism is able to read up to 16 bytes (FIFO size), it should not be a problem.

Quoted 25 lines
Quoted 25 lines
drivers/i3c/master/svc-i3c-master.c new file +25 -0
+	else
+		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
+
+	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+}
+
+static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
+{
+	writel(SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK |
+	       SVC_I3C_MCTRL_IBIRESP_NACK,
+	       master->regs + SVC_I3C_MCTRL);
+}
+
+static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 active = readl(master->regs + SVC_I3C_MINTMASKED);
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);
+	unsigned int ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;
+	bool rdata;
+
+	if (active & SVC_I3C_MINT_SLVSTART) {
+		writel(SVC_I3C_MINT_SLVSTART, master->regs + SVC_I3C_MSTATUS);
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 315

Quoted 3 lines
drivers/i3c/master/svc-i3c-master.c new file +3 -0
+		writel(SVC_I3C_MCTRL_REQUEST_AUTO_IBI |
+		       SVC_I3C_MCTRL_IBIRESP_MANUAL,
+		       master->regs + SVC_I3C_MCTRL);  

I would expect some kind of auto-ack/nack mechanism. Not sure what happens when you do it manually, but if that blocks the bus waiting for the interrupt handler to tell the I3C master what to do with IBI, that's far from ideal.

After discussing with people who designed the IP, they told me that the time between SDA being pulled low to interrupt the master and the master responding is unbounded. What is critical is the handling of the interrupt once the master authorized the interrupt. I entirely reworked the IRQ handling for that in v3.

Quoted 9 lines
Quoted 9 lines
drivers/i3c/master/svc-i3c-master.c new file +9 -0
+		return IRQ_HANDLED;
+	}
+
+	if (!(active & SVC_I3C_MINT_IBIWON))
+		return IRQ_NONE;
+
+	writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+
+	switch (ibitype) {
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 327

Quoted 3 lines
drivers/i3c/master/svc-i3c-master.c new file +3 -0
+	case SVC_I3C_MSTATUS_IBITYPE_IBI:
+		dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+		if (WARN_ON(!dev)) {  

I wouldn't WARN_ON() that. I wouldn't be surprised if some slaves send IBIs without being allowed, and you're in an interrupt context. This being said, you should probably trigger a DISEC on this device when that happens.

I dropped the warning, however the point of warning here is that I cannot identify the device, hence I cannot disable the event calls coming from this device :)

Quoted 27 lines
Quoted 27 lines
drivers/i3c/master/svc-i3c-master.c new file +27 -0
+			svc_i3c_master_nack_ibi(master);
+			break;
+		}
+
+		rdata = dev->info.bcr & I3C_BCR_IBI_PAYLOAD;
+		svc_i3c_master_ack_ibi(master, rdata);
+		if (rdata) {
+			svc_i3c_master_disable_interrupts(master);
+			return IRQ_WAKE_THREAD;
+		}
+
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
+		svc_i3c_master_nack_ibi(master);
+		break;
+	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
+		svc_i3c_master_ack_ibi(master, false);
+		queue_work(master->base.wq, &master->hj_work);
+		break;
+	default:
+		return IRQ_NONE;
+	}
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t svc_i3c_master_threaded_handler(int irq, void *dev_id)
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 308

Quoted 5 lines
drivers/i3c/master/svc-i3c-master.c new file +5 -0
+{
+	struct svc_i3c_master *master = (struct svc_i3c_master *)dev_id;
+	u32 status = readl(master->regs + SVC_I3C_MSTATUS);
+	unsigned int ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
+	struct i3c_dev_desc *dev;  

Do you really need a threaded irq? We already have a workqueue per master, maybe you can use it to schedule the IBI dequeuing?

Right, I moved the code to an "IBI work" over the master's workqueue.

Quoted 16 lines
Quoted 16 lines
drivers/i3c/master/svc-i3c-master.c new file +16 -0
+
+	dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
+	if (WARN_ON(!dev)) {
+		svc_i3c_master_emit_stop(master);
+		svc_i3c_master_flush_fifo(master);
+		return IRQ_HANDLED;
+	}
+
+	svc_i3c_master_handle_ibi(master, dev);
+	svc_i3c_master_enable_interrupts(master,
+					 SVC_I3C_MINT_SLVSTART |
+					 SVC_I3C_MINT_IBIWON);
+
+	return IRQ_HANDLED;
+}
+  

[...]

Quoted 1 line
Quoted 1 line

+static int svc_i3c_master_do_daa_locked(struct svc_i3c_master

*master,

Quoted 20 lines
Quoted 20 lines
drivers/i3c/master/svc-i3c-master.c new file +20 -0
+					u8 *addrs, unsigned int *count)
+{
+	u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0;
+	unsigned int dev_nb = 0, last_addr = 0;
+	u32 reg;
+	int ret, i;
+
+	while (true) {
+		/* Enter/proceed with DAA */
+		writel(SVC_I3C_MCTRL_REQUEST_PROC_DAA |
+		       SVC_I3C_MCTRL_TYPE_I3C |
+		       SVC_I3C_MCTRL_IBIRESP_MANUAL |
+		       SVC_I3C_MCTRL_DIR(SVC_I3C_MCTRL_DIR_WRITE),
+		       master->regs + SVC_I3C_MCTRL);
+
+		/*
+		 * Either one slave will send its ID, or the assignment process
+		 * is done.
+		 */
+		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 607

Quoted 3 lines
drivers/i3c/master/svc-i3c-master.c new file +3 -0
+					 reg & (SVC_I3C_MINT_RXPEND |
+						SVC_I3C_MINT_MCTRLDONE),
+					 1, 1000);  

No interrupt for the DAA? I'm also curious about the RX FIFO size. Looks like PIDs/BCRs/DCRs of attached devices go there. What happens if it exceeds the size of the FIFO and you're not dequeuing things fast enough?

Interrupts are available but for clarity reasons (the current handler is already very complicated to avoid any races and prevent misreads or endless loops) I decided to keep using polling here. I guess it does not hurt anyway.

About the FIFO size, it is 16 bytes, so it is pretty safe for this kind of operation.

Quoted 15 lines
Quoted 15 lines
drivers/i3c/master/svc-i3c-master.c new file +15 -0
+		if (ret)
+			return ret;
+
+		if (reg & SVC_I3C_MINT_RXPEND) {
+			u8 datab;
+
+			/*
+			 * We only care about the 48-bit provisional ID yet to
+			 * be sure a device does not nack an address twice.
+			 * Otherwise, we would just need to flush the RX FIFO.
+			 */
+			for (i = 0; i < 6; i++) {
+				ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS,
+							 reg,
+							 reg & SVC_I3C_MINT_RXPEND,
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 628

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c new file +6 -0
+							 0, 1000);
+				if (ret)
+					return ret;
+
+				datab = readl(master->regs + SVC_I3C_MRDATAB);
+				prov_id[dev_nb] |= (u64)(datab) << (8 * (5 - i));  

This calls for an svc_i3c_read_bytes() helper.

Done.

Quoted 17 lines
Quoted 5 lines
drivers/i3c/master/svc-i3c-master.c new file +4 -0
+			}
+
+			/* We do not care about the BCR and DCR yet */
+			for (i = 0; i < 2; i++) {

drivers/i3c/master/svc-i3c-master.c line 642

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+				ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS,
+							 reg,
+							 reg & SVC_I3C_MINT_RXPEND,
+							 0, 1000);
+				if (ret)
+					return ret;
+
+				reg = readl(master->regs + SVC_I3C_MRDATAB);
+			}
+		} else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) {  

Can't you have both SVC_I3C_MSTATUS_MCTRLDONE and SVC_I3C_MINT_RXPEND?

If we have MCTRLDONE it means there is nothing left to read, so RXPEND cannot be also set.

Quoted 11 lines

BTW, can we make the bit definitions consistent. You sometimes have:

#define FOO(x) FIELD_GET(BIT(n), (x))

and sometimes

#define BAR BIT(n)

which leads to inconsistencies in how you test presence of those bits:

'if (FOO(reg))' vs 'if (reg & BAR)'.

Done.

Quoted 20 lines
Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c new file +6 -0
+			if (SVC_I3C_MSTATUS_STATE_IDLE(reg) &&
+			    SVC_I3C_MSTATUS_COMPLETE(reg)) {
+				/*
+				 * All devices received and acked they dynamic
+				 * address, this is the natural end of the DAA
+				 * procedure.

drivers/i3c/master/svc-i3c-master.c line 658

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c new file +10 -0
+				 */
+				break;
+			} else if (SVC_I3C_MSTATUS_NACKED(reg)) {
+				/*
+				 * A slave device nacked the address, this is
+				 * allowed only once, DAA will be stopped and
+				 * then resumed. The same device is supposed to
+				 * answer again immediately and shall ack the
+				 * address this time.
+				 */  

I couldn't find where this is described in v1 of the spec. All I see is:

Quoted 4 lines

"
The Arbitration-winning Device shall acknowledge the assigned Dynamic Address
"

I was told to do it this way, and got the following snippet from the I3C v1 spec:

"
If a given Slave does not acknowledge its assigned Dynamic Address, then the procedure requires the Main Master to continue from step 4 [sending the broadcast address and iterating again]. The Slave will then participate in the Address Arbitration using the same 48-bit Provisional ID, and as a result the Slave will win the Arbitration round. If the Slave does not ACK the Dynamic Address a second time, then the Main Master shall exit the Dynamic Address Assignment procedure and execute an error management procedure provided by the I3C Bus designer.
"

Quoted 39 lines
Quoted 39 lines
(quoted diff) +1 -0
+				if (prov_id[dev_nb] ==

nacking_prov_id)

drivers/i3c/master/svc-i3c-master.c new file +13 -0
+					return -EIO;
+
+				dev_nb--;
+				nacking_prov_id = prov_id[dev_nb];
+				svc_i3c_master_emit_stop(master);
+
+				continue;
+			} else {
+				return -EIO;
+			}
+		}
+
+		/* Wait for the slave to be ready to receive its

address */

(quoted diff) +1 -0
+		ret = readl_poll_timeout(master->regs +

SVC_I3C_MSTATUS, reg,
+
SVC_I3C_MSTATUS_MCTRLDONE(reg) &&
+
SVC_I3C_MSTATUS_STATE_DAA(reg) &&
+
SVC_I3C_MSTATUS_BETWEEN(reg),

drivers/i3c/master/svc-i3c-master.c new file +5 -0
+					 0, 1000);
+		if (ret)
+			return ret;
+
+		/* Give the slave device a suitable dynamic

address */

(quoted diff) +1 -0
+		ret = i3c_master_get_free_addr(&master->base,

last_addr + 1);

drivers/i3c/master/svc-i3c-master.c new file +6 -0
+		if (ret < 0)
+			return ret;
+
+		addrs[dev_nb] = ret;
+
+		writel(addrs[dev_nb], master->regs +
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c line 695

Quoted 8 lines

SVC_I3C_MWDATAB);

drivers/i3c/master/svc-i3c-master.c new file +7 -0
+		last_addr = addrs[dev_nb++];
+	}
+
+	*count = dev_nb;
+
+	return 0;
+}  

Thanks for the review :)

Miquèl

Signature · 3 lines
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
author maintainer
#7 lore raw

PATCH v2 4/4 MAINTAINERS: Add Silvaco I3C master

In reply to Miquel Raynal

Add Conor and myself as maintainers.

---

Changes in v2:
* None.

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index e627ed60d75a..fedd10537723 100644
@@ -15764,6 +15764,14 @@ S:	Maintained
 F:	Documentation/fb/sm712fb.rst
 F:	drivers/video/fbdev/sm712*
 
+SILVACO I3C DUAL-ROLE MASTER
+M:	Miquel Raynal <[email protected]>
+M:	Conor Culhane <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/i3c/svc,i3c-master.yaml
+F:	drivers/i3c/master/svc-i3c-master.c
+
 SIMPLE FIRMWARE INTERFACE (SFI)
 S:	Obsolete
 W:	http://simplefirmware.org/
Signature · 1 line
2.20.1
author maintainer
#8 lore raw

Re: [PATCH v2 4/4] MAINTAINERS: Add Silvaco I3C master

Hello,

Miquel Raynal <[email protected]> wrote on Wed, 12 Aug 2020 16:13:12 +0200:

Quoted 16 lines

Add Conor and myself as maintainers.

---

Changes in v2:
* None.

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +0 -0
index e627ed60d75a..fedd10537723 100644

MAINTAINERS S: Maintained · line 15772

Quoted 9 lines
MAINTAINERS +6 -0
@@ -15764,6 +15764,14 @@ S:	Maintained
 F:	Documentation/fb/sm712fb.rst
 F:	drivers/video/fbdev/sm712*
 
+SILVACO I3C DUAL-ROLE MASTER
+M:	Miquel Raynal <[email protected]>
+M:	Conor Culhane <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/i3c/svc,i3c-master.yaml

Should be silvaco,i3c-master.yaml...

I'll correct in v3.

Thanks,
Miquèl

maintainer Acked-by on v2 1/4
#9 lore raw
In reply to Miquel Raynal
Quoted 6 lines · Miquel Raynal

Silvaco, Inc. is an EDA provider of software tools used for process and device development and for analog/mixed-signal, power IC and memory design [1].

[1] https://www.silvaco.com/company/profile/profile.html

Quoted 9 lines

---

Changes in v2:
* Change the prefix 'svc,' -> 'silvaco,'.

 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)