mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
Bluetooth: Convert SCO configure_datapath to hci_sync
Recoding HCI cmds to offload SCO codec to use hci_sync mechanism rather than deprecated hci_request mechanism. Signed-off-by: Brian Gix <brian.gix@intel.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
9e63767dd5
commit
e07a06b4eb
3 changed files with 75 additions and 60 deletions
|
@ -44,6 +44,11 @@ struct sco_param {
|
||||||
u8 retrans_effort;
|
u8 retrans_effort;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct conn_handle_t {
|
||||||
|
struct hci_conn *conn;
|
||||||
|
__u16 handle;
|
||||||
|
};
|
||||||
|
|
||||||
static const struct sco_param esco_param_cvsd[] = {
|
static const struct sco_param esco_param_cvsd[] = {
|
||||||
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x000a, 0x01 }, /* S3 */
|
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x000a, 0x01 }, /* S3 */
|
||||||
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x0007, 0x01 }, /* S2 */
|
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x0007, 0x01 }, /* S2 */
|
||||||
|
@ -316,17 +321,60 @@ static bool find_next_esco_param(struct hci_conn *conn,
|
||||||
return conn->attempt <= size;
|
return conn->attempt <= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
static int configure_datapath_sync(struct hci_dev *hdev, struct bt_codec *codec)
|
||||||
{
|
{
|
||||||
struct hci_dev *hdev = conn->hdev;
|
int err;
|
||||||
|
__u8 vnd_len, *vnd_data = NULL;
|
||||||
|
struct hci_op_configure_data_path *cmd = NULL;
|
||||||
|
|
||||||
|
err = hdev->get_codec_config_data(hdev, ESCO_LINK, codec, &vnd_len,
|
||||||
|
&vnd_data);
|
||||||
|
if (err < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
cmd = kzalloc(sizeof(*cmd) + vnd_len, GFP_KERNEL);
|
||||||
|
if (!cmd) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hdev->get_data_path_id(hdev, &cmd->data_path_id);
|
||||||
|
if (err < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
cmd->vnd_len = vnd_len;
|
||||||
|
memcpy(cmd->vnd_data, vnd_data, vnd_len);
|
||||||
|
|
||||||
|
cmd->direction = 0x00;
|
||||||
|
__hci_cmd_sync_status(hdev, HCI_CONFIGURE_DATA_PATH,
|
||||||
|
sizeof(*cmd) + vnd_len, cmd, HCI_CMD_TIMEOUT);
|
||||||
|
|
||||||
|
cmd->direction = 0x01;
|
||||||
|
err = __hci_cmd_sync_status(hdev, HCI_CONFIGURE_DATA_PATH,
|
||||||
|
sizeof(*cmd) + vnd_len, cmd,
|
||||||
|
HCI_CMD_TIMEOUT);
|
||||||
|
error:
|
||||||
|
|
||||||
|
kfree(cmd);
|
||||||
|
kfree(vnd_data);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
|
||||||
|
{
|
||||||
|
struct conn_handle_t *conn_handle = data;
|
||||||
|
struct hci_conn *conn = conn_handle->conn;
|
||||||
|
__u16 handle = conn_handle->handle;
|
||||||
struct hci_cp_enhanced_setup_sync_conn cp;
|
struct hci_cp_enhanced_setup_sync_conn cp;
|
||||||
const struct sco_param *param;
|
const struct sco_param *param;
|
||||||
|
|
||||||
|
kfree(conn_handle);
|
||||||
|
|
||||||
bt_dev_dbg(hdev, "hcon %p", conn);
|
bt_dev_dbg(hdev, "hcon %p", conn);
|
||||||
|
|
||||||
/* for offload use case, codec needs to configured before opening SCO */
|
/* for offload use case, codec needs to configured before opening SCO */
|
||||||
if (conn->codec.data_path)
|
if (conn->codec.data_path)
|
||||||
hci_req_configure_datapath(hdev, &conn->codec);
|
configure_datapath_sync(hdev, &conn->codec);
|
||||||
|
|
||||||
conn->state = BT_CONNECT;
|
conn->state = BT_CONNECT;
|
||||||
conn->out = true;
|
conn->out = true;
|
||||||
|
@ -344,7 +392,7 @@ static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
case BT_CODEC_MSBC:
|
case BT_CODEC_MSBC:
|
||||||
if (!find_next_esco_param(conn, esco_param_msbc,
|
if (!find_next_esco_param(conn, esco_param_msbc,
|
||||||
ARRAY_SIZE(esco_param_msbc)))
|
ARRAY_SIZE(esco_param_msbc)))
|
||||||
return false;
|
return -EINVAL;
|
||||||
|
|
||||||
param = &esco_param_msbc[conn->attempt - 1];
|
param = &esco_param_msbc[conn->attempt - 1];
|
||||||
cp.tx_coding_format.id = 0x05;
|
cp.tx_coding_format.id = 0x05;
|
||||||
|
@ -396,11 +444,11 @@ static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
if (lmp_esco_capable(conn->link)) {
|
if (lmp_esco_capable(conn->link)) {
|
||||||
if (!find_next_esco_param(conn, esco_param_cvsd,
|
if (!find_next_esco_param(conn, esco_param_cvsd,
|
||||||
ARRAY_SIZE(esco_param_cvsd)))
|
ARRAY_SIZE(esco_param_cvsd)))
|
||||||
return false;
|
return -EINVAL;
|
||||||
param = &esco_param_cvsd[conn->attempt - 1];
|
param = &esco_param_cvsd[conn->attempt - 1];
|
||||||
} else {
|
} else {
|
||||||
if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
|
if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
|
||||||
return false;
|
return -EINVAL;
|
||||||
param = &sco_param_cvsd[conn->attempt - 1];
|
param = &sco_param_cvsd[conn->attempt - 1];
|
||||||
}
|
}
|
||||||
cp.tx_coding_format.id = 2;
|
cp.tx_coding_format.id = 2;
|
||||||
|
@ -423,7 +471,7 @@ static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
cp.out_transport_unit_size = 16;
|
cp.out_transport_unit_size = 16;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cp.retrans_effort = param->retrans_effort;
|
cp.retrans_effort = param->retrans_effort;
|
||||||
|
@ -431,9 +479,9 @@ static bool hci_enhanced_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
cp.max_latency = __cpu_to_le16(param->max_latency);
|
cp.max_latency = __cpu_to_le16(param->max_latency);
|
||||||
|
|
||||||
if (hci_send_cmd(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN, sizeof(cp), &cp) < 0)
|
if (hci_send_cmd(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN, sizeof(cp), &cp) < 0)
|
||||||
return false;
|
return -EIO;
|
||||||
|
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
|
@ -490,8 +538,24 @@ static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
||||||
|
|
||||||
bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
|
bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
|
||||||
{
|
{
|
||||||
if (enhanced_sync_conn_capable(conn->hdev))
|
int result;
|
||||||
return hci_enhanced_setup_sync_conn(conn, handle);
|
struct conn_handle_t *conn_handle;
|
||||||
|
|
||||||
|
if (enhanced_sync_conn_capable(conn->hdev)) {
|
||||||
|
conn_handle = kzalloc(sizeof(*conn_handle), GFP_KERNEL);
|
||||||
|
|
||||||
|
if (!conn_handle)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
conn_handle->conn = conn;
|
||||||
|
conn_handle->handle = handle;
|
||||||
|
result = hci_cmd_sync_queue(conn->hdev, hci_enhanced_setup_sync,
|
||||||
|
conn_handle, NULL);
|
||||||
|
if (result < 0)
|
||||||
|
kfree(conn_handle);
|
||||||
|
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
|
||||||
return hci_setup_sync_conn(conn, handle);
|
return hci_setup_sync_conn(conn, handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1975,53 +1975,6 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void config_data_path_complete(struct hci_dev *hdev, u8 status,
|
|
||||||
u16 opcode)
|
|
||||||
{
|
|
||||||
bt_dev_dbg(hdev, "status %u", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec)
|
|
||||||
{
|
|
||||||
struct hci_request req;
|
|
||||||
int err;
|
|
||||||
__u8 vnd_len, *vnd_data = NULL;
|
|
||||||
struct hci_op_configure_data_path *cmd = NULL;
|
|
||||||
|
|
||||||
hci_req_init(&req, hdev);
|
|
||||||
|
|
||||||
err = hdev->get_codec_config_data(hdev, ESCO_LINK, codec, &vnd_len,
|
|
||||||
&vnd_data);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
cmd = kzalloc(sizeof(*cmd) + vnd_len, GFP_KERNEL);
|
|
||||||
if (!cmd) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = hdev->get_data_path_id(hdev, &cmd->data_path_id);
|
|
||||||
if (err < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
cmd->vnd_len = vnd_len;
|
|
||||||
memcpy(cmd->vnd_data, vnd_data, vnd_len);
|
|
||||||
|
|
||||||
cmd->direction = 0x00;
|
|
||||||
hci_req_add(&req, HCI_CONFIGURE_DATA_PATH, sizeof(*cmd) + vnd_len, cmd);
|
|
||||||
|
|
||||||
cmd->direction = 0x01;
|
|
||||||
hci_req_add(&req, HCI_CONFIGURE_DATA_PATH, sizeof(*cmd) + vnd_len, cmd);
|
|
||||||
|
|
||||||
err = hci_req_run(&req, config_data_path_complete);
|
|
||||||
error:
|
|
||||||
|
|
||||||
kfree(cmd);
|
|
||||||
kfree(vnd_data);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hci_request_setup(struct hci_dev *hdev)
|
void hci_request_setup(struct hci_dev *hdev)
|
||||||
{
|
{
|
||||||
INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire);
|
INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire);
|
||||||
|
|
|
@ -113,8 +113,6 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
|
||||||
void __hci_req_update_class(struct hci_request *req);
|
void __hci_req_update_class(struct hci_request *req);
|
||||||
|
|
||||||
/* Returns true if HCI commands were queued */
|
/* Returns true if HCI commands were queued */
|
||||||
int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec);
|
|
||||||
|
|
||||||
void __hci_req_update_scan(struct hci_request *req);
|
void __hci_req_update_scan(struct hci_request *req);
|
||||||
|
|
||||||
int hci_update_random_address(struct hci_request *req, bool require_privacy,
|
int hci_update_random_address(struct hci_request *req, bool require_privacy,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue