vxge-main.c 119 KB

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