bna_txrx.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include "bna.h"
  19. #include "bfa_sm.h"
  20. #include "bfi.h"
  21. /**
  22. * IB
  23. */
  24. #define bna_ib_find_free_ibidx(_mask, _pos)\
  25. do {\
  26. (_pos) = 0;\
  27. while (((_pos) < (BFI_IBIDX_MAX_SEGSIZE)) &&\
  28. ((1 << (_pos)) & (_mask)))\
  29. (_pos)++;\
  30. } while (0)
  31. #define bna_ib_count_ibidx(_mask, _count)\
  32. do {\
  33. int pos = 0;\
  34. (_count) = 0;\
  35. while (pos < (BFI_IBIDX_MAX_SEGSIZE)) {\
  36. if ((1 << pos) & (_mask))\
  37. (_count) = pos + 1;\
  38. pos++;\
  39. } \
  40. } while (0)
  41. #define bna_ib_select_segpool(_count, _q_idx)\
  42. do {\
  43. int i;\
  44. (_q_idx) = -1;\
  45. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {\
  46. if ((_count <= ibidx_pool[i].pool_entry_size)) {\
  47. (_q_idx) = i;\
  48. break;\
  49. } \
  50. } \
  51. } while (0)
  52. struct bna_ibidx_pool {
  53. int pool_size;
  54. int pool_entry_size;
  55. };
  56. init_ibidx_pool(ibidx_pool);
  57. static struct bna_intr *
  58. bna_intr_get(struct bna_ib_mod *ib_mod, enum bna_intr_type intr_type,
  59. int vector)
  60. {
  61. struct bna_intr *intr;
  62. struct list_head *qe;
  63. list_for_each(qe, &ib_mod->intr_active_q) {
  64. intr = (struct bna_intr *)qe;
  65. if ((intr->intr_type == intr_type) &&
  66. (intr->vector == vector)) {
  67. intr->ref_count++;
  68. return intr;
  69. }
  70. }
  71. if (list_empty(&ib_mod->intr_free_q))
  72. return NULL;
  73. bfa_q_deq(&ib_mod->intr_free_q, &intr);
  74. bfa_q_qe_init(&intr->qe);
  75. intr->ref_count = 1;
  76. intr->intr_type = intr_type;
  77. intr->vector = vector;
  78. list_add_tail(&intr->qe, &ib_mod->intr_active_q);
  79. return intr;
  80. }
  81. static void
  82. bna_intr_put(struct bna_ib_mod *ib_mod,
  83. struct bna_intr *intr)
  84. {
  85. intr->ref_count--;
  86. if (intr->ref_count == 0) {
  87. intr->ib = NULL;
  88. list_del(&intr->qe);
  89. bfa_q_qe_init(&intr->qe);
  90. list_add_tail(&intr->qe, &ib_mod->intr_free_q);
  91. }
  92. }
  93. void
  94. bna_ib_mod_init(struct bna_ib_mod *ib_mod, struct bna *bna,
  95. struct bna_res_info *res_info)
  96. {
  97. int i;
  98. int j;
  99. int count;
  100. u8 offset;
  101. struct bna_doorbell_qset *qset;
  102. unsigned long off;
  103. ib_mod->bna = bna;
  104. ib_mod->ib = (struct bna_ib *)
  105. res_info[BNA_RES_MEM_T_IB_ARRAY].res_u.mem_info.mdl[0].kva;
  106. ib_mod->intr = (struct bna_intr *)
  107. res_info[BNA_RES_MEM_T_INTR_ARRAY].res_u.mem_info.mdl[0].kva;
  108. ib_mod->idx_seg = (struct bna_ibidx_seg *)
  109. res_info[BNA_RES_MEM_T_IDXSEG_ARRAY].res_u.mem_info.mdl[0].kva;
  110. INIT_LIST_HEAD(&ib_mod->ib_free_q);
  111. INIT_LIST_HEAD(&ib_mod->intr_free_q);
  112. INIT_LIST_HEAD(&ib_mod->intr_active_q);
  113. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++)
  114. INIT_LIST_HEAD(&ib_mod->ibidx_seg_pool[i]);
  115. for (i = 0; i < BFI_MAX_IB; i++) {
  116. ib_mod->ib[i].ib_id = i;
  117. ib_mod->ib[i].ib_seg_host_addr_kva =
  118. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].kva;
  119. ib_mod->ib[i].ib_seg_host_addr.lsb =
  120. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].dma.lsb;
  121. ib_mod->ib[i].ib_seg_host_addr.msb =
  122. res_info[BNA_RES_MEM_T_IBIDX].res_u.mem_info.mdl[i].dma.msb;
  123. qset = (struct bna_doorbell_qset *)0;
  124. off = (unsigned long)(&qset[i >> 1].ib0[(i & 0x1)
  125. * (0x20 >> 2)]);
  126. ib_mod->ib[i].door_bell.doorbell_addr = off +
  127. BNA_GET_DOORBELL_BASE_ADDR(bna->pcidev.pci_bar_kva);
  128. bfa_q_qe_init(&ib_mod->ib[i].qe);
  129. list_add_tail(&ib_mod->ib[i].qe, &ib_mod->ib_free_q);
  130. bfa_q_qe_init(&ib_mod->intr[i].qe);
  131. list_add_tail(&ib_mod->intr[i].qe, &ib_mod->intr_free_q);
  132. }
  133. count = 0;
  134. offset = 0;
  135. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {
  136. for (j = 0; j < ibidx_pool[i].pool_size; j++) {
  137. bfa_q_qe_init(&ib_mod->idx_seg[count]);
  138. ib_mod->idx_seg[count].ib_seg_size =
  139. ibidx_pool[i].pool_entry_size;
  140. ib_mod->idx_seg[count].ib_idx_tbl_offset = offset;
  141. list_add_tail(&ib_mod->idx_seg[count].qe,
  142. &ib_mod->ibidx_seg_pool[i]);
  143. count++;
  144. offset += ibidx_pool[i].pool_entry_size;
  145. }
  146. }
  147. }
  148. void
  149. bna_ib_mod_uninit(struct bna_ib_mod *ib_mod)
  150. {
  151. int i;
  152. int j;
  153. struct list_head *qe;
  154. i = 0;
  155. list_for_each(qe, &ib_mod->ib_free_q)
  156. i++;
  157. i = 0;
  158. list_for_each(qe, &ib_mod->intr_free_q)
  159. i++;
  160. for (i = 0; i < BFI_IBIDX_TOTAL_POOLS; i++) {
  161. j = 0;
  162. list_for_each(qe, &ib_mod->ibidx_seg_pool[i])
  163. j++;
  164. }
  165. ib_mod->bna = NULL;
  166. }
  167. static struct bna_ib *
  168. bna_ib_get(struct bna_ib_mod *ib_mod,
  169. enum bna_intr_type intr_type,
  170. int vector)
  171. {
  172. struct bna_ib *ib;
  173. struct bna_intr *intr;
  174. if (intr_type == BNA_INTR_T_INTX)
  175. vector = (1 << vector);
  176. intr = bna_intr_get(ib_mod, intr_type, vector);
  177. if (intr == NULL)
  178. return NULL;
  179. if (intr->ib) {
  180. if (intr->ib->ref_count == BFI_IBIDX_MAX_SEGSIZE) {
  181. bna_intr_put(ib_mod, intr);
  182. return NULL;
  183. }
  184. intr->ib->ref_count++;
  185. return intr->ib;
  186. }
  187. if (list_empty(&ib_mod->ib_free_q)) {
  188. bna_intr_put(ib_mod, intr);
  189. return NULL;
  190. }
  191. bfa_q_deq(&ib_mod->ib_free_q, &ib);
  192. bfa_q_qe_init(&ib->qe);
  193. ib->ref_count = 1;
  194. ib->start_count = 0;
  195. ib->idx_mask = 0;
  196. ib->intr = intr;
  197. ib->idx_seg = NULL;
  198. intr->ib = ib;
  199. ib->bna = ib_mod->bna;
  200. return ib;
  201. }
  202. static void
  203. bna_ib_put(struct bna_ib_mod *ib_mod, struct bna_ib *ib)
  204. {
  205. bna_intr_put(ib_mod, ib->intr);
  206. ib->ref_count--;
  207. if (ib->ref_count == 0) {
  208. ib->intr = NULL;
  209. ib->bna = NULL;
  210. list_add_tail(&ib->qe, &ib_mod->ib_free_q);
  211. }
  212. }
  213. /* Returns index offset - starting from 0 */
  214. static int
  215. bna_ib_reserve_idx(struct bna_ib *ib)
  216. {
  217. struct bna_ib_mod *ib_mod = &ib->bna->ib_mod;
  218. struct bna_ibidx_seg *idx_seg;
  219. int idx;
  220. int num_idx;
  221. int q_idx;
  222. /* Find the first free index position */
  223. bna_ib_find_free_ibidx(ib->idx_mask, idx);
  224. if (idx == BFI_IBIDX_MAX_SEGSIZE)
  225. return -1;
  226. /*
  227. * Calculate the total number of indexes held by this IB,
  228. * including the index newly reserved above.
  229. */
  230. bna_ib_count_ibidx((ib->idx_mask | (1 << idx)), num_idx);
  231. /* See if there is a free space in the index segment held by this IB */
  232. if (ib->idx_seg && (num_idx <= ib->idx_seg->ib_seg_size)) {
  233. ib->idx_mask |= (1 << idx);
  234. return idx;
  235. }
  236. if (ib->start_count)
  237. return -1;
  238. /* Allocate a new segment */
  239. bna_ib_select_segpool(num_idx, q_idx);
  240. while (1) {
  241. if (q_idx == BFI_IBIDX_TOTAL_POOLS)
  242. return -1;
  243. if (!list_empty(&ib_mod->ibidx_seg_pool[q_idx]))
  244. break;
  245. q_idx++;
  246. }
  247. bfa_q_deq(&ib_mod->ibidx_seg_pool[q_idx], &idx_seg);
  248. bfa_q_qe_init(&idx_seg->qe);
  249. /* Free the old segment */
  250. if (ib->idx_seg) {
  251. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, q_idx);
  252. list_add_tail(&ib->idx_seg->qe, &ib_mod->ibidx_seg_pool[q_idx]);
  253. }
  254. ib->idx_seg = idx_seg;
  255. ib->idx_mask |= (1 << idx);
  256. return idx;
  257. }
  258. static void
  259. bna_ib_release_idx(struct bna_ib *ib, int idx)
  260. {
  261. struct bna_ib_mod *ib_mod = &ib->bna->ib_mod;
  262. struct bna_ibidx_seg *idx_seg;
  263. int num_idx;
  264. int cur_q_idx;
  265. int new_q_idx;
  266. ib->idx_mask &= ~(1 << idx);
  267. if (ib->start_count)
  268. return;
  269. bna_ib_count_ibidx(ib->idx_mask, num_idx);
  270. /*
  271. * Free the segment, if there are no more indexes in the segment
  272. * held by this IB
  273. */
  274. if (!num_idx) {
  275. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, cur_q_idx);
  276. list_add_tail(&ib->idx_seg->qe,
  277. &ib_mod->ibidx_seg_pool[cur_q_idx]);
  278. ib->idx_seg = NULL;
  279. return;
  280. }
  281. /* See if we can move to a smaller segment */
  282. bna_ib_select_segpool(num_idx, new_q_idx);
  283. bna_ib_select_segpool(ib->idx_seg->ib_seg_size, cur_q_idx);
  284. while (new_q_idx < cur_q_idx) {
  285. if (!list_empty(&ib_mod->ibidx_seg_pool[new_q_idx]))
  286. break;
  287. new_q_idx++;
  288. }
  289. if (new_q_idx < cur_q_idx) {
  290. /* Select the new smaller segment */
  291. bfa_q_deq(&ib_mod->ibidx_seg_pool[new_q_idx], &idx_seg);
  292. bfa_q_qe_init(&idx_seg->qe);
  293. /* Free the old segment */
  294. list_add_tail(&ib->idx_seg->qe,
  295. &ib_mod->ibidx_seg_pool[cur_q_idx]);
  296. ib->idx_seg = idx_seg;
  297. }
  298. }
  299. static int
  300. bna_ib_config(struct bna_ib *ib, struct bna_ib_config *ib_config)
  301. {
  302. if (ib->start_count)
  303. return -1;
  304. ib->ib_config.coalescing_timeo = ib_config->coalescing_timeo;
  305. ib->ib_config.interpkt_timeo = ib_config->interpkt_timeo;
  306. ib->ib_config.interpkt_count = ib_config->interpkt_count;
  307. ib->ib_config.ctrl_flags = ib_config->ctrl_flags;
  308. ib->ib_config.ctrl_flags |= BFI_IB_CF_MASTER_ENABLE;
  309. if (ib->intr->intr_type == BNA_INTR_T_MSIX)
  310. ib->ib_config.ctrl_flags |= BFI_IB_CF_MSIX_MODE;
  311. return 0;
  312. }
  313. static void
  314. bna_ib_start(struct bna_ib *ib)
  315. {
  316. struct bna_ib_blk_mem ib_cfg;
  317. struct bna_ib_blk_mem *ib_mem;
  318. u32 pg_num;
  319. u32 intx_mask;
  320. int i;
  321. void __iomem *base_addr;
  322. unsigned long off;
  323. ib->start_count++;
  324. if (ib->start_count > 1)
  325. return;
  326. ib_cfg.host_addr_lo = (u32)(ib->ib_seg_host_addr.lsb);
  327. ib_cfg.host_addr_hi = (u32)(ib->ib_seg_host_addr.msb);
  328. ib_cfg.clsc_n_ctrl_n_msix = (((u32)
  329. ib->ib_config.coalescing_timeo << 16) |
  330. ((u32)ib->ib_config.ctrl_flags << 8) |
  331. (ib->intr->vector));
  332. ib_cfg.ipkt_n_ent_n_idxof =
  333. ((u32)
  334. (ib->ib_config.interpkt_timeo & 0xf) << 16) |
  335. ((u32)ib->idx_seg->ib_seg_size << 8) |
  336. (ib->idx_seg->ib_idx_tbl_offset);
  337. ib_cfg.ipkt_cnt_cfg_n_unacked = ((u32)
  338. ib->ib_config.interpkt_count << 24);
  339. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + ib->bna->port_num,
  340. HQM_IB_RAM_BASE_OFFSET);
  341. writel(pg_num, ib->bna->regs.page_addr);
  342. base_addr = BNA_GET_MEM_BASE_ADDR(ib->bna->pcidev.pci_bar_kva,
  343. HQM_IB_RAM_BASE_OFFSET);
  344. ib_mem = (struct bna_ib_blk_mem *)0;
  345. off = (unsigned long)&ib_mem[ib->ib_id].host_addr_lo;
  346. writel(htonl(ib_cfg.host_addr_lo), base_addr + off);
  347. off = (unsigned long)&ib_mem[ib->ib_id].host_addr_hi;
  348. writel(htonl(ib_cfg.host_addr_hi), base_addr + off);
  349. off = (unsigned long)&ib_mem[ib->ib_id].clsc_n_ctrl_n_msix;
  350. writel(ib_cfg.clsc_n_ctrl_n_msix, base_addr + off);
  351. off = (unsigned long)&ib_mem[ib->ib_id].ipkt_n_ent_n_idxof;
  352. writel(ib_cfg.ipkt_n_ent_n_idxof, base_addr + off);
  353. off = (unsigned long)&ib_mem[ib->ib_id].ipkt_cnt_cfg_n_unacked;
  354. writel(ib_cfg.ipkt_cnt_cfg_n_unacked, base_addr + off);
  355. ib->door_bell.doorbell_ack = BNA_DOORBELL_IB_INT_ACK(
  356. (u32)ib->ib_config.coalescing_timeo, 0);
  357. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + ib->bna->port_num,
  358. HQM_INDX_TBL_RAM_BASE_OFFSET);
  359. writel(pg_num, ib->bna->regs.page_addr);
  360. base_addr = BNA_GET_MEM_BASE_ADDR(ib->bna->pcidev.pci_bar_kva,
  361. HQM_INDX_TBL_RAM_BASE_OFFSET);
  362. for (i = 0; i < ib->idx_seg->ib_seg_size; i++) {
  363. off = (unsigned long)
  364. ((ib->idx_seg->ib_idx_tbl_offset + i) * BFI_IBIDX_SIZE);
  365. writel(0, base_addr + off);
  366. }
  367. if (ib->intr->intr_type == BNA_INTR_T_INTX) {
  368. bna_intx_disable(ib->bna, intx_mask);
  369. intx_mask &= ~(ib->intr->vector);
  370. bna_intx_enable(ib->bna, intx_mask);
  371. }
  372. }
  373. static void
  374. bna_ib_stop(struct bna_ib *ib)
  375. {
  376. u32 intx_mask;
  377. ib->start_count--;
  378. if (ib->start_count == 0) {
  379. writel(BNA_DOORBELL_IB_INT_DISABLE,
  380. ib->door_bell.doorbell_addr);
  381. if (ib->intr->intr_type == BNA_INTR_T_INTX) {
  382. bna_intx_disable(ib->bna, intx_mask);
  383. intx_mask |= (ib->intr->vector);
  384. bna_intx_enable(ib->bna, intx_mask);
  385. }
  386. }
  387. }
  388. static void
  389. bna_ib_fail(struct bna_ib *ib)
  390. {
  391. ib->start_count = 0;
  392. }
  393. /**
  394. * RXF
  395. */
  396. static void rxf_enable(struct bna_rxf *rxf);
  397. static void rxf_disable(struct bna_rxf *rxf);
  398. static void __rxf_config_set(struct bna_rxf *rxf);
  399. static void __rxf_rit_set(struct bna_rxf *rxf);
  400. static void __bna_rxf_stat_clr(struct bna_rxf *rxf);
  401. static int rxf_process_packet_filter(struct bna_rxf *rxf);
  402. static int rxf_clear_packet_filter(struct bna_rxf *rxf);
  403. static void rxf_reset_packet_filter(struct bna_rxf *rxf);
  404. static void rxf_cb_enabled(void *arg, int status);
  405. static void rxf_cb_disabled(void *arg, int status);
  406. static void bna_rxf_cb_stats_cleared(void *arg, int status);
  407. static void __rxf_enable(struct bna_rxf *rxf);
  408. static void __rxf_disable(struct bna_rxf *rxf);
  409. bfa_fsm_state_decl(bna_rxf, stopped, struct bna_rxf,
  410. enum bna_rxf_event);
  411. bfa_fsm_state_decl(bna_rxf, start_wait, struct bna_rxf,
  412. enum bna_rxf_event);
  413. bfa_fsm_state_decl(bna_rxf, cam_fltr_mod_wait, struct bna_rxf,
  414. enum bna_rxf_event);
  415. bfa_fsm_state_decl(bna_rxf, started, struct bna_rxf,
  416. enum bna_rxf_event);
  417. bfa_fsm_state_decl(bna_rxf, cam_fltr_clr_wait, struct bna_rxf,
  418. enum bna_rxf_event);
  419. bfa_fsm_state_decl(bna_rxf, stop_wait, struct bna_rxf,
  420. enum bna_rxf_event);
  421. bfa_fsm_state_decl(bna_rxf, pause_wait, struct bna_rxf,
  422. enum bna_rxf_event);
  423. bfa_fsm_state_decl(bna_rxf, resume_wait, struct bna_rxf,
  424. enum bna_rxf_event);
  425. bfa_fsm_state_decl(bna_rxf, stat_clr_wait, struct bna_rxf,
  426. enum bna_rxf_event);
  427. static struct bfa_sm_table rxf_sm_table[] = {
  428. {BFA_SM(bna_rxf_sm_stopped), BNA_RXF_STOPPED},
  429. {BFA_SM(bna_rxf_sm_start_wait), BNA_RXF_START_WAIT},
  430. {BFA_SM(bna_rxf_sm_cam_fltr_mod_wait), BNA_RXF_CAM_FLTR_MOD_WAIT},
  431. {BFA_SM(bna_rxf_sm_started), BNA_RXF_STARTED},
  432. {BFA_SM(bna_rxf_sm_cam_fltr_clr_wait), BNA_RXF_CAM_FLTR_CLR_WAIT},
  433. {BFA_SM(bna_rxf_sm_stop_wait), BNA_RXF_STOP_WAIT},
  434. {BFA_SM(bna_rxf_sm_pause_wait), BNA_RXF_PAUSE_WAIT},
  435. {BFA_SM(bna_rxf_sm_resume_wait), BNA_RXF_RESUME_WAIT},
  436. {BFA_SM(bna_rxf_sm_stat_clr_wait), BNA_RXF_STAT_CLR_WAIT}
  437. };
  438. static void
  439. bna_rxf_sm_stopped_entry(struct bna_rxf *rxf)
  440. {
  441. call_rxf_stop_cbfn(rxf, BNA_CB_SUCCESS);
  442. }
  443. static void
  444. bna_rxf_sm_stopped(struct bna_rxf *rxf, enum bna_rxf_event event)
  445. {
  446. switch (event) {
  447. case RXF_E_START:
  448. bfa_fsm_set_state(rxf, bna_rxf_sm_start_wait);
  449. break;
  450. case RXF_E_STOP:
  451. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  452. break;
  453. case RXF_E_FAIL:
  454. /* No-op */
  455. break;
  456. case RXF_E_CAM_FLTR_MOD:
  457. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  458. break;
  459. case RXF_E_STARTED:
  460. case RXF_E_STOPPED:
  461. case RXF_E_CAM_FLTR_RESP:
  462. /**
  463. * These events are received due to flushing of mbox
  464. * when device fails
  465. */
  466. /* No-op */
  467. break;
  468. case RXF_E_PAUSE:
  469. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  470. call_rxf_pause_cbfn(rxf, BNA_CB_SUCCESS);
  471. break;
  472. case RXF_E_RESUME:
  473. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  474. call_rxf_resume_cbfn(rxf, BNA_CB_SUCCESS);
  475. break;
  476. default:
  477. bfa_sm_fault(rxf->rx->bna, event);
  478. }
  479. }
  480. static void
  481. bna_rxf_sm_start_wait_entry(struct bna_rxf *rxf)
  482. {
  483. __rxf_config_set(rxf);
  484. __rxf_rit_set(rxf);
  485. rxf_enable(rxf);
  486. }
  487. static void
  488. bna_rxf_sm_start_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  489. {
  490. switch (event) {
  491. case RXF_E_STOP:
  492. /**
  493. * STOP is originated from bnad. When this happens,
  494. * it can not be waiting for filter update
  495. */
  496. call_rxf_start_cbfn(rxf, BNA_CB_INTERRUPT);
  497. bfa_fsm_set_state(rxf, bna_rxf_sm_stop_wait);
  498. break;
  499. case RXF_E_FAIL:
  500. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  501. call_rxf_start_cbfn(rxf, BNA_CB_FAIL);
  502. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  503. break;
  504. case RXF_E_CAM_FLTR_MOD:
  505. /* No-op */
  506. break;
  507. case RXF_E_STARTED:
  508. /**
  509. * Force rxf_process_filter() to go through initial
  510. * config
  511. */
  512. if ((rxf->ucast_active_mac != NULL) &&
  513. (rxf->ucast_pending_set == 0))
  514. rxf->ucast_pending_set = 1;
  515. if (rxf->rss_status == BNA_STATUS_T_ENABLED)
  516. rxf->rxf_flags |= BNA_RXF_FL_RSS_CONFIG_PENDING;
  517. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  518. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_mod_wait);
  519. break;
  520. case RXF_E_PAUSE:
  521. case RXF_E_RESUME:
  522. rxf->rxf_flags |= BNA_RXF_FL_OPERSTATE_CHANGED;
  523. break;
  524. default:
  525. bfa_sm_fault(rxf->rx->bna, event);
  526. }
  527. }
  528. static void
  529. bna_rxf_sm_cam_fltr_mod_wait_entry(struct bna_rxf *rxf)
  530. {
  531. if (!rxf_process_packet_filter(rxf)) {
  532. /* No more pending CAM entries to update */
  533. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  534. }
  535. }
  536. static void
  537. bna_rxf_sm_cam_fltr_mod_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  538. {
  539. switch (event) {
  540. case RXF_E_STOP:
  541. /**
  542. * STOP is originated from bnad. When this happens,
  543. * it can not be waiting for filter update
  544. */
  545. call_rxf_start_cbfn(rxf, BNA_CB_INTERRUPT);
  546. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_clr_wait);
  547. break;
  548. case RXF_E_FAIL:
  549. rxf_reset_packet_filter(rxf);
  550. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  551. call_rxf_start_cbfn(rxf, BNA_CB_FAIL);
  552. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  553. break;
  554. case RXF_E_CAM_FLTR_MOD:
  555. /* No-op */
  556. break;
  557. case RXF_E_CAM_FLTR_RESP:
  558. if (!rxf_process_packet_filter(rxf)) {
  559. /* No more pending CAM entries to update */
  560. call_rxf_cam_fltr_cbfn(rxf, BNA_CB_SUCCESS);
  561. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  562. }
  563. break;
  564. case RXF_E_PAUSE:
  565. case RXF_E_RESUME:
  566. rxf->rxf_flags |= BNA_RXF_FL_OPERSTATE_CHANGED;
  567. break;
  568. default:
  569. bfa_sm_fault(rxf->rx->bna, event);
  570. }
  571. }
  572. static void
  573. bna_rxf_sm_started_entry(struct bna_rxf *rxf)
  574. {
  575. call_rxf_start_cbfn(rxf, BNA_CB_SUCCESS);
  576. if (rxf->rxf_flags & BNA_RXF_FL_OPERSTATE_CHANGED) {
  577. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  578. bfa_fsm_send_event(rxf, RXF_E_PAUSE);
  579. else
  580. bfa_fsm_send_event(rxf, RXF_E_RESUME);
  581. }
  582. }
  583. static void
  584. bna_rxf_sm_started(struct bna_rxf *rxf, enum bna_rxf_event event)
  585. {
  586. switch (event) {
  587. case RXF_E_STOP:
  588. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_clr_wait);
  589. /* Hack to get FSM start clearing CAM entries */
  590. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_RESP);
  591. break;
  592. case RXF_E_FAIL:
  593. rxf_reset_packet_filter(rxf);
  594. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  595. break;
  596. case RXF_E_CAM_FLTR_MOD:
  597. bfa_fsm_set_state(rxf, bna_rxf_sm_cam_fltr_mod_wait);
  598. break;
  599. case RXF_E_PAUSE:
  600. bfa_fsm_set_state(rxf, bna_rxf_sm_pause_wait);
  601. break;
  602. case RXF_E_RESUME:
  603. bfa_fsm_set_state(rxf, bna_rxf_sm_resume_wait);
  604. break;
  605. default:
  606. bfa_sm_fault(rxf->rx->bna, event);
  607. }
  608. }
  609. static void
  610. bna_rxf_sm_cam_fltr_clr_wait_entry(struct bna_rxf *rxf)
  611. {
  612. /**
  613. * Note: Do not add rxf_clear_packet_filter here.
  614. * It will overstep mbox when this transition happens:
  615. * cam_fltr_mod_wait -> cam_fltr_clr_wait on RXF_E_STOP event
  616. */
  617. }
  618. static void
  619. bna_rxf_sm_cam_fltr_clr_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  620. {
  621. switch (event) {
  622. case RXF_E_FAIL:
  623. /**
  624. * FSM was in the process of stopping, initiated by
  625. * bnad. When this happens, no one can be waiting for
  626. * start or filter update
  627. */
  628. rxf_reset_packet_filter(rxf);
  629. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  630. break;
  631. case RXF_E_CAM_FLTR_RESP:
  632. if (!rxf_clear_packet_filter(rxf)) {
  633. /* No more pending CAM entries to clear */
  634. bfa_fsm_set_state(rxf, bna_rxf_sm_stop_wait);
  635. rxf_disable(rxf);
  636. }
  637. break;
  638. default:
  639. bfa_sm_fault(rxf->rx->bna, event);
  640. }
  641. }
  642. static void
  643. bna_rxf_sm_stop_wait_entry(struct bna_rxf *rxf)
  644. {
  645. /**
  646. * NOTE: Do not add rxf_disable here.
  647. * It will overstep mbox when this transition happens:
  648. * start_wait -> stop_wait on RXF_E_STOP event
  649. */
  650. }
  651. static void
  652. bna_rxf_sm_stop_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  653. {
  654. switch (event) {
  655. case RXF_E_FAIL:
  656. /**
  657. * FSM was in the process of stopping, initiated by
  658. * bnad. When this happens, no one can be waiting for
  659. * start or filter update
  660. */
  661. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  662. break;
  663. case RXF_E_STARTED:
  664. /**
  665. * This event is received due to abrupt transition from
  666. * bna_rxf_sm_start_wait state on receiving
  667. * RXF_E_STOP event
  668. */
  669. rxf_disable(rxf);
  670. break;
  671. case RXF_E_STOPPED:
  672. /**
  673. * FSM was in the process of stopping, initiated by
  674. * bnad. When this happens, no one can be waiting for
  675. * start or filter update
  676. */
  677. bfa_fsm_set_state(rxf, bna_rxf_sm_stat_clr_wait);
  678. break;
  679. case RXF_E_PAUSE:
  680. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  681. break;
  682. case RXF_E_RESUME:
  683. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  684. break;
  685. default:
  686. bfa_sm_fault(rxf->rx->bna, event);
  687. }
  688. }
  689. static void
  690. bna_rxf_sm_pause_wait_entry(struct bna_rxf *rxf)
  691. {
  692. rxf->rxf_flags &=
  693. ~(BNA_RXF_FL_OPERSTATE_CHANGED | BNA_RXF_FL_RXF_ENABLED);
  694. __rxf_disable(rxf);
  695. }
  696. static void
  697. bna_rxf_sm_pause_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  698. {
  699. switch (event) {
  700. case RXF_E_FAIL:
  701. /**
  702. * FSM was in the process of disabling rxf, initiated by
  703. * bnad.
  704. */
  705. call_rxf_pause_cbfn(rxf, BNA_CB_FAIL);
  706. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  707. break;
  708. case RXF_E_STOPPED:
  709. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_PAUSED;
  710. call_rxf_pause_cbfn(rxf, BNA_CB_SUCCESS);
  711. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  712. break;
  713. /*
  714. * Since PAUSE/RESUME can only be sent by bnad, we don't expect
  715. * any other event during these states
  716. */
  717. default:
  718. bfa_sm_fault(rxf->rx->bna, event);
  719. }
  720. }
  721. static void
  722. bna_rxf_sm_resume_wait_entry(struct bna_rxf *rxf)
  723. {
  724. rxf->rxf_flags &= ~(BNA_RXF_FL_OPERSTATE_CHANGED);
  725. rxf->rxf_flags |= BNA_RXF_FL_RXF_ENABLED;
  726. __rxf_enable(rxf);
  727. }
  728. static void
  729. bna_rxf_sm_resume_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  730. {
  731. switch (event) {
  732. case RXF_E_FAIL:
  733. /**
  734. * FSM was in the process of disabling rxf, initiated by
  735. * bnad.
  736. */
  737. call_rxf_resume_cbfn(rxf, BNA_CB_FAIL);
  738. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  739. break;
  740. case RXF_E_STARTED:
  741. rxf->rxf_oper_state = BNA_RXF_OPER_STATE_RUNNING;
  742. call_rxf_resume_cbfn(rxf, BNA_CB_SUCCESS);
  743. bfa_fsm_set_state(rxf, bna_rxf_sm_started);
  744. break;
  745. /*
  746. * Since PAUSE/RESUME can only be sent by bnad, we don't expect
  747. * any other event during these states
  748. */
  749. default:
  750. bfa_sm_fault(rxf->rx->bna, event);
  751. }
  752. }
  753. static void
  754. bna_rxf_sm_stat_clr_wait_entry(struct bna_rxf *rxf)
  755. {
  756. __bna_rxf_stat_clr(rxf);
  757. }
  758. static void
  759. bna_rxf_sm_stat_clr_wait(struct bna_rxf *rxf, enum bna_rxf_event event)
  760. {
  761. switch (event) {
  762. case RXF_E_FAIL:
  763. case RXF_E_STAT_CLEARED:
  764. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  765. break;
  766. default:
  767. bfa_sm_fault(rxf->rx->bna, event);
  768. }
  769. }
  770. static void
  771. __rxf_enable(struct bna_rxf *rxf)
  772. {
  773. struct bfi_ll_rxf_multi_req ll_req;
  774. u32 bm[2] = {0, 0};
  775. if (rxf->rxf_id < 32)
  776. bm[0] = 1 << rxf->rxf_id;
  777. else
  778. bm[1] = 1 << (rxf->rxf_id - 32);
  779. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RX_REQ, 0);
  780. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  781. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  782. ll_req.enable = 1;
  783. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  784. rxf_cb_enabled, rxf);
  785. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  786. }
  787. static void
  788. __rxf_disable(struct bna_rxf *rxf)
  789. {
  790. struct bfi_ll_rxf_multi_req ll_req;
  791. u32 bm[2] = {0, 0};
  792. if (rxf->rxf_id < 32)
  793. bm[0] = 1 << rxf->rxf_id;
  794. else
  795. bm[1] = 1 << (rxf->rxf_id - 32);
  796. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RX_REQ, 0);
  797. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  798. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  799. ll_req.enable = 0;
  800. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  801. rxf_cb_disabled, rxf);
  802. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  803. }
  804. static void
  805. __rxf_config_set(struct bna_rxf *rxf)
  806. {
  807. u32 i;
  808. struct bna_rss_mem *rss_mem;
  809. struct bna_rx_fndb_ram *rx_fndb_ram;
  810. struct bna *bna = rxf->rx->bna;
  811. void __iomem *base_addr;
  812. unsigned long off;
  813. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  814. RSS_TABLE_BASE_OFFSET);
  815. rss_mem = (struct bna_rss_mem *)0;
  816. /* Configure RSS if required */
  817. if (rxf->ctrl_flags & BNA_RXF_CF_RSS_ENABLE) {
  818. /* configure RSS Table */
  819. writel(BNA_GET_PAGE_NUM(RAD0_MEM_BLK_BASE_PG_NUM +
  820. bna->port_num, RSS_TABLE_BASE_OFFSET),
  821. bna->regs.page_addr);
  822. /* temporarily disable RSS, while hash value is written */
  823. off = (unsigned long)&rss_mem[0].type_n_hash;
  824. writel(0, base_addr + off);
  825. for (i = 0; i < BFI_RSS_HASH_KEY_LEN; i++) {
  826. off = (unsigned long)
  827. &rss_mem[0].hash_key[(BFI_RSS_HASH_KEY_LEN - 1) - i];
  828. writel(htonl(rxf->rss_cfg.toeplitz_hash_key[i]),
  829. base_addr + off);
  830. }
  831. off = (unsigned long)&rss_mem[0].type_n_hash;
  832. writel(rxf->rss_cfg.hash_type | rxf->rss_cfg.hash_mask,
  833. base_addr + off);
  834. }
  835. /* Configure RxF */
  836. writel(BNA_GET_PAGE_NUM(
  837. LUT0_MEM_BLK_BASE_PG_NUM + (bna->port_num * 2),
  838. RX_FNDB_RAM_BASE_OFFSET),
  839. bna->regs.page_addr);
  840. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  841. RX_FNDB_RAM_BASE_OFFSET);
  842. rx_fndb_ram = (struct bna_rx_fndb_ram *)0;
  843. /* We always use RSS table 0 */
  844. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].rss_prop;
  845. writel(rxf->ctrl_flags & BNA_RXF_CF_RSS_ENABLE,
  846. base_addr + off);
  847. /* small large buffer enable/disable */
  848. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].size_routing_props;
  849. writel((rxf->ctrl_flags & BNA_RXF_CF_SM_LG_RXQ) | 0x80,
  850. base_addr + off);
  851. /* RIT offset, HDS forced offset, multicast RxQ Id */
  852. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].rit_hds_mcastq;
  853. writel((rxf->rit_segment->rit_offset << 16) |
  854. (rxf->forced_offset << 8) |
  855. (rxf->hds_cfg.hdr_type & BNA_HDS_FORCED) | rxf->mcast_rxq_id,
  856. base_addr + off);
  857. /*
  858. * default vlan tag, default function enable, strip vlan bytes,
  859. * HDS type, header size
  860. */
  861. off = (unsigned long)&rx_fndb_ram[rxf->rxf_id].control_flags;
  862. writel(((u32)rxf->default_vlan_tag << 16) |
  863. (rxf->ctrl_flags &
  864. (BNA_RXF_CF_DEFAULT_VLAN |
  865. BNA_RXF_CF_DEFAULT_FUNCTION_ENABLE |
  866. BNA_RXF_CF_VLAN_STRIP)) |
  867. (rxf->hds_cfg.hdr_type & ~BNA_HDS_FORCED) |
  868. rxf->hds_cfg.header_size,
  869. base_addr + off);
  870. }
  871. void
  872. __rxf_vlan_filter_set(struct bna_rxf *rxf, enum bna_status status)
  873. {
  874. struct bna *bna = rxf->rx->bna;
  875. int i;
  876. writel(BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  877. (bna->port_num * 2), VLAN_RAM_BASE_OFFSET),
  878. bna->regs.page_addr);
  879. if (status == BNA_STATUS_T_ENABLED) {
  880. /* enable VLAN filtering on this function */
  881. for (i = 0; i <= BFI_MAX_VLAN / 32; i++) {
  882. writel(rxf->vlan_filter_table[i],
  883. BNA_GET_VLAN_MEM_ENTRY_ADDR
  884. (bna->pcidev.pci_bar_kva, rxf->rxf_id,
  885. i * 32));
  886. }
  887. } else {
  888. /* disable VLAN filtering on this function */
  889. for (i = 0; i <= BFI_MAX_VLAN / 32; i++) {
  890. writel(0xffffffff,
  891. BNA_GET_VLAN_MEM_ENTRY_ADDR
  892. (bna->pcidev.pci_bar_kva, rxf->rxf_id,
  893. i * 32));
  894. }
  895. }
  896. }
  897. static void
  898. __rxf_rit_set(struct bna_rxf *rxf)
  899. {
  900. struct bna *bna = rxf->rx->bna;
  901. struct bna_rit_mem *rit_mem;
  902. int i;
  903. void __iomem *base_addr;
  904. unsigned long off;
  905. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  906. FUNCTION_TO_RXQ_TRANSLATE);
  907. rit_mem = (struct bna_rit_mem *)0;
  908. writel(BNA_GET_PAGE_NUM(RXA0_MEM_BLK_BASE_PG_NUM + bna->port_num,
  909. FUNCTION_TO_RXQ_TRANSLATE),
  910. bna->regs.page_addr);
  911. for (i = 0; i < rxf->rit_segment->rit_size; i++) {
  912. off = (unsigned long)&rit_mem[i + rxf->rit_segment->rit_offset];
  913. writel(rxf->rit_segment->rit[i].large_rxq_id << 6 |
  914. rxf->rit_segment->rit[i].small_rxq_id,
  915. base_addr + off);
  916. }
  917. }
  918. static void
  919. __bna_rxf_stat_clr(struct bna_rxf *rxf)
  920. {
  921. struct bfi_ll_stats_req ll_req;
  922. u32 bm[2] = {0, 0};
  923. if (rxf->rxf_id < 32)
  924. bm[0] = 1 << rxf->rxf_id;
  925. else
  926. bm[1] = 1 << (rxf->rxf_id - 32);
  927. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_CLEAR_REQ, 0);
  928. ll_req.stats_mask = 0;
  929. ll_req.txf_id_mask[0] = 0;
  930. ll_req.txf_id_mask[1] = 0;
  931. ll_req.rxf_id_mask[0] = htonl(bm[0]);
  932. ll_req.rxf_id_mask[1] = htonl(bm[1]);
  933. bna_mbox_qe_fill(&rxf->mbox_qe, &ll_req, sizeof(ll_req),
  934. bna_rxf_cb_stats_cleared, rxf);
  935. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  936. }
  937. static void
  938. rxf_enable(struct bna_rxf *rxf)
  939. {
  940. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  941. bfa_fsm_send_event(rxf, RXF_E_STARTED);
  942. else {
  943. rxf->rxf_flags |= BNA_RXF_FL_RXF_ENABLED;
  944. __rxf_enable(rxf);
  945. }
  946. }
  947. static void
  948. rxf_cb_enabled(void *arg, int status)
  949. {
  950. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  951. bfa_q_qe_init(&rxf->mbox_qe.qe);
  952. bfa_fsm_send_event(rxf, RXF_E_STARTED);
  953. }
  954. static void
  955. rxf_disable(struct bna_rxf *rxf)
  956. {
  957. if (rxf->rxf_oper_state == BNA_RXF_OPER_STATE_PAUSED)
  958. bfa_fsm_send_event(rxf, RXF_E_STOPPED);
  959. else
  960. rxf->rxf_flags &= ~BNA_RXF_FL_RXF_ENABLED;
  961. __rxf_disable(rxf);
  962. }
  963. static void
  964. rxf_cb_disabled(void *arg, int status)
  965. {
  966. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  967. bfa_q_qe_init(&rxf->mbox_qe.qe);
  968. bfa_fsm_send_event(rxf, RXF_E_STOPPED);
  969. }
  970. void
  971. rxf_cb_cam_fltr_mbox_cmd(void *arg, int status)
  972. {
  973. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  974. bfa_q_qe_init(&rxf->mbox_qe.qe);
  975. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_RESP);
  976. }
  977. static void
  978. bna_rxf_cb_stats_cleared(void *arg, int status)
  979. {
  980. struct bna_rxf *rxf = (struct bna_rxf *)arg;
  981. bfa_q_qe_init(&rxf->mbox_qe.qe);
  982. bfa_fsm_send_event(rxf, RXF_E_STAT_CLEARED);
  983. }
  984. void
  985. rxf_cam_mbox_cmd(struct bna_rxf *rxf, u8 cmd,
  986. const struct bna_mac *mac_addr)
  987. {
  988. struct bfi_ll_mac_addr_req req;
  989. bfi_h2i_set(req.mh, BFI_MC_LL, cmd, 0);
  990. req.rxf_id = rxf->rxf_id;
  991. memcpy(&req.mac_addr, (void *)&mac_addr->addr, ETH_ALEN);
  992. bna_mbox_qe_fill(&rxf->mbox_qe, &req, sizeof(req),
  993. rxf_cb_cam_fltr_mbox_cmd, rxf);
  994. bna_mbox_send(rxf->rx->bna, &rxf->mbox_qe);
  995. }
  996. static int
  997. rxf_process_packet_filter_mcast(struct bna_rxf *rxf)
  998. {
  999. struct bna_mac *mac = NULL;
  1000. struct list_head *qe;
  1001. /* Add multicast entries */
  1002. if (!list_empty(&rxf->mcast_pending_add_q)) {
  1003. bfa_q_deq(&rxf->mcast_pending_add_q, &qe);
  1004. bfa_q_qe_init(qe);
  1005. mac = (struct bna_mac *)qe;
  1006. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_ADD_REQ, mac);
  1007. list_add_tail(&mac->qe, &rxf->mcast_active_q);
  1008. return 1;
  1009. }
  1010. /* Delete multicast entries previousely added */
  1011. if (!list_empty(&rxf->mcast_pending_del_q)) {
  1012. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1013. bfa_q_qe_init(qe);
  1014. mac = (struct bna_mac *)qe;
  1015. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1016. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1017. return 1;
  1018. }
  1019. return 0;
  1020. }
  1021. static int
  1022. rxf_process_packet_filter_vlan(struct bna_rxf *rxf)
  1023. {
  1024. /* Apply the VLAN filter */
  1025. if (rxf->rxf_flags & BNA_RXF_FL_VLAN_CONFIG_PENDING) {
  1026. rxf->rxf_flags &= ~BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1027. if (!(rxf->rxmode_active & BNA_RXMODE_PROMISC) &&
  1028. !(rxf->rxmode_active & BNA_RXMODE_DEFAULT))
  1029. __rxf_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1030. }
  1031. /* Apply RSS configuration */
  1032. if (rxf->rxf_flags & BNA_RXF_FL_RSS_CONFIG_PENDING) {
  1033. rxf->rxf_flags &= ~BNA_RXF_FL_RSS_CONFIG_PENDING;
  1034. if (rxf->rss_status == BNA_STATUS_T_DISABLED) {
  1035. /* RSS is being disabled */
  1036. rxf->ctrl_flags &= ~BNA_RXF_CF_RSS_ENABLE;
  1037. __rxf_rit_set(rxf);
  1038. __rxf_config_set(rxf);
  1039. } else {
  1040. /* RSS is being enabled or reconfigured */
  1041. rxf->ctrl_flags |= BNA_RXF_CF_RSS_ENABLE;
  1042. __rxf_rit_set(rxf);
  1043. __rxf_config_set(rxf);
  1044. }
  1045. }
  1046. return 0;
  1047. }
  1048. /**
  1049. * Processes pending ucast, mcast entry addition/deletion and issues mailbox
  1050. * command. Also processes pending filter configuration - promiscuous mode,
  1051. * default mode, allmutli mode and issues mailbox command or directly applies
  1052. * to h/w
  1053. */
  1054. static int
  1055. rxf_process_packet_filter(struct bna_rxf *rxf)
  1056. {
  1057. /* Set the default MAC first */
  1058. if (rxf->ucast_pending_set > 0) {
  1059. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_SET_REQ,
  1060. rxf->ucast_active_mac);
  1061. rxf->ucast_pending_set--;
  1062. return 1;
  1063. }
  1064. if (rxf_process_packet_filter_ucast(rxf))
  1065. return 1;
  1066. if (rxf_process_packet_filter_mcast(rxf))
  1067. return 1;
  1068. if (rxf_process_packet_filter_promisc(rxf))
  1069. return 1;
  1070. if (rxf_process_packet_filter_default(rxf))
  1071. return 1;
  1072. if (rxf_process_packet_filter_allmulti(rxf))
  1073. return 1;
  1074. if (rxf_process_packet_filter_vlan(rxf))
  1075. return 1;
  1076. return 0;
  1077. }
  1078. static int
  1079. rxf_clear_packet_filter_mcast(struct bna_rxf *rxf)
  1080. {
  1081. struct bna_mac *mac = NULL;
  1082. struct list_head *qe;
  1083. /* 3. delete pending mcast entries */
  1084. if (!list_empty(&rxf->mcast_pending_del_q)) {
  1085. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1086. bfa_q_qe_init(qe);
  1087. mac = (struct bna_mac *)qe;
  1088. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1089. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1090. return 1;
  1091. }
  1092. /* 4. clear active mcast entries; move them to pending_add_q */
  1093. if (!list_empty(&rxf->mcast_active_q)) {
  1094. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1095. bfa_q_qe_init(qe);
  1096. mac = (struct bna_mac *)qe;
  1097. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1098. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1099. return 1;
  1100. }
  1101. return 0;
  1102. }
  1103. /**
  1104. * In the rxf stop path, processes pending ucast/mcast delete queue and issues
  1105. * the mailbox command. Moves the active ucast/mcast entries to pending add q,
  1106. * so that they are added to CAM again in the rxf start path. Moves the current
  1107. * filter settings - promiscuous, default, allmutli - to pending filter
  1108. * configuration
  1109. */
  1110. static int
  1111. rxf_clear_packet_filter(struct bna_rxf *rxf)
  1112. {
  1113. if (rxf_clear_packet_filter_ucast(rxf))
  1114. return 1;
  1115. if (rxf_clear_packet_filter_mcast(rxf))
  1116. return 1;
  1117. /* 5. clear active default MAC in the CAM */
  1118. if (rxf->ucast_pending_set > 0)
  1119. rxf->ucast_pending_set = 0;
  1120. if (rxf_clear_packet_filter_promisc(rxf))
  1121. return 1;
  1122. if (rxf_clear_packet_filter_default(rxf))
  1123. return 1;
  1124. if (rxf_clear_packet_filter_allmulti(rxf))
  1125. return 1;
  1126. return 0;
  1127. }
  1128. static void
  1129. rxf_reset_packet_filter_mcast(struct bna_rxf *rxf)
  1130. {
  1131. struct list_head *qe;
  1132. struct bna_mac *mac;
  1133. /* 3. Move active mcast entries to pending_add_q */
  1134. while (!list_empty(&rxf->mcast_active_q)) {
  1135. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1136. bfa_q_qe_init(qe);
  1137. list_add_tail(qe, &rxf->mcast_pending_add_q);
  1138. }
  1139. /* 4. Throw away delete pending mcast entries */
  1140. while (!list_empty(&rxf->mcast_pending_del_q)) {
  1141. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1142. bfa_q_qe_init(qe);
  1143. mac = (struct bna_mac *)qe;
  1144. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1145. }
  1146. }
  1147. /**
  1148. * In the rxf fail path, throws away the ucast/mcast entries pending for
  1149. * deletion, moves all active ucast/mcast entries to pending queue so that
  1150. * they are added back to CAM in the rxf start path. Also moves the current
  1151. * filter configuration to pending filter configuration.
  1152. */
  1153. static void
  1154. rxf_reset_packet_filter(struct bna_rxf *rxf)
  1155. {
  1156. rxf_reset_packet_filter_ucast(rxf);
  1157. rxf_reset_packet_filter_mcast(rxf);
  1158. /* 5. Turn off ucast set flag */
  1159. rxf->ucast_pending_set = 0;
  1160. rxf_reset_packet_filter_promisc(rxf);
  1161. rxf_reset_packet_filter_default(rxf);
  1162. rxf_reset_packet_filter_allmulti(rxf);
  1163. }
  1164. static void
  1165. bna_rxf_init(struct bna_rxf *rxf,
  1166. struct bna_rx *rx,
  1167. struct bna_rx_config *q_config)
  1168. {
  1169. struct list_head *qe;
  1170. struct bna_rxp *rxp;
  1171. /* rxf_id is initialized during rx_mod init */
  1172. rxf->rx = rx;
  1173. INIT_LIST_HEAD(&rxf->ucast_pending_add_q);
  1174. INIT_LIST_HEAD(&rxf->ucast_pending_del_q);
  1175. rxf->ucast_pending_set = 0;
  1176. INIT_LIST_HEAD(&rxf->ucast_active_q);
  1177. rxf->ucast_active_mac = NULL;
  1178. INIT_LIST_HEAD(&rxf->mcast_pending_add_q);
  1179. INIT_LIST_HEAD(&rxf->mcast_pending_del_q);
  1180. INIT_LIST_HEAD(&rxf->mcast_active_q);
  1181. bfa_q_qe_init(&rxf->mbox_qe.qe);
  1182. if (q_config->vlan_strip_status == BNA_STATUS_T_ENABLED)
  1183. rxf->ctrl_flags |= BNA_RXF_CF_VLAN_STRIP;
  1184. rxf->rxf_oper_state = (q_config->paused) ?
  1185. BNA_RXF_OPER_STATE_PAUSED : BNA_RXF_OPER_STATE_RUNNING;
  1186. bna_rxf_adv_init(rxf, rx, q_config);
  1187. rxf->rit_segment = bna_rit_mod_seg_get(&rxf->rx->bna->rit_mod,
  1188. q_config->num_paths);
  1189. list_for_each(qe, &rx->rxp_q) {
  1190. rxp = (struct bna_rxp *)qe;
  1191. if (q_config->rxp_type == BNA_RXP_SINGLE)
  1192. rxf->mcast_rxq_id = rxp->rxq.single.only->rxq_id;
  1193. else
  1194. rxf->mcast_rxq_id = rxp->rxq.slr.large->rxq_id;
  1195. break;
  1196. }
  1197. rxf->vlan_filter_status = BNA_STATUS_T_DISABLED;
  1198. memset(rxf->vlan_filter_table, 0,
  1199. (sizeof(u32) * ((BFI_MAX_VLAN + 1) / 32)));
  1200. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  1201. }
  1202. static void
  1203. bna_rxf_uninit(struct bna_rxf *rxf)
  1204. {
  1205. struct bna_mac *mac;
  1206. bna_rit_mod_seg_put(&rxf->rx->bna->rit_mod, rxf->rit_segment);
  1207. rxf->rit_segment = NULL;
  1208. rxf->ucast_pending_set = 0;
  1209. while (!list_empty(&rxf->ucast_pending_add_q)) {
  1210. bfa_q_deq(&rxf->ucast_pending_add_q, &mac);
  1211. bfa_q_qe_init(&mac->qe);
  1212. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1213. }
  1214. if (rxf->ucast_active_mac) {
  1215. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1216. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod,
  1217. rxf->ucast_active_mac);
  1218. rxf->ucast_active_mac = NULL;
  1219. }
  1220. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1221. bfa_q_deq(&rxf->mcast_pending_add_q, &mac);
  1222. bfa_q_qe_init(&mac->qe);
  1223. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1224. }
  1225. rxf->rx = NULL;
  1226. }
  1227. static void
  1228. bna_rx_cb_rxf_started(struct bna_rx *rx, enum bna_cb_status status)
  1229. {
  1230. bfa_fsm_send_event(rx, RX_E_RXF_STARTED);
  1231. if (rx->rxf.rxf_id < 32)
  1232. rx->bna->rx_mod.rxf_bmap[0] |= ((u32)1 << rx->rxf.rxf_id);
  1233. else
  1234. rx->bna->rx_mod.rxf_bmap[1] |= ((u32)
  1235. 1 << (rx->rxf.rxf_id - 32));
  1236. }
  1237. static void
  1238. bna_rxf_start(struct bna_rxf *rxf)
  1239. {
  1240. rxf->start_cbfn = bna_rx_cb_rxf_started;
  1241. rxf->start_cbarg = rxf->rx;
  1242. rxf->rxf_flags &= ~BNA_RXF_FL_FAILED;
  1243. bfa_fsm_send_event(rxf, RXF_E_START);
  1244. }
  1245. static void
  1246. bna_rx_cb_rxf_stopped(struct bna_rx *rx, enum bna_cb_status status)
  1247. {
  1248. bfa_fsm_send_event(rx, RX_E_RXF_STOPPED);
  1249. if (rx->rxf.rxf_id < 32)
  1250. rx->bna->rx_mod.rxf_bmap[0] &= ~(u32)1 << rx->rxf.rxf_id;
  1251. else
  1252. rx->bna->rx_mod.rxf_bmap[1] &= ~(u32)
  1253. 1 << (rx->rxf.rxf_id - 32);
  1254. }
  1255. static void
  1256. bna_rxf_stop(struct bna_rxf *rxf)
  1257. {
  1258. rxf->stop_cbfn = bna_rx_cb_rxf_stopped;
  1259. rxf->stop_cbarg = rxf->rx;
  1260. bfa_fsm_send_event(rxf, RXF_E_STOP);
  1261. }
  1262. static void
  1263. bna_rxf_fail(struct bna_rxf *rxf)
  1264. {
  1265. rxf->rxf_flags |= BNA_RXF_FL_FAILED;
  1266. bfa_fsm_send_event(rxf, RXF_E_FAIL);
  1267. }
  1268. int
  1269. bna_rxf_state_get(struct bna_rxf *rxf)
  1270. {
  1271. return bfa_sm_to_state(rxf_sm_table, rxf->fsm);
  1272. }
  1273. enum bna_cb_status
  1274. bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
  1275. void (*cbfn)(struct bnad *, struct bna_rx *,
  1276. enum bna_cb_status))
  1277. {
  1278. struct bna_rxf *rxf = &rx->rxf;
  1279. if (rxf->ucast_active_mac == NULL) {
  1280. rxf->ucast_active_mac =
  1281. bna_ucam_mod_mac_get(&rxf->rx->bna->ucam_mod);
  1282. if (rxf->ucast_active_mac == NULL)
  1283. return BNA_CB_UCAST_CAM_FULL;
  1284. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1285. }
  1286. memcpy(rxf->ucast_active_mac->addr, ucmac, ETH_ALEN);
  1287. rxf->ucast_pending_set++;
  1288. rxf->cam_fltr_cbfn = cbfn;
  1289. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1290. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1291. return BNA_CB_SUCCESS;
  1292. }
  1293. enum bna_cb_status
  1294. bna_rx_mcast_add(struct bna_rx *rx, u8 *addr,
  1295. void (*cbfn)(struct bnad *, struct bna_rx *,
  1296. enum bna_cb_status))
  1297. {
  1298. struct bna_rxf *rxf = &rx->rxf;
  1299. struct list_head *qe;
  1300. struct bna_mac *mac;
  1301. /* Check if already added */
  1302. list_for_each(qe, &rxf->mcast_active_q) {
  1303. mac = (struct bna_mac *)qe;
  1304. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1305. if (cbfn)
  1306. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1307. return BNA_CB_SUCCESS;
  1308. }
  1309. }
  1310. /* Check if pending addition */
  1311. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1312. mac = (struct bna_mac *)qe;
  1313. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1314. if (cbfn)
  1315. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1316. return BNA_CB_SUCCESS;
  1317. }
  1318. }
  1319. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1320. if (mac == NULL)
  1321. return BNA_CB_MCAST_LIST_FULL;
  1322. bfa_q_qe_init(&mac->qe);
  1323. memcpy(mac->addr, addr, ETH_ALEN);
  1324. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1325. rxf->cam_fltr_cbfn = cbfn;
  1326. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1327. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1328. return BNA_CB_SUCCESS;
  1329. }
  1330. enum bna_cb_status
  1331. bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mclist,
  1332. void (*cbfn)(struct bnad *, struct bna_rx *,
  1333. enum bna_cb_status))
  1334. {
  1335. struct bna_rxf *rxf = &rx->rxf;
  1336. struct list_head list_head;
  1337. struct list_head *qe;
  1338. u8 *mcaddr;
  1339. struct bna_mac *mac;
  1340. struct bna_mac *mac1;
  1341. int skip;
  1342. int delete;
  1343. int need_hw_config = 0;
  1344. int i;
  1345. /* Allocate nodes */
  1346. INIT_LIST_HEAD(&list_head);
  1347. for (i = 0, mcaddr = mclist; i < count; i++) {
  1348. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1349. if (mac == NULL)
  1350. goto err_return;
  1351. bfa_q_qe_init(&mac->qe);
  1352. memcpy(mac->addr, mcaddr, ETH_ALEN);
  1353. list_add_tail(&mac->qe, &list_head);
  1354. mcaddr += ETH_ALEN;
  1355. }
  1356. /* Schedule for addition */
  1357. while (!list_empty(&list_head)) {
  1358. bfa_q_deq(&list_head, &qe);
  1359. mac = (struct bna_mac *)qe;
  1360. bfa_q_qe_init(&mac->qe);
  1361. skip = 0;
  1362. /* Skip if already added */
  1363. list_for_each(qe, &rxf->mcast_active_q) {
  1364. mac1 = (struct bna_mac *)qe;
  1365. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1366. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1367. mac);
  1368. skip = 1;
  1369. break;
  1370. }
  1371. }
  1372. if (skip)
  1373. continue;
  1374. /* Skip if pending addition */
  1375. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1376. mac1 = (struct bna_mac *)qe;
  1377. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1378. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1379. mac);
  1380. skip = 1;
  1381. break;
  1382. }
  1383. }
  1384. if (skip)
  1385. continue;
  1386. need_hw_config = 1;
  1387. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1388. }
  1389. /**
  1390. * Delete the entries that are in the pending_add_q but not
  1391. * in the new list
  1392. */
  1393. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1394. bfa_q_deq(&rxf->mcast_pending_add_q, &qe);
  1395. mac = (struct bna_mac *)qe;
  1396. bfa_q_qe_init(&mac->qe);
  1397. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1398. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1399. delete = 0;
  1400. break;
  1401. }
  1402. mcaddr += ETH_ALEN;
  1403. }
  1404. if (delete)
  1405. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1406. else
  1407. list_add_tail(&mac->qe, &list_head);
  1408. }
  1409. while (!list_empty(&list_head)) {
  1410. bfa_q_deq(&list_head, &qe);
  1411. mac = (struct bna_mac *)qe;
  1412. bfa_q_qe_init(&mac->qe);
  1413. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1414. }
  1415. /**
  1416. * Schedule entries for deletion that are in the active_q but not
  1417. * in the new list
  1418. */
  1419. while (!list_empty(&rxf->mcast_active_q)) {
  1420. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1421. mac = (struct bna_mac *)qe;
  1422. bfa_q_qe_init(&mac->qe);
  1423. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1424. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1425. delete = 0;
  1426. break;
  1427. }
  1428. mcaddr += ETH_ALEN;
  1429. }
  1430. if (delete) {
  1431. list_add_tail(&mac->qe, &rxf->mcast_pending_del_q);
  1432. need_hw_config = 1;
  1433. } else {
  1434. list_add_tail(&mac->qe, &list_head);
  1435. }
  1436. }
  1437. while (!list_empty(&list_head)) {
  1438. bfa_q_deq(&list_head, &qe);
  1439. mac = (struct bna_mac *)qe;
  1440. bfa_q_qe_init(&mac->qe);
  1441. list_add_tail(&mac->qe, &rxf->mcast_active_q);
  1442. }
  1443. if (need_hw_config) {
  1444. rxf->cam_fltr_cbfn = cbfn;
  1445. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1446. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1447. } else if (cbfn)
  1448. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1449. return BNA_CB_SUCCESS;
  1450. err_return:
  1451. while (!list_empty(&list_head)) {
  1452. bfa_q_deq(&list_head, &qe);
  1453. mac = (struct bna_mac *)qe;
  1454. bfa_q_qe_init(&mac->qe);
  1455. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1456. }
  1457. return BNA_CB_MCAST_LIST_FULL;
  1458. }
  1459. void
  1460. bna_rx_vlan_add(struct bna_rx *rx, int vlan_id)
  1461. {
  1462. struct bna_rxf *rxf = &rx->rxf;
  1463. int index = (vlan_id >> 5);
  1464. int bit = (1 << (vlan_id & 0x1F));
  1465. rxf->vlan_filter_table[index] |= bit;
  1466. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1467. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1468. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1469. }
  1470. }
  1471. void
  1472. bna_rx_vlan_del(struct bna_rx *rx, int vlan_id)
  1473. {
  1474. struct bna_rxf *rxf = &rx->rxf;
  1475. int index = (vlan_id >> 5);
  1476. int bit = (1 << (vlan_id & 0x1F));
  1477. rxf->vlan_filter_table[index] &= ~bit;
  1478. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1479. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1480. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1481. }
  1482. }
  1483. /**
  1484. * RX
  1485. */
  1486. #define RXQ_RCB_INIT(q, rxp, qdepth, bna, _id, unmapq_mem) do { \
  1487. struct bna_doorbell_qset *_qset; \
  1488. unsigned long off; \
  1489. (q)->rcb->producer_index = (q)->rcb->consumer_index = 0; \
  1490. (q)->rcb->q_depth = (qdepth); \
  1491. (q)->rcb->unmap_q = unmapq_mem; \
  1492. (q)->rcb->rxq = (q); \
  1493. (q)->rcb->cq = &(rxp)->cq; \
  1494. (q)->rcb->bnad = (bna)->bnad; \
  1495. _qset = (struct bna_doorbell_qset *)0; \
  1496. off = (unsigned long)&_qset[(q)->rxq_id].rxq[0]; \
  1497. (q)->rcb->q_dbell = off + \
  1498. BNA_GET_DOORBELL_BASE_ADDR((bna)->pcidev.pci_bar_kva); \
  1499. (q)->rcb->id = _id; \
  1500. } while (0)
  1501. #define BNA_GET_RXQS(qcfg) (((qcfg)->rxp_type == BNA_RXP_SINGLE) ? \
  1502. (qcfg)->num_paths : ((qcfg)->num_paths * 2))
  1503. #define SIZE_TO_PAGES(size) (((size) >> PAGE_SHIFT) + ((((size) &\
  1504. (PAGE_SIZE - 1)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  1505. #define call_rx_stop_callback(rx, status) \
  1506. if ((rx)->stop_cbfn) { \
  1507. (*(rx)->stop_cbfn)((rx)->stop_cbarg, rx, (status)); \
  1508. (rx)->stop_cbfn = NULL; \
  1509. (rx)->stop_cbarg = NULL; \
  1510. }
  1511. /*
  1512. * Since rx_enable is synchronous callback, there is no start_cbfn required.
  1513. * Instead, we'll call bnad_rx_post(rxp) so that bnad can post the buffers
  1514. * for each rxpath.
  1515. */
  1516. #define call_rx_disable_cbfn(rx, status) \
  1517. if ((rx)->disable_cbfn) { \
  1518. (*(rx)->disable_cbfn)((rx)->disable_cbarg, \
  1519. status); \
  1520. (rx)->disable_cbfn = NULL; \
  1521. (rx)->disable_cbarg = NULL; \
  1522. } \
  1523. #define rxqs_reqd(type, num_rxqs) \
  1524. (((type) == BNA_RXP_SINGLE) ? (num_rxqs) : ((num_rxqs) * 2))
  1525. #define rx_ib_fail(rx) \
  1526. do { \
  1527. struct bna_rxp *rxp; \
  1528. struct list_head *qe; \
  1529. list_for_each(qe, &(rx)->rxp_q) { \
  1530. rxp = (struct bna_rxp *)qe; \
  1531. bna_ib_fail(rxp->cq.ib); \
  1532. } \
  1533. } while (0)
  1534. static void __bna_multi_rxq_stop(struct bna_rxp *, u32 *);
  1535. static void __bna_rxq_start(struct bna_rxq *rxq);
  1536. static void __bna_cq_start(struct bna_cq *cq);
  1537. static void bna_rit_create(struct bna_rx *rx);
  1538. static void bna_rx_cb_multi_rxq_stopped(void *arg, int status);
  1539. static void bna_rx_cb_rxq_stopped_all(void *arg);
  1540. bfa_fsm_state_decl(bna_rx, stopped,
  1541. struct bna_rx, enum bna_rx_event);
  1542. bfa_fsm_state_decl(bna_rx, rxf_start_wait,
  1543. struct bna_rx, enum bna_rx_event);
  1544. bfa_fsm_state_decl(bna_rx, started,
  1545. struct bna_rx, enum bna_rx_event);
  1546. bfa_fsm_state_decl(bna_rx, rxf_stop_wait,
  1547. struct bna_rx, enum bna_rx_event);
  1548. bfa_fsm_state_decl(bna_rx, rxq_stop_wait,
  1549. struct bna_rx, enum bna_rx_event);
  1550. static const struct bfa_sm_table rx_sm_table[] = {
  1551. {BFA_SM(bna_rx_sm_stopped), BNA_RX_STOPPED},
  1552. {BFA_SM(bna_rx_sm_rxf_start_wait), BNA_RX_RXF_START_WAIT},
  1553. {BFA_SM(bna_rx_sm_started), BNA_RX_STARTED},
  1554. {BFA_SM(bna_rx_sm_rxf_stop_wait), BNA_RX_RXF_STOP_WAIT},
  1555. {BFA_SM(bna_rx_sm_rxq_stop_wait), BNA_RX_RXQ_STOP_WAIT},
  1556. };
  1557. static void bna_rx_sm_stopped_entry(struct bna_rx *rx)
  1558. {
  1559. struct bna_rxp *rxp;
  1560. struct list_head *qe_rxp;
  1561. list_for_each(qe_rxp, &rx->rxp_q) {
  1562. rxp = (struct bna_rxp *)qe_rxp;
  1563. rx->rx_cleanup_cbfn(rx->bna->bnad, rxp->cq.ccb);
  1564. }
  1565. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1566. }
  1567. static void bna_rx_sm_stopped(struct bna_rx *rx,
  1568. enum bna_rx_event event)
  1569. {
  1570. switch (event) {
  1571. case RX_E_START:
  1572. bfa_fsm_set_state(rx, bna_rx_sm_rxf_start_wait);
  1573. break;
  1574. case RX_E_STOP:
  1575. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1576. break;
  1577. case RX_E_FAIL:
  1578. /* no-op */
  1579. break;
  1580. default:
  1581. bfa_sm_fault(rx->bna, event);
  1582. break;
  1583. }
  1584. }
  1585. static void bna_rx_sm_rxf_start_wait_entry(struct bna_rx *rx)
  1586. {
  1587. struct bna_rxp *rxp;
  1588. struct list_head *qe_rxp;
  1589. struct bna_rxq *q0 = NULL, *q1 = NULL;
  1590. /* Setup the RIT */
  1591. bna_rit_create(rx);
  1592. list_for_each(qe_rxp, &rx->rxp_q) {
  1593. rxp = (struct bna_rxp *)qe_rxp;
  1594. bna_ib_start(rxp->cq.ib);
  1595. GET_RXQS(rxp, q0, q1);
  1596. q0->buffer_size = bna_port_mtu_get(&rx->bna->port);
  1597. __bna_rxq_start(q0);
  1598. rx->rx_post_cbfn(rx->bna->bnad, q0->rcb);
  1599. if (q1) {
  1600. __bna_rxq_start(q1);
  1601. rx->rx_post_cbfn(rx->bna->bnad, q1->rcb);
  1602. }
  1603. __bna_cq_start(&rxp->cq);
  1604. }
  1605. bna_rxf_start(&rx->rxf);
  1606. }
  1607. static void bna_rx_sm_rxf_start_wait(struct bna_rx *rx,
  1608. enum bna_rx_event event)
  1609. {
  1610. switch (event) {
  1611. case RX_E_STOP:
  1612. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1613. break;
  1614. case RX_E_FAIL:
  1615. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1616. rx_ib_fail(rx);
  1617. bna_rxf_fail(&rx->rxf);
  1618. break;
  1619. case RX_E_RXF_STARTED:
  1620. bfa_fsm_set_state(rx, bna_rx_sm_started);
  1621. break;
  1622. default:
  1623. bfa_sm_fault(rx->bna, event);
  1624. break;
  1625. }
  1626. }
  1627. void
  1628. bna_rx_sm_started_entry(struct bna_rx *rx)
  1629. {
  1630. struct bna_rxp *rxp;
  1631. struct list_head *qe_rxp;
  1632. /* Start IB */
  1633. list_for_each(qe_rxp, &rx->rxp_q) {
  1634. rxp = (struct bna_rxp *)qe_rxp;
  1635. bna_ib_ack(&rxp->cq.ib->door_bell, 0);
  1636. }
  1637. bna_llport_admin_up(&rx->bna->port.llport);
  1638. }
  1639. void
  1640. bna_rx_sm_started(struct bna_rx *rx, enum bna_rx_event event)
  1641. {
  1642. switch (event) {
  1643. case RX_E_FAIL:
  1644. bna_llport_admin_down(&rx->bna->port.llport);
  1645. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1646. rx_ib_fail(rx);
  1647. bna_rxf_fail(&rx->rxf);
  1648. break;
  1649. case RX_E_STOP:
  1650. bna_llport_admin_down(&rx->bna->port.llport);
  1651. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1652. break;
  1653. default:
  1654. bfa_sm_fault(rx->bna, event);
  1655. break;
  1656. }
  1657. }
  1658. void
  1659. bna_rx_sm_rxf_stop_wait_entry(struct bna_rx *rx)
  1660. {
  1661. bna_rxf_stop(&rx->rxf);
  1662. }
  1663. void
  1664. bna_rx_sm_rxf_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1665. {
  1666. switch (event) {
  1667. case RX_E_RXF_STOPPED:
  1668. bfa_fsm_set_state(rx, bna_rx_sm_rxq_stop_wait);
  1669. break;
  1670. case RX_E_RXF_STARTED:
  1671. /**
  1672. * RxF was in the process of starting up when
  1673. * RXF_E_STOP was issued. Ignore this event
  1674. */
  1675. break;
  1676. case RX_E_FAIL:
  1677. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1678. rx_ib_fail(rx);
  1679. bna_rxf_fail(&rx->rxf);
  1680. break;
  1681. default:
  1682. bfa_sm_fault(rx->bna, event);
  1683. break;
  1684. }
  1685. }
  1686. void
  1687. bna_rx_sm_rxq_stop_wait_entry(struct bna_rx *rx)
  1688. {
  1689. struct bna_rxp *rxp = NULL;
  1690. struct bna_rxq *q0 = NULL;
  1691. struct bna_rxq *q1 = NULL;
  1692. struct list_head *qe;
  1693. u32 rxq_mask[2] = {0, 0};
  1694. /* Only one call to multi-rxq-stop for all RXPs in this RX */
  1695. bfa_wc_up(&rx->rxq_stop_wc);
  1696. list_for_each(qe, &rx->rxp_q) {
  1697. rxp = (struct bna_rxp *)qe;
  1698. GET_RXQS(rxp, q0, q1);
  1699. if (q0->rxq_id < 32)
  1700. rxq_mask[0] |= ((u32)1 << q0->rxq_id);
  1701. else
  1702. rxq_mask[1] |= ((u32)1 << (q0->rxq_id - 32));
  1703. if (q1) {
  1704. if (q1->rxq_id < 32)
  1705. rxq_mask[0] |= ((u32)1 << q1->rxq_id);
  1706. else
  1707. rxq_mask[1] |= ((u32)
  1708. 1 << (q1->rxq_id - 32));
  1709. }
  1710. }
  1711. __bna_multi_rxq_stop(rxp, rxq_mask);
  1712. }
  1713. void
  1714. bna_rx_sm_rxq_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1715. {
  1716. struct bna_rxp *rxp = NULL;
  1717. struct list_head *qe;
  1718. switch (event) {
  1719. case RX_E_RXQ_STOPPED:
  1720. list_for_each(qe, &rx->rxp_q) {
  1721. rxp = (struct bna_rxp *)qe;
  1722. bna_ib_stop(rxp->cq.ib);
  1723. }
  1724. /* Fall through */
  1725. case RX_E_FAIL:
  1726. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1727. break;
  1728. default:
  1729. bfa_sm_fault(rx->bna, event);
  1730. break;
  1731. }
  1732. }
  1733. void
  1734. __bna_multi_rxq_stop(struct bna_rxp *rxp, u32 * rxq_id_mask)
  1735. {
  1736. struct bfi_ll_q_stop_req ll_req;
  1737. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RXQ_STOP_REQ, 0);
  1738. ll_req.q_id_mask[0] = htonl(rxq_id_mask[0]);
  1739. ll_req.q_id_mask[1] = htonl(rxq_id_mask[1]);
  1740. bna_mbox_qe_fill(&rxp->mbox_qe, &ll_req, sizeof(ll_req),
  1741. bna_rx_cb_multi_rxq_stopped, rxp);
  1742. bna_mbox_send(rxp->rx->bna, &rxp->mbox_qe);
  1743. }
  1744. void
  1745. __bna_rxq_start(struct bna_rxq *rxq)
  1746. {
  1747. struct bna_rxtx_q_mem *q_mem;
  1748. struct bna_rxq_mem rxq_cfg, *rxq_mem;
  1749. struct bna_dma_addr cur_q_addr;
  1750. /* struct bna_doorbell_qset *qset; */
  1751. struct bna_qpt *qpt;
  1752. u32 pg_num;
  1753. struct bna *bna = rxq->rx->bna;
  1754. void __iomem *base_addr;
  1755. unsigned long off;
  1756. qpt = &rxq->qpt;
  1757. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1758. rxq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1759. rxq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1760. rxq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1761. rxq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1762. rxq_cfg.pg_cnt_n_prd_ptr = ((u32)qpt->page_count << 16) | 0x0;
  1763. rxq_cfg.entry_n_pg_size = ((u32)(BFI_RXQ_WI_SIZE >> 2) << 16) |
  1764. (qpt->page_size >> 2);
  1765. rxq_cfg.sg_n_cq_n_cns_ptr =
  1766. ((u32)(rxq->rxp->cq.cq_id & 0xff) << 16) | 0x0;
  1767. rxq_cfg.buf_sz_n_q_state = ((u32)rxq->buffer_size << 16) |
  1768. BNA_Q_IDLE_STATE;
  1769. rxq_cfg.next_qid = 0x0 | (0x3 << 8);
  1770. /* Write the page number register */
  1771. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1772. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1773. writel(pg_num, bna->regs.page_addr);
  1774. /* Write to h/w */
  1775. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1776. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1777. q_mem = (struct bna_rxtx_q_mem *)0;
  1778. rxq_mem = &q_mem[rxq->rxq_id].rxq;
  1779. off = (unsigned long)&rxq_mem->pg_tbl_addr_lo;
  1780. writel(htonl(rxq_cfg.pg_tbl_addr_lo), base_addr + off);
  1781. off = (unsigned long)&rxq_mem->pg_tbl_addr_hi;
  1782. writel(htonl(rxq_cfg.pg_tbl_addr_hi), base_addr + off);
  1783. off = (unsigned long)&rxq_mem->cur_q_entry_lo;
  1784. writel(htonl(rxq_cfg.cur_q_entry_lo), base_addr + off);
  1785. off = (unsigned long)&rxq_mem->cur_q_entry_hi;
  1786. writel(htonl(rxq_cfg.cur_q_entry_hi), base_addr + off);
  1787. off = (unsigned long)&rxq_mem->pg_cnt_n_prd_ptr;
  1788. writel(rxq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1789. off = (unsigned long)&rxq_mem->entry_n_pg_size;
  1790. writel(rxq_cfg.entry_n_pg_size, base_addr + off);
  1791. off = (unsigned long)&rxq_mem->sg_n_cq_n_cns_ptr;
  1792. writel(rxq_cfg.sg_n_cq_n_cns_ptr, base_addr + off);
  1793. off = (unsigned long)&rxq_mem->buf_sz_n_q_state;
  1794. writel(rxq_cfg.buf_sz_n_q_state, base_addr + off);
  1795. off = (unsigned long)&rxq_mem->next_qid;
  1796. writel(rxq_cfg.next_qid, base_addr + off);
  1797. rxq->rcb->producer_index = 0;
  1798. rxq->rcb->consumer_index = 0;
  1799. }
  1800. void
  1801. __bna_cq_start(struct bna_cq *cq)
  1802. {
  1803. struct bna_cq_mem cq_cfg, *cq_mem;
  1804. const struct bna_qpt *qpt;
  1805. struct bna_dma_addr cur_q_addr;
  1806. u32 pg_num;
  1807. struct bna *bna = cq->rx->bna;
  1808. void __iomem *base_addr;
  1809. unsigned long off;
  1810. qpt = &cq->qpt;
  1811. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1812. /*
  1813. * Fill out structure, to be subsequently written
  1814. * to hardware
  1815. */
  1816. cq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1817. cq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1818. cq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1819. cq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1820. cq_cfg.pg_cnt_n_prd_ptr = (qpt->page_count << 16) | 0x0;
  1821. cq_cfg.entry_n_pg_size =
  1822. ((u32)(BFI_CQ_WI_SIZE >> 2) << 16) | (qpt->page_size >> 2);
  1823. cq_cfg.int_blk_n_cns_ptr = ((((u32)cq->ib_seg_offset) << 24) |
  1824. ((u32)(cq->ib->ib_id & 0xff) << 16) | 0x0);
  1825. cq_cfg.q_state = BNA_Q_IDLE_STATE;
  1826. /* Write the page number register */
  1827. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1828. HQM_CQ_RAM_BASE_OFFSET);
  1829. writel(pg_num, bna->regs.page_addr);
  1830. /* H/W write */
  1831. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1832. HQM_CQ_RAM_BASE_OFFSET);
  1833. cq_mem = (struct bna_cq_mem *)0;
  1834. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_lo;
  1835. writel(htonl(cq_cfg.pg_tbl_addr_lo), base_addr + off);
  1836. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_hi;
  1837. writel(htonl(cq_cfg.pg_tbl_addr_hi), base_addr + off);
  1838. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_lo;
  1839. writel(htonl(cq_cfg.cur_q_entry_lo), base_addr + off);
  1840. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_hi;
  1841. writel(htonl(cq_cfg.cur_q_entry_hi), base_addr + off);
  1842. off = (unsigned long)&cq_mem[cq->cq_id].pg_cnt_n_prd_ptr;
  1843. writel(cq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1844. off = (unsigned long)&cq_mem[cq->cq_id].entry_n_pg_size;
  1845. writel(cq_cfg.entry_n_pg_size, base_addr + off);
  1846. off = (unsigned long)&cq_mem[cq->cq_id].int_blk_n_cns_ptr;
  1847. writel(cq_cfg.int_blk_n_cns_ptr, base_addr + off);
  1848. off = (unsigned long)&cq_mem[cq->cq_id].q_state;
  1849. writel(cq_cfg.q_state, base_addr + off);
  1850. cq->ccb->producer_index = 0;
  1851. *(cq->ccb->hw_producer_index) = 0;
  1852. }
  1853. void
  1854. bna_rit_create(struct bna_rx *rx)
  1855. {
  1856. struct list_head *qe_rxp;
  1857. struct bna *bna;
  1858. struct bna_rxp *rxp;
  1859. struct bna_rxq *q0 = NULL;
  1860. struct bna_rxq *q1 = NULL;
  1861. int offset;
  1862. bna = rx->bna;
  1863. offset = 0;
  1864. list_for_each(qe_rxp, &rx->rxp_q) {
  1865. rxp = (struct bna_rxp *)qe_rxp;
  1866. GET_RXQS(rxp, q0, q1);
  1867. rx->rxf.rit_segment->rit[offset].large_rxq_id = q0->rxq_id;
  1868. rx->rxf.rit_segment->rit[offset].small_rxq_id =
  1869. (q1 ? q1->rxq_id : 0);
  1870. offset++;
  1871. }
  1872. }
  1873. static int
  1874. _rx_can_satisfy(struct bna_rx_mod *rx_mod,
  1875. struct bna_rx_config *rx_cfg)
  1876. {
  1877. if ((rx_mod->rx_free_count == 0) ||
  1878. (rx_mod->rxp_free_count == 0) ||
  1879. (rx_mod->rxq_free_count == 0))
  1880. return 0;
  1881. if (rx_cfg->rxp_type == BNA_RXP_SINGLE) {
  1882. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1883. (rx_mod->rxq_free_count < rx_cfg->num_paths))
  1884. return 0;
  1885. } else {
  1886. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1887. (rx_mod->rxq_free_count < (2 * rx_cfg->num_paths)))
  1888. return 0;
  1889. }
  1890. if (!bna_rit_mod_can_satisfy(&rx_mod->bna->rit_mod, rx_cfg->num_paths))
  1891. return 0;
  1892. return 1;
  1893. }
  1894. static struct bna_rxq *
  1895. _get_free_rxq(struct bna_rx_mod *rx_mod)
  1896. {
  1897. struct bna_rxq *rxq = NULL;
  1898. struct list_head *qe = NULL;
  1899. bfa_q_deq(&rx_mod->rxq_free_q, &qe);
  1900. if (qe) {
  1901. rx_mod->rxq_free_count--;
  1902. rxq = (struct bna_rxq *)qe;
  1903. }
  1904. return rxq;
  1905. }
  1906. static void
  1907. _put_free_rxq(struct bna_rx_mod *rx_mod, struct bna_rxq *rxq)
  1908. {
  1909. bfa_q_qe_init(&rxq->qe);
  1910. list_add_tail(&rxq->qe, &rx_mod->rxq_free_q);
  1911. rx_mod->rxq_free_count++;
  1912. }
  1913. static struct bna_rxp *
  1914. _get_free_rxp(struct bna_rx_mod *rx_mod)
  1915. {
  1916. struct list_head *qe = NULL;
  1917. struct bna_rxp *rxp = NULL;
  1918. bfa_q_deq(&rx_mod->rxp_free_q, &qe);
  1919. if (qe) {
  1920. rx_mod->rxp_free_count--;
  1921. rxp = (struct bna_rxp *)qe;
  1922. }
  1923. return rxp;
  1924. }
  1925. static void
  1926. _put_free_rxp(struct bna_rx_mod *rx_mod, struct bna_rxp *rxp)
  1927. {
  1928. bfa_q_qe_init(&rxp->qe);
  1929. list_add_tail(&rxp->qe, &rx_mod->rxp_free_q);
  1930. rx_mod->rxp_free_count++;
  1931. }
  1932. static struct bna_rx *
  1933. _get_free_rx(struct bna_rx_mod *rx_mod)
  1934. {
  1935. struct list_head *qe = NULL;
  1936. struct bna_rx *rx = NULL;
  1937. bfa_q_deq(&rx_mod->rx_free_q, &qe);
  1938. if (qe) {
  1939. rx_mod->rx_free_count--;
  1940. rx = (struct bna_rx *)qe;
  1941. bfa_q_qe_init(qe);
  1942. list_add_tail(&rx->qe, &rx_mod->rx_active_q);
  1943. }
  1944. return rx;
  1945. }
  1946. static void
  1947. _put_free_rx(struct bna_rx_mod *rx_mod, struct bna_rx *rx)
  1948. {
  1949. bfa_q_qe_init(&rx->qe);
  1950. list_add_tail(&rx->qe, &rx_mod->rx_free_q);
  1951. rx_mod->rx_free_count++;
  1952. }
  1953. static void
  1954. _rx_init(struct bna_rx *rx, struct bna *bna)
  1955. {
  1956. rx->bna = bna;
  1957. rx->rx_flags = 0;
  1958. INIT_LIST_HEAD(&rx->rxp_q);
  1959. rx->rxq_stop_wc.wc_resume = bna_rx_cb_rxq_stopped_all;
  1960. rx->rxq_stop_wc.wc_cbarg = rx;
  1961. rx->rxq_stop_wc.wc_count = 0;
  1962. rx->stop_cbfn = NULL;
  1963. rx->stop_cbarg = NULL;
  1964. }
  1965. static void
  1966. _rxp_add_rxqs(struct bna_rxp *rxp,
  1967. struct bna_rxq *q0,
  1968. struct bna_rxq *q1)
  1969. {
  1970. switch (rxp->type) {
  1971. case BNA_RXP_SINGLE:
  1972. rxp->rxq.single.only = q0;
  1973. rxp->rxq.single.reserved = NULL;
  1974. break;
  1975. case BNA_RXP_SLR:
  1976. rxp->rxq.slr.large = q0;
  1977. rxp->rxq.slr.small = q1;
  1978. break;
  1979. case BNA_RXP_HDS:
  1980. rxp->rxq.hds.data = q0;
  1981. rxp->rxq.hds.hdr = q1;
  1982. break;
  1983. default:
  1984. break;
  1985. }
  1986. }
  1987. static void
  1988. _rxq_qpt_init(struct bna_rxq *rxq,
  1989. struct bna_rxp *rxp,
  1990. u32 page_count,
  1991. u32 page_size,
  1992. struct bna_mem_descr *qpt_mem,
  1993. struct bna_mem_descr *swqpt_mem,
  1994. struct bna_mem_descr *page_mem)
  1995. {
  1996. int i;
  1997. rxq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  1998. rxq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  1999. rxq->qpt.kv_qpt_ptr = qpt_mem->kva;
  2000. rxq->qpt.page_count = page_count;
  2001. rxq->qpt.page_size = page_size;
  2002. rxq->rcb->sw_qpt = (void **) swqpt_mem->kva;
  2003. for (i = 0; i < rxq->qpt.page_count; i++) {
  2004. rxq->rcb->sw_qpt[i] = page_mem[i].kva;
  2005. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].lsb =
  2006. page_mem[i].dma.lsb;
  2007. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].msb =
  2008. page_mem[i].dma.msb;
  2009. }
  2010. }
  2011. static void
  2012. _rxp_cqpt_setup(struct bna_rxp *rxp,
  2013. u32 page_count,
  2014. u32 page_size,
  2015. struct bna_mem_descr *qpt_mem,
  2016. struct bna_mem_descr *swqpt_mem,
  2017. struct bna_mem_descr *page_mem)
  2018. {
  2019. int i;
  2020. rxp->cq.qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  2021. rxp->cq.qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  2022. rxp->cq.qpt.kv_qpt_ptr = qpt_mem->kva;
  2023. rxp->cq.qpt.page_count = page_count;
  2024. rxp->cq.qpt.page_size = page_size;
  2025. rxp->cq.ccb->sw_qpt = (void **) swqpt_mem->kva;
  2026. for (i = 0; i < rxp->cq.qpt.page_count; i++) {
  2027. rxp->cq.ccb->sw_qpt[i] = page_mem[i].kva;
  2028. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].lsb =
  2029. page_mem[i].dma.lsb;
  2030. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].msb =
  2031. page_mem[i].dma.msb;
  2032. }
  2033. }
  2034. static void
  2035. _rx_add_rxp(struct bna_rx *rx, struct bna_rxp *rxp)
  2036. {
  2037. list_add_tail(&rxp->qe, &rx->rxp_q);
  2038. }
  2039. static void
  2040. _init_rxmod_queues(struct bna_rx_mod *rx_mod)
  2041. {
  2042. INIT_LIST_HEAD(&rx_mod->rx_free_q);
  2043. INIT_LIST_HEAD(&rx_mod->rxq_free_q);
  2044. INIT_LIST_HEAD(&rx_mod->rxp_free_q);
  2045. INIT_LIST_HEAD(&rx_mod->rx_active_q);
  2046. rx_mod->rx_free_count = 0;
  2047. rx_mod->rxq_free_count = 0;
  2048. rx_mod->rxp_free_count = 0;
  2049. }
  2050. static void
  2051. _rx_ctor(struct bna_rx *rx, int id)
  2052. {
  2053. bfa_q_qe_init(&rx->qe);
  2054. INIT_LIST_HEAD(&rx->rxp_q);
  2055. rx->bna = NULL;
  2056. rx->rxf.rxf_id = id;
  2057. /* FIXME: mbox_qe ctor()?? */
  2058. bfa_q_qe_init(&rx->mbox_qe.qe);
  2059. rx->stop_cbfn = NULL;
  2060. rx->stop_cbarg = NULL;
  2061. }
  2062. void
  2063. bna_rx_cb_multi_rxq_stopped(void *arg, int status)
  2064. {
  2065. struct bna_rxp *rxp = (struct bna_rxp *)arg;
  2066. bfa_wc_down(&rxp->rx->rxq_stop_wc);
  2067. }
  2068. void
  2069. bna_rx_cb_rxq_stopped_all(void *arg)
  2070. {
  2071. struct bna_rx *rx = (struct bna_rx *)arg;
  2072. bfa_fsm_send_event(rx, RX_E_RXQ_STOPPED);
  2073. }
  2074. static void
  2075. bna_rx_mod_cb_rx_stopped(void *arg, struct bna_rx *rx,
  2076. enum bna_cb_status status)
  2077. {
  2078. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2079. bfa_wc_down(&rx_mod->rx_stop_wc);
  2080. }
  2081. static void
  2082. bna_rx_mod_cb_rx_stopped_all(void *arg)
  2083. {
  2084. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2085. if (rx_mod->stop_cbfn)
  2086. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2087. rx_mod->stop_cbfn = NULL;
  2088. }
  2089. static void
  2090. bna_rx_start(struct bna_rx *rx)
  2091. {
  2092. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2093. if (rx->rx_flags & BNA_RX_F_ENABLE)
  2094. bfa_fsm_send_event(rx, RX_E_START);
  2095. }
  2096. static void
  2097. bna_rx_stop(struct bna_rx *rx)
  2098. {
  2099. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2100. if (rx->fsm == (bfa_fsm_t) bna_rx_sm_stopped)
  2101. bna_rx_mod_cb_rx_stopped(&rx->bna->rx_mod, rx, BNA_CB_SUCCESS);
  2102. else {
  2103. rx->stop_cbfn = bna_rx_mod_cb_rx_stopped;
  2104. rx->stop_cbarg = &rx->bna->rx_mod;
  2105. bfa_fsm_send_event(rx, RX_E_STOP);
  2106. }
  2107. }
  2108. static void
  2109. bna_rx_fail(struct bna_rx *rx)
  2110. {
  2111. /* Indicate port is not enabled, and failed */
  2112. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2113. rx->rx_flags |= BNA_RX_F_PORT_FAILED;
  2114. bfa_fsm_send_event(rx, RX_E_FAIL);
  2115. }
  2116. void
  2117. bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2118. {
  2119. struct bna_rx *rx;
  2120. struct list_head *qe;
  2121. rx_mod->flags |= BNA_RX_MOD_F_PORT_STARTED;
  2122. if (type == BNA_RX_T_LOOPBACK)
  2123. rx_mod->flags |= BNA_RX_MOD_F_PORT_LOOPBACK;
  2124. list_for_each(qe, &rx_mod->rx_active_q) {
  2125. rx = (struct bna_rx *)qe;
  2126. if (rx->type == type)
  2127. bna_rx_start(rx);
  2128. }
  2129. }
  2130. void
  2131. bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2132. {
  2133. struct bna_rx *rx;
  2134. struct list_head *qe;
  2135. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2136. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2137. rx_mod->stop_cbfn = bna_port_cb_rx_stopped;
  2138. /**
  2139. * Before calling bna_rx_stop(), increment rx_stop_wc as many times
  2140. * as we are going to call bna_rx_stop
  2141. */
  2142. list_for_each(qe, &rx_mod->rx_active_q) {
  2143. rx = (struct bna_rx *)qe;
  2144. if (rx->type == type)
  2145. bfa_wc_up(&rx_mod->rx_stop_wc);
  2146. }
  2147. if (rx_mod->rx_stop_wc.wc_count == 0) {
  2148. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2149. rx_mod->stop_cbfn = NULL;
  2150. return;
  2151. }
  2152. list_for_each(qe, &rx_mod->rx_active_q) {
  2153. rx = (struct bna_rx *)qe;
  2154. if (rx->type == type)
  2155. bna_rx_stop(rx);
  2156. }
  2157. }
  2158. void
  2159. bna_rx_mod_fail(struct bna_rx_mod *rx_mod)
  2160. {
  2161. struct bna_rx *rx;
  2162. struct list_head *qe;
  2163. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2164. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2165. list_for_each(qe, &rx_mod->rx_active_q) {
  2166. rx = (struct bna_rx *)qe;
  2167. bna_rx_fail(rx);
  2168. }
  2169. }
  2170. void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
  2171. struct bna_res_info *res_info)
  2172. {
  2173. int index;
  2174. struct bna_rx *rx_ptr;
  2175. struct bna_rxp *rxp_ptr;
  2176. struct bna_rxq *rxq_ptr;
  2177. rx_mod->bna = bna;
  2178. rx_mod->flags = 0;
  2179. rx_mod->rx = (struct bna_rx *)
  2180. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.mdl[0].kva;
  2181. rx_mod->rxp = (struct bna_rxp *)
  2182. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mdl[0].kva;
  2183. rx_mod->rxq = (struct bna_rxq *)
  2184. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  2185. /* Initialize the queues */
  2186. _init_rxmod_queues(rx_mod);
  2187. /* Build RX queues */
  2188. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2189. rx_ptr = &rx_mod->rx[index];
  2190. _rx_ctor(rx_ptr, index);
  2191. list_add_tail(&rx_ptr->qe, &rx_mod->rx_free_q);
  2192. rx_mod->rx_free_count++;
  2193. }
  2194. /* build RX-path queue */
  2195. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2196. rxp_ptr = &rx_mod->rxp[index];
  2197. rxp_ptr->cq.cq_id = index;
  2198. bfa_q_qe_init(&rxp_ptr->qe);
  2199. list_add_tail(&rxp_ptr->qe, &rx_mod->rxp_free_q);
  2200. rx_mod->rxp_free_count++;
  2201. }
  2202. /* build RXQ queue */
  2203. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2204. rxq_ptr = &rx_mod->rxq[index];
  2205. rxq_ptr->rxq_id = index;
  2206. bfa_q_qe_init(&rxq_ptr->qe);
  2207. list_add_tail(&rxq_ptr->qe, &rx_mod->rxq_free_q);
  2208. rx_mod->rxq_free_count++;
  2209. }
  2210. rx_mod->rx_stop_wc.wc_resume = bna_rx_mod_cb_rx_stopped_all;
  2211. rx_mod->rx_stop_wc.wc_cbarg = rx_mod;
  2212. rx_mod->rx_stop_wc.wc_count = 0;
  2213. }
  2214. void
  2215. bna_rx_mod_uninit(struct bna_rx_mod *rx_mod)
  2216. {
  2217. struct list_head *qe;
  2218. int i;
  2219. i = 0;
  2220. list_for_each(qe, &rx_mod->rx_free_q)
  2221. i++;
  2222. i = 0;
  2223. list_for_each(qe, &rx_mod->rxp_free_q)
  2224. i++;
  2225. i = 0;
  2226. list_for_each(qe, &rx_mod->rxq_free_q)
  2227. i++;
  2228. rx_mod->bna = NULL;
  2229. }
  2230. int
  2231. bna_rx_state_get(struct bna_rx *rx)
  2232. {
  2233. return bfa_sm_to_state(rx_sm_table, rx->fsm);
  2234. }
  2235. void
  2236. bna_rx_res_req(struct bna_rx_config *q_cfg, struct bna_res_info *res_info)
  2237. {
  2238. u32 cq_size, hq_size, dq_size;
  2239. u32 cpage_count, hpage_count, dpage_count;
  2240. struct bna_mem_info *mem_info;
  2241. u32 cq_depth;
  2242. u32 hq_depth;
  2243. u32 dq_depth;
  2244. dq_depth = q_cfg->q_depth;
  2245. hq_depth = ((q_cfg->rxp_type == BNA_RXP_SINGLE) ? 0 : q_cfg->q_depth);
  2246. cq_depth = dq_depth + hq_depth;
  2247. BNA_TO_POWER_OF_2_HIGH(cq_depth);
  2248. cq_size = cq_depth * BFI_CQ_WI_SIZE;
  2249. cq_size = ALIGN(cq_size, PAGE_SIZE);
  2250. cpage_count = SIZE_TO_PAGES(cq_size);
  2251. BNA_TO_POWER_OF_2_HIGH(dq_depth);
  2252. dq_size = dq_depth * BFI_RXQ_WI_SIZE;
  2253. dq_size = ALIGN(dq_size, PAGE_SIZE);
  2254. dpage_count = SIZE_TO_PAGES(dq_size);
  2255. if (BNA_RXP_SINGLE != q_cfg->rxp_type) {
  2256. BNA_TO_POWER_OF_2_HIGH(hq_depth);
  2257. hq_size = hq_depth * BFI_RXQ_WI_SIZE;
  2258. hq_size = ALIGN(hq_size, PAGE_SIZE);
  2259. hpage_count = SIZE_TO_PAGES(hq_size);
  2260. } else {
  2261. hpage_count = 0;
  2262. }
  2263. /* CCB structures */
  2264. res_info[BNA_RX_RES_MEM_T_CCB].res_type = BNA_RES_T_MEM;
  2265. mem_info = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info;
  2266. mem_info->mem_type = BNA_MEM_T_KVA;
  2267. mem_info->len = sizeof(struct bna_ccb);
  2268. mem_info->num = q_cfg->num_paths;
  2269. /* RCB structures */
  2270. res_info[BNA_RX_RES_MEM_T_RCB].res_type = BNA_RES_T_MEM;
  2271. mem_info = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info;
  2272. mem_info->mem_type = BNA_MEM_T_KVA;
  2273. mem_info->len = sizeof(struct bna_rcb);
  2274. mem_info->num = BNA_GET_RXQS(q_cfg);
  2275. /* Completion QPT */
  2276. res_info[BNA_RX_RES_MEM_T_CQPT].res_type = BNA_RES_T_MEM;
  2277. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info;
  2278. mem_info->mem_type = BNA_MEM_T_DMA;
  2279. mem_info->len = cpage_count * sizeof(struct bna_dma_addr);
  2280. mem_info->num = q_cfg->num_paths;
  2281. /* Completion s/w QPT */
  2282. res_info[BNA_RX_RES_MEM_T_CSWQPT].res_type = BNA_RES_T_MEM;
  2283. mem_info = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info;
  2284. mem_info->mem_type = BNA_MEM_T_KVA;
  2285. mem_info->len = cpage_count * sizeof(void *);
  2286. mem_info->num = q_cfg->num_paths;
  2287. /* Completion QPT pages */
  2288. res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_type = BNA_RES_T_MEM;
  2289. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info;
  2290. mem_info->mem_type = BNA_MEM_T_DMA;
  2291. mem_info->len = PAGE_SIZE;
  2292. mem_info->num = cpage_count * q_cfg->num_paths;
  2293. /* Data QPTs */
  2294. res_info[BNA_RX_RES_MEM_T_DQPT].res_type = BNA_RES_T_MEM;
  2295. mem_info = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info;
  2296. mem_info->mem_type = BNA_MEM_T_DMA;
  2297. mem_info->len = dpage_count * sizeof(struct bna_dma_addr);
  2298. mem_info->num = q_cfg->num_paths;
  2299. /* Data s/w QPTs */
  2300. res_info[BNA_RX_RES_MEM_T_DSWQPT].res_type = BNA_RES_T_MEM;
  2301. mem_info = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info;
  2302. mem_info->mem_type = BNA_MEM_T_KVA;
  2303. mem_info->len = dpage_count * sizeof(void *);
  2304. mem_info->num = q_cfg->num_paths;
  2305. /* Data QPT pages */
  2306. res_info[BNA_RX_RES_MEM_T_DPAGE].res_type = BNA_RES_T_MEM;
  2307. mem_info = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info;
  2308. mem_info->mem_type = BNA_MEM_T_DMA;
  2309. mem_info->len = PAGE_SIZE;
  2310. mem_info->num = dpage_count * q_cfg->num_paths;
  2311. /* Hdr QPTs */
  2312. res_info[BNA_RX_RES_MEM_T_HQPT].res_type = BNA_RES_T_MEM;
  2313. mem_info = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info;
  2314. mem_info->mem_type = BNA_MEM_T_DMA;
  2315. mem_info->len = hpage_count * sizeof(struct bna_dma_addr);
  2316. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2317. /* Hdr s/w QPTs */
  2318. res_info[BNA_RX_RES_MEM_T_HSWQPT].res_type = BNA_RES_T_MEM;
  2319. mem_info = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info;
  2320. mem_info->mem_type = BNA_MEM_T_KVA;
  2321. mem_info->len = hpage_count * sizeof(void *);
  2322. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2323. /* Hdr QPT pages */
  2324. res_info[BNA_RX_RES_MEM_T_HPAGE].res_type = BNA_RES_T_MEM;
  2325. mem_info = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info;
  2326. mem_info->mem_type = BNA_MEM_T_DMA;
  2327. mem_info->len = (hpage_count ? PAGE_SIZE : 0);
  2328. mem_info->num = (hpage_count ? (hpage_count * q_cfg->num_paths) : 0);
  2329. /* RX Interrupts */
  2330. res_info[BNA_RX_RES_T_INTR].res_type = BNA_RES_T_INTR;
  2331. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.intr_type = BNA_INTR_T_MSIX;
  2332. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.num = q_cfg->num_paths;
  2333. }
  2334. struct bna_rx *
  2335. bna_rx_create(struct bna *bna, struct bnad *bnad,
  2336. struct bna_rx_config *rx_cfg,
  2337. struct bna_rx_event_cbfn *rx_cbfn,
  2338. struct bna_res_info *res_info,
  2339. void *priv)
  2340. {
  2341. struct bna_rx_mod *rx_mod = &bna->rx_mod;
  2342. struct bna_rx *rx;
  2343. struct bna_rxp *rxp;
  2344. struct bna_rxq *q0;
  2345. struct bna_rxq *q1;
  2346. struct bna_intr_info *intr_info;
  2347. u32 page_count;
  2348. struct bna_mem_descr *ccb_mem;
  2349. struct bna_mem_descr *rcb_mem;
  2350. struct bna_mem_descr *unmapq_mem;
  2351. struct bna_mem_descr *cqpt_mem;
  2352. struct bna_mem_descr *cswqpt_mem;
  2353. struct bna_mem_descr *cpage_mem;
  2354. struct bna_mem_descr *hqpt_mem; /* Header/Small Q qpt */
  2355. struct bna_mem_descr *dqpt_mem; /* Data/Large Q qpt */
  2356. struct bna_mem_descr *hsqpt_mem; /* s/w qpt for hdr */
  2357. struct bna_mem_descr *dsqpt_mem; /* s/w qpt for data */
  2358. struct bna_mem_descr *hpage_mem; /* hdr page mem */
  2359. struct bna_mem_descr *dpage_mem; /* data page mem */
  2360. int i, cpage_idx = 0, dpage_idx = 0, hpage_idx = 0, ret;
  2361. int dpage_count, hpage_count, rcb_idx;
  2362. struct bna_ib_config ibcfg;
  2363. /* Fail if we don't have enough RXPs, RXQs */
  2364. if (!_rx_can_satisfy(rx_mod, rx_cfg))
  2365. return NULL;
  2366. /* Initialize resource pointers */
  2367. intr_info = &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
  2368. ccb_mem = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info.mdl[0];
  2369. rcb_mem = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info.mdl[0];
  2370. unmapq_mem = &res_info[BNA_RX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[0];
  2371. cqpt_mem = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info.mdl[0];
  2372. cswqpt_mem = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info.mdl[0];
  2373. cpage_mem = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.mdl[0];
  2374. hqpt_mem = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info.mdl[0];
  2375. dqpt_mem = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info.mdl[0];
  2376. hsqpt_mem = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info.mdl[0];
  2377. dsqpt_mem = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info.mdl[0];
  2378. hpage_mem = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.mdl[0];
  2379. dpage_mem = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.mdl[0];
  2380. /* Compute q depth & page count */
  2381. page_count = res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.num /
  2382. rx_cfg->num_paths;
  2383. dpage_count = res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.num /
  2384. rx_cfg->num_paths;
  2385. hpage_count = res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.num /
  2386. rx_cfg->num_paths;
  2387. /* Get RX pointer */
  2388. rx = _get_free_rx(rx_mod);
  2389. _rx_init(rx, bna);
  2390. rx->priv = priv;
  2391. rx->type = rx_cfg->rx_type;
  2392. rx->rcb_setup_cbfn = rx_cbfn->rcb_setup_cbfn;
  2393. rx->rcb_destroy_cbfn = rx_cbfn->rcb_destroy_cbfn;
  2394. rx->ccb_setup_cbfn = rx_cbfn->ccb_setup_cbfn;
  2395. rx->ccb_destroy_cbfn = rx_cbfn->ccb_destroy_cbfn;
  2396. /* Following callbacks are mandatory */
  2397. rx->rx_cleanup_cbfn = rx_cbfn->rx_cleanup_cbfn;
  2398. rx->rx_post_cbfn = rx_cbfn->rx_post_cbfn;
  2399. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_STARTED) {
  2400. switch (rx->type) {
  2401. case BNA_RX_T_REGULAR:
  2402. if (!(rx->bna->rx_mod.flags &
  2403. BNA_RX_MOD_F_PORT_LOOPBACK))
  2404. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2405. break;
  2406. case BNA_RX_T_LOOPBACK:
  2407. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_LOOPBACK)
  2408. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2409. break;
  2410. }
  2411. }
  2412. for (i = 0, rcb_idx = 0; i < rx_cfg->num_paths; i++) {
  2413. rxp = _get_free_rxp(rx_mod);
  2414. rxp->type = rx_cfg->rxp_type;
  2415. rxp->rx = rx;
  2416. rxp->cq.rx = rx;
  2417. /* Get required RXQs, and queue them to rx-path */
  2418. q0 = _get_free_rxq(rx_mod);
  2419. if (BNA_RXP_SINGLE == rx_cfg->rxp_type)
  2420. q1 = NULL;
  2421. else
  2422. q1 = _get_free_rxq(rx_mod);
  2423. /* Initialize IB */
  2424. if (1 == intr_info->num) {
  2425. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2426. intr_info->intr_type,
  2427. intr_info->idl[0].vector);
  2428. rxp->vector = intr_info->idl[0].vector;
  2429. } else {
  2430. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2431. intr_info->intr_type,
  2432. intr_info->idl[i].vector);
  2433. /* Map the MSI-x vector used for this RXP */
  2434. rxp->vector = intr_info->idl[i].vector;
  2435. }
  2436. rxp->cq.ib_seg_offset = bna_ib_reserve_idx(rxp->cq.ib);
  2437. ibcfg.coalescing_timeo = BFI_RX_COALESCING_TIMEO;
  2438. ibcfg.interpkt_count = BFI_RX_INTERPKT_COUNT;
  2439. ibcfg.interpkt_timeo = BFI_RX_INTERPKT_TIMEO;
  2440. ibcfg.ctrl_flags = BFI_IB_CF_INT_ENABLE;
  2441. ret = bna_ib_config(rxp->cq.ib, &ibcfg);
  2442. /* Link rxqs to rxp */
  2443. _rxp_add_rxqs(rxp, q0, q1);
  2444. /* Link rxp to rx */
  2445. _rx_add_rxp(rx, rxp);
  2446. q0->rx = rx;
  2447. q0->rxp = rxp;
  2448. /* Initialize RCB for the large / data q */
  2449. q0->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2450. RXQ_RCB_INIT(q0, rxp, rx_cfg->q_depth, bna, 0,
  2451. (void *)unmapq_mem[rcb_idx].kva);
  2452. rcb_idx++;
  2453. (q0)->rx_packets = (q0)->rx_bytes = 0;
  2454. (q0)->rx_packets_with_error = (q0)->rxbuf_alloc_failed = 0;
  2455. /* Initialize RXQs */
  2456. _rxq_qpt_init(q0, rxp, dpage_count, PAGE_SIZE,
  2457. &dqpt_mem[i], &dsqpt_mem[i], &dpage_mem[dpage_idx]);
  2458. q0->rcb->page_idx = dpage_idx;
  2459. q0->rcb->page_count = dpage_count;
  2460. dpage_idx += dpage_count;
  2461. /* Call bnad to complete rcb setup */
  2462. if (rx->rcb_setup_cbfn)
  2463. rx->rcb_setup_cbfn(bnad, q0->rcb);
  2464. if (q1) {
  2465. q1->rx = rx;
  2466. q1->rxp = rxp;
  2467. q1->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2468. RXQ_RCB_INIT(q1, rxp, rx_cfg->q_depth, bna, 1,
  2469. (void *)unmapq_mem[rcb_idx].kva);
  2470. rcb_idx++;
  2471. (q1)->buffer_size = (rx_cfg)->small_buff_size;
  2472. (q1)->rx_packets = (q1)->rx_bytes = 0;
  2473. (q1)->rx_packets_with_error =
  2474. (q1)->rxbuf_alloc_failed = 0;
  2475. _rxq_qpt_init(q1, rxp, hpage_count, PAGE_SIZE,
  2476. &hqpt_mem[i], &hsqpt_mem[i],
  2477. &hpage_mem[hpage_idx]);
  2478. q1->rcb->page_idx = hpage_idx;
  2479. q1->rcb->page_count = hpage_count;
  2480. hpage_idx += hpage_count;
  2481. /* Call bnad to complete rcb setup */
  2482. if (rx->rcb_setup_cbfn)
  2483. rx->rcb_setup_cbfn(bnad, q1->rcb);
  2484. }
  2485. /* Setup RXP::CQ */
  2486. rxp->cq.ccb = (struct bna_ccb *) ccb_mem[i].kva;
  2487. _rxp_cqpt_setup(rxp, page_count, PAGE_SIZE,
  2488. &cqpt_mem[i], &cswqpt_mem[i], &cpage_mem[cpage_idx]);
  2489. rxp->cq.ccb->page_idx = cpage_idx;
  2490. rxp->cq.ccb->page_count = page_count;
  2491. cpage_idx += page_count;
  2492. rxp->cq.ccb->pkt_rate.small_pkt_cnt = 0;
  2493. rxp->cq.ccb->pkt_rate.large_pkt_cnt = 0;
  2494. rxp->cq.ccb->producer_index = 0;
  2495. rxp->cq.ccb->q_depth = rx_cfg->q_depth +
  2496. ((rx_cfg->rxp_type == BNA_RXP_SINGLE) ?
  2497. 0 : rx_cfg->q_depth);
  2498. rxp->cq.ccb->i_dbell = &rxp->cq.ib->door_bell;
  2499. rxp->cq.ccb->rcb[0] = q0->rcb;
  2500. if (q1)
  2501. rxp->cq.ccb->rcb[1] = q1->rcb;
  2502. rxp->cq.ccb->cq = &rxp->cq;
  2503. rxp->cq.ccb->bnad = bna->bnad;
  2504. rxp->cq.ccb->hw_producer_index =
  2505. ((volatile u32 *)rxp->cq.ib->ib_seg_host_addr_kva +
  2506. (rxp->cq.ib_seg_offset * BFI_IBIDX_SIZE));
  2507. *(rxp->cq.ccb->hw_producer_index) = 0;
  2508. rxp->cq.ccb->intr_type = intr_info->intr_type;
  2509. rxp->cq.ccb->intr_vector = (intr_info->num == 1) ?
  2510. intr_info->idl[0].vector :
  2511. intr_info->idl[i].vector;
  2512. rxp->cq.ccb->rx_coalescing_timeo =
  2513. rxp->cq.ib->ib_config.coalescing_timeo;
  2514. rxp->cq.ccb->id = i;
  2515. /* Call bnad to complete CCB setup */
  2516. if (rx->ccb_setup_cbfn)
  2517. rx->ccb_setup_cbfn(bnad, rxp->cq.ccb);
  2518. } /* for each rx-path */
  2519. bna_rxf_init(&rx->rxf, rx, rx_cfg);
  2520. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  2521. return rx;
  2522. }
  2523. void
  2524. bna_rx_destroy(struct bna_rx *rx)
  2525. {
  2526. struct bna_rx_mod *rx_mod = &rx->bna->rx_mod;
  2527. struct bna_ib_mod *ib_mod = &rx->bna->ib_mod;
  2528. struct bna_rxq *q0 = NULL;
  2529. struct bna_rxq *q1 = NULL;
  2530. struct bna_rxp *rxp;
  2531. struct list_head *qe;
  2532. bna_rxf_uninit(&rx->rxf);
  2533. while (!list_empty(&rx->rxp_q)) {
  2534. bfa_q_deq(&rx->rxp_q, &rxp);
  2535. GET_RXQS(rxp, q0, q1);
  2536. /* Callback to bnad for destroying RCB */
  2537. if (rx->rcb_destroy_cbfn)
  2538. rx->rcb_destroy_cbfn(rx->bna->bnad, q0->rcb);
  2539. q0->rcb = NULL;
  2540. q0->rxp = NULL;
  2541. q0->rx = NULL;
  2542. _put_free_rxq(rx_mod, q0);
  2543. if (q1) {
  2544. /* Callback to bnad for destroying RCB */
  2545. if (rx->rcb_destroy_cbfn)
  2546. rx->rcb_destroy_cbfn(rx->bna->bnad, q1->rcb);
  2547. q1->rcb = NULL;
  2548. q1->rxp = NULL;
  2549. q1->rx = NULL;
  2550. _put_free_rxq(rx_mod, q1);
  2551. }
  2552. rxp->rxq.slr.large = NULL;
  2553. rxp->rxq.slr.small = NULL;
  2554. if (rxp->cq.ib) {
  2555. if (rxp->cq.ib_seg_offset != 0xff)
  2556. bna_ib_release_idx(rxp->cq.ib,
  2557. rxp->cq.ib_seg_offset);
  2558. bna_ib_put(ib_mod, rxp->cq.ib);
  2559. rxp->cq.ib = NULL;
  2560. }
  2561. /* Callback to bnad for destroying CCB */
  2562. if (rx->ccb_destroy_cbfn)
  2563. rx->ccb_destroy_cbfn(rx->bna->bnad, rxp->cq.ccb);
  2564. rxp->cq.ccb = NULL;
  2565. rxp->rx = NULL;
  2566. _put_free_rxp(rx_mod, rxp);
  2567. }
  2568. list_for_each(qe, &rx_mod->rx_active_q) {
  2569. if (qe == &rx->qe) {
  2570. list_del(&rx->qe);
  2571. bfa_q_qe_init(&rx->qe);
  2572. break;
  2573. }
  2574. }
  2575. rx->bna = NULL;
  2576. rx->priv = NULL;
  2577. _put_free_rx(rx_mod, rx);
  2578. }
  2579. void
  2580. bna_rx_enable(struct bna_rx *rx)
  2581. {
  2582. if (rx->fsm != (bfa_sm_t)bna_rx_sm_stopped)
  2583. return;
  2584. rx->rx_flags |= BNA_RX_F_ENABLE;
  2585. if (rx->rx_flags & BNA_RX_F_PORT_ENABLED)
  2586. bfa_fsm_send_event(rx, RX_E_START);
  2587. }
  2588. void
  2589. bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
  2590. void (*cbfn)(void *, struct bna_rx *,
  2591. enum bna_cb_status))
  2592. {
  2593. if (type == BNA_SOFT_CLEANUP) {
  2594. /* h/w should not be accessed. Treat we're stopped */
  2595. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  2596. } else {
  2597. rx->stop_cbfn = cbfn;
  2598. rx->stop_cbarg = rx->bna->bnad;
  2599. rx->rx_flags &= ~BNA_RX_F_ENABLE;
  2600. bfa_fsm_send_event(rx, RX_E_STOP);
  2601. }
  2602. }
  2603. /**
  2604. * TX
  2605. */
  2606. #define call_tx_stop_cbfn(tx, status)\
  2607. do {\
  2608. if ((tx)->stop_cbfn)\
  2609. (tx)->stop_cbfn((tx)->stop_cbarg, (tx), status);\
  2610. (tx)->stop_cbfn = NULL;\
  2611. (tx)->stop_cbarg = NULL;\
  2612. } while (0)
  2613. #define call_tx_prio_change_cbfn(tx, status)\
  2614. do {\
  2615. if ((tx)->prio_change_cbfn)\
  2616. (tx)->prio_change_cbfn((tx)->bna->bnad, (tx), status);\
  2617. (tx)->prio_change_cbfn = NULL;\
  2618. } while (0)
  2619. static void bna_tx_mod_cb_tx_stopped(void *tx_mod, struct bna_tx *tx,
  2620. enum bna_cb_status status);
  2621. static void bna_tx_cb_txq_stopped(void *arg, int status);
  2622. static void bna_tx_cb_stats_cleared(void *arg, int status);
  2623. static void __bna_tx_stop(struct bna_tx *tx);
  2624. static void __bna_tx_start(struct bna_tx *tx);
  2625. static void __bna_txf_stat_clr(struct bna_tx *tx);
  2626. enum bna_tx_event {
  2627. TX_E_START = 1,
  2628. TX_E_STOP = 2,
  2629. TX_E_FAIL = 3,
  2630. TX_E_TXQ_STOPPED = 4,
  2631. TX_E_PRIO_CHANGE = 5,
  2632. TX_E_STAT_CLEARED = 6,
  2633. };
  2634. enum bna_tx_state {
  2635. BNA_TX_STOPPED = 1,
  2636. BNA_TX_STARTED = 2,
  2637. BNA_TX_TXQ_STOP_WAIT = 3,
  2638. BNA_TX_PRIO_STOP_WAIT = 4,
  2639. BNA_TX_STAT_CLR_WAIT = 5,
  2640. };
  2641. bfa_fsm_state_decl(bna_tx, stopped, struct bna_tx,
  2642. enum bna_tx_event);
  2643. bfa_fsm_state_decl(bna_tx, started, struct bna_tx,
  2644. enum bna_tx_event);
  2645. bfa_fsm_state_decl(bna_tx, txq_stop_wait, struct bna_tx,
  2646. enum bna_tx_event);
  2647. bfa_fsm_state_decl(bna_tx, prio_stop_wait, struct bna_tx,
  2648. enum bna_tx_event);
  2649. bfa_fsm_state_decl(bna_tx, stat_clr_wait, struct bna_tx,
  2650. enum bna_tx_event);
  2651. static struct bfa_sm_table tx_sm_table[] = {
  2652. {BFA_SM(bna_tx_sm_stopped), BNA_TX_STOPPED},
  2653. {BFA_SM(bna_tx_sm_started), BNA_TX_STARTED},
  2654. {BFA_SM(bna_tx_sm_txq_stop_wait), BNA_TX_TXQ_STOP_WAIT},
  2655. {BFA_SM(bna_tx_sm_prio_stop_wait), BNA_TX_PRIO_STOP_WAIT},
  2656. {BFA_SM(bna_tx_sm_stat_clr_wait), BNA_TX_STAT_CLR_WAIT},
  2657. };
  2658. static void
  2659. bna_tx_sm_stopped_entry(struct bna_tx *tx)
  2660. {
  2661. struct bna_txq *txq;
  2662. struct list_head *qe;
  2663. list_for_each(qe, &tx->txq_q) {
  2664. txq = (struct bna_txq *)qe;
  2665. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2666. }
  2667. call_tx_stop_cbfn(tx, BNA_CB_SUCCESS);
  2668. }
  2669. static void
  2670. bna_tx_sm_stopped(struct bna_tx *tx, enum bna_tx_event event)
  2671. {
  2672. switch (event) {
  2673. case TX_E_START:
  2674. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2675. break;
  2676. case TX_E_STOP:
  2677. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2678. break;
  2679. case TX_E_FAIL:
  2680. /* No-op */
  2681. break;
  2682. case TX_E_PRIO_CHANGE:
  2683. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2684. break;
  2685. case TX_E_TXQ_STOPPED:
  2686. /**
  2687. * This event is received due to flushing of mbox when
  2688. * device fails
  2689. */
  2690. /* No-op */
  2691. break;
  2692. default:
  2693. bfa_sm_fault(tx->bna, event);
  2694. }
  2695. }
  2696. static void
  2697. bna_tx_sm_started_entry(struct bna_tx *tx)
  2698. {
  2699. struct bna_txq *txq;
  2700. struct list_head *qe;
  2701. __bna_tx_start(tx);
  2702. /* Start IB */
  2703. list_for_each(qe, &tx->txq_q) {
  2704. txq = (struct bna_txq *)qe;
  2705. bna_ib_ack(&txq->ib->door_bell, 0);
  2706. }
  2707. }
  2708. static void
  2709. bna_tx_sm_started(struct bna_tx *tx, enum bna_tx_event event)
  2710. {
  2711. struct bna_txq *txq;
  2712. struct list_head *qe;
  2713. switch (event) {
  2714. case TX_E_STOP:
  2715. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2716. __bna_tx_stop(tx);
  2717. break;
  2718. case TX_E_FAIL:
  2719. list_for_each(qe, &tx->txq_q) {
  2720. txq = (struct bna_txq *)qe;
  2721. bna_ib_fail(txq->ib);
  2722. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  2723. }
  2724. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2725. break;
  2726. case TX_E_PRIO_CHANGE:
  2727. bfa_fsm_set_state(tx, bna_tx_sm_prio_stop_wait);
  2728. break;
  2729. default:
  2730. bfa_sm_fault(tx->bna, event);
  2731. }
  2732. }
  2733. static void
  2734. bna_tx_sm_txq_stop_wait_entry(struct bna_tx *tx)
  2735. {
  2736. }
  2737. static void
  2738. bna_tx_sm_txq_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2739. {
  2740. struct bna_txq *txq;
  2741. struct list_head *qe;
  2742. switch (event) {
  2743. case TX_E_FAIL:
  2744. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2745. break;
  2746. case TX_E_TXQ_STOPPED:
  2747. list_for_each(qe, &tx->txq_q) {
  2748. txq = (struct bna_txq *)qe;
  2749. bna_ib_stop(txq->ib);
  2750. }
  2751. bfa_fsm_set_state(tx, bna_tx_sm_stat_clr_wait);
  2752. break;
  2753. case TX_E_PRIO_CHANGE:
  2754. /* No-op */
  2755. break;
  2756. default:
  2757. bfa_sm_fault(tx->bna, event);
  2758. }
  2759. }
  2760. static void
  2761. bna_tx_sm_prio_stop_wait_entry(struct bna_tx *tx)
  2762. {
  2763. __bna_tx_stop(tx);
  2764. }
  2765. static void
  2766. bna_tx_sm_prio_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2767. {
  2768. struct bna_txq *txq;
  2769. struct list_head *qe;
  2770. switch (event) {
  2771. case TX_E_STOP:
  2772. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2773. break;
  2774. case TX_E_FAIL:
  2775. call_tx_prio_change_cbfn(tx, BNA_CB_FAIL);
  2776. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2777. break;
  2778. case TX_E_TXQ_STOPPED:
  2779. list_for_each(qe, &tx->txq_q) {
  2780. txq = (struct bna_txq *)qe;
  2781. bna_ib_stop(txq->ib);
  2782. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2783. }
  2784. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2785. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2786. break;
  2787. case TX_E_PRIO_CHANGE:
  2788. /* No-op */
  2789. break;
  2790. default:
  2791. bfa_sm_fault(tx->bna, event);
  2792. }
  2793. }
  2794. static void
  2795. bna_tx_sm_stat_clr_wait_entry(struct bna_tx *tx)
  2796. {
  2797. __bna_txf_stat_clr(tx);
  2798. }
  2799. static void
  2800. bna_tx_sm_stat_clr_wait(struct bna_tx *tx, enum bna_tx_event event)
  2801. {
  2802. switch (event) {
  2803. case TX_E_FAIL:
  2804. case TX_E_STAT_CLEARED:
  2805. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2806. break;
  2807. default:
  2808. bfa_sm_fault(tx->bna, event);
  2809. }
  2810. }
  2811. static void
  2812. __bna_txq_start(struct bna_tx *tx, struct bna_txq *txq)
  2813. {
  2814. struct bna_rxtx_q_mem *q_mem;
  2815. struct bna_txq_mem txq_cfg;
  2816. struct bna_txq_mem *txq_mem;
  2817. struct bna_dma_addr cur_q_addr;
  2818. u32 pg_num;
  2819. void __iomem *base_addr;
  2820. unsigned long off;
  2821. /* Fill out structure, to be subsequently written to hardware */
  2822. txq_cfg.pg_tbl_addr_lo = txq->qpt.hw_qpt_ptr.lsb;
  2823. txq_cfg.pg_tbl_addr_hi = txq->qpt.hw_qpt_ptr.msb;
  2824. cur_q_addr = *((struct bna_dma_addr *)(txq->qpt.kv_qpt_ptr));
  2825. txq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  2826. txq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  2827. txq_cfg.pg_cnt_n_prd_ptr = (txq->qpt.page_count << 16) | 0x0;
  2828. txq_cfg.entry_n_pg_size = ((u32)(BFI_TXQ_WI_SIZE >> 2) << 16) |
  2829. (txq->qpt.page_size >> 2);
  2830. txq_cfg.int_blk_n_cns_ptr = ((((u32)txq->ib_seg_offset) << 24) |
  2831. ((u32)(txq->ib->ib_id & 0xff) << 16) | 0x0);
  2832. txq_cfg.cns_ptr2_n_q_state = BNA_Q_IDLE_STATE;
  2833. txq_cfg.nxt_qid_n_fid_n_pri = (((tx->txf.txf_id & 0x3f) << 3) |
  2834. (txq->priority & 0x3));
  2835. txq_cfg.wvc_n_cquota_n_rquota =
  2836. ((((u32)BFI_TX_MAX_WRR_QUOTA & 0xfff) << 12) |
  2837. (BFI_TX_MAX_WRR_QUOTA & 0xfff));
  2838. /* Setup the page and write to H/W */
  2839. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + tx->bna->port_num,
  2840. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2841. writel(pg_num, tx->bna->regs.page_addr);
  2842. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2843. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2844. q_mem = (struct bna_rxtx_q_mem *)0;
  2845. txq_mem = &q_mem[txq->txq_id].txq;
  2846. /*
  2847. * The following 4 lines, is a hack b'cos the H/W needs to read
  2848. * these DMA addresses as little endian
  2849. */
  2850. off = (unsigned long)&txq_mem->pg_tbl_addr_lo;
  2851. writel(htonl(txq_cfg.pg_tbl_addr_lo), base_addr + off);
  2852. off = (unsigned long)&txq_mem->pg_tbl_addr_hi;
  2853. writel(htonl(txq_cfg.pg_tbl_addr_hi), base_addr + off);
  2854. off = (unsigned long)&txq_mem->cur_q_entry_lo;
  2855. writel(htonl(txq_cfg.cur_q_entry_lo), base_addr + off);
  2856. off = (unsigned long)&txq_mem->cur_q_entry_hi;
  2857. writel(htonl(txq_cfg.cur_q_entry_hi), base_addr + off);
  2858. off = (unsigned long)&txq_mem->pg_cnt_n_prd_ptr;
  2859. writel(txq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  2860. off = (unsigned long)&txq_mem->entry_n_pg_size;
  2861. writel(txq_cfg.entry_n_pg_size, base_addr + off);
  2862. off = (unsigned long)&txq_mem->int_blk_n_cns_ptr;
  2863. writel(txq_cfg.int_blk_n_cns_ptr, base_addr + off);
  2864. off = (unsigned long)&txq_mem->cns_ptr2_n_q_state;
  2865. writel(txq_cfg.cns_ptr2_n_q_state, base_addr + off);
  2866. off = (unsigned long)&txq_mem->nxt_qid_n_fid_n_pri;
  2867. writel(txq_cfg.nxt_qid_n_fid_n_pri, base_addr + off);
  2868. off = (unsigned long)&txq_mem->wvc_n_cquota_n_rquota;
  2869. writel(txq_cfg.wvc_n_cquota_n_rquota, base_addr + off);
  2870. txq->tcb->producer_index = 0;
  2871. txq->tcb->consumer_index = 0;
  2872. *(txq->tcb->hw_consumer_index) = 0;
  2873. }
  2874. static void
  2875. __bna_txq_stop(struct bna_tx *tx, struct bna_txq *txq)
  2876. {
  2877. struct bfi_ll_q_stop_req ll_req;
  2878. u32 bit_mask[2] = {0, 0};
  2879. if (txq->txq_id < 32)
  2880. bit_mask[0] = (u32)1 << txq->txq_id;
  2881. else
  2882. bit_mask[1] = (u32)1 << (txq->txq_id - 32);
  2883. memset(&ll_req, 0, sizeof(ll_req));
  2884. ll_req.mh.msg_class = BFI_MC_LL;
  2885. ll_req.mh.msg_id = BFI_LL_H2I_TXQ_STOP_REQ;
  2886. ll_req.mh.mtag.h2i.lpu_id = 0;
  2887. ll_req.q_id_mask[0] = htonl(bit_mask[0]);
  2888. ll_req.q_id_mask[1] = htonl(bit_mask[1]);
  2889. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2890. bna_tx_cb_txq_stopped, tx);
  2891. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2892. }
  2893. static void
  2894. __bna_txf_start(struct bna_tx *tx)
  2895. {
  2896. struct bna_tx_fndb_ram *tx_fndb;
  2897. struct bna_txf *txf = &tx->txf;
  2898. void __iomem *base_addr;
  2899. unsigned long off;
  2900. writel(BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2901. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET),
  2902. tx->bna->regs.page_addr);
  2903. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2904. TX_FNDB_RAM_BASE_OFFSET);
  2905. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2906. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2907. writel(((u32)txf->vlan << 16) | txf->ctrl_flags,
  2908. base_addr + off);
  2909. if (tx->txf.txf_id < 32)
  2910. tx->bna->tx_mod.txf_bmap[0] |= ((u32)1 << tx->txf.txf_id);
  2911. else
  2912. tx->bna->tx_mod.txf_bmap[1] |= ((u32)
  2913. 1 << (tx->txf.txf_id - 32));
  2914. }
  2915. static void
  2916. __bna_txf_stop(struct bna_tx *tx)
  2917. {
  2918. struct bna_tx_fndb_ram *tx_fndb;
  2919. u32 page_num;
  2920. u32 ctl_flags;
  2921. struct bna_txf *txf = &tx->txf;
  2922. void __iomem *base_addr;
  2923. unsigned long off;
  2924. /* retrieve the running txf_flags & turn off enable bit */
  2925. page_num = BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2926. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET);
  2927. writel(page_num, tx->bna->regs.page_addr);
  2928. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2929. TX_FNDB_RAM_BASE_OFFSET);
  2930. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2931. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2932. ctl_flags = readl(base_addr + off);
  2933. ctl_flags &= ~BFI_TXF_CF_ENABLE;
  2934. writel(ctl_flags, base_addr + off);
  2935. if (tx->txf.txf_id < 32)
  2936. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)1 << tx->txf.txf_id);
  2937. else
  2938. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)
  2939. 1 << (tx->txf.txf_id - 32));
  2940. }
  2941. static void
  2942. __bna_txf_stat_clr(struct bna_tx *tx)
  2943. {
  2944. struct bfi_ll_stats_req ll_req;
  2945. u32 txf_bmap[2] = {0, 0};
  2946. if (tx->txf.txf_id < 32)
  2947. txf_bmap[0] = ((u32)1 << tx->txf.txf_id);
  2948. else
  2949. txf_bmap[1] = ((u32)1 << (tx->txf.txf_id - 32));
  2950. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_CLEAR_REQ, 0);
  2951. ll_req.stats_mask = 0;
  2952. ll_req.rxf_id_mask[0] = 0;
  2953. ll_req.rxf_id_mask[1] = 0;
  2954. ll_req.txf_id_mask[0] = htonl(txf_bmap[0]);
  2955. ll_req.txf_id_mask[1] = htonl(txf_bmap[1]);
  2956. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2957. bna_tx_cb_stats_cleared, tx);
  2958. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2959. }
  2960. static void
  2961. __bna_tx_start(struct bna_tx *tx)
  2962. {
  2963. struct bna_txq *txq;
  2964. struct list_head *qe;
  2965. list_for_each(qe, &tx->txq_q) {
  2966. txq = (struct bna_txq *)qe;
  2967. bna_ib_start(txq->ib);
  2968. __bna_txq_start(tx, txq);
  2969. }
  2970. __bna_txf_start(tx);
  2971. list_for_each(qe, &tx->txq_q) {
  2972. txq = (struct bna_txq *)qe;
  2973. txq->tcb->priority = txq->priority;
  2974. (tx->tx_resume_cbfn)(tx->bna->bnad, txq->tcb);
  2975. }
  2976. }
  2977. static void
  2978. __bna_tx_stop(struct bna_tx *tx)
  2979. {
  2980. struct bna_txq *txq;
  2981. struct list_head *qe;
  2982. list_for_each(qe, &tx->txq_q) {
  2983. txq = (struct bna_txq *)qe;
  2984. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  2985. }
  2986. __bna_txf_stop(tx);
  2987. list_for_each(qe, &tx->txq_q) {
  2988. txq = (struct bna_txq *)qe;
  2989. bfa_wc_up(&tx->txq_stop_wc);
  2990. }
  2991. list_for_each(qe, &tx->txq_q) {
  2992. txq = (struct bna_txq *)qe;
  2993. __bna_txq_stop(tx, txq);
  2994. }
  2995. }
  2996. static void
  2997. bna_txq_qpt_setup(struct bna_txq *txq, int page_count, int page_size,
  2998. struct bna_mem_descr *qpt_mem,
  2999. struct bna_mem_descr *swqpt_mem,
  3000. struct bna_mem_descr *page_mem)
  3001. {
  3002. int i;
  3003. txq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  3004. txq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  3005. txq->qpt.kv_qpt_ptr = qpt_mem->kva;
  3006. txq->qpt.page_count = page_count;
  3007. txq->qpt.page_size = page_size;
  3008. txq->tcb->sw_qpt = (void **) swqpt_mem->kva;
  3009. for (i = 0; i < page_count; i++) {
  3010. txq->tcb->sw_qpt[i] = page_mem[i].kva;
  3011. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].lsb =
  3012. page_mem[i].dma.lsb;
  3013. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].msb =
  3014. page_mem[i].dma.msb;
  3015. }
  3016. }
  3017. static void
  3018. bna_tx_free(struct bna_tx *tx)
  3019. {
  3020. struct bna_tx_mod *tx_mod = &tx->bna->tx_mod;
  3021. struct bna_txq *txq;
  3022. struct bna_ib_mod *ib_mod = &tx->bna->ib_mod;
  3023. struct list_head *qe;
  3024. while (!list_empty(&tx->txq_q)) {
  3025. bfa_q_deq(&tx->txq_q, &txq);
  3026. bfa_q_qe_init(&txq->qe);
  3027. if (txq->ib) {
  3028. if (txq->ib_seg_offset != -1)
  3029. bna_ib_release_idx(txq->ib,
  3030. txq->ib_seg_offset);
  3031. bna_ib_put(ib_mod, txq->ib);
  3032. txq->ib = NULL;
  3033. }
  3034. txq->tcb = NULL;
  3035. txq->tx = NULL;
  3036. list_add_tail(&txq->qe, &tx_mod->txq_free_q);
  3037. }
  3038. list_for_each(qe, &tx_mod->tx_active_q) {
  3039. if (qe == &tx->qe) {
  3040. list_del(&tx->qe);
  3041. bfa_q_qe_init(&tx->qe);
  3042. break;
  3043. }
  3044. }
  3045. tx->bna = NULL;
  3046. tx->priv = NULL;
  3047. list_add_tail(&tx->qe, &tx_mod->tx_free_q);
  3048. }
  3049. static void
  3050. bna_tx_cb_txq_stopped(void *arg, int status)
  3051. {
  3052. struct bna_tx *tx = (struct bna_tx *)arg;
  3053. bfa_q_qe_init(&tx->mbox_qe.qe);
  3054. bfa_wc_down(&tx->txq_stop_wc);
  3055. }
  3056. static void
  3057. bna_tx_cb_txq_stopped_all(void *arg)
  3058. {
  3059. struct bna_tx *tx = (struct bna_tx *)arg;
  3060. bfa_fsm_send_event(tx, TX_E_TXQ_STOPPED);
  3061. }
  3062. static void
  3063. bna_tx_cb_stats_cleared(void *arg, int status)
  3064. {
  3065. struct bna_tx *tx = (struct bna_tx *)arg;
  3066. bfa_q_qe_init(&tx->mbox_qe.qe);
  3067. bfa_fsm_send_event(tx, TX_E_STAT_CLEARED);
  3068. }
  3069. static void
  3070. bna_tx_start(struct bna_tx *tx)
  3071. {
  3072. tx->flags |= BNA_TX_F_PORT_STARTED;
  3073. if (tx->flags & BNA_TX_F_ENABLED)
  3074. bfa_fsm_send_event(tx, TX_E_START);
  3075. }
  3076. static void
  3077. bna_tx_stop(struct bna_tx *tx)
  3078. {
  3079. tx->stop_cbfn = bna_tx_mod_cb_tx_stopped;
  3080. tx->stop_cbarg = &tx->bna->tx_mod;
  3081. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3082. bfa_fsm_send_event(tx, TX_E_STOP);
  3083. }
  3084. static void
  3085. bna_tx_fail(struct bna_tx *tx)
  3086. {
  3087. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3088. bfa_fsm_send_event(tx, TX_E_FAIL);
  3089. }
  3090. static void
  3091. bna_tx_prio_changed(struct bna_tx *tx, int prio)
  3092. {
  3093. struct bna_txq *txq;
  3094. struct list_head *qe;
  3095. list_for_each(qe, &tx->txq_q) {
  3096. txq = (struct bna_txq *)qe;
  3097. txq->priority = prio;
  3098. }
  3099. bfa_fsm_send_event(tx, TX_E_PRIO_CHANGE);
  3100. }
  3101. static void
  3102. bna_tx_cee_link_status(struct bna_tx *tx, int cee_link)
  3103. {
  3104. if (cee_link)
  3105. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3106. else
  3107. tx->flags &= ~BNA_TX_F_PRIO_LOCK;
  3108. }
  3109. static void
  3110. bna_tx_mod_cb_tx_stopped(void *arg, struct bna_tx *tx,
  3111. enum bna_cb_status status)
  3112. {
  3113. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3114. bfa_wc_down(&tx_mod->tx_stop_wc);
  3115. }
  3116. static void
  3117. bna_tx_mod_cb_tx_stopped_all(void *arg)
  3118. {
  3119. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3120. if (tx_mod->stop_cbfn)
  3121. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3122. tx_mod->stop_cbfn = NULL;
  3123. }
  3124. void
  3125. bna_tx_res_req(int num_txq, int txq_depth, struct bna_res_info *res_info)
  3126. {
  3127. u32 q_size;
  3128. u32 page_count;
  3129. struct bna_mem_info *mem_info;
  3130. res_info[BNA_TX_RES_MEM_T_TCB].res_type = BNA_RES_T_MEM;
  3131. mem_info = &res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info;
  3132. mem_info->mem_type = BNA_MEM_T_KVA;
  3133. mem_info->len = sizeof(struct bna_tcb);
  3134. mem_info->num = num_txq;
  3135. q_size = txq_depth * BFI_TXQ_WI_SIZE;
  3136. q_size = ALIGN(q_size, PAGE_SIZE);
  3137. page_count = q_size >> PAGE_SHIFT;
  3138. res_info[BNA_TX_RES_MEM_T_QPT].res_type = BNA_RES_T_MEM;
  3139. mem_info = &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info;
  3140. mem_info->mem_type = BNA_MEM_T_DMA;
  3141. mem_info->len = page_count * sizeof(struct bna_dma_addr);
  3142. mem_info->num = num_txq;
  3143. res_info[BNA_TX_RES_MEM_T_SWQPT].res_type = BNA_RES_T_MEM;
  3144. mem_info = &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info;
  3145. mem_info->mem_type = BNA_MEM_T_KVA;
  3146. mem_info->len = page_count * sizeof(void *);
  3147. mem_info->num = num_txq;
  3148. res_info[BNA_TX_RES_MEM_T_PAGE].res_type = BNA_RES_T_MEM;
  3149. mem_info = &res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info;
  3150. mem_info->mem_type = BNA_MEM_T_DMA;
  3151. mem_info->len = PAGE_SIZE;
  3152. mem_info->num = num_txq * page_count;
  3153. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_type = BNA_RES_T_INTR;
  3154. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.intr_type =
  3155. BNA_INTR_T_MSIX;
  3156. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.num = num_txq;
  3157. }
  3158. struct bna_tx *
  3159. bna_tx_create(struct bna *bna, struct bnad *bnad,
  3160. struct bna_tx_config *tx_cfg,
  3161. struct bna_tx_event_cbfn *tx_cbfn,
  3162. struct bna_res_info *res_info, void *priv)
  3163. {
  3164. struct bna_intr_info *intr_info;
  3165. struct bna_tx_mod *tx_mod = &bna->tx_mod;
  3166. struct bna_tx *tx;
  3167. struct bna_txq *txq;
  3168. struct list_head *qe;
  3169. struct bna_ib_mod *ib_mod = &bna->ib_mod;
  3170. struct bna_doorbell_qset *qset;
  3171. struct bna_ib_config ib_config;
  3172. int page_count;
  3173. int page_size;
  3174. int page_idx;
  3175. int i;
  3176. unsigned long off;
  3177. intr_info = &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
  3178. page_count = (res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.num) /
  3179. tx_cfg->num_txq;
  3180. page_size = res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.len;
  3181. /**
  3182. * Get resources
  3183. */
  3184. if ((intr_info->num != 1) && (intr_info->num != tx_cfg->num_txq))
  3185. return NULL;
  3186. /* Tx */
  3187. if (list_empty(&tx_mod->tx_free_q))
  3188. return NULL;
  3189. bfa_q_deq(&tx_mod->tx_free_q, &tx);
  3190. bfa_q_qe_init(&tx->qe);
  3191. /* TxQs */
  3192. INIT_LIST_HEAD(&tx->txq_q);
  3193. for (i = 0; i < tx_cfg->num_txq; i++) {
  3194. if (list_empty(&tx_mod->txq_free_q))
  3195. goto err_return;
  3196. bfa_q_deq(&tx_mod->txq_free_q, &txq);
  3197. bfa_q_qe_init(&txq->qe);
  3198. list_add_tail(&txq->qe, &tx->txq_q);
  3199. txq->ib = NULL;
  3200. txq->ib_seg_offset = -1;
  3201. txq->tx = tx;
  3202. }
  3203. /* IBs */
  3204. i = 0;
  3205. list_for_each(qe, &tx->txq_q) {
  3206. txq = (struct bna_txq *)qe;
  3207. if (intr_info->num == 1)
  3208. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3209. intr_info->idl[0].vector);
  3210. else
  3211. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3212. intr_info->idl[i].vector);
  3213. if (txq->ib == NULL)
  3214. goto err_return;
  3215. txq->ib_seg_offset = bna_ib_reserve_idx(txq->ib);
  3216. if (txq->ib_seg_offset == -1)
  3217. goto err_return;
  3218. i++;
  3219. }
  3220. /*
  3221. * Initialize
  3222. */
  3223. /* Tx */
  3224. tx->tcb_setup_cbfn = tx_cbfn->tcb_setup_cbfn;
  3225. tx->tcb_destroy_cbfn = tx_cbfn->tcb_destroy_cbfn;
  3226. /* Following callbacks are mandatory */
  3227. tx->tx_stall_cbfn = tx_cbfn->tx_stall_cbfn;
  3228. tx->tx_resume_cbfn = tx_cbfn->tx_resume_cbfn;
  3229. tx->tx_cleanup_cbfn = tx_cbfn->tx_cleanup_cbfn;
  3230. list_add_tail(&tx->qe, &tx_mod->tx_active_q);
  3231. tx->bna = bna;
  3232. tx->priv = priv;
  3233. tx->txq_stop_wc.wc_resume = bna_tx_cb_txq_stopped_all;
  3234. tx->txq_stop_wc.wc_cbarg = tx;
  3235. tx->txq_stop_wc.wc_count = 0;
  3236. tx->type = tx_cfg->tx_type;
  3237. tx->flags = 0;
  3238. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_STARTED) {
  3239. switch (tx->type) {
  3240. case BNA_TX_T_REGULAR:
  3241. if (!(tx->bna->tx_mod.flags &
  3242. BNA_TX_MOD_F_PORT_LOOPBACK))
  3243. tx->flags |= BNA_TX_F_PORT_STARTED;
  3244. break;
  3245. case BNA_TX_T_LOOPBACK:
  3246. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_LOOPBACK)
  3247. tx->flags |= BNA_TX_F_PORT_STARTED;
  3248. break;
  3249. }
  3250. }
  3251. if (tx->bna->tx_mod.cee_link)
  3252. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3253. /* TxQ */
  3254. i = 0;
  3255. page_idx = 0;
  3256. list_for_each(qe, &tx->txq_q) {
  3257. txq = (struct bna_txq *)qe;
  3258. txq->priority = tx_mod->priority;
  3259. txq->tcb = (struct bna_tcb *)
  3260. res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info.mdl[i].kva;
  3261. txq->tx_packets = 0;
  3262. txq->tx_bytes = 0;
  3263. /* IB */
  3264. ib_config.coalescing_timeo = BFI_TX_COALESCING_TIMEO;
  3265. ib_config.interpkt_timeo = 0; /* Not used */
  3266. ib_config.interpkt_count = BFI_TX_INTERPKT_COUNT;
  3267. ib_config.ctrl_flags = (BFI_IB_CF_INTER_PKT_DMA |
  3268. BFI_IB_CF_INT_ENABLE |
  3269. BFI_IB_CF_COALESCING_MODE);
  3270. bna_ib_config(txq->ib, &ib_config);
  3271. /* TCB */
  3272. txq->tcb->producer_index = 0;
  3273. txq->tcb->consumer_index = 0;
  3274. txq->tcb->hw_consumer_index = (volatile u32 *)
  3275. ((volatile u8 *)txq->ib->ib_seg_host_addr_kva +
  3276. (txq->ib_seg_offset * BFI_IBIDX_SIZE));
  3277. *(txq->tcb->hw_consumer_index) = 0;
  3278. txq->tcb->q_depth = tx_cfg->txq_depth;
  3279. txq->tcb->unmap_q = (void *)
  3280. res_info[BNA_TX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[i].kva;
  3281. qset = (struct bna_doorbell_qset *)0;
  3282. off = (unsigned long)&qset[txq->txq_id].txq[0];
  3283. txq->tcb->q_dbell = off +
  3284. BNA_GET_DOORBELL_BASE_ADDR(bna->pcidev.pci_bar_kva);
  3285. txq->tcb->i_dbell = &txq->ib->door_bell;
  3286. txq->tcb->intr_type = intr_info->intr_type;
  3287. txq->tcb->intr_vector = (intr_info->num == 1) ?
  3288. intr_info->idl[0].vector :
  3289. intr_info->idl[i].vector;
  3290. txq->tcb->txq = txq;
  3291. txq->tcb->bnad = bnad;
  3292. txq->tcb->id = i;
  3293. /* QPT, SWQPT, Pages */
  3294. bna_txq_qpt_setup(txq, page_count, page_size,
  3295. &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info.mdl[i],
  3296. &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info.mdl[i],
  3297. &res_info[BNA_TX_RES_MEM_T_PAGE].
  3298. res_u.mem_info.mdl[page_idx]);
  3299. txq->tcb->page_idx = page_idx;
  3300. txq->tcb->page_count = page_count;
  3301. page_idx += page_count;
  3302. /* Callback to bnad for setting up TCB */
  3303. if (tx->tcb_setup_cbfn)
  3304. (tx->tcb_setup_cbfn)(bna->bnad, txq->tcb);
  3305. i++;
  3306. }
  3307. /* TxF */
  3308. tx->txf.ctrl_flags = BFI_TXF_CF_ENABLE | BFI_TXF_CF_VLAN_WI_BASED;
  3309. tx->txf.vlan = 0;
  3310. /* Mbox element */
  3311. bfa_q_qe_init(&tx->mbox_qe.qe);
  3312. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  3313. return tx;
  3314. err_return:
  3315. bna_tx_free(tx);
  3316. return NULL;
  3317. }
  3318. void
  3319. bna_tx_destroy(struct bna_tx *tx)
  3320. {
  3321. /* Callback to bnad for destroying TCB */
  3322. if (tx->tcb_destroy_cbfn) {
  3323. struct bna_txq *txq;
  3324. struct list_head *qe;
  3325. list_for_each(qe, &tx->txq_q) {
  3326. txq = (struct bna_txq *)qe;
  3327. (tx->tcb_destroy_cbfn)(tx->bna->bnad, txq->tcb);
  3328. }
  3329. }
  3330. bna_tx_free(tx);
  3331. }
  3332. void
  3333. bna_tx_enable(struct bna_tx *tx)
  3334. {
  3335. if (tx->fsm != (bfa_sm_t)bna_tx_sm_stopped)
  3336. return;
  3337. tx->flags |= BNA_TX_F_ENABLED;
  3338. if (tx->flags & BNA_TX_F_PORT_STARTED)
  3339. bfa_fsm_send_event(tx, TX_E_START);
  3340. }
  3341. void
  3342. bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
  3343. void (*cbfn)(void *, struct bna_tx *, enum bna_cb_status))
  3344. {
  3345. if (type == BNA_SOFT_CLEANUP) {
  3346. (*cbfn)(tx->bna->bnad, tx, BNA_CB_SUCCESS);
  3347. return;
  3348. }
  3349. tx->stop_cbfn = cbfn;
  3350. tx->stop_cbarg = tx->bna->bnad;
  3351. tx->flags &= ~BNA_TX_F_ENABLED;
  3352. bfa_fsm_send_event(tx, TX_E_STOP);
  3353. }
  3354. int
  3355. bna_tx_state_get(struct bna_tx *tx)
  3356. {
  3357. return bfa_sm_to_state(tx_sm_table, tx->fsm);
  3358. }
  3359. void
  3360. bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
  3361. struct bna_res_info *res_info)
  3362. {
  3363. int i;
  3364. tx_mod->bna = bna;
  3365. tx_mod->flags = 0;
  3366. tx_mod->tx = (struct bna_tx *)
  3367. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.mdl[0].kva;
  3368. tx_mod->txq = (struct bna_txq *)
  3369. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  3370. INIT_LIST_HEAD(&tx_mod->tx_free_q);
  3371. INIT_LIST_HEAD(&tx_mod->tx_active_q);
  3372. INIT_LIST_HEAD(&tx_mod->txq_free_q);
  3373. for (i = 0; i < BFI_MAX_TXQ; i++) {
  3374. tx_mod->tx[i].txf.txf_id = i;
  3375. bfa_q_qe_init(&tx_mod->tx[i].qe);
  3376. list_add_tail(&tx_mod->tx[i].qe, &tx_mod->tx_free_q);
  3377. tx_mod->txq[i].txq_id = i;
  3378. bfa_q_qe_init(&tx_mod->txq[i].qe);
  3379. list_add_tail(&tx_mod->txq[i].qe, &tx_mod->txq_free_q);
  3380. }
  3381. tx_mod->tx_stop_wc.wc_resume = bna_tx_mod_cb_tx_stopped_all;
  3382. tx_mod->tx_stop_wc.wc_cbarg = tx_mod;
  3383. tx_mod->tx_stop_wc.wc_count = 0;
  3384. }
  3385. void
  3386. bna_tx_mod_uninit(struct bna_tx_mod *tx_mod)
  3387. {
  3388. struct list_head *qe;
  3389. int i;
  3390. i = 0;
  3391. list_for_each(qe, &tx_mod->tx_free_q)
  3392. i++;
  3393. i = 0;
  3394. list_for_each(qe, &tx_mod->txq_free_q)
  3395. i++;
  3396. tx_mod->bna = NULL;
  3397. }
  3398. void
  3399. bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3400. {
  3401. struct bna_tx *tx;
  3402. struct list_head *qe;
  3403. tx_mod->flags |= BNA_TX_MOD_F_PORT_STARTED;
  3404. if (type == BNA_TX_T_LOOPBACK)
  3405. tx_mod->flags |= BNA_TX_MOD_F_PORT_LOOPBACK;
  3406. list_for_each(qe, &tx_mod->tx_active_q) {
  3407. tx = (struct bna_tx *)qe;
  3408. if (tx->type == type)
  3409. bna_tx_start(tx);
  3410. }
  3411. }
  3412. void
  3413. bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3414. {
  3415. struct bna_tx *tx;
  3416. struct list_head *qe;
  3417. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3418. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3419. tx_mod->stop_cbfn = bna_port_cb_tx_stopped;
  3420. /**
  3421. * Before calling bna_tx_stop(), increment tx_stop_wc as many times
  3422. * as we are going to call bna_tx_stop
  3423. */
  3424. list_for_each(qe, &tx_mod->tx_active_q) {
  3425. tx = (struct bna_tx *)qe;
  3426. if (tx->type == type)
  3427. bfa_wc_up(&tx_mod->tx_stop_wc);
  3428. }
  3429. if (tx_mod->tx_stop_wc.wc_count == 0) {
  3430. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3431. tx_mod->stop_cbfn = NULL;
  3432. return;
  3433. }
  3434. list_for_each(qe, &tx_mod->tx_active_q) {
  3435. tx = (struct bna_tx *)qe;
  3436. if (tx->type == type)
  3437. bna_tx_stop(tx);
  3438. }
  3439. }
  3440. void
  3441. bna_tx_mod_fail(struct bna_tx_mod *tx_mod)
  3442. {
  3443. struct bna_tx *tx;
  3444. struct list_head *qe;
  3445. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3446. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3447. list_for_each(qe, &tx_mod->tx_active_q) {
  3448. tx = (struct bna_tx *)qe;
  3449. bna_tx_fail(tx);
  3450. }
  3451. }
  3452. void
  3453. bna_tx_mod_prio_changed(struct bna_tx_mod *tx_mod, int prio)
  3454. {
  3455. struct bna_tx *tx;
  3456. struct list_head *qe;
  3457. if (prio != tx_mod->priority) {
  3458. tx_mod->priority = prio;
  3459. list_for_each(qe, &tx_mod->tx_active_q) {
  3460. tx = (struct bna_tx *)qe;
  3461. bna_tx_prio_changed(tx, prio);
  3462. }
  3463. }
  3464. }
  3465. void
  3466. bna_tx_mod_cee_link_status(struct bna_tx_mod *tx_mod, int cee_link)
  3467. {
  3468. struct bna_tx *tx;
  3469. struct list_head *qe;
  3470. tx_mod->cee_link = cee_link;
  3471. list_for_each(qe, &tx_mod->tx_active_q) {
  3472. tx = (struct bna_tx *)qe;
  3473. bna_tx_cee_link_status(tx, cee_link);
  3474. }
  3475. }