Received: by 10.192.165.148 with SMTP id m20csp3881824imm; Mon, 7 May 2018 22:12:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoa3xYVWk7wlSPR5aCWbCjwBR2KB9W+145Q/myJz+fQygtUFTYnGH6V0yH3KBK2AjFI+roB X-Received: by 10.98.5.129 with SMTP id 123mr25859663pff.38.1525756343393; Mon, 07 May 2018 22:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525756343; cv=none; d=google.com; s=arc-20160816; b=aFMcmRoccddx1lIcW8ez35rcMib04FecV7hob41QPaH0EtALC37sT7PynzY559KexR 9GC8kAFYNg3SB1syLxDdBNtsaJiOjVMsAEr0D+04A8ZfV7D70UPgQuxbsQOZEb/A7Ihq o4SHE1xnKiEcZEi4XLEy/QkjAEKcUO1hJObLdWSuKY/YR9/nAWzxNFMtCdD7GH2GjBGb Q/1WYcj8SjGxmwV+kV0Ft3c8fScngMPI9raqkTmzkASWH6c6btjdWmGiMkHcRYiLWLN5 h2X9rR3U/LKvdsQv0QQjkQTKdXrzjNF191LAZEmlXDzmjqjqyUyEA3FPCnPucwgffb8n /pjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ZXqwYJnxc3ywT4QhOjfDshYyp+N1RylSaPrOrFb35C8=; b=yQDk8l0TE3a5HcAkkCgtgh6r8d7dudvzi3JiJ79ceVmJ4nJHhIgV8TyZ7uLnJlZfkr Tr1QdEOg3nho7NfP7y0WmMy6rE3RAjRoIcd2GXKkanjtnVVHABWlI+3m9g6ayAnTXtaw dJfpJWB8IQeyfNCKEeWGLiRt86CeTeNfcF3pfj+cOrTDZC+/m77u/CJdBItdKsyWlX+i p48yWPoXaIXHCtHpkMhMV8J8iP7hi6ZPF7eUfl57Am2K6SxFtXox0wUn3QabraPVOK6n ncxLKjAnpsfjXM2QDfv2HGpEm/GfIPxzlGtaAGUnnXmoIOHDeZ3exc0AsUAdS5qmcpJL 5X6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SXZOoSWT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c20-v6si15299553pls.557.2018.05.07.22.12.08; Mon, 07 May 2018 22:12:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SXZOoSWT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbeEHFLr (ORCPT + 99 others); Tue, 8 May 2018 01:11:47 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:45573 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750745AbeEHFLq (ORCPT ); Tue, 8 May 2018 01:11:46 -0400 Received: by mail-vk0-f67.google.com with SMTP id 203-v6so18877679vka.12 for ; Mon, 07 May 2018 22:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ZXqwYJnxc3ywT4QhOjfDshYyp+N1RylSaPrOrFb35C8=; b=SXZOoSWTCzcqmc2pBT+4c3BHK3o6ONN329uW1MalFMcmBJRzRLvxMUeUnXnuWsKkRN Ci4SsLNFYT6F9aYUGGn1J+G7WEV2KuuZ/yL/62rBmJ5o70z8yhEDlEbqqmalFtqlXVrf qQd8ZcjkIc1wT0NWc9n0i79oSK2udO2I2Pil7YUcafAXroIKsObckBbLaxQlXtWHnvRP s9IPqQ3qfK29XMn0Ipp37vYamOdWINiXhTyhpo/e6fCmrWQHERyK5Lj4qHLXbdf2PJYL P0c/a5fYX5yYN9amTQ/eAdIUyU16mSJ6X4Po5DiyQvru3zXKmWTYJfV0r+3ny2Unosmx P9DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ZXqwYJnxc3ywT4QhOjfDshYyp+N1RylSaPrOrFb35C8=; b=I9v55lanvqXLB2NP2VkRyvv8EtYx8kRbu2IGBCy1HzmBL5v6hYre1PHrGzcSECMueW DXSGYHu8Ve0ueoWbXvHq+9xfR0S3eArqjz7YuZSTAeaCsYHBPwOVdbcF1dkfYdWj/7Zo p8vd8PNLqN1iLchMhNYntemejAFuAcVbkvzZnxVOnIk5Aa/zF9owOo2dskvDHDBR8Z4G SCoSlG2vqoMrpKlH7I4D8Mw1NHV1qPpcePxYA15qCx6tqGJ7V1APLoAv8BeuxHNhp3fl YZb5OyXLE0UmV/g7gewKHvXv5amKn33ew5Y+VxzkvlW1Pm7rOwzllFoMCqEhsKPysajj yBfA== X-Gm-Message-State: ALQs6tALfpOlBilwJUJ8DVJXw6UUpZxIJcZKGXIANKiNITXKKDdGe5v+ 0XF0kh17MdsVgDUS5/oxoDbMUtufKR2CTcADvi2t6w== X-Received: by 2002:a1f:c0c1:: with SMTP id q184-v6mr29376923vkf.144.1525756304664; Mon, 07 May 2018 22:11:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.48.82 with HTTP; Mon, 7 May 2018 22:11:43 -0700 (PDT) In-Reply-To: <1525748846-7767-2-git-send-email-william.wu@rock-chips.com> References: <1525748846-7767-1-git-send-email-william.wu@rock-chips.com> <1525748846-7767-2-git-send-email-william.wu@rock-chips.com> From: Doug Anderson Date: Mon, 7 May 2018 22:11:43 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] usb: dwc2: alloc dma aligned buffer for isoc split in To: William Wu Cc: hminas@synopsys.com, felipe.balbi@linux.intel.com, Greg Kroah-Hartman , Sergei Shtylyov , =?UTF-8?Q?Heiko_St=C3=BCbner?= , LKML , linux-usb@vger.kernel.org, "open list:ARM/Rockchip SoC..." , Frank Wang , =?UTF-8?B?6buE5rab?= , "daniel.meng" , John Youn , =?UTF-8?B?546L5b6B5aKe?= , zsq@rock-chips.com, =?UTF-8?B?6Kix5ZiJ6YqY?= , Stan Tsui , =?UTF-8?B?U3BydWNlIFd1ICjlkLPlu7rli7Mp?= , Martin.Tsai@quantatw.com, Kevin.Shai@quantatw.com, =?UTF-8?B?TW9uLUplciBXdSAo5ZCz5a2f5ZOyKQ==?= , =?UTF-8?B?Q2xhdWQgQ2hhbmcgKOW8teaBreeviSk=?= , =?UTF-8?B?U2FuIExpbiAo5p6X5bu66I+xKQ==?= , Ren.Kuo@quantatw.com, "David H.T. Wang" , Fong Lin , Steven Cheng , Tom Chen , donchang@aopen.com, milesschofield@aopen.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, May 7, 2018 at 8:07 PM, William Wu wrote: > +static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg, > + struct dwc2_qh *qh, > + struct dwc2_host_chan *chan) > +{ > + if (!hsotg->unaligned_cache) > + return -ENOMEM; > + > + if (!qh->dw_align_buf) { > + qh->dw_align_buf = kmem_cache_alloc(hsotg->unaligned_cache, > + GFP_ATOMIC | GFP_DMA); > + if (!qh->dw_align_buf) > + return -ENOMEM; > + > + qh->dw_align_buf_size = min_t(u32, chan->max_packet, > + DWC2_KMEM_UNALIGNED_BUF_SIZE); Rather than using min_t, wouldn't it be better to return -ENOMEM if "max_packet" > DWC2_KMEM_UNALIGNED_BUF_SIZE? As it is, you might allocate less space than you need, right? That seems like it would be bad (even though this is probably impossible). > @@ -2797,6 +2837,32 @@ static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) > /* Set the transfer attributes */ > dwc2_hc_init_xfer(hsotg, chan, qtd); > > + /* For non-dword aligned buffers */ > + if (hsotg->params.host_dma && qh->do_split && > + chan->ep_is_in && (chan->xfer_dma & 0x3)) { > + dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); > + if (dwc2_alloc_split_dma_aligned_buf(hsotg, qh, chan)) { > + dev_err(hsotg->dev, > + "Failed to allocate memory to handle non-aligned buffer\n"); > + /* Add channel back to free list */ > + chan->align_buf = 0; > + chan->multi_count = 0; > + list_add_tail(&chan->hc_list_entry, > + &hsotg->free_hc_list); > + qtd->in_process = 0; > + qh->channel = NULL; > + return -ENOMEM; > + } > + } else { > + /* > + * We assume that DMA is always aligned in non-split > + * case or split out case. Warn if not. > + */ > + WARN_ON_ONCE(hsotg->params.host_dma && > + (chan->xfer_dma & 0x3)); > + chan->align_buf = 0; > + } > + > if (chan->ep_type == USB_ENDPOINT_XFER_INT || > chan->ep_type == USB_ENDPOINT_XFER_ISOC) > /* > @@ -5241,6 +5307,17 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) > hsotg->params.dma_desc_enable = false; > hsotg->params.dma_desc_fs_enable = false; > } > + } else if (hsotg->params.host_dma) { Are you sure this is "else if"? Can't you have descriptor DMA enabled in the controller and still need to do a normal DMA transfer if you plug in a hub? Seems like this should be just "if". > + /* > + * Create kmem caches to handle non-aligned buffer > + * in Buffer DMA mode. > + */ > + hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma", > + DWC2_KMEM_UNALIGNED_BUF_SIZE, 4, Worth using "DWC2_USB_DMA_ALIGN" rather than 4? > + SLAB_CACHE_DMA, NULL); > + if (!hsotg->unaligned_cache) > + dev_err(hsotg->dev, > + "unable to create dwc2 unaligned cache\n"); > } > > hsotg->otg_port = 1; > @@ -5279,6 +5356,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) > error4: > kmem_cache_destroy(hsotg->desc_gen_cache); > kmem_cache_destroy(hsotg->desc_hsisoc_cache); > + kmem_cache_destroy(hsotg->unaligned_cache); nitty nit: freeing order should be opposite of allocation, so the new line should be above the other two.