From bdda45e44613ebddf85aafc6626c318e1eee64b4 Mon Sep 17 00:00:00 2001 From: wanxiaoqing Date: Mon, 20 May 2024 10:06:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E6=A0=B8=E4=BB=A3=E7=A0=81=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanxiaoqing --- linux-5.10/rk3568_patch/kernel.patch | 244 ++++----------------------- 1 file changed, 37 insertions(+), 207 deletions(-) diff --git a/linux-5.10/rk3568_patch/kernel.patch b/linux-5.10/rk3568_patch/kernel.patch index 7b220c6..0fd3984 100644 --- a/linux-5.10/rk3568_patch/kernel.patch +++ b/linux-5.10/rk3568_patch/kernel.patch @@ -1597044,8 +1597044,7 @@ index b69b8c7e7966..78345e425264 - } else { - td_to_noop(xhci, ep_ring, cur_td, false); - } -+ ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); - +- -remove_finished_td: - /* - * The event handler won't see a completion for this TD anymore, @@ -1597056,7 +1597055,8 @@ index b69b8c7e7966..78345e425264 - } - - xhci_stop_watchdog_timer_in_irq(xhci, ep); -- ++ ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); + - /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ - if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { - xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, @@ -1597384,23 +1597384,9 @@ index b69b8c7e7966..78345e425264 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) handle_cmd_completion(xhci, &event->event_cmd); -@@ -2062,29 +2155,60 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) - return 0; - } +@@ -2070,18 +2163,52 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, --static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, -- struct xhci_transfer_event *event, struct xhci_virt_ep *ep) -+static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, -+ struct xhci_ring *ep_ring, struct xhci_td *td, -+ u32 trb_comp_code) - { - struct xhci_ep_ctx *ep_ctx; -- struct xhci_ring *ep_ring; -- u32 trb_comp_code; - -- ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer)); ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); -- trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); - if (trb_comp_code == COMP_STOPPED_LENGTH_INVALID || - trb_comp_code == COMP_STOPPED || @@ -1597460,7 +1597446,7 @@ index b69b8c7e7966..78345e425264 /* * xhci internal endpoint state will go to a "halt" state for * any stall, including default control pipe protocol stall. -@@ -2095,18 +2219,23 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, +@@ -2092,18 +2219,22 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, * stall later. Hub TT buffer should only be cleared for FS/LS * devices behind HS hubs for functional stalls. */ @@ -1597472,55 +1597458,27 @@ index b69b8c7e7966..78345e425264 - EP_HARD_RESET); - } else { - /* Update ring dequeue pointer */ -- while (ep_ring->dequeue != td->last_trb) -- inc_deq(xhci, ep_ring); +- ep_ring->dequeue = td->last_trb; +- ep_ring->deq_seg = td->last_trb_seg; +- ep_ring->num_trbs_free += td->num_trbs - 1; - inc_deq(xhci, ep_ring); +- } + EP_HARD_RESET); + + return 0; /* xhci_handle_halted_endpoint marked td cancelled */ + default: + break; - } - ++ } ++ + /* Update ring dequeue pointer */ + ep_ring->dequeue = td->last_trb; + ep_ring->deq_seg = td->last_trb_seg; + ep_ring->num_trbs_free += td->num_trbs - 1; + inc_deq(xhci, ep_ring); -+ - return xhci_td_cleanup(xhci, td, ep_ring, td->status); - } - -@@ -2128,9 +2257,9 @@ static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, - /* - * Process control tds, update urb status and actual_length. - */ --static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, -- union xhci_trb *ep_trb, struct xhci_transfer_event *event, -- struct xhci_virt_ep *ep) -+static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, -+ struct xhci_ring *ep_ring, struct xhci_td *td, -+ union xhci_trb *ep_trb, struct xhci_transfer_event *event) - { - struct xhci_ep_ctx *ep_ctx; - u32 trb_comp_code; -@@ -2218,18 +2347,19 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, - td->urb->actual_length = requested; - finish_td: -- return finish_td(xhci, td, event, ep); -+ return finish_td(xhci, ep, ep_ring, td, trb_comp_code); + return xhci_td_cleanup(xhci, td, ep_ring, td->status); } - - /* - * Process isochronous tds, update urb packet status and actual_length. - */ --static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, -- union xhci_trb *ep_trb, struct xhci_transfer_event *event, -- struct xhci_virt_ep *ep) -+static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, -+ struct xhci_ring *ep_ring, struct xhci_td *td, -+ union xhci_trb *ep_trb, struct xhci_transfer_event *event) +@@ -2228,6 +2359,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, { struct urb_priv *urb_priv; int idx; @@ -1597528,58 +1597486,7 @@ index b69b8c7e7966..78345e425264 struct usb_iso_packet_descriptor *frame; u32 trb_comp_code; bool sum_trbs_for_length = false; -@@ -2303,7 +2433,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, - - td->urb->actual_length += frame->actual_length; - -- return finish_td(xhci, td, event, ep); -+ return finish_td(xhci, ep, ep_ring, td, trb_comp_code); - } - - static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, -@@ -2324,8 +2454,9 @@ static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, - frame->actual_length = 0; - - /* Update ring dequeue pointer */ -- while (ep->ring->dequeue != td->last_trb) -- inc_deq(xhci, ep->ring); -+ ep->ring->dequeue = td->last_trb; -+ ep->ring->deq_seg = td->last_trb_seg; -+ ep->ring->num_trbs_free += td->num_trbs - 1; - inc_deq(xhci, ep->ring); - - return xhci_td_cleanup(xhci, td, ep->ring, status); -@@ -2334,17 +2465,15 @@ static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, - /* - * Process bulk and interrupt tds, update urb status and actual_length. - */ --static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td, -- union xhci_trb *ep_trb, struct xhci_transfer_event *event, -- struct xhci_virt_ep *ep) -+static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, -+ struct xhci_ring *ep_ring, struct xhci_td *td, -+ union xhci_trb *ep_trb, struct xhci_transfer_event *event) - { - struct xhci_slot_ctx *slot_ctx; -- struct xhci_ring *ep_ring; - u32 trb_comp_code; - u32 remaining, requested, ep_trb_len; - - slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); -- ep_ring = xhci_dma_to_transfer_ring(ep, le64_to_cpu(event->buffer)); - trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); - remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); - ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); -@@ -2404,7 +2533,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td, - remaining); - td->urb->actual_length = 0; - } -- return finish_td(xhci, td, event, ep); -+ return finish_td(xhci, ep, ep_ring, td, trb_comp_code); - } - - /* -@@ -2415,7 +2544,6 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td, +@@ -2432,7 +2564,6 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, static int handle_tx_event(struct xhci_hcd *xhci, struct xhci_transfer_event *event) { @@ -1597587,7 +1597494,7 @@ index b69b8c7e7966..78345e425264 struct xhci_virt_ep *ep; struct xhci_ring *ep_ring; unsigned int slot_id; -@@ -2442,9 +2570,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, +@@ -2459,9 +2590,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, goto err_out; } @@ -1597598,7 +1597505,7 @@ index b69b8c7e7966..78345e425264 if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_DISABLED) { xhci_err(xhci, -@@ -2522,7 +2649,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, +@@ -2539,7 +2669,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, case COMP_STALL_ERROR: xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, ep_index); @@ -1597606,22 +1597513,7 @@ index b69b8c7e7966..78345e425264 status = -EPIPE; break; case COMP_SPLIT_TRANSACTION_ERROR: -@@ -2755,11 +2881,11 @@ static int handle_tx_event(struct xhci_hcd *xhci, - - /* update the urb's actual_length and give back to the core */ - if (usb_endpoint_xfer_control(&td->urb->ep->desc)) -- process_ctrl_td(xhci, td, ep_trb, event, ep); -+ process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); - else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) -- process_isoc_td(xhci, td, ep_trb, event, ep); -+ process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); - else -- process_bulk_intr_td(xhci, td, ep_trb, event, ep); -+ process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); - cleanup: - handling_skipped_tds = ep->skip && - trb_comp_code != COMP_MISSED_SERVICE_ERROR && -@@ -2800,10 +2926,11 @@ static int handle_tx_event(struct xhci_hcd *xhci, +@@ -2848,10 +2977,11 @@ static int handle_tx_event(struct xhci_hcd *xhci, * Returns >0 for "possibly more events to process" (caller should call again), * otherwise 0 if done. In future, <0 returns should indicate error code. */ @@ -1597634,7 +1597526,7 @@ index b69b8c7e7966..78345e425264 int ret; /* Event ring hasn't been allocated yet. */ -@@ -2825,31 +2952,30 @@ static int xhci_handle_event(struct xhci_hcd *xhci) +@@ -2873,31 +3003,30 @@ static int xhci_handle_event(struct xhci_hcd *xhci) * speculative reads of the event's flags/data below. */ rmb(); @@ -1597676,7 +1597568,7 @@ index b69b8c7e7966..78345e425264 } /* Any of the above functions may drop and re-acquire the lock, so check * to make sure a watchdog timer didn't mark the host as non-responsive. -@@ -2869,13 +2995,14 @@ static int xhci_handle_event(struct xhci_hcd *xhci) +@@ -2917,13 +3046,14 @@ static int xhci_handle_event(struct xhci_hcd *xhci) */ return 1; } @@ -1597692,7 +1597584,7 @@ index b69b8c7e7966..78345e425264 union xhci_trb *event_ring_deq) { u64 temp_64; -@@ -2905,6 +3032,16 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, +@@ -2953,6 +3083,16 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, temp_64 |= ERST_EHB; xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); } @@ -1597709,7 +1597601,7 @@ index b69b8c7e7966..78345e425264 /* * xHCI spec says we can get an interrupt, and if the HC has an error condition, -@@ -2940,6 +3077,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) +@@ -2988,6 +3128,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) goto out; } @@ -1597720,7 +1597612,7 @@ index b69b8c7e7966..78345e425264 /* * Clear the op reg interrupt status first, * so we can receive interrupts from other MSI-X interrupters. -@@ -3032,6 +3173,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, +@@ -3080,6 +3224,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, u32 ep_state, unsigned int num_trbs, gfp_t mem_flags) { unsigned int num_trbs_needed; @@ -1597728,7 +1597620,7 @@ index b69b8c7e7966..78345e425264 /* Make sure the endpoint has been added to xHC schedule */ switch (ep_state) { -@@ -3102,7 +3244,19 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, +@@ -3150,7 +3295,19 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, ep_ring->enq_seg = ep_ring->enq_seg->next; ep_ring->enqueue = ep_ring->enq_seg->trbs; @@ -1597738,17 +1597630,17 @@ index b69b8c7e7966..78345e425264 + xhci_warn(xhci, "Ring is an endless link TRB loop\n"); + return -EINVAL; + } - } ++ } + + if (last_trb_on_seg(ep_ring->enq_seg, ep_ring->enqueue)) { + xhci_warn(xhci, "Missing link TRB at end of ring segment\n"); + return -EINVAL; -+ } + } + return 0; } -@@ -3121,7 +3275,8 @@ static int prepare_transfer(struct xhci_hcd *xhci, +@@ -3169,7 +3326,8 @@ static int prepare_transfer(struct xhci_hcd *xhci, struct xhci_ring *ep_ring; struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); @@ -1597758,68 +1597650,15 @@ index b69b8c7e7966..78345e425264 if (!ep_ring) { xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", stream_id); -@@ -3490,7 +3645,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - field |= TRB_IOC; - more_trbs_coming = false; - td->last_trb = ring->enqueue; -- -+ td->last_trb_seg = ring->enq_seg; - if (xhci_urb_suitable_for_idt(urb)) { - memcpy(&send_addr, urb->transfer_buffer, - trb_buff_len); -@@ -3516,7 +3671,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - upper_32_bits(send_addr), - length_field, - field); -- -+ td->num_trbs++; - addr += trb_buff_len; - sent_len = trb_buff_len; - -@@ -3540,8 +3695,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - ep_index, urb->stream_id, - 1, urb, 1, mem_flags); - urb_priv->td[1].last_trb = ring->enqueue; -+ urb_priv->td[1].last_trb_seg = ring->enq_seg; - field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; - queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); -+ urb_priv->td[1].num_trbs++; - } - - check_trb_math(urb, enqd_len); -@@ -3592,6 +3749,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, +@@ -3488,6 +3646,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, + need_zero_pkt = true; - urb_priv = urb->hcpriv; td = &urb_priv->td[0]; + td->num_trbs = num_trbs; /* * Don't give the first TRB to the hardware (by toggling the cycle bit) -@@ -3664,6 +3822,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - - /* Save the DMA address of the last TRB in the TD */ - td->last_trb = ep_ring->enqueue; -+ td->last_trb_seg = ep_ring->enq_seg; - - /* Queue status TRB - see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 */ - /* If the device sent data, the status stage is an OUT transfer */ -@@ -3908,6 +4067,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - goto cleanup; - } - td = &urb_priv->td[i]; -+ td->num_trbs = trbs_per_td; - - /* use SIA as default, if frame id is used overwrite it */ - sia_frame_id = TRB_SIA; -@@ -3951,6 +4111,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, - } else { - more_trbs_coming = false; - td->last_trb = ep_ring->enqueue; -+ td->last_trb_seg = ep_ring->enq_seg; - field |= TRB_IOC; - if (trb_block_event_intr(xhci, num_tds, i)) - field |= TRB_BEI; -@@ -4233,71 +4394,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, +@@ -4286,71 +4445,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, return queue_command(xhci, cmd, 0, 0, 0, trb_slot_id | trb_ep_index | type | trb_suspend, false); } @@ -1598348,7 +1598187,7 @@ index c7749f6e3474..06243f940bd4 /* Nec vendor-specific command completion event. */ #define TRB_NEC_CMD_COMP 48 /* Get NEC firmware revision. */ -@@ -1542,17 +1542,27 @@ struct xhci_segment { +@@ -1542,10 +1542,18 @@ struct xhci_segment { unsigned int bounce_len; }; @@ -1598367,16 +1598206,7 @@ index c7749f6e3474..06243f940bd4 struct urb *urb; struct xhci_segment *start_seg; union xhci_trb *first_trb; - union xhci_trb *last_trb; -+ struct xhci_segment *last_trb_seg; - struct xhci_segment *bounce_seg; - /* actual_length of the URB has already been set */ - bool urb_length_set; -+ unsigned int num_trbs; - }; - - /* xHCI command default timeout value */ -@@ -1564,13 +1574,6 @@ struct xhci_cd { +@@ -1567,13 +1575,6 @@ struct xhci_cd { union xhci_trb *cmd_trb; }; @@ -1598390,7 +1598220,7 @@ index c7749f6e3474..06243f940bd4 enum xhci_ring_type { TYPE_CTRL = 0, TYPE_ISOC, -@@ -1923,6 +1926,7 @@ struct xhci_hcd { +@@ -1926,6 +1927,7 @@ struct xhci_hcd { struct list_head regset_list; void *dbc; @@ -1598398,7 +1598228,7 @@ index c7749f6e3474..06243f940bd4 /* platform-specific data -- must come last */ unsigned long priv[] __aligned(sizeof(s64)); }; -@@ -1932,8 +1936,15 @@ struct xhci_driver_overrides { +@@ -1935,8 +1937,15 @@ struct xhci_driver_overrides { size_t extra_priv_size; int (*reset)(struct usb_hcd *hcd); int (*start)(struct usb_hcd *hcd); @@ -1598414,7 +1598244,7 @@ index c7749f6e3474..06243f940bd4 int (*update_hub_device)(struct usb_hcd *hcd, struct usb_device *hdev, struct usb_tt *tt, gfp_t mem_flags); }; -@@ -2062,10 +2073,6 @@ void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, +@@ -2065,10 +2074,6 @@ void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, struct xhci_ring *xhci_dma_to_transfer_ring( struct xhci_virt_ep *ep, u64 address); @@ -1598425,7 +1598255,7 @@ index c7749f6e3474..06243f940bd4 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, bool allocate_completion, gfp_t mem_flags); struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci, -@@ -2090,8 +2097,13 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); +@@ -2093,8 +2098,13 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); void xhci_shutdown(struct usb_hcd *hcd); void xhci_init_driver(struct hc_driver *drv, const struct xhci_driver_overrides *over); @@ -1598439,7 +1598269,7 @@ index c7749f6e3474..06243f940bd4 int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, struct usb_tt *tt, gfp_t mem_flags); int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id); -@@ -2141,13 +2153,6 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, +@@ -2144,13 +2154,6 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, enum xhci_ep_reset_type reset_type); int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, u32 slot_id); @@ -1598453,7 +1598283,7 @@ index c7749f6e3474..06243f940bd4 void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, unsigned int stream_id, struct xhci_td *td); -@@ -2208,6 +2213,53 @@ static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, +@@ -2211,6 +2214,53 @@ static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, urb->stream_id); } -- Gitee