Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4595991yba; Tue, 30 Apr 2019 00:43:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkbrx/EQulrDGxbyfNcC5ZzgT+Lhdkg4zzgv3U0l6uFKuz7AU+0zS0PDUe5B9KPDsGlc+Z X-Received: by 2002:a63:3fc1:: with SMTP id m184mr30383091pga.222.1556610234381; Tue, 30 Apr 2019 00:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556610234; cv=none; d=google.com; s=arc-20160816; b=xi6Dp3RR6OMvi9ZdHXOu2mqdKGd4Xvp3DYtqsBNb328LYnhzV4xOeiKu/JnPc/HAOR P55UrLaVZDYuI+zn6oK4tFG+8hJw/IrgcOW4NVjf6mZQyrLC7jwL4Od/9SToethf9o2V 5jPNx6ebPgBc3XUvzYNddGO0Cy+l9sFNUF8VGubiZIjGDlYgmRVtP1Pqg+mEHpMonaAJ iKk2KmKteyv7rmk/kSuNnILeCmCntr7+5TqXAKK2KhlGjnOXyMRjPQ35tlIRvwd+fLHe 6+PSYpBl4XVgM0kiwwW/RCfiv1PnzWg6cxqUBu0aILj1o4gtUOwJOyRNse4oWo4Phxh1 1+jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ubQSIm/VPg6Dp6w2ARqE2zaEsG18x/cDQfZkX9QYX80=; b=lwd8tH/sJtm0Lk830qdGW7+hJbvJ3oMv8wCUhm5Auyiuhsyx60/vaD7rZDfFcw+SBM K75klW2RMJr2ba5DKLFBQh4tKkqE+r7mMSjxYWojrYBTA5t6oS8jno5QYC3eGQ2mNE5A 4TibbDh4agQaHYj9w5CJUVBh51cm8s7uALFa7z982Leq68pjiWu1BkHi/5rBqeg3/f4s 1Qdo+NuAc7ZnfmcQsQQWM93zOLvndYOBNz6iv/cGsPVg4R2KFcSaYPUccCp55U7a7dEv fuL8IrkzwKI6m9zYVeK5Q8Y5+ey9LytIEPNcDDOFH7/gi3mQ8fFCM2W8i65dB4LcFwwi c0zQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si581566pld.322.2019.04.30.00.43.39; Tue, 30 Apr 2019 00:43:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726145AbfD3HmZ (ORCPT + 99 others); Tue, 30 Apr 2019 03:42:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbfD3HmZ (ORCPT ); Tue, 30 Apr 2019 03:42:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAFCB46202; Tue, 30 Apr 2019 07:42:24 +0000 (UTC) Received: from localhost (unknown [10.43.2.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 389875DD6F; Tue, 30 Apr 2019 07:42:22 +0000 (UTC) From: Stanislaw Gruszka To: linux-wireless@vger.kernel.org Cc: Felix Fietkau , Lorenzo Bianconi Subject: [PATCH] mt76: usb: use EP max packet aligned buffer sizes for rx Date: Tue, 30 Apr 2019 09:42:19 +0200 Message-Id: <20190430074219.8495-1-sgruszka@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 30 Apr 2019 07:42:24 +0000 (UTC) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org If buffer size is not usb_endpoint_maxp (512 or 1024 bytes) multiple, usb host driver has to use bounce buffer and copy data. For RX we can avoid that since we alreay allocate q->buf_size (2kB) buffers and mt76usb hardware will not fill more data as rx packet size is limited by network protocol. However add error message if this assumption somehow will be not true. Signed-off-by: Stanislaw Gruszka --- drivers/net/wireless/mediatek/mt76/usb.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index c299c6591072..025e072cff28 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -286,7 +286,6 @@ static int mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb, int nsgs, gfp_t gfp) { - int sglen = SKB_WITH_OVERHEAD(q->buf_size); int i; for (i = 0; i < nsgs; i++) { @@ -300,7 +299,7 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb, page = virt_to_head_page(data); offset = data - page_address(page); - sg_set_page(&urb->sg[i], page, sglen, offset); + sg_set_page(&urb->sg[i], page, q->buf_size, offset); } if (i < nsgs) { @@ -312,7 +311,7 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb, } urb->num_sgs = max_t(int, i, urb->num_sgs); - urb->transfer_buffer_length = urb->num_sgs * sglen, + urb->transfer_buffer_length = urb->num_sgs * q->buf_size, sg_init_marker(urb->sg, urb->num_sgs); return i ? : -ENOMEM; @@ -326,7 +325,7 @@ mt76u_refill_rx(struct mt76_dev *dev, struct urb *urb, int nsgs, gfp_t gfp) if (dev->usb.sg_en) { return mt76u_fill_rx_sg(dev, q, urb, nsgs, gfp); } else { - urb->transfer_buffer_length = SKB_WITH_OVERHEAD(q->buf_size); + urb->transfer_buffer_length = q->buf_size; urb->transfer_buffer = page_frag_alloc(&q->rx_page, q->buf_size, gfp); return urb->transfer_buffer ? 0 : -ENOMEM; @@ -447,8 +446,10 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) return 0; data_len = min_t(int, len, data_len - MT_DMA_HDR_LEN); - if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) + if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) { + dev_err(dev->dev, "rx data too big %d\n", data_len); return 0; + } skb = build_skb(data, q->buf_size); if (!skb) -- 2.20.1