hpi6000.c 49 KB

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