2011-01-04 10:59:46

by Pavan Savoy

[permalink] [raw]
Subject: [RFC 0/2] remove BT references from TI_ST

From: Pavan Savoy <[email protected]>

Gustavo,

Based on your comments, that the underlying shared transport driver
for btwilink driver made use of the BT references to peek into the packets
I have modified the TI_ST.

Since there lacks a generic way to parse the packets coming in from the
UART into BT, FM or GPS, we have to look into the data to fragment assembled
data or assemble fragmented data.
For this reason, Now the above lying protocol drivers like BT, FM and GPS
would send details about their packet types and header information which
would assist shared transport driver to parse the data.

Gustavo, please also notice the change in btwilink driver in and around,
st_register and suggest if something like this is OK.
btwilink can also be modified to send in all the packet specific data
in one shot, if that is preferred.

Please review and provide comments..

Note:
If this is alright, I will send out a modified patch with updated
subject to lkml/Greg for linux-next.

Thanks & Regards,
Pavan Savoy.

Pavan Savoy (2):
drivers:misc:ti-st: change protocol parse logic
Bluetooth: btwilink driver

drivers/bluetooth/Kconfig | 10 +
drivers/bluetooth/Makefile | 1 +
drivers/bluetooth/btwilink.c | 397 ++++++++++++++++++++++++++++++++++++++++++
drivers/misc/ti-st/st_core.c | 355 ++++++++++++--------------------------
drivers/misc/ti-st/st_kim.c | 56 +++---
include/linux/ti_wilink_st.h | 40 +++--
6 files changed, 575 insertions(+), 284 deletions(-)
create mode 100644 drivers/bluetooth/btwilink.c


2011-01-21 21:10:01

by Pavan Savoy

[permalink] [raw]
Subject: Re: [RFC 0/2] remove BT references from TI_ST

Gustavo,

On Fri, Jan 21, 2011 at 11:57 PM, Gustavo F. Padovan
<[email protected]> wrote:
> Hi Pavan,
>
> * Pavan Savoy <[email protected]> [2011-01-21 23:10:28 +0530]:
>
>> >> > If this is alright, I will send out a modified patch with updated
>> >> > subject to lkml/Greg for linux-next.
>> >
>> > Ok. Go ahead. Then tell me when I'll be able to apply your patch. (I need to
>> > have the core modifications in my tree first). Or I just ack the patch and it
>> > finds its way to mainline through Greg's tree.
>>
>> Yes, I will post a patch to lkml against linux-next to greg KH, and
>> based on that send a
>> separate patch to linux-bluetooth for the btwilink..
>
> Actually send everything to Greg KH, will work out better. Otherwise you will
> have to one release cycle to merge it here (until the other patches reach my
> tree). Then I just Ack it.

Thanks, I will do that.
I will fix up the btwilink comments too...
I have few other patches on TI ST lined up as well. (kind of reviewed
by Samuel Ortiz too...).
So I will put them all together and post them within couple of days.

Thanks a lot.


> --
> Gustavo F. Padovan
> http://profusion.mobi
>

2011-01-21 18:27:49

by Gustavo Padovan

[permalink] [raw]
Subject: Re: [RFC 0/2] remove BT references from TI_ST

Hi Pavan,

* Pavan Savoy <[email protected]> [2011-01-21 23:10:28 +0530]:

> >> > If this is alright, I will send out a modified patch with updated
> >> > subject to lkml/Greg for linux-next.
> >
> > Ok. Go ahead. Then tell me when I'll be able to apply your patch. (I need to
> > have the core modifications in my tree first). Or I just ack the patch and it
> > finds its way to mainline through Greg's tree.
>
> Yes, I will post a patch to lkml against linux-next to greg KH, and
> based on that send a
> separate patch to linux-bluetooth for the btwilink..

Actually send everything to Greg KH, will work out better. Otherwise you will
have to one release cycle to merge it here (until the other patches reach my
tree). Then I just Ack it.

--
Gustavo F. Padovan
http://profusion.mobi

2011-01-21 17:57:18

by Gustavo Padovan

[permalink] [raw]
Subject: Re: [RFC 2/2] Bluetooth: btwilink driver

Hi Pavan,

* [email protected] <[email protected]> [2011-01-04 04:59:48 -0600]:

> From: Pavan Savoy <[email protected]>
>
> -- patch description --
>
> This is the bluetooth protocol driver for the TI WiLink7 chipsets.
> Texas Instrument's WiLink chipsets combine wireless technologies
> like BT, FM, GPS and WLAN onto a single chip.
>
> This Bluetooth driver works on top of the TI_ST shared transport
> line discipline driver which also allows other drivers like
> FM V4L2 and GPS character driver to make use of the same UART interface.
>
> Kconfig and Makefile modifications to enable the Bluetooth
> driver for Texas Instrument's WiLink 7 chipset.
>
> Signed-off-by: Pavan Savoy <[email protected]>
> ---
> drivers/bluetooth/Kconfig | 10 +
> drivers/bluetooth/Makefile | 1 +
> drivers/bluetooth/btwilink.c | 397 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 408 insertions(+), 0 deletions(-)
> create mode 100644 drivers/bluetooth/btwilink.c
>
> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
> index 02deef4..8e0de9a 100644
> --- a/drivers/bluetooth/Kconfig
> +++ b/drivers/bluetooth/Kconfig
> @@ -219,4 +219,14 @@ config BT_ATH3K
> Say Y here to compile support for "Atheros firmware download driver"
> into the kernel or say M to compile it as module (ath3k).
>
> +config BT_WILINK
> + tristate "Texas Instruments WiLink7 driver"
> + depends on TI_ST
> + help
> + This enables the Bluetooth driver for Texas Instrument's BT/FM/GPS
> + combo devices. This makes use of shared transport line discipline
> + core driver to communicate with the BT core of the combo chip.
> +
> + Say Y here to compile support for Texas Instrument's WiLink7 driver
> + into the kernel or say M to compile it as module.
> endmenu
> diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
> index 71bdf13..f4460f4 100644
> --- a/drivers/bluetooth/Makefile
> +++ b/drivers/bluetooth/Makefile
> @@ -18,6 +18,7 @@ obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o
> obj-$(CONFIG_BT_ATH3K) += ath3k.o
> obj-$(CONFIG_BT_MRVL) += btmrvl.o
> obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o
> +obj-$(CONFIG_BT_WILINK) += btwilink.o
>
> btmrvl-y := btmrvl_main.o
> btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o
> diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
> new file mode 100644
> index 0000000..0201aca
> --- /dev/null
> +++ b/drivers/bluetooth/btwilink.c
> @@ -0,0 +1,397 @@
> +/*
> + * Texas Instrument's Bluetooth Driver For Shared Transport.
> + *
> + * Bluetooth Driver acts as interface between HCI core and
> + * TI Shared Transport Layer.
> + *
> + * Copyright (C) 2009-2010 Texas Instruments
> + * Author: Raja Mani <[email protected]>
> + * Pavan Savoy <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#include <linux/platform_device.h>
> +#include <net/bluetooth/bluetooth.h>
> +#include <net/bluetooth/hci_core.h>
> +
> +#include <linux/ti_wilink_st.h>
> +
> +/* Bluetooth Driver Version */
> +#define VERSION "1.0"
> +
> +/* Number of seconds to wait for registration completion
> + * when ST returns PENDING status.
> + */
> +#define BT_REGISTER_TIMEOUT 6000 /* 6 sec */
> +
> +/**
> + * struct ti_st - driver operation structure
> + * @hdev: hci device pointer which binds to bt driver
> + * @reg_status: ST registration callback status
> + * @st_write: write function provided by the ST driver
> + * to be used by the driver during send_frame.
> + * @wait_reg_completion - completion sync between ti_st_open
> + * and ti_st_registration_completion_cb.
> + */
> +struct ti_st {
> + struct hci_dev *hdev;
> + char reg_status;
> + long (*st_write) (struct sk_buff *);
> + struct completion wait_reg_completion;
> +};
> +
> +/* Increments HCI counters based on pocket ID (cmd,acl,sco) */
> +static inline void ti_st_tx_complete(struct ti_st *hst, int pkt_type)
> +{
> + struct hci_dev *hdev = hst->hdev;
> +
> + /* Update HCI stat counters */
> + switch (pkt_type) {
> + case HCI_COMMAND_PKT:
> + hdev->stat.cmd_tx++;
> + break;
> +
> + case HCI_ACLDATA_PKT:
> + hdev->stat.acl_tx++;
> + break;
> +
> + case HCI_SCODATA_PKT:
> + hdev->stat.sco_tx++;
> + break;
> + }
> +}
> +
> +/* ------- Interfaces to Shared Transport ------ */
> +
> +/* Called by ST layer to indicate protocol registration completion
> + * status.ti_st_open() function will wait for signal from this
> + * API when st_register() function returns ST_PENDING.
> + */
> +static void st_registration_completion_cb(void *priv_data, char data)
> +{
> + struct ti_st *lhst = priv_data;
> +
> + /* Save registration status for use in ti_st_open() */
> + lhst->reg_status = data;
> + /* complete the wait in ti_st_open() */
> + complete(&lhst->wait_reg_completion);
> +}
> +
> +/* Called by Shared Transport layer when receive data is
> + * available */
> +static long st_receive(void *priv_data, struct sk_buff *skb)
> +{
> + struct ti_st *lhst = priv_data;
> + int err;
> +
> + if (!skb)
> + return -EFAULT;
> +
> + if (!lhst) {
> + kfree_skb(skb);
> + return -EFAULT;
> + }
> +
> + skb->dev = (void *) lhst->hdev;
> +
> + /* Forward skb to HCI core layer */
> + err = hci_recv_frame(skb);
> + if (err < 0) {
> + BT_ERR("Unable to push skb to HCI core(%d)", err);
> + return err;
> + }
> +
> + lhst->hdev->stat.byte_rx += skb->len;
> +
> + return 0;
> +}
> +
> +/* ------- Interfaces to HCI layer ------ */
> +/* protocol structure registered with shared transport */
> +static struct st_proto_s ti_st_proto[3] = {
> + {
> + .chnl_id = 0x02, /* ACL */

Please create macros for the chnl_id in the core driver.

> + .recv = st_receive,
> + .reg_complete_cb = st_registration_completion_cb,
> + .hdr_len = 4,
> + .offset_len_in_hdr = 2,
> + .len_size = 2,
> + .reserve = 8,
> + },
> + {
> + .chnl_id = 0x03, /* SCO */
> + .recv = st_receive,
> + .reg_complete_cb = st_registration_completion_cb,
> + .hdr_len = 3,
> + .offset_len_in_hdr = 2,
> + .len_size = 1,
> + .reserve = 8,
> + },
> + {
> + .chnl_id = 0x04, /* HCI Events */
> + .recv = st_receive,
> + .reg_complete_cb = st_registration_completion_cb,
> + .hdr_len = 2,
> + .offset_len_in_hdr = 1,
> + .len_size = 1,
> + .reserve = 8,
> + },
> +};
> +
> +/* Called from HCI core to initialize the device */
> +static int ti_st_open(struct hci_dev *hdev)
> +{
> + unsigned long timeleft;
> + struct ti_st *hst;
> + int err, i;
> +
> + BT_DBG("%s %p", hdev->name, hdev);

Blank line here.

> + if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) {
> + BT_ERR("btwilink already opened");

No need for this BT_ERR. It already returns -EBUSY.

> + return -EBUSY;
> + }
> +
> + /* provide contexts for callbacks from ST */
> + hst = hdev->driver_data;
> +
> + for (i = 0; i < 3; i++) {
> + ti_st_proto[i].priv_data = hst;
> + ti_st_proto[i].max_frame_size = HCI_MAX_FRAME_SIZE;
> +
> + err = st_register(&ti_st_proto[i]);

Let's change the order here. First

if (!err)
goto to "hst->st_write = ti_st_proto[i].write"

if (err != -EINPROGRESS) {
}

then here code for err == -EINPROGRESS


> + if (err == -EINPROGRESS) {
> + /* ST is busy with either protocol
> + * registration or firmware download.
> + */
> + /* Prepare wait-for-completion handler data structures.
> + */
> + init_completion(&hst->wait_reg_completion);
> +
> + /* Reset ST registration callback status flag,
> + * this value will be updated in
> + * ti_st_registration_completion_cb()
> + * function whenever it called from ST driver.
> + */
> + hst->reg_status = -EINPROGRESS;
> +
> + BT_DBG("waiting for registration "
> + "completion signal from ST");
> + timeleft = wait_for_completion_timeout
> + (&hst->wait_reg_completion,
> + msecs_to_jiffies(BT_REGISTER_TIMEOUT));
> + if (!timeleft) {
> + clear_bit(HCI_RUNNING, &hdev->flags);
> + BT_ERR("Timeout(%d sec),didn't get reg "
> + "completion signal from ST",
> + BT_REGISTER_TIMEOUT / 1000);
> + return -ETIMEDOUT;
> + }
> +
> + /* Is ST registration callback
> + * called with ERROR status? */
> + if (hst->reg_status != 0) {
> + clear_bit(HCI_RUNNING, &hdev->flags);
> + BT_ERR("ST registration completed with invalid "
> + "status %d", hst->reg_status);
> + return -EAGAIN;
> + }
> + err = 0;

remove this err = 0; and return 0 in the end of the function.

> + } else if (err != 0) {
> + clear_bit(HCI_RUNNING, &hdev->flags);
> + BT_ERR("st_register failed %d", err);
> + return err;
> + }

Blank line here.

> + hst->st_write = ti_st_proto[i].write;
> + if (!hst->st_write) {
> + BT_ERR("undefined ST write function");
> + clear_bit(HCI_RUNNING, &hdev->flags);
> +
> + /* Undo registration with ST */
> + err = st_unregister(&ti_st_proto[i]);
> + if (err)
> + BT_ERR("st_unregister() failed with "
> + "error %d", err);


You are unregistering only one protocol here, if the fail happens in the third
one you will leak two of them.

> +
> + hst->st_write = NULL;
> + /* ti_st_proto.write is filled up by the
> + * underlying shared transport driver
> + * upon registration
> + */
> + return err;
> + }
> + }
> +
> + return err;
> +}
> +
> +/* Close device */
> +static int ti_st_close(struct hci_dev *hdev)
> +{
> + int err, i;
> + struct ti_st *hst = hdev->driver_data;
> +
> + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
> + return 0;
> +
> + for (i = 0; i < 3; i++) {
> + /* continue to unregister from transport */

This comment is pointless.

> + err = st_unregister(&ti_st_proto[i]);
> + if (err)
> + BT_ERR("st_unregister() failed with error %d", err);
> + }
> +
> + hst->st_write = NULL;
> +
> + return err;

err is will report the error if it happens in the first or second unregister.


--
Gustavo F. Padovan
http://profusion.mobi

2011-01-21 17:40:28

by Pavan Savoy

[permalink] [raw]
Subject: Re: [RFC 0/2] remove BT references from TI_ST

Gustavo,

On Fri, Jan 21, 2011 at 10:48 PM, Gustavo F. Padovan
<[email protected]> wrote:
> Hi Pavan,
>
> * Pavan Savoy <[email protected]> [2011-01-19 23:56:29 +0530]:
>
>> Gustavo,
>>
>> On Tue, Jan 4, 2011 at 4:29 PM, =C2=A0<[email protected]> wrote:
>> > From: Pavan Savoy <[email protected]>
>> >
>> > Gustavo,
>> >
>> > Based on your comments, that the underlying shared transport driver
>> > for btwilink driver made use of the BT references to peek into the pac=
kets
>> > I have modified the TI_ST.
>>
>> Since there lacks a generic way to parse the packets coming in from the
>> UART into BT, FM or GPS, we have to look into the data to fragment assem=
bled
>> data or assemble fragmented data.
>>
>> Please have a look, Please suggest whether something like this is requir=
ed,
>> If not, please also suggest, if including BT headers is a problem ?
>
> Not really. The real problem is to break the abstraction between drivers
> layers (core and bluetooth drivers in this case)

ok, fine. Although I myself personally would prefer the older way ...
But its fine, I understand why references to bluetooth headers doesn't look=
good
at shared transport level...

>>
>> Because I just include the BT headers and don't have a build
>> dependency as such on
>> BT/HCI and don't use any functions from hci_core in my shared transport =
driver.
>>
>> > For this reason, Now the above lying protocol drivers like BT, FM and =
GPS
>> > would send details about their packet types and header information whi=
ch
>> > would assist shared transport driver to parse the data.
>
> Fair enough. This new approach is way better.

Ok, So there is no problem with BT driver doing this multiple calls to
st_register (or a single call
with info array of ACL, SCO, Event to st_register) ?
This would only hold true for BT.
For FM or GPS there would be only 1 set of info sent across from protocol
drivers to the shared transport drivers...

Also, during firmware download, is hard-coding of few parameters
pertaining to HCI-Event alright ?
because this needs to happen even if say BT doesn't plan to use the
shared transport and only FM
V4L2 is at works..

>> >
>> > Gustavo, please also notice the change in btwilink driver in and aroun=
d,
>> > st_register and suggest if something like this is OK.
>> > btwilink can also be modified to send in all the packet specific data
>> > in one shot, if that is preferred.
>> >
>> > Please review and provide comments..
>> >
>> > Note:
>> > If this is alright, I will send out a modified patch with updated
>> > subject to lkml/Greg for linux-next.
>
> Ok. Go ahead. Then tell me when I'll be able to apply your patch. (I need=
to
> have the core modifications in my tree first). Or I just ack the patch an=
d it
> finds its way to mainline through Greg's tree.

Yes, I will post a patch to lkml against linux-next to greg KH, and
based on that send a
separate patch to linux-bluetooth for the btwilink..

> --
> Gustavo F. Padovan
> http://profusion.mobi
>

2011-01-21 17:18:57

by Gustavo Padovan

[permalink] [raw]
Subject: Re: [RFC 0/2] remove BT references from TI_ST

Hi Pavan,

* Pavan Savoy <[email protected]> [2011-01-19 23:56:29 +0530]:

> Gustavo,
>
> On Tue, Jan 4, 2011 at 4:29 PM, <[email protected]> wrote:
> > From: Pavan Savoy <[email protected]>
> >
> > Gustavo,
> >
> > Based on your comments, that the underlying shared transport driver
> > for btwilink driver made use of the BT references to peek into the packets
> > I have modified the TI_ST.
>
> Since there lacks a generic way to parse the packets coming in from the
> UART into BT, FM or GPS, we have to look into the data to fragment assembled
> data or assemble fragmented data.
>
> Please have a look, Please suggest whether something like this is required,
> If not, please also suggest, if including BT headers is a problem ?

Not really. The real problem is to break the abstraction between drivers
layers (core and bluetooth drivers in this case)

>
> Because I just include the BT headers and don't have a build
> dependency as such on
> BT/HCI and don't use any functions from hci_core in my shared transport driver.
>
> > For this reason, Now the above lying protocol drivers like BT, FM and GPS
> > would send details about their packet types and header information which
> > would assist shared transport driver to parse the data.

Fair enough. This new approach is way better.

> >
> > Gustavo, please also notice the change in btwilink driver in and around,
> > st_register and suggest if something like this is OK.
> > btwilink can also be modified to send in all the packet specific data
> > in one shot, if that is preferred.
> >
> > Please review and provide comments..
> >
> > Note:
> > If this is alright, I will send out a modified patch with updated
> > subject to lkml/Greg for linux-next.

Ok. Go ahead. Then tell me when I'll be able to apply your patch. (I need to
have the core modifications in my tree first). Or I just ack the patch and it
finds its way to mainline through Greg's tree.

--
Gustavo F. Padovan
http://profusion.mobi

2011-01-19 18:26:29

by Pavan Savoy

[permalink] [raw]
Subject: Re: [RFC 0/2] remove BT references from TI_ST

Gustavo,

On Tue, Jan 4, 2011 at 4:29 PM, <[email protected]> wrote:
> From: Pavan Savoy <[email protected]>
>
> Gustavo,
>
> Based on your comments, that the underlying shared transport driver
> for btwilink driver made use of the BT references to peek into the packets
> I have modified the TI_ST.

Since there lacks a generic way to parse the packets coming in from the
UART into BT, FM or GPS, we have to look into the data to fragment assembled
data or assemble fragmented data.

Please have a look, Please suggest whether something like this is required,
If not, please also suggest, if including BT headers is a problem ?

Because I just include the BT headers and don't have a build
dependency as such on
BT/HCI and don't use any functions from hci_core in my shared transport driver.

> For this reason, Now the above lying protocol drivers like BT, FM and GPS
> would send details about their packet types and header information which
> would assist shared transport driver to parse the data.
>
> Gustavo, please also notice the change in btwilink driver in and around,
> st_register and suggest if something like this is OK.
> btwilink can also be modified to send in all the packet specific data
> in one shot, if that is preferred.
>
> Please review and provide comments..
>
> Note:
> If this is alright, I will send out a modified patch with updated
> subject to lkml/Greg for linux-next.
>
> Thanks & Regards,
> Pavan Savoy.
>
> Pavan Savoy (2):
>  drivers:misc:ti-st: change protocol parse logic
>  Bluetooth: btwilink driver
>
>  drivers/bluetooth/Kconfig    |   10 +
>  drivers/bluetooth/Makefile   |    1 +
>  drivers/bluetooth/btwilink.c |  397 ++++++++++++++++++++++++++++++++++++++++++
>  drivers/misc/ti-st/st_core.c |  355 ++++++++++++--------------------------
>  drivers/misc/ti-st/st_kim.c  |   56 +++---
>  include/linux/ti_wilink_st.h |   40 +++--
>  6 files changed, 575 insertions(+), 284 deletions(-)
>  create mode 100644 drivers/bluetooth/btwilink.c
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

2011-01-04 10:59:48

by Pavan Savoy

[permalink] [raw]
Subject: [RFC 2/2] Bluetooth: btwilink driver

From: Pavan Savoy <[email protected]>

-- patch description --

This is the bluetooth protocol driver for the TI WiLink7 chipsets.
Texas Instrument's WiLink chipsets combine wireless technologies
like BT, FM, GPS and WLAN onto a single chip.

This Bluetooth driver works on top of the TI_ST shared transport
line discipline driver which also allows other drivers like
FM V4L2 and GPS character driver to make use of the same UART interface.

Kconfig and Makefile modifications to enable the Bluetooth
driver for Texas Instrument's WiLink 7 chipset.

Signed-off-by: Pavan Savoy <[email protected]>
---
drivers/bluetooth/Kconfig | 10 +
drivers/bluetooth/Makefile | 1 +
drivers/bluetooth/btwilink.c | 397 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 408 insertions(+), 0 deletions(-)
create mode 100644 drivers/bluetooth/btwilink.c

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 02deef4..8e0de9a 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -219,4 +219,14 @@ config BT_ATH3K
Say Y here to compile support for "Atheros firmware download driver"
into the kernel or say M to compile it as module (ath3k).

+config BT_WILINK
+ tristate "Texas Instruments WiLink7 driver"
+ depends on TI_ST
+ help
+ This enables the Bluetooth driver for Texas Instrument's BT/FM/GPS
+ combo devices. This makes use of shared transport line discipline
+ core driver to communicate with the BT core of the combo chip.
+
+ Say Y here to compile support for Texas Instrument's WiLink7 driver
+ into the kernel or say M to compile it as module.
endmenu
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 71bdf13..f4460f4 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o
obj-$(CONFIG_BT_ATH3K) += ath3k.o
obj-$(CONFIG_BT_MRVL) += btmrvl.o
obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o
+obj-$(CONFIG_BT_WILINK) += btwilink.o

btmrvl-y := btmrvl_main.o
btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o
diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
new file mode 100644
index 0000000..0201aca
--- /dev/null
+++ b/drivers/bluetooth/btwilink.c
@@ -0,0 +1,397 @@
+/*
+ * Texas Instrument's Bluetooth Driver For Shared Transport.
+ *
+ * Bluetooth Driver acts as interface between HCI core and
+ * TI Shared Transport Layer.
+ *
+ * Copyright (C) 2009-2010 Texas Instruments
+ * Author: Raja Mani <[email protected]>
+ * Pavan Savoy <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+
+#include <linux/ti_wilink_st.h>
+
+/* Bluetooth Driver Version */
+#define VERSION "1.0"
+
+/* Number of seconds to wait for registration completion
+ * when ST returns PENDING status.
+ */
+#define BT_REGISTER_TIMEOUT 6000 /* 6 sec */
+
+/**
+ * struct ti_st - driver operation structure
+ * @hdev: hci device pointer which binds to bt driver
+ * @reg_status: ST registration callback status
+ * @st_write: write function provided by the ST driver
+ * to be used by the driver during send_frame.
+ * @wait_reg_completion - completion sync between ti_st_open
+ * and ti_st_registration_completion_cb.
+ */
+struct ti_st {
+ struct hci_dev *hdev;
+ char reg_status;
+ long (*st_write) (struct sk_buff *);
+ struct completion wait_reg_completion;
+};
+
+/* Increments HCI counters based on pocket ID (cmd,acl,sco) */
+static inline void ti_st_tx_complete(struct ti_st *hst, int pkt_type)
+{
+ struct hci_dev *hdev = hst->hdev;
+
+ /* Update HCI stat counters */
+ switch (pkt_type) {
+ case HCI_COMMAND_PKT:
+ hdev->stat.cmd_tx++;
+ break;
+
+ case HCI_ACLDATA_PKT:
+ hdev->stat.acl_tx++;
+ break;
+
+ case HCI_SCODATA_PKT:
+ hdev->stat.sco_tx++;
+ break;
+ }
+}
+
+/* ------- Interfaces to Shared Transport ------ */
+
+/* Called by ST layer to indicate protocol registration completion
+ * status.ti_st_open() function will wait for signal from this
+ * API when st_register() function returns ST_PENDING.
+ */
+static void st_registration_completion_cb(void *priv_data, char data)
+{
+ struct ti_st *lhst = priv_data;
+
+ /* Save registration status for use in ti_st_open() */
+ lhst->reg_status = data;
+ /* complete the wait in ti_st_open() */
+ complete(&lhst->wait_reg_completion);
+}
+
+/* Called by Shared Transport layer when receive data is
+ * available */
+static long st_receive(void *priv_data, struct sk_buff *skb)
+{
+ struct ti_st *lhst = priv_data;
+ int err;
+
+ if (!skb)
+ return -EFAULT;
+
+ if (!lhst) {
+ kfree_skb(skb);
+ return -EFAULT;
+ }
+
+ skb->dev = (void *) lhst->hdev;
+
+ /* Forward skb to HCI core layer */
+ err = hci_recv_frame(skb);
+ if (err < 0) {
+ BT_ERR("Unable to push skb to HCI core(%d)", err);
+ return err;
+ }
+
+ lhst->hdev->stat.byte_rx += skb->len;
+
+ return 0;
+}
+
+/* ------- Interfaces to HCI layer ------ */
+/* protocol structure registered with shared transport */
+static struct st_proto_s ti_st_proto[3] = {
+ {
+ .chnl_id = 0x02, /* ACL */
+ .recv = st_receive,
+ .reg_complete_cb = st_registration_completion_cb,
+ .hdr_len = 4,
+ .offset_len_in_hdr = 2,
+ .len_size = 2,
+ .reserve = 8,
+ },
+ {
+ .chnl_id = 0x03, /* SCO */
+ .recv = st_receive,
+ .reg_complete_cb = st_registration_completion_cb,
+ .hdr_len = 3,
+ .offset_len_in_hdr = 2,
+ .len_size = 1,
+ .reserve = 8,
+ },
+ {
+ .chnl_id = 0x04, /* HCI Events */
+ .recv = st_receive,
+ .reg_complete_cb = st_registration_completion_cb,
+ .hdr_len = 2,
+ .offset_len_in_hdr = 1,
+ .len_size = 1,
+ .reserve = 8,
+ },
+};
+
+/* Called from HCI core to initialize the device */
+static int ti_st_open(struct hci_dev *hdev)
+{
+ unsigned long timeleft;
+ struct ti_st *hst;
+ int err, i;
+
+ BT_DBG("%s %p", hdev->name, hdev);
+ if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) {
+ BT_ERR("btwilink already opened");
+ return -EBUSY;
+ }
+
+ /* provide contexts for callbacks from ST */
+ hst = hdev->driver_data;
+
+ for (i = 0; i < 3; i++) {
+ ti_st_proto[i].priv_data = hst;
+ ti_st_proto[i].max_frame_size = HCI_MAX_FRAME_SIZE;
+
+ err = st_register(&ti_st_proto[i]);
+ if (err == -EINPROGRESS) {
+ /* ST is busy with either protocol
+ * registration or firmware download.
+ */
+ /* Prepare wait-for-completion handler data structures.
+ */
+ init_completion(&hst->wait_reg_completion);
+
+ /* Reset ST registration callback status flag,
+ * this value will be updated in
+ * ti_st_registration_completion_cb()
+ * function whenever it called from ST driver.
+ */
+ hst->reg_status = -EINPROGRESS;
+
+ BT_DBG("waiting for registration "
+ "completion signal from ST");
+ timeleft = wait_for_completion_timeout
+ (&hst->wait_reg_completion,
+ msecs_to_jiffies(BT_REGISTER_TIMEOUT));
+ if (!timeleft) {
+ clear_bit(HCI_RUNNING, &hdev->flags);
+ BT_ERR("Timeout(%d sec),didn't get reg "
+ "completion signal from ST",
+ BT_REGISTER_TIMEOUT / 1000);
+ return -ETIMEDOUT;
+ }
+
+ /* Is ST registration callback
+ * called with ERROR status? */
+ if (hst->reg_status != 0) {
+ clear_bit(HCI_RUNNING, &hdev->flags);
+ BT_ERR("ST registration completed with invalid "
+ "status %d", hst->reg_status);
+ return -EAGAIN;
+ }
+ err = 0;
+ } else if (err != 0) {
+ clear_bit(HCI_RUNNING, &hdev->flags);
+ BT_ERR("st_register failed %d", err);
+ return err;
+ }
+ hst->st_write = ti_st_proto[i].write;
+ if (!hst->st_write) {
+ BT_ERR("undefined ST write function");
+ clear_bit(HCI_RUNNING, &hdev->flags);
+
+ /* Undo registration with ST */
+ err = st_unregister(&ti_st_proto[i]);
+ if (err)
+ BT_ERR("st_unregister() failed with "
+ "error %d", err);
+
+ hst->st_write = NULL;
+ /* ti_st_proto.write is filled up by the
+ * underlying shared transport driver
+ * upon registration
+ */
+ return err;
+ }
+ }
+
+ return err;
+}
+
+/* Close device */
+static int ti_st_close(struct hci_dev *hdev)
+{
+ int err, i;
+ struct ti_st *hst = hdev->driver_data;
+
+ if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
+ return 0;
+
+ for (i = 0; i < 3; i++) {
+ /* continue to unregister from transport */
+ err = st_unregister(&ti_st_proto[i]);
+ if (err)
+ BT_ERR("st_unregister() failed with error %d", err);
+ }
+
+ hst->st_write = NULL;
+
+ return err;
+}
+
+static int ti_st_send_frame(struct sk_buff *skb)
+{
+ struct hci_dev *hdev;
+ struct ti_st *hst;
+ long len;
+
+ hdev = (struct hci_dev *)skb->dev;
+
+ if (!test_bit(HCI_RUNNING, &hdev->flags))
+ return -EBUSY;
+
+ hst = hdev->driver_data;
+
+ /* Prepend skb with frame type */
+ memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
+
+ BT_DBG("%s: type %d len %d", hdev->name, bt_cb(skb)->pkt_type,
+ skb->len);
+
+ /* Insert skb to shared transport layer's transmit queue.
+ * Freeing skb memory is taken care in shared transport layer,
+ * so don't free skb memory here.
+ */
+ len = hst->st_write(skb);
+ if (len < 0) {
+ kfree_skb(skb);
+ BT_ERR("ST write failed (%ld)", len);
+ /* Try Again, would only fail if UART has gone bad */
+ return -EAGAIN;
+ }
+
+ /* ST accepted our skb. So, Go ahead and do rest */
+ hdev->stat.byte_tx += len;
+ ti_st_tx_complete(hst, bt_cb(skb)->pkt_type);
+
+ return 0;
+}
+
+static void ti_st_destruct(struct hci_dev *hdev)
+{
+ BT_DBG("%s", hdev->name);
+ kfree(hdev->driver_data);
+}
+
+static int bt_ti_probe(struct platform_device *pdev)
+{
+ static struct ti_st *hst;
+ struct hci_dev *hdev;
+ int err;
+
+ hst = kzalloc(sizeof(struct ti_st), GFP_KERNEL);
+ if (!hst)
+ return -ENOMEM;
+
+ /* Expose "hciX" device to user space */
+ hdev = hci_alloc_dev();
+ if (!hdev) {
+ kfree(hst);
+ return -ENOMEM;
+ }
+
+ BT_DBG("hdev %p", hdev);
+
+ hst->hdev = hdev;
+ hdev->bus = HCI_UART;
+ hdev->driver_data = hst;
+ hdev->open = ti_st_open;
+ hdev->close = ti_st_close;
+ hdev->flush = NULL;
+ hdev->send = ti_st_send_frame;
+ hdev->destruct = ti_st_destruct;
+ hdev->owner = THIS_MODULE;
+
+ err = hci_register_dev(hdev);
+ if (err < 0) {
+ BT_ERR("Can't register HCI device error %d", err);
+ kfree(hst);
+ hci_free_dev(hdev);
+ return err;
+ }
+
+ BT_DBG("HCI device registered (hdev %p)", hdev);
+
+ dev_set_drvdata(&pdev->dev, hst);
+ return err;
+}
+
+static int bt_ti_remove(struct platform_device *pdev)
+{
+ struct hci_dev *hdev;
+ struct ti_st *hst = dev_get_drvdata(&pdev->dev);
+
+ if (!hst)
+ return -EFAULT;
+
+ hdev = hst->hdev;
+ ti_st_close(hdev);
+ hci_unregister_dev(hdev);
+
+ hci_free_dev(hdev);
+ kfree(hst);
+
+ dev_set_drvdata(&pdev->dev, NULL);
+ return 0;
+}
+
+static struct platform_driver btwilink_driver = {
+ .probe = bt_ti_probe,
+ .remove = bt_ti_remove,
+ .driver = {
+ .name = "btwilink",
+ .owner = THIS_MODULE,
+ },
+};
+
+/* ------- Module Init/Exit interfaces ------ */
+static int __init btwilink_init(void)
+{
+ BT_INFO("Bluetooth Driver for TI WiLink - Version %s", VERSION);
+
+ return platform_driver_register(&btwilink_driver);
+}
+
+static void __exit btwilink_exit(void)
+{
+ platform_driver_unregister(&btwilink_driver);
+}
+
+module_init(btwilink_init);
+module_exit(btwilink_exit);
+
+/* ------ Module Info ------ */
+
+MODULE_AUTHOR("Raja Mani <[email protected]>");
+MODULE_DESCRIPTION("Bluetooth Driver for TI Shared Transport" VERSION);
+MODULE_VERSION(VERSION);
+MODULE_LICENSE("GPL");
--
1.6.3.3

2011-01-04 10:59:47

by Pavan Savoy

[permalink] [raw]
Subject: [RFC 1/2] drivers:misc:ti-st: change protocol parse logic

From: Pavan Savoy <[email protected]>

TI shared transport driver had to specifically know the
protocol headers for each type of data it can receive to
properly re-assemble data if its fragmented during UART
transaction or fragment if the data is an assembly of
different protocol data.

Now the individual protocol drivers provide enough header
information for shared transport driver to do this in a
generic way applicable for all protocols.

Signed-off-by: Pavan Savoy <[email protected]>
---
drivers/misc/ti-st/st_core.c | 355 +++++++++++++-----------------------------
drivers/misc/ti-st/st_kim.c | 56 ++++----
include/linux/ti_wilink_st.h | 40 ++++--
3 files changed, 167 insertions(+), 284 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index f9aad06..84d73c5 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -25,10 +25,9 @@
#include <linux/init.h>
#include <linux/tty.h>

-/* understand BT, FM and GPS for now */
-#include <net/bluetooth/bluetooth.h>
-#include <net/bluetooth/hci_core.h>
-#include <net/bluetooth/hci.h>
+#include <linux/seq_file.h>
+#include <linux/skbuff.h>
+
#include <linux/ti_wilink_st.h>

/* function pointer pointing to either,
@@ -38,21 +37,20 @@
void (*st_recv) (void*, const unsigned char*, long);

/********************************************************************/
-#if 0
-/* internal misc functions */
-bool is_protocol_list_empty(void)
+static void add_channel_to_table(struct st_data_s *st_gdata,
+ struct st_proto_s *new_proto)
{
- unsigned char i = 0;
- pr_debug(" %s ", __func__);
- for (i = 0; i < ST_MAX; i++) {
- if (st_gdata->list[i] != NULL)
- return ST_NOTEMPTY;
- /* not empty */
- }
- /* list empty */
- return ST_EMPTY;
+ pr_info("%s: id %d\n", __func__, new_proto->chnl_id);
+ /* list now has the channel id as index itself */
+ st_gdata->list[new_proto->chnl_id] = new_proto;
+}
+
+static void remove_channel_from_table(struct st_data_s *st_gdata,
+ struct st_proto_s *proto)
+{
+ pr_info("%s: id %d\n", __func__, proto->chnl_id);
+ st_gdata->list[proto->chnl_id] = NULL;
}
-#endif

/* can be called in from
* -- KIM (during fw download)
@@ -82,15 +80,15 @@ int st_int_write(struct st_data_s *st_gdata,
* push the skb received to relevant
* protocol stacks
*/
-void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
+void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
{
- pr_info(" %s(prot:%d) ", __func__, protoid);
+ pr_info(" %s(prot:%d) ", __func__, chnl_id);

if (unlikely
(st_gdata == NULL || st_gdata->rx_skb == NULL
- || st_gdata->list[protoid] == NULL)) {
- pr_err("protocol %d not registered, no data to send?",
- protoid);
+ || st_gdata->list[chnl_id] == NULL)) {
+ pr_err("chnl_id %d not registered, no data to send?",
+ chnl_id);
kfree_skb(st_gdata->rx_skb);
return;
}
@@ -99,17 +97,17 @@ void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
* - should be just skb_queue_tail for the
* protocol stack driver
*/
- if (likely(st_gdata->list[protoid]->recv != NULL)) {
+ if (likely(st_gdata->list[chnl_id]->recv != NULL)) {
if (unlikely
- (st_gdata->list[protoid]->recv
- (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb)
+ (st_gdata->list[chnl_id]->recv
+ (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb)
!= 0)) {
- pr_err(" proto stack %d's ->recv failed", protoid);
+ pr_err(" proto stack %d's ->recv failed", chnl_id);
kfree_skb(st_gdata->rx_skb);
return;
}
} else {
- pr_err(" proto stack %d's ->recv null", protoid);
+ pr_err(" proto stack %d's ->recv null", chnl_id);
kfree_skb(st_gdata->rx_skb);
}
return;
@@ -124,7 +122,7 @@ void st_reg_complete(struct st_data_s *st_gdata, char err)
{
unsigned char i = 0;
pr_info(" %s ", __func__);
- for (i = 0; i < ST_MAX; i++) {
+ for (i = 0; i < ST_MAX_CHANNELS; i++) {
if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
st_gdata->list[i]->reg_complete_cb != NULL))
st_gdata->list[i]->reg_complete_cb
@@ -133,7 +131,7 @@ void st_reg_complete(struct st_data_s *st_gdata, char err)
}

static inline int st_check_data_len(struct st_data_s *st_gdata,
- int protoid, int len)
+ unsigned char chnl_id, int len)
{
int room = skb_tailroom(st_gdata->rx_skb);

@@ -144,7 +142,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
* has zero length payload. So, ask ST CORE to
* forward the packet to protocol driver (BT/FM/GPS)
*/
- st_send_frame(protoid, st_gdata);
+ st_send_frame(chnl_id, st_gdata);

} else if (len > room) {
/* Received packet's payload length is larger.
@@ -157,7 +155,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
/* Packet header has non-zero payload length and
* we have enough space in created skb. Lets read
* payload data */
- st_gdata->rx_state = ST_BT_W4_DATA;
+ st_gdata->rx_state = ST_W4_DATA;
st_gdata->rx_count = len;
return len;
}
@@ -167,6 +165,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
st_gdata->rx_state = ST_W4_PACKET_TYPE;
st_gdata->rx_skb = NULL;
st_gdata->rx_count = 0;
+ st_gdata->rx_chnl = 0;

return 0;
}
@@ -208,13 +207,10 @@ void st_int_recv(void *disc_data,
const unsigned char *data, long count)
{
char *ptr;
- struct hci_event_hdr *eh;
- struct hci_acl_hdr *ah;
- struct hci_sco_hdr *sh;
- struct fm_event_hdr *fm;
- struct gps_event_hdr *gps;
- int len = 0, type = 0, dlen = 0;
- static enum proto_type protoid = ST_MAX;
+ struct st_proto_s *proto;
+ unsigned short payload_len = 0;
+ int len = 0, type = 0;
+ unsigned char *plen;
struct st_data_s *st_gdata = (struct st_data_s *)disc_data;

ptr = (char *)data;
@@ -242,64 +238,36 @@ void st_int_recv(void *disc_data,

/* Check ST RX state machine , where are we? */
switch (st_gdata->rx_state) {
-
- /* Waiting for complete packet ? */
- case ST_BT_W4_DATA:
+ /* Waiting for complete packet ? */
+ case ST_W4_DATA:
pr_debug("Complete pkt received");
-
/* Ask ST CORE to forward
* the packet to protocol driver */
- st_send_frame(protoid, st_gdata);
+ st_send_frame(st_gdata->rx_chnl, st_gdata);

st_gdata->rx_state = ST_W4_PACKET_TYPE;
st_gdata->rx_skb = NULL;
- protoid = ST_MAX; /* is this required ? */
- continue;
-
- /* Waiting for Bluetooth event header ? */
- case ST_BT_W4_EVENT_HDR:
- eh = (struct hci_event_hdr *)st_gdata->rx_skb->
- data;
-
- pr_debug("Event header: evt 0x%2.2x"
- "plen %d", eh->evt, eh->plen);
-
- st_check_data_len(st_gdata, protoid, eh->plen);
- continue;
-
- /* Waiting for Bluetooth acl header ? */
- case ST_BT_W4_ACL_HDR:
- ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
- data;
- dlen = __le16_to_cpu(ah->dlen);
-
- pr_info("ACL header: dlen %d", dlen);
-
- st_check_data_len(st_gdata, protoid, dlen);
- continue;
-
- /* Waiting for Bluetooth sco header ? */
- case ST_BT_W4_SCO_HDR:
- sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
- data;
-
- pr_info("SCO header: dlen %d", sh->dlen);
-
- st_check_data_len(st_gdata, protoid, sh->dlen);
- continue;
- case ST_FM_W4_EVENT_HDR:
- fm = (struct fm_event_hdr *)st_gdata->rx_skb->
- data;
- pr_info("FM Header: ");
- st_check_data_len(st_gdata, ST_FM, fm->plen);
continue;
- /* TODO : Add GPS packet machine logic here */
- case ST_GPS_W4_EVENT_HDR:
- /* [0x09 pkt hdr][R/W byte][2 byte len] */
- gps = (struct gps_event_hdr *)st_gdata->rx_skb->
- data;
- pr_info("GPS Header: ");
- st_check_data_len(st_gdata, ST_GPS, gps->plen);
+ /* parse the header to know details */
+ case ST_W4_HEADER:
+ proto = st_gdata->list[st_gdata->rx_chnl];
+ plen =
+ &st_gdata->rx_skb->data
+ [proto->offset_len_in_hdr];
+ pr_info("plen pointing to %x\n", *plen);
+ if (proto->len_size == 1)/* 1 byte len field */
+ payload_len = *(unsigned char *)plen;
+ else if (proto->len_size == 2)
+ payload_len =
+ __le16_to_cpu(*(unsigned short *)plen);
+ else
+ pr_info("%s: invalid length "
+ "for id %d\n",
+ __func__, proto->chnl_id);
+ st_check_data_len(st_gdata, proto->chnl_id,
+ payload_len);
+ pr_info("off %d, pay len %d\n",
+ proto->offset_len_in_hdr, payload_len);
continue;
} /* end of switch rx_state */
}
@@ -308,51 +276,6 @@ void st_int_recv(void *disc_data,
/* Check first byte of packet and identify module
* owner (BT/FM/GPS) */
switch (*ptr) {
-
- /* Bluetooth event packet? */
- case HCI_EVENT_PKT:
- pr_info("Event packet");
- st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
- st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
- type = HCI_EVENT_PKT;
- protoid = ST_BT;
- break;
-
- /* Bluetooth acl packet? */
- case HCI_ACLDATA_PKT:
- pr_info("ACL packet");
- st_gdata->rx_state = ST_BT_W4_ACL_HDR;
- st_gdata->rx_count = HCI_ACL_HDR_SIZE;
- type = HCI_ACLDATA_PKT;
- protoid = ST_BT;
- break;
-
- /* Bluetooth sco packet? */
- case HCI_SCODATA_PKT:
- pr_info("SCO packet");
- st_gdata->rx_state = ST_BT_W4_SCO_HDR;
- st_gdata->rx_count = HCI_SCO_HDR_SIZE;
- type = HCI_SCODATA_PKT;
- protoid = ST_BT;
- break;
-
- /* Channel 8(FM) packet? */
- case ST_FM_CH8_PKT:
- pr_info("FM CH8 packet");
- type = ST_FM_CH8_PKT;
- st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
- st_gdata->rx_count = FM_EVENT_HDR_SIZE;
- protoid = ST_FM;
- break;
-
- /* Channel 9(GPS) packet? */
- case 0x9: /*ST_LL_GPS_CH9_PKT */
- pr_info("GPS CH9 packet");
- type = 0x9; /* ST_LL_GPS_CH9_PKT; */
- protoid = ST_GPS;
- st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
- st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/
- break;
case LL_SLEEP_IND:
case LL_SLEEP_ACK:
case LL_WAKE_UP_IND:
@@ -373,57 +296,22 @@ void st_int_recv(void *disc_data,
continue;
/* Unknow packet? */
default:
- pr_err("Unknown packet type %2.2x", (__u8) *ptr);
- ptr++;
- count--;
- continue;
+ type = *ptr;
+ st_gdata->rx_skb = alloc_skb(
+ st_gdata->list[type]->max_frame_size,
+ GFP_ATOMIC);
+ skb_reserve(st_gdata->rx_skb,
+ st_gdata->list[type]->reserve);
+ /* next 2 required for BT only */
+ st_gdata->rx_skb->cb[0] = type; /*pkt_type*/
+ st_gdata->rx_skb->cb[1] = 0; /*incoming*/
+ st_gdata->rx_chnl = *ptr;
+ st_gdata->rx_state = ST_W4_HEADER;
+ st_gdata->rx_count = st_gdata->list[type]->hdr_len;
+ pr_info("rx_count %ld\n", st_gdata->rx_count);
};
ptr++;
count--;
-
- switch (protoid) {
- case ST_BT:
- /* Allocate new packet to hold received data */
- st_gdata->rx_skb =
- bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
- if (!st_gdata->rx_skb) {
- pr_err("Can't allocate mem for new packet");
- st_gdata->rx_state = ST_W4_PACKET_TYPE;
- st_gdata->rx_count = 0;
- return;
- }
- bt_cb(st_gdata->rx_skb)->pkt_type = type;
- break;
- case ST_FM: /* for FM */
- st_gdata->rx_skb =
- alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
- if (!st_gdata->rx_skb) {
- pr_err("Can't allocate mem for new packet");
- st_gdata->rx_state = ST_W4_PACKET_TYPE;
- st_gdata->rx_count = 0;
- return;
- }
- /* place holder 0x08 */
- skb_reserve(st_gdata->rx_skb, 1);
- st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
- break;
- case ST_GPS:
- /* for GPS */
- st_gdata->rx_skb =
- alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
- if (!st_gdata->rx_skb) {
- pr_err("Can't allocate mem for new packet");
- st_gdata->rx_state = ST_W4_PACKET_TYPE;
- st_gdata->rx_count = 0;
- return;
- }
- /* place holder 0x09 */
- skb_reserve(st_gdata->rx_skb, 1);
- st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */
- break;
- case ST_MAX:
- break;
- }
}
pr_debug("done %s", __func__);
return;
@@ -565,20 +453,28 @@ long st_register(struct st_proto_s *new_proto)
unsigned long flags = 0;

st_kim_ref(&st_gdata, 0);
- pr_info("%s(%d) ", __func__, new_proto->type);
+ pr_info("%s(%d) ", __func__, new_proto->chnl_id);
if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
|| new_proto->reg_complete_cb == NULL) {
pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
+ if (st_gdata == NULL)
+ pr_err("error 1\n");
+ if (new_proto == NULL)
+ pr_err("error 2\n");
+ if (new_proto->recv == NULL)
+ pr_err("error 3\n");
+ if (new_proto->reg_complete_cb == NULL)
+ pr_err("erro 4\n");
return -1;
}

- if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
- pr_err("protocol %d not supported", new_proto->type);
+ if (new_proto->chnl_id >= ST_MAX_CHANNELS) {
+ pr_err("chnl_id %d not supported", new_proto->chnl_id);
return -EPROTONOSUPPORT;
}

- if (st_gdata->list[new_proto->type] != NULL) {
- pr_err("protocol %d already registered", new_proto->type);
+ if (st_gdata->list[new_proto->chnl_id] != NULL) {
+ pr_err("chnl_id %d already registered", new_proto->chnl_id);
return -EALREADY;
}

@@ -586,11 +482,11 @@ long st_register(struct st_proto_s *new_proto)
spin_lock_irqsave(&st_gdata->lock, flags);

if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
- pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
+ pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id);
/* fw download in progress */
- st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+ st_kim_chip_toggle(new_proto->chnl_id, KIM_GPIO_ACTIVE);

- st_gdata->list[new_proto->type] = new_proto;
+ add_channel_to_table(st_gdata, new_proto);
st_gdata->protos_registered++;
new_proto->write = st_write;

@@ -598,7 +494,7 @@ long st_register(struct st_proto_s *new_proto)
spin_unlock_irqrestore(&st_gdata->lock, flags);
return -EINPROGRESS;
} else if (st_gdata->protos_registered == ST_EMPTY) {
- pr_info(" protocol list empty :%d ", new_proto->type);
+ pr_info(" chnl_id list empty :%d ", new_proto->chnl_id);
set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
st_recv = st_kim_recv;

@@ -622,9 +518,9 @@ long st_register(struct st_proto_s *new_proto)
return -1;
}

- /* the protocol might require other gpios to be toggled
+ /* the chnl_id might require other gpios to be toggled
*/
- st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
+ st_kim_chip_toggle(new_proto->chnl_id, KIM_GPIO_ACTIVE);

clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
st_recv = st_int_recv;
@@ -642,14 +538,14 @@ long st_register(struct st_proto_s *new_proto)
/* check for already registered once more,
* since the above check is old
*/
- if (st_gdata->list[new_proto->type] != NULL) {
+ if (st_gdata->list[new_proto->chnl_id] != NULL) {
pr_err(" proto %d already registered ",
- new_proto->type);
+ new_proto->chnl_id);
return -EALREADY;
}

spin_lock_irqsave(&st_gdata->lock, flags);
- st_gdata->list[new_proto->type] = new_proto;
+ add_channel_to_table(st_gdata, new_proto);
st_gdata->protos_registered++;
new_proto->write = st_write;
spin_unlock_irqrestore(&st_gdata->lock, flags);
@@ -657,22 +553,7 @@ long st_register(struct st_proto_s *new_proto)
}
/* if fw is already downloaded & new stack registers protocol */
else {
- switch (new_proto->type) {
- case ST_BT:
- /* do nothing */
- break;
- case ST_FM:
- case ST_GPS:
- st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
- break;
- case ST_MAX:
- default:
- pr_err("%d protocol not supported",
- new_proto->type);
- spin_unlock_irqrestore(&st_gdata->lock, flags);
- return -EPROTONOSUPPORT;
- }
- st_gdata->list[new_proto->type] = new_proto;
+ add_channel_to_table(st_gdata, new_proto);
st_gdata->protos_registered++;
new_proto->write = st_write;

@@ -680,48 +561,48 @@ long st_register(struct st_proto_s *new_proto)
spin_unlock_irqrestore(&st_gdata->lock, flags);
return err;
}
- pr_debug("done %s(%d) ", __func__, new_proto->type);
+ pr_debug("done %s(%d) ", __func__, new_proto->chnl_id);
}
EXPORT_SYMBOL_GPL(st_register);

/* to unregister a protocol -
* to be called from protocol stack driver
*/
-long st_unregister(enum proto_type type)
+long st_unregister(struct st_proto_s *proto)
{
long err = 0;
unsigned long flags = 0;
struct st_data_s *st_gdata;

- pr_debug("%s: %d ", __func__, type);
+ pr_debug("%s: %d ", __func__, proto->chnl_id);

st_kim_ref(&st_gdata, 0);
- if (type < ST_BT || type >= ST_MAX) {
- pr_err(" protocol %d not supported", type);
+ if (proto->chnl_id >= ST_MAX_CHANNELS) {
+ pr_err(" chnl_id %d not supported", proto->chnl_id);
return -EPROTONOSUPPORT;
}

spin_lock_irqsave(&st_gdata->lock, flags);

- if (st_gdata->list[type] == NULL) {
- pr_err(" protocol %d not registered", type);
+ if (st_gdata->list[proto->chnl_id] == NULL) {
+ pr_err(" chnl_id %d not registered", proto->chnl_id);
spin_unlock_irqrestore(&st_gdata->lock, flags);
return -EPROTONOSUPPORT;
}

st_gdata->protos_registered--;
- st_gdata->list[type] = NULL;
+ remove_channel_from_table(st_gdata, proto);

/* kim ignores BT in the below function
* and handles the rest, BT is toggled
* only in kim_start and kim_stop
*/
- st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
+ st_kim_chip_toggle(proto->chnl_id, KIM_GPIO_INACTIVE);
spin_unlock_irqrestore(&st_gdata->lock, flags);

if ((st_gdata->protos_registered == ST_EMPTY) &&
(!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
- pr_info(" all protocols unregistered ");
+ pr_info(" all chnl_ids unregistered ");

/* stop traffic on tty */
if (st_gdata->tty) {
@@ -729,7 +610,7 @@ long st_unregister(enum proto_type type)
stop_tty(st_gdata->tty);
}

- /* all protocols now unregistered */
+ /* all chnl_ids now unregistered */
st_kim_stop(st_gdata->kim_data);
/* disable ST LL */
st_ll_disable(st_gdata);
@@ -745,7 +626,7 @@ long st_write(struct sk_buff *skb)
{
struct st_data_s *st_gdata;
#ifdef DEBUG
- enum proto_type protoid = ST_MAX;
+ unsigned char chnl_id = ST_MAX_CHANNELS;
#endif
long len;

@@ -756,22 +637,10 @@ long st_write(struct sk_buff *skb)
return -1;
}
#ifdef DEBUG /* open-up skb to read the 1st byte */
- switch (skb->data[0]) {
- case HCI_COMMAND_PKT:
- case HCI_ACLDATA_PKT:
- case HCI_SCODATA_PKT:
- protoid = ST_BT;
- break;
- case ST_FM_CH8_PKT:
- protoid = ST_FM;
- break;
- case 0x09:
- protoid = ST_GPS;
- break;
- }
- if (unlikely(st_gdata->list[protoid] == NULL)) {
- pr_err(" protocol %d not registered, and writing? ",
- protoid);
+ chnl_id = skb->data[0];
+ if (unlikely(st_gdata->list[chnl_id] == NULL)) {
+ pr_err(" chnl_id %d not registered, and writing? ",
+ chnl_id);
return -1;
}
#endif
@@ -824,7 +693,7 @@ static int st_tty_open(struct tty_struct *tty)

static void st_tty_close(struct tty_struct *tty)
{
- unsigned char i = ST_MAX;
+ unsigned char i = ST_MAX_CHANNELS;
unsigned long flags = 0;
struct st_data_s *st_gdata = tty->disc_data;

@@ -835,7 +704,7 @@ static void st_tty_close(struct tty_struct *tty)
* un-installed for some reason - what should be done ?
*/
spin_lock_irqsave(&st_gdata->lock, flags);
- for (i = ST_BT; i < ST_MAX; i++) {
+ for (i = ST_BT; i < ST_MAX_CHANNELS; i++) {
if (st_gdata->list[i] != NULL)
pr_err("%d not un-registered", i);
st_gdata->list[i] = NULL;
@@ -869,7 +738,7 @@ static void st_tty_close(struct tty_struct *tty)
static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
char *tty_flags, int count)
{
-
+#define VERBOSE
#ifdef VERBOSE
print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
16, 1, data, count, 0);
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 73b6c8b..707c858 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -32,11 +32,7 @@
#include <linux/sched.h>
#include <linux/rfkill.h>

-/* understand BT events for fw response */
-#include <net/bluetooth/bluetooth.h>
-#include <net/bluetooth/hci_core.h>
-#include <net/bluetooth/hci.h>
-
+#include <linux/skbuff.h>
#include <linux/ti_wilink_st.h>


@@ -134,7 +130,7 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
/* Packet header has non-zero payload length and
* we have enough space in created skb. Lets read
* payload data */
- kim_gdata->rx_state = ST_BT_W4_DATA;
+ kim_gdata->rx_state = ST_W4_DATA;
kim_gdata->rx_count = len;
return len;
}
@@ -158,8 +154,8 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
const unsigned char *data, long count)
{
const unsigned char *ptr;
- struct hci_event_hdr *eh;
int len = 0, type = 0;
+ unsigned char *plen;

pr_debug("%s", __func__);
/* Decode received bytes here */
@@ -183,29 +179,27 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
/* Check ST RX state machine , where are we? */
switch (kim_gdata->rx_state) {
/* Waiting for complete packet ? */
- case ST_BT_W4_DATA:
+ case ST_W4_DATA:
pr_debug("Complete pkt received");
validate_firmware_response(kim_gdata);
kim_gdata->rx_state = ST_W4_PACKET_TYPE;
kim_gdata->rx_skb = NULL;
continue;
/* Waiting for Bluetooth event header ? */
- case ST_BT_W4_EVENT_HDR:
- eh = (struct hci_event_hdr *)kim_gdata->
- rx_skb->data;
- pr_debug("Event header: evt 0x%2.2x"
- "plen %d", eh->evt, eh->plen);
- kim_check_data_len(kim_gdata, eh->plen);
+ case ST_W4_HEADER:
+ plen =
+ (unsigned char *)&kim_gdata->rx_skb->data[1];
+ pr_debug("event hdr: plen 0x%02x\n", *plen);
+ kim_check_data_len(kim_gdata, *plen);
continue;
} /* end of switch */
} /* end of if rx_state */
switch (*ptr) {
/* Bluetooth event packet? */
- case HCI_EVENT_PKT:
- pr_info("Event packet");
- kim_gdata->rx_state = ST_BT_W4_EVENT_HDR;
- kim_gdata->rx_count = HCI_EVENT_HDR_SIZE;
- type = HCI_EVENT_PKT;
+ case 0x04:
+ kim_gdata->rx_state = ST_W4_HEADER;
+ kim_gdata->rx_count = 2;
+ type = *ptr;
break;
default:
pr_info("unknown packet");
@@ -216,16 +210,18 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
ptr++;
count--;
kim_gdata->rx_skb =
- bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ alloc_skb(1024+8, GFP_ATOMIC);
if (!kim_gdata->rx_skb) {
pr_err("can't allocate mem for new packet");
kim_gdata->rx_state = ST_W4_PACKET_TYPE;
kim_gdata->rx_count = 0;
return;
}
- bt_cb(kim_gdata->rx_skb)->pkt_type = type;
+ skb_reserve(kim_gdata->rx_skb, 8);
+ kim_gdata->rx_skb->cb[0] = 4;
+ kim_gdata->rx_skb->cb[1] = 0;
+
}
- pr_info("done %s", __func__);
return;
}

@@ -398,7 +394,7 @@ void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW);
break;

- case ST_MAX:
+ case ST_MAX_CHANNELS:
default:
break;
}
@@ -416,7 +412,6 @@ void st_kim_recv(void *disc_data, const unsigned char *data, long count)
struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
struct kim_data_s *kim_gdata = st_gdata->kim_data;

- pr_info(" %s ", __func__);
/* copy to local buffer */
if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) {
/* must be the read_ver_cmd */
@@ -578,7 +573,7 @@ static int kim_toggle_radio(void *data, bool blocked)
else
st_kim_chip_toggle(type, KIM_GPIO_ACTIVE);
break;
- case ST_MAX:
+ case ST_MAX_CHANNELS:
pr_err(" wrong proto type ");
break;
}
@@ -664,12 +659,13 @@ static int kim_probe(struct platform_device *pdev)
/* refer to itself */
kim_gdata->core_data->kim_data = kim_gdata;

- for (proto = 0; proto < ST_MAX; proto++) {
+ for (proto = 0; proto < ST_MAX_CHANNELS; proto++) {
kim_gdata->gpios[proto] = gpios[proto];
pr_info(" %ld gpio to be requested", gpios[proto]);
}

- for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+ for (proto = 0; (proto < ST_MAX_CHANNELS)
+ && (gpios[proto] != -1); proto++) {
/* Claim the Bluetooth/FM/GPIO
* nShutdown gpio from the system
*/
@@ -704,7 +700,8 @@ static int kim_probe(struct platform_device *pdev)
init_completion(&kim_gdata->kim_rcvd);
init_completion(&kim_gdata->ldisc_installed);

- for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+ for (proto = 0; (proto < ST_MAX_CHANNELS)
+ && (gpios[proto] != -1); proto++) {
/* TODO: should all types be rfkill_type_bt ? */
kim_gdata->rf_protos[proto] = proto;
kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto],
@@ -752,7 +749,8 @@ static int kim_remove(struct platform_device *pdev)

kim_gdata = dev_get_drvdata(&pdev->dev);

- for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
+ for (proto = 0; (proto < ST_MAX_CHANNELS)
+ && (gpios[proto] != -1); proto++) {
/* Claim the Bluetooth/FM/GPIO
* nShutdown gpio from the system
*/
diff --git a/include/linux/ti_wilink_st.h b/include/linux/ti_wilink_st.h
index 4c7be22..1674ca7 100644
--- a/include/linux/ti_wilink_st.h
+++ b/include/linux/ti_wilink_st.h
@@ -42,7 +42,7 @@ enum proto_type {
ST_BT,
ST_FM,
ST_GPS,
- ST_MAX,
+ ST_MAX_CHANNELS = 16,
};

/**
@@ -62,6 +62,17 @@ enum proto_type {
* @priv_data: privdate data holder for the protocol drivers, sent
* from the protocol drivers during registration, and sent back on
* reg_complete_cb and recv.
+ * @chnl_id: channel id the protocol driver is interested in, the channel
+ * id is nothing but the 1st byte of the packet in UART frame.
+ * @max_frame_size: size of the largest frame the protocol can receive.
+ * @hdr_len: length of the header structure of the protocol.
+ * @offset_len_in_hdr: this provides the offset of the length field in the
+ * header structure of the protocol header, to assist ST to know
+ * how much to receive, if the data is split across UART frames.
+ * @len_size: whether the length field inside the header is 2 bytes
+ * or 1 byte.
+ * @reserve: the number of bytes ST needs to reserve in the skb being
+ * prepared for the protocol driver.
*/
struct st_proto_s {
enum proto_type type;
@@ -70,10 +81,17 @@ struct st_proto_s {
void (*reg_complete_cb) (void *, char data);
long (*write) (struct sk_buff *skb);
void *priv_data;
+
+ unsigned char chnl_id;
+ unsigned short max_frame_size;
+ unsigned char hdr_len;
+ unsigned char offset_len_in_hdr;
+ unsigned char len_size;
+ unsigned char reserve;
};

extern long st_register(struct st_proto_s *);
-extern long st_unregister(enum proto_type);
+extern long st_unregister(struct st_proto_s *);


/*
@@ -114,6 +132,7 @@ extern long st_unregister(enum proto_type);
* @rx_skb: the skb where all data for a protocol gets accumulated,
* since tty might not call receive when a complete event packet
* is received, the states, count and the skb needs to be maintained.
+ * @rx_chnl: the channel ID for which the data is getting accumalated for.
* @txq: the list of skbs which needs to be sent onto the TTY.
* @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
* up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
@@ -135,10 +154,11 @@ struct st_data_s {
#define ST_TX_SENDING 1
#define ST_TX_WAKEUP 2
unsigned long tx_state;
- struct st_proto_s *list[ST_MAX];
+ struct st_proto_s *list[ST_MAX_CHANNELS];
unsigned long rx_state;
unsigned long rx_count;
struct sk_buff *rx_skb;
+ unsigned char rx_chnl;
struct sk_buff_head txq, tx_waitq;
spinlock_t lock;
unsigned char protos_registered;
@@ -243,12 +263,12 @@ struct kim_data_s {
struct completion kim_rcvd, ldisc_installed;
char resp_buffer[30];
const struct firmware *fw_entry;
- long gpios[ST_MAX];
+ long gpios[ST_MAX_CHANNELS];
unsigned long rx_state;
unsigned long rx_count;
struct sk_buff *rx_skb;
- struct rfkill *rfkill[ST_MAX];
- enum proto_type rf_protos[ST_MAX];
+ struct rfkill *rfkill[ST_MAX_CHANNELS];
+ enum proto_type rf_protos[ST_MAX_CHANNELS];
struct st_data_s *core_data;
struct chip_version version;
};
@@ -338,12 +358,8 @@ struct hci_command {

/* ST LL receiver states */
#define ST_W4_PACKET_TYPE 0
-#define ST_BT_W4_EVENT_HDR 1
-#define ST_BT_W4_ACL_HDR 2
-#define ST_BT_W4_SCO_HDR 3
-#define ST_BT_W4_DATA 4
-#define ST_FM_W4_EVENT_HDR 5
-#define ST_GPS_W4_EVENT_HDR 6
+#define ST_W4_HEADER 1
+#define ST_W4_DATA 2

/* ST LL state machines */
#define ST_LL_ASLEEP 0
--
1.6.3.3