Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4737222ioa; Wed, 27 Apr 2022 10:00:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkKgHzc0mKjLRFwLKcGsfWKFB9QqOdIYh0gJDTMGDGUTmUhBThwaGkMoCpFuuLFlHjiZnX X-Received: by 2002:a17:903:2002:b0:15c:686f:da1a with SMTP id s2-20020a170903200200b0015c686fda1amr27172972pla.30.1651078841571; Wed, 27 Apr 2022 10:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651078841; cv=none; d=google.com; s=arc-20160816; b=dcGLwe8XXVycYezruZdcRM6asYmR/1GLw4lw7JAY0hsZSOSSIh+c1vTBjWM5AnVkqf EjHQJayimPM5CxRoFwrgDJdkU3Rv54vdIpN+lQvLTDIIT9YdQuBHfjVoHUmz4vxhjGeg ylL8qigJGJ38tlwSOfIA4RaE4hvCfpptLMAnLbM0k/nHnq1p1aFurntPIz9IyU8gS1mA dLFdBy/4OZjNkRviBdagOVswCgfN1hRLwN7mVZjpDQD8OXaoPwlVL/t0Nj0Lm9UyXYyd qtPv1LcdcmcbMsXQ5sGoNLfTOVoeYog004lb003+WVkIqr9asnBOdB8CzvpKQknBcVDv ldDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=H6OJ3zpVzkOf1MZ5z3ZFWq2AGJ4nvgaqjw9EGmqNnNA=; b=MwnPuytgomQCfHNPut/pBH7x9QmH1tT73JkuOSA5h0duUYGwaADvXIVrxxouMq9153 428uP8VTv6mAAIjmog9/S1LZoy0se03Kz31Puabdt2e9IwPI1li8lIrR3f4iVBa559iQ i3I0gFstpA1v7BhGZSrXiJsyFZW7tEzaJbGzCAmVHIRKqQmYYbzdVBYrLdGhWOuMKSiv JbPpPLpiP6cApqAdYQkbuT+W9wWNvk2FQg6Xu7Nx0p11arVq6yxxPyuNFJKfuFiSsiAi FFfVM1K8T2y1/VcCxC0SVKwERtldlHpTiQTmcjI3b8XSN9Hhm9hBGX2xvtCx6Lp/N7Ag weEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jU0eryoM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s6-20020a170902ea0600b001582e0ac939si2231685plg.450.2022.04.27.10.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 10:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jU0eryoM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A07FD4D27C; Wed, 27 Apr 2022 09:30:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243537AbiD0QcT (ORCPT + 99 others); Wed, 27 Apr 2022 12:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243385AbiD0QcK (ORCPT ); Wed, 27 Apr 2022 12:32:10 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C51373F320; Wed, 27 Apr 2022 09:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651076866; x=1682612866; h=to:cc:references:from:subject:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=CPMjo6U9PUtaGVa14pO3sunqUrDh79MQUPdvmaVu8cw=; b=jU0eryoMSnwcYapAxLMjSKRkRC3kQQS7YfZGBMI2pApcKN8IbGoXiG4D GB2leEQdH8+jU2kNx06EHwOwbPPcHVtlaEwtTFf0s4cRUeaCFFvlR00lx FHHEu9N0aVlSO/fWg1uLD5JnVTJIypV/UvUJqQ0uo2Z5kfhM4qKT37+Jr 7+FXZpCt53t4awT6mTRekMbAq51f/duCHKJsqZgvJhWf4f63IfP+s6jHd 9TXyzHc5taI87pG23dgH2KaijOFUOx+XOe8HZ0/rXOgU/Njnj5U/oah1e XDO27ggkrHirf4MN3z+cc4sy8hNgLZbPpVW2qlXqkf1LyEkycPgxAxSUA Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10330"; a="253372372" X-IronPort-AV: E=Sophos;i="5.90,293,1643702400"; d="scan'208";a="253372372" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2022 09:23:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,293,1643702400"; d="scan'208";a="876729017" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.199]) ([10.237.72.199]) by fmsmga005.fm.intel.com with ESMTP; 27 Apr 2022 09:23:22 -0700 To: Daehwan Jung , Mathias Nyman , Greg Kroah-Hartman Cc: "open list:USB XHCI DRIVER" , open list , Howard Yen , Jack Pham , Puma Hsu , "J . Avila" , sc.suh@samsung.com, Krzysztof Kozlowski References: <1650964728-175347-1-git-send-email-dh10.jung@samsung.com> <1650964728-175347-6-git-send-email-dh10.jung@samsung.com> From: Mathias Nyman Subject: Re: [PATCH v4 5/5] usb: host: add xhci-exynos driver Message-ID: Date: Wed, 27 Apr 2022 19:25:21 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <1650964728-175347-6-git-send-email-dh10.jung@samsung.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26.4.2022 12.18, Daehwan Jung wrote: > This driver is for Samsung Exynos xhci host conroller. It uses xhci-plat > driver mainly and extends some functions by xhci hooks and overrides. > > It supports USB Audio offload with Co-processor. It only cares DCBAA, > Device Context, Transfer Ring, Event Ring, and ERST. They are allocated > on specific address with xhci hooks. Co-processor could use them directly > without xhci driver after then. > > Signed-off-by: Daehwan Jung I have to agree with Krzysztof's comments, this is an odd driver stub. Perhaps open up a bit how the Exynos offloading works so we can figure out in more detail what the hardware needs from software. (...) > + > +static void xhci_exynos_alloc_container_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, > + int type, gfp_t flags) > +{ > + /* Only first Device Context uses URAM */ > + int i; > + > + ctx->bytes = ioremap(EXYNOS_URAM_DEVICE_CTX_ADDR, EXYNOS_URAM_CTX_SIZE); > + if (!ctx->bytes) > + return; > + > + for (i = 0; i < EXYNOS_URAM_CTX_SIZE; i++) > + ctx->bytes[i] = 0; > + > + ctx->dma = EXYNOS_URAM_DEVICE_CTX_ADDR; This can't work with more than one USB device. This hardcodes the same context address for every usb device. > +static void xhci_exynos_parse_endpoint(struct xhci_hcd *xhci, struct usb_device *udev, > + struct usb_endpoint_descriptor *desc, struct xhci_container_ctx *ctx) > +{ > + struct xhci_plat_priv *priv = xhci_to_priv(xhci); > + struct xhci_hcd_exynos *xhci_exynos = priv->vendor_priv; > + struct usb_endpoint_descriptor *d = desc; > + unsigned int ep_index; > + struct xhci_ep_ctx *ep_ctx; > + > + ep_index = xhci_get_endpoint_index(d); > + ep_ctx = xhci_get_ep_ctx(xhci, ctx, ep_index); > + > + if ((d->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == > + USB_ENDPOINT_XFER_ISOC) { > + if (d->bEndpointAddress & USB_ENDPOINT_DIR_MASK) > + xhci_exynos->in_ep = d->bEndpointAddress; > + else > + xhci_exynos->out_ep = d->bEndpointAddress; > + } This won't work if more than one device that has isoc endpoints, or even if that device has more than one in/out isoc endpoint pair. > +static int xhci_alloc_segments_for_ring_uram(struct xhci_hcd *xhci, > + struct xhci_segment **first, struct xhci_segment **last, > + unsigned int num_segs, unsigned int cycle_state, > + enum xhci_ring_type type, unsigned int max_packet, gfp_t flags, > + u32 endpoint_type) > +{ > + struct xhci_segment *prev; > + bool chain_links = false; > + > + while (num_segs > 0) { > + struct xhci_segment *next = NULL; > + > + if (!next) { > + prev = *first; > + while (prev) { > + next = prev->next; > + xhci_segment_free(xhci, prev); > + prev = next; > + } > + return -ENOMEM; This always return -ENOMEM Also this whole function never allocates or remaps any memory. > + } > + xhci_link_segments(prev, next, type, chain_links); > + > + prev = next; > + num_segs--; > + } > + xhci_link_segments(prev, *first, type, chain_links); > + *last = prev; > + > + return 0; > +} > + > +static struct xhci_ring *xhci_ring_alloc_uram(struct xhci_hcd *xhci, > + unsigned int num_segs, unsigned int cycle_state, > + enum xhci_ring_type type, unsigned int max_packet, gfp_t flags, > + u32 endpoint_type) > +{ > + struct xhci_ring *ring; > + int ret; > + struct device *dev = xhci_to_hcd(xhci)->self.sysdev; > + > + ring = kzalloc_node(sizeof(*ring), flags, dev_to_node(dev)); > + if (!ring) > + return NULL; > + > + ring->num_segs = num_segs; > + ring->bounce_buf_len = max_packet; > + INIT_LIST_HEAD(&ring->td_list); > + ring->type = type; > + if (num_segs == 0) > + return ring; > + > + ret = xhci_alloc_segments_for_ring_uram(xhci, &ring->first_seg, > + &ring->last_seg, num_segs, cycle_state, type, > + max_packet, flags, endpoint_type); > + if (ret) > + goto fail; > + > + /* Only event ring does not use link TRB */ > + if (type != TYPE_EVENT) { > + /* See section 4.9.2.1 and 6.4.4.1 */ > + ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= > + cpu_to_le32(LINK_TOGGLE); No memory was allocated for trbs A lot of this code seems to exists just to avoid xhci driver from allocating dma capable memory, we can refactor the existing xhci_mem_init() and move dcbaa and event ring allocation and other code to their own overridable functions. This way we can probably get rid of a lot of the code in this series. Thanks Mathias