Revert "Put the knc rx and tx buffers inside the knc state struct, protecting their access with the mutex." This reverts commit e9ae364f00aa26afca9547dcf3e936ab51822a82.
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
diff --git a/driver-knc-spi-fpga.c b/driver-knc-spi-fpga.c
index 3ecf002..21745c7 100644
--- a/driver-knc-spi-fpga.c
+++ b/driver-knc-spi-fpga.c
@@ -104,13 +104,13 @@ struct spi_response {
uint32_t core;
};
-typedef struct spi_request spi_txbuf_t;
-
#define MAX_REQUESTS_IN_BATCH ( MAX_BYTES_IN_SPI_XSFER / \
- sizeof(spi_txbuf_t) \
+ sizeof(struct spi_request) \
)
-#define MAX_RESPONSES_IN_BATCH ( (sizeof(spi_txbuf_t) * MAX_REQUESTS_IN_BATCH - 12) / \
+static struct spi_request spi_txbuf[MAX_REQUESTS_IN_BATCH];
+
+#define MAX_RESPONSES_IN_BATCH ( (sizeof(spi_txbuf) - 12) / \
sizeof(struct spi_response) \
)
@@ -133,6 +133,8 @@ struct spi_rx_t {
struct spi_response responses[MAX_RESPONSES_IN_BATCH];
};
+static struct spi_rx_t spi_rxbuf;
+
struct active_work {
struct work *work;
uint32_t work_id;
@@ -179,8 +181,6 @@ struct knc_state {
unsigned int last_hour_hwerrs_index[MAX_ASICS][256];
pthread_mutex_t lock;
- spi_txbuf_t spi_txbuf[MAX_REQUESTS_IN_BATCH];
- struct spi_rx_t spi_rxbuf;
};
static inline bool knc_queued_fifo_full(struct knc_state *knc)
@@ -678,10 +678,10 @@ static int _internal_knc_flush_fpga(struct knc_state *knc)
{
int len;
- knc->spi_txbuf[0].cmd = CMD_FLUSH_QUEUE;
- knc->spi_txbuf[0].queue_id = 0; /* at the moment we have one and only queue #0 */
- len = spi_transfer(knc->ctx, (uint8_t *)knc->spi_txbuf,
- (uint8_t *)&knc->spi_rxbuf, sizeof(struct spi_request));
+ spi_txbuf[0].cmd = CMD_FLUSH_QUEUE;
+ spi_txbuf[0].queue_id = 0; /* at the moment we have one and only queue #0 */
+ len = spi_transfer(knc->ctx, (uint8_t *)spi_txbuf,
+ (uint8_t *)&spi_rxbuf, sizeof(struct spi_request));
if (len != sizeof(struct spi_request))
return -1;
@@ -789,17 +789,17 @@ static int64_t knc_scanwork(struct thr_info *thr)
knc_check_disabled_cores(knc);
+ /* Prepare tx buffer */
+ memset(spi_txbuf, 0, sizeof(spi_txbuf));
num = 0;
mutex_lock(&knc->lock);
- /* Prepare tx buffer */
- memset(knc->spi_txbuf, 0, sizeof(spi_txbuf_t));
next_read_q = knc->read_q;
knc_queued_fifo_inc_idx(&next_read_q);
while (next_read_q != knc->write_q) {
knc_work_from_queue_to_spi(knc, &knc->queued_fifo[next_read_q],
- &knc->spi_txbuf[num], knc->next_work_id + num);
+ &spi_txbuf[num], knc->next_work_id + num);
knc_queued_fifo_inc_idx(&next_read_q);
++num;
}
@@ -809,16 +809,16 @@ static int64_t knc_scanwork(struct thr_info *thr)
* consumed by FPGA.
*/
- len = spi_transfer(knc->ctx, (uint8_t *)knc->spi_txbuf,
- (uint8_t *)&knc->spi_rxbuf, sizeof(spi_txbuf_t));
- if (len != sizeof(knc->spi_rxbuf)) {
+ len = spi_transfer(knc->ctx, (uint8_t *)spi_txbuf,
+ (uint8_t *)&spi_rxbuf, sizeof(spi_txbuf));
+ if (len != sizeof(spi_rxbuf)) {
ret = -1;
goto out_unlock;
}
applog(LOG_DEBUG, "KnC spi: %d works in request", num);
- ret = knc_process_response(thr, cgpu, &knc->spi_rxbuf);
+ ret = knc_process_response(thr, cgpu, &spi_rxbuf);
out_unlock:
mutex_unlock(&knc->lock);
@@ -886,7 +886,7 @@ static void knc_flush_work(struct cgpu_info *cgpu)
len = _internal_knc_flush_fpga(knc);
if (len > 0)
- knc_process_response(NULL, cgpu, &knc->spi_rxbuf);
+ knc_process_response(NULL, cgpu, &spi_rxbuf);
mutex_unlock(&knc->lock);
}