hpi6000.c 50 KB

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