vxge-main.c 128 KB

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