vxge-main.c 120 KB

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