Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f246e89 authored by Andrei Emeltchenko's avatar Andrei Emeltchenko Committed by Gustavo Padovan
Browse files

Bluetooth: Update HCI timeouts constants to use msecs_to_jiffies



The HCI constants are always used in form of jiffies. So just
include the conversion from msecs in the define itself. This has the
advantage of making the code where the timeout is used more readable
and avoiding unnecessary conversions.

The patch is similar to commit ba13ccd9 doing the same job for L2CAP

Reported-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
parent 975b91bb
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -139,11 +139,11 @@ enum {
#define HCIINQUIRY	_IOR('H', 240, int)
#define HCIINQUIRY	_IOR('H', 240, int)


/* HCI timeouts */
/* HCI timeouts */
#define HCI_DISCONN_TIMEOUT	(2000)	/* 2 seconds */
#define HCI_DISCONN_TIMEOUT	msecs_to_jiffies(2000)	/* 2 seconds */
#define HCI_PAIRING_TIMEOUT	(60000)	/* 60 seconds */
#define HCI_PAIRING_TIMEOUT	msecs_to_jiffies(60000)	/* 60 seconds */
#define HCI_INIT_TIMEOUT	(10000)	/* 10 seconds */
#define HCI_INIT_TIMEOUT	msecs_to_jiffies(10000)	/* 10 seconds */
#define HCI_CMD_TIMEOUT		(1000)	/* 1 seconds */
#define HCI_CMD_TIMEOUT		msecs_to_jiffies(1000)	/* 1 seconds */
#define HCI_ACL_TX_TIMEOUT	(45000)	/* 45 seconds */
#define HCI_ACL_TX_TIMEOUT	msecs_to_jiffies(45000)	/* 45 seconds */


/* HCI data types */
/* HCI data types */
#define HCI_COMMAND_PKT		0x01
#define HCI_COMMAND_PKT		0x01
+1 −1
Original line number Original line Diff line number Diff line
@@ -598,7 +598,7 @@ static inline void hci_conn_put(struct hci_conn *conn)
		if (conn->type == ACL_LINK || conn->type == LE_LINK) {
		if (conn->type == ACL_LINK || conn->type == LE_LINK) {
			del_timer(&conn->idle_timer);
			del_timer(&conn->idle_timer);
			if (conn->state == BT_CONNECTED) {
			if (conn->state == BT_CONNECTED) {
				timeo = msecs_to_jiffies(conn->disc_timeout);
				timeo = conn->disc_timeout;
				if (!conn->out)
				if (!conn->out)
					timeo *= 2;
					timeo *= 2;
			} else {
			} else {
+11 −14
Original line number Original line Diff line number Diff line
@@ -690,12 +690,11 @@ int hci_dev_open(__u16 dev)
		set_bit(HCI_INIT, &hdev->flags);
		set_bit(HCI_INIT, &hdev->flags);
		hdev->init_last_cmd = 0;
		hdev->init_last_cmd = 0;


		ret = __hci_request(hdev, hci_init_req, 0,
		ret = __hci_request(hdev, hci_init_req, 0, HCI_INIT_TIMEOUT);
				    msecs_to_jiffies(HCI_INIT_TIMEOUT));


		if (lmp_host_le_capable(hdev))
		if (lmp_host_le_capable(hdev))
			ret = __hci_request(hdev, hci_le_init_req, 0,
			ret = __hci_request(hdev, hci_le_init_req, 0,
					    msecs_to_jiffies(HCI_INIT_TIMEOUT));
					    HCI_INIT_TIMEOUT);


		clear_bit(HCI_INIT, &hdev->flags);
		clear_bit(HCI_INIT, &hdev->flags);
	}
	}
@@ -782,8 +781,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
	if (!test_bit(HCI_RAW, &hdev->flags) &&
	if (!test_bit(HCI_RAW, &hdev->flags) &&
	    test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) {
	    test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) {
		set_bit(HCI_INIT, &hdev->flags);
		set_bit(HCI_INIT, &hdev->flags);
		__hci_request(hdev, hci_reset_req, 0,
		__hci_request(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT);
			      msecs_to_jiffies(HCI_CMD_TIMEOUT));
		clear_bit(HCI_INIT, &hdev->flags);
		clear_bit(HCI_INIT, &hdev->flags);
	}
	}


@@ -872,8 +870,7 @@ int hci_dev_reset(__u16 dev)
	hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0;
	hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0;


	if (!test_bit(HCI_RAW, &hdev->flags))
	if (!test_bit(HCI_RAW, &hdev->flags))
		ret = __hci_request(hdev, hci_reset_req, 0,
		ret = __hci_request(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT);
				    msecs_to_jiffies(HCI_INIT_TIMEOUT));


done:
done:
	hci_req_unlock(hdev);
	hci_req_unlock(hdev);
@@ -913,7 +910,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
	switch (cmd) {
	switch (cmd) {
	case HCISETAUTH:
	case HCISETAUTH:
		err = hci_request(hdev, hci_auth_req, dr.dev_opt,
		err = hci_request(hdev, hci_auth_req, dr.dev_opt,
				  msecs_to_jiffies(HCI_INIT_TIMEOUT));
				  HCI_INIT_TIMEOUT);
		break;
		break;


	case HCISETENCRYPT:
	case HCISETENCRYPT:
@@ -925,23 +922,23 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
		if (!test_bit(HCI_AUTH, &hdev->flags)) {
		if (!test_bit(HCI_AUTH, &hdev->flags)) {
			/* Auth must be enabled first */
			/* Auth must be enabled first */
			err = hci_request(hdev, hci_auth_req, dr.dev_opt,
			err = hci_request(hdev, hci_auth_req, dr.dev_opt,
					  msecs_to_jiffies(HCI_INIT_TIMEOUT));
					  HCI_INIT_TIMEOUT);
			if (err)
			if (err)
				break;
				break;
		}
		}


		err = hci_request(hdev, hci_encrypt_req, dr.dev_opt,
		err = hci_request(hdev, hci_encrypt_req, dr.dev_opt,
				  msecs_to_jiffies(HCI_INIT_TIMEOUT));
				  HCI_INIT_TIMEOUT);
		break;
		break;


	case HCISETSCAN:
	case HCISETSCAN:
		err = hci_request(hdev, hci_scan_req, dr.dev_opt,
		err = hci_request(hdev, hci_scan_req, dr.dev_opt,
				  msecs_to_jiffies(HCI_INIT_TIMEOUT));
				  HCI_INIT_TIMEOUT);
		break;
		break;


	case HCISETLINKPOL:
	case HCISETLINKPOL:
		err = hci_request(hdev, hci_linkpol_req, dr.dev_opt,
		err = hci_request(hdev, hci_linkpol_req, dr.dev_opt,
				  msecs_to_jiffies(HCI_INIT_TIMEOUT));
				  HCI_INIT_TIMEOUT);
		break;
		break;


	case HCISETLINKMODE:
	case HCISETLINKMODE:
@@ -2455,7 +2452,7 @@ static void __check_timeout(struct hci_dev *hdev, unsigned int cnt)
		/* ACL tx timeout must be longer than maximum
		/* ACL tx timeout must be longer than maximum
		 * link supervision timeout (40.9 seconds) */
		 * link supervision timeout (40.9 seconds) */
		if (!cnt && time_after(jiffies, hdev->acl_last_tx +
		if (!cnt && time_after(jiffies, hdev->acl_last_tx +
				       msecs_to_jiffies(HCI_ACL_TX_TIMEOUT)))
				       HCI_ACL_TX_TIMEOUT))
			hci_link_tx_to(hdev, ACL_LINK);
			hci_link_tx_to(hdev, ACL_LINK);
	}
	}
}
}
@@ -2839,7 +2836,7 @@ static void hci_cmd_work(struct work_struct *work)
				del_timer(&hdev->cmd_timer);
				del_timer(&hdev->cmd_timer);
			else
			else
				mod_timer(&hdev->cmd_timer,
				mod_timer(&hdev->cmd_timer,
				  jiffies + msecs_to_jiffies(HCI_CMD_TIMEOUT));
					  jiffies + HCI_CMD_TIMEOUT);
		} else {
		} else {
			skb_queue_head(&hdev->cmd_q, skb);
			skb_queue_head(&hdev->cmd_q, skb);
			queue_work(hdev->workqueue, &hdev->cmd_work);
			queue_work(hdev->workqueue, &hdev->cmd_work);