hpi6000.c 50 KB

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