bna_txrx.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188
  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_vlan_filter_set(rxf, rxf->vlan_filter_status);
  1029. }
  1030. /* Apply RSS configuration */
  1031. if (rxf->rxf_flags & BNA_RXF_FL_RSS_CONFIG_PENDING) {
  1032. rxf->rxf_flags &= ~BNA_RXF_FL_RSS_CONFIG_PENDING;
  1033. if (rxf->rss_status == BNA_STATUS_T_DISABLED) {
  1034. /* RSS is being disabled */
  1035. rxf->ctrl_flags &= ~BNA_RXF_CF_RSS_ENABLE;
  1036. __rxf_rit_set(rxf);
  1037. __rxf_config_set(rxf);
  1038. } else {
  1039. /* RSS is being enabled or reconfigured */
  1040. rxf->ctrl_flags |= BNA_RXF_CF_RSS_ENABLE;
  1041. __rxf_rit_set(rxf);
  1042. __rxf_config_set(rxf);
  1043. }
  1044. }
  1045. return 0;
  1046. }
  1047. /**
  1048. * Processes pending ucast, mcast entry addition/deletion and issues mailbox
  1049. * command. Also processes pending filter configuration - promiscuous mode,
  1050. * default mode, allmutli mode and issues mailbox command or directly applies
  1051. * to h/w
  1052. */
  1053. static int
  1054. rxf_process_packet_filter(struct bna_rxf *rxf)
  1055. {
  1056. /* Set the default MAC first */
  1057. if (rxf->ucast_pending_set > 0) {
  1058. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_UCAST_SET_REQ,
  1059. rxf->ucast_active_mac);
  1060. rxf->ucast_pending_set--;
  1061. return 1;
  1062. }
  1063. if (rxf_process_packet_filter_ucast(rxf))
  1064. return 1;
  1065. if (rxf_process_packet_filter_mcast(rxf))
  1066. return 1;
  1067. if (rxf_process_packet_filter_promisc(rxf))
  1068. return 1;
  1069. if (rxf_process_packet_filter_allmulti(rxf))
  1070. return 1;
  1071. if (rxf_process_packet_filter_vlan(rxf))
  1072. return 1;
  1073. return 0;
  1074. }
  1075. static int
  1076. rxf_clear_packet_filter_mcast(struct bna_rxf *rxf)
  1077. {
  1078. struct bna_mac *mac = NULL;
  1079. struct list_head *qe;
  1080. /* 3. delete pending mcast entries */
  1081. if (!list_empty(&rxf->mcast_pending_del_q)) {
  1082. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1083. bfa_q_qe_init(qe);
  1084. mac = (struct bna_mac *)qe;
  1085. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1086. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1087. return 1;
  1088. }
  1089. /* 4. clear active mcast entries; move them to pending_add_q */
  1090. if (!list_empty(&rxf->mcast_active_q)) {
  1091. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1092. bfa_q_qe_init(qe);
  1093. mac = (struct bna_mac *)qe;
  1094. rxf_cam_mbox_cmd(rxf, BFI_LL_H2I_MAC_MCAST_DEL_REQ, mac);
  1095. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1096. return 1;
  1097. }
  1098. return 0;
  1099. }
  1100. /**
  1101. * In the rxf stop path, processes pending ucast/mcast delete queue and issues
  1102. * the mailbox command. Moves the active ucast/mcast entries to pending add q,
  1103. * so that they are added to CAM again in the rxf start path. Moves the current
  1104. * filter settings - promiscuous, default, allmutli - to pending filter
  1105. * configuration
  1106. */
  1107. static int
  1108. rxf_clear_packet_filter(struct bna_rxf *rxf)
  1109. {
  1110. if (rxf_clear_packet_filter_ucast(rxf))
  1111. return 1;
  1112. if (rxf_clear_packet_filter_mcast(rxf))
  1113. return 1;
  1114. /* 5. clear active default MAC in the CAM */
  1115. if (rxf->ucast_pending_set > 0)
  1116. rxf->ucast_pending_set = 0;
  1117. if (rxf_clear_packet_filter_promisc(rxf))
  1118. return 1;
  1119. if (rxf_clear_packet_filter_allmulti(rxf))
  1120. return 1;
  1121. return 0;
  1122. }
  1123. static void
  1124. rxf_reset_packet_filter_mcast(struct bna_rxf *rxf)
  1125. {
  1126. struct list_head *qe;
  1127. struct bna_mac *mac;
  1128. /* 3. Move active mcast entries to pending_add_q */
  1129. while (!list_empty(&rxf->mcast_active_q)) {
  1130. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1131. bfa_q_qe_init(qe);
  1132. list_add_tail(qe, &rxf->mcast_pending_add_q);
  1133. }
  1134. /* 4. Throw away delete pending mcast entries */
  1135. while (!list_empty(&rxf->mcast_pending_del_q)) {
  1136. bfa_q_deq(&rxf->mcast_pending_del_q, &qe);
  1137. bfa_q_qe_init(qe);
  1138. mac = (struct bna_mac *)qe;
  1139. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1140. }
  1141. }
  1142. /**
  1143. * In the rxf fail path, throws away the ucast/mcast entries pending for
  1144. * deletion, moves all active ucast/mcast entries to pending queue so that
  1145. * they are added back to CAM in the rxf start path. Also moves the current
  1146. * filter configuration to pending filter configuration.
  1147. */
  1148. static void
  1149. rxf_reset_packet_filter(struct bna_rxf *rxf)
  1150. {
  1151. rxf_reset_packet_filter_ucast(rxf);
  1152. rxf_reset_packet_filter_mcast(rxf);
  1153. /* 5. Turn off ucast set flag */
  1154. rxf->ucast_pending_set = 0;
  1155. rxf_reset_packet_filter_promisc(rxf);
  1156. rxf_reset_packet_filter_allmulti(rxf);
  1157. }
  1158. static void
  1159. bna_rxf_init(struct bna_rxf *rxf,
  1160. struct bna_rx *rx,
  1161. struct bna_rx_config *q_config)
  1162. {
  1163. struct list_head *qe;
  1164. struct bna_rxp *rxp;
  1165. /* rxf_id is initialized during rx_mod init */
  1166. rxf->rx = rx;
  1167. INIT_LIST_HEAD(&rxf->ucast_pending_add_q);
  1168. INIT_LIST_HEAD(&rxf->ucast_pending_del_q);
  1169. rxf->ucast_pending_set = 0;
  1170. INIT_LIST_HEAD(&rxf->ucast_active_q);
  1171. rxf->ucast_active_mac = NULL;
  1172. INIT_LIST_HEAD(&rxf->mcast_pending_add_q);
  1173. INIT_LIST_HEAD(&rxf->mcast_pending_del_q);
  1174. INIT_LIST_HEAD(&rxf->mcast_active_q);
  1175. bfa_q_qe_init(&rxf->mbox_qe.qe);
  1176. if (q_config->vlan_strip_status == BNA_STATUS_T_ENABLED)
  1177. rxf->ctrl_flags |= BNA_RXF_CF_VLAN_STRIP;
  1178. rxf->rxf_oper_state = (q_config->paused) ?
  1179. BNA_RXF_OPER_STATE_PAUSED : BNA_RXF_OPER_STATE_RUNNING;
  1180. bna_rxf_adv_init(rxf, rx, q_config);
  1181. rxf->rit_segment = bna_rit_mod_seg_get(&rxf->rx->bna->rit_mod,
  1182. q_config->num_paths);
  1183. list_for_each(qe, &rx->rxp_q) {
  1184. rxp = (struct bna_rxp *)qe;
  1185. if (q_config->rxp_type == BNA_RXP_SINGLE)
  1186. rxf->mcast_rxq_id = rxp->rxq.single.only->rxq_id;
  1187. else
  1188. rxf->mcast_rxq_id = rxp->rxq.slr.large->rxq_id;
  1189. break;
  1190. }
  1191. rxf->vlan_filter_status = BNA_STATUS_T_DISABLED;
  1192. memset(rxf->vlan_filter_table, 0,
  1193. (sizeof(u32) * ((BFI_MAX_VLAN + 1) / 32)));
  1194. /* Set up VLAN 0 for pure priority tagged packets */
  1195. rxf->vlan_filter_table[0] |= 1;
  1196. bfa_fsm_set_state(rxf, bna_rxf_sm_stopped);
  1197. }
  1198. static void
  1199. bna_rxf_uninit(struct bna_rxf *rxf)
  1200. {
  1201. struct bna *bna = rxf->rx->bna;
  1202. struct bna_mac *mac;
  1203. bna_rit_mod_seg_put(&rxf->rx->bna->rit_mod, rxf->rit_segment);
  1204. rxf->rit_segment = NULL;
  1205. rxf->ucast_pending_set = 0;
  1206. while (!list_empty(&rxf->ucast_pending_add_q)) {
  1207. bfa_q_deq(&rxf->ucast_pending_add_q, &mac);
  1208. bfa_q_qe_init(&mac->qe);
  1209. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod, mac);
  1210. }
  1211. if (rxf->ucast_active_mac) {
  1212. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1213. bna_ucam_mod_mac_put(&rxf->rx->bna->ucam_mod,
  1214. rxf->ucast_active_mac);
  1215. rxf->ucast_active_mac = NULL;
  1216. }
  1217. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1218. bfa_q_deq(&rxf->mcast_pending_add_q, &mac);
  1219. bfa_q_qe_init(&mac->qe);
  1220. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1221. }
  1222. /* Turn off pending promisc mode */
  1223. if (is_promisc_enable(rxf->rxmode_pending,
  1224. rxf->rxmode_pending_bitmask)) {
  1225. /* system promisc state should be pending */
  1226. BUG_ON(!(bna->rxf_promisc_id == rxf->rxf_id));
  1227. promisc_inactive(rxf->rxmode_pending,
  1228. rxf->rxmode_pending_bitmask);
  1229. bna->rxf_promisc_id = BFI_MAX_RXF;
  1230. }
  1231. /* Promisc mode should not be active */
  1232. BUG_ON(rxf->rxmode_active & BNA_RXMODE_PROMISC);
  1233. /* Turn off pending all-multi mode */
  1234. if (is_allmulti_enable(rxf->rxmode_pending,
  1235. rxf->rxmode_pending_bitmask)) {
  1236. allmulti_inactive(rxf->rxmode_pending,
  1237. rxf->rxmode_pending_bitmask);
  1238. }
  1239. /* Allmulti mode should not be active */
  1240. BUG_ON(rxf->rxmode_active & BNA_RXMODE_ALLMULTI);
  1241. rxf->rx = NULL;
  1242. }
  1243. static void
  1244. bna_rx_cb_rxf_started(struct bna_rx *rx, enum bna_cb_status status)
  1245. {
  1246. bfa_fsm_send_event(rx, RX_E_RXF_STARTED);
  1247. if (rx->rxf.rxf_id < 32)
  1248. rx->bna->rx_mod.rxf_bmap[0] |= ((u32)1 << rx->rxf.rxf_id);
  1249. else
  1250. rx->bna->rx_mod.rxf_bmap[1] |= ((u32)
  1251. 1 << (rx->rxf.rxf_id - 32));
  1252. }
  1253. static void
  1254. bna_rxf_start(struct bna_rxf *rxf)
  1255. {
  1256. rxf->start_cbfn = bna_rx_cb_rxf_started;
  1257. rxf->start_cbarg = rxf->rx;
  1258. rxf->rxf_flags &= ~BNA_RXF_FL_FAILED;
  1259. bfa_fsm_send_event(rxf, RXF_E_START);
  1260. }
  1261. static void
  1262. bna_rx_cb_rxf_stopped(struct bna_rx *rx, enum bna_cb_status status)
  1263. {
  1264. bfa_fsm_send_event(rx, RX_E_RXF_STOPPED);
  1265. if (rx->rxf.rxf_id < 32)
  1266. rx->bna->rx_mod.rxf_bmap[0] &= ~(u32)1 << rx->rxf.rxf_id;
  1267. else
  1268. rx->bna->rx_mod.rxf_bmap[1] &= ~(u32)
  1269. 1 << (rx->rxf.rxf_id - 32);
  1270. }
  1271. static void
  1272. bna_rxf_stop(struct bna_rxf *rxf)
  1273. {
  1274. rxf->stop_cbfn = bna_rx_cb_rxf_stopped;
  1275. rxf->stop_cbarg = rxf->rx;
  1276. bfa_fsm_send_event(rxf, RXF_E_STOP);
  1277. }
  1278. static void
  1279. bna_rxf_fail(struct bna_rxf *rxf)
  1280. {
  1281. rxf->rxf_flags |= BNA_RXF_FL_FAILED;
  1282. bfa_fsm_send_event(rxf, RXF_E_FAIL);
  1283. }
  1284. int
  1285. bna_rxf_state_get(struct bna_rxf *rxf)
  1286. {
  1287. return bfa_sm_to_state(rxf_sm_table, rxf->fsm);
  1288. }
  1289. enum bna_cb_status
  1290. bna_rx_ucast_set(struct bna_rx *rx, u8 *ucmac,
  1291. void (*cbfn)(struct bnad *, struct bna_rx *,
  1292. enum bna_cb_status))
  1293. {
  1294. struct bna_rxf *rxf = &rx->rxf;
  1295. if (rxf->ucast_active_mac == NULL) {
  1296. rxf->ucast_active_mac =
  1297. bna_ucam_mod_mac_get(&rxf->rx->bna->ucam_mod);
  1298. if (rxf->ucast_active_mac == NULL)
  1299. return BNA_CB_UCAST_CAM_FULL;
  1300. bfa_q_qe_init(&rxf->ucast_active_mac->qe);
  1301. }
  1302. memcpy(rxf->ucast_active_mac->addr, ucmac, ETH_ALEN);
  1303. rxf->ucast_pending_set++;
  1304. rxf->cam_fltr_cbfn = cbfn;
  1305. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1306. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1307. return BNA_CB_SUCCESS;
  1308. }
  1309. enum bna_cb_status
  1310. bna_rx_mcast_add(struct bna_rx *rx, u8 *addr,
  1311. void (*cbfn)(struct bnad *, struct bna_rx *,
  1312. enum bna_cb_status))
  1313. {
  1314. struct bna_rxf *rxf = &rx->rxf;
  1315. struct list_head *qe;
  1316. struct bna_mac *mac;
  1317. /* Check if already added */
  1318. list_for_each(qe, &rxf->mcast_active_q) {
  1319. mac = (struct bna_mac *)qe;
  1320. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1321. if (cbfn)
  1322. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1323. return BNA_CB_SUCCESS;
  1324. }
  1325. }
  1326. /* Check if pending addition */
  1327. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1328. mac = (struct bna_mac *)qe;
  1329. if (BNA_MAC_IS_EQUAL(mac->addr, addr)) {
  1330. if (cbfn)
  1331. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1332. return BNA_CB_SUCCESS;
  1333. }
  1334. }
  1335. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1336. if (mac == NULL)
  1337. return BNA_CB_MCAST_LIST_FULL;
  1338. bfa_q_qe_init(&mac->qe);
  1339. memcpy(mac->addr, addr, ETH_ALEN);
  1340. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1341. rxf->cam_fltr_cbfn = cbfn;
  1342. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1343. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1344. return BNA_CB_SUCCESS;
  1345. }
  1346. enum bna_cb_status
  1347. bna_rx_mcast_listset(struct bna_rx *rx, int count, u8 *mclist,
  1348. void (*cbfn)(struct bnad *, struct bna_rx *,
  1349. enum bna_cb_status))
  1350. {
  1351. struct bna_rxf *rxf = &rx->rxf;
  1352. struct list_head list_head;
  1353. struct list_head *qe;
  1354. u8 *mcaddr;
  1355. struct bna_mac *mac;
  1356. struct bna_mac *mac1;
  1357. int skip;
  1358. int delete;
  1359. int need_hw_config = 0;
  1360. int i;
  1361. /* Allocate nodes */
  1362. INIT_LIST_HEAD(&list_head);
  1363. for (i = 0, mcaddr = mclist; i < count; i++) {
  1364. mac = bna_mcam_mod_mac_get(&rxf->rx->bna->mcam_mod);
  1365. if (mac == NULL)
  1366. goto err_return;
  1367. bfa_q_qe_init(&mac->qe);
  1368. memcpy(mac->addr, mcaddr, ETH_ALEN);
  1369. list_add_tail(&mac->qe, &list_head);
  1370. mcaddr += ETH_ALEN;
  1371. }
  1372. /* Schedule for addition */
  1373. while (!list_empty(&list_head)) {
  1374. bfa_q_deq(&list_head, &qe);
  1375. mac = (struct bna_mac *)qe;
  1376. bfa_q_qe_init(&mac->qe);
  1377. skip = 0;
  1378. /* Skip if already added */
  1379. list_for_each(qe, &rxf->mcast_active_q) {
  1380. mac1 = (struct bna_mac *)qe;
  1381. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1382. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1383. mac);
  1384. skip = 1;
  1385. break;
  1386. }
  1387. }
  1388. if (skip)
  1389. continue;
  1390. /* Skip if pending addition */
  1391. list_for_each(qe, &rxf->mcast_pending_add_q) {
  1392. mac1 = (struct bna_mac *)qe;
  1393. if (BNA_MAC_IS_EQUAL(mac1->addr, mac->addr)) {
  1394. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod,
  1395. mac);
  1396. skip = 1;
  1397. break;
  1398. }
  1399. }
  1400. if (skip)
  1401. continue;
  1402. need_hw_config = 1;
  1403. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1404. }
  1405. /**
  1406. * Delete the entries that are in the pending_add_q but not
  1407. * in the new list
  1408. */
  1409. while (!list_empty(&rxf->mcast_pending_add_q)) {
  1410. bfa_q_deq(&rxf->mcast_pending_add_q, &qe);
  1411. mac = (struct bna_mac *)qe;
  1412. bfa_q_qe_init(&mac->qe);
  1413. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1414. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1415. delete = 0;
  1416. break;
  1417. }
  1418. mcaddr += ETH_ALEN;
  1419. }
  1420. if (delete)
  1421. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1422. else
  1423. list_add_tail(&mac->qe, &list_head);
  1424. }
  1425. while (!list_empty(&list_head)) {
  1426. bfa_q_deq(&list_head, &qe);
  1427. mac = (struct bna_mac *)qe;
  1428. bfa_q_qe_init(&mac->qe);
  1429. list_add_tail(&mac->qe, &rxf->mcast_pending_add_q);
  1430. }
  1431. /**
  1432. * Schedule entries for deletion that are in the active_q but not
  1433. * in the new list
  1434. */
  1435. while (!list_empty(&rxf->mcast_active_q)) {
  1436. bfa_q_deq(&rxf->mcast_active_q, &qe);
  1437. mac = (struct bna_mac *)qe;
  1438. bfa_q_qe_init(&mac->qe);
  1439. for (i = 0, mcaddr = mclist, delete = 1; i < count; i++) {
  1440. if (BNA_MAC_IS_EQUAL(mcaddr, mac->addr)) {
  1441. delete = 0;
  1442. break;
  1443. }
  1444. mcaddr += ETH_ALEN;
  1445. }
  1446. if (delete) {
  1447. list_add_tail(&mac->qe, &rxf->mcast_pending_del_q);
  1448. need_hw_config = 1;
  1449. } else {
  1450. list_add_tail(&mac->qe, &list_head);
  1451. }
  1452. }
  1453. while (!list_empty(&list_head)) {
  1454. bfa_q_deq(&list_head, &qe);
  1455. mac = (struct bna_mac *)qe;
  1456. bfa_q_qe_init(&mac->qe);
  1457. list_add_tail(&mac->qe, &rxf->mcast_active_q);
  1458. }
  1459. if (need_hw_config) {
  1460. rxf->cam_fltr_cbfn = cbfn;
  1461. rxf->cam_fltr_cbarg = rx->bna->bnad;
  1462. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1463. } else if (cbfn)
  1464. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  1465. return BNA_CB_SUCCESS;
  1466. err_return:
  1467. while (!list_empty(&list_head)) {
  1468. bfa_q_deq(&list_head, &qe);
  1469. mac = (struct bna_mac *)qe;
  1470. bfa_q_qe_init(&mac->qe);
  1471. bna_mcam_mod_mac_put(&rxf->rx->bna->mcam_mod, mac);
  1472. }
  1473. return BNA_CB_MCAST_LIST_FULL;
  1474. }
  1475. void
  1476. bna_rx_vlan_add(struct bna_rx *rx, int vlan_id)
  1477. {
  1478. struct bna_rxf *rxf = &rx->rxf;
  1479. int index = (vlan_id >> 5);
  1480. int bit = (1 << (vlan_id & 0x1F));
  1481. rxf->vlan_filter_table[index] |= bit;
  1482. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1483. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1484. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1485. }
  1486. }
  1487. void
  1488. bna_rx_vlan_del(struct bna_rx *rx, int vlan_id)
  1489. {
  1490. struct bna_rxf *rxf = &rx->rxf;
  1491. int index = (vlan_id >> 5);
  1492. int bit = (1 << (vlan_id & 0x1F));
  1493. rxf->vlan_filter_table[index] &= ~bit;
  1494. if (rxf->vlan_filter_status == BNA_STATUS_T_ENABLED) {
  1495. rxf->rxf_flags |= BNA_RXF_FL_VLAN_CONFIG_PENDING;
  1496. bfa_fsm_send_event(rxf, RXF_E_CAM_FLTR_MOD);
  1497. }
  1498. }
  1499. /**
  1500. * RX
  1501. */
  1502. #define RXQ_RCB_INIT(q, rxp, qdepth, bna, _id, unmapq_mem) do { \
  1503. struct bna_doorbell_qset *_qset; \
  1504. unsigned long off; \
  1505. (q)->rcb->producer_index = (q)->rcb->consumer_index = 0; \
  1506. (q)->rcb->q_depth = (qdepth); \
  1507. (q)->rcb->unmap_q = unmapq_mem; \
  1508. (q)->rcb->rxq = (q); \
  1509. (q)->rcb->cq = &(rxp)->cq; \
  1510. (q)->rcb->bnad = (bna)->bnad; \
  1511. _qset = (struct bna_doorbell_qset *)0; \
  1512. off = (unsigned long)&_qset[(q)->rxq_id].rxq[0]; \
  1513. (q)->rcb->q_dbell = off + \
  1514. BNA_GET_DOORBELL_BASE_ADDR((bna)->pcidev.pci_bar_kva); \
  1515. (q)->rcb->id = _id; \
  1516. } while (0)
  1517. #define BNA_GET_RXQS(qcfg) (((qcfg)->rxp_type == BNA_RXP_SINGLE) ? \
  1518. (qcfg)->num_paths : ((qcfg)->num_paths * 2))
  1519. #define SIZE_TO_PAGES(size) (((size) >> PAGE_SHIFT) + ((((size) &\
  1520. (PAGE_SIZE - 1)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
  1521. #define call_rx_stop_callback(rx, status) \
  1522. if ((rx)->stop_cbfn) { \
  1523. (*(rx)->stop_cbfn)((rx)->stop_cbarg, rx, (status)); \
  1524. (rx)->stop_cbfn = NULL; \
  1525. (rx)->stop_cbarg = NULL; \
  1526. }
  1527. /*
  1528. * Since rx_enable is synchronous callback, there is no start_cbfn required.
  1529. * Instead, we'll call bnad_rx_post(rxp) so that bnad can post the buffers
  1530. * for each rxpath.
  1531. */
  1532. #define call_rx_disable_cbfn(rx, status) \
  1533. if ((rx)->disable_cbfn) { \
  1534. (*(rx)->disable_cbfn)((rx)->disable_cbarg, \
  1535. status); \
  1536. (rx)->disable_cbfn = NULL; \
  1537. (rx)->disable_cbarg = NULL; \
  1538. } \
  1539. #define rxqs_reqd(type, num_rxqs) \
  1540. (((type) == BNA_RXP_SINGLE) ? (num_rxqs) : ((num_rxqs) * 2))
  1541. #define rx_ib_fail(rx) \
  1542. do { \
  1543. struct bna_rxp *rxp; \
  1544. struct list_head *qe; \
  1545. list_for_each(qe, &(rx)->rxp_q) { \
  1546. rxp = (struct bna_rxp *)qe; \
  1547. bna_ib_fail(rxp->cq.ib); \
  1548. } \
  1549. } while (0)
  1550. static void __bna_multi_rxq_stop(struct bna_rxp *, u32 *);
  1551. static void __bna_rxq_start(struct bna_rxq *rxq);
  1552. static void __bna_cq_start(struct bna_cq *cq);
  1553. static void bna_rit_create(struct bna_rx *rx);
  1554. static void bna_rx_cb_multi_rxq_stopped(void *arg, int status);
  1555. static void bna_rx_cb_rxq_stopped_all(void *arg);
  1556. bfa_fsm_state_decl(bna_rx, stopped,
  1557. struct bna_rx, enum bna_rx_event);
  1558. bfa_fsm_state_decl(bna_rx, rxf_start_wait,
  1559. struct bna_rx, enum bna_rx_event);
  1560. bfa_fsm_state_decl(bna_rx, started,
  1561. struct bna_rx, enum bna_rx_event);
  1562. bfa_fsm_state_decl(bna_rx, rxf_stop_wait,
  1563. struct bna_rx, enum bna_rx_event);
  1564. bfa_fsm_state_decl(bna_rx, rxq_stop_wait,
  1565. struct bna_rx, enum bna_rx_event);
  1566. static const struct bfa_sm_table rx_sm_table[] = {
  1567. {BFA_SM(bna_rx_sm_stopped), BNA_RX_STOPPED},
  1568. {BFA_SM(bna_rx_sm_rxf_start_wait), BNA_RX_RXF_START_WAIT},
  1569. {BFA_SM(bna_rx_sm_started), BNA_RX_STARTED},
  1570. {BFA_SM(bna_rx_sm_rxf_stop_wait), BNA_RX_RXF_STOP_WAIT},
  1571. {BFA_SM(bna_rx_sm_rxq_stop_wait), BNA_RX_RXQ_STOP_WAIT},
  1572. };
  1573. static void bna_rx_sm_stopped_entry(struct bna_rx *rx)
  1574. {
  1575. struct bna_rxp *rxp;
  1576. struct list_head *qe_rxp;
  1577. list_for_each(qe_rxp, &rx->rxp_q) {
  1578. rxp = (struct bna_rxp *)qe_rxp;
  1579. rx->rx_cleanup_cbfn(rx->bna->bnad, rxp->cq.ccb);
  1580. }
  1581. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1582. }
  1583. static void bna_rx_sm_stopped(struct bna_rx *rx,
  1584. enum bna_rx_event event)
  1585. {
  1586. switch (event) {
  1587. case RX_E_START:
  1588. bfa_fsm_set_state(rx, bna_rx_sm_rxf_start_wait);
  1589. break;
  1590. case RX_E_STOP:
  1591. call_rx_stop_callback(rx, BNA_CB_SUCCESS);
  1592. break;
  1593. case RX_E_FAIL:
  1594. /* no-op */
  1595. break;
  1596. default:
  1597. bfa_sm_fault(rx->bna, event);
  1598. break;
  1599. }
  1600. }
  1601. static void bna_rx_sm_rxf_start_wait_entry(struct bna_rx *rx)
  1602. {
  1603. struct bna_rxp *rxp;
  1604. struct list_head *qe_rxp;
  1605. struct bna_rxq *q0 = NULL, *q1 = NULL;
  1606. /* Setup the RIT */
  1607. bna_rit_create(rx);
  1608. list_for_each(qe_rxp, &rx->rxp_q) {
  1609. rxp = (struct bna_rxp *)qe_rxp;
  1610. bna_ib_start(rxp->cq.ib);
  1611. GET_RXQS(rxp, q0, q1);
  1612. q0->buffer_size = bna_port_mtu_get(&rx->bna->port);
  1613. __bna_rxq_start(q0);
  1614. rx->rx_post_cbfn(rx->bna->bnad, q0->rcb);
  1615. if (q1) {
  1616. __bna_rxq_start(q1);
  1617. rx->rx_post_cbfn(rx->bna->bnad, q1->rcb);
  1618. }
  1619. __bna_cq_start(&rxp->cq);
  1620. }
  1621. bna_rxf_start(&rx->rxf);
  1622. }
  1623. static void bna_rx_sm_rxf_start_wait(struct bna_rx *rx,
  1624. enum bna_rx_event event)
  1625. {
  1626. switch (event) {
  1627. case RX_E_STOP:
  1628. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1629. break;
  1630. case RX_E_FAIL:
  1631. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1632. rx_ib_fail(rx);
  1633. bna_rxf_fail(&rx->rxf);
  1634. break;
  1635. case RX_E_RXF_STARTED:
  1636. bfa_fsm_set_state(rx, bna_rx_sm_started);
  1637. break;
  1638. default:
  1639. bfa_sm_fault(rx->bna, event);
  1640. break;
  1641. }
  1642. }
  1643. void
  1644. bna_rx_sm_started_entry(struct bna_rx *rx)
  1645. {
  1646. struct bna_rxp *rxp;
  1647. struct list_head *qe_rxp;
  1648. /* Start IB */
  1649. list_for_each(qe_rxp, &rx->rxp_q) {
  1650. rxp = (struct bna_rxp *)qe_rxp;
  1651. bna_ib_ack(&rxp->cq.ib->door_bell, 0);
  1652. }
  1653. bna_llport_rx_started(&rx->bna->port.llport);
  1654. }
  1655. void
  1656. bna_rx_sm_started(struct bna_rx *rx, enum bna_rx_event event)
  1657. {
  1658. switch (event) {
  1659. case RX_E_FAIL:
  1660. bna_llport_rx_stopped(&rx->bna->port.llport);
  1661. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1662. rx_ib_fail(rx);
  1663. bna_rxf_fail(&rx->rxf);
  1664. break;
  1665. case RX_E_STOP:
  1666. bna_llport_rx_stopped(&rx->bna->port.llport);
  1667. bfa_fsm_set_state(rx, bna_rx_sm_rxf_stop_wait);
  1668. break;
  1669. default:
  1670. bfa_sm_fault(rx->bna, event);
  1671. break;
  1672. }
  1673. }
  1674. void
  1675. bna_rx_sm_rxf_stop_wait_entry(struct bna_rx *rx)
  1676. {
  1677. bna_rxf_stop(&rx->rxf);
  1678. }
  1679. void
  1680. bna_rx_sm_rxf_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1681. {
  1682. switch (event) {
  1683. case RX_E_RXF_STOPPED:
  1684. bfa_fsm_set_state(rx, bna_rx_sm_rxq_stop_wait);
  1685. break;
  1686. case RX_E_RXF_STARTED:
  1687. /**
  1688. * RxF was in the process of starting up when
  1689. * RXF_E_STOP was issued. Ignore this event
  1690. */
  1691. break;
  1692. case RX_E_FAIL:
  1693. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1694. rx_ib_fail(rx);
  1695. bna_rxf_fail(&rx->rxf);
  1696. break;
  1697. default:
  1698. bfa_sm_fault(rx->bna, event);
  1699. break;
  1700. }
  1701. }
  1702. void
  1703. bna_rx_sm_rxq_stop_wait_entry(struct bna_rx *rx)
  1704. {
  1705. struct bna_rxp *rxp = NULL;
  1706. struct bna_rxq *q0 = NULL;
  1707. struct bna_rxq *q1 = NULL;
  1708. struct list_head *qe;
  1709. u32 rxq_mask[2] = {0, 0};
  1710. /* Only one call to multi-rxq-stop for all RXPs in this RX */
  1711. bfa_wc_up(&rx->rxq_stop_wc);
  1712. list_for_each(qe, &rx->rxp_q) {
  1713. rxp = (struct bna_rxp *)qe;
  1714. GET_RXQS(rxp, q0, q1);
  1715. if (q0->rxq_id < 32)
  1716. rxq_mask[0] |= ((u32)1 << q0->rxq_id);
  1717. else
  1718. rxq_mask[1] |= ((u32)1 << (q0->rxq_id - 32));
  1719. if (q1) {
  1720. if (q1->rxq_id < 32)
  1721. rxq_mask[0] |= ((u32)1 << q1->rxq_id);
  1722. else
  1723. rxq_mask[1] |= ((u32)
  1724. 1 << (q1->rxq_id - 32));
  1725. }
  1726. }
  1727. __bna_multi_rxq_stop(rxp, rxq_mask);
  1728. }
  1729. void
  1730. bna_rx_sm_rxq_stop_wait(struct bna_rx *rx, enum bna_rx_event event)
  1731. {
  1732. struct bna_rxp *rxp = NULL;
  1733. struct list_head *qe;
  1734. switch (event) {
  1735. case RX_E_RXQ_STOPPED:
  1736. list_for_each(qe, &rx->rxp_q) {
  1737. rxp = (struct bna_rxp *)qe;
  1738. bna_ib_stop(rxp->cq.ib);
  1739. }
  1740. /* Fall through */
  1741. case RX_E_FAIL:
  1742. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  1743. break;
  1744. default:
  1745. bfa_sm_fault(rx->bna, event);
  1746. break;
  1747. }
  1748. }
  1749. void
  1750. __bna_multi_rxq_stop(struct bna_rxp *rxp, u32 * rxq_id_mask)
  1751. {
  1752. struct bfi_ll_q_stop_req ll_req;
  1753. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_RXQ_STOP_REQ, 0);
  1754. ll_req.q_id_mask[0] = htonl(rxq_id_mask[0]);
  1755. ll_req.q_id_mask[1] = htonl(rxq_id_mask[1]);
  1756. bna_mbox_qe_fill(&rxp->mbox_qe, &ll_req, sizeof(ll_req),
  1757. bna_rx_cb_multi_rxq_stopped, rxp);
  1758. bna_mbox_send(rxp->rx->bna, &rxp->mbox_qe);
  1759. }
  1760. void
  1761. __bna_rxq_start(struct bna_rxq *rxq)
  1762. {
  1763. struct bna_rxtx_q_mem *q_mem;
  1764. struct bna_rxq_mem rxq_cfg, *rxq_mem;
  1765. struct bna_dma_addr cur_q_addr;
  1766. /* struct bna_doorbell_qset *qset; */
  1767. struct bna_qpt *qpt;
  1768. u32 pg_num;
  1769. struct bna *bna = rxq->rx->bna;
  1770. void __iomem *base_addr;
  1771. unsigned long off;
  1772. qpt = &rxq->qpt;
  1773. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1774. rxq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1775. rxq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1776. rxq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1777. rxq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1778. rxq_cfg.pg_cnt_n_prd_ptr = ((u32)qpt->page_count << 16) | 0x0;
  1779. rxq_cfg.entry_n_pg_size = ((u32)(BFI_RXQ_WI_SIZE >> 2) << 16) |
  1780. (qpt->page_size >> 2);
  1781. rxq_cfg.sg_n_cq_n_cns_ptr =
  1782. ((u32)(rxq->rxp->cq.cq_id & 0xff) << 16) | 0x0;
  1783. rxq_cfg.buf_sz_n_q_state = ((u32)rxq->buffer_size << 16) |
  1784. BNA_Q_IDLE_STATE;
  1785. rxq_cfg.next_qid = 0x0 | (0x3 << 8);
  1786. /* Write the page number register */
  1787. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1788. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1789. writel(pg_num, bna->regs.page_addr);
  1790. /* Write to h/w */
  1791. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1792. HQM_RXTX_Q_RAM_BASE_OFFSET);
  1793. q_mem = (struct bna_rxtx_q_mem *)0;
  1794. rxq_mem = &q_mem[rxq->rxq_id].rxq;
  1795. off = (unsigned long)&rxq_mem->pg_tbl_addr_lo;
  1796. writel(htonl(rxq_cfg.pg_tbl_addr_lo), base_addr + off);
  1797. off = (unsigned long)&rxq_mem->pg_tbl_addr_hi;
  1798. writel(htonl(rxq_cfg.pg_tbl_addr_hi), base_addr + off);
  1799. off = (unsigned long)&rxq_mem->cur_q_entry_lo;
  1800. writel(htonl(rxq_cfg.cur_q_entry_lo), base_addr + off);
  1801. off = (unsigned long)&rxq_mem->cur_q_entry_hi;
  1802. writel(htonl(rxq_cfg.cur_q_entry_hi), base_addr + off);
  1803. off = (unsigned long)&rxq_mem->pg_cnt_n_prd_ptr;
  1804. writel(rxq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1805. off = (unsigned long)&rxq_mem->entry_n_pg_size;
  1806. writel(rxq_cfg.entry_n_pg_size, base_addr + off);
  1807. off = (unsigned long)&rxq_mem->sg_n_cq_n_cns_ptr;
  1808. writel(rxq_cfg.sg_n_cq_n_cns_ptr, base_addr + off);
  1809. off = (unsigned long)&rxq_mem->buf_sz_n_q_state;
  1810. writel(rxq_cfg.buf_sz_n_q_state, base_addr + off);
  1811. off = (unsigned long)&rxq_mem->next_qid;
  1812. writel(rxq_cfg.next_qid, base_addr + off);
  1813. rxq->rcb->producer_index = 0;
  1814. rxq->rcb->consumer_index = 0;
  1815. }
  1816. void
  1817. __bna_cq_start(struct bna_cq *cq)
  1818. {
  1819. struct bna_cq_mem cq_cfg, *cq_mem;
  1820. const struct bna_qpt *qpt;
  1821. struct bna_dma_addr cur_q_addr;
  1822. u32 pg_num;
  1823. struct bna *bna = cq->rx->bna;
  1824. void __iomem *base_addr;
  1825. unsigned long off;
  1826. qpt = &cq->qpt;
  1827. cur_q_addr = *((struct bna_dma_addr *)(qpt->kv_qpt_ptr));
  1828. /*
  1829. * Fill out structure, to be subsequently written
  1830. * to hardware
  1831. */
  1832. cq_cfg.pg_tbl_addr_lo = qpt->hw_qpt_ptr.lsb;
  1833. cq_cfg.pg_tbl_addr_hi = qpt->hw_qpt_ptr.msb;
  1834. cq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  1835. cq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  1836. cq_cfg.pg_cnt_n_prd_ptr = (qpt->page_count << 16) | 0x0;
  1837. cq_cfg.entry_n_pg_size =
  1838. ((u32)(BFI_CQ_WI_SIZE >> 2) << 16) | (qpt->page_size >> 2);
  1839. cq_cfg.int_blk_n_cns_ptr = ((((u32)cq->ib_seg_offset) << 24) |
  1840. ((u32)(cq->ib->ib_id & 0xff) << 16) | 0x0);
  1841. cq_cfg.q_state = BNA_Q_IDLE_STATE;
  1842. /* Write the page number register */
  1843. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + bna->port_num,
  1844. HQM_CQ_RAM_BASE_OFFSET);
  1845. writel(pg_num, bna->regs.page_addr);
  1846. /* H/W write */
  1847. base_addr = BNA_GET_MEM_BASE_ADDR(bna->pcidev.pci_bar_kva,
  1848. HQM_CQ_RAM_BASE_OFFSET);
  1849. cq_mem = (struct bna_cq_mem *)0;
  1850. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_lo;
  1851. writel(htonl(cq_cfg.pg_tbl_addr_lo), base_addr + off);
  1852. off = (unsigned long)&cq_mem[cq->cq_id].pg_tbl_addr_hi;
  1853. writel(htonl(cq_cfg.pg_tbl_addr_hi), base_addr + off);
  1854. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_lo;
  1855. writel(htonl(cq_cfg.cur_q_entry_lo), base_addr + off);
  1856. off = (unsigned long)&cq_mem[cq->cq_id].cur_q_entry_hi;
  1857. writel(htonl(cq_cfg.cur_q_entry_hi), base_addr + off);
  1858. off = (unsigned long)&cq_mem[cq->cq_id].pg_cnt_n_prd_ptr;
  1859. writel(cq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  1860. off = (unsigned long)&cq_mem[cq->cq_id].entry_n_pg_size;
  1861. writel(cq_cfg.entry_n_pg_size, base_addr + off);
  1862. off = (unsigned long)&cq_mem[cq->cq_id].int_blk_n_cns_ptr;
  1863. writel(cq_cfg.int_blk_n_cns_ptr, base_addr + off);
  1864. off = (unsigned long)&cq_mem[cq->cq_id].q_state;
  1865. writel(cq_cfg.q_state, base_addr + off);
  1866. cq->ccb->producer_index = 0;
  1867. *(cq->ccb->hw_producer_index) = 0;
  1868. }
  1869. void
  1870. bna_rit_create(struct bna_rx *rx)
  1871. {
  1872. struct list_head *qe_rxp;
  1873. struct bna *bna;
  1874. struct bna_rxp *rxp;
  1875. struct bna_rxq *q0 = NULL;
  1876. struct bna_rxq *q1 = NULL;
  1877. int offset;
  1878. bna = rx->bna;
  1879. offset = 0;
  1880. list_for_each(qe_rxp, &rx->rxp_q) {
  1881. rxp = (struct bna_rxp *)qe_rxp;
  1882. GET_RXQS(rxp, q0, q1);
  1883. rx->rxf.rit_segment->rit[offset].large_rxq_id = q0->rxq_id;
  1884. rx->rxf.rit_segment->rit[offset].small_rxq_id =
  1885. (q1 ? q1->rxq_id : 0);
  1886. offset++;
  1887. }
  1888. }
  1889. static int
  1890. _rx_can_satisfy(struct bna_rx_mod *rx_mod,
  1891. struct bna_rx_config *rx_cfg)
  1892. {
  1893. if ((rx_mod->rx_free_count == 0) ||
  1894. (rx_mod->rxp_free_count == 0) ||
  1895. (rx_mod->rxq_free_count == 0))
  1896. return 0;
  1897. if (rx_cfg->rxp_type == BNA_RXP_SINGLE) {
  1898. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1899. (rx_mod->rxq_free_count < rx_cfg->num_paths))
  1900. return 0;
  1901. } else {
  1902. if ((rx_mod->rxp_free_count < rx_cfg->num_paths) ||
  1903. (rx_mod->rxq_free_count < (2 * rx_cfg->num_paths)))
  1904. return 0;
  1905. }
  1906. if (!bna_rit_mod_can_satisfy(&rx_mod->bna->rit_mod, rx_cfg->num_paths))
  1907. return 0;
  1908. return 1;
  1909. }
  1910. static struct bna_rxq *
  1911. _get_free_rxq(struct bna_rx_mod *rx_mod)
  1912. {
  1913. struct bna_rxq *rxq = NULL;
  1914. struct list_head *qe = NULL;
  1915. bfa_q_deq(&rx_mod->rxq_free_q, &qe);
  1916. if (qe) {
  1917. rx_mod->rxq_free_count--;
  1918. rxq = (struct bna_rxq *)qe;
  1919. }
  1920. return rxq;
  1921. }
  1922. static void
  1923. _put_free_rxq(struct bna_rx_mod *rx_mod, struct bna_rxq *rxq)
  1924. {
  1925. bfa_q_qe_init(&rxq->qe);
  1926. list_add_tail(&rxq->qe, &rx_mod->rxq_free_q);
  1927. rx_mod->rxq_free_count++;
  1928. }
  1929. static struct bna_rxp *
  1930. _get_free_rxp(struct bna_rx_mod *rx_mod)
  1931. {
  1932. struct list_head *qe = NULL;
  1933. struct bna_rxp *rxp = NULL;
  1934. bfa_q_deq(&rx_mod->rxp_free_q, &qe);
  1935. if (qe) {
  1936. rx_mod->rxp_free_count--;
  1937. rxp = (struct bna_rxp *)qe;
  1938. }
  1939. return rxp;
  1940. }
  1941. static void
  1942. _put_free_rxp(struct bna_rx_mod *rx_mod, struct bna_rxp *rxp)
  1943. {
  1944. bfa_q_qe_init(&rxp->qe);
  1945. list_add_tail(&rxp->qe, &rx_mod->rxp_free_q);
  1946. rx_mod->rxp_free_count++;
  1947. }
  1948. static struct bna_rx *
  1949. _get_free_rx(struct bna_rx_mod *rx_mod)
  1950. {
  1951. struct list_head *qe = NULL;
  1952. struct bna_rx *rx = NULL;
  1953. bfa_q_deq(&rx_mod->rx_free_q, &qe);
  1954. if (qe) {
  1955. rx_mod->rx_free_count--;
  1956. rx = (struct bna_rx *)qe;
  1957. bfa_q_qe_init(qe);
  1958. list_add_tail(&rx->qe, &rx_mod->rx_active_q);
  1959. }
  1960. return rx;
  1961. }
  1962. static void
  1963. _put_free_rx(struct bna_rx_mod *rx_mod, struct bna_rx *rx)
  1964. {
  1965. bfa_q_qe_init(&rx->qe);
  1966. list_add_tail(&rx->qe, &rx_mod->rx_free_q);
  1967. rx_mod->rx_free_count++;
  1968. }
  1969. static void
  1970. _rx_init(struct bna_rx *rx, struct bna *bna)
  1971. {
  1972. rx->bna = bna;
  1973. rx->rx_flags = 0;
  1974. INIT_LIST_HEAD(&rx->rxp_q);
  1975. rx->rxq_stop_wc.wc_resume = bna_rx_cb_rxq_stopped_all;
  1976. rx->rxq_stop_wc.wc_cbarg = rx;
  1977. rx->rxq_stop_wc.wc_count = 0;
  1978. rx->stop_cbfn = NULL;
  1979. rx->stop_cbarg = NULL;
  1980. }
  1981. static void
  1982. _rxp_add_rxqs(struct bna_rxp *rxp,
  1983. struct bna_rxq *q0,
  1984. struct bna_rxq *q1)
  1985. {
  1986. switch (rxp->type) {
  1987. case BNA_RXP_SINGLE:
  1988. rxp->rxq.single.only = q0;
  1989. rxp->rxq.single.reserved = NULL;
  1990. break;
  1991. case BNA_RXP_SLR:
  1992. rxp->rxq.slr.large = q0;
  1993. rxp->rxq.slr.small = q1;
  1994. break;
  1995. case BNA_RXP_HDS:
  1996. rxp->rxq.hds.data = q0;
  1997. rxp->rxq.hds.hdr = q1;
  1998. break;
  1999. default:
  2000. break;
  2001. }
  2002. }
  2003. static void
  2004. _rxq_qpt_init(struct bna_rxq *rxq,
  2005. struct bna_rxp *rxp,
  2006. u32 page_count,
  2007. u32 page_size,
  2008. struct bna_mem_descr *qpt_mem,
  2009. struct bna_mem_descr *swqpt_mem,
  2010. struct bna_mem_descr *page_mem)
  2011. {
  2012. int i;
  2013. rxq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  2014. rxq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  2015. rxq->qpt.kv_qpt_ptr = qpt_mem->kva;
  2016. rxq->qpt.page_count = page_count;
  2017. rxq->qpt.page_size = page_size;
  2018. rxq->rcb->sw_qpt = (void **) swqpt_mem->kva;
  2019. for (i = 0; i < rxq->qpt.page_count; i++) {
  2020. rxq->rcb->sw_qpt[i] = page_mem[i].kva;
  2021. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].lsb =
  2022. page_mem[i].dma.lsb;
  2023. ((struct bna_dma_addr *)rxq->qpt.kv_qpt_ptr)[i].msb =
  2024. page_mem[i].dma.msb;
  2025. }
  2026. }
  2027. static void
  2028. _rxp_cqpt_setup(struct bna_rxp *rxp,
  2029. u32 page_count,
  2030. u32 page_size,
  2031. struct bna_mem_descr *qpt_mem,
  2032. struct bna_mem_descr *swqpt_mem,
  2033. struct bna_mem_descr *page_mem)
  2034. {
  2035. int i;
  2036. rxp->cq.qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  2037. rxp->cq.qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  2038. rxp->cq.qpt.kv_qpt_ptr = qpt_mem->kva;
  2039. rxp->cq.qpt.page_count = page_count;
  2040. rxp->cq.qpt.page_size = page_size;
  2041. rxp->cq.ccb->sw_qpt = (void **) swqpt_mem->kva;
  2042. for (i = 0; i < rxp->cq.qpt.page_count; i++) {
  2043. rxp->cq.ccb->sw_qpt[i] = page_mem[i].kva;
  2044. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].lsb =
  2045. page_mem[i].dma.lsb;
  2046. ((struct bna_dma_addr *)rxp->cq.qpt.kv_qpt_ptr)[i].msb =
  2047. page_mem[i].dma.msb;
  2048. }
  2049. }
  2050. static void
  2051. _rx_add_rxp(struct bna_rx *rx, struct bna_rxp *rxp)
  2052. {
  2053. list_add_tail(&rxp->qe, &rx->rxp_q);
  2054. }
  2055. static void
  2056. _init_rxmod_queues(struct bna_rx_mod *rx_mod)
  2057. {
  2058. INIT_LIST_HEAD(&rx_mod->rx_free_q);
  2059. INIT_LIST_HEAD(&rx_mod->rxq_free_q);
  2060. INIT_LIST_HEAD(&rx_mod->rxp_free_q);
  2061. INIT_LIST_HEAD(&rx_mod->rx_active_q);
  2062. rx_mod->rx_free_count = 0;
  2063. rx_mod->rxq_free_count = 0;
  2064. rx_mod->rxp_free_count = 0;
  2065. }
  2066. static void
  2067. _rx_ctor(struct bna_rx *rx, int id)
  2068. {
  2069. bfa_q_qe_init(&rx->qe);
  2070. INIT_LIST_HEAD(&rx->rxp_q);
  2071. rx->bna = NULL;
  2072. rx->rxf.rxf_id = id;
  2073. /* FIXME: mbox_qe ctor()?? */
  2074. bfa_q_qe_init(&rx->mbox_qe.qe);
  2075. rx->stop_cbfn = NULL;
  2076. rx->stop_cbarg = NULL;
  2077. }
  2078. void
  2079. bna_rx_cb_multi_rxq_stopped(void *arg, int status)
  2080. {
  2081. struct bna_rxp *rxp = (struct bna_rxp *)arg;
  2082. bfa_wc_down(&rxp->rx->rxq_stop_wc);
  2083. }
  2084. void
  2085. bna_rx_cb_rxq_stopped_all(void *arg)
  2086. {
  2087. struct bna_rx *rx = (struct bna_rx *)arg;
  2088. bfa_fsm_send_event(rx, RX_E_RXQ_STOPPED);
  2089. }
  2090. static void
  2091. bna_rx_mod_cb_rx_stopped(void *arg, struct bna_rx *rx,
  2092. enum bna_cb_status status)
  2093. {
  2094. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2095. bfa_wc_down(&rx_mod->rx_stop_wc);
  2096. }
  2097. static void
  2098. bna_rx_mod_cb_rx_stopped_all(void *arg)
  2099. {
  2100. struct bna_rx_mod *rx_mod = (struct bna_rx_mod *)arg;
  2101. if (rx_mod->stop_cbfn)
  2102. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2103. rx_mod->stop_cbfn = NULL;
  2104. }
  2105. static void
  2106. bna_rx_start(struct bna_rx *rx)
  2107. {
  2108. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2109. if (rx->rx_flags & BNA_RX_F_ENABLE)
  2110. bfa_fsm_send_event(rx, RX_E_START);
  2111. }
  2112. static void
  2113. bna_rx_stop(struct bna_rx *rx)
  2114. {
  2115. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2116. if (rx->fsm == (bfa_fsm_t) bna_rx_sm_stopped)
  2117. bna_rx_mod_cb_rx_stopped(&rx->bna->rx_mod, rx, BNA_CB_SUCCESS);
  2118. else {
  2119. rx->stop_cbfn = bna_rx_mod_cb_rx_stopped;
  2120. rx->stop_cbarg = &rx->bna->rx_mod;
  2121. bfa_fsm_send_event(rx, RX_E_STOP);
  2122. }
  2123. }
  2124. static void
  2125. bna_rx_fail(struct bna_rx *rx)
  2126. {
  2127. /* Indicate port is not enabled, and failed */
  2128. rx->rx_flags &= ~BNA_RX_F_PORT_ENABLED;
  2129. rx->rx_flags |= BNA_RX_F_PORT_FAILED;
  2130. bfa_fsm_send_event(rx, RX_E_FAIL);
  2131. }
  2132. void
  2133. bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2134. {
  2135. struct bna_rx *rx;
  2136. struct list_head *qe;
  2137. rx_mod->flags |= BNA_RX_MOD_F_PORT_STARTED;
  2138. if (type == BNA_RX_T_LOOPBACK)
  2139. rx_mod->flags |= BNA_RX_MOD_F_PORT_LOOPBACK;
  2140. list_for_each(qe, &rx_mod->rx_active_q) {
  2141. rx = (struct bna_rx *)qe;
  2142. if (rx->type == type)
  2143. bna_rx_start(rx);
  2144. }
  2145. }
  2146. void
  2147. bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type)
  2148. {
  2149. struct bna_rx *rx;
  2150. struct list_head *qe;
  2151. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2152. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2153. rx_mod->stop_cbfn = bna_port_cb_rx_stopped;
  2154. /**
  2155. * Before calling bna_rx_stop(), increment rx_stop_wc as many times
  2156. * as we are going to call bna_rx_stop
  2157. */
  2158. list_for_each(qe, &rx_mod->rx_active_q) {
  2159. rx = (struct bna_rx *)qe;
  2160. if (rx->type == type)
  2161. bfa_wc_up(&rx_mod->rx_stop_wc);
  2162. }
  2163. if (rx_mod->rx_stop_wc.wc_count == 0) {
  2164. rx_mod->stop_cbfn(&rx_mod->bna->port, BNA_CB_SUCCESS);
  2165. rx_mod->stop_cbfn = NULL;
  2166. return;
  2167. }
  2168. list_for_each(qe, &rx_mod->rx_active_q) {
  2169. rx = (struct bna_rx *)qe;
  2170. if (rx->type == type)
  2171. bna_rx_stop(rx);
  2172. }
  2173. }
  2174. void
  2175. bna_rx_mod_fail(struct bna_rx_mod *rx_mod)
  2176. {
  2177. struct bna_rx *rx;
  2178. struct list_head *qe;
  2179. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_STARTED;
  2180. rx_mod->flags &= ~BNA_RX_MOD_F_PORT_LOOPBACK;
  2181. list_for_each(qe, &rx_mod->rx_active_q) {
  2182. rx = (struct bna_rx *)qe;
  2183. bna_rx_fail(rx);
  2184. }
  2185. }
  2186. void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
  2187. struct bna_res_info *res_info)
  2188. {
  2189. int index;
  2190. struct bna_rx *rx_ptr;
  2191. struct bna_rxp *rxp_ptr;
  2192. struct bna_rxq *rxq_ptr;
  2193. rx_mod->bna = bna;
  2194. rx_mod->flags = 0;
  2195. rx_mod->rx = (struct bna_rx *)
  2196. res_info[BNA_RES_MEM_T_RX_ARRAY].res_u.mem_info.mdl[0].kva;
  2197. rx_mod->rxp = (struct bna_rxp *)
  2198. res_info[BNA_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mdl[0].kva;
  2199. rx_mod->rxq = (struct bna_rxq *)
  2200. res_info[BNA_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  2201. /* Initialize the queues */
  2202. _init_rxmod_queues(rx_mod);
  2203. /* Build RX queues */
  2204. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2205. rx_ptr = &rx_mod->rx[index];
  2206. _rx_ctor(rx_ptr, index);
  2207. list_add_tail(&rx_ptr->qe, &rx_mod->rx_free_q);
  2208. rx_mod->rx_free_count++;
  2209. }
  2210. /* build RX-path queue */
  2211. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2212. rxp_ptr = &rx_mod->rxp[index];
  2213. rxp_ptr->cq.cq_id = index;
  2214. bfa_q_qe_init(&rxp_ptr->qe);
  2215. list_add_tail(&rxp_ptr->qe, &rx_mod->rxp_free_q);
  2216. rx_mod->rxp_free_count++;
  2217. }
  2218. /* build RXQ queue */
  2219. for (index = 0; index < BFI_MAX_RXQ; index++) {
  2220. rxq_ptr = &rx_mod->rxq[index];
  2221. rxq_ptr->rxq_id = index;
  2222. bfa_q_qe_init(&rxq_ptr->qe);
  2223. list_add_tail(&rxq_ptr->qe, &rx_mod->rxq_free_q);
  2224. rx_mod->rxq_free_count++;
  2225. }
  2226. rx_mod->rx_stop_wc.wc_resume = bna_rx_mod_cb_rx_stopped_all;
  2227. rx_mod->rx_stop_wc.wc_cbarg = rx_mod;
  2228. rx_mod->rx_stop_wc.wc_count = 0;
  2229. }
  2230. void
  2231. bna_rx_mod_uninit(struct bna_rx_mod *rx_mod)
  2232. {
  2233. struct list_head *qe;
  2234. int i;
  2235. i = 0;
  2236. list_for_each(qe, &rx_mod->rx_free_q)
  2237. i++;
  2238. i = 0;
  2239. list_for_each(qe, &rx_mod->rxp_free_q)
  2240. i++;
  2241. i = 0;
  2242. list_for_each(qe, &rx_mod->rxq_free_q)
  2243. i++;
  2244. rx_mod->bna = NULL;
  2245. }
  2246. int
  2247. bna_rx_state_get(struct bna_rx *rx)
  2248. {
  2249. return bfa_sm_to_state(rx_sm_table, rx->fsm);
  2250. }
  2251. void
  2252. bna_rx_res_req(struct bna_rx_config *q_cfg, struct bna_res_info *res_info)
  2253. {
  2254. u32 cq_size, hq_size, dq_size;
  2255. u32 cpage_count, hpage_count, dpage_count;
  2256. struct bna_mem_info *mem_info;
  2257. u32 cq_depth;
  2258. u32 hq_depth;
  2259. u32 dq_depth;
  2260. dq_depth = q_cfg->q_depth;
  2261. hq_depth = ((q_cfg->rxp_type == BNA_RXP_SINGLE) ? 0 : q_cfg->q_depth);
  2262. cq_depth = dq_depth + hq_depth;
  2263. BNA_TO_POWER_OF_2_HIGH(cq_depth);
  2264. cq_size = cq_depth * BFI_CQ_WI_SIZE;
  2265. cq_size = ALIGN(cq_size, PAGE_SIZE);
  2266. cpage_count = SIZE_TO_PAGES(cq_size);
  2267. BNA_TO_POWER_OF_2_HIGH(dq_depth);
  2268. dq_size = dq_depth * BFI_RXQ_WI_SIZE;
  2269. dq_size = ALIGN(dq_size, PAGE_SIZE);
  2270. dpage_count = SIZE_TO_PAGES(dq_size);
  2271. if (BNA_RXP_SINGLE != q_cfg->rxp_type) {
  2272. BNA_TO_POWER_OF_2_HIGH(hq_depth);
  2273. hq_size = hq_depth * BFI_RXQ_WI_SIZE;
  2274. hq_size = ALIGN(hq_size, PAGE_SIZE);
  2275. hpage_count = SIZE_TO_PAGES(hq_size);
  2276. } else {
  2277. hpage_count = 0;
  2278. }
  2279. /* CCB structures */
  2280. res_info[BNA_RX_RES_MEM_T_CCB].res_type = BNA_RES_T_MEM;
  2281. mem_info = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info;
  2282. mem_info->mem_type = BNA_MEM_T_KVA;
  2283. mem_info->len = sizeof(struct bna_ccb);
  2284. mem_info->num = q_cfg->num_paths;
  2285. /* RCB structures */
  2286. res_info[BNA_RX_RES_MEM_T_RCB].res_type = BNA_RES_T_MEM;
  2287. mem_info = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info;
  2288. mem_info->mem_type = BNA_MEM_T_KVA;
  2289. mem_info->len = sizeof(struct bna_rcb);
  2290. mem_info->num = BNA_GET_RXQS(q_cfg);
  2291. /* Completion QPT */
  2292. res_info[BNA_RX_RES_MEM_T_CQPT].res_type = BNA_RES_T_MEM;
  2293. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info;
  2294. mem_info->mem_type = BNA_MEM_T_DMA;
  2295. mem_info->len = cpage_count * sizeof(struct bna_dma_addr);
  2296. mem_info->num = q_cfg->num_paths;
  2297. /* Completion s/w QPT */
  2298. res_info[BNA_RX_RES_MEM_T_CSWQPT].res_type = BNA_RES_T_MEM;
  2299. mem_info = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info;
  2300. mem_info->mem_type = BNA_MEM_T_KVA;
  2301. mem_info->len = cpage_count * sizeof(void *);
  2302. mem_info->num = q_cfg->num_paths;
  2303. /* Completion QPT pages */
  2304. res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_type = BNA_RES_T_MEM;
  2305. mem_info = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info;
  2306. mem_info->mem_type = BNA_MEM_T_DMA;
  2307. mem_info->len = PAGE_SIZE;
  2308. mem_info->num = cpage_count * q_cfg->num_paths;
  2309. /* Data QPTs */
  2310. res_info[BNA_RX_RES_MEM_T_DQPT].res_type = BNA_RES_T_MEM;
  2311. mem_info = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info;
  2312. mem_info->mem_type = BNA_MEM_T_DMA;
  2313. mem_info->len = dpage_count * sizeof(struct bna_dma_addr);
  2314. mem_info->num = q_cfg->num_paths;
  2315. /* Data s/w QPTs */
  2316. res_info[BNA_RX_RES_MEM_T_DSWQPT].res_type = BNA_RES_T_MEM;
  2317. mem_info = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info;
  2318. mem_info->mem_type = BNA_MEM_T_KVA;
  2319. mem_info->len = dpage_count * sizeof(void *);
  2320. mem_info->num = q_cfg->num_paths;
  2321. /* Data QPT pages */
  2322. res_info[BNA_RX_RES_MEM_T_DPAGE].res_type = BNA_RES_T_MEM;
  2323. mem_info = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info;
  2324. mem_info->mem_type = BNA_MEM_T_DMA;
  2325. mem_info->len = PAGE_SIZE;
  2326. mem_info->num = dpage_count * q_cfg->num_paths;
  2327. /* Hdr QPTs */
  2328. res_info[BNA_RX_RES_MEM_T_HQPT].res_type = BNA_RES_T_MEM;
  2329. mem_info = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info;
  2330. mem_info->mem_type = BNA_MEM_T_DMA;
  2331. mem_info->len = hpage_count * sizeof(struct bna_dma_addr);
  2332. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2333. /* Hdr s/w QPTs */
  2334. res_info[BNA_RX_RES_MEM_T_HSWQPT].res_type = BNA_RES_T_MEM;
  2335. mem_info = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info;
  2336. mem_info->mem_type = BNA_MEM_T_KVA;
  2337. mem_info->len = hpage_count * sizeof(void *);
  2338. mem_info->num = (hpage_count ? q_cfg->num_paths : 0);
  2339. /* Hdr QPT pages */
  2340. res_info[BNA_RX_RES_MEM_T_HPAGE].res_type = BNA_RES_T_MEM;
  2341. mem_info = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info;
  2342. mem_info->mem_type = BNA_MEM_T_DMA;
  2343. mem_info->len = (hpage_count ? PAGE_SIZE : 0);
  2344. mem_info->num = (hpage_count ? (hpage_count * q_cfg->num_paths) : 0);
  2345. /* RX Interrupts */
  2346. res_info[BNA_RX_RES_T_INTR].res_type = BNA_RES_T_INTR;
  2347. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.intr_type = BNA_INTR_T_MSIX;
  2348. res_info[BNA_RX_RES_T_INTR].res_u.intr_info.num = q_cfg->num_paths;
  2349. }
  2350. struct bna_rx *
  2351. bna_rx_create(struct bna *bna, struct bnad *bnad,
  2352. struct bna_rx_config *rx_cfg,
  2353. struct bna_rx_event_cbfn *rx_cbfn,
  2354. struct bna_res_info *res_info,
  2355. void *priv)
  2356. {
  2357. struct bna_rx_mod *rx_mod = &bna->rx_mod;
  2358. struct bna_rx *rx;
  2359. struct bna_rxp *rxp;
  2360. struct bna_rxq *q0;
  2361. struct bna_rxq *q1;
  2362. struct bna_intr_info *intr_info;
  2363. u32 page_count;
  2364. struct bna_mem_descr *ccb_mem;
  2365. struct bna_mem_descr *rcb_mem;
  2366. struct bna_mem_descr *unmapq_mem;
  2367. struct bna_mem_descr *cqpt_mem;
  2368. struct bna_mem_descr *cswqpt_mem;
  2369. struct bna_mem_descr *cpage_mem;
  2370. struct bna_mem_descr *hqpt_mem; /* Header/Small Q qpt */
  2371. struct bna_mem_descr *dqpt_mem; /* Data/Large Q qpt */
  2372. struct bna_mem_descr *hsqpt_mem; /* s/w qpt for hdr */
  2373. struct bna_mem_descr *dsqpt_mem; /* s/w qpt for data */
  2374. struct bna_mem_descr *hpage_mem; /* hdr page mem */
  2375. struct bna_mem_descr *dpage_mem; /* data page mem */
  2376. int i, cpage_idx = 0, dpage_idx = 0, hpage_idx = 0, ret;
  2377. int dpage_count, hpage_count, rcb_idx;
  2378. struct bna_ib_config ibcfg;
  2379. /* Fail if we don't have enough RXPs, RXQs */
  2380. if (!_rx_can_satisfy(rx_mod, rx_cfg))
  2381. return NULL;
  2382. /* Initialize resource pointers */
  2383. intr_info = &res_info[BNA_RX_RES_T_INTR].res_u.intr_info;
  2384. ccb_mem = &res_info[BNA_RX_RES_MEM_T_CCB].res_u.mem_info.mdl[0];
  2385. rcb_mem = &res_info[BNA_RX_RES_MEM_T_RCB].res_u.mem_info.mdl[0];
  2386. unmapq_mem = &res_info[BNA_RX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[0];
  2387. cqpt_mem = &res_info[BNA_RX_RES_MEM_T_CQPT].res_u.mem_info.mdl[0];
  2388. cswqpt_mem = &res_info[BNA_RX_RES_MEM_T_CSWQPT].res_u.mem_info.mdl[0];
  2389. cpage_mem = &res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.mdl[0];
  2390. hqpt_mem = &res_info[BNA_RX_RES_MEM_T_HQPT].res_u.mem_info.mdl[0];
  2391. dqpt_mem = &res_info[BNA_RX_RES_MEM_T_DQPT].res_u.mem_info.mdl[0];
  2392. hsqpt_mem = &res_info[BNA_RX_RES_MEM_T_HSWQPT].res_u.mem_info.mdl[0];
  2393. dsqpt_mem = &res_info[BNA_RX_RES_MEM_T_DSWQPT].res_u.mem_info.mdl[0];
  2394. hpage_mem = &res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.mdl[0];
  2395. dpage_mem = &res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.mdl[0];
  2396. /* Compute q depth & page count */
  2397. page_count = res_info[BNA_RX_RES_MEM_T_CQPT_PAGE].res_u.mem_info.num /
  2398. rx_cfg->num_paths;
  2399. dpage_count = res_info[BNA_RX_RES_MEM_T_DPAGE].res_u.mem_info.num /
  2400. rx_cfg->num_paths;
  2401. hpage_count = res_info[BNA_RX_RES_MEM_T_HPAGE].res_u.mem_info.num /
  2402. rx_cfg->num_paths;
  2403. /* Get RX pointer */
  2404. rx = _get_free_rx(rx_mod);
  2405. _rx_init(rx, bna);
  2406. rx->priv = priv;
  2407. rx->type = rx_cfg->rx_type;
  2408. rx->rcb_setup_cbfn = rx_cbfn->rcb_setup_cbfn;
  2409. rx->rcb_destroy_cbfn = rx_cbfn->rcb_destroy_cbfn;
  2410. rx->ccb_setup_cbfn = rx_cbfn->ccb_setup_cbfn;
  2411. rx->ccb_destroy_cbfn = rx_cbfn->ccb_destroy_cbfn;
  2412. /* Following callbacks are mandatory */
  2413. rx->rx_cleanup_cbfn = rx_cbfn->rx_cleanup_cbfn;
  2414. rx->rx_post_cbfn = rx_cbfn->rx_post_cbfn;
  2415. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_STARTED) {
  2416. switch (rx->type) {
  2417. case BNA_RX_T_REGULAR:
  2418. if (!(rx->bna->rx_mod.flags &
  2419. BNA_RX_MOD_F_PORT_LOOPBACK))
  2420. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2421. break;
  2422. case BNA_RX_T_LOOPBACK:
  2423. if (rx->bna->rx_mod.flags & BNA_RX_MOD_F_PORT_LOOPBACK)
  2424. rx->rx_flags |= BNA_RX_F_PORT_ENABLED;
  2425. break;
  2426. }
  2427. }
  2428. for (i = 0, rcb_idx = 0; i < rx_cfg->num_paths; i++) {
  2429. rxp = _get_free_rxp(rx_mod);
  2430. rxp->type = rx_cfg->rxp_type;
  2431. rxp->rx = rx;
  2432. rxp->cq.rx = rx;
  2433. /* Get required RXQs, and queue them to rx-path */
  2434. q0 = _get_free_rxq(rx_mod);
  2435. if (BNA_RXP_SINGLE == rx_cfg->rxp_type)
  2436. q1 = NULL;
  2437. else
  2438. q1 = _get_free_rxq(rx_mod);
  2439. /* Initialize IB */
  2440. if (1 == intr_info->num) {
  2441. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2442. intr_info->intr_type,
  2443. intr_info->idl[0].vector);
  2444. rxp->vector = intr_info->idl[0].vector;
  2445. } else {
  2446. rxp->cq.ib = bna_ib_get(&bna->ib_mod,
  2447. intr_info->intr_type,
  2448. intr_info->idl[i].vector);
  2449. /* Map the MSI-x vector used for this RXP */
  2450. rxp->vector = intr_info->idl[i].vector;
  2451. }
  2452. rxp->cq.ib_seg_offset = bna_ib_reserve_idx(rxp->cq.ib);
  2453. ibcfg.coalescing_timeo = BFI_RX_COALESCING_TIMEO;
  2454. ibcfg.interpkt_count = BFI_RX_INTERPKT_COUNT;
  2455. ibcfg.interpkt_timeo = BFI_RX_INTERPKT_TIMEO;
  2456. ibcfg.ctrl_flags = BFI_IB_CF_INT_ENABLE;
  2457. ret = bna_ib_config(rxp->cq.ib, &ibcfg);
  2458. /* Link rxqs to rxp */
  2459. _rxp_add_rxqs(rxp, q0, q1);
  2460. /* Link rxp to rx */
  2461. _rx_add_rxp(rx, rxp);
  2462. q0->rx = rx;
  2463. q0->rxp = rxp;
  2464. /* Initialize RCB for the large / data q */
  2465. q0->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2466. RXQ_RCB_INIT(q0, rxp, rx_cfg->q_depth, bna, 0,
  2467. (void *)unmapq_mem[rcb_idx].kva);
  2468. rcb_idx++;
  2469. (q0)->rx_packets = (q0)->rx_bytes = 0;
  2470. (q0)->rx_packets_with_error = (q0)->rxbuf_alloc_failed = 0;
  2471. /* Initialize RXQs */
  2472. _rxq_qpt_init(q0, rxp, dpage_count, PAGE_SIZE,
  2473. &dqpt_mem[i], &dsqpt_mem[i], &dpage_mem[dpage_idx]);
  2474. q0->rcb->page_idx = dpage_idx;
  2475. q0->rcb->page_count = dpage_count;
  2476. dpage_idx += dpage_count;
  2477. /* Call bnad to complete rcb setup */
  2478. if (rx->rcb_setup_cbfn)
  2479. rx->rcb_setup_cbfn(bnad, q0->rcb);
  2480. if (q1) {
  2481. q1->rx = rx;
  2482. q1->rxp = rxp;
  2483. q1->rcb = (struct bna_rcb *) rcb_mem[rcb_idx].kva;
  2484. RXQ_RCB_INIT(q1, rxp, rx_cfg->q_depth, bna, 1,
  2485. (void *)unmapq_mem[rcb_idx].kva);
  2486. rcb_idx++;
  2487. (q1)->buffer_size = (rx_cfg)->small_buff_size;
  2488. (q1)->rx_packets = (q1)->rx_bytes = 0;
  2489. (q1)->rx_packets_with_error =
  2490. (q1)->rxbuf_alloc_failed = 0;
  2491. _rxq_qpt_init(q1, rxp, hpage_count, PAGE_SIZE,
  2492. &hqpt_mem[i], &hsqpt_mem[i],
  2493. &hpage_mem[hpage_idx]);
  2494. q1->rcb->page_idx = hpage_idx;
  2495. q1->rcb->page_count = hpage_count;
  2496. hpage_idx += hpage_count;
  2497. /* Call bnad to complete rcb setup */
  2498. if (rx->rcb_setup_cbfn)
  2499. rx->rcb_setup_cbfn(bnad, q1->rcb);
  2500. }
  2501. /* Setup RXP::CQ */
  2502. rxp->cq.ccb = (struct bna_ccb *) ccb_mem[i].kva;
  2503. _rxp_cqpt_setup(rxp, page_count, PAGE_SIZE,
  2504. &cqpt_mem[i], &cswqpt_mem[i], &cpage_mem[cpage_idx]);
  2505. rxp->cq.ccb->page_idx = cpage_idx;
  2506. rxp->cq.ccb->page_count = page_count;
  2507. cpage_idx += page_count;
  2508. rxp->cq.ccb->pkt_rate.small_pkt_cnt = 0;
  2509. rxp->cq.ccb->pkt_rate.large_pkt_cnt = 0;
  2510. rxp->cq.ccb->producer_index = 0;
  2511. rxp->cq.ccb->q_depth = rx_cfg->q_depth +
  2512. ((rx_cfg->rxp_type == BNA_RXP_SINGLE) ?
  2513. 0 : rx_cfg->q_depth);
  2514. rxp->cq.ccb->i_dbell = &rxp->cq.ib->door_bell;
  2515. rxp->cq.ccb->rcb[0] = q0->rcb;
  2516. if (q1)
  2517. rxp->cq.ccb->rcb[1] = q1->rcb;
  2518. rxp->cq.ccb->cq = &rxp->cq;
  2519. rxp->cq.ccb->bnad = bna->bnad;
  2520. rxp->cq.ccb->hw_producer_index =
  2521. ((volatile u32 *)rxp->cq.ib->ib_seg_host_addr_kva +
  2522. (rxp->cq.ib_seg_offset * BFI_IBIDX_SIZE));
  2523. *(rxp->cq.ccb->hw_producer_index) = 0;
  2524. rxp->cq.ccb->intr_type = intr_info->intr_type;
  2525. rxp->cq.ccb->intr_vector = (intr_info->num == 1) ?
  2526. intr_info->idl[0].vector :
  2527. intr_info->idl[i].vector;
  2528. rxp->cq.ccb->rx_coalescing_timeo =
  2529. rxp->cq.ib->ib_config.coalescing_timeo;
  2530. rxp->cq.ccb->id = i;
  2531. /* Call bnad to complete CCB setup */
  2532. if (rx->ccb_setup_cbfn)
  2533. rx->ccb_setup_cbfn(bnad, rxp->cq.ccb);
  2534. } /* for each rx-path */
  2535. bna_rxf_init(&rx->rxf, rx, rx_cfg);
  2536. bfa_fsm_set_state(rx, bna_rx_sm_stopped);
  2537. return rx;
  2538. }
  2539. void
  2540. bna_rx_destroy(struct bna_rx *rx)
  2541. {
  2542. struct bna_rx_mod *rx_mod = &rx->bna->rx_mod;
  2543. struct bna_ib_mod *ib_mod = &rx->bna->ib_mod;
  2544. struct bna_rxq *q0 = NULL;
  2545. struct bna_rxq *q1 = NULL;
  2546. struct bna_rxp *rxp;
  2547. struct list_head *qe;
  2548. bna_rxf_uninit(&rx->rxf);
  2549. while (!list_empty(&rx->rxp_q)) {
  2550. bfa_q_deq(&rx->rxp_q, &rxp);
  2551. GET_RXQS(rxp, q0, q1);
  2552. /* Callback to bnad for destroying RCB */
  2553. if (rx->rcb_destroy_cbfn)
  2554. rx->rcb_destroy_cbfn(rx->bna->bnad, q0->rcb);
  2555. q0->rcb = NULL;
  2556. q0->rxp = NULL;
  2557. q0->rx = NULL;
  2558. _put_free_rxq(rx_mod, q0);
  2559. if (q1) {
  2560. /* Callback to bnad for destroying RCB */
  2561. if (rx->rcb_destroy_cbfn)
  2562. rx->rcb_destroy_cbfn(rx->bna->bnad, q1->rcb);
  2563. q1->rcb = NULL;
  2564. q1->rxp = NULL;
  2565. q1->rx = NULL;
  2566. _put_free_rxq(rx_mod, q1);
  2567. }
  2568. rxp->rxq.slr.large = NULL;
  2569. rxp->rxq.slr.small = NULL;
  2570. if (rxp->cq.ib) {
  2571. if (rxp->cq.ib_seg_offset != 0xff)
  2572. bna_ib_release_idx(rxp->cq.ib,
  2573. rxp->cq.ib_seg_offset);
  2574. bna_ib_put(ib_mod, rxp->cq.ib);
  2575. rxp->cq.ib = NULL;
  2576. }
  2577. /* Callback to bnad for destroying CCB */
  2578. if (rx->ccb_destroy_cbfn)
  2579. rx->ccb_destroy_cbfn(rx->bna->bnad, rxp->cq.ccb);
  2580. rxp->cq.ccb = NULL;
  2581. rxp->rx = NULL;
  2582. _put_free_rxp(rx_mod, rxp);
  2583. }
  2584. list_for_each(qe, &rx_mod->rx_active_q) {
  2585. if (qe == &rx->qe) {
  2586. list_del(&rx->qe);
  2587. bfa_q_qe_init(&rx->qe);
  2588. break;
  2589. }
  2590. }
  2591. rx->bna = NULL;
  2592. rx->priv = NULL;
  2593. _put_free_rx(rx_mod, rx);
  2594. }
  2595. void
  2596. bna_rx_enable(struct bna_rx *rx)
  2597. {
  2598. if (rx->fsm != (bfa_sm_t)bna_rx_sm_stopped)
  2599. return;
  2600. rx->rx_flags |= BNA_RX_F_ENABLE;
  2601. if (rx->rx_flags & BNA_RX_F_PORT_ENABLED)
  2602. bfa_fsm_send_event(rx, RX_E_START);
  2603. }
  2604. void
  2605. bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
  2606. void (*cbfn)(void *, struct bna_rx *,
  2607. enum bna_cb_status))
  2608. {
  2609. if (type == BNA_SOFT_CLEANUP) {
  2610. /* h/w should not be accessed. Treat we're stopped */
  2611. (*cbfn)(rx->bna->bnad, rx, BNA_CB_SUCCESS);
  2612. } else {
  2613. rx->stop_cbfn = cbfn;
  2614. rx->stop_cbarg = rx->bna->bnad;
  2615. rx->rx_flags &= ~BNA_RX_F_ENABLE;
  2616. bfa_fsm_send_event(rx, RX_E_STOP);
  2617. }
  2618. }
  2619. /**
  2620. * TX
  2621. */
  2622. #define call_tx_stop_cbfn(tx, status)\
  2623. do {\
  2624. if ((tx)->stop_cbfn)\
  2625. (tx)->stop_cbfn((tx)->stop_cbarg, (tx), status);\
  2626. (tx)->stop_cbfn = NULL;\
  2627. (tx)->stop_cbarg = NULL;\
  2628. } while (0)
  2629. #define call_tx_prio_change_cbfn(tx, status)\
  2630. do {\
  2631. if ((tx)->prio_change_cbfn)\
  2632. (tx)->prio_change_cbfn((tx)->bna->bnad, (tx), status);\
  2633. (tx)->prio_change_cbfn = NULL;\
  2634. } while (0)
  2635. static void bna_tx_mod_cb_tx_stopped(void *tx_mod, struct bna_tx *tx,
  2636. enum bna_cb_status status);
  2637. static void bna_tx_cb_txq_stopped(void *arg, int status);
  2638. static void bna_tx_cb_stats_cleared(void *arg, int status);
  2639. static void __bna_tx_stop(struct bna_tx *tx);
  2640. static void __bna_tx_start(struct bna_tx *tx);
  2641. static void __bna_txf_stat_clr(struct bna_tx *tx);
  2642. enum bna_tx_event {
  2643. TX_E_START = 1,
  2644. TX_E_STOP = 2,
  2645. TX_E_FAIL = 3,
  2646. TX_E_TXQ_STOPPED = 4,
  2647. TX_E_PRIO_CHANGE = 5,
  2648. TX_E_STAT_CLEARED = 6,
  2649. };
  2650. enum bna_tx_state {
  2651. BNA_TX_STOPPED = 1,
  2652. BNA_TX_STARTED = 2,
  2653. BNA_TX_TXQ_STOP_WAIT = 3,
  2654. BNA_TX_PRIO_STOP_WAIT = 4,
  2655. BNA_TX_STAT_CLR_WAIT = 5,
  2656. };
  2657. bfa_fsm_state_decl(bna_tx, stopped, struct bna_tx,
  2658. enum bna_tx_event);
  2659. bfa_fsm_state_decl(bna_tx, started, struct bna_tx,
  2660. enum bna_tx_event);
  2661. bfa_fsm_state_decl(bna_tx, txq_stop_wait, struct bna_tx,
  2662. enum bna_tx_event);
  2663. bfa_fsm_state_decl(bna_tx, prio_stop_wait, struct bna_tx,
  2664. enum bna_tx_event);
  2665. bfa_fsm_state_decl(bna_tx, stat_clr_wait, struct bna_tx,
  2666. enum bna_tx_event);
  2667. static struct bfa_sm_table tx_sm_table[] = {
  2668. {BFA_SM(bna_tx_sm_stopped), BNA_TX_STOPPED},
  2669. {BFA_SM(bna_tx_sm_started), BNA_TX_STARTED},
  2670. {BFA_SM(bna_tx_sm_txq_stop_wait), BNA_TX_TXQ_STOP_WAIT},
  2671. {BFA_SM(bna_tx_sm_prio_stop_wait), BNA_TX_PRIO_STOP_WAIT},
  2672. {BFA_SM(bna_tx_sm_stat_clr_wait), BNA_TX_STAT_CLR_WAIT},
  2673. };
  2674. static void
  2675. bna_tx_sm_stopped_entry(struct bna_tx *tx)
  2676. {
  2677. struct bna_txq *txq;
  2678. struct list_head *qe;
  2679. list_for_each(qe, &tx->txq_q) {
  2680. txq = (struct bna_txq *)qe;
  2681. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2682. }
  2683. call_tx_stop_cbfn(tx, BNA_CB_SUCCESS);
  2684. }
  2685. static void
  2686. bna_tx_sm_stopped(struct bna_tx *tx, enum bna_tx_event event)
  2687. {
  2688. switch (event) {
  2689. case TX_E_START:
  2690. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2691. break;
  2692. case TX_E_STOP:
  2693. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2694. break;
  2695. case TX_E_FAIL:
  2696. /* No-op */
  2697. break;
  2698. case TX_E_PRIO_CHANGE:
  2699. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2700. break;
  2701. case TX_E_TXQ_STOPPED:
  2702. /**
  2703. * This event is received due to flushing of mbox when
  2704. * device fails
  2705. */
  2706. /* No-op */
  2707. break;
  2708. default:
  2709. bfa_sm_fault(tx->bna, event);
  2710. }
  2711. }
  2712. static void
  2713. bna_tx_sm_started_entry(struct bna_tx *tx)
  2714. {
  2715. struct bna_txq *txq;
  2716. struct list_head *qe;
  2717. __bna_tx_start(tx);
  2718. /* Start IB */
  2719. list_for_each(qe, &tx->txq_q) {
  2720. txq = (struct bna_txq *)qe;
  2721. bna_ib_ack(&txq->ib->door_bell, 0);
  2722. }
  2723. }
  2724. static void
  2725. bna_tx_sm_started(struct bna_tx *tx, enum bna_tx_event event)
  2726. {
  2727. struct bna_txq *txq;
  2728. struct list_head *qe;
  2729. switch (event) {
  2730. case TX_E_STOP:
  2731. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2732. __bna_tx_stop(tx);
  2733. break;
  2734. case TX_E_FAIL:
  2735. list_for_each(qe, &tx->txq_q) {
  2736. txq = (struct bna_txq *)qe;
  2737. bna_ib_fail(txq->ib);
  2738. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  2739. }
  2740. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2741. break;
  2742. case TX_E_PRIO_CHANGE:
  2743. bfa_fsm_set_state(tx, bna_tx_sm_prio_stop_wait);
  2744. break;
  2745. default:
  2746. bfa_sm_fault(tx->bna, event);
  2747. }
  2748. }
  2749. static void
  2750. bna_tx_sm_txq_stop_wait_entry(struct bna_tx *tx)
  2751. {
  2752. }
  2753. static void
  2754. bna_tx_sm_txq_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2755. {
  2756. struct bna_txq *txq;
  2757. struct list_head *qe;
  2758. switch (event) {
  2759. case TX_E_FAIL:
  2760. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2761. break;
  2762. case TX_E_TXQ_STOPPED:
  2763. list_for_each(qe, &tx->txq_q) {
  2764. txq = (struct bna_txq *)qe;
  2765. bna_ib_stop(txq->ib);
  2766. }
  2767. bfa_fsm_set_state(tx, bna_tx_sm_stat_clr_wait);
  2768. break;
  2769. case TX_E_PRIO_CHANGE:
  2770. /* No-op */
  2771. break;
  2772. default:
  2773. bfa_sm_fault(tx->bna, event);
  2774. }
  2775. }
  2776. static void
  2777. bna_tx_sm_prio_stop_wait_entry(struct bna_tx *tx)
  2778. {
  2779. __bna_tx_stop(tx);
  2780. }
  2781. static void
  2782. bna_tx_sm_prio_stop_wait(struct bna_tx *tx, enum bna_tx_event event)
  2783. {
  2784. struct bna_txq *txq;
  2785. struct list_head *qe;
  2786. switch (event) {
  2787. case TX_E_STOP:
  2788. bfa_fsm_set_state(tx, bna_tx_sm_txq_stop_wait);
  2789. break;
  2790. case TX_E_FAIL:
  2791. call_tx_prio_change_cbfn(tx, BNA_CB_FAIL);
  2792. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2793. break;
  2794. case TX_E_TXQ_STOPPED:
  2795. list_for_each(qe, &tx->txq_q) {
  2796. txq = (struct bna_txq *)qe;
  2797. bna_ib_stop(txq->ib);
  2798. (tx->tx_cleanup_cbfn)(tx->bna->bnad, txq->tcb);
  2799. }
  2800. call_tx_prio_change_cbfn(tx, BNA_CB_SUCCESS);
  2801. bfa_fsm_set_state(tx, bna_tx_sm_started);
  2802. break;
  2803. case TX_E_PRIO_CHANGE:
  2804. /* No-op */
  2805. break;
  2806. default:
  2807. bfa_sm_fault(tx->bna, event);
  2808. }
  2809. }
  2810. static void
  2811. bna_tx_sm_stat_clr_wait_entry(struct bna_tx *tx)
  2812. {
  2813. __bna_txf_stat_clr(tx);
  2814. }
  2815. static void
  2816. bna_tx_sm_stat_clr_wait(struct bna_tx *tx, enum bna_tx_event event)
  2817. {
  2818. switch (event) {
  2819. case TX_E_FAIL:
  2820. case TX_E_STAT_CLEARED:
  2821. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  2822. break;
  2823. default:
  2824. bfa_sm_fault(tx->bna, event);
  2825. }
  2826. }
  2827. static void
  2828. __bna_txq_start(struct bna_tx *tx, struct bna_txq *txq)
  2829. {
  2830. struct bna_rxtx_q_mem *q_mem;
  2831. struct bna_txq_mem txq_cfg;
  2832. struct bna_txq_mem *txq_mem;
  2833. struct bna_dma_addr cur_q_addr;
  2834. u32 pg_num;
  2835. void __iomem *base_addr;
  2836. unsigned long off;
  2837. /* Fill out structure, to be subsequently written to hardware */
  2838. txq_cfg.pg_tbl_addr_lo = txq->qpt.hw_qpt_ptr.lsb;
  2839. txq_cfg.pg_tbl_addr_hi = txq->qpt.hw_qpt_ptr.msb;
  2840. cur_q_addr = *((struct bna_dma_addr *)(txq->qpt.kv_qpt_ptr));
  2841. txq_cfg.cur_q_entry_lo = cur_q_addr.lsb;
  2842. txq_cfg.cur_q_entry_hi = cur_q_addr.msb;
  2843. txq_cfg.pg_cnt_n_prd_ptr = (txq->qpt.page_count << 16) | 0x0;
  2844. txq_cfg.entry_n_pg_size = ((u32)(BFI_TXQ_WI_SIZE >> 2) << 16) |
  2845. (txq->qpt.page_size >> 2);
  2846. txq_cfg.int_blk_n_cns_ptr = ((((u32)txq->ib_seg_offset) << 24) |
  2847. ((u32)(txq->ib->ib_id & 0xff) << 16) | 0x0);
  2848. txq_cfg.cns_ptr2_n_q_state = BNA_Q_IDLE_STATE;
  2849. txq_cfg.nxt_qid_n_fid_n_pri = (((tx->txf.txf_id & 0x3f) << 3) |
  2850. (txq->priority & 0x7));
  2851. txq_cfg.wvc_n_cquota_n_rquota =
  2852. ((((u32)BFI_TX_MAX_WRR_QUOTA & 0xfff) << 12) |
  2853. (BFI_TX_MAX_WRR_QUOTA & 0xfff));
  2854. /* Setup the page and write to H/W */
  2855. pg_num = BNA_GET_PAGE_NUM(HQM0_BLK_PG_NUM + tx->bna->port_num,
  2856. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2857. writel(pg_num, tx->bna->regs.page_addr);
  2858. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2859. HQM_RXTX_Q_RAM_BASE_OFFSET);
  2860. q_mem = (struct bna_rxtx_q_mem *)0;
  2861. txq_mem = &q_mem[txq->txq_id].txq;
  2862. /*
  2863. * The following 4 lines, is a hack b'cos the H/W needs to read
  2864. * these DMA addresses as little endian
  2865. */
  2866. off = (unsigned long)&txq_mem->pg_tbl_addr_lo;
  2867. writel(htonl(txq_cfg.pg_tbl_addr_lo), base_addr + off);
  2868. off = (unsigned long)&txq_mem->pg_tbl_addr_hi;
  2869. writel(htonl(txq_cfg.pg_tbl_addr_hi), base_addr + off);
  2870. off = (unsigned long)&txq_mem->cur_q_entry_lo;
  2871. writel(htonl(txq_cfg.cur_q_entry_lo), base_addr + off);
  2872. off = (unsigned long)&txq_mem->cur_q_entry_hi;
  2873. writel(htonl(txq_cfg.cur_q_entry_hi), base_addr + off);
  2874. off = (unsigned long)&txq_mem->pg_cnt_n_prd_ptr;
  2875. writel(txq_cfg.pg_cnt_n_prd_ptr, base_addr + off);
  2876. off = (unsigned long)&txq_mem->entry_n_pg_size;
  2877. writel(txq_cfg.entry_n_pg_size, base_addr + off);
  2878. off = (unsigned long)&txq_mem->int_blk_n_cns_ptr;
  2879. writel(txq_cfg.int_blk_n_cns_ptr, base_addr + off);
  2880. off = (unsigned long)&txq_mem->cns_ptr2_n_q_state;
  2881. writel(txq_cfg.cns_ptr2_n_q_state, base_addr + off);
  2882. off = (unsigned long)&txq_mem->nxt_qid_n_fid_n_pri;
  2883. writel(txq_cfg.nxt_qid_n_fid_n_pri, base_addr + off);
  2884. off = (unsigned long)&txq_mem->wvc_n_cquota_n_rquota;
  2885. writel(txq_cfg.wvc_n_cquota_n_rquota, base_addr + off);
  2886. txq->tcb->producer_index = 0;
  2887. txq->tcb->consumer_index = 0;
  2888. *(txq->tcb->hw_consumer_index) = 0;
  2889. }
  2890. static void
  2891. __bna_txq_stop(struct bna_tx *tx, struct bna_txq *txq)
  2892. {
  2893. struct bfi_ll_q_stop_req ll_req;
  2894. u32 bit_mask[2] = {0, 0};
  2895. if (txq->txq_id < 32)
  2896. bit_mask[0] = (u32)1 << txq->txq_id;
  2897. else
  2898. bit_mask[1] = (u32)1 << (txq->txq_id - 32);
  2899. memset(&ll_req, 0, sizeof(ll_req));
  2900. ll_req.mh.msg_class = BFI_MC_LL;
  2901. ll_req.mh.msg_id = BFI_LL_H2I_TXQ_STOP_REQ;
  2902. ll_req.mh.mtag.h2i.lpu_id = 0;
  2903. ll_req.q_id_mask[0] = htonl(bit_mask[0]);
  2904. ll_req.q_id_mask[1] = htonl(bit_mask[1]);
  2905. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2906. bna_tx_cb_txq_stopped, tx);
  2907. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2908. }
  2909. static void
  2910. __bna_txf_start(struct bna_tx *tx)
  2911. {
  2912. struct bna_tx_fndb_ram *tx_fndb;
  2913. struct bna_txf *txf = &tx->txf;
  2914. void __iomem *base_addr;
  2915. unsigned long off;
  2916. writel(BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2917. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET),
  2918. tx->bna->regs.page_addr);
  2919. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2920. TX_FNDB_RAM_BASE_OFFSET);
  2921. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2922. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2923. writel(((u32)txf->vlan << 16) | txf->ctrl_flags,
  2924. base_addr + off);
  2925. if (tx->txf.txf_id < 32)
  2926. tx->bna->tx_mod.txf_bmap[0] |= ((u32)1 << tx->txf.txf_id);
  2927. else
  2928. tx->bna->tx_mod.txf_bmap[1] |= ((u32)
  2929. 1 << (tx->txf.txf_id - 32));
  2930. }
  2931. static void
  2932. __bna_txf_stop(struct bna_tx *tx)
  2933. {
  2934. struct bna_tx_fndb_ram *tx_fndb;
  2935. u32 page_num;
  2936. u32 ctl_flags;
  2937. struct bna_txf *txf = &tx->txf;
  2938. void __iomem *base_addr;
  2939. unsigned long off;
  2940. /* retrieve the running txf_flags & turn off enable bit */
  2941. page_num = BNA_GET_PAGE_NUM(LUT0_MEM_BLK_BASE_PG_NUM +
  2942. (tx->bna->port_num * 2), TX_FNDB_RAM_BASE_OFFSET);
  2943. writel(page_num, tx->bna->regs.page_addr);
  2944. base_addr = BNA_GET_MEM_BASE_ADDR(tx->bna->pcidev.pci_bar_kva,
  2945. TX_FNDB_RAM_BASE_OFFSET);
  2946. tx_fndb = (struct bna_tx_fndb_ram *)0;
  2947. off = (unsigned long)&tx_fndb[txf->txf_id].vlan_n_ctrl_flags;
  2948. ctl_flags = readl(base_addr + off);
  2949. ctl_flags &= ~BFI_TXF_CF_ENABLE;
  2950. writel(ctl_flags, base_addr + off);
  2951. if (tx->txf.txf_id < 32)
  2952. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)1 << tx->txf.txf_id);
  2953. else
  2954. tx->bna->tx_mod.txf_bmap[0] &= ~((u32)
  2955. 1 << (tx->txf.txf_id - 32));
  2956. }
  2957. static void
  2958. __bna_txf_stat_clr(struct bna_tx *tx)
  2959. {
  2960. struct bfi_ll_stats_req ll_req;
  2961. u32 txf_bmap[2] = {0, 0};
  2962. if (tx->txf.txf_id < 32)
  2963. txf_bmap[0] = ((u32)1 << tx->txf.txf_id);
  2964. else
  2965. txf_bmap[1] = ((u32)1 << (tx->txf.txf_id - 32));
  2966. bfi_h2i_set(ll_req.mh, BFI_MC_LL, BFI_LL_H2I_STATS_CLEAR_REQ, 0);
  2967. ll_req.stats_mask = 0;
  2968. ll_req.rxf_id_mask[0] = 0;
  2969. ll_req.rxf_id_mask[1] = 0;
  2970. ll_req.txf_id_mask[0] = htonl(txf_bmap[0]);
  2971. ll_req.txf_id_mask[1] = htonl(txf_bmap[1]);
  2972. bna_mbox_qe_fill(&tx->mbox_qe, &ll_req, sizeof(ll_req),
  2973. bna_tx_cb_stats_cleared, tx);
  2974. bna_mbox_send(tx->bna, &tx->mbox_qe);
  2975. }
  2976. static void
  2977. __bna_tx_start(struct bna_tx *tx)
  2978. {
  2979. struct bna_txq *txq;
  2980. struct list_head *qe;
  2981. list_for_each(qe, &tx->txq_q) {
  2982. txq = (struct bna_txq *)qe;
  2983. bna_ib_start(txq->ib);
  2984. __bna_txq_start(tx, txq);
  2985. }
  2986. __bna_txf_start(tx);
  2987. list_for_each(qe, &tx->txq_q) {
  2988. txq = (struct bna_txq *)qe;
  2989. txq->tcb->priority = txq->priority;
  2990. (tx->tx_resume_cbfn)(tx->bna->bnad, txq->tcb);
  2991. }
  2992. }
  2993. static void
  2994. __bna_tx_stop(struct bna_tx *tx)
  2995. {
  2996. struct bna_txq *txq;
  2997. struct list_head *qe;
  2998. list_for_each(qe, &tx->txq_q) {
  2999. txq = (struct bna_txq *)qe;
  3000. (tx->tx_stall_cbfn)(tx->bna->bnad, txq->tcb);
  3001. }
  3002. __bna_txf_stop(tx);
  3003. list_for_each(qe, &tx->txq_q) {
  3004. txq = (struct bna_txq *)qe;
  3005. bfa_wc_up(&tx->txq_stop_wc);
  3006. }
  3007. list_for_each(qe, &tx->txq_q) {
  3008. txq = (struct bna_txq *)qe;
  3009. __bna_txq_stop(tx, txq);
  3010. }
  3011. }
  3012. static void
  3013. bna_txq_qpt_setup(struct bna_txq *txq, int page_count, int page_size,
  3014. struct bna_mem_descr *qpt_mem,
  3015. struct bna_mem_descr *swqpt_mem,
  3016. struct bna_mem_descr *page_mem)
  3017. {
  3018. int i;
  3019. txq->qpt.hw_qpt_ptr.lsb = qpt_mem->dma.lsb;
  3020. txq->qpt.hw_qpt_ptr.msb = qpt_mem->dma.msb;
  3021. txq->qpt.kv_qpt_ptr = qpt_mem->kva;
  3022. txq->qpt.page_count = page_count;
  3023. txq->qpt.page_size = page_size;
  3024. txq->tcb->sw_qpt = (void **) swqpt_mem->kva;
  3025. for (i = 0; i < page_count; i++) {
  3026. txq->tcb->sw_qpt[i] = page_mem[i].kva;
  3027. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].lsb =
  3028. page_mem[i].dma.lsb;
  3029. ((struct bna_dma_addr *)txq->qpt.kv_qpt_ptr)[i].msb =
  3030. page_mem[i].dma.msb;
  3031. }
  3032. }
  3033. static void
  3034. bna_tx_free(struct bna_tx *tx)
  3035. {
  3036. struct bna_tx_mod *tx_mod = &tx->bna->tx_mod;
  3037. struct bna_txq *txq;
  3038. struct bna_ib_mod *ib_mod = &tx->bna->ib_mod;
  3039. struct list_head *qe;
  3040. while (!list_empty(&tx->txq_q)) {
  3041. bfa_q_deq(&tx->txq_q, &txq);
  3042. bfa_q_qe_init(&txq->qe);
  3043. if (txq->ib) {
  3044. if (txq->ib_seg_offset != -1)
  3045. bna_ib_release_idx(txq->ib,
  3046. txq->ib_seg_offset);
  3047. bna_ib_put(ib_mod, txq->ib);
  3048. txq->ib = NULL;
  3049. }
  3050. txq->tcb = NULL;
  3051. txq->tx = NULL;
  3052. list_add_tail(&txq->qe, &tx_mod->txq_free_q);
  3053. }
  3054. list_for_each(qe, &tx_mod->tx_active_q) {
  3055. if (qe == &tx->qe) {
  3056. list_del(&tx->qe);
  3057. bfa_q_qe_init(&tx->qe);
  3058. break;
  3059. }
  3060. }
  3061. tx->bna = NULL;
  3062. tx->priv = NULL;
  3063. list_add_tail(&tx->qe, &tx_mod->tx_free_q);
  3064. }
  3065. static void
  3066. bna_tx_cb_txq_stopped(void *arg, int status)
  3067. {
  3068. struct bna_tx *tx = (struct bna_tx *)arg;
  3069. bfa_q_qe_init(&tx->mbox_qe.qe);
  3070. bfa_wc_down(&tx->txq_stop_wc);
  3071. }
  3072. static void
  3073. bna_tx_cb_txq_stopped_all(void *arg)
  3074. {
  3075. struct bna_tx *tx = (struct bna_tx *)arg;
  3076. bfa_fsm_send_event(tx, TX_E_TXQ_STOPPED);
  3077. }
  3078. static void
  3079. bna_tx_cb_stats_cleared(void *arg, int status)
  3080. {
  3081. struct bna_tx *tx = (struct bna_tx *)arg;
  3082. bfa_q_qe_init(&tx->mbox_qe.qe);
  3083. bfa_fsm_send_event(tx, TX_E_STAT_CLEARED);
  3084. }
  3085. static void
  3086. bna_tx_start(struct bna_tx *tx)
  3087. {
  3088. tx->flags |= BNA_TX_F_PORT_STARTED;
  3089. if (tx->flags & BNA_TX_F_ENABLED)
  3090. bfa_fsm_send_event(tx, TX_E_START);
  3091. }
  3092. static void
  3093. bna_tx_stop(struct bna_tx *tx)
  3094. {
  3095. tx->stop_cbfn = bna_tx_mod_cb_tx_stopped;
  3096. tx->stop_cbarg = &tx->bna->tx_mod;
  3097. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3098. bfa_fsm_send_event(tx, TX_E_STOP);
  3099. }
  3100. static void
  3101. bna_tx_fail(struct bna_tx *tx)
  3102. {
  3103. tx->flags &= ~BNA_TX_F_PORT_STARTED;
  3104. bfa_fsm_send_event(tx, TX_E_FAIL);
  3105. }
  3106. static void
  3107. bna_tx_prio_changed(struct bna_tx *tx, int prio)
  3108. {
  3109. struct bna_txq *txq;
  3110. struct list_head *qe;
  3111. list_for_each(qe, &tx->txq_q) {
  3112. txq = (struct bna_txq *)qe;
  3113. txq->priority = prio;
  3114. }
  3115. bfa_fsm_send_event(tx, TX_E_PRIO_CHANGE);
  3116. }
  3117. static void
  3118. bna_tx_cee_link_status(struct bna_tx *tx, int cee_link)
  3119. {
  3120. if (cee_link)
  3121. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3122. else
  3123. tx->flags &= ~BNA_TX_F_PRIO_LOCK;
  3124. }
  3125. static void
  3126. bna_tx_mod_cb_tx_stopped(void *arg, struct bna_tx *tx,
  3127. enum bna_cb_status status)
  3128. {
  3129. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3130. bfa_wc_down(&tx_mod->tx_stop_wc);
  3131. }
  3132. static void
  3133. bna_tx_mod_cb_tx_stopped_all(void *arg)
  3134. {
  3135. struct bna_tx_mod *tx_mod = (struct bna_tx_mod *)arg;
  3136. if (tx_mod->stop_cbfn)
  3137. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3138. tx_mod->stop_cbfn = NULL;
  3139. }
  3140. void
  3141. bna_tx_res_req(int num_txq, int txq_depth, struct bna_res_info *res_info)
  3142. {
  3143. u32 q_size;
  3144. u32 page_count;
  3145. struct bna_mem_info *mem_info;
  3146. res_info[BNA_TX_RES_MEM_T_TCB].res_type = BNA_RES_T_MEM;
  3147. mem_info = &res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info;
  3148. mem_info->mem_type = BNA_MEM_T_KVA;
  3149. mem_info->len = sizeof(struct bna_tcb);
  3150. mem_info->num = num_txq;
  3151. q_size = txq_depth * BFI_TXQ_WI_SIZE;
  3152. q_size = ALIGN(q_size, PAGE_SIZE);
  3153. page_count = q_size >> PAGE_SHIFT;
  3154. res_info[BNA_TX_RES_MEM_T_QPT].res_type = BNA_RES_T_MEM;
  3155. mem_info = &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info;
  3156. mem_info->mem_type = BNA_MEM_T_DMA;
  3157. mem_info->len = page_count * sizeof(struct bna_dma_addr);
  3158. mem_info->num = num_txq;
  3159. res_info[BNA_TX_RES_MEM_T_SWQPT].res_type = BNA_RES_T_MEM;
  3160. mem_info = &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info;
  3161. mem_info->mem_type = BNA_MEM_T_KVA;
  3162. mem_info->len = page_count * sizeof(void *);
  3163. mem_info->num = num_txq;
  3164. res_info[BNA_TX_RES_MEM_T_PAGE].res_type = BNA_RES_T_MEM;
  3165. mem_info = &res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info;
  3166. mem_info->mem_type = BNA_MEM_T_DMA;
  3167. mem_info->len = PAGE_SIZE;
  3168. mem_info->num = num_txq * page_count;
  3169. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_type = BNA_RES_T_INTR;
  3170. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.intr_type =
  3171. BNA_INTR_T_MSIX;
  3172. res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info.num = num_txq;
  3173. }
  3174. struct bna_tx *
  3175. bna_tx_create(struct bna *bna, struct bnad *bnad,
  3176. struct bna_tx_config *tx_cfg,
  3177. struct bna_tx_event_cbfn *tx_cbfn,
  3178. struct bna_res_info *res_info, void *priv)
  3179. {
  3180. struct bna_intr_info *intr_info;
  3181. struct bna_tx_mod *tx_mod = &bna->tx_mod;
  3182. struct bna_tx *tx;
  3183. struct bna_txq *txq;
  3184. struct list_head *qe;
  3185. struct bna_ib_mod *ib_mod = &bna->ib_mod;
  3186. struct bna_doorbell_qset *qset;
  3187. struct bna_ib_config ib_config;
  3188. int page_count;
  3189. int page_size;
  3190. int page_idx;
  3191. int i;
  3192. unsigned long off;
  3193. intr_info = &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info;
  3194. page_count = (res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.num) /
  3195. tx_cfg->num_txq;
  3196. page_size = res_info[BNA_TX_RES_MEM_T_PAGE].res_u.mem_info.len;
  3197. /**
  3198. * Get resources
  3199. */
  3200. if ((intr_info->num != 1) && (intr_info->num != tx_cfg->num_txq))
  3201. return NULL;
  3202. /* Tx */
  3203. if (list_empty(&tx_mod->tx_free_q))
  3204. return NULL;
  3205. bfa_q_deq(&tx_mod->tx_free_q, &tx);
  3206. bfa_q_qe_init(&tx->qe);
  3207. /* TxQs */
  3208. INIT_LIST_HEAD(&tx->txq_q);
  3209. for (i = 0; i < tx_cfg->num_txq; i++) {
  3210. if (list_empty(&tx_mod->txq_free_q))
  3211. goto err_return;
  3212. bfa_q_deq(&tx_mod->txq_free_q, &txq);
  3213. bfa_q_qe_init(&txq->qe);
  3214. list_add_tail(&txq->qe, &tx->txq_q);
  3215. txq->ib = NULL;
  3216. txq->ib_seg_offset = -1;
  3217. txq->tx = tx;
  3218. }
  3219. /* IBs */
  3220. i = 0;
  3221. list_for_each(qe, &tx->txq_q) {
  3222. txq = (struct bna_txq *)qe;
  3223. if (intr_info->num == 1)
  3224. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3225. intr_info->idl[0].vector);
  3226. else
  3227. txq->ib = bna_ib_get(ib_mod, intr_info->intr_type,
  3228. intr_info->idl[i].vector);
  3229. if (txq->ib == NULL)
  3230. goto err_return;
  3231. txq->ib_seg_offset = bna_ib_reserve_idx(txq->ib);
  3232. if (txq->ib_seg_offset == -1)
  3233. goto err_return;
  3234. i++;
  3235. }
  3236. /*
  3237. * Initialize
  3238. */
  3239. /* Tx */
  3240. tx->tcb_setup_cbfn = tx_cbfn->tcb_setup_cbfn;
  3241. tx->tcb_destroy_cbfn = tx_cbfn->tcb_destroy_cbfn;
  3242. /* Following callbacks are mandatory */
  3243. tx->tx_stall_cbfn = tx_cbfn->tx_stall_cbfn;
  3244. tx->tx_resume_cbfn = tx_cbfn->tx_resume_cbfn;
  3245. tx->tx_cleanup_cbfn = tx_cbfn->tx_cleanup_cbfn;
  3246. list_add_tail(&tx->qe, &tx_mod->tx_active_q);
  3247. tx->bna = bna;
  3248. tx->priv = priv;
  3249. tx->txq_stop_wc.wc_resume = bna_tx_cb_txq_stopped_all;
  3250. tx->txq_stop_wc.wc_cbarg = tx;
  3251. tx->txq_stop_wc.wc_count = 0;
  3252. tx->type = tx_cfg->tx_type;
  3253. tx->flags = 0;
  3254. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_STARTED) {
  3255. switch (tx->type) {
  3256. case BNA_TX_T_REGULAR:
  3257. if (!(tx->bna->tx_mod.flags &
  3258. BNA_TX_MOD_F_PORT_LOOPBACK))
  3259. tx->flags |= BNA_TX_F_PORT_STARTED;
  3260. break;
  3261. case BNA_TX_T_LOOPBACK:
  3262. if (tx->bna->tx_mod.flags & BNA_TX_MOD_F_PORT_LOOPBACK)
  3263. tx->flags |= BNA_TX_F_PORT_STARTED;
  3264. break;
  3265. }
  3266. }
  3267. if (tx->bna->tx_mod.cee_link)
  3268. tx->flags |= BNA_TX_F_PRIO_LOCK;
  3269. /* TxQ */
  3270. i = 0;
  3271. page_idx = 0;
  3272. list_for_each(qe, &tx->txq_q) {
  3273. txq = (struct bna_txq *)qe;
  3274. txq->priority = tx_mod->priority;
  3275. txq->tcb = (struct bna_tcb *)
  3276. res_info[BNA_TX_RES_MEM_T_TCB].res_u.mem_info.mdl[i].kva;
  3277. txq->tx_packets = 0;
  3278. txq->tx_bytes = 0;
  3279. /* IB */
  3280. ib_config.coalescing_timeo = BFI_TX_COALESCING_TIMEO;
  3281. ib_config.interpkt_timeo = 0; /* Not used */
  3282. ib_config.interpkt_count = BFI_TX_INTERPKT_COUNT;
  3283. ib_config.ctrl_flags = (BFI_IB_CF_INTER_PKT_DMA |
  3284. BFI_IB_CF_INT_ENABLE |
  3285. BFI_IB_CF_COALESCING_MODE);
  3286. bna_ib_config(txq->ib, &ib_config);
  3287. /* TCB */
  3288. txq->tcb->producer_index = 0;
  3289. txq->tcb->consumer_index = 0;
  3290. txq->tcb->hw_consumer_index = (volatile u32 *)
  3291. ((volatile u8 *)txq->ib->ib_seg_host_addr_kva +
  3292. (txq->ib_seg_offset * BFI_IBIDX_SIZE));
  3293. *(txq->tcb->hw_consumer_index) = 0;
  3294. txq->tcb->q_depth = tx_cfg->txq_depth;
  3295. txq->tcb->unmap_q = (void *)
  3296. res_info[BNA_TX_RES_MEM_T_UNMAPQ].res_u.mem_info.mdl[i].kva;
  3297. qset = (struct bna_doorbell_qset *)0;
  3298. off = (unsigned long)&qset[txq->txq_id].txq[0];
  3299. txq->tcb->q_dbell = off +
  3300. BNA_GET_DOORBELL_BASE_ADDR(bna->pcidev.pci_bar_kva);
  3301. txq->tcb->i_dbell = &txq->ib->door_bell;
  3302. txq->tcb->intr_type = intr_info->intr_type;
  3303. txq->tcb->intr_vector = (intr_info->num == 1) ?
  3304. intr_info->idl[0].vector :
  3305. intr_info->idl[i].vector;
  3306. txq->tcb->txq = txq;
  3307. txq->tcb->bnad = bnad;
  3308. txq->tcb->id = i;
  3309. /* QPT, SWQPT, Pages */
  3310. bna_txq_qpt_setup(txq, page_count, page_size,
  3311. &res_info[BNA_TX_RES_MEM_T_QPT].res_u.mem_info.mdl[i],
  3312. &res_info[BNA_TX_RES_MEM_T_SWQPT].res_u.mem_info.mdl[i],
  3313. &res_info[BNA_TX_RES_MEM_T_PAGE].
  3314. res_u.mem_info.mdl[page_idx]);
  3315. txq->tcb->page_idx = page_idx;
  3316. txq->tcb->page_count = page_count;
  3317. page_idx += page_count;
  3318. /* Callback to bnad for setting up TCB */
  3319. if (tx->tcb_setup_cbfn)
  3320. (tx->tcb_setup_cbfn)(bna->bnad, txq->tcb);
  3321. i++;
  3322. }
  3323. /* TxF */
  3324. tx->txf.ctrl_flags = BFI_TXF_CF_ENABLE | BFI_TXF_CF_VLAN_WI_BASED;
  3325. tx->txf.vlan = 0;
  3326. /* Mbox element */
  3327. bfa_q_qe_init(&tx->mbox_qe.qe);
  3328. bfa_fsm_set_state(tx, bna_tx_sm_stopped);
  3329. return tx;
  3330. err_return:
  3331. bna_tx_free(tx);
  3332. return NULL;
  3333. }
  3334. void
  3335. bna_tx_destroy(struct bna_tx *tx)
  3336. {
  3337. /* Callback to bnad for destroying TCB */
  3338. if (tx->tcb_destroy_cbfn) {
  3339. struct bna_txq *txq;
  3340. struct list_head *qe;
  3341. list_for_each(qe, &tx->txq_q) {
  3342. txq = (struct bna_txq *)qe;
  3343. (tx->tcb_destroy_cbfn)(tx->bna->bnad, txq->tcb);
  3344. }
  3345. }
  3346. bna_tx_free(tx);
  3347. }
  3348. void
  3349. bna_tx_enable(struct bna_tx *tx)
  3350. {
  3351. if (tx->fsm != (bfa_sm_t)bna_tx_sm_stopped)
  3352. return;
  3353. tx->flags |= BNA_TX_F_ENABLED;
  3354. if (tx->flags & BNA_TX_F_PORT_STARTED)
  3355. bfa_fsm_send_event(tx, TX_E_START);
  3356. }
  3357. void
  3358. bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
  3359. void (*cbfn)(void *, struct bna_tx *, enum bna_cb_status))
  3360. {
  3361. if (type == BNA_SOFT_CLEANUP) {
  3362. (*cbfn)(tx->bna->bnad, tx, BNA_CB_SUCCESS);
  3363. return;
  3364. }
  3365. tx->stop_cbfn = cbfn;
  3366. tx->stop_cbarg = tx->bna->bnad;
  3367. tx->flags &= ~BNA_TX_F_ENABLED;
  3368. bfa_fsm_send_event(tx, TX_E_STOP);
  3369. }
  3370. int
  3371. bna_tx_state_get(struct bna_tx *tx)
  3372. {
  3373. return bfa_sm_to_state(tx_sm_table, tx->fsm);
  3374. }
  3375. void
  3376. bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
  3377. struct bna_res_info *res_info)
  3378. {
  3379. int i;
  3380. tx_mod->bna = bna;
  3381. tx_mod->flags = 0;
  3382. tx_mod->tx = (struct bna_tx *)
  3383. res_info[BNA_RES_MEM_T_TX_ARRAY].res_u.mem_info.mdl[0].kva;
  3384. tx_mod->txq = (struct bna_txq *)
  3385. res_info[BNA_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mdl[0].kva;
  3386. INIT_LIST_HEAD(&tx_mod->tx_free_q);
  3387. INIT_LIST_HEAD(&tx_mod->tx_active_q);
  3388. INIT_LIST_HEAD(&tx_mod->txq_free_q);
  3389. for (i = 0; i < BFI_MAX_TXQ; i++) {
  3390. tx_mod->tx[i].txf.txf_id = i;
  3391. bfa_q_qe_init(&tx_mod->tx[i].qe);
  3392. list_add_tail(&tx_mod->tx[i].qe, &tx_mod->tx_free_q);
  3393. tx_mod->txq[i].txq_id = i;
  3394. bfa_q_qe_init(&tx_mod->txq[i].qe);
  3395. list_add_tail(&tx_mod->txq[i].qe, &tx_mod->txq_free_q);
  3396. }
  3397. tx_mod->tx_stop_wc.wc_resume = bna_tx_mod_cb_tx_stopped_all;
  3398. tx_mod->tx_stop_wc.wc_cbarg = tx_mod;
  3399. tx_mod->tx_stop_wc.wc_count = 0;
  3400. }
  3401. void
  3402. bna_tx_mod_uninit(struct bna_tx_mod *tx_mod)
  3403. {
  3404. struct list_head *qe;
  3405. int i;
  3406. i = 0;
  3407. list_for_each(qe, &tx_mod->tx_free_q)
  3408. i++;
  3409. i = 0;
  3410. list_for_each(qe, &tx_mod->txq_free_q)
  3411. i++;
  3412. tx_mod->bna = NULL;
  3413. }
  3414. void
  3415. bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3416. {
  3417. struct bna_tx *tx;
  3418. struct list_head *qe;
  3419. tx_mod->flags |= BNA_TX_MOD_F_PORT_STARTED;
  3420. if (type == BNA_TX_T_LOOPBACK)
  3421. tx_mod->flags |= BNA_TX_MOD_F_PORT_LOOPBACK;
  3422. list_for_each(qe, &tx_mod->tx_active_q) {
  3423. tx = (struct bna_tx *)qe;
  3424. if (tx->type == type)
  3425. bna_tx_start(tx);
  3426. }
  3427. }
  3428. void
  3429. bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type)
  3430. {
  3431. struct bna_tx *tx;
  3432. struct list_head *qe;
  3433. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3434. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3435. tx_mod->stop_cbfn = bna_port_cb_tx_stopped;
  3436. /**
  3437. * Before calling bna_tx_stop(), increment tx_stop_wc as many times
  3438. * as we are going to call bna_tx_stop
  3439. */
  3440. list_for_each(qe, &tx_mod->tx_active_q) {
  3441. tx = (struct bna_tx *)qe;
  3442. if (tx->type == type)
  3443. bfa_wc_up(&tx_mod->tx_stop_wc);
  3444. }
  3445. if (tx_mod->tx_stop_wc.wc_count == 0) {
  3446. tx_mod->stop_cbfn(&tx_mod->bna->port, BNA_CB_SUCCESS);
  3447. tx_mod->stop_cbfn = NULL;
  3448. return;
  3449. }
  3450. list_for_each(qe, &tx_mod->tx_active_q) {
  3451. tx = (struct bna_tx *)qe;
  3452. if (tx->type == type)
  3453. bna_tx_stop(tx);
  3454. }
  3455. }
  3456. void
  3457. bna_tx_mod_fail(struct bna_tx_mod *tx_mod)
  3458. {
  3459. struct bna_tx *tx;
  3460. struct list_head *qe;
  3461. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_STARTED;
  3462. tx_mod->flags &= ~BNA_TX_MOD_F_PORT_LOOPBACK;
  3463. list_for_each(qe, &tx_mod->tx_active_q) {
  3464. tx = (struct bna_tx *)qe;
  3465. bna_tx_fail(tx);
  3466. }
  3467. }
  3468. void
  3469. bna_tx_mod_prio_changed(struct bna_tx_mod *tx_mod, int prio)
  3470. {
  3471. struct bna_tx *tx;
  3472. struct list_head *qe;
  3473. if (prio != tx_mod->priority) {
  3474. tx_mod->priority = prio;
  3475. list_for_each(qe, &tx_mod->tx_active_q) {
  3476. tx = (struct bna_tx *)qe;
  3477. bna_tx_prio_changed(tx, prio);
  3478. }
  3479. }
  3480. }
  3481. void
  3482. bna_tx_mod_cee_link_status(struct bna_tx_mod *tx_mod, int cee_link)
  3483. {
  3484. struct bna_tx *tx;
  3485. struct list_head *qe;
  3486. tx_mod->cee_link = cee_link;
  3487. list_for_each(qe, &tx_mod->tx_active_q) {
  3488. tx = (struct bna_tx *)qe;
  3489. bna_tx_cee_link_status(tx, cee_link);
  3490. }
  3491. }