All of lore.kernel.org
 help / color / mirror / Atom feed
From: Loic Poulain <loic.poulain@intel.com>
To: Amitkumar Karwar <akarwar@marvell.com>, linux-bluetooth@vger.kernel.org
Cc: Cathy Luo <cluo@marvell.com>,
	linux-kernel@vger.kernel.org,
	Nishant Sarmukadam <nishants@marvell.com>,
	Ganapathi Bhat <gbhat@marvell.com>
Subject: Re: [PATCH v4] Bluetooth: hci_uart: Support firmware download for Marvell
Date: Mon, 14 Mar 2016 16:54:46 +0100	[thread overview]
Message-ID: <56E6DEC6.2070709@intel.com> (raw)
In-Reply-To: <1457006200-8132-2-git-send-email-akarwar@marvell.com>

Hi Amitkumar,

Quick review inline.

On 03/03/2016 12:56, Amitkumar Karwar wrote:
> From: Ganapathi Bhat <gbhat@marvell.com>
>
> This patch implement firmware download feature for
> Marvell Bluetooth devices. If firmware is already
> downloaded, it will skip downloading.
>
> Signed-off-by: Ganapathi Bhat <gbhat@marvell.com>
> Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
> ---
> v2: Fixed compilation warning reported by kbuild test robot
> v3: Addressed review comments from Marcel Holtmann
>      a) Removed vendor specific code from hci_ldisc.c
>      b) Get rid of static forward declaration
>      c) Removed unnecessary heavy nesting
>      d) Git rid of module parameter and global variables
>      e) Add logic to pick right firmware image
> v4: Addresses review comments from Alan
>      a) Use existing kernel helper APIs instead of writing own.
>      b) Replace mdelay() with msleep()
> ---
>   drivers/bluetooth/Kconfig     |  10 +
>   drivers/bluetooth/Makefile    |   1 +
>   drivers/bluetooth/btmrvl.h    |  41 +++
>   drivers/bluetooth/hci_ldisc.c |   6 +
>   drivers/bluetooth/hci_mrvl.c  | 585 ++++++++++++++++++++++++++++++++++++++++++
>   drivers/bluetooth/hci_uart.h  |  13 +-
>   6 files changed, 655 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/bluetooth/btmrvl.h
>   create mode 100644 drivers/bluetooth/hci_mrvl.c
>

> +
> +/* Download firmware to the device */
> +static int mrvl_dnld_fw(struct hci_uart *hu, const char *file_name)
> +{
> +	struct hci_dev *hdev = hu->hdev;
> +	const struct firmware *fw;
> +	struct sk_buff *skb = NULL;
> +	int offset = 0;
> +	int ret, tx_len;
> +	struct mrvl_data *mrvl = hu->priv;
> +	struct fw_data *fw_data = mrvl->fwdata;
> +
> +	ret = request_firmware(&fw, file_name, &hdev->dev);
> +	if (ret < 0) {
> +		BT_ERR("request_firmware() failed");

Overall comment, You should use bt_dev_err/warn/dbg helpers when
relevant.

> +
> +void hci_uart_recv_data(struct hci_uart *hu, u8 *buf, int len)

Why this is not a static function ?

> +{
> +	struct mrvl_data *mrvl = hu->priv;
> +	struct fw_data *fw_data = mrvl->fwdata;
> +	int i = 0;
> +
> +	if (len < 5) {

Be careful, here you seem to suppose that tty layer provides well 
shaped/non-split marvell packets. But this is just a byte stream, you
can receive bytes one by one or more than you expect.

> +		if ((!fw_data->next_index) &&
> +		    (buf[0] != fw_data->expected_ack)) {
> +			/*ex: XX XX XX*/
> +			return;
> +		}
> +	}
> +
> +	if (len == 5) {
> +		if (buf[0] != fw_data->expected_ack) {
> +			/*ex: XX XX XX XX XX*/
> +			return;
> +		}
> +		/*ex: 5A LL LL LL LL*/
> +		fw_data->next_index = 0;
> +		mrvl_validate_hdr_and_len(hu, buf);
> +		return;
> +	}
> +
> +	if (len > 5) {
> +		i = 0;
> +
> +		while ((i < len) && (buf[i] != fw_data->expected_ack))
> +			i++;
> +
> +		if (i == len) {
> +			/* Could not find a header */
> +			return;
> +		}
> +
> +		if ((len - i) >= 5) {
> +			/*ex: 00 00 00 00 a5 LL LL LL LL*/
> +			/*ex: a5 LL LL LL LL 00 00 00 00*/
> +			/*ex: 00 00 a5 LL LL LL LL 00 00*/
> +			/*ex: a5 LL LL LL LL*/

Check all your comments and respect Linux Kernel coding style.
Add short explanation of the expected data format.

> +			fw_data->next_index = 0;
> +			mrvl_validate_hdr_and_len(hu, buf + i);
> +			return;
> +		}
> +
> +		/*ex: 00 00 00 00 a5 LL LL*/
> +		hci_uart_recv_data(hu, buf + i, len - i);
> +		return;
> +	}
> +
> +	for (i = 0; i < len; i++) {
> +		fw_data->five_bytes[fw_data->next_index] = buf[i];
> +		if (++fw_data->next_index == 5) {
> +			fw_data->next_index = 0;
> +			mrvl_validate_hdr_and_len(hu, fw_data->five_bytes);
> +			return;
> +		}
> +	}
> +}

I think you should rework this function and make it more comprehensible.
h4_recv_buf or h5_recv are good examples.

> diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
> index 4814ff0..245cab58 100644
> --- a/drivers/bluetooth/hci_uart.h
> +++ b/drivers/bluetooth/hci_uart.h
> @@ -35,7 +35,7 @@
>   #define HCIUARTGETFLAGS		_IOR('U', 204, int)
>
>   /* UART protocols */
> -#define HCI_UART_MAX_PROTO	10
> +#define HCI_UART_MAX_PROTO	11
>
>   #define HCI_UART_H4	0
>   #define HCI_UART_BCSP	1
> @@ -47,6 +47,7 @@
>   #define HCI_UART_BCM	7
>   #define HCI_UART_QCA	8
>   #define HCI_UART_AG6XX	9
> +#define HCI_UART_MRVL	10
>
>   #define HCI_UART_RAW_DEVICE	0
>   #define HCI_UART_RESET_ON_INIT	1
> @@ -95,11 +96,16 @@ struct hci_uart {
>   /* HCI_UART proto flag bits */
>   #define HCI_UART_PROTO_SET	0
>   #define HCI_UART_REGISTERED	1
> +#define HCI_UART_DNLD_FW	2

This flag is specific and should be part of your proto private data 
(mrvl_data).

>
>   /* TX states  */
>   #define HCI_UART_SENDING	1
>   #define HCI_UART_TX_WAKEUP	2
>
> +#ifdef CONFIG_BT_HCIUART_MRVL
> +void hci_uart_recv_data(struct hci_uart *hu, u8 *buf, int len);
> +int hci_uart_dnld_fw(struct hci_uart *hu);

Why you declare these functions here ?


Regards,
Loic
-- 
Intel Open Source Technology Center
http://oss.intel.com/

  parent reply	other threads:[~2016-03-14 15:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03 11:56 [PATCH BlueZ v4] tools/btattach: add marvell support Amitkumar Karwar
2016-03-03 11:56 ` [PATCH v4] Bluetooth: hci_uart: Support firmware download for Marvell Amitkumar Karwar
2016-03-14  6:32   ` Amitkumar Karwar
2016-03-14 15:54   ` Loic Poulain [this message]
2016-03-17 14:36     ` Amitkumar Karwar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56E6DEC6.2070709@intel.com \
    --to=loic.poulain@intel.com \
    --cc=akarwar@marvell.com \
    --cc=cluo@marvell.com \
    --cc=gbhat@marvell.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nishants@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.