vxge-main.c 119 KB

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