Bluetooth: btintel: Refactoring setup routines
Subsystems (6)
v3 cover Bluetooth: btintel: Refactoring setup routines
From: Tedd Ho-Jeong An <[email protected]>
This patch set refactors the multiple setup routines for various Intel devices to a combined single entry. Here are the highlight of the changes:
1. Updated hci_alloc_dev() to allocate the hdev object with an extra buffer for the private data. btintel introduces the btintel_data struct and store it to the private data in hdev object.
2. Added a single entry for setup and shutdown and uses the HCI_Intel_Read_Version command to identify the device, instead of relying on the USB VID and PID.
Also, it uses the new format of HCI_Intel_Read_Version command for legacy ROM and legacy bootloader devices. Luckly legacy devices support the new format.
3. Keep the state of bootloader in btintel object. The bootloader state is agnostic to the transport type, so btintel uses the btintel_data to keep track of the state in the private data section in hdev.
4. After identifying the setup type for the device, it uses the correspond setup routines based on the setup type, and the setup routines were moved from btusb to btintel.
However, actual work for the setup routines were not changed or very minimal.
5. Since many functions were moved from btusb to btintel, clean up the exported functions and make them static if possible.
Tedd Ho-Jeong An (9):
Bluetooth: Add support hdev to allocate private data
Bluetooth: btintel: Add combined setup and shutdown functions
Bluetooth: btintel: Refactoring setup routine for legacy ROM sku
Bluetooth: btintel: Add btintel data struct
Bluetooth: btintel: Fix the first HCI command not work with ROM
device.
Bluetooth: btintel: Add combined set_diag functions
Bluetooth: btintel: Refactoring setup routine for legacy bootloader
Bluetooth: btintel: Refactoring setup routine for TLV based booloader
Bluetooth: btintel: Clean the exported function to static
drivers/bluetooth/bfusb.c | 2 +- drivers/bluetooth/bluecard_cs.c | 2 +- drivers/bluetooth/bpa10x.c | 2 +- drivers/bluetooth/bt3c_cs.c | 2 +- drivers/bluetooth/btintel.c | 1184 ++++++++++++++++++++++++++++-- drivers/bluetooth/btintel.h | 82 +-- drivers/bluetooth/btmrvl_main.c | 2 +- drivers/bluetooth/btmtksdio.c | 2 +- drivers/bluetooth/btmtkuart.c | 2 +- drivers/bluetooth/btqcomsmd.c | 2 +- drivers/bluetooth/btrsi.c | 2 +- drivers/bluetooth/btsdio.c | 2 +- drivers/bluetooth/btusb.c | 1098 ++------------------------- drivers/bluetooth/dtl1_cs.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/bluetooth/hci_serdev.c | 2 +- drivers/bluetooth/hci_vhci.c | 2 +- drivers/bluetooth/virtio_bt.c | 2 +- include/net/bluetooth/hci_core.h | 7 +- net/bluetooth/hci_core.c | 11 +- 20 files changed, 1225 insertions(+), 1187 deletions(-)
Signature · 1 line
2.26.3
RFC PATCH v3 1/9 Bluetooth: Add support hdev to allocate private data
From: Tedd Ho-Jeong An <[email protected]>
This patch adds support hdev to allocate extra size for private data. The size of private data is specified in the hdev_alloc_size(priv_size) and the allocated buffer can be accessed with hci_get_priv(hdev).
--- drivers/bluetooth/bfusb.c | 2 +- drivers/bluetooth/bluecard_cs.c | 2 +- drivers/bluetooth/bpa10x.c | 2 +- drivers/bluetooth/bt3c_cs.c | 2 +- drivers/bluetooth/btmrvl_main.c | 2 +- drivers/bluetooth/btmtksdio.c | 2 +- drivers/bluetooth/btmtkuart.c | 2 +- drivers/bluetooth/btqcomsmd.c | 2 +- drivers/bluetooth/btrsi.c | 2 +- drivers/bluetooth/btsdio.c | 2 +- drivers/bluetooth/btusb.c | 2 +- drivers/bluetooth/dtl1_cs.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/bluetooth/hci_serdev.c | 2 +- drivers/bluetooth/hci_vhci.c | 2 +- drivers/bluetooth/virtio_bt.c | 2 +- include/net/bluetooth/hci_core.h | 7 ++++++- net/bluetooth/hci_core.c | 11 +++++++++-- 18 files changed, 31 insertions(+), 19 deletions(-)
drivers/bluetooth/bfusb.c +1 -1
@@ -651,7 +651,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *irelease_firmware (firmware);/* Initialize and register HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" ); goto done;
drivers/bluetooth/bluecard_cs.c +1 -1
@@ -694,7 +694,7 @@ static int bluecard_open(struct bluecard_info *info) info->rx_skb =NULL ;/* Initialize HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" );return -ENOMEM ;
drivers/bluetooth/bpa10x.c +1 -1
@@ -380,7 +380,7 @@ static int bpa10x_probe(struct usb_interface *intf,init_usb_anchor (&data->tx_anchor);init_usb_anchor (&data->rx_anchor); - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev)return -ENOMEM ;
drivers/bluetooth/bt3c_cs.c +1 -1
@@ -550,7 +550,7 @@ static int bt3c_open(struct bt3c_info *info) info->rx_skb =NULL ;/* Initialize HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" );return -ENOMEM ;
drivers/bluetooth/btmrvl_main.c +1 -1
@@ -680,7 +680,7 @@ int btmrvl_register_hdev(struct btmrvl_private *priv)struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;int ret; - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can not allocate HCI device" ); goto err_hdev;
drivers/bluetooth/btmtksdio.c +1 -1
@@ -959,7 +959,7 @@ static int btmtksdio_probe(struct sdio_func *func,skb_queue_head_init (&bdev->txq);/* Initialize and register HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {dev_err (&func->dev,"Can't allocate HCI device\n" );return -ENOMEM ;
drivers/bluetooth/btmtkuart.c +1 -1
@@ -987,7 +987,7 @@ static int btmtkuart_probe(struct serdev_device *serdev)skb_queue_head_init (&bdev->txq);/* Initialize and register HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {dev_err (&serdev->dev,"Can't allocate HCI device\n" );return -ENOMEM ;
drivers/bluetooth/btqcomsmd.c +1 -1
@@ -147,7 +147,7 @@ static int btqcomsmd_probe(struct platform_device *pdev) goto destroy_acl_channel; } - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) { ret = -ENOMEM ; goto destroy_cmd_channel;
drivers/bluetooth/btrsi.c +1 -1
@@ -121,7 +121,7 @@ static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops) ops->set_bt_context (priv, h_adapter); h_adapter->proto_ops = ops; - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Failed to alloc HCI device" ); goto err;
drivers/bluetooth/btsdio.c +1 -1
@@ -310,7 +310,7 @@ static int btsdio_probe(struct sdio_func *func,skb_queue_head_init (&data->txq); - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev)return -ENOMEM ;
drivers/bluetooth/btusb.c +1 -1
@@ -4560,7 +4560,7 @@ static int btusb_probe(struct usb_interface *intf, data->recv_bulk = btusb_recv_bulk; } - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev)return -ENOMEM ;
drivers/bluetooth/dtl1_cs.c +1 -1
@@ -449,7 +449,7 @@ static int dtl1_open(struct dtl1_info *info)set_bit (XMIT_WAITING , &(info->tx_state));/* Initialize HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" );return -ENOMEM ;
drivers/bluetooth/hci_ldisc.c +1 -1
@@ -627,7 +627,7 @@ static int hci_uart_register_dev(struct hci_uart *hu)BT_DBG ("" );/* Initialize and register HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" );return -ENOMEM ;
drivers/bluetooth/hci_serdev.c +1 -1
@@ -313,7 +313,7 @@ int hci_uart_register_device(struct hci_uart *hu,set_bit (HCI_UART_PROTO_READY , &hu->flags);/* Initialize and register HCI device */ - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {BT_ERR ("Can't allocate HCI device" ); err = -ENOMEM ;
drivers/bluetooth/hci_vhci.c +1 -1
@@ -96,7 +96,7 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)if (!skb)return -ENOMEM ; - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) {kfree_skb (skb);return -ENOMEM ;
drivers/bluetooth/virtio_bt.c +1 -1
@@ -283,7 +283,7 @@ static int virtbt_probe(struct virtio_device *vdev)if (err)return err; - hdev =hci_alloc_dev (); + hdev =hci_alloc_dev (0 );if (!hdev) { err = -ENOMEM ; goto failed;
include/net/bluetooth/hci_core.h +6 -1
@@ -1223,10 +1223,15 @@ static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)dev_set_drvdata (&hdev->dev, data); } +static inline void *hci_get_priv (struct hci_dev *hdev) +{ +return (char *)hdev +sizeof (*hdev); +} +struct hci_dev *hci_dev_get (int index);struct hci_dev *hci_get_route (bdaddr_t *dst,bdaddr_t *src,u8 src_type); -struct hci_dev *hci_alloc_dev (void ); +struct hci_dev *hci_alloc_dev (int sizeof_priv);void hci_free_dev (struct hci_dev *hdev);int hci_register_dev (struct hci_dev *hdev);void hci_unregister_dev (struct hci_dev *hdev);
net/bluetooth/hci_core.c +9 -2
@@ -3751,11 +3751,18 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, }/* Alloc HCI device */ -struct hci_dev *hci_alloc_dev (void ) +struct hci_dev *hci_alloc_dev (int sizeof_priv) {struct hci_dev *hdev; +unsigned int alloc_size; - hdev =kzalloc (sizeof (*hdev),GFP_KERNEL ); + alloc_size =sizeof (*hdev); +if (sizeof_priv) { +/* Fixme: May need ALIGN-ment? */ + alloc_size += sizeof_priv; + } + + hdev =kzalloc (alloc_size,GFP_KERNEL );if (!hdev)return NULL ;
Signature · 1 line
2.26.3
RFC PATCH v3 2/9 Bluetooth: btintel: Add combined setup and shutdown functions
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
There are multiple setup and shutdown functions for Intel device and the setup function to use is depends on the USB PID/VID, which makes difficult to maintain the code and increases the code size.
This patch adds combined setup and shutdown functions to provide a single entry point for all Intel devices and choose the setup functions based on the information read with HCI_Intel_Read_Version command.
Starting from TyP device, for HCI_Intel_Read_Version command, the command parameter and response are changed even though OCF remains same. Luckly the legacy devices still can handle the command without error even if it has a extra parameter, so it uses the new command format to support both legacy and new (tlv based) format.
--- drivers/bluetooth/btintel.c | 210 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 12 +++ 2 files changed, 222 insertions(+)
drivers/bluetooth/btintel.c +210 -0
@@ -236,6 +236,8 @@ int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)* compatibility options when newer hardware variants come along. */ switch (ver->hw_variant) { +case 0x07 :/* WP - Legacy ROM */ +case 0x08 :/* StP - Legacy ROM */ case 0x0b :/* SfP */ case 0x0c :/* WsP */ case 0x11 :/* JfP */
@@ -250,9 +252,15 @@ int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver) }switch (ver->fw_variant) { +case 0x01 : + variant ="Legacy ROM 2.5" ; +break ;case 0x06 : variant ="Bootloader" ;break ; +case 0x22 : + variant ="Legacy ROM 2.x" ; +break ;case 0x23 : variant ="Firmware" ;break ;
@@ -483,6 +491,98 @@ int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver }EXPORT_SYMBOL_GPL (btintel_version_info_tlv); +static int btintel_parse_version_tlv (struct hci_dev *hdev, +struct intel_version_tlv *version, +struct sk_buff *skb) +{ +/* Consume Command Complete Status field */ +skb_pull (skb,1 ); + +/* Event parameters contatin multiple TLVs. Read each of them +* and only keep the required data. Also, it use existing legacy +* version field like hw_platform, hw_variant, and fw_variant +* to keep the existing setup flow +*/ +while (skb->len) { +struct intel_tlv *tlv; + + tlv = (struct intel_tlv *)skb->data; +switch (tlv->type) { +case INTEL_TLV_CNVI_TOP : + version->cnvi_top =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVR_TOP : + version->cnvr_top =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVI_BT : + version->cnvi_bt =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVR_BT : + version->cnvr_bt =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_DEV_REV_ID : + version->dev_rev_id =get_unaligned_le16 (tlv->val); +break ; +case INTEL_TLV_IMAGE_TYPE : + version->img_type = tlv->val[0 ]; +break ; +case INTEL_TLV_TIME_STAMP : +/* If image type is Operational firmware (0x03), then +* running FW Calendar Week and Year information can +* be extracted from Timestamp information +*/ + version->min_fw_build_cw = tlv->val[0 ]; + version->min_fw_build_yy = tlv->val[1 ]; + version->timestamp =get_unaligned_le16 (tlv->val); +break ; +case INTEL_TLV_BUILD_TYPE : + version->build_type = tlv->val[0 ]; +break ; +case INTEL_TLV_BUILD_NUM : +/* If image type is Operational firmware (0x03), then +* running FW build number can be extracted from the +* Build information +*/ + version->min_fw_build_nn = tlv->val[0 ]; + version->build_num =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_SECURE_BOOT : + version->secure_boot = tlv->val[0 ]; +break ; +case INTEL_TLV_OTP_LOCK : + version->otp_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_API_LOCK : + version->api_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_DEBUG_LOCK : + version->debug_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_MIN_FW : + version->min_fw_build_nn = tlv->val[0 ]; + version->min_fw_build_cw = tlv->val[1 ]; + version->min_fw_build_yy = tlv->val[2 ]; +break ; +case INTEL_TLV_LIMITED_CCE : + version->limited_cce = tlv->val[0 ]; +break ; +case INTEL_TLV_SBE_TYPE : + version->sbe_type = tlv->val[0 ]; +break ; +case INTEL_TLV_OTP_BDADDR : +memcpy (&version->otp_bd_addr, tlv->val, tlv->len); +break ; +default : +/* Ignore rest of information */ +break ; + } +/* consume the current tlv and move to next*/ +skb_pull (skb, tlv->len +sizeof (*tlv)); + } + +return 0 ; +} +int btintel_read_version_tlv (struct hci_dev *hdev,struct intel_version_tlv *version) {struct sk_buff *skb;
@@ -1272,6 +1372,116 @@ int btintel_set_debug_features(struct hci_dev *hdev, }EXPORT_SYMBOL_GPL (btintel_set_debug_features); +int btintel_setup_combined (struct hci_dev *hdev) +{ +const u8 param[1 ] = {0xFF }; +struct intel_version ver; +struct intel_version_tlv ver_tlv; +struct sk_buff *skb; +int err; + +BT_DBG ("%s" , hdev->name); + +/* Starting from TyP device, the command parameter and response are +* changed even though the OCF for HCI_Intel_Read_Version command +* remains same. The legacy devices can handle even if the +* command has a parameter and returns a correct version information. +* So, it uses new format to support both legacy and new format. +*/ + skb =__hci_cmd_sync (hdev,0xfc05 ,1 , param,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev,"Reading Intel version command failed (%ld)" , +PTR_ERR (skb)); +return PTR_ERR (skb); + } + +/* Check the status */ +if (skb->data[0 ]) { +bt_dev_err (hdev,"Intel Read Version command failed (%02x)" , + skb->data[0 ]); +kfree_skb (skb); +return -EIO ; + } + +/* For Legacy device, check the HW platform value and size */ +if (skb->data[1 ] ==0x37 && skb->len ==sizeof (ver)) { +bt_dev_dbg (hdev,"Read the legacy Intel version information" ); + +memcpy (&ver, skb->data,sizeof (ver)); + +/* Display version information */ +btintel_version_info (hdev, &ver); + +/* Identify the device type based on the read version */ +switch (ver.hw_variant) { +case 0x07 :/* WP */ +case 0x08 :/* StP */ +/* Legacy ROM product */ +/* TODO: call setup routine for legacy rom product */ +break ; +case 0x0b :/* SfP */ +case 0x0c :/* WsP */ +case 0x11 :/* JfP */ +case 0x12 :/* ThP */ +case 0x13 :/* HrP */ +case 0x14 :/* CcP */ +/* TODO: call setup routine for bootloader product */ +break ; +default : +bt_dev_err (hdev,"Unsupported Intel hw variant (%u)" , + ver.hw_variant); +return -EINVAL ; + } + +return err; + } + +/* For TLV type device, parse the tlv data */ +btintel_parse_version_tlv (hdev, &ver_tlv, skb); + +/* Display version information of TLV type */ +btintel_version_info_tlv (hdev, &ver_tlv); + +/* TODO: Need to filter the device for new generation */ +/* TODO: call setup routine for tlv based bootloader product */ + +return err; +} +EXPORT_SYMBOL_GPL (btintel_setup_combined); + +int btintel_shutdown_combined (struct hci_dev *hdev) +{ +struct sk_buff *skb; + +/* Send HCI Reset to the controller to stop any BT activity which +* were triggered. This will help to save power and maintain the +* sync b/w Host and controller +*/ + skb =__hci_cmd_sync (hdev,HCI_OP_RESET ,0 ,NULL ,HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev,"HCI reset during shutdown failed" ); +return PTR_ERR (skb); + } +kfree_skb (skb); + +/* Fix me: All legacy ROM and RAM works? +* This code was only for legacy ROM +*/ +/* Some platforms have an issue with BT LED when the interface is +* down or BT radio is turned off, which takes 5 seconds to BT LED +* goes off. This command turns off the BT LED immediately. +*/ + skb =__hci_cmd_sync (hdev,0xfc3f ,0 ,NULL ,HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev,"turning off Intel device LED failed" ); +return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} +EXPORT_SYMBOL_GPL (btintel_shutdown_combined); +MODULE_AUTHOR ("Marcel Holtmann <[email protected]>" );MODULE_DESCRIPTION ("Bluetooth support for Intel devices ver " VERSION );MODULE_VERSION (VERSION );
drivers/bluetooth/btintel.h +12 -0
@@ -165,6 +165,8 @@ int btintel_read_boot_params(struct hci_dev *hdev, struct intel_boot_params *params);int btintel_download_firmware (struct hci_dev *dev,struct intel_version *ver,const struct firmware *fw,u32 *boot_param); +int btintel_setup_combined (struct hci_dev *hdev); +int btintel_shutdown_combined (struct hci_dev *hdev); int btintel_download_firmware_newgen(struct hci_dev *hdev, struct intel_version_tlv *ver, const struct firmware *fw,
@@ -283,6 +285,16 @@ static inline int btintel_download_firmware(struct hci_dev *dev,return -EOPNOTSUPP ; } +static inline int btintel_setup_combined (struct hci_dev *hdev) +{ +return -EOPNOTSUPP ; +} + +static inline int btintel_shutdown_combined (struct hci_dev *hdev) +{ +return -EOPNOTSUPP ; +} + static inline int btintel_download_firmware_newgen(struct hci_dev *hdev, const struct firmware *fw, u32 *boot_param,
Signature · 1 line
2.26.3
RE: [RFC PATCH v3 2/9] Bluetooth: btintel: Add combined setup and shutdown functions
Hi Tedd,
There is already a patch published to have a generic setup function for RAM products.
https://patchwork.kernel.org/project/bluetooth/patch/[email protected]/
Thanks,
Kiran
Quoted 315 lines
-----Original Message-----
From: Tedd Ho-Jeong An <[email protected]>
Sent: Saturday, July 24, 2021 1:00 PM
To: [email protected]
Cc: An, Tedd <[email protected]>
Subject: [RFC PATCH v3 2/9] Bluetooth: btintel: Add combined setup and shutdown functionsFrom: Tedd Ho-Jeong An <[email protected]>
There are multiple setup and shutdown functions for Intel device and the setup function to use is depends on the USB PID/VID, which makes difficult to maintain the code and increases the code size.
This patch adds combined setup and shutdown functions to provide a single entry point for all Intel devices and choose the setup functions based on the information read with
HCI_Intel_Read_Versioncommand.Starting from TyP device, for
HCI_Intel_Read_Versioncommand, the command parameter and response are changed even though OCF remains same. Luckly the legacy devices still can handle the command without error even if it has a extra parameter, so it uses the new command format to support both legacy and new (tlv based) format.Signed-off-by Tedd Ho-Jeong An <[email protected]>--- drivers/bluetooth/btintel.c | 210 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 12 +++ 2 files changed, 222 insertions(+)drivers/bluetooth/btintel.c index renamed from drivers/bluetooth/btintel.c +0
-0
e44b6993cf91..5513a2ba2504100644drivers/bluetooth/btintel.c +2
-0@@ -236,6 +236,8 @@ int btintel_version_info(struct hci_dev *hdev, structintel_version *ver) * compatibility options when newer hardware variants come along. */ switch (ver->hw_variant) { +case 0x07 :/* WP - Legacy ROM */ +case 0x08 :/* StP - Legacy ROM */ case 0x0b :/* SfP */ case 0x0c :/* WsP */ drivers/bluetooth/btintel.c +6
-0case 0x11 :/* JfP */ @@ -250,9 +252,15 @@ int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver) }switch (ver->fw_variant) { +case 0x01 : + variant ="Legacy ROM 2.5" ; +break ;case 0x06 : variant ="Bootloader" ;break ; +case 0x22 : + variant ="Legacy ROM 2.x" ; +break ;case 0x23 : variant ="Firmware" ;drivers/bluetooth/btintel.c +38
-0break ;@@ -483,6 +491,98 @@ int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver }EXPORT_SYMBOL_GPL (btintel_version_info_tlv); +static int btintel_parse_version_tlv (struct hci_dev *hdev, +struct intel_version_tlv *version, +struct sk_buff *skb) +{ +/* Consume Command Complete Status field */ +skb_pull (skb,1 ); + +/* Event parameters contatin multiple TLVs. Read each of them +* and only keep the required data. Also, it use existing legacy +* version field like hw_platform, hw_variant, and fw_variant +* to keep the existing setup flow +*/ +while (skb->len) { +struct intel_tlv *tlv; + + tlv = (struct intel_tlv *)skb->data; +switch (tlv->type) { +case INTEL_TLV_CNVI_TOP : + version->cnvi_top =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVR_TOP : + version->cnvr_top =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVI_BT : + version->cnvi_bt =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_CNVR_BT : + version->cnvr_bt =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_DEV_REV_ID : + version->dev_rev_id =get_unaligned_le16 (tlv->val); +break ; +case INTEL_TLV_IMAGE_TYPE : + version->img_type = tlv->val[0 ]; +break ; +case INTEL_TLV_TIME_STAMP : +/* If image type is Operational firmware (0x03), then +* running FW Calendar Week and Year information can
drivers/bluetooth/btintel.c +12
-0+* be extracted from Timestamp information +*/ + version->min_fw_build_cw = tlv->val[0 ]; + version->min_fw_build_yy = tlv->val[1 ]; + version->timestamp =get_unaligned_le16 (tlv->val); +break ; +case INTEL_TLV_BUILD_TYPE : + version->build_type = tlv->val[0 ]; +break ; +case INTEL_TLV_BUILD_NUM : +/* If image type is Operational firmware (0x03), then +* running FW build number can be extracted from the
drivers/bluetooth/btintel.c +42
-0+* Build information +*/ + version->min_fw_build_nn = tlv->val[0 ]; + version->build_num =get_unaligned_le32 (tlv->val); +break ; +case INTEL_TLV_SECURE_BOOT : + version->secure_boot = tlv->val[0 ]; +break ; +case INTEL_TLV_OTP_LOCK : + version->otp_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_API_LOCK : + version->api_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_DEBUG_LOCK : + version->debug_lock = tlv->val[0 ]; +break ; +case INTEL_TLV_MIN_FW : + version->min_fw_build_nn = tlv->val[0 ]; + version->min_fw_build_cw = tlv->val[1 ]; + version->min_fw_build_yy = tlv->val[2 ]; +break ; +case INTEL_TLV_LIMITED_CCE : + version->limited_cce = tlv->val[0 ]; +break ; +case INTEL_TLV_SBE_TYPE : + version->sbe_type = tlv->val[0 ]; +break ; +case INTEL_TLV_OTP_BDADDR : +memcpy (&version->otp_bd_addr, tlv->val, tlv->len); +break ; +default : +/* Ignore rest of information */ +break ; + } +/* consume the current tlv and move to next*/ +skb_pull (skb, tlv->len +sizeof (*tlv)); + } + +return 0 ; +} + int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv*version) {
drivers/bluetooth/btintel.c +10
-0struct sk_buff *skb;@@ -1272,6 +1372,116 @@ int btintel_set_debug_features(struct hci_dev *hdev, } EXPORT_SYMBOL_GPL(btintel_set_debug_features); +int btintel_setup_combined (struct hci_dev *hdev) { +const u8 param[1 ] = {0xFF }; +struct intel_version ver; +struct intel_version_tlv ver_tlv; +struct sk_buff *skb; +int err; + +BT_DBG ("%s" , hdev->name); + +/* Starting from TyP device, the command parameter and response are
drivers/bluetooth/btintel.c +1
-0+* changed even though the OCF for HCI_Intel_Read_Version command
drivers/bluetooth/btintel.c +2
-0+* remains same. The legacy devices can handle even if the +* command has a parameter and returns a correct version information.
drivers/bluetooth/btintel.c +5
-0+* So, it uses new format to support both legacy and new format. +*/ + skb =__hci_cmd_sync (hdev,0xfc05 ,1 , param,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { + bt_dev_err(hdev, "Reading Intel version command failed(%ld)",
drivers/bluetooth/btintel.c +7
-0+ PTR_ERR(skb)); +return PTR_ERR (skb); + } + +/* Check the status */ +if (skb->data[0 ]) { + bt_dev_err(hdev, "Intel Read Version command failed(%02x)",
drivers/bluetooth/btintel.c +8
-0+ skb->data[0]); +kfree_skb (skb); +return -EIO ; + } + +/* For Legacy device, check the HW platform value and size */ +if (skb->data[1 ] ==0x37 && skb->len ==sizeof (ver)) { + bt_dev_dbg(hdev, "Read the legacy Intel versioninformation");
drivers/bluetooth/btintel.c +20
-0+ +memcpy (&ver, skb->data,sizeof (ver)); + +/* Display version information */ +btintel_version_info (hdev, &ver); + +/* Identify the device type based on the read version */ +switch (ver.hw_variant) { +case 0x07 :/* WP */ +case 0x08 :/* StP */ +/* Legacy ROM product */ +/* TODO: call setup routine for legacy rom product */ +break ; +case 0x0b :/* SfP */ +case 0x0c :/* WsP */ +case 0x11 :/* JfP */ +case 0x12 :/* ThP */ +case 0x13 :/* HrP */ +case 0x14 :/* CcP */ +/* TODO: call setup routine for bootloader product */
drivers/bluetooth/btintel.c +3
-0+break ; +default : + bt_dev_err(hdev, "Unsupported Intel hw variant(%u)",
drivers/bluetooth/btintel.c +28
-0+ ver.hw_variant); +return -EINVAL ; + } + +return err; + } + +/* For TLV type device, parse the tlv data */ +btintel_parse_version_tlv (hdev, &ver_tlv, skb); + +/* Display version information of TLV type */ +btintel_version_info_tlv (hdev, &ver_tlv); + +/* TODO: Need to filter the device for new generation */ +/* TODO: call setup routine for tlv based bootloader product */ + +return err; +} +EXPORT_SYMBOL_GPL (btintel_setup_combined); + +int btintel_shutdown_combined (struct hci_dev *hdev) { +struct sk_buff *skb; + +/* Send HCI Reset to the controller to stop any BT activity which +* were triggered. This will help to save power and maintain the +* sync b/w Host and controller +*/ + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
HCI_INIT_TIMEOUT);drivers/bluetooth/btintel.c +24
-0+if (IS_ERR (skb)) { +bt_dev_err (hdev,"HCI reset during shutdown failed" ); +return PTR_ERR (skb); + } +kfree_skb (skb); + +/* Fix me: All legacy ROM and RAM works? +* This code was only for legacy ROM +*/ +/* Some platforms have an issue with BT LED when the interface is +* down or BT radio is turned off, which takes 5 seconds to BT LED +* goes off. This command turns off the BT LED immediately. +*/ + skb =__hci_cmd_sync (hdev,0xfc3f ,0 ,NULL ,HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev,"turning off Intel device LED failed" ); +return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} +EXPORT_SYMBOL_GPL (btintel_shutdown_combined); +MODULE_AUTHOR ("Marcel Holtmann <[email protected]>" );
MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);MODULE_VERSION(VERSION); diff --gita/drivers/bluetooth/btintel.hb/drivers/bluetooth/btintel.hindexd184064a5e7c..68ffa84fa87a100644drivers/bluetooth/btintel.h +10
-1@@ -165,6 +165,8 @@ int btintel_read_boot_params(struct hci_dev *hdev, struct intel_boot_params *params); intbtintel_download_firmware (struct hci_dev *dev,struct intel_version *ver,const struct firmware *fw,u32 *boot_param); +int btintel_setup_combined (struct hci_dev *hdev);int +btintel_shutdown_combined (struct hci_dev *hdev); int btintel_download_firmware_newgen(struct hci_dev *hdev, struct intel_version_tlv *ver, const struct firmware *fw,@@ -283,6 +285,16 @@ static inline int btintel_download_firmware(struct hci_dev *dev, return -EOPNOTSUPP ; } +static inline int btintel_setup_combined (struct hci_dev *hdev) { +return -EOPNOTSUPP ; +} + +static inline int btintel_shutdown_combined (struct hci_dev *hdev) { +return -EOPNOTSUPP ; +} + static inline int btintel_download_firmware_newgen(struct hci_dev *hdev, const struct firmware *fw, u32 *boot_param, --2.26.3
RFC PATCH v3 3/9 Bluetooth: btintel: Refactoring setup routine for legacy ROM sku
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch refactors the setup routines for legacy ROM product into combined setup, and move the related functions from btusb to btintel.
--- drivers/bluetooth/btintel.c | 287 +++++++++++++++++++++++++++- drivers/bluetooth/btusb.c | 362 +----------------------------------- 2 files changed, 294 insertions(+), 355 deletions(-)
drivers/bluetooth/btintel.c +286 -1
@@ -1372,6 +1372,291 @@ int btintel_set_debug_features(struct hci_dev *hdev, }EXPORT_SYMBOL_GPL (btintel_set_debug_features); +static const struct firmware *btintel_legacy_rom_get_fw (struct hci_dev *hdev, +struct intel_version *ver) +{ +const struct firmware *fw; +char fwname[64 ]; +int ret; + +snprintf (fwname,sizeof (fwname), +"intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq" , + ver->hw_platform, ver->hw_variant, ver->hw_revision, + ver->fw_variant, ver->fw_revision, ver->fw_build_num, + ver->fw_build_ww, ver->fw_build_yy); + + ret =request_firmware (&fw, fwname, &hdev->dev); +if (ret <0 ) { +if (ret == -EINVAL ) { +bt_dev_err (hdev,"Intel firmware file request failed (%d)" , + ret); +return NULL ; + } + +bt_dev_err (hdev,"failed to open Intel firmware file: %s (%d)" , + fwname, ret); + +/* If the correct firmware patch file is not found, use the +* default firmware patch file instead +*/ +snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.bseq" , + ver->hw_platform, ver->hw_variant); +if (request_firmware (&fw, fwname, &hdev->dev) <0 ) { +bt_dev_err (hdev,"failed to open default fw file: %s" , + fwname); +return NULL ; + } + } + +bt_dev_info (hdev,"Intel Bluetooth firmware file: %s" , fwname); + +return fw; +} + +static int btintel_legacy_rom_patching (struct hci_dev *hdev, +const struct firmware *fw, +const u8 **fw_ptr,int *disable_patch) +{ +struct sk_buff *skb; +struct hci_command_hdr *cmd; +const u8 *cmd_param; +struct hci_event_hdr *evt =NULL ; +const u8 *evt_param =NULL ; +int remain = fw->size - (*fw_ptr - fw->data); + +/* The first byte indicates the types of the patch command or event. +* 0x01 means HCI command and 0x02 is HCI event. If the first bytes +* in the current firmware buffer doesn't start with 0x01 or +* the size of remain buffer is smaller than HCI command header, +* the firmware file is corrupted and it should stop the patching +* process. +*/ +if (remain >HCI_COMMAND_HDR_SIZE && *fw_ptr[0 ] !=0x01 ) { +bt_dev_err (hdev,"Intel fw corrupted: invalid cmd read" ); +return -EINVAL ; + } + (*fw_ptr)++; + remain--; + + cmd = (struct hci_command_hdr *)(*fw_ptr); + *fw_ptr +=sizeof (*cmd); + remain -=sizeof (*cmd); + +/* Ensure that the remain firmware data is long enough than the length +* of command parameter. If not, the firmware file is corrupted. +*/ +if (remain < cmd->plen) { +bt_dev_err (hdev,"Intel fw corrupted: invalid cmd len" ); +return -EFAULT ; + } + +/* If there is a command that loads a patch in the firmware +* file, then enable the patch upon success, otherwise just +* disable the manufacturer mode, for example patch activation +* is not required when the default firmware patch file is used +* because there are no patch data to load. +*/ +if (*disable_patch &&le16_to_cpu (cmd->opcode) ==0xfc8e ) + *disable_patch =0 ; + + cmd_param = *fw_ptr; + *fw_ptr += cmd->plen; + remain -= cmd->plen; + +/* This reads the expected events when the above command is sent to the +* device. Some vendor commands expects more than one events, for +* example command status event followed by vendor specific event. +* For this case, it only keeps the last expected event. so the command +* can be sent with __hci_cmd_sync_ev() which returns the sk_buff of +* last expected event. +*/ +while (remain >HCI_EVENT_HDR_SIZE && *fw_ptr[0 ] ==0x02 ) { + (*fw_ptr)++; + remain--; + + evt = (struct hci_event_hdr *)(*fw_ptr); + *fw_ptr +=sizeof (*evt); + remain -=sizeof (*evt); + +if (remain < evt->plen) { +bt_dev_err (hdev,"Intel fw corrupted: invalid evt len" ); +return -EFAULT ; + } + + evt_param = *fw_ptr; + *fw_ptr += evt->plen; + remain -= evt->plen; + } + +/* Every HCI commands in the firmware file has its correspond event. +* If event is not found or remain is smaller than zero, the firmware +* file is corrupted. +*/ +if (!evt || !evt_param || remain <0 ) { +bt_dev_err (hdev,"Intel fw corrupted: invalid evt read" ); +return -EFAULT ; + } + + skb =__hci_cmd_sync_ev (hdev,le16_to_cpu (cmd->opcode), cmd->plen, + cmd_param, evt->evt,HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev,"sending Intel patch command (0x%4.4x) failed (%ld)" , + cmd->opcode,PTR_ERR (skb)); +return PTR_ERR (skb); + } + +/* It ensures that the returned event matches the event data read from +* the firmware file. At fist, it checks the length and then +* the contents of the event. +*/ +if (skb->len != evt->plen) { +bt_dev_err (hdev,"mismatch event length (opcode 0x%4.4x)" , +le16_to_cpu (cmd->opcode)); +kfree_skb (skb); +return -EFAULT ; + } + +if (memcmp (skb->data, evt_param, evt->plen)) { +bt_dev_err (hdev,"mismatch event parameter (opcode 0x%4.4x)" , +le16_to_cpu (cmd->opcode)); +kfree_skb (skb); +return -EFAULT ; + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_legacy_rom_setup (struct hci_dev *hdev, +struct intel_version *ver) +{ +const struct firmware *fw; +const u8 *fw_ptr; +int disable_patch, err; +struct intel_version new_ver; + +BT_DBG ("%s" , hdev->name); + +/* fw_patch_num indicates the version of patch the device currently +* have. If there is no patch data in the device, it is always 0x00. +* So, if it is other than 0x00, no need to patch the device again. +*/ +if (ver->fw_patch_num) { +bt_dev_info (hdev, +"Intel device is already patched. patch num: %02x" , + ver->fw_patch_num); + goto complete; + } + +/* Opens the firmware patch file based on the firmware version read +* from the controller. If it fails to open the matching firmware +* patch file, it tries to open the default firmware patch file. +* If no patch file is found, allow the device to operate without +* a patch. +*/ + fw =btintel_legacy_rom_get_fw (hdev, ver); +if (!fw) + goto complete; + fw_ptr = fw->data; + +/* Enable the manufacturer mode of the controller. +* Only while this mode is enabled, the driver can download the +* firmware patch data and configuration parameters. +*/ + err =btintel_enter_mfg (hdev); +if (err) { +release_firmware (fw); +return err; + } + + disable_patch =1 ; + +/* The firmware data file consists of list of Intel specific HCI +* commands and its expected events. The first byte indicates the +* type of the message, either HCI command or HCI event. +* +* It reads the command and its expected event from the firmware file, +* and send to the controller. Once __hci_cmd_sync_ev() returns, +* the returned event is compared with the event read from the firmware +* file and it will continue until all the messages are downloaded to +* the controller. +* +* Once the firmware patching is completed successfully, +* the manufacturer mode is disabled with reset and activating the +* downloaded patch. +* +* If the firmware patching fails, the manufacturer mode is +* disabled with reset and deactivating the patch. +* +* If the default patch file is used, no reset is done when disabling +* the manufacturer. +*/ +while (fw->size > fw_ptr - fw->data) { +int ret; + + ret =btintel_legacy_rom_patching (hdev, fw, &fw_ptr, + &disable_patch); +if (ret <0 ) + goto exit_mfg_deactivate; + } + +release_firmware (fw); + +if (disable_patch) + goto exit_mfg_disable; + +/* Patching completed successfully and disable the manufacturer mode +* with reset and activate the downloaded firmware patches. +*/ + err =btintel_exit_mfg (hdev, true, true); +if (err) +return err; + +/* Need build number for downloaded fw patches in +* every power-on boot +*/ + err =btintel_read_version (hdev, &new_ver); +if (err) +return err; + +bt_dev_info (hdev,"Intel BT fw patch 0x%02x completed & activated" , + new_ver.fw_patch_num); + + goto complete; + +exit_mfg_disable: +/* Disable the manufacturer mode without reset */ + err =btintel_exit_mfg (hdev, false, false); +if (err) +return err; + +bt_dev_info (hdev,"Intel firmware patch completed" ); + + goto complete; + +exit_mfg_deactivate: +release_firmware (fw); + +/* Patching failed. Disable the manufacturer mode with reset and +* deactivate the downloaded firmware patches. +*/ + err =btintel_exit_mfg (hdev, true, false); +if (err) +return err; + +bt_dev_info (hdev,"Intel firmware patch completed and deactivated" ); + +complete: +/* Set the event mask for Intel specific vendor events. This enables +* a few extra events that are useful during general operation. +*/ +btintel_set_event_mask_mfg (hdev, false); + +btintel_check_bdaddr (hdev); + +return 0 ; +} +int btintel_setup_combined (struct hci_dev *hdev) {const u8 param[1 ] = {0xFF };
@@ -1417,7 +1702,7 @@ int btintel_setup_combined(struct hci_dev *hdev)case 0x07 :/* WP */ case 0x08 :/* StP */ /* Legacy ROM product */ -/* TODO: call setup routine for legacy rom product */ + err =btintel_legacy_rom_setup (hdev, &ver);break ;case 0x0b :/* SfP */ case 0x0c :/* WsP */
drivers/bluetooth/btusb.c +8 -354
395 lines not on this page · raw message
Signature · 1 line
2.26.3
RFC PATCH v3 4/9 Bluetooth: btintel: Add btintel data struct
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch adds a data structure for btintel for btintel object, and the definition of bootloder states.
--- drivers/bluetooth/btintel.c | 8 ++++++++ drivers/bluetooth/btintel.h | 15 +++++++++++++++ drivers/bluetooth/btusb.c | 6 ++++-- 3 files changed, 27 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel.c +8 -0
@@ -1767,6 +1767,14 @@ int btintel_shutdown_combined(struct hci_dev *hdev) }EXPORT_SYMBOL_GPL (btintel_shutdown_combined); +void btintel_set_flags (struct hci_dev *hdev,unsigned int flag) +{ +struct btintel_data *intel =hci_get_priv (hdev); + +set_bit (flag, &intel->flags); +} +EXPORT_SYMBOL_GPL (btintel_set_flags); +MODULE_AUTHOR ("Marcel Holtmann <[email protected]>" );MODULE_DESCRIPTION ("Bluetooth support for Intel devices ver " VERSION );MODULE_VERSION (VERSION );
drivers/bluetooth/btintel.h +15 -0
@@ -138,6 +138,16 @@ struct intel_debug_features {#define INTEL_CNVX_TOP_STEP (cnvx_top) (((cnvx_top) & 0x0f000000) >> 24)#define INTEL_CNVX_TOP_PACK_SWAB (t, s) __swab16(((__u16)(((t) << 4) | (s)))) +#define INTEL_BOOTLOADER 0 +#define INTEL_DOWNLOADING 1 +#define INTEL_FIRMWARE_LOADED 2 +#define INTEL_FIRMWARE_FAILED 3 +#define INTEL_BOOTING 4 + +struct btintel_data { +unsigned long flags; +}; +#if IS_ENABLED (CONFIG_BT_INTEL )int btintel_check_bdaddr (struct hci_dev *hdev);
@@ -167,6 +177,7 @@ int btintel_download_firmware(struct hci_dev *dev, struct intel_version *ver, const struct firmware *fw, u32 *boot_param);int btintel_setup_combined (struct hci_dev *hdev);int btintel_shutdown_combined (struct hci_dev *hdev); +void btintel_set_flags (struct hci_dev *hdev,unsigned int flag); int btintel_download_firmware_newgen(struct hci_dev *hdev, struct intel_version_tlv *ver, const struct firmware *fw,
@@ -295,6 +306,10 @@ static inline int btintel_shutdown_combined(struct hci_dev *hdev)return -EOPNOTSUPP ; } +static inline void btintel_set_flags (struct hci_dev *hdev,unsigned int flag) +{ +} + static inline int btintel_download_firmware_newgen(struct hci_dev *hdev, const struct firmware *fw, u32 *boot_param,
drivers/bluetooth/btusb.c +4 -2
@@ -4118,7 +4118,7 @@ static int btusb_probe(struct usb_interface *intf,struct btusb_data *data;struct hci_dev *hdev;unsigned ifnum_base; -int i, err; +int i, err, priv_size;BT_DBG ("intf %p id %p" , intf, id);
@@ -4204,6 +4204,8 @@ static int btusb_probe(struct usb_interface *intf,init_usb_anchor (&data->ctrl_anchor);spin_lock_init (&data->rxlock); + priv_size =0 ; +if (id->driver_info &BTUSB_INTEL_NEW ) { data->recv_event = btusb_recv_event_intel; data->recv_bulk = btusb_recv_bulk_intel;
@@ -4213,7 +4215,7 @@ static int btusb_probe(struct usb_interface *intf, data->recv_bulk = btusb_recv_bulk; } - hdev =hci_alloc_dev (0 ); + hdev =hci_alloc_dev (priv_size);if (!hdev)return -ENOMEM ;
Signature · 1 line
2.26.3
RFC PATCH v3 5/9 Bluetooth: btintel: Fix the first HCI command not work with ROM device.
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
The some legacy ROM controllers have a bug with the first HCI command sent to it returning number of completed commands as zero, which would stall the command processing in the Bluetooth core.
As a workaround, send HCI Rest command first which will reset the controller to fix the issue.
--- drivers/bluetooth/btintel.c | 21 +++++++++++++++++++++ drivers/bluetooth/btintel.h | 1 + drivers/bluetooth/btusb.c | 16 ++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel.c +21 -0
@@ -1659,6 +1659,7 @@ static int btintel_legacy_rom_setup(struct hci_dev *hdev,int btintel_setup_combined (struct hci_dev *hdev) { +struct btintel_data *intel =hci_get_priv (hdev);const u8 param[1 ] = {0xFF };struct intel_version ver;struct intel_version_tlv ver_tlv;
@@ -1667,6 +1668,26 @@ int btintel_setup_combined(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); +/* The some controllers have a bug with the first HCI command sent to it +* returning number of completed commands as zero. This would stall the +* command processing in the Bluetooth core. +* +* As a workaround, send HCI Reset command first which will reset the +* number of completed commands and allow normal command processing +* from now on. +*/ +if (test_bit (INTEL_BROKEN_READ_VERSION , &intel->flags)) { + skb =__hci_cmd_sync (hdev,HCI_OP_RESET ,0 ,NULL , +HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_err (hdev, +"sending initial HCI reset failed (%ld)" , +PTR_ERR (skb)); +return PTR_ERR (skb); + } +kfree_skb (skb); + } +/* Starting from TyP device, the command parameter and response are * changed even though the OCF for HCI_Intel_Read_Version command * remains same. The legacy devices can handle even if the
drivers/bluetooth/btintel.h +1 -0
@@ -143,6 +143,7 @@ struct intel_debug_features {#define INTEL_FIRMWARE_LOADED 2#define INTEL_FIRMWARE_FAILED 3#define INTEL_BOOTING 4 +#define INTEL_BROKEN_READ_VERSION 5struct btintel_data {unsigned long flags;
drivers/bluetooth/btusb.c +14 -2
@@ -62,6 +62,7 @@ static struct usb_driver btusb_driver;#define BTUSB_QCA_WCN6855 0x1000000#define BTUSB_INTEL_NEWGEN 0x2000000#define BTUSB_INTEL_COMBINED 0x4000000 +#define BTUSB_INTEL_BROKEN_READ_VERSION 0x8000000static const struct usb_device_id btusb_table[] = {/* Generic Bluetooth USB device */
@@ -374,11 +375,14 @@ static const struct usb_device_id blacklist_table[] = { { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_NEWGEN | BTUSB_WIDEBAND_SPEECH}, { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, - { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED }, - { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED }, + { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED | + BTUSB_INTEL_BROKEN_READ_VERSION }, + { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED | + BTUSB_INTEL_BROKEN_READ_VERSION }, { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW | BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED | +BTUSB_INTEL_BROKEN_READ_VERSION | BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW | BTUSB_WIDEBAND_SPEECH |
@@ -4206,6 +4210,11 @@ static int btusb_probe(struct usb_interface *intf, priv_size =0 ; +if (id->driver_info &BTUSB_INTEL_COMBINED ) { +/* Allocate extra space for Intel device */ + priv_size +=sizeof (struct btintel_data ); + } +if (id->driver_info &BTUSB_INTEL_NEW ) { data->recv_event = btusb_recv_event_intel; data->recv_bulk = btusb_recv_bulk_intel;
@@ -4300,6 +4309,9 @@ static int btusb_probe(struct usb_interface *intf,set_bit (HCI_QUIRK_STRICT_DUPLICATE_FILTER , &hdev->quirks);set_bit (HCI_QUIRK_SIMULTANEOUS_DISCOVERY , &hdev->quirks);set_bit (HCI_QUIRK_NON_PERSISTENT_DIAG , &hdev->quirks); + +if (id->driver_info &BTUSB_INTEL_BROKEN_READ_VERSION ) +btintel_set_flags (hdev,INTEL_BROKEN_READ_VERSION ); }if (id->driver_info &BTUSB_INTEL_NEW ) {
Signature · 1 line
2.26.3
RFC PATCH v3 6/9 Bluetooth: btintel: Add combined set_diag functions
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch adds a combined set_diag functions.
It also changes the btintel_set_diag_mfg() to static since it is no longer used by others.
--- drivers/bluetooth/btintel.c | 23 +++++++++++++++++++++-- drivers/bluetooth/btintel.h | 5 +++-- drivers/bluetooth/btusb.c | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/bluetooth/btintel.c +21 -2
@@ -164,7 +164,7 @@ int btintel_set_diag(struct hci_dev *hdev, bool enable) }EXPORT_SYMBOL_GPL (btintel_set_diag); -int btintel_set_diag_mfg (struct hci_dev *hdev,bool enable) +static int btintel_set_diag_mfg (struct hci_dev *hdev,bool enable) {int err, ret;
@@ -180,7 +180,25 @@ int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable)return ret; } -EXPORT_SYMBOL_GPL (btintel_set_diag_mfg); + +int btintel_set_diag_combined (struct hci_dev *hdev,bool enable) +{ +struct btintel_data *intel =hci_get_priv (hdev); +int ret; + +/* Legacy ROM device needs to be in the manufacturer mode to apply +* diagnostic setting +* +* This flag is set after reading the Intel version. +*/ +if (test_bit (INTEL_ROM_LEGACY , &intel->flags)) + ret =btintel_set_diag_mfg (hdev, enable); +else + ret =btintel_set_diag (hdev, enable); + +return ret; +} +EXPORT_SYMBOL_GPL (btintel_set_diag_combined);void btintel_hw_error (struct hci_dev *hdev,u8 code) {
@@ -1723,6 +1741,7 @@ int btintel_setup_combined(struct hci_dev *hdev)case 0x07 :/* WP */ case 0x08 :/* StP */ /* Legacy ROM product */ +set_bit (INTEL_ROM_LEGACY , &intel->flags); err =btintel_legacy_rom_setup (hdev, &ver);break ;case 0x0b :/* SfP */
drivers/bluetooth/btintel.h +3 -2
@@ -144,6 +144,7 @@ struct intel_debug_features {#define INTEL_FIRMWARE_FAILED 3#define INTEL_BOOTING 4#define INTEL_BROKEN_READ_VERSION 5 +#define INTEL_ROM_LEGACY 6struct btintel_data {unsigned long flags;
@@ -156,7 +157,7 @@ int btintel_enter_mfg(struct hci_dev *hdev);int btintel_exit_mfg (struct hci_dev *hdev,bool reset,bool patched);int btintel_set_bdaddr (struct hci_dev *hdev,const bdaddr_t *bdaddr);int btintel_set_diag (struct hci_dev *hdev,bool enable); -int btintel_set_diag_mfg (struct hci_dev *hdev,bool enable); +int btintel_set_diag_combined (struct hci_dev *hdev,bool enable);void btintel_hw_error (struct hci_dev *hdev,u8 code);int btintel_version_info (struct hci_dev *hdev,struct intel_version *ver);
@@ -216,7 +217,7 @@ static inline int btintel_set_diag(struct hci_dev *hdev, bool enable)return -EOPNOTSUPP ; } -static inline int btintel_set_diag_mfg (struct hci_dev *hdev,bool enable) +static inline int btintel_set_diag_combined (struct hci_dev *hdev,bool enable) {return -EOPNOTSUPP ; }
drivers/bluetooth/btusb.c +1 -1
@@ -4303,7 +4303,7 @@ static int btusb_probe(struct usb_interface *intf, hdev->manufacturer =2 ; hdev->setup = btintel_setup_combined; hdev->shutdown = btintel_shutdown_combined; - hdev->set_diag = btintel_set_diag_mfg; + hdev->set_diag = btintel_set_diag_combined; hdev->set_bdaddr = btintel_set_bdaddr; hdev->cmd_timeout = btusb_intel_cmd_timeout;set_bit (HCI_QUIRK_STRICT_DUPLICATE_FILTER , &hdev->quirks);
Signature · 1 line
2.26.3
RFC PATCH v3 7/9 Bluetooth: btintel: Refactoring setup routine for legacy bootloader
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch refactors the setup routines for legacy bootloader devices into combined setup, and move the related functions from btusb to btintel.
--- drivers/bluetooth/btintel.c | 418 +++++++++++++++++++++++++++++++++++- drivers/bluetooth/btintel.h | 12 ++ drivers/bluetooth/btusb.c | 376 +++++--------------------------- 3 files changed, 478 insertions(+), 328 deletions(-)
drivers/bluetooth/btintel.c +417 -1
@@ -1675,6 +1675,391 @@ static int btintel_legacy_rom_setup(struct hci_dev *hdev,return 0 ; } +static int btintel_download_wait (struct hci_dev *hdev,ktime_t calltime,int msec) +{ +struct btintel_data *intel =hci_get_priv (hdev); +ktime_t delta, rettime; +unsigned long long duration; +int err; + +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); + +bt_dev_info (hdev,"Waiting for firmware download to complete" ); + + err =wait_on_bit_timeout (&intel->flags,INTEL_DOWNLOADING , +TASK_INTERRUPTIBLE , +msecs_to_jiffies (msec)); +if (err == -EINTR ) { +bt_dev_err (hdev,"Firmware loading interrupted" ); +return err; + } + +if (err) { +bt_dev_err (hdev,"Firmware loading timeout" ); +return -ETIMEDOUT ; + } + +if (test_bit (INTEL_FIRMWARE_FAILED , &intel->flags)) { +bt_dev_err (hdev,"Firmware loading failed" ); +return -ENOEXEC ; + } + + rettime =ktime_get (); + delta =ktime_sub (rettime, calltime); + duration = (unsigned long long )ktime_to_ns (delta) >>10 ; + +bt_dev_info (hdev,"Firmware loaded in %llu usecs" , duration); + +return 0 ; +} + +static int btintel_boot_wait (struct hci_dev *hdev,ktime_t calltime,int msec) +{ +struct btintel_data *intel =hci_get_priv (hdev); +ktime_t delta, rettime; +unsigned long long duration; +int err; + +bt_dev_info (hdev,"Waiting for device to boot" ); + + err =wait_on_bit_timeout (&intel->flags,INTEL_BOOTING , +TASK_INTERRUPTIBLE ,msecs_to_jiffies (msec)); +if (err == -EINTR ) { +bt_dev_err (hdev,"Device boot interrupted" ); +return -EINTR ; + } + +if (err) { +bt_dev_err (hdev,"Device boot timeout" ); +return -ETIMEDOUT ; + } + + rettime =ktime_get (); + delta =ktime_sub (rettime, calltime); + duration = (unsigned long long )ktime_to_ns (delta) >>10 ; + +bt_dev_info (hdev,"Device booted in %llu usecs" , duration); + +return 0 ; +} + +static int btintel_boot (struct hci_dev *hdev,u32 boot_addr) +{ +struct btintel_data *intel =hci_get_priv (hdev); +ktime_t calltime; +int err; + + calltime =ktime_get (); + +set_bit (INTEL_BOOTING , &intel->flags); + + err =btintel_send_intel_reset (hdev, boot_addr); +if (err) { +bt_dev_err (hdev,"Intel Soft Reset failed (%d)" , err); +btintel_reset_to_bootloader (hdev); +return err; + } + +/* The bootloader will not indicate when the device is ready. This +* is done by the operational firmware sending bootup notification. +* +* Booting into operational firmware should not take longer than +* 1 second. However if that happens, then just fail the setup +* since something went wrong. +*/ + err =btintel_boot_wait (hdev, calltime,1000 ); +if (err == -ETIMEDOUT ) +btintel_reset_to_bootloader (hdev); + +return err; +} + +static int btintel_get_fw_name (struct intel_version *ver, +struct intel_boot_params *params, +char *fw_name,size_t len, +const char *suffix) +{ +switch (ver->hw_variant) { +case 0x0b :/* SfP */ +case 0x0c :/* WsP */ +snprintf (fw_name, len,"intel/ibt-%u-%u.%s" , +le16_to_cpu (ver->hw_variant), +le16_to_cpu (params->dev_revid), + suffix); +break ; +case 0x11 :/* JfP */ +case 0x12 :/* ThP */ +case 0x13 :/* HrP */ +case 0x14 :/* CcP */ +snprintf (fw_name, len,"intel/ibt-%u-%u-%u.%s" , +le16_to_cpu (ver->hw_variant), +le16_to_cpu (ver->hw_revision), +le16_to_cpu (ver->fw_revision), + suffix); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int btintel_download_fw (struct hci_dev *hdev, +struct intel_version *ver, +struct intel_boot_params *params, +u32 *boot_param) +{ +const struct firmware *fw; +char fwname[64 ]; +int err; +struct btintel_data *intel =hci_get_priv (hdev); +ktime_t calltime; + +if (!ver || !params) +return -EINVAL ; + +/* The firmware variant determines if the device is in bootloader +* mode or is running operational firmware. The value 0x06 identifies +* the bootloader and the value 0x23 identifies the operational +* firmware. +* +* When the operational firmware is already present, then only +* the check for valid Bluetooth device address is needed. This +* determines if the device will be added as configured or +* unconfigured controller. +* +* It is not possible to use the Secure Boot Parameters in this +* case since that command is only available in bootloader mode. +*/ +if (ver->fw_variant ==0x23 ) { +clear_bit (INTEL_BOOTLOADER , &intel->flags); +btintel_check_bdaddr (hdev); + +/* SfP and WsP don't seem to update the firmware version on file +* so version checking is currently possible. +*/ +switch (ver->hw_variant) { +case 0x0b :/* SfP */ +case 0x0c :/* WsP */ +return 0 ; + } + +/* Proceed to download to check if the version matches */ + goto download; + } + +/* Read the secure boot parameters to identify the operating +* details of the bootloader. +*/ + err =btintel_read_boot_params (hdev, params); +if (err) +return err; + +/* It is required that every single firmware fragment is acknowledged +* with a command complete event. If the boot parameters indicate +* that this bootloader does not send them, then abort the setup. +*/ +if (params->limited_cce !=0x00 ) { +bt_dev_err (hdev,"Unsupported Intel firmware loading method (%u)" , + params->limited_cce); +return -EINVAL ; + } + +/* If the OTP has no valid Bluetooth device address, then there will +* also be no valid address for the operational firmware. +*/ +if (!bacmp (¶ms->otp_bdaddr,BDADDR_ANY )) { +bt_dev_info (hdev,"No device address configured" ); +set_bit (HCI_QUIRK_INVALID_BDADDR , &hdev->quirks); + } + +download: +/* With this Intel bootloader only the hardware variant and device +* revision information are used to select the right firmware for SfP +* and WsP. +* +* The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi. +* +* Currently the supported hardware variants are: +* 11 (0x0b) for iBT3.0 (LnP/SfP) +* 12 (0x0c) for iBT3.5 (WsP) +* +* For ThP/JfP and for future SKU's, the FW name varies based on HW +* variant, HW revision and FW revision, as these are dependent on CNVi +* and RF Combination. +* +* 17 (0x11) for iBT3.5 (JfP) +* 18 (0x12) for iBT3.5 (ThP) +* +* The firmware file name for these will be +* ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. +* +*/ + err =btintel_get_fw_name (ver, params, fwname,sizeof (fwname),"sfi" ); +if (err <0 ) { +if (!test_bit (INTEL_BOOTLOADER , &intel->flags)) { +/* Firmware has already been loaded */ +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); +return 0 ; + } + +bt_dev_err (hdev,"Unsupported Intel firmware naming" ); +return -EINVAL ; + } + + err =firmware_request_nowarn (&fw, fwname, &hdev->dev); +if (err <0 ) { +if (!test_bit (INTEL_BOOTLOADER , &intel->flags)) { +/* Firmware has already been loaded */ +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); +return 0 ; + } + +bt_dev_err (hdev,"Failed to load Intel firmware file %s (%d)" , + fwname, err); +return err; + } + +bt_dev_info (hdev,"Found device firmware: %s" , fwname); + +if (fw->size <644 ) { +bt_dev_err (hdev,"Invalid size of firmware file (%zu)" , + fw->size); + err = -EBADF ; + goto done; + } + + calltime =ktime_get (); + +set_bit (INTEL_DOWNLOADING , &intel->flags); + +/* Start firmware downloading and get boot parameter */ + err =btintel_download_firmware (hdev, ver, fw, boot_param); +if (err <0 ) { +if (err == -EALREADY ) { +/* Firmware has already been loaded */ +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); + err =0 ; + goto done; + } + +/* When FW download fails, send Intel Reset to retry +* FW download. +*/ +btintel_reset_to_bootloader (hdev); + goto done; + } + +/* Before switching the device into operational mode and with that +* booting the loaded firmware, wait for the bootloader notification +* that all fragments have been successfully received. +* +* When the event processing receives the notification, then the +* INTEL_DOWNLOADING flag will be cleared. +* +* The firmware loading should not take longer than 5 seconds +* and thus just timeout if that happens and fail the setup +* of this device. +*/ + err =btintel_download_wait (hdev, calltime,5000 ); +if (err == -ETIMEDOUT ) +btintel_reset_to_bootloader (hdev); + +done: +release_firmware (fw); +return err; +} + +static int btintel_bootloader_setup (struct hci_dev *hdev, +struct intel_version *ver) +{ +struct btintel_data *intel =hci_get_priv (hdev); +struct intel_version new_ver; +struct intel_boot_params params; +u32 boot_param; +char ddcname[64 ]; +int err; +struct intel_debug_features features; + +BT_DBG ("%s" , hdev->name); + +/* Set the default boot parameter to 0x0 and it is updated to +* SKU specific boot parameter after reading Intel_Write_Boot_Params +* command while downloading the firmware. +*/ + boot_param =0x00000000 ; + +set_bit (INTEL_BOOTLOADER , &intel->flags); + + err =btintel_download_fw (hdev, ver, ¶ms, &boot_param); +if (err) +return err; + +/* controller is already having an operational firmware */ +if (ver->fw_variant ==0x23 ) + goto finish; + + err =btintel_boot (hdev, boot_param); +if (err) +return err; + +clear_bit (INTEL_BOOTLOADER , &intel->flags); + + err =btintel_get_fw_name (ver, ¶ms, ddcname, +sizeof (ddcname),"ddc" ); + +if (err <0 ) { +bt_dev_err (hdev,"Unsupported Intel firmware naming" ); + }else { +/* Once the device is running in operational mode, it needs to +* apply the device configuration (DDC) parameters. +* +* The device can work without DDC parameters, so even if it +* fails to load the file, no need to fail the setup. +*/ +btintel_load_ddc_config (hdev, ddcname); + } + +/* Read the Intel supported features and if new exception formats +* supported, need to load the additional DDC config to enable. +*/ +btintel_read_debug_features (hdev, &features); + +/* Set DDC mask for available debug features */ +btintel_set_debug_features (hdev, &features); + +/* Read the Intel version information after loading the FW */ + err =btintel_read_version (hdev, &new_ver); +if (err) +return err; + +btintel_version_info (hdev, &new_ver); + +finish: +/* All Intel controllers that support the Microsoft vendor +* extension are using 0xFC1E for VsMsftOpCode. +*/ +switch (ver->hw_variant) { +case 0x11 :/* JfP */ +case 0x12 :/* ThP */ +case 0x13 :/* HrP */ +case 0x14 :/* CcP */ +hci_set_msft_opcode (hdev,0xFC1E ); +break ; + } + +/* Set the event mask for Intel specific vendor events. This enables +* a few extra events that are useful during general operation. It +* does not enable any debugging related events. +* +* The device will function correctly without these events enabled +* and thus no need to fail the setup. +*/ +btintel_set_event_mask (hdev, false); + +return 0 ; +} +int btintel_setup_combined (struct hci_dev *hdev) {struct btintel_data *intel =hci_get_priv (hdev);
@@ -1750,7 +2135,7 @@ int btintel_setup_combined(struct hci_dev *hdev)case 0x12 :/* ThP */ case 0x13 :/* HrP */ case 0x14 :/* CcP */ -/* TODO: call setup routine for bootloader product */ + err =btintel_bootloader_setup (hdev, &ver);break ;default : bt_dev_err(hdev, "Unsupported Intel hw variant (%u)",
@@ -1815,6 +2200,37 @@ void btintel_set_flags(struct hci_dev *hdev, unsigned int flag) }EXPORT_SYMBOL_GPL (btintel_set_flags); +void btintel_bootup (struct hci_dev *hdev,const void *ptr,unsigned int len) +{ +struct btintel_data *intel =hci_get_priv (hdev); +const struct intel_bootup *evt = ptr; + +if (len !=sizeof (*evt)) +return ; + +if (test_and_clear_bit (INTEL_BOOTING , &intel->flags)) +wake_up_bit (&intel->flags,INTEL_BOOTING ); +} +EXPORT_SYMBOL_GPL (btintel_bootup); + +void btintel_secure_send_result (struct hci_dev *hdev, +const void *ptr,unsigned int len) +{ +struct btintel_data *intel =hci_get_priv (hdev); +const struct intel_secure_send_result *evt = ptr; + +if (len !=sizeof (*evt)) +return ; + +if (evt->result) +set_bit (INTEL_FIRMWARE_FAILED , &intel->flags); + +if (test_and_clear_bit (INTEL_DOWNLOADING , &intel->flags) && +test_bit (INTEL_FIRMWARE_LOADED , &intel->flags)) +wake_up_bit (&intel->flags,INTEL_DOWNLOADING ); +} +EXPORT_SYMBOL_GPL (btintel_secure_send_result); +MODULE_AUTHOR ("Marcel Holtmann <[email protected]>" );MODULE_DESCRIPTION ("Bluetooth support for Intel devices ver " VERSION );MODULE_VERSION (VERSION );
drivers/bluetooth/btintel.h +12 -0
@@ -190,6 +190,9 @@ int btintel_read_debug_features(struct hci_dev *hdev, struct intel_debug_features *features);int btintel_set_debug_features (struct hci_dev *hdev,const struct intel_debug_features *features); +void btintel_bootup (struct hci_dev *hdev,const void *ptr,unsigned int len); +void btintel_secure_send_result (struct hci_dev *hdev, +const void *ptr,unsigned int len);#else static inline int btintel_check_bdaddr (struct hci_dev *hdev)
@@ -336,4 +339,13 @@ static inline int btintel_set_debug_features(struct hci_dev *hdev, return -EOPNOTSUPP; } +static inline void btintel_bootup (struct hci_dev *hdev, +const void *ptr,unsigned int len) +{ +} + +static inline void btintel_secure_send_result (struct hci_dev *hdev, +const void *ptr,unsigned int len) +{ +}#endif
drivers/bluetooth/btusb.c +49 -327
472 lines not on this page · raw message
Signature · 1 line
2.26.3
RFC PATCH v3 8/9 Bluetooth: btintel: Refactoring setup routine for TLV based booloader
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch refactors the setup routines for the TLV based bootloader devices into combined setup, and move the related functions from btubs to btintel.
--- drivers/bluetooth/btintel.c | 286 +++++++++++++++++-------- drivers/bluetooth/btintel.h | 13 -- drivers/bluetooth/btusb.c | 412 +----------------------------------- 3 files changed, 201 insertions(+), 510 deletions(-)
drivers/bluetooth/btintel.c +196 -90
@@ -623,90 +623,7 @@ int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *verreturn -EIO ; } -/* Consume Command Complete Status field */ -skb_pull (skb,1 ); - -/* Event parameters contatin multiple TLVs. Read each of them -* and only keep the required data. Also, it use existing legacy -* version field like hw_platform, hw_variant, and fw_variant -* to keep the existing setup flow -*/ -while (skb->len) { -struct intel_tlv *tlv; - - tlv = (struct intel_tlv *)skb->data; -switch (tlv->type) { -case INTEL_TLV_CNVI_TOP : - version->cnvi_top =get_unaligned_le32 (tlv->val); -break ; -case INTEL_TLV_CNVR_TOP : - version->cnvr_top =get_unaligned_le32 (tlv->val); -break ; -case INTEL_TLV_CNVI_BT : - version->cnvi_bt =get_unaligned_le32 (tlv->val); -break ; -case INTEL_TLV_CNVR_BT : - version->cnvr_bt =get_unaligned_le32 (tlv->val); -break ; -case INTEL_TLV_DEV_REV_ID : - version->dev_rev_id =get_unaligned_le16 (tlv->val); -break ; -case INTEL_TLV_IMAGE_TYPE : - version->img_type = tlv->val[0 ]; -break ; -case INTEL_TLV_TIME_STAMP : -/* If image type is Operational firmware (0x03), then -* running FW Calendar Week and Year information can -* be extracted from Timestamp information -*/ - version->min_fw_build_cw = tlv->val[0 ]; - version->min_fw_build_yy = tlv->val[1 ]; - version->timestamp =get_unaligned_le16 (tlv->val); -break ; -case INTEL_TLV_BUILD_TYPE : - version->build_type = tlv->val[0 ]; -break ; -case INTEL_TLV_BUILD_NUM : -/* If image type is Operational firmware (0x03), then -* running FW build number can be extracted from the -* Build information -*/ - version->min_fw_build_nn = tlv->val[0 ]; - version->build_num =get_unaligned_le32 (tlv->val); -break ; -case INTEL_TLV_SECURE_BOOT : - version->secure_boot = tlv->val[0 ]; -break ; -case INTEL_TLV_OTP_LOCK : - version->otp_lock = tlv->val[0 ]; -break ; -case INTEL_TLV_API_LOCK : - version->api_lock = tlv->val[0 ]; -break ; -case INTEL_TLV_DEBUG_LOCK : - version->debug_lock = tlv->val[0 ]; -break ; -case INTEL_TLV_MIN_FW : - version->min_fw_build_nn = tlv->val[0 ]; - version->min_fw_build_cw = tlv->val[1 ]; - version->min_fw_build_yy = tlv->val[2 ]; -break ; -case INTEL_TLV_LIMITED_CCE : - version->limited_cce = tlv->val[0 ]; -break ; -case INTEL_TLV_SBE_TYPE : - version->sbe_type = tlv->val[0 ]; -break ; -case INTEL_TLV_OTP_BDADDR : -memcpy (&version->otp_bd_addr, tlv->val, tlv->len); -break ; -default : -/* Ignore rest of information */ -break ; - } -/* consume the current tlv and move to next*/ -skb_pull (skb, tlv->len +sizeof (*tlv)); - } +btintel_parse_version_tlv (hdev, version, skb);kfree_skb (skb);return 0 ;
@@ -1184,10 +1101,10 @@ int btintel_download_firmware(struct hci_dev *hdev, }EXPORT_SYMBOL_GPL (btintel_download_firmware); -int btintel_download_firmware_newgen (struct hci_dev *hdev, -struct intel_version_tlv *ver, -const struct firmware *fw,u32 *boot_param, -u8 hw_variant,u8 sbe_type) +static int btintel_download_fw_tlv (struct hci_dev *hdev, +struct intel_version_tlv *ver, +const struct firmware *fw,u32 *boot_param, +u8 hw_variant,u8 sbe_type) {int err;u32 css_header_ver;
@@ -1284,7 +1201,6 @@ int btintel_download_firmware_newgen(struct hci_dev *hdev, }return 0 ; } -EXPORT_SYMBOL_GPL (btintel_download_firmware_newgen);void btintel_reset_to_bootloader (struct hci_dev *hdev) {
@@ -2060,6 +1976,196 @@ static int btintel_bootloader_setup(struct hci_dev *hdev,return 0 ; } +static void btintel_get_fw_name_tlv (const struct intel_version_tlv *ver, +char *fw_name,size_t len, +const char *suffix) +{ +/* The firmware file name for new generation controllers will be +* ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step> +*/ +snprintf (fw_name, len,"intel/ibt-%04x-%04x.%s" , +INTEL_CNVX_TOP_PACK_SWAB (INTEL_CNVX_TOP_TYPE (ver->cnvi_top), +INTEL_CNVX_TOP_STEP (ver->cnvi_top)), +INTEL_CNVX_TOP_PACK_SWAB (INTEL_CNVX_TOP_TYPE (ver->cnvr_top), +INTEL_CNVX_TOP_STEP (ver->cnvr_top)), + suffix); +} + +static int btintel_prepare_fw_download_tlv (struct hci_dev *hdev, +struct intel_version_tlv *ver, +u32 *boot_param) +{ +struct btintel_data *intel =hci_get_priv (hdev); +const struct firmware *fw; +char fwname[64 ]; +int err; +ktime_t calltime; + +if (!ver || !boot_param) +return -EINVAL ; + +/* The firmware variant determines if the device is in bootloader +* mode or is running operational firmware. The value 0x03 identifies +* the bootloader and the value 0x23 identifies the operational +* firmware. +* +* When the operational firmware is already present, then only +* the check for valid Bluetooth device address is needed. This +* determines if the device will be added as configured or +* unconfigured controller. +* +* It is not possible to use the Secure Boot Parameters in this +* case since that command is only available in bootloader mode. +*/ +if (ver->img_type ==0x03 ) { +clear_bit (INTEL_BOOTLOADER , &intel->flags); +btintel_check_bdaddr (hdev); + } + +/* If the OTP has no valid Bluetooth device address, then there will +* also be no valid address for the operational firmware. +*/ +if (!bacmp (&ver->otp_bd_addr,BDADDR_ANY )) { +bt_dev_info (hdev,"No device address configured" ); +set_bit (HCI_QUIRK_INVALID_BDADDR , &hdev->quirks); + } + +btintel_get_fw_name_tlv (ver, fwname,sizeof (fwname),"sfi" ); + err =firmware_request_nowarn (&fw, fwname, &hdev->dev); +if (err <0 ) { +if (!test_bit (INTEL_BOOTLOADER , &intel->flags)) { +/* Firmware has already been loaded */ +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); +return 0 ; + } + +bt_dev_err (hdev,"Failed to load Intel firmware file %s (%d)" , + fwname, err); + +return err; + } + +bt_dev_info (hdev,"Found device firmware: %s" , fwname); + +if (fw->size <644 ) { +bt_dev_err (hdev,"Invalid size of firmware file (%zu)" , + fw->size); + err = -EBADF ; + goto done; + } + + calltime =ktime_get (); + +set_bit (INTEL_DOWNLOADING , &intel->flags); + +/* Start firmware downloading and get boot parameter */ + err =btintel_download_fw_tlv (hdev, ver, fw, boot_param, +INTEL_HW_VARIANT (ver->cnvi_bt), + ver->sbe_type); +if (err <0 ) { +if (err == -EALREADY ) { +/* Firmware has already been loaded */ +set_bit (INTEL_FIRMWARE_LOADED , &intel->flags); + err =0 ; + goto done; + } + +/* When FW download fails, send Intel Reset to retry +* FW download. +*/ +btintel_reset_to_bootloader (hdev); + goto done; + } + +/* Before switching the device into operational mode and with that +* booting the loaded firmware, wait for the bootloader notification +* that all fragments have been successfully received. +* +* When the event processing receives the notification, then the +* BTUSB_DOWNLOADING flag will be cleared. +* +* The firmware loading should not take longer than 5 seconds +* and thus just timeout if that happens and fail the setup +* of this device. +*/ + err =btintel_download_wait (hdev, calltime,5000 ); +if (err == -ETIMEDOUT ) +btintel_reset_to_bootloader (hdev); + +done: +release_firmware (fw); +return err; +} + +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev, +struct intel_version_tlv *ver) +{ +struct btintel_data *intel =hci_get_priv (hdev); +u32 boot_param; +char ddcname[64 ]; +int err; +struct intel_debug_features features; +struct intel_version_tlv new_ver; + +bt_dev_dbg (hdev,"" ); + +/* Set the default boot parameter to 0x0 and it is updated to +* SKU specific boot parameter after reading Intel_Write_Boot_Params +* command while downloading the firmware. +*/ + boot_param =0x00000000 ; + + err =btintel_prepare_fw_download_tlv (hdev, ver, &boot_param); +if (err) +return err; + +/* check if controller is already having an operational firmware */ +if (ver->img_type ==0x03 ) + goto finish; + + err =btintel_boot (hdev, boot_param); +if (err) +return err; + +clear_bit (INTEL_BOOTLOADER , &intel->flags); + +btintel_get_fw_name_tlv (ver, ddcname,sizeof (ddcname),"ddc" ); +/* Once the device is running in operational mode, it needs to +* apply the device configuration (DDC) parameters. +* +* The device can work without DDC parameters, so even if it +* fails to load the file, no need to fail the setup. +*/ +btintel_load_ddc_config (hdev, ddcname); + +/* Read the Intel supported features and if new exception formats +* supported, need to load the additional DDC config to enable. +*/ +btintel_read_debug_features (hdev, &features); + +/* Set DDC mask for available debug features */ +btintel_set_debug_features (hdev, &features); + +/* Read the Intel version information after loading the FW */ + err =btintel_read_version_tlv (hdev, &new_ver); +if (err) +return err; + +btintel_version_info_tlv (hdev, &new_ver); + +finish: +/* Set the event mask for Intel specific vendor events. This enables +* a few extra events that are useful during general operation. It +* does not enable any debugging related events. +* +* The device will function correctly without these events enabled +* and thus no need to fail the setup. +*/ +btintel_set_event_mask (hdev, false); + +return 0 ; +} +int btintel_setup_combined (struct hci_dev *hdev) {struct btintel_data *intel =hci_get_priv (hdev);
@@ -2153,7 +2259,7 @@ int btintel_setup_combined(struct hci_dev *hdev)btintel_version_info_tlv (hdev, &ver_tlv);/* TODO: Need to filter the device for new generation */ -/* TODO: call setup routine for tlv based bootloader product */ + err =btintel_bootloader_setup_tlv (hdev, &ver_tlv);return err; }
drivers/bluetooth/btintel.h +0 -13
@@ -180,11 +180,6 @@ int btintel_download_firmware(struct hci_dev *dev, struct intel_version *ver,int btintel_setup_combined (struct hci_dev *hdev);int btintel_shutdown_combined (struct hci_dev *hdev);void btintel_set_flags (struct hci_dev *hdev,unsigned int flag); -int btintel_download_firmware_newgen (struct hci_dev *hdev, -struct intel_version_tlv *ver, -const struct firmware *fw, -u32 *boot_param,u8 hw_variant, -u8 sbe_type);void btintel_reset_to_bootloader (struct hci_dev *hdev);int btintel_read_debug_features (struct hci_dev *hdev,struct intel_debug_features *features);
@@ -315,14 +310,6 @@ static inline void btintel_set_flags(struct hci_dev *hdev, unsigned int flag) { } -static inline int btintel_download_firmware_newgen (struct hci_dev *hdev, -const struct firmware *fw, -u32 *boot_param, -u8 hw_variant,u8 sbe_type) -{ -return -EOPNOTSUPP ; -} -static inline void btintel_reset_to_bootloader (struct hci_dev *hdev) { }
drivers/bluetooth/btusb.c +5 -407
464 lines not on this page · raw message
Signature · 1 line
2.26.3
RFC PATCH v3 9/9 Bluetooth: btintel: Clean the exported function to static
In reply to Tedd Ho-Jeong AnFrom: Tedd Ho-Jeong An <[email protected]>
This patch changes the exported functions to static if they are no longer used by others.
--- drivers/bluetooth/btintel.c | 65 +++++++++++++++++-------------------- drivers/bluetooth/btintel.h | 50 ---------------------------- 2 files changed, 30 insertions(+), 85 deletions(-)
drivers/bluetooth/btintel.c +30 -35
@@ -131,6 +131,26 @@ int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) }EXPORT_SYMBOL_GPL (btintel_set_bdaddr); +static int btintel_set_event_mask (struct hci_dev *hdev,bool debug) +{ +u8 mask[8 ] = {0x87 ,0x0c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; +struct sk_buff *skb; +int err; + +if (debug) + mask[1 ] |=0x62 ; + + skb =__hci_cmd_sync (hdev,0xfc52 ,8 , mask,HCI_INIT_TIMEOUT ); +if (IS_ERR (skb)) { + err =PTR_ERR (skb); +bt_dev_err (hdev,"Setting Intel event mask failed (%d)" , err); +return err; + } +kfree_skb (skb); + +return 0 ; +} +int btintel_set_diag (struct hci_dev *hdev,bool enable) {struct sk_buff *skb;
@@ -296,8 +316,8 @@ int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver) }EXPORT_SYMBOL_GPL (btintel_version_info); -int btintel_secure_send (struct hci_dev *hdev,u8 fragment_type,u32 plen, -const void *param) +static int btintel_secure_send (struct hci_dev *hdev,u8 fragment_type,u32 plen, +const void *param) {while (plen >0 ) {struct sk_buff *skb;
@@ -319,7 +339,6 @@ int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,return 0 ; } -EXPORT_SYMBOL_GPL (btintel_secure_send);int btintel_load_ddc_config (struct hci_dev *hdev,const char *ddc_name) {
@@ -366,27 +385,6 @@ int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name) }EXPORT_SYMBOL_GPL (btintel_load_ddc_config); -int btintel_set_event_mask (struct hci_dev *hdev,bool debug) -{ -u8 mask[8 ] = {0x87 ,0x0c ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; -struct sk_buff *skb; -int err; - -if (debug) - mask[1 ] |=0x62 ; - - skb =__hci_cmd_sync (hdev,0xfc52 ,8 , mask,HCI_INIT_TIMEOUT ); -if (IS_ERR (skb)) { - err =PTR_ERR (skb); -bt_dev_err (hdev,"Setting Intel event mask failed (%d)" , err); -return err; - } -kfree_skb (skb); - -return 0 ; -} -EXPORT_SYMBOL_GPL (btintel_set_event_mask); -int btintel_set_event_mask_mfg (struct hci_dev *hdev,bool debug) {int err, ret;
@@ -430,7 +428,8 @@ int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver) }EXPORT_SYMBOL_GPL (btintel_read_version); -int btintel_version_info_tlv (struct hci_dev *hdev,struct intel_version_tlv *version) +static int btintel_version_info_tlv (struct hci_dev *hdev, +struct intel_version_tlv *version) {const char *variant;
@@ -507,7 +506,6 @@ int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *verreturn 0 ; } -EXPORT_SYMBOL_GPL (btintel_version_info_tlv); static int btintel_parse_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *version,
@@ -601,7 +599,8 @@ static int btintel_parse_version_tlv(struct hci_dev *hdev,return 0 ; } -int btintel_read_version_tlv (struct hci_dev *hdev,struct intel_version_tlv *version) +static int btintel_read_version_tlv (struct hci_dev *hdev, +struct intel_version_tlv *version) {struct sk_buff *skb;const u8 param[1 ] = {0xFF };
@@ -628,7 +627,6 @@ int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *verkfree_skb (skb);return 0 ; } -EXPORT_SYMBOL_GPL (btintel_read_version_tlv);/* ------- REGMAP IBT SUPPORT ------- */
@@ -1202,7 +1200,7 @@ static int btintel_download_fw_tlv(struct hci_dev *hdev,return 0 ; } -void btintel_reset_to_bootloader (struct hci_dev *hdev) +static void btintel_reset_to_bootloader (struct hci_dev *hdev) {struct intel_reset params;struct sk_buff *skb;
@@ -1245,10 +1243,9 @@ void btintel_reset_to_bootloader(struct hci_dev *hdev)*/ msleep (150 ); } -EXPORT_SYMBOL_GPL (btintel_reset_to_bootloader); -int btintel_read_debug_features (struct hci_dev *hdev, -struct intel_debug_features *features) +static int btintel_read_debug_features (struct hci_dev *hdev, +struct intel_debug_features *features) {struct sk_buff *skb;u8 page_no =1 ;
@@ -1277,9 +1274,8 @@ int btintel_read_debug_features(struct hci_dev *hdev,kfree_skb (skb);return 0 ; } -EXPORT_SYMBOL_GPL (btintel_read_debug_features); -int btintel_set_debug_features (struct hci_dev *hdev, +static int btintel_set_debug_features (struct hci_dev *hdev,const struct intel_debug_features *features) {u8 mask[11 ] = {0x0a ,0x92 ,0x02 ,0x07 ,0x00 ,0x00 ,0x00 ,0x00 ,
@@ -1304,7 +1300,6 @@ int btintel_set_debug_features(struct hci_dev *hdev,kfree_skb (skb);return 0 ; } -EXPORT_SYMBOL_GPL (btintel_set_debug_features);static const struct firmware *btintel_legacy_rom_get_fw (struct hci_dev *hdev,struct intel_version *ver)
drivers/bluetooth/btintel.h +0 -50
89 lines not on this page · raw message
Signature · 1 line
2.26.3