hpi6000.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Hardware Programming Interface (HPI) for AudioScience ASI6200 series adapters.
  15. These PCI bus adapters are based on the TI C6711 DSP.
  16. Exported functions:
  17. void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
  18. #defines
  19. HIDE_PCI_ASSERTS to show the PCI asserts
  20. PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
  21. (C) Copyright AudioScience Inc. 1998-2003
  22. *******************************************************************************/
  23. #define SOURCEFILE_NAME "hpi6000.c"
  24. #include "hpi_internal.h"
  25. #include "hpimsginit.h"
  26. #include "hpidebug.h"
  27. #include "hpi6000.h"
  28. #include "hpidspcd.h"
  29. #include "hpicmn.h"
  30. #define HPI_HIF_BASE (0x00000200) /* start of C67xx internal RAM */
  31. #define HPI_HIF_ADDR(member) \
  32. (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
  33. #define HPI_HIF_ERROR_MASK 0x4000
  34. /* HPI6000 specific error codes */
  35. #define HPI6000_ERROR_BASE 900 /* not actually used anywhere */
  36. /* operational/messaging errors */
  37. #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
  38. #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK 903
  39. #define HPI6000_ERROR_MSG_GET_ADR 904
  40. #define HPI6000_ERROR_RESP_GET_ADR 905
  41. #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32 906
  42. #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32 907
  43. #define HPI6000_ERROR_CONTROL_CACHE_PARAMS 909
  44. #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT 911
  45. #define HPI6000_ERROR_SEND_DATA_ACK 912
  46. #define HPI6000_ERROR_SEND_DATA_ADR 913
  47. #define HPI6000_ERROR_SEND_DATA_TIMEOUT 914
  48. #define HPI6000_ERROR_SEND_DATA_CMD 915
  49. #define HPI6000_ERROR_SEND_DATA_WRITE 916
  50. #define HPI6000_ERROR_SEND_DATA_IDLECMD 917
  51. #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT 921
  52. #define HPI6000_ERROR_GET_DATA_ACK 922
  53. #define HPI6000_ERROR_GET_DATA_CMD 923
  54. #define HPI6000_ERROR_GET_DATA_READ 924
  55. #define HPI6000_ERROR_GET_DATA_IDLECMD 925
  56. #define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN 951
  57. #define HPI6000_ERROR_CONTROL_CACHE_READ 952
  58. #define HPI6000_ERROR_CONTROL_CACHE_FLUSH 953
  59. #define HPI6000_ERROR_MSG_RESP_GETRESPCMD 961
  60. #define HPI6000_ERROR_MSG_RESP_IDLECMD 962
  61. /* Initialisation/bootload errors */
  62. #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
  63. /* can't access PCI2040 */
  64. #define HPI6000_ERROR_INIT_PCI2040 931
  65. /* can't access DSP HPI i/f */
  66. #define HPI6000_ERROR_INIT_DSPHPI 932
  67. /* can't access internal DSP memory */
  68. #define HPI6000_ERROR_INIT_DSPINTMEM 933
  69. /* can't access SDRAM - test#1 */
  70. #define HPI6000_ERROR_INIT_SDRAM1 934
  71. /* can't access SDRAM - test#2 */
  72. #define HPI6000_ERROR_INIT_SDRAM2 935
  73. #define HPI6000_ERROR_INIT_VERIFY 938
  74. #define HPI6000_ERROR_INIT_NOACK 939
  75. #define HPI6000_ERROR_INIT_PLDTEST1 941
  76. #define HPI6000_ERROR_INIT_PLDTEST2 942
  77. /* local defines */
  78. #define HIDE_PCI_ASSERTS
  79. #define PROFILE_DSP2
  80. /* for PCI2040 i/f chip */
  81. /* HPI CSR registers */
  82. /* word offsets from CSR base */
  83. /* use when io addresses defined as u32 * */
  84. #define INTERRUPT_EVENT_SET 0
  85. #define INTERRUPT_EVENT_CLEAR 1
  86. #define INTERRUPT_MASK_SET 2
  87. #define INTERRUPT_MASK_CLEAR 3
  88. #define HPI_ERROR_REPORT 4
  89. #define HPI_RESET 5
  90. #define HPI_DATA_WIDTH 6
  91. #define MAX_DSPS 2
  92. /* HPI registers, spaced 8K bytes = 2K words apart */
  93. #define DSP_SPACING 0x800
  94. #define CONTROL 0x0000
  95. #define ADDRESS 0x0200
  96. #define DATA_AUTOINC 0x0400
  97. #define DATA 0x0600
  98. #define TIMEOUT 500000
  99. struct dsp_obj {
  100. __iomem u32 *prHPI_control;
  101. __iomem u32 *prHPI_address;
  102. __iomem u32 *prHPI_data;
  103. __iomem u32 *prHPI_data_auto_inc;
  104. char c_dsp_rev; /*A, B */
  105. u32 control_cache_address_on_dsp;
  106. u32 control_cache_length_on_dsp;
  107. struct hpi_adapter_obj *pa_parent_adapter;
  108. };
  109. struct hpi_hw_obj {
  110. __iomem u32 *dw2040_HPICSR;
  111. __iomem u32 *dw2040_HPIDSP;
  112. u16 num_dsp;
  113. struct dsp_obj ado[MAX_DSPS];
  114. u32 message_buffer_address_on_dsp;
  115. u32 response_buffer_address_on_dsp;
  116. u32 pCI2040HPI_error_count;
  117. struct hpi_control_cache_single control_cache[HPI_NMIXER_CONTROLS];
  118. struct hpi_control_cache *p_cache;
  119. };
  120. static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
  121. u16 dsp_index, u32 hpi_address, u32 *source, u32 count);
  122. static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
  123. u16 dsp_index, u32 hpi_address, u32 *dest, u32 count);
  124. static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  125. u32 *pos_error_code);
  126. static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
  127. u16 read_or_write);
  128. #define H6READ 1
  129. #define H6WRITE 0
  130. static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
  131. struct hpi_message *phm);
  132. static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
  133. u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr);
  134. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  135. struct hpi_response *phr);
  136. static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
  137. u32 ack_value);
  138. static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
  139. u16 dsp_index, u32 host_cmd);
  140. static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo);
  141. static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  142. struct hpi_message *phm, struct hpi_response *phr);
  143. static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  144. struct hpi_message *phm, struct hpi_response *phr);
  145. static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data);
  146. static u32 hpi_read_word(struct dsp_obj *pdo, u32 address);
  147. static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  148. u32 length);
  149. static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  150. u32 length);
  151. static void subsys_create_adapter(struct hpi_message *phm,
  152. struct hpi_response *phr);
  153. static void subsys_delete_adapter(struct hpi_message *phm,
  154. struct hpi_response *phr);
  155. static void adapter_get_asserts(struct hpi_adapter_obj *pao,
  156. struct hpi_message *phm, struct hpi_response *phr);
  157. static short create_adapter_obj(struct hpi_adapter_obj *pao,
  158. u32 *pos_error_code);
  159. static void delete_adapter_obj(struct hpi_adapter_obj *pao);
  160. /* local globals */
  161. static u16 gw_pci_read_asserts; /* used to count PCI2040 errors */
  162. static u16 gw_pci_write_asserts; /* used to count PCI2040 errors */
  163. static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
  164. {
  165. switch (phm->function) {
  166. case HPI_SUBSYS_CREATE_ADAPTER:
  167. subsys_create_adapter(phm, phr);
  168. break;
  169. case HPI_SUBSYS_DELETE_ADAPTER:
  170. subsys_delete_adapter(phm, phr);
  171. break;
  172. default:
  173. phr->error = HPI_ERROR_INVALID_FUNC;
  174. break;
  175. }
  176. }
  177. static void control_message(struct hpi_adapter_obj *pao,
  178. struct hpi_message *phm, struct hpi_response *phr)
  179. {
  180. switch (phm->function) {
  181. case HPI_CONTROL_GET_STATE:
  182. if (pao->has_control_cache) {
  183. u16 err;
  184. err = hpi6000_update_control_cache(pao, phm);
  185. if (err) {
  186. if (err >= HPI_ERROR_BACKEND_BASE) {
  187. phr->error =
  188. HPI_ERROR_CONTROL_CACHING;
  189. phr->specific_error = err;
  190. } else {
  191. phr->error = err;
  192. }
  193. break;
  194. }
  195. if (hpi_check_control_cache(((struct hpi_hw_obj *)
  196. pao->priv)->p_cache, phm,
  197. phr))
  198. break;
  199. }
  200. hw_message(pao, phm, phr);
  201. break;
  202. case HPI_CONTROL_SET_STATE:
  203. hw_message(pao, phm, phr);
  204. hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj *)pao->
  205. priv)->p_cache, phm, phr);
  206. break;
  207. case HPI_CONTROL_GET_INFO:
  208. default:
  209. hw_message(pao, phm, phr);
  210. break;
  211. }
  212. }
  213. static void adapter_message(struct hpi_adapter_obj *pao,
  214. struct hpi_message *phm, struct hpi_response *phr)
  215. {
  216. switch (phm->function) {
  217. case HPI_ADAPTER_GET_ASSERT:
  218. adapter_get_asserts(pao, phm, phr);
  219. break;
  220. default:
  221. hw_message(pao, phm, phr);
  222. break;
  223. }
  224. }
  225. static void outstream_message(struct hpi_adapter_obj *pao,
  226. struct hpi_message *phm, struct hpi_response *phr)
  227. {
  228. switch (phm->function) {
  229. case HPI_OSTREAM_HOSTBUFFER_ALLOC:
  230. case HPI_OSTREAM_HOSTBUFFER_FREE:
  231. /* Don't let these messages go to the HW function because
  232. * they're called without locking the spinlock.
  233. * For the HPI6000 adapters the HW would return
  234. * HPI_ERROR_INVALID_FUNC anyway.
  235. */
  236. phr->error = HPI_ERROR_INVALID_FUNC;
  237. break;
  238. default:
  239. hw_message(pao, phm, phr);
  240. return;
  241. }
  242. }
  243. static void instream_message(struct hpi_adapter_obj *pao,
  244. struct hpi_message *phm, struct hpi_response *phr)
  245. {
  246. switch (phm->function) {
  247. case HPI_ISTREAM_HOSTBUFFER_ALLOC:
  248. case HPI_ISTREAM_HOSTBUFFER_FREE:
  249. /* Don't let these messages go to the HW function because
  250. * they're called without locking the spinlock.
  251. * For the HPI6000 adapters the HW would return
  252. * HPI_ERROR_INVALID_FUNC anyway.
  253. */
  254. phr->error = HPI_ERROR_INVALID_FUNC;
  255. break;
  256. default:
  257. hw_message(pao, phm, phr);
  258. return;
  259. }
  260. }
  261. /************************************************************************/
  262. /** HPI_6000()
  263. * Entry point from HPIMAN
  264. * All calls to the HPI start here
  265. */
  266. void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
  267. {
  268. struct hpi_adapter_obj *pao = NULL;
  269. /* subsytem messages get executed by every HPI. */
  270. /* All other messages are ignored unless the adapter index matches */
  271. /* an adapter in the HPI */
  272. /*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */
  273. /* if Dsp has crashed then do not communicate with it any more */
  274. if (phm->object != HPI_OBJ_SUBSYSTEM) {
  275. pao = hpi_find_adapter(phm->adapter_index);
  276. if (!pao) {
  277. HPI_DEBUG_LOG(DEBUG,
  278. " %d,%d refused, for another HPI?\n",
  279. phm->object, phm->function);
  280. return;
  281. }
  282. if (pao->dsp_crashed >= 10) {
  283. hpi_init_response(phr, phm->object, phm->function,
  284. HPI_ERROR_DSP_HARDWARE);
  285. HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n",
  286. phm->object, phm->function);
  287. return;
  288. }
  289. }
  290. /* Init default response including the size field */
  291. if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
  292. hpi_init_response(phr, phm->object, phm->function,
  293. HPI_ERROR_PROCESSING_MESSAGE);
  294. switch (phm->type) {
  295. case HPI_TYPE_MESSAGE:
  296. switch (phm->object) {
  297. case HPI_OBJ_SUBSYSTEM:
  298. subsys_message(phm, phr);
  299. break;
  300. case HPI_OBJ_ADAPTER:
  301. phr->size =
  302. sizeof(struct hpi_response_header) +
  303. sizeof(struct hpi_adapter_res);
  304. adapter_message(pao, phm, phr);
  305. break;
  306. case HPI_OBJ_CONTROL:
  307. control_message(pao, phm, phr);
  308. break;
  309. case HPI_OBJ_OSTREAM:
  310. outstream_message(pao, phm, phr);
  311. break;
  312. case HPI_OBJ_ISTREAM:
  313. instream_message(pao, phm, phr);
  314. break;
  315. default:
  316. hw_message(pao, phm, phr);
  317. break;
  318. }
  319. break;
  320. default:
  321. phr->error = HPI_ERROR_INVALID_TYPE;
  322. break;
  323. }
  324. }
  325. /************************************************************************/
  326. /* SUBSYSTEM */
  327. /* create an adapter object and initialise it based on resource information
  328. * passed in in the message
  329. * NOTE - you cannot use this function AND the FindAdapters function at the
  330. * same time, the application must use only one of them to get the adapters
  331. */
  332. static void subsys_create_adapter(struct hpi_message *phm,
  333. struct hpi_response *phr)
  334. {
  335. /* create temp adapter obj, because we don't know what index yet */
  336. struct hpi_adapter_obj ao;
  337. struct hpi_adapter_obj *pao;
  338. u32 os_error_code;
  339. u16 err = 0;
  340. u32 dsp_index = 0;
  341. HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
  342. memset(&ao, 0, sizeof(ao));
  343. ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
  344. if (!ao.priv) {
  345. HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
  346. phr->error = HPI_ERROR_MEMORY_ALLOC;
  347. return;
  348. }
  349. /* create the adapter object based on the resource information */
  350. ao.pci = *phm->u.s.resource.r.pci;
  351. err = create_adapter_obj(&ao, &os_error_code);
  352. if (err) {
  353. delete_adapter_obj(&ao);
  354. if (err >= HPI_ERROR_BACKEND_BASE) {
  355. phr->error = HPI_ERROR_DSP_BOOTLOAD;
  356. phr->specific_error = err;
  357. } else {
  358. phr->error = err;
  359. }
  360. phr->u.s.data = os_error_code;
  361. return;
  362. }
  363. /* need to update paParentAdapter */
  364. pao = hpi_find_adapter(ao.index);
  365. if (!pao) {
  366. /* We just added this adapter, why can't we find it!? */
  367. HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
  368. phr->error = HPI_ERROR_BAD_ADAPTER;
  369. return;
  370. }
  371. for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
  372. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  373. phw->ado[dsp_index].pa_parent_adapter = pao;
  374. }
  375. phr->u.s.adapter_type = ao.adapter_type;
  376. phr->u.s.adapter_index = ao.index;
  377. phr->error = 0;
  378. }
  379. static void subsys_delete_adapter(struct hpi_message *phm,
  380. struct hpi_response *phr)
  381. {
  382. struct hpi_adapter_obj *pao = NULL;
  383. pao = hpi_find_adapter(phm->obj_index);
  384. if (!pao)
  385. return;
  386. delete_adapter_obj(pao);
  387. hpi_delete_adapter(pao);
  388. phr->error = 0;
  389. }
  390. /* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
  391. static short create_adapter_obj(struct hpi_adapter_obj *pao,
  392. u32 *pos_error_code)
  393. {
  394. short boot_error = 0;
  395. u32 dsp_index = 0;
  396. u32 control_cache_size = 0;
  397. u32 control_cache_count = 0;
  398. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  399. /* The PCI2040 has the following address map */
  400. /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
  401. /* BAR1 - 32K = HPI registers on DSP */
  402. phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
  403. phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
  404. HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
  405. phw->dw2040_HPIDSP);
  406. /* set addresses for the possible DSP HPI interfaces */
  407. for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
  408. phw->ado[dsp_index].prHPI_control =
  409. phw->dw2040_HPIDSP + (CONTROL +
  410. DSP_SPACING * dsp_index);
  411. phw->ado[dsp_index].prHPI_address =
  412. phw->dw2040_HPIDSP + (ADDRESS +
  413. DSP_SPACING * dsp_index);
  414. phw->ado[dsp_index].prHPI_data =
  415. phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
  416. phw->ado[dsp_index].prHPI_data_auto_inc =
  417. phw->dw2040_HPIDSP + (DATA_AUTOINC +
  418. DSP_SPACING * dsp_index);
  419. HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
  420. phw->ado[dsp_index].prHPI_control,
  421. phw->ado[dsp_index].prHPI_address,
  422. phw->ado[dsp_index].prHPI_data,
  423. phw->ado[dsp_index].prHPI_data_auto_inc);
  424. phw->ado[dsp_index].pa_parent_adapter = pao;
  425. }
  426. phw->pCI2040HPI_error_count = 0;
  427. pao->has_control_cache = 0;
  428. /* Set the default number of DSPs on this card */
  429. /* This is (conditionally) adjusted after bootloading */
  430. /* of the first DSP in the bootload section. */
  431. phw->num_dsp = 1;
  432. boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
  433. if (boot_error)
  434. return boot_error;
  435. HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
  436. phw->message_buffer_address_on_dsp = 0L;
  437. phw->response_buffer_address_on_dsp = 0L;
  438. /* get info about the adapter by asking the adapter */
  439. /* send a HPI_ADAPTER_GET_INFO message */
  440. {
  441. struct hpi_message hm;
  442. struct hpi_response hr0; /* response from DSP 0 */
  443. struct hpi_response hr1; /* response from DSP 1 */
  444. u16 error = 0;
  445. HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
  446. memset(&hm, 0, sizeof(hm));
  447. hm.type = HPI_TYPE_MESSAGE;
  448. hm.size = sizeof(struct hpi_message);
  449. hm.object = HPI_OBJ_ADAPTER;
  450. hm.function = HPI_ADAPTER_GET_INFO;
  451. hm.adapter_index = 0;
  452. memset(&hr0, 0, sizeof(hr0));
  453. memset(&hr1, 0, sizeof(hr1));
  454. hr0.size = sizeof(hr0);
  455. hr1.size = sizeof(hr1);
  456. error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
  457. if (hr0.error) {
  458. HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
  459. return hr0.error;
  460. }
  461. if (phw->num_dsp == 2) {
  462. error = hpi6000_message_response_sequence(pao, 1, &hm,
  463. &hr1);
  464. if (error)
  465. return error;
  466. }
  467. pao->adapter_type = hr0.u.ax.info.adapter_type;
  468. pao->index = hr0.u.ax.info.adapter_index;
  469. }
  470. memset(&phw->control_cache[0], 0,
  471. sizeof(struct hpi_control_cache_single) *
  472. HPI_NMIXER_CONTROLS);
  473. /* Read the control cache length to figure out if it is turned on */
  474. control_cache_size =
  475. hpi_read_word(&phw->ado[0],
  476. HPI_HIF_ADDR(control_cache_size_in_bytes));
  477. if (control_cache_size) {
  478. control_cache_count =
  479. hpi_read_word(&phw->ado[0],
  480. HPI_HIF_ADDR(control_cache_count));
  481. phw->p_cache =
  482. hpi_alloc_control_cache(control_cache_count,
  483. control_cache_size, (unsigned char *)
  484. &phw->control_cache[0]
  485. );
  486. if (phw->p_cache)
  487. pao->has_control_cache = 1;
  488. }
  489. HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n",
  490. pao->adapter_type, pao->index);
  491. pao->open = 0; /* upon creation the adapter is closed */
  492. if (phw->p_cache)
  493. phw->p_cache->adap_idx = pao->index;
  494. return hpi_add_adapter(pao);
  495. }
  496. static void delete_adapter_obj(struct hpi_adapter_obj *pao)
  497. {
  498. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  499. if (pao->has_control_cache)
  500. hpi_free_control_cache(phw->p_cache);
  501. /* reset DSPs on adapter */
  502. iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
  503. kfree(phw);
  504. }
  505. /************************************************************************/
  506. /* ADAPTER */
  507. static void adapter_get_asserts(struct hpi_adapter_obj *pao,
  508. struct hpi_message *phm, struct hpi_response *phr)
  509. {
  510. #ifndef HIDE_PCI_ASSERTS
  511. /* if we have PCI2040 asserts then collect them */
  512. if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
  513. phr->u.ax.assert.p1 =
  514. gw_pci_read_asserts * 100 + gw_pci_write_asserts;
  515. phr->u.ax.assert.p2 = 0;
  516. phr->u.ax.assert.count = 1; /* assert count */
  517. phr->u.ax.assert.dsp_index = -1; /* "dsp index" */
  518. strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
  519. phr->u.ax.assert.dsp_msg_addr = 0;
  520. gw_pci_read_asserts = 0;
  521. gw_pci_write_asserts = 0;
  522. phr->error = 0;
  523. } else
  524. #endif
  525. hw_message(pao, phm, phr); /*get DSP asserts */
  526. return;
  527. }
  528. /************************************************************************/
  529. /* LOW-LEVEL */
  530. static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  531. u32 *pos_error_code)
  532. {
  533. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  534. short error;
  535. u32 timeout;
  536. u32 read = 0;
  537. u32 i = 0;
  538. u32 data = 0;
  539. u32 j = 0;
  540. u32 test_addr = 0x80000000;
  541. u32 test_data = 0x00000001;
  542. u32 dw2040_reset = 0;
  543. u32 dsp_index = 0;
  544. u32 endian = 0;
  545. u32 adapter_info = 0;
  546. u32 delay = 0;
  547. struct dsp_code dsp_code;
  548. u16 boot_load_family = 0;
  549. /* NOTE don't use wAdapterType in this routine. It is not setup yet */
  550. switch (pao->pci.pci_dev->subsystem_device) {
  551. case 0x5100:
  552. case 0x5110: /* ASI5100 revB or higher with C6711D */
  553. case 0x5200: /* ASI5200 PCIe version of ASI5100 */
  554. case 0x6100:
  555. case 0x6200:
  556. boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
  557. break;
  558. default:
  559. return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
  560. }
  561. /* reset all DSPs, indicate two DSPs are present
  562. * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
  563. */
  564. endian = 0;
  565. dw2040_reset = 0x0003000F;
  566. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  567. /* read back register to make sure PCI2040 chip is functioning
  568. * note that bits 4..15 are read-only and so should always return zero,
  569. * even though we wrote 1 to them
  570. */
  571. hpios_delay_micro_seconds(1000);
  572. delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
  573. if (delay != dw2040_reset) {
  574. HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
  575. delay);
  576. return HPI6000_ERROR_INIT_PCI2040;
  577. }
  578. /* Indicate that DSP#0,1 is a C6X */
  579. iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
  580. /* set Bit30 and 29 - which will prevent Target aborts from being
  581. * issued upon HPI or GP error
  582. */
  583. iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
  584. /* isolate DSP HAD8 line from PCI2040 so that
  585. * Little endian can be set by pullup
  586. */
  587. dw2040_reset = dw2040_reset & (~(endian << 3));
  588. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  589. phw->ado[0].c_dsp_rev = 'B'; /* revB */
  590. phw->ado[1].c_dsp_rev = 'B'; /* revB */
  591. /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
  592. dw2040_reset = dw2040_reset & (~0x00000001); /* start DSP 0 */
  593. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  594. dw2040_reset = dw2040_reset & (~0x00000002); /* start DSP 1 */
  595. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  596. /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
  597. dw2040_reset = dw2040_reset & (~0x00000008);
  598. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  599. /*delay to allow DSP to get going */
  600. hpios_delay_micro_seconds(100);
  601. /* loop through all DSPs, downloading DSP code */
  602. for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
  603. struct dsp_obj *pdo = &phw->ado[dsp_index];
  604. /* configure DSP so that we download code into the SRAM */
  605. /* set control reg for little endian, HWOB=1 */
  606. iowrite32(0x00010001, pdo->prHPI_control);
  607. /* test access to the HPI address register (HPIA) */
  608. test_data = 0x00000001;
  609. for (j = 0; j < 32; j++) {
  610. iowrite32(test_data, pdo->prHPI_address);
  611. data = ioread32(pdo->prHPI_address);
  612. if (data != test_data) {
  613. HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
  614. test_data, data, dsp_index);
  615. return HPI6000_ERROR_INIT_DSPHPI;
  616. }
  617. test_data = test_data << 1;
  618. }
  619. /* if C6713 the setup PLL to generate 225MHz from 25MHz.
  620. * Since the PLLDIV1 read is sometimes wrong, even on a C6713,
  621. * we're going to do this unconditionally
  622. */
  623. /* PLLDIV1 should have a value of 8000 after reset */
  624. /*
  625. if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
  626. */
  627. {
  628. /* C6713 datasheet says we cannot program PLL from HPI,
  629. * and indeed if we try to set the PLL multiply from the
  630. * HPI, the PLL does not seem to lock,
  631. * so we enable the PLL and use the default of x 7
  632. */
  633. /* bypass PLL */
  634. hpi_write_word(pdo, 0x01B7C100, 0x0000);
  635. hpios_delay_micro_seconds(100);
  636. /* ** use default of PLL x7 ** */
  637. /* EMIF = 225/3=75MHz */
  638. hpi_write_word(pdo, 0x01B7C120, 0x8002);
  639. hpios_delay_micro_seconds(100);
  640. /* peri = 225/2 */
  641. hpi_write_word(pdo, 0x01B7C11C, 0x8001);
  642. hpios_delay_micro_seconds(100);
  643. /* cpu = 225/1 */
  644. hpi_write_word(pdo, 0x01B7C118, 0x8000);
  645. /* ~2ms delay */
  646. hpios_delay_micro_seconds(2000);
  647. /* PLL not bypassed */
  648. hpi_write_word(pdo, 0x01B7C100, 0x0001);
  649. /* ~2ms delay */
  650. hpios_delay_micro_seconds(2000);
  651. }
  652. /* test r/w to internal DSP memory
  653. * C6711 has L2 cache mapped to 0x0 when reset
  654. *
  655. * revB - because of bug 3.0.1 last HPI read
  656. * (before HPI address issued) must be non-autoinc
  657. */
  658. /* test each bit in the 32bit word */
  659. for (i = 0; i < 100; i++) {
  660. test_addr = 0x00000000;
  661. test_data = 0x00000001;
  662. for (j = 0; j < 32; j++) {
  663. hpi_write_word(pdo, test_addr + i, test_data);
  664. data = hpi_read_word(pdo, test_addr + i);
  665. if (data != test_data) {
  666. HPI_DEBUG_LOG(ERROR,
  667. "DSP mem %x %x %x %x\n",
  668. test_addr + i, test_data,
  669. data, dsp_index);
  670. return HPI6000_ERROR_INIT_DSPINTMEM;
  671. }
  672. test_data = test_data << 1;
  673. }
  674. }
  675. /* memory map of ASI6200
  676. 00000000-0000FFFF 16Kx32 internal program
  677. 01800000-019FFFFF Internal peripheral
  678. 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
  679. 90000000-9000FFFF CE1 Async peripherals:
  680. EMIF config
  681. ------------
  682. Global EMIF control
  683. 0 -
  684. 1 -
  685. 2 -
  686. 3 CLK2EN = 1 CLKOUT2 enabled
  687. 4 CLK1EN = 0 CLKOUT1 disabled
  688. 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
  689. 6 -
  690. 7 NOHOLD = 1 external HOLD disabled
  691. 8 HOLDA = 0 HOLDA output is low
  692. 9 HOLD = 0 HOLD input is low
  693. 10 ARDY = 1 ARDY input is high
  694. 11 BUSREQ = 0 BUSREQ output is low
  695. 12,13 Reserved = 1
  696. */
  697. hpi_write_word(pdo, 0x01800000, 0x34A8);
  698. /* EMIF CE0 setup - 2Mx32 Sync DRAM
  699. 31..28 Wr setup
  700. 27..22 Wr strobe
  701. 21..20 Wr hold
  702. 19..16 Rd setup
  703. 15..14 -
  704. 13..8 Rd strobe
  705. 7..4 MTYPE 0011 Sync DRAM 32bits
  706. 3 Wr hold MSB
  707. 2..0 Rd hold
  708. */
  709. hpi_write_word(pdo, 0x01800008, 0x00000030);
  710. /* EMIF SDRAM Extension
  711. 31-21 0
  712. 20 WR2RD = 0
  713. 19-18 WR2DEAC = 1
  714. 17 WR2WR = 0
  715. 16-15 R2WDQM = 2
  716. 14-12 RD2WR = 4
  717. 11-10 RD2DEAC = 1
  718. 9 RD2RD = 1
  719. 8-7 THZP = 10b
  720. 6-5 TWR = 2-1 = 01b (tWR = 10ns)
  721. 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
  722. 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
  723. 1 CAS latency = 3 ECLK
  724. (for Micron 2M32-7 operating at 100Mhz)
  725. */
  726. /* need to use this else DSP code crashes */
  727. hpi_write_word(pdo, 0x01800020, 0x001BDF29);
  728. /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
  729. 31 - -
  730. 30 SDBSZ 1 4 bank
  731. 29..28 SDRSZ 00 11 row address pins
  732. 27..26 SDCSZ 01 8 column address pins
  733. 25 RFEN 1 refersh enabled
  734. 24 INIT 1 init SDRAM
  735. 23..20 TRCD 0001
  736. 19..16 TRP 0001
  737. 15..12 TRC 0110
  738. 11..0 - -
  739. */
  740. /* need to use this else DSP code crashes */
  741. hpi_write_word(pdo, 0x01800018, 0x47117000);
  742. /* EMIF SDRAM Refresh Timing */
  743. hpi_write_word(pdo, 0x0180001C, 0x00000410);
  744. /*MIF CE1 setup - Async peripherals
  745. @100MHz bus speed, each cycle is 10ns,
  746. 31..28 Wr setup = 1
  747. 27..22 Wr strobe = 3 30ns
  748. 21..20 Wr hold = 1
  749. 19..16 Rd setup =1
  750. 15..14 Ta = 2
  751. 13..8 Rd strobe = 3 30ns
  752. 7..4 MTYPE 0010 Async 32bits
  753. 3 Wr hold MSB =0
  754. 2..0 Rd hold = 1
  755. */
  756. {
  757. u32 cE1 =
  758. (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
  759. 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
  760. hpi_write_word(pdo, 0x01800004, cE1);
  761. }
  762. /* delay a little to allow SDRAM and DSP to "get going" */
  763. hpios_delay_micro_seconds(1000);
  764. /* test access to SDRAM */
  765. {
  766. test_addr = 0x80000000;
  767. test_data = 0x00000001;
  768. /* test each bit in the 32bit word */
  769. for (j = 0; j < 32; j++) {
  770. hpi_write_word(pdo, test_addr, test_data);
  771. data = hpi_read_word(pdo, test_addr);
  772. if (data != test_data) {
  773. HPI_DEBUG_LOG(ERROR,
  774. "DSP dram %x %x %x %x\n",
  775. test_addr, test_data, data,
  776. dsp_index);
  777. return HPI6000_ERROR_INIT_SDRAM1;
  778. }
  779. test_data = test_data << 1;
  780. }
  781. /* test every Nth address in the DRAM */
  782. #define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
  783. #define DRAM_INC 1024
  784. test_addr = 0x80000000;
  785. test_data = 0x0;
  786. for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
  787. hpi_write_word(pdo, test_addr + i, test_data);
  788. test_data++;
  789. }
  790. test_addr = 0x80000000;
  791. test_data = 0x0;
  792. for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
  793. data = hpi_read_word(pdo, test_addr + i);
  794. if (data != test_data) {
  795. HPI_DEBUG_LOG(ERROR,
  796. "DSP dram %x %x %x %x\n",
  797. test_addr + i, test_data,
  798. data, dsp_index);
  799. return HPI6000_ERROR_INIT_SDRAM2;
  800. }
  801. test_data++;
  802. }
  803. }
  804. /* write the DSP code down into the DSPs memory */
  805. /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
  806. dsp_code.ps_dev = pao->pci.pci_dev;
  807. error = hpi_dsp_code_open(boot_load_family, &dsp_code,
  808. pos_error_code);
  809. if (error)
  810. return error;
  811. while (1) {
  812. u32 length;
  813. u32 address;
  814. u32 type;
  815. u32 *pcode;
  816. error = hpi_dsp_code_read_word(&dsp_code, &length);
  817. if (error)
  818. break;
  819. if (length == 0xFFFFFFFF)
  820. break; /* end of code */
  821. error = hpi_dsp_code_read_word(&dsp_code, &address);
  822. if (error)
  823. break;
  824. error = hpi_dsp_code_read_word(&dsp_code, &type);
  825. if (error)
  826. break;
  827. error = hpi_dsp_code_read_block(length, &dsp_code,
  828. &pcode);
  829. if (error)
  830. break;
  831. error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
  832. address, pcode, length);
  833. if (error)
  834. break;
  835. }
  836. if (error) {
  837. hpi_dsp_code_close(&dsp_code);
  838. return error;
  839. }
  840. /* verify that code was written correctly */
  841. /* this time through, assume no errors in DSP code file/array */
  842. hpi_dsp_code_rewind(&dsp_code);
  843. while (1) {
  844. u32 length;
  845. u32 address;
  846. u32 type;
  847. u32 *pcode;
  848. hpi_dsp_code_read_word(&dsp_code, &length);
  849. if (length == 0xFFFFFFFF)
  850. break; /* end of code */
  851. hpi_dsp_code_read_word(&dsp_code, &address);
  852. hpi_dsp_code_read_word(&dsp_code, &type);
  853. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  854. for (i = 0; i < length; i++) {
  855. data = hpi_read_word(pdo, address);
  856. if (data != *pcode) {
  857. error = HPI6000_ERROR_INIT_VERIFY;
  858. HPI_DEBUG_LOG(ERROR,
  859. "DSP verify %x %x %x %x\n",
  860. address, *pcode, data,
  861. dsp_index);
  862. break;
  863. }
  864. pcode++;
  865. address += 4;
  866. }
  867. if (error)
  868. break;
  869. }
  870. hpi_dsp_code_close(&dsp_code);
  871. if (error)
  872. return error;
  873. /* zero out the hostmailbox */
  874. {
  875. u32 address = HPI_HIF_ADDR(host_cmd);
  876. for (i = 0; i < 4; i++) {
  877. hpi_write_word(pdo, address, 0);
  878. address += 4;
  879. }
  880. }
  881. /* write the DSP number into the hostmailbox */
  882. /* structure before starting the DSP */
  883. hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
  884. /* write the DSP adapter Info into the */
  885. /* hostmailbox before starting the DSP */
  886. if (dsp_index > 0)
  887. hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
  888. adapter_info);
  889. /* step 3. Start code by sending interrupt */
  890. iowrite32(0x00030003, pdo->prHPI_control);
  891. hpios_delay_micro_seconds(10000);
  892. /* wait for a non-zero value in hostcmd -
  893. * indicating initialization is complete
  894. *
  895. * Init could take a while if DSP checks SDRAM memory
  896. * Was 200000. Increased to 2000000 for ASI8801 so we
  897. * don't get 938 errors.
  898. */
  899. timeout = 2000000;
  900. while (timeout) {
  901. do {
  902. read = hpi_read_word(pdo,
  903. HPI_HIF_ADDR(host_cmd));
  904. } while (--timeout
  905. && hpi6000_check_PCI2040_error_flag(pao,
  906. H6READ));
  907. if (read)
  908. break;
  909. /* The following is a workaround for bug #94:
  910. * Bluescreen on install and subsequent boots on a
  911. * DELL PowerEdge 600SC PC with 1.8GHz P4 and
  912. * ServerWorks chipset. Without this delay the system
  913. * locks up with a bluescreen (NOT GPF or pagefault).
  914. */
  915. else
  916. hpios_delay_micro_seconds(10000);
  917. }
  918. if (timeout == 0)
  919. return HPI6000_ERROR_INIT_NOACK;
  920. /* read the DSP adapter Info from the */
  921. /* hostmailbox structure after starting the DSP */
  922. if (dsp_index == 0) {
  923. /*u32 dwTestData=0; */
  924. u32 mask = 0;
  925. adapter_info =
  926. hpi_read_word(pdo,
  927. HPI_HIF_ADDR(adapter_info));
  928. if (HPI_ADAPTER_FAMILY_ASI
  929. (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
  930. (adapter_info)) ==
  931. HPI_ADAPTER_FAMILY_ASI(0x6200))
  932. /* all 6200 cards have this many DSPs */
  933. phw->num_dsp = 2;
  934. /* test that the PLD is programmed */
  935. /* and we can read/write 24bits */
  936. #define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
  937. switch (boot_load_family) {
  938. case HPI_ADAPTER_FAMILY_ASI(0x6200):
  939. /* ASI6100/6200 has 24bit path to FPGA */
  940. mask = 0xFFFFFF00L;
  941. /* ASI5100 uses AX6 code, */
  942. /* but has no PLD r/w register to test */
  943. if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
  944. subsystem_device) ==
  945. HPI_ADAPTER_FAMILY_ASI(0x5100))
  946. mask = 0x00000000L;
  947. /* ASI5200 uses AX6 code, */
  948. /* but has no PLD r/w register to test */
  949. if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
  950. subsystem_device) ==
  951. HPI_ADAPTER_FAMILY_ASI(0x5200))
  952. mask = 0x00000000L;
  953. break;
  954. case HPI_ADAPTER_FAMILY_ASI(0x8800):
  955. /* ASI8800 has 16bit path to FPGA */
  956. mask = 0xFFFF0000L;
  957. break;
  958. }
  959. test_data = 0xAAAAAA00L & mask;
  960. /* write to 24 bit Debug register (D31-D8) */
  961. hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
  962. read = hpi_read_word(pdo,
  963. PLD_BASE_ADDRESS + 4L) & mask;
  964. if (read != test_data) {
  965. HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
  966. read);
  967. return HPI6000_ERROR_INIT_PLDTEST1;
  968. }
  969. test_data = 0x55555500L & mask;
  970. hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
  971. read = hpi_read_word(pdo,
  972. PLD_BASE_ADDRESS + 4L) & mask;
  973. if (read != test_data) {
  974. HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
  975. read);
  976. return HPI6000_ERROR_INIT_PLDTEST2;
  977. }
  978. }
  979. } /* for numDSP */
  980. return 0;
  981. }
  982. #define PCI_TIMEOUT 100
  983. static int hpi_set_address(struct dsp_obj *pdo, u32 address)
  984. {
  985. u32 timeout = PCI_TIMEOUT;
  986. do {
  987. iowrite32(address, pdo->prHPI_address);
  988. } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
  989. H6WRITE)
  990. && --timeout);
  991. if (timeout)
  992. return 0;
  993. return 1;
  994. }
  995. /* write one word to the HPI port */
  996. static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
  997. {
  998. if (hpi_set_address(pdo, address))
  999. return;
  1000. iowrite32(data, pdo->prHPI_data);
  1001. }
  1002. /* read one word from the HPI port */
  1003. static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
  1004. {
  1005. u32 data = 0;
  1006. if (hpi_set_address(pdo, address))
  1007. return 0; /*? No way to return error */
  1008. /* take care of errata in revB DSP (2.0.1) */
  1009. data = ioread32(pdo->prHPI_data);
  1010. return data;
  1011. }
  1012. /* write a block of 32bit words to the DSP HPI port using auto-inc mode */
  1013. static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  1014. u32 length)
  1015. {
  1016. u16 length16 = length - 1;
  1017. if (length == 0)
  1018. return;
  1019. if (hpi_set_address(pdo, address))
  1020. return;
  1021. iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
  1022. /* take care of errata in revB DSP (2.0.1) */
  1023. /* must end with non auto-inc */
  1024. iowrite32(*(pdata + length - 1), pdo->prHPI_data);
  1025. }
  1026. /** read a block of 32bit words from the DSP HPI port using auto-inc mode
  1027. */
  1028. static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  1029. u32 length)
  1030. {
  1031. u16 length16 = length - 1;
  1032. if (length == 0)
  1033. return;
  1034. if (hpi_set_address(pdo, address))
  1035. return;
  1036. ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
  1037. /* take care of errata in revB DSP (2.0.1) */
  1038. /* must end with non auto-inc */
  1039. *(pdata + length - 1) = ioread32(pdo->prHPI_data);
  1040. }
  1041. static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
  1042. u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
  1043. {
  1044. struct dsp_obj *pdo =
  1045. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1046. u32 time_out = PCI_TIMEOUT;
  1047. int c6711_burst_size = 128;
  1048. u32 local_hpi_address = hpi_address;
  1049. int local_count = count;
  1050. int xfer_size;
  1051. u32 *pdata = source;
  1052. while (local_count) {
  1053. if (local_count > c6711_burst_size)
  1054. xfer_size = c6711_burst_size;
  1055. else
  1056. xfer_size = local_count;
  1057. time_out = PCI_TIMEOUT;
  1058. do {
  1059. hpi_write_block(pdo, local_hpi_address, pdata,
  1060. xfer_size);
  1061. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
  1062. && --time_out);
  1063. if (!time_out)
  1064. break;
  1065. pdata += xfer_size;
  1066. local_hpi_address += sizeof(u32) * xfer_size;
  1067. local_count -= xfer_size;
  1068. }
  1069. if (time_out)
  1070. return 0;
  1071. else
  1072. return 1;
  1073. }
  1074. static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
  1075. u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
  1076. {
  1077. struct dsp_obj *pdo =
  1078. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1079. u32 time_out = PCI_TIMEOUT;
  1080. int c6711_burst_size = 16;
  1081. u32 local_hpi_address = hpi_address;
  1082. int local_count = count;
  1083. int xfer_size;
  1084. u32 *pdata = dest;
  1085. u32 loop_count = 0;
  1086. while (local_count) {
  1087. if (local_count > c6711_burst_size)
  1088. xfer_size = c6711_burst_size;
  1089. else
  1090. xfer_size = local_count;
  1091. time_out = PCI_TIMEOUT;
  1092. do {
  1093. hpi_read_block(pdo, local_hpi_address, pdata,
  1094. xfer_size);
  1095. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1096. && --time_out);
  1097. if (!time_out)
  1098. break;
  1099. pdata += xfer_size;
  1100. local_hpi_address += sizeof(u32) * xfer_size;
  1101. local_count -= xfer_size;
  1102. loop_count++;
  1103. }
  1104. if (time_out)
  1105. return 0;
  1106. else
  1107. return 1;
  1108. }
  1109. static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
  1110. u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
  1111. {
  1112. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  1113. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1114. u32 timeout;
  1115. u16 ack;
  1116. u32 address;
  1117. u32 length;
  1118. u32 *p_data;
  1119. u16 error = 0;
  1120. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1121. if (ack & HPI_HIF_ERROR_MASK) {
  1122. pao->dsp_crashed++;
  1123. return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1124. }
  1125. pao->dsp_crashed = 0;
  1126. /* get the message address and size */
  1127. if (phw->message_buffer_address_on_dsp == 0) {
  1128. timeout = TIMEOUT;
  1129. do {
  1130. address =
  1131. hpi_read_word(pdo,
  1132. HPI_HIF_ADDR(message_buffer_address));
  1133. phw->message_buffer_address_on_dsp = address;
  1134. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1135. && --timeout);
  1136. if (!timeout)
  1137. return HPI6000_ERROR_MSG_GET_ADR;
  1138. } else
  1139. address = phw->message_buffer_address_on_dsp;
  1140. length = phm->size;
  1141. /* send the message */
  1142. p_data = (u32 *)phm;
  1143. if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
  1144. (u16)length / 4))
  1145. return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
  1146. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
  1147. return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
  1148. hpi6000_send_dsp_interrupt(pdo);
  1149. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
  1150. if (ack & HPI_HIF_ERROR_MASK)
  1151. return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
  1152. /* get the response address */
  1153. if (phw->response_buffer_address_on_dsp == 0) {
  1154. timeout = TIMEOUT;
  1155. do {
  1156. address =
  1157. hpi_read_word(pdo,
  1158. HPI_HIF_ADDR(response_buffer_address));
  1159. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1160. && --timeout);
  1161. phw->response_buffer_address_on_dsp = address;
  1162. if (!timeout)
  1163. return HPI6000_ERROR_RESP_GET_ADR;
  1164. } else
  1165. address = phw->response_buffer_address_on_dsp;
  1166. /* read the length of the response back from the DSP */
  1167. timeout = TIMEOUT;
  1168. do {
  1169. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1170. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
  1171. if (!timeout)
  1172. length = sizeof(struct hpi_response);
  1173. /* get the response */
  1174. p_data = (u32 *)phr;
  1175. if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
  1176. (u16)length / 4))
  1177. return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
  1178. /* set i/f back to idle */
  1179. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1180. return HPI6000_ERROR_MSG_RESP_IDLECMD;
  1181. hpi6000_send_dsp_interrupt(pdo);
  1182. error = hpi_validate_response(phm, phr);
  1183. return error;
  1184. }
  1185. /* have to set up the below defines to match stuff in the MAP file */
  1186. #define MSG_ADDRESS (HPI_HIF_BASE+0x18)
  1187. #define MSG_LENGTH 11
  1188. #define RESP_ADDRESS (HPI_HIF_BASE+0x44)
  1189. #define RESP_LENGTH 16
  1190. #define QUEUE_START (HPI_HIF_BASE+0x88)
  1191. #define QUEUE_SIZE 0x8000
  1192. static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
  1193. {
  1194. /*#define CHECKING // comment this line in to enable checking */
  1195. #ifdef CHECKING
  1196. if (address < (u32)MSG_ADDRESS)
  1197. return 0;
  1198. if (address > (u32)(QUEUE_START + QUEUE_SIZE))
  1199. return 0;
  1200. if ((address + (length_in_dwords << 2)) >
  1201. (u32)(QUEUE_START + QUEUE_SIZE))
  1202. return 0;
  1203. #else
  1204. (void)address;
  1205. (void)length_in_dwords;
  1206. return 1;
  1207. #endif
  1208. }
  1209. static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  1210. struct hpi_message *phm, struct hpi_response *phr)
  1211. {
  1212. struct dsp_obj *pdo =
  1213. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1214. u32 data_sent = 0;
  1215. u16 ack;
  1216. u32 length, address;
  1217. u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
  1218. u16 time_out = 8;
  1219. (void)phr;
  1220. /* round dwDataSize down to nearest 4 bytes */
  1221. while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
  1222. && --time_out) {
  1223. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1224. if (ack & HPI_HIF_ERROR_MASK)
  1225. return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
  1226. if (hpi6000_send_host_command(pao, dsp_index,
  1227. HPI_HIF_SEND_DATA))
  1228. return HPI6000_ERROR_SEND_DATA_CMD;
  1229. hpi6000_send_dsp_interrupt(pdo);
  1230. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
  1231. if (ack & HPI_HIF_ERROR_MASK)
  1232. return HPI6000_ERROR_SEND_DATA_ACK;
  1233. do {
  1234. /* get the address and size */
  1235. address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
  1236. /* DSP returns number of DWORDS */
  1237. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1238. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
  1239. if (!hpi6000_send_data_check_adr(address, length))
  1240. return HPI6000_ERROR_SEND_DATA_ADR;
  1241. /* send the data. break data into 512 DWORD blocks (2K bytes)
  1242. * and send using block write. 2Kbytes is the max as this is the
  1243. * memory window given to the HPI data register by the PCI2040
  1244. */
  1245. {
  1246. u32 len = length;
  1247. u32 blk_len = 512;
  1248. while (len) {
  1249. if (len < blk_len)
  1250. blk_len = len;
  1251. if (hpi6000_dsp_block_write32(pao, dsp_index,
  1252. address, p_data, blk_len))
  1253. return HPI6000_ERROR_SEND_DATA_WRITE;
  1254. address += blk_len * 4;
  1255. p_data += blk_len;
  1256. len -= blk_len;
  1257. }
  1258. }
  1259. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1260. return HPI6000_ERROR_SEND_DATA_IDLECMD;
  1261. hpi6000_send_dsp_interrupt(pdo);
  1262. data_sent += length * 4;
  1263. }
  1264. if (!time_out)
  1265. return HPI6000_ERROR_SEND_DATA_TIMEOUT;
  1266. return 0;
  1267. }
  1268. static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  1269. struct hpi_message *phm, struct hpi_response *phr)
  1270. {
  1271. struct dsp_obj *pdo =
  1272. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1273. u32 data_got = 0;
  1274. u16 ack;
  1275. u32 length, address;
  1276. u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
  1277. (void)phr; /* this parameter not used! */
  1278. /* round dwDataSize down to nearest 4 bytes */
  1279. while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
  1280. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1281. if (ack & HPI_HIF_ERROR_MASK)
  1282. return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
  1283. if (hpi6000_send_host_command(pao, dsp_index,
  1284. HPI_HIF_GET_DATA))
  1285. return HPI6000_ERROR_GET_DATA_CMD;
  1286. hpi6000_send_dsp_interrupt(pdo);
  1287. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
  1288. if (ack & HPI_HIF_ERROR_MASK)
  1289. return HPI6000_ERROR_GET_DATA_ACK;
  1290. /* get the address and size */
  1291. do {
  1292. address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
  1293. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1294. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
  1295. /* read the data */
  1296. {
  1297. u32 len = length;
  1298. u32 blk_len = 512;
  1299. while (len) {
  1300. if (len < blk_len)
  1301. blk_len = len;
  1302. if (hpi6000_dsp_block_read32(pao, dsp_index,
  1303. address, p_data, blk_len))
  1304. return HPI6000_ERROR_GET_DATA_READ;
  1305. address += blk_len * 4;
  1306. p_data += blk_len;
  1307. len -= blk_len;
  1308. }
  1309. }
  1310. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1311. return HPI6000_ERROR_GET_DATA_IDLECMD;
  1312. hpi6000_send_dsp_interrupt(pdo);
  1313. data_got += length * 4;
  1314. }
  1315. return 0;
  1316. }
  1317. static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
  1318. {
  1319. iowrite32(0x00030003, pdo->prHPI_control); /* DSPINT */
  1320. }
  1321. static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
  1322. u16 dsp_index, u32 host_cmd)
  1323. {
  1324. struct dsp_obj *pdo =
  1325. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1326. u32 timeout = TIMEOUT;
  1327. /* set command */
  1328. do {
  1329. hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
  1330. /* flush the FIFO */
  1331. hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
  1332. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
  1333. /* reset the interrupt bit */
  1334. iowrite32(0x00040004, pdo->prHPI_control);
  1335. if (timeout)
  1336. return 0;
  1337. else
  1338. return 1;
  1339. }
  1340. /* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
  1341. static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
  1342. u16 read_or_write)
  1343. {
  1344. u32 hPI_error;
  1345. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  1346. /* read the error bits from the PCI2040 */
  1347. hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
  1348. if (hPI_error) {
  1349. /* reset the error flag */
  1350. iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
  1351. phw->pCI2040HPI_error_count++;
  1352. if (read_or_write == 1)
  1353. gw_pci_read_asserts++; /************* inc global */
  1354. else
  1355. gw_pci_write_asserts++;
  1356. return 1;
  1357. } else
  1358. return 0;
  1359. }
  1360. static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
  1361. u32 ack_value)
  1362. {
  1363. struct dsp_obj *pdo =
  1364. &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
  1365. u32 ack = 0L;
  1366. u32 timeout;
  1367. u32 hPIC = 0L;
  1368. /* wait for host interrupt to signal ack is ready */
  1369. timeout = TIMEOUT;
  1370. while (--timeout) {
  1371. hPIC = ioread32(pdo->prHPI_control);
  1372. if (hPIC & 0x04) /* 0x04 = HINT from DSP */
  1373. break;
  1374. }
  1375. if (timeout == 0)
  1376. return HPI_HIF_ERROR_MASK;
  1377. /* wait for dwAckValue */
  1378. timeout = TIMEOUT;
  1379. while (--timeout) {
  1380. /* read the ack mailbox */
  1381. ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
  1382. if (ack == ack_value)
  1383. break;
  1384. if ((ack & HPI_HIF_ERROR_MASK)
  1385. && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
  1386. break;
  1387. /*for (i=0;i<1000;i++) */
  1388. /* dwPause=i+1; */
  1389. }
  1390. if (ack & HPI_HIF_ERROR_MASK)
  1391. /* indicates bad read from DSP -
  1392. typically 0xffffff is read for some reason */
  1393. ack = HPI_HIF_ERROR_MASK;
  1394. if (timeout == 0)
  1395. ack = HPI_HIF_ERROR_MASK;
  1396. return (short)ack;
  1397. }
  1398. static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
  1399. struct hpi_message *phm)
  1400. {
  1401. const u16 dsp_index = 0;
  1402. struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
  1403. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1404. u32 timeout;
  1405. u32 cache_dirty_flag;
  1406. u16 err;
  1407. hpios_dsplock_lock(pao);
  1408. timeout = TIMEOUT;
  1409. do {
  1410. cache_dirty_flag =
  1411. hpi_read_word((struct dsp_obj *)pdo,
  1412. HPI_HIF_ADDR(control_cache_is_dirty));
  1413. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
  1414. if (!timeout) {
  1415. err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
  1416. goto unlock;
  1417. }
  1418. if (cache_dirty_flag) {
  1419. /* read the cached controls */
  1420. u32 address;
  1421. u32 length;
  1422. timeout = TIMEOUT;
  1423. if (pdo->control_cache_address_on_dsp == 0) {
  1424. do {
  1425. address =
  1426. hpi_read_word((struct dsp_obj *)pdo,
  1427. HPI_HIF_ADDR(control_cache_address));
  1428. length = hpi_read_word((struct dsp_obj *)pdo,
  1429. HPI_HIF_ADDR
  1430. (control_cache_size_in_bytes));
  1431. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1432. && --timeout);
  1433. if (!timeout) {
  1434. err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
  1435. goto unlock;
  1436. }
  1437. pdo->control_cache_address_on_dsp = address;
  1438. pdo->control_cache_length_on_dsp = length;
  1439. } else {
  1440. address = pdo->control_cache_address_on_dsp;
  1441. length = pdo->control_cache_length_on_dsp;
  1442. }
  1443. if (hpi6000_dsp_block_read32(pao, dsp_index, address,
  1444. (u32 *)&phw->control_cache[0],
  1445. length / sizeof(u32))) {
  1446. err = HPI6000_ERROR_CONTROL_CACHE_READ;
  1447. goto unlock;
  1448. }
  1449. do {
  1450. hpi_write_word((struct dsp_obj *)pdo,
  1451. HPI_HIF_ADDR(control_cache_is_dirty), 0);
  1452. /* flush the FIFO */
  1453. hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
  1454. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
  1455. && --timeout);
  1456. if (!timeout) {
  1457. err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
  1458. goto unlock;
  1459. }
  1460. }
  1461. err = 0;
  1462. unlock:
  1463. hpios_dsplock_unlock(pao);
  1464. return err;
  1465. }
  1466. /** Get dsp index for multi DSP adapters only */
  1467. static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
  1468. {
  1469. u16 ret = 0;
  1470. switch (phm->object) {
  1471. case HPI_OBJ_ISTREAM:
  1472. if (phm->obj_index < 2)
  1473. ret = 1;
  1474. break;
  1475. case HPI_OBJ_PROFILE:
  1476. ret = phm->obj_index;
  1477. break;
  1478. default:
  1479. break;
  1480. }
  1481. return ret;
  1482. }
  1483. /** Complete transaction with DSP
  1484. Send message, get response, send or get stream data if any.
  1485. */
  1486. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1487. struct hpi_response *phr)
  1488. {
  1489. u16 error = 0;
  1490. u16 dsp_index = 0;
  1491. u16 num_dsp = ((struct hpi_hw_obj *)pao->priv)->num_dsp;
  1492. if (num_dsp < 2)
  1493. dsp_index = 0;
  1494. else {
  1495. dsp_index = get_dsp_index(pao, phm);
  1496. /* is this checked on the DSP anyway? */
  1497. if ((phm->function == HPI_ISTREAM_GROUP_ADD)
  1498. || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
  1499. struct hpi_message hm;
  1500. u16 add_index;
  1501. hm.obj_index = phm->u.d.u.stream.stream_index;
  1502. hm.object = phm->u.d.u.stream.object_type;
  1503. add_index = get_dsp_index(pao, &hm);
  1504. if (add_index != dsp_index) {
  1505. phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
  1506. return;
  1507. }
  1508. }
  1509. }
  1510. hpios_dsplock_lock(pao);
  1511. error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
  1512. if (error) /* something failed in the HPI/DSP interface */
  1513. goto err;
  1514. if (phr->error) /* something failed in the DSP */
  1515. goto out;
  1516. switch (phm->function) {
  1517. case HPI_OSTREAM_WRITE:
  1518. case HPI_ISTREAM_ANC_WRITE:
  1519. error = hpi6000_send_data(pao, dsp_index, phm, phr);
  1520. break;
  1521. case HPI_ISTREAM_READ:
  1522. case HPI_OSTREAM_ANC_READ:
  1523. error = hpi6000_get_data(pao, dsp_index, phm, phr);
  1524. break;
  1525. case HPI_ADAPTER_GET_ASSERT:
  1526. phr->u.ax.assert.dsp_index = 0; /* dsp 0 default */
  1527. if (num_dsp == 2) {
  1528. if (!phr->u.ax.assert.count) {
  1529. /* no assert from dsp 0, check dsp 1 */
  1530. error = hpi6000_message_response_sequence(pao,
  1531. 1, phm, phr);
  1532. phr->u.ax.assert.dsp_index = 1;
  1533. }
  1534. }
  1535. }
  1536. err:
  1537. if (error) {
  1538. if (error >= HPI_ERROR_BACKEND_BASE) {
  1539. phr->error = HPI_ERROR_DSP_COMMUNICATION;
  1540. phr->specific_error = error;
  1541. } else {
  1542. phr->error = error;
  1543. }
  1544. /* just the header of the response is valid */
  1545. phr->size = sizeof(struct hpi_response_header);
  1546. }
  1547. out:
  1548. hpios_dsplock_unlock(pao);
  1549. return;
  1550. }