@@ -758,6 +758,32 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
758758
759759static DEVICE_ATTR_RW (dev_nack_retry_count );
760760
761+ static ssize_t do_daa_store (struct device * dev ,
762+ struct device_attribute * attr ,
763+ const char * buf , size_t count )
764+ {
765+ struct i3c_master_controller * master = dev_to_i3cmaster (dev );
766+ bool val ;
767+ int ret ;
768+
769+ if (kstrtobool (buf , & val ))
770+ return - EINVAL ;
771+
772+ if (!val )
773+ return - EINVAL ;
774+
775+ if (!master -> init_done )
776+ return - EAGAIN ;
777+
778+ ret = i3c_master_do_daa (master );
779+ if (ret )
780+ return ret ;
781+
782+ return count ;
783+ }
784+
785+ static DEVICE_ATTR_WO (do_daa );
786+
761787static struct attribute * i3c_masterdev_attrs [] = {
762788 & dev_attr_mode .attr ,
763789 & dev_attr_current_master .attr ,
@@ -769,6 +795,7 @@ static struct attribute *i3c_masterdev_attrs[] = {
769795 & dev_attr_dynamic_address .attr ,
770796 & dev_attr_hdrcap .attr ,
771797 & dev_attr_hotjoin .attr ,
798+ & dev_attr_do_daa .attr ,
772799 NULL ,
773800};
774801ATTRIBUTE_GROUPS (i3c_masterdev );
@@ -898,11 +925,17 @@ static void i3c_ccc_cmd_init(struct i3c_ccc_cmd *cmd, bool rnw, u8 id,
898925 cmd -> err = I3C_ERROR_UNKNOWN ;
899926}
900927
928+ /**
929+ * i3c_master_send_ccc_cmd_locked() - send a CCC (Common Command Codes)
930+ * @master: master used to send frames on the bus
931+ * @cmd: command to send
932+ *
933+ * Return: 0 in case of success, or a negative error code otherwise.
934+ * I3C Mx error codes are stored in cmd->err.
935+ */
901936static int i3c_master_send_ccc_cmd_locked (struct i3c_master_controller * master ,
902937 struct i3c_ccc_cmd * cmd )
903938{
904- int ret ;
905-
906939 if (!cmd || !master )
907940 return - EINVAL ;
908941
@@ -920,15 +953,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
920953 !master -> ops -> supports_ccc_cmd (master , cmd ))
921954 return - EOPNOTSUPP ;
922955
923- ret = master -> ops -> send_ccc_cmd (master , cmd );
924- if (ret ) {
925- if (cmd -> err != I3C_ERROR_UNKNOWN )
926- return cmd -> err ;
927-
928- return ret ;
929- }
930-
931- return 0 ;
956+ return master -> ops -> send_ccc_cmd (master , cmd );
932957}
933958
934959static struct i2c_dev_desc *
@@ -1016,6 +1041,10 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
10161041 ret = i3c_master_send_ccc_cmd_locked (master , & cmd );
10171042 i3c_ccc_cmd_dest_cleanup (& dest );
10181043
1044+ /* No active devices on the bus. */
1045+ if (ret && cmd .err == I3C_ERROR_M2 )
1046+ ret = 0 ;
1047+
10191048 return ret ;
10201049}
10211050
@@ -1032,8 +1061,7 @@ static int i3c_master_rstdaa_locked(struct i3c_master_controller *master,
10321061 *
10331062 * This function must be called with the bus lock held in write mode.
10341063 *
1035- * Return: 0 in case of success, a positive I3C error code if the error is
1036- * one of the official Mx error codes, and a negative error code otherwise.
1064+ * Return: 0 in case of success, or a negative error code otherwise.
10371065 */
10381066int i3c_master_entdaa_locked (struct i3c_master_controller * master )
10391067{
@@ -1046,12 +1074,17 @@ int i3c_master_entdaa_locked(struct i3c_master_controller *master)
10461074 ret = i3c_master_send_ccc_cmd_locked (master , & cmd );
10471075 i3c_ccc_cmd_dest_cleanup (& dest );
10481076
1077+ /* No active devices need an address. */
1078+ if (ret && cmd .err == I3C_ERROR_M2 )
1079+ ret = 0 ;
1080+
10491081 return ret ;
10501082}
10511083EXPORT_SYMBOL_GPL (i3c_master_entdaa_locked );
10521084
10531085static int i3c_master_enec_disec_locked (struct i3c_master_controller * master ,
1054- u8 addr , bool enable , u8 evts )
1086+ u8 addr , bool enable , u8 evts ,
1087+ bool suppress_m2 )
10551088{
10561089 struct i3c_ccc_events * events ;
10571090 struct i3c_ccc_cmd_dest dest ;
@@ -1071,6 +1104,9 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
10711104 ret = i3c_master_send_ccc_cmd_locked (master , & cmd );
10721105 i3c_ccc_cmd_dest_cleanup (& dest );
10731106
1107+ if (suppress_m2 && ret && cmd .err == I3C_ERROR_M2 )
1108+ ret = 0 ;
1109+
10741110 return ret ;
10751111}
10761112
@@ -1085,13 +1121,12 @@ static int i3c_master_enec_disec_locked(struct i3c_master_controller *master,
10851121 *
10861122 * This function must be called with the bus lock held in write mode.
10871123 *
1088- * Return: 0 in case of success, a positive I3C error code if the error is
1089- * one of the official Mx error codes, and a negative error code otherwise.
1124+ * Return: 0 in case of success, or a negative error code otherwise.
10901125 */
10911126int i3c_master_disec_locked (struct i3c_master_controller * master , u8 addr ,
10921127 u8 evts )
10931128{
1094- return i3c_master_enec_disec_locked (master , addr , false, evts );
1129+ return i3c_master_enec_disec_locked (master , addr , false, evts , false );
10951130}
10961131EXPORT_SYMBOL_GPL (i3c_master_disec_locked );
10971132
@@ -1106,13 +1141,12 @@ EXPORT_SYMBOL_GPL(i3c_master_disec_locked);
11061141 *
11071142 * This function must be called with the bus lock held in write mode.
11081143 *
1109- * Return: 0 in case of success, a positive I3C error code if the error is
1110- * one of the official Mx error codes, and a negative error code otherwise.
1144+ * Return: 0 in case of success, or a negative error code otherwise.
11111145 */
11121146int i3c_master_enec_locked (struct i3c_master_controller * master , u8 addr ,
11131147 u8 evts )
11141148{
1115- return i3c_master_enec_disec_locked (master , addr , true, evts );
1149+ return i3c_master_enec_disec_locked (master , addr , true, evts , false );
11161150}
11171151EXPORT_SYMBOL_GPL (i3c_master_enec_locked );
11181152
@@ -1132,8 +1166,7 @@ EXPORT_SYMBOL_GPL(i3c_master_enec_locked);
11321166 *
11331167 * This function must be called with the bus lock held in write mode.
11341168 *
1135- * Return: 0 in case of success, a positive I3C error code if the error is
1136- * one of the official Mx error codes, and a negative error code otherwise.
1169+ * Return: 0 in case of success, or a negative error code otherwise.
11371170 */
11381171int i3c_master_defslvs_locked (struct i3c_master_controller * master )
11391172{
@@ -1794,11 +1827,8 @@ int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstdaa)
17941827
17951828 i3c_bus_maintenance_lock (& master -> bus );
17961829
1797- if (rstdaa ) {
1830+ if (rstdaa )
17981831 rstret = i3c_master_rstdaa_locked (master , I3C_BROADCAST_ADDR );
1799- if (rstret == I3C_ERROR_M2 )
1800- rstret = 0 ;
1801- }
18021832
18031833 ret = master -> ops -> do_daa (master );
18041834
@@ -2093,7 +2123,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
20932123 * (assigned by the bootloader for example).
20942124 */
20952125 ret = i3c_master_rstdaa_locked (master , I3C_BROADCAST_ADDR );
2096- if (ret && ret != I3C_ERROR_M2 )
2126+ if (ret )
20972127 goto err_bus_cleanup ;
20982128
20992129 if (master -> ops -> set_speed ) {
@@ -2102,11 +2132,14 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
21022132 goto err_bus_cleanup ;
21032133 }
21042134
2105- /* Disable all slave events before starting DAA. */
2106- ret = i3c_master_disec_locked (master , I3C_BROADCAST_ADDR ,
2107- I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
2108- I3C_CCC_EVENT_HJ );
2109- if (ret && ret != I3C_ERROR_M2 )
2135+ /*
2136+ * Disable all slave events before starting DAA. When no active device
2137+ * is on the bus, returns Mx error code M2, this error is ignored.
2138+ */
2139+ ret = i3c_master_enec_disec_locked (master , I3C_BROADCAST_ADDR , false,
2140+ I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
2141+ I3C_CCC_EVENT_HJ , true);
2142+ if (ret )
21102143 goto err_bus_cleanup ;
21112144
21122145 /*
@@ -2396,7 +2429,7 @@ of_i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master,
23962429 * DEFSLVS command.
23972430 */
23982431 if (boardinfo -> base .flags & I2C_CLIENT_TEN ) {
2399- dev_err (dev , "I2C device with 10 bit address not supported." );
2432+ dev_err (dev , "I2C device with 10 bit address not supported.\n " );
24002433 return - EOPNOTSUPP ;
24012434 }
24022435
@@ -2793,10 +2826,10 @@ struct i3c_generic_ibi_slot {
27932826struct i3c_generic_ibi_pool {
27942827 spinlock_t lock ;
27952828 unsigned int num_slots ;
2796- struct i3c_generic_ibi_slot * slots ;
27972829 void * payload_buf ;
27982830 struct list_head free_slots ;
27992831 struct list_head pending ;
2832+ struct i3c_generic_ibi_slot slots [] __counted_by (num_slots );
28002833};
28012834
28022835/**
@@ -2824,7 +2857,6 @@ void i3c_generic_ibi_free_pool(struct i3c_generic_ibi_pool *pool)
28242857 WARN_ON (nslots != pool -> num_slots );
28252858
28262859 kfree (pool -> payload_buf );
2827- kfree (pool -> slots );
28282860 kfree (pool );
28292861}
28302862EXPORT_SYMBOL_GPL (i3c_generic_ibi_free_pool );
@@ -2847,20 +2879,16 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
28472879 unsigned int i ;
28482880 int ret ;
28492881
2850- pool = kzalloc_obj (* pool );
2882+ pool = kzalloc_flex (* pool , slots , req -> num_slots );
28512883 if (!pool )
28522884 return ERR_PTR (- ENOMEM );
28532885
2886+ pool -> num_slots = req -> num_slots ;
2887+
28542888 spin_lock_init (& pool -> lock );
28552889 INIT_LIST_HEAD (& pool -> free_slots );
28562890 INIT_LIST_HEAD (& pool -> pending );
28572891
2858- pool -> slots = kzalloc_objs (* slot , req -> num_slots );
2859- if (!pool -> slots ) {
2860- ret = - ENOMEM ;
2861- goto err_free_pool ;
2862- }
2863-
28642892 if (req -> max_payload_len ) {
28652893 pool -> payload_buf = kcalloc (req -> num_slots ,
28662894 req -> max_payload_len , GFP_KERNEL );
@@ -2879,7 +2907,6 @@ i3c_generic_ibi_alloc_pool(struct i3c_dev_desc *dev,
28792907 (i * req -> max_payload_len );
28802908
28812909 list_add_tail (& slot -> node , & pool -> free_slots );
2882- pool -> num_slots ++ ;
28832910 }
28842911
28852912 return pool ;
0 commit comments