Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6328875pxb; Wed, 17 Feb 2021 01:17:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1KnKsDchJDoTw0JgLi2CzQXDJvbFA+KjQI3y1zpOKUvcxtP+D7OBMRHAZaRIkPZZnr99B X-Received: by 2002:a50:ee16:: with SMTP id g22mr14718472eds.235.1613553423408; Wed, 17 Feb 2021 01:17:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613553423; cv=none; d=google.com; s=arc-20160816; b=jhG2fsFbCyqi+g86fzXGK+6OhDkeWHGtQDuaZkqE3ZzQGQSlXUoaflOuej5s6NJZu4 rZtUFF3rFf9RVeE9TWKOS7C1bUfhyLA5NRFsw50Kl+LmqHgb4ZyCnZa6CUjUgyH+WVFo CbdPwnS1G7vZ9Ot1TQfB2YaIit8B2UUF5AZ+0N2U1OTChjGnFRvgi5I1NV9tcddqApGm VDLGOHqM+tXnXji7B+vUD4ybmxgXlpXfGD5L8rTBKJnAUOkkvejjFkEwZBOgNfwiAeyq 9jOx9+jZ5jSFCLMlnpCHKHKfz9TFxFEeoXSRuRKOAgFL0vrM+SGDhYQkEHDIzWL44aRQ 044Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=l6Yd12JB9YRXAov0DNcI714LgvmJxqaENy/RzQoUlMI=; b=HDedQCrm7+jCnDZ8Im1xZeAfEqK2Hkp6jCnPpZEZmYeWiKhTn68ZhyqhB0rXh/kzOE VmdTccC/480Rff2/g/zc4U96FLQXp1Ar/FDCOPft3TXk3TlILkI3kMjwFV/p4TlgZQoM WyL8hnOJXmxuZi/gibAEhp7QOLVeX+O2lo+JEwOfuiYTInuDKaax9pO17M1YUKZ3PI1i hlw4GnIFTJY4al1iihIfNQyyEdrAMXk9nIl935Hu3PB2YMYpfp2w7gT9UgOGyFWAPNhO Qj44jLYLuZt7bc328w2WRPyjYaRXuYSQgmEny+5pMJMHnkFAyu8xypJo+7KnmzuRKpBY IaAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si920499edn.568.2021.02.17.01.16.40; Wed, 17 Feb 2021 01:17:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbhBQIeV (ORCPT + 99 others); Wed, 17 Feb 2021 03:34:21 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:52376 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231871AbhBQIdq (ORCPT ); Wed, 17 Feb 2021 03:33:46 -0500 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11H8ULvX026114; Wed, 17 Feb 2021 03:32:54 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 36p9gb2huk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Feb 2021 03:32:54 -0500 Received: from SCSQMBX10.ad.analog.com (SCSQMBX10.ad.analog.com [10.77.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 11H8WqGp055869 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 17 Feb 2021 03:32:53 -0500 Received: from SCSQCASHYB7.ad.analog.com (10.77.17.133) by SCSQMBX10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.721.2; Wed, 17 Feb 2021 00:32:51 -0800 Received: from SCSQMBX10.ad.analog.com (10.77.17.5) by SCSQCASHYB7.ad.analog.com (10.77.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.721.2; Wed, 17 Feb 2021 00:32:50 -0800 Received: from zeus.spd.analog.com (10.66.68.11) by scsqmbx10.ad.analog.com (10.77.17.5) with Microsoft SMTP Server id 15.2.721.2 via Frontend Transport; Wed, 17 Feb 2021 00:32:50 -0800 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 11H8WWlH007757; Wed, 17 Feb 2021 03:32:47 -0500 From: Alexandru Ardelean To: , CC: , , , , , Alexandru Ardelean Subject: [PATCH v2 3/5] iio: kfifo-buffer: Add output buffer support Date: Wed, 17 Feb 2021 10:34:36 +0200 Message-ID: <20210217083438.37865-4-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210217083438.37865-1-alexandru.ardelean@analog.com> References: <20210217083438.37865-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Type: text/plain X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-02-17_06:2021-02-16,2021-02-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 clxscore=1015 mlxscore=0 priorityscore=1501 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102170064 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen Add output buffer support to the kfifo buffer implementation. The implementation is straight forward and mostly just wraps the kfifo API to provide the required operations. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean --- drivers/iio/buffer/kfifo_buf.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c index 34289ce12f20..e8a434f84778 100644 --- a/drivers/iio/buffer/kfifo_buf.c +++ b/drivers/iio/buffer/kfifo_buf.c @@ -138,10 +138,60 @@ static void iio_kfifo_buffer_release(struct iio_buffer *buffer) kfree(kf); } +static size_t iio_kfifo_buf_space_available(struct iio_buffer *r) +{ + struct iio_kfifo *kf = iio_to_kfifo(r); + size_t avail; + + mutex_lock(&kf->user_lock); + avail = kfifo_avail(&kf->kf); + mutex_unlock(&kf->user_lock); + + return avail; +} + +static int iio_kfifo_remove_from(struct iio_buffer *r, void *data) +{ + int ret; + struct iio_kfifo *kf = iio_to_kfifo(r); + + if (kfifo_size(&kf->kf) < r->bytes_per_datum) + return -EBUSY; + + ret = kfifo_out(&kf->kf, data, r->bytes_per_datum); + if (ret != r->bytes_per_datum) + return -EBUSY; + + wake_up_interruptible_poll(&r->pollq, POLLOUT | POLLWRNORM); + + return 0; +} + +static int iio_kfifo_write(struct iio_buffer *r, size_t n, + const char __user *buf) +{ + struct iio_kfifo *kf = iio_to_kfifo(r); + int ret, copied; + + mutex_lock(&kf->user_lock); + if (!kfifo_initialized(&kf->kf) || n < kfifo_esize(&kf->kf)) + ret = -EINVAL; + else + ret = kfifo_from_user(&kf->kf, buf, n, &copied); + mutex_unlock(&kf->user_lock); + if (ret) + return ret; + + return copied; +} + static const struct iio_buffer_access_funcs kfifo_access_funcs = { .store_to = &iio_store_to_kfifo, .read = &iio_read_kfifo, .data_available = iio_kfifo_buf_data_available, + .remove_from = &iio_kfifo_remove_from, + .write = &iio_kfifo_write, + .space_available = &iio_kfifo_buf_space_available, .request_update = &iio_request_update_kfifo, .set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo, .set_length = &iio_set_length_kfifo, -- 2.17.1