View | Details | Raw Unified | Return to bug 10721
Collapse All | Expand All

(-)a/include/net/bluetooth/hci.h (+7 lines)
Lines 767-772 struct hci_dev_stats { Link Here
767
	__u32 byte_tx;
767
	__u32 byte_tx;
768
};
768
};
769
769
770
/* Fields down there are mostly the same as hci_dev,
771
   as this structure is meant to communicate info
772
   to userspace */
770
struct hci_dev_info {
773
struct hci_dev_info {
771
	__u16 dev_id;
774
	__u16 dev_id;
772
	char  name[8];
775
	char  name[8];
Lines 782-790 struct hci_dev_info { Link Here
782
	__u32 link_policy;
785
	__u32 link_policy;
783
	__u32 link_mode;
786
	__u32 link_mode;
784
787
788
	/* Maximum transmition unit for ACL packets */
785
	__u16 acl_mtu;
789
	__u16 acl_mtu;
790
	/* Number of ACL packets the baseband is able to buffer */
786
	__u16 acl_pkts;
791
	__u16 acl_pkts;
792
	/* Maximum transmition unit for SCO packets */
787
	__u16 sco_mtu;
793
	__u16 sco_mtu;
794
	/* Number of SCO packets the baseband is able to buffer */
788
	__u16 sco_pkts;
795
	__u16 sco_pkts;
789
796
790
	struct hci_dev_stats stat;
797
	struct hci_dev_stats stat;
(-)a/include/net/bluetooth/hci_core.h (-6 / +22 lines)
Lines 25-30 Link Here
25
#ifndef __HCI_CORE_H
25
#ifndef __HCI_CORE_H
26
#define __HCI_CORE_H
26
#define __HCI_CORE_H
27
27
28
#include <linux/hrtimer.h>
29
28
#include <net/bluetooth/hci.h>
30
#include <net/bluetooth/hci.h>
29
31
30
/* HCI upper protocols */
32
/* HCI upper protocols */
Lines 88-99 struct hci_dev { Link Here
88
	unsigned long	quirks;
90
	unsigned long	quirks;
89
91
90
	atomic_t	cmd_cnt;
92
	atomic_t	cmd_cnt;
93
	/* Number of available controller buffers for ACL packets */
91
	unsigned int	acl_cnt;
94
	unsigned int	acl_cnt;
92
	unsigned int	sco_cnt;
95
	/* Number of available controller buffers for SCO packets */
96
	atomic_t	sco_cnt;
93
97
98
	/* Maximum transmition unit for ACL packets */
94
	unsigned int	acl_mtu;
99
	unsigned int	acl_mtu;
100
	/* Maximum transmition unit for SCO packets */
95
	unsigned int	sco_mtu;
101
	unsigned int	sco_mtu;
102
	/* Maximum number of ACL packets the controller is able to buffer */
96
	unsigned int	acl_pkts;
103
	unsigned int	acl_pkts;
104
	/* Maximum number of SCO packets the controller is able to buffer */
97
	unsigned int	sco_pkts;
105
	unsigned int	sco_pkts;
98
106
99
	unsigned long	cmd_last_tx;
107
	unsigned long	cmd_last_tx;
Lines 145-156 struct hci_conn { Link Here
145
	struct list_head list;
153
	struct list_head list;
146
154
147
	atomic_t	 refcnt;
155
	atomic_t	 refcnt;
148
	spinlock_t	 lock;
149
156
150
	bdaddr_t	 dst;
157
	bdaddr_t	 dst;
151
	__u16		 handle;
158
	__u16		 handle;
152
	__u16		 state;
159
	__u16		 state;
153
	__u8             mode;
160
	__u8             mode;
161
  	/* type : ACL or SCO */
154
	__u8		 type;
162
	__u8		 type;
155
	__u8		 out;
163
	__u8		 out;
156
	__u8		 attempt;
164
	__u8		 attempt;
Lines 162-171 struct hci_conn { Link Here
162
	__u8             power_save;
170
	__u8             power_save;
163
	unsigned long	 pend;
171
	unsigned long	 pend;
164
172
165
	unsigned int	 sent;
173
	/* sent represents the number of packets this connections
166
174
             has "on the wire" : .... oh f.... there are no wire
167
	struct sk_buff_head data_q;
175
             with bluetooth. By on the wire, i mean packets that have been sent
168
176
	   to the HCI device, and that are still in its buffers */
177
	atomic_t	 sent;
178
 
179
	struct sk_buff_head out_q;
180
 
181
	/* tx timer : used only for SCO */
182
	struct hrtimer tx_timer;
183
	/* Disconnect timer */
169
	struct timer_list disc_timer;
184
	struct timer_list disc_timer;
170
	struct timer_list idle_timer;
185
	struct timer_list idle_timer;
171
186
Lines 175-180 struct hci_conn { Link Here
175
190
176
	struct hci_dev	*hdev;
191
	struct hci_dev	*hdev;
177
	void		*l2cap_data;
192
	void		*l2cap_data;
193
 	/* private use for sco */
178
	void		*sco_data;
194
	void		*sco_data;
179
	void		*priv;
195
	void		*priv;
180
196
(-)a/net/bluetooth/hci_conn.c (-3 / +8 lines)
Lines 184-190 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) Link Here
184
184
185
	conn->power_save = 1;
185
	conn->power_save = 1;
186
186
187
	skb_queue_head_init(&conn->data_q);
187
	skb_queue_head_init(&conn->out_q);
188
189
	hrtimer_init(&conn->tx_timer, CLOCK_MONOTONIC, HRTIMER_NORESTART);
188
190
189
	init_timer(&conn->disc_timer);
191
	init_timer(&conn->disc_timer);
190
	conn->disc_timer.function = hci_conn_timeout;
192
	conn->disc_timer.function = hci_conn_timeout;
Lines 195-200 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) Link Here
195
	conn->idle_timer.data = (unsigned long) conn;
197
	conn->idle_timer.data = (unsigned long) conn;
196
198
197
	atomic_set(&conn->refcnt, 0);
199
	atomic_set(&conn->refcnt, 0);
200
	atomic_set(&conn->sent, 0);
198
201
199
	hci_dev_hold(hdev);
202
	hci_dev_hold(hdev);
200
203
Lines 221-226 int hci_conn_del(struct hci_conn *conn) Link Here
221
224
222
	del_timer(&conn->disc_timer);
225
	del_timer(&conn->disc_timer);
223
226
227
	hrtimer_cancel(&conn->tx_timer);
228
224
	if (conn->type == SCO_LINK) {
229
	if (conn->type == SCO_LINK) {
225
		struct hci_conn *acl = conn->link;
230
		struct hci_conn *acl = conn->link;
226
		if (acl) {
231
		if (acl) {
Lines 233-239 int hci_conn_del(struct hci_conn *conn) Link Here
233
			sco->link = NULL;
238
			sco->link = NULL;
234
239
235
		/* Unacked frames */
240
		/* Unacked frames */
236
		hdev->acl_cnt += conn->sent;
241
		hdev->acl_cnt += atomic_read(&conn->sent);
237
	}
242
	}
238
243
239
	tasklet_disable(&hdev->tx_task);
244
	tasklet_disable(&hdev->tx_task);
Lines 246-252 int hci_conn_del(struct hci_conn *conn) Link Here
246
251
247
	tasklet_enable(&hdev->tx_task);
252
	tasklet_enable(&hdev->tx_task);
248
253
249
	skb_queue_purge(&conn->data_q);
254
	skb_queue_purge(&conn->out_q);
250
255
251
	hci_dev_put(hdev);
256
	hci_dev_put(hdev);
252
257
(-)a/net/bluetooth/hci_core.c (-40 / +105 lines)
Lines 619-626 int hci_dev_reset(__u16 dev) Link Here
619
	if (hdev->flush)
619
	if (hdev->flush)
620
		hdev->flush(hdev);
620
		hdev->flush(hdev);
621
621
622
	atomic_set(&hdev->cmd_cnt, 1); 
622
	atomic_set(&hdev->cmd_cnt, 1);
623
	hdev->acl_cnt = 0; hdev->sco_cnt = 0;
623
	atomic_set(&hdev->sco_cnt, 0); 
624
	hdev->acl_cnt = 0; 
624
625
625
	if (!test_bit(HCI_RAW, &hdev->flags))
626
	if (!test_bit(HCI_RAW, &hdev->flags))
626
		ret = __hci_request(hdev, hci_reset_req, 0,
627
		ret = __hci_request(hdev, hci_reset_req, 0,
Lines 1012-1018 static int hci_send_frame(struct sk_buff *skb) Link Here
1012
		hci_send_to_sock(hdev, skb);
1013
		hci_send_to_sock(hdev, skb);
1013
	}
1014
	}
1014
1015
1015
	/* Get rid of skb owner, prior to sending to the driver. */
1016
       /* Get rid of skb owner, prior to sending to the driver. */
1016
	skb_orphan(skb);
1017
	skb_orphan(skb);
1017
1018
1018
	return hdev->send(skb);
1019
	return hdev->send(skb);
Lines 1096-1102 int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags) Link Here
1096
		/* Non fragmented */
1097
		/* Non fragmented */
1097
		BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
1098
		BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
1098
1099
1099
		skb_queue_tail(&conn->data_q, skb);
1100
		skb_queue_tail(&conn->out_q, skb);
1100
	} else {
1101
	} else {
1101
		/* Fragmented */
1102
		/* Fragmented */
1102
		BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1103
		BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
Lines 1104-1112 int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags) Link Here
1104
		skb_shinfo(skb)->frag_list = NULL;
1105
		skb_shinfo(skb)->frag_list = NULL;
1105
1106
1106
		/* Queue all fragments atomically */
1107
		/* Queue all fragments atomically */
1107
		spin_lock_bh(&conn->data_q.lock);
1108
		spin_lock_bh(&conn->out_q.lock);
1108
1109
1109
		__skb_queue_tail(&conn->data_q, skb);
1110
		__skb_queue_tail(&conn->out_q, skb);
1110
		do {
1111
		do {
1111
			skb = list; list = list->next;
1112
			skb = list; list = list->next;
1112
			
1113
			
Lines 1116-1125 int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags) Link Here
1116
1117
1117
			BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1118
			BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1118
1119
1119
			__skb_queue_tail(&conn->data_q, skb);
1120
			__skb_queue_tail(&conn->out_q, skb);
1120
		} while (list);
1121
		} while (list);
1121
1122
1122
		spin_unlock_bh(&conn->data_q.lock);
1123
		spin_unlock_bh(&conn->out_q.lock);
1123
	}
1124
	}
1124
1125
1125
	hci_sched_tx(hdev);
1126
	hci_sched_tx(hdev);
Lines 1132-1145 int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb) Link Here
1132
{
1133
{
1133
	struct hci_dev *hdev = conn->hdev;
1134
	struct hci_dev *hdev = conn->hdev;
1134
	struct hci_sco_hdr hdr;
1135
	struct hci_sco_hdr hdr;
1135
1136
	ktime_t now = conn->tx_timer.base->get_time();
1136
	BT_DBG("%s len %d", hdev->name, skb->len);
1137
#ifdef CONFIG_BT_HCI_CORE_DEBUG
1138
	ktime_t timer_exp = conn->tx_timer.expires;
1139
	BT_DBG("conn %p skb %p, timer %5lu.%06lu", conn, skb,
1140
		(unsigned long) timer_exp.tv64, 
1141
		do_div(timer_exp.tv64, NSEC_PER_SEC) / 1000);
1142
#endif
1137
1143
1138
	if (skb->len > hdev->sco_mtu) {
1144
	if (skb->len > hdev->sco_mtu) {
1139
		kfree_skb(skb);
1145
		kfree_skb(skb);
1140
		return -EINVAL;
1146
		return -EINVAL;
1141
	}
1147
	}
1142
1148
1149
	/* Criteria for underrun condition : more than 100 ms late */
1150
	if(conn->tx_timer.expires.tv64 + NSEC_PER_SEC / 10 <= now.tv64) {
1151
		/* We are under underrun condition, just we do a clean start */
1152
		conn->tx_timer.expires = now;
1153
	}
1154
1143
	hdr.handle = __cpu_to_le16(conn->handle);
1155
	hdr.handle = __cpu_to_le16(conn->handle);
1144
	hdr.dlen   = skb->len;
1156
	hdr.dlen   = skb->len;
1145
1157
Lines 1148-1154 int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb) Link Here
1148
1160
1149
	skb->dev = (void *) hdev;
1161
	skb->dev = (void *) hdev;
1150
	bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
1162
	bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
1151
	skb_queue_tail(&conn->data_q, skb);
1163
	skb_queue_tail(&conn->out_q, skb);
1152
	hci_sched_tx(hdev);
1164
	hci_sched_tx(hdev);
1153
	return 0;
1165
	return 0;
1154
}
1166
}
Lines 1156-1167 EXPORT_SYMBOL(hci_send_sco); Link Here
1156
1168
1157
/* ---- HCI TX task (outgoing data) ---- */
1169
/* ---- HCI TX task (outgoing data) ---- */
1158
1170
1159
/* HCI Connection scheduler */
1171
/* HCI ACL Connection scheduler */
1160
static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote)
1172
static inline struct hci_conn *hci_low_sent_acl(struct hci_dev *hdev, int *quote)
1161
{
1173
{
1162
	struct hci_conn_hash *h = &hdev->conn_hash;
1174
	struct hci_conn_hash *h = &hdev->conn_hash;
1163
	struct hci_conn  *conn = NULL;
1175
	struct hci_conn  *conn = NULL;
1164
	int num = 0, min = ~0;
1176
	unsigned int num = 0, min = ~0;
1165
	struct list_head *p;
1177
	struct list_head *p;
1166
1178
1167
	/* We don't have to lock device here. Connections are always 
1179
	/* We don't have to lock device here. Connections are always 
Lines 1170-1189 static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int Link Here
1170
		struct hci_conn *c;
1182
		struct hci_conn *c;
1171
		c = list_entry(p, struct hci_conn, list);
1183
		c = list_entry(p, struct hci_conn, list);
1172
1184
1173
		if (c->type != type || c->state != BT_CONNECTED
1185
		BT_DBG("c->type %d c->state %d len(c->out_q) %d min %d c->sent %d", 
1174
				|| skb_queue_empty(&c->data_q))
1186
			c->type, c->state, skb_queue_len(&c->out_q), min, atomic_read(&c->sent));
1187
1188
		if (c->type != ACL_LINK || c->state != BT_CONNECTED
1189
				|| skb_queue_empty(&c->out_q))
1175
			continue;
1190
			continue;
1176
		num++;
1191
		num++;
1177
1192
1178
		if (c->sent < min) {
1193
		if (atomic_read(&c->sent) < min) {
1179
			min  = c->sent;
1194
			min  = atomic_read(&c->sent);
1180
			conn = c;
1195
			conn = c;
1181
		}
1196
		}
1182
	}
1197
	}
1183
1198
1184
	if (conn) {
1199
	if (conn) {
1185
		int cnt = (type == ACL_LINK ? hdev->acl_cnt : hdev->sco_cnt);
1200
		int q = hdev->acl_cnt / num;
1186
		int q = cnt / num;
1187
		*quote = q ? q : 1;
1201
		*quote = q ? q : 1;
1188
	} else
1202
	} else
1189
		*quote = 0;
1203
		*quote = 0;
Lines 1203-1209 static inline void hci_acl_tx_to(struct hci_dev *hdev) Link Here
1203
	/* Kill stalled connections */
1217
	/* Kill stalled connections */
1204
	list_for_each(p, &h->list) {
1218
	list_for_each(p, &h->list) {
1205
		c = list_entry(p, struct hci_conn, list);
1219
		c = list_entry(p, struct hci_conn, list);
1206
		if (c->type == ACL_LINK && c->sent) {
1220
		if (c->type == ACL_LINK && atomic_read(&c->sent)) {
1207
			BT_ERR("%s killing stalled ACL connection %s",
1221
			BT_ERR("%s killing stalled ACL connection %s",
1208
				hdev->name, batostr(&c->dst));
1222
				hdev->name, batostr(&c->dst));
1209
			hci_acl_disconn(c, 0x13);
1223
			hci_acl_disconn(c, 0x13);
Lines 1226-1233 static inline void hci_sched_acl(struct hci_dev *hdev) Link Here
1226
			hci_acl_tx_to(hdev);
1240
			hci_acl_tx_to(hdev);
1227
	}
1241
	}
1228
1242
1229
	while (hdev->acl_cnt && (conn = hci_low_sent(hdev, ACL_LINK, &quote))) {
1243
	while (hdev->acl_cnt && (conn = hci_low_sent_acl(hdev, &quote))) {
1230
		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
1244
		while (quote-- && (skb = skb_dequeue(&conn->out_q))) {
1231
			BT_DBG("skb %p len %d", skb, skb->len);
1245
			BT_DBG("skb %p len %d", skb, skb->len);
1232
1246
1233
			hci_conn_enter_active_mode(conn);
1247
			hci_conn_enter_active_mode(conn);
Lines 1236-1263 static inline void hci_sched_acl(struct hci_dev *hdev) Link Here
1236
			hdev->acl_last_tx = jiffies;
1250
			hdev->acl_last_tx = jiffies;
1237
1251
1238
			hdev->acl_cnt--;
1252
			hdev->acl_cnt--;
1239
			conn->sent++;
1253
			atomic_inc(&conn->sent);
1240
		}
1254
		}
1241
	}
1255
	}
1242
}
1256
}
1243
1257
1244
/* Schedule SCO */
1258
/* HCI SCO tx timer */
1245
static inline void hci_sched_sco(struct hci_dev *hdev)
1259
1260
static int hci_sco_tx_timer(struct hrtimer *timer)
1246
{
1261
{
1247
	struct hci_conn *conn;
1262
	struct hci_conn *conn = container_of(timer, struct hci_conn, tx_timer);
1248
	struct sk_buff *skb;
1263
#ifdef CONFIG_BT_HCI_CORE_DEBUG
1249
	int quote;
1264
	ktime_t now = timer->base->get_time();
1250
1265
1251
	BT_DBG("%s", hdev->name);
1266
	BT_DBG("%s, conn %p, time %5lu.%06lu", conn->hdev->name, conn,
1267
		(unsigned long) now.tv64, 
1268
		do_div(now.tv64, NSEC_PER_SEC) / 1000);
1269
#endif
1252
1270
1253
	while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) {
1271
	if(atomic_read(&conn->sent) > 0) {
1254
		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
1272
		atomic_dec(&conn->sent);
1255
			BT_DBG("skb %p len %d", skb, skb->len);
1273
		atomic_inc(&conn->hdev->sco_cnt);
1256
			hci_send_frame(skb);
1274
		hci_sched_tx(conn->hdev);
1275
	}
1276
	return HRTIMER_NORESTART;
1277
}
1278
 
1279
/* HCI SCO Connection scheduler */
1257
1280
1258
			conn->sent++;
1281
static inline void hci_sched_sco(struct hci_dev *hdev)
1259
			if (conn->sent == ~0)
1282
{
1260
				conn->sent = 0;
1283
	struct hci_conn_hash *h = &hdev->conn_hash;
1284
	struct sk_buff *skb;
1285
	struct list_head *p;
1286
	struct hci_conn *c;
1287
	
1288
	BT_DBG("%s", hdev->name);
1289
  
1290
	/* We don't have to lock device here. Connections are always 
1291
	 * added and removed with TX task disabled. */
1292
	list_for_each(p, &h->list) {
1293
		c = list_entry(p, struct hci_conn, list);
1294
  
1295
		/* SCO scheduling algorithm makes sure there is never more than
1296
		   1 outstanding packet for each connection */
1297
		if (c->type == SCO_LINK && atomic_read(&c->sent) < 1  && c->state == BT_CONNECTED)
1298
		{
1299
			if(atomic_read(&hdev->sco_cnt) > 0) {
1300
				if((skb = skb_dequeue(&c->out_q)) != NULL) {
1301
					ktime_t now, pkt_time;
1302
1303
					hci_send_frame(skb);
1304
 
1305
					atomic_inc(&c->sent);			
1306
					atomic_dec(&hdev->sco_cnt);
1307
1308
					c->tx_timer.function = hci_sco_tx_timer;
1309
					
1310
					pkt_time =
1311
						ktime_set(0, NSEC_PER_SEC / 16000 * (skb->len - HCI_SCO_HDR_SIZE));
1312
					now = c->tx_timer.base->get_time();
1313
1314
					c->tx_timer.expires.tv64 += pkt_time.tv64;
1315
					if(c->tx_timer.expires.tv64 > now.tv64) {
1316
						hrtimer_restart(&c->tx_timer);
1317
					}
1318
					else {
1319
						/* Timer is to expire in the past - this can happen if timer base
1320
						 precision is less than pkt_time. In this case we force timer
1321
						 expiration by calling its expires function */
1322
						c->tx_timer.function(&c->tx_timer);
1323
					}
1324
				}
1325
			}
1261
		}
1326
		}
1262
	}
1327
	}
1263
}
1328
}
Lines 1269-1282 static void hci_tx_task(unsigned long arg) Link Here
1269
1334
1270
	read_lock(&hci_task_lock);
1335
	read_lock(&hci_task_lock);
1271
1336
1272
	BT_DBG("%s acl %d sco %d", hdev->name, hdev->acl_cnt, hdev->sco_cnt);
1337
	BT_DBG("%s acl %d sco %d", hdev->name, hdev->acl_cnt, atomic_read(&hdev->sco_cnt));
1273
1338
1274
	/* Schedule queues and send stuff to HCI driver */
1339
	/* Schedule queues and send stuff to HCI driver */
1275
1340
1276
	hci_sched_acl(hdev);
1277
1278
	hci_sched_sco(hdev);
1341
	hci_sched_sco(hdev);
1279
1342
1343
	hci_sched_acl(hdev);
1344
1280
	/* Send next queued raw (unknown type) packet */
1345
	/* Send next queued raw (unknown type) packet */
1281
	while ((skb = skb_dequeue(&hdev->raw_q)))
1346
	while ((skb = skb_dequeue(&hdev->raw_q)))
1282
		hci_send_frame(skb);
1347
		hci_send_frame(skb);
(-)a/net/bluetooth/hci_event.c (-7 / +7 lines)
Lines 320-326 static void hci_cc_info_param(struct hci_dev *hdev, __u16 ocf, struct sk_buff *s Link Here
320
		lv = (struct hci_rp_read_loc_version *) skb->data;
320
		lv = (struct hci_rp_read_loc_version *) skb->data;
321
321
322
		if (lv->status) {
322
		if (lv->status) {
323
			BT_DBG("%s READ_LOCAL_VERSION failed %d", hdev->name, lf->status);
323
			BT_DBG("%s READ_LOCAL_VERSION failed %d", hdev->name, lv->status);
324
			break;
324
			break;
325
		}
325
		}
326
326
Lines 382-388 static void hci_cc_info_param(struct hci_dev *hdev, __u16 ocf, struct sk_buff *s Link Here
382
		}
382
		}
383
383
384
		hdev->acl_cnt = hdev->acl_pkts;
384
		hdev->acl_cnt = hdev->acl_pkts;
385
		hdev->sco_cnt = hdev->sco_pkts;
385
		atomic_set(&hdev->sco_cnt, hdev->sco_pkts);
386
386
387
		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
387
		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
388
			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
388
			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
Lines 880-894 static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s Link Here
880
880
881
		conn = hci_conn_hash_lookup_handle(hdev, handle);
881
		conn = hci_conn_hash_lookup_handle(hdev, handle);
882
		if (conn) {
882
		if (conn) {
883
			conn->sent -= count;
883
			atomic_sub(count, &conn->sent);
884
884
885
			if (conn->type == SCO_LINK) {
885
			if (conn->type == ACL_LINK) {
886
				if ((hdev->sco_cnt += count) > hdev->sco_pkts)
887
					hdev->sco_cnt = hdev->sco_pkts;
888
			} else {
889
				if ((hdev->acl_cnt += count) > hdev->acl_pkts)
886
				if ((hdev->acl_cnt += count) > hdev->acl_pkts)
890
					hdev->acl_cnt = hdev->acl_pkts;
887
					hdev->acl_cnt = hdev->acl_pkts;
891
			}
888
			}
889
			/* Note : we do not use the "number of completed packets" event
890
			to increment hdev->sco_cnt, as this feature is only optionnally support
891
			by bluetooth controllers. So there is no if branch for SCO_LINK packets */
892
		}
892
		}
893
	}
893
	}
894
	hci_sched_tx(hdev);
894
	hci_sched_tx(hdev);
(-)a/include/net/bluetooth/sco.h (-5 / +3 lines)
Lines 26-37 Link Here
26
#define __SCO_H
26
#define __SCO_H
27
27
28
/* SCO defaults */
28
/* SCO defaults */
29
#define SCO_DEFAULT_MTU		500
30
#define SCO_DEFAULT_FLUSH_TO	0xFFFF
31
32
#define SCO_CONN_TIMEOUT	(HZ * 40)
29
#define SCO_CONN_TIMEOUT	(HZ * 40)
33
#define SCO_DISCONN_TIMEOUT	(HZ * 2)
34
#define SCO_CONN_IDLE_TIMEOUT	(HZ * 60)
35
30
36
/* SCO socket address */
31
/* SCO socket address */
37
struct sockaddr_sco {
32
struct sockaddr_sco {
Lines 51-56 struct sco_conninfo { Link Here
51
	__u8  dev_class[3];
46
	__u8  dev_class[3];
52
};
47
};
53
48
49
#define SCO_TXBUFS	0x03
50
#define SCO_RXBUFS	0x04
51
54
/* ---- SCO connections ---- */
52
/* ---- SCO connections ---- */
55
struct sco_conn {
53
struct sco_conn {
56
	struct hci_conn	*hcon;
54
	struct hci_conn	*hcon;
(-)a/net/bluetooth/sco.c (-16 / +144 lines)
Lines 53-59 Link Here
53
#define BT_DBG(D...)
53
#define BT_DBG(D...)
54
#endif
54
#endif
55
55
56
#define VERSION "0.5"
56
#define VERSION "0.6"
57
58
#define MAX_SCO_TXBUFS 200
59
#define MAX_SCO_RXBUFS 200
60
61
#define DEFAULT_SCO_TXBUFS 5
62
#define DEFAULT_SCO_RXBUFS 5
57
63
58
static const struct proto_ops sco_sock_ops;
64
static const struct proto_ops sco_sock_ops;
59
65
Lines 61-66 static struct bt_sock_list sco_sk_list = { Link Here
61
	.lock = RW_LOCK_UNLOCKED
67
	.lock = RW_LOCK_UNLOCKED
62
};
68
};
63
69
70
/* Local functions declaration */
71
64
static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent);
72
static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent);
65
static void sco_chan_del(struct sock *sk, int err);
73
static void sco_chan_del(struct sock *sk, int err);
66
74
Lines 69-74 static int sco_conn_del(struct hci_conn *conn, int err); Link Here
69
static void sco_sock_close(struct sock *sk);
77
static void sco_sock_close(struct sock *sk);
70
static void sco_sock_kill(struct sock *sk);
78
static void sco_sock_kill(struct sock *sk);
71
79
80
static int sco_sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
81
82
/* 
83
 * Write buffer destructor automatically called from kfree_skb. 
84
 */
85
void sco_sock_wfree(struct sk_buff *skb)
86
{
87
	struct sock *sk = skb->sk;
88
89
	atomic_dec(&sk->sk_wmem_alloc);
90
	sk->sk_write_space(sk);
91
	sock_put(sk);
92
}
93
94
static void sco_sock_write_space(struct sock *sk)
95
{
96
	read_lock(&sk->sk_callback_lock);
97
98
	if(atomic_read(&sk->sk_wmem_alloc) < sk->sk_sndbuf) {
99
		if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
100
			wake_up_interruptible(sk->sk_sleep);
101
102
		if (sock_writeable(sk))
103
			sk_wake_async(sk, 2, POLL_OUT);
104
	}
105
106
	read_unlock(&sk->sk_callback_lock);
107
}
108
72
/* ---- SCO timers ---- */
109
/* ---- SCO timers ---- */
73
static void sco_sock_timeout(unsigned long arg)
110
static void sco_sock_timeout(unsigned long arg)
74
{
111
{
Lines 234-260 static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) Link Here
234
{
271
{
235
	struct sco_conn *conn = sco_pi(sk)->conn;
272
	struct sco_conn *conn = sco_pi(sk)->conn;
236
	struct sk_buff *skb;
273
	struct sk_buff *skb;
237
	int err, count;
274
	int err;
238
239
	/* Check outgoing MTU */
240
	if (len > conn->mtu)
241
		return -EINVAL;
242
275
243
	BT_DBG("sk %p len %d", sk, len);
276
	BT_DBG("sk %p len %d", sk, len);
244
277
245
	count = min_t(unsigned int, conn->mtu, len);
278
	if (!(skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err)))
246
	if (!(skb = bt_skb_send_alloc(sk, count, msg->msg_flags & MSG_DONTWAIT, &err)))
247
		return err;
279
		return err;
248
280
249
	if (memcpy_fromiovec(skb_put(skb, count), msg->msg_iov, count)) {
281
	/* fix sk_wmem_alloc value : by default it is increased by  skb->truesize, but
282
	we want it only increased by 1 */
283
	atomic_sub(skb->truesize - 1, &sk->sk_wmem_alloc);
284
	/* fix destructor */
285
	skb->destructor = sco_sock_wfree;
286
287
	if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
250
		err = -EFAULT;
288
		err = -EFAULT;
251
		goto fail;
289
		goto fail;
252
	}
290
	}
253
291
254
	if ((err = hci_send_sco(conn->hcon, skb)) < 0)
292
	err = hci_send_sco(conn->hcon, skb);
255
		return err;
256
293
257
	return count;
294
	if (err < 0)
295
		goto fail;
296
297
	return len;
258
298
259
fail:
299
fail:
260
	kfree_skb(skb);
300
	kfree_skb(skb);
Lines 273-280 static inline void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) Link Here
273
	if (sk->sk_state != BT_CONNECTED)
313
	if (sk->sk_state != BT_CONNECTED)
274
		goto drop;
314
		goto drop;
275
315
276
	if (!sock_queue_rcv_skb(sk, skb))
316
	if (sco_sock_queue_rcv_skb(sk, skb) == 0) {
277
		return;
317
		return;
318
	}
278
319
279
drop:
320
drop:
280
	kfree_skb(skb);
321
	kfree_skb(skb);
Lines 328-334 static void sco_sock_destruct(struct sock *sk) Link Here
328
	BT_DBG("sk %p", sk);
369
	BT_DBG("sk %p", sk);
329
370
330
	skb_queue_purge(&sk->sk_receive_queue);
371
	skb_queue_purge(&sk->sk_receive_queue);
331
	skb_queue_purge(&sk->sk_write_queue);
332
}
372
}
333
373
334
static void sco_sock_cleanup_listen(struct sock *parent)
374
static void sco_sock_cleanup_listen(struct sock *parent)
Lines 360-365 static void sco_sock_kill(struct sock *sk) Link Here
360
	/* Kill poor orphan */
400
	/* Kill poor orphan */
361
	bt_sock_unlink(&sco_sk_list, sk);
401
	bt_sock_unlink(&sco_sk_list, sk);
362
	sock_set_flag(sk, SOCK_DEAD);
402
	sock_set_flag(sk, SOCK_DEAD);
403
	
404
	/* release socket */
363
	sock_put(sk);
405
	sock_put(sk);
364
}
406
}
365
407
Lines 376-382 static void sco_sock_close(struct sock *sk) Link Here
376
418
377
	conn = sco_pi(sk)->conn;
419
	conn = sco_pi(sk)->conn;
378
420
379
	BT_DBG("sk %p state %d conn %p socket %p", sk, sk->sk_state, conn, sk->sk_socket);
421
	BT_DBG("sk %p state %d conn %p socket %p refcnt %d", sk, sk->sk_state, conn, sk->sk_socket, atomic_read(&sk->sk_refcnt));
380
422
381
	switch (sk->sk_state) {
423
	switch (sk->sk_state) {
382
	case BT_LISTEN:
424
	case BT_LISTEN:
Lines 426-431 static struct sock *sco_sock_alloc(struct socket *sock, int proto, gfp_t prio) Link Here
426
	INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
468
	INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
427
469
428
	sk->sk_destruct = sco_sock_destruct;
470
	sk->sk_destruct = sco_sock_destruct;
471
	sk->sk_write_space = sco_sock_write_space;
472
473
       /* Put sensible values for a voice link (i.e. not too big),
474
          as sysctl_rmem_default & sysctl_wmem_default are
475
           really not designed for that -- In our case we use sk_**buf to
476
           store a count of SCO packets, not a number of bytes as most of other type of
477
           sockets do */
478
	sk->sk_sndbuf = DEFAULT_SCO_TXBUFS;
479
	sk->sk_rcvbuf = DEFAULT_SCO_RXBUFS;
429
	sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
480
	sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
430
481
431
	sock_reset_flag(sk, SOCK_ZAPPED);
482
	sock_reset_flag(sk, SOCK_ZAPPED);
Lines 656-661 static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock, Link Here
656
static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
707
static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
657
{
708
{
658
	struct sock *sk = sock->sk;
709
	struct sock *sk = sock->sk;
710
	u32 opt;
659
	int err = 0;
711
	int err = 0;
660
712
661
	BT_DBG("sk %p", sk);
713
	BT_DBG("sk %p", sk);
Lines 663-668 static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char Link Here
663
	lock_sock(sk);
715
	lock_sock(sk);
664
716
665
	switch (optname) {
717
	switch (optname) {
718
	case SCO_TXBUFS:
719
		if (get_user(opt, (u32 __user *) optval)) {
720
			err = -EFAULT;
721
			break;
722
		}
723
		if(opt > MAX_SCO_TXBUFS) {
724
			err = -EINVAL;
725
			break;
726
		}
727
728
		sk->sk_sndbuf = opt;
729
		/*
730
		 *	Wake up sending tasks if we
731
		 *	upped the value.
732
		 */
733
		sk->sk_write_space(sk);
734
		break;
735
	case SCO_RXBUFS:
736
		if (get_user(opt, (u32 __user *) optval)) {
737
			err = -EFAULT;
738
			break;
739
		}
740
		if(opt > MAX_SCO_RXBUFS) {
741
			err = -EINVAL;
742
			break;
743
		}
744
745
		sk->sk_rcvbuf = opt;
746
		break;
666
	default:
747
	default:
667
		err = -ENOPROTOOPT;
748
		err = -ENOPROTOOPT;
668
		break;
749
		break;
Lines 677-683 static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char Link Here
677
	struct sock *sk = sock->sk;
758
	struct sock *sk = sock->sk;
678
	struct sco_options opts;
759
	struct sco_options opts;
679
	struct sco_conninfo cinfo;
760
	struct sco_conninfo cinfo;
680
	int len, err = 0; 
761
	int len, err = 0;
762
	int val;
681
763
682
	BT_DBG("sk %p", sk);
764
	BT_DBG("sk %p", sk);
683
765
Lines 687-692 static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char Link Here
687
	lock_sock(sk);
769
	lock_sock(sk);
688
770
689
	switch (optname) {
771
	switch (optname) {
772
	case SCO_RXBUFS:
773
		val = sk->sk_rcvbuf;
774
775
		len = min_t(unsigned int, len, sizeof(val));
776
		if (copy_to_user(optval, (char *)&val, len))
777
			err = -EFAULT;
778
779
		break;
780
781
	case SCO_TXBUFS:
782
		val = sk->sk_sndbuf;
783
784
		len = min_t(unsigned int, len, sizeof(val));
785
		if (copy_to_user(optval, (char *)&val, len))
786
			err = -EFAULT;
787
788
		break;
789
690
	case SCO_OPTIONS:
790
	case SCO_OPTIONS:
691
		if (sk->sk_state != BT_CONNECTED) {
791
		if (sk->sk_state != BT_CONNECTED) {
692
			err = -ENOTCONN;
792
			err = -ENOTCONN;
Lines 891-896 drop: Link Here
891
	return 0;
991
	return 0;
892
}
992
}
893
993
994
static int sco_sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
995
{
996
       int err = 0;
997
998
       BT_DBG("sock %p, sk_rcvbuf %d, qlen %d", sk, sk->sk_rcvbuf, skb_queue_len(&sk->sk_receive_queue));
999
       /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
1000
          number of warnings when compiling with -W --ANK
1001
        */
1002
       if (skb_queue_len(&sk->sk_receive_queue) + 1 >
1003
           (unsigned)sk->sk_rcvbuf) {
1004
               err = -ENOMEM;
1005
               goto out;
1006
       }
1007
1008
       skb->dev = NULL;
1009
       skb->sk = sk;
1010
       skb->destructor = NULL;
1011
1012
       skb_queue_tail(&sk->sk_receive_queue, skb);
1013
1014
       if (!sock_flag(sk, SOCK_DEAD))
1015
               sk->sk_data_ready(sk, 1);
1016
out:
1017
       return err;
1018
}
1019
1020
/* ------- Others ------- */
1021
894
static ssize_t sco_sysfs_show(struct class *dev, char *buf)
1022
static ssize_t sco_sysfs_show(struct class *dev, char *buf)
895
{
1023
{
896
	struct sock *sk;
1024
	struct sock *sk;

Return to bug 10721