htc.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457
  1. /*
  2. * Copyright (c) 2007-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "core.h"
  17. #include "htc_hif.h"
  18. #include "debug.h"
  19. #include "hif-ops.h"
  20. #include <asm/unaligned.h>
  21. #define CALC_TXRX_PADDED_LEN(dev, len) (__ALIGN_MASK((len), (dev)->block_mask))
  22. static void htc_prep_send_pkt(struct htc_packet *packet, u8 flags, int ctrl0,
  23. int ctrl1)
  24. {
  25. struct htc_frame_hdr *hdr;
  26. packet->buf -= HTC_HDR_LENGTH;
  27. hdr = (struct htc_frame_hdr *)packet->buf;
  28. /* Endianess? */
  29. put_unaligned((u16)packet->act_len, &hdr->payld_len);
  30. hdr->flags = flags;
  31. hdr->eid = packet->endpoint;
  32. hdr->ctrl[0] = ctrl0;
  33. hdr->ctrl[1] = ctrl1;
  34. }
  35. static void htc_reclaim_txctrl_buf(struct htc_target *target,
  36. struct htc_packet *pkt)
  37. {
  38. spin_lock_bh(&target->htc_lock);
  39. list_add_tail(&pkt->list, &target->free_ctrl_txbuf);
  40. spin_unlock_bh(&target->htc_lock);
  41. }
  42. static struct htc_packet *htc_get_control_buf(struct htc_target *target,
  43. bool tx)
  44. {
  45. struct htc_packet *packet = NULL;
  46. struct list_head *buf_list;
  47. buf_list = tx ? &target->free_ctrl_txbuf : &target->free_ctrl_rxbuf;
  48. spin_lock_bh(&target->htc_lock);
  49. if (list_empty(buf_list)) {
  50. spin_unlock_bh(&target->htc_lock);
  51. return NULL;
  52. }
  53. packet = list_first_entry(buf_list, struct htc_packet, list);
  54. list_del(&packet->list);
  55. spin_unlock_bh(&target->htc_lock);
  56. if (tx)
  57. packet->buf = packet->buf_start + HTC_HDR_LENGTH;
  58. return packet;
  59. }
  60. static void htc_tx_comp_update(struct htc_target *target,
  61. struct htc_endpoint *endpoint,
  62. struct htc_packet *packet)
  63. {
  64. packet->completion = NULL;
  65. packet->buf += HTC_HDR_LENGTH;
  66. if (!packet->status)
  67. return;
  68. ath6kl_err("req failed (status:%d, ep:%d, len:%d creds:%d)\n",
  69. packet->status, packet->endpoint, packet->act_len,
  70. packet->info.tx.cred_used);
  71. /* on failure to submit, reclaim credits for this packet */
  72. spin_lock_bh(&target->tx_lock);
  73. endpoint->cred_dist.cred_to_dist +=
  74. packet->info.tx.cred_used;
  75. endpoint->cred_dist.txq_depth = get_queue_depth(&endpoint->txq);
  76. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
  77. target->cred_dist_cntxt, &target->cred_dist_list);
  78. ath6k_credit_distribute(target->cred_dist_cntxt,
  79. &target->cred_dist_list,
  80. HTC_CREDIT_DIST_SEND_COMPLETE);
  81. spin_unlock_bh(&target->tx_lock);
  82. }
  83. static void htc_tx_complete(struct htc_endpoint *endpoint,
  84. struct list_head *txq)
  85. {
  86. if (list_empty(txq))
  87. return;
  88. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  89. "send complete ep %d, (%d pkts)\n",
  90. endpoint->eid, get_queue_depth(txq));
  91. ath6kl_tx_complete(endpoint->target->dev->ar, txq);
  92. }
  93. static void htc_tx_comp_handler(struct htc_target *target,
  94. struct htc_packet *packet)
  95. {
  96. struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
  97. struct list_head container;
  98. htc_tx_comp_update(target, endpoint, packet);
  99. INIT_LIST_HEAD(&container);
  100. list_add_tail(&packet->list, &container);
  101. /* do completion */
  102. htc_tx_complete(endpoint, &container);
  103. }
  104. static void htc_async_tx_scat_complete(struct htc_target *target,
  105. struct hif_scatter_req *scat_req)
  106. {
  107. struct htc_endpoint *endpoint;
  108. struct htc_packet *packet;
  109. struct list_head tx_compq;
  110. int i;
  111. INIT_LIST_HEAD(&tx_compq);
  112. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  113. "htc_async_tx_scat_complete total len: %d entries: %d\n",
  114. scat_req->len, scat_req->scat_entries);
  115. if (scat_req->status)
  116. ath6kl_err("send scatter req failed: %d\n", scat_req->status);
  117. packet = scat_req->scat_list[0].packet;
  118. endpoint = &target->endpoint[packet->endpoint];
  119. /* walk through the scatter list and process */
  120. for (i = 0; i < scat_req->scat_entries; i++) {
  121. packet = scat_req->scat_list[i].packet;
  122. if (!packet) {
  123. WARN_ON(1);
  124. return;
  125. }
  126. packet->status = scat_req->status;
  127. htc_tx_comp_update(target, endpoint, packet);
  128. list_add_tail(&packet->list, &tx_compq);
  129. }
  130. /* free scatter request */
  131. hif_scatter_req_add(target->dev->ar, scat_req);
  132. /* complete all packets */
  133. htc_tx_complete(endpoint, &tx_compq);
  134. }
  135. static int htc_issue_send(struct htc_target *target, struct htc_packet *packet)
  136. {
  137. int status;
  138. bool sync = false;
  139. u32 padded_len, send_len;
  140. if (!packet->completion)
  141. sync = true;
  142. send_len = packet->act_len + HTC_HDR_LENGTH;
  143. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "%s: transmit len : %d (%s)\n",
  144. __func__, send_len, sync ? "sync" : "async");
  145. padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
  146. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  147. "DevSendPacket, padded len: %d mbox:0x%X (mode:%s)\n",
  148. padded_len,
  149. target->dev->ar->mbox_info.htc_addr,
  150. sync ? "sync" : "async");
  151. if (sync) {
  152. status = hif_read_write_sync(target->dev->ar,
  153. target->dev->ar->mbox_info.htc_addr,
  154. packet->buf, padded_len,
  155. HIF_WR_SYNC_BLOCK_INC);
  156. packet->status = status;
  157. packet->buf += HTC_HDR_LENGTH;
  158. } else
  159. status = hif_write_async(target->dev->ar,
  160. target->dev->ar->mbox_info.htc_addr,
  161. packet->buf, padded_len,
  162. HIF_WR_ASYNC_BLOCK_INC, packet);
  163. return status;
  164. }
  165. static int htc_check_credits(struct htc_target *target,
  166. struct htc_endpoint *ep, u8 *flags,
  167. enum htc_endpoint_id eid, unsigned int len,
  168. int *req_cred)
  169. {
  170. *req_cred = (len > target->tgt_cred_sz) ?
  171. DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
  172. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "creds required:%d got:%d\n",
  173. *req_cred, ep->cred_dist.credits);
  174. if (ep->cred_dist.credits < *req_cred) {
  175. if (eid == ENDPOINT_0)
  176. return -EINVAL;
  177. /* Seek more credits */
  178. ep->cred_dist.seek_cred = *req_cred - ep->cred_dist.credits;
  179. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
  180. target->cred_dist_cntxt, &ep->cred_dist);
  181. ath6k_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
  182. ep->cred_dist.seek_cred = 0;
  183. if (ep->cred_dist.credits < *req_cred) {
  184. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  185. "not enough credits for ep %d - leaving packet in queue\n",
  186. eid);
  187. return -EINVAL;
  188. }
  189. }
  190. ep->cred_dist.credits -= *req_cred;
  191. ep->ep_st.cred_cosumd += *req_cred;
  192. /* When we are getting low on credits, ask for more */
  193. if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
  194. ep->cred_dist.seek_cred =
  195. ep->cred_dist.cred_per_msg - ep->cred_dist.credits;
  196. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
  197. target->cred_dist_cntxt, &ep->cred_dist);
  198. ath6k_seek_credits(target->cred_dist_cntxt, &ep->cred_dist);
  199. /* see if we were successful in getting more */
  200. if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
  201. /* tell the target we need credits ASAP! */
  202. *flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
  203. ep->ep_st.cred_low_indicate += 1;
  204. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "host needs credits\n");
  205. }
  206. }
  207. return 0;
  208. }
  209. static void htc_tx_pkts_get(struct htc_target *target,
  210. struct htc_endpoint *endpoint,
  211. struct list_head *queue)
  212. {
  213. int req_cred;
  214. u8 flags;
  215. struct htc_packet *packet;
  216. unsigned int len;
  217. while (true) {
  218. flags = 0;
  219. if (list_empty(&endpoint->txq))
  220. break;
  221. packet = list_first_entry(&endpoint->txq, struct htc_packet,
  222. list);
  223. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  224. "got head pkt:0x%p , queue depth: %d\n",
  225. packet, get_queue_depth(&endpoint->txq));
  226. len = CALC_TXRX_PADDED_LEN(target,
  227. packet->act_len + HTC_HDR_LENGTH);
  228. if (htc_check_credits(target, endpoint, &flags,
  229. packet->endpoint, len, &req_cred))
  230. break;
  231. /* now we can fully move onto caller's queue */
  232. packet = list_first_entry(&endpoint->txq, struct htc_packet,
  233. list);
  234. list_move_tail(&packet->list, queue);
  235. /* save the number of credits this packet consumed */
  236. packet->info.tx.cred_used = req_cred;
  237. /* all TX packets are handled asynchronously */
  238. packet->completion = htc_tx_comp_handler;
  239. packet->context = target;
  240. endpoint->ep_st.tx_issued += 1;
  241. /* save send flags */
  242. packet->info.tx.flags = flags;
  243. packet->info.tx.seqno = endpoint->seqno;
  244. endpoint->seqno++;
  245. }
  246. }
  247. /* See if the padded tx length falls on a credit boundary */
  248. static int htc_get_credit_padding(unsigned int cred_sz, int *len,
  249. struct htc_endpoint *ep)
  250. {
  251. int rem_cred, cred_pad;
  252. rem_cred = *len % cred_sz;
  253. /* No padding needed */
  254. if (!rem_cred)
  255. return 0;
  256. if (!(ep->conn_flags & HTC_FLGS_TX_BNDL_PAD_EN))
  257. return -1;
  258. /*
  259. * The transfer consumes a "partial" credit, this
  260. * packet cannot be bundled unless we add
  261. * additional "dummy" padding (max 255 bytes) to
  262. * consume the entire credit.
  263. */
  264. cred_pad = *len < cred_sz ? (cred_sz - *len) : rem_cred;
  265. if ((cred_pad > 0) && (cred_pad <= 255))
  266. *len += cred_pad;
  267. else
  268. /* The amount of padding is too large, send as non-bundled */
  269. return -1;
  270. return cred_pad;
  271. }
  272. static int htc_setup_send_scat_list(struct htc_target *target,
  273. struct htc_endpoint *endpoint,
  274. struct hif_scatter_req *scat_req,
  275. int n_scat,
  276. struct list_head *queue)
  277. {
  278. struct htc_packet *packet;
  279. int i, len, rem_scat, cred_pad;
  280. int status = 0;
  281. rem_scat = target->max_tx_bndl_sz;
  282. for (i = 0; i < n_scat; i++) {
  283. scat_req->scat_list[i].packet = NULL;
  284. if (list_empty(queue))
  285. break;
  286. packet = list_first_entry(queue, struct htc_packet, list);
  287. len = CALC_TXRX_PADDED_LEN(target,
  288. packet->act_len + HTC_HDR_LENGTH);
  289. cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
  290. &len, endpoint);
  291. if (cred_pad < 0) {
  292. status = -EINVAL;
  293. break;
  294. }
  295. if (rem_scat < len) {
  296. /* exceeds what we can transfer */
  297. status = -ENOSPC;
  298. break;
  299. }
  300. rem_scat -= len;
  301. /* now remove it from the queue */
  302. packet = list_first_entry(queue, struct htc_packet, list);
  303. list_del(&packet->list);
  304. scat_req->scat_list[i].packet = packet;
  305. /* prepare packet and flag message as part of a send bundle */
  306. htc_prep_send_pkt(packet,
  307. packet->info.tx.flags | HTC_FLAGS_SEND_BUNDLE,
  308. cred_pad, packet->info.tx.seqno);
  309. scat_req->scat_list[i].buf = packet->buf;
  310. scat_req->scat_list[i].len = len;
  311. scat_req->len += len;
  312. scat_req->scat_entries++;
  313. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  314. "%d, adding pkt : 0x%p len:%d (remaining space:%d)\n",
  315. i, packet, len, rem_scat);
  316. }
  317. /* Roll back scatter setup in case of any failure */
  318. if (status || (scat_req->scat_entries < HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
  319. for (i = scat_req->scat_entries - 1; i >= 0; i--) {
  320. packet = scat_req->scat_list[i].packet;
  321. if (packet) {
  322. packet->buf += HTC_HDR_LENGTH;
  323. list_add(&packet->list, queue);
  324. }
  325. }
  326. return -EINVAL;
  327. }
  328. return 0;
  329. }
  330. /*
  331. * htc_issue_send_bundle: drain a queue and send as bundles
  332. * this function may return without fully draining the queue
  333. * when
  334. *
  335. * 1. scatter resources are exhausted
  336. * 2. a message that will consume a partial credit will stop the
  337. * bundling process early
  338. * 3. we drop below the minimum number of messages for a bundle
  339. */
  340. static void htc_issue_send_bundle(struct htc_endpoint *endpoint,
  341. struct list_head *queue,
  342. int *sent_bundle, int *n_bundle_pkts)
  343. {
  344. struct htc_target *target = endpoint->target;
  345. struct hif_scatter_req *scat_req = NULL;
  346. int n_scat, n_sent_bundle = 0, tot_pkts_bundle = 0;
  347. while (true) {
  348. n_scat = get_queue_depth(queue);
  349. n_scat = min(n_scat, target->msg_per_bndl_max);
  350. if (n_scat < HTC_MIN_HTC_MSGS_TO_BUNDLE)
  351. /* not enough to bundle */
  352. break;
  353. scat_req = hif_scatter_req_get(target->dev->ar);
  354. if (!scat_req) {
  355. /* no scatter resources */
  356. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  357. "no more scatter resources\n");
  358. break;
  359. }
  360. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "pkts to scatter: %d\n",
  361. n_scat);
  362. scat_req->len = 0;
  363. scat_req->scat_entries = 0;
  364. if (htc_setup_send_scat_list(target, endpoint, scat_req,
  365. n_scat, queue)) {
  366. hif_scatter_req_add(target->dev->ar, scat_req);
  367. break;
  368. }
  369. /* send path is always asynchronous */
  370. scat_req->complete = htc_async_tx_scat_complete;
  371. n_sent_bundle++;
  372. tot_pkts_bundle += scat_req->scat_entries;
  373. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  374. "send scatter total bytes: %d , entries: %d\n",
  375. scat_req->len, scat_req->scat_entries);
  376. ath6kldev_submit_scat_req(target->dev, scat_req, false);
  377. }
  378. *sent_bundle = n_sent_bundle;
  379. *n_bundle_pkts = tot_pkts_bundle;
  380. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "htc_issue_send_bundle (sent:%d)\n",
  381. n_sent_bundle);
  382. return;
  383. }
  384. static void htc_tx_from_ep_txq(struct htc_target *target,
  385. struct htc_endpoint *endpoint)
  386. {
  387. struct list_head txq;
  388. struct htc_packet *packet;
  389. int bundle_sent;
  390. int n_pkts_bundle;
  391. spin_lock_bh(&target->tx_lock);
  392. endpoint->tx_proc_cnt++;
  393. if (endpoint->tx_proc_cnt > 1) {
  394. endpoint->tx_proc_cnt--;
  395. spin_unlock_bh(&target->tx_lock);
  396. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "htc_try_send (busy)\n");
  397. return;
  398. }
  399. /*
  400. * drain the endpoint TX queue for transmission as long
  401. * as we have enough credits.
  402. */
  403. INIT_LIST_HEAD(&txq);
  404. while (true) {
  405. if (list_empty(&endpoint->txq))
  406. break;
  407. htc_tx_pkts_get(target, endpoint, &txq);
  408. if (list_empty(&txq))
  409. break;
  410. spin_unlock_bh(&target->tx_lock);
  411. bundle_sent = 0;
  412. n_pkts_bundle = 0;
  413. while (true) {
  414. /* try to send a bundle on each pass */
  415. if ((target->tx_bndl_enable) &&
  416. (get_queue_depth(&txq) >=
  417. HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
  418. int temp1 = 0, temp2 = 0;
  419. htc_issue_send_bundle(endpoint, &txq,
  420. &temp1, &temp2);
  421. bundle_sent += temp1;
  422. n_pkts_bundle += temp2;
  423. }
  424. if (list_empty(&txq))
  425. break;
  426. packet = list_first_entry(&txq, struct htc_packet,
  427. list);
  428. list_del(&packet->list);
  429. htc_prep_send_pkt(packet, packet->info.tx.flags,
  430. 0, packet->info.tx.seqno);
  431. htc_issue_send(target, packet);
  432. }
  433. spin_lock_bh(&target->tx_lock);
  434. endpoint->ep_st.tx_bundles += bundle_sent;
  435. endpoint->ep_st.tx_pkt_bundled += n_pkts_bundle;
  436. }
  437. endpoint->tx_proc_cnt = 0;
  438. spin_unlock_bh(&target->tx_lock);
  439. }
  440. static bool htc_try_send(struct htc_target *target,
  441. struct htc_endpoint *endpoint,
  442. struct htc_packet *tx_pkt)
  443. {
  444. struct htc_ep_callbacks ep_cb;
  445. int txq_depth;
  446. bool overflow = false;
  447. ep_cb = endpoint->ep_cb;
  448. spin_lock_bh(&target->tx_lock);
  449. txq_depth = get_queue_depth(&endpoint->txq);
  450. spin_unlock_bh(&target->tx_lock);
  451. if (txq_depth >= endpoint->max_txq_depth)
  452. overflow = true;
  453. if (overflow)
  454. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  455. "ep %d, tx queue will overflow :%d , tx depth:%d, max:%d\n",
  456. endpoint->eid, overflow, txq_depth,
  457. endpoint->max_txq_depth);
  458. if (overflow && ep_cb.tx_full) {
  459. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  460. "indicating overflowed tx packet: 0x%p\n", tx_pkt);
  461. if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
  462. HTC_SEND_FULL_DROP) {
  463. endpoint->ep_st.tx_dropped += 1;
  464. return false;
  465. }
  466. }
  467. spin_lock_bh(&target->tx_lock);
  468. list_add_tail(&tx_pkt->list, &endpoint->txq);
  469. spin_unlock_bh(&target->tx_lock);
  470. htc_tx_from_ep_txq(target, endpoint);
  471. return true;
  472. }
  473. static void htc_chk_ep_txq(struct htc_target *target)
  474. {
  475. struct htc_endpoint *endpoint;
  476. struct htc_endpoint_credit_dist *cred_dist;
  477. /*
  478. * Run through the credit distribution list to see if there are
  479. * packets queued. NOTE: no locks need to be taken since the
  480. * distribution list is not dynamic (cannot be re-ordered) and we
  481. * are not modifying any state.
  482. */
  483. list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
  484. endpoint = (struct htc_endpoint *)cred_dist->htc_rsvd;
  485. spin_lock_bh(&target->tx_lock);
  486. if (!list_empty(&endpoint->txq)) {
  487. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  488. "ep %d has %d credits and %d packets in tx queue\n",
  489. cred_dist->endpoint,
  490. endpoint->cred_dist.credits,
  491. get_queue_depth(&endpoint->txq));
  492. spin_unlock_bh(&target->tx_lock);
  493. /*
  494. * Try to start the stalled queue, this list is
  495. * ordered by priority. If there are credits
  496. * available the highest priority queue will get a
  497. * chance to reclaim credits from lower priority
  498. * ones.
  499. */
  500. htc_tx_from_ep_txq(target, endpoint);
  501. spin_lock_bh(&target->tx_lock);
  502. }
  503. spin_unlock_bh(&target->tx_lock);
  504. }
  505. }
  506. static int htc_setup_tx_complete(struct htc_target *target)
  507. {
  508. struct htc_packet *send_pkt = NULL;
  509. int status;
  510. send_pkt = htc_get_control_buf(target, true);
  511. if (!send_pkt)
  512. return -ENOMEM;
  513. if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
  514. struct htc_setup_comp_ext_msg *setup_comp_ext;
  515. u32 flags = 0;
  516. setup_comp_ext =
  517. (struct htc_setup_comp_ext_msg *)send_pkt->buf;
  518. memset(setup_comp_ext, 0, sizeof(*setup_comp_ext));
  519. setup_comp_ext->msg_id =
  520. cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
  521. if (target->msg_per_bndl_max > 0) {
  522. /* Indicate HTC bundling to the target */
  523. flags |= HTC_SETUP_COMP_FLG_RX_BNDL_EN;
  524. setup_comp_ext->msg_per_rxbndl =
  525. target->msg_per_bndl_max;
  526. }
  527. memcpy(&setup_comp_ext->flags, &flags,
  528. sizeof(setup_comp_ext->flags));
  529. set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp_ext,
  530. sizeof(struct htc_setup_comp_ext_msg),
  531. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  532. } else {
  533. struct htc_setup_comp_msg *setup_comp;
  534. setup_comp = (struct htc_setup_comp_msg *)send_pkt->buf;
  535. memset(setup_comp, 0, sizeof(struct htc_setup_comp_msg));
  536. setup_comp->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_ID);
  537. set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp,
  538. sizeof(struct htc_setup_comp_msg),
  539. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  540. }
  541. /* we want synchronous operation */
  542. send_pkt->completion = NULL;
  543. htc_prep_send_pkt(send_pkt, 0, 0, 0);
  544. status = htc_issue_send(target, send_pkt);
  545. if (send_pkt != NULL)
  546. htc_reclaim_txctrl_buf(target, send_pkt);
  547. return status;
  548. }
  549. void ath6kl_htc_set_credit_dist(struct htc_target *target,
  550. struct htc_credit_state_info *cred_dist_cntxt,
  551. u16 srvc_pri_order[], int list_len)
  552. {
  553. struct htc_endpoint *endpoint;
  554. int i, ep;
  555. target->cred_dist_cntxt = cred_dist_cntxt;
  556. list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
  557. &target->cred_dist_list);
  558. for (i = 0; i < list_len; i++) {
  559. for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) {
  560. endpoint = &target->endpoint[ep];
  561. if (endpoint->svc_id == srvc_pri_order[i]) {
  562. list_add_tail(&endpoint->cred_dist.list,
  563. &target->cred_dist_list);
  564. break;
  565. }
  566. }
  567. if (ep >= ENDPOINT_MAX) {
  568. WARN_ON(1);
  569. return;
  570. }
  571. }
  572. }
  573. int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet)
  574. {
  575. struct htc_endpoint *endpoint;
  576. struct list_head queue;
  577. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  578. "htc_tx: ep id: %d, buf: 0x%p, len: %d\n",
  579. packet->endpoint, packet->buf, packet->act_len);
  580. if (packet->endpoint >= ENDPOINT_MAX) {
  581. WARN_ON(1);
  582. return -EINVAL;
  583. }
  584. endpoint = &target->endpoint[packet->endpoint];
  585. if (!htc_try_send(target, endpoint, packet)) {
  586. packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
  587. -ECANCELED : -ENOSPC;
  588. INIT_LIST_HEAD(&queue);
  589. list_add(&packet->list, &queue);
  590. htc_tx_complete(endpoint, &queue);
  591. }
  592. return 0;
  593. }
  594. /* flush endpoint TX queue */
  595. void ath6kl_htc_flush_txep(struct htc_target *target,
  596. enum htc_endpoint_id eid, u16 tag)
  597. {
  598. struct htc_packet *packet, *tmp_pkt;
  599. struct list_head discard_q, container;
  600. struct htc_endpoint *endpoint = &target->endpoint[eid];
  601. if (!endpoint->svc_id) {
  602. WARN_ON(1);
  603. return;
  604. }
  605. /* initialize the discard queue */
  606. INIT_LIST_HEAD(&discard_q);
  607. spin_lock_bh(&target->tx_lock);
  608. list_for_each_entry_safe(packet, tmp_pkt, &endpoint->txq, list) {
  609. if ((tag == HTC_TX_PACKET_TAG_ALL) ||
  610. (tag == packet->info.tx.tag))
  611. list_move_tail(&packet->list, &discard_q);
  612. }
  613. spin_unlock_bh(&target->tx_lock);
  614. list_for_each_entry_safe(packet, tmp_pkt, &discard_q, list) {
  615. packet->status = -ECANCELED;
  616. list_del(&packet->list);
  617. ath6kl_dbg(ATH6KL_DBG_TRC,
  618. "flushing tx pkt:0x%p, len:%d, ep:%d tag:0x%X\n",
  619. packet, packet->act_len,
  620. packet->endpoint, packet->info.tx.tag);
  621. INIT_LIST_HEAD(&container);
  622. list_add_tail(&packet->list, &container);
  623. htc_tx_complete(endpoint, &container);
  624. }
  625. }
  626. static void ath6kl_htc_flush_txep_all(struct htc_target *target)
  627. {
  628. struct htc_endpoint *endpoint;
  629. int i;
  630. dump_cred_dist_stats(target);
  631. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  632. endpoint = &target->endpoint[i];
  633. if (endpoint->svc_id == 0)
  634. /* not in use.. */
  635. continue;
  636. ath6kl_htc_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
  637. }
  638. }
  639. void ath6kl_htc_indicate_activity_change(struct htc_target *target,
  640. enum htc_endpoint_id eid, bool active)
  641. {
  642. struct htc_endpoint *endpoint = &target->endpoint[eid];
  643. bool dist = false;
  644. if (endpoint->svc_id == 0) {
  645. WARN_ON(1);
  646. return;
  647. }
  648. spin_lock_bh(&target->tx_lock);
  649. if (active) {
  650. if (!(endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE)) {
  651. endpoint->cred_dist.dist_flags |= HTC_EP_ACTIVE;
  652. dist = true;
  653. }
  654. } else {
  655. if (endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE) {
  656. endpoint->cred_dist.dist_flags &= ~HTC_EP_ACTIVE;
  657. dist = true;
  658. }
  659. }
  660. if (dist) {
  661. endpoint->cred_dist.txq_depth =
  662. get_queue_depth(&endpoint->txq);
  663. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
  664. target->cred_dist_cntxt, &target->cred_dist_list);
  665. ath6k_credit_distribute(target->cred_dist_cntxt,
  666. &target->cred_dist_list,
  667. HTC_CREDIT_DIST_ACTIVITY_CHANGE);
  668. }
  669. spin_unlock_bh(&target->tx_lock);
  670. if (dist && !active)
  671. htc_chk_ep_txq(target);
  672. }
  673. /* HTC Rx */
  674. static inline void htc_update_rx_stats(struct htc_endpoint *endpoint,
  675. int n_look_ahds)
  676. {
  677. endpoint->ep_st.rx_pkts++;
  678. if (n_look_ahds == 1)
  679. endpoint->ep_st.rx_lkahds++;
  680. else if (n_look_ahds > 1)
  681. endpoint->ep_st.rx_bundle_lkahd++;
  682. }
  683. static inline bool htc_valid_rx_frame_len(struct htc_target *target,
  684. enum htc_endpoint_id eid, int len)
  685. {
  686. return (eid == target->dev->ar->ctrl_ep) ?
  687. len <= ATH6KL_BUFFER_SIZE : len <= ATH6KL_AMSDU_BUFFER_SIZE;
  688. }
  689. static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
  690. {
  691. struct list_head queue;
  692. INIT_LIST_HEAD(&queue);
  693. list_add_tail(&packet->list, &queue);
  694. return ath6kl_htc_add_rxbuf_multiple(target, &queue);
  695. }
  696. static void htc_reclaim_rxbuf(struct htc_target *target,
  697. struct htc_packet *packet,
  698. struct htc_endpoint *ep)
  699. {
  700. if (packet->info.rx.rx_flags & HTC_RX_PKT_NO_RECYCLE) {
  701. htc_rxpkt_reset(packet);
  702. packet->status = -ECANCELED;
  703. ep->ep_cb.rx(ep->target, packet);
  704. } else {
  705. htc_rxpkt_reset(packet);
  706. htc_add_rxbuf((void *)(target), packet);
  707. }
  708. }
  709. static void reclaim_rx_ctrl_buf(struct htc_target *target,
  710. struct htc_packet *packet)
  711. {
  712. spin_lock_bh(&target->htc_lock);
  713. list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
  714. spin_unlock_bh(&target->htc_lock);
  715. }
  716. static int dev_rx_pkt(struct htc_target *target, struct htc_packet *packet,
  717. u32 rx_len)
  718. {
  719. struct ath6kl_device *dev = target->dev;
  720. u32 padded_len;
  721. int status;
  722. padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
  723. if (padded_len > packet->buf_len) {
  724. ath6kl_err("not enough receive space for packet - padlen:%d recvlen:%d bufferlen:%d\n",
  725. padded_len, rx_len, packet->buf_len);
  726. return -ENOMEM;
  727. }
  728. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  729. "dev_rx_pkt (0x%p : hdr:0x%X) padded len: %d mbox:0x%X (mode:%s)\n",
  730. packet, packet->info.rx.exp_hdr,
  731. padded_len, dev->ar->mbox_info.htc_addr, "sync");
  732. status = hif_read_write_sync(dev->ar,
  733. dev->ar->mbox_info.htc_addr,
  734. packet->buf, padded_len,
  735. HIF_RD_SYNC_BLOCK_FIX);
  736. packet->status = status;
  737. return status;
  738. }
  739. /*
  740. * optimization for recv packets, we can indicate a
  741. * "hint" that there are more single-packets to fetch
  742. * on this endpoint.
  743. */
  744. static void set_rxpkt_indication_flag(u32 lk_ahd,
  745. struct htc_endpoint *endpoint,
  746. struct htc_packet *packet)
  747. {
  748. struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)&lk_ahd;
  749. if (htc_hdr->eid == packet->endpoint) {
  750. if (!list_empty(&endpoint->rx_bufq))
  751. packet->info.rx.indicat_flags |=
  752. HTC_RX_FLAGS_INDICATE_MORE_PKTS;
  753. }
  754. }
  755. static void chk_rx_water_mark(struct htc_endpoint *endpoint)
  756. {
  757. struct htc_ep_callbacks ep_cb = endpoint->ep_cb;
  758. if (ep_cb.rx_refill_thresh > 0) {
  759. spin_lock_bh(&endpoint->target->rx_lock);
  760. if (get_queue_depth(&endpoint->rx_bufq)
  761. < ep_cb.rx_refill_thresh) {
  762. spin_unlock_bh(&endpoint->target->rx_lock);
  763. ep_cb.rx_refill(endpoint->target, endpoint->eid);
  764. return;
  765. }
  766. spin_unlock_bh(&endpoint->target->rx_lock);
  767. }
  768. }
  769. /* This function is called with rx_lock held */
  770. static int htc_setup_rxpkts(struct htc_target *target, struct htc_endpoint *ep,
  771. u32 *lk_ahds, struct list_head *queue, int n_msg)
  772. {
  773. struct htc_packet *packet;
  774. /* FIXME: type of lk_ahds can't be right */
  775. struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)lk_ahds;
  776. struct htc_ep_callbacks ep_cb;
  777. int status = 0, j, full_len;
  778. bool no_recycle;
  779. full_len = CALC_TXRX_PADDED_LEN(target,
  780. le16_to_cpu(htc_hdr->payld_len) +
  781. sizeof(*htc_hdr));
  782. if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
  783. ath6kl_warn("Rx buffer requested with invalid length\n");
  784. return -EINVAL;
  785. }
  786. ep_cb = ep->ep_cb;
  787. for (j = 0; j < n_msg; j++) {
  788. /*
  789. * Reset flag, any packets allocated using the
  790. * rx_alloc() API cannot be recycled on
  791. * cleanup,they must be explicitly returned.
  792. */
  793. no_recycle = false;
  794. if (ep_cb.rx_allocthresh &&
  795. (full_len > ep_cb.rx_alloc_thresh)) {
  796. ep->ep_st.rx_alloc_thresh_hit += 1;
  797. ep->ep_st.rxalloc_thresh_byte +=
  798. le16_to_cpu(htc_hdr->payld_len);
  799. spin_unlock_bh(&target->rx_lock);
  800. no_recycle = true;
  801. packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
  802. full_len);
  803. spin_lock_bh(&target->rx_lock);
  804. } else {
  805. /* refill handler is being used */
  806. if (list_empty(&ep->rx_bufq)) {
  807. if (ep_cb.rx_refill) {
  808. spin_unlock_bh(&target->rx_lock);
  809. ep_cb.rx_refill(ep->target, ep->eid);
  810. spin_lock_bh(&target->rx_lock);
  811. }
  812. }
  813. if (list_empty(&ep->rx_bufq))
  814. packet = NULL;
  815. else {
  816. packet = list_first_entry(&ep->rx_bufq,
  817. struct htc_packet, list);
  818. list_del(&packet->list);
  819. }
  820. }
  821. if (!packet) {
  822. target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
  823. target->ep_waiting = ep->eid;
  824. return -ENOSPC;
  825. }
  826. /* clear flags */
  827. packet->info.rx.rx_flags = 0;
  828. packet->info.rx.indicat_flags = 0;
  829. packet->status = 0;
  830. if (no_recycle)
  831. /*
  832. * flag that these packets cannot be
  833. * recycled, they have to be returned to
  834. * the user
  835. */
  836. packet->info.rx.rx_flags |= HTC_RX_PKT_NO_RECYCLE;
  837. /* Caller needs to free this upon any failure */
  838. list_add_tail(&packet->list, queue);
  839. if (target->htc_flags & HTC_OP_STATE_STOPPING) {
  840. status = -ECANCELED;
  841. break;
  842. }
  843. if (j) {
  844. packet->info.rx.rx_flags |= HTC_RX_PKT_REFRESH_HDR;
  845. packet->info.rx.exp_hdr = 0xFFFFFFFF;
  846. } else
  847. /* set expected look ahead */
  848. packet->info.rx.exp_hdr = *lk_ahds;
  849. packet->act_len = le16_to_cpu(htc_hdr->payld_len) +
  850. HTC_HDR_LENGTH;
  851. }
  852. return status;
  853. }
  854. static int alloc_and_prep_rxpkts(struct htc_target *target,
  855. u32 lk_ahds[], int msg,
  856. struct htc_endpoint *endpoint,
  857. struct list_head *queue)
  858. {
  859. int status = 0;
  860. struct htc_packet *packet, *tmp_pkt;
  861. struct htc_frame_hdr *htc_hdr;
  862. int i, n_msg;
  863. spin_lock_bh(&target->rx_lock);
  864. for (i = 0; i < msg; i++) {
  865. htc_hdr = (struct htc_frame_hdr *)&lk_ahds[i];
  866. if (htc_hdr->eid >= ENDPOINT_MAX) {
  867. ath6kl_err("invalid ep in look-ahead: %d\n",
  868. htc_hdr->eid);
  869. status = -ENOMEM;
  870. break;
  871. }
  872. if (htc_hdr->eid != endpoint->eid) {
  873. ath6kl_err("invalid ep in look-ahead: %d should be : %d (index:%d)\n",
  874. htc_hdr->eid, endpoint->eid, i);
  875. status = -ENOMEM;
  876. break;
  877. }
  878. if (le16_to_cpu(htc_hdr->payld_len) > HTC_MAX_PAYLOAD_LENGTH) {
  879. ath6kl_err("payload len %d exceeds max htc : %d !\n",
  880. htc_hdr->payld_len,
  881. (u32) HTC_MAX_PAYLOAD_LENGTH);
  882. status = -ENOMEM;
  883. break;
  884. }
  885. if (endpoint->svc_id == 0) {
  886. ath6kl_err("ep %d is not connected !\n", htc_hdr->eid);
  887. status = -ENOMEM;
  888. break;
  889. }
  890. if (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) {
  891. /*
  892. * HTC header indicates that every packet to follow
  893. * has the same padded length so that it can be
  894. * optimally fetched as a full bundle.
  895. */
  896. n_msg = (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) >>
  897. HTC_FLG_RX_BNDL_CNT_S;
  898. /* the count doesn't include the starter frame */
  899. n_msg++;
  900. if (n_msg > target->msg_per_bndl_max) {
  901. status = -ENOMEM;
  902. break;
  903. }
  904. endpoint->ep_st.rx_bundle_from_hdr += 1;
  905. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  906. "htc hdr indicates :%d msg can be fetched as a bundle\n",
  907. n_msg);
  908. } else
  909. /* HTC header only indicates 1 message to fetch */
  910. n_msg = 1;
  911. /* Setup packet buffers for each message */
  912. status = htc_setup_rxpkts(target, endpoint, &lk_ahds[i], queue,
  913. n_msg);
  914. /*
  915. * This is due to unavailabilty of buffers to rx entire data.
  916. * Return no error so that free buffers from queue can be used
  917. * to receive partial data.
  918. */
  919. if (status == -ENOSPC) {
  920. spin_unlock_bh(&target->rx_lock);
  921. return 0;
  922. }
  923. if (status)
  924. break;
  925. }
  926. spin_unlock_bh(&target->rx_lock);
  927. if (status) {
  928. list_for_each_entry_safe(packet, tmp_pkt, queue, list) {
  929. list_del(&packet->list);
  930. htc_reclaim_rxbuf(target, packet,
  931. &target->endpoint[packet->endpoint]);
  932. }
  933. }
  934. return status;
  935. }
  936. static void htc_ctrl_rx(struct htc_target *context, struct htc_packet *packets)
  937. {
  938. if (packets->endpoint != ENDPOINT_0) {
  939. WARN_ON(1);
  940. return;
  941. }
  942. if (packets->status == -ECANCELED) {
  943. reclaim_rx_ctrl_buf(context, packets);
  944. return;
  945. }
  946. if (packets->act_len > 0) {
  947. ath6kl_err("htc_ctrl_rx, got message with len:%zu\n",
  948. packets->act_len + HTC_HDR_LENGTH);
  949. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES,
  950. "Unexpected ENDPOINT 0 Message",
  951. packets->buf - HTC_HDR_LENGTH,
  952. packets->act_len + HTC_HDR_LENGTH);
  953. }
  954. htc_reclaim_rxbuf(context, packets, &context->endpoint[0]);
  955. }
  956. static void htc_proc_cred_rpt(struct htc_target *target,
  957. struct htc_credit_report *rpt,
  958. int n_entries,
  959. enum htc_endpoint_id from_ep)
  960. {
  961. struct htc_endpoint *endpoint;
  962. int tot_credits = 0, i;
  963. bool dist = false;
  964. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  965. "htc_proc_cred_rpt, credit report entries:%d\n", n_entries);
  966. spin_lock_bh(&target->tx_lock);
  967. for (i = 0; i < n_entries; i++, rpt++) {
  968. if (rpt->eid >= ENDPOINT_MAX) {
  969. WARN_ON(1);
  970. spin_unlock_bh(&target->tx_lock);
  971. return;
  972. }
  973. endpoint = &target->endpoint[rpt->eid];
  974. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, " ep %d got %d credits\n",
  975. rpt->eid, rpt->credits);
  976. endpoint->ep_st.tx_cred_rpt += 1;
  977. endpoint->ep_st.cred_retnd += rpt->credits;
  978. if (from_ep == rpt->eid) {
  979. /*
  980. * This credit report arrived on the same endpoint
  981. * indicating it arrived in an RX packet.
  982. */
  983. endpoint->ep_st.cred_from_rx += rpt->credits;
  984. endpoint->ep_st.cred_rpt_from_rx += 1;
  985. } else if (from_ep == ENDPOINT_0) {
  986. /* credit arrived on endpoint 0 as a NULL message */
  987. endpoint->ep_st.cred_from_ep0 += rpt->credits;
  988. endpoint->ep_st.cred_rpt_ep0 += 1;
  989. } else {
  990. endpoint->ep_st.cred_from_other += rpt->credits;
  991. endpoint->ep_st.cred_rpt_from_other += 1;
  992. }
  993. if (rpt->eid == ENDPOINT_0)
  994. /* always give endpoint 0 credits back */
  995. endpoint->cred_dist.credits += rpt->credits;
  996. else {
  997. endpoint->cred_dist.cred_to_dist += rpt->credits;
  998. dist = true;
  999. }
  1000. /*
  1001. * Refresh tx depth for distribution function that will
  1002. * recover these credits NOTE: this is only valid when
  1003. * there are credits to recover!
  1004. */
  1005. endpoint->cred_dist.txq_depth =
  1006. get_queue_depth(&endpoint->txq);
  1007. tot_credits += rpt->credits;
  1008. }
  1009. ath6kl_dbg(ATH6KL_DBG_HTC_SEND,
  1010. "report indicated %d credits to distribute\n",
  1011. tot_credits);
  1012. if (dist) {
  1013. /*
  1014. * This was a credit return based on a completed send
  1015. * operations note, this is done with the lock held
  1016. */
  1017. ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:0x%p dist:0x%p\n",
  1018. target->cred_dist_cntxt, &target->cred_dist_list);
  1019. ath6k_credit_distribute(target->cred_dist_cntxt,
  1020. &target->cred_dist_list,
  1021. HTC_CREDIT_DIST_SEND_COMPLETE);
  1022. }
  1023. spin_unlock_bh(&target->tx_lock);
  1024. if (tot_credits)
  1025. htc_chk_ep_txq(target);
  1026. }
  1027. static int htc_parse_trailer(struct htc_target *target,
  1028. struct htc_record_hdr *record,
  1029. u8 *record_buf, u32 *next_lk_ahds,
  1030. enum htc_endpoint_id endpoint,
  1031. int *n_lk_ahds)
  1032. {
  1033. struct htc_bundle_lkahd_rpt *bundle_lkahd_rpt;
  1034. struct htc_lookahead_report *lk_ahd;
  1035. int len;
  1036. switch (record->rec_id) {
  1037. case HTC_RECORD_CREDITS:
  1038. len = record->len / sizeof(struct htc_credit_report);
  1039. if (!len) {
  1040. WARN_ON(1);
  1041. return -EINVAL;
  1042. }
  1043. htc_proc_cred_rpt(target,
  1044. (struct htc_credit_report *) record_buf,
  1045. len, endpoint);
  1046. break;
  1047. case HTC_RECORD_LOOKAHEAD:
  1048. len = record->len / sizeof(*lk_ahd);
  1049. if (!len) {
  1050. WARN_ON(1);
  1051. return -EINVAL;
  1052. }
  1053. lk_ahd = (struct htc_lookahead_report *) record_buf;
  1054. if ((lk_ahd->pre_valid == ((~lk_ahd->post_valid) & 0xFF))
  1055. && next_lk_ahds) {
  1056. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1057. "lk_ahd report found (pre valid:0x%X, post valid:0x%X)\n",
  1058. lk_ahd->pre_valid, lk_ahd->post_valid);
  1059. /* look ahead bytes are valid, copy them over */
  1060. memcpy((u8 *)&next_lk_ahds[0], lk_ahd->lk_ahd, 4);
  1061. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Next Look Ahead",
  1062. next_lk_ahds, 4);
  1063. *n_lk_ahds = 1;
  1064. }
  1065. break;
  1066. case HTC_RECORD_LOOKAHEAD_BUNDLE:
  1067. len = record->len / sizeof(*bundle_lkahd_rpt);
  1068. if (!len || (len > HTC_HOST_MAX_MSG_PER_BUNDLE)) {
  1069. WARN_ON(1);
  1070. return -EINVAL;
  1071. }
  1072. if (next_lk_ahds) {
  1073. int i;
  1074. bundle_lkahd_rpt =
  1075. (struct htc_bundle_lkahd_rpt *) record_buf;
  1076. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Bundle lk_ahd",
  1077. record_buf, record->len);
  1078. for (i = 0; i < len; i++) {
  1079. memcpy((u8 *)&next_lk_ahds[i],
  1080. bundle_lkahd_rpt->lk_ahd, 4);
  1081. bundle_lkahd_rpt++;
  1082. }
  1083. *n_lk_ahds = i;
  1084. }
  1085. break;
  1086. default:
  1087. ath6kl_err("unhandled record: id:%d len:%d\n",
  1088. record->rec_id, record->len);
  1089. break;
  1090. }
  1091. return 0;
  1092. }
  1093. static int htc_proc_trailer(struct htc_target *target,
  1094. u8 *buf, int len, u32 *next_lk_ahds,
  1095. int *n_lk_ahds, enum htc_endpoint_id endpoint)
  1096. {
  1097. struct htc_record_hdr *record;
  1098. int orig_len;
  1099. int status;
  1100. u8 *record_buf;
  1101. u8 *orig_buf;
  1102. ath6kl_dbg(ATH6KL_DBG_HTC_RECV, "+htc_proc_trailer (len:%d)\n", len);
  1103. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Recv Trailer", buf, len);
  1104. orig_buf = buf;
  1105. orig_len = len;
  1106. status = 0;
  1107. while (len > 0) {
  1108. if (len < sizeof(struct htc_record_hdr)) {
  1109. status = -ENOMEM;
  1110. break;
  1111. }
  1112. /* these are byte aligned structs */
  1113. record = (struct htc_record_hdr *) buf;
  1114. len -= sizeof(struct htc_record_hdr);
  1115. buf += sizeof(struct htc_record_hdr);
  1116. if (record->len > len) {
  1117. ath6kl_err("invalid record len: %d (id:%d) buf has: %d bytes left\n",
  1118. record->len, record->rec_id, len);
  1119. status = -ENOMEM;
  1120. break;
  1121. }
  1122. record_buf = buf;
  1123. status = htc_parse_trailer(target, record, record_buf,
  1124. next_lk_ahds, endpoint, n_lk_ahds);
  1125. if (status)
  1126. break;
  1127. /* advance buffer past this record for next time around */
  1128. buf += record->len;
  1129. len -= record->len;
  1130. }
  1131. if (status)
  1132. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "BAD Recv Trailer",
  1133. orig_buf, orig_len);
  1134. return status;
  1135. }
  1136. static int htc_proc_rxhdr(struct htc_target *target,
  1137. struct htc_packet *packet,
  1138. u32 *next_lkahds, int *n_lkahds)
  1139. {
  1140. int status = 0;
  1141. u16 payload_len;
  1142. u32 lk_ahd;
  1143. struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)packet->buf;
  1144. if (n_lkahds != NULL)
  1145. *n_lkahds = 0;
  1146. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "HTC Recv PKT", packet->buf,
  1147. packet->act_len);
  1148. /*
  1149. * NOTE: we cannot assume the alignment of buf, so we use the safe
  1150. * macros to retrieve 16 bit fields.
  1151. */
  1152. payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
  1153. memcpy((u8 *)&lk_ahd, packet->buf, sizeof(lk_ahd));
  1154. if (packet->info.rx.rx_flags & HTC_RX_PKT_REFRESH_HDR) {
  1155. /*
  1156. * Refresh the expected header and the actual length as it
  1157. * was unknown when this packet was grabbed as part of the
  1158. * bundle.
  1159. */
  1160. packet->info.rx.exp_hdr = lk_ahd;
  1161. packet->act_len = payload_len + HTC_HDR_LENGTH;
  1162. /* validate the actual header that was refreshed */
  1163. if (packet->act_len > packet->buf_len) {
  1164. ath6kl_err("refreshed hdr payload len (%d) in bundled recv is invalid (hdr: 0x%X)\n",
  1165. payload_len, lk_ahd);
  1166. /*
  1167. * Limit this to max buffer just to print out some
  1168. * of the buffer.
  1169. */
  1170. packet->act_len = min(packet->act_len, packet->buf_len);
  1171. status = -ENOMEM;
  1172. goto fail_rx;
  1173. }
  1174. if (packet->endpoint != htc_hdr->eid) {
  1175. ath6kl_err("refreshed hdr ep (%d) does not match expected ep (%d)\n",
  1176. htc_hdr->eid, packet->endpoint);
  1177. status = -ENOMEM;
  1178. goto fail_rx;
  1179. }
  1180. }
  1181. if (lk_ahd != packet->info.rx.exp_hdr) {
  1182. ath6kl_err("htc_proc_rxhdr, lk_ahd mismatch! (pPkt:0x%p flags:0x%X)\n",
  1183. packet, packet->info.rx.rx_flags);
  1184. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Expected Message lk_ahd",
  1185. &packet->info.rx.exp_hdr, 4);
  1186. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "Current Frame Header",
  1187. (u8 *)&lk_ahd, sizeof(lk_ahd));
  1188. status = -ENOMEM;
  1189. goto fail_rx;
  1190. }
  1191. if (htc_hdr->flags & HTC_FLG_RX_TRAILER) {
  1192. if (htc_hdr->ctrl[0] < sizeof(struct htc_record_hdr) ||
  1193. htc_hdr->ctrl[0] > payload_len) {
  1194. ath6kl_err("htc_proc_rxhdr, invalid hdr (payload len should be :%d, CB[0] is:%d)\n",
  1195. payload_len, htc_hdr->ctrl[0]);
  1196. status = -ENOMEM;
  1197. goto fail_rx;
  1198. }
  1199. if (packet->info.rx.rx_flags & HTC_RX_PKT_IGNORE_LOOKAHEAD) {
  1200. next_lkahds = NULL;
  1201. n_lkahds = NULL;
  1202. }
  1203. status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
  1204. + payload_len - htc_hdr->ctrl[0],
  1205. htc_hdr->ctrl[0], next_lkahds,
  1206. n_lkahds, packet->endpoint);
  1207. if (status)
  1208. goto fail_rx;
  1209. packet->act_len -= htc_hdr->ctrl[0];
  1210. }
  1211. packet->buf += HTC_HDR_LENGTH;
  1212. packet->act_len -= HTC_HDR_LENGTH;
  1213. fail_rx:
  1214. if (status)
  1215. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "BAD HTC Recv PKT",
  1216. packet->buf,
  1217. packet->act_len < 256 ? packet->act_len : 256);
  1218. else {
  1219. if (packet->act_len > 0)
  1220. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES,
  1221. "HTC - Application Msg",
  1222. packet->buf, packet->act_len);
  1223. }
  1224. return status;
  1225. }
  1226. static void do_rx_completion(struct htc_endpoint *endpoint,
  1227. struct htc_packet *packet)
  1228. {
  1229. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1230. "htc calling ep %d recv callback on packet 0x%p\n",
  1231. endpoint->eid, packet);
  1232. endpoint->ep_cb.rx(endpoint->target, packet);
  1233. }
  1234. static int htc_issue_rxpkt_bundle(struct htc_target *target,
  1235. struct list_head *rxq,
  1236. struct list_head *sync_compq,
  1237. int *n_pkt_fetched, bool part_bundle)
  1238. {
  1239. struct hif_scatter_req *scat_req;
  1240. struct htc_packet *packet;
  1241. int rem_space = target->max_rx_bndl_sz;
  1242. int n_scat_pkt, status = 0, i, len;
  1243. n_scat_pkt = get_queue_depth(rxq);
  1244. n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
  1245. if ((get_queue_depth(rxq) - n_scat_pkt) > 0) {
  1246. /*
  1247. * We were forced to split this bundle receive operation
  1248. * all packets in this partial bundle must have their
  1249. * lookaheads ignored.
  1250. */
  1251. part_bundle = true;
  1252. /*
  1253. * This would only happen if the target ignored our max
  1254. * bundle limit.
  1255. */
  1256. ath6kl_warn("htc_issue_rxpkt_bundle : partial bundle detected num:%d , %d\n",
  1257. get_queue_depth(rxq), n_scat_pkt);
  1258. }
  1259. len = 0;
  1260. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1261. "htc_issue_rxpkt_bundle (numpackets: %d , actual : %d)\n",
  1262. get_queue_depth(rxq), n_scat_pkt);
  1263. scat_req = hif_scatter_req_get(target->dev->ar);
  1264. if (scat_req == NULL)
  1265. goto fail_rx_pkt;
  1266. for (i = 0; i < n_scat_pkt; i++) {
  1267. int pad_len;
  1268. packet = list_first_entry(rxq, struct htc_packet, list);
  1269. list_del(&packet->list);
  1270. pad_len = CALC_TXRX_PADDED_LEN(target,
  1271. packet->act_len);
  1272. if ((rem_space - pad_len) < 0) {
  1273. list_add(&packet->list, rxq);
  1274. break;
  1275. }
  1276. rem_space -= pad_len;
  1277. if (part_bundle || (i < (n_scat_pkt - 1)))
  1278. /*
  1279. * Packet 0..n-1 cannot be checked for look-aheads
  1280. * since we are fetching a bundle the last packet
  1281. * however can have it's lookahead used
  1282. */
  1283. packet->info.rx.rx_flags |=
  1284. HTC_RX_PKT_IGNORE_LOOKAHEAD;
  1285. /* NOTE: 1 HTC packet per scatter entry */
  1286. scat_req->scat_list[i].buf = packet->buf;
  1287. scat_req->scat_list[i].len = pad_len;
  1288. packet->info.rx.rx_flags |= HTC_RX_PKT_PART_OF_BUNDLE;
  1289. list_add_tail(&packet->list, sync_compq);
  1290. WARN_ON(!scat_req->scat_list[i].len);
  1291. len += scat_req->scat_list[i].len;
  1292. }
  1293. scat_req->len = len;
  1294. scat_req->scat_entries = i;
  1295. status = ath6kldev_submit_scat_req(target->dev, scat_req, true);
  1296. if (!status)
  1297. *n_pkt_fetched = i;
  1298. /* free scatter request */
  1299. hif_scatter_req_add(target->dev->ar, scat_req);
  1300. fail_rx_pkt:
  1301. return status;
  1302. }
  1303. static int htc_proc_fetched_rxpkts(struct htc_target *target,
  1304. struct list_head *comp_pktq, u32 lk_ahds[],
  1305. int *n_lk_ahd)
  1306. {
  1307. struct htc_packet *packet, *tmp_pkt;
  1308. struct htc_endpoint *ep;
  1309. int status = 0;
  1310. list_for_each_entry_safe(packet, tmp_pkt, comp_pktq, list) {
  1311. list_del(&packet->list);
  1312. ep = &target->endpoint[packet->endpoint];
  1313. /* process header for each of the recv packet */
  1314. status = htc_proc_rxhdr(target, packet, lk_ahds, n_lk_ahd);
  1315. if (status)
  1316. return status;
  1317. if (list_empty(comp_pktq)) {
  1318. /*
  1319. * Last packet's more packet flag is set
  1320. * based on the lookahead.
  1321. */
  1322. if (*n_lk_ahd > 0)
  1323. set_rxpkt_indication_flag(lk_ahds[0],
  1324. ep, packet);
  1325. } else
  1326. /*
  1327. * Packets in a bundle automatically have
  1328. * this flag set.
  1329. */
  1330. packet->info.rx.indicat_flags |=
  1331. HTC_RX_FLAGS_INDICATE_MORE_PKTS;
  1332. htc_update_rx_stats(ep, *n_lk_ahd);
  1333. if (packet->info.rx.rx_flags & HTC_RX_PKT_PART_OF_BUNDLE)
  1334. ep->ep_st.rx_bundl += 1;
  1335. do_rx_completion(ep, packet);
  1336. }
  1337. return status;
  1338. }
  1339. static int htc_fetch_rxpkts(struct htc_target *target,
  1340. struct list_head *rx_pktq,
  1341. struct list_head *comp_pktq)
  1342. {
  1343. int fetched_pkts;
  1344. bool part_bundle = false;
  1345. int status = 0;
  1346. /* now go fetch the list of HTC packets */
  1347. while (!list_empty(rx_pktq)) {
  1348. fetched_pkts = 0;
  1349. if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
  1350. /*
  1351. * There are enough packets to attempt a
  1352. * bundle transfer and recv bundling is
  1353. * allowed.
  1354. */
  1355. status = htc_issue_rxpkt_bundle(target, rx_pktq,
  1356. comp_pktq,
  1357. &fetched_pkts,
  1358. part_bundle);
  1359. if (status)
  1360. return status;
  1361. if (!list_empty(rx_pktq))
  1362. part_bundle = true;
  1363. }
  1364. if (!fetched_pkts) {
  1365. struct htc_packet *packet;
  1366. packet = list_first_entry(rx_pktq, struct htc_packet,
  1367. list);
  1368. list_del(&packet->list);
  1369. /* fully synchronous */
  1370. packet->completion = NULL;
  1371. if (!list_empty(rx_pktq))
  1372. /*
  1373. * look_aheads in all packet
  1374. * except the last one in the
  1375. * bundle must be ignored
  1376. */
  1377. packet->info.rx.rx_flags |=
  1378. HTC_RX_PKT_IGNORE_LOOKAHEAD;
  1379. /* go fetch the packet */
  1380. status = dev_rx_pkt(target, packet, packet->act_len);
  1381. if (status)
  1382. return status;
  1383. list_add_tail(&packet->list, comp_pktq);
  1384. }
  1385. }
  1386. return status;
  1387. }
  1388. int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
  1389. u32 msg_look_ahead[], int *num_pkts)
  1390. {
  1391. struct htc_packet *packets, *tmp_pkt;
  1392. struct htc_endpoint *endpoint;
  1393. struct list_head rx_pktq, comp_pktq;
  1394. int status = 0;
  1395. u32 look_aheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
  1396. int num_look_ahead = 1;
  1397. enum htc_endpoint_id id;
  1398. int n_fetched = 0;
  1399. *num_pkts = 0;
  1400. /*
  1401. * On first entry copy the look_aheads into our temp array for
  1402. * processing
  1403. */
  1404. memcpy(look_aheads, msg_look_ahead, sizeof(look_aheads));
  1405. while (true) {
  1406. /*
  1407. * First lookahead sets the expected endpoint IDs for all
  1408. * packets in a bundle.
  1409. */
  1410. id = ((struct htc_frame_hdr *)&look_aheads[0])->eid;
  1411. endpoint = &target->endpoint[id];
  1412. if (id >= ENDPOINT_MAX) {
  1413. ath6kl_err("MsgPend, invalid endpoint in look-ahead: %d\n",
  1414. id);
  1415. status = -ENOMEM;
  1416. break;
  1417. }
  1418. INIT_LIST_HEAD(&rx_pktq);
  1419. INIT_LIST_HEAD(&comp_pktq);
  1420. /*
  1421. * Try to allocate as many HTC RX packets indicated by the
  1422. * look_aheads.
  1423. */
  1424. status = alloc_and_prep_rxpkts(target, look_aheads,
  1425. num_look_ahead, endpoint,
  1426. &rx_pktq);
  1427. if (status)
  1428. break;
  1429. if (get_queue_depth(&rx_pktq) >= 2)
  1430. /*
  1431. * A recv bundle was detected, force IRQ status
  1432. * re-check again
  1433. */
  1434. target->chk_irq_status_cnt = 1;
  1435. n_fetched += get_queue_depth(&rx_pktq);
  1436. num_look_ahead = 0;
  1437. status = htc_fetch_rxpkts(target, &rx_pktq, &comp_pktq);
  1438. if (!status)
  1439. chk_rx_water_mark(endpoint);
  1440. /* Process fetched packets */
  1441. status = htc_proc_fetched_rxpkts(target, &comp_pktq,
  1442. look_aheads, &num_look_ahead);
  1443. if (!num_look_ahead || status)
  1444. break;
  1445. /*
  1446. * For SYNCH processing, if we get here, we are running
  1447. * through the loop again due to a detected lookahead. Set
  1448. * flag that we should re-check IRQ status registers again
  1449. * before leaving IRQ processing, this can net better
  1450. * performance in high throughput situations.
  1451. */
  1452. target->chk_irq_status_cnt = 1;
  1453. }
  1454. if (status) {
  1455. ath6kl_err("failed to get pending recv messages: %d\n",
  1456. status);
  1457. /*
  1458. * Cleanup any packets we allocated but didn't use to
  1459. * actually fetch any packets.
  1460. */
  1461. list_for_each_entry_safe(packets, tmp_pkt, &rx_pktq, list) {
  1462. list_del(&packets->list);
  1463. htc_reclaim_rxbuf(target, packets,
  1464. &target->endpoint[packets->endpoint]);
  1465. }
  1466. /* cleanup any packets in sync completion queue */
  1467. list_for_each_entry_safe(packets, tmp_pkt, &comp_pktq, list) {
  1468. list_del(&packets->list);
  1469. htc_reclaim_rxbuf(target, packets,
  1470. &target->endpoint[packets->endpoint]);
  1471. }
  1472. if (target->htc_flags & HTC_OP_STATE_STOPPING) {
  1473. ath6kl_warn("host is going to stop blocking receiver for htc_stop\n");
  1474. ath6kldev_rx_control(target->dev, false);
  1475. }
  1476. }
  1477. /*
  1478. * Before leaving, check to see if host ran out of buffers and
  1479. * needs to stop the receiver.
  1480. */
  1481. if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
  1482. ath6kl_warn("host has no rx buffers blocking receiver to prevent overrun\n");
  1483. ath6kldev_rx_control(target->dev, false);
  1484. }
  1485. *num_pkts = n_fetched;
  1486. return status;
  1487. }
  1488. /*
  1489. * Synchronously wait for a control message from the target,
  1490. * This function is used at initialization time ONLY. At init messages
  1491. * on ENDPOINT 0 are expected.
  1492. */
  1493. static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
  1494. {
  1495. struct htc_packet *packet = NULL;
  1496. struct htc_frame_hdr *htc_hdr;
  1497. u32 look_ahead;
  1498. if (ath6kldev_poll_mboxmsg_rx(target->dev, &look_ahead,
  1499. HTC_TARGET_RESPONSE_TIMEOUT))
  1500. return NULL;
  1501. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1502. "htc_wait_for_ctrl_msg: look_ahead : 0x%X\n", look_ahead);
  1503. htc_hdr = (struct htc_frame_hdr *)&look_ahead;
  1504. if (htc_hdr->eid != ENDPOINT_0)
  1505. return NULL;
  1506. packet = htc_get_control_buf(target, false);
  1507. if (!packet)
  1508. return NULL;
  1509. packet->info.rx.rx_flags = 0;
  1510. packet->info.rx.exp_hdr = look_ahead;
  1511. packet->act_len = le16_to_cpu(htc_hdr->payld_len) + HTC_HDR_LENGTH;
  1512. if (packet->act_len > packet->buf_len)
  1513. goto fail_ctrl_rx;
  1514. /* we want synchronous operation */
  1515. packet->completion = NULL;
  1516. /* get the message from the device, this will block */
  1517. if (dev_rx_pkt(target, packet, packet->act_len))
  1518. goto fail_ctrl_rx;
  1519. /* process receive header */
  1520. packet->status = htc_proc_rxhdr(target, packet, NULL, NULL);
  1521. if (packet->status) {
  1522. ath6kl_err("htc_wait_for_ctrl_msg, htc_proc_rxhdr failed (status = %d)\n",
  1523. packet->status);
  1524. goto fail_ctrl_rx;
  1525. }
  1526. return packet;
  1527. fail_ctrl_rx:
  1528. if (packet != NULL) {
  1529. htc_rxpkt_reset(packet);
  1530. reclaim_rx_ctrl_buf(target, packet);
  1531. }
  1532. return NULL;
  1533. }
  1534. int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
  1535. struct list_head *pkt_queue)
  1536. {
  1537. struct htc_endpoint *endpoint;
  1538. struct htc_packet *first_pkt;
  1539. bool rx_unblock = false;
  1540. int status = 0, depth;
  1541. if (list_empty(pkt_queue))
  1542. return -ENOMEM;
  1543. first_pkt = list_first_entry(pkt_queue, struct htc_packet, list);
  1544. if (first_pkt->endpoint >= ENDPOINT_MAX)
  1545. return status;
  1546. depth = get_queue_depth(pkt_queue);
  1547. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1548. "htc_add_rxbuf_multiple: ep id: %d, cnt:%d, len: %d\n",
  1549. first_pkt->endpoint, depth, first_pkt->buf_len);
  1550. endpoint = &target->endpoint[first_pkt->endpoint];
  1551. if (target->htc_flags & HTC_OP_STATE_STOPPING) {
  1552. struct htc_packet *packet, *tmp_pkt;
  1553. /* walk through queue and mark each one canceled */
  1554. list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
  1555. packet->status = -ECANCELED;
  1556. list_del(&packet->list);
  1557. do_rx_completion(endpoint, packet);
  1558. }
  1559. return status;
  1560. }
  1561. spin_lock_bh(&target->rx_lock);
  1562. list_splice_tail_init(pkt_queue, &endpoint->rx_bufq);
  1563. /* check if we are blocked waiting for a new buffer */
  1564. if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
  1565. if (target->ep_waiting == first_pkt->endpoint) {
  1566. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1567. "receiver was blocked on ep:%d, unblocking.\n",
  1568. target->ep_waiting);
  1569. target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
  1570. target->ep_waiting = ENDPOINT_MAX;
  1571. rx_unblock = true;
  1572. }
  1573. }
  1574. spin_unlock_bh(&target->rx_lock);
  1575. if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
  1576. /* TODO : implement a buffer threshold count? */
  1577. ath6kldev_rx_control(target->dev, true);
  1578. return status;
  1579. }
  1580. void ath6kl_htc_flush_rx_buf(struct htc_target *target)
  1581. {
  1582. struct htc_endpoint *endpoint;
  1583. struct htc_packet *packet, *tmp_pkt;
  1584. int i;
  1585. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  1586. endpoint = &target->endpoint[i];
  1587. if (!endpoint->svc_id)
  1588. /* not in use.. */
  1589. continue;
  1590. spin_lock_bh(&target->rx_lock);
  1591. list_for_each_entry_safe(packet, tmp_pkt,
  1592. &endpoint->rx_bufq, list) {
  1593. list_del(&packet->list);
  1594. spin_unlock_bh(&target->rx_lock);
  1595. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1596. "flushing rx pkt:0x%p, len:%d, ep:%d\n",
  1597. packet, packet->buf_len,
  1598. packet->endpoint);
  1599. dev_kfree_skb(packet->pkt_cntxt);
  1600. spin_lock_bh(&target->rx_lock);
  1601. }
  1602. spin_unlock_bh(&target->rx_lock);
  1603. }
  1604. }
  1605. int ath6kl_htc_conn_service(struct htc_target *target,
  1606. struct htc_service_connect_req *conn_req,
  1607. struct htc_service_connect_resp *conn_resp)
  1608. {
  1609. struct htc_packet *rx_pkt = NULL;
  1610. struct htc_packet *tx_pkt = NULL;
  1611. struct htc_conn_service_resp *resp_msg;
  1612. struct htc_conn_service_msg *conn_msg;
  1613. struct htc_endpoint *endpoint;
  1614. enum htc_endpoint_id assigned_ep = ENDPOINT_MAX;
  1615. unsigned int max_msg_sz = 0;
  1616. int status = 0;
  1617. ath6kl_dbg(ATH6KL_DBG_TRC,
  1618. "htc_conn_service, target:0x%p service id:0x%X\n",
  1619. target, conn_req->svc_id);
  1620. if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
  1621. /* special case for pseudo control service */
  1622. assigned_ep = ENDPOINT_0;
  1623. max_msg_sz = HTC_MAX_CTRL_MSG_LEN;
  1624. } else {
  1625. /* allocate a packet to send to the target */
  1626. tx_pkt = htc_get_control_buf(target, true);
  1627. if (!tx_pkt)
  1628. return -ENOMEM;
  1629. conn_msg = (struct htc_conn_service_msg *)tx_pkt->buf;
  1630. memset(conn_msg, 0, sizeof(*conn_msg));
  1631. conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
  1632. conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
  1633. conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags);
  1634. set_htc_pkt_info(tx_pkt, NULL, (u8 *) conn_msg,
  1635. sizeof(*conn_msg) + conn_msg->svc_meta_len,
  1636. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  1637. /* we want synchronous operation */
  1638. tx_pkt->completion = NULL;
  1639. htc_prep_send_pkt(tx_pkt, 0, 0, 0);
  1640. status = htc_issue_send(target, tx_pkt);
  1641. if (status)
  1642. goto fail_tx;
  1643. /* wait for response */
  1644. rx_pkt = htc_wait_for_ctrl_msg(target);
  1645. if (!rx_pkt) {
  1646. status = -ENOMEM;
  1647. goto fail_tx;
  1648. }
  1649. resp_msg = (struct htc_conn_service_resp *)rx_pkt->buf;
  1650. if ((le16_to_cpu(resp_msg->msg_id) != HTC_MSG_CONN_SVC_RESP_ID)
  1651. || (rx_pkt->act_len < sizeof(*resp_msg))) {
  1652. status = -ENOMEM;
  1653. goto fail_tx;
  1654. }
  1655. conn_resp->resp_code = resp_msg->status;
  1656. /* check response status */
  1657. if (resp_msg->status != HTC_SERVICE_SUCCESS) {
  1658. ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
  1659. resp_msg->svc_id, resp_msg->status);
  1660. status = -ENOMEM;
  1661. goto fail_tx;
  1662. }
  1663. assigned_ep = (enum htc_endpoint_id)resp_msg->eid;
  1664. max_msg_sz = le16_to_cpu(resp_msg->max_msg_sz);
  1665. }
  1666. if (assigned_ep >= ENDPOINT_MAX || !max_msg_sz) {
  1667. status = -ENOMEM;
  1668. goto fail_tx;
  1669. }
  1670. endpoint = &target->endpoint[assigned_ep];
  1671. endpoint->eid = assigned_ep;
  1672. if (endpoint->svc_id) {
  1673. status = -ENOMEM;
  1674. goto fail_tx;
  1675. }
  1676. /* return assigned endpoint to caller */
  1677. conn_resp->endpoint = assigned_ep;
  1678. conn_resp->len_max = max_msg_sz;
  1679. /* setup the endpoint */
  1680. /* this marks the endpoint in use */
  1681. endpoint->svc_id = conn_req->svc_id;
  1682. endpoint->max_txq_depth = conn_req->max_txq_depth;
  1683. endpoint->len_max = max_msg_sz;
  1684. endpoint->ep_cb = conn_req->ep_cb;
  1685. endpoint->cred_dist.svc_id = conn_req->svc_id;
  1686. endpoint->cred_dist.htc_rsvd = endpoint;
  1687. endpoint->cred_dist.endpoint = assigned_ep;
  1688. endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
  1689. if (conn_req->max_rxmsg_sz) {
  1690. /*
  1691. * Override cred_per_msg calculation, this optimizes
  1692. * the credit-low indications since the host will actually
  1693. * issue smaller messages in the Send path.
  1694. */
  1695. if (conn_req->max_rxmsg_sz > max_msg_sz) {
  1696. status = -ENOMEM;
  1697. goto fail_tx;
  1698. }
  1699. endpoint->cred_dist.cred_per_msg =
  1700. conn_req->max_rxmsg_sz / target->tgt_cred_sz;
  1701. } else
  1702. endpoint->cred_dist.cred_per_msg =
  1703. max_msg_sz / target->tgt_cred_sz;
  1704. if (!endpoint->cred_dist.cred_per_msg)
  1705. endpoint->cred_dist.cred_per_msg = 1;
  1706. /* save local connection flags */
  1707. endpoint->conn_flags = conn_req->flags;
  1708. fail_tx:
  1709. if (tx_pkt)
  1710. htc_reclaim_txctrl_buf(target, tx_pkt);
  1711. if (rx_pkt) {
  1712. htc_rxpkt_reset(rx_pkt);
  1713. reclaim_rx_ctrl_buf(target, rx_pkt);
  1714. }
  1715. return status;
  1716. }
  1717. static void reset_ep_state(struct htc_target *target)
  1718. {
  1719. struct htc_endpoint *endpoint;
  1720. int i;
  1721. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  1722. endpoint = &target->endpoint[i];
  1723. memset(&endpoint->cred_dist, 0, sizeof(endpoint->cred_dist));
  1724. endpoint->svc_id = 0;
  1725. endpoint->len_max = 0;
  1726. endpoint->max_txq_depth = 0;
  1727. memset(&endpoint->ep_st, 0,
  1728. sizeof(endpoint->ep_st));
  1729. INIT_LIST_HEAD(&endpoint->rx_bufq);
  1730. INIT_LIST_HEAD(&endpoint->txq);
  1731. endpoint->target = target;
  1732. }
  1733. /* reset distribution list */
  1734. INIT_LIST_HEAD(&target->cred_dist_list);
  1735. }
  1736. int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
  1737. enum htc_endpoint_id endpoint)
  1738. {
  1739. int num;
  1740. spin_lock_bh(&target->rx_lock);
  1741. num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
  1742. spin_unlock_bh(&target->rx_lock);
  1743. return num;
  1744. }
  1745. static void htc_setup_msg_bndl(struct htc_target *target)
  1746. {
  1747. /* limit what HTC can handle */
  1748. target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
  1749. target->msg_per_bndl_max);
  1750. if (ath6kl_hif_enable_scatter(target->dev->ar)) {
  1751. target->msg_per_bndl_max = 0;
  1752. return;
  1753. }
  1754. /* limit bundle what the device layer can handle */
  1755. target->msg_per_bndl_max = min(target->max_scat_entries,
  1756. target->msg_per_bndl_max);
  1757. ath6kl_dbg(ATH6KL_DBG_TRC,
  1758. "htc bundling allowed. max msg per htc bundle: %d\n",
  1759. target->msg_per_bndl_max);
  1760. /* Max rx bundle size is limited by the max tx bundle size */
  1761. target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
  1762. /* Max tx bundle size if limited by the extended mbox address range */
  1763. target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
  1764. target->max_xfer_szper_scatreq);
  1765. ath6kl_dbg(ATH6KL_DBG_ANY, "max recv: %d max send: %d\n",
  1766. target->max_rx_bndl_sz, target->max_tx_bndl_sz);
  1767. if (target->max_tx_bndl_sz)
  1768. target->tx_bndl_enable = true;
  1769. if (target->max_rx_bndl_sz)
  1770. target->rx_bndl_enable = true;
  1771. if ((target->tgt_cred_sz % target->block_sz) != 0) {
  1772. ath6kl_warn("credit size: %d is not block aligned! Disabling send bundling\n",
  1773. target->tgt_cred_sz);
  1774. /*
  1775. * Disallow send bundling since the credit size is
  1776. * not aligned to a block size the I/O block
  1777. * padding will spill into the next credit buffer
  1778. * which is fatal.
  1779. */
  1780. target->tx_bndl_enable = false;
  1781. }
  1782. }
  1783. int ath6kl_htc_wait_target(struct htc_target *target)
  1784. {
  1785. struct htc_packet *packet = NULL;
  1786. struct htc_ready_ext_msg *rdy_msg;
  1787. struct htc_service_connect_req connect;
  1788. struct htc_service_connect_resp resp;
  1789. int status;
  1790. /* we should be getting 1 control message that the target is ready */
  1791. packet = htc_wait_for_ctrl_msg(target);
  1792. if (!packet)
  1793. return -ENOMEM;
  1794. /* we controlled the buffer creation so it's properly aligned */
  1795. rdy_msg = (struct htc_ready_ext_msg *)packet->buf;
  1796. if ((le16_to_cpu(rdy_msg->ver2_0_info.msg_id) != HTC_MSG_READY_ID) ||
  1797. (packet->act_len < sizeof(struct htc_ready_msg))) {
  1798. status = -ENOMEM;
  1799. goto fail_wait_target;
  1800. }
  1801. if (!rdy_msg->ver2_0_info.cred_cnt || !rdy_msg->ver2_0_info.cred_sz) {
  1802. status = -ENOMEM;
  1803. goto fail_wait_target;
  1804. }
  1805. target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
  1806. target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
  1807. ath6kl_dbg(ATH6KL_DBG_HTC_RECV,
  1808. "target ready: credits: %d credit size: %d\n",
  1809. target->tgt_creds, target->tgt_cred_sz);
  1810. /* check if this is an extended ready message */
  1811. if (packet->act_len >= sizeof(struct htc_ready_ext_msg)) {
  1812. /* this is an extended message */
  1813. target->htc_tgt_ver = rdy_msg->htc_ver;
  1814. target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
  1815. } else {
  1816. /* legacy */
  1817. target->htc_tgt_ver = HTC_VERSION_2P0;
  1818. target->msg_per_bndl_max = 0;
  1819. }
  1820. ath6kl_dbg(ATH6KL_DBG_TRC, "using htc protocol version : %s (%d)\n",
  1821. (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
  1822. target->htc_tgt_ver);
  1823. if (target->msg_per_bndl_max > 0)
  1824. htc_setup_msg_bndl(target);
  1825. /* setup our pseudo HTC control endpoint connection */
  1826. memset(&connect, 0, sizeof(connect));
  1827. memset(&resp, 0, sizeof(resp));
  1828. connect.ep_cb.rx = htc_ctrl_rx;
  1829. connect.ep_cb.rx_refill = NULL;
  1830. connect.ep_cb.tx_full = NULL;
  1831. connect.max_txq_depth = NUM_CONTROL_BUFFERS;
  1832. connect.svc_id = HTC_CTRL_RSVD_SVC;
  1833. /* connect fake service */
  1834. status = ath6kl_htc_conn_service((void *)target, &connect, &resp);
  1835. if (status)
  1836. ath6kl_hif_cleanup_scatter(target->dev->ar);
  1837. fail_wait_target:
  1838. if (packet) {
  1839. htc_rxpkt_reset(packet);
  1840. reclaim_rx_ctrl_buf(target, packet);
  1841. }
  1842. return status;
  1843. }
  1844. /*
  1845. * Start HTC, enable interrupts and let the target know
  1846. * host has finished setup.
  1847. */
  1848. int ath6kl_htc_start(struct htc_target *target)
  1849. {
  1850. struct htc_packet *packet;
  1851. int status;
  1852. /* Disable interrupts at the chip level */
  1853. ath6kldev_disable_intrs(target->dev);
  1854. target->htc_flags = 0;
  1855. target->rx_st_flags = 0;
  1856. /* Push control receive buffers into htc control endpoint */
  1857. while ((packet = htc_get_control_buf(target, false)) != NULL) {
  1858. status = htc_add_rxbuf(target, packet);
  1859. if (status)
  1860. return status;
  1861. }
  1862. /* NOTE: the first entry in the distribution list is ENDPOINT_0 */
  1863. ath6k_credit_init(target->cred_dist_cntxt, &target->cred_dist_list,
  1864. target->tgt_creds);
  1865. dump_cred_dist_stats(target);
  1866. /* Indicate to the target of the setup completion */
  1867. status = htc_setup_tx_complete(target);
  1868. if (status)
  1869. return status;
  1870. /* unmask interrupts */
  1871. status = ath6kldev_unmask_intrs(target->dev);
  1872. if (status)
  1873. ath6kl_htc_stop(target);
  1874. return status;
  1875. }
  1876. /* htc_stop: stop interrupt reception, and flush all queued buffers */
  1877. void ath6kl_htc_stop(struct htc_target *target)
  1878. {
  1879. spin_lock_bh(&target->htc_lock);
  1880. target->htc_flags |= HTC_OP_STATE_STOPPING;
  1881. spin_unlock_bh(&target->htc_lock);
  1882. /*
  1883. * Masking interrupts is a synchronous operation, when this
  1884. * function returns all pending HIF I/O has completed, we can
  1885. * safely flush the queues.
  1886. */
  1887. ath6kldev_mask_intrs(target->dev);
  1888. ath6kl_htc_flush_txep_all(target);
  1889. ath6kl_htc_flush_rx_buf(target);
  1890. reset_ep_state(target);
  1891. }
  1892. void *ath6kl_htc_create(struct ath6kl *ar)
  1893. {
  1894. struct htc_target *target = NULL;
  1895. struct htc_packet *packet;
  1896. int status = 0, i = 0;
  1897. u32 block_size, ctrl_bufsz;
  1898. target = kzalloc(sizeof(*target), GFP_KERNEL);
  1899. if (!target) {
  1900. ath6kl_err("unable to allocate memory\n");
  1901. return NULL;
  1902. }
  1903. target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
  1904. if (!target->dev) {
  1905. ath6kl_err("unable to allocate memory\n");
  1906. status = -ENOMEM;
  1907. goto fail_create_htc;
  1908. }
  1909. spin_lock_init(&target->htc_lock);
  1910. spin_lock_init(&target->rx_lock);
  1911. spin_lock_init(&target->tx_lock);
  1912. INIT_LIST_HEAD(&target->free_ctrl_txbuf);
  1913. INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
  1914. INIT_LIST_HEAD(&target->cred_dist_list);
  1915. target->dev->ar = ar;
  1916. target->dev->htc_cnxt = target;
  1917. target->ep_waiting = ENDPOINT_MAX;
  1918. reset_ep_state(target);
  1919. status = ath6kldev_setup(target->dev);
  1920. if (status)
  1921. goto fail_create_htc;
  1922. block_size = ar->mbox_info.block_size;
  1923. ctrl_bufsz = (block_size > HTC_MAX_CTRL_MSG_LEN) ?
  1924. (block_size + HTC_HDR_LENGTH) :
  1925. (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH);
  1926. for (i = 0; i < NUM_CONTROL_BUFFERS; i++) {
  1927. packet = kzalloc(sizeof(*packet), GFP_KERNEL);
  1928. if (!packet)
  1929. break;
  1930. packet->buf_start = kzalloc(ctrl_bufsz, GFP_KERNEL);
  1931. if (!packet->buf_start) {
  1932. kfree(packet);
  1933. break;
  1934. }
  1935. packet->buf_len = ctrl_bufsz;
  1936. if (i < NUM_CONTROL_RX_BUFFERS) {
  1937. packet->act_len = 0;
  1938. packet->buf = packet->buf_start;
  1939. packet->endpoint = ENDPOINT_0;
  1940. list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
  1941. } else
  1942. list_add_tail(&packet->list, &target->free_ctrl_txbuf);
  1943. }
  1944. fail_create_htc:
  1945. if (i != NUM_CONTROL_BUFFERS || status) {
  1946. if (target) {
  1947. ath6kl_htc_cleanup(target);
  1948. target = NULL;
  1949. }
  1950. }
  1951. return target;
  1952. }
  1953. /* cleanup the HTC instance */
  1954. void ath6kl_htc_cleanup(struct htc_target *target)
  1955. {
  1956. struct htc_packet *packet, *tmp_packet;
  1957. ath6kl_hif_cleanup_scatter(target->dev->ar);
  1958. list_for_each_entry_safe(packet, tmp_packet,
  1959. &target->free_ctrl_txbuf, list) {
  1960. list_del(&packet->list);
  1961. kfree(packet->buf_start);
  1962. kfree(packet);
  1963. }
  1964. list_for_each_entry_safe(packet, tmp_packet,
  1965. &target->free_ctrl_rxbuf, list) {
  1966. list_del(&packet->list);
  1967. kfree(packet->buf_start);
  1968. kfree(packet);
  1969. }
  1970. kfree(target->dev);
  1971. kfree(target);
  1972. }