vxge-main.c 129 KB

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