vxge-main.c 128 KB

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