vxge-main.c 126 KB

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