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#define SOURCEFILE_NAME "hpi6000.c"
32
33#include "hpi_internal.h"
34#include "hpimsginit.h"
35#include "hpidebug.h"
36#include "hpi6000.h"
37#include "hpidspcd.h"
38#include "hpicmn.h"
39
40#define HPI_HIF_BASE (0x00000200)
41#define HPI_HIF_ADDR(member) \
42 (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
43#define HPI_HIF_ERROR_MASK 0x4000
44
45
46#define HPI6000_ERROR_BASE 900
47
48
49#define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
50
51#define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK 903
52#define HPI6000_ERROR_MSG_GET_ADR 904
53#define HPI6000_ERROR_RESP_GET_ADR 905
54#define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32 906
55#define HPI6000_ERROR_MSG_RESP_BLOCKREAD32 907
56
57#define HPI6000_ERROR_CONTROL_CACHE_PARAMS 909
58
59#define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT 911
60#define HPI6000_ERROR_SEND_DATA_ACK 912
61#define HPI6000_ERROR_SEND_DATA_ADR 913
62#define HPI6000_ERROR_SEND_DATA_TIMEOUT 914
63#define HPI6000_ERROR_SEND_DATA_CMD 915
64#define HPI6000_ERROR_SEND_DATA_WRITE 916
65#define HPI6000_ERROR_SEND_DATA_IDLECMD 917
66
67#define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT 921
68#define HPI6000_ERROR_GET_DATA_ACK 922
69#define HPI6000_ERROR_GET_DATA_CMD 923
70#define HPI6000_ERROR_GET_DATA_READ 924
71#define HPI6000_ERROR_GET_DATA_IDLECMD 925
72
73#define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN 951
74#define HPI6000_ERROR_CONTROL_CACHE_READ 952
75#define HPI6000_ERROR_CONTROL_CACHE_FLUSH 953
76
77#define HPI6000_ERROR_MSG_RESP_GETRESPCMD 961
78#define HPI6000_ERROR_MSG_RESP_IDLECMD 962
79
80
81#define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
82
83
84#define HPI6000_ERROR_INIT_PCI2040 931
85
86#define HPI6000_ERROR_INIT_DSPHPI 932
87
88#define HPI6000_ERROR_INIT_DSPINTMEM 933
89
90#define HPI6000_ERROR_INIT_SDRAM1 934
91
92#define HPI6000_ERROR_INIT_SDRAM2 935
93
94#define HPI6000_ERROR_INIT_VERIFY 938
95
96#define HPI6000_ERROR_INIT_NOACK 939
97
98#define HPI6000_ERROR_INIT_PLDTEST1 941
99#define HPI6000_ERROR_INIT_PLDTEST2 942
100
101
102
103#define HIDE_PCI_ASSERTS
104#define PROFILE_DSP2
105
106
107
108
109
110
111#define INTERRUPT_EVENT_SET 0
112#define INTERRUPT_EVENT_CLEAR 1
113#define INTERRUPT_MASK_SET 2
114#define INTERRUPT_MASK_CLEAR 3
115#define HPI_ERROR_REPORT 4
116#define HPI_RESET 5
117#define HPI_DATA_WIDTH 6
118
119#define MAX_DSPS 2
120
121#define DSP_SPACING 0x800
122
123#define CONTROL 0x0000
124#define ADDRESS 0x0200
125#define DATA_AUTOINC 0x0400
126#define DATA 0x0600
127
128#define TIMEOUT 500000
129
130struct dsp_obj {
131 __iomem u32 *prHPI_control;
132 __iomem u32 *prHPI_address;
133 __iomem u32 *prHPI_data;
134 __iomem u32 *prHPI_data_auto_inc;
135 char c_dsp_rev;
136 u32 control_cache_address_on_dsp;
137 u32 control_cache_length_on_dsp;
138 struct hpi_adapter_obj *pa_parent_adapter;
139};
140
141struct hpi_hw_obj {
142 __iomem u32 *dw2040_HPICSR;
143 __iomem u32 *dw2040_HPIDSP;
144
145 u16 num_dsp;
146 struct dsp_obj ado[MAX_DSPS];
147
148 u32 message_buffer_address_on_dsp;
149 u32 response_buffer_address_on_dsp;
150 u32 pCI2040HPI_error_count;
151
152 struct hpi_control_cache_single control_cache[HPI_NMIXER_CONTROLS];
153 struct hpi_control_cache *p_cache;
154};
155
156static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
157 u16 dsp_index, u32 hpi_address, u32 *source, u32 count);
158static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
159 u16 dsp_index, u32 hpi_address, u32 *dest, u32 count);
160
161static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
162 u32 *pos_error_code);
163static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
164 u16 read_or_write);
165#define H6READ 1
166#define H6WRITE 0
167
168static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
169 struct hpi_message *phm);
170static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
171 u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr);
172
173static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
174 struct hpi_response *phr);
175
176static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
177 u32 ack_value);
178
179static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
180 u16 dsp_index, u32 host_cmd);
181
182static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo);
183
184static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
185 struct hpi_message *phm, struct hpi_response *phr);
186
187static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
188 struct hpi_message *phm, struct hpi_response *phr);
189
190static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data);
191
192static u32 hpi_read_word(struct dsp_obj *pdo, u32 address);
193
194static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
195 u32 length);
196
197static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
198 u32 length);
199
200static void subsys_create_adapter(struct hpi_message *phm,
201 struct hpi_response *phr);
202
203static void subsys_delete_adapter(struct hpi_message *phm,
204 struct hpi_response *phr);
205
206static void adapter_get_asserts(struct hpi_adapter_obj *pao,
207 struct hpi_message *phm, struct hpi_response *phr);
208
209static short create_adapter_obj(struct hpi_adapter_obj *pao,
210 u32 *pos_error_code);
211
212static void delete_adapter_obj(struct hpi_adapter_obj *pao);
213
214
215
216static u16 gw_pci_read_asserts;
217static u16 gw_pci_write_asserts;
218
219static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
220{
221 switch (phm->function) {
222 case HPI_SUBSYS_CREATE_ADAPTER:
223 subsys_create_adapter(phm, phr);
224 break;
225 case HPI_SUBSYS_DELETE_ADAPTER:
226 subsys_delete_adapter(phm, phr);
227 break;
228 default:
229 phr->error = HPI_ERROR_INVALID_FUNC;
230 break;
231 }
232}
233
234static void control_message(struct hpi_adapter_obj *pao,
235 struct hpi_message *phm, struct hpi_response *phr)
236{
237 switch (phm->function) {
238 case HPI_CONTROL_GET_STATE:
239 if (pao->has_control_cache) {
240 u16 err;
241 err = hpi6000_update_control_cache(pao, phm);
242
243 if (err) {
244 if (err >= HPI_ERROR_BACKEND_BASE) {
245 phr->error =
246 HPI_ERROR_CONTROL_CACHING;
247 phr->specific_error = err;
248 } else {
249 phr->error = err;
250 }
251 break;
252 }
253
254 if (hpi_check_control_cache(((struct hpi_hw_obj *)
255 pao->priv)->p_cache, phm,
256 phr))
257 break;
258 }
259 hw_message(pao, phm, phr);
260 break;
261 case HPI_CONTROL_SET_STATE:
262 hw_message(pao, phm, phr);
263 hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj *)pao->
264 priv)->p_cache, phm, phr);
265 break;
266
267 case HPI_CONTROL_GET_INFO:
268 default:
269 hw_message(pao, phm, phr);
270 break;
271 }
272}
273
274static void adapter_message(struct hpi_adapter_obj *pao,
275 struct hpi_message *phm, struct hpi_response *phr)
276{
277 switch (phm->function) {
278 case HPI_ADAPTER_GET_ASSERT:
279 adapter_get_asserts(pao, phm, phr);
280 break;
281
282 default:
283 hw_message(pao, phm, phr);
284 break;
285 }
286}
287
288static void outstream_message(struct hpi_adapter_obj *pao,
289 struct hpi_message *phm, struct hpi_response *phr)
290{
291 switch (phm->function) {
292 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
293 case HPI_OSTREAM_HOSTBUFFER_FREE:
294
295
296
297
298
299 phr->error = HPI_ERROR_INVALID_FUNC;
300 break;
301 default:
302 hw_message(pao, phm, phr);
303 return;
304 }
305}
306
307static void instream_message(struct hpi_adapter_obj *pao,
308 struct hpi_message *phm, struct hpi_response *phr)
309{
310
311 switch (phm->function) {
312 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
313 case HPI_ISTREAM_HOSTBUFFER_FREE:
314
315
316
317
318
319 phr->error = HPI_ERROR_INVALID_FUNC;
320 break;
321 default:
322 hw_message(pao, phm, phr);
323 return;
324 }
325}
326
327
328
329
330
331
332void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
333{
334 struct hpi_adapter_obj *pao = NULL;
335
336
337
338
339
340
341
342 if (phm->object != HPI_OBJ_SUBSYSTEM) {
343 pao = hpi_find_adapter(phm->adapter_index);
344 if (!pao) {
345 HPI_DEBUG_LOG(DEBUG,
346 " %d,%d refused, for another HPI?\n",
347 phm->object, phm->function);
348 return;
349 }
350
351 if (pao->dsp_crashed >= 10) {
352 hpi_init_response(phr, phm->object, phm->function,
353 HPI_ERROR_DSP_HARDWARE);
354 HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n",
355 phm->object, phm->function);
356 return;
357 }
358 }
359
360 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
361 hpi_init_response(phr, phm->object, phm->function,
362 HPI_ERROR_PROCESSING_MESSAGE);
363
364 switch (phm->type) {
365 case HPI_TYPE_MESSAGE:
366 switch (phm->object) {
367 case HPI_OBJ_SUBSYSTEM:
368 subsys_message(phm, phr);
369 break;
370
371 case HPI_OBJ_ADAPTER:
372 phr->size =
373 sizeof(struct hpi_response_header) +
374 sizeof(struct hpi_adapter_res);
375 adapter_message(pao, phm, phr);
376 break;
377
378 case HPI_OBJ_CONTROL:
379 control_message(pao, phm, phr);
380 break;
381
382 case HPI_OBJ_OSTREAM:
383 outstream_message(pao, phm, phr);
384 break;
385
386 case HPI_OBJ_ISTREAM:
387 instream_message(pao, phm, phr);
388 break;
389
390 default:
391 hw_message(pao, phm, phr);
392 break;
393 }
394 break;
395
396 default:
397 phr->error = HPI_ERROR_INVALID_TYPE;
398 break;
399 }
400}
401
402
403
404
405
406
407
408
409
410static void subsys_create_adapter(struct hpi_message *phm,
411 struct hpi_response *phr)
412{
413
414 struct hpi_adapter_obj ao;
415 struct hpi_adapter_obj *pao;
416 u32 os_error_code;
417 u16 err = 0;
418 u32 dsp_index = 0;
419
420 HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
421
422 memset(&ao, 0, sizeof(ao));
423
424 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
425 if (!ao.priv) {
426 HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
427 phr->error = HPI_ERROR_MEMORY_ALLOC;
428 return;
429 }
430
431
432 ao.pci = *phm->u.s.resource.r.pci;
433
434 err = create_adapter_obj(&ao, &os_error_code);
435 if (err) {
436 delete_adapter_obj(&ao);
437 if (err >= HPI_ERROR_BACKEND_BASE) {
438 phr->error = HPI_ERROR_DSP_BOOTLOAD;
439 phr->specific_error = err;
440 } else {
441 phr->error = err;
442 }
443
444 phr->u.s.data = os_error_code;
445 return;
446 }
447
448 pao = hpi_find_adapter(ao.index);
449 if (!pao) {
450
451 HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
452 phr->error = HPI_ERROR_BAD_ADAPTER;
453 return;
454 }
455
456 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
457 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
458 phw->ado[dsp_index].pa_parent_adapter = pao;
459 }
460
461 phr->u.s.adapter_type = ao.adapter_type;
462 phr->u.s.adapter_index = ao.index;
463 phr->error = 0;
464}
465
466static void subsys_delete_adapter(struct hpi_message *phm,
467 struct hpi_response *phr)
468{
469 struct hpi_adapter_obj *pao = NULL;
470
471 pao = hpi_find_adapter(phm->obj_index);
472 if (!pao)
473 return;
474
475 delete_adapter_obj(pao);
476 hpi_delete_adapter(pao);
477 phr->error = 0;
478}
479
480
481static short create_adapter_obj(struct hpi_adapter_obj *pao,
482 u32 *pos_error_code)
483{
484 short boot_error = 0;
485 u32 dsp_index = 0;
486 u32 control_cache_size = 0;
487 u32 control_cache_count = 0;
488 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
489
490
491
492
493 phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
494 phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
495 HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
496 phw->dw2040_HPIDSP);
497
498
499 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
500 phw->ado[dsp_index].prHPI_control =
501 phw->dw2040_HPIDSP + (CONTROL +
502 DSP_SPACING * dsp_index);
503
504 phw->ado[dsp_index].prHPI_address =
505 phw->dw2040_HPIDSP + (ADDRESS +
506 DSP_SPACING * dsp_index);
507 phw->ado[dsp_index].prHPI_data =
508 phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
509
510 phw->ado[dsp_index].prHPI_data_auto_inc =
511 phw->dw2040_HPIDSP + (DATA_AUTOINC +
512 DSP_SPACING * dsp_index);
513
514 HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
515 phw->ado[dsp_index].prHPI_control,
516 phw->ado[dsp_index].prHPI_address,
517 phw->ado[dsp_index].prHPI_data,
518 phw->ado[dsp_index].prHPI_data_auto_inc);
519
520 phw->ado[dsp_index].pa_parent_adapter = pao;
521 }
522
523 phw->pCI2040HPI_error_count = 0;
524 pao->has_control_cache = 0;
525
526
527
528
529 phw->num_dsp = 1;
530
531 boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
532 if (boot_error)
533 return boot_error;
534
535 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
536
537 phw->message_buffer_address_on_dsp = 0L;
538 phw->response_buffer_address_on_dsp = 0L;
539
540
541
542 {
543 struct hpi_message hm;
544 struct hpi_response hr0;
545 struct hpi_response hr1;
546 u16 error = 0;
547
548 HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
549 memset(&hm, 0, sizeof(hm));
550 hm.type = HPI_TYPE_MESSAGE;
551 hm.size = sizeof(struct hpi_message);
552 hm.object = HPI_OBJ_ADAPTER;
553 hm.function = HPI_ADAPTER_GET_INFO;
554 hm.adapter_index = 0;
555 memset(&hr0, 0, sizeof(hr0));
556 memset(&hr1, 0, sizeof(hr1));
557 hr0.size = sizeof(hr0);
558 hr1.size = sizeof(hr1);
559
560 error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
561 if (hr0.error) {
562 HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
563 return hr0.error;
564 }
565 if (phw->num_dsp == 2) {
566 error = hpi6000_message_response_sequence(pao, 1, &hm,
567 &hr1);
568 if (error)
569 return error;
570 }
571 pao->adapter_type = hr0.u.ax.info.adapter_type;
572 pao->index = hr0.u.ax.info.adapter_index;
573 }
574
575 memset(&phw->control_cache[0], 0,
576 sizeof(struct hpi_control_cache_single) *
577 HPI_NMIXER_CONTROLS);
578
579 control_cache_size =
580 hpi_read_word(&phw->ado[0],
581 HPI_HIF_ADDR(control_cache_size_in_bytes));
582 if (control_cache_size) {
583 control_cache_count =
584 hpi_read_word(&phw->ado[0],
585 HPI_HIF_ADDR(control_cache_count));
586
587 phw->p_cache =
588 hpi_alloc_control_cache(control_cache_count,
589 control_cache_size, (unsigned char *)
590 &phw->control_cache[0]
591 );
592 if (phw->p_cache)
593 pao->has_control_cache = 1;
594 }
595
596 HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n",
597 pao->adapter_type, pao->index);
598 pao->open = 0;
599
600 if (phw->p_cache)
601 phw->p_cache->adap_idx = pao->index;
602
603 return hpi_add_adapter(pao);
604}
605
606static void delete_adapter_obj(struct hpi_adapter_obj *pao)
607{
608 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
609
610 if (pao->has_control_cache)
611 hpi_free_control_cache(phw->p_cache);
612
613
614 iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
615
616 kfree(phw);
617}
618
619
620
621
622static void adapter_get_asserts(struct hpi_adapter_obj *pao,
623 struct hpi_message *phm, struct hpi_response *phr)
624{
625#ifndef HIDE_PCI_ASSERTS
626
627 if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
628 phr->u.ax.assert.p1 =
629 gw_pci_read_asserts * 100 + gw_pci_write_asserts;
630 phr->u.ax.assert.p2 = 0;
631 phr->u.ax.assert.count = 1;
632 phr->u.ax.assert.dsp_index = -1;
633 strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
634 phr->u.ax.assert.dsp_msg_addr = 0;
635 gw_pci_read_asserts = 0;
636 gw_pci_write_asserts = 0;
637 phr->error = 0;
638 } else
639#endif
640 hw_message(pao, phm, phr);
641
642 return;
643}
644
645
646
647
648static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
649 u32 *pos_error_code)
650{
651 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
652 short error;
653 u32 timeout;
654 u32 read = 0;
655 u32 i = 0;
656 u32 data = 0;
657 u32 j = 0;
658 u32 test_addr = 0x80000000;
659 u32 test_data = 0x00000001;
660 u32 dw2040_reset = 0;
661 u32 dsp_index = 0;
662 u32 endian = 0;
663 u32 adapter_info = 0;
664 u32 delay = 0;
665
666 struct dsp_code dsp_code;
667 u16 boot_load_family = 0;
668
669
670
671 switch (pao->pci.pci_dev->subsystem_device) {
672 case 0x5100:
673 case 0x5110:
674 case 0x5200:
675 case 0x6100:
676 case 0x6200:
677 boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
678 break;
679 default:
680 return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
681 }
682
683
684
685
686 endian = 0;
687 dw2040_reset = 0x0003000F;
688 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
689
690
691
692
693
694 hpios_delay_micro_seconds(1000);
695 delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
696
697 if (delay != dw2040_reset) {
698 HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
699 delay);
700 return HPI6000_ERROR_INIT_PCI2040;
701 }
702
703
704 iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
705
706
707
708 iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
709
710
711
712
713 dw2040_reset = dw2040_reset & (~(endian << 3));
714 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
715
716 phw->ado[0].c_dsp_rev = 'B';
717 phw->ado[1].c_dsp_rev = 'B';
718
719
720 dw2040_reset = dw2040_reset & (~0x00000001);
721 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
722 dw2040_reset = dw2040_reset & (~0x00000002);
723 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
724
725
726 dw2040_reset = dw2040_reset & (~0x00000008);
727 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
728
729 hpios_delay_micro_seconds(100);
730
731
732 for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
733 struct dsp_obj *pdo = &phw->ado[dsp_index];
734
735
736
737 iowrite32(0x00010001, pdo->prHPI_control);
738
739
740 test_data = 0x00000001;
741 for (j = 0; j < 32; j++) {
742 iowrite32(test_data, pdo->prHPI_address);
743 data = ioread32(pdo->prHPI_address);
744 if (data != test_data) {
745 HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
746 test_data, data, dsp_index);
747 return HPI6000_ERROR_INIT_DSPHPI;
748 }
749 test_data = test_data << 1;
750 }
751
752
753
754
755
756
757
758
759
760 {
761
762
763
764
765
766
767 hpi_write_word(pdo, 0x01B7C100, 0x0000);
768 hpios_delay_micro_seconds(100);
769
770
771
772 hpi_write_word(pdo, 0x01B7C120, 0x8002);
773 hpios_delay_micro_seconds(100);
774
775
776 hpi_write_word(pdo, 0x01B7C11C, 0x8001);
777 hpios_delay_micro_seconds(100);
778
779
780 hpi_write_word(pdo, 0x01B7C118, 0x8000);
781
782
783 hpios_delay_micro_seconds(2000);
784
785
786 hpi_write_word(pdo, 0x01B7C100, 0x0001);
787
788 hpios_delay_micro_seconds(2000);
789 }
790
791
792
793
794
795
796
797
798 for (i = 0; i < 100; i++) {
799 test_addr = 0x00000000;
800 test_data = 0x00000001;
801 for (j = 0; j < 32; j++) {
802 hpi_write_word(pdo, test_addr + i, test_data);
803 data = hpi_read_word(pdo, test_addr + i);
804 if (data != test_data) {
805 HPI_DEBUG_LOG(ERROR,
806 "DSP mem %x %x %x %x\n",
807 test_addr + i, test_data,
808 data, dsp_index);
809
810 return HPI6000_ERROR_INIT_DSPINTMEM;
811 }
812 test_data = test_data << 1;
813 }
814 }
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839 hpi_write_word(pdo, 0x01800000, 0x34A8);
840
841
842
843
844
845
846
847
848
849
850
851
852 hpi_write_word(pdo, 0x01800008, 0x00000030);
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 hpi_write_word(pdo, 0x01800020, 0x001BDF29);
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887 hpi_write_word(pdo, 0x01800018, 0x47117000);
888
889
890 hpi_write_word(pdo, 0x0180001C, 0x00000410);
891
892
893
894
895
896
897
898
899
900
901
902
903
904 {
905 u32 cE1 =
906 (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
907 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
908 hpi_write_word(pdo, 0x01800004, cE1);
909 }
910
911
912 hpios_delay_micro_seconds(1000);
913
914
915 {
916 test_addr = 0x80000000;
917 test_data = 0x00000001;
918
919 for (j = 0; j < 32; j++) {
920 hpi_write_word(pdo, test_addr, test_data);
921 data = hpi_read_word(pdo, test_addr);
922 if (data != test_data) {
923 HPI_DEBUG_LOG(ERROR,
924 "DSP dram %x %x %x %x\n",
925 test_addr, test_data, data,
926 dsp_index);
927
928 return HPI6000_ERROR_INIT_SDRAM1;
929 }
930 test_data = test_data << 1;
931 }
932
933#define DRAM_SIZE_WORDS 0x200000
934#define DRAM_INC 1024
935 test_addr = 0x80000000;
936 test_data = 0x0;
937 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
938 hpi_write_word(pdo, test_addr + i, test_data);
939 test_data++;
940 }
941 test_addr = 0x80000000;
942 test_data = 0x0;
943 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
944 data = hpi_read_word(pdo, test_addr + i);
945 if (data != test_data) {
946 HPI_DEBUG_LOG(ERROR,
947 "DSP dram %x %x %x %x\n",
948 test_addr + i, test_data,
949 data, dsp_index);
950 return HPI6000_ERROR_INIT_SDRAM2;
951 }
952 test_data++;
953 }
954
955 }
956
957
958
959 dsp_code.ps_dev = pao->pci.pci_dev;
960
961 error = hpi_dsp_code_open(boot_load_family, &dsp_code,
962 pos_error_code);
963
964 if (error)
965 return error;
966
967 while (1) {
968 u32 length;
969 u32 address;
970 u32 type;
971 u32 *pcode;
972
973 error = hpi_dsp_code_read_word(&dsp_code, &length);
974 if (error)
975 break;
976 if (length == 0xFFFFFFFF)
977 break;
978
979 error = hpi_dsp_code_read_word(&dsp_code, &address);
980 if (error)
981 break;
982 error = hpi_dsp_code_read_word(&dsp_code, &type);
983 if (error)
984 break;
985 error = hpi_dsp_code_read_block(length, &dsp_code,
986 &pcode);
987 if (error)
988 break;
989 error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
990 address, pcode, length);
991 if (error)
992 break;
993 }
994
995 if (error) {
996 hpi_dsp_code_close(&dsp_code);
997 return error;
998 }
999
1000
1001 hpi_dsp_code_rewind(&dsp_code);
1002 while (1) {
1003 u32 length;
1004 u32 address;
1005 u32 type;
1006 u32 *pcode;
1007
1008 hpi_dsp_code_read_word(&dsp_code, &length);
1009 if (length == 0xFFFFFFFF)
1010 break;
1011
1012 hpi_dsp_code_read_word(&dsp_code, &address);
1013 hpi_dsp_code_read_word(&dsp_code, &type);
1014 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
1015
1016 for (i = 0; i < length; i++) {
1017 data = hpi_read_word(pdo, address);
1018 if (data != *pcode) {
1019 error = HPI6000_ERROR_INIT_VERIFY;
1020 HPI_DEBUG_LOG(ERROR,
1021 "DSP verify %x %x %x %x\n",
1022 address, *pcode, data,
1023 dsp_index);
1024 break;
1025 }
1026 pcode++;
1027 address += 4;
1028 }
1029 if (error)
1030 break;
1031 }
1032 hpi_dsp_code_close(&dsp_code);
1033 if (error)
1034 return error;
1035
1036
1037 {
1038 u32 address = HPI_HIF_ADDR(host_cmd);
1039 for (i = 0; i < 4; i++) {
1040 hpi_write_word(pdo, address, 0);
1041 address += 4;
1042 }
1043 }
1044
1045
1046 hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
1047
1048
1049
1050 if (dsp_index > 0)
1051 hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
1052 adapter_info);
1053
1054
1055 iowrite32(0x00030003, pdo->prHPI_control);
1056 hpios_delay_micro_seconds(10000);
1057
1058
1059
1060
1061
1062
1063
1064
1065 timeout = 2000000;
1066 while (timeout) {
1067 do {
1068 read = hpi_read_word(pdo,
1069 HPI_HIF_ADDR(host_cmd));
1070 } while (--timeout
1071 && hpi6000_check_PCI2040_error_flag(pao,
1072 H6READ));
1073
1074 if (read)
1075 break;
1076
1077
1078
1079
1080
1081
1082 else
1083 hpios_delay_micro_seconds(10000);
1084 }
1085 if (timeout == 0)
1086 return HPI6000_ERROR_INIT_NOACK;
1087
1088
1089
1090 if (dsp_index == 0) {
1091
1092 u32 mask = 0;
1093
1094 adapter_info =
1095 hpi_read_word(pdo,
1096 HPI_HIF_ADDR(adapter_info));
1097 if (HPI_ADAPTER_FAMILY_ASI
1098 (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
1099 (adapter_info)) ==
1100 HPI_ADAPTER_FAMILY_ASI(0x6200))
1101
1102 phw->num_dsp = 2;
1103
1104
1105
1106#define PLD_BASE_ADDRESS 0x90000000L
1107
1108 switch (boot_load_family) {
1109 case HPI_ADAPTER_FAMILY_ASI(0x6200):
1110
1111 mask = 0xFFFFFF00L;
1112
1113
1114 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1115 subsystem_device) ==
1116 HPI_ADAPTER_FAMILY_ASI(0x5100))
1117 mask = 0x00000000L;
1118
1119
1120 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1121 subsystem_device) ==
1122 HPI_ADAPTER_FAMILY_ASI(0x5200))
1123 mask = 0x00000000L;
1124 break;
1125 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1126
1127 mask = 0xFFFF0000L;
1128 break;
1129 }
1130 test_data = 0xAAAAAA00L & mask;
1131
1132 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1133 read = hpi_read_word(pdo,
1134 PLD_BASE_ADDRESS + 4L) & mask;
1135 if (read != test_data) {
1136 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1137 read);
1138 return HPI6000_ERROR_INIT_PLDTEST1;
1139 }
1140 test_data = 0x55555500L & mask;
1141 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1142 read = hpi_read_word(pdo,
1143 PLD_BASE_ADDRESS + 4L) & mask;
1144 if (read != test_data) {
1145 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1146 read);
1147 return HPI6000_ERROR_INIT_PLDTEST2;
1148 }
1149 }
1150 }
1151 return 0;
1152}
1153
1154#define PCI_TIMEOUT 100
1155
1156static int hpi_set_address(struct dsp_obj *pdo, u32 address)
1157{
1158 u32 timeout = PCI_TIMEOUT;
1159
1160 do {
1161 iowrite32(address, pdo->prHPI_address);
1162 } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
1163 H6WRITE)
1164 && --timeout);
1165
1166 if (timeout)
1167 return 0;
1168
1169 return 1;
1170}
1171
1172
1173static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
1174{
1175 if (hpi_set_address(pdo, address))
1176 return;
1177 iowrite32(data, pdo->prHPI_data);
1178}
1179
1180
1181static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
1182{
1183 u32 data = 0;
1184
1185 if (hpi_set_address(pdo, address))
1186 return 0;
1187
1188
1189 data = ioread32(pdo->prHPI_data);
1190 return data;
1191}
1192
1193
1194static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1195 u32 length)
1196{
1197 u16 length16 = length - 1;
1198
1199 if (length == 0)
1200 return;
1201
1202 if (hpi_set_address(pdo, address))
1203 return;
1204
1205 iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1206
1207
1208
1209 iowrite32(*(pdata + length - 1), pdo->prHPI_data);
1210}
1211
1212
1213
1214static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1215 u32 length)
1216{
1217 u16 length16 = length - 1;
1218
1219 if (length == 0)
1220 return;
1221
1222 if (hpi_set_address(pdo, address))
1223 return;
1224
1225 ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1226
1227
1228
1229 *(pdata + length - 1) = ioread32(pdo->prHPI_data);
1230}
1231
1232static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
1233 u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
1234{
1235 struct dsp_obj *pdo =
1236 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1237 u32 time_out = PCI_TIMEOUT;
1238 int c6711_burst_size = 128;
1239 u32 local_hpi_address = hpi_address;
1240 int local_count = count;
1241 int xfer_size;
1242 u32 *pdata = source;
1243
1244 while (local_count) {
1245 if (local_count > c6711_burst_size)
1246 xfer_size = c6711_burst_size;
1247 else
1248 xfer_size = local_count;
1249
1250 time_out = PCI_TIMEOUT;
1251 do {
1252 hpi_write_block(pdo, local_hpi_address, pdata,
1253 xfer_size);
1254 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1255 && --time_out);
1256
1257 if (!time_out)
1258 break;
1259 pdata += xfer_size;
1260 local_hpi_address += sizeof(u32) * xfer_size;
1261 local_count -= xfer_size;
1262 }
1263
1264 if (time_out)
1265 return 0;
1266 else
1267 return 1;
1268}
1269
1270static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
1271 u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
1272{
1273 struct dsp_obj *pdo =
1274 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1275 u32 time_out = PCI_TIMEOUT;
1276 int c6711_burst_size = 16;
1277 u32 local_hpi_address = hpi_address;
1278 int local_count = count;
1279 int xfer_size;
1280 u32 *pdata = dest;
1281 u32 loop_count = 0;
1282
1283 while (local_count) {
1284 if (local_count > c6711_burst_size)
1285 xfer_size = c6711_burst_size;
1286 else
1287 xfer_size = local_count;
1288
1289 time_out = PCI_TIMEOUT;
1290 do {
1291 hpi_read_block(pdo, local_hpi_address, pdata,
1292 xfer_size);
1293 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1294 && --time_out);
1295 if (!time_out)
1296 break;
1297
1298 pdata += xfer_size;
1299 local_hpi_address += sizeof(u32) * xfer_size;
1300 local_count -= xfer_size;
1301 loop_count++;
1302 }
1303
1304 if (time_out)
1305 return 0;
1306 else
1307 return 1;
1308}
1309
1310static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
1311 u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
1312{
1313 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1314 struct dsp_obj *pdo = &phw->ado[dsp_index];
1315 u32 timeout;
1316 u16 ack;
1317 u32 address;
1318 u32 length;
1319 u32 *p_data;
1320 u16 error = 0;
1321
1322 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1323 if (ack & HPI_HIF_ERROR_MASK) {
1324 pao->dsp_crashed++;
1325 return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
1326 }
1327 pao->dsp_crashed = 0;
1328
1329
1330 if (phw->message_buffer_address_on_dsp == 0) {
1331 timeout = TIMEOUT;
1332 do {
1333 address =
1334 hpi_read_word(pdo,
1335 HPI_HIF_ADDR(message_buffer_address));
1336 phw->message_buffer_address_on_dsp = address;
1337 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1338 && --timeout);
1339 if (!timeout)
1340 return HPI6000_ERROR_MSG_GET_ADR;
1341 } else
1342 address = phw->message_buffer_address_on_dsp;
1343
1344 length = phm->size;
1345
1346
1347 p_data = (u32 *)phm;
1348 if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
1349 (u16)length / 4))
1350 return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
1351
1352 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
1353 return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
1354 hpi6000_send_dsp_interrupt(pdo);
1355
1356 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
1357 if (ack & HPI_HIF_ERROR_MASK)
1358 return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
1359
1360
1361 if (phw->response_buffer_address_on_dsp == 0) {
1362 timeout = TIMEOUT;
1363 do {
1364 address =
1365 hpi_read_word(pdo,
1366 HPI_HIF_ADDR(response_buffer_address));
1367 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1368 && --timeout);
1369 phw->response_buffer_address_on_dsp = address;
1370
1371 if (!timeout)
1372 return HPI6000_ERROR_RESP_GET_ADR;
1373 } else
1374 address = phw->response_buffer_address_on_dsp;
1375
1376
1377 timeout = TIMEOUT;
1378 do {
1379 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1380 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1381 if (!timeout)
1382 length = sizeof(struct hpi_response);
1383
1384
1385 p_data = (u32 *)phr;
1386 if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
1387 (u16)length / 4))
1388 return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
1389
1390
1391 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1392 return HPI6000_ERROR_MSG_RESP_IDLECMD;
1393 hpi6000_send_dsp_interrupt(pdo);
1394
1395 error = hpi_validate_response(phm, phr);
1396 return error;
1397}
1398
1399
1400
1401#define MSG_ADDRESS (HPI_HIF_BASE+0x18)
1402#define MSG_LENGTH 11
1403#define RESP_ADDRESS (HPI_HIF_BASE+0x44)
1404#define RESP_LENGTH 16
1405#define QUEUE_START (HPI_HIF_BASE+0x88)
1406#define QUEUE_SIZE 0x8000
1407
1408static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
1409{
1410
1411#ifdef CHECKING
1412 if (address < (u32)MSG_ADDRESS)
1413 return 0;
1414 if (address > (u32)(QUEUE_START + QUEUE_SIZE))
1415 return 0;
1416 if ((address + (length_in_dwords << 2)) >
1417 (u32)(QUEUE_START + QUEUE_SIZE))
1418 return 0;
1419#else
1420 (void)address;
1421 (void)length_in_dwords;
1422 return 1;
1423#endif
1424}
1425
1426static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1427 struct hpi_message *phm, struct hpi_response *phr)
1428{
1429 struct dsp_obj *pdo =
1430 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1431 u32 data_sent = 0;
1432 u16 ack;
1433 u32 length, address;
1434 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1435 u16 time_out = 8;
1436
1437 (void)phr;
1438
1439
1440 while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
1441 && --time_out) {
1442 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1443 if (ack & HPI_HIF_ERROR_MASK)
1444 return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
1445
1446 if (hpi6000_send_host_command(pao, dsp_index,
1447 HPI_HIF_SEND_DATA))
1448 return HPI6000_ERROR_SEND_DATA_CMD;
1449
1450 hpi6000_send_dsp_interrupt(pdo);
1451
1452 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
1453
1454 if (ack & HPI_HIF_ERROR_MASK)
1455 return HPI6000_ERROR_SEND_DATA_ACK;
1456
1457 do {
1458
1459 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1460
1461 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1462 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1463
1464 if (!hpi6000_send_data_check_adr(address, length))
1465 return HPI6000_ERROR_SEND_DATA_ADR;
1466
1467
1468
1469
1470
1471
1472 {
1473 u32 len = length;
1474 u32 blk_len = 512;
1475 while (len) {
1476 if (len < blk_len)
1477 blk_len = len;
1478 if (hpi6000_dsp_block_write32(pao, dsp_index,
1479 address, p_data, blk_len))
1480 return HPI6000_ERROR_SEND_DATA_WRITE;
1481 address += blk_len * 4;
1482 p_data += blk_len;
1483 len -= blk_len;
1484 }
1485 }
1486
1487 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1488 return HPI6000_ERROR_SEND_DATA_IDLECMD;
1489
1490 hpi6000_send_dsp_interrupt(pdo);
1491
1492 data_sent += length * 4;
1493 }
1494 if (!time_out)
1495 return HPI6000_ERROR_SEND_DATA_TIMEOUT;
1496 return 0;
1497}
1498
1499static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1500 struct hpi_message *phm, struct hpi_response *phr)
1501{
1502 struct dsp_obj *pdo =
1503 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1504 u32 data_got = 0;
1505 u16 ack;
1506 u32 length, address;
1507 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1508
1509 (void)phr;
1510
1511
1512 while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
1513 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1514 if (ack & HPI_HIF_ERROR_MASK)
1515 return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
1516
1517 if (hpi6000_send_host_command(pao, dsp_index,
1518 HPI_HIF_GET_DATA))
1519 return HPI6000_ERROR_GET_DATA_CMD;
1520 hpi6000_send_dsp_interrupt(pdo);
1521
1522 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
1523
1524 if (ack & HPI_HIF_ERROR_MASK)
1525 return HPI6000_ERROR_GET_DATA_ACK;
1526
1527
1528 do {
1529 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1530 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1531 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1532
1533
1534 {
1535 u32 len = length;
1536 u32 blk_len = 512;
1537 while (len) {
1538 if (len < blk_len)
1539 blk_len = len;
1540 if (hpi6000_dsp_block_read32(pao, dsp_index,
1541 address, p_data, blk_len))
1542 return HPI6000_ERROR_GET_DATA_READ;
1543 address += blk_len * 4;
1544 p_data += blk_len;
1545 len -= blk_len;
1546 }
1547 }
1548
1549 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1550 return HPI6000_ERROR_GET_DATA_IDLECMD;
1551 hpi6000_send_dsp_interrupt(pdo);
1552
1553 data_got += length * 4;
1554 }
1555 return 0;
1556}
1557
1558static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
1559{
1560 iowrite32(0x00030003, pdo->prHPI_control);
1561}
1562
1563static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
1564 u16 dsp_index, u32 host_cmd)
1565{
1566 struct dsp_obj *pdo =
1567 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1568 u32 timeout = TIMEOUT;
1569
1570
1571 do {
1572 hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
1573
1574 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1575 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
1576
1577
1578 iowrite32(0x00040004, pdo->prHPI_control);
1579
1580 if (timeout)
1581 return 0;
1582 else
1583 return 1;
1584}
1585
1586
1587static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
1588 u16 read_or_write)
1589{
1590 u32 hPI_error;
1591
1592 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1593
1594
1595 hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1596 if (hPI_error) {
1597
1598 iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1599 phw->pCI2040HPI_error_count++;
1600 if (read_or_write == 1)
1601 gw_pci_read_asserts++;
1602 else
1603 gw_pci_write_asserts++;
1604 return 1;
1605 } else
1606 return 0;
1607}
1608
1609static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
1610 u32 ack_value)
1611{
1612 struct dsp_obj *pdo =
1613 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1614 u32 ack = 0L;
1615 u32 timeout;
1616 u32 hPIC = 0L;
1617
1618
1619 timeout = TIMEOUT;
1620 while (--timeout) {
1621 hPIC = ioread32(pdo->prHPI_control);
1622 if (hPIC & 0x04)
1623 break;
1624 }
1625 if (timeout == 0)
1626 return HPI_HIF_ERROR_MASK;
1627
1628
1629 timeout = TIMEOUT;
1630 while (--timeout) {
1631
1632 ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
1633 if (ack == ack_value)
1634 break;
1635 if ((ack & HPI_HIF_ERROR_MASK)
1636 && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
1637 break;
1638
1639
1640 }
1641 if (ack & HPI_HIF_ERROR_MASK)
1642
1643
1644 ack = HPI_HIF_ERROR_MASK;
1645
1646 if (timeout == 0)
1647 ack = HPI_HIF_ERROR_MASK;
1648 return (short)ack;
1649}
1650
1651static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
1652 struct hpi_message *phm)
1653{
1654 const u16 dsp_index = 0;
1655 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1656 struct dsp_obj *pdo = &phw->ado[dsp_index];
1657 u32 timeout;
1658 u32 cache_dirty_flag;
1659 u16 err;
1660
1661 hpios_dsplock_lock(pao);
1662
1663 timeout = TIMEOUT;
1664 do {
1665 cache_dirty_flag =
1666 hpi_read_word((struct dsp_obj *)pdo,
1667 HPI_HIF_ADDR(control_cache_is_dirty));
1668 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1669 if (!timeout) {
1670 err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
1671 goto unlock;
1672 }
1673
1674 if (cache_dirty_flag) {
1675
1676 u32 address;
1677 u32 length;
1678
1679 timeout = TIMEOUT;
1680 if (pdo->control_cache_address_on_dsp == 0) {
1681 do {
1682 address =
1683 hpi_read_word((struct dsp_obj *)pdo,
1684 HPI_HIF_ADDR(control_cache_address));
1685
1686 length = hpi_read_word((struct dsp_obj *)pdo,
1687 HPI_HIF_ADDR
1688 (control_cache_size_in_bytes));
1689 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1690 && --timeout);
1691 if (!timeout) {
1692 err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
1693 goto unlock;
1694 }
1695 pdo->control_cache_address_on_dsp = address;
1696 pdo->control_cache_length_on_dsp = length;
1697 } else {
1698 address = pdo->control_cache_address_on_dsp;
1699 length = pdo->control_cache_length_on_dsp;
1700 }
1701
1702 if (hpi6000_dsp_block_read32(pao, dsp_index, address,
1703 (u32 *)&phw->control_cache[0],
1704 length / sizeof(u32))) {
1705 err = HPI6000_ERROR_CONTROL_CACHE_READ;
1706 goto unlock;
1707 }
1708 do {
1709 hpi_write_word((struct dsp_obj *)pdo,
1710 HPI_HIF_ADDR(control_cache_is_dirty), 0);
1711
1712 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1713 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1714 && --timeout);
1715 if (!timeout) {
1716 err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
1717 goto unlock;
1718 }
1719
1720 }
1721 err = 0;
1722
1723unlock:
1724 hpios_dsplock_unlock(pao);
1725 return err;
1726}
1727
1728
1729static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
1730{
1731 u16 ret = 0;
1732 switch (phm->object) {
1733 case HPI_OBJ_ISTREAM:
1734 if (phm->obj_index < 2)
1735 ret = 1;
1736 break;
1737 case HPI_OBJ_PROFILE:
1738 ret = phm->obj_index;
1739 break;
1740 default:
1741 break;
1742 }
1743 return ret;
1744}
1745
1746
1747
1748
1749
1750static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
1751 struct hpi_response *phr)
1752{
1753 u16 error = 0;
1754 u16 dsp_index = 0;
1755 u16 num_dsp = ((struct hpi_hw_obj *)pao->priv)->num_dsp;
1756
1757 if (num_dsp < 2)
1758 dsp_index = 0;
1759 else {
1760 dsp_index = get_dsp_index(pao, phm);
1761
1762
1763 if ((phm->function == HPI_ISTREAM_GROUP_ADD)
1764 || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
1765 struct hpi_message hm;
1766 u16 add_index;
1767 hm.obj_index = phm->u.d.u.stream.stream_index;
1768 hm.object = phm->u.d.u.stream.object_type;
1769 add_index = get_dsp_index(pao, &hm);
1770 if (add_index != dsp_index) {
1771 phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
1772 return;
1773 }
1774 }
1775 }
1776
1777 hpios_dsplock_lock(pao);
1778 error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
1779
1780 if (error)
1781 goto err;
1782
1783 if (phr->error)
1784 goto out;
1785
1786 switch (phm->function) {
1787 case HPI_OSTREAM_WRITE:
1788 case HPI_ISTREAM_ANC_WRITE:
1789 error = hpi6000_send_data(pao, dsp_index, phm, phr);
1790 break;
1791 case HPI_ISTREAM_READ:
1792 case HPI_OSTREAM_ANC_READ:
1793 error = hpi6000_get_data(pao, dsp_index, phm, phr);
1794 break;
1795 case HPI_ADAPTER_GET_ASSERT:
1796 phr->u.ax.assert.dsp_index = 0;
1797 if (num_dsp == 2) {
1798 if (!phr->u.ax.assert.count) {
1799
1800 error = hpi6000_message_response_sequence(pao,
1801 1, phm, phr);
1802 phr->u.ax.assert.dsp_index = 1;
1803 }
1804 }
1805 }
1806
1807err:
1808 if (error) {
1809 if (error >= HPI_ERROR_BACKEND_BASE) {
1810 phr->error = HPI_ERROR_DSP_COMMUNICATION;
1811 phr->specific_error = error;
1812 } else {
1813 phr->error = error;
1814 }
1815
1816
1817 phr->size = sizeof(struct hpi_response_header);
1818 }
1819out:
1820 hpios_dsplock_unlock(pao);
1821 return;
1822}
1823