vxge-main.c 129 KB

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