Add Intel LJCA device driver
Subsystems (5)
v19 cover Add Intel LJCA device driver
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
---
v19:
- add v17's change which v18 doesn't apply
v18:
- rebase patch set on top of Linus' master branch (57d88e8a5974644039fbc47806bac7bb12025636)
v17:
- change valid_pins type to __le32 and access valid_pins with get_unaligned_le32
- remove COMPILE_TEST for USB_LJCA Kconfig
v16:
- drop all void * and use real types in the exported apis and internal ljca_send()
- remove #ifdef in usb-ljca.c file
- add documentation in ljca.h for the public structures
- add error message in ljca_handle_cmd_ack() if error happens and remove blank line
- use the functionality in cleanup.h for spinlock to make function much simpler
- change the type of ex_buf in struct ljca_adapter to u8 *
v15:
- enhance disconnect() of usb-ljca driver
- change memchr to strchr in ljca_match_device_ids() of usb-ljca driver
v14:
- fix build error: implicit declaration of function 'acpi_dev_clear_dependencies'
v13:
- make ljca-usb more robust with the help of Hans de Goede
- call acpi_dev_clear_dependencies() to mark _DEP ACPI dependencies on the I2C controller as satisfied, and patch is from Hans de Goede
v12:
- switch dev_err to dev_dbg for i2c-ljca driver
- avoid err printing because of calling usb_kill_urb when attempts to resubmit the rx urb
v11:
- switch dev_err to dev_dbg for i2c-ljca driver
- remove message length check because of defined quirk structure
- remove I2C_FUNC_SMBUS_EMUL support
v10:
- remove ljca_i2c_format_slave_addr
- remove memset before write write w_packet
- make ljca_i2c_stop void and print err message in case failure
- use dev_err_probe in ljca_i2c_probe function
v9:
- overhaul usb-ljca driver to make it more structured and easy understand
- fix memory leak issue for usb-ljca driver
- add spinlock to protect tx_buf and ex_buf
- change exported APIs for usb-ljca driver
- unify prefix for structures and functions for i2c-ljca driver
- unify prefix for structures and functions for spi-ljca driver
- unify prefix for structures and functions for gpio-ljca driver
- update gpio-ljca, i2c-ljca and spi-ljca drivers according to usb-ljca's changes
Wentong Wu (4):
usb: Add support for Intel LJCA device
i2c: Add support for Intel LJCA USB I2C driver
spi: Add support for Intel LJCA USB SPI driver
gpio: update Intel LJCA USB GPIO driver
drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++------ drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 342 +++++++++++++++++ drivers/spi/Kconfig | 11 + drivers/spi/Makefile | 1 + drivers/spi/spi-ljca.c | 297 +++++++++++++++ drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb-ljca.c | 837 ++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 145 ++++++++ 12 files changed, 1804 insertions(+), 105 deletions(-) create mode 100644 drivers/i2c/busses/i2c-ljca.c create mode 100644 drivers/spi/spi-ljca.c create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h
Signature · 1 line
2.7.4
PATCH v19 1/4 usb: Add support for Intel LJCA device
Implements the USB part of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA).
The communication between the various LJCA module drivers and the hardware will be muxed/demuxed by this driver. Three modules ( I2C, GPIO, and SPI) are supported currently.
Each sub-module of LJCA device is identified by type field within the LJCA message header.
The sub-modules of LJCA can use ljca_transfer() to issue a transfer between host and hardware. And ljca_register_event_cb is exported to LJCA sub-module drivers for hardware event subscription.
The minimum code in ASL that covers this board is
Scope (\_SB.PCI0.DWC3.RHUB.HS01)
{
Device (GPIO)
{
Name (_ADR, Zero)
Name (_STA, 0x0F)
}
Device (I2C)
{
Name (_ADR, One)
Name (_STA, 0x0F)
}
Device (SPI)
{
Name (_ADR, 0x02)
Name (_STA, 0x0F)
}
}--- drivers/usb/misc/Kconfig | 13 + drivers/usb/misc/Makefile | 1 + drivers/usb/misc/usb-ljca.c | 837 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/ljca.h | 145 ++++++++ 4 files changed, 996 insertions(+) create mode 100644 drivers/usb/misc/usb-ljca.c create mode 100644 include/linux/usb/ljca.h
drivers/usb/misc/Kconfig +13 -0
@@ -165,6 +165,19 @@ config APPLE_MFI_FASTCHARGE It is safe to say M here. +config USB_LJCA + tristate "Intel La Jolla Cove Adapter support" + select AUXILIARY_BUS + depends on USB && ACPI + help + This adds support for Intel La Jolla Cove USB-I2C/SPI/GPIO + Master Adapter (LJCA). Additional drivers such as I2C_LJCA, + GPIO_LJCA and SPI_LJCA must be enabled in order to use the + functionality of the device. + + This driver can also be built as a module. If so, the module + will be called usb-ljca. + source "drivers/usb/misc/sisusbvga/Kconfig" config USB_LD
drivers/usb/misc/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_USB_EMI26) += emi26.o obj-$(CONFIG_USB_EMI62) += emi62.o obj-$(CONFIG_USB_EZUSB_FX2) += ezusb.o obj-$(CONFIG_APPLE_MFI_FASTCHARGE) += apple-mfi-fastcharge.o +obj-$(CONFIG_USB_LJCA) += usb-ljca.o obj-$(CONFIG_USB_IDMOUSE) += idmouse.o obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o obj-$(CONFIG_USB_ISIGHTFW) += isight_firmware.o
drivers/usb/misc/usb-ljca.c new file +837 -0
837 lines not on this page · raw message
include/linux/usb/ljca.h new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.7.4
Greg KH
maintainerRe: [PATCH v19 1/4] usb: Add support for Intel LJCA device
drivers/usb/misc/usb-ljca.c line 69
Quoted 7 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +7
-0+/* ljca cmd message structure */ +struct ljca_msg { +u8 type; +u8 cmd; +u8 flags; +u8 len; +u8 data[];
Shouldn't you be using the __counted_by attributes for all of these [] arrays so that the compiler knows what to do and how to check that you don't overrun the buffer?
Adding that now will save you having to add it later, AND it might catch bugs you already have so please add that.
Quoted 30 lines
drivers/usb/misc/usb-ljca.c new file +30
-0+ +struct ljca_adapter { +struct usb_interface *intf; +struct usb_device *usb_dev; +struct device *dev; + +unsigned int rx_pipe; +unsigned int tx_pipe; + +/* urb for recv */ +struct urb *rx_urb; +/* buffer for recv */ +void *rx_buf; +unsigned int rx_len; + +/* external buffer for recv */ +u8 *ex_buf; +unsigned int ex_buf_len; +/* actual data length copied to external buffer */ +unsigned int actual_length; + +/* buffer for send */ +void *tx_buf; +unsigned int tx_buf_len; + +/* lock to protect tx_buf and ex_buf */ +spinlock_t lock; + +struct completion cmd_completion; +
drivers/usb/misc/usb-ljca.c line 145
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+/* mutex to protect command download */ +struct mutex mutex; + +/* client device list */ +struct list_head client_list; + +/* disconnect ongoing or not */ +bool disconnect; + +/* used to reset firmware */
Can you use proper kernel doc for this structure instead of inline comments?
Quoted 34 lines
drivers/usb/misc/usb-ljca.c new file +34
-0+u32 reset_id; +}; + +struct ljca_match_ids_walk_data { +const struct acpi_device_id *ids; +const char *uid; +struct acpi_device *adev; +}; + +static const struct acpi_device_id ljca_gpio_hids[] = { + {"INTC1074" }, + {"INTC1096" }, + {"INTC100B" }, + {"INTC10D1" }, + {}, +}; + +static const struct acpi_device_id ljca_i2c_hids[] = { + {"INTC1075" }, + {"INTC1097" }, + {"INTC100C" }, + {"INTC10D2" }, + {}, +}; + +static const struct acpi_device_id ljca_spi_hids[] = { + {"INTC1091" }, + {"INTC1098" }, + {"INTC100D" }, + {"INTC10D3" }, + {}, +}; + +static void ljca_handle_event(struct ljca_adapter *adap,
drivers/usb/misc/usb-ljca.c line 189
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ struct ljca_msg *header) +{ +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. +* firmware message structure should include id when +* multiple same type clients register event callback. +*/
When will this be fixed?
If not now, why not?
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+if (client->type == header->type) { + scoped_guard(spinlock_irqsave, &client->event_cb_lock) { + client->event_cb (client->context, header->cmd, + header->data, header->len);
drivers/usb/misc/usb-ljca.c line 203
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ } + +break ; + } + } +} + +/* process command ack */ +static void ljca_handle_cmd_ack (struct ljca_adapter *adap, +struct ljca_msg *header)
We can use 100 columns...
drivers/usb/misc/usb-ljca.c line 214
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +11
-0+{ +struct ljca_msg *tx_header = adap->tx_buf; +unsigned int actual_len =0 ; +unsigned int ibuf_len; +unsigned long flags; +u8 *ibuf; + +spin_lock_irqsave (&adap->lock, flags); + +if (tx_header->type != header->type || tx_header->cmd != header->cmd) { +dev_err (adap->dev,"cmd ack mismatch error\n" );
When you print error messages like this, who can do something about it? And why print with interrupts disabled?
drivers/usb/misc/usb-ljca.c line 223
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+spin_unlock_irqrestore (&adap->lock, flags); +return ; + } + + ibuf_len = adap->ex_buf_len; + ibuf = adap->ex_buf; + +if (ibuf && ibuf_len) { + actual_len = min_t(unsigned int, header->len, ibuf_len);
You control both of these types, why aren't they the same type to start with? Why the force cast?
drivers/usb/misc/usb-ljca.c line 229
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ +/* copy received data to external buffer */ +memcpy (ibuf, header->data, actual_len); + } +/* update copied data length */ + adap->actual_length = actual_len;
Wait, what happens if you don't actually copy the data? Why lie and say you did? Where is the error handling?
drivers/usb/misc/usb-ljca.c line 236
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+ +spin_unlock_irqrestore (&adap->lock, flags); + +complete (&adap->cmd_completion); +} + +static void ljca_recv (struct urb *urb)
No error handling?
Quoted 12 lines
drivers/usb/misc/usb-ljca.c new file +12
-0+{ +struct ljca_msg *header = urb->transfer_buffer; +struct ljca_adapter *adap = urb->context; +int ret; + +if (urb->status) { +/* sync/async unlink faults aren't errors */ +if (urb->status == -ENOENT ) { +/* +* directly complete the possible ongoing transfer +* during disconnect +*/
drivers/usb/misc/usb-ljca.c line 258
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (adap->disconnect) +complete (&adap->cmd_completion); +return ; + } + +if (urb->status == -ECONNRESET || urb->status == -ESHUTDOWN ) +return ; + +dev_err (adap->dev,"recv urb error: %d\n" , urb->status); + goto resubmit;
You have an error, yet you don't report it you just spam the kernel log? Why? Doesn't this happen when a device is removed?
drivers/usb/misc/usb-ljca.c line 270
Quoted 12 lines
drivers/usb/misc/usb-ljca.c new file +12
-0+ } + +if (header->len +sizeof (*header) != urb->actual_length) + goto resubmit; + +if (header->flags &LJCA_ACK_FLAG ) +ljca_handle_cmd_ack (adap, header); +else +ljca_handle_event (adap, header); + +resubmit: + ret =usb_submit_urb (urb,GFP_ATOMIC );
Why atomic, is this in a urb callback?
drivers/usb/misc/usb-ljca.c line 272
Quoted 2 lines
drivers/usb/misc/usb-ljca.c new file +2
-0+if (ret && ret != -EPERM ) +dev_err (adap->dev,"resubmit recv urb error %d\n" , ret);
What happens if ret is an error here?
Quoted 21 lines
drivers/usb/misc/usb-ljca.c new file +21
-0+} + +static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const u8 *obuf,unsigned int obuf_len,u8 *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout) +{ +unsigned int msg_len =sizeof (struct ljca_msg ) + obuf_len; +struct ljca_msg *header = adap->tx_buf; +unsigned int actual; +int ret =0 ; + +if (adap->disconnect) +return -ENODEV ; + +if (msg_len > adap->tx_buf_len) +return -EINVAL ; + +mutex_lock (&adap->mutex); + + scoped_guard(spinlock_irqsave, &adap->lock) { + header->type = type;
drivers/usb/misc/usb-ljca.c line 303
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ header->cmd = cmd; + header->len = obuf_len; +if (obuf) +memcpy (header->data, obuf, obuf_len); + header->flags =LJCA_CMPL_FLAG | (ack ?LJCA_ACK_FLAG :0 ); + + adap->ex_buf = ibuf; + adap->ex_buf_len = ibuf_len; + adap->actual_length =0 ; + }
Do you really need a scoped guard when you can not fail out of the block?
Why do you have both a mutex and spinlock grabed?
drivers/usb/misc/usb-ljca.c line 307
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+ +reinit_completion (&adap->cmd_completion); + +usb_autopm_get_interface (adap->intf);
This can fail. Why aren't you checking that?
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+ + ret =usb_bulk_msg (adap->usb_dev, adap->tx_pipe, header, + msg_len, &actual,LJCA_WRITE_TIMEOUT_MS ); + +usb_autopm_put_interface (adap->intf); + +if (!ret && ack) {
drivers/usb/misc/usb-ljca.c line 324
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ ret =wait_for_completion_timeout (&adap->cmd_completion, + timeout); +if (ret <0 ) { + goto out; + }if (!ret) { + ret = -ETIMEDOUT ; + goto out; + } + } + ret = adap->actual_length;
Why are you not verifying that you sent what you wanted to send?
When you call this function, sometimes you check that the function sent the proper amount of data, but in many places you do not, and you assume that the full buffer was sent, which is not correct. So please change _this_ function to check that you sent the proper amount and then the caller logic will be much simpler and actually work like you are using it in many places (some places you got it right, some wrong, which is a HUGE indication that the API is wrong because you wrote this code, and if you can't get it right...)
drivers/usb/misc/usb-ljca.c line 331
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+out: + scoped_guard(spinlock_irqsave, &adap->lock) { + adap->ex_buf =NULL ; + adap->ex_buf_len =0 ; +memset (header,0 ,sizeof (*header)); + }
Again, why a scoped guard for something like this that does not need it?
Quoted 59 lines
drivers/usb/misc/usb-ljca.c new file +59
-0+ +mutex_unlock (&adap->mutex); + +return ret; +} + +int ljca_transfer (struct ljca_client *client,u8 cmd,const u8 *obuf, +unsigned int obuf_len,u8 *ibuf,unsigned int ibuf_len) +{ +return ljca_send (client->adapter, client->type, cmd, + obuf, obuf_len, ibuf, ibuf_len, true, +LJCA_WRITE_ACK_TIMEOUT_MS ); +} +EXPORT_SYMBOL_NS_GPL (ljca_transfer,LJCA ); + +int ljca_transfer_noack (struct ljca_client *client,u8 cmd,const u8 *obuf, +unsigned int obuf_len) +{ +return ljca_send (client->adapter, client->type, cmd, obuf, + obuf_len,NULL ,0 , false,LJCA_WRITE_ACK_TIMEOUT_MS ); +} +EXPORT_SYMBOL_NS_GPL (ljca_transfer_noack,LJCA ); + +int ljca_register_event_cb (struct ljca_client *client,ljca_event_cb_t event_cb, +void *context) +{ +unsigned long flags; + +if (!event_cb) +return -EINVAL ; + +spin_lock_irqsave (&client->event_cb_lock, flags); + +if (client->event_cb) { +spin_unlock_irqrestore (&client->event_cb_lock, flags); +return -EALREADY ; + } + + client->event_cb = event_cb; + client->context = context; + +spin_unlock_irqrestore (&client->event_cb_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (ljca_register_event_cb,LJCA ); + +void ljca_unregister_event_cb (struct ljca_client *client) +{ + scoped_guard(spinlock_irqsave, &client->event_cb_lock) { + client->event_cb =NULL ; + client->context =NULL ; + } +} +EXPORT_SYMBOL_NS_GPL (ljca_unregister_event_cb,LJCA ); + +static int ljca_match_device_ids (struct acpi_device *adev,void *data) +{ +struct ljca_match_ids_walk_data *wd = data;
drivers/usb/misc/usb-ljca.c line 400
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+const char *uid =acpi_device_uid (adev); + +if (acpi_match_device_ids (adev, wd->ids)) +return 0 ; + +if (!wd->uid) + goto match; + +if (!uid) + uid ="0" ;
Are you sure this is a valid uid to use? If so, why? What happens if this gets set to "0" for multiple ones? Don't underestimate broken firmware tables, but also don't paper over problems in ways that will be impossible to notice and can cause problems.
Or am I mis-reading this function wrong, how can this ever be a valid UID to compare against?
Quoted 228 lines
drivers/usb/misc/usb-ljca.c new file +228
-0+else + uid =strchr (uid, wd->uid[0 ]); + +if (!uid ||strcmp (uid, wd->uid)) +return 0 ; + +match: + wd->adev = adev; + +return 1 ; +} + +/* bind auxiliary device to acpi device */ +static void ljca_auxdev_acpi_bind (struct ljca_adapter *adap, +struct auxiliary_device *auxdev, +u64 adr,u8 id) +{ +struct ljca_match_ids_walk_data wd = {0 }; +struct acpi_device *parent, *adev; +struct device *dev = adap->dev; +char uid[4 ]; + + parent =ACPI_COMPANION (dev); +if (!parent) +return ; + +/* +* get auxdev ACPI handle from the ACPI device directly +* under the parent that matches _ADR. +*/ + adev =acpi_find_child_device (parent, adr, false); +if (adev) { +ACPI_COMPANION_SET (&auxdev->dev, adev); +return ; + } + +/* +* _ADR is a grey area in the ACPI specification, some +* platforms use _HID to distinguish children devices. +*/ +switch (adr) { +case LJCA_GPIO_ACPI_ADR : + wd.ids = ljca_gpio_hids; +break ; +case LJCA_I2C1_ACPI_ADR : +case LJCA_I2C2_ACPI_ADR : +snprintf (uid,sizeof (uid),"%d" , id); + wd.uid = uid; + wd.ids = ljca_i2c_hids; +break ; +case LJCA_SPI1_ACPI_ADR : +case LJCA_SPI2_ACPI_ADR : + wd.ids = ljca_spi_hids; +break ; +default : +dev_warn (dev,"unsupported _ADR\n" ); +return ; + } + +acpi_dev_for_each_child (parent, ljca_match_device_ids, &wd); +if (wd.adev) { +ACPI_COMPANION_SET (&auxdev->dev, wd.adev); +return ; + } + + parent =ACPI_COMPANION (dev->parent->parent); +if (!parent) +return ; + +acpi_dev_for_each_child (parent, ljca_match_device_ids, &wd); +if (wd.adev) +ACPI_COMPANION_SET (&auxdev->dev, wd.adev); +} + +static void ljca_auxdev_release (struct device *dev) +{ +struct auxiliary_device *auxdev =to_auxiliary_dev (dev); + +kfree (auxdev->dev.platform_data); +} + +static int ljca_new_client_device (struct ljca_adapter *adap,u8 type,u8 id, +char *name,void *data,u64 adr) +{ +struct auxiliary_device *auxdev; +struct ljca_client *client; +int ret; + + client =kzalloc (sizeof *client,GFP_KERNEL ); +if (!client) +return -ENOMEM ; + + client->type = type; + client->id = id; + client->adapter = adap; +spin_lock_init (&client->event_cb_lock); + + auxdev = &client->auxdev; + auxdev->name = name; + auxdev->id = id; + + auxdev->dev.parent = adap->dev; + auxdev->dev.platform_data = data; + auxdev->dev.release = ljca_auxdev_release; + + ret =auxiliary_device_init (auxdev); +if (ret) + goto err_free; + +ljca_auxdev_acpi_bind (adap, auxdev, adr, id); + + ret =auxiliary_device_add (auxdev); +if (ret) + goto err_uninit; + +list_add_tail (&client->link, &adap->client_list); + +return 0 ; + +err_uninit: +auxiliary_device_uninit (auxdev); + +err_free: +kfree (client); + +return ret; +} + +static int ljca_enumerate_gpio (struct ljca_adapter *adap) +{ +u32 valid_pin[LJCA_MAX_GPIO_NUM /BITS_PER_TYPE (u32)]; +struct ljca_gpio_descriptor *desc; +struct ljca_gpio_info *gpio_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +int ret, gpio_num; +unsigned int i; + + ret =ljca_send (adap,LJCA_CLIENT_MNG ,LJCA_MNG_ENUM_GPIO ,NULL ,0 , buf, +sizeof (buf), true,LJCA_ENUM_CLIENT_TIMEOUT_MS ); +if (ret <0 ) +return ret; + +/* check firmware response */ + desc = (struct ljca_gpio_descriptor *)buf; +if (ret !=struct_size (desc, bank_desc, desc->bank_num)) +return -EINVAL ; + + gpio_num = desc->pins_per_bank * desc->bank_num; +if (gpio_num >LJCA_MAX_GPIO_NUM ) +return -EINVAL ; + +/* construct platform data */ + gpio_info =kzalloc (sizeof *gpio_info,GFP_KERNEL ); +if (!gpio_info) +return -ENOMEM ; + gpio_info->num = gpio_num; + +for (i =0 ; i < desc->bank_num; i++) + valid_pin[i] =get_unaligned_le32 (&desc->bank_desc[i].valid_pins); +bitmap_from_arr32 (gpio_info->valid_pin_map, valid_pin, gpio_num); + + ret =ljca_new_client_device (adap,LJCA_CLIENT_GPIO ,0 ,"ljca-gpio" , + gpio_info,LJCA_GPIO_ACPI_ADR ); +if (ret) +kfree (gpio_info); + +return ret; +} + +static int ljca_enumerate_i2c (struct ljca_adapter *adap) +{ +struct ljca_i2c_descriptor *desc; +struct ljca_i2c_info *i2c_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +unsigned int i; +int ret; + + ret =ljca_send (adap,LJCA_CLIENT_MNG ,LJCA_MNG_ENUM_I2C ,NULL ,0 , buf, +sizeof (buf), true,LJCA_ENUM_CLIENT_TIMEOUT_MS ); +if (ret <0 ) +return ret; + +/* check firmware response */ + desc = (struct ljca_i2c_descriptor *)buf; +if (ret !=struct_size (desc, info, desc->num)) +return -EINVAL ; + +for (i =0 ; i < desc->num; i++) { +/* construct platform data */ + i2c_info =kzalloc (sizeof *i2c_info,GFP_KERNEL ); +if (!i2c_info) +return -ENOMEM ; + + i2c_info->id = desc->info[i].id; + i2c_info->capacity = desc->info[i].capacity; + i2c_info->intr_pin = desc->info[i].intr_pin; + + ret =ljca_new_client_device (adap,LJCA_CLIENT_I2C , i, +"ljca-i2c" , i2c_info, +LJCA_I2C1_ACPI_ADR + i); +if (ret) { +kfree (i2c_info); +return ret; + } + } + +return 0 ; +} + +static int ljca_enumerate_spi (struct ljca_adapter *adap) +{ +struct ljca_spi_descriptor *desc; +struct ljca_spi_info *spi_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +unsigned int i; +int ret; + + ret =ljca_send (adap,LJCA_CLIENT_MNG ,LJCA_MNG_ENUM_SPI ,NULL ,0 , buf, +sizeof (buf), true,LJCA_ENUM_CLIENT_TIMEOUT_MS ); +if (ret <0 ) +return ret; + + desc = (struct ljca_spi_descriptor *)buf; +for (i =0 ; i < desc->num; i++) { +/* construct platform data */ + spi_info =kzalloc (sizeof *spi_info,GFP_KERNEL ); +if (!spi_info) +return -ENOMEM ;
drivers/usb/misc/usb-ljca.c line 638
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ + spi_info->id = desc->info[i].id; + spi_info->capacity = desc->info[i].capacity; + + ret =ljca_new_client_device (adap,LJCA_CLIENT_SPI , i, +"ljca-spi" , spi_info, +LJCA_SPI1_ACPI_ADR + i); +if (ret) { +kfree (spi_info); +return ret;
What about the other objects that you created here, don't you need to unwind the new ones if one in the chain fails? And if not, why stop at the first failure?
Quoted 35 lines
drivers/usb/misc/usb-ljca.c new file +35
-0+ } + } + +return 0 ; +} + +static int ljca_reset_handshake (struct ljca_adapter *adap) +{ +__le32 reset_id =cpu_to_le32 (adap->reset_id); +__le32 reset_id_ret =0 ; +int ret; + + adap->reset_id++; + + ret =ljca_send (adap,LJCA_CLIENT_MNG ,LJCA_MNG_RESET , (u8 *)&reset_id, +sizeof (__le32), (u8 *)&reset_id_ret,sizeof (__le32), + true,LJCA_WRITE_ACK_TIMEOUT_MS ); +if (ret <0 ) +return ret; + +if (reset_id_ret != reset_id) +return -EINVAL ; + +return 0 ; +} + +static int ljca_enumerate_clients (struct ljca_adapter *adap) +{ +int ret; + + ret =ljca_reset_handshake (adap); +if (ret) +return ret; + + ret =ljca_enumerate_gpio (adap);
drivers/usb/misc/usb-ljca.c line 683
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (ret) +dev_warn (adap->dev,"enumerate GPIO error\n" ); + + ret =ljca_enumerate_i2c (adap); +if (ret) +dev_warn (adap->dev,"enumerate I2C error\n" ); + + ret =ljca_enumerate_spi (adap); +if (ret) +dev_warn (adap->dev,"enumerate SPI error\n" );
So none of these "errors" are actually errors:
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;
You return success? Why? Are they not actually problems?
thanks,
greg k-h
RE: [PATCH v19 1/4] usb: Add support for Intel LJCA device
Hi Greg,
Thanks for your review
Quoted 13 lines
From: Greg KH <[email protected]>
drivers/usb/misc/usb-ljca.c line 69
Quoted 7 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +7
-0+/* ljca cmd message structure */ +struct ljca_msg { +u8 type; +u8 cmd; +u8 flags; +u8 len; +u8 data[];Shouldn't you be using the
__counted_byattributes for all of these [] arrays so that the compiler knows what to do and how to check that you don't overrun the buffer?
In this structure, len is not for data length, instead it's the length of header and data.
Quoted 3 lines
Adding that now will save you having to add it later, AND it might catch bugs you already have so please add that.
But, I will add the __counted_by attribute for others like below:
struct ljca_i2c_descriptor {
u8 num;
struct ljca_i2c_ctr_info info[] __counted_by(num);
} __packed;struct ljca_spi_descriptor {
u8 num;
struct ljca_spi_ctr_info info[] __counted_by(num);
} __packed;struct ljca_gpio_descriptor {
u8 pins_per_bank;
u8 bank_num;
struct ljca_bank_descriptor bank_desc[] __counted_by(bank_num);
} __packed;Quoted 35 lines
Quoted 35 lines
drivers/usb/misc/usb-ljca.c new file +34
-0+ +struct ljca_adapter { +struct usb_interface *intf; +struct usb_device *usb_dev; +struct device *dev; + +unsigned int rx_pipe; +unsigned int tx_pipe; + +/* urb for recv */ +struct urb *rx_urb; +/* buffer for recv */ +void *rx_buf; +unsigned int rx_len; + +/* external buffer for recv */ +u8 *ex_buf; +unsigned int ex_buf_len; +/* actual data length copied to external buffer */ +unsigned int actual_length; + +/* buffer for send */ +void *tx_buf; +unsigned int tx_buf_len; + +/* lock to protect tx_buf and ex_buf */ +spinlock_t lock; + +struct completion cmd_completion; + +/* mutex to protect command download */ +struct mutex mutex; + +/* client device list */
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 145
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+struct list_head client_list; + +/* disconnect ongoing or not */ +bool disconnect; + +/* used to reset firmware */ Can you use proper kernel doc for this structure instead of inline comments?
Ack, thanks
Quoted 48 lines
Quoted 35 lines
drivers/usb/misc/usb-ljca.c new file +34
-0+u32 reset_id; +}; + +struct ljca_match_ids_walk_data { +const struct acpi_device_id *ids; +const char *uid; +struct acpi_device *adev; +}; + +static const struct acpi_device_id ljca_gpio_hids[] = { + {"INTC1074" }, + {"INTC1096" }, + {"INTC100B" }, + {"INTC10D1" }, + {}, +}; + +static const struct acpi_device_id ljca_i2c_hids[] = { + {"INTC1075" }, + {"INTC1097" }, + {"INTC100C" }, + {"INTC10D2" }, + {}, +}; + +static const struct acpi_device_id ljca_spi_hids[] = { + {"INTC1091" }, + {"INTC1098" }, + {"INTC100D" }, + {"INTC10D3" }, + {}, +}; + +static void ljca_handle_event(struct ljca_adapter *adap,drivers/usb/misc/usb-ljca.c line 189
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ struct ljca_msg *header) +{ +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. +* firmware message structure should include id when +* multiple same type clients register event callback. +*/ When will this be fixed?
Quoted 1 line
If not now, why not?
Actually this doesn't impact current functionality because only GPIO register event callback, but from coding perspective it should add the id in the message structure. This fix should be done by firmware first, but many products have already been running the firmware, it's not easy to update the firmware.
Can I just remove the 'FIXME' and leave the comment here?
Quoted 10 lines
Quoted 10 lines
(quoted diff) +2
-0+ if (client->type == header->type) { + scoped_guard(spinlock_irqsave, &client-
event_cb_lock) {drivers/usb/misc/usb-ljca.c new file +6
-0+ client->event_cb (client->context, header->cmd, + header->data, header->len); + } + +break ; + }
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 203
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ } +} + +/* process command ack */ +static void ljca_handle_cmd_ack (struct ljca_adapter *adap, +struct ljca_msg *header)We can use 100 columns...
Ok, I will make this in one row.
Quoted 12 lines
drivers/usb/misc/usb-ljca.c
Quoted 11 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+{ +struct ljca_msg *tx_header = adap->tx_buf; +unsigned int actual_len =0 ; +unsigned int ibuf_len; +unsigned long flags; +u8 *ibuf; + +spin_lock_irqsave (&adap->lock, flags); + +if (tx_header->type != header->type || tx_header->cmd != header->cmd){
Quoted 4 lines
drivers/usb/misc/usb-ljca.c line 214
Quoted 1 line
drivers/usb/misc/usb-ljca.c new file +1
-0+dev_err (adap->dev,"cmd ack mismatch error\n" );When you print error messages like this, who can do something about it? And why print with interrupts disabled?
Thanks, this will be like below:
if (tx_header->type != header->type || tx_header->cmd != header->cmd) {
spin_unlock_irqrestore(&adap->lock, flags);
dev_err(adap->dev, "cmd ack mismatch error\n");
return;
}Quoted 13 lines
drivers/usb/misc/usb-ljca.c line 223
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+spin_unlock_irqrestore (&adap->lock, flags); +return ; + } + + ibuf_len = adap->ex_buf_len; + ibuf = adap->ex_buf; + +if (ibuf && ibuf_len) { + actual_len = min_t(unsigned int, header->len, ibuf_len);You control both of these types, why aren't they the same type to start with? Why the force cast?
The len of header is defined by firmware, it should be u8 type. But the ex_buf_len is passed by API users, I don't want users to do the cast if their buffer is large than 256.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c line 229
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ +/* copy received data to external buffer */ +memcpy (ibuf, header->data, actual_len); + } +/* update copied data length */ + adap->actual_length = actual_len;Wait, what happens if you don't actually copy the data?
This actual_length is the actual length of data copied to external buffer where is to save the command response. The API callers should check the response length according to the command you passed to this API.
Quoted 1 line
Why lie and say you did? Where is the error handling?
As I said, the API callers should have the error handing because they know the exact response format, and actually I already the error handling in this patch set.
Quoted 10 lines
drivers/usb/misc/usb-ljca.c line 236
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +7
-0+ +spin_unlock_irqrestore (&adap->lock, flags); + +complete (&adap->cmd_completion); +} + +static void ljca_recv (struct urb *urb)No error handling?
Actually I have, I re-structure this function as below to make it more clear,
static void ljca_recv(struct urb *urb)
{
struct ljca_msg *header = urb->transfer_buffer;
struct ljca_adapter *adap = urb->context;
int ret;
switch (urb->status) {
case 0:
/* success */
break;
case -ENOENT:
/*
* directly complete the possible ongoing transfer
* during disconnect
*/
if (adap->disconnect)
complete(&adap->cmd_completion);
return;
case -ECONNRESET:
case -ESHUTDOWN:
case -EPIPE:
/* rx urb is terminated */
dev_dbg(adap->dev, "rx urb terminated with status: %d\n",
urb->status);
return;
default:
dev_dbg(adap->dev, "rx urb error: %d\n", urb->status);
goto resubmit;
}
if (header->len + sizeof(*header) != urb->actual_length)
goto resubmit;
if (header->flags & LJCA_ACK_FLAG)
ljca_handle_cmd_ack(adap, header);
else
ljca_handle_event(adap, header);resubmit:
ret = usb_submit_urb(urb, GFP_ATOMIC); if (ret && ret != -EPERM) dev_err(adap->dev, "resubmit rx urb error %d\n", ret); }
Quoted 20 lines
Quoted 9 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+{ +struct ljca_msg *header = urb->transfer_buffer; +struct ljca_adapter *adap = urb->context; +int ret; + +if (urb->status) { +/* sync/async unlink faults aren't errors */ +if (urb->status == -ENOENT ) {drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+/* +* directly complete the possible ongoing transfer +* during disconnect +*/ +if (adap->disconnect) +complete (&adap->cmd_completion); +return ; + } + + if (urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)
Quoted 7 lines
drivers/usb/misc/usb-ljca.c line 258
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+return ; + +dev_err (adap->dev,"recv urb error: %d\n" , urb->status); + goto resubmit;You have an error, yet you don't report it you just spam the kernel log? Why? Doesn't this happen when a device is removed?
When device is removed, it will be covered by ESHUTDOWN case in the above 'if (urb->status == -ECONNRESET || urb->status == -ESHUTDOWN) '
Most of the command error cases have been handled by the above
'if (usb->status == ', for others it will print error log, In the re-structured code, I changed it to dev_dbg to avoid spam.
Quoted 15 lines
drivers/usb/misc/usb-ljca.c line 270
Quoted 13 lines
drivers/usb/misc/usb-ljca.c new file +12
-0+ } + +if (header->len +sizeof (*header) != urb->actual_length) + goto resubmit; + +if (header->flags &LJCA_ACK_FLAG ) +ljca_handle_cmd_ack (adap, header); +else +ljca_handle_event (adap, header); + +resubmit: + ret =usb_submit_urb (urb,GFP_ATOMIC );Why atomic, is this in a urb callback?
Yes,
Quoted 5 lines
drivers/usb/misc/usb-ljca.c line 272
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +2
-0+if (ret && ret != -EPERM ) +dev_err (adap->dev,"resubmit recv urb error %d\n" , ret);What happens if ret is an error here?
No command response, and there will be command timeout.
Quoted 25 lines
Quoted 25 lines
drivers/usb/misc/usb-ljca.c new file +24
-0+} + +static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const u8 *obuf,unsigned int obuf_len,u8 *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout) { +unsigned int msg_len =sizeof (struct ljca_msg ) + obuf_len; +struct ljca_msg *header = adap->tx_buf; +unsigned int actual; +int ret =0 ; + +if (adap->disconnect) +return -ENODEV ; + +if (msg_len > adap->tx_buf_len) +return -EINVAL ; + +mutex_lock (&adap->mutex); + + scoped_guard(spinlock_irqsave, &adap->lock) { + header->type = type; + header->cmd = cmd; + header->len = obuf_len; +if (obuf) +memcpy (header->data, obuf, obuf_len);
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 303
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ header->flags =LJCA_CMPL_FLAG | (ack ?LJCA_ACK_FLAG :0 ); + + adap->ex_buf = ibuf; + adap->ex_buf_len = ibuf_len; + adap->actual_length =0 ; + }Do you really need a scoped guard when you can not fail out of the block?
The scoped_guard is required by you with "Why not use the functionality in cleanup.h for this lock? Makes this function much simpler." If I understand correctly, so I use the scoped_guard where I can to make things simpler.
Quoted 2 lines
Why do you have both a mutex and spinlock grabed?
The mutex is to avoid command download concurrently
The spinlock is to protect tx_buf and ex_buf, which may be accessed by tx and rx at the same time.
Quoted 7 lines
drivers/usb/misc/usb-ljca.c line 307
Quoted 5 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+ +reinit_completion (&adap->cmd_completion); + +usb_autopm_get_interface (adap->intf);This can fail. Why aren't you checking that?
Ack, thanks, and it will be like below:
ret = usb_autopm_get_interface(adap->intf); if (ret < 0) goto out;
Quoted 12 lines
Quoted 12 lines
drivers/usb/misc/usb-ljca.c new file +11
-0+ + ret =usb_bulk_msg (adap->usb_dev, adap->tx_pipe, header, + msg_len, &actual,LJCA_WRITE_TIMEOUT_MS ); + +usb_autopm_put_interface (adap->intf); + +if (!ret && ack) { + ret =wait_for_completion_timeout (&adap->cmd_completion, + timeout); +if (ret <0 ) { + goto out;
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 324
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ }if (!ret) { + ret = -ETIMEDOUT ; + goto out; + } + } + ret = adap->actual_length;Why are you not verifying that you sent what you wanted to send?
As I said, the actual_length is the actual length of data copied to user buffer instead of the length of what we want to send.
And even for verifying the length of what we want to send, the max length of the message is sizeof(struct ljca_msg) + LJCA_MAX_PACKET_SIZE which is less than the endpoint's max packet size, so I don't check the actual sent length in above usb_bulk_msg().
Quoted 8 lines
When you call this function, sometimes you check that the function sent the proper amount of data, but in many places you do not, and you assume that the full buffer was sent, which is not correct. So please change _this_ function to check that you sent the proper amount and then the caller logic will be much simpler and actually work like you are using it in many places (some places you got it right, some wrong, which is a HUGE indication that the API is wrong because you wrote this code, and if you can't get it right...)
As I said, the return value of this function is the response data length instead of sent data length. And in this patch set, every caller has verified if the response length matched with the sent command.
Quoted 9 lines
drivers/usb/misc/usb-ljca.c line 331
Quoted 7 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+out: + scoped_guard(spinlock_irqsave, &adap->lock) { + adap->ex_buf =NULL ; + adap->ex_buf_len =0 ; +memset (header,0 ,sizeof (*header)); + }Again, why a scoped guard for something like this that does not need it?
As I said above, this is to address your last time review comment if I understand correctly, I can switch to the original one if we don't need this scoped guard.
Quoted 65 lines
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +9
-0+ +mutex_unlock (&adap->mutex); + +return ret; +} + +int ljca_transfer (struct ljca_client *client,u8 cmd,const u8 *obuf, +unsigned int obuf_len,u8 *ibuf,unsigned int ibuf_len) { + return ljca_send(client->adapter, client->type, cmd,drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ obuf, obuf_len, ibuf, ibuf_len, true, + LJCA_WRITE_ACK_TIMEOUT_MS); +} +EXPORT_SYMBOL_NS_GPL (ljca_transfer,LJCA ); + +int ljca_transfer_noack (struct ljca_client *client,u8 cmd,const u8 *obuf, +unsigned int obuf_len) +{ + return ljca_send(client->adapter, client->type, cmd, obuf, + obuf_len, NULL, 0, false,
LJCA_WRITE_ACK_TIMEOUT_MS); }Quoted 44 lines
drivers/usb/misc/usb-ljca.c new file +44
-0+EXPORT_SYMBOL_NS_GPL (ljca_transfer_noack,LJCA ); + +int ljca_register_event_cb (struct ljca_client *client,ljca_event_cb_t event_cb, +void *context) +{ +unsigned long flags; + +if (!event_cb) +return -EINVAL ; + +spin_lock_irqsave (&client->event_cb_lock, flags); + +if (client->event_cb) { +spin_unlock_irqrestore (&client->event_cb_lock, flags); +return -EALREADY ; + } + + client->event_cb = event_cb; + client->context = context; + +spin_unlock_irqrestore (&client->event_cb_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (ljca_register_event_cb,LJCA ); + +void ljca_unregister_event_cb (struct ljca_client *client) { + scoped_guard(spinlock_irqsave, &client->event_cb_lock) { + client->event_cb =NULL ; + client->context =NULL ; + } +} +EXPORT_SYMBOL_NS_GPL (ljca_unregister_event_cb,LJCA ); + +static int ljca_match_device_ids (struct acpi_device *adev,void +*data) { +struct ljca_match_ids_walk_data *wd = data; +const char *uid =acpi_device_uid (adev); + +if (acpi_match_device_ids (adev, wd->ids)) +return 0 ; + +if (!wd->uid) + goto match;
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 400
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ +if (!uid) + uid ="0" ;Are you sure this is a valid uid to use? If so, why? What happens if this gets set to "0" for multiple ones? Don't underestimate broken firmware tables, but also don't paper over problems in ways that will be impossible to notice and can cause problems.
This actually has been discussed in previous email as bellow:
some DSDTs have only 1 ACPI companion for the 2 I2C controllers and these don't set a UID at all. On these models only the first I2C controller is used. So if a HID match has no UID use "0" for the HID. assigning the ACPI companion to the first I2C controller. An example device with this setup is the Dell Latitude 9420.
Quoted 273 lines
Or am I mis-reading this function wrong, how can this ever be a valid UID to compare against?
Quoted 124 lines
drivers/usb/misc/usb-ljca.c new file +124
-0+else + uid =strchr (uid, wd->uid[0 ]); + +if (!uid ||strcmp (uid, wd->uid)) +return 0 ; + +match: + wd->adev = adev; + +return 1 ; +} + +/* bind auxiliary device to acpi device */ static void +ljca_auxdev_acpi_bind (struct ljca_adapter *adap, +struct auxiliary_device *auxdev, +u64 adr,u8 id) +{ +struct ljca_match_ids_walk_data wd = {0 }; +struct acpi_device *parent, *adev; +struct device *dev = adap->dev; +char uid[4 ]; + + parent =ACPI_COMPANION (dev); +if (!parent) +return ; + +/* +* get auxdev ACPI handle from the ACPI device directly +* under the parent that matches _ADR. +*/ + adev =acpi_find_child_device (parent, adr, false); +if (adev) { +ACPI_COMPANION_SET (&auxdev->dev, adev); +return ; + } + +/* +* _ADR is a grey area in the ACPI specification, some +* platforms use _HID to distinguish children devices. +*/ +switch (adr) { +case LJCA_GPIO_ACPI_ADR : + wd.ids = ljca_gpio_hids; +break ; +case LJCA_I2C1_ACPI_ADR : +case LJCA_I2C2_ACPI_ADR : +snprintf (uid,sizeof (uid),"%d" , id); + wd.uid = uid; + wd.ids = ljca_i2c_hids; +break ; +case LJCA_SPI1_ACPI_ADR : +case LJCA_SPI2_ACPI_ADR : + wd.ids = ljca_spi_hids; +break ; +default : +dev_warn (dev,"unsupported _ADR\n" ); +return ; + } + +acpi_dev_for_each_child (parent, ljca_match_device_ids, &wd); +if (wd.adev) { +ACPI_COMPANION_SET (&auxdev->dev, wd.adev); +return ; + } + + parent =ACPI_COMPANION (dev->parent->parent); +if (!parent) +return ; + +acpi_dev_for_each_child (parent, ljca_match_device_ids, &wd); +if (wd.adev) +ACPI_COMPANION_SET (&auxdev->dev, wd.adev); } + +static void ljca_auxdev_release (struct device *dev) { +struct auxiliary_device *auxdev =to_auxiliary_dev (dev); + +kfree (auxdev->dev.platform_data); +} + +static int ljca_new_client_device (struct ljca_adapter *adap,u8 type,u8 id, +char *name,void *data,u64 adr) { +struct auxiliary_device *auxdev; +struct ljca_client *client; +int ret; + + client =kzalloc (sizeof *client,GFP_KERNEL ); +if (!client) +return -ENOMEM ; + + client->type = type; + client->id = id; + client->adapter = adap; +spin_lock_init (&client->event_cb_lock); + + auxdev = &client->auxdev; + auxdev->name = name; + auxdev->id = id; + + auxdev->dev.parent = adap->dev; + auxdev->dev.platform_data = data; + auxdev->dev.release = ljca_auxdev_release; + + ret =auxiliary_device_init (auxdev); +if (ret) + goto err_free; + +ljca_auxdev_acpi_bind (adap, auxdev, adr, id); + + ret =auxiliary_device_add (auxdev); +if (ret) + goto err_uninit; + +list_add_tail (&client->link, &adap->client_list); + +return 0 ; + +err_uninit: +auxiliary_device_uninit (auxdev); + +err_free: +kfree (client); + +return ret; +}drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ +static int ljca_enumerate_gpio (struct ljca_adapter *adap) { +u32 valid_pin[LJCA_MAX_GPIO_NUM /BITS_PER_TYPE (u32)]; +struct ljca_gpio_descriptor *desc; +struct ljca_gpio_info *gpio_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +int ret, gpio_num; +unsigned int i; + + ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_ENUM_GPIO,NULL, 0, buf,
Quoted 30 lines
drivers/usb/misc/usb-ljca.c new file +21
-0+ sizeof(buf), true, LJCA_ENUM_CLIENT_TIMEOUT_MS); +if (ret <0 ) +return ret; + +/* check firmware response */ + desc = (struct ljca_gpio_descriptor *)buf; +if (ret !=struct_size (desc, bank_desc, desc->bank_num)) +return -EINVAL ; + + gpio_num = desc->pins_per_bank * desc->bank_num; +if (gpio_num >LJCA_MAX_GPIO_NUM ) +return -EINVAL ; + +/* construct platform data */ + gpio_info =kzalloc (sizeof *gpio_info,GFP_KERNEL ); +if (!gpio_info) +return -ENOMEM ; + gpio_info->num = gpio_num; + +for (i =0 ; i < desc->bank_num; i++) + valid_pin[i] = get_unaligned_le32(&desc-bank_desc[i].valid_pins);
drivers/usb/misc/usb-ljca.c new file +8
-0+bitmap_from_arr32 (gpio_info->valid_pin_map, valid_pin, gpio_num); + + ret =ljca_new_client_device (adap,LJCA_CLIENT_GPIO ,0 ,"ljca-gpio" , + gpio_info,LJCA_GPIO_ACPI_ADR ); +if (ret) +kfree (gpio_info); + +return ret;drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+} + +static int ljca_enumerate_i2c (struct ljca_adapter *adap) { +struct ljca_i2c_descriptor *desc; +struct ljca_i2c_info *i2c_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +unsigned int i; +int ret; + + ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_ENUM_I2C, NULL,0, buf,
Quoted 29 lines
drivers/usb/misc/usb-ljca.c new file +29
-0+ sizeof(buf), true, LJCA_ENUM_CLIENT_TIMEOUT_MS); +if (ret <0 ) +return ret; + +/* check firmware response */ + desc = (struct ljca_i2c_descriptor *)buf; +if (ret !=struct_size (desc, info, desc->num)) +return -EINVAL ; + +for (i =0 ; i < desc->num; i++) { +/* construct platform data */ + i2c_info =kzalloc (sizeof *i2c_info,GFP_KERNEL ); +if (!i2c_info) +return -ENOMEM ; + + i2c_info->id = desc->info[i].id; + i2c_info->capacity = desc->info[i].capacity; + i2c_info->intr_pin = desc->info[i].intr_pin; + + ret =ljca_new_client_device (adap,LJCA_CLIENT_I2C , i, +"ljca-i2c" , i2c_info, +LJCA_I2C1_ACPI_ADR + i); +if (ret) { +kfree (i2c_info); +return ret; + } + } + +return 0 ;drivers/usb/misc/usb-ljca.c
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+} + +static int ljca_enumerate_spi (struct ljca_adapter *adap) { +struct ljca_spi_descriptor *desc; +struct ljca_spi_info *spi_info; +u8 buf[LJCA_MAX_PAYLOAD_SIZE ]; +unsigned int i; +int ret; + + ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_ENUM_SPI, NULL,0, buf,
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ sizeof(buf), true, LJCA_ENUM_CLIENT_TIMEOUT_MS); +if (ret <0 ) +return ret; + + desc = (struct ljca_spi_descriptor *)buf; +for (i =0 ; i < desc->num; i++) { +/* construct platform data */ + spi_info =kzalloc (sizeof *spi_info,GFP_KERNEL ); +if (!spi_info) +return -ENOMEM ;drivers/usb/misc/usb-ljca.c line 638
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ + spi_info->id = desc->info[i].id; + spi_info->capacity = desc->info[i].capacity; + + ret =ljca_new_client_device (adap,LJCA_CLIENT_SPI , i, +"ljca-spi" , spi_info, +LJCA_SPI1_ACPI_ADR + i); +if (ret) { +kfree (spi_info); +return ret;What about the other objects that you created here, don't you need to unwind the new ones if one in the chain fails? And if not, why stop at the first failure?
Quoted 15 lines
drivers/usb/misc/usb-ljca.c new file +15
-0+ } + } + +return 0 ; +} + + +static int ljca_enumerate_clients (struct ljca_adapter *adap) { +int ret; + + ret =ljca_reset_handshake (adap); +if (ret) +return ret; + + ret =ljca_enumerate_gpio (adap);drivers/usb/misc/usb-ljca.c line 683
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (ret) +dev_warn (adap->dev,"enumerate GPIO error\n" ); + + ret =ljca_enumerate_i2c (adap); +if (ret) +dev_warn (adap->dev,"enumerate I2C error\n" ); + + ret =ljca_enumerate_spi (adap); +if (ret) +dev_warn (adap->dev,"enumerate SPI error\n" );So none of these "errors" are actually errors:
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;You return success? Why? Are they not actually problems?
This is to be compatible with old version FW which does not support full USB2xxx functions, so it just warn here as this is. To make things more clear, I re-structure this as below, hope that helps, thanks
static int ljca_enumerate_clients(struct ljca_adapter *adap)
{
struct ljca_client *client, *next;
int ret;
ret = ljca_reset_handshake(adap);
if (ret)
return ret;
ret = ljca_enumerate_gpio(adap);
if (ret)
goto err_free;
ret = ljca_enumerate_i2c(adap);
if (ret)
goto err_free;
ret = ljca_enumerate_spi(adap);
if (ret)
goto err_free;
return 0;err_free:
adap->disconnect = true;
list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) {
auxiliary_device_delete(&client->auxdev);
auxiliary_device_uninit(&client->auxdev);
list_del_init(&client->link);
kfree(client);
}
return ret;
}And accordingly, the ljca_enumerate_xxx() has slightly change to cover the unsupported case as below( take spi as an example)
@@ -617,6 +633,11 @@ static int ljca_enumerate_spi(struct ljca_adapter *adap)
ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_ENUM_SPI, NULL, 0, buf,
sizeof(buf), true, LJCA_ENUM_CLIENT_TIMEOUT_MS);
+ if (ret == -ETIMEDOUT) {
+ dev_warn(adap->dev, "doesn't support SPI function\n");
+ return 0;
+ }
+
if (ret < 0)
return ret;Thanks
Wentong
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH v19 1/4] usb: Add support for Intel LJCA device
Quoted 16 lines · Wentong
Quoted 16 lines
From: Greg KH <[email protected]>
drivers/usb/misc/usb-ljca.c line 189
Quoted 11 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +11
-0+static void ljca_handle_event (struct ljca_adapter *adap, +struct ljca_msg *header) +{ +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. +* firmware message structure should include id when +* multiple same type clients register event callback. +*/ When will this be fixed?
Quoted 8 lines
Quoted 1 line
If not now, why not?
Actually this doesn't impact current functionality because only GPIO register event callback, but from coding perspective it should add the id in the message structure. This fix should be done by firmware first, but many products have already been running the firmware, it's not easy to update the firmware.
Can I just remove the 'FIXME' and leave the comment here?
If you are never going to fix it, it does not need a FIXME, right? :)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/usb/misc/usb-ljca.c new file +4
-0+spin_unlock_irqrestore (&adap->lock, flags); +return ; + } +Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 223
Quoted 5 lines
drivers/usb/misc/usb-ljca.c new file +5
-0+ ibuf_len = adap->ex_buf_len; + ibuf = adap->ex_buf; + +if (ibuf && ibuf_len) { + actual_len = min_t(unsigned int, header->len, ibuf_len);You control both of these types, why aren't they the same type to start with? Why the force cast?
Quoted 3 lines
The len of header is defined by firmware, it should be u8 type. But the
ex_buf_lenis passed by API users, I don't want users to do the cast if their buffer is large than 256.
Then fix the api to use a u8 as obviously you can not handle more data then that for now.
Quoted 9 lines
Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 229
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ +/* copy received data to external buffer */ +memcpy (ibuf, header->data, actual_len); + } +/* update copied data length */ + adap->actual_length = actual_len;Wait, what happens if you don't actually copy the data?
Quoted 3 lines
This
actual_lengthis the actual length of data copied to external buffer where is to save the command response. The API callers should check the response length according to the command you passed to this API.
But they aren't checking it as I pointed out elsewhere.
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
drivers/usb/misc/usb-ljca.c new file +24
-0+} + +static int ljca_send (struct ljca_adapter *adap,u8 type,u8 cmd, +const u8 *obuf,unsigned int obuf_len,u8 *ibuf, +unsigned int ibuf_len,bool ack,unsigned long timeout) { +unsigned int msg_len =sizeof (struct ljca_msg ) + obuf_len; +struct ljca_msg *header = adap->tx_buf; +unsigned int actual; +int ret =0 ; + +if (adap->disconnect) +return -ENODEV ; + +if (msg_len > adap->tx_buf_len) +return -EINVAL ; + +mutex_lock (&adap->mutex); + + scoped_guard(spinlock_irqsave, &adap->lock) { + header->type = type; + header->cmd = cmd; + header->len = obuf_len; +if (obuf) +memcpy (header->data, obuf, obuf_len);Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 303
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ header->flags =LJCA_CMPL_FLAG | (ack ?LJCA_ACK_FLAG :0 ); + + adap->ex_buf = ibuf; + adap->ex_buf_len = ibuf_len; + adap->actual_length =0 ; + }Do you really need a scoped guard when you can not fail out of the block?
Quoted 3 lines
The
scoped_guardis required by you with "Why not use the functionality incleanup.hfor this lock? Makes this function much simpler." If I understand correctly, so I use thescoped_guardwhere I can to make things simpler.
But that's not making anything simpler here, cleanup.h works well when you have error paths that would be more complex without it. You do not have that here at all now (maybe you did before?)
Quoted 6 lines
Quoted 1 line
Why do you have both a mutex and spinlock grabed?
The mutex is to avoid command download concurrently
The spinlock is to protect
tx_bufandex_buf, which may be accessed by tx and rx at the same time.
Please document this somewhere.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+ ret =usb_bulk_msg (adap->usb_dev, adap->tx_pipe, header, + msg_len, &actual,LJCA_WRITE_TIMEOUT_MS ); + +usb_autopm_put_interface (adap->intf); + +if (!ret && ack) { + ret =wait_for_completion_timeout (&adap->cmd_completion, + timeout); +if (ret <0 ) { + goto out;Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 324
Quoted 6 lines
drivers/usb/misc/usb-ljca.c new file +6
-0+ }if (!ret) { + ret = -ETIMEDOUT ; + goto out; + } + } + ret = adap->actual_length;Why are you not verifying that you sent what you wanted to send?
Quoted 7 lines
As I said, the
actual_lengthis the actual length of data copied to user buffer instead of the length of what we want to send.And even for verifying the length of what we want to send, the max length of the message is
sizeof(struct ljca_msg)+LJCA_MAX_PACKET_SIZEwhich is less than the endpoint's max packet size, so I don't check the actual sent length in aboveusb_bulk_msg().
But you need to.
Quoted 11 lines
Quoted 7 lines
When you call this function, sometimes you check that the function sent the proper amount of data, but in many places you do not, and you assume that the full buffer was sent, which is not correct. So please change _this_ function to check that you sent the proper amount and then the caller logic will be much simpler and actually work like you are using it in many places (some places you got it right, some wrong, which is a HUGE indication that the API is wrong because you wrote this code, and if you can't get it right...)
As I said, the return value of this function is the response data length instead of sent data length. And in this patch set, every caller has verified if the response length matched with the sent command.
No, I found many users that did not do this. Please make the api easy to use, right now it's not.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+static int ljca_match_device_ids (struct acpi_device *adev,void +*data) { +struct ljca_match_ids_walk_data *wd = data; +const char *uid =acpi_device_uid (adev); + +if (acpi_match_device_ids (adev, wd->ids)) +return 0 ; + +if (!wd->uid) + goto match;Quoted 8 lines
drivers/usb/misc/usb-ljca.c line 400
Quoted 3 lines
drivers/usb/misc/usb-ljca.c new file +3
-0+ +if (!uid) + uid ="0" ;Are you sure this is a valid uid to use? If so, why? What happens if this gets set to "0" for multiple ones? Don't underestimate broken firmware tables, but also don't paper over problems in ways that will be impossible to notice and can cause problems.
Quoted 7 lines
This actually has been discussed in previous email as bellow:
some DSDTs have only 1 ACPI companion for the 2 I2C controllers and these don't set a UID at all. On these models only the first I2C controller is used. So if a HID match has no UID use "0" for the HID. assigning the ACPI companion to the first I2C controller. An example device with this setup is the Dell Latitude 9420.
Then document this really really well in the code itself, otherwise it looks broken.
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
drivers/usb/misc/usb-ljca.c new file +8
-0+static int ljca_enumerate_clients (struct ljca_adapter *adap) { +int ret; + + ret =ljca_reset_handshake (adap); +if (ret) +return ret; + + ret =ljca_enumerate_gpio (adap);drivers/usb/misc/usb-ljca.c line 683
Quoted 10 lines
drivers/usb/misc/usb-ljca.c new file +10
-0+if (ret) +dev_warn (adap->dev,"enumerate GPIO error\n" ); + + ret =ljca_enumerate_i2c (adap); +if (ret) +dev_warn (adap->dev,"enumerate I2C error\n" ); + + ret =ljca_enumerate_spi (adap); +if (ret) +dev_warn (adap->dev,"enumerate SPI error\n" );So none of these "errors" are actually errors:
Quoted 6 lines
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;You return success? Why? Are they not actually problems?
This is to be compatible with old version FW which does not support full USB2xxx functions, so it just warn here as this is.
Why do you have to support obsolete and broken firmware? Can't it be updated?
Quoted 44 lines
To make things more clear, I re-structure this as below, hope that helps, thanks
static int
ljca_enumerate_clients(struct ljca_adapter *adap){ struct ljca_client *client, *next; int ret; ret = ljca_reset_handshake(adap); if (ret) return ret; ret = ljca_enumerate_gpio(adap); if (ret) goto err_free; ret = ljca_enumerate_i2c(adap); if (ret) goto err_free; ret = ljca_enumerate_spi(adap); if (ret) goto err_free; return 0;
err_free:adap->disconnect = true; list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) { auxiliary_device_delete(&client->auxdev); auxiliary_device_uninit(&client->auxdev); list_del_init(&client->link); kfree(client); } return ret; }And accordingly, the
ljca_enumerate_xxx()has slightly change to cover the unsupported case as below( take spi as an example)
Review static int ljca_enumerate_spi(struct ljca_adapter *adap) · line 638
Quoted 6 lines
(quoted diff) +3
-0@@ -617,6 +633,11 @@ static int ljca_enumerate_spi(struct ljca_adapter *adap) ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_ENUM_SPI, NULL, 0, buf, sizeof(buf), true, LJCA_ENUM_CLIENT_TIMEOUT_MS); + if (ret == -ETIMEDOUT) { + dev_warn(adap->dev, "doesn't support SPI function\n"); + return 0;
You warn, yet return success? Again, that doesn't work well as you never know if you need to unwind it or not.
Either report an error and handle it, or don't, but what you have here looks broken as-is.
thanks,
greg k-h
RE: [PATCH v19 1/4] usb: Add support for Intel LJCA device
Quoted 23 lines
From: Greg KH <[email protected]>
Quoted 15 lines · Wentong
Quoted 15 lines
From: Greg KH <[email protected]> On Sun, Sep 17, 2023 at
drivers/usb/misc/usb-ljca.c line 189
Quoted 10 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +10
-0+static void ljca_handle_event (struct ljca_adapter *adap, +struct ljca_msg *header) { +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. +* firmware message structure should include id when +* multiple same type clients register event callback. +*/ When will this be fixed?
Quoted 6 lines
Quoted 1 line
If not now, why not?
Actually this doesn't impact current functionality because only GPIO register event callback, but from coding perspective it should add the id in the message structure. This fix should be done by firmware first, but many products have already been running the firmware, it's not easy
Quoted 5 lines
to update the firmware.
Quoted 2 lines
Can I just remove the 'FIXME' and leave the comment here?
If you are never going to fix it, it does not need a FIXME, right? :)
Thanks, I will remove 'FIXME' here.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
You control both of these types, why aren't they the same type to start with? Why the force cast?
The len of header is defined by firmware, it should be u8 type. But the
ex_buf_lenis passed by API users, I don't want users to do the cast if their buffer is large than 256.Then fix the api to use a u8 as obviously you can not handle more data then that for now.
Ack, thanks
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
Do you really need a scoped guard when you can not fail out of the block?
The
scoped_guardis required by you with "Why not use the functionality incleanup.hfor this lock? Makes this function much simpler." If I understand correctly, so I use thescoped_guardwhere I can tomake things simpler.
But that's not making anything simpler here,
cleanup.hworks well when you have error paths that would be more complex without it. You do not have that here at all now (maybe you did before?)
I'll remove scoped guard
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
Why do you have both a mutex and spinlock grabed?
The mutex is to avoid command download concurrently
The spinlock is to protect
tx_bufandex_buf, which may be accessed by tx and rx at the same time.Please document this somewhere.
Ack, thanks. Below is the kernel doc for struct ljca_adapter where we have spinlock and mutex document.
/**
* struct ljca_adapter - represent a ljca adapter
*
* @intf: the usb interface for this ljca adapter
* @usb_dev: the usb device for this ljca adapter
* @dev: the specific device info of the usb interface
* @rx_pipe: bulk in pipe for receive data from firmware
* @tx_pipe: bulk out pipe for send data to firmware
* @rx_urb: urb used for the bulk in pipe
* @rx_buf: buffer used to receive command response and event
* @rx_len: length of rx buffer
* @ex_buf: external buffer to save command response
* @ex_buf_len: length of external buffer
* @actual_length: actual length of data copied to external buffer
* @tx_buf: buffer used to download command to firmware
* @tx_buf_len: length of tx buffer
* @lock: spinlock to protect tx_buf and ex_buf
* @cmd_completion: completion object as the command receives ack
* @mutex: mutex to avoid command download concurrently
* @client_list: client device list
* @disconnect: usb disconnect ongoing or not
* @reset_id: used to reset firmware
*/
struct ljca_adapter {
struct usb_interface *intf;
struct usb_device *usb_dev;
struct device *dev;
unsigned int rx_pipe;
unsigned int tx_pipe;
struct urb *rx_urb;
void *rx_buf;
unsigned int rx_len;
u8 *ex_buf;
u8 ex_buf_len;
u8 actual_length;
void *tx_buf;
u8 tx_buf_len;
spinlock_t lock;
struct completion cmd_completion;
struct mutex mutex;
struct list_head client_list;
bool disconnect;
u32 reset_id;
};Quoted 11 lines
Quoted 9 lines
Quoted 1 line
Why are you not verifying that you sent what you wanted to send?
As I said, the
actual_lengthis the actual length of data copied to user buffer instead of the length of what we want to send.And even for verifying the length of what we want to send, the max length of the message is
sizeof(struct ljca_msg)+LJCA_MAX_PACKET_SIZEwhich is less than the endpoint's max packet size, so I don't check the actual sent length in aboveusb_bulk_msg().But you need to.
Ack, thanks.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
When you call this function, sometimes you check that the function sent the proper amount of data, but in many places you do not, and you assume that the full buffer was sent, which is not correct. So please change _this_ function to check that you sent the proper amount and then the caller logic will be much simpler and actually work like you are using it in many places (some places you got it right, some wrong, which is a HUGE indication that the API is wrong because you wrote this code, and if you can't get it right...)
Quoted 5 lines
Quoted 3 lines
As I said, the return value of this function is the response data length instead of sent data length. And in this patch set, every caller has verified if the response length matched with the sent command.
No, I found many users that did not do this.
Ack, I will check more, thanks
Quoted 1 line
Please make the api easy to use, right now it's not.
I post the new ljca_send() here to try to address several comments.
First it changes the type of buffer length to u8, second it checks the actual sent of length usb_bulk_msg(). It removes the scoped guard as well.
And below gives an explanation of the parameters and return value.
The parameters(type, cmd, obuf_len) are used to construct message header, obuf is used for message data. And ibuf and ibuf_len are for response buffer and buffer length passed by API users. ack indicates if the command need an ack from firmware, timeout is timeout value to wait command ack.
And the return value is the response copied to response buffer passed by API users, normally the users know how large buffer they have to pass to this API, but from coding perspective we should check the passed response buffer length(ibuf_len) and return the actual copied data length to the buffer.
Hope that helps, thanks
static int ljca_send(struct ljca_adapter *adap, u8 type, u8 cmd,
const u8 *obuf, u8 obuf_len, u8 *ibuf, u8 ibuf_len, bool ack, unsigned long timeout)
{
unsigned int msg_len = sizeof(struct ljca_msg) + obuf_len;
struct ljca_msg *header = adap->tx_buf;
unsigned int transferred;
unsigned long flags;
int ret;
if (adap->disconnect)
return -ENODEV;
if (msg_len > adap->tx_buf_len)
return -EINVAL;
mutex_lock(&adap->mutex);
spin_lock_irqsave(&adap->lock, flags);
header->type = type;
header->cmd = cmd;
header->len = obuf_len;
if (obuf)
memcpy(header->data, obuf, obuf_len);
header->flags = LJCA_CMPL_FLAG | (ack ? LJCA_ACK_FLAG : 0);
adap->ex_buf = ibuf;
adap->ex_buf_len = ibuf_len;
adap->actual_length = 0;
spin_unlock_irqrestore(&adap->lock, flags); reinit_completion(&adap->cmd_completion);
ret = usb_autopm_get_interface(adap->intf);
if (ret < 0)
goto out;
ret = usb_bulk_msg(adap->usb_dev, adap->tx_pipe, header,
msg_len, &transferred, LJCA_WRITE_TIMEOUT_MS);
usb_autopm_put_interface(adap->intf);
if (ret < 0)
goto out;
if (transferred != msg_len) {
ret = -EIO;
goto out;
}
if (ack) {
ret = wait_for_completion_timeout(&adap->cmd_completion,
timeout);
if (!ret) {
ret = -ETIMEDOUT;
goto out;
}
}
ret = adap->actual_length;out:
spin_lock_irqsave(&adap->lock, flags); adap->ex_buf = NULL; adap->ex_buf_len = 0; memset(header, 0, sizeof(*header)); spin_unlock_irqrestore(&adap->lock, flags); mutex_unlock(&adap->mutex); return ret; }
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Are you sure this is a valid uid to use? If so, why? What happens if this gets set to "0" for multiple ones? Don't underestimate broken firmware tables, but also don't paper over problems in ways that will be impossible to notice and can cause problems.
This actually has been discussed in previous email as bellow:
Quoted 7 lines
Quoted 5 lines
some DSDTs have only 1 ACPI companion for the 2 I2C controllers and these don't set a UID at all. On these models only the first I2C controller is used. So if a HID match has no UID use "0" for the HID. assigning the ACPI companion to the first I2C controller. An example device with this setup is the Dell Latitude 9420.
Then document this really really well in the code itself, otherwise it looks broken.
Ack, thanks, I post the new ljca_match_device_ids() here, hope that helps, thanks.
static int ljca_match_device_ids(struct acpi_device *adev, void *data)
{
struct ljca_match_ids_walk_data *wd = data;
const char *uid = acpi_device_uid(adev);
if (acpi_match_device_ids(adev, wd->ids))
return 0;
if (!wd->uid)
goto match;
if (!uid)
/*
* Some DSDTs have only one ACPI companion for the two I2C
* controllers and they don't set a UID at all (e.g. Dell
* Latitude 9420). On these platforms only the first I2C
* controller is used, so if a HID match has no UID we use
* "0" as the UID and assign ACPI companion to the first
* I2C controller.
*/
uid = "0";
else
uid = strchr(uid, wd->uid[0]);
if (!uid || strcmp(uid, wd->uid))
return 0;match:
wd->adev = adev; return 1; }
Quoted 4 lines
Quoted 2 lines
This is to be compatible with old version FW which does not support full USB2xxx functions, so it just warn here as this is.
Why do you have to support obsolete and broken firmware? Can't it be updated?
make sense, and probably they have to update, thanks
Quoted 5 lines
You warn, yet return success? Again, that doesn't work well as you never know if you need to unwind it or not.
Either report an error and handle it, or don't, but what you have here looks broken as-is.
Ack, it should report error and handle it. Thanks, the function will be like below:
static int ljca_enumerate_clients(struct ljca_adapter *adap)
{
struct ljca_client *client, *next;
int ret;
ret = ljca_reset_handshake(adap);
if (ret)
goto err_kill;
ret = ljca_enumerate_gpio(adap);
if (ret) {
dev_err(adap->dev, "enumerate GPIO error\n");
goto err_kill;
}
ret = ljca_enumerate_i2c(adap);
if (ret) {
dev_err(adap->dev, "enumerate I2C error\n");
goto err_kill;
}
ret = ljca_enumerate_spi(adap);
if (ret) {
dev_err(adap->dev, "enumerate SPI error\n");
goto err_kill;
}
return 0;err_kill:
adap->disconnect = true;
usb_kill_urb(adap->rx_urb);
list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) {
auxiliary_device_delete(&client->auxdev);
auxiliary_device_uninit(&client->auxdev);
list_del_init(&client->link);
kfree(client);
}
return ret;
}Thanks,
Wentong
Quoted 4 lines
thanks,
greg k-h
RE: [PATCH v19 1/4] usb: Add support for Intel LJCA device
Quoted 350 lines
From: Wu, Wentong
Quoted 24 lines
From: Greg KH <[email protected]> On Fri, Sep 29, 2023 at
Quoted 15 lines · Wentong
Quoted 15 lines
From: Greg KH <[email protected]> On Sun, Sep 17, 2023 at
drivers/usb/misc/usb-ljca.c line 189
Quoted 10 lines · Wentong Wu
drivers/usb/misc/usb-ljca.c new file +10
-0+static void ljca_handle_event (struct ljca_adapter *adap, +struct ljca_msg *header) { +struct ljca_client *client; + +list_for_each_entry (client, &adap->client_list, link) { +/* +* FIXME: currently only GPIO register event callback. +* firmware message structure should include id when +* multiple same type clients register event callback. +*/ When will this be fixed?
Quoted 7 lines
Quoted 1 line
If not now, why not?
Actually this doesn't impact current functionality because only GPIO register event callback, but from coding perspective it should add the id in the message structure. This fix should be done by firmware first, but many products have already been running the firmware, it's not easy
Quoted 5 lines
to update the firmware.
Quoted 2 lines
Can I just remove the 'FIXME' and leave the comment here?
If you are never going to fix it, it does not need a FIXME, right? :)
Thanks, I will remove 'FIXME' here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
You control both of these types, why aren't they the same type to start
with?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Why the force cast?
The len of header is defined by firmware, it should be u8 type. But the
ex_buf_lenis passed by API users, I don't want users to do the cast if their buffer is large than 256.Then fix the api to use a u8 as obviously you can not handle more data then that for now.
Ack, thanks
Quoted 11 lines
Quoted 6 lines
Quoted 1 line
Do you really need a scoped guard when you can not fail out of the block?
The
scoped_guardis required by you with "Why not use the functionality incleanup.hfor this lock? Makes this function much simpler." If I understand correctly, so I use thescoped_guardwhere I can tomake things simpler.
But that's not making anything simpler here,
cleanup.hworks well when you have error paths that would be more complex without it. You do not have that here at all now (maybe you did before?)I'll remove scoped guard
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
Why do you have both a mutex and spinlock grabed?
The mutex is to avoid command download concurrently
The spinlock is to protect
tx_bufandex_buf, which may be accessed by tx and rx at the same time.Please document this somewhere.
Ack, thanks. Below is the kernel doc for struct
ljca_adapterwhere we have spinlock and mutex document./**
* structljca_adapter- represent a ljca adapter
*
* @intf: the usb interface for this ljca adapter
* @usb_dev: the usb device for this ljca adapter
* @dev: the specific device info of the usb interface
* @rx_pipe: bulk in pipe for receive data from firmware
* @tx_pipe: bulk out pipe for send data to firmware
* @rx_urb: urb used for the bulk in pipe
* @rx_buf: buffer used to receive command response and event
* @rx_len: length of rx buffer
* @ex_buf: external buffer to save command response
* @ex_buf_len: length of external buffer
* @actual_length: actual length of data copied to external buffer
* @tx_buf: buffer used to download command to firmware
* @tx_buf_len: length of tx buffer
* @lock: spinlock to protecttx_bufandex_buf
* @cmd_completion: completion object as the command receives ack
* @mutex: mutex to avoid command download concurrently
* @client_list: client device list
* @disconnect: usb disconnect ongoing or not
* @reset_id: used to reset firmware
*/struct ljca_adapter { struct usb_interface *intf; struct usb_device *usb_dev; struct device *dev; unsigned int rx_pipe; unsigned int tx_pipe; struct urb *rx_urb; void *rx_buf; unsigned int rx_len; u8 *ex_buf; u8 ex_buf_len; u8 actual_length; void *tx_buf; u8 tx_buf_len; spinlock_t lock; struct completion cmd_completion; struct mutex mutex; struct list_head client_list; bool disconnect; u32 reset_id; };Quoted 11 lines
Quoted 9 lines
Quoted 1 line
Why are you not verifying that you sent what you wanted to send?
As I said, the
actual_lengthis the actual length of data copied to user buffer instead of the length of what we want to send.And even for verifying the length of what we want to send, the max length of the message is
sizeof(struct ljca_msg)+LJCA_MAX_PACKET_SIZEwhich is less than the endpoint's max packet size, so I don't check the actual sent length in aboveusb_bulk_msg().But you need to.
Ack, thanks.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
When you call this function, sometimes you check that the function sent the proper amount of data, but in many places you do not, and you assume that the full buffer was sent, which is not correct. So please change _this_ function to check that you sent the proper amount and then the caller logic will be much simpler and actually work like you are using it in many places (some places you got it right, some wrong, which is a HUGE indication that the API is wrong because you wrote this code, and if you can't get it right...)
Quoted 5 lines
Quoted 3 lines
As I said, the return value of this function is the response data length instead of sent data length. And in this patch set, every caller has verified if the response length matched with the sent command.
No, I found many users that did not do this.
Ack, I will check more, thanks
Quoted 1 line
Please make the api easy to use, right now it's not.
I post the new
ljca_send()here to try to address several comments.First it changes the type of buffer length to u8, second it checks the actual sent of length
usb_bulk_msg(). It removes the scoped guard as well.And below gives an explanation of the parameters and return value.
The
parameters(type, cmd, obuf_len)are used to construct message header, obuf is used for message data. And ibuf andibuf_lenare for response buffer and buffer length passed by API users. ack indicates if the command need an ack from firmware, timeout is timeout value to wait command ack.And the return value is the response copied to response buffer passed by API users, normally the users know how large buffer they have to pass to this API, but from coding perspective we should check the passed response buffer
length(ibuf_len)and return the actual copied data length to the buffer.Hope that helps, thanks
static int ljca_send(struct
ljca_adapter*adap, u8 type, u8 cmd,const u8 *obuf, u8 obuf_len, u8 *ibuf, u8 ibuf_len, bool ack, unsigned long timeout) { unsigned int msg_len = sizeof(struct ljca_msg) + obuf_len; struct ljca_msg *header = adap->tx_buf; unsigned int transferred; unsigned long flags; int ret; if (adap->disconnect) return -ENODEV; if (msg_len > adap->tx_buf_len) return -EINVAL; mutex_lock(&adap->mutex); spin_lock_irqsave(&adap->lock, flags); header->type = type; header->cmd = cmd; header->len = obuf_len; if (obuf) memcpy(header->data, obuf, obuf_len); header->flags = LJCA_CMPL_FLAG | (ack ? LJCA_ACK_FLAG : 0); adap->ex_buf = ibuf; adap->ex_buf_len = ibuf_len; adap->actual_length = 0; spin_unlock_irqrestore(&adap->lock, flags);
reinit_completion(&adap->cmd_completion);ret = usb_autopm_get_interface(adap->intf); if (ret < 0) goto out; ret = usb_bulk_msg(adap->usb_dev, adap->tx_pipe, header, msg_len, &transferred, LJCA_WRITE_TIMEOUT_MS); usb_autopm_put_interface(adap->intf); if (ret < 0) goto out; if (transferred != msg_len) { ret = -EIO; goto out; } if (ack) { ret = wait_for_completion_timeout(&adap->cmd_completion, timeout); if (!ret) { ret = -ETIMEDOUT; goto out; } } ret = adap->actual_length;out:
spin_lock_irqsave(&adap->lock, flags); adap->ex_buf = NULL; adap->ex_buf_len = 0; memset(header, 0, sizeof(*header)); spin_unlock_irqrestore(&adap->lock, flags); mutex_unlock(&adap->mutex); return ret; }Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Are you sure this is a valid uid to use? If so, why? What happens if this gets set to "0" for multiple ones? Don't underestimate broken firmware tables, but also don't paper over problems in ways that will be impossible to notice and can cause problems.
This actually has been discussed in previous email as bellow:
Quoted 7 lines
Quoted 5 lines
some DSDTs have only 1 ACPI companion for the 2 I2C controllers and these don't set a UID at all. On these models only the first I2C controller is used. So if a HID match has no UID use "0" for the HID. assigning the ACPI companion to the first I2C controller. An example device with this setup is the Dell Latitude 9420.
Then document this really really well in the code itself, otherwise it looks
broken.
Ack, thanks, I post the new
ljca_match_device_ids()here, hope that helps, thanks.static int ljca_match_device_ids(struct acpi_device *adev, void *data) { struct ljca_match_ids_walk_data *wd = data; const char *uid = acpi_device_uid(adev); if (acpi_match_device_ids(adev, wd->ids)) return 0; if (!wd->uid) goto match; if (!uid) /* * Some DSDTs have only one ACPI companion for the two I2C * controllers and they don't set a UID at all (e.g. Dell * Latitude 9420). On these platforms only the first I2C * controller is used, so if a HID match has no UID we use * "0" as the UID and assign ACPI companion to the first * I2C controller. */ uid = "0"; else uid = strchr(uid, wd->uid[0]); if (!uid || strcmp(uid, wd->uid)) return 0;match:
wd->adev = adev; return 1; }Quoted 4 lines
Quoted 2 lines
This is to be compatible with old version FW which does not support full USB2xxx functions, so it just warn here as this is.
Why do you have to support obsolete and broken firmware? Can't it be
updated?
make sense, and probably they have to update, thanks
Quoted 5 lines
You warn, yet return success? Again, that doesn't work well as you never know if you need to unwind it or not.
Either report an error and handle it, or don't, but what you have here looks broken as-is.
Ack, it should report error and handle it. Thanks, the function will be like below:
static int ljca_enumerate_clients(struct ljca_adapter *adap) { struct ljca_client *client, *next; int ret; ret = ljca_reset_handshake(adap); if (ret) goto err_kill; ret = ljca_enumerate_gpio(adap); if (ret) { dev_err(adap->dev, "enumerate GPIO error\n"); goto err_kill; } ret = ljca_enumerate_i2c(adap); if (ret) { dev_err(adap->dev, "enumerate I2C error\n"); goto err_kill; } ret = ljca_enumerate_spi(adap); if (ret) { dev_err(adap->dev, "enumerate SPI error\n"); goto err_kill; } return 0;
err_kill:
Quoted 15 lines
adap->disconnect = true;
usb_kill_urb(adap->rx_urb);
list_for_each_entry_safe_reverse(client, next, &adap->client_list, link) {
auxiliary_device_delete(&client->auxdev);
auxiliary_device_uninit(&client->auxdev);
list_del_init(&client->link);
kfree(client);
}
return ret;
}Hi Greg,
Could you please share your comment about this? If no more comment, I will sent out next version patch set. Thanks
BR,
Wentong
Quoted 5 lines
Quoted 5 lines
thanks,
greg k-h
PATCH v19 2/4 i2c: Add support for Intel LJCA USB I2C driver
In reply to Wentong WuImplements the I2C function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA I2C module with specific protocol through interfaces exported by LJCA USB driver.
--- drivers/i2c/busses/Kconfig | 11 ++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ljca.c | 342 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100644 drivers/i2c/busses/i2c-ljca.c
drivers/i2c/busses/Kconfig +11 -0
@@ -1264,6 +1264,17 @@ config I2C_DLN2 This driver can also be built as a module. If so, the module will be called i2c-dln2. +config I2C_LJCA + tristate "I2C functionality of Intel La Jolla Cove Adapter" + depends on USB_LJCA + default USB_LJCA + help + If you say yes to this option, I2C functionality support of Intel + La Jolla Cove Adapter (LJCA) will be included. + + This driver can also be built as a module. If so, the module + will be called i2c-ljca. + config I2C_CP2615 tristate "Silicon Labs CP2615 USB sound card and I2C adapter" depends on USB
drivers/i2c/busses/Makefile +1 -0
@@ -133,6 +133,7 @@ obj-$(CONFIG_I2C_GXP) += i2c-gxp.o # External I2C/SMBus adapter drivers obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o +obj-$(CONFIG_I2C_LJCA) += i2c-ljca.o obj-$(CONFIG_I2C_CP2615) += i2c-cp2615.o obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o obj-$(CONFIG_I2C_PCI1XXXX) += i2c-mchp-pci1xxxx.o
drivers/i2c/busses/i2c-ljca.c new file +342 -0
342 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v19 2/4] i2c: Add support for Intel LJCA USB I2C driver
drivers/i2c/busses/i2c-ljca.c line 259
Quoted 4 lines
drivers/i2c/busses/i2c-ljca.c new file +3
-0+static u32 ljca_i2c_func (struct i2c_adapter *adap) +{ +return I2C_FUNC_I2C ;
You could use this here to make the driver way more useful:
return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
Except I2C_FUNC_SMBUS_QUICK, emulated SMBUS calls work out of the box.
For I2C_FUNC_SMBUS_QUICK, you need to test zero-length transfers indeed ('i2cdetect <busnum>' will use it and is a good testcase). Which would be good anyway, because if it is not supporting zero-length, we need to add an adapter->quirk flag as well.
We could add this incrementally, but it will be better to have this correct right away. i2cdetect is a good and simple testcase.
RE: [PATCH v19 2/4] i2c: Add support for Intel LJCA USB I2C driver
Quoted 7 lines
From: Wolfram Sang <[email protected]>
Review
Quoted 2 lines
(quoted diff) +2
-0+static u32 ljca_i2c_func(struct i2c_adapter *adap) { + return I2C_FUNC_I2C;You could use this here to make the driver way more useful:
Quoted 9 lines
return
I2C_FUNC_I2C| (I2C_FUNC_SMBUS_EMUL&
~I2C_FUNC_SMBUS_QUICK);Except
I2C_FUNC_SMBUS_QUICK, emulated SMBUS calls work out of the box.For
I2C_FUNC_SMBUS_QUICK, you need to test zero-length transfers indeed ('i2cdetect <busnum>' will use it and is a good testcase). Which would be good anyway, because if it is not supporting zero-length, we need to add an adapter-Quoted 1 line
quirk flag as well.
Thanks.
And with i2cdetect -q busnum, I see error on driver side which enable I2C_FUNC_SMBUS_EMUL and not disable I2C_FUNC_SMBUS_QUICK, I think it means we don't support zero-length transfer if I understand correctly.
Quoted 3 lines
We could add this incrementally, but it will be better to have this correct right away. i2cdetect is a good and simple testcase.
So the code will be like below, please help take a look, thanks.
static u32 ljca_i2c_func(struct i2c_adapter *adap)
{
return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
}static const struct i2c_adapter_quirks ljca_i2c_quirks = {
.flags = I2C_AQ_NO_ZERO_LEN,
.max_read_len = LJCA_I2C_MAX_XFER_SIZE,
.max_write_len = LJCA_I2C_MAX_XFER_SIZE,
};BR,
Wentong
Re: [PATCH v19 2/4] i2c: Add support for Intel LJCA USB I2C driver
Quoted 4 lines
And with i2cdetect -q busnum, I see error on driver side which enable
I2C_FUNC_SMBUS_EMULand not disableI2C_FUNC_SMBUS_QUICK, I think it means we don't support zero-length transfer if I understand correctly.
At least, not currently. Sometimes the driver just needs updates, sometimes the HW simply cannot do it. If it is a software issue, we can fix it incrementally.
Quoted 4 lines
static u32
ljca_i2c_func(struct i2c_adapter *adap){ return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); }
Yes.
Quoted 5 lines
static const struct i2c_adapter_quirks ljca_i2c_quirks = {
.flags = I2C_AQ_NO_ZERO_LEN,
.max_read_len = LJCA_I2C_MAX_XFER_SIZE,
.max_write_len = LJCA_I2C_MAX_XFER_SIZE,
};Yes.
I think the I2C driver is good then.
PATCH v19 3/4 spi: Add support for Intel LJCA USB SPI driver
In reply to Wentong WuImplements the SPI function of Intel USB-I2C/GPIO/SPI adapter device named "La Jolla Cove Adapter" (LJCA). It communicate with LJCA SPI module with specific protocol through interfaces exported by LJCA USB driver.
--- drivers/spi/Kconfig | 11 ++ drivers/spi/Makefile | 1 + drivers/spi/spi-ljca.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 drivers/spi/spi-ljca.c
drivers/spi/Kconfig +11 -0
@@ -616,6 +616,17 @@ config SPI_FSL_ESPI From MPC8536, 85xx platform uses the controller, and all P10xx, P20xx, P30xx,P40xx, P50xx uses this controller. +config SPI_LJCA + tristate "Intel La Jolla Cove Adapter SPI support" + depends on USB_LJCA + default USB_LJCA + help + Select this option to enable SPI driver for the Intel + La Jolla Cove Adapter (LJCA) board. + + This driver can also be built as a module. If so, the module + will be called spi-ljca. + config SPI_MESON_SPICC tristate "Amlogic Meson SPICC controller" depends on COMMON_CLK
drivers/spi/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_SPI_INTEL_PCI) += spi-intel-pci.o obj-$(CONFIG_SPI_INTEL_PLATFORM) += spi-intel-platform.o obj-$(CONFIG_SPI_LANTIQ_SSC) += spi-lantiq-ssc.o obj-$(CONFIG_SPI_JCORE) += spi-jcore.o +obj-$(CONFIG_SPI_LJCA) += spi-ljca.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o obj-$(CONFIG_SPI_LOONGSON_CORE) += spi-loongson-core.o obj-$(CONFIG_SPI_LOONGSON_PCI) += spi-loongson-pci.o
drivers/spi/spi-ljca.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v19 4/4 gpio: update Intel LJCA USB GPIO driver
In reply to Wentong WuThis driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver. Update the driver according to LJCA USB driver's changes.
--- drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++++++++++++++++++++++-------------------- 2 files changed, 145 insertions(+), 105 deletions(-)
drivers/gpio/Kconfig +2 -2
@@ -1312,9 +1312,9 @@ config GPIO_KEMPLD config GPIO_LJCA tristate "INTEL La Jolla Cove Adapter GPIO support" - depends on MFD_LJCA + depends on USB_LJCA select GPIOLIB_IRQCHIP - default MFD_LJCA + default USB_LJCA help Select this option to enable GPIO driver for the INTEL La Jolla Cove Adapter (LJCA) board.
drivers/gpio/gpio-ljca.c +143 -103
473 lines not on this page · raw message
Signature · 1 line
2.7.4
Greg KH
maintainerRe: [PATCH v19 4/4] gpio: update Intel LJCA USB GPIO driver
Quoted 56 lines · Wentong Wu
This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver. Update the driver according to LJCA USB driver's changes.
Signed-off-by Wentong Wu <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Acked-by Linus Walleij <[email protected]>Tested-by Hans de Goede <[email protected]>--- drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++++++++++++++++++++++-------------------- 2 files changed, 145 insertions(+), 105 deletions(-)drivers/gpio/Kconfig +2
-2@@ -1312,9 +1312,9 @@ config GPIO_KEMPLD config GPIO_LJCA tristate "INTEL La Jolla Cove Adapter GPIO support" - depends on MFD_LJCA + depends on USB_LJCA select GPIOLIB_IRQCHIP - default MFD_LJCA + default USB_LJCA help Select this option to enable GPIO driver for the INTEL La Jolla Cove Adapter (LJCA) board.drivers/gpio/gpio-ljca.c +2
-4@@ -6,6 +6,7 @@*/ #include <linux/acpi.h> +#include <linux/auxiliary_bus.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/dev_printk.h> @@ -13,19 +14,18 @@#include <linux/irq.h> #include <linux/kernel.h> #include <linux/kref.h> -#include <linux/mfd/ljca.h> #include <linux/module.h> -#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/usb/ljca.h> /* GPIO commands */ -#define LJCA_GPIO_CONFIG 1 -#define LJCA_GPIO_READ 2
drivers/gpio/gpio-ljca.c line 28
Quoted 10 lines
drivers/gpio/gpio-ljca.c +6
-4-#define LJCA_GPIO_WRITE 3 -#define LJCA_GPIO_INT_EVENT 4 -#define LJCA_GPIO_INT_MASK 5 -#define LJCA_GPIO_INT_UNMASK 6 +#define LJCA_GPIO_CONFIG 1 +#define LJCA_GPIO_READ 2 +#define LJCA_GPIO_WRITE 3 +#define LJCA_GPIO_INT_EVENT 4 +#define LJCA_GPIO_INT_MASK 5 +#define LJCA_GPIO_INT_UNMASK 6
Why are you changing whitespace for no good reason?
Please don't do that, it makes finding the actual changes in this driver impossible to notice and review.
Quoted 10 lines
drivers/gpio/gpio-ljca.c +1
-2#define LJCA_GPIO_CONF_DISABLE BIT(0)#define LJCA_GPIO_CONF_INPUT BIT(1)@@ -36,45 +36,49 @@#define LJCA_GPIO_CONF_INTERRUPT BIT(6)#define LJCA_GPIO_INT_TYPE BIT(7) -#define LJCA_GPIO_CONF_EDGE FIELD_PREP(LJCA_GPIO_INT_TYPE, 1) -#define LJCA_GPIO_CONF_LEVEL FIELD_PREP(LJCA_GPIO_INT_TYPE, 0) +#define LJCA_GPIO_CONF_EDGE FIELD_PREP(LJCA_GPIO_INT_TYPE, 1)
drivers/gpio/gpio-ljca.c line 46
Quoted 10 lines
drivers/gpio/gpio-ljca.c +4
-3+#define LJCA_GPIO_CONF_LEVEL FIELD_PREP(LJCA_GPIO_INT_TYPE, 0)/* Intentional overlap with PULLUP / PULLDOWN */ -#define LJCA_GPIO_CONF_SET BIT(3) -#define LJCA_GPIO_CONF_CLR BIT(4) +#define LJCA_GPIO_CONF_SET BIT(3) +#define LJCA_GPIO_CONF_CLR BIT(4) -struct gpio_op { +#define LJCA_GPIO_BUF_SIZE 60u
Why "u"? What requires that?
Odd, sorry, I know people are just getting tired of the constant churn here, but really, you know better than making changes that are not needed, or not documented.
greg k-h
RE: [PATCH v19 4/4] gpio: update Intel LJCA USB GPIO driver
Quoted 56 lines
From: Greg KH
Quoted 54 lines · Wentong Wu
This driver communicate with LJCA GPIO module with specific protocol through interfaces exported by LJCA USB driver.
Update the driver according to LJCA USB driver's changes.Signed-off-by Wentong Wu <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Acked-by Linus Walleij <[email protected]>Tested-by Hans de Goede <[email protected]>--- drivers/gpio/Kconfig | 4 +- drivers/gpio/gpio-ljca.c | 246 +++++++++++++++++++++++++++-------------------- 2 files changed, 145 insertions(+), 105 deletions(-)drivers/gpio/Kconfig index renamed from drivers/gpio/Kconfig +0
-0673bafb..8d5b6c3 100644
drivers/gpio/Kconfig +2
-2@@ -1312,9 +1312,9 @@ config GPIO_KEMPLD config GPIO_LJCA tristate "INTEL La Jolla Cove Adapter GPIO support" - depends on MFD_LJCA + depends on USB_LJCA select GPIOLIB_IRQCHIP - default MFD_LJCA + default USB_LJCA help Select this option to enable GPIO driver for the INTEL La Jolla Cove Adapter (LJCA) board.drivers/gpio/gpio-ljca.c index renamed from drivers/gpio/gpio-ljca.c +0
-087863f0..7fae26d 100644
drivers/gpio/gpio-ljca.c +2
-2@@ -6,6 +6,7 @@*/ #include <linux/acpi.h> +#include <linux/auxiliary_bus.h> #include <linux/bitfield.h> #include <linux/bitops.h> #include <linux/dev_printk.h> @@ -13,19 +14,18 @@#include <linux/irq.h> #include <linux/kernel.h> #include <linux/kref.h> -#include <linux/mfd/ljca.h> #include <linux/module.h> -#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/usb/ljca.h>
Quoted 15 lines
drivers/gpio/gpio-ljca.c line 28
Quoted 13 lines
drivers/gpio/gpio-ljca.c +6
-6/* GPIO commands */ -#define LJCA_GPIO_CONFIG 1 -#define LJCA_GPIO_READ 2 -#define LJCA_GPIO_WRITE 3 -#define LJCA_GPIO_INT_EVENT 4 -#define LJCA_GPIO_INT_MASK 5 -#define LJCA_GPIO_INT_UNMASK 6 +#define LJCA_GPIO_CONFIG 1 +#define LJCA_GPIO_READ 2 +#define LJCA_GPIO_WRITE 3 +#define LJCA_GPIO_INT_EVENT 4 +#define LJCA_GPIO_INT_MASK 5 +#define LJCA_GPIO_INT_UNMASK 6Why are you changing whitespace for no good reason?
This is to make all the macro value in the same column to make them look better.
Quoted 3 lines
Please don't do that, it makes finding the actual changes in this driver impossible to notice and review.
Understand, I'll follow this going forward. Thanks
Thanks
Wentong
Quoted 33 lines
drivers/gpio/gpio-ljca.c line 39
Quoted 13 lines
drivers/gpio/gpio-ljca.c +1
-2#define LJCA_GPIO_CONF_DISABLE BIT(0)#define LJCA_GPIO_CONF_INPUT BIT(1)@@ -36,45 +36,49 @@#define LJCA_GPIO_CONF_INTERRUPT BIT(6)#define LJCA_GPIO_INT_TYPE BIT(7) -#define LJCA_GPIO_CONF_EDGE FIELD_PREP(LJCA_GPIO_INT_TYPE, 1) -#define LJCA_GPIO_CONF_LEVEL FIELD_PREP(LJCA_GPIO_INT_TYPE, 0) +#define LJCA_GPIO_CONF_EDGE
FIELD_PREP(LJCA_GPIO_INT_TYPE, 1)drivers/gpio/gpio-ljca.c line 40
Quoted 1 line
drivers/gpio/gpio-ljca.c +1
-0+#define LJCA_GPIO_CONF_LEVEL
FIELD_PREP(LJCA_GPIO_INT_TYPE, 0)drivers/gpio/gpio-ljca.c line 46
Quoted 9 lines
drivers/gpio/gpio-ljca.c +3
-3/* Intentional overlap with PULLUP / PULLDOWN */ -#define LJCA_GPIO_CONF_SET BIT(3) -#define LJCA_GPIO_CONF_CLR BIT(4) +#define LJCA_GPIO_CONF_SET BIT(3) +#define LJCA_GPIO_CONF_CLR BIT(4) -struct gpio_op { +#define LJCA_GPIO_BUF_SIZE 60uWhy "u"? What requires that?
Odd, sorry, I know people are just getting tired of the constant churn here, but really, you know better than making changes that are not needed, or not documented.
greg k-h
Quoted 5 lines · Wentong Wu
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
Can I be a pain and ask you to limit the rate at which you repost this series? You send it every other day, hence actively discouraging people from reviewing it (why would they, there's another version coming).
Once a week is a perfectly good rate, and would probably lead to better results.
Alternatively, if you decide that you really want to keep sending it that often, please drop me from the Cc list.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Greg KH
maintainerQuoted 9 lines · Wentong Wu
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
---
v19:
- add v17's change which v18 doesn't apply
I don't understand this changelog line at all, what do you mean?
Quoted 2 lines
v18:
- rebase patch set on top of Linus' master branch (57d88e8a5974644039fbc47806bac7bb12025636)
Why? What required this?
As Marc says, you are sending this way too often. I'm going to move this to the bottom of my pile and get to it in a week or so as with the constant resends, there are way more changes that were sent before yours that need to be reviewed.
thanks,
greg k-h
Hi Marc, Greg,
Quoted 11 lines · Greg KH
Quoted 9 lines · Wentong Wu
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
---
v19:
- add v17's change which v18 doesn't apply
Quoted 6 lines
I don't understand this changelog line at all, what do you mean?
Quoted 2 lines
v18:
- rebase patch set on top of Linus' master branch (57d88e8a5974644039fbc47806bac7bb12025636)Why? What required this?
I noticed that this did not apply cleanly (the SPI patch did not apply cleanly), so I asked for the next version to be based on 6.6-rc1 or Linus' master branch.
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Regards,
Hans
Quoted 4 lines · Hans de Goede
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Hi,
what to do now? It's been ten days.
I am sure this driver has been very thoroughly reviewed by now. We are dragging this out. Do we want the developer to do another release or do we ask Greg to take it as is?
This is becoming almost comical, but that is not what we want driver submission to be.
As far as I am concerned on the USB side everything is fine now. Hans? Greg?
Regards
Oliver
Hi,
Quoted 16 lines · Oliver Neukum
On 17.09.23 13:26, Hans de Goede wrote:
Quoted 4 lines
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Hi,
what to do now? It's been ten days.
I am sure this driver has been very thoroughly reviewed by now. We are dragging this out. Do we want the developer to do another release or do we ask Greg to take it as is?
This is becoming almost comical, but that is not what we want driver submission to be.
Quoted 2 lines
As far as I am concerned on the USB side everything is fine now. Hans? Greg?
Note I have been mostly involved in testing these patches I have *not* thoroughly reviewed them. I have taken a quick(ish) look which did not find anything obviously wrong.
I agree that at least patch 1/4 is ready for merging. I'm not sure if Greg should pick-up the entire series or if the rest should be merged through there relevant subsystems to also give the relevant subsys maintainer tree.
For the series:
Regards,
Hans
Greg KH
maintainerQuoted 31 lines · Hans de Goede
Hi,
Quoted 16 lines · Oliver Neukum
On 17.09.23 13:26, Hans de Goede wrote:
Quoted 4 lines
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Hi,
what to do now? It's been ten days.
I am sure this driver has been very thoroughly reviewed by now. We are dragging this out. Do we want the developer to do another release or do we ask Greg to take it as is?
This is becoming almost comical, but that is not what we want driver submission to be.Quoted 2 lines
As far as I am concerned on the USB side everything is fine now. Hans? Greg?
Note I have been mostly involved in testing these patches I have *not* thoroughly reviewed them. I have taken a quick(ish) look which did not find anything obviously wrong.
I agree that at least patch 1/4 is ready for merging. I'm not sure if Greg should pick-up the entire series or if the rest should be merged through there relevant subsystems to also give the relevant subsys maintainer tree.
Quoted 4 lines
For the series:
Acked-by Hans de Goede <[email protected]>Tested-by Hans de Goede <[email protected]>
Ok, I'll take a look at these again next week when I return home and catch up on my pending patch review queue.
thanks for the review!
greg k-h
Mark Brown
maintainerQuoted 4 lines · Hans de Goede
I agree that at least patch 1/4 is ready for merging. I'm not sure if Greg should pick-up the entire series or if the rest should be merged through there relevant subsystems to also give the relevant subsys maintainer tree.
I stopped paying attention when it was obvious that the USB stuff was struggling badly and getting lots of resends, I've not checked the SPI stuff in a while.
Hi,
Quoted 15 lines · Oliver Neukum
Quoted 4 lines · Hans de Goede
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Hi,
what to do now? It's been ten days.
I am sure this driver has been very thoroughly reviewed by now. We are dragging this out. Do we want the developer to do another release or do we ask Greg to take it as is?
This is becoming almost comical, but that is not what we want driver submission to be.
Quoted 2 lines
As far as I am concerned on the USB side everything is fine now. Hans? Greg?
i2c is also good to go and the rest looks good, as well. I have some concerns on patch 4 that looks like a mixture of many random things.
Andi
Quoted 19 lines · Andi Shyti
Hi,
Quoted 15 lines · Oliver Neukum
Quoted 4 lines · Hans de Goede
Note I did not ask for a new version to be send right away, but I'm afraid there has been a bit of miscommunication and instead of rebasing the next version based on further review Wentong has send out a new rebased version immediately, sorry about that.
Hi,
what to do now? It's been ten days.
I am sure this driver has been very thoroughly reviewed by now. We are dragging this out. Do we want the developer to do another release or do we ask Greg to take it as is?
This is becoming almost comical, but that is not what we want driver submission to be.
Quoted 8 lines
Quoted 2 lines
As far as I am concerned on the USB side everything is fine now. Hans? Greg?
i2c is also good to go and the rest looks good, as well. I have some concerns on patch 4 that looks like a mixture of many random things.
Andi
It's got a lot of coding style fixes ninja-packed in there that are not mentioned by the commit message. But as it's been reviewed by Linus, acked by Andy (and myself) and tested by Hans, I'm ready to let it slide if that saves me from seeing ten additional versions of this series in my inbox.
Bart
Hi Greg and Marc,
It's my bad. I'm so sorry for this, and apologize for it here.
And I thought you have lots of patches to review, so I just try to address all the issues currently I know before you start to review, so that my patch doesn't take over your bandwidth much.
And now I understand your pain here, I will follow your advise going forward. Thanks
Also thank @Hans de Goede for the help. Thanks
BR,
Wentong
Quoted 9 lines
From: Greg KH
Quoted 6 lines · Wentong Wu
Add driver for Intel La Jolla Cove Adapter (LJCA) device. This IO-expander adds additional functions to the host system such as GPIO, I2C and SPI with USB host interface. We add 4 drivers to support this
device: a USB driver, a GPIO chip driver, a I2C controller driver and a SPI controller driver.
Quoted 5 lines
Quoted 3 lines
---
v19:
- add v17's change which v18 doesn't applyI don't understand this changelog line at all, what do you mean?
In v18, I forgot to include v17's change, so resend with v19 immediately, sorry for this again.
Quoted 6 lines
Quoted 4 lines
v18:
- rebase patch set on top of Linus' master branch
(57d88e8a5974644039fbc47806bac7bb12025636)Why? What required this?
This is just a rebase for you and other viewers review and apply the patch easily. Sorry again.
BR,
Wentong
Quoted 9 lines
As Marc says, you are sending this way too often. I'm going to move this to the bottom of my pile and get to it in a week or so as with the constant resends, there are way more changes that were sent before yours that need to be reviewed.
thanks,
greg k-h