Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 64 additions & 13 deletions drivers/bluetooth/btcentauri_t6050.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct cen_bt {
int suspend_error;
u8 native_startup_steps;
bool connection_command_supported, connection_status_pending;
bool dup_filter_fallback;
u16 sync_pending_wire, sync_pending_orig;
struct cen_hrb_conn hrb_conns[CEN_MAX_HRB_CONNS];
};
Expand Down Expand Up @@ -410,9 +411,13 @@ static int cen_aux_drain(struct cen_bt *bt, bool repost)

dma_rmb();
length = get_unaligned_le32(descriptor) >> 8;
if (length > spec->footer)
return -EPROTO;
if (repost) {
if (length > spec->footer) {
bt->hdev->stat.err_rx++;
dev_warn_ratelimited(&bt->pdev->dev,
"Dropping RX descriptor with bad length (ring=%u head=%u tail=%u len=%u)\n",
spec->id, state->head, tail,
length);
} else if (repost) {
if (spec->id == 8)
cen_receive_acl(bt, descriptor + 16,
length);
Expand Down Expand Up @@ -617,6 +622,19 @@ static int cen_transmit(struct cen_bt *bt, struct sk_buff_head *queue, u16 ring,
}
if (ring == 1 && get_unaligned_le16(skb->data) == HCI_OP_RESET)
cen_hrb_clear(bt);
/*
* If the firmware refused to reset its duplicate filter, enable
* scans with Filter_Duplicates = 0 (byte 4 of both commands);
* the host copes with repeated reports.
*/
if (ring == 1 && skb->len >= 5 &&
READ_ONCE(bt->dup_filter_fallback) &&
(get_unaligned_le16(skb->data) ==
HCI_OP_LE_SET_EXT_SCAN_ENABLE ||
get_unaligned_le16(skb->data) ==
HCI_OP_LE_SET_SCAN_ENABLE) &&
descriptor[16 + 3])
descriptor[16 + 4] = 0;
if (ring == 1 && READ_ONCE(bt->connection_command_supported) &&
get_unaligned_le16(skb->data) == HCI_OP_CREATE_CONN) {
u8 *command = descriptor + 16;
Expand Down Expand Up @@ -755,6 +773,14 @@ static bool cen_tx_ready(struct cen_bt *bt, struct sk_buff_head *queue,
return (head + 1) % slots != cen_tail(bt, ring);
}

static void cen_rx_consume(struct cen_bt *bt)
{
bt->rx_head = (bt->rx_head + 1) % CEN_RX_SLOTS;
cen_rx_buffer(bt, bt->rx_post);
bt->rx_post = (bt->rx_post + 1) % CEN_RX_SLOTS;
cen_post(bt, 7, bt->rx_post);
}

static void cen_io_work(struct work_struct *work)
{
struct cen_bt *bt = container_of(work, struct cen_bt, io_work);
Expand Down Expand Up @@ -784,10 +810,14 @@ static void cen_io_work(struct work_struct *work)
descriptor = bt->arena + CEN_LE_RX +
bt->le_rx_head * CEN_LE_STRIDE;
length = get_unaligned_le32(descriptor) >> 8;
if (length > CEN_LE_FOOTER)
goto protocol_error;
if (cen_receive_acl(bt, descriptor + 16, length))
if (length > CEN_LE_FOOTER) {
hdev->stat.err_rx++;
dev_warn_ratelimited(&bt->pdev->dev,
"Dropping RX descriptor with bad length (ring=10 head=%u tail=%u len=%u)\n",
bt->le_rx_head, tail, length);
} else if (cen_receive_acl(bt, descriptor + 16, length)) {
goto protocol_error;
}
bt->le_rx_head = (bt->le_rx_head + 1) % CEN_LE_SLOTS;
cen_le_rx_buffer(bt, bt->le_rx_post);
bt->le_rx_post = (bt->le_rx_post + 1) % CEN_LE_SLOTS;
Expand All @@ -803,8 +833,15 @@ static void cen_io_work(struct work_struct *work)
descriptor = bt->arena + CEN_RX + bt->rx_head * CEN_STRIDE;
length = get_unaligned_le32(descriptor) >> 8;
if (length < HCI_EVENT_HDR_SIZE || length > CEN_FOOTER ||
length != descriptor[17] + HCI_EVENT_HDR_SIZE)
goto protocol_error;
length != descriptor[17] + HCI_EVENT_HDR_SIZE) {
hdev->stat.err_rx++;
dev_warn_ratelimited(&bt->pdev->dev,
"Dropping malformed event (ring=7 head=%u tail=%u len=%u plen=%u)\n",
bt->rx_head, tail, length,
descriptor[17]);
cen_rx_consume(bt);
continue;
}
skb = bt_skb_alloc(length, GFP_KERNEL);
if (skb) {
skb_put_data(skb, descriptor + 16, length);
Expand Down Expand Up @@ -870,10 +907,7 @@ static void cen_io_work(struct work_struct *work)
} else {
hdev->stat.err_rx++;
}
bt->rx_head = (bt->rx_head + 1) % CEN_RX_SLOTS;
cen_rx_buffer(bt, bt->rx_post);
bt->rx_post = (bt->rx_post + 1) % CEN_RX_SLOTS;
cen_post(bt, 7, bt->rx_post);
cen_rx_consume(bt);
}
if (cen_transmit(bt, &bt->txq, 1, CEN_TX_SLOTS, CEN_TX, CEN_FOOTER,
&bt->tx_head))
Expand Down Expand Up @@ -992,15 +1026,32 @@ static int cen_vendor_command(struct hci_dev *hdev, u16 opcode,

static int cen_hci_reset_dup_filter(struct hci_dev *hdev)
{
struct cen_bt *bt = hci_get_drvdata(hdev);
static const u8 flags;
int ret;

if (READ_ONCE(bt->dup_filter_fallback))
return 0;
/*
* A refusal in Command Complete or Command Status reaches us as a
* negative errno from bt_to_errno(), not as a positive status. Only
* the codes of Unknown Command (0x01), Command Disallowed (0x0c),
* Unsupported Feature (0x11) and Invalid Parameters (0x12) select
* host filtering; send, cancel and timeout errors are passed on.
*/
ret = __hci_cmd_sync_status(hdev, CEN_OP_FLUSH_DUPLICATES,
sizeof(flags), &flags, HCI_CMD_TIMEOUT);
if (ret) {
if (ret < 0 && ret != -EBADRQC && ret != -EBUSY &&
ret != -EOPNOTSUPP && ret != -EINVAL) {
bt_dev_warn(hdev, "Duplicate filter reset failed: %d", ret);
return ret;
}
if (ret) {
bt_dev_warn(hdev,
"Duplicate filter reset refused (%d); falling back to host filtering",
ret);
WRITE_ONCE(bt->dup_filter_fallback, true);
}
return 0;
}

Expand Down