vxge-main.c 129 KB

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