vxge-main.c 118 KB

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