mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Brad Larson" <brad@pensando.io>, linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org,
	"linux-mmc @ vger . kernel . org" <linux-mmc@vger.kernel.org>,
	linux-spi@vger.kernel.org, adrian.hunter@intel.com,
	alcooperx@gmail.com,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	blarson@amd.com, brendan.higgins@linux.dev,
	"Brian Norris" <briannorris@chromium.org>,
	brijeshkumar.singh@amd.com,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"David Gow" <davidgow@google.com>,
	gsomlo@gmail.com, gerg@linux-m68k.org,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	krzysztof.kozlowski+dt@linaro.org, "Lee Jones" <lee@kernel.org>,
	"Lee Jones" <lee.jones@linaro.org>,
	"Mark Brown" <broonie@kernel.org>,
	yamada.masahiro@socionext.com,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	piotrs@cadence.com, p.yadav@ti.com,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Samuel Holland" <samuel@sholland.org>,
	"Serge Semin" <fancer.lancer@gmail.com>,
	skhan@linuxfoundation.org, suravee.suthikulpanit@amd.com,
	thomas.lendacky@amd.com,
	"Tony Huang" <tonyhuang.sunplus@gmail.com>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	vaishnav.a@ti.com, "Will Deacon" <will@kernel.org>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v9 15/15] spi: pensando-sr: Add AMD Pensando SoC System Resource
Date: Thu, 19 Jan 2023 10:22:37 +0100	[thread overview]
Message-ID: <e7180562-dddf-47ff-8e6d-34265521b10d@app.fastmail.com> (raw)
In-Reply-To: <20230119033918.44117-16-blarson@amd.com>

On Thu, Jan 19, 2023, at 04:39, Brad Larson wrote:

> drivers/spi/spi-pensando-sr.c

I don't think that is the right place for this driver: it's not a spi
controller implementation but rather a user interface driver that should
be in another subsystem depending on its purpose. drivers/misc/ might
be an option, but ideally I think there should be a higher-level
interface.

I'm still confused about what this driver actually does, and how
the corresponding user space side is meant to be used.

> +config SPI_PENSANDO_SR
> +	bool "AMD Pensando SoC System Resource chip"
> +	depends on SPI_MASTER=y

Why can this not be a loadable module, i.e. a 'tristate' option?

> +
> +#define PENSR_MAX_REG		0xff
> +#define PENSR_CTRL0_REG		0x10
> +#define PENSR_SPI_CMD_REGRD	0x0b
> +#define PENSR_SPI_CMD_REGWR	0x02
> +#define SPI_IOC_MAGIC		'k'
> +
> +#define SPI_MSGSIZE(N) \
> +	((((N)*(sizeof(struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
> +		? ((N)*(sizeof(struct spi_ioc_transfer))) : 0)
> +#define SPI_IOC_MESSAGE(N)	_IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
> +
> +struct spi_ioc_transfer {
> +	__u64 tx_buf;
> +	__u64 rx_buf;
> +	__u32 len;
> +	__u32 speed_hz;
> +	__u16 delay_usecs;
> +	__u8 bits_per_word;
> +	__u8 cs_change;
> +	__u8 tx_nbits;
> +	__u8 rx_nbits;
> +	__u8 word_delay_usecs;
> +	__u8 pad;
> +};

When you create a new user interface, the interface definition should
be in include/uapi/linux/*.h. The structure name and command name should
indicate what driver they are used for, these names look overly
generic.

> +struct pensr_device {
> +	struct spi_device *spi_dev;
> +	struct reset_controller_dev rcdev;
> +	struct mutex buf_lock;
> +	spinlock_t spi_lock;
> +	u8 *tx_buffer;
> +	u8 *rx_buffer;
> +};
> +
> +static dev_t pensr_devt;
> +static struct pensr_device *pensr;
> +static struct class *pensr_class;
> +static unsigned int bufsiz = 4096;

Even if there is only ever a single instance of the device known to the
kernel, it is better style to avoid static variables but instead make
everything passed around as part of the device structure.


> +
> +	t[0].tx_buf = tx_buf;
> +	t[0].len = u_xfer->len;
> +	if (copy_from_user(tx_buf, (const u8 __user *) (uintptr_t) 
> u_xfer->tx_buf, u_xfer->len)) {
> +		ret = -EFAULT;
> +		goto done;
> +	}

Use u64_to_user_ptr() instead of open-coding the type cast.

> +static const struct file_operations pensr_spi_fops = {
> +	.owner =	THIS_MODULE,
> +	.unlocked_ioctl = pensr_spi_ioctl,

There should be a '.compat_ioctl = compat_ptr_ioctl,' line here to
allow the ioctl to work in 32-bit processes.

      Arnd

  reply	other threads:[~2023-01-19  9:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19  3:39 [PATCH v9 00/15] Support AMD Pensando Elba SoC Brad Larson
2023-01-19  3:39 ` [PATCH v9 01/15] dt-bindings: arm: add AMD Pensando boards Brad Larson
2023-01-19  3:39 ` [PATCH v9 02/15] dt-bindings: mmc: cdns: Add AMD Pensando Elba SoC Brad Larson
2023-01-19  3:39 ` [PATCH v9 03/15] dt-bindings: spi: cdns: Add compatible for " Brad Larson
2023-01-19  3:39 ` [PATCH v9 04/15] dt-bindings: spi: dw: Add AMD Pensando Elba SoC SPI Controller bindings Brad Larson
2023-01-19  3:39 ` [PATCH v9 05/15] dt-bindings: mfd: syscon: Add amd,pensando-elba-syscon compatible Brad Larson
2023-01-19  3:39 ` [PATCH v9 06/15] dt-bindings: mfd: amd,pensando-elbasr: Add AMD Pensando System Resource chip Brad Larson
2023-01-19  3:39 ` [PATCH v9 07/15] MAINTAINERS: Add entry for AMD PENSANDO Brad Larson
2023-01-19  3:39 ` [PATCH v9 08/15] arm64: Add config for AMD Pensando SoC platforms Brad Larson
2023-01-19  3:39 ` [PATCH v9 09/15] arm64: dts: Add AMD Pensando Elba SoC support Brad Larson
2023-01-19  3:39 ` [PATCH v9 10/15] spi: cadence-quadspi: Add compatible for AMD Pensando Elba SoC Brad Larson
2023-01-19  3:39 ` [PATCH v9 11/15] spi: dw: Add support " Brad Larson
2023-01-19  3:39 ` [PATCH v9 12/15] mmc: sdhci-cadence: Enable device specific override of writel() Brad Larson
2023-01-19  3:39 ` [PATCH v9 13/15] mmc: sdhci-cadence: Add AMD Pensando Elba SoC support Brad Larson
2023-01-19  3:39 ` [PATCH v9 14/15] mmc: sdhci-cadence: Support mmc hardware reset Brad Larson
2023-01-19  8:57   ` Arnd Bergmann
2023-02-07  1:51     ` Brad Larson
2023-01-19  3:39 ` [PATCH v9 15/15] spi: pensando-sr: Add AMD Pensando SoC System Resource Brad Larson
2023-01-19  9:22   ` Arnd Bergmann [this message]
2023-01-19  3:51 [PATCH v9 00/15] Support AMD Pensando Elba SoC Brad Larson
2023-01-19  3:51 ` [PATCH v9 15/15] spi: pensando-sr: Add AMD Pensando SoC System Resource Brad Larson
2023-01-19 13:57   ` Mark Brown
2023-02-07  2:12     ` Brad Larson

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=e7180562-dddf-47ff-8e6d-34265521b10d@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=adrian.hunter@intel.com \
    --cc=alcooperx@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=blarson@amd.com \
    --cc=brad@pensando.io \
    --cc=brendan.higgins@linux.dev \
    --cc=briannorris@chromium.org \
    --cc=brijeshkumar.singh@amd.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=davidgow@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=gerg@linux-m68k.org \
    --cc=gsomlo@gmail.com \
    --cc=krzk@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee.jones@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=p.yadav@ti.com \
    --cc=p.zabel@pengutronix.de \
    --cc=piotrs@cadence.com \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=samuel@sholland.org \
    --cc=skhan@linuxfoundation.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=thomas.lendacky@amd.com \
    --cc=tonyhuang.sunplus@gmail.com \
    --cc=ulf.hansson@linaro.org \
    --cc=vaishnav.a@ti.com \
    --cc=will@kernel.org \
    --cc=yamada.masahiro@socionext.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

all inboxes | Powered by JetHome®