Commit 52778727f3f489d82aaca5240839b1361f08b25a

Con Kolivas 2014-03-02T23:13:38

Merge branch 'bpmx'

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 1d50e42..fcca8dd 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -23,6 +23,57 @@ int opt_nf1_bits = 50;
 #define BF1MSGSIZE 7
 #define BF1INFOSIZE 14
 
+#define TWELVE_MHZ 12000000
+
+//Low port pins
+#define SK      1
+#define DO      2
+#define DI      4
+#define CS      8
+#define GPIO0   16
+#define GPIO1   32
+#define GPIO2   64
+#define GPIO3   128
+
+//GPIO pins
+#define GPIOL0  0
+#define GPIOL1  1
+#define GPIOL2  2
+#define GPIOL3  3
+#define GPIOH   4
+#define GPIOH1  5
+#define GPIOH2  6
+#define GPIOH3  7
+#define GPIOH4  8
+#define GPIOH5  9
+#define GPIOH6  10
+#define GPIOH7  11
+
+#define DEFAULT_DIR            (SK | DO | CS | GPIO0 | GPIO1 | GPIO2 | GPIO3)  /* Setup default input or output state per FTDI for SPI */
+#define DEFAULT_STATE          (CS)                                       /* CS idles high, CLK idles LOW for SPI0 */
+
+//MPSSE commands from FTDI AN_108
+#define INVALID_COMMAND           0xAB
+#define ENABLE_ADAPTIVE_CLOCK     0x96
+#define DISABLE_ADAPTIVE_CLOCK    0x97
+#define ENABLE_3_PHASE_CLOCK      0x8C
+#define DISABLE_3_PHASE_CLOCK     0x8D
+#define TCK_X5                    0x8A
+#define TCK_D5                    0x8B
+#define CLOCK_N_CYCLES            0x8E
+#define CLOCK_N8_CYCLES           0x8F
+#define PULSE_CLOCK_IO_HIGH       0x94
+#define PULSE_CLOCK_IO_LOW        0x95
+#define CLOCK_N8_CYCLES_IO_HIGH   0x9C
+#define CLOCK_N8_CYCLES_IO_LOW    0x9D
+#define TRISTATE_IO               0x9E
+#define TCK_DIVISOR               0x86
+#define LOOPBACK_END              0x85
+#define SET_OUT_ADBUS             0x80
+#define SET_OUT_ACBUS             0x82
+#define WRITE_BYTES_SPI0          0x11
+#define READ_WRITE_BYTES_SPI0     0x31
+
 static void bf1_empty_buffer(struct cgpu_info *bitfury)
 {
 	char buf[512];
@@ -303,7 +354,7 @@ static bool nf1_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
 	spi_send_conf(info);
 	spi_send_init(info);
 	spi_reset(bitfury, info);
-	return spi_txrx(bitfury, info);
+	return info->spi_txrx(bitfury, info);
 }
 
 static bool nf1_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info *info)
@@ -322,6 +373,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 	bool ret = false;
 	int i, val;
 
+	info->spi_txrx = &mcp_spi_txrx;
 	mcp2210_get_gpio_settings(bitfury, mcp);
 
 	for (i = 0; i < 9; i++) {
@@ -425,7 +477,7 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 
 	update_usb_stats(bitfury);
 	applog(LOG_INFO, "%s %d: Successfully initialised %s",
-	bitfury->drv->name, bitfury->device_id, bitfury->device_path);
+	       bitfury->drv->name, bitfury->device_id, bitfury->device_path);
 	spi_clear_buf(info);
 
 	info->total_nonces = 1;
@@ -436,6 +488,229 @@ out:
 	return ret;
 }
 
+static bool bxm_purge_buffers(struct cgpu_info *bitfury)
+{
+	int err;
+
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_RESET_REQUEST, SIO_RESET_PURGE_RX, 1, C_BXM_PURGERX);
+	if (err)
+		return false;
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_RESET_REQUEST, SIO_RESET_PURGE_TX, 1, C_BXM_PURGETX);
+	if (err)
+		return false;
+	return true;
+}
+
+/* Calculate required divisor for desired frequency see FTDI AN_108 page 19*/
+static uint16_t calc_divisor(uint32_t system_clock, uint32_t freq)
+{
+	uint16_t divisor = system_clock / freq;
+
+	divisor /= 2;
+	divisor -= 1;
+	return divisor;
+}
+
+static void bxm_close(struct cgpu_info *bitfury)
+{
+	unsigned char bitmask = 0;
+	unsigned char mode = BITMODE_RESET;
+	unsigned short usb_val = bitmask;
+
+	//Need to do BITMODE_RESET before close per FTDI
+	usb_val |= (mode << 8);
+	usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_BITMODE_REQUEST, usb_val, 1, C_BXM_SETBITMODE);
+}
+
+static bool bxm_open(struct cgpu_info *bitfury)
+{
+	unsigned char mode = BITMODE_RESET;
+	unsigned char bitmask = 0;
+	unsigned short usb_val = bitmask;
+	uint32_t system_clock = TWELVE_MHZ;
+	uint32_t freq = 200000;
+	uint16_t divisor = calc_divisor(system_clock,freq);
+	int amount, err;
+	char buf[4];
+
+	/* Enable the transaction translator emulator for these devices
+	 * otherwise we may write to them too quickly. */
+	bitfury->usbdev->tt = true;
+
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_RESET_REQUEST, SIO_RESET_SIO, 1, C_BXM_SRESET);
+	if (err)
+		return false;
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_LATENCY_TIMER_REQUEST, BXM_LATENCY_MS, 1, C_BXM_SETLATENCY);
+	if (err)
+		return false;
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_EVENT_CHAR_REQUEST, 0x00, 1, C_BXM_SECR);
+	if (err)
+		return false;
+
+	//Do a BITMODE_RESET
+	usb_val |= (mode << 8);
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_BITMODE_REQUEST, usb_val, 1, C_BXM_SETBITMODE);
+	if (err)
+		return false;
+	//Now set to MPSSE mode
+	bitmask = 0;
+	mode = BITMODE_MPSSE;
+	usb_val = bitmask;
+	usb_val |= (mode << 8);
+	err = usb_transfer(bitfury, FTDI_TYPE_OUT, SIO_SET_BITMODE_REQUEST, usb_val, 1, C_BXM_SETBITMODE);
+	if (err)
+		return false;
+
+	//Now set the clock divisor
+	//First send just the 0x8B command to set the system clock to 12MHz
+	memset(buf, 0, 4);
+	buf[0] = TCK_D5;
+	err = usb_write(bitfury, buf, 1, &amount, C_BXM_CLOCK);
+	if (err || amount != 1)
+		return false;
+
+	buf[0] = TCK_DIVISOR;
+	buf[1] = (divisor & 0xFF);
+	buf[2] = ((divisor >> 8) & 0xFF);
+	err = usb_write(bitfury, buf, 3, &amount, C_BXM_CLOCKDIV);
+	if (err || amount != 3)
+		return false;
+
+	//Disable internal loopback
+	buf[0] = LOOPBACK_END;
+	err = usb_write(bitfury, buf, 1, &amount, C_BXM_LOOP);
+	if (err || amount != 1)
+		return false;
+
+	//Now set direction and idle (initial) states for the pins
+	buf[0] = SET_OUT_ADBUS;
+	buf[1] = DEFAULT_STATE; //Bitmask for LOW_PORT
+	buf[2] = DEFAULT_DIR;
+	err = usb_write(bitfury, buf, 3, &amount, C_BXM_ADBUS);
+	if (err || amount != 3)
+		return false;
+
+	//Set the pin states for the HIGH_BITS port as all outputs, all low
+	buf[0] = SET_OUT_ACBUS;
+	buf[1] = 0x00; //Bitmask for HIGH_PORT
+	buf[2] = 0xFF;
+	err = usb_write(bitfury, buf, 3, &amount, C_BXM_ACBUS);
+	if (err || amount != 3)
+		return false;
+
+	return true;
+}
+
+static bool bxm_set_CS_low(struct cgpu_info *bitfury)
+{
+	char buf[4] = { 0 };
+	int err, amount;
+
+	buf[0] = SET_OUT_ADBUS;
+	buf[1] &= ~DEFAULT_STATE; //Bitmask for LOW_PORT
+	buf[2] = DEFAULT_DIR;
+	err = usb_write(bitfury, buf, 3, &amount, C_BXM_CSLOW);
+	if (err || amount != 3)
+		return false;
+
+	return true;
+}
+
+static bool bxm_set_CS_high(struct cgpu_info *bitfury)
+{
+	char buf[4] = { 0 };
+	int err, amount;
+
+	buf[0] = SET_OUT_ADBUS;
+	buf[1] = DEFAULT_STATE; //Bitmask for LOW_PORT
+	buf[2] = DEFAULT_DIR;
+	err = usb_write(bitfury, buf, 3, &amount, C_BXM_CSHIGH);
+	if (err || amount != 3)
+		return false;
+
+	return true;
+}
+
+static bool bxm_reset_bitfury(struct cgpu_info *bitfury)
+{
+	char buf[20] = { 0 };
+	char rst_buf[8] = {0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00};
+	int err, amount;
+
+	//Set the FTDI CS pin HIGH. This will gate the clock to the Bitfury chips so we can send the reset sequence.
+	if (!bxm_set_CS_high(bitfury))
+		return false;
+
+	buf[0] = WRITE_BYTES_SPI0;
+	buf[1] = (uint8_t)16 - (uint8_t)1;
+	buf[2] = 0;
+	memcpy(&buf[3], rst_buf, 8);
+	memcpy(&buf[11], rst_buf, 8);
+	err = usb_write(bitfury, buf, 19, &amount, C_BXM_RESET);
+	if (err || amount != 19)
+		return false;
+
+	if (!bxm_set_CS_low(bitfury))
+		return false;
+
+	return true;
+}
+
+static bool bxm_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	spi_clear_buf(info);
+	spi_add_break(info);
+	spi_set_freq(info);
+	spi_send_conf(info);
+	spi_send_init(info);
+	return info->spi_txrx(bitfury, info);
+}
+
+static bool bxm_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	bool ret;
+
+	info->spi_txrx = &ftdi_spi_txrx;
+	ret = bxm_open(bitfury);
+	if (!ret)
+		goto out;
+	ret = bxm_purge_buffers(bitfury);
+	if (!ret)
+		goto out;
+	ret = bxm_reset_bitfury(bitfury);
+	if (!ret)
+		goto out;
+	ret = bxm_purge_buffers(bitfury);
+	if (!ret)
+		goto out;
+
+	/* Do a dummy read */
+	memset(info->spibuf, 0, 80);
+	info->spibufsz = 80;
+	ret = info->spi_txrx(bitfury, info);
+	if (!ret)
+		goto out;
+	/* FIXME make configurable and use a faster default. */
+	info->osc6_bits = 50;
+	ret = bxm_reinit(bitfury, info);
+	if (!ret)
+		goto out;
+
+	if (!add_cgpu(bitfury))
+		quit(1, "Failed to add_cgpu in bxm_detect_one");
+
+	update_usb_stats(bitfury);
+	applog(LOG_INFO, "%s %d: Successfully initialised %s",
+	       bitfury->drv->name, bitfury->device_id, bitfury->device_path);
+	spi_clear_buf(info);
+
+	info->total_nonces = 1;
+out:
+	if (!ret)
+		bxm_close(bitfury);
+	return ret;
+}
+
 static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
 {
 	struct cgpu_info *bitfury;
@@ -465,6 +740,9 @@ static struct cgpu_info *bitfury_detect_one(struct libusb_device *dev, struct us
 		case IDENT_NF1:
 			ret = nf1_detect_one(bitfury, info);
 			break;
+		case IDENT_BXM:
+			ret = bxm_detect_one(bitfury, info);
+			break;
 		default:
 			applog(LOG_INFO, "%s %d: Unrecognised bitfury device",
 			       bitfury->drv->name, bitfury->device_id);
@@ -937,6 +1215,41 @@ static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
 	return ret;
 }
 
+static int64_t bxm_scan(struct thr_info *thr, struct cgpu_info *bitfury,
+			struct bitfury_info *info)
+{
+	int64_t ret = 0;
+
+	if (!info->work) {
+		info->work = get_work(thr, thr->id);
+		if (unlikely(thr->work_restart)) {
+			free_work(info->work);
+			info->work = NULL;
+			return 0;
+		}
+		bitfury_work_to_payload(&info->payload, info->work);
+	}
+	if (!libbitfury_sendHashData(thr, bitfury, info))
+		return -1;
+
+	if (info->job_switched) {
+		if (likely(info->owork))
+			free_work(info->owork);
+		info->owork = info->work;
+		info->work = NULL;
+	}
+
+	ret = bitfury_rate(info);
+
+	if (unlikely(bitfury->usbinfo.nodev)) {
+		applog(LOG_WARNING, "%s %d: Device disappeared, disabling thread",
+		       bitfury->drv->name, bitfury->device_id);
+		ret = -1;
+	}
+
+	return ret;
+}
+
 static int64_t bitfury_scanwork(struct thr_info *thr)
 {
 	struct cgpu_info *bitfury = thr->cgpu;
@@ -971,6 +1284,9 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 		case IDENT_NF1:
 			ret = nf1_scan(thr, bitfury, info);
 			break;
+		case IDENT_BXM:
+			ret = bxm_scan(thr, bitfury, info);
+			break;
 		default:
 			ret = 0;
 			break;
@@ -1116,7 +1432,6 @@ static void bitfury_get_statline_before(char *buf, size_t bufsiz, struct cgpu_in
 		case IDENT_BXF:
 			tailsprintf(buf, bufsiz, "%5.1fC", cgpu->temp);
 			break;
-		case IDENT_BF1:
 		default:
 			break;
 	}
@@ -1137,7 +1452,6 @@ static void bitfury_init(struct cgpu_info *bitfury)
 		case IDENT_BF1:
 			bf1_init(bitfury);
 			break;
-		case IDENT_BXF:
 		default:
 			break;
 	}
@@ -1164,6 +1478,9 @@ static void bitfury_shutdown(struct thr_info *thr)
 		case IDENT_NF1:
 			nf1_close(bitfury);
 			break;
+		case IDENT_BXM:
+			bxm_close(bitfury);
+			break;
 		default:
 			break;
 	}
diff --git a/driver-bitfury.h b/driver-bitfury.h
index a9f05a2..fb66114 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -33,6 +33,20 @@ extern int opt_nf1_bits;
 #define SPIBUF_SIZE 16384
 #define BITFURY_REFRESH_DELAY 100
 
+#define SIO_RESET_REQUEST 0
+#define SIO_SET_LATENCY_TIMER_REQUEST 0x09
+#define SIO_SET_EVENT_CHAR_REQUEST    0x06
+#define SIO_SET_ERROR_CHAR_REQUEST    0x07
+#define SIO_SET_BITMODE_REQUEST       0x0B
+#define SIO_RESET_PURGE_RX 1
+#define SIO_RESET_PURGE_TX 2
+
+#define BITMODE_RESET 0x00
+#define BITMODE_MPSSE 0x02
+#define SIO_RESET_SIO 0
+
+#define BXM_LATENCY_MS 2
+
 struct bitfury_payload {
 	unsigned char midstate[32];
 	unsigned int junk[8];
@@ -90,6 +104,8 @@ struct bitfury_info {
 	bool second_run;
 	struct work *work;
 	struct work *owork;
+
+	bool (*spi_txrx)(struct cgpu_info *, struct bitfury_info *info);
 };
 
 #endif /* BITFURY_H */
diff --git a/libbitfury.c b/libbitfury.c
index bd10ff0..4cc7172 100644
--- a/libbitfury.c
+++ b/libbitfury.c
@@ -242,7 +242,7 @@ bool spi_reset(struct cgpu_info *bitfury, struct bitfury_info *info)
 	return true;
 }
 
-bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
+bool mcp_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
 	unsigned int length, sendrcv;
 	int offset = 0;
@@ -272,6 +272,45 @@ bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
 	return true;
 }
 
+#define READ_WRITE_BYTES_SPI0     0x31
+
+bool ftdi_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
+	int err, amount, len;
+	uint16_t length;
+	char buf[1024];
+
+	len = info->spibufsz;
+	length = info->spibufsz - 1; //FTDI length is shifted by one 0x0000 = one byte
+	buf[0] = READ_WRITE_BYTES_SPI0;
+	buf[1] = length & 0x00FF;
+	buf[2] = (length & 0xFF00) >> 8;
+	memcpy(&buf[3], info->spibuf, info->spibufsz);
+	info->spibufsz += 3;
+	err = usb_write(bitfury, buf, info->spibufsz, &amount, C_BXM_SPITX);
+	if (err || amount != (int)info->spibufsz) {
+		applog(LOG_ERR, "%s %d: SPI TX error %d, sent %d of %d", bitfury->drv->name,
+		       bitfury->device_id, err, amount, info->spibufsz);
+		return false;
+	}
+	info->spibufsz = len;
+	/* We shouldn't even get a timeout error on reads in spi mode */
+	err = usb_read(bitfury, info->spibuf, len, &amount, C_BXM_SPIRX);
+	if (err || amount != len) {
+		applog(LOG_ERR, "%s %d: SPI RX error %d, read %d of %d", bitfury->drv->name,
+		       bitfury->device_id, err, amount, info->spibufsz);
+		return false;
+	}
+	amount = usb_buffer_size(bitfury);
+	if (amount) {
+		applog(LOG_ERR, "%s %d: SPI RX Extra read buffer size %d", bitfury->drv->name,
+		       bitfury->device_id, amount);
+		usb_buffer_clear(bitfury);
+		return false;
+	}
+	return true;
+}
+
 #define BT_OFFSETS 3
 
 bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonce)
@@ -306,7 +345,7 @@ bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
 	spi_clear_buf(info);
 	spi_add_break(info);
 	spi_add_data(info, 0x3000, (void*)localvec, 19 * 4);
-	if (!spi_txrx(bitfury, info))
+	if (!info->spi_txrx(bitfury, info))
 		return false;
 
 	memcpy(newbuf, info->spibuf + 4, 17 * 4);
diff --git a/libbitfury.h b/libbitfury.h
index 79ed564..90a79c5 100644
--- a/libbitfury.h
+++ b/libbitfury.h
@@ -23,7 +23,8 @@ void spi_add_buf(struct bitfury_info *info, const void *buf, const int sz);
 void spi_add_break(struct bitfury_info *info);
 void spi_add_data(struct bitfury_info *info, uint16_t addr, const void *buf, int len);
 bool spi_reset(struct cgpu_info *bitfury, struct bitfury_info *info);
-bool spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info);
+bool mcp_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info);
+bool ftdi_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info);
 bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonce);
 bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
 			     struct bitfury_info *info);
diff --git a/usbutils.c b/usbutils.c
index 204dd6b..23045e9 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -167,6 +167,15 @@ static struct usb_epinfo nf1_epinfos[] = {
 static struct usb_intinfo nf1_ints[] = {
 	USB_EPS(0, nf1_epinfos)
 };
+
+static struct usb_epinfo bxm_epinfos[] = {
+	{ LIBUSB_TRANSFER_TYPE_BULK,	512,	EPI(1), 0, 0 },
+	{ LIBUSB_TRANSFER_TYPE_BULK,	512,	EPO(2), 0, 0 }
+};
+
+static struct usb_intinfo bxm_ints[] = {
+	USB_EPS(0, bxm_epinfos)
+};
 #endif
 
 #ifdef USE_DRILLBIT
@@ -415,6 +424,17 @@ static struct usb_find_devices find_dev[] = {
 		.latency = LATENCY_UNUSED,
 		INTINFO(nf1_ints)
 	},
+	{
+		.drv = DRIVER_bitfury,
+		.name = "BXM",
+		.ident = IDENT_BXM,
+		.idVendor = 0x0403,
+		.idProduct = 0x6014,
+		.config = 1,
+		.timeout = BITFURY_TIMEOUT_MS,
+		.latency = LATENCY_UNUSED,
+		INTINFO(bxm_ints)
+	},
 #endif
 #ifdef USE_DRILLBIT
 	{
@@ -2016,6 +2036,10 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
 	}
 
 	cgusb->usbver = cgusb->descriptor->bcdUSB;
+	if (cgusb->usbver < 0x0200) {
+		cgusb->usb11 = true;
+		cgusb->tt = true;
+	}
 
 // TODO: allow this with the right version of the libusb include and running library
 //	cgusb->speed = libusb_get_device_speed(dev);
@@ -2957,10 +2981,10 @@ out_noerrmsg:
 int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t bufsiz, int *processed, int timeout, enum usb_cmds cmd)
 {
 	struct timeval write_start, tv_finish;
-	bool first = true, usb11 = false;
 	struct cg_usb_device *usbdev;
 	unsigned int initial_timeout;
 	int err, sent, tot, pstate;
+	bool first = true;
 	double done;
 
 	DEVRLOCK(cgpu, pstate);
@@ -2977,8 +3001,6 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 	}
 
 	usbdev = cgpu->usbdev;
-	if (usbdev->descriptor->bcdUSB < 0x0200)
-		usb11 = true;
 	if (timeout == DEVTIMEOUT)
 		timeout = usbdev->found->timeout;
 
@@ -2992,7 +3014,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 		/* USB 1.1 devices don't handle zero packets well so split them
 		 * up to not have the final transfer equal to the wMaxPacketSize
 		 * or they will stall waiting for more data. */
-		if (usb11) {
+		if (usbdev->usb11) {
 			struct usb_epinfo *ue = &usbdev->found->intinfos[intinfo].epinfos[epinfo];
 
 			if (tosend == ue->wMaxPacketSize) {
@@ -3003,7 +3025,7 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
 		}
 		err = usb_perform_transfer(cgpu, usbdev, intinfo, epinfo, (unsigned char *)buf,
 					tosend, &sent, timeout, MODE_BULK_WRITE,
-					cmd, first ? SEQ0 : SEQ1, false, usb11);
+					cmd, first ? SEQ0 : SEQ1, false, usbdev->tt);
 		cgtime(&tv_finish);
 
 		USBDEBUG("USB debug: @_usb_write(%s (nodev=%s)) err=%d%s sent=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), sent);
diff --git a/usbutils.h b/usbutils.h
index db360d0..5d918fd 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -148,6 +148,7 @@ enum sub_ident {
 	IDENT_BLT,
 	IDENT_BTB,
 	IDENT_BXF,
+	IDENT_BXM,
 	IDENT_CMR1,
 	IDENT_CMR2,
 	IDENT_CTA,
@@ -211,6 +212,8 @@ struct cg_usb_device {
 	char buffer[USB_MAX_READ];
 	uint32_t bufsiz;
 	uint32_t bufamt;
+	bool usb11; // USB 1.1 flag for convenience
+	bool tt; // Enable the transaction translator
 };
 
 #define USB_NOSTAT 0
@@ -372,6 +375,23 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_BXF_MAXROLL, "BXFMaxRoll") \
 	USB_ADD_COMMAND(C_BXF_FLUSH, "BXFFlush") \
 	USB_ADD_COMMAND(C_BXF_CLOCK, "BXFClock") \
+	USB_ADD_COMMAND(C_BXM_FLUSH, "BXMFlush") \
+	USB_ADD_COMMAND(C_BXM_SRESET, "BXMSReset") \
+	USB_ADD_COMMAND(C_BXM_SETLATENCY, "BXMSetLatency") \
+	USB_ADD_COMMAND(C_BXM_SECR, "BXMSetEventCharRequest") \
+	USB_ADD_COMMAND(C_BXM_SETBITMODE, "BXMSetBitmodeRequest") \
+	USB_ADD_COMMAND(C_BXM_CLOCK, "BXMClock") \
+	USB_ADD_COMMAND(C_BXM_CLOCKDIV, "BXMClockDiv") \
+	USB_ADD_COMMAND(C_BXM_LOOP, "BXMLoop") \
+	USB_ADD_COMMAND(C_BXM_ADBUS, "BXMADBus") \
+	USB_ADD_COMMAND(C_BXM_ACBUS, "BXMACBus") \
+	USB_ADD_COMMAND(C_BXM_PURGERX, "BXMPurgeRX") \
+	USB_ADD_COMMAND(C_BXM_PURGETX, "BXMPurgeTX") \
+	USB_ADD_COMMAND(C_BXM_CSLOW, "BXMCSLow") \
+	USB_ADD_COMMAND(C_BXM_CSHIGH, "BXMCSHigh") \
+	USB_ADD_COMMAND(C_BXM_RESET, "BXMReset") \
+	USB_ADD_COMMAND(C_BXM_SPITX, "BXMSPITX") \
+	USB_ADD_COMMAND(C_BXM_SPIRX, "BXMSPIRX") \
 	USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
 	USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
 	USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \