blob: 43465832a910ff39533b6abb5ef9612e2f8f86e9 [file] [log] [blame]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001/******************************************************************************
2
3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Hardware Programming Interface (HPI) for AudioScience ASI6200 series adapters.
20 These PCI bus adapters are based on the TI C6711 DSP.
21
22 Exported functions:
23 void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
24
25 #defines
26 HIDE_PCI_ASSERTS to show the PCI asserts
27 PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
28
29(C) Copyright AudioScience Inc. 1998-2003
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) /* start of C67xx internal RAM */
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/* HPI6000 specific error codes */
Eliot Blennerhassett1528fbb2011-02-10 17:26:02 +130046#define HPI6000_ERROR_BASE 900 /* not actually used anywhere */
47
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +130048/* operational/messaging errors */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020049#define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +130050
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020051#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
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +130056
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020057#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
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020066
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
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020079
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +130080/* Initialisation/bootload errors */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020081#define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
82
83/* can't access PCI2040 */
84#define HPI6000_ERROR_INIT_PCI2040 931
85/* can't access DSP HPI i/f */
86#define HPI6000_ERROR_INIT_DSPHPI 932
87/* can't access internal DSP memory */
88#define HPI6000_ERROR_INIT_DSPINTMEM 933
89/* can't access SDRAM - test#1 */
90#define HPI6000_ERROR_INIT_SDRAM1 934
91/* can't access SDRAM - test#2 */
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/* local defines */
102
103#define HIDE_PCI_ASSERTS
104#define PROFILE_DSP2
105
106/* for PCI2040 i/f chip */
107/* HPI CSR registers */
108/* word offsets from CSR base */
109/* use when io addresses defined as u32 * */
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/* HPI registers, spaced 8K bytes = 2K words apart */
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; /*A, B */
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
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300212static void delete_adapter_obj(struct hpi_adapter_obj *pao);
213
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200214/* local globals */
215
216static u16 gw_pci_read_asserts; /* used to count PCI2040 errors */
217static u16 gw_pci_write_asserts; /* used to count PCI2040 errors */
218
219static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
220{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200221 switch (phm->function) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200222 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{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200237 switch (phm->function) {
238 case HPI_CONTROL_GET_STATE:
239 if (pao->has_control_cache) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300240 phr->error = hpi6000_update_control_cache(pao, phm);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200241
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300242 if (phr->error)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200243 break;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200244
245 if (hpi_check_control_cache(((struct hpi_hw_obj *)
246 pao->priv)->p_cache, phm,
247 phr))
248 break;
249 }
250 hw_message(pao, phm, phr);
251 break;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200252 case HPI_CONTROL_SET_STATE:
253 hw_message(pao, phm, phr);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300254 hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj *)pao->
255 priv)->p_cache, phm, phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200256 break;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300257
258 case HPI_CONTROL_GET_INFO:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200259 default:
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300260 hw_message(pao, phm, phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200261 break;
262 }
263}
264
265static void adapter_message(struct hpi_adapter_obj *pao,
266 struct hpi_message *phm, struct hpi_response *phr)
267{
268 switch (phm->function) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200269 case HPI_ADAPTER_GET_ASSERT:
270 adapter_get_asserts(pao, phm, phr);
271 break;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300272
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200273 default:
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300274 hw_message(pao, phm, phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200275 break;
276 }
277}
278
279static void outstream_message(struct hpi_adapter_obj *pao,
280 struct hpi_message *phm, struct hpi_response *phr)
281{
282 switch (phm->function) {
283 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
284 case HPI_OSTREAM_HOSTBUFFER_FREE:
285 /* Don't let these messages go to the HW function because
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300286 * they're called without locking the spinlock.
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200287 * For the HPI6000 adapters the HW would return
288 * HPI_ERROR_INVALID_FUNC anyway.
289 */
290 phr->error = HPI_ERROR_INVALID_FUNC;
291 break;
292 default:
293 hw_message(pao, phm, phr);
294 return;
295 }
296}
297
298static void instream_message(struct hpi_adapter_obj *pao,
299 struct hpi_message *phm, struct hpi_response *phr)
300{
301
302 switch (phm->function) {
303 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
304 case HPI_ISTREAM_HOSTBUFFER_FREE:
305 /* Don't let these messages go to the HW function because
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300306 * they're called without locking the spinlock.
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200307 * For the HPI6000 adapters the HW would return
308 * HPI_ERROR_INVALID_FUNC anyway.
309 */
310 phr->error = HPI_ERROR_INVALID_FUNC;
311 break;
312 default:
313 hw_message(pao, phm, phr);
314 return;
315 }
316}
317
318/************************************************************************/
319/** HPI_6000()
320 * Entry point from HPIMAN
321 * All calls to the HPI start here
322 */
323void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
324{
325 struct hpi_adapter_obj *pao = NULL;
326
327 /* subsytem messages get executed by every HPI. */
328 /* All other messages are ignored unless the adapter index matches */
329 /* an adapter in the HPI */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300330 /*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200331
332 /* if Dsp has crashed then do not communicate with it any more */
333 if (phm->object != HPI_OBJ_SUBSYSTEM) {
334 pao = hpi_find_adapter(phm->adapter_index);
335 if (!pao) {
336 HPI_DEBUG_LOG(DEBUG,
337 " %d,%d refused, for another HPI?\n",
338 phm->object, phm->function);
339 return;
340 }
341
342 if (pao->dsp_crashed >= 10) {
343 hpi_init_response(phr, phm->object, phm->function,
344 HPI_ERROR_DSP_HARDWARE);
345 HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n",
346 phm->object, phm->function);
347 return;
348 }
349 }
350 /* Init default response including the size field */
351 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
352 hpi_init_response(phr, phm->object, phm->function,
353 HPI_ERROR_PROCESSING_MESSAGE);
354
355 switch (phm->type) {
356 case HPI_TYPE_MESSAGE:
357 switch (phm->object) {
358 case HPI_OBJ_SUBSYSTEM:
359 subsys_message(phm, phr);
360 break;
361
362 case HPI_OBJ_ADAPTER:
363 phr->size =
364 sizeof(struct hpi_response_header) +
365 sizeof(struct hpi_adapter_res);
366 adapter_message(pao, phm, phr);
367 break;
368
369 case HPI_OBJ_CONTROL:
370 control_message(pao, phm, phr);
371 break;
372
373 case HPI_OBJ_OSTREAM:
374 outstream_message(pao, phm, phr);
375 break;
376
377 case HPI_OBJ_ISTREAM:
378 instream_message(pao, phm, phr);
379 break;
380
381 default:
382 hw_message(pao, phm, phr);
383 break;
384 }
385 break;
386
387 default:
388 phr->error = HPI_ERROR_INVALID_TYPE;
389 break;
390 }
391}
392
393/************************************************************************/
394/* SUBSYSTEM */
395
396/* create an adapter object and initialise it based on resource information
397 * passed in in the message
398 * NOTE - you cannot use this function AND the FindAdapters function at the
399 * same time, the application must use only one of them to get the adapters
400 */
401static void subsys_create_adapter(struct hpi_message *phm,
402 struct hpi_response *phr)
403{
404 /* create temp adapter obj, because we don't know what index yet */
405 struct hpi_adapter_obj ao;
406 struct hpi_adapter_obj *pao;
407 u32 os_error_code;
408 short error = 0;
409 u32 dsp_index = 0;
410
411 HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
412
413 memset(&ao, 0, sizeof(ao));
414
Julia Lawall550a8b62010-05-13 21:58:37 +0200415 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200416 if (!ao.priv) {
417 HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
418 phr->error = HPI_ERROR_MEMORY_ALLOC;
419 return;
420 }
421
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200422 /* create the adapter object based on the resource information */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200423 ao.pci = *phm->u.s.resource.r.pci;
424
425 error = create_adapter_obj(&ao, &os_error_code);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200426 if (error) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300427 delete_adapter_obj(&ao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200428 phr->error = error;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300429 phr->u.s.data = os_error_code;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200430 return;
431 }
432 /* need to update paParentAdapter */
433 pao = hpi_find_adapter(ao.index);
434 if (!pao) {
435 /* We just added this adapter, why can't we find it!? */
436 HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
437 phr->error = 950;
438 return;
439 }
440
441 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
442 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
443 phw->ado[dsp_index].pa_parent_adapter = pao;
444 }
445
446 phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type;
447 phr->u.s.adapter_index = ao.index;
448 phr->u.s.num_adapters++;
449 phr->error = 0;
450}
451
452static void subsys_delete_adapter(struct hpi_message *phm,
453 struct hpi_response *phr)
454{
455 struct hpi_adapter_obj *pao = NULL;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200456
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300457 pao = hpi_find_adapter(phm->obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200458 if (!pao)
459 return;
460
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300461 delete_adapter_obj(pao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200462 hpi_delete_adapter(pao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200463 phr->error = 0;
464}
465
466/* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
467static short create_adapter_obj(struct hpi_adapter_obj *pao,
468 u32 *pos_error_code)
469{
470 short boot_error = 0;
471 u32 dsp_index = 0;
472 u32 control_cache_size = 0;
473 u32 control_cache_count = 0;
474 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
475
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200476 /* The PCI2040 has the following address map */
477 /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
478 /* BAR1 - 32K = HPI registers on DSP */
479 phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
480 phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
481 HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
482 phw->dw2040_HPIDSP);
483
484 /* set addresses for the possible DSP HPI interfaces */
485 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
486 phw->ado[dsp_index].prHPI_control =
487 phw->dw2040_HPIDSP + (CONTROL +
488 DSP_SPACING * dsp_index);
489
490 phw->ado[dsp_index].prHPI_address =
491 phw->dw2040_HPIDSP + (ADDRESS +
492 DSP_SPACING * dsp_index);
493 phw->ado[dsp_index].prHPI_data =
494 phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
495
496 phw->ado[dsp_index].prHPI_data_auto_inc =
497 phw->dw2040_HPIDSP + (DATA_AUTOINC +
498 DSP_SPACING * dsp_index);
499
500 HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
501 phw->ado[dsp_index].prHPI_control,
502 phw->ado[dsp_index].prHPI_address,
503 phw->ado[dsp_index].prHPI_data,
504 phw->ado[dsp_index].prHPI_data_auto_inc);
505
506 phw->ado[dsp_index].pa_parent_adapter = pao;
507 }
508
509 phw->pCI2040HPI_error_count = 0;
510 pao->has_control_cache = 0;
511
512 /* Set the default number of DSPs on this card */
513 /* This is (conditionally) adjusted after bootloading */
514 /* of the first DSP in the bootload section. */
515 phw->num_dsp = 1;
516
517 boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
518 if (boot_error)
519 return boot_error;
520
521 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
522
523 phw->message_buffer_address_on_dsp = 0L;
524 phw->response_buffer_address_on_dsp = 0L;
525
526 /* get info about the adapter by asking the adapter */
527 /* send a HPI_ADAPTER_GET_INFO message */
528 {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300529 struct hpi_message hm;
530 struct hpi_response hr0; /* response from DSP 0 */
531 struct hpi_response hr1; /* response from DSP 1 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200532 u16 error = 0;
533
534 HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300535 memset(&hm, 0, sizeof(hm));
536 hm.type = HPI_TYPE_MESSAGE;
537 hm.size = sizeof(struct hpi_message);
538 hm.object = HPI_OBJ_ADAPTER;
539 hm.function = HPI_ADAPTER_GET_INFO;
540 hm.adapter_index = 0;
541 memset(&hr0, 0, sizeof(hr0));
542 memset(&hr1, 0, sizeof(hr1));
543 hr0.size = sizeof(hr0);
544 hr1.size = sizeof(hr1);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200545
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300546 error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
547 if (hr0.error) {
548 HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
549 return hr0.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200550 }
551 if (phw->num_dsp == 2) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300552 error = hpi6000_message_response_sequence(pao, 1, &hm,
553 &hr1);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200554 if (error)
555 return error;
556 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300557 pao->adapter_type = hr0.u.ax.info.adapter_type;
558 pao->index = hr0.u.ax.info.adapter_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200559 }
560
561 memset(&phw->control_cache[0], 0,
562 sizeof(struct hpi_control_cache_single) *
563 HPI_NMIXER_CONTROLS);
564 /* Read the control cache length to figure out if it is turned on */
565 control_cache_size =
566 hpi_read_word(&phw->ado[0],
567 HPI_HIF_ADDR(control_cache_size_in_bytes));
568 if (control_cache_size) {
569 control_cache_count =
570 hpi_read_word(&phw->ado[0],
571 HPI_HIF_ADDR(control_cache_count));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200572
573 phw->p_cache =
574 hpi_alloc_control_cache(control_cache_count,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300575 control_cache_size, (unsigned char *)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200576 &phw->control_cache[0]
577 );
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300578 if (phw->p_cache)
579 pao->has_control_cache = 1;
580 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200581
582 HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n",
583 pao->adapter_type, pao->index);
584 pao->open = 0; /* upon creation the adapter is closed */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300585
Eliot Blennerhassettffdb5782011-02-10 17:26:00 +1300586 if (phw->p_cache)
587 phw->p_cache->adap_idx = pao->index;
588
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300589 return hpi_add_adapter(pao);
590}
591
592static void delete_adapter_obj(struct hpi_adapter_obj *pao)
593{
594 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
595
596 if (pao->has_control_cache)
597 hpi_free_control_cache(phw->p_cache);
598
599 /* reset DSPs on adapter */
600 iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
601
602 kfree(phw);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200603}
604
605/************************************************************************/
606/* ADAPTER */
607
608static void adapter_get_asserts(struct hpi_adapter_obj *pao,
609 struct hpi_message *phm, struct hpi_response *phr)
610{
611#ifndef HIDE_PCI_ASSERTS
612 /* if we have PCI2040 asserts then collect them */
613 if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300614 phr->u.ax.assert.p1 =
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200615 gw_pci_read_asserts * 100 + gw_pci_write_asserts;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300616 phr->u.ax.assert.p2 = 0;
617 phr->u.ax.assert.count = 1; /* assert count */
618 phr->u.ax.assert.dsp_index = -1; /* "dsp index" */
619 strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
620 phr->u.ax.assert.dsp_msg_addr = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200621 gw_pci_read_asserts = 0;
622 gw_pci_write_asserts = 0;
623 phr->error = 0;
624 } else
625#endif
626 hw_message(pao, phm, phr); /*get DSP asserts */
627
628 return;
629}
630
631/************************************************************************/
632/* LOW-LEVEL */
633
634static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
635 u32 *pos_error_code)
636{
637 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
638 short error;
639 u32 timeout;
640 u32 read = 0;
641 u32 i = 0;
642 u32 data = 0;
643 u32 j = 0;
644 u32 test_addr = 0x80000000;
645 u32 test_data = 0x00000001;
646 u32 dw2040_reset = 0;
647 u32 dsp_index = 0;
648 u32 endian = 0;
649 u32 adapter_info = 0;
650 u32 delay = 0;
651
652 struct dsp_code dsp_code;
653 u16 boot_load_family = 0;
654
655 /* NOTE don't use wAdapterType in this routine. It is not setup yet */
656
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300657 switch (pao->pci.pci_dev->subsystem_device) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200658 case 0x5100:
659 case 0x5110: /* ASI5100 revB or higher with C6711D */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300660 case 0x5200: /* ASI5200 PCIe version of ASI5100 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200661 case 0x6100:
662 case 0x6200:
663 boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
664 break;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200665 default:
666 return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
667 }
668
669 /* reset all DSPs, indicate two DSPs are present
670 * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
671 */
672 endian = 0;
673 dw2040_reset = 0x0003000F;
674 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
675
676 /* read back register to make sure PCI2040 chip is functioning
677 * note that bits 4..15 are read-only and so should always return zero,
678 * even though we wrote 1 to them
679 */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300680 hpios_delay_micro_seconds(1000);
681 delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
682
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200683 if (delay != dw2040_reset) {
684 HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
685 delay);
686 return HPI6000_ERROR_INIT_PCI2040;
687 }
688
689 /* Indicate that DSP#0,1 is a C6X */
690 iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
691 /* set Bit30 and 29 - which will prevent Target aborts from being
692 * issued upon HPI or GP error
693 */
694 iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
695
696 /* isolate DSP HAD8 line from PCI2040 so that
697 * Little endian can be set by pullup
698 */
699 dw2040_reset = dw2040_reset & (~(endian << 3));
700 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
701
702 phw->ado[0].c_dsp_rev = 'B'; /* revB */
703 phw->ado[1].c_dsp_rev = 'B'; /* revB */
704
705 /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
706 dw2040_reset = dw2040_reset & (~0x00000001); /* start DSP 0 */
707 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
708 dw2040_reset = dw2040_reset & (~0x00000002); /* start DSP 1 */
709 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
710
711 /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
712 dw2040_reset = dw2040_reset & (~0x00000008);
713 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
714 /*delay to allow DSP to get going */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300715 hpios_delay_micro_seconds(100);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200716
717 /* loop through all DSPs, downloading DSP code */
718 for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
719 struct dsp_obj *pdo = &phw->ado[dsp_index];
720
721 /* configure DSP so that we download code into the SRAM */
722 /* set control reg for little endian, HWOB=1 */
723 iowrite32(0x00010001, pdo->prHPI_control);
724
725 /* test access to the HPI address register (HPIA) */
726 test_data = 0x00000001;
727 for (j = 0; j < 32; j++) {
728 iowrite32(test_data, pdo->prHPI_address);
729 data = ioread32(pdo->prHPI_address);
730 if (data != test_data) {
731 HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
732 test_data, data, dsp_index);
733 return HPI6000_ERROR_INIT_DSPHPI;
734 }
735 test_data = test_data << 1;
736 }
737
738/* if C6713 the setup PLL to generate 225MHz from 25MHz.
739* Since the PLLDIV1 read is sometimes wrong, even on a C6713,
740* we're going to do this unconditionally
741*/
742/* PLLDIV1 should have a value of 8000 after reset */
743/*
744 if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
745*/
746 {
747 /* C6713 datasheet says we cannot program PLL from HPI,
748 * and indeed if we try to set the PLL multiply from the
749 * HPI, the PLL does not seem to lock,
750 * so we enable the PLL and use the default of x 7
751 */
752 /* bypass PLL */
753 hpi_write_word(pdo, 0x01B7C100, 0x0000);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300754 hpios_delay_micro_seconds(100);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200755
756 /* ** use default of PLL x7 ** */
757 /* EMIF = 225/3=75MHz */
758 hpi_write_word(pdo, 0x01B7C120, 0x8002);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300759 hpios_delay_micro_seconds(100);
760
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200761 /* peri = 225/2 */
762 hpi_write_word(pdo, 0x01B7C11C, 0x8001);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300763 hpios_delay_micro_seconds(100);
764
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200765 /* cpu = 225/1 */
766 hpi_write_word(pdo, 0x01B7C118, 0x8000);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300767
768 /* ~2ms delay */
769 hpios_delay_micro_seconds(2000);
770
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200771 /* PLL not bypassed */
772 hpi_write_word(pdo, 0x01B7C100, 0x0001);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300773 /* ~2ms delay */
774 hpios_delay_micro_seconds(2000);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200775 }
776
777 /* test r/w to internal DSP memory
778 * C6711 has L2 cache mapped to 0x0 when reset
779 *
780 * revB - because of bug 3.0.1 last HPI read
781 * (before HPI address issued) must be non-autoinc
782 */
783 /* test each bit in the 32bit word */
784 for (i = 0; i < 100; i++) {
785 test_addr = 0x00000000;
786 test_data = 0x00000001;
787 for (j = 0; j < 32; j++) {
788 hpi_write_word(pdo, test_addr + i, test_data);
789 data = hpi_read_word(pdo, test_addr + i);
790 if (data != test_data) {
791 HPI_DEBUG_LOG(ERROR,
792 "DSP mem %x %x %x %x\n",
793 test_addr + i, test_data,
794 data, dsp_index);
795
796 return HPI6000_ERROR_INIT_DSPINTMEM;
797 }
798 test_data = test_data << 1;
799 }
800 }
801
802 /* memory map of ASI6200
803 00000000-0000FFFF 16Kx32 internal program
804 01800000-019FFFFF Internal peripheral
805 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
806 90000000-9000FFFF CE1 Async peripherals:
807
808 EMIF config
809 ------------
810 Global EMIF control
811 0 -
812 1 -
813 2 -
814 3 CLK2EN = 1 CLKOUT2 enabled
815 4 CLK1EN = 0 CLKOUT1 disabled
816 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
817 6 -
818 7 NOHOLD = 1 external HOLD disabled
819 8 HOLDA = 0 HOLDA output is low
820 9 HOLD = 0 HOLD input is low
821 10 ARDY = 1 ARDY input is high
822 11 BUSREQ = 0 BUSREQ output is low
823 12,13 Reserved = 1
824 */
825 hpi_write_word(pdo, 0x01800000, 0x34A8);
826
827 /* EMIF CE0 setup - 2Mx32 Sync DRAM
828 31..28 Wr setup
829 27..22 Wr strobe
830 21..20 Wr hold
831 19..16 Rd setup
832 15..14 -
833 13..8 Rd strobe
834 7..4 MTYPE 0011 Sync DRAM 32bits
835 3 Wr hold MSB
836 2..0 Rd hold
837 */
838 hpi_write_word(pdo, 0x01800008, 0x00000030);
839
840 /* EMIF SDRAM Extension
841 31-21 0
842 20 WR2RD = 0
843 19-18 WR2DEAC = 1
844 17 WR2WR = 0
845 16-15 R2WDQM = 2
846 14-12 RD2WR = 4
847 11-10 RD2DEAC = 1
848 9 RD2RD = 1
849 8-7 THZP = 10b
850 6-5 TWR = 2-1 = 01b (tWR = 10ns)
851 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
852 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
853 1 CAS latency = 3 ECLK
854 (for Micron 2M32-7 operating at 100Mhz)
855 */
856
857 /* need to use this else DSP code crashes */
858 hpi_write_word(pdo, 0x01800020, 0x001BDF29);
859
860 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
861 31 - -
862 30 SDBSZ 1 4 bank
863 29..28 SDRSZ 00 11 row address pins
864 27..26 SDCSZ 01 8 column address pins
865 25 RFEN 1 refersh enabled
866 24 INIT 1 init SDRAM
867 23..20 TRCD 0001
868 19..16 TRP 0001
869 15..12 TRC 0110
870 11..0 - -
871 */
872 /* need to use this else DSP code crashes */
873 hpi_write_word(pdo, 0x01800018, 0x47117000);
874
875 /* EMIF SDRAM Refresh Timing */
876 hpi_write_word(pdo, 0x0180001C, 0x00000410);
877
878 /*MIF CE1 setup - Async peripherals
879 @100MHz bus speed, each cycle is 10ns,
880 31..28 Wr setup = 1
881 27..22 Wr strobe = 3 30ns
882 21..20 Wr hold = 1
883 19..16 Rd setup =1
884 15..14 Ta = 2
885 13..8 Rd strobe = 3 30ns
886 7..4 MTYPE 0010 Async 32bits
887 3 Wr hold MSB =0
888 2..0 Rd hold = 1
889 */
890 {
891 u32 cE1 =
892 (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
893 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
894 hpi_write_word(pdo, 0x01800004, cE1);
895 }
896
897 /* delay a little to allow SDRAM and DSP to "get going" */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300898 hpios_delay_micro_seconds(1000);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200899
900 /* test access to SDRAM */
901 {
902 test_addr = 0x80000000;
903 test_data = 0x00000001;
904 /* test each bit in the 32bit word */
905 for (j = 0; j < 32; j++) {
906 hpi_write_word(pdo, test_addr, test_data);
907 data = hpi_read_word(pdo, test_addr);
908 if (data != test_data) {
909 HPI_DEBUG_LOG(ERROR,
910 "DSP dram %x %x %x %x\n",
911 test_addr, test_data, data,
912 dsp_index);
913
914 return HPI6000_ERROR_INIT_SDRAM1;
915 }
916 test_data = test_data << 1;
917 }
918 /* test every Nth address in the DRAM */
919#define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
920#define DRAM_INC 1024
921 test_addr = 0x80000000;
922 test_data = 0x0;
923 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
924 hpi_write_word(pdo, test_addr + i, test_data);
925 test_data++;
926 }
927 test_addr = 0x80000000;
928 test_data = 0x0;
929 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
930 data = hpi_read_word(pdo, test_addr + i);
931 if (data != test_data) {
932 HPI_DEBUG_LOG(ERROR,
933 "DSP dram %x %x %x %x\n",
934 test_addr + i, test_data,
935 data, dsp_index);
936 return HPI6000_ERROR_INIT_SDRAM2;
937 }
938 test_data++;
939 }
940
941 }
942
943 /* write the DSP code down into the DSPs memory */
944 /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300945 dsp_code.ps_dev = pao->pci.pci_dev;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200946
947 error = hpi_dsp_code_open(boot_load_family, &dsp_code,
948 pos_error_code);
949
950 if (error)
951 return error;
952
953 while (1) {
954 u32 length;
955 u32 address;
956 u32 type;
957 u32 *pcode;
958
959 error = hpi_dsp_code_read_word(&dsp_code, &length);
960 if (error)
961 break;
962 if (length == 0xFFFFFFFF)
963 break; /* end of code */
964
965 error = hpi_dsp_code_read_word(&dsp_code, &address);
966 if (error)
967 break;
968 error = hpi_dsp_code_read_word(&dsp_code, &type);
969 if (error)
970 break;
971 error = hpi_dsp_code_read_block(length, &dsp_code,
972 &pcode);
973 if (error)
974 break;
975 error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
976 address, pcode, length);
977 if (error)
978 break;
979 }
980
981 if (error) {
982 hpi_dsp_code_close(&dsp_code);
983 return error;
984 }
985 /* verify that code was written correctly */
986 /* this time through, assume no errors in DSP code file/array */
987 hpi_dsp_code_rewind(&dsp_code);
988 while (1) {
989 u32 length;
990 u32 address;
991 u32 type;
992 u32 *pcode;
993
994 hpi_dsp_code_read_word(&dsp_code, &length);
995 if (length == 0xFFFFFFFF)
996 break; /* end of code */
997
998 hpi_dsp_code_read_word(&dsp_code, &address);
999 hpi_dsp_code_read_word(&dsp_code, &type);
1000 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
1001
1002 for (i = 0; i < length; i++) {
1003 data = hpi_read_word(pdo, address);
1004 if (data != *pcode) {
1005 error = HPI6000_ERROR_INIT_VERIFY;
1006 HPI_DEBUG_LOG(ERROR,
1007 "DSP verify %x %x %x %x\n",
1008 address, *pcode, data,
1009 dsp_index);
1010 break;
1011 }
1012 pcode++;
1013 address += 4;
1014 }
1015 if (error)
1016 break;
1017 }
1018 hpi_dsp_code_close(&dsp_code);
1019 if (error)
1020 return error;
1021
1022 /* zero out the hostmailbox */
1023 {
1024 u32 address = HPI_HIF_ADDR(host_cmd);
1025 for (i = 0; i < 4; i++) {
1026 hpi_write_word(pdo, address, 0);
1027 address += 4;
1028 }
1029 }
1030 /* write the DSP number into the hostmailbox */
1031 /* structure before starting the DSP */
1032 hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
1033
1034 /* write the DSP adapter Info into the */
1035 /* hostmailbox before starting the DSP */
1036 if (dsp_index > 0)
1037 hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
1038 adapter_info);
1039
1040 /* step 3. Start code by sending interrupt */
1041 iowrite32(0x00030003, pdo->prHPI_control);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001042 hpios_delay_micro_seconds(10000);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001043
1044 /* wait for a non-zero value in hostcmd -
1045 * indicating initialization is complete
1046 *
1047 * Init could take a while if DSP checks SDRAM memory
1048 * Was 200000. Increased to 2000000 for ASI8801 so we
1049 * don't get 938 errors.
1050 */
1051 timeout = 2000000;
1052 while (timeout) {
1053 do {
1054 read = hpi_read_word(pdo,
1055 HPI_HIF_ADDR(host_cmd));
1056 } while (--timeout
1057 && hpi6000_check_PCI2040_error_flag(pao,
1058 H6READ));
1059
1060 if (read)
1061 break;
1062 /* The following is a workaround for bug #94:
1063 * Bluescreen on install and subsequent boots on a
1064 * DELL PowerEdge 600SC PC with 1.8GHz P4 and
1065 * ServerWorks chipset. Without this delay the system
1066 * locks up with a bluescreen (NOT GPF or pagefault).
1067 */
1068 else
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001069 hpios_delay_micro_seconds(10000);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001070 }
1071 if (timeout == 0)
1072 return HPI6000_ERROR_INIT_NOACK;
1073
1074 /* read the DSP adapter Info from the */
1075 /* hostmailbox structure after starting the DSP */
1076 if (dsp_index == 0) {
1077 /*u32 dwTestData=0; */
1078 u32 mask = 0;
1079
1080 adapter_info =
1081 hpi_read_word(pdo,
1082 HPI_HIF_ADDR(adapter_info));
1083 if (HPI_ADAPTER_FAMILY_ASI
1084 (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
1085 (adapter_info)) ==
1086 HPI_ADAPTER_FAMILY_ASI(0x6200))
1087 /* all 6200 cards have this many DSPs */
1088 phw->num_dsp = 2;
1089
1090 /* test that the PLD is programmed */
1091 /* and we can read/write 24bits */
1092#define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
1093
1094 switch (boot_load_family) {
1095 case HPI_ADAPTER_FAMILY_ASI(0x6200):
1096 /* ASI6100/6200 has 24bit path to FPGA */
1097 mask = 0xFFFFFF00L;
1098 /* ASI5100 uses AX6 code, */
1099 /* but has no PLD r/w register to test */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001100 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1101 subsystem_device) ==
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001102 HPI_ADAPTER_FAMILY_ASI(0x5100))
1103 mask = 0x00000000L;
Eliot Blennerhassett38439142010-07-06 08:37:08 +12001104 /* ASI5200 uses AX6 code, */
1105 /* but has no PLD r/w register to test */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001106 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1107 subsystem_device) ==
Eliot Blennerhassett38439142010-07-06 08:37:08 +12001108 HPI_ADAPTER_FAMILY_ASI(0x5200))
1109 mask = 0x00000000L;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001110 break;
1111 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1112 /* ASI8800 has 16bit path to FPGA */
1113 mask = 0xFFFF0000L;
1114 break;
1115 }
1116 test_data = 0xAAAAAA00L & mask;
1117 /* write to 24 bit Debug register (D31-D8) */
1118 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1119 read = hpi_read_word(pdo,
1120 PLD_BASE_ADDRESS + 4L) & mask;
1121 if (read != test_data) {
1122 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1123 read);
1124 return HPI6000_ERROR_INIT_PLDTEST1;
1125 }
1126 test_data = 0x55555500L & mask;
1127 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1128 read = hpi_read_word(pdo,
1129 PLD_BASE_ADDRESS + 4L) & mask;
1130 if (read != test_data) {
1131 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1132 read);
1133 return HPI6000_ERROR_INIT_PLDTEST2;
1134 }
1135 }
1136 } /* for numDSP */
1137 return 0;
1138}
1139
1140#define PCI_TIMEOUT 100
1141
1142static int hpi_set_address(struct dsp_obj *pdo, u32 address)
1143{
1144 u32 timeout = PCI_TIMEOUT;
1145
1146 do {
1147 iowrite32(address, pdo->prHPI_address);
1148 } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
1149 H6WRITE)
1150 && --timeout);
1151
1152 if (timeout)
1153 return 0;
1154
1155 return 1;
1156}
1157
1158/* write one word to the HPI port */
1159static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
1160{
1161 if (hpi_set_address(pdo, address))
1162 return;
1163 iowrite32(data, pdo->prHPI_data);
1164}
1165
1166/* read one word from the HPI port */
1167static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
1168{
1169 u32 data = 0;
1170
1171 if (hpi_set_address(pdo, address))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001172 return 0; /*? No way to return error */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001173
1174 /* take care of errata in revB DSP (2.0.1) */
1175 data = ioread32(pdo->prHPI_data);
1176 return data;
1177}
1178
1179/* write a block of 32bit words to the DSP HPI port using auto-inc mode */
1180static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1181 u32 length)
1182{
1183 u16 length16 = length - 1;
1184
1185 if (length == 0)
1186 return;
1187
1188 if (hpi_set_address(pdo, address))
1189 return;
1190
1191 iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1192
1193 /* take care of errata in revB DSP (2.0.1) */
1194 /* must end with non auto-inc */
1195 iowrite32(*(pdata + length - 1), pdo->prHPI_data);
1196}
1197
1198/** read a block of 32bit words from the DSP HPI port using auto-inc mode
1199 */
1200static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1201 u32 length)
1202{
1203 u16 length16 = length - 1;
1204
1205 if (length == 0)
1206 return;
1207
1208 if (hpi_set_address(pdo, address))
1209 return;
1210
1211 ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1212
1213 /* take care of errata in revB DSP (2.0.1) */
1214 /* must end with non auto-inc */
1215 *(pdata + length - 1) = ioread32(pdo->prHPI_data);
1216}
1217
1218static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
1219 u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
1220{
1221 struct dsp_obj *pdo =
1222 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1223 u32 time_out = PCI_TIMEOUT;
1224 int c6711_burst_size = 128;
1225 u32 local_hpi_address = hpi_address;
1226 int local_count = count;
1227 int xfer_size;
1228 u32 *pdata = source;
1229
1230 while (local_count) {
1231 if (local_count > c6711_burst_size)
1232 xfer_size = c6711_burst_size;
1233 else
1234 xfer_size = local_count;
1235
1236 time_out = PCI_TIMEOUT;
1237 do {
1238 hpi_write_block(pdo, local_hpi_address, pdata,
1239 xfer_size);
1240 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1241 && --time_out);
1242
1243 if (!time_out)
1244 break;
1245 pdata += xfer_size;
1246 local_hpi_address += sizeof(u32) * xfer_size;
1247 local_count -= xfer_size;
1248 }
1249
1250 if (time_out)
1251 return 0;
1252 else
1253 return 1;
1254}
1255
1256static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
1257 u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
1258{
1259 struct dsp_obj *pdo =
1260 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1261 u32 time_out = PCI_TIMEOUT;
1262 int c6711_burst_size = 16;
1263 u32 local_hpi_address = hpi_address;
1264 int local_count = count;
1265 int xfer_size;
1266 u32 *pdata = dest;
1267 u32 loop_count = 0;
1268
1269 while (local_count) {
1270 if (local_count > c6711_burst_size)
1271 xfer_size = c6711_burst_size;
1272 else
1273 xfer_size = local_count;
1274
1275 time_out = PCI_TIMEOUT;
1276 do {
1277 hpi_read_block(pdo, local_hpi_address, pdata,
1278 xfer_size);
1279 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1280 && --time_out);
1281 if (!time_out)
1282 break;
1283
1284 pdata += xfer_size;
1285 local_hpi_address += sizeof(u32) * xfer_size;
1286 local_count -= xfer_size;
1287 loop_count++;
1288 }
1289
1290 if (time_out)
1291 return 0;
1292 else
1293 return 1;
1294}
1295
1296static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
1297 u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
1298{
1299 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1300 struct dsp_obj *pdo = &phw->ado[dsp_index];
1301 u32 timeout;
1302 u16 ack;
1303 u32 address;
1304 u32 length;
1305 u32 *p_data;
1306 u16 error = 0;
1307
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001308 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1309 if (ack & HPI_HIF_ERROR_MASK) {
1310 pao->dsp_crashed++;
1311 return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
1312 }
1313 pao->dsp_crashed = 0;
1314
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001315 /* get the message address and size */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001316 if (phw->message_buffer_address_on_dsp == 0) {
1317 timeout = TIMEOUT;
1318 do {
1319 address =
1320 hpi_read_word(pdo,
1321 HPI_HIF_ADDR(message_buffer_address));
1322 phw->message_buffer_address_on_dsp = address;
1323 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1324 && --timeout);
1325 if (!timeout)
1326 return HPI6000_ERROR_MSG_GET_ADR;
1327 } else
1328 address = phw->message_buffer_address_on_dsp;
1329
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001330 length = phm->size;
1331
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001332 /* send the message */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001333 p_data = (u32 *)phm;
1334 if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
1335 (u16)length / 4))
1336 return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
1337
1338 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
1339 return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
1340 hpi6000_send_dsp_interrupt(pdo);
1341
1342 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
1343 if (ack & HPI_HIF_ERROR_MASK)
1344 return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
1345
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001346 /* get the response address */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001347 if (phw->response_buffer_address_on_dsp == 0) {
1348 timeout = TIMEOUT;
1349 do {
1350 address =
1351 hpi_read_word(pdo,
1352 HPI_HIF_ADDR(response_buffer_address));
1353 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1354 && --timeout);
1355 phw->response_buffer_address_on_dsp = address;
1356
1357 if (!timeout)
1358 return HPI6000_ERROR_RESP_GET_ADR;
1359 } else
1360 address = phw->response_buffer_address_on_dsp;
1361
1362 /* read the length of the response back from the DSP */
1363 timeout = TIMEOUT;
1364 do {
1365 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1366 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1367 if (!timeout)
1368 length = sizeof(struct hpi_response);
1369
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001370 /* get the response */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001371 p_data = (u32 *)phr;
1372 if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
1373 (u16)length / 4))
1374 return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
1375
1376 /* set i/f back to idle */
1377 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1378 return HPI6000_ERROR_MSG_RESP_IDLECMD;
1379 hpi6000_send_dsp_interrupt(pdo);
1380
1381 error = hpi_validate_response(phm, phr);
1382 return error;
1383}
1384
1385/* have to set up the below defines to match stuff in the MAP file */
1386
1387#define MSG_ADDRESS (HPI_HIF_BASE+0x18)
1388#define MSG_LENGTH 11
1389#define RESP_ADDRESS (HPI_HIF_BASE+0x44)
1390#define RESP_LENGTH 16
1391#define QUEUE_START (HPI_HIF_BASE+0x88)
1392#define QUEUE_SIZE 0x8000
1393
1394static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
1395{
1396/*#define CHECKING // comment this line in to enable checking */
1397#ifdef CHECKING
1398 if (address < (u32)MSG_ADDRESS)
1399 return 0;
1400 if (address > (u32)(QUEUE_START + QUEUE_SIZE))
1401 return 0;
1402 if ((address + (length_in_dwords << 2)) >
1403 (u32)(QUEUE_START + QUEUE_SIZE))
1404 return 0;
1405#else
1406 (void)address;
1407 (void)length_in_dwords;
1408 return 1;
1409#endif
1410}
1411
1412static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1413 struct hpi_message *phm, struct hpi_response *phr)
1414{
1415 struct dsp_obj *pdo =
1416 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1417 u32 data_sent = 0;
1418 u16 ack;
1419 u32 length, address;
1420 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1421 u16 time_out = 8;
1422
1423 (void)phr;
1424
1425 /* round dwDataSize down to nearest 4 bytes */
1426 while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
1427 && --time_out) {
1428 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1429 if (ack & HPI_HIF_ERROR_MASK)
1430 return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
1431
1432 if (hpi6000_send_host_command(pao, dsp_index,
1433 HPI_HIF_SEND_DATA))
1434 return HPI6000_ERROR_SEND_DATA_CMD;
1435
1436 hpi6000_send_dsp_interrupt(pdo);
1437
1438 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
1439
1440 if (ack & HPI_HIF_ERROR_MASK)
1441 return HPI6000_ERROR_SEND_DATA_ACK;
1442
1443 do {
1444 /* get the address and size */
1445 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1446 /* DSP returns number of DWORDS */
1447 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1448 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1449
1450 if (!hpi6000_send_data_check_adr(address, length))
1451 return HPI6000_ERROR_SEND_DATA_ADR;
1452
1453 /* send the data. break data into 512 DWORD blocks (2K bytes)
1454 * and send using block write. 2Kbytes is the max as this is the
1455 * memory window given to the HPI data register by the PCI2040
1456 */
1457
1458 {
1459 u32 len = length;
1460 u32 blk_len = 512;
1461 while (len) {
1462 if (len < blk_len)
1463 blk_len = len;
1464 if (hpi6000_dsp_block_write32(pao, dsp_index,
1465 address, p_data, blk_len))
1466 return HPI6000_ERROR_SEND_DATA_WRITE;
1467 address += blk_len * 4;
1468 p_data += blk_len;
1469 len -= blk_len;
1470 }
1471 }
1472
1473 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1474 return HPI6000_ERROR_SEND_DATA_IDLECMD;
1475
1476 hpi6000_send_dsp_interrupt(pdo);
1477
1478 data_sent += length * 4;
1479 }
1480 if (!time_out)
1481 return HPI6000_ERROR_SEND_DATA_TIMEOUT;
1482 return 0;
1483}
1484
1485static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1486 struct hpi_message *phm, struct hpi_response *phr)
1487{
1488 struct dsp_obj *pdo =
1489 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1490 u32 data_got = 0;
1491 u16 ack;
1492 u32 length, address;
1493 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1494
1495 (void)phr; /* this parameter not used! */
1496
1497 /* round dwDataSize down to nearest 4 bytes */
1498 while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
1499 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1500 if (ack & HPI_HIF_ERROR_MASK)
1501 return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
1502
1503 if (hpi6000_send_host_command(pao, dsp_index,
1504 HPI_HIF_GET_DATA))
1505 return HPI6000_ERROR_GET_DATA_CMD;
1506 hpi6000_send_dsp_interrupt(pdo);
1507
1508 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
1509
1510 if (ack & HPI_HIF_ERROR_MASK)
1511 return HPI6000_ERROR_GET_DATA_ACK;
1512
1513 /* get the address and size */
1514 do {
1515 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1516 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1517 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1518
1519 /* read the data */
1520 {
1521 u32 len = length;
1522 u32 blk_len = 512;
1523 while (len) {
1524 if (len < blk_len)
1525 blk_len = len;
1526 if (hpi6000_dsp_block_read32(pao, dsp_index,
1527 address, p_data, blk_len))
1528 return HPI6000_ERROR_GET_DATA_READ;
1529 address += blk_len * 4;
1530 p_data += blk_len;
1531 len -= blk_len;
1532 }
1533 }
1534
1535 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1536 return HPI6000_ERROR_GET_DATA_IDLECMD;
1537 hpi6000_send_dsp_interrupt(pdo);
1538
1539 data_got += length * 4;
1540 }
1541 return 0;
1542}
1543
1544static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
1545{
1546 iowrite32(0x00030003, pdo->prHPI_control); /* DSPINT */
1547}
1548
1549static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
1550 u16 dsp_index, u32 host_cmd)
1551{
1552 struct dsp_obj *pdo =
1553 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1554 u32 timeout = TIMEOUT;
1555
1556 /* set command */
1557 do {
1558 hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
1559 /* flush the FIFO */
1560 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1561 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
1562
1563 /* reset the interrupt bit */
1564 iowrite32(0x00040004, pdo->prHPI_control);
1565
1566 if (timeout)
1567 return 0;
1568 else
1569 return 1;
1570}
1571
1572/* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
1573static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
1574 u16 read_or_write)
1575{
1576 u32 hPI_error;
1577
1578 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1579
1580 /* read the error bits from the PCI2040 */
1581 hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1582 if (hPI_error) {
1583 /* reset the error flag */
1584 iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1585 phw->pCI2040HPI_error_count++;
1586 if (read_or_write == 1)
1587 gw_pci_read_asserts++; /************* inc global */
1588 else
1589 gw_pci_write_asserts++;
1590 return 1;
1591 } else
1592 return 0;
1593}
1594
1595static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
1596 u32 ack_value)
1597{
1598 struct dsp_obj *pdo =
1599 &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
1600 u32 ack = 0L;
1601 u32 timeout;
1602 u32 hPIC = 0L;
1603
1604 /* wait for host interrupt to signal ack is ready */
1605 timeout = TIMEOUT;
1606 while (--timeout) {
1607 hPIC = ioread32(pdo->prHPI_control);
1608 if (hPIC & 0x04) /* 0x04 = HINT from DSP */
1609 break;
1610 }
1611 if (timeout == 0)
1612 return HPI_HIF_ERROR_MASK;
1613
1614 /* wait for dwAckValue */
1615 timeout = TIMEOUT;
1616 while (--timeout) {
1617 /* read the ack mailbox */
1618 ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
1619 if (ack == ack_value)
1620 break;
1621 if ((ack & HPI_HIF_ERROR_MASK)
1622 && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
1623 break;
1624 /*for (i=0;i<1000;i++) */
1625 /* dwPause=i+1; */
1626 }
1627 if (ack & HPI_HIF_ERROR_MASK)
1628 /* indicates bad read from DSP -
1629 typically 0xffffff is read for some reason */
1630 ack = HPI_HIF_ERROR_MASK;
1631
1632 if (timeout == 0)
1633 ack = HPI_HIF_ERROR_MASK;
1634 return (short)ack;
1635}
1636
1637static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
1638 struct hpi_message *phm)
1639{
1640 const u16 dsp_index = 0;
1641 struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
1642 struct dsp_obj *pdo = &phw->ado[dsp_index];
1643 u32 timeout;
1644 u32 cache_dirty_flag;
1645 u16 err;
1646
1647 hpios_dsplock_lock(pao);
1648
1649 timeout = TIMEOUT;
1650 do {
1651 cache_dirty_flag =
1652 hpi_read_word((struct dsp_obj *)pdo,
1653 HPI_HIF_ADDR(control_cache_is_dirty));
1654 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1655 if (!timeout) {
1656 err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
1657 goto unlock;
1658 }
1659
1660 if (cache_dirty_flag) {
1661 /* read the cached controls */
1662 u32 address;
1663 u32 length;
1664
1665 timeout = TIMEOUT;
1666 if (pdo->control_cache_address_on_dsp == 0) {
1667 do {
1668 address =
1669 hpi_read_word((struct dsp_obj *)pdo,
1670 HPI_HIF_ADDR(control_cache_address));
1671
1672 length = hpi_read_word((struct dsp_obj *)pdo,
1673 HPI_HIF_ADDR
1674 (control_cache_size_in_bytes));
1675 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1676 && --timeout);
1677 if (!timeout) {
1678 err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
1679 goto unlock;
1680 }
1681 pdo->control_cache_address_on_dsp = address;
1682 pdo->control_cache_length_on_dsp = length;
1683 } else {
1684 address = pdo->control_cache_address_on_dsp;
1685 length = pdo->control_cache_length_on_dsp;
1686 }
1687
1688 if (hpi6000_dsp_block_read32(pao, dsp_index, address,
1689 (u32 *)&phw->control_cache[0],
1690 length / sizeof(u32))) {
1691 err = HPI6000_ERROR_CONTROL_CACHE_READ;
1692 goto unlock;
1693 }
1694 do {
1695 hpi_write_word((struct dsp_obj *)pdo,
1696 HPI_HIF_ADDR(control_cache_is_dirty), 0);
1697 /* flush the FIFO */
1698 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1699 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1700 && --timeout);
1701 if (!timeout) {
1702 err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
1703 goto unlock;
1704 }
1705
1706 }
1707 err = 0;
1708
1709unlock:
1710 hpios_dsplock_unlock(pao);
1711 return err;
1712}
1713
1714/** Get dsp index for multi DSP adapters only */
1715static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
1716{
1717 u16 ret = 0;
1718 switch (phm->object) {
1719 case HPI_OBJ_ISTREAM:
1720 if (phm->obj_index < 2)
1721 ret = 1;
1722 break;
1723 case HPI_OBJ_PROFILE:
1724 ret = phm->obj_index;
1725 break;
1726 default:
1727 break;
1728 }
1729 return ret;
1730}
1731
1732/** Complete transaction with DSP
1733
1734Send message, get response, send or get stream data if any.
1735*/
1736static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
1737 struct hpi_response *phr)
1738{
1739 u16 error = 0;
1740 u16 dsp_index = 0;
1741 u16 num_dsp = ((struct hpi_hw_obj *)pao->priv)->num_dsp;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001742
1743 if (num_dsp < 2)
1744 dsp_index = 0;
1745 else {
1746 dsp_index = get_dsp_index(pao, phm);
1747
1748 /* is this checked on the DSP anyway? */
1749 if ((phm->function == HPI_ISTREAM_GROUP_ADD)
1750 || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
1751 struct hpi_message hm;
1752 u16 add_index;
1753 hm.obj_index = phm->u.d.u.stream.stream_index;
1754 hm.object = phm->u.d.u.stream.object_type;
1755 add_index = get_dsp_index(pao, &hm);
1756 if (add_index != dsp_index) {
1757 phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
1758 return;
1759 }
1760 }
1761 }
Eliot Blennerhassettbca516b2010-05-27 17:53:53 +12001762
1763 hpios_dsplock_lock(pao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001764 error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
1765
1766 /* maybe an error response */
1767 if (error) {
1768 /* something failed in the HPI/DSP interface */
1769 phr->error = error;
1770 /* just the header of the response is valid */
1771 phr->size = sizeof(struct hpi_response_header);
1772 goto err;
1773 }
1774
1775 if (phr->error != 0) /* something failed in the DSP */
1776 goto err;
1777
1778 switch (phm->function) {
1779 case HPI_OSTREAM_WRITE:
1780 case HPI_ISTREAM_ANC_WRITE:
1781 error = hpi6000_send_data(pao, dsp_index, phm, phr);
1782 break;
1783 case HPI_ISTREAM_READ:
1784 case HPI_OSTREAM_ANC_READ:
1785 error = hpi6000_get_data(pao, dsp_index, phm, phr);
1786 break;
1787 case HPI_ADAPTER_GET_ASSERT:
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001788 phr->u.ax.assert.dsp_index = 0; /* dsp 0 default */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001789 if (num_dsp == 2) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001790 if (!phr->u.ax.assert.count) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001791 /* no assert from dsp 0, check dsp 1 */
1792 error = hpi6000_message_response_sequence(pao,
1793 1, phm, phr);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001794 phr->u.ax.assert.dsp_index = 1;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001795 }
1796 }
1797 }
1798
1799 if (error)
1800 phr->error = error;
1801
1802err:
1803 hpios_dsplock_unlock(pao);
1804 return;
1805}