vxge-main.c 128 KB

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