vxge-main.c 117 KB

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