i3c: master: svc: fix probe failure when no i3c device exist
authorFrank Li <Frank.Li@nxp.com>
Thu, 31 Aug 2023 14:13:24 +0000 (10:13 -0400)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 5 Sep 2023 23:21:47 +0000 (01:21 +0200)
I3C masters are expected to support hot-join. This means at initialization
time we might not yet discover any device and this should not be treated
as a fatal error.

During the DAA procedure which happens at probe time, if no device has
joined, all CCC will be NACKed (from a bus perspective). This leads to an
early return with an error code which fails the probe of the master.

Let's avoid this by just telling the core through an I3C_ERROR_M2
return command code that no device was discovered, which is a valid
situation. This way the master will no longer bail out and fail to probe
for a wrong reason.

Cc: stable@vger.kernel.org
Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230831141324.2841525-1-Frank.Li@nxp.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/i3c/master/svc-i3c-master.c

index 17b4ce1..8f8295a 100644 (file)
@@ -790,6 +790,10 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
                                 */
                                break;
                        } else if (SVC_I3C_MSTATUS_NACKED(reg)) {
+                               /* No I3C devices attached */
+                               if (dev_nb == 0)
+                                       break;
+
                                /*
                                 * A slave device nacked the address, this is
                                 * allowed only once, DAA will be stopped and
@@ -1264,11 +1268,17 @@ static int svc_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
 {
        struct svc_i3c_master *master = to_svc_i3c_master(m);
        bool broadcast = cmd->id < 0x80;
+       int ret;
 
        if (broadcast)
-               return svc_i3c_master_send_bdcast_ccc_cmd(master, cmd);
+               ret = svc_i3c_master_send_bdcast_ccc_cmd(master, cmd);
        else
-               return svc_i3c_master_send_direct_ccc_cmd(master, cmd);
+               ret = svc_i3c_master_send_direct_ccc_cmd(master, cmd);
+
+       if (ret)
+               cmd->err = I3C_ERROR_M2;
+
+       return ret;
 }
 
 static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev,