diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 643781f3ad029..95262e56dff5b 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1755,7 +1755,14 @@ static int afk_send_compact_command(struct apple_epic_service *service, u8 type, static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, enum epic_type etype, enum epic_category ecat, u8 stype, const void *payload, size_t payload_len, u64 token, - bool *published); + u64 *published); + +/* The TX write pointer has moved from @old to @new, which is another place in the ring. */ +static void afk_tx_published_locked(struct apple_dcp_afkep *ep, u32 old, u32 new) +{ + lockdep_assert_held(&ep->lock); + ep->tx_published += new > old ? new - old : ep->txbfr.bufsz - old + new; +} /* Caller has closed host publication and settled ordinary commands first. */ int afk_v27_sleep_check(struct apple_dcp_afkep *ep) @@ -1882,6 +1889,7 @@ int afk_v27_sleep_control(struct apple_dcp_afkep *ep, bool open) ep->sleep_waiting = true; dma_wmb(); WRITE_ONCE(*ep->txbfr.wptr, cpu_to_le32(next)); + afk_tx_published_locked(ep, old, next); dma_wmb(); /* Return the transport's send error; a published entry still poisons it. */ ret = apple_rtkit_send_message(ep->dcp->rtk, ep->endpoint, @@ -3271,9 +3279,9 @@ int afk_receive_message(struct apple_dcp_afkep *ep, u64 message) static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, enum epic_type etype, enum epic_category ecat, u8 stype, const void *payload, size_t payload_len, u64 token, - bool *published) + u64 *published) { - u32 rptr, wptr; + u32 rptr, wptr, old; struct afk_qe *hdr, *hdr2; struct epic_hdr *ehdr; struct epic_sub_hdr *eshdr; @@ -3286,7 +3294,7 @@ static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, bool panel_resume; if (published) - *published = false; + *published = 0; /* External H17P services use AFKV2; the internal profile has no EPIC sender. */ if (ep->dcp->fw_compat == DCP_FIRMWARE_H17P && !ep->wire_v2) { @@ -3367,6 +3375,7 @@ static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, dma_rmb(); rptr = le32_to_cpu(*ep->txbfr.rptr); wptr = le32_to_cpu(*ep->txbfr.wptr); + old = wptr; if (rptr >= ep->txbfr.bufsz || wptr >= ep->txbfr.bufsz || !IS_ALIGNED(rptr, ep->txbfr.stride) || !IS_ALIGNED(wptr, ep->txbfr.stride)) { @@ -3536,8 +3545,9 @@ static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, if (!ret) { dma_wmb(); *ep->txbfr.wptr = cpu_to_le32(wptr); + afk_tx_published_locked(ep, old, wptr); if (published) - *published = true; + *published = ep->tx_published; if (!afk_send_may_sleep(ep)) ret = afk_send_raw_locked(ep, FIELD_PREP(RBEP_TYPE, RBEP_SEND) | FIELD_PREP(SEND_WPTR, wptr)); @@ -3565,7 +3575,7 @@ static int afk_send_epic_token(struct apple_dcp_afkep *ep, u32 channel, u16 tag, static int afk_send_epic_published(struct apple_dcp_afkep *ep, u32 channel, u16 tag, enum epic_type etype, enum epic_category ecat, u8 stype, const void *payload, size_t payload_len, - bool *published) + u64 *published) { return afk_send_epic_token(ep, channel, tag, etype, ecat, stype, payload, payload_len, 0, published); @@ -3614,6 +3624,85 @@ static u16 afk_command_tag(struct apple_epic_service *service, u8 slot) return tag; } +/** + * afk_service_call_ring_unread - ring again for a call the firmware has not read + * @service: the service the call is for + * @group: the call's group + * @command: the call's command + * @data: the call's input + * @data_len: the length of @data + * + * When the command queued last on @service is this call, with the same input, + * it has gone unanswered and the firmware has not read its entry in the TX ring, + * only ring the doorbell again and return true: the call itself waits. A copy would + * queue behind it to the same effect, and keep a command slot of its own until + * answered, so a caller that repeats a call to firmware that has stopped reading + * takes every slot, and the service then refuses all of its calls with -ENOSPC. + * + * A call the sender would refuse gets its error from there. Compact EPIC keeps + * its timed-out commands apart, and is not covered. + */ +bool afk_service_call_ring_unread(struct apple_epic_service *service, u16 group, + u32 command, const void *data, size_t data_len) +{ + const struct epic_service_call *call; + const struct epic_cmd_info *cmd; + struct apple_dcp_afkep *ep; + u32 rptr, wptr = 0, unread; + unsigned long flags; + bool waits; + u64 end; + + if (!service || !service->ep || READ_ONCE(service->ep->compact)) + return false; + ep = service->ep; + + spin_lock_irqsave(&service->lock, flags); + cmd = &service->cmds[service->last_slot]; + call = cmd->txbuf; + /* A set slot bit keeps the buffers: the reply clears it before freeing them. */ + waits = service->enabled && !service->torndown && + test_bit(service->last_slot, service->cmd_map) && + !cmd->done && !cmd->completion && + cmd->type == EPIC_SUBTYPE_STD_SERVICE && + cmd->txlen >= sizeof(*call) + data_len && + le32_to_cpu(call->magic) == EPIC_SERVICE_CALL_MAGIC && + le16_to_cpu(call->group) == group && + le32_to_cpu(call->command) == command && + !memcmp(call + 1, data, data_len); + /* Its sender writes this without the lock until it gives its slot up. */ + end = waits ? cmd->tx_end : 0; + spin_unlock_irqrestore(&service->lock, flags); + if (!waits) + return false; + + mutex_lock(&ep->tx_lock); + spin_lock_irqsave(&ep->lock, flags); + waits = !READ_ONCE(ep->dcp->quiescing) && !afk_tx_admit_locked(ep) && + READ_ONCE(ep->dcp->sleep_v27_closed) == DCP_V27_TX_LIVE && + ep->txbfr.ready; + if (waits) { + dma_rmb(); + rptr = le32_to_cpu(READ_ONCE(*ep->txbfr.rptr)); + wptr = le32_to_cpu(READ_ONCE(*ep->txbfr.wptr)); + unread = wptr >= rptr ? wptr - rptr : ep->txbfr.bufsz - rptr + wptr; + /* Fewer bytes follow its entry than the firmware has not read: it's unread. */ + waits = ep->tx_published - end < unread; + } + if (waits) + ep->tx_active++; + spin_unlock_irqrestore(&ep->lock, flags); + if (waits) { + afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SEND) | + FIELD_PREP(SEND_WPTR, wptr)); + spin_lock_irqsave(&ep->lock, flags); + ep->tx_active--; + spin_unlock_irqrestore(&ep->lock, flags); + } + mutex_unlock(&ep->tx_lock); + return waits; +} + static int afk_send_command_common(struct apple_epic_service *service, u8 type, const void *payload, size_t payload_len, void *output, size_t output_len, u32 *retcode, @@ -3664,7 +3753,7 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, void *rxbuf, *txbuf; dma_addr_t rxbuf_dma, txbuf_dma; unsigned long flags; - bool published = false; + u64 published = 0; int ret, idx; u16 tag; struct apple_dcp_afkep *ep; @@ -3813,7 +3902,9 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, service->cmds[idx].txlen = payload_len; service->cmds[idx].free_on_ack = false; service->cmds[idx].done = false; + service->cmds[idx].tx_end = 0; service->cmds[idx].completion = &completion; + service->last_slot = idx; init_completion(&completion); spin_unlock_irqrestore(&service->lock, flags); @@ -3836,6 +3927,8 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, } kfree(inline_command); inline_command = NULL; + /* Read only once this call has given its slot up, under the lock. */ + service->cmds[idx].tx_end = published; if (ret) { if (!published) goto err_free_cmd; @@ -3877,7 +3970,7 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, "AFK[ep:%02x]: %s (chan:%u) command type 0x%x tag 0x%04x timed out after %u ms\n", ep->endpoint, service->ops->name, service->channel, type, tag, timeout_ms); - if (ep->dcp->external && ep->txbfr.ready && ep->rxbfr.ready) { + if (ep->txbfr.ready && ep->rxbfr.ready) { /* Diagnostic snapshot of shared RAM, not coprocessor MMIO. * Unequal TX pointers mean firmware has not drained the queue. */ diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index 7e17d5188c218..ac96943698600 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -43,6 +43,9 @@ struct epic_cmd_info { size_t reply_len; bool reply_len_valid; + /* Where its TX ring entry ends, as tx_published; 0 before it is published. */ + u64 tx_end; + u32 retcode; bool done; bool free_on_ack; @@ -57,6 +60,11 @@ struct apple_epic_service { DECLARE_BITMAP(cmd_map, MAX_PENDING_CMDS); /* Legacy EPIC sequence; AFKV2 history belongs to the interface. */ u8 cmd_tag; + /* + * Slot of the command queued last (lock). It names none once that slot + * is free, so none of an earlier instance either: reuse needs all free. + */ + u8 last_slot; spinlock_t lock; /* Pins held by owners and synchronous callers; protected by lock. */ unsigned int users; @@ -596,6 +604,8 @@ struct apple_dcp_afkep { /* Serializes TX ring writes and mailbox doorbells outside ep->lock. */ struct mutex tx_lock; u16 qe_seq; + /* lock: bytes the host has advanced the TX write pointer by, ever. */ + u64 tx_published; bool stopping; /* lock: no new receive work after shutdown. */ bool tx_paused; /* lock: no new host commands while stopping/stopped. */ bool rx_paused; /* lock: defer incoming RX words while stopping/stopped. */ @@ -742,6 +752,8 @@ int afk_service_call_timeout_len(struct apple_epic_service *service, u16 group, size_t data_pad, void *output, size_t output_len, size_t output_pad, unsigned int timeout_ms, size_t *received); +bool afk_service_call_ring_unread(struct apple_epic_service *service, u16 group, + u32 command, const void *data, size_t data_len); /* Strict variants return only firmware-reported bytes; legacy callers unchanged. */ int afk_send_command_with_reply_len(struct apple_epic_service *service, u8 type, diff --git a/drivers/gpu/drm/apple/dptxep.c b/drivers/gpu/drm/apple/dptxep.c index 60e1a31aa773a..4c718b6f9ef23 100644 --- a/drivers/gpu/drm/apple/dptxep.c +++ b/drivers/gpu/drm/apple/dptxep.c @@ -32,6 +32,10 @@ struct dcpdptx_connection_cmd { __le32 target; } __attribute__((packed)); +/* The port's HPD level: group and command of the call, and its input. */ +#define DCPDPTX_HOTPLUG_GROUP 8 +#define DCPDPTX_HOTPLUG_CMD 8 + struct dcpdptx_hotplug_cmd { u8 _pad0[16]; __le32 unk; @@ -254,7 +258,24 @@ int dptxport_set_hpd_timeout(struct apple_epic_service *service, bool hpd, if (hpd) cmd.unk = cpu_to_le32(1); - ret = afk_service_call_timeout_len(service, 8, 8, &cmd, sizeof(cmd), 12, + /* + * The same HPD level went unanswered and still waits in the firmware's + * queue, with nothing of the port behind it. A copy would change nothing, + * and keep a command slot until answered. A port whose Type-C SAFE state + * is retried (dcp_typec_route_prepare()) repeats its HPD low, and would + * take every slot: the port then refuses all its calls with -ENOSPC, the + * HPD of the next display among them. + */ + if (afk_service_call_ring_unread(service, DCPDPTX_HOTPLUG_GROUP, + DCPDPTX_HOTPLUG_CMD, &cmd, sizeof(cmd))) { + dev_warn_ratelimited(service->ep->dcp->dev, + "set_hpd(%d): the same request is still unread, only rang again\n", + hpd); + return -ETIMEDOUT; + } + + ret = afk_service_call_timeout_len(service, DCPDPTX_HOTPLUG_GROUP, + DCPDPTX_HOTPLUG_CMD, &cmd, sizeof(cmd), 12, &resp, sizeof(resp), 12, timeout_ms, &received); if (ret) diff --git a/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-hpd.py b/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-hpd.py index ea3915f0de720..f57153b12fa99 100644 --- a/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-hpd.py +++ b/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-hpd.py @@ -2,7 +2,8 @@ # SPDX-License-Identifier: GPL-2.0-only OR MIT """Exercise the production DPTX HPD request with mocked service-call replies. -Covers the legacy, AFK-v2 and compact EPIC replies and the 14.7 AV client close. +Covers the legacy, AFK-v2 and compact EPIC replies, the 14.7 AV client close, +and a request that is not sent again while the same one still waits unread. """ import pathlib import re @@ -27,6 +28,7 @@ def function(source, name): dptx, re.M | re.S) if not command: raise RuntimeError("production HPD request layout not found") +call_ids = re.findall(r"^#define DCPDPTX_HOTPLUG_\w+\s.*$", dptx, re.M) prefix = r''' #undef NDEBUG #include @@ -48,6 +50,7 @@ def function(source, name): #define EPIC_SERVICE_CALL_MAGIC 0x69706378 #define EPIC_SUBTYPE_STD_SERVICE 0xc0 #define dev_warn(...) do {} while (0) +#define dev_warn_ratelimited(...) do {} while (0) #define dev_dbg(...) do {} while (0) #define READ_ONCE(x) (x) static u32 get_unaligned_le32(const void *p) @@ -95,6 +98,17 @@ def function(source, name): assert(dcp == expected_dcp && service != NULL); cec_closes++; } +/* The HPD request queued last on the port still waits unread. */ +static bool unread; +static unsigned int sends, unread_asked; +bool afk_service_call_ring_unread(struct apple_epic_service *service, u16 group, + u32 command, const void *data, size_t data_len) +{ + (void)service; (void)data; + assert(group == 8 && command == 8 && data_len == 20); + unread_asked++; + return unread; +} static int afk_send_command_timeout_len(struct apple_epic_service *s, u8 type, const void *payload, size_t payload_len, void *output, size_t output_len, u32 *retcode, unsigned int timeout_ms, size_t *received) @@ -109,6 +123,7 @@ def function(source, name): assert(call->group == 8 && call->command == 8); closes_at_send = v14_closes; cec_closes_at_send = cec_closes; + sends++; if (wire_v2 && !received && arrived < output_len - sizeof(*call)) return -EMSGSIZE; memcpy(&echo, body + 16, sizeof(echo)); @@ -206,14 +221,25 @@ def function(source, name): } ep.compact = false; compact_status = 0; } + /* A copy of an unread request is not sent, and fails as the request did. */ + for (int hpd = 0; hpd < 2; hpd++) { + unsigned int before = sends, asked = unread_asked; + int ret; + + unread = true; + ret = dptxport_set_hpd_timeout(&service, hpd, 1000); + unread = false; + expect(ret == -ETIMEDOUT && sends == before && unread_asked == asked + 1, + "copy of an unread request not sent", hpd, ret); + } printf("%d HPD reply checks failed\n", failures); if (failures) return 1; - puts("PASS: extracted production DPTX HPD request: short, oversized, wrong-echo and complete replies, legacy, AFK-v2 and compact status, AV client close on HPD low"); + puts("PASS: extracted production DPTX HPD request: short, oversized, wrong-echo and complete replies, legacy, AFK-v2 and compact status, AV client close on HPD low, no copy of an unread request"); return 0; } ''' -unit = (prefix + command.group(0) + "\n" + function(afk, "afk_service_call_timeout_len") + "\n" + +unit = (prefix + "\n".join(call_ids) + "\n" + command.group(0) + "\n" + function(afk, "afk_service_call_timeout_len") + "\n" + function(afk, "afk_service_call_timeout") + "\n" + function(dptx, "dptxport_set_hpd_timeout") + suffix) pathlib.Path(sys.argv[3]).write_text(unit) diff --git a/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-send.py b/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-send.py index cf0ad596f984c..c88f71c1f6472 100644 --- a/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-send.py +++ b/tools/testing/selftests/drivers/gpu/apple-afkv2/extract-send.py @@ -2,7 +2,8 @@ # SPDX-License-Identifier: GPL-2.0-only OR MIT """Compile the real command sender against synthetic ring and DMA operations. -Covers AFK-v2, legacy reply-length and compact EPIC requests. +Covers AFK-v2, legacy reply-length and compact EPIC requests, and the repeat of +a call the firmware has not read. """ import pathlib import re @@ -83,6 +84,7 @@ def function(pattern, what): #define DCP_FIRMWARE_V_14_7 2 #define DCP_FIRMWARE_M4 3 #define EPIC_SUBTYPE_STD_SERVICE 0xc0 +#define EPIC_SERVICE_CALL_MAGIC 0x69706378 enum epic_type { EPIC_TYPE_NOTIFY = 0, EPIC_TYPE_COMMAND = 3, EPIC_TYPE_REPLY = 4 }; enum epic_category { EPIC_CAT_REPORT = 0x00, EPIC_CAT_NOTIFY = 0x10, @@ -109,12 +111,16 @@ def function(pattern, what): #define wait_for_completion_timeout(p,t) ((void)(t),*(p)) typedef u64 dma_addr_t; struct epic_cmd { u32 retcode; u64 rxbuf,txbuf; u32 rxlen,txlen; u8 rxcookie,txcookie; }; -struct cmd_info { +struct epic_cmd_info { u16 tag; u8 type; size_t reply_length; void *rxbuf,*txbuf; dma_addr_t rxbuf_dma,txbuf_dma; size_t rxlen,txlen; u32 retcode; size_t reply_len; bool reply_len_valid; - bool done,free_on_ack; int *completion; + bool done,free_on_ack; int *completion; struct { u64 end; } tx[1]; }; +/* A retry must leave tx_end alone while the first call's sender, who writes it unlocked, has the slot. */ +static bool retrying; +static int tx_end_index(void) { assert(!retrying); return 0; } +#define tx_end tx[tx_end_index()].end struct apple_dcp { void *dev; int fw_compat; bool quiescing,external,crashed,ext26,afk_tx_closed,afk_rx_failed; @@ -132,17 +138,20 @@ def function(pattern, what): struct apple_dcp *dcp; bool wire_v2,inline_v2,compact,stopping,tx_paused,rx_paused,rx_failed; bool j516s_panel_service; - int endpoint,lock,tx_lock; unsigned int tx_active; u16 qe_seq; u8 *command_tags; + int endpoint,lock,tx_lock; unsigned int tx_active; u16 qe_seq; u64 tx_published; u8 *command_tags; struct afk_ringbuffer txbfr,rxbfr; size_t ext26_command_bytes; unsigned int ext26_command_count; }; struct ops { const char *name; }; +struct epic_service_call { u8 _pad0[2]; u16 group; u32 command,data_len,magic; u8 _pad1[48]; } __attribute__((packed)); struct apple_epic_service { struct apple_dcp_afkep *ep; struct ops *ops; unsigned int channel; unsigned long cmd_map[1]; - int lock; unsigned int users; bool enabled,torndown; u8 cmd_tag; struct cmd_info cmds[16]; + int lock; unsigned int users; bool enabled,torndown; u8 cmd_tag; struct epic_cmd_info cmds[16]; + u8 last_slot; }; static struct apple_epic_service *active; static struct apple_dcp_afkep *active_ep; static unsigned int frees, sends; +static u64 last_doorbell; static int wire_fail, timeout, reply_status; static bool raw_doorbell_mode, inject_overflow_on_alloc, complete_before_doorbell_fail; static u32 tx_consumed_wptr; @@ -151,6 +160,9 @@ def function(pattern, what): static bool real_reply; static u32 legacy_rxlen; static void afk_recv_handle_reply(struct apple_dcp_afkep *ep,u32 channel,u16 tag,void *payload,size_t payload_size); +/* The input of a call to retry from its own doorbell, before its sender has gone on. */ +static const u8 *retry; +bool afk_service_call_ring_unread(struct apple_epic_service *s,u16 group,u32 command,const void *data,size_t len); /* Compact EPIC goes inline through the ring; this mock stands for that transport. */ static bool compact_echo; static u32 compact_reply,compact_request; @@ -185,12 +197,12 @@ def function(pattern, what): static void dma_free_coherent(void *dev,size_t n,void *p,dma_addr_t a) { (void)dev;(void)n;assert((uintptr_t)p==a);free(p);frees++; } static int bitmap_find_free_region(unsigned long *map,unsigned int n,int order) -{ (void)n;(void)order;assert(!*map);*map=1;return 0; } +{ assert(!order);for(unsigned int i=0;icmds[0]; + struct epic_cmd_info *c=&active->cmds[0]; if(real_reply) { struct epic_cmd reply={.retcode=reply_status,.rxlen=legacy_rxlen}; assert(!ep->wire_v2); @@ -214,7 +226,11 @@ def function(pattern, what): assert(dcp->afk_tx_lock); if(!raw_doorbell_mode) assert(active_ep->tx_lock && active_ep->lock); } - sends++; + sends++;last_doorbell=message; + if(retry) { + retrying=true;assert(!afk_service_call_ring_unread(active,8,8,retry,20)); + retrying=false;retry=NULL; + } if(raw_doorbell_mode) return wire_fail; assert((message >> 48)==RBEP_SEND); @@ -431,6 +447,94 @@ def function(pattern, what): assert(afk_send_epic(&ep,4,0,EPIC_TYPE_NOTIFY,EPIC_CAT_REPORT,AFKV2_OPEN,NULL,0)==-ENOSPC); assert(tx_wptr==panel_wptr); puts("PASS: v27 panel OPEN exception preserves the independent transmit gates"); + + /* The repeat of a call the firmware has not read only rings again. */ + ep.wire_v2=ep.inline_v2=ep.tx_paused=ep.j516s_panel_service=false; + dcp.afk_tx_closed=dcp.afk_rx_failed=false;dcp.sleep_v27_closed=DCP_V27_TX_LIVE; + struct { struct epic_service_call call; u8 data[20]; u8 pad[28]; } low={0},high; + low.call=(struct epic_service_call){.group=8,.command=8,.data_len=32,.magic=EPIC_SERVICE_CALL_MAGIC}; + high=low;high.data[16]=1; + u8 result[112]; +#define RING(group,command,input) afk_service_call_ring_unread(&s,group,command,(input).data,sizeof((input).data)) +#define SEND(input) afk_send_command_timeout_len(&s,0xc0,&(input),sizeof(input),result,sizeof(result),&status,1000,NULL) + assert(sizeof(low)==112 && !RING(8,8,low)); + /* Delivered and timed out, then with its doorbell lost. */ + for(int lost=0;lost<2;lost++) { + struct epic_cmd late={0}; + tx_rptr=tx_wptr;wire_fail=lost?-ETIMEDOUT:0;retry=low.data; + assert(SEND(low)==-ETIMEDOUT && !retry && s.cmd_map[0] && tx_rptr!=tx_wptr); + wire_fail=0; + u32 queued=tx_wptr;unsigned int rung=sends; + for(int i=0;i<32;i++) assert(RING(8,8,low)); + assert(sends==rung+32 && last_doorbell==((RBEP_SEND<<48)|queued)); + assert(tx_wptr==queued && s.cmd_map[0]==1 && !ep.tx_active && !ep.tx_lock); + /* Another level or call is left to the sender. */ + assert(!RING(8,8,high) && !RING(8,7,low) && !RING(0,8,low)); + /* So is one the sender refuses, with its own error. */ + ep.tx_paused=true;assert(!RING(8,8,low));ep.tx_paused=false; + ep.stopping=true;assert(!RING(8,8,low));ep.stopping=false; + dcp.quiescing=true;assert(!RING(8,8,low));dcp.quiescing=false; + dcp.crashed=true;assert(!RING(8,8,low));dcp.crashed=false; + dcp.sleep_v27_closed=DCP_V27_TX_REPLIES;assert(!RING(8,8,low)); + dcp.sleep_v27_closed=DCP_V27_TX_PANEL_OPEN;assert(!RING(8,8,low)); + dcp.sleep_v27_closed=DCP_V27_TX_LIVE; + ep.txbfr.ready=false;assert(!RING(8,8,low));ep.txbfr.ready=true; + s.enabled=false;assert(!RING(8,8,low));s.enabled=true; + ep.compact=true;assert(!RING(8,8,low));ep.compact=false; + /* Nor one its caller still waits for, or that is answered with the slot kept. */ + int waiter=0; + s.cmds[0].completion=&waiter;assert(!RING(8,8,low));s.cmds[0].completion=NULL; + s.cmds[0].done=true;assert(!RING(8,8,low));s.cmds[0].done=false; + /* Read without an answer, or answered: the next one is sent. */ + tx_rptr=tx_wptr;assert(!RING(8,8,low));tx_rptr=0;assert(tx_rptr!=tx_wptr && RING(8,8,low)); + assert(sends==rung+33); + afk_recv_handle_reply(&ep,4,s.cmds[0].tag,&late,sizeof(late)); + assert(!s.cmd_map[0] && !RING(8,8,low) && sends==rung+33); + } + /* Read without an answer, and the unread entry behind it is another's: the next one is sent. */ +#define OTHER() assert(!afk_send_epic(&ep,5,0,EPIC_TYPE_NOTIFY,EPIC_CAT_REPORT,1,note,sizeof(note))) + struct epic_cmd gone={0};u8 note[4]={0}; + tx_rptr=tx_wptr; + assert(SEND(low)==-ETIMEDOUT && RING(8,8,low)); + u32 behind=tx_wptr; + OTHER(); + unsigned int before=sends; + assert(RING(8,8,low) && sends==before+1 && last_doorbell==((RBEP_SEND<<48)|tx_wptr)); + tx_rptr=behind; + assert(tx_rptr!=tx_wptr && !RING(8,8,low) && sends==before+1); + /* Nor is the entry that comes to lie where it was, a lap of the ring later. */ + for(u32 at=tx_wptr,lap=0;lapat?tx_wptr-at:sizeof(tx_ring_buf)-at+tx_wptr; + assert(!RING(8,8,low)); + } + assert(sends>before+1 && s.cmd_map[0]==1); + afk_recv_handle_reply(&ep,4,s.cmds[0].tag,&gone,sizeof(gone)); + assert(!s.cmd_map[0]); + /* The same wherever in the ring the entries lie, around its end too. */ + for(int i=0;i<64;i++) { + tx_rptr=tx_wptr; + assert(SEND(low)==-ETIMEDOUT);behind=tx_wptr; + assert(RING(8,8,low)); + OTHER(); + assert(RING(8,8,low)); + tx_rptr=behind;assert(tx_rptr!=tx_wptr && !RING(8,8,low)); + tx_rptr=tx_wptr;assert(!RING(8,8,low)); + afk_recv_handle_reply(&ep,4,s.cmds[0].tag,&gone,sizeof(gone)); + assert(!s.cmd_map[0]); + } + /* With both levels unread, only the one queued last is the port's: an edge is never swallowed. */ + tx_rptr=tx_wptr; + assert(SEND(low)==-ETIMEDOUT && RING(8,8,low) && !RING(8,8,high)); + assert(SEND(high)==-ETIMEDOUT && s.cmd_map[0]==3 && RING(8,8,high) && !RING(8,8,low)); + assert(SEND(low)==-ETIMEDOUT && s.cmd_map[0]==7 && RING(8,8,low) && !RING(8,8,high)); + /* The last one is answered: the one before it, the other level, is not taken for it. */ + struct epic_cmd answer={0}; + afk_recv_handle_reply(&ep,4,s.cmds[2].tag,&answer,sizeof(answer)); + assert(s.cmd_map[0]==3 && !RING(8,8,low) && !RING(8,8,high)); + for(int i=0;i<2;i++) afk_recv_handle_reply(&ep,4,s.cmds[i].tag,&answer,sizeof(answer)); + assert(!s.cmd_map[0]); + puts("PASS: the repeat of an unread call rings again and takes no second slot"); puts("PASS: extracted production sender, transport boundary lock assertions, overflow injection, failed doorbell after publication, and ext26 budget"); } ''' @@ -439,11 +543,14 @@ def function(pattern, what): function(r"static int afk_tx_admit_locked", "TX admission check"), function(r"static int afk_send_raw_locked", "locked doorbell helper"), function(r"static int afk_send_ret", "doorbell helper"), + function(r"static void afk_send", "control doorbell"), + function(r"static void afk_tx_published_locked", "TX publish count"), function(r"static int afk_send_epic_token", "EPIC ring sender"), function(r"static int afk_send_epic_published", "published EPIC sender"), function(r"int afk_send_epic", "EPIC sender"), function(r"static u32 afk_compact_next_status", "compact status allocator"), function(r"static u16 afk_command_tag", "interface tag allocator"), + function(r"bool afk_service_call_ring_unread", "unread call check"), function(r"static int afk_send_command_common", "command sender"), function(r"static int afk_send_command_timeout_len", "length-aware sender"), function(r"int afk_send_command_with_reply_len", "legacy reply-length sender"), diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index c18108ca7f0c6..369199cb2630d 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -87,10 +87,11 @@ def function(file,signature): void afk_service_retry(struct apple_dcp_afkep *ep); /* open_later: a firmware 27 panel service that sends its own OPEN; none is here. */ struct apple_epic_service_ops { char name[32];bool reusable,optional,open_later,singleton;void (*init)(struct apple_epic_service *,const char *,const char *,s64);int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);void (*teardown)(struct apple_epic_service *); }; -struct epic_cmd_info { u16 tag;u8 type;size_t reply_length,reply_len;bool reply_len_valid;void *rxbuf,*txbuf;dma_addr_t rxbuf_dma,txbuf_dma;size_t rxlen,txlen;u32 retcode;bool done,free_on_ack;int *completion; }; +struct epic_cmd_info { u16 tag;u8 type;size_t reply_length,reply_len;bool reply_len_valid;void *rxbuf,*txbuf;dma_addr_t rxbuf_dma,txbuf_dma;size_t rxlen,txlen;u64 tx_end;u32 retcode;bool done,free_on_ack;int *completion; }; struct apple_epic_service { struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops; bool lock,enabled,torndown,defer_start,started;unsigned int users;u32 channel;u8 cmd_tag; + u8 last_slot; unsigned long cmd_map[1];struct epic_cmd_info cmds[MAX_PENDING_CMDS]; struct { u64 generation,epoch; } admission;void *cookie; bool pending_open;const char *pending_name,*pending_class;s64 pending_unit; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/recovery.py b/tools/testing/selftests/drivers/gpu/apple-dcp/recovery.py index 94529dbc719a9..0a07f9531e6b7 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/recovery.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/recovery.py @@ -111,7 +111,7 @@ def extract(text,signature): } '''+marker) unit=unit.replace('static void afk_v2_callback(', - 'static int afk_send_epic_published(struct apple_dcp_afkep *e,u32 channel,u16 tag,int type,int category,u8 subtype,const void *p,size_t n,bool *published)\n' + 'static int afk_send_epic_published(struct apple_dcp_afkep *e,u32 channel,u16 tag,int type,int category,u8 subtype,const void *p,size_t n,u64 *published)\n' '{ int r=afk_send_epic(e,channel,tag,type,category,subtype,p,n); if(published) *published=!r; return r; }\n' 'static void afk_v2_callback(')