From: Jonathan Cameron <jic23@kernel.org>
To: Vasileios Amoiridis <vassilisamir@gmail.com>
Cc: lars@metafoo.de, himanshujha199640@gmail.com,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Catalin Marinas <catalin.marinas@arm.com>
Subject: Re: [PATCH v1 11/17] iio: chemical: bme680: Use bulk reads for calibration data
Date: Thu, 6 Jun 2024 20:36:03 +0100 [thread overview]
Message-ID: <20240606203603.18e9a17b@jic23-huawei> (raw)
In-Reply-To: <20240603203003.GA444780@vamoiridPC>
On Mon, 3 Jun 2024 22:30:03 +0200
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> On Mon, Jun 03, 2024 at 08:25:37PM +0100, Jonathan Cameron wrote:
> > On Sun, 2 Jun 2024 21:30:23 +0200
> > Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> >
> > > On Sun, Jun 02, 2024 at 01:57:26PM +0100, Jonathan Cameron wrote:
> > > > On Mon, 27 May 2024 20:37:59 +0200
> > > > Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> > > >
> > > > > Calibration data are located in contiguous-ish registers
> > > > > inside the chip. For that reason we can use bulk reads as is
> > > > > done as well in the BME68x Sensor API [1].
> > > > >
> > > > > The arrays that are used for reading the data out of the sensor
> > > > > are located inside DMA safe buffer.
> > > >
> > > > See below. I think in this case that isn't necessary.
> > > > However it's a quirk of how the custom regmap works. Whilst
> > > > we can't rely on regmap core spi implementations continuing to
> > > > bounce buffer, we can rely on one local to our particular driver.
> > > >
> > >
> > > What about the I2C implementation though? I watched recently a video
> > > from Wolfram Sang [1] and as far as I understood, the buffers are not
> > > provided by the I2C API, but you have to provide them. In any case, I
> > > should maybe check both SPI and I2C reads to understand the internals.
> > >
> > > [1]: https://www.youtube.com/watch?v=JDwaMClvV-s
> > >
> >
> > I'm not sure Wolfram got far with his desire for generally avoiding the
> > bounce buffers for i2c. I think it's strictly opt in only so don't opt in
> > unless your code is safe for it and regmap never will by default as too
> > many drivers will be subtly broken.
> >
>
> The things that I found about DMA "safety" in I2C are [1] and [2] so I think
> that the IIO_DMA_MINALIGN should remain because in the future, in case it's
> needed for triggered buffers to do buffer reads from the volatile registers
> of the device, then it might be a problem for I2C.
>
> [1]: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L2627
> [2]: https://elixir.bootlin.com/linux/latest/source/include/linux/i2c.h#L92
>
Those will remain opt in for a very long time if not for ever.
I suspect they will actually go away as a result of Catalin's
https://lore.kernel.org/linux-arm-kernel/20230612153201.554742-15-catalin.marinas@arm.com/
which bounces small or unaligned buffers and will apply to an annoying number of
IIO buffers even though they are actually safe because it's a heuristic
on the size part.
Today only a few architectures that do non coherent DMA use it though.
Will take the others opting in to the point where the config variable
goes away before we can stop this dance.
I don't know if anyone has yet looked at the impact on performance of that
change on the many drivers that have to work whether that is in place
or not and do small dma mappings. Maybe we need to teach bus drivers
when they need to map padding around an actually safe buffer that
doesn't look like it.
Jonathan
> >
> > > > >
> > > > > [1]: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L1769
> > > > > Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> > > >
> > > >
> > > > > diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
> > > > > index 681f271f9b06..ed4cdb4d64af 100644
> > > > > --- a/drivers/iio/chemical/bme680_core.c
> > > > > +++ b/drivers/iio/chemical/bme680_core.c
> > > >
> > > > > +
> > > > > struct bme680_calib {
> > > > > u16 par_t1;
> > > > > s16 par_t2;
> > > > > @@ -64,6 +109,16 @@ struct bme680_data {
> > > > > * and humidity compensation calculations.
> > > > > */
> > > > > s32 t_fine;
> > > > > +
> > > > > + /*
> > > > > + * DMA (thus cache coherency maintenance) may require the
> > > > > + * transfer buffers to live in their own cache lines.
> > > > > + */
> > > > > + union {
> > > > > + u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN];
> > > > > + u8 bme680_cal_buf_2[BME680_CALIB_RANGE_2_LEN];
> > > > > + u8 bme680_cal_buf_3[BME680_CALIB_RANGE_3_LEN];
> > > > > + } __aligned(IIO_DMA_MINALIGN);
> > > > Ah! I should have read ahead. I don't think you need this alignment forcing
> > > > because bme680_regmap_spi_read uses spi_write_then_read() which always
> > > > bounces the data.
> > > >
> > >
> > > Same comment. What about I2C?
> > >
> > > > > };
> > > > >
> > > > > static const struct regmap_range bme680_volatile_ranges[] = {
> > > > > @@ -112,217 +167,73 @@ static int bme680_read_calib(struct bme680_data *data,
> > > > > struct bme680_calib *calib)
> > > > > {
> > > >
> > > >
> > > > > + calib->par_h3 = data->bme680_cal_buf_2[H3];
> > > > > + calib->par_h4 = data->bme680_cal_buf_2[H4];
> > > > > + calib->par_h5 = data->bme680_cal_buf_2[H5];
> > > > > + calib->par_h6 = data->bme680_cal_buf_2[H6];
> > > > > + calib->par_h7 = data->bme680_cal_buf_2[H7];
> > > > > + calib->par_t1 = get_unaligned_le16(&data->bme680_cal_buf_2[T1_LSB]);
> > > > > + calib->par_gh2 = get_unaligned_le16(&data->bme680_cal_buf_2[GH2_LSB]);
> > > > > + calib->par_gh1 = data->bme680_cal_buf_2[GH1];
> > > > > + calib->par_gh3 = data->bme680_cal_buf_2[GH3];
> > > > >
> > > > > - ret = regmap_read(data->regmap, BME680_H7_REG, &tmp);
> > > > > + ret = regmap_bulk_read(data->regmap, BME680_REG_RES_HEAT_VAL,
> > > > > + &data->bme680_cal_buf_3[0],
> > > > This one is always debated, but personally I'd prefer
> > > > data->bme680_cal_buf_3,
> > > >
> > >
> > > For me it's the same, I could change it to what you proposed, no problem!
> > >
> > > Cheers,
> > > Vasilis
> > >
> > > > for cases like this. Up to you though.
> > > > > + sizeof(data->bme680_cal_buf_3));
> > > > > if (ret < 0) {
> > > > > - dev_err(dev, "failed to read BME680_H7_REG\n");
> > > > > + dev_err(dev, "failed to read 3rd set of calib data;\n");
> > > > > return ret;
> > > > > }
> > > >
> >
next prev parent reply other threads:[~2024-06-06 19:36 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 18:37 [PATCH v1 00/17] iio: chemical: bme680: Driver cleanup Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 01/17] iio: chemical: bme680: Fix pressure value output Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 02/17] iio: chemical: bme680: Fix calibration data variable Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 03/17] iio: chemical: bme680: Fix overflows in compensate() functions Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 04/17] iio: chemical: bme680: Fix sensor data read operation Vasileios Amoiridis
2024-06-02 12:41 ` Jonathan Cameron
2024-06-02 19:00 ` Vasileios Amoiridis
2024-06-03 19:23 ` Jonathan Cameron
2024-06-03 20:31 ` Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 05/17] iio: chemical: bme680: Fix type in define Vasileios Amoiridis
2024-06-02 12:41 ` Jonathan Cameron
2024-06-02 19:17 ` Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 06/17] iio: chemical: bme680: Add mutexes to guard read/write to device Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 07/17] iio: chemical: bme680: Drop unnecessary casts and correct adc data types Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 08/17] iio: chemical: bme680: Remove remaining ACPI-only stuff Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 09/17] iio: chemical: bme680: Sort headers alphabetically Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 10/17] iio: chemical: bme680: Remove duplicate register read Vasileios Amoiridis
2024-06-02 12:50 ` Jonathan Cameron
2024-06-02 19:25 ` Vasileios Amoiridis
2024-05-27 18:37 ` [PATCH v1 11/17] iio: chemical: bme680: Use bulk reads for calibration data Vasileios Amoiridis
2024-06-02 12:57 ` Jonathan Cameron
2024-06-02 19:30 ` Vasileios Amoiridis
2024-06-03 19:25 ` Jonathan Cameron
2024-06-03 20:30 ` Vasileios Amoiridis
2024-06-06 19:36 ` Jonathan Cameron [this message]
2024-05-27 18:38 ` [PATCH v1 12/17] iio: chemical: bme680: Allocate IIO device before chip initialization Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 13/17] iio: chemical: bme680: Add read buffers in DMA safe region Vasileios Amoiridis
2024-06-02 12:59 ` Jonathan Cameron
2024-06-02 19:33 ` Vasileios Amoiridis
2024-06-03 19:27 ` Jonathan Cameron
2024-05-27 18:38 ` [PATCH v1 14/17] iio: chemical: bme680: Modify startup procedure Vasileios Amoiridis
2024-06-02 13:01 ` Jonathan Cameron
2024-06-02 19:40 ` Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 15/17] iio: chemical: bme680: Remove redundant gas configuration Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 16/17] iio: chemical: bme680: Move forced mode setup in ->read_raw() Vasileios Amoiridis
2024-05-27 18:38 ` [PATCH v1 17/17] iio: chemical: bme680: Refactorize reading functions Vasileios Amoiridis
2024-06-02 13:04 ` Jonathan Cameron
2024-06-02 19:53 ` Vasileios Amoiridis
2024-06-02 12:31 ` [PATCH v1 00/17] iio: chemical: bme680: Driver cleanup Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240606203603.18e9a17b@jic23-huawei \
--to=jic23@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=himanshujha199640@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vassilisamir@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox