vxge-main.c 119 KB

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