Skip to content

Commit 401b0e0

Browse files
committed
Merge tag 'i3c/for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux
Pull i3c updates from Alexandre Belloni: "Subsystem: - add sysfs option to rescan bus via entdaa - fix error code handling for send_ccc_cmd Drivers: - mipi-i3c-hci-pci: Intel Nova Lake-H I3C support" * tag 'i3c/for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux: (22 commits) i3c: mipi-i3c-hci: fix IBI payload length calculation for final status i3c: master: adi: Fix error propagation for CCCs i3c: master: Fix error codes at send_ccc_cmd i3c: master: Move bus_init error suppression i3c: master: Move entdaa error suppression i3c: master: Move rstdaa error suppression i3c: dw: Simplify xfer cleanup with __free(kfree) i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers() i3c: master: renesas: Use __free(kfree) for xfer cleanup in renesas_i3c_send_ccc_cmd() i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers() i3c: master: dw-i3c: Balance PM runtime usage count on probe failure i3c: master: dw-i3c: Fix missing reset assertion in remove() callback i3c: mipi-i3c-hci-pci: Enable IBI while runtime suspended for Intel controllers i3c: mipi-i3c-hci-pci: Add optional ability to manage child runtime PM i3c: mipi-i3c-hci: Allow parent to manage runtime PM i3c: mipi-i3c-hci: Add quirk to allow IBI while runtime suspended i3c: mipi-i3c-hci-pci: Set d3hot_delay to 0 for Intel controllers i3c: fix missing newline in dev_err messages i3c: master: use kzalloc_flex i3c: mipi-i3c-hci-pci: Add support for Intel Nova Lake-H I3C ...
2 parents eb5249b + d35a6db commit 401b0e0

11 files changed

Lines changed: 293 additions & 100 deletions

File tree

Documentation/ABI/testing/sysfs-bus-i3c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,23 @@ Description:
172172
the automatic retries. Exist only when I3C constroller supports
173173
this retry on nack feature.
174174

175+
What: /sys/bus/i3c/devices/i3c-<bus-id>/do_daa
176+
KernelVersion: 7.0
177+
Contact: linux-i3c@vger.kernel.org
178+
Description:
179+
Write-only attribute that triggers a Dynamic Address Assignment
180+
(DAA) procedure which discovers new I3C devices on the bus.
181+
Writing a boolean true value (1, y, yes, true, on) to this
182+
attribute causes the master controller to perform DAA, which
183+
includes broadcasting an ENTDAA (Enter Dynamic Address Assignment)
184+
Common Command Code (CCC) on the bus. Writing a false value
185+
returns -EINVAL.
186+
187+
This is useful for discovering I3C devices that were not present
188+
during initial bus initialization and are unable to issue
189+
Hot-Join. Only devices without a currently assigned dynamic address
190+
will respond to the ENTDAA broadcast and be assigned addresses.
191+
192+
Note that this mechanism is distinct from Hot-Join, since this is
193+
controller-initiated discovery, while Hot-Join is device-initiated
194+
method to provoke controller discovery procedure.

drivers/i3c/master.c

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,32 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,
758758

759759
static 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+
761787
static 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
};
774801
ATTRIBUTE_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+
*/
901936
static 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

934959
static 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
*/
10381066
int 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
}
10511083
EXPORT_SYMBOL_GPL(i3c_master_entdaa_locked);
10521084

10531085
static 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
*/
10911126
int 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
}
10961131
EXPORT_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
*/
11121146
int 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
}
11171151
EXPORT_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
*/
11381171
int 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 {
27932826
struct 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
}
28302862
EXPORT_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;

drivers/i3c/master/adi-i3c-master.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int adi_i3c_master_send_ccc_cmd(struct i3c_master_controller *m,
361361

362362
cmd->err = adi_i3c_cmd_get_err(&xfer->cmds[0]);
363363

364-
return 0;
364+
return xfer->ret;
365365
}
366366

367367
static int adi_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
@@ -655,8 +655,7 @@ static int adi_i3c_master_do_daa(struct i3c_master_controller *m)
655655

656656
writel(irq_mask, master->regs + REG_IRQ_MASK);
657657

658-
/* DAA always finishes with CE2_ERROR or NACK_RESP */
659-
if (ret && ret != I3C_ERROR_M2)
658+
if (ret)
660659
return ret;
661660

662661
/* Add I3C devices discovered */

0 commit comments

Comments
 (0)