vxge-main.c 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2010 Exar Corp.
  13. *
  14. * The module loadable parameters that are supported by the driver and a brief
  15. * explanation of all the variables:
  16. * vlan_tag_strip:
  17. * Strip VLAN Tag enable/disable. Instructs the device to remove
  18. * the VLAN tag from all received tagged frames that are not
  19. * replicated at the internal L2 switch.
  20. * 0 - Do not strip the VLAN tag.
  21. * 1 - Strip the VLAN tag.
  22. *
  23. * addr_learn_en:
  24. * Enable learning the mac address of the guest OS interface in
  25. * a virtualization environment.
  26. * 0 - DISABLE
  27. * 1 - ENABLE
  28. *
  29. * max_config_port:
  30. * Maximum number of port to be supported.
  31. * MIN -1 and MAX - 2
  32. *
  33. * max_config_vpath:
  34. * This configures the maximum no of VPATH configures for each
  35. * device function.
  36. * MIN - 1 and MAX - 17
  37. *
  38. * max_config_dev:
  39. * This configures maximum no of Device function to be enabled.
  40. * MIN - 1 and MAX - 17
  41. *
  42. ******************************************************************************/
  43. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  44. #include <linux/bitops.h>
  45. #include <linux/if_vlan.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/pci.h>
  48. #include <linux/slab.h>
  49. #include <linux/tcp.h>
  50. #include <net/ip.h>
  51. #include <linux/netdevice.h>
  52. #include <linux/etherdevice.h>
  53. #include <linux/firmware.h>
  54. #include <linux/net_tstamp.h>
  55. #include <linux/prefetch.h>
  56. #include "vxge-main.h"
  57. #include "vxge-reg.h"
  58. MODULE_LICENSE("Dual BSD/GPL");
  59. MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
  60. "Virtualized Server Adapter");
  61. static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
  62. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
  63. PCI_ANY_ID},
  64. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
  65. PCI_ANY_ID},
  66. {0}
  67. };
  68. MODULE_DEVICE_TABLE(pci, vxge_id_table);
  69. VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
  70. VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
  71. VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
  72. VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
  73. VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
  74. VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
  75. static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
  76. {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
  77. static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
  78. {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
  79. module_param_array(bw_percentage, uint, NULL, 0);
  80. static struct vxge_drv_config *driver_config;
  81. static inline int is_vxge_card_up(struct vxgedev *vdev)
  82. {
  83. return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  84. }
  85. static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
  86. {
  87. struct sk_buff **skb_ptr = NULL;
  88. struct sk_buff **temp;
  89. #define NR_SKB_COMPLETED 128
  90. struct sk_buff *completed[NR_SKB_COMPLETED];
  91. int more;
  92. do {
  93. more = 0;
  94. skb_ptr = completed;
  95. if (__netif_tx_trylock(fifo->txq)) {
  96. vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
  97. NR_SKB_COMPLETED, &more);
  98. __netif_tx_unlock(fifo->txq);
  99. }
  100. /* free SKBs */
  101. for (temp = completed; temp != skb_ptr; temp++)
  102. dev_kfree_skb_irq(*temp);
  103. } while (more);
  104. }
  105. static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
  106. {
  107. int i;
  108. /* Complete all transmits */
  109. for (i = 0; i < vdev->no_of_vpath; i++)
  110. VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
  111. }
  112. static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
  113. {
  114. int i;
  115. struct vxge_ring *ring;
  116. /* Complete all receives*/
  117. for (i = 0; i < vdev->no_of_vpath; i++) {
  118. ring = &vdev->vpaths[i].ring;
  119. vxge_hw_vpath_poll_rx(ring->handle);
  120. }
  121. }
  122. /*
  123. * vxge_callback_link_up
  124. *
  125. * This function is called during interrupt context to notify link up state
  126. * change.
  127. */
  128. static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
  129. {
  130. struct net_device *dev = hldev->ndev;
  131. struct vxgedev *vdev = netdev_priv(dev);
  132. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  133. vdev->ndev->name, __func__, __LINE__);
  134. netdev_notice(vdev->ndev, "Link Up\n");
  135. vdev->stats.link_up++;
  136. netif_carrier_on(vdev->ndev);
  137. netif_tx_wake_all_queues(vdev->ndev);
  138. vxge_debug_entryexit(VXGE_TRACE,
  139. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  140. }
  141. /*
  142. * vxge_callback_link_down
  143. *
  144. * This function is called during interrupt context to notify link down state
  145. * change.
  146. */
  147. static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
  148. {
  149. struct net_device *dev = hldev->ndev;
  150. struct vxgedev *vdev = netdev_priv(dev);
  151. vxge_debug_entryexit(VXGE_TRACE,
  152. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  153. netdev_notice(vdev->ndev, "Link Down\n");
  154. vdev->stats.link_down++;
  155. netif_carrier_off(vdev->ndev);
  156. netif_tx_stop_all_queues(vdev->ndev);
  157. vxge_debug_entryexit(VXGE_TRACE,
  158. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  159. }
  160. /*
  161. * vxge_rx_alloc
  162. *
  163. * Allocate SKB.
  164. */
  165. static struct sk_buff *
  166. vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
  167. {
  168. struct net_device *dev;
  169. struct sk_buff *skb;
  170. struct vxge_rx_priv *rx_priv;
  171. dev = ring->ndev;
  172. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  173. ring->ndev->name, __func__, __LINE__);
  174. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  175. /* try to allocate skb first. this one may fail */
  176. skb = netdev_alloc_skb(dev, skb_size +
  177. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  178. if (skb == NULL) {
  179. vxge_debug_mem(VXGE_ERR,
  180. "%s: out of memory to allocate SKB", dev->name);
  181. ring->stats.skb_alloc_fail++;
  182. return NULL;
  183. }
  184. vxge_debug_mem(VXGE_TRACE,
  185. "%s: %s:%d Skb : 0x%p", ring->ndev->name,
  186. __func__, __LINE__, skb);
  187. skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  188. rx_priv->skb = skb;
  189. rx_priv->skb_data = NULL;
  190. rx_priv->data_size = skb_size;
  191. vxge_debug_entryexit(VXGE_TRACE,
  192. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  193. return skb;
  194. }
  195. /*
  196. * vxge_rx_map
  197. */
  198. static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
  199. {
  200. struct vxge_rx_priv *rx_priv;
  201. dma_addr_t dma_addr;
  202. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  203. ring->ndev->name, __func__, __LINE__);
  204. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  205. rx_priv->skb_data = rx_priv->skb->data;
  206. dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
  207. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  208. if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
  209. ring->stats.pci_map_fail++;
  210. return -EIO;
  211. }
  212. vxge_debug_mem(VXGE_TRACE,
  213. "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
  214. ring->ndev->name, __func__, __LINE__,
  215. (unsigned long long)dma_addr);
  216. vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
  217. rx_priv->data_dma = dma_addr;
  218. vxge_debug_entryexit(VXGE_TRACE,
  219. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  220. return 0;
  221. }
  222. /*
  223. * vxge_rx_initial_replenish
  224. * Allocation of RxD as an initial replenish procedure.
  225. */
  226. static enum vxge_hw_status
  227. vxge_rx_initial_replenish(void *dtrh, void *userdata)
  228. {
  229. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  230. struct vxge_rx_priv *rx_priv;
  231. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  232. ring->ndev->name, __func__, __LINE__);
  233. if (vxge_rx_alloc(dtrh, ring,
  234. VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
  235. return VXGE_HW_FAIL;
  236. if (vxge_rx_map(dtrh, ring)) {
  237. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  238. dev_kfree_skb(rx_priv->skb);
  239. return VXGE_HW_FAIL;
  240. }
  241. vxge_debug_entryexit(VXGE_TRACE,
  242. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  243. return VXGE_HW_OK;
  244. }
  245. static inline void
  246. vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
  247. int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
  248. {
  249. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  250. ring->ndev->name, __func__, __LINE__);
  251. skb_record_rx_queue(skb, ring->driver_id);
  252. skb->protocol = eth_type_trans(skb, ring->ndev);
  253. u64_stats_update_begin(&ring->stats.syncp);
  254. ring->stats.rx_frms++;
  255. ring->stats.rx_bytes += pkt_length;
  256. if (skb->pkt_type == PACKET_MULTICAST)
  257. ring->stats.rx_mcast++;
  258. u64_stats_update_end(&ring->stats.syncp);
  259. vxge_debug_rx(VXGE_TRACE,
  260. "%s: %s:%d skb protocol = %d",
  261. ring->ndev->name, __func__, __LINE__, skb->protocol);
  262. if (ext_info->vlan &&
  263. ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
  264. __vlan_hwaccel_put_tag(skb, ext_info->vlan);
  265. napi_gro_receive(ring->napi_p, skb);
  266. vxge_debug_entryexit(VXGE_TRACE,
  267. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  268. }
  269. static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
  270. struct vxge_rx_priv *rx_priv)
  271. {
  272. pci_dma_sync_single_for_device(ring->pdev,
  273. rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
  274. vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
  275. vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
  276. }
  277. static inline void vxge_post(int *dtr_cnt, void **first_dtr,
  278. void *post_dtr, struct __vxge_hw_ring *ringh)
  279. {
  280. int dtr_count = *dtr_cnt;
  281. if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
  282. if (*first_dtr)
  283. vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
  284. *first_dtr = post_dtr;
  285. } else
  286. vxge_hw_ring_rxd_post_post(ringh, post_dtr);
  287. dtr_count++;
  288. *dtr_cnt = dtr_count;
  289. }
  290. /*
  291. * vxge_rx_1b_compl
  292. *
  293. * If the interrupt is because of a received frame or if the receive ring
  294. * contains fresh as yet un-processed frames, this function is called.
  295. */
  296. static enum vxge_hw_status
  297. vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
  298. u8 t_code, void *userdata)
  299. {
  300. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  301. struct net_device *dev = ring->ndev;
  302. unsigned int dma_sizes;
  303. void *first_dtr = NULL;
  304. int dtr_cnt = 0;
  305. int data_size;
  306. dma_addr_t data_dma;
  307. int pkt_length;
  308. struct sk_buff *skb;
  309. struct vxge_rx_priv *rx_priv;
  310. struct vxge_hw_ring_rxd_info ext_info;
  311. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  312. ring->ndev->name, __func__, __LINE__);
  313. do {
  314. prefetch((char *)dtr + L1_CACHE_BYTES);
  315. rx_priv = vxge_hw_ring_rxd_private_get(dtr);
  316. skb = rx_priv->skb;
  317. data_size = rx_priv->data_size;
  318. data_dma = rx_priv->data_dma;
  319. prefetch(rx_priv->skb_data);
  320. vxge_debug_rx(VXGE_TRACE,
  321. "%s: %s:%d skb = 0x%p",
  322. ring->ndev->name, __func__, __LINE__, skb);
  323. vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
  324. pkt_length = dma_sizes;
  325. pkt_length -= ETH_FCS_LEN;
  326. vxge_debug_rx(VXGE_TRACE,
  327. "%s: %s:%d Packet Length = %d",
  328. ring->ndev->name, __func__, __LINE__, pkt_length);
  329. vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
  330. /* check skb validity */
  331. vxge_assert(skb);
  332. prefetch((char *)skb + L1_CACHE_BYTES);
  333. if (unlikely(t_code)) {
  334. if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
  335. VXGE_HW_OK) {
  336. ring->stats.rx_errors++;
  337. vxge_debug_rx(VXGE_TRACE,
  338. "%s: %s :%d Rx T_code is %d",
  339. ring->ndev->name, __func__,
  340. __LINE__, t_code);
  341. /* If the t_code is not supported and if the
  342. * t_code is other than 0x5 (unparseable packet
  343. * such as unknown UPV6 header), Drop it !!!
  344. */
  345. vxge_re_pre_post(dtr, ring, rx_priv);
  346. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  347. ring->stats.rx_dropped++;
  348. continue;
  349. }
  350. }
  351. if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
  352. if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
  353. if (!vxge_rx_map(dtr, ring)) {
  354. skb_put(skb, pkt_length);
  355. pci_unmap_single(ring->pdev, data_dma,
  356. data_size, PCI_DMA_FROMDEVICE);
  357. vxge_hw_ring_rxd_pre_post(ringh, dtr);
  358. vxge_post(&dtr_cnt, &first_dtr, dtr,
  359. ringh);
  360. } else {
  361. dev_kfree_skb(rx_priv->skb);
  362. rx_priv->skb = skb;
  363. rx_priv->data_size = data_size;
  364. vxge_re_pre_post(dtr, ring, rx_priv);
  365. vxge_post(&dtr_cnt, &first_dtr, dtr,
  366. ringh);
  367. ring->stats.rx_dropped++;
  368. break;
  369. }
  370. } else {
  371. vxge_re_pre_post(dtr, ring, rx_priv);
  372. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  373. ring->stats.rx_dropped++;
  374. break;
  375. }
  376. } else {
  377. struct sk_buff *skb_up;
  378. skb_up = netdev_alloc_skb(dev, pkt_length +
  379. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  380. if (skb_up != NULL) {
  381. skb_reserve(skb_up,
  382. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  383. pci_dma_sync_single_for_cpu(ring->pdev,
  384. data_dma, data_size,
  385. PCI_DMA_FROMDEVICE);
  386. vxge_debug_mem(VXGE_TRACE,
  387. "%s: %s:%d skb_up = %p",
  388. ring->ndev->name, __func__,
  389. __LINE__, skb);
  390. memcpy(skb_up->data, skb->data, pkt_length);
  391. vxge_re_pre_post(dtr, ring, rx_priv);
  392. vxge_post(&dtr_cnt, &first_dtr, dtr,
  393. ringh);
  394. /* will netif_rx small SKB instead */
  395. skb = skb_up;
  396. skb_put(skb, pkt_length);
  397. } else {
  398. vxge_re_pre_post(dtr, ring, rx_priv);
  399. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  400. vxge_debug_rx(VXGE_ERR,
  401. "%s: vxge_rx_1b_compl: out of "
  402. "memory", dev->name);
  403. ring->stats.skb_alloc_fail++;
  404. break;
  405. }
  406. }
  407. if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
  408. !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
  409. (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
  410. ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
  411. ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
  412. skb->ip_summed = CHECKSUM_UNNECESSARY;
  413. else
  414. skb_checksum_none_assert(skb);
  415. if (ring->rx_hwts) {
  416. struct skb_shared_hwtstamps *skb_hwts;
  417. u32 ns = *(u32 *)(skb->head + pkt_length);
  418. skb_hwts = skb_hwtstamps(skb);
  419. skb_hwts->hwtstamp = ns_to_ktime(ns);
  420. skb_hwts->syststamp.tv64 = 0;
  421. }
  422. /* rth_hash_type and rth_it_hit are non-zero regardless of
  423. * whether rss is enabled. Only the rth_value is zero/non-zero
  424. * if rss is disabled/enabled, so key off of that.
  425. */
  426. if (ext_info.rth_value)
  427. skb->rxhash = ext_info.rth_value;
  428. vxge_rx_complete(ring, skb, ext_info.vlan,
  429. pkt_length, &ext_info);
  430. ring->budget--;
  431. ring->pkts_processed++;
  432. if (!ring->budget)
  433. break;
  434. } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
  435. &t_code) == VXGE_HW_OK);
  436. if (first_dtr)
  437. vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
  438. vxge_debug_entryexit(VXGE_TRACE,
  439. "%s:%d Exiting...",
  440. __func__, __LINE__);
  441. return VXGE_HW_OK;
  442. }
  443. /*
  444. * vxge_xmit_compl
  445. *
  446. * If an interrupt was raised to indicate DMA complete of the Tx packet,
  447. * this function is called. It identifies the last TxD whose buffer was
  448. * freed and frees all skbs whose data have already DMA'ed into the NICs
  449. * internal memory.
  450. */
  451. static enum vxge_hw_status
  452. vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
  453. enum vxge_hw_fifo_tcode t_code, void *userdata,
  454. struct sk_buff ***skb_ptr, int nr_skb, int *more)
  455. {
  456. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  457. struct sk_buff *skb, **done_skb = *skb_ptr;
  458. int pkt_cnt = 0;
  459. vxge_debug_entryexit(VXGE_TRACE,
  460. "%s:%d Entered....", __func__, __LINE__);
  461. do {
  462. int frg_cnt;
  463. skb_frag_t *frag;
  464. int i = 0, j;
  465. struct vxge_tx_priv *txd_priv =
  466. vxge_hw_fifo_txdl_private_get(dtr);
  467. skb = txd_priv->skb;
  468. frg_cnt = skb_shinfo(skb)->nr_frags;
  469. frag = &skb_shinfo(skb)->frags[0];
  470. vxge_debug_tx(VXGE_TRACE,
  471. "%s: %s:%d fifo_hw = %p dtr = %p "
  472. "tcode = 0x%x", fifo->ndev->name, __func__,
  473. __LINE__, fifo_hw, dtr, t_code);
  474. /* check skb validity */
  475. vxge_assert(skb);
  476. vxge_debug_tx(VXGE_TRACE,
  477. "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
  478. fifo->ndev->name, __func__, __LINE__,
  479. skb, txd_priv, frg_cnt);
  480. if (unlikely(t_code)) {
  481. fifo->stats.tx_errors++;
  482. vxge_debug_tx(VXGE_ERR,
  483. "%s: tx: dtr %p completed due to "
  484. "error t_code %01x", fifo->ndev->name,
  485. dtr, t_code);
  486. vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
  487. }
  488. /* for unfragmented skb */
  489. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  490. skb_headlen(skb), PCI_DMA_TODEVICE);
  491. for (j = 0; j < frg_cnt; j++) {
  492. pci_unmap_page(fifo->pdev,
  493. txd_priv->dma_buffers[i++],
  494. frag->size, PCI_DMA_TODEVICE);
  495. frag += 1;
  496. }
  497. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  498. /* Updating the statistics block */
  499. u64_stats_update_begin(&fifo->stats.syncp);
  500. fifo->stats.tx_frms++;
  501. fifo->stats.tx_bytes += skb->len;
  502. u64_stats_update_end(&fifo->stats.syncp);
  503. *done_skb++ = skb;
  504. if (--nr_skb <= 0) {
  505. *more = 1;
  506. break;
  507. }
  508. pkt_cnt++;
  509. if (pkt_cnt > fifo->indicate_max_pkts)
  510. break;
  511. } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
  512. &dtr, &t_code) == VXGE_HW_OK);
  513. *skb_ptr = done_skb;
  514. if (netif_tx_queue_stopped(fifo->txq))
  515. netif_tx_wake_queue(fifo->txq);
  516. vxge_debug_entryexit(VXGE_TRACE,
  517. "%s: %s:%d Exiting...",
  518. fifo->ndev->name, __func__, __LINE__);
  519. return VXGE_HW_OK;
  520. }
  521. /* select a vpath to transmit the packet */
  522. static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
  523. {
  524. u16 queue_len, counter = 0;
  525. if (skb->protocol == htons(ETH_P_IP)) {
  526. struct iphdr *ip;
  527. struct tcphdr *th;
  528. ip = ip_hdr(skb);
  529. if (!ip_is_fragment(ip)) {
  530. th = (struct tcphdr *)(((unsigned char *)ip) +
  531. ip->ihl*4);
  532. queue_len = vdev->no_of_vpath;
  533. counter = (ntohs(th->source) +
  534. ntohs(th->dest)) &
  535. vdev->vpath_selector[queue_len - 1];
  536. if (counter >= queue_len)
  537. counter = queue_len - 1;
  538. }
  539. }
  540. return counter;
  541. }
  542. static enum vxge_hw_status vxge_search_mac_addr_in_list(
  543. struct vxge_vpath *vpath, u64 del_mac)
  544. {
  545. struct list_head *entry, *next;
  546. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  547. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
  548. return TRUE;
  549. }
  550. return FALSE;
  551. }
  552. static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
  553. {
  554. struct vxge_mac_addrs *new_mac_entry;
  555. u8 *mac_address = NULL;
  556. if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
  557. return TRUE;
  558. new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
  559. if (!new_mac_entry) {
  560. vxge_debug_mem(VXGE_ERR,
  561. "%s: memory allocation failed",
  562. VXGE_DRIVER_NAME);
  563. return FALSE;
  564. }
  565. list_add(&new_mac_entry->item, &vpath->mac_addr_list);
  566. /* Copy the new mac address to the list */
  567. mac_address = (u8 *)&new_mac_entry->macaddr;
  568. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  569. new_mac_entry->state = mac->state;
  570. vpath->mac_addr_cnt++;
  571. if (is_multicast_ether_addr(mac->macaddr))
  572. vpath->mcast_addr_cnt++;
  573. return TRUE;
  574. }
  575. /* Add a mac address to DA table */
  576. static enum vxge_hw_status
  577. vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  578. {
  579. enum vxge_hw_status status = VXGE_HW_OK;
  580. struct vxge_vpath *vpath;
  581. enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
  582. if (is_multicast_ether_addr(mac->macaddr))
  583. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
  584. else
  585. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
  586. vpath = &vdev->vpaths[mac->vpath_no];
  587. status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
  588. mac->macmask, duplicate_mode);
  589. if (status != VXGE_HW_OK) {
  590. vxge_debug_init(VXGE_ERR,
  591. "DA config add entry failed for vpath:%d",
  592. vpath->device_id);
  593. } else
  594. if (FALSE == vxge_mac_list_add(vpath, mac))
  595. status = -EPERM;
  596. return status;
  597. }
  598. static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
  599. {
  600. struct macInfo mac_info;
  601. u8 *mac_address = NULL;
  602. u64 mac_addr = 0, vpath_vector = 0;
  603. int vpath_idx = 0;
  604. enum vxge_hw_status status = VXGE_HW_OK;
  605. struct vxge_vpath *vpath = NULL;
  606. struct __vxge_hw_device *hldev;
  607. hldev = pci_get_drvdata(vdev->pdev);
  608. mac_address = (u8 *)&mac_addr;
  609. memcpy(mac_address, mac_header, ETH_ALEN);
  610. /* Is this mac address already in the list? */
  611. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  612. vpath = &vdev->vpaths[vpath_idx];
  613. if (vxge_search_mac_addr_in_list(vpath, mac_addr))
  614. return vpath_idx;
  615. }
  616. memset(&mac_info, 0, sizeof(struct macInfo));
  617. memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
  618. /* Any vpath has room to add mac address to its da table? */
  619. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  620. vpath = &vdev->vpaths[vpath_idx];
  621. if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
  622. /* Add this mac address to this vpath */
  623. mac_info.vpath_no = vpath_idx;
  624. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  625. status = vxge_add_mac_addr(vdev, &mac_info);
  626. if (status != VXGE_HW_OK)
  627. return -EPERM;
  628. return vpath_idx;
  629. }
  630. }
  631. mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
  632. vpath_idx = 0;
  633. mac_info.vpath_no = vpath_idx;
  634. /* Is the first vpath already selected as catch-basin ? */
  635. vpath = &vdev->vpaths[vpath_idx];
  636. if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
  637. /* Add this mac address to this vpath */
  638. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  639. return -EPERM;
  640. return vpath_idx;
  641. }
  642. /* Select first vpath as catch-basin */
  643. vpath_vector = vxge_mBIT(vpath->device_id);
  644. status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
  645. vxge_hw_mgmt_reg_type_mrpcim,
  646. 0,
  647. (ulong)offsetof(
  648. struct vxge_hw_mrpcim_reg,
  649. rts_mgr_cbasin_cfg),
  650. vpath_vector);
  651. if (status != VXGE_HW_OK) {
  652. vxge_debug_tx(VXGE_ERR,
  653. "%s: Unable to set the vpath-%d in catch-basin mode",
  654. VXGE_DRIVER_NAME, vpath->device_id);
  655. return -EPERM;
  656. }
  657. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  658. return -EPERM;
  659. return vpath_idx;
  660. }
  661. /**
  662. * vxge_xmit
  663. * @skb : the socket buffer containing the Tx data.
  664. * @dev : device pointer.
  665. *
  666. * This function is the Tx entry point of the driver. Neterion NIC supports
  667. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  668. */
  669. static netdev_tx_t
  670. vxge_xmit(struct sk_buff *skb, struct net_device *dev)
  671. {
  672. struct vxge_fifo *fifo = NULL;
  673. void *dtr_priv;
  674. void *dtr = NULL;
  675. struct vxgedev *vdev = NULL;
  676. enum vxge_hw_status status;
  677. int frg_cnt, first_frg_len;
  678. skb_frag_t *frag;
  679. int i = 0, j = 0, avail;
  680. u64 dma_pointer;
  681. struct vxge_tx_priv *txdl_priv = NULL;
  682. struct __vxge_hw_fifo *fifo_hw;
  683. int offload_type;
  684. int vpath_no = 0;
  685. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  686. dev->name, __func__, __LINE__);
  687. /* A buffer with no data will be dropped */
  688. if (unlikely(skb->len <= 0)) {
  689. vxge_debug_tx(VXGE_ERR,
  690. "%s: Buffer has no data..", dev->name);
  691. dev_kfree_skb(skb);
  692. return NETDEV_TX_OK;
  693. }
  694. vdev = netdev_priv(dev);
  695. if (unlikely(!is_vxge_card_up(vdev))) {
  696. vxge_debug_tx(VXGE_ERR,
  697. "%s: vdev not initialized", dev->name);
  698. dev_kfree_skb(skb);
  699. return NETDEV_TX_OK;
  700. }
  701. if (vdev->config.addr_learn_en) {
  702. vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
  703. if (vpath_no == -EPERM) {
  704. vxge_debug_tx(VXGE_ERR,
  705. "%s: Failed to store the mac address",
  706. dev->name);
  707. dev_kfree_skb(skb);
  708. return NETDEV_TX_OK;
  709. }
  710. }
  711. if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
  712. vpath_no = skb_get_queue_mapping(skb);
  713. else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
  714. vpath_no = vxge_get_vpath_no(vdev, skb);
  715. vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
  716. if (vpath_no >= vdev->no_of_vpath)
  717. vpath_no = 0;
  718. fifo = &vdev->vpaths[vpath_no].fifo;
  719. fifo_hw = fifo->handle;
  720. if (netif_tx_queue_stopped(fifo->txq))
  721. return NETDEV_TX_BUSY;
  722. avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
  723. if (avail == 0) {
  724. vxge_debug_tx(VXGE_ERR,
  725. "%s: No free TXDs available", dev->name);
  726. fifo->stats.txd_not_free++;
  727. goto _exit0;
  728. }
  729. /* Last TXD? Stop tx queue to avoid dropping packets. TX
  730. * completion will resume the queue.
  731. */
  732. if (avail == 1)
  733. netif_tx_stop_queue(fifo->txq);
  734. status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
  735. if (unlikely(status != VXGE_HW_OK)) {
  736. vxge_debug_tx(VXGE_ERR,
  737. "%s: Out of descriptors .", dev->name);
  738. fifo->stats.txd_out_of_desc++;
  739. goto _exit0;
  740. }
  741. vxge_debug_tx(VXGE_TRACE,
  742. "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
  743. dev->name, __func__, __LINE__,
  744. fifo_hw, dtr, dtr_priv);
  745. if (vlan_tx_tag_present(skb)) {
  746. u16 vlan_tag = vlan_tx_tag_get(skb);
  747. vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
  748. }
  749. first_frg_len = skb_headlen(skb);
  750. dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
  751. PCI_DMA_TODEVICE);
  752. if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
  753. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  754. fifo->stats.pci_map_fail++;
  755. goto _exit0;
  756. }
  757. txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
  758. txdl_priv->skb = skb;
  759. txdl_priv->dma_buffers[j] = dma_pointer;
  760. frg_cnt = skb_shinfo(skb)->nr_frags;
  761. vxge_debug_tx(VXGE_TRACE,
  762. "%s: %s:%d skb = %p txdl_priv = %p "
  763. "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
  764. __func__, __LINE__, skb, txdl_priv,
  765. frg_cnt, (unsigned long long)dma_pointer);
  766. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  767. first_frg_len);
  768. frag = &skb_shinfo(skb)->frags[0];
  769. for (i = 0; i < frg_cnt; i++) {
  770. /* ignore 0 length fragment */
  771. if (!frag->size)
  772. continue;
  773. dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
  774. frag->page_offset, frag->size,
  775. PCI_DMA_TODEVICE);
  776. if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
  777. goto _exit2;
  778. vxge_debug_tx(VXGE_TRACE,
  779. "%s: %s:%d frag = %d dma_pointer = 0x%llx",
  780. dev->name, __func__, __LINE__, i,
  781. (unsigned long long)dma_pointer);
  782. txdl_priv->dma_buffers[j] = dma_pointer;
  783. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  784. frag->size);
  785. frag += 1;
  786. }
  787. offload_type = vxge_offload_type(skb);
  788. if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
  789. int mss = vxge_tcp_mss(skb);
  790. if (mss) {
  791. vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
  792. dev->name, __func__, __LINE__, mss);
  793. vxge_hw_fifo_txdl_mss_set(dtr, mss);
  794. } else {
  795. vxge_assert(skb->len <=
  796. dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
  797. vxge_assert(0);
  798. goto _exit1;
  799. }
  800. }
  801. if (skb->ip_summed == CHECKSUM_PARTIAL)
  802. vxge_hw_fifo_txdl_cksum_set_bits(dtr,
  803. VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
  804. VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
  805. VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
  806. vxge_hw_fifo_txdl_post(fifo_hw, dtr);
  807. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  808. dev->name, __func__, __LINE__);
  809. return NETDEV_TX_OK;
  810. _exit2:
  811. vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
  812. _exit1:
  813. j = 0;
  814. frag = &skb_shinfo(skb)->frags[0];
  815. pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
  816. skb_headlen(skb), PCI_DMA_TODEVICE);
  817. for (; j < i; j++) {
  818. pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
  819. frag->size, PCI_DMA_TODEVICE);
  820. frag += 1;
  821. }
  822. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  823. _exit0:
  824. netif_tx_stop_queue(fifo->txq);
  825. dev_kfree_skb(skb);
  826. return NETDEV_TX_OK;
  827. }
  828. /*
  829. * vxge_rx_term
  830. *
  831. * Function will be called by hw function to abort all outstanding receive
  832. * descriptors.
  833. */
  834. static void
  835. vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
  836. {
  837. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  838. struct vxge_rx_priv *rx_priv =
  839. vxge_hw_ring_rxd_private_get(dtrh);
  840. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  841. ring->ndev->name, __func__, __LINE__);
  842. if (state != VXGE_HW_RXD_STATE_POSTED)
  843. return;
  844. pci_unmap_single(ring->pdev, rx_priv->data_dma,
  845. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  846. dev_kfree_skb(rx_priv->skb);
  847. rx_priv->skb_data = NULL;
  848. vxge_debug_entryexit(VXGE_TRACE,
  849. "%s: %s:%d Exiting...",
  850. ring->ndev->name, __func__, __LINE__);
  851. }
  852. /*
  853. * vxge_tx_term
  854. *
  855. * Function will be called to abort all outstanding tx descriptors
  856. */
  857. static void
  858. vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
  859. {
  860. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  861. skb_frag_t *frag;
  862. int i = 0, j, frg_cnt;
  863. struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
  864. struct sk_buff *skb = txd_priv->skb;
  865. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  866. if (state != VXGE_HW_TXDL_STATE_POSTED)
  867. return;
  868. /* check skb validity */
  869. vxge_assert(skb);
  870. frg_cnt = skb_shinfo(skb)->nr_frags;
  871. frag = &skb_shinfo(skb)->frags[0];
  872. /* for unfragmented skb */
  873. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  874. skb_headlen(skb), PCI_DMA_TODEVICE);
  875. for (j = 0; j < frg_cnt; j++) {
  876. pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
  877. frag->size, PCI_DMA_TODEVICE);
  878. frag += 1;
  879. }
  880. dev_kfree_skb(skb);
  881. vxge_debug_entryexit(VXGE_TRACE,
  882. "%s:%d Exiting...", __func__, __LINE__);
  883. }
  884. static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
  885. {
  886. struct list_head *entry, *next;
  887. u64 del_mac = 0;
  888. u8 *mac_address = (u8 *) (&del_mac);
  889. /* Copy the mac address to delete from the list */
  890. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  891. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  892. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
  893. list_del(entry);
  894. kfree((struct vxge_mac_addrs *)entry);
  895. vpath->mac_addr_cnt--;
  896. if (is_multicast_ether_addr(mac->macaddr))
  897. vpath->mcast_addr_cnt--;
  898. return TRUE;
  899. }
  900. }
  901. return FALSE;
  902. }
  903. /* delete a mac address from DA table */
  904. static enum vxge_hw_status
  905. vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  906. {
  907. enum vxge_hw_status status = VXGE_HW_OK;
  908. struct vxge_vpath *vpath;
  909. vpath = &vdev->vpaths[mac->vpath_no];
  910. status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
  911. mac->macmask);
  912. if (status != VXGE_HW_OK) {
  913. vxge_debug_init(VXGE_ERR,
  914. "DA config delete entry failed for vpath:%d",
  915. vpath->device_id);
  916. } else
  917. vxge_mac_list_del(vpath, mac);
  918. return status;
  919. }
  920. /**
  921. * vxge_set_multicast
  922. * @dev: pointer to the device structure
  923. *
  924. * Entry point for multicast address enable/disable
  925. * This function is a driver entry point which gets called by the kernel
  926. * whenever multicast addresses must be enabled/disabled. This also gets
  927. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  928. * determine, if multicast address must be enabled or if promiscuous mode
  929. * is to be disabled etc.
  930. */
  931. static void vxge_set_multicast(struct net_device *dev)
  932. {
  933. struct netdev_hw_addr *ha;
  934. struct vxgedev *vdev;
  935. int i, mcast_cnt = 0;
  936. struct __vxge_hw_device *hldev;
  937. struct vxge_vpath *vpath;
  938. enum vxge_hw_status status = VXGE_HW_OK;
  939. struct macInfo mac_info;
  940. int vpath_idx = 0;
  941. struct vxge_mac_addrs *mac_entry;
  942. struct list_head *list_head;
  943. struct list_head *entry, *next;
  944. u8 *mac_address = NULL;
  945. vxge_debug_entryexit(VXGE_TRACE,
  946. "%s:%d", __func__, __LINE__);
  947. vdev = netdev_priv(dev);
  948. hldev = (struct __vxge_hw_device *)vdev->devh;
  949. if (unlikely(!is_vxge_card_up(vdev)))
  950. return;
  951. if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
  952. for (i = 0; i < vdev->no_of_vpath; i++) {
  953. vpath = &vdev->vpaths[i];
  954. vxge_assert(vpath->is_open);
  955. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  956. if (status != VXGE_HW_OK)
  957. vxge_debug_init(VXGE_ERR, "failed to enable "
  958. "multicast, status %d", status);
  959. vdev->all_multi_flg = 1;
  960. }
  961. } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
  962. for (i = 0; i < vdev->no_of_vpath; i++) {
  963. vpath = &vdev->vpaths[i];
  964. vxge_assert(vpath->is_open);
  965. status = vxge_hw_vpath_mcast_disable(vpath->handle);
  966. if (status != VXGE_HW_OK)
  967. vxge_debug_init(VXGE_ERR, "failed to disable "
  968. "multicast, status %d", status);
  969. vdev->all_multi_flg = 0;
  970. }
  971. }
  972. if (!vdev->config.addr_learn_en) {
  973. for (i = 0; i < vdev->no_of_vpath; i++) {
  974. vpath = &vdev->vpaths[i];
  975. vxge_assert(vpath->is_open);
  976. if (dev->flags & IFF_PROMISC)
  977. status = vxge_hw_vpath_promisc_enable(
  978. vpath->handle);
  979. else
  980. status = vxge_hw_vpath_promisc_disable(
  981. vpath->handle);
  982. if (status != VXGE_HW_OK)
  983. vxge_debug_init(VXGE_ERR, "failed to %s promisc"
  984. ", status %d", dev->flags&IFF_PROMISC ?
  985. "enable" : "disable", status);
  986. }
  987. }
  988. memset(&mac_info, 0, sizeof(struct macInfo));
  989. /* Update individual M_CAST address list */
  990. if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
  991. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  992. list_head = &vdev->vpaths[0].mac_addr_list;
  993. if ((netdev_mc_count(dev) +
  994. (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
  995. vdev->vpaths[0].max_mac_addr_cnt)
  996. goto _set_all_mcast;
  997. /* Delete previous MC's */
  998. for (i = 0; i < mcast_cnt; i++) {
  999. list_for_each_safe(entry, next, list_head) {
  1000. mac_entry = (struct vxge_mac_addrs *)entry;
  1001. /* Copy the mac address to delete */
  1002. mac_address = (u8 *)&mac_entry->macaddr;
  1003. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1004. if (is_multicast_ether_addr(mac_info.macaddr)) {
  1005. for (vpath_idx = 0; vpath_idx <
  1006. vdev->no_of_vpath;
  1007. vpath_idx++) {
  1008. mac_info.vpath_no = vpath_idx;
  1009. status = vxge_del_mac_addr(
  1010. vdev,
  1011. &mac_info);
  1012. }
  1013. }
  1014. }
  1015. }
  1016. /* Add new ones */
  1017. netdev_for_each_mc_addr(ha, dev) {
  1018. memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
  1019. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1020. vpath_idx++) {
  1021. mac_info.vpath_no = vpath_idx;
  1022. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1023. status = vxge_add_mac_addr(vdev, &mac_info);
  1024. if (status != VXGE_HW_OK) {
  1025. vxge_debug_init(VXGE_ERR,
  1026. "%s:%d Setting individual"
  1027. "multicast address failed",
  1028. __func__, __LINE__);
  1029. goto _set_all_mcast;
  1030. }
  1031. }
  1032. }
  1033. return;
  1034. _set_all_mcast:
  1035. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  1036. /* Delete previous MC's */
  1037. for (i = 0; i < mcast_cnt; i++) {
  1038. list_for_each_safe(entry, next, list_head) {
  1039. mac_entry = (struct vxge_mac_addrs *)entry;
  1040. /* Copy the mac address to delete */
  1041. mac_address = (u8 *)&mac_entry->macaddr;
  1042. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1043. if (is_multicast_ether_addr(mac_info.macaddr))
  1044. break;
  1045. }
  1046. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1047. vpath_idx++) {
  1048. mac_info.vpath_no = vpath_idx;
  1049. status = vxge_del_mac_addr(vdev, &mac_info);
  1050. }
  1051. }
  1052. /* Enable all multicast */
  1053. for (i = 0; i < vdev->no_of_vpath; i++) {
  1054. vpath = &vdev->vpaths[i];
  1055. vxge_assert(vpath->is_open);
  1056. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  1057. if (status != VXGE_HW_OK) {
  1058. vxge_debug_init(VXGE_ERR,
  1059. "%s:%d Enabling all multicasts failed",
  1060. __func__, __LINE__);
  1061. }
  1062. vdev->all_multi_flg = 1;
  1063. }
  1064. dev->flags |= IFF_ALLMULTI;
  1065. }
  1066. vxge_debug_entryexit(VXGE_TRACE,
  1067. "%s:%d Exiting...", __func__, __LINE__);
  1068. }
  1069. /**
  1070. * vxge_set_mac_addr
  1071. * @dev: pointer to the device structure
  1072. *
  1073. * Update entry "0" (default MAC addr)
  1074. */
  1075. static int vxge_set_mac_addr(struct net_device *dev, void *p)
  1076. {
  1077. struct sockaddr *addr = p;
  1078. struct vxgedev *vdev;
  1079. struct __vxge_hw_device *hldev;
  1080. enum vxge_hw_status status = VXGE_HW_OK;
  1081. struct macInfo mac_info_new, mac_info_old;
  1082. int vpath_idx = 0;
  1083. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1084. vdev = netdev_priv(dev);
  1085. hldev = vdev->devh;
  1086. if (!is_valid_ether_addr(addr->sa_data))
  1087. return -EINVAL;
  1088. memset(&mac_info_new, 0, sizeof(struct macInfo));
  1089. memset(&mac_info_old, 0, sizeof(struct macInfo));
  1090. vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
  1091. __func__, __LINE__);
  1092. /* Get the old address */
  1093. memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
  1094. /* Copy the new address */
  1095. memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
  1096. /* First delete the old mac address from all the vpaths
  1097. as we can't specify the index while adding new mac address */
  1098. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1099. struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
  1100. if (!vpath->is_open) {
  1101. /* This can happen when this interface is added/removed
  1102. to the bonding interface. Delete this station address
  1103. from the linked list */
  1104. vxge_mac_list_del(vpath, &mac_info_old);
  1105. /* Add this new address to the linked list
  1106. for later restoring */
  1107. vxge_mac_list_add(vpath, &mac_info_new);
  1108. continue;
  1109. }
  1110. /* Delete the station address */
  1111. mac_info_old.vpath_no = vpath_idx;
  1112. status = vxge_del_mac_addr(vdev, &mac_info_old);
  1113. }
  1114. if (unlikely(!is_vxge_card_up(vdev))) {
  1115. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1116. return VXGE_HW_OK;
  1117. }
  1118. /* Set this mac address to all the vpaths */
  1119. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1120. mac_info_new.vpath_no = vpath_idx;
  1121. mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1122. status = vxge_add_mac_addr(vdev, &mac_info_new);
  1123. if (status != VXGE_HW_OK)
  1124. return -EINVAL;
  1125. }
  1126. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1127. return status;
  1128. }
  1129. /*
  1130. * vxge_vpath_intr_enable
  1131. * @vdev: pointer to vdev
  1132. * @vp_id: vpath for which to enable the interrupts
  1133. *
  1134. * Enables the interrupts for the vpath
  1135. */
  1136. static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
  1137. {
  1138. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1139. int msix_id = 0;
  1140. int tim_msix_id[4] = {0, 1, 0, 0};
  1141. int alarm_msix_id = VXGE_ALARM_MSIX_ID;
  1142. vxge_hw_vpath_intr_enable(vpath->handle);
  1143. if (vdev->config.intr_type == INTA)
  1144. vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
  1145. else {
  1146. vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
  1147. alarm_msix_id);
  1148. msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1149. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
  1150. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
  1151. /* enable the alarm vector */
  1152. msix_id = (vpath->handle->vpath->hldev->first_vp_id *
  1153. VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
  1154. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
  1155. }
  1156. }
  1157. /*
  1158. * vxge_vpath_intr_disable
  1159. * @vdev: pointer to vdev
  1160. * @vp_id: vpath for which to disable the interrupts
  1161. *
  1162. * Disables the interrupts for the vpath
  1163. */
  1164. static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
  1165. {
  1166. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1167. struct __vxge_hw_device *hldev;
  1168. int msix_id;
  1169. hldev = pci_get_drvdata(vdev->pdev);
  1170. vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
  1171. vxge_hw_vpath_intr_disable(vpath->handle);
  1172. if (vdev->config.intr_type == INTA)
  1173. vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
  1174. else {
  1175. msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1176. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1177. vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
  1178. /* disable the alarm vector */
  1179. msix_id = (vpath->handle->vpath->hldev->first_vp_id *
  1180. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  1181. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1182. }
  1183. }
  1184. /* list all mac addresses from DA table */
  1185. static enum vxge_hw_status
  1186. vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
  1187. {
  1188. enum vxge_hw_status status = VXGE_HW_OK;
  1189. unsigned char macmask[ETH_ALEN];
  1190. unsigned char macaddr[ETH_ALEN];
  1191. status = vxge_hw_vpath_mac_addr_get(vpath->handle,
  1192. macaddr, macmask);
  1193. if (status != VXGE_HW_OK) {
  1194. vxge_debug_init(VXGE_ERR,
  1195. "DA config list entry failed for vpath:%d",
  1196. vpath->device_id);
  1197. return status;
  1198. }
  1199. while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
  1200. status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
  1201. macaddr, macmask);
  1202. if (status != VXGE_HW_OK)
  1203. break;
  1204. }
  1205. return status;
  1206. }
  1207. /* Store all mac addresses from the list to the DA table */
  1208. static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
  1209. {
  1210. enum vxge_hw_status status = VXGE_HW_OK;
  1211. struct macInfo mac_info;
  1212. u8 *mac_address = NULL;
  1213. struct list_head *entry, *next;
  1214. memset(&mac_info, 0, sizeof(struct macInfo));
  1215. if (vpath->is_open) {
  1216. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  1217. mac_address =
  1218. (u8 *)&
  1219. ((struct vxge_mac_addrs *)entry)->macaddr;
  1220. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1221. ((struct vxge_mac_addrs *)entry)->state =
  1222. VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1223. /* does this mac address already exist in da table? */
  1224. status = vxge_search_mac_addr_in_da_table(vpath,
  1225. &mac_info);
  1226. if (status != VXGE_HW_OK) {
  1227. /* Add this mac address to the DA table */
  1228. status = vxge_hw_vpath_mac_addr_add(
  1229. vpath->handle, mac_info.macaddr,
  1230. mac_info.macmask,
  1231. VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
  1232. if (status != VXGE_HW_OK) {
  1233. vxge_debug_init(VXGE_ERR,
  1234. "DA add entry failed for vpath:%d",
  1235. vpath->device_id);
  1236. ((struct vxge_mac_addrs *)entry)->state
  1237. = VXGE_LL_MAC_ADDR_IN_LIST;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. return status;
  1243. }
  1244. /* Store all vlan ids from the list to the vid table */
  1245. static enum vxge_hw_status
  1246. vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
  1247. {
  1248. enum vxge_hw_status status = VXGE_HW_OK;
  1249. struct vxgedev *vdev = vpath->vdev;
  1250. u16 vid;
  1251. if (!vpath->is_open)
  1252. return status;
  1253. for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
  1254. status = vxge_hw_vpath_vid_add(vpath->handle, vid);
  1255. return status;
  1256. }
  1257. /*
  1258. * vxge_reset_vpath
  1259. * @vdev: pointer to vdev
  1260. * @vp_id: vpath to reset
  1261. *
  1262. * Resets the vpath
  1263. */
  1264. static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
  1265. {
  1266. enum vxge_hw_status status = VXGE_HW_OK;
  1267. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1268. int ret = 0;
  1269. /* check if device is down already */
  1270. if (unlikely(!is_vxge_card_up(vdev)))
  1271. return 0;
  1272. /* is device reset already scheduled */
  1273. if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1274. return 0;
  1275. if (vpath->handle) {
  1276. if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
  1277. if (is_vxge_card_up(vdev) &&
  1278. vxge_hw_vpath_recover_from_reset(vpath->handle)
  1279. != VXGE_HW_OK) {
  1280. vxge_debug_init(VXGE_ERR,
  1281. "vxge_hw_vpath_recover_from_reset"
  1282. "failed for vpath:%d", vp_id);
  1283. return status;
  1284. }
  1285. } else {
  1286. vxge_debug_init(VXGE_ERR,
  1287. "vxge_hw_vpath_reset failed for"
  1288. "vpath:%d", vp_id);
  1289. return status;
  1290. }
  1291. } else
  1292. return VXGE_HW_FAIL;
  1293. vxge_restore_vpath_mac_addr(vpath);
  1294. vxge_restore_vpath_vid_table(vpath);
  1295. /* Enable all broadcast */
  1296. vxge_hw_vpath_bcast_enable(vpath->handle);
  1297. /* Enable all multicast */
  1298. if (vdev->all_multi_flg) {
  1299. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  1300. if (status != VXGE_HW_OK)
  1301. vxge_debug_init(VXGE_ERR,
  1302. "%s:%d Enabling multicast failed",
  1303. __func__, __LINE__);
  1304. }
  1305. /* Enable the interrupts */
  1306. vxge_vpath_intr_enable(vdev, vp_id);
  1307. smp_wmb();
  1308. /* Enable the flow of traffic through the vpath */
  1309. vxge_hw_vpath_enable(vpath->handle);
  1310. smp_wmb();
  1311. vxge_hw_vpath_rx_doorbell_init(vpath->handle);
  1312. vpath->ring.last_status = VXGE_HW_OK;
  1313. /* Vpath reset done */
  1314. clear_bit(vp_id, &vdev->vp_reset);
  1315. /* Start the vpath queue */
  1316. if (netif_tx_queue_stopped(vpath->fifo.txq))
  1317. netif_tx_wake_queue(vpath->fifo.txq);
  1318. return ret;
  1319. }
  1320. /* Configure CI */
  1321. static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
  1322. {
  1323. int i = 0;
  1324. /* Enable CI for RTI */
  1325. if (vdev->config.intr_type == MSI_X) {
  1326. for (i = 0; i < vdev->no_of_vpath; i++) {
  1327. struct __vxge_hw_ring *hw_ring;
  1328. hw_ring = vdev->vpaths[i].ring.handle;
  1329. vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
  1330. }
  1331. }
  1332. /* Enable CI for TTI */
  1333. for (i = 0; i < vdev->no_of_vpath; i++) {
  1334. struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
  1335. vxge_hw_vpath_tti_ci_set(hw_fifo);
  1336. /*
  1337. * For Inta (with or without napi), Set CI ON for only one
  1338. * vpath. (Have only one free running timer).
  1339. */
  1340. if ((vdev->config.intr_type == INTA) && (i == 0))
  1341. break;
  1342. }
  1343. return;
  1344. }
  1345. static int do_vxge_reset(struct vxgedev *vdev, int event)
  1346. {
  1347. enum vxge_hw_status status;
  1348. int ret = 0, vp_id, i;
  1349. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1350. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
  1351. /* check if device is down already */
  1352. if (unlikely(!is_vxge_card_up(vdev)))
  1353. return 0;
  1354. /* is reset already scheduled */
  1355. if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1356. return 0;
  1357. }
  1358. if (event == VXGE_LL_FULL_RESET) {
  1359. netif_carrier_off(vdev->ndev);
  1360. /* wait for all the vpath reset to complete */
  1361. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1362. while (test_bit(vp_id, &vdev->vp_reset))
  1363. msleep(50);
  1364. }
  1365. netif_carrier_on(vdev->ndev);
  1366. /* if execution mode is set to debug, don't reset the adapter */
  1367. if (unlikely(vdev->exec_mode)) {
  1368. vxge_debug_init(VXGE_ERR,
  1369. "%s: execution mode is debug, returning..",
  1370. vdev->ndev->name);
  1371. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1372. netif_tx_stop_all_queues(vdev->ndev);
  1373. return 0;
  1374. }
  1375. }
  1376. if (event == VXGE_LL_FULL_RESET) {
  1377. vxge_hw_device_wait_receive_idle(vdev->devh);
  1378. vxge_hw_device_intr_disable(vdev->devh);
  1379. switch (vdev->cric_err_event) {
  1380. case VXGE_HW_EVENT_UNKNOWN:
  1381. netif_tx_stop_all_queues(vdev->ndev);
  1382. vxge_debug_init(VXGE_ERR,
  1383. "fatal: %s: Disabling device due to"
  1384. "unknown error",
  1385. vdev->ndev->name);
  1386. ret = -EPERM;
  1387. goto out;
  1388. case VXGE_HW_EVENT_RESET_START:
  1389. break;
  1390. case VXGE_HW_EVENT_RESET_COMPLETE:
  1391. case VXGE_HW_EVENT_LINK_DOWN:
  1392. case VXGE_HW_EVENT_LINK_UP:
  1393. case VXGE_HW_EVENT_ALARM_CLEARED:
  1394. case VXGE_HW_EVENT_ECCERR:
  1395. case VXGE_HW_EVENT_MRPCIM_ECCERR:
  1396. ret = -EPERM;
  1397. goto out;
  1398. case VXGE_HW_EVENT_FIFO_ERR:
  1399. case VXGE_HW_EVENT_VPATH_ERR:
  1400. break;
  1401. case VXGE_HW_EVENT_CRITICAL_ERR:
  1402. netif_tx_stop_all_queues(vdev->ndev);
  1403. vxge_debug_init(VXGE_ERR,
  1404. "fatal: %s: Disabling device due to"
  1405. "serious error",
  1406. vdev->ndev->name);
  1407. /* SOP or device reset required */
  1408. /* This event is not currently used */
  1409. ret = -EPERM;
  1410. goto out;
  1411. case VXGE_HW_EVENT_SERR:
  1412. netif_tx_stop_all_queues(vdev->ndev);
  1413. vxge_debug_init(VXGE_ERR,
  1414. "fatal: %s: Disabling device due to"
  1415. "serious error",
  1416. vdev->ndev->name);
  1417. ret = -EPERM;
  1418. goto out;
  1419. case VXGE_HW_EVENT_SRPCIM_SERR:
  1420. case VXGE_HW_EVENT_MRPCIM_SERR:
  1421. ret = -EPERM;
  1422. goto out;
  1423. case VXGE_HW_EVENT_SLOT_FREEZE:
  1424. netif_tx_stop_all_queues(vdev->ndev);
  1425. vxge_debug_init(VXGE_ERR,
  1426. "fatal: %s: Disabling device due to"
  1427. "slot freeze",
  1428. vdev->ndev->name);
  1429. ret = -EPERM;
  1430. goto out;
  1431. default:
  1432. break;
  1433. }
  1434. }
  1435. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
  1436. netif_tx_stop_all_queues(vdev->ndev);
  1437. if (event == VXGE_LL_FULL_RESET) {
  1438. status = vxge_reset_all_vpaths(vdev);
  1439. if (status != VXGE_HW_OK) {
  1440. vxge_debug_init(VXGE_ERR,
  1441. "fatal: %s: can not reset vpaths",
  1442. vdev->ndev->name);
  1443. ret = -EPERM;
  1444. goto out;
  1445. }
  1446. }
  1447. if (event == VXGE_LL_COMPL_RESET) {
  1448. for (i = 0; i < vdev->no_of_vpath; i++)
  1449. if (vdev->vpaths[i].handle) {
  1450. if (vxge_hw_vpath_recover_from_reset(
  1451. vdev->vpaths[i].handle)
  1452. != VXGE_HW_OK) {
  1453. vxge_debug_init(VXGE_ERR,
  1454. "vxge_hw_vpath_recover_"
  1455. "from_reset failed for vpath: "
  1456. "%d", i);
  1457. ret = -EPERM;
  1458. goto out;
  1459. }
  1460. } else {
  1461. vxge_debug_init(VXGE_ERR,
  1462. "vxge_hw_vpath_reset failed for "
  1463. "vpath:%d", i);
  1464. ret = -EPERM;
  1465. goto out;
  1466. }
  1467. }
  1468. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
  1469. /* Reprogram the DA table with populated mac addresses */
  1470. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1471. vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
  1472. vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
  1473. }
  1474. /* enable vpath interrupts */
  1475. for (i = 0; i < vdev->no_of_vpath; i++)
  1476. vxge_vpath_intr_enable(vdev, i);
  1477. vxge_hw_device_intr_enable(vdev->devh);
  1478. smp_wmb();
  1479. /* Indicate card up */
  1480. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1481. /* Get the traffic to flow through the vpaths */
  1482. for (i = 0; i < vdev->no_of_vpath; i++) {
  1483. vxge_hw_vpath_enable(vdev->vpaths[i].handle);
  1484. smp_wmb();
  1485. vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
  1486. }
  1487. netif_tx_wake_all_queues(vdev->ndev);
  1488. }
  1489. /* configure CI */
  1490. vxge_config_ci_for_tti_rti(vdev);
  1491. out:
  1492. vxge_debug_entryexit(VXGE_TRACE,
  1493. "%s:%d Exiting...", __func__, __LINE__);
  1494. /* Indicate reset done */
  1495. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
  1496. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  1497. return ret;
  1498. }
  1499. /*
  1500. * vxge_reset
  1501. * @vdev: pointer to ll device
  1502. *
  1503. * driver may reset the chip on events of serr, eccerr, etc
  1504. */
  1505. static void vxge_reset(struct work_struct *work)
  1506. {
  1507. struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
  1508. if (!netif_running(vdev->ndev))
  1509. return;
  1510. do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
  1511. }
  1512. /**
  1513. * vxge_poll - Receive handler when Receive Polling is used.
  1514. * @dev: pointer to the device structure.
  1515. * @budget: Number of packets budgeted to be processed in this iteration.
  1516. *
  1517. * This function comes into picture only if Receive side is being handled
  1518. * through polling (called NAPI in linux). It mostly does what the normal
  1519. * Rx interrupt handler does in terms of descriptor and packet processing
  1520. * but not in an interrupt context. Also it will process a specified number
  1521. * of packets at most in one iteration. This value is passed down by the
  1522. * kernel as the function argument 'budget'.
  1523. */
  1524. static int vxge_poll_msix(struct napi_struct *napi, int budget)
  1525. {
  1526. struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
  1527. int pkts_processed;
  1528. int budget_org = budget;
  1529. ring->budget = budget;
  1530. ring->pkts_processed = 0;
  1531. vxge_hw_vpath_poll_rx(ring->handle);
  1532. pkts_processed = ring->pkts_processed;
  1533. if (ring->pkts_processed < budget_org) {
  1534. napi_complete(napi);
  1535. /* Re enable the Rx interrupts for the vpath */
  1536. vxge_hw_channel_msix_unmask(
  1537. (struct __vxge_hw_channel *)ring->handle,
  1538. ring->rx_vector_no);
  1539. mmiowb();
  1540. }
  1541. /* We are copying and returning the local variable, in case if after
  1542. * clearing the msix interrupt above, if the interrupt fires right
  1543. * away which can preempt this NAPI thread */
  1544. return pkts_processed;
  1545. }
  1546. static int vxge_poll_inta(struct napi_struct *napi, int budget)
  1547. {
  1548. struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
  1549. int pkts_processed = 0;
  1550. int i;
  1551. int budget_org = budget;
  1552. struct vxge_ring *ring;
  1553. struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
  1554. for (i = 0; i < vdev->no_of_vpath; i++) {
  1555. ring = &vdev->vpaths[i].ring;
  1556. ring->budget = budget;
  1557. ring->pkts_processed = 0;
  1558. vxge_hw_vpath_poll_rx(ring->handle);
  1559. pkts_processed += ring->pkts_processed;
  1560. budget -= ring->pkts_processed;
  1561. if (budget <= 0)
  1562. break;
  1563. }
  1564. VXGE_COMPLETE_ALL_TX(vdev);
  1565. if (pkts_processed < budget_org) {
  1566. napi_complete(napi);
  1567. /* Re enable the Rx interrupts for the ring */
  1568. vxge_hw_device_unmask_all(hldev);
  1569. vxge_hw_device_flush_io(hldev);
  1570. }
  1571. return pkts_processed;
  1572. }
  1573. #ifdef CONFIG_NET_POLL_CONTROLLER
  1574. /**
  1575. * vxge_netpoll - netpoll event handler entry point
  1576. * @dev : pointer to the device structure.
  1577. * Description:
  1578. * This function will be called by upper layer to check for events on the
  1579. * interface in situations where interrupts are disabled. It is used for
  1580. * specific in-kernel networking tasks, such as remote consoles and kernel
  1581. * debugging over the network (example netdump in RedHat).
  1582. */
  1583. static void vxge_netpoll(struct net_device *dev)
  1584. {
  1585. struct __vxge_hw_device *hldev;
  1586. struct vxgedev *vdev;
  1587. vdev = netdev_priv(dev);
  1588. hldev = pci_get_drvdata(vdev->pdev);
  1589. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1590. if (pci_channel_offline(vdev->pdev))
  1591. return;
  1592. disable_irq(dev->irq);
  1593. vxge_hw_device_clear_tx_rx(hldev);
  1594. vxge_hw_device_clear_tx_rx(hldev);
  1595. VXGE_COMPLETE_ALL_RX(vdev);
  1596. VXGE_COMPLETE_ALL_TX(vdev);
  1597. enable_irq(dev->irq);
  1598. vxge_debug_entryexit(VXGE_TRACE,
  1599. "%s:%d Exiting...", __func__, __LINE__);
  1600. }
  1601. #endif
  1602. /* RTH configuration */
  1603. static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
  1604. {
  1605. enum vxge_hw_status status = VXGE_HW_OK;
  1606. struct vxge_hw_rth_hash_types hash_types;
  1607. u8 itable[256] = {0}; /* indirection table */
  1608. u8 mtable[256] = {0}; /* CPU to vpath mapping */
  1609. int index;
  1610. /*
  1611. * Filling
  1612. * - itable with bucket numbers
  1613. * - mtable with bucket-to-vpath mapping
  1614. */
  1615. for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
  1616. itable[index] = index;
  1617. mtable[index] = index % vdev->no_of_vpath;
  1618. }
  1619. /* set indirection table, bucket-to-vpath mapping */
  1620. status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
  1621. vdev->no_of_vpath,
  1622. mtable, itable,
  1623. vdev->config.rth_bkt_sz);
  1624. if (status != VXGE_HW_OK) {
  1625. vxge_debug_init(VXGE_ERR,
  1626. "RTH indirection table configuration failed "
  1627. "for vpath:%d", vdev->vpaths[0].device_id);
  1628. return status;
  1629. }
  1630. /* Fill RTH hash types */
  1631. hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
  1632. hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
  1633. hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
  1634. hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
  1635. hash_types.hash_type_tcpipv6ex_en =
  1636. vdev->config.rth_hash_type_tcpipv6ex;
  1637. hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
  1638. /*
  1639. * Because the itable_set() method uses the active_table field
  1640. * for the target virtual path the RTH config should be updated
  1641. * for all VPATHs. The h/w only uses the lowest numbered VPATH
  1642. * when steering frames.
  1643. */
  1644. for (index = 0; index < vdev->no_of_vpath; index++) {
  1645. status = vxge_hw_vpath_rts_rth_set(
  1646. vdev->vpaths[index].handle,
  1647. vdev->config.rth_algorithm,
  1648. &hash_types,
  1649. vdev->config.rth_bkt_sz);
  1650. if (status != VXGE_HW_OK) {
  1651. vxge_debug_init(VXGE_ERR,
  1652. "RTH configuration failed for vpath:%d",
  1653. vdev->vpaths[index].device_id);
  1654. return status;
  1655. }
  1656. }
  1657. return status;
  1658. }
  1659. /* reset vpaths */
  1660. enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
  1661. {
  1662. enum vxge_hw_status status = VXGE_HW_OK;
  1663. struct vxge_vpath *vpath;
  1664. int i;
  1665. for (i = 0; i < vdev->no_of_vpath; i++) {
  1666. vpath = &vdev->vpaths[i];
  1667. if (vpath->handle) {
  1668. if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
  1669. if (is_vxge_card_up(vdev) &&
  1670. vxge_hw_vpath_recover_from_reset(
  1671. vpath->handle) != VXGE_HW_OK) {
  1672. vxge_debug_init(VXGE_ERR,
  1673. "vxge_hw_vpath_recover_"
  1674. "from_reset failed for vpath: "
  1675. "%d", i);
  1676. return status;
  1677. }
  1678. } else {
  1679. vxge_debug_init(VXGE_ERR,
  1680. "vxge_hw_vpath_reset failed for "
  1681. "vpath:%d", i);
  1682. return status;
  1683. }
  1684. }
  1685. }
  1686. return status;
  1687. }
  1688. /* close vpaths */
  1689. static void vxge_close_vpaths(struct vxgedev *vdev, int index)
  1690. {
  1691. struct vxge_vpath *vpath;
  1692. int i;
  1693. for (i = index; i < vdev->no_of_vpath; i++) {
  1694. vpath = &vdev->vpaths[i];
  1695. if (vpath->handle && vpath->is_open) {
  1696. vxge_hw_vpath_close(vpath->handle);
  1697. vdev->stats.vpaths_open--;
  1698. }
  1699. vpath->is_open = 0;
  1700. vpath->handle = NULL;
  1701. }
  1702. }
  1703. /* open vpaths */
  1704. static int vxge_open_vpaths(struct vxgedev *vdev)
  1705. {
  1706. struct vxge_hw_vpath_attr attr;
  1707. enum vxge_hw_status status;
  1708. struct vxge_vpath *vpath;
  1709. u32 vp_id = 0;
  1710. int i;
  1711. for (i = 0; i < vdev->no_of_vpath; i++) {
  1712. vpath = &vdev->vpaths[i];
  1713. vxge_assert(vpath->is_configured);
  1714. if (!vdev->titan1) {
  1715. struct vxge_hw_vp_config *vcfg;
  1716. vcfg = &vdev->devh->config.vp_config[vpath->device_id];
  1717. vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
  1718. vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
  1719. vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
  1720. vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
  1721. vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
  1722. vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
  1723. vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
  1724. vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
  1725. vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
  1726. }
  1727. attr.vp_id = vpath->device_id;
  1728. attr.fifo_attr.callback = vxge_xmit_compl;
  1729. attr.fifo_attr.txdl_term = vxge_tx_term;
  1730. attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
  1731. attr.fifo_attr.userdata = &vpath->fifo;
  1732. attr.ring_attr.callback = vxge_rx_1b_compl;
  1733. attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
  1734. attr.ring_attr.rxd_term = vxge_rx_term;
  1735. attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
  1736. attr.ring_attr.userdata = &vpath->ring;
  1737. vpath->ring.ndev = vdev->ndev;
  1738. vpath->ring.pdev = vdev->pdev;
  1739. status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
  1740. if (status == VXGE_HW_OK) {
  1741. vpath->fifo.handle =
  1742. (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
  1743. vpath->ring.handle =
  1744. (struct __vxge_hw_ring *)attr.ring_attr.userdata;
  1745. vpath->fifo.tx_steering_type =
  1746. vdev->config.tx_steering_type;
  1747. vpath->fifo.ndev = vdev->ndev;
  1748. vpath->fifo.pdev = vdev->pdev;
  1749. if (vdev->config.tx_steering_type)
  1750. vpath->fifo.txq =
  1751. netdev_get_tx_queue(vdev->ndev, i);
  1752. else
  1753. vpath->fifo.txq =
  1754. netdev_get_tx_queue(vdev->ndev, 0);
  1755. vpath->fifo.indicate_max_pkts =
  1756. vdev->config.fifo_indicate_max_pkts;
  1757. vpath->fifo.tx_vector_no = 0;
  1758. vpath->ring.rx_vector_no = 0;
  1759. vpath->ring.rx_hwts = vdev->rx_hwts;
  1760. vpath->is_open = 1;
  1761. vdev->vp_handles[i] = vpath->handle;
  1762. vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
  1763. vdev->stats.vpaths_open++;
  1764. } else {
  1765. vdev->stats.vpath_open_fail++;
  1766. vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
  1767. "open with status: %d",
  1768. vdev->ndev->name, vpath->device_id,
  1769. status);
  1770. vxge_close_vpaths(vdev, 0);
  1771. return -EPERM;
  1772. }
  1773. vp_id = vpath->handle->vpath->vp_id;
  1774. vdev->vpaths_deployed |= vxge_mBIT(vp_id);
  1775. }
  1776. return VXGE_HW_OK;
  1777. }
  1778. /**
  1779. * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
  1780. * if the interrupts are not within a range
  1781. * @fifo: pointer to transmit fifo structure
  1782. * Description: The function changes boundary timer and restriction timer
  1783. * value depends on the traffic
  1784. * Return Value: None
  1785. */
  1786. static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
  1787. {
  1788. fifo->interrupt_count++;
  1789. if (jiffies > fifo->jiffies + HZ / 100) {
  1790. struct __vxge_hw_fifo *hw_fifo = fifo->handle;
  1791. fifo->jiffies = jiffies;
  1792. if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
  1793. hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
  1794. hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
  1795. vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
  1796. } else if (hw_fifo->rtimer != 0) {
  1797. hw_fifo->rtimer = 0;
  1798. vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
  1799. }
  1800. fifo->interrupt_count = 0;
  1801. }
  1802. }
  1803. /**
  1804. * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
  1805. * if the interrupts are not within a range
  1806. * @ring: pointer to receive ring structure
  1807. * Description: The function increases of decreases the packet counts within
  1808. * the ranges of traffic utilization, if the interrupts due to this ring are
  1809. * not within a fixed range.
  1810. * Return Value: Nothing
  1811. */
  1812. static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
  1813. {
  1814. ring->interrupt_count++;
  1815. if (jiffies > ring->jiffies + HZ / 100) {
  1816. struct __vxge_hw_ring *hw_ring = ring->handle;
  1817. ring->jiffies = jiffies;
  1818. if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
  1819. hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
  1820. hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
  1821. vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
  1822. } else if (hw_ring->rtimer != 0) {
  1823. hw_ring->rtimer = 0;
  1824. vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
  1825. }
  1826. ring->interrupt_count = 0;
  1827. }
  1828. }
  1829. /*
  1830. * vxge_isr_napi
  1831. * @irq: the irq of the device.
  1832. * @dev_id: a void pointer to the hldev structure of the Titan device
  1833. * @ptregs: pointer to the registers pushed on the stack.
  1834. *
  1835. * This function is the ISR handler of the device when napi is enabled. It
  1836. * identifies the reason for the interrupt and calls the relevant service
  1837. * routines.
  1838. */
  1839. static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
  1840. {
  1841. struct net_device *dev;
  1842. struct __vxge_hw_device *hldev;
  1843. u64 reason;
  1844. enum vxge_hw_status status;
  1845. struct vxgedev *vdev = (struct vxgedev *)dev_id;
  1846. vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1847. dev = vdev->ndev;
  1848. hldev = pci_get_drvdata(vdev->pdev);
  1849. if (pci_channel_offline(vdev->pdev))
  1850. return IRQ_NONE;
  1851. if (unlikely(!is_vxge_card_up(vdev)))
  1852. return IRQ_HANDLED;
  1853. status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
  1854. if (status == VXGE_HW_OK) {
  1855. vxge_hw_device_mask_all(hldev);
  1856. if (reason &
  1857. VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
  1858. vdev->vpaths_deployed >>
  1859. (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
  1860. vxge_hw_device_clear_tx_rx(hldev);
  1861. napi_schedule(&vdev->napi);
  1862. vxge_debug_intr(VXGE_TRACE,
  1863. "%s:%d Exiting...", __func__, __LINE__);
  1864. return IRQ_HANDLED;
  1865. } else
  1866. vxge_hw_device_unmask_all(hldev);
  1867. } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
  1868. (status == VXGE_HW_ERR_CRITICAL) ||
  1869. (status == VXGE_HW_ERR_FIFO))) {
  1870. vxge_hw_device_mask_all(hldev);
  1871. vxge_hw_device_flush_io(hldev);
  1872. return IRQ_HANDLED;
  1873. } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
  1874. return IRQ_HANDLED;
  1875. vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
  1876. return IRQ_NONE;
  1877. }
  1878. #ifdef CONFIG_PCI_MSI
  1879. static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
  1880. {
  1881. struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
  1882. adaptive_coalesce_tx_interrupts(fifo);
  1883. vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
  1884. fifo->tx_vector_no);
  1885. vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
  1886. fifo->tx_vector_no);
  1887. VXGE_COMPLETE_VPATH_TX(fifo);
  1888. vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
  1889. fifo->tx_vector_no);
  1890. mmiowb();
  1891. return IRQ_HANDLED;
  1892. }
  1893. static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
  1894. {
  1895. struct vxge_ring *ring = (struct vxge_ring *)dev_id;
  1896. adaptive_coalesce_rx_interrupts(ring);
  1897. vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
  1898. ring->rx_vector_no);
  1899. vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
  1900. ring->rx_vector_no);
  1901. napi_schedule(&ring->napi);
  1902. return IRQ_HANDLED;
  1903. }
  1904. static irqreturn_t
  1905. vxge_alarm_msix_handle(int irq, void *dev_id)
  1906. {
  1907. int i;
  1908. enum vxge_hw_status status;
  1909. struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
  1910. struct vxgedev *vdev = vpath->vdev;
  1911. int msix_id = (vpath->handle->vpath->vp_id *
  1912. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  1913. for (i = 0; i < vdev->no_of_vpath; i++) {
  1914. /* Reduce the chance of losing alarm interrupts by masking
  1915. * the vector. A pending bit will be set if an alarm is
  1916. * generated and on unmask the interrupt will be fired.
  1917. */
  1918. vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
  1919. vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
  1920. mmiowb();
  1921. status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
  1922. vdev->exec_mode);
  1923. if (status == VXGE_HW_OK) {
  1924. vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
  1925. msix_id);
  1926. mmiowb();
  1927. continue;
  1928. }
  1929. vxge_debug_intr(VXGE_ERR,
  1930. "%s: vxge_hw_vpath_alarm_process failed %x ",
  1931. VXGE_DRIVER_NAME, status);
  1932. }
  1933. return IRQ_HANDLED;
  1934. }
  1935. static int vxge_alloc_msix(struct vxgedev *vdev)
  1936. {
  1937. int j, i, ret = 0;
  1938. int msix_intr_vect = 0, temp;
  1939. vdev->intr_cnt = 0;
  1940. start:
  1941. /* Tx/Rx MSIX Vectors count */
  1942. vdev->intr_cnt = vdev->no_of_vpath * 2;
  1943. /* Alarm MSIX Vectors count */
  1944. vdev->intr_cnt++;
  1945. vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
  1946. GFP_KERNEL);
  1947. if (!vdev->entries) {
  1948. vxge_debug_init(VXGE_ERR,
  1949. "%s: memory allocation failed",
  1950. VXGE_DRIVER_NAME);
  1951. ret = -ENOMEM;
  1952. goto alloc_entries_failed;
  1953. }
  1954. vdev->vxge_entries = kcalloc(vdev->intr_cnt,
  1955. sizeof(struct vxge_msix_entry),
  1956. GFP_KERNEL);
  1957. if (!vdev->vxge_entries) {
  1958. vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
  1959. VXGE_DRIVER_NAME);
  1960. ret = -ENOMEM;
  1961. goto alloc_vxge_entries_failed;
  1962. }
  1963. for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
  1964. msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
  1965. /* Initialize the fifo vector */
  1966. vdev->entries[j].entry = msix_intr_vect;
  1967. vdev->vxge_entries[j].entry = msix_intr_vect;
  1968. vdev->vxge_entries[j].in_use = 0;
  1969. j++;
  1970. /* Initialize the ring vector */
  1971. vdev->entries[j].entry = msix_intr_vect + 1;
  1972. vdev->vxge_entries[j].entry = msix_intr_vect + 1;
  1973. vdev->vxge_entries[j].in_use = 0;
  1974. j++;
  1975. }
  1976. /* Initialize the alarm vector */
  1977. vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
  1978. vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
  1979. vdev->vxge_entries[j].in_use = 0;
  1980. ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
  1981. if (ret > 0) {
  1982. vxge_debug_init(VXGE_ERR,
  1983. "%s: MSI-X enable failed for %d vectors, ret: %d",
  1984. VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
  1985. if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
  1986. ret = -ENODEV;
  1987. goto enable_msix_failed;
  1988. }
  1989. kfree(vdev->entries);
  1990. kfree(vdev->vxge_entries);
  1991. vdev->entries = NULL;
  1992. vdev->vxge_entries = NULL;
  1993. /* Try with less no of vector by reducing no of vpaths count */
  1994. temp = (ret - 1)/2;
  1995. vxge_close_vpaths(vdev, temp);
  1996. vdev->no_of_vpath = temp;
  1997. goto start;
  1998. } else if (ret < 0) {
  1999. ret = -ENODEV;
  2000. goto enable_msix_failed;
  2001. }
  2002. return 0;
  2003. enable_msix_failed:
  2004. kfree(vdev->vxge_entries);
  2005. alloc_vxge_entries_failed:
  2006. kfree(vdev->entries);
  2007. alloc_entries_failed:
  2008. return ret;
  2009. }
  2010. static int vxge_enable_msix(struct vxgedev *vdev)
  2011. {
  2012. int i, ret = 0;
  2013. /* 0 - Tx, 1 - Rx */
  2014. int tim_msix_id[4] = {0, 1, 0, 0};
  2015. vdev->intr_cnt = 0;
  2016. /* allocate msix vectors */
  2017. ret = vxge_alloc_msix(vdev);
  2018. if (!ret) {
  2019. for (i = 0; i < vdev->no_of_vpath; i++) {
  2020. struct vxge_vpath *vpath = &vdev->vpaths[i];
  2021. /* If fifo or ring are not enabled, the MSIX vector for
  2022. * it should be set to 0.
  2023. */
  2024. vpath->ring.rx_vector_no = (vpath->device_id *
  2025. VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
  2026. vpath->fifo.tx_vector_no = (vpath->device_id *
  2027. VXGE_HW_VPATH_MSIX_ACTIVE);
  2028. vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
  2029. VXGE_ALARM_MSIX_ID);
  2030. }
  2031. }
  2032. return ret;
  2033. }
  2034. static void vxge_rem_msix_isr(struct vxgedev *vdev)
  2035. {
  2036. int intr_cnt;
  2037. for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
  2038. intr_cnt++) {
  2039. if (vdev->vxge_entries[intr_cnt].in_use) {
  2040. synchronize_irq(vdev->entries[intr_cnt].vector);
  2041. free_irq(vdev->entries[intr_cnt].vector,
  2042. vdev->vxge_entries[intr_cnt].arg);
  2043. vdev->vxge_entries[intr_cnt].in_use = 0;
  2044. }
  2045. }
  2046. kfree(vdev->entries);
  2047. kfree(vdev->vxge_entries);
  2048. vdev->entries = NULL;
  2049. vdev->vxge_entries = NULL;
  2050. if (vdev->config.intr_type == MSI_X)
  2051. pci_disable_msix(vdev->pdev);
  2052. }
  2053. #endif
  2054. static void vxge_rem_isr(struct vxgedev *vdev)
  2055. {
  2056. struct __vxge_hw_device *hldev;
  2057. hldev = pci_get_drvdata(vdev->pdev);
  2058. #ifdef CONFIG_PCI_MSI
  2059. if (vdev->config.intr_type == MSI_X) {
  2060. vxge_rem_msix_isr(vdev);
  2061. } else
  2062. #endif
  2063. if (vdev->config.intr_type == INTA) {
  2064. synchronize_irq(vdev->pdev->irq);
  2065. free_irq(vdev->pdev->irq, vdev);
  2066. }
  2067. }
  2068. static int vxge_add_isr(struct vxgedev *vdev)
  2069. {
  2070. int ret = 0;
  2071. #ifdef CONFIG_PCI_MSI
  2072. int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
  2073. int pci_fun = PCI_FUNC(vdev->pdev->devfn);
  2074. if (vdev->config.intr_type == MSI_X)
  2075. ret = vxge_enable_msix(vdev);
  2076. if (ret) {
  2077. vxge_debug_init(VXGE_ERR,
  2078. "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
  2079. vxge_debug_init(VXGE_ERR,
  2080. "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
  2081. vdev->config.intr_type = INTA;
  2082. }
  2083. if (vdev->config.intr_type == MSI_X) {
  2084. for (intr_idx = 0;
  2085. intr_idx < (vdev->no_of_vpath *
  2086. VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
  2087. msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
  2088. irq_req = 0;
  2089. switch (msix_idx) {
  2090. case 0:
  2091. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2092. "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
  2093. vdev->ndev->name,
  2094. vdev->entries[intr_cnt].entry,
  2095. pci_fun, vp_idx);
  2096. ret = request_irq(
  2097. vdev->entries[intr_cnt].vector,
  2098. vxge_tx_msix_handle, 0,
  2099. vdev->desc[intr_cnt],
  2100. &vdev->vpaths[vp_idx].fifo);
  2101. vdev->vxge_entries[intr_cnt].arg =
  2102. &vdev->vpaths[vp_idx].fifo;
  2103. irq_req = 1;
  2104. break;
  2105. case 1:
  2106. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2107. "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
  2108. vdev->ndev->name,
  2109. vdev->entries[intr_cnt].entry,
  2110. pci_fun, vp_idx);
  2111. ret = request_irq(
  2112. vdev->entries[intr_cnt].vector,
  2113. vxge_rx_msix_napi_handle,
  2114. 0,
  2115. vdev->desc[intr_cnt],
  2116. &vdev->vpaths[vp_idx].ring);
  2117. vdev->vxge_entries[intr_cnt].arg =
  2118. &vdev->vpaths[vp_idx].ring;
  2119. irq_req = 1;
  2120. break;
  2121. }
  2122. if (ret) {
  2123. vxge_debug_init(VXGE_ERR,
  2124. "%s: MSIX - %d Registration failed",
  2125. vdev->ndev->name, intr_cnt);
  2126. vxge_rem_msix_isr(vdev);
  2127. vdev->config.intr_type = INTA;
  2128. vxge_debug_init(VXGE_ERR,
  2129. "%s: Defaulting to INTA"
  2130. , vdev->ndev->name);
  2131. goto INTA_MODE;
  2132. }
  2133. if (irq_req) {
  2134. /* We requested for this msix interrupt */
  2135. vdev->vxge_entries[intr_cnt].in_use = 1;
  2136. msix_idx += vdev->vpaths[vp_idx].device_id *
  2137. VXGE_HW_VPATH_MSIX_ACTIVE;
  2138. vxge_hw_vpath_msix_unmask(
  2139. vdev->vpaths[vp_idx].handle,
  2140. msix_idx);
  2141. intr_cnt++;
  2142. }
  2143. /* Point to next vpath handler */
  2144. if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
  2145. (vp_idx < (vdev->no_of_vpath - 1)))
  2146. vp_idx++;
  2147. }
  2148. intr_cnt = vdev->no_of_vpath * 2;
  2149. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2150. "%s:vxge:MSI-X %d - Alarm - fn:%d",
  2151. vdev->ndev->name,
  2152. vdev->entries[intr_cnt].entry,
  2153. pci_fun);
  2154. /* For Alarm interrupts */
  2155. ret = request_irq(vdev->entries[intr_cnt].vector,
  2156. vxge_alarm_msix_handle, 0,
  2157. vdev->desc[intr_cnt],
  2158. &vdev->vpaths[0]);
  2159. if (ret) {
  2160. vxge_debug_init(VXGE_ERR,
  2161. "%s: MSIX - %d Registration failed",
  2162. vdev->ndev->name, intr_cnt);
  2163. vxge_rem_msix_isr(vdev);
  2164. vdev->config.intr_type = INTA;
  2165. vxge_debug_init(VXGE_ERR,
  2166. "%s: Defaulting to INTA",
  2167. vdev->ndev->name);
  2168. goto INTA_MODE;
  2169. }
  2170. msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
  2171. VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
  2172. vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
  2173. msix_idx);
  2174. vdev->vxge_entries[intr_cnt].in_use = 1;
  2175. vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
  2176. }
  2177. INTA_MODE:
  2178. #endif
  2179. if (vdev->config.intr_type == INTA) {
  2180. snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
  2181. "%s:vxge:INTA", vdev->ndev->name);
  2182. vxge_hw_device_set_intr_type(vdev->devh,
  2183. VXGE_HW_INTR_MODE_IRQLINE);
  2184. vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
  2185. ret = request_irq((int) vdev->pdev->irq,
  2186. vxge_isr_napi,
  2187. IRQF_SHARED, vdev->desc[0], vdev);
  2188. if (ret) {
  2189. vxge_debug_init(VXGE_ERR,
  2190. "%s %s-%d: ISR registration failed",
  2191. VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
  2192. return -ENODEV;
  2193. }
  2194. vxge_debug_init(VXGE_TRACE,
  2195. "new %s-%d line allocated",
  2196. "IRQ", vdev->pdev->irq);
  2197. }
  2198. return VXGE_HW_OK;
  2199. }
  2200. static void vxge_poll_vp_reset(unsigned long data)
  2201. {
  2202. struct vxgedev *vdev = (struct vxgedev *)data;
  2203. int i, j = 0;
  2204. for (i = 0; i < vdev->no_of_vpath; i++) {
  2205. if (test_bit(i, &vdev->vp_reset)) {
  2206. vxge_reset_vpath(vdev, i);
  2207. j++;
  2208. }
  2209. }
  2210. if (j && (vdev->config.intr_type != MSI_X)) {
  2211. vxge_hw_device_unmask_all(vdev->devh);
  2212. vxge_hw_device_flush_io(vdev->devh);
  2213. }
  2214. mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
  2215. }
  2216. static void vxge_poll_vp_lockup(unsigned long data)
  2217. {
  2218. struct vxgedev *vdev = (struct vxgedev *)data;
  2219. enum vxge_hw_status status = VXGE_HW_OK;
  2220. struct vxge_vpath *vpath;
  2221. struct vxge_ring *ring;
  2222. int i;
  2223. unsigned long rx_frms;
  2224. for (i = 0; i < vdev->no_of_vpath; i++) {
  2225. ring = &vdev->vpaths[i].ring;
  2226. /* Truncated to machine word size number of frames */
  2227. rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
  2228. /* Did this vpath received any packets */
  2229. if (ring->stats.prev_rx_frms == rx_frms) {
  2230. status = vxge_hw_vpath_check_leak(ring->handle);
  2231. /* Did it received any packets last time */
  2232. if ((VXGE_HW_FAIL == status) &&
  2233. (VXGE_HW_FAIL == ring->last_status)) {
  2234. /* schedule vpath reset */
  2235. if (!test_and_set_bit(i, &vdev->vp_reset)) {
  2236. vpath = &vdev->vpaths[i];
  2237. /* disable interrupts for this vpath */
  2238. vxge_vpath_intr_disable(vdev, i);
  2239. /* stop the queue for this vpath */
  2240. netif_tx_stop_queue(vpath->fifo.txq);
  2241. continue;
  2242. }
  2243. }
  2244. }
  2245. ring->stats.prev_rx_frms = rx_frms;
  2246. ring->last_status = status;
  2247. }
  2248. /* Check every 1 milli second */
  2249. mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
  2250. }
  2251. static u32 vxge_fix_features(struct net_device *dev, u32 features)
  2252. {
  2253. u32 changed = dev->features ^ features;
  2254. /* Enabling RTH requires some of the logic in vxge_device_register and a
  2255. * vpath reset. Due to these restrictions, only allow modification
  2256. * while the interface is down.
  2257. */
  2258. if ((changed & NETIF_F_RXHASH) && netif_running(dev))
  2259. features ^= NETIF_F_RXHASH;
  2260. return features;
  2261. }
  2262. static int vxge_set_features(struct net_device *dev, u32 features)
  2263. {
  2264. struct vxgedev *vdev = netdev_priv(dev);
  2265. u32 changed = dev->features ^ features;
  2266. if (!(changed & NETIF_F_RXHASH))
  2267. return 0;
  2268. /* !netif_running() ensured by vxge_fix_features() */
  2269. vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
  2270. if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
  2271. dev->features = features ^ NETIF_F_RXHASH;
  2272. vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
  2273. return -EIO;
  2274. }
  2275. return 0;
  2276. }
  2277. /**
  2278. * vxge_open
  2279. * @dev: pointer to the device structure.
  2280. *
  2281. * This function is the open entry point of the driver. It mainly calls a
  2282. * function to allocate Rx buffers and inserts them into the buffer
  2283. * descriptors and then enables the Rx part of the NIC.
  2284. * Return value: '0' on success and an appropriate (-)ve integer as
  2285. * defined in errno.h file on failure.
  2286. */
  2287. static int vxge_open(struct net_device *dev)
  2288. {
  2289. enum vxge_hw_status status;
  2290. struct vxgedev *vdev;
  2291. struct __vxge_hw_device *hldev;
  2292. struct vxge_vpath *vpath;
  2293. int ret = 0;
  2294. int i;
  2295. u64 val64, function_mode;
  2296. vxge_debug_entryexit(VXGE_TRACE,
  2297. "%s: %s:%d", dev->name, __func__, __LINE__);
  2298. vdev = netdev_priv(dev);
  2299. hldev = pci_get_drvdata(vdev->pdev);
  2300. function_mode = vdev->config.device_hw_info.function_mode;
  2301. /* make sure you have link off by default every time Nic is
  2302. * initialized */
  2303. netif_carrier_off(dev);
  2304. /* Open VPATHs */
  2305. status = vxge_open_vpaths(vdev);
  2306. if (status != VXGE_HW_OK) {
  2307. vxge_debug_init(VXGE_ERR,
  2308. "%s: fatal: Vpath open failed", vdev->ndev->name);
  2309. ret = -EPERM;
  2310. goto out0;
  2311. }
  2312. vdev->mtu = dev->mtu;
  2313. status = vxge_add_isr(vdev);
  2314. if (status != VXGE_HW_OK) {
  2315. vxge_debug_init(VXGE_ERR,
  2316. "%s: fatal: ISR add failed", dev->name);
  2317. ret = -EPERM;
  2318. goto out1;
  2319. }
  2320. if (vdev->config.intr_type != MSI_X) {
  2321. netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
  2322. vdev->config.napi_weight);
  2323. napi_enable(&vdev->napi);
  2324. for (i = 0; i < vdev->no_of_vpath; i++) {
  2325. vpath = &vdev->vpaths[i];
  2326. vpath->ring.napi_p = &vdev->napi;
  2327. }
  2328. } else {
  2329. for (i = 0; i < vdev->no_of_vpath; i++) {
  2330. vpath = &vdev->vpaths[i];
  2331. netif_napi_add(dev, &vpath->ring.napi,
  2332. vxge_poll_msix, vdev->config.napi_weight);
  2333. napi_enable(&vpath->ring.napi);
  2334. vpath->ring.napi_p = &vpath->ring.napi;
  2335. }
  2336. }
  2337. /* configure RTH */
  2338. if (vdev->config.rth_steering) {
  2339. status = vxge_rth_configure(vdev);
  2340. if (status != VXGE_HW_OK) {
  2341. vxge_debug_init(VXGE_ERR,
  2342. "%s: fatal: RTH configuration failed",
  2343. dev->name);
  2344. ret = -EPERM;
  2345. goto out2;
  2346. }
  2347. }
  2348. printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
  2349. hldev->config.rth_en ? "enabled" : "disabled");
  2350. for (i = 0; i < vdev->no_of_vpath; i++) {
  2351. vpath = &vdev->vpaths[i];
  2352. /* set initial mtu before enabling the device */
  2353. status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
  2354. if (status != VXGE_HW_OK) {
  2355. vxge_debug_init(VXGE_ERR,
  2356. "%s: fatal: can not set new MTU", dev->name);
  2357. ret = -EPERM;
  2358. goto out2;
  2359. }
  2360. }
  2361. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
  2362. vxge_debug_init(vdev->level_trace,
  2363. "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
  2364. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
  2365. /* Restore the DA, VID table and also multicast and promiscuous mode
  2366. * states
  2367. */
  2368. if (vdev->all_multi_flg) {
  2369. for (i = 0; i < vdev->no_of_vpath; i++) {
  2370. vpath = &vdev->vpaths[i];
  2371. vxge_restore_vpath_mac_addr(vpath);
  2372. vxge_restore_vpath_vid_table(vpath);
  2373. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  2374. if (status != VXGE_HW_OK)
  2375. vxge_debug_init(VXGE_ERR,
  2376. "%s:%d Enabling multicast failed",
  2377. __func__, __LINE__);
  2378. }
  2379. }
  2380. /* Enable vpath to sniff all unicast/multicast traffic that not
  2381. * addressed to them. We allow promiscuous mode for PF only
  2382. */
  2383. val64 = 0;
  2384. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  2385. val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
  2386. vxge_hw_mgmt_reg_write(vdev->devh,
  2387. vxge_hw_mgmt_reg_type_mrpcim,
  2388. 0,
  2389. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2390. rxmac_authorize_all_addr),
  2391. val64);
  2392. vxge_hw_mgmt_reg_write(vdev->devh,
  2393. vxge_hw_mgmt_reg_type_mrpcim,
  2394. 0,
  2395. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2396. rxmac_authorize_all_vid),
  2397. val64);
  2398. vxge_set_multicast(dev);
  2399. /* Enabling Bcast and mcast for all vpath */
  2400. for (i = 0; i < vdev->no_of_vpath; i++) {
  2401. vpath = &vdev->vpaths[i];
  2402. status = vxge_hw_vpath_bcast_enable(vpath->handle);
  2403. if (status != VXGE_HW_OK)
  2404. vxge_debug_init(VXGE_ERR,
  2405. "%s : Can not enable bcast for vpath "
  2406. "id %d", dev->name, i);
  2407. if (vdev->config.addr_learn_en) {
  2408. status = vxge_hw_vpath_mcast_enable(vpath->handle);
  2409. if (status != VXGE_HW_OK)
  2410. vxge_debug_init(VXGE_ERR,
  2411. "%s : Can not enable mcast for vpath "
  2412. "id %d", dev->name, i);
  2413. }
  2414. }
  2415. vxge_hw_device_setpause_data(vdev->devh, 0,
  2416. vdev->config.tx_pause_enable,
  2417. vdev->config.rx_pause_enable);
  2418. if (vdev->vp_reset_timer.function == NULL)
  2419. vxge_os_timer(vdev->vp_reset_timer,
  2420. vxge_poll_vp_reset, vdev, (HZ/2));
  2421. /* There is no need to check for RxD leak and RxD lookup on Titan1A */
  2422. if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
  2423. vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
  2424. HZ / 2);
  2425. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2426. smp_wmb();
  2427. if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
  2428. netif_carrier_on(vdev->ndev);
  2429. netdev_notice(vdev->ndev, "Link Up\n");
  2430. vdev->stats.link_up++;
  2431. }
  2432. vxge_hw_device_intr_enable(vdev->devh);
  2433. smp_wmb();
  2434. for (i = 0; i < vdev->no_of_vpath; i++) {
  2435. vpath = &vdev->vpaths[i];
  2436. vxge_hw_vpath_enable(vpath->handle);
  2437. smp_wmb();
  2438. vxge_hw_vpath_rx_doorbell_init(vpath->handle);
  2439. }
  2440. netif_tx_start_all_queues(vdev->ndev);
  2441. /* configure CI */
  2442. vxge_config_ci_for_tti_rti(vdev);
  2443. goto out0;
  2444. out2:
  2445. vxge_rem_isr(vdev);
  2446. /* Disable napi */
  2447. if (vdev->config.intr_type != MSI_X)
  2448. napi_disable(&vdev->napi);
  2449. else {
  2450. for (i = 0; i < vdev->no_of_vpath; i++)
  2451. napi_disable(&vdev->vpaths[i].ring.napi);
  2452. }
  2453. out1:
  2454. vxge_close_vpaths(vdev, 0);
  2455. out0:
  2456. vxge_debug_entryexit(VXGE_TRACE,
  2457. "%s: %s:%d Exiting...",
  2458. dev->name, __func__, __LINE__);
  2459. return ret;
  2460. }
  2461. /* Loop through the mac address list and delete all the entries */
  2462. static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
  2463. {
  2464. struct list_head *entry, *next;
  2465. if (list_empty(&vpath->mac_addr_list))
  2466. return;
  2467. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  2468. list_del(entry);
  2469. kfree((struct vxge_mac_addrs *)entry);
  2470. }
  2471. }
  2472. static void vxge_napi_del_all(struct vxgedev *vdev)
  2473. {
  2474. int i;
  2475. if (vdev->config.intr_type != MSI_X)
  2476. netif_napi_del(&vdev->napi);
  2477. else {
  2478. for (i = 0; i < vdev->no_of_vpath; i++)
  2479. netif_napi_del(&vdev->vpaths[i].ring.napi);
  2480. }
  2481. }
  2482. static int do_vxge_close(struct net_device *dev, int do_io)
  2483. {
  2484. enum vxge_hw_status status;
  2485. struct vxgedev *vdev;
  2486. struct __vxge_hw_device *hldev;
  2487. int i;
  2488. u64 val64, vpath_vector;
  2489. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  2490. dev->name, __func__, __LINE__);
  2491. vdev = netdev_priv(dev);
  2492. hldev = pci_get_drvdata(vdev->pdev);
  2493. if (unlikely(!is_vxge_card_up(vdev)))
  2494. return 0;
  2495. /* If vxge_handle_crit_err task is executing,
  2496. * wait till it completes. */
  2497. while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  2498. msleep(50);
  2499. if (do_io) {
  2500. /* Put the vpath back in normal mode */
  2501. vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
  2502. status = vxge_hw_mgmt_reg_read(vdev->devh,
  2503. vxge_hw_mgmt_reg_type_mrpcim,
  2504. 0,
  2505. (ulong)offsetof(
  2506. struct vxge_hw_mrpcim_reg,
  2507. rts_mgr_cbasin_cfg),
  2508. &val64);
  2509. if (status == VXGE_HW_OK) {
  2510. val64 &= ~vpath_vector;
  2511. status = vxge_hw_mgmt_reg_write(vdev->devh,
  2512. vxge_hw_mgmt_reg_type_mrpcim,
  2513. 0,
  2514. (ulong)offsetof(
  2515. struct vxge_hw_mrpcim_reg,
  2516. rts_mgr_cbasin_cfg),
  2517. val64);
  2518. }
  2519. /* Remove the function 0 from promiscuous mode */
  2520. vxge_hw_mgmt_reg_write(vdev->devh,
  2521. vxge_hw_mgmt_reg_type_mrpcim,
  2522. 0,
  2523. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2524. rxmac_authorize_all_addr),
  2525. 0);
  2526. vxge_hw_mgmt_reg_write(vdev->devh,
  2527. vxge_hw_mgmt_reg_type_mrpcim,
  2528. 0,
  2529. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2530. rxmac_authorize_all_vid),
  2531. 0);
  2532. smp_wmb();
  2533. }
  2534. if (vdev->titan1)
  2535. del_timer_sync(&vdev->vp_lockup_timer);
  2536. del_timer_sync(&vdev->vp_reset_timer);
  2537. if (do_io)
  2538. vxge_hw_device_wait_receive_idle(hldev);
  2539. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2540. /* Disable napi */
  2541. if (vdev->config.intr_type != MSI_X)
  2542. napi_disable(&vdev->napi);
  2543. else {
  2544. for (i = 0; i < vdev->no_of_vpath; i++)
  2545. napi_disable(&vdev->vpaths[i].ring.napi);
  2546. }
  2547. netif_carrier_off(vdev->ndev);
  2548. netdev_notice(vdev->ndev, "Link Down\n");
  2549. netif_tx_stop_all_queues(vdev->ndev);
  2550. /* Note that at this point xmit() is stopped by upper layer */
  2551. if (do_io)
  2552. vxge_hw_device_intr_disable(vdev->devh);
  2553. vxge_rem_isr(vdev);
  2554. vxge_napi_del_all(vdev);
  2555. if (do_io)
  2556. vxge_reset_all_vpaths(vdev);
  2557. vxge_close_vpaths(vdev, 0);
  2558. vxge_debug_entryexit(VXGE_TRACE,
  2559. "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
  2560. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  2561. return 0;
  2562. }
  2563. /**
  2564. * vxge_close
  2565. * @dev: device pointer.
  2566. *
  2567. * This is the stop entry point of the driver. It needs to undo exactly
  2568. * whatever was done by the open entry point, thus it's usually referred to
  2569. * as the close function.Among other things this function mainly stops the
  2570. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  2571. * Return value: '0' on success and an appropriate (-)ve integer as
  2572. * defined in errno.h file on failure.
  2573. */
  2574. static int vxge_close(struct net_device *dev)
  2575. {
  2576. do_vxge_close(dev, 1);
  2577. return 0;
  2578. }
  2579. /**
  2580. * vxge_change_mtu
  2581. * @dev: net device pointer.
  2582. * @new_mtu :the new MTU size for the device.
  2583. *
  2584. * A driver entry point to change MTU size for the device. Before changing
  2585. * the MTU the device must be stopped.
  2586. */
  2587. static int vxge_change_mtu(struct net_device *dev, int new_mtu)
  2588. {
  2589. struct vxgedev *vdev = netdev_priv(dev);
  2590. vxge_debug_entryexit(vdev->level_trace,
  2591. "%s:%d", __func__, __LINE__);
  2592. if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
  2593. vxge_debug_init(vdev->level_err,
  2594. "%s: mtu size is invalid", dev->name);
  2595. return -EPERM;
  2596. }
  2597. /* check if device is down already */
  2598. if (unlikely(!is_vxge_card_up(vdev))) {
  2599. /* just store new value, will use later on open() */
  2600. dev->mtu = new_mtu;
  2601. vxge_debug_init(vdev->level_err,
  2602. "%s", "device is down on MTU change");
  2603. return 0;
  2604. }
  2605. vxge_debug_init(vdev->level_trace,
  2606. "trying to apply new MTU %d", new_mtu);
  2607. if (vxge_close(dev))
  2608. return -EIO;
  2609. dev->mtu = new_mtu;
  2610. vdev->mtu = new_mtu;
  2611. if (vxge_open(dev))
  2612. return -EIO;
  2613. vxge_debug_init(vdev->level_trace,
  2614. "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
  2615. vxge_debug_entryexit(vdev->level_trace,
  2616. "%s:%d Exiting...", __func__, __LINE__);
  2617. return 0;
  2618. }
  2619. /**
  2620. * vxge_get_stats64
  2621. * @dev: pointer to the device structure
  2622. * @stats: pointer to struct rtnl_link_stats64
  2623. *
  2624. */
  2625. static struct rtnl_link_stats64 *
  2626. vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
  2627. {
  2628. struct vxgedev *vdev = netdev_priv(dev);
  2629. int k;
  2630. /* net_stats already zeroed by caller */
  2631. for (k = 0; k < vdev->no_of_vpath; k++) {
  2632. struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
  2633. struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
  2634. unsigned int start;
  2635. u64 packets, bytes, multicast;
  2636. do {
  2637. start = u64_stats_fetch_begin(&rxstats->syncp);
  2638. packets = rxstats->rx_frms;
  2639. multicast = rxstats->rx_mcast;
  2640. bytes = rxstats->rx_bytes;
  2641. } while (u64_stats_fetch_retry(&rxstats->syncp, start));
  2642. net_stats->rx_packets += packets;
  2643. net_stats->rx_bytes += bytes;
  2644. net_stats->multicast += multicast;
  2645. net_stats->rx_errors += rxstats->rx_errors;
  2646. net_stats->rx_dropped += rxstats->rx_dropped;
  2647. do {
  2648. start = u64_stats_fetch_begin(&txstats->syncp);
  2649. packets = txstats->tx_frms;
  2650. bytes = txstats->tx_bytes;
  2651. } while (u64_stats_fetch_retry(&txstats->syncp, start));
  2652. net_stats->tx_packets += packets;
  2653. net_stats->tx_bytes += bytes;
  2654. net_stats->tx_errors += txstats->tx_errors;
  2655. }
  2656. return net_stats;
  2657. }
  2658. static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
  2659. {
  2660. enum vxge_hw_status status;
  2661. u64 val64;
  2662. /* Timestamp is passed to the driver via the FCS, therefore we
  2663. * must disable the FCS stripping by the adapter. Since this is
  2664. * required for the driver to load (due to a hardware bug),
  2665. * there is no need to do anything special here.
  2666. */
  2667. val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
  2668. VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
  2669. VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
  2670. status = vxge_hw_mgmt_reg_write(devh,
  2671. vxge_hw_mgmt_reg_type_mrpcim,
  2672. 0,
  2673. offsetof(struct vxge_hw_mrpcim_reg,
  2674. xmac_timestamp),
  2675. val64);
  2676. vxge_hw_device_flush_io(devh);
  2677. devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
  2678. return status;
  2679. }
  2680. static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
  2681. {
  2682. struct hwtstamp_config config;
  2683. int i;
  2684. if (copy_from_user(&config, data, sizeof(config)))
  2685. return -EFAULT;
  2686. /* reserved for future extensions */
  2687. if (config.flags)
  2688. return -EINVAL;
  2689. /* Transmit HW Timestamp not supported */
  2690. switch (config.tx_type) {
  2691. case HWTSTAMP_TX_OFF:
  2692. break;
  2693. case HWTSTAMP_TX_ON:
  2694. default:
  2695. return -ERANGE;
  2696. }
  2697. switch (config.rx_filter) {
  2698. case HWTSTAMP_FILTER_NONE:
  2699. vdev->rx_hwts = 0;
  2700. config.rx_filter = HWTSTAMP_FILTER_NONE;
  2701. break;
  2702. case HWTSTAMP_FILTER_ALL:
  2703. case HWTSTAMP_FILTER_SOME:
  2704. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2705. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2706. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2707. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2708. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2709. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2710. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  2711. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  2712. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  2713. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2714. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  2715. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  2716. if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
  2717. return -EFAULT;
  2718. vdev->rx_hwts = 1;
  2719. config.rx_filter = HWTSTAMP_FILTER_ALL;
  2720. break;
  2721. default:
  2722. return -ERANGE;
  2723. }
  2724. for (i = 0; i < vdev->no_of_vpath; i++)
  2725. vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
  2726. if (copy_to_user(data, &config, sizeof(config)))
  2727. return -EFAULT;
  2728. return 0;
  2729. }
  2730. /**
  2731. * vxge_ioctl
  2732. * @dev: Device pointer.
  2733. * @ifr: An IOCTL specific structure, that can contain a pointer to
  2734. * a proprietary structure used to pass information to the driver.
  2735. * @cmd: This is used to distinguish between the different commands that
  2736. * can be passed to the IOCTL functions.
  2737. *
  2738. * Entry point for the Ioctl.
  2739. */
  2740. static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2741. {
  2742. struct vxgedev *vdev = netdev_priv(dev);
  2743. int ret;
  2744. switch (cmd) {
  2745. case SIOCSHWTSTAMP:
  2746. ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
  2747. if (ret)
  2748. return ret;
  2749. break;
  2750. default:
  2751. return -EOPNOTSUPP;
  2752. }
  2753. return 0;
  2754. }
  2755. /**
  2756. * vxge_tx_watchdog
  2757. * @dev: pointer to net device structure
  2758. *
  2759. * Watchdog for transmit side.
  2760. * This function is triggered if the Tx Queue is stopped
  2761. * for a pre-defined amount of time when the Interface is still up.
  2762. */
  2763. static void vxge_tx_watchdog(struct net_device *dev)
  2764. {
  2765. struct vxgedev *vdev;
  2766. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2767. vdev = netdev_priv(dev);
  2768. vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
  2769. schedule_work(&vdev->reset_task);
  2770. vxge_debug_entryexit(VXGE_TRACE,
  2771. "%s:%d Exiting...", __func__, __LINE__);
  2772. }
  2773. /**
  2774. * vxge_vlan_rx_add_vid
  2775. * @dev: net device pointer.
  2776. * @vid: vid
  2777. *
  2778. * Add the vlan id to the devices vlan id table
  2779. */
  2780. static void
  2781. vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  2782. {
  2783. struct vxgedev *vdev = netdev_priv(dev);
  2784. struct vxge_vpath *vpath;
  2785. int vp_id;
  2786. /* Add these vlan to the vid table */
  2787. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2788. vpath = &vdev->vpaths[vp_id];
  2789. if (!vpath->is_open)
  2790. continue;
  2791. vxge_hw_vpath_vid_add(vpath->handle, vid);
  2792. }
  2793. set_bit(vid, vdev->active_vlans);
  2794. }
  2795. /**
  2796. * vxge_vlan_rx_add_vid
  2797. * @dev: net device pointer.
  2798. * @vid: vid
  2799. *
  2800. * Remove the vlan id from the device's vlan id table
  2801. */
  2802. static void
  2803. vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  2804. {
  2805. struct vxgedev *vdev = netdev_priv(dev);
  2806. struct vxge_vpath *vpath;
  2807. int vp_id;
  2808. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2809. /* Delete this vlan from the vid table */
  2810. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2811. vpath = &vdev->vpaths[vp_id];
  2812. if (!vpath->is_open)
  2813. continue;
  2814. vxge_hw_vpath_vid_delete(vpath->handle, vid);
  2815. }
  2816. vxge_debug_entryexit(VXGE_TRACE,
  2817. "%s:%d Exiting...", __func__, __LINE__);
  2818. clear_bit(vid, vdev->active_vlans);
  2819. }
  2820. static const struct net_device_ops vxge_netdev_ops = {
  2821. .ndo_open = vxge_open,
  2822. .ndo_stop = vxge_close,
  2823. .ndo_get_stats64 = vxge_get_stats64,
  2824. .ndo_start_xmit = vxge_xmit,
  2825. .ndo_validate_addr = eth_validate_addr,
  2826. .ndo_set_multicast_list = vxge_set_multicast,
  2827. .ndo_do_ioctl = vxge_ioctl,
  2828. .ndo_set_mac_address = vxge_set_mac_addr,
  2829. .ndo_change_mtu = vxge_change_mtu,
  2830. .ndo_fix_features = vxge_fix_features,
  2831. .ndo_set_features = vxge_set_features,
  2832. .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
  2833. .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
  2834. .ndo_tx_timeout = vxge_tx_watchdog,
  2835. #ifdef CONFIG_NET_POLL_CONTROLLER
  2836. .ndo_poll_controller = vxge_netpoll,
  2837. #endif
  2838. };
  2839. static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
  2840. struct vxge_config *config,
  2841. int high_dma, int no_of_vpath,
  2842. struct vxgedev **vdev_out)
  2843. {
  2844. struct net_device *ndev;
  2845. enum vxge_hw_status status = VXGE_HW_OK;
  2846. struct vxgedev *vdev;
  2847. int ret = 0, no_of_queue = 1;
  2848. u64 stat;
  2849. *vdev_out = NULL;
  2850. if (config->tx_steering_type)
  2851. no_of_queue = no_of_vpath;
  2852. ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
  2853. no_of_queue);
  2854. if (ndev == NULL) {
  2855. vxge_debug_init(
  2856. vxge_hw_device_trace_level_get(hldev),
  2857. "%s : device allocation failed", __func__);
  2858. ret = -ENODEV;
  2859. goto _out0;
  2860. }
  2861. vxge_debug_entryexit(
  2862. vxge_hw_device_trace_level_get(hldev),
  2863. "%s: %s:%d Entering...",
  2864. ndev->name, __func__, __LINE__);
  2865. vdev = netdev_priv(ndev);
  2866. memset(vdev, 0, sizeof(struct vxgedev));
  2867. vdev->ndev = ndev;
  2868. vdev->devh = hldev;
  2869. vdev->pdev = hldev->pdev;
  2870. memcpy(&vdev->config, config, sizeof(struct vxge_config));
  2871. vdev->rx_hwts = 0;
  2872. vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
  2873. SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
  2874. ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
  2875. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  2876. NETIF_F_TSO | NETIF_F_TSO6 |
  2877. NETIF_F_HW_VLAN_TX;
  2878. if (vdev->config.rth_steering != NO_STEERING)
  2879. ndev->hw_features |= NETIF_F_RXHASH;
  2880. ndev->features |= ndev->hw_features |
  2881. NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
  2882. /* Driver entry points */
  2883. ndev->irq = vdev->pdev->irq;
  2884. ndev->base_addr = (unsigned long) hldev->bar0;
  2885. ndev->netdev_ops = &vxge_netdev_ops;
  2886. ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
  2887. INIT_WORK(&vdev->reset_task, vxge_reset);
  2888. vxge_initialize_ethtool_ops(ndev);
  2889. /* Allocate memory for vpath */
  2890. vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
  2891. no_of_vpath, GFP_KERNEL);
  2892. if (!vdev->vpaths) {
  2893. vxge_debug_init(VXGE_ERR,
  2894. "%s: vpath memory allocation failed",
  2895. vdev->ndev->name);
  2896. ret = -ENOMEM;
  2897. goto _out1;
  2898. }
  2899. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2900. "%s : checksuming enabled", __func__);
  2901. if (high_dma) {
  2902. ndev->features |= NETIF_F_HIGHDMA;
  2903. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2904. "%s : using High DMA", __func__);
  2905. }
  2906. ret = register_netdev(ndev);
  2907. if (ret) {
  2908. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2909. "%s: %s : device registration failed!",
  2910. ndev->name, __func__);
  2911. goto _out2;
  2912. }
  2913. /* Set the factory defined MAC address initially */
  2914. ndev->addr_len = ETH_ALEN;
  2915. /* Make Link state as off at this point, when the Link change
  2916. * interrupt comes the state will be automatically changed to
  2917. * the right state.
  2918. */
  2919. netif_carrier_off(ndev);
  2920. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2921. "%s: Ethernet device registered",
  2922. ndev->name);
  2923. hldev->ndev = ndev;
  2924. *vdev_out = vdev;
  2925. /* Resetting the Device stats */
  2926. status = vxge_hw_mrpcim_stats_access(
  2927. hldev,
  2928. VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
  2929. 0,
  2930. 0,
  2931. &stat);
  2932. if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
  2933. vxge_debug_init(
  2934. vxge_hw_device_trace_level_get(hldev),
  2935. "%s: device stats clear returns"
  2936. "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
  2937. vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
  2938. "%s: %s:%d Exiting...",
  2939. ndev->name, __func__, __LINE__);
  2940. return ret;
  2941. _out2:
  2942. kfree(vdev->vpaths);
  2943. _out1:
  2944. free_netdev(ndev);
  2945. _out0:
  2946. return ret;
  2947. }
  2948. /*
  2949. * vxge_device_unregister
  2950. *
  2951. * This function will unregister and free network device
  2952. */
  2953. static void vxge_device_unregister(struct __vxge_hw_device *hldev)
  2954. {
  2955. struct vxgedev *vdev;
  2956. struct net_device *dev;
  2957. char buf[IFNAMSIZ];
  2958. dev = hldev->ndev;
  2959. vdev = netdev_priv(dev);
  2960. vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
  2961. __func__, __LINE__);
  2962. strncpy(buf, dev->name, IFNAMSIZ);
  2963. flush_work_sync(&vdev->reset_task);
  2964. /* in 2.6 will call stop() if device is up */
  2965. unregister_netdev(dev);
  2966. kfree(vdev->vpaths);
  2967. /* we are safe to free it now */
  2968. free_netdev(dev);
  2969. vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
  2970. buf);
  2971. vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
  2972. __func__, __LINE__);
  2973. }
  2974. /*
  2975. * vxge_callback_crit_err
  2976. *
  2977. * This function is called by the alarm handler in interrupt context.
  2978. * Driver must analyze it based on the event type.
  2979. */
  2980. static void
  2981. vxge_callback_crit_err(struct __vxge_hw_device *hldev,
  2982. enum vxge_hw_event type, u64 vp_id)
  2983. {
  2984. struct net_device *dev = hldev->ndev;
  2985. struct vxgedev *vdev = netdev_priv(dev);
  2986. struct vxge_vpath *vpath = NULL;
  2987. int vpath_idx;
  2988. vxge_debug_entryexit(vdev->level_trace,
  2989. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  2990. /* Note: This event type should be used for device wide
  2991. * indications only - Serious errors, Slot freeze and critical errors
  2992. */
  2993. vdev->cric_err_event = type;
  2994. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  2995. vpath = &vdev->vpaths[vpath_idx];
  2996. if (vpath->device_id == vp_id)
  2997. break;
  2998. }
  2999. if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
  3000. if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
  3001. vxge_debug_init(VXGE_ERR,
  3002. "%s: Slot is frozen", vdev->ndev->name);
  3003. } else if (type == VXGE_HW_EVENT_SERR) {
  3004. vxge_debug_init(VXGE_ERR,
  3005. "%s: Encountered Serious Error",
  3006. vdev->ndev->name);
  3007. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
  3008. vxge_debug_init(VXGE_ERR,
  3009. "%s: Encountered Critical Error",
  3010. vdev->ndev->name);
  3011. }
  3012. if ((type == VXGE_HW_EVENT_SERR) ||
  3013. (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
  3014. if (unlikely(vdev->exec_mode))
  3015. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3016. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
  3017. vxge_hw_device_mask_all(hldev);
  3018. if (unlikely(vdev->exec_mode))
  3019. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3020. } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
  3021. (type == VXGE_HW_EVENT_VPATH_ERR)) {
  3022. if (unlikely(vdev->exec_mode))
  3023. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  3024. else {
  3025. /* check if this vpath is already set for reset */
  3026. if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
  3027. /* disable interrupts for this vpath */
  3028. vxge_vpath_intr_disable(vdev, vpath_idx);
  3029. /* stop the queue for this vpath */
  3030. netif_tx_stop_queue(vpath->fifo.txq);
  3031. }
  3032. }
  3033. }
  3034. vxge_debug_entryexit(vdev->level_trace,
  3035. "%s: %s:%d Exiting...",
  3036. vdev->ndev->name, __func__, __LINE__);
  3037. }
  3038. static void verify_bandwidth(void)
  3039. {
  3040. int i, band_width, total = 0, equal_priority = 0;
  3041. /* 1. If user enters 0 for some fifo, give equal priority to all */
  3042. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3043. if (bw_percentage[i] == 0) {
  3044. equal_priority = 1;
  3045. break;
  3046. }
  3047. }
  3048. if (!equal_priority) {
  3049. /* 2. If sum exceeds 100, give equal priority to all */
  3050. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3051. if (bw_percentage[i] == 0xFF)
  3052. break;
  3053. total += bw_percentage[i];
  3054. if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
  3055. equal_priority = 1;
  3056. break;
  3057. }
  3058. }
  3059. }
  3060. if (!equal_priority) {
  3061. /* Is all the bandwidth consumed? */
  3062. if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
  3063. if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
  3064. /* Split rest of bw equally among next VPs*/
  3065. band_width =
  3066. (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
  3067. (VXGE_HW_MAX_VIRTUAL_PATHS - i);
  3068. if (band_width < 2) /* min of 2% */
  3069. equal_priority = 1;
  3070. else {
  3071. for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
  3072. i++)
  3073. bw_percentage[i] =
  3074. band_width;
  3075. }
  3076. }
  3077. } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
  3078. equal_priority = 1;
  3079. }
  3080. if (equal_priority) {
  3081. vxge_debug_init(VXGE_ERR,
  3082. "%s: Assigning equal bandwidth to all the vpaths",
  3083. VXGE_DRIVER_NAME);
  3084. bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
  3085. VXGE_HW_MAX_VIRTUAL_PATHS;
  3086. for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3087. bw_percentage[i] = bw_percentage[0];
  3088. }
  3089. }
  3090. /*
  3091. * Vpath configuration
  3092. */
  3093. static int __devinit vxge_config_vpaths(
  3094. struct vxge_hw_device_config *device_config,
  3095. u64 vpath_mask, struct vxge_config *config_param)
  3096. {
  3097. int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
  3098. u32 txdl_size, txdl_per_memblock;
  3099. temp = driver_config->vpath_per_dev;
  3100. if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
  3101. (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
  3102. /* No more CPU. Return vpath number as zero.*/
  3103. if (driver_config->g_no_cpus == -1)
  3104. return 0;
  3105. if (!driver_config->g_no_cpus)
  3106. driver_config->g_no_cpus = num_online_cpus();
  3107. driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
  3108. if (!driver_config->vpath_per_dev)
  3109. driver_config->vpath_per_dev = 1;
  3110. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3111. if (!vxge_bVALn(vpath_mask, i, 1))
  3112. continue;
  3113. else
  3114. default_no_vpath++;
  3115. if (default_no_vpath < driver_config->vpath_per_dev)
  3116. driver_config->vpath_per_dev = default_no_vpath;
  3117. driver_config->g_no_cpus = driver_config->g_no_cpus -
  3118. (driver_config->vpath_per_dev * 2);
  3119. if (driver_config->g_no_cpus <= 0)
  3120. driver_config->g_no_cpus = -1;
  3121. }
  3122. if (driver_config->vpath_per_dev == 1) {
  3123. vxge_debug_ll_config(VXGE_TRACE,
  3124. "%s: Disable tx and rx steering, "
  3125. "as single vpath is configured", VXGE_DRIVER_NAME);
  3126. config_param->rth_steering = NO_STEERING;
  3127. config_param->tx_steering_type = NO_STEERING;
  3128. device_config->rth_en = 0;
  3129. }
  3130. /* configure bandwidth */
  3131. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3132. device_config->vp_config[i].min_bandwidth = bw_percentage[i];
  3133. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3134. device_config->vp_config[i].vp_id = i;
  3135. device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
  3136. if (no_of_vpaths < driver_config->vpath_per_dev) {
  3137. if (!vxge_bVALn(vpath_mask, i, 1)) {
  3138. vxge_debug_ll_config(VXGE_TRACE,
  3139. "%s: vpath: %d is not available",
  3140. VXGE_DRIVER_NAME, i);
  3141. continue;
  3142. } else {
  3143. vxge_debug_ll_config(VXGE_TRACE,
  3144. "%s: vpath: %d available",
  3145. VXGE_DRIVER_NAME, i);
  3146. no_of_vpaths++;
  3147. }
  3148. } else {
  3149. vxge_debug_ll_config(VXGE_TRACE,
  3150. "%s: vpath: %d is not configured, "
  3151. "max_config_vpath exceeded",
  3152. VXGE_DRIVER_NAME, i);
  3153. break;
  3154. }
  3155. /* Configure Tx fifo's */
  3156. device_config->vp_config[i].fifo.enable =
  3157. VXGE_HW_FIFO_ENABLE;
  3158. device_config->vp_config[i].fifo.max_frags =
  3159. MAX_SKB_FRAGS + 1;
  3160. device_config->vp_config[i].fifo.memblock_size =
  3161. VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
  3162. txdl_size = device_config->vp_config[i].fifo.max_frags *
  3163. sizeof(struct vxge_hw_fifo_txd);
  3164. txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
  3165. device_config->vp_config[i].fifo.fifo_blocks =
  3166. ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
  3167. device_config->vp_config[i].fifo.intr =
  3168. VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
  3169. /* Configure tti properties */
  3170. device_config->vp_config[i].tti.intr_enable =
  3171. VXGE_HW_TIM_INTR_ENABLE;
  3172. device_config->vp_config[i].tti.btimer_val =
  3173. (VXGE_TTI_BTIMER_VAL * 1000) / 272;
  3174. device_config->vp_config[i].tti.timer_ac_en =
  3175. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3176. /* For msi-x with napi (each vector has a handler of its own) -
  3177. * Set CI to OFF for all vpaths
  3178. */
  3179. device_config->vp_config[i].tti.timer_ci_en =
  3180. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3181. device_config->vp_config[i].tti.timer_ri_en =
  3182. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3183. device_config->vp_config[i].tti.util_sel =
  3184. VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
  3185. device_config->vp_config[i].tti.ltimer_val =
  3186. (VXGE_TTI_LTIMER_VAL * 1000) / 272;
  3187. device_config->vp_config[i].tti.rtimer_val =
  3188. (VXGE_TTI_RTIMER_VAL * 1000) / 272;
  3189. device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
  3190. device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
  3191. device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
  3192. device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
  3193. device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
  3194. device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
  3195. device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
  3196. /* Configure Rx rings */
  3197. device_config->vp_config[i].ring.enable =
  3198. VXGE_HW_RING_ENABLE;
  3199. device_config->vp_config[i].ring.ring_blocks =
  3200. VXGE_HW_DEF_RING_BLOCKS;
  3201. device_config->vp_config[i].ring.buffer_mode =
  3202. VXGE_HW_RING_RXD_BUFFER_MODE_1;
  3203. device_config->vp_config[i].ring.rxds_limit =
  3204. VXGE_HW_DEF_RING_RXDS_LIMIT;
  3205. device_config->vp_config[i].ring.scatter_mode =
  3206. VXGE_HW_RING_SCATTER_MODE_A;
  3207. /* Configure rti properties */
  3208. device_config->vp_config[i].rti.intr_enable =
  3209. VXGE_HW_TIM_INTR_ENABLE;
  3210. device_config->vp_config[i].rti.btimer_val =
  3211. (VXGE_RTI_BTIMER_VAL * 1000)/272;
  3212. device_config->vp_config[i].rti.timer_ac_en =
  3213. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3214. device_config->vp_config[i].rti.timer_ci_en =
  3215. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3216. device_config->vp_config[i].rti.timer_ri_en =
  3217. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3218. device_config->vp_config[i].rti.util_sel =
  3219. VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
  3220. device_config->vp_config[i].rti.urange_a =
  3221. RTI_RX_URANGE_A;
  3222. device_config->vp_config[i].rti.urange_b =
  3223. RTI_RX_URANGE_B;
  3224. device_config->vp_config[i].rti.urange_c =
  3225. RTI_RX_URANGE_C;
  3226. device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
  3227. device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
  3228. device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
  3229. device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
  3230. device_config->vp_config[i].rti.rtimer_val =
  3231. (VXGE_RTI_RTIMER_VAL * 1000) / 272;
  3232. device_config->vp_config[i].rti.ltimer_val =
  3233. (VXGE_RTI_LTIMER_VAL * 1000) / 272;
  3234. device_config->vp_config[i].rpa_strip_vlan_tag =
  3235. vlan_tag_strip;
  3236. }
  3237. driver_config->vpath_per_dev = temp;
  3238. return no_of_vpaths;
  3239. }
  3240. /* initialize device configuratrions */
  3241. static void __devinit vxge_device_config_init(
  3242. struct vxge_hw_device_config *device_config,
  3243. int *intr_type)
  3244. {
  3245. /* Used for CQRQ/SRQ. */
  3246. device_config->dma_blockpool_initial =
  3247. VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
  3248. device_config->dma_blockpool_max =
  3249. VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
  3250. if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
  3251. max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
  3252. #ifndef CONFIG_PCI_MSI
  3253. vxge_debug_init(VXGE_ERR,
  3254. "%s: This Kernel does not support "
  3255. "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
  3256. *intr_type = INTA;
  3257. #endif
  3258. /* Configure whether MSI-X or IRQL. */
  3259. switch (*intr_type) {
  3260. case INTA:
  3261. device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
  3262. break;
  3263. case MSI_X:
  3264. device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
  3265. break;
  3266. }
  3267. /* Timer period between device poll */
  3268. device_config->device_poll_millis = VXGE_TIMER_DELAY;
  3269. /* Configure mac based steering. */
  3270. device_config->rts_mac_en = addr_learn_en;
  3271. /* Configure Vpaths */
  3272. device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
  3273. vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
  3274. __func__);
  3275. vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
  3276. device_config->intr_mode);
  3277. vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
  3278. device_config->device_poll_millis);
  3279. vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
  3280. device_config->rth_en);
  3281. vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
  3282. device_config->rth_it_type);
  3283. }
  3284. static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
  3285. {
  3286. int i;
  3287. vxge_debug_init(VXGE_TRACE,
  3288. "%s: %d Vpath(s) opened",
  3289. vdev->ndev->name, vdev->no_of_vpath);
  3290. switch (vdev->config.intr_type) {
  3291. case INTA:
  3292. vxge_debug_init(VXGE_TRACE,
  3293. "%s: Interrupt type INTA", vdev->ndev->name);
  3294. break;
  3295. case MSI_X:
  3296. vxge_debug_init(VXGE_TRACE,
  3297. "%s: Interrupt type MSI-X", vdev->ndev->name);
  3298. break;
  3299. }
  3300. if (vdev->config.rth_steering) {
  3301. vxge_debug_init(VXGE_TRACE,
  3302. "%s: RTH steering enabled for TCP_IPV4",
  3303. vdev->ndev->name);
  3304. } else {
  3305. vxge_debug_init(VXGE_TRACE,
  3306. "%s: RTH steering disabled", vdev->ndev->name);
  3307. }
  3308. switch (vdev->config.tx_steering_type) {
  3309. case NO_STEERING:
  3310. vxge_debug_init(VXGE_TRACE,
  3311. "%s: Tx steering disabled", vdev->ndev->name);
  3312. break;
  3313. case TX_PRIORITY_STEERING:
  3314. vxge_debug_init(VXGE_TRACE,
  3315. "%s: Unsupported tx steering option",
  3316. vdev->ndev->name);
  3317. vxge_debug_init(VXGE_TRACE,
  3318. "%s: Tx steering disabled", vdev->ndev->name);
  3319. vdev->config.tx_steering_type = 0;
  3320. break;
  3321. case TX_VLAN_STEERING:
  3322. vxge_debug_init(VXGE_TRACE,
  3323. "%s: Unsupported tx steering option",
  3324. vdev->ndev->name);
  3325. vxge_debug_init(VXGE_TRACE,
  3326. "%s: Tx steering disabled", vdev->ndev->name);
  3327. vdev->config.tx_steering_type = 0;
  3328. break;
  3329. case TX_MULTIQ_STEERING:
  3330. vxge_debug_init(VXGE_TRACE,
  3331. "%s: Tx multiqueue steering enabled",
  3332. vdev->ndev->name);
  3333. break;
  3334. case TX_PORT_STEERING:
  3335. vxge_debug_init(VXGE_TRACE,
  3336. "%s: Tx port steering enabled",
  3337. vdev->ndev->name);
  3338. break;
  3339. default:
  3340. vxge_debug_init(VXGE_ERR,
  3341. "%s: Unsupported tx steering type",
  3342. vdev->ndev->name);
  3343. vxge_debug_init(VXGE_TRACE,
  3344. "%s: Tx steering disabled", vdev->ndev->name);
  3345. vdev->config.tx_steering_type = 0;
  3346. }
  3347. if (vdev->config.addr_learn_en)
  3348. vxge_debug_init(VXGE_TRACE,
  3349. "%s: MAC Address learning enabled", vdev->ndev->name);
  3350. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3351. if (!vxge_bVALn(vpath_mask, i, 1))
  3352. continue;
  3353. vxge_debug_ll_config(VXGE_TRACE,
  3354. "%s: MTU size - %d", vdev->ndev->name,
  3355. ((struct __vxge_hw_device *)(vdev->devh))->
  3356. config.vp_config[i].mtu);
  3357. vxge_debug_init(VXGE_TRACE,
  3358. "%s: VLAN tag stripping %s", vdev->ndev->name,
  3359. ((struct __vxge_hw_device *)(vdev->devh))->
  3360. config.vp_config[i].rpa_strip_vlan_tag
  3361. ? "Enabled" : "Disabled");
  3362. vxge_debug_ll_config(VXGE_TRACE,
  3363. "%s: Max frags : %d", vdev->ndev->name,
  3364. ((struct __vxge_hw_device *)(vdev->devh))->
  3365. config.vp_config[i].fifo.max_frags);
  3366. break;
  3367. }
  3368. }
  3369. #ifdef CONFIG_PM
  3370. /**
  3371. * vxge_pm_suspend - vxge power management suspend entry point
  3372. *
  3373. */
  3374. static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
  3375. {
  3376. return -ENOSYS;
  3377. }
  3378. /**
  3379. * vxge_pm_resume - vxge power management resume entry point
  3380. *
  3381. */
  3382. static int vxge_pm_resume(struct pci_dev *pdev)
  3383. {
  3384. return -ENOSYS;
  3385. }
  3386. #endif
  3387. /**
  3388. * vxge_io_error_detected - called when PCI error is detected
  3389. * @pdev: Pointer to PCI device
  3390. * @state: The current pci connection state
  3391. *
  3392. * This function is called after a PCI bus error affecting
  3393. * this device has been detected.
  3394. */
  3395. static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
  3396. pci_channel_state_t state)
  3397. {
  3398. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3399. struct net_device *netdev = hldev->ndev;
  3400. netif_device_detach(netdev);
  3401. if (state == pci_channel_io_perm_failure)
  3402. return PCI_ERS_RESULT_DISCONNECT;
  3403. if (netif_running(netdev)) {
  3404. /* Bring down the card, while avoiding PCI I/O */
  3405. do_vxge_close(netdev, 0);
  3406. }
  3407. pci_disable_device(pdev);
  3408. return PCI_ERS_RESULT_NEED_RESET;
  3409. }
  3410. /**
  3411. * vxge_io_slot_reset - called after the pci bus has been reset.
  3412. * @pdev: Pointer to PCI device
  3413. *
  3414. * Restart the card from scratch, as if from a cold-boot.
  3415. * At this point, the card has exprienced a hard reset,
  3416. * followed by fixups by BIOS, and has its config space
  3417. * set up identically to what it was at cold boot.
  3418. */
  3419. static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
  3420. {
  3421. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3422. struct net_device *netdev = hldev->ndev;
  3423. struct vxgedev *vdev = netdev_priv(netdev);
  3424. if (pci_enable_device(pdev)) {
  3425. netdev_err(netdev, "Cannot re-enable device after reset\n");
  3426. return PCI_ERS_RESULT_DISCONNECT;
  3427. }
  3428. pci_set_master(pdev);
  3429. do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
  3430. return PCI_ERS_RESULT_RECOVERED;
  3431. }
  3432. /**
  3433. * vxge_io_resume - called when traffic can start flowing again.
  3434. * @pdev: Pointer to PCI device
  3435. *
  3436. * This callback is called when the error recovery driver tells
  3437. * us that its OK to resume normal operation.
  3438. */
  3439. static void vxge_io_resume(struct pci_dev *pdev)
  3440. {
  3441. struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
  3442. struct net_device *netdev = hldev->ndev;
  3443. if (netif_running(netdev)) {
  3444. if (vxge_open(netdev)) {
  3445. netdev_err(netdev,
  3446. "Can't bring device back up after reset\n");
  3447. return;
  3448. }
  3449. }
  3450. netif_device_attach(netdev);
  3451. }
  3452. static inline u32 vxge_get_num_vfs(u64 function_mode)
  3453. {
  3454. u32 num_functions = 0;
  3455. switch (function_mode) {
  3456. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
  3457. case VXGE_HW_FUNCTION_MODE_SRIOV_8:
  3458. num_functions = 8;
  3459. break;
  3460. case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
  3461. num_functions = 1;
  3462. break;
  3463. case VXGE_HW_FUNCTION_MODE_SRIOV:
  3464. case VXGE_HW_FUNCTION_MODE_MRIOV:
  3465. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
  3466. num_functions = 17;
  3467. break;
  3468. case VXGE_HW_FUNCTION_MODE_SRIOV_4:
  3469. num_functions = 4;
  3470. break;
  3471. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
  3472. num_functions = 2;
  3473. break;
  3474. case VXGE_HW_FUNCTION_MODE_MRIOV_8:
  3475. num_functions = 8; /* TODO */
  3476. break;
  3477. }
  3478. return num_functions;
  3479. }
  3480. int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
  3481. {
  3482. struct __vxge_hw_device *hldev = vdev->devh;
  3483. u32 maj, min, bld, cmaj, cmin, cbld;
  3484. enum vxge_hw_status status;
  3485. const struct firmware *fw;
  3486. int ret;
  3487. ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
  3488. if (ret) {
  3489. vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
  3490. VXGE_DRIVER_NAME, fw_name);
  3491. goto out;
  3492. }
  3493. /* Load the new firmware onto the adapter */
  3494. status = vxge_update_fw_image(hldev, fw->data, fw->size);
  3495. if (status != VXGE_HW_OK) {
  3496. vxge_debug_init(VXGE_ERR,
  3497. "%s: FW image download to adapter failed '%s'.",
  3498. VXGE_DRIVER_NAME, fw_name);
  3499. ret = -EIO;
  3500. goto out;
  3501. }
  3502. /* Read the version of the new firmware */
  3503. status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
  3504. if (status != VXGE_HW_OK) {
  3505. vxge_debug_init(VXGE_ERR,
  3506. "%s: Upgrade read version failed '%s'.",
  3507. VXGE_DRIVER_NAME, fw_name);
  3508. ret = -EIO;
  3509. goto out;
  3510. }
  3511. cmaj = vdev->config.device_hw_info.fw_version.major;
  3512. cmin = vdev->config.device_hw_info.fw_version.minor;
  3513. cbld = vdev->config.device_hw_info.fw_version.build;
  3514. /* It's possible the version in /lib/firmware is not the latest version.
  3515. * If so, we could get into a loop of trying to upgrade to the latest
  3516. * and flashing the older version.
  3517. */
  3518. if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
  3519. !override) {
  3520. ret = -EINVAL;
  3521. goto out;
  3522. }
  3523. printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
  3524. maj, min, bld);
  3525. /* Flash the adapter with the new firmware */
  3526. status = vxge_hw_flash_fw(hldev);
  3527. if (status != VXGE_HW_OK) {
  3528. vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
  3529. VXGE_DRIVER_NAME, fw_name);
  3530. ret = -EIO;
  3531. goto out;
  3532. }
  3533. printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
  3534. "hard reset before using, thus requiring a system reboot or a "
  3535. "hotplug event.\n");
  3536. out:
  3537. release_firmware(fw);
  3538. return ret;
  3539. }
  3540. static int vxge_probe_fw_update(struct vxgedev *vdev)
  3541. {
  3542. u32 maj, min, bld;
  3543. int ret, gpxe = 0;
  3544. char *fw_name;
  3545. maj = vdev->config.device_hw_info.fw_version.major;
  3546. min = vdev->config.device_hw_info.fw_version.minor;
  3547. bld = vdev->config.device_hw_info.fw_version.build;
  3548. if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
  3549. return 0;
  3550. /* Ignore the build number when determining if the current firmware is
  3551. * "too new" to load the driver
  3552. */
  3553. if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
  3554. vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
  3555. "version, unable to load driver\n",
  3556. VXGE_DRIVER_NAME);
  3557. return -EINVAL;
  3558. }
  3559. /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
  3560. * work with this driver.
  3561. */
  3562. if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
  3563. vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
  3564. "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
  3565. return -EINVAL;
  3566. }
  3567. /* If file not specified, determine gPXE or not */
  3568. if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
  3569. int i;
  3570. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
  3571. if (vdev->devh->eprom_versions[i]) {
  3572. gpxe = 1;
  3573. break;
  3574. }
  3575. }
  3576. if (gpxe)
  3577. fw_name = "vxge/X3fw-pxe.ncf";
  3578. else
  3579. fw_name = "vxge/X3fw.ncf";
  3580. ret = vxge_fw_upgrade(vdev, fw_name, 0);
  3581. /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
  3582. * probe, so ignore them
  3583. */
  3584. if (ret != -EINVAL && ret != -ENOENT)
  3585. return -EIO;
  3586. else
  3587. ret = 0;
  3588. if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
  3589. VXGE_FW_VER(maj, min, 0)) {
  3590. vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
  3591. " be used with this driver.\n"
  3592. "Please get the latest version from "
  3593. "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
  3594. VXGE_DRIVER_NAME, maj, min, bld);
  3595. return -EINVAL;
  3596. }
  3597. return ret;
  3598. }
  3599. static int __devinit is_sriov_initialized(struct pci_dev *pdev)
  3600. {
  3601. int pos;
  3602. u16 ctrl;
  3603. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  3604. if (pos) {
  3605. pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
  3606. if (ctrl & PCI_SRIOV_CTRL_VFE)
  3607. return 1;
  3608. }
  3609. return 0;
  3610. }
  3611. /**
  3612. * vxge_probe
  3613. * @pdev : structure containing the PCI related information of the device.
  3614. * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
  3615. * Description:
  3616. * This function is called when a new PCI device gets detected and initializes
  3617. * it.
  3618. * Return value:
  3619. * returns 0 on success and negative on failure.
  3620. *
  3621. */
  3622. static int __devinit
  3623. vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
  3624. {
  3625. struct __vxge_hw_device *hldev;
  3626. enum vxge_hw_status status;
  3627. int ret;
  3628. int high_dma = 0;
  3629. u64 vpath_mask = 0;
  3630. struct vxgedev *vdev;
  3631. struct vxge_config *ll_config = NULL;
  3632. struct vxge_hw_device_config *device_config = NULL;
  3633. struct vxge_hw_device_attr attr;
  3634. int i, j, no_of_vpath = 0, max_vpath_supported = 0;
  3635. u8 *macaddr;
  3636. struct vxge_mac_addrs *entry;
  3637. static int bus = -1, device = -1;
  3638. u32 host_type;
  3639. u8 new_device = 0;
  3640. enum vxge_hw_status is_privileged;
  3641. u32 function_mode;
  3642. u32 num_vfs = 0;
  3643. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  3644. attr.pdev = pdev;
  3645. /* In SRIOV-17 mode, functions of the same adapter
  3646. * can be deployed on different buses
  3647. */
  3648. if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
  3649. !pdev->is_virtfn)
  3650. new_device = 1;
  3651. bus = pdev->bus->number;
  3652. device = PCI_SLOT(pdev->devfn);
  3653. if (new_device) {
  3654. if (driver_config->config_dev_cnt &&
  3655. (driver_config->config_dev_cnt !=
  3656. driver_config->total_dev_cnt))
  3657. vxge_debug_init(VXGE_ERR,
  3658. "%s: Configured %d of %d devices",
  3659. VXGE_DRIVER_NAME,
  3660. driver_config->config_dev_cnt,
  3661. driver_config->total_dev_cnt);
  3662. driver_config->config_dev_cnt = 0;
  3663. driver_config->total_dev_cnt = 0;
  3664. }
  3665. /* Now making the CPU based no of vpath calculation
  3666. * applicable for individual functions as well.
  3667. */
  3668. driver_config->g_no_cpus = 0;
  3669. driver_config->vpath_per_dev = max_config_vpath;
  3670. driver_config->total_dev_cnt++;
  3671. if (++driver_config->config_dev_cnt > max_config_dev) {
  3672. ret = 0;
  3673. goto _exit0;
  3674. }
  3675. device_config = kzalloc(sizeof(struct vxge_hw_device_config),
  3676. GFP_KERNEL);
  3677. if (!device_config) {
  3678. ret = -ENOMEM;
  3679. vxge_debug_init(VXGE_ERR,
  3680. "device_config : malloc failed %s %d",
  3681. __FILE__, __LINE__);
  3682. goto _exit0;
  3683. }
  3684. ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
  3685. if (!ll_config) {
  3686. ret = -ENOMEM;
  3687. vxge_debug_init(VXGE_ERR,
  3688. "device_config : malloc failed %s %d",
  3689. __FILE__, __LINE__);
  3690. goto _exit0;
  3691. }
  3692. ll_config->tx_steering_type = TX_MULTIQ_STEERING;
  3693. ll_config->intr_type = MSI_X;
  3694. ll_config->napi_weight = NEW_NAPI_WEIGHT;
  3695. ll_config->rth_steering = RTH_STEERING;
  3696. /* get the default configuration parameters */
  3697. vxge_hw_device_config_default_get(device_config);
  3698. /* initialize configuration parameters */
  3699. vxge_device_config_init(device_config, &ll_config->intr_type);
  3700. ret = pci_enable_device(pdev);
  3701. if (ret) {
  3702. vxge_debug_init(VXGE_ERR,
  3703. "%s : can not enable PCI device", __func__);
  3704. goto _exit0;
  3705. }
  3706. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  3707. vxge_debug_ll_config(VXGE_TRACE,
  3708. "%s : using 64bit DMA", __func__);
  3709. high_dma = 1;
  3710. if (pci_set_consistent_dma_mask(pdev,
  3711. DMA_BIT_MASK(64))) {
  3712. vxge_debug_init(VXGE_ERR,
  3713. "%s : unable to obtain 64bit DMA for "
  3714. "consistent allocations", __func__);
  3715. ret = -ENOMEM;
  3716. goto _exit1;
  3717. }
  3718. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  3719. vxge_debug_ll_config(VXGE_TRACE,
  3720. "%s : using 32bit DMA", __func__);
  3721. } else {
  3722. ret = -ENOMEM;
  3723. goto _exit1;
  3724. }
  3725. ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
  3726. if (ret) {
  3727. vxge_debug_init(VXGE_ERR,
  3728. "%s : request regions failed", __func__);
  3729. goto _exit1;
  3730. }
  3731. pci_set_master(pdev);
  3732. attr.bar0 = pci_ioremap_bar(pdev, 0);
  3733. if (!attr.bar0) {
  3734. vxge_debug_init(VXGE_ERR,
  3735. "%s : cannot remap io memory bar0", __func__);
  3736. ret = -ENODEV;
  3737. goto _exit2;
  3738. }
  3739. vxge_debug_ll_config(VXGE_TRACE,
  3740. "pci ioremap bar0: %p:0x%llx",
  3741. attr.bar0,
  3742. (unsigned long long)pci_resource_start(pdev, 0));
  3743. status = vxge_hw_device_hw_info_get(attr.bar0,
  3744. &ll_config->device_hw_info);
  3745. if (status != VXGE_HW_OK) {
  3746. vxge_debug_init(VXGE_ERR,
  3747. "%s: Reading of hardware info failed."
  3748. "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
  3749. ret = -EINVAL;
  3750. goto _exit3;
  3751. }
  3752. vpath_mask = ll_config->device_hw_info.vpath_mask;
  3753. if (vpath_mask == 0) {
  3754. vxge_debug_ll_config(VXGE_TRACE,
  3755. "%s: No vpaths available in device", VXGE_DRIVER_NAME);
  3756. ret = -EINVAL;
  3757. goto _exit3;
  3758. }
  3759. vxge_debug_ll_config(VXGE_TRACE,
  3760. "%s:%d Vpath mask = %llx", __func__, __LINE__,
  3761. (unsigned long long)vpath_mask);
  3762. function_mode = ll_config->device_hw_info.function_mode;
  3763. host_type = ll_config->device_hw_info.host_type;
  3764. is_privileged = __vxge_hw_device_is_privilaged(host_type,
  3765. ll_config->device_hw_info.func_id);
  3766. /* Check how many vpaths are available */
  3767. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3768. if (!((vpath_mask) & vxge_mBIT(i)))
  3769. continue;
  3770. max_vpath_supported++;
  3771. }
  3772. if (new_device)
  3773. num_vfs = vxge_get_num_vfs(function_mode) - 1;
  3774. /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
  3775. if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
  3776. (ll_config->intr_type != INTA)) {
  3777. ret = pci_enable_sriov(pdev, num_vfs);
  3778. if (ret)
  3779. vxge_debug_ll_config(VXGE_ERR,
  3780. "Failed in enabling SRIOV mode: %d\n", ret);
  3781. /* No need to fail out, as an error here is non-fatal */
  3782. }
  3783. /*
  3784. * Configure vpaths and get driver configured number of vpaths
  3785. * which is less than or equal to the maximum vpaths per function.
  3786. */
  3787. no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
  3788. if (!no_of_vpath) {
  3789. vxge_debug_ll_config(VXGE_ERR,
  3790. "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
  3791. ret = 0;
  3792. goto _exit3;
  3793. }
  3794. /* Setting driver callbacks */
  3795. attr.uld_callbacks.link_up = vxge_callback_link_up;
  3796. attr.uld_callbacks.link_down = vxge_callback_link_down;
  3797. attr.uld_callbacks.crit_err = vxge_callback_crit_err;
  3798. status = vxge_hw_device_initialize(&hldev, &attr, device_config);
  3799. if (status != VXGE_HW_OK) {
  3800. vxge_debug_init(VXGE_ERR,
  3801. "Failed to initialize device (%d)", status);
  3802. ret = -EINVAL;
  3803. goto _exit3;
  3804. }
  3805. if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
  3806. ll_config->device_hw_info.fw_version.minor,
  3807. ll_config->device_hw_info.fw_version.build) >=
  3808. VXGE_EPROM_FW_VER) {
  3809. struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
  3810. status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
  3811. if (status != VXGE_HW_OK) {
  3812. vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
  3813. VXGE_DRIVER_NAME);
  3814. /* This is a non-fatal error, continue */
  3815. }
  3816. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
  3817. hldev->eprom_versions[i] = img[i].version;
  3818. if (!img[i].is_valid)
  3819. break;
  3820. vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
  3821. "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
  3822. VXGE_EPROM_IMG_MAJOR(img[i].version),
  3823. VXGE_EPROM_IMG_MINOR(img[i].version),
  3824. VXGE_EPROM_IMG_FIX(img[i].version),
  3825. VXGE_EPROM_IMG_BUILD(img[i].version));
  3826. }
  3827. }
  3828. /* if FCS stripping is not disabled in MAC fail driver load */
  3829. status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
  3830. if (status != VXGE_HW_OK) {
  3831. vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
  3832. " failing driver load", VXGE_DRIVER_NAME);
  3833. ret = -EINVAL;
  3834. goto _exit4;
  3835. }
  3836. /* Always enable HWTS. This will always cause the FCS to be invalid,
  3837. * due to the fact that HWTS is using the FCS as the location of the
  3838. * timestamp. The HW FCS checking will still correctly determine if
  3839. * there is a valid checksum, and the FCS is being removed by the driver
  3840. * anyway. So no fucntionality is being lost. Since it is always
  3841. * enabled, we now simply use the ioctl call to set whether or not the
  3842. * driver should be paying attention to the HWTS.
  3843. */
  3844. if (is_privileged == VXGE_HW_OK) {
  3845. status = vxge_timestamp_config(hldev);
  3846. if (status != VXGE_HW_OK) {
  3847. vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
  3848. VXGE_DRIVER_NAME);
  3849. ret = -EFAULT;
  3850. goto _exit4;
  3851. }
  3852. }
  3853. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  3854. /* set private device info */
  3855. pci_set_drvdata(pdev, hldev);
  3856. ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
  3857. ll_config->addr_learn_en = addr_learn_en;
  3858. ll_config->rth_algorithm = RTH_ALG_JENKINS;
  3859. ll_config->rth_hash_type_tcpipv4 = 1;
  3860. ll_config->rth_hash_type_ipv4 = 0;
  3861. ll_config->rth_hash_type_tcpipv6 = 0;
  3862. ll_config->rth_hash_type_ipv6 = 0;
  3863. ll_config->rth_hash_type_tcpipv6ex = 0;
  3864. ll_config->rth_hash_type_ipv6ex = 0;
  3865. ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
  3866. ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3867. ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3868. ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
  3869. &vdev);
  3870. if (ret) {
  3871. ret = -EINVAL;
  3872. goto _exit4;
  3873. }
  3874. ret = vxge_probe_fw_update(vdev);
  3875. if (ret)
  3876. goto _exit5;
  3877. vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
  3878. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  3879. vxge_hw_device_trace_level_get(hldev));
  3880. /* set private HW device info */
  3881. vdev->mtu = VXGE_HW_DEFAULT_MTU;
  3882. vdev->bar0 = attr.bar0;
  3883. vdev->max_vpath_supported = max_vpath_supported;
  3884. vdev->no_of_vpath = no_of_vpath;
  3885. /* Virtual Path count */
  3886. for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3887. if (!vxge_bVALn(vpath_mask, i, 1))
  3888. continue;
  3889. if (j >= vdev->no_of_vpath)
  3890. break;
  3891. vdev->vpaths[j].is_configured = 1;
  3892. vdev->vpaths[j].device_id = i;
  3893. vdev->vpaths[j].ring.driver_id = j;
  3894. vdev->vpaths[j].vdev = vdev;
  3895. vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
  3896. memcpy((u8 *)vdev->vpaths[j].macaddr,
  3897. ll_config->device_hw_info.mac_addrs[i],
  3898. ETH_ALEN);
  3899. /* Initialize the mac address list header */
  3900. INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
  3901. vdev->vpaths[j].mac_addr_cnt = 0;
  3902. vdev->vpaths[j].mcast_addr_cnt = 0;
  3903. j++;
  3904. }
  3905. vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
  3906. vdev->max_config_port = max_config_port;
  3907. vdev->vlan_tag_strip = vlan_tag_strip;
  3908. /* map the hashing selector table to the configured vpaths */
  3909. for (i = 0; i < vdev->no_of_vpath; i++)
  3910. vdev->vpath_selector[i] = vpath_selector[i];
  3911. macaddr = (u8 *)vdev->vpaths[0].macaddr;
  3912. ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3913. ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
  3914. ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3915. vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
  3916. vdev->ndev->name, ll_config->device_hw_info.serial_number);
  3917. vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
  3918. vdev->ndev->name, ll_config->device_hw_info.part_number);
  3919. vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
  3920. vdev->ndev->name, ll_config->device_hw_info.product_desc);
  3921. vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
  3922. vdev->ndev->name, macaddr);
  3923. vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
  3924. vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
  3925. vxge_debug_init(VXGE_TRACE,
  3926. "%s: Firmware version : %s Date : %s", vdev->ndev->name,
  3927. ll_config->device_hw_info.fw_version.version,
  3928. ll_config->device_hw_info.fw_date.date);
  3929. if (new_device) {
  3930. switch (ll_config->device_hw_info.function_mode) {
  3931. case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
  3932. vxge_debug_init(VXGE_TRACE,
  3933. "%s: Single Function Mode Enabled", vdev->ndev->name);
  3934. break;
  3935. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
  3936. vxge_debug_init(VXGE_TRACE,
  3937. "%s: Multi Function Mode Enabled", vdev->ndev->name);
  3938. break;
  3939. case VXGE_HW_FUNCTION_MODE_SRIOV:
  3940. vxge_debug_init(VXGE_TRACE,
  3941. "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
  3942. break;
  3943. case VXGE_HW_FUNCTION_MODE_MRIOV:
  3944. vxge_debug_init(VXGE_TRACE,
  3945. "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
  3946. break;
  3947. }
  3948. }
  3949. vxge_print_parm(vdev, vpath_mask);
  3950. /* Store the fw version for ethttool option */
  3951. strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
  3952. memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
  3953. memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
  3954. /* Copy the station mac address to the list */
  3955. for (i = 0; i < vdev->no_of_vpath; i++) {
  3956. entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
  3957. if (NULL == entry) {
  3958. vxge_debug_init(VXGE_ERR,
  3959. "%s: mac_addr_list : memory allocation failed",
  3960. vdev->ndev->name);
  3961. ret = -EPERM;
  3962. goto _exit6;
  3963. }
  3964. macaddr = (u8 *)&entry->macaddr;
  3965. memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
  3966. list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
  3967. vdev->vpaths[i].mac_addr_cnt = 1;
  3968. }
  3969. kfree(device_config);
  3970. /*
  3971. * INTA is shared in multi-function mode. This is unlike the INTA
  3972. * implementation in MR mode, where each VH has its own INTA message.
  3973. * - INTA is masked (disabled) as long as at least one function sets
  3974. * its TITAN_MASK_ALL_INT.ALARM bit.
  3975. * - INTA is unmasked (enabled) when all enabled functions have cleared
  3976. * their own TITAN_MASK_ALL_INT.ALARM bit.
  3977. * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
  3978. * Though this driver leaves the top level interrupts unmasked while
  3979. * leaving the required module interrupt bits masked on exit, there
  3980. * could be a rougue driver around that does not follow this procedure
  3981. * resulting in a failure to generate interrupts. The following code is
  3982. * present to prevent such a failure.
  3983. */
  3984. if (ll_config->device_hw_info.function_mode ==
  3985. VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
  3986. if (vdev->config.intr_type == INTA)
  3987. vxge_hw_device_unmask_all(hldev);
  3988. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  3989. vdev->ndev->name, __func__, __LINE__);
  3990. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  3991. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  3992. vxge_hw_device_trace_level_get(hldev));
  3993. kfree(ll_config);
  3994. return 0;
  3995. _exit6:
  3996. for (i = 0; i < vdev->no_of_vpath; i++)
  3997. vxge_free_mac_add_list(&vdev->vpaths[i]);
  3998. _exit5:
  3999. vxge_device_unregister(hldev);
  4000. _exit4:
  4001. pci_set_drvdata(pdev, NULL);
  4002. vxge_hw_device_terminate(hldev);
  4003. pci_disable_sriov(pdev);
  4004. _exit3:
  4005. iounmap(attr.bar0);
  4006. _exit2:
  4007. pci_release_region(pdev, 0);
  4008. _exit1:
  4009. pci_disable_device(pdev);
  4010. _exit0:
  4011. kfree(ll_config);
  4012. kfree(device_config);
  4013. driver_config->config_dev_cnt--;
  4014. driver_config->total_dev_cnt--;
  4015. return ret;
  4016. }
  4017. /**
  4018. * vxge_rem_nic - Free the PCI device
  4019. * @pdev: structure containing the PCI related information of the device.
  4020. * Description: This function is called by the Pci subsystem to release a
  4021. * PCI device and free up all resource held up by the device.
  4022. */
  4023. static void __devexit vxge_remove(struct pci_dev *pdev)
  4024. {
  4025. struct __vxge_hw_device *hldev;
  4026. struct vxgedev *vdev;
  4027. int i;
  4028. hldev = pci_get_drvdata(pdev);
  4029. if (hldev == NULL)
  4030. return;
  4031. vdev = netdev_priv(hldev->ndev);
  4032. vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
  4033. vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
  4034. __func__);
  4035. for (i = 0; i < vdev->no_of_vpath; i++)
  4036. vxge_free_mac_add_list(&vdev->vpaths[i]);
  4037. vxge_device_unregister(hldev);
  4038. pci_set_drvdata(pdev, NULL);
  4039. /* Do not call pci_disable_sriov here, as it will break child devices */
  4040. vxge_hw_device_terminate(hldev);
  4041. iounmap(vdev->bar0);
  4042. pci_release_region(pdev, 0);
  4043. pci_disable_device(pdev);
  4044. driver_config->config_dev_cnt--;
  4045. driver_config->total_dev_cnt--;
  4046. vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
  4047. __func__, __LINE__);
  4048. vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
  4049. __LINE__);
  4050. }
  4051. static struct pci_error_handlers vxge_err_handler = {
  4052. .error_detected = vxge_io_error_detected,
  4053. .slot_reset = vxge_io_slot_reset,
  4054. .resume = vxge_io_resume,
  4055. };
  4056. static struct pci_driver vxge_driver = {
  4057. .name = VXGE_DRIVER_NAME,
  4058. .id_table = vxge_id_table,
  4059. .probe = vxge_probe,
  4060. .remove = __devexit_p(vxge_remove),
  4061. #ifdef CONFIG_PM
  4062. .suspend = vxge_pm_suspend,
  4063. .resume = vxge_pm_resume,
  4064. #endif
  4065. .err_handler = &vxge_err_handler,
  4066. };
  4067. static int __init
  4068. vxge_starter(void)
  4069. {
  4070. int ret = 0;
  4071. pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
  4072. pr_info("Driver version: %s\n", DRV_VERSION);
  4073. verify_bandwidth();
  4074. driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
  4075. if (!driver_config)
  4076. return -ENOMEM;
  4077. ret = pci_register_driver(&vxge_driver);
  4078. if (ret) {
  4079. kfree(driver_config);
  4080. goto err;
  4081. }
  4082. if (driver_config->config_dev_cnt &&
  4083. (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
  4084. vxge_debug_init(VXGE_ERR,
  4085. "%s: Configured %d of %d devices",
  4086. VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
  4087. driver_config->total_dev_cnt);
  4088. err:
  4089. return ret;
  4090. }
  4091. static void __exit
  4092. vxge_closer(void)
  4093. {
  4094. pci_unregister_driver(&vxge_driver);
  4095. kfree(driver_config);
  4096. }
  4097. module_init(vxge_starter);
  4098. module_exit(vxge_closer);