summaryrefslogtreecommitdiff
path: root/patches/collateral-evolutions/network/0053-remove_wait_on_bit_timeout/hci_intel.patch
blob: 54d7bdf0800ce116448767cdf84a0ba1e80d1f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--- a/drivers/bluetooth/hci_intel.c
+++ b/drivers/bluetooth/hci_intel.c
@@ -94,8 +94,9 @@ static u8 intel_convert_speed(unsigned i
 static int intel_wait_booting(struct hci_uart *hu)
 {
 	struct intel_data *intel = hu->priv;
-	int err;
+	int err = 0;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
 	err = wait_on_bit_timeout(&intel->flags, STATE_BOOTING,
 				  TASK_INTERRUPTIBLE,
 				  msecs_to_jiffies(1000));
@@ -109,6 +110,33 @@ static int intel_wait_booting(struct hci
 		BT_ERR("%s: Device boot timeout", hu->hdev->name);
 		return -ETIMEDOUT;
 	}
+#else
+	if (test_bit(STATE_BOOTING, &intel->flags)) {
+		DECLARE_WAITQUEUE(wait, current);
+		signed long timeout;
+
+		add_wait_queue(&hu->hdev->req_wait_q, &wait);
+		set_current_state(TASK_INTERRUPTIBLE);
+
+		/* Booting into operational firmware should not take
+		 * longer than 1 second. However if that happens, then
+		 * just fail the setup since something went wrong.
+		 */
+		timeout = schedule_timeout(msecs_to_jiffies(1000));
+
+		remove_wait_queue(&hu->hdev->req_wait_q, &wait);
+
+		if (signal_pending(current)) {
+			BT_ERR("%s: Device boot interrupted", hu->hdev->name);
+			return -EINTR;
+		}
+
+		if (!timeout) {
+			BT_ERR("%s: Device boot timeout", hu->hdev->name);
+			return -ETIMEDOUT;
+		}
+	}
+#endif
 
 	return err;
 }
@@ -576,6 +604,7 @@ static int intel_setup(struct hci_uart *
 	 * and thus just timeout if that happens and fail the setup
 	 * of this device.
 	 */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
 	err = wait_on_bit_timeout(&intel->flags, STATE_DOWNLOADING,
 				  TASK_INTERRUPTIBLE,
 				  msecs_to_jiffies(5000));
@@ -590,6 +619,33 @@ static int intel_setup(struct hci_uart *
 		err = -ETIMEDOUT;
 		goto done;
 	}
+#else
+	if (test_bit(STATE_DOWNLOADING, &intel->flags)) {
+		DECLARE_WAITQUEUE(wait, current);
+		signed long timeout;
+
+		add_wait_queue(&hdev->req_wait_q, &wait);
+		set_current_state(TASK_INTERRUPTIBLE);
+
+		/* Booting into operational firmware should not take
+		 * longer than 1 second. However if that happens, then
+		 * just fail the setup since something went wrong.
+		 */
+		timeout = schedule_timeout(msecs_to_jiffies(5000));
+
+		remove_wait_queue(&hdev->req_wait_q, &wait);
+
+		if (signal_pending(current)) {
+			BT_ERR("%s: Firmware loading interrupted", hdev->name);
+			return -EINTR;
+		}
+
+		if (!timeout) {
+			BT_ERR("%s: Firmware loading timeout", hdev->name);
+			return -ETIMEDOUT;
+		}
+	}
+#endif
 
 	if (test_bit(STATE_FIRMWARE_FAILED, &intel->flags)) {
 		BT_ERR("%s: Firmware loading failed", hdev->name);
@@ -689,8 +745,12 @@ static int intel_recv_event(struct hci_d
 
 		if (test_and_clear_bit(STATE_DOWNLOADING, &intel->flags) &&
 		    test_bit(STATE_FIRMWARE_LOADED, &intel->flags)) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
 			smp_mb__after_atomic();
 			wake_up_bit(&intel->flags, STATE_DOWNLOADING);
+#else
+			wake_up_interruptible(&hu->hdev->req_wait_q);
+#endif
 		}
 
 	/* When switching to the operational firmware the device
@@ -700,8 +760,12 @@ static int intel_recv_event(struct hci_d
 	} else if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 &&
 		   skb->data[2] == 0x02) {
 		if (test_and_clear_bit(STATE_BOOTING, &intel->flags)) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
 			smp_mb__after_atomic();
 			wake_up_bit(&intel->flags, STATE_BOOTING);
+#else
+			wake_up_interruptible(&hu->hdev->req_wait_q);
+#endif
 		}
 	}
 recv: