vxge-main.c 125 KB

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