ipa_uc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include "ipa_i.h"
  6. #include <linux/delay.h>
  7. #define IPA_RAM_UC_SMEM_SIZE 128
  8. #define IPA_HW_INTERFACE_VERSION 0x2000
  9. #define IPA_PKT_FLUSH_TO_US 100
  10. #define IPA_UC_POLL_SLEEP_USEC 100
  11. #define IPA_UC_POLL_MAX_RETRY 10000
  12. #define IPA_UC_DBG_STATS_GET_PROT_ID(x) (0xff & ((x) >> 24))
  13. #define IPA_UC_DBG_STATS_GET_OFFSET(x) (0x00ffffff & (x))
  14. #define IPA_UC_EVENT_RING_SIZE 10
  15. /**
  16. * Mailbox register to Interrupt HWP for CPU cmd
  17. * Usage of IPA_UC_MAILBOX_m_n doorbell instead of IPA_IRQ_EE_UC_0
  18. * due to HW limitation.
  19. *
  20. */
  21. #define IPA_CPU_2_HW_CMD_MBOX_m 0
  22. #define IPA_CPU_2_HW_CMD_MBOX_n 23
  23. #define IPA_UC_ERING_m 0
  24. #define IPA_UC_ERING_n_r 1
  25. #define IPA_UC_ERING_n_w 0
  26. #define IPA_UC_MON_INTERVAL 5
  27. /**
  28. * enum ipa3_cpu_2_hw_commands - Values that represent the commands from the CPU
  29. * IPA_CPU_2_HW_CMD_NO_OP : No operation is required.
  30. * IPA_CPU_2_HW_CMD_UPDATE_FLAGS : Update SW flags which defines the behavior
  31. * of HW.
  32. * IPA_CPU_2_HW_CMD_DEBUG_RUN_TEST : Launch predefined test over HW.
  33. * IPA_CPU_2_HW_CMD_DEBUG_GET_INFO : Read HW internal debug information.
  34. * IPA_CPU_2_HW_CMD_ERR_FATAL : CPU instructs HW to perform error fatal
  35. * handling.
  36. * IPA_CPU_2_HW_CMD_CLK_GATE : CPU instructs HW to goto Clock Gated state.
  37. * IPA_CPU_2_HW_CMD_CLK_UNGATE : CPU instructs HW to goto Clock Ungated state.
  38. * IPA_CPU_2_HW_CMD_MEMCPY : CPU instructs HW to do memcopy using QMB.
  39. * IPA_CPU_2_HW_CMD_RESET_PIPE : Command to reset a pipe - SW WA for a HW bug.
  40. * IPA_CPU_2_HW_CMD_GSI_CH_EMPTY : Command to check for GSI channel emptiness.
  41. * IPA_CPU_2_HW_CMD_REMOTE_IPA_INFO: Command to store remote IPA Info
  42. * IPA_CPU_2_HW_CMD_SETUP_EVENT_RING: Command to setup the event ring
  43. * IPA_CPU_2_HW_CMD_ENABLE_FLOW_CTL_MONITOR: Command to enable pipe monitoring.
  44. * IPA_CPU_2_HW_CMD_UPDATE_FLOW_CTL_MONITOR: Command to update pipes to monitor.
  45. * IPA_CPU_2_HW_CMD_DISABLE_FLOW_CTL_MONITOR: Command to disable pipe
  46. monitoring, no parameter required.
  47. */
  48. enum ipa3_cpu_2_hw_commands {
  49. IPA_CPU_2_HW_CMD_NO_OP =
  50. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 0),
  51. IPA_CPU_2_HW_CMD_UPDATE_FLAGS =
  52. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 1),
  53. IPA_CPU_2_HW_CMD_DEBUG_RUN_TEST =
  54. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 2),
  55. IPA_CPU_2_HW_CMD_DEBUG_GET_INFO =
  56. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 3),
  57. IPA_CPU_2_HW_CMD_ERR_FATAL =
  58. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 4),
  59. IPA_CPU_2_HW_CMD_CLK_GATE =
  60. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 5),
  61. IPA_CPU_2_HW_CMD_CLK_UNGATE =
  62. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 6),
  63. IPA_CPU_2_HW_CMD_MEMCPY =
  64. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 7),
  65. IPA_CPU_2_HW_CMD_RESET_PIPE =
  66. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 8),
  67. IPA_CPU_2_HW_CMD_REG_WRITE =
  68. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 9),
  69. IPA_CPU_2_HW_CMD_GSI_CH_EMPTY =
  70. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 10),
  71. IPA_CPU_2_HW_CMD_REMOTE_IPA_INFO =
  72. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 11),
  73. IPA_CPU_2_HW_CMD_SETUP_EVENT_RING =
  74. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 12),
  75. IPA_CPU_2_HW_CMD_ENABLE_FLOW_CTL_MONITOR =
  76. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 13),
  77. IPA_CPU_2_HW_CMD_UPDATE_FLOW_CTL_MONITOR =
  78. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 14),
  79. IPA_CPU_2_HW_CMD_DISABLE_FLOW_CTL_MONITOR =
  80. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 15),
  81. };
  82. /**
  83. * enum ipa3_hw_2_cpu_responses - Values that represent common HW responses
  84. * to CPU commands.
  85. * @IPA_HW_2_CPU_RESPONSE_NO_OP : No operation response
  86. * @IPA_HW_2_CPU_RESPONSE_INIT_COMPLETED : HW shall send this command once
  87. * boot sequence is completed and HW is ready to serve commands from CPU
  88. * @IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED: Response to CPU commands
  89. * @IPA_HW_2_CPU_RESPONSE_DEBUG_GET_INFO : Response to
  90. * IPA_CPU_2_HW_CMD_DEBUG_GET_INFO command
  91. */
  92. enum ipa3_hw_2_cpu_responses {
  93. IPA_HW_2_CPU_RESPONSE_NO_OP =
  94. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 0),
  95. IPA_HW_2_CPU_RESPONSE_INIT_COMPLETED =
  96. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 1),
  97. IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED =
  98. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 2),
  99. IPA_HW_2_CPU_RESPONSE_DEBUG_GET_INFO =
  100. FEATURE_ENUM_VAL(IPA_HW_FEATURE_COMMON, 3),
  101. };
  102. /**
  103. * struct IpaHwMemCopyData_t - Structure holding the parameters
  104. * for IPA_CPU_2_HW_CMD_MEMCPY command.
  105. *
  106. * The parameters are passed as immediate params in the shared memory
  107. */
  108. struct IpaHwMemCopyData_t {
  109. u32 destination_addr;
  110. u32 source_addr;
  111. u32 dest_buffer_size;
  112. u32 source_buffer_size;
  113. };
  114. /**
  115. * struct IpaHwRegWriteCmdData_t - holds the parameters for
  116. * IPA_CPU_2_HW_CMD_REG_WRITE command. Parameters are
  117. * sent as 64b immediate parameters.
  118. * @RegisterAddress: RG10 register address where the value needs to be written
  119. * @RegisterValue: 32-Bit value to be written into the register
  120. */
  121. struct IpaHwRegWriteCmdData_t {
  122. u32 RegisterAddress;
  123. u32 RegisterValue;
  124. };
  125. /**
  126. * union IpaHwCpuCmdCompletedResponseData_t - Structure holding the parameters
  127. * for IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED response.
  128. * @originalCmdOp : The original command opcode
  129. * @status : 0 for success indication, otherwise failure
  130. * @responseData : 16b responseData
  131. *
  132. * Parameters are sent as 32b immediate parameters.
  133. */
  134. union IpaHwCpuCmdCompletedResponseData_t {
  135. struct IpaHwCpuCmdCompletedResponseParams_t {
  136. u32 originalCmdOp:8;
  137. u32 status:8;
  138. u32 responseData:16;
  139. } __packed params;
  140. u32 raw32b;
  141. } __packed;
  142. /**
  143. * union IpaHwUpdateFlagsCmdData_t - Structure holding the parameters for
  144. * IPA_CPU_2_HW_CMD_UPDATE_FLAGS command
  145. * @newFlags: SW flags defined the behavior of HW.
  146. * This field is expected to be used as bitmask for enum ipa3_hw_flags
  147. */
  148. union IpaHwUpdateFlagsCmdData_t {
  149. struct IpaHwUpdateFlagsCmdParams_t {
  150. u32 newFlags;
  151. } params;
  152. u32 raw32b;
  153. };
  154. /**
  155. * union IpaHwChkChEmptyCmdData_t - Structure holding the parameters for
  156. * IPA_CPU_2_HW_CMD_GSI_CH_EMPTY command. Parameters are sent as 32b
  157. * immediate parameters.
  158. * @ee_n : EE owner of the channel
  159. * @vir_ch_id : GSI virtual channel ID of the channel to checked of emptiness
  160. * @reserved_02_04 : Reserved
  161. */
  162. union IpaHwChkChEmptyCmdData_t {
  163. struct IpaHwChkChEmptyCmdParams_t {
  164. u8 ee_n;
  165. u8 vir_ch_id;
  166. u16 reserved_02_04;
  167. } __packed params;
  168. u32 raw32b;
  169. } __packed;
  170. struct IpaSetupEventRingCmdParams_t {
  171. u32 ring_base_pa;
  172. u32 ring_base_pa_hi;
  173. u32 ring_size; //size = 10
  174. } __packed;
  175. /**
  176. * Structure holding the parameters for
  177. * IPA_CPU_2_HW_CMD_SETUP_EVENT_RING command. Parameters are
  178. * sent as 32b immediate parameters.
  179. */
  180. union IpaSetupEventRingCmdData_t {
  181. struct IpaSetupEventRingCmdParams_t event;
  182. u32 raw32b[6]; //uc-internal
  183. } __packed;
  184. /**
  185. * Structure holding the parameters for IPA_CPU_2_HW_CMD_REMOTE_IPA_INFO
  186. * command.
  187. * @remoteIPAAddr: 5G IPA address : uC proxies Q6 doorbell to this address
  188. * @mboxN: mbox on which Q6 will interrupt uC
  189. */
  190. struct IpaHwDbAddrInfo_t {
  191. u32 remoteIPAAddr;
  192. uint32_t mboxN;
  193. } __packed;
  194. /**
  195. * Structure holding the parameters for IPA_CPU_2_HW_CMD_ENABLE_PIPE_MONITOR
  196. * command.
  197. * @ipaProdGsiChid IPA prod GSI chid to monitor
  198. * @redMarkerThreshold red marker threshold in elements for the GSI channel
  199. */
  200. union IpaEnablePipeMonitorCmdData_t {
  201. struct IpaEnablePipeMonitorCmdParams_t {
  202. u32 ipaProdGsiChid:16;
  203. u32 redMarkerThreshold:16;
  204. } __packed params;
  205. u32 raw32b;
  206. } __packed;
  207. /**
  208. * Structure holding the parameters for IPA_CPU_2_HW_CMD_UPDATE_PIPE_MONITOR
  209. * command.
  210. *
  211. * @bitmask The parameter of bitmask to add/delete channels/pipes from
  212. * global monitoring pipemask
  213. * IPA pipe# bitmask or GSI chid bitmask
  214. * add_delete 1: add pipes to monitor
  215. * 0: delete pipes to monitor
  216. */
  217. struct IpaUpdateFlowCtlMonitorData_t {
  218. u32 bitmask;
  219. u8 add_delete;
  220. };
  221. static DEFINE_MUTEX(uc_loaded_nb_lock);
  222. static BLOCKING_NOTIFIER_HEAD(uc_loaded_notifier);
  223. struct ipa3_uc_hdlrs ipa3_uc_hdlrs[IPA_HW_NUM_FEATURES] = { { 0 } };
  224. const char *ipa_hw_error_str(enum ipa3_hw_errors err_type)
  225. {
  226. const char *str;
  227. switch (err_type) {
  228. case IPA_HW_ERROR_NONE:
  229. str = "IPA_HW_ERROR_NONE";
  230. break;
  231. case IPA_HW_INVALID_DOORBELL_ERROR:
  232. str = "IPA_HW_INVALID_DOORBELL_ERROR";
  233. break;
  234. case IPA_HW_DMA_ERROR:
  235. str = "IPA_HW_DMA_ERROR";
  236. break;
  237. case IPA_HW_FATAL_SYSTEM_ERROR:
  238. str = "IPA_HW_FATAL_SYSTEM_ERROR";
  239. break;
  240. case IPA_HW_INVALID_OPCODE:
  241. str = "IPA_HW_INVALID_OPCODE";
  242. break;
  243. case IPA_HW_INVALID_PARAMS:
  244. str = "IPA_HW_INVALID_PARAMS";
  245. break;
  246. case IPA_HW_CONS_DISABLE_CMD_GSI_STOP_FAILURE:
  247. str = "IPA_HW_CONS_DISABLE_CMD_GSI_STOP_FAILURE";
  248. break;
  249. case IPA_HW_PROD_DISABLE_CMD_GSI_STOP_FAILURE:
  250. str = "IPA_HW_PROD_DISABLE_CMD_GSI_STOP_FAILURE";
  251. break;
  252. case IPA_HW_GSI_CH_NOT_EMPTY_FAILURE:
  253. str = "IPA_HW_GSI_CH_NOT_EMPTY_FAILURE";
  254. break;
  255. default:
  256. str = "INVALID ipa_hw_errors type";
  257. }
  258. return str;
  259. }
  260. static void ipa3_uc_save_dbg_stats(u32 size)
  261. {
  262. u8 prot_id;
  263. u32 addr_offset;
  264. void __iomem *mmio;
  265. prot_id = IPA_UC_DBG_STATS_GET_PROT_ID(
  266. ipa3_ctx->uc_ctx.uc_sram_mmio->responseParams_1);
  267. addr_offset = IPA_UC_DBG_STATS_GET_OFFSET(
  268. ipa3_ctx->uc_ctx.uc_sram_mmio->responseParams_1);
  269. mmio = ioremap(ipa3_ctx->ipa_wrapper_base +
  270. addr_offset, sizeof(struct IpaHwRingStats_t) *
  271. MAX_CH_STATS_SUPPORTED);
  272. if (mmio == NULL) {
  273. IPAERR("unexpected NULL mmio\n");
  274. return;
  275. }
  276. switch (prot_id) {
  277. case IPA_HW_PROTOCOL_AQC:
  278. if (!ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_mmio) {
  279. ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_size =
  280. size;
  281. ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_ofst =
  282. addr_offset;
  283. ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_mmio =
  284. mmio;
  285. } else
  286. goto unmap;
  287. break;
  288. case IPA_HW_PROTOCOL_11ad:
  289. break;
  290. case IPA_HW_PROTOCOL_WDI:
  291. if (!ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_mmio) {
  292. ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_size =
  293. size;
  294. ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_ofst =
  295. addr_offset;
  296. ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_mmio =
  297. mmio;
  298. } else
  299. goto unmap;
  300. break;
  301. case IPA_HW_PROTOCOL_WDI3:
  302. if (!ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_mmio) {
  303. ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_size =
  304. size;
  305. ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_ofst =
  306. addr_offset;
  307. ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_mmio =
  308. mmio;
  309. } else
  310. goto unmap;
  311. break;
  312. case IPA_HW_PROTOCOL_ETH:
  313. break;
  314. case IPA_HW_PROTOCOL_MHIP:
  315. if (!ipa3_ctx->mhip_ctx.dbg_stats.uc_dbg_stats_mmio) {
  316. ipa3_ctx->mhip_ctx.dbg_stats.uc_dbg_stats_size =
  317. size;
  318. ipa3_ctx->mhip_ctx.dbg_stats.uc_dbg_stats_ofst =
  319. addr_offset;
  320. ipa3_ctx->mhip_ctx.dbg_stats.uc_dbg_stats_mmio =
  321. mmio;
  322. } else
  323. goto unmap;
  324. break;
  325. case IPA_HW_PROTOCOL_USB:
  326. if (!ipa3_ctx->usb_ctx.dbg_stats.uc_dbg_stats_mmio) {
  327. ipa3_ctx->usb_ctx.dbg_stats.uc_dbg_stats_size =
  328. size;
  329. ipa3_ctx->usb_ctx.dbg_stats.uc_dbg_stats_ofst =
  330. addr_offset;
  331. ipa3_ctx->usb_ctx.dbg_stats.uc_dbg_stats_mmio =
  332. mmio;
  333. } else
  334. goto unmap;
  335. break;
  336. default:
  337. IPAERR("unknown protocols %d\n", prot_id);
  338. goto unmap;
  339. }
  340. return;
  341. unmap:
  342. iounmap(mmio);
  343. }
  344. static void ipa3_log_evt_hdlr(void)
  345. {
  346. int i;
  347. if (!ipa3_ctx->uc_ctx.uc_event_top_ofst) {
  348. ipa3_ctx->uc_ctx.uc_event_top_ofst =
  349. ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams;
  350. if (ipa3_ctx->uc_ctx.uc_event_top_ofst +
  351. sizeof(struct IpaHwEventLogInfoData_t) >=
  352. ipa3_ctx->ctrl->ipa_reg_base_ofst +
  353. ipahal_get_reg_n_ofst(
  354. IPA_SW_AREA_RAM_DIRECT_ACCESS_n, 0) +
  355. ipa3_ctx->smem_sz) {
  356. IPAERR("uc_top 0x%x outside SRAM\n",
  357. ipa3_ctx->uc_ctx.uc_event_top_ofst);
  358. goto bad_uc_top_ofst;
  359. }
  360. ipa3_ctx->uc_ctx.uc_event_top_mmio = ioremap(
  361. ipa3_ctx->ipa_wrapper_base +
  362. ipa3_ctx->uc_ctx.uc_event_top_ofst,
  363. sizeof(struct IpaHwEventLogInfoData_t));
  364. if (!ipa3_ctx->uc_ctx.uc_event_top_mmio) {
  365. IPAERR("fail to ioremap uc top\n");
  366. goto bad_uc_top_ofst;
  367. }
  368. for (i = 0; i < IPA_HW_NUM_FEATURES; i++) {
  369. if (ipa3_uc_hdlrs[i].ipa_uc_event_log_info_hdlr)
  370. ipa3_uc_hdlrs[i].ipa_uc_event_log_info_hdlr
  371. (ipa3_ctx->uc_ctx.uc_event_top_mmio);
  372. }
  373. } else {
  374. if (ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams !=
  375. ipa3_ctx->uc_ctx.uc_event_top_ofst) {
  376. IPAERR("uc top ofst changed new=%u cur=%u\n",
  377. ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams,
  378. ipa3_ctx->uc_ctx.uc_event_top_ofst);
  379. }
  380. }
  381. return;
  382. bad_uc_top_ofst:
  383. ipa3_ctx->uc_ctx.uc_event_top_ofst = 0;
  384. }
  385. static void ipa3_event_ring_hdlr(void)
  386. {
  387. u32 ering_rp, offset;
  388. void *rp_va;
  389. struct ipa_inform_wlan_bw bw_info;
  390. struct eventElement_t *e_b = NULL, *e_q = NULL;
  391. int mul = 0;
  392. ering_rp = ipahal_read_reg_mn(IPA_UC_MAILBOX_m_n,
  393. IPA_UC_ERING_m, IPA_UC_ERING_n_r);
  394. offset = sizeof(struct eventElement_t);
  395. ipa3_ctx->uc_ctx.ering_rp = ering_rp;
  396. while (ipa3_ctx->uc_ctx.ering_rp_local != ering_rp) {
  397. rp_va = ipa3_ctx->uc_ctx.event_ring.base +
  398. ipa3_ctx->uc_ctx.ering_rp_local;
  399. if (((struct eventElement_t *) rp_va)->Opcode == BW_NOTIFY) {
  400. e_b = ((struct eventElement_t *) rp_va);
  401. IPADBG("prot(%d), index (%d) throughput (%lu)\n",
  402. e_b->Protocol,
  403. e_b->Value.bw_param.ThresholdIndex,
  404. e_b->Value.bw_param.throughput);
  405. memset(&bw_info, 0, sizeof(struct ipa_inform_wlan_bw));
  406. bw_info.index =
  407. e_b->Value.bw_param.ThresholdIndex;
  408. mul = 1000 / IPA_UC_MON_INTERVAL;
  409. bw_info.throughput =
  410. e_b->Value.bw_param.throughput*mul;
  411. if (ipa3_inform_wlan_bw(&bw_info))
  412. IPAERR_RL("failed on index %d to wlan\n",
  413. bw_info.index);
  414. } else if (((struct eventElement_t *) rp_va)->Opcode
  415. == QUOTA_NOTIFY) {
  416. e_q = ((struct eventElement_t *) rp_va);
  417. IPADBG("got quota-notify %d reach(%d) usage (%lu)\n",
  418. e_q->Protocol,
  419. e_q->Value.quota_param.ThreasholdReached,
  420. e_q->Value.quota_param.usage);
  421. if (ipa3_broadcast_wdi_quota_reach_ind(0,
  422. e_q->Value.quota_param.usage))
  423. IPAERR_RL("failed on quota_reach for %d\n",
  424. e_q->Protocol);
  425. }
  426. ipa3_ctx->uc_ctx.ering_rp_local += offset;
  427. ipa3_ctx->uc_ctx.ering_rp_local %=
  428. ipa3_ctx->uc_ctx.event_ring.size;
  429. /* update wp */
  430. ipa3_ctx->uc_ctx.ering_wp_local += offset;
  431. ipa3_ctx->uc_ctx.ering_wp_local %=
  432. ipa3_ctx->uc_ctx.event_ring.size;
  433. ipahal_write_reg_mn(IPA_UC_MAILBOX_m_n, IPA_UC_ERING_m,
  434. IPA_UC_ERING_n_w, ipa3_ctx->uc_ctx.ering_wp_local);
  435. }
  436. }
  437. /**
  438. * ipa3_uc_state_check() - Check the status of the uC interface
  439. *
  440. * Return value: 0 if the uC is loaded, interface is initialized
  441. * and there was no recent failure in one of the commands.
  442. * A negative value is returned otherwise.
  443. */
  444. int ipa3_uc_state_check(void)
  445. {
  446. if (!ipa3_ctx->uc_ctx.uc_inited) {
  447. IPAERR("uC interface not initialized\n");
  448. return -EFAULT;
  449. }
  450. if (!ipa3_ctx->uc_ctx.uc_loaded) {
  451. IPAERR("uC is not loaded\n");
  452. return -EFAULT;
  453. }
  454. if (ipa3_ctx->uc_ctx.uc_failed) {
  455. IPAERR("uC has failed its last command\n");
  456. return -EFAULT;
  457. }
  458. return 0;
  459. }
  460. /**
  461. * ipa3_uc_loaded_check() - Check the uC has been loaded
  462. *
  463. * Return value: 1 if the uC is loaded, 0 otherwise
  464. */
  465. int ipa3_uc_loaded_check(void)
  466. {
  467. return ipa3_ctx->uc_ctx.uc_loaded;
  468. }
  469. EXPORT_SYMBOL(ipa3_uc_loaded_check);
  470. /**
  471. * ipa3_uc_register_ready_cb() - register a uC ready callback notifier block
  472. * @nb: notifier
  473. *
  474. * Register a callback to be called when uC is ready to receive commands. uC is
  475. * considered to be ready when it sends %IPA_HW_2_CPU_RESPONSE_INIT_COMPLETED.
  476. *
  477. * Return: 0 on successful registration, negative errno otherwise
  478. *
  479. * See blocking_notifier_chain_register() for possible errno values
  480. */
  481. int ipa3_uc_register_ready_cb(struct notifier_block *nb)
  482. {
  483. int rc;
  484. mutex_lock(&uc_loaded_nb_lock);
  485. rc = blocking_notifier_chain_register(&uc_loaded_notifier, nb);
  486. if (!rc && ipa3_ctx->uc_ctx.uc_loaded)
  487. (void) nb->notifier_call(nb, false, ipa3_ctx);
  488. mutex_unlock(&uc_loaded_nb_lock);
  489. return rc;
  490. }
  491. EXPORT_SYMBOL(ipa3_uc_register_ready_cb);
  492. /**
  493. * ipa3_uc_unregister_ready_cb() - unregister a uC ready callback
  494. * @nb: notifier
  495. *
  496. * Unregister a uC loaded notifier block that was previously registered by
  497. * ipa3_uc_register_ready_cb().
  498. *
  499. * Return: 0 on successful unregistration, negative errno otherwise
  500. *
  501. * See blocking_notifier_chain_unregister() for possible errno values
  502. */
  503. int ipa3_uc_unregister_ready_cb(struct notifier_block *nb)
  504. {
  505. return blocking_notifier_chain_unregister(&uc_loaded_notifier, nb);
  506. }
  507. EXPORT_SYMBOL(ipa3_uc_unregister_ready_cb);
  508. static void ipa3_uc_event_handler(enum ipa_irq_type interrupt,
  509. void *private_data,
  510. void *interrupt_data)
  511. {
  512. union IpaHwErrorEventData_t evt;
  513. u8 feature;
  514. WARN_ON(private_data != ipa3_ctx);
  515. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  516. IPADBG("uC evt opcode=%u\n",
  517. ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp);
  518. feature = EXTRACT_UC_FEATURE(ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp);
  519. if (feature >= IPA_HW_FEATURE_MAX) {
  520. IPAERR("Invalid feature %u for event %u\n",
  521. feature, ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp);
  522. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  523. return;
  524. }
  525. /* Feature specific handling */
  526. if (ipa3_uc_hdlrs[feature].ipa_uc_event_hdlr)
  527. ipa3_uc_hdlrs[feature].ipa_uc_event_hdlr
  528. (ipa3_ctx->uc_ctx.uc_sram_mmio);
  529. /* General handling */
  530. if (ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp ==
  531. IPA_HW_2_CPU_EVENT_ERROR) {
  532. evt.raw32b = ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams;
  533. IPAERR("uC Error, evt errorType = %s\n",
  534. ipa_hw_error_str(evt.params.errorType));
  535. ipa3_ctx->uc_ctx.uc_failed = true;
  536. ipa3_ctx->uc_ctx.uc_error_type = evt.params.errorType;
  537. ipa3_ctx->uc_ctx.uc_error_timestamp =
  538. ipahal_read_reg(IPA_TAG_TIMER);
  539. /* Unexpected UC hardware state */
  540. ipa_assert();
  541. } else if (ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp ==
  542. IPA_HW_2_CPU_EVENT_LOG_INFO) {
  543. IPADBG("uC evt log info ofst=0x%x\n",
  544. ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams);
  545. ipa3_log_evt_hdlr();
  546. } else if (ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp ==
  547. IPA_HW_2_CPU_EVNT_RING_NOTIFY) {
  548. IPADBG("uC evt log info ofst=0x%x\n",
  549. ipa3_ctx->uc_ctx.uc_sram_mmio->eventParams);
  550. ipa3_event_ring_hdlr();
  551. } else {
  552. IPADBG("unsupported uC evt opcode=%u\n",
  553. ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp);
  554. }
  555. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  556. }
  557. int ipa3_uc_panic_notifier(struct notifier_block *this,
  558. unsigned long event, void *ptr)
  559. {
  560. int result = 0;
  561. struct ipa_active_client_logging_info log_info;
  562. IPADBG("this=%pK evt=%lu ptr=%pK\n", this, event, ptr);
  563. result = ipa3_uc_state_check();
  564. if (result)
  565. goto fail;
  566. IPA_ACTIVE_CLIENTS_PREP_SIMPLE(log_info);
  567. if (ipa3_inc_client_enable_clks_no_block(&log_info))
  568. goto fail;
  569. ipa3_ctx->uc_ctx.uc_sram_mmio->cmdOp =
  570. IPA_CPU_2_HW_CMD_ERR_FATAL;
  571. ipa3_ctx->uc_ctx.pending_cmd = ipa3_ctx->uc_ctx.uc_sram_mmio->cmdOp;
  572. /* ensure write to shared memory is done before triggering uc */
  573. wmb();
  574. ipahal_write_reg_n(IPA_IRQ_EE_UC_n, 0, 0x1);
  575. /* give uc enough time to save state */
  576. udelay(IPA_PKT_FLUSH_TO_US);
  577. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  578. IPADBG("err_fatal issued\n");
  579. fail:
  580. return NOTIFY_DONE;
  581. }
  582. static void ipa3_uc_response_hdlr(enum ipa_irq_type interrupt,
  583. void *private_data,
  584. void *interrupt_data)
  585. {
  586. union IpaHwCpuCmdCompletedResponseData_t uc_rsp;
  587. u8 feature;
  588. int res;
  589. int i;
  590. WARN_ON(private_data != ipa3_ctx);
  591. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  592. IPADBG("uC rsp opcode=%u\n",
  593. ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp);
  594. feature = EXTRACT_UC_FEATURE(ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp);
  595. if (feature >= IPA_HW_FEATURE_MAX) {
  596. IPAERR("Invalid feature %u for event %u\n",
  597. feature, ipa3_ctx->uc_ctx.uc_sram_mmio->eventOp);
  598. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  599. return;
  600. }
  601. /* Feature specific handling */
  602. if (ipa3_uc_hdlrs[feature].ipa3_uc_response_hdlr) {
  603. res = ipa3_uc_hdlrs[feature].ipa3_uc_response_hdlr(
  604. ipa3_ctx->uc_ctx.uc_sram_mmio,
  605. &ipa3_ctx->uc_ctx.uc_status);
  606. if (res == 0) {
  607. IPADBG("feature %d specific response handler\n",
  608. feature);
  609. complete_all(&ipa3_ctx->uc_ctx.uc_completion);
  610. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  611. return;
  612. }
  613. }
  614. /* General handling */
  615. if (ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp ==
  616. IPA_HW_2_CPU_RESPONSE_INIT_COMPLETED) {
  617. if (ipa3_ctx->uc_ctx.uc_loaded) {
  618. IPADBG("uC resp op INIT_COMPLETED is unexpected\n");
  619. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  620. return;
  621. }
  622. mutex_lock(&uc_loaded_nb_lock);
  623. ipa3_ctx->uc_ctx.uc_loaded = true;
  624. (void) blocking_notifier_call_chain(&uc_loaded_notifier, true,
  625. ipa3_ctx);
  626. mutex_unlock(&uc_loaded_nb_lock);
  627. IPADBG("IPA uC loaded\n");
  628. /*
  629. * The proxy vote is held until uC is loaded to ensure that
  630. * IPA_HW_2_CPU_RESPONSE_INIT_COMPLETED is received.
  631. */
  632. ipa3_proxy_clk_unvote();
  633. /*
  634. * To enable ipa power collapse we need to enable rpmh and uc
  635. * handshake So that uc can do register retention. To enable
  636. * this handshake we need to send the below message to rpmh.
  637. */
  638. ipa_pc_qmp_enable();
  639. for (i = 0; i < IPA_HW_NUM_FEATURES; i++) {
  640. if (ipa3_uc_hdlrs[i].ipa_uc_loaded_hdlr)
  641. ipa3_uc_hdlrs[i].ipa_uc_loaded_hdlr();
  642. }
  643. } else if (ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp ==
  644. IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED) {
  645. uc_rsp.raw32b = ipa3_ctx->uc_ctx.uc_sram_mmio->responseParams;
  646. IPADBG("uC cmd response opcode=%u status=%u\n",
  647. uc_rsp.params.originalCmdOp,
  648. uc_rsp.params.status);
  649. if (uc_rsp.params.originalCmdOp ==
  650. ipa3_ctx->uc_ctx.pending_cmd) {
  651. ipa3_ctx->uc_ctx.uc_status = uc_rsp.params.status;
  652. if (uc_rsp.params.originalCmdOp ==
  653. IPA_CPU_2_HW_CMD_OFFLOAD_STATS_ALLOC)
  654. ipa3_uc_save_dbg_stats(
  655. uc_rsp.params.responseData);
  656. complete_all(&ipa3_ctx->uc_ctx.uc_completion);
  657. } else {
  658. IPAERR("Expected cmd=%u rcvd cmd=%u\n",
  659. ipa3_ctx->uc_ctx.pending_cmd,
  660. uc_rsp.params.originalCmdOp);
  661. }
  662. } else {
  663. IPAERR("Unsupported uC rsp opcode = %u\n",
  664. ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp);
  665. }
  666. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  667. }
  668. static void ipa3_uc_wigig_misc_int_handler(enum ipa_irq_type interrupt,
  669. void *private_data,
  670. void *interrupt_data)
  671. {
  672. IPADBG("\n");
  673. WARN_ON(private_data != ipa3_ctx);
  674. if (ipa3_ctx->uc_wigig_ctx.misc_notify_cb)
  675. ipa3_ctx->uc_wigig_ctx.misc_notify_cb(
  676. ipa3_ctx->uc_wigig_ctx.priv);
  677. IPADBG("exit\n");
  678. }
  679. static int ipa3_uc_send_cmd_64b_param(u32 cmd_lo, u32 cmd_hi, u32 opcode,
  680. u32 expected_status, bool polling_mode, unsigned long timeout_jiffies)
  681. {
  682. int index;
  683. union IpaHwCpuCmdCompletedResponseData_t uc_rsp;
  684. int retries = 0;
  685. u32 uc_error_type;
  686. send_cmd_lock:
  687. mutex_lock(&ipa3_ctx->uc_ctx.uc_lock);
  688. if (ipa3_uc_state_check()) {
  689. IPADBG("uC send command aborted\n");
  690. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  691. return -EBADF;
  692. }
  693. send_cmd:
  694. init_completion(&ipa3_ctx->uc_ctx.uc_completion);
  695. ipa3_ctx->uc_ctx.uc_sram_mmio->cmdParams = cmd_lo;
  696. ipa3_ctx->uc_ctx.uc_sram_mmio->cmdParams_hi = cmd_hi;
  697. ipa3_ctx->uc_ctx.uc_sram_mmio->cmdOp = opcode;
  698. ipa3_ctx->uc_ctx.pending_cmd = opcode;
  699. ipa3_ctx->uc_ctx.uc_sram_mmio->responseOp = 0;
  700. ipa3_ctx->uc_ctx.uc_sram_mmio->responseParams = 0;
  701. ipa3_ctx->uc_ctx.uc_status = 0;
  702. /* ensure write to shared memory is done before triggering uc */
  703. wmb();
  704. ipahal_write_reg_n(IPA_IRQ_EE_UC_n, 0, 0x1);
  705. if (polling_mode) {
  706. struct IpaHwSharedMemCommonMapping_t *uc_sram_ptr =
  707. ipa3_ctx->uc_ctx.uc_sram_mmio;
  708. for (index = 0; index < IPA_UC_POLL_MAX_RETRY; index++) {
  709. if (uc_sram_ptr->responseOp ==
  710. IPA_HW_2_CPU_RESPONSE_CMD_COMPLETED) {
  711. uc_rsp.raw32b = uc_sram_ptr->responseParams;
  712. if (uc_rsp.params.originalCmdOp ==
  713. ipa3_ctx->uc_ctx.pending_cmd) {
  714. ipa3_ctx->uc_ctx.uc_status =
  715. uc_rsp.params.status;
  716. break;
  717. }
  718. }
  719. usleep_range(IPA_UC_POLL_SLEEP_USEC,
  720. IPA_UC_POLL_SLEEP_USEC);
  721. }
  722. if (index == IPA_UC_POLL_MAX_RETRY) {
  723. IPAERR("uC max polling retries reached\n");
  724. if (ipa3_ctx->uc_ctx.uc_failed) {
  725. uc_error_type = ipa3_ctx->uc_ctx.uc_error_type;
  726. IPAERR("uC reported on Error, errorType = %s\n",
  727. ipa_hw_error_str(uc_error_type));
  728. }
  729. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  730. /* Unexpected UC hardware state */
  731. ipa_assert();
  732. }
  733. } else {
  734. if (wait_for_completion_timeout(&ipa3_ctx->uc_ctx.uc_completion,
  735. timeout_jiffies) == 0) {
  736. IPAERR("uC timed out\n");
  737. if (ipa3_ctx->uc_ctx.uc_failed) {
  738. uc_error_type = ipa3_ctx->uc_ctx.uc_error_type;
  739. IPAERR("uC reported on Error, errorType = %s\n",
  740. ipa_hw_error_str(uc_error_type));
  741. }
  742. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  743. /* Unexpected UC hardware state */
  744. ipa_assert();
  745. }
  746. }
  747. if (ipa3_ctx->uc_ctx.uc_status != expected_status) {
  748. if (ipa3_ctx->uc_ctx.uc_status ==
  749. IPA_HW_PROD_DISABLE_CMD_GSI_STOP_FAILURE ||
  750. ipa3_ctx->uc_ctx.uc_status ==
  751. IPA_HW_CONS_DISABLE_CMD_GSI_STOP_FAILURE ||
  752. ipa3_ctx->uc_ctx.uc_status ==
  753. IPA_HW_CONS_STOP_FAILURE ||
  754. ipa3_ctx->uc_ctx.uc_status ==
  755. IPA_HW_PROD_STOP_FAILURE) {
  756. retries++;
  757. if (retries == IPA_GSI_CHANNEL_STOP_MAX_RETRY) {
  758. IPAERR("Failed after %d tries\n", retries);
  759. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  760. /* Unexpected UC hardware state */
  761. ipa_assert();
  762. }
  763. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  764. if (ipa3_ctx->uc_ctx.uc_status ==
  765. IPA_HW_PROD_DISABLE_CMD_GSI_STOP_FAILURE)
  766. ipa3_inject_dma_task_for_gsi();
  767. /* sleep for short period to flush IPA */
  768. usleep_range(IPA_GSI_CHANNEL_STOP_SLEEP_MIN_USEC,
  769. IPA_GSI_CHANNEL_STOP_SLEEP_MAX_USEC);
  770. goto send_cmd_lock;
  771. }
  772. if (ipa3_ctx->uc_ctx.uc_status ==
  773. IPA_HW_GSI_CH_NOT_EMPTY_FAILURE) {
  774. retries++;
  775. if (retries >= IPA_GSI_CHANNEL_EMPTY_MAX_RETRY) {
  776. IPAERR("Failed after %d tries\n", retries);
  777. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  778. return -EFAULT;
  779. }
  780. usleep_range(
  781. IPA_GSI_CHANNEL_EMPTY_SLEEP_MIN_USEC,
  782. IPA_GSI_CHANNEL_EMPTY_SLEEP_MAX_USEC);
  783. goto send_cmd;
  784. }
  785. IPAERR("Received status %u, Expected status %u\n",
  786. ipa3_ctx->uc_ctx.uc_status, expected_status);
  787. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  788. return -EFAULT;
  789. }
  790. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  791. IPADBG("uC cmd %u send succeeded\n", opcode);
  792. return 0;
  793. }
  794. /**
  795. * ipa3_uc_interface_init() - Initialize the interface with the uC
  796. *
  797. * Return value: 0 on success, negative value otherwise
  798. */
  799. int ipa3_uc_interface_init(void)
  800. {
  801. int result;
  802. unsigned long phys_addr;
  803. if (ipa3_ctx->uc_ctx.uc_inited) {
  804. IPADBG("uC interface already initialized\n");
  805. return 0;
  806. }
  807. mutex_init(&ipa3_ctx->uc_ctx.uc_lock);
  808. spin_lock_init(&ipa3_ctx->uc_ctx.uc_spinlock);
  809. phys_addr = ipa3_ctx->ipa_wrapper_base +
  810. ipa3_ctx->ctrl->ipa_reg_base_ofst +
  811. ipahal_get_reg_n_ofst(IPA_SW_AREA_RAM_DIRECT_ACCESS_n, 0);
  812. ipa3_ctx->uc_ctx.uc_sram_mmio = ioremap(phys_addr,
  813. IPA_RAM_UC_SMEM_SIZE);
  814. if (!ipa3_ctx->uc_ctx.uc_sram_mmio) {
  815. IPAERR("Fail to ioremap IPA uC SRAM\n");
  816. result = -ENOMEM;
  817. goto remap_fail;
  818. }
  819. result = ipa3_add_interrupt_handler(IPA_UC_IRQ_0,
  820. ipa3_uc_event_handler, true,
  821. ipa3_ctx);
  822. if (result) {
  823. IPAERR("Fail to register for UC_IRQ0 event interrupt\n");
  824. result = -EFAULT;
  825. goto irq_fail0;
  826. }
  827. result = ipa3_add_interrupt_handler(IPA_UC_IRQ_1,
  828. ipa3_uc_response_hdlr, true,
  829. ipa3_ctx);
  830. if (result) {
  831. IPAERR("fail to register for UC_IRQ1 rsp interrupt\n");
  832. result = -EFAULT;
  833. goto irq_fail1;
  834. }
  835. result = ipa3_add_interrupt_handler(IPA_UC_IRQ_2,
  836. ipa3_uc_wigig_misc_int_handler, true,
  837. ipa3_ctx);
  838. if (result) {
  839. IPAERR("fail to register for UC_IRQ2 wigig misc interrupt\n");
  840. result = -EFAULT;
  841. goto irq_fail2;
  842. }
  843. ipa3_ctx->uc_ctx.uc_inited = true;
  844. IPADBG("IPA uC interface is initialized\n");
  845. return 0;
  846. irq_fail2:
  847. ipa3_remove_interrupt_handler(IPA_UC_IRQ_1);
  848. irq_fail1:
  849. ipa3_remove_interrupt_handler(IPA_UC_IRQ_0);
  850. irq_fail0:
  851. iounmap(ipa3_ctx->uc_ctx.uc_sram_mmio);
  852. remap_fail:
  853. return result;
  854. }
  855. /**
  856. * ipa3_uc_send_cmd() - Send a command to the uC
  857. *
  858. * Note1: This function sends command with 32bit parameter and do not
  859. * use the higher 32bit of the command parameter (set to zero).
  860. *
  861. * Note2: In case the operation times out (No response from the uC) or
  862. * polling maximal amount of retries has reached, the logic
  863. * considers it as an invalid state of the uC/IPA, and
  864. * issues a kernel panic.
  865. *
  866. * Returns: 0 on success.
  867. * -EINVAL in case of invalid input.
  868. * -EBADF in case uC interface is not initialized /
  869. * or the uC has failed previously.
  870. * -EFAULT in case the received status doesn't match
  871. * the expected.
  872. */
  873. int ipa3_uc_send_cmd(u32 cmd, u32 opcode, u32 expected_status,
  874. bool polling_mode, unsigned long timeout_jiffies)
  875. {
  876. return ipa3_uc_send_cmd_64b_param(cmd, 0, opcode,
  877. expected_status, polling_mode, timeout_jiffies);
  878. }
  879. /**
  880. * ipa3_uc_register_handlers() - Registers event, response and log event
  881. * handlers for a specific feature.Please note
  882. * that currently only one handler can be
  883. * registered per feature.
  884. *
  885. * Return value: None
  886. */
  887. void ipa3_uc_register_handlers(enum ipa3_hw_features feature,
  888. struct ipa3_uc_hdlrs *hdlrs)
  889. {
  890. if (0 > feature || IPA_HW_FEATURE_MAX <= feature) {
  891. IPAERR("Feature %u is invalid, not registering hdlrs\n",
  892. feature);
  893. return;
  894. }
  895. mutex_lock(&ipa3_ctx->uc_ctx.uc_lock);
  896. ipa3_uc_hdlrs[feature] = *hdlrs;
  897. mutex_unlock(&ipa3_ctx->uc_ctx.uc_lock);
  898. IPADBG("uC handlers registered for feature %u\n", feature);
  899. }
  900. int ipa3_uc_is_gsi_channel_empty(enum ipa_client_type ipa_client)
  901. {
  902. const struct ipa_gsi_ep_config *gsi_ep_info;
  903. union IpaHwChkChEmptyCmdData_t cmd;
  904. int ret;
  905. gsi_ep_info = ipa3_get_gsi_ep_info(ipa_client);
  906. if (!gsi_ep_info) {
  907. IPAERR("Failed getting GSI EP info for client=%d\n",
  908. ipa_client);
  909. return 0;
  910. }
  911. if (ipa3_uc_state_check()) {
  912. IPADBG("uC cannot be used to validate ch emptiness clnt=%d\n"
  913. , ipa_client);
  914. return 0;
  915. }
  916. cmd.params.ee_n = gsi_ep_info->ee;
  917. cmd.params.vir_ch_id = gsi_ep_info->ipa_gsi_chan_num;
  918. IPADBG("uC emptiness check for IPA GSI Channel %d\n",
  919. gsi_ep_info->ipa_gsi_chan_num);
  920. ret = ipa3_uc_send_cmd(cmd.raw32b, IPA_CPU_2_HW_CMD_GSI_CH_EMPTY, 0,
  921. false, 10*HZ);
  922. return ret;
  923. }
  924. /**
  925. * ipa3_uc_notify_clk_state() - notify to uC of clock enable / disable
  926. * @enabled: true if clock are enabled
  927. *
  928. * The function uses the uC interface in order to notify uC before IPA clocks
  929. * are disabled to make sure uC is not in the middle of operation.
  930. * Also after clocks are enabled ned to notify uC to start processing.
  931. *
  932. * Returns: 0 on success, negative on failure
  933. */
  934. int ipa3_uc_notify_clk_state(bool enabled)
  935. {
  936. u32 opcode;
  937. if (ipa3_ctx->ipa_hw_type > IPA_HW_v4_0) {
  938. IPADBG_LOW("not supported past IPA v4.0\n");
  939. return 0;
  940. }
  941. /*
  942. * If the uC interface has not been initialized yet,
  943. * don't notify the uC on the enable/disable
  944. */
  945. if (ipa3_uc_state_check()) {
  946. IPADBG("uC interface will not notify the UC on clock state\n");
  947. return 0;
  948. }
  949. IPADBG("uC clock %s notification\n", (enabled) ? "UNGATE" : "GATE");
  950. opcode = (enabled) ? IPA_CPU_2_HW_CMD_CLK_UNGATE :
  951. IPA_CPU_2_HW_CMD_CLK_GATE;
  952. return ipa3_uc_send_cmd(0, opcode, 0, true, 0);
  953. }
  954. /**
  955. * ipa3_uc_update_hw_flags() - send uC the HW flags to be used
  956. * @flags: This field is expected to be used as bitmask for enum ipa3_hw_flags
  957. *
  958. * Returns: 0 on success, negative on failure
  959. */
  960. int ipa3_uc_update_hw_flags(u32 flags)
  961. {
  962. union IpaHwUpdateFlagsCmdData_t cmd;
  963. memset(&cmd, 0, sizeof(cmd));
  964. cmd.params.newFlags = flags;
  965. return ipa3_uc_send_cmd(cmd.raw32b, IPA_CPU_2_HW_CMD_UPDATE_FLAGS, 0,
  966. false, HZ);
  967. }
  968. /**
  969. * ipa3_uc_memcpy() - Perform a memcpy action using IPA uC
  970. * @dest: physical address to store the copied data.
  971. * @src: physical address of the source data to copy.
  972. * @len: number of bytes to copy.
  973. *
  974. * Returns: 0 on success, negative on failure
  975. */
  976. int ipa3_uc_memcpy(phys_addr_t dest, phys_addr_t src, int len)
  977. {
  978. int res;
  979. struct ipa_mem_buffer mem;
  980. struct IpaHwMemCopyData_t *cmd;
  981. IPADBG("dest 0x%pa src 0x%pa len %d\n", &dest, &src, len);
  982. mem.size = sizeof(cmd);
  983. mem.base = dma_alloc_coherent(ipa3_ctx->pdev, mem.size, &mem.phys_base,
  984. GFP_KERNEL);
  985. if (!mem.base) {
  986. IPAERR("fail to alloc DMA buff of size %d\n", mem.size);
  987. return -ENOMEM;
  988. }
  989. cmd = (struct IpaHwMemCopyData_t *)mem.base;
  990. memset(cmd, 0, sizeof(*cmd));
  991. cmd->destination_addr = dest;
  992. cmd->dest_buffer_size = len;
  993. cmd->source_addr = src;
  994. cmd->source_buffer_size = len;
  995. res = ipa3_uc_send_cmd((u32)mem.phys_base, IPA_CPU_2_HW_CMD_MEMCPY, 0,
  996. true, 10 * HZ);
  997. if (res) {
  998. IPAERR("ipa3_uc_send_cmd failed %d\n", res);
  999. goto free_coherent;
  1000. }
  1001. res = 0;
  1002. free_coherent:
  1003. dma_free_coherent(ipa3_ctx->pdev, mem.size, mem.base, mem.phys_base);
  1004. return res;
  1005. }
  1006. int ipa3_uc_send_remote_ipa_info(u32 remote_addr, uint32_t mbox_n)
  1007. {
  1008. int res;
  1009. struct ipa_mem_buffer cmd;
  1010. struct IpaHwDbAddrInfo_t *uc_info;
  1011. cmd.size = sizeof(*uc_info);
  1012. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1013. &cmd.phys_base, GFP_KERNEL);
  1014. if (cmd.base == NULL)
  1015. return -ENOMEM;
  1016. uc_info = (struct IpaHwDbAddrInfo_t *) cmd.base;
  1017. uc_info->remoteIPAAddr = remote_addr;
  1018. uc_info->mboxN = mbox_n;
  1019. res = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1020. IPA_CPU_2_HW_CMD_REMOTE_IPA_INFO, 0,
  1021. false, 10 * HZ);
  1022. if (res) {
  1023. IPAERR("fail to map 0x%x to mbox %d\n",
  1024. uc_info->remoteIPAAddr,
  1025. uc_info->mboxN);
  1026. goto free_coherent;
  1027. }
  1028. res = 0;
  1029. free_coherent:
  1030. dma_free_coherent(ipa3_ctx->uc_pdev, cmd.size, cmd.base, cmd.phys_base);
  1031. return res;
  1032. }
  1033. int ipa3_uc_debug_stats_alloc(
  1034. struct IpaHwOffloadStatsAllocCmdData_t cmdinfo)
  1035. {
  1036. int result;
  1037. struct ipa_mem_buffer cmd;
  1038. enum ipa_cpu_2_hw_offload_commands command;
  1039. struct IpaHwOffloadStatsAllocCmdData_t *cmd_data;
  1040. cmd.size = sizeof(*cmd_data);
  1041. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1042. &cmd.phys_base, GFP_KERNEL);
  1043. if (cmd.base == NULL) {
  1044. result = -ENOMEM;
  1045. return result;
  1046. }
  1047. cmd_data = (struct IpaHwOffloadStatsAllocCmdData_t *)cmd.base;
  1048. memcpy(cmd_data, &cmdinfo,
  1049. sizeof(struct IpaHwOffloadStatsAllocCmdData_t));
  1050. command = IPA_CPU_2_HW_CMD_OFFLOAD_STATS_ALLOC;
  1051. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1052. result = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1053. command,
  1054. IPA_HW_2_CPU_OFFLOAD_CMD_STATUS_SUCCESS,
  1055. false, 10 * HZ);
  1056. if (result) {
  1057. IPAERR("fail to alloc offload stats\n");
  1058. goto cleanup;
  1059. }
  1060. result = 0;
  1061. cleanup:
  1062. dma_free_coherent(ipa3_ctx->uc_pdev,
  1063. cmd.size,
  1064. cmd.base, cmd.phys_base);
  1065. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1066. IPADBG("exit\n");
  1067. return result;
  1068. }
  1069. int ipa3_uc_debug_stats_dealloc(uint32_t prot_id)
  1070. {
  1071. int result;
  1072. struct ipa_mem_buffer cmd;
  1073. enum ipa_cpu_2_hw_offload_commands command;
  1074. struct IpaHwOffloadStatsDeAllocCmdData_t *cmd_data;
  1075. cmd.size = sizeof(*cmd_data);
  1076. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1077. &cmd.phys_base, GFP_KERNEL);
  1078. if (cmd.base == NULL) {
  1079. result = -ENOMEM;
  1080. return result;
  1081. }
  1082. cmd_data = (struct IpaHwOffloadStatsDeAllocCmdData_t *)
  1083. cmd.base;
  1084. cmd_data->protocol = prot_id;
  1085. command = IPA_CPU_2_HW_CMD_OFFLOAD_STATS_DEALLOC;
  1086. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1087. result = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1088. command,
  1089. IPA_HW_2_CPU_OFFLOAD_CMD_STATUS_SUCCESS,
  1090. false, 10 * HZ);
  1091. if (result) {
  1092. IPAERR("fail to dealloc offload stats\n");
  1093. goto cleanup;
  1094. }
  1095. switch (prot_id) {
  1096. case IPA_HW_PROTOCOL_AQC:
  1097. iounmap(ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_mmio);
  1098. ipa3_ctx->aqc_ctx.dbg_stats.uc_dbg_stats_mmio = NULL;
  1099. break;
  1100. case IPA_HW_PROTOCOL_11ad:
  1101. break;
  1102. case IPA_HW_PROTOCOL_WDI:
  1103. iounmap(ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_mmio);
  1104. ipa3_ctx->wdi2_ctx.dbg_stats.uc_dbg_stats_mmio = NULL;
  1105. break;
  1106. case IPA_HW_PROTOCOL_WDI3:
  1107. iounmap(ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_mmio);
  1108. ipa3_ctx->wdi3_ctx.dbg_stats.uc_dbg_stats_mmio = NULL;
  1109. break;
  1110. case IPA_HW_PROTOCOL_ETH:
  1111. break;
  1112. default:
  1113. IPAERR("unknown protocols %d\n", prot_id);
  1114. }
  1115. result = 0;
  1116. cleanup:
  1117. dma_free_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1118. cmd.base, cmd.phys_base);
  1119. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1120. IPADBG("exit\n");
  1121. return result;
  1122. }
  1123. int ipa3_uc_setup_event_ring(void)
  1124. {
  1125. int res = 0;
  1126. struct ipa_mem_buffer cmd, *ring;
  1127. union IpaSetupEventRingCmdData_t *ring_info;
  1128. ring = &ipa3_ctx->uc_ctx.event_ring;
  1129. /* Allocate event ring */
  1130. ring->size = sizeof(struct eventElement_t) * IPA_UC_EVENT_RING_SIZE;
  1131. ring->base = dma_alloc_coherent(ipa3_ctx->uc_pdev, ring->size,
  1132. &ring->phys_base, GFP_KERNEL);
  1133. if (ring->base == NULL)
  1134. return -ENOMEM;
  1135. cmd.size = sizeof(*ring_info);
  1136. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1137. &cmd.phys_base, GFP_KERNEL);
  1138. if (cmd.base == NULL) {
  1139. dma_free_coherent(ipa3_ctx->uc_pdev, ring->size,
  1140. ring->base, ring->phys_base);
  1141. return -ENOMEM;
  1142. }
  1143. ring_info = (union IpaSetupEventRingCmdData_t *) cmd.base;
  1144. ring_info->event.ring_base_pa = (u32) (ring->phys_base & 0xFFFFFFFF);
  1145. ring_info->event.ring_base_pa_hi =
  1146. (u32) ((ring->phys_base & 0xFFFFFFFF00000000) >> 32);
  1147. ring_info->event.ring_size = IPA_UC_EVENT_RING_SIZE;
  1148. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1149. res = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1150. IPA_CPU_2_HW_CMD_SETUP_EVENT_RING, 0,
  1151. false, 10 * HZ);
  1152. if (res) {
  1153. IPAERR(" faile to setup event ring 0x%x 0x%x, size %d\n",
  1154. ring_info->event.ring_base_pa,
  1155. ring_info->event.ring_base_pa_hi,
  1156. ring_info->event.ring_size);
  1157. goto free_cmd;
  1158. }
  1159. ipa3_ctx->uc_ctx.uc_event_ring_valid = true;
  1160. /* write wp/rp values */
  1161. ipa3_ctx->uc_ctx.ering_rp_local = 0;
  1162. ipa3_ctx->uc_ctx.ering_wp_local =
  1163. ring->size - sizeof(struct eventElement_t);
  1164. ipahal_write_reg_mn(IPA_UC_MAILBOX_m_n,
  1165. IPA_UC_ERING_m, IPA_UC_ERING_n_r, 0);
  1166. ipahal_write_reg_mn(IPA_UC_MAILBOX_m_n,
  1167. IPA_UC_ERING_m, IPA_UC_ERING_n_w,
  1168. ipa3_ctx->uc_ctx.ering_wp_local);
  1169. ipa3_ctx->uc_ctx.ering_wp =
  1170. ipa3_ctx->uc_ctx.ering_wp_local;
  1171. ipa3_ctx->uc_ctx.ering_rp = 0;
  1172. free_cmd:
  1173. dma_free_coherent(ipa3_ctx->uc_pdev,
  1174. cmd.size, cmd.base, cmd.phys_base);
  1175. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1176. return res;
  1177. }
  1178. int ipa3_uc_quota_monitor(uint64_t quota)
  1179. {
  1180. int ind, res = 0;
  1181. struct ipa_mem_buffer cmd;
  1182. struct IpaQuotaMonitoring_t *quota_info;
  1183. cmd.size = sizeof(*quota_info);
  1184. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1185. &cmd.phys_base, GFP_KERNEL);
  1186. if (cmd.base == NULL)
  1187. return -ENOMEM;
  1188. quota_info = (struct IpaQuotaMonitoring_t *)cmd.base;
  1189. quota_info->protocol = IPA_HW_PROTOCOL_WDI3;
  1190. quota_info->params.WdiQM.Quota = quota;
  1191. quota_info->params.WdiQM.info.Num = 4;
  1192. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1193. UL_HW - 1;
  1194. quota_info->params.WdiQM.info.Offset[0] =
  1195. IPA_MEM_PART(stats_fnr_ofst) +
  1196. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1197. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1198. DL_ALL - 1;
  1199. quota_info->params.WdiQM.info.Offset[1] =
  1200. IPA_MEM_PART(stats_fnr_ofst) +
  1201. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1202. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1203. UL_HW_CACHE - 1;
  1204. quota_info->params.WdiQM.info.Offset[2] =
  1205. IPA_MEM_PART(stats_fnr_ofst) +
  1206. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1207. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1208. UL_WLAN_TX - 1;
  1209. quota_info->params.WdiQM.info.Offset[3] =
  1210. IPA_MEM_PART(stats_fnr_ofst) +
  1211. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1212. quota_info->params.WdiQM.info.Interval =
  1213. IPA_UC_MON_INTERVAL;
  1214. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1215. res = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1216. IPA_CPU_2_HW_CMD_QUOTA_MONITORING,
  1217. IPA_HW_2_CPU_OFFLOAD_CMD_STATUS_SUCCESS,
  1218. false, 10 * HZ);
  1219. if (res) {
  1220. IPAERR(" faile to set quota %d, number offset %d\n",
  1221. quota_info->params.WdiQM.Quota,
  1222. quota_info->params.WdiQM.info.Num);
  1223. goto free_cmd;
  1224. }
  1225. IPADBG(" offest1 %d offest2 %d offest3 %d offest4 %d\n",
  1226. quota_info->params.WdiQM.info.Offset[0],
  1227. quota_info->params.WdiQM.info.Offset[1],
  1228. quota_info->params.WdiQM.info.Offset[2],
  1229. quota_info->params.WdiQM.info.Offset[3]);
  1230. free_cmd:
  1231. dma_free_coherent(ipa3_ctx->uc_pdev, cmd.size, cmd.base, cmd.phys_base);
  1232. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1233. return res;
  1234. }
  1235. int ipa3_uc_bw_monitor(struct ipa_wdi_bw_info *info)
  1236. {
  1237. int i, ind, res = 0;
  1238. struct ipa_mem_buffer cmd;
  1239. struct IpaBwMonitoring_t *bw_info;
  1240. if (!info)
  1241. return -EINVAL;
  1242. /* check max entry */
  1243. if (info->num > BW_MONITORING_MAX_THRESHOLD) {
  1244. IPAERR("%d, support max %d bw monitor\n", info->num,
  1245. BW_MONITORING_MAX_THRESHOLD);
  1246. return -EINVAL;
  1247. }
  1248. cmd.size = sizeof(*bw_info);
  1249. cmd.base = dma_alloc_coherent(ipa3_ctx->uc_pdev, cmd.size,
  1250. &cmd.phys_base, GFP_KERNEL);
  1251. if (cmd.base == NULL)
  1252. return -ENOMEM;
  1253. bw_info = (struct IpaBwMonitoring_t *)cmd.base;
  1254. bw_info->protocol = IPA_HW_PROTOCOL_WDI3;
  1255. bw_info->params.WdiBw.NumThresh = info->num;
  1256. bw_info->params.WdiBw.Stop = info->stop;
  1257. IPADBG("stop bw-monitor? %d\n", bw_info->params.WdiBw.Stop);
  1258. for (i = 0; i < info->num; i++) {
  1259. bw_info->params.WdiBw.BwThreshold[i] = info->threshold[i];
  1260. IPADBG("%d-st, %lu\n", i, bw_info->params.WdiBw.BwThreshold[i]);
  1261. }
  1262. bw_info->params.WdiBw.info.Num = 8;
  1263. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1264. UL_HW - 1;
  1265. bw_info->params.WdiBw.info.Offset[0] =
  1266. IPA_MEM_PART(stats_fnr_ofst) +
  1267. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1268. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1269. DL_HW - 1;
  1270. bw_info->params.WdiBw.info.Offset[1] =
  1271. IPA_MEM_PART(stats_fnr_ofst) +
  1272. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1273. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1274. DL_ALL - 1;
  1275. bw_info->params.WdiBw.info.Offset[2] =
  1276. IPA_MEM_PART(stats_fnr_ofst) +
  1277. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1278. ind = ipa3_ctx->fnr_info.hw_counter_offset +
  1279. UL_ALL - 1;
  1280. bw_info->params.WdiBw.info.Offset[3] =
  1281. IPA_MEM_PART(stats_fnr_ofst) +
  1282. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1283. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1284. UL_HW_CACHE - 1;
  1285. bw_info->params.WdiBw.info.Offset[4] =
  1286. IPA_MEM_PART(stats_fnr_ofst) +
  1287. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1288. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1289. DL_HW_CACHE - 1;
  1290. bw_info->params.WdiBw.info.Offset[5] =
  1291. IPA_MEM_PART(stats_fnr_ofst) +
  1292. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1293. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1294. UL_WLAN_TX - 1;
  1295. bw_info->params.WdiBw.info.Offset[6] =
  1296. IPA_MEM_PART(stats_fnr_ofst) +
  1297. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1298. ind = ipa3_ctx->fnr_info.sw_counter_offset +
  1299. DL_WLAN_TX - 1;
  1300. bw_info->params.WdiBw.info.Offset[7] =
  1301. IPA_MEM_PART(stats_fnr_ofst) +
  1302. sizeof(struct ipa_flt_rt_stats) * ind + 8;
  1303. bw_info->params.WdiBw.info.Interval =
  1304. IPA_UC_MON_INTERVAL;
  1305. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1306. res = ipa3_uc_send_cmd((u32)(cmd.phys_base),
  1307. IPA_CPU_2_HW_CMD_BW_MONITORING,
  1308. IPA_HW_2_CPU_OFFLOAD_CMD_STATUS_SUCCESS,
  1309. false, 10 * HZ);
  1310. if (res) {
  1311. IPAERR(" faile to set bw %d level with %d coutners\n",
  1312. bw_info->params.WdiBw.NumThresh,
  1313. bw_info->params.WdiBw.info.Num);
  1314. goto free_cmd;
  1315. }
  1316. free_cmd:
  1317. dma_free_coherent(ipa3_ctx->uc_pdev, cmd.size, cmd.base, cmd.phys_base);
  1318. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1319. return res;
  1320. }
  1321. int ipa3_set_wlan_tx_info(struct ipa_wdi_tx_info *info)
  1322. {
  1323. struct ipa_flt_rt_stats stats;
  1324. struct ipacm_fnr_info fnr_info;
  1325. memset(&fnr_info, 0, sizeof(struct ipacm_fnr_info));
  1326. if (!ipa_get_fnr_info(&fnr_info)) {
  1327. IPAERR("FNR counter haven't configured\n");
  1328. return -EINVAL;
  1329. }
  1330. /* update sw counters */
  1331. memset(&stats, 0, sizeof(struct ipa_flt_rt_stats));
  1332. stats.num_bytes = info->sta_tx;
  1333. if (ipa_set_flt_rt_stats(fnr_info.sw_counter_offset +
  1334. UL_WLAN_TX, stats)) {
  1335. IPAERR("Failed to set stats to ul_wlan_tx %d\n",
  1336. fnr_info.sw_counter_offset + UL_WLAN_TX);
  1337. return -EINVAL;
  1338. }
  1339. stats.num_bytes = info->ap_tx;
  1340. if (ipa_set_flt_rt_stats(fnr_info.sw_counter_offset +
  1341. DL_WLAN_TX, stats)) {
  1342. IPAERR("Failed to set stats to dl_wlan_tx %d\n",
  1343. fnr_info.sw_counter_offset + DL_WLAN_TX);
  1344. return -EINVAL;
  1345. }
  1346. return 0;
  1347. }
  1348. int ipa3_uc_send_enable_flow_control(uint16_t gsi_chid,
  1349. uint16_t redMarkerThreshold)
  1350. {
  1351. int res;
  1352. union IpaEnablePipeMonitorCmdData_t cmd;
  1353. cmd.params.ipaProdGsiChid = gsi_chid;
  1354. cmd.params.redMarkerThreshold = redMarkerThreshold;
  1355. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1356. res = ipa3_uc_send_cmd((cmd.raw32b),
  1357. IPA_CPU_2_HW_CMD_ENABLE_FLOW_CTL_MONITOR, 0,
  1358. false, 10 * HZ);
  1359. if (res)
  1360. IPAERR("fail to enable flow ctrl for 0x%x\n",
  1361. cmd.params.ipaProdGsiChid);
  1362. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1363. return res;
  1364. }
  1365. int ipa3_uc_send_disable_flow_control(void)
  1366. {
  1367. int res;
  1368. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1369. res = ipa3_uc_send_cmd(0,
  1370. IPA_CPU_2_HW_CMD_DISABLE_FLOW_CTL_MONITOR, 0,
  1371. false, 10 * HZ);
  1372. if (res)
  1373. IPAERR("fail to disable flow control\n");
  1374. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1375. return res;
  1376. }
  1377. int ipa3_uc_send_update_flow_control(uint32_t bitmask,
  1378. uint8_t add_delete)
  1379. {
  1380. int res;
  1381. if (bitmask == 0) {
  1382. IPAERR("Err update flow control, mask = 0\n");
  1383. return 0;
  1384. }
  1385. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1386. res = ipa3_uc_send_cmd_64b_param(bitmask, add_delete,
  1387. IPA_CPU_2_HW_CMD_UPDATE_FLOW_CTL_MONITOR, 0,
  1388. false, 10 * HZ);
  1389. if (res)
  1390. IPAERR("fail flowCtrl update mask = 0x%x add_del = 0x%x\n",
  1391. bitmask, add_delete);
  1392. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  1393. return res;
  1394. }