esc_esi.c 15.2 KB
Newer Older
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
/*
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
	Copyright Stichting C.A. Muller Radioastronomiestation, 2013

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */
/*
	esc_esi.c
	
	Code for accessing the ESI data stored in the device's eeprom.
	The ESI data contains a device description which can be used during
	initialization.
	
 */

#include <string.h>

Jeroen Vreeken's avatar
Jeroen Vreeken committed
30
31
32
33
34
35
36
37
38
#include <ec/ec.h>
#include <ec/esc.h>
#include <ec/esc_esi.h>
#include <ec/esc_dc.h>
#include <ec/esc_registers.h>
#include <ec/esc_mailbox.h>
#include <ec/esc_watchdog.h>
#include <log/log.h>
#include <controller/controller_sample.h>
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

ssize_t esc_esi_eeprom_read(struct ec_dgram_addr *ec_addr, 
    void *buffer, size_t offset, size_t size)
{
	int r;
	uint8_t val8;
	uint16_t val16, status;
	uint32_t val32;
	int wordsize;
	size_t readsize = 0;
	
	/* Make sure ecat side has eeprom control */
	do {
		ec_addr->addr.position.off = ESC_ADDR_MAP_ESI_EEPROM_CONFIG;
		r = ec_datagram_read(ec_addr, &val8, 1);
		if (val8 & ESC_ESI_EEPROM_CONFIG_PDI && r == 1) {
			uint8_t resetval8 = ESC_ESI_EEPROM_CONFIG_FORCE_ECAT;
			r = ec_datagram_write(ec_addr, &resetval8, 1);
		}
	} while (val8 & ESC_ESI_EEPROM_CONFIG_PDI && r == 1);
	if (r != 1)
		return -1;

	/* get status */
	ec_addr->addr.position.off = ESC_ADDR_MAP_ESI_EEPROM_CONTROL_STATUS;
	r = ec_datagram_read(ec_addr, &val16, 2);
	if (r != 2)
		return -1;
	
	status = le16toh(val16);
	if (status & ESC_ESI_EEPROM_CONTROL_STATUS_READ_8B) {
		wordsize = 8;
	} else {
		wordsize = 4;
	}

	while (size) {
		uint8_t data[8];
		size_t copysize;
		
		/* set address */
		val32 = htole32(offset / 2);
		ec_addr->addr.position.off = ESC_ADDR_MAP_ESI_EEPROM_ADDRESS;
		r = ec_datagram_write(ec_addr, &val32, 4);
		
		/* Wait for other stuff to finish */
		do {
			r = ec_datagram_read(ec_addr, &val16, 2);
		} while (le16toh(val16) & ESC_ESI_EEPROM_CONTROL_STATUS_BUSY && r == 2);

		/* Issue read command */
		ec_addr->addr.position.off = ESC_ADDR_MAP_ESI_EEPROM_CONTROL_STATUS;
		val16 = htole16(ESC_ESI_EEPROM_CONTROL_STATUS_CMD_READ);
		r = ec_datagram_write(ec_addr, &val16, 2);
		
		/* Wait for read to finish */
		do {
			r = ec_datagram_read(ec_addr, &val16, 2);
		} while (le16toh(val16) & ESC_ESI_EEPROM_CONTROL_STATUS_BUSY && r == 2);
		
		/* make sure nothing is fucked up.... */
		status = le16toh(val16);
		if (status & ESC_ESI_EEPROM_CONTROL_STATUS_CHKSUM_ERR ||
		    status & ESC_ESI_EEPROM_CONTROL_STATUS_NOT_LOADED ||
		    status & ESC_ESI_EEPROM_CONTROL_STATUS_ACK_ERR ||
		    status & ESC_ESI_EEPROM_CONTROL_STATUS_WRITE_ERR) {
			return -1;
		}

		/* read data and copy to client buffer */
		ec_addr->addr.position.off = ESC_ADDR_MAP_ESI_EEPROM_DATA;
		if (size < wordsize)
			wordsize = size;
		r = ec_datagram_read(ec_addr, data, wordsize);
		if (r != wordsize)
			break;
		
		copysize = size;
		if (copysize > wordsize)
			copysize = wordsize;
		memcpy(buffer, data, copysize);
		size -= copysize;
		offset += copysize;
		buffer += copysize;
		readsize += copysize;
	}
	
	return readsize;
}


uint16_t esc_esi_read16(struct ec_dgram_addr *ec_addr, size_t offset)
{
	uint16_t val16 = 0;
	
	esc_esi_eeprom_read(ec_addr, &val16, offset, sizeof(uint16_t));
	
	return le16toh(val16);
}

uint32_t esc_esi_read32(struct ec_dgram_addr *ec_addr, size_t offset)
{
	uint32_t val32 = 0;
	
	esc_esi_eeprom_read(ec_addr, &val32, offset, sizeof(uint32_t));
	
	return le32toh(val32);
}

size_t esc_esi_standard_rx_mailbox_offset_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read16(ec_addr, ESC_ESI_STANDARD_RX_MAILBOX_OFFSET);
}

size_t esc_esi_standard_tx_mailbox_offset_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read16(ec_addr, ESC_ESI_STANDARD_TX_MAILBOX_OFFSET);
}

size_t esc_esi_standard_rx_mailbox_size_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read16(ec_addr, ESC_ESI_STANDARD_RX_MAILBOX_SIZE);
}

size_t esc_esi_standard_tx_mailbox_size_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read16(ec_addr, ESC_ESI_STANDARD_TX_MAILBOX_SIZE);
}

uint32_t esc_esi_vendorid_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read32(ec_addr, ESC_ESI_ADDR_VENDORID);
}

uint32_t esc_esi_productcode_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read32(ec_addr, ESC_ESI_ADDR_PRODUCTCODE);
}

uint32_t esc_esi_revisionno_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read32(ec_addr, ESC_ESI_ADDR_REVISIONNO);
}

uint32_t esc_esi_serialno_get(struct ec_dgram_addr *ec_addr)
{
	return esc_esi_read32(ec_addr, ESC_ESI_ADDR_SERIALNO);
}


struct esc_esi_category *esc_esi_categories_create(struct ec_dgram_addr *ec_addr)
{
	struct esc_esi_category *categories = NULL, *cat, **catp;
	size_t word_offset;
	int max_cat = 100;
	ssize_t r;

	word_offset = ESC_ESI_FIRST_CATEGORY_TYPE/2;
	
	do {
		uint16_t type;
		uint16_t size;
		
		type = esc_esi_read16(ec_addr, word_offset*2);
		size = esc_esi_read16(ec_addr, (word_offset+1)*2);
		
		if (type == 0xffff) {
			break;
		}
		
		cat = calloc(1, sizeof(struct esc_esi_category));
		if (!cat)
			break;
		
		cat->length = size*2;
		cat->type = type;
		
		cat->data = calloc(1, cat->length);
		if (!cat->data) {
			free(cat);
			break;
		}
		r = esc_esi_eeprom_read(ec_addr, cat->data, (word_offset+2)*2,
		    cat->length);
		if (r != cat->length) {
			free(cat->data);
			free(cat);
			break;
		}
		
		word_offset += size + 2;
		
		for (catp = &categories; *catp; catp = &(*catp)->next);
		(*catp) = cat;
	} while (max_cat--);
	
	return categories;
}

void esc_esi_categories_destroy(struct esc_esi_category *cat)
{
	struct esc_esi_category *old;
	
	while (cat) {
		old = cat;
		cat = old->next;
		free(old->data);
		free(old);
	}
}

ssize_t esc_esi_category_strings_get(struct esc_esi_category *categories,
    int nr, char *str, size_t len)
{
	struct esc_esi_category *cat;
	ssize_t r = -1;
	uint8_t nr_strings;
	int cur;
	size_t offset;
	
	if (len > 1)
		str[0] = 0;
	
	for (cat = categories; cat && cat->type != ESC_ESI_CATEGORY_STRINGS; 
	    cat	= cat->next);
	
	if (!cat || cat->length < 2)
		return r;
	
	nr_strings = cat->data[0];
	if (nr > nr_strings)
		return r;

	offset = 1;
	cur = 1;
	
	while (offset < cat->length && cur < nr_strings && cur != nr) {
		cur++;
		offset += cat->data[offset] + 1;
	}
	
	if (cur == nr) {
		size_t copysize;
		
		copysize = cat->data[offset];
		if (copysize + offset > cat->length)
			copysize = cat->length - offset;
		if (copysize > len-1)
			copysize = len-1;

		memcpy(str, &cat->data[offset+1], copysize);
		str[copysize] = 0;
		
		r = copysize;
	}
	
	return r;
}

struct esc_esi_syncmanager {
	uint16_t	offset;
	uint16_t	size;
	uint8_t		ctrl;
	uint8_t		stat;
	uint8_t		enabled;
	uint8_t		unknown1; /* pdictrl ?*/
} __packed;

struct esc_esi_pdo {
	uint16_t	index;
	uint8_t		entries;
	uint8_t		sm;
	uint8_t		unknown1;
	uint8_t		string;
	uint8_t		unknown2;
	uint8_t		unknown3;
} __packed;

struct esc_esi_pdo_entry {
	uint16_t	index;
	uint8_t		unknown1; /* probably sub-index */
	uint8_t		string;
	uint8_t		unknown2;
	uint8_t		bitsize;
	uint8_t		unknown3;
	uint8_t		unknown4;
} __packed;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
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
struct esc_esi_fmmu {
	uint8_t		unknown1;
} __packed;

struct esc_esi_dcclock {
	uint32_t	cycle_time_sync0;
	int32_t		shift_time_sync0;
	int32_t		shift_time_sync1;
	int16_t		cycle_time_sync1_factor;
	uint16_t	assign_activate;
	int16_t		cycle_time_sync0_factor;
	uint8_t		dc_sync_name;
	uint8_t		unknown1;
	uint8_t		unknown2;
	uint8_t		unknown3;
	uint8_t		unknown4;
	uint8_t		unknown5;
} __packed;

static int esc_esi_device_fill_dc(struct esc_device *dev)
{
	struct esc_esi_category *cat;
	struct esc_esi_dcclock *dc;
	int i, nr;
	double period;
	uint32_t period_cycle;

	period = controller_sample_period();
	period_cycle = (uint32_t)(period * 1000 * 1000 * 1000);

	for (cat = dev->categories; 
	    cat && cat->type != ESC_ESI_CATEGORY_DCCLOCK; 
	    cat	= cat->next);
	
	if (!cat)
		return -1;
	
	if (cat->length % sizeof(struct esc_esi_dcclock)) {
		log_send(LOG_T_ERROR, 
		    "SII DC clock data is not a multiple of %zd",
		    sizeof(struct esc_esi_dcclock));
		return -1;
	}
	nr = cat->length / sizeof(struct esc_esi_dcclock);

	dc = (struct esc_esi_dcclock *)cat->data;
	for (i = 0; i < nr; i++) {
		char string[200];
		uint8_t activate, cyclic;
		uint32_t cycle0;
		int32_t shift0, shift1;
		int16_t factor0, factor1;
		bool sync_out, sync0, sync1, latch0, latch1;

		cycle0 = le32toh(dc->cycle_time_sync0);
		shift0 = le32toh(dc->shift_time_sync0);
		shift1 = le32toh(dc->shift_time_sync1);
		factor0 = le16toh(dc->cycle_time_sync0_factor);
		factor1 = le16toh(dc->cycle_time_sync1_factor);

		/* what is the extra byte doing here??? */
		activate = le16toh(dc->assign_activate) >> 8;
		cyclic = le16toh(dc->assign_activate) & 0xff;
	
		if (activate & ESC_DC_ACTIVATION_REGISTER_SYNC_OUT_ACTIVE)
			sync_out = true;
		else
			sync_out = false;
		if (activate & ESC_DC_ACTIVATION_REGISTER_SYNC0_ACTIVE)
			sync0 = true;
		else
			sync0 = false;
		if (activate & ESC_DC_ACTIVATION_REGISTER_SYNC1_ACTIVE)
			sync1 = true;
		else
			sync1 = false;

		if (cyclic & ESC_DC_CYCLIC_UNIT_CONTROL_LATCH0_PDI)
			latch0 = true;
		else
			latch0 = false;
		if (cyclic & ESC_DC_CYCLIC_UNIT_CONTROL_LATCH1_PDI)
			latch1 = true;
		else
			latch1 = false;

		/* lots of guessing here: */
		// todo: is factor/cycle logic ok?
		// todo: what is a negative factor?
		if (sync_out) {
			if (sync0 && !cycle0) {
				/* factor and cycle 0? */
				if (!factor0)
					factor0 = 1;
				cycle0 = period_cycle * factor0;
			}
			if (sync1 && factor1) {
				/* factor? */
				shift1 = cycle0 * (factor1 - 1) + shift1;
			}
		}

		esc_esi_category_strings_get(dev->categories,
		    dc->dc_sync_name, string, 200);
		log_send(LOG_T_DEBUG, "\tDC: %s", string);
		
		log_send(LOG_T_DEBUG, "\t\tSYNC0: cycle: %d, factor: %d, shift: %d",
		    cycle0, factor0, shift0);
		log_send(LOG_T_DEBUG, "\t\tSYNC1: factor: %d, shift: %d",
		    factor1, shift1);
		log_send(LOG_T_DEBUG, "\t\tassign_activate: 0x%04x",
		    le16toh(dc->assign_activate));

		dev->dc_sync.sync0_cycle = cycle0;
		dev->dc_sync.sync0_shift = shift0;
		dev->dc_sync.sync1_shift = shift1;
		
		dev->dc_sync.sync_out_active = sync_out;
		dev->dc_sync.sync0_active = sync0;
		dev->dc_sync.sync1_active = sync1;

		dev->dc_sync.latch0_pdi = latch0;
		dev->dc_sync.latch1_pdi = latch1;
	
		dc++;
	}
	return 0;
}

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
static int esc_esi_device_fill_sm(struct esc_device *dev)
{
	struct esc_esi_category *cat;
	struct esc_esi_syncmanager *sm;
	int i, nr;
	
	for (cat = dev->categories; 
	    cat && cat->type != ESC_ESI_CATEGORY_SYNCMANAGER; 
	    cat	= cat->next);
	
	if (!cat)
		return -1;
	
	if (cat->length % sizeof(struct esc_esi_syncmanager)) {
		log_send(LOG_T_ERROR, 
		    "SII syncmanager data is not a multiple of %zd",
		    sizeof(struct esc_esi_syncmanager));
		return -1;
	}
	nr = cat->length / sizeof(struct esc_esi_syncmanager);
	if (nr > ESC_SYNCMANAGER_MAX) {
		log_send(LOG_T_ERROR,
		    "SII syncmanager data contains more than %d entries: %d",
		    ESC_SYNCMANAGER_MAX, nr);
		return -1;
	}
	
	sm = (struct esc_esi_syncmanager *)cat->data;
	for (i = 0; i < nr; i++) {
		dev->sm[i].start = le16toh(sm[i].offset);
		dev->sm[i].len = le16toh(sm[i].size);
		dev->sm[i].sm = i;
		dev->sm[i].enabled = sm[i].enabled;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
490
491
492
493
494
		log_send(LOG_T_DEBUG, 
		    "\tsm%d: %zd bytes @ 0x%zx, enabled: %d, ctrl: %02x",
		    i, dev->sm[i].len, dev->sm[i].start, dev->sm[i].enabled,
		    sm[i].ctrl);

495
496
497
		if (sm[i].ctrl == ESC_SYNCMANAGER_CONTROL_INT_PDI) {
			dev->rx_pdo = true;
			dev->rx_pdo_sm = i;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
498
			log_send(LOG_T_DEBUG, "\tUsing sm%d for rx pdo",
499
500
			    dev->rx_pdo_sm);
		}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
501
		if (sm[i].ctrl & ESC_SYNCMANAGER_CONTROL_WRITE) {
502
503
504
505
			dev->tx_pdo = true;
			dev->tx_pdo_sm = i;
			dev->tx_pdo_watchdog =
			    sm[i].ctrl & ESC_SYNCMANAGER_CONTROL_WATCHDOG_ENABLE;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
506
			log_send(LOG_T_DEBUG, "\tUsing sm%d for tx pdo",
507
508
509
510
511
512
513
			    dev->tx_pdo_sm);
		}
	}

	return 0;
}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
514
515
static int esc_esi_device_fill_pdo_cat(struct esc_device *dev, 
    struct esc_esi_category *cat)
516
517
518
519
{
	struct esc_esi_pdo *pdo;
	struct esc_esi_pdo_entry *pdo_entry;
	int i, j, nr, entries;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
520

521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
	if (cat->length % sizeof(struct esc_esi_pdo)) {
		log_send(LOG_T_ERROR, 
		    "SII pdo data is not a multiple of %zd",
		    sizeof(struct esc_esi_pdo));
		return -1;
	}
	nr = cat->length / sizeof(struct esc_esi_pdo);
	
	for (i = 0; i < nr; i++) {
		char string[200];
		pdo = ((struct esc_esi_pdo *)cat->data) + i;
		
		entries = pdo->entries;
		esc_esi_category_strings_get(dev->categories,
		    pdo->string, string, 200);
		log_send(LOG_T_DEBUG, 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
537
		    "\tPDO index: 0x%04x, sm: %d, entries: %d, name: %s",
538
539
540
541
542
543
544
545
		    le16toh(pdo->index), pdo->sm, entries, string);
		
		for (j = 0; j < entries && j + i < nr; j++) {
			pdo_entry = (struct esc_esi_pdo_entry *)(pdo+1+j);
			
			esc_esi_category_strings_get(dev->categories,
			    pdo_entry->string, string, 200);
			log_send(LOG_T_DEBUG, 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
546
			    "\t\tindex: 0x%04x, bitsize: %d, name: %s",
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
			    le16toh(pdo_entry->index), pdo_entry->bitsize,
			    string);
			
			if (pdo->sm < ESC_SYNCMANAGER_MAX) {
				dev->sm[pdo->sm].bitlen += pdo_entry->bitsize;
				if (cat->type == ESC_ESI_CATEGORY_PDO_RX) {
					dev->rx_pdo_sm = pdo->sm;
					dev->rx_pdo = true;
				}
				if (cat->type == ESC_ESI_CATEGORY_PDO_TX) {
					dev->tx_pdo_sm = pdo->sm;
					dev->tx_pdo = true;
				}
			}
		}
		i += j;
	}

	for (i = 0; i < ESC_SYNCMANAGER_MAX; i++) {
		if (!dev->sm[i].len) {
			dev->sm[i].len = dev->sm[i].bitlen / 8;
		}
	}

	return 0;
}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
static int esc_esi_device_fill_pdo(struct esc_device *dev)
{
	struct esc_esi_category *cat;
	int r = 0;
		
	for (cat = dev->categories; cat; cat = cat->next) { 
		if (cat->type == ESC_ESI_CATEGORY_PDO_RX ||
		    cat->type == ESC_ESI_CATEGORY_PDO_TX) {
			r = esc_esi_device_fill_pdo_cat(dev, cat);
		}
	}

	return r;
}

589
590
591
592
593
594
595
/*
	This function will create a device structure and will fill initialize
	according to the ESI data found on the device.
	
	Upon return the rx/tx PDOs will be set, if present a mailbox has been
	created, and the device is set to the pre-operational state.
 */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
596
int esc_esi_device_fill(struct esc_device *dev)
597
{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
598
	int r = 0;
599
600
601
602
	size_t mbox_rx_offset, mbox_tx_offset;
	size_t mbox_rx_size, mbox_tx_size;
	int i;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
603
604
605
	log_send(LOG_T_DEBUG, "%s: Filling device based on ESI information",
	    dev->name);
		
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
	dev->categories = esc_esi_categories_create(&dev->addr);

	esc_esi_device_fill_sm(dev);
	esc_esi_device_fill_pdo(dev);

	mbox_rx_offset = esc_esi_standard_rx_mailbox_offset_get(&dev->addr);
	mbox_rx_size = esc_esi_standard_rx_mailbox_offset_get(&dev->addr);
	mbox_tx_offset = esc_esi_standard_tx_mailbox_offset_get(&dev->addr);
	mbox_tx_size = esc_esi_standard_tx_mailbox_offset_get(&dev->addr);

	for (i = 0; i < ESC_SYNCMANAGER_MAX; i++) {
		if (!dev->sm[i].enabled)
			continue;
		if (dev->sm[i].start == mbox_rx_offset) {
			if (!dev->sm[i].len)
				dev->sm[i].len = mbox_rx_size;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
622
			dev->mbox_wr_sm = i;
623
624
625
626
		}
		if (dev->sm[i].start == mbox_tx_offset) {
			if (!dev->sm[i].len)
				dev->sm[i].len = mbox_tx_size;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
627
			dev->mbox_rd_sm = i;
628
629
630
		}
	}
	
Jeroen Vreeken's avatar
Jeroen Vreeken committed
631
632
633
	esc_esi_device_fill_dc(dev);

	return r;
634
635
}