s2io.c 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949
  1. /************************************************************************
  2. * s2io.c: A Linux PCI-X Ethernet driver for S2IO 10GbE Server NIC
  3. * Copyright(c) 2002-2005 Neterion Inc.
  4. * This software may be used and distributed according to the terms of
  5. * the GNU General Public License (GPL), incorporated herein by reference.
  6. * Drivers based on or derived from this code fall under the GPL and must
  7. * retain the authorship, copyright and license notice. This file is not
  8. * a complete program and may only be used when the entire operating
  9. * system is licensed under the GPL.
  10. * See the file COPYING in this distribution for more information.
  11. *
  12. * Credits:
  13. * Jeff Garzik : For pointing out the improper error condition
  14. * check in the s2io_xmit routine and also some
  15. * issues in the Tx watch dog function. Also for
  16. * patiently answering all those innumerable
  17. * questions regaring the 2.6 porting issues.
  18. * Stephen Hemminger : Providing proper 2.6 porting mechanism for some
  19. * macros available only in 2.6 Kernel.
  20. * Francois Romieu : For pointing out all code part that were
  21. * deprecated and also styling related comments.
  22. * Grant Grundler : For helping me get rid of some Architecture
  23. * dependent code.
  24. * Christopher Hellwig : Some more 2.6 specific issues in the driver.
  25. *
  26. * The module loadable parameters that are supported by the driver and a brief
  27. * explaination of all the variables.
  28. * rx_ring_num : This can be used to program the number of receive rings used
  29. * in the driver.
  30. * rx_ring_len: This defines the number of descriptors each ring can have. This
  31. * is also an array of size 8.
  32. * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
  33. * tx_fifo_len: This too is an array of 8. Each element defines the number of
  34. * Tx descriptors that can be associated with each corresponding FIFO.
  35. * in PCI Configuration space.
  36. ************************************************************************/
  37. #include <linux/config.h>
  38. #include <linux/module.h>
  39. #include <linux/types.h>
  40. #include <linux/errno.h>
  41. #include <linux/ioport.h>
  42. #include <linux/pci.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/kernel.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/etherdevice.h>
  47. #include <linux/skbuff.h>
  48. #include <linux/init.h>
  49. #include <linux/delay.h>
  50. #include <linux/stddef.h>
  51. #include <linux/ioctl.h>
  52. #include <linux/timex.h>
  53. #include <linux/sched.h>
  54. #include <linux/ethtool.h>
  55. #include <linux/version.h>
  56. #include <linux/workqueue.h>
  57. #include <asm/io.h>
  58. #include <asm/system.h>
  59. #include <asm/uaccess.h>
  60. /* local include */
  61. #include "s2io.h"
  62. #include "s2io-regs.h"
  63. /* S2io Driver name & version. */
  64. static char s2io_driver_name[] = "s2io";
  65. static char s2io_driver_version[] = "Version 1.7.7.1";
  66. /*
  67. * Cards with following subsystem_id have a link state indication
  68. * problem, 600B, 600C, 600D, 640B, 640C and 640D.
  69. * macro below identifies these cards given the subsystem_id.
  70. */
  71. #define CARDS_WITH_FAULTY_LINK_INDICATORS(subid) \
  72. (((subid >= 0x600B) && (subid <= 0x600D)) || \
  73. ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0
  74. #define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
  75. ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
  76. #define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
  77. #define PANIC 1
  78. #define LOW 2
  79. static inline int rx_buffer_level(nic_t * sp, int rxb_size, int ring)
  80. {
  81. int level = 0;
  82. if ((sp->pkt_cnt[ring] - rxb_size) > 16) {
  83. level = LOW;
  84. if ((sp->pkt_cnt[ring] - rxb_size) < MAX_RXDS_PER_BLOCK) {
  85. level = PANIC;
  86. }
  87. }
  88. return level;
  89. }
  90. /* Ethtool related variables and Macros. */
  91. static char s2io_gstrings[][ETH_GSTRING_LEN] = {
  92. "Register test\t(offline)",
  93. "Eeprom test\t(offline)",
  94. "Link test\t(online)",
  95. "RLDRAM test\t(offline)",
  96. "BIST Test\t(offline)"
  97. };
  98. static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
  99. {"tmac_frms"},
  100. {"tmac_data_octets"},
  101. {"tmac_drop_frms"},
  102. {"tmac_mcst_frms"},
  103. {"tmac_bcst_frms"},
  104. {"tmac_pause_ctrl_frms"},
  105. {"tmac_any_err_frms"},
  106. {"tmac_vld_ip_octets"},
  107. {"tmac_vld_ip"},
  108. {"tmac_drop_ip"},
  109. {"tmac_icmp"},
  110. {"tmac_rst_tcp"},
  111. {"tmac_tcp"},
  112. {"tmac_udp"},
  113. {"rmac_vld_frms"},
  114. {"rmac_data_octets"},
  115. {"rmac_fcs_err_frms"},
  116. {"rmac_drop_frms"},
  117. {"rmac_vld_mcst_frms"},
  118. {"rmac_vld_bcst_frms"},
  119. {"rmac_in_rng_len_err_frms"},
  120. {"rmac_long_frms"},
  121. {"rmac_pause_ctrl_frms"},
  122. {"rmac_discarded_frms"},
  123. {"rmac_usized_frms"},
  124. {"rmac_osized_frms"},
  125. {"rmac_frag_frms"},
  126. {"rmac_jabber_frms"},
  127. {"rmac_ip"},
  128. {"rmac_ip_octets"},
  129. {"rmac_hdr_err_ip"},
  130. {"rmac_drop_ip"},
  131. {"rmac_icmp"},
  132. {"rmac_tcp"},
  133. {"rmac_udp"},
  134. {"rmac_err_drp_udp"},
  135. {"rmac_pause_cnt"},
  136. {"rmac_accepted_ip"},
  137. {"rmac_err_tcp"},
  138. };
  139. #define S2IO_STAT_LEN sizeof(ethtool_stats_keys)/ ETH_GSTRING_LEN
  140. #define S2IO_STAT_STRINGS_LEN S2IO_STAT_LEN * ETH_GSTRING_LEN
  141. #define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
  142. #define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
  143. /*
  144. * Constants to be programmed into the Xena's registers, to configure
  145. * the XAUI.
  146. */
  147. #define SWITCH_SIGN 0xA5A5A5A5A5A5A5A5ULL
  148. #define END_SIGN 0x0
  149. static u64 default_mdio_cfg[] = {
  150. /* Reset PMA PLL */
  151. 0xC001010000000000ULL, 0xC0010100000000E0ULL,
  152. 0xC0010100008000E4ULL,
  153. /* Remove Reset from PMA PLL */
  154. 0xC001010000000000ULL, 0xC0010100000000E0ULL,
  155. 0xC0010100000000E4ULL,
  156. END_SIGN
  157. };
  158. static u64 default_dtx_cfg[] = {
  159. 0x8000051500000000ULL, 0x80000515000000E0ULL,
  160. 0x80000515D93500E4ULL, 0x8001051500000000ULL,
  161. 0x80010515000000E0ULL, 0x80010515001E00E4ULL,
  162. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  163. 0x80020515F21000E4ULL,
  164. /* Set PADLOOPBACKN */
  165. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  166. 0x80020515B20000E4ULL, 0x8003051500000000ULL,
  167. 0x80030515000000E0ULL, 0x80030515B20000E4ULL,
  168. 0x8004051500000000ULL, 0x80040515000000E0ULL,
  169. 0x80040515B20000E4ULL, 0x8005051500000000ULL,
  170. 0x80050515000000E0ULL, 0x80050515B20000E4ULL,
  171. SWITCH_SIGN,
  172. /* Remove PADLOOPBACKN */
  173. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  174. 0x80020515F20000E4ULL, 0x8003051500000000ULL,
  175. 0x80030515000000E0ULL, 0x80030515F20000E4ULL,
  176. 0x8004051500000000ULL, 0x80040515000000E0ULL,
  177. 0x80040515F20000E4ULL, 0x8005051500000000ULL,
  178. 0x80050515000000E0ULL, 0x80050515F20000E4ULL,
  179. END_SIGN
  180. };
  181. /*
  182. * Constants for Fixing the MacAddress problem seen mostly on
  183. * Alpha machines.
  184. */
  185. static u64 fix_mac[] = {
  186. 0x0060000000000000ULL, 0x0060600000000000ULL,
  187. 0x0040600000000000ULL, 0x0000600000000000ULL,
  188. 0x0020600000000000ULL, 0x0060600000000000ULL,
  189. 0x0020600000000000ULL, 0x0060600000000000ULL,
  190. 0x0020600000000000ULL, 0x0060600000000000ULL,
  191. 0x0020600000000000ULL, 0x0060600000000000ULL,
  192. 0x0020600000000000ULL, 0x0060600000000000ULL,
  193. 0x0020600000000000ULL, 0x0060600000000000ULL,
  194. 0x0020600000000000ULL, 0x0060600000000000ULL,
  195. 0x0020600000000000ULL, 0x0060600000000000ULL,
  196. 0x0020600000000000ULL, 0x0060600000000000ULL,
  197. 0x0020600000000000ULL, 0x0060600000000000ULL,
  198. 0x0020600000000000ULL, 0x0000600000000000ULL,
  199. 0x0040600000000000ULL, 0x0060600000000000ULL,
  200. END_SIGN
  201. };
  202. /* Module Loadable parameters. */
  203. static unsigned int tx_fifo_num = 1;
  204. static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
  205. {[0 ...(MAX_TX_FIFOS - 1)] = 0 };
  206. static unsigned int rx_ring_num = 1;
  207. static unsigned int rx_ring_sz[MAX_RX_RINGS] =
  208. {[0 ...(MAX_RX_RINGS - 1)] = 0 };
  209. static unsigned int Stats_refresh_time = 4;
  210. static unsigned int rmac_pause_time = 65535;
  211. static unsigned int mc_pause_threshold_q0q3 = 187;
  212. static unsigned int mc_pause_threshold_q4q7 = 187;
  213. static unsigned int shared_splits;
  214. static unsigned int tmac_util_period = 5;
  215. static unsigned int rmac_util_period = 5;
  216. #ifndef CONFIG_S2IO_NAPI
  217. static unsigned int indicate_max_pkts;
  218. #endif
  219. /*
  220. * S2IO device table.
  221. * This table lists all the devices that this driver supports.
  222. */
  223. static struct pci_device_id s2io_tbl[] __devinitdata = {
  224. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
  225. PCI_ANY_ID, PCI_ANY_ID},
  226. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
  227. PCI_ANY_ID, PCI_ANY_ID},
  228. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
  229. PCI_ANY_ID, PCI_ANY_ID},
  230. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
  231. PCI_ANY_ID, PCI_ANY_ID},
  232. {0,}
  233. };
  234. MODULE_DEVICE_TABLE(pci, s2io_tbl);
  235. static struct pci_driver s2io_driver = {
  236. .name = "S2IO",
  237. .id_table = s2io_tbl,
  238. .probe = s2io_init_nic,
  239. .remove = __devexit_p(s2io_rem_nic),
  240. };
  241. /* A simplifier macro used both by init and free shared_mem Fns(). */
  242. #define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
  243. /**
  244. * init_shared_mem - Allocation and Initialization of Memory
  245. * @nic: Device private variable.
  246. * Description: The function allocates all the memory areas shared
  247. * between the NIC and the driver. This includes Tx descriptors,
  248. * Rx descriptors and the statistics block.
  249. */
  250. static int init_shared_mem(struct s2io_nic *nic)
  251. {
  252. u32 size;
  253. void *tmp_v_addr, *tmp_v_addr_next;
  254. dma_addr_t tmp_p_addr, tmp_p_addr_next;
  255. RxD_block_t *pre_rxd_blk = NULL;
  256. int i, j, blk_cnt;
  257. int lst_size, lst_per_page;
  258. struct net_device *dev = nic->dev;
  259. #ifdef CONFIG_2BUFF_MODE
  260. unsigned long tmp;
  261. buffAdd_t *ba;
  262. #endif
  263. mac_info_t *mac_control;
  264. struct config_param *config;
  265. mac_control = &nic->mac_control;
  266. config = &nic->config;
  267. /* Allocation and initialization of TXDLs in FIOFs */
  268. size = 0;
  269. for (i = 0; i < config->tx_fifo_num; i++) {
  270. size += config->tx_cfg[i].fifo_len;
  271. }
  272. if (size > MAX_AVAILABLE_TXDS) {
  273. DBG_PRINT(ERR_DBG, "%s: Total number of Tx FIFOs ",
  274. dev->name);
  275. DBG_PRINT(ERR_DBG, "exceeds the maximum value ");
  276. DBG_PRINT(ERR_DBG, "that can be used\n");
  277. return FAILURE;
  278. }
  279. lst_size = (sizeof(TxD_t) * config->max_txds);
  280. lst_per_page = PAGE_SIZE / lst_size;
  281. for (i = 0; i < config->tx_fifo_num; i++) {
  282. int fifo_len = config->tx_cfg[i].fifo_len;
  283. int list_holder_size = fifo_len * sizeof(list_info_hold_t);
  284. nic->list_info[i] = kmalloc(list_holder_size, GFP_KERNEL);
  285. if (!nic->list_info[i]) {
  286. DBG_PRINT(ERR_DBG,
  287. "Malloc failed for list_info\n");
  288. return -ENOMEM;
  289. }
  290. memset(nic->list_info[i], 0, list_holder_size);
  291. }
  292. for (i = 0; i < config->tx_fifo_num; i++) {
  293. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  294. lst_per_page);
  295. mac_control->tx_curr_put_info[i].offset = 0;
  296. mac_control->tx_curr_put_info[i].fifo_len =
  297. config->tx_cfg[i].fifo_len - 1;
  298. mac_control->tx_curr_get_info[i].offset = 0;
  299. mac_control->tx_curr_get_info[i].fifo_len =
  300. config->tx_cfg[i].fifo_len - 1;
  301. for (j = 0; j < page_num; j++) {
  302. int k = 0;
  303. dma_addr_t tmp_p;
  304. void *tmp_v;
  305. tmp_v = pci_alloc_consistent(nic->pdev,
  306. PAGE_SIZE, &tmp_p);
  307. if (!tmp_v) {
  308. DBG_PRINT(ERR_DBG,
  309. "pci_alloc_consistent ");
  310. DBG_PRINT(ERR_DBG, "failed for TxDL\n");
  311. return -ENOMEM;
  312. }
  313. while (k < lst_per_page) {
  314. int l = (j * lst_per_page) + k;
  315. if (l == config->tx_cfg[i].fifo_len)
  316. goto end_txd_alloc;
  317. nic->list_info[i][l].list_virt_addr =
  318. tmp_v + (k * lst_size);
  319. nic->list_info[i][l].list_phy_addr =
  320. tmp_p + (k * lst_size);
  321. k++;
  322. }
  323. }
  324. }
  325. end_txd_alloc:
  326. /* Allocation and initialization of RXDs in Rings */
  327. size = 0;
  328. for (i = 0; i < config->rx_ring_num; i++) {
  329. if (config->rx_cfg[i].num_rxd % (MAX_RXDS_PER_BLOCK + 1)) {
  330. DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
  331. DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
  332. i);
  333. DBG_PRINT(ERR_DBG, "RxDs per Block");
  334. return FAILURE;
  335. }
  336. size += config->rx_cfg[i].num_rxd;
  337. nic->block_count[i] =
  338. config->rx_cfg[i].num_rxd / (MAX_RXDS_PER_BLOCK + 1);
  339. nic->pkt_cnt[i] =
  340. config->rx_cfg[i].num_rxd - nic->block_count[i];
  341. }
  342. for (i = 0; i < config->rx_ring_num; i++) {
  343. mac_control->rx_curr_get_info[i].block_index = 0;
  344. mac_control->rx_curr_get_info[i].offset = 0;
  345. mac_control->rx_curr_get_info[i].ring_len =
  346. config->rx_cfg[i].num_rxd - 1;
  347. mac_control->rx_curr_put_info[i].block_index = 0;
  348. mac_control->rx_curr_put_info[i].offset = 0;
  349. mac_control->rx_curr_put_info[i].ring_len =
  350. config->rx_cfg[i].num_rxd - 1;
  351. blk_cnt =
  352. config->rx_cfg[i].num_rxd / (MAX_RXDS_PER_BLOCK + 1);
  353. /* Allocating all the Rx blocks */
  354. for (j = 0; j < blk_cnt; j++) {
  355. #ifndef CONFIG_2BUFF_MODE
  356. size = (MAX_RXDS_PER_BLOCK + 1) * (sizeof(RxD_t));
  357. #else
  358. size = SIZE_OF_BLOCK;
  359. #endif
  360. tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
  361. &tmp_p_addr);
  362. if (tmp_v_addr == NULL) {
  363. /*
  364. * In case of failure, free_shared_mem()
  365. * is called, which should free any
  366. * memory that was alloced till the
  367. * failure happened.
  368. */
  369. nic->rx_blocks[i][j].block_virt_addr =
  370. tmp_v_addr;
  371. return -ENOMEM;
  372. }
  373. memset(tmp_v_addr, 0, size);
  374. nic->rx_blocks[i][j].block_virt_addr = tmp_v_addr;
  375. nic->rx_blocks[i][j].block_dma_addr = tmp_p_addr;
  376. }
  377. /* Interlinking all Rx Blocks */
  378. for (j = 0; j < blk_cnt; j++) {
  379. tmp_v_addr = nic->rx_blocks[i][j].block_virt_addr;
  380. tmp_v_addr_next =
  381. nic->rx_blocks[i][(j + 1) %
  382. blk_cnt].block_virt_addr;
  383. tmp_p_addr = nic->rx_blocks[i][j].block_dma_addr;
  384. tmp_p_addr_next =
  385. nic->rx_blocks[i][(j + 1) %
  386. blk_cnt].block_dma_addr;
  387. pre_rxd_blk = (RxD_block_t *) tmp_v_addr;
  388. pre_rxd_blk->reserved_1 = END_OF_BLOCK; /* last RxD
  389. * marker.
  390. */
  391. #ifndef CONFIG_2BUFF_MODE
  392. pre_rxd_blk->reserved_2_pNext_RxD_block =
  393. (unsigned long) tmp_v_addr_next;
  394. #endif
  395. pre_rxd_blk->pNext_RxD_Blk_physical =
  396. (u64) tmp_p_addr_next;
  397. }
  398. }
  399. #ifdef CONFIG_2BUFF_MODE
  400. /*
  401. * Allocation of Storages for buffer addresses in 2BUFF mode
  402. * and the buffers as well.
  403. */
  404. for (i = 0; i < config->rx_ring_num; i++) {
  405. blk_cnt =
  406. config->rx_cfg[i].num_rxd / (MAX_RXDS_PER_BLOCK + 1);
  407. nic->ba[i] = kmalloc((sizeof(buffAdd_t *) * blk_cnt),
  408. GFP_KERNEL);
  409. if (!nic->ba[i])
  410. return -ENOMEM;
  411. for (j = 0; j < blk_cnt; j++) {
  412. int k = 0;
  413. nic->ba[i][j] = kmalloc((sizeof(buffAdd_t) *
  414. (MAX_RXDS_PER_BLOCK + 1)),
  415. GFP_KERNEL);
  416. if (!nic->ba[i][j])
  417. return -ENOMEM;
  418. while (k != MAX_RXDS_PER_BLOCK) {
  419. ba = &nic->ba[i][j][k];
  420. ba->ba_0_org = kmalloc
  421. (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
  422. if (!ba->ba_0_org)
  423. return -ENOMEM;
  424. tmp = (unsigned long) ba->ba_0_org;
  425. tmp += ALIGN_SIZE;
  426. tmp &= ~((unsigned long) ALIGN_SIZE);
  427. ba->ba_0 = (void *) tmp;
  428. ba->ba_1_org = kmalloc
  429. (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
  430. if (!ba->ba_1_org)
  431. return -ENOMEM;
  432. tmp = (unsigned long) ba->ba_1_org;
  433. tmp += ALIGN_SIZE;
  434. tmp &= ~((unsigned long) ALIGN_SIZE);
  435. ba->ba_1 = (void *) tmp;
  436. k++;
  437. }
  438. }
  439. }
  440. #endif
  441. /* Allocation and initialization of Statistics block */
  442. size = sizeof(StatInfo_t);
  443. mac_control->stats_mem = pci_alloc_consistent
  444. (nic->pdev, size, &mac_control->stats_mem_phy);
  445. if (!mac_control->stats_mem) {
  446. /*
  447. * In case of failure, free_shared_mem() is called, which
  448. * should free any memory that was alloced till the
  449. * failure happened.
  450. */
  451. return -ENOMEM;
  452. }
  453. mac_control->stats_mem_sz = size;
  454. tmp_v_addr = mac_control->stats_mem;
  455. mac_control->stats_info = (StatInfo_t *) tmp_v_addr;
  456. memset(tmp_v_addr, 0, size);
  457. DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
  458. (unsigned long long) tmp_p_addr);
  459. return SUCCESS;
  460. }
  461. /**
  462. * free_shared_mem - Free the allocated Memory
  463. * @nic: Device private variable.
  464. * Description: This function is to free all memory locations allocated by
  465. * the init_shared_mem() function and return it to the kernel.
  466. */
  467. static void free_shared_mem(struct s2io_nic *nic)
  468. {
  469. int i, j, blk_cnt, size;
  470. void *tmp_v_addr;
  471. dma_addr_t tmp_p_addr;
  472. mac_info_t *mac_control;
  473. struct config_param *config;
  474. int lst_size, lst_per_page;
  475. if (!nic)
  476. return;
  477. mac_control = &nic->mac_control;
  478. config = &nic->config;
  479. lst_size = (sizeof(TxD_t) * config->max_txds);
  480. lst_per_page = PAGE_SIZE / lst_size;
  481. for (i = 0; i < config->tx_fifo_num; i++) {
  482. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  483. lst_per_page);
  484. for (j = 0; j < page_num; j++) {
  485. int mem_blks = (j * lst_per_page);
  486. if (!nic->list_info[i][mem_blks].list_virt_addr)
  487. break;
  488. pci_free_consistent(nic->pdev, PAGE_SIZE,
  489. nic->list_info[i][mem_blks].
  490. list_virt_addr,
  491. nic->list_info[i][mem_blks].
  492. list_phy_addr);
  493. }
  494. kfree(nic->list_info[i]);
  495. }
  496. #ifndef CONFIG_2BUFF_MODE
  497. size = (MAX_RXDS_PER_BLOCK + 1) * (sizeof(RxD_t));
  498. #else
  499. size = SIZE_OF_BLOCK;
  500. #endif
  501. for (i = 0; i < config->rx_ring_num; i++) {
  502. blk_cnt = nic->block_count[i];
  503. for (j = 0; j < blk_cnt; j++) {
  504. tmp_v_addr = nic->rx_blocks[i][j].block_virt_addr;
  505. tmp_p_addr = nic->rx_blocks[i][j].block_dma_addr;
  506. if (tmp_v_addr == NULL)
  507. break;
  508. pci_free_consistent(nic->pdev, size,
  509. tmp_v_addr, tmp_p_addr);
  510. }
  511. }
  512. #ifdef CONFIG_2BUFF_MODE
  513. /* Freeing buffer storage addresses in 2BUFF mode. */
  514. for (i = 0; i < config->rx_ring_num; i++) {
  515. blk_cnt =
  516. config->rx_cfg[i].num_rxd / (MAX_RXDS_PER_BLOCK + 1);
  517. if (!nic->ba[i])
  518. goto end_free;
  519. for (j = 0; j < blk_cnt; j++) {
  520. int k = 0;
  521. if (!nic->ba[i][j]) {
  522. kfree(nic->ba[i]);
  523. goto end_free;
  524. }
  525. while (k != MAX_RXDS_PER_BLOCK) {
  526. buffAdd_t *ba = &nic->ba[i][j][k];
  527. if (!ba || !ba->ba_0_org || !ba->ba_1_org)
  528. {
  529. kfree(nic->ba[i]);
  530. kfree(nic->ba[i][j]);
  531. if(ba->ba_0_org)
  532. kfree(ba->ba_0_org);
  533. if(ba->ba_1_org)
  534. kfree(ba->ba_1_org);
  535. goto end_free;
  536. }
  537. kfree(ba->ba_0_org);
  538. kfree(ba->ba_1_org);
  539. k++;
  540. }
  541. kfree(nic->ba[i][j]);
  542. }
  543. kfree(nic->ba[i]);
  544. }
  545. end_free:
  546. #endif
  547. if (mac_control->stats_mem) {
  548. pci_free_consistent(nic->pdev,
  549. mac_control->stats_mem_sz,
  550. mac_control->stats_mem,
  551. mac_control->stats_mem_phy);
  552. }
  553. }
  554. /**
  555. * init_nic - Initialization of hardware
  556. * @nic: device peivate variable
  557. * Description: The function sequentially configures every block
  558. * of the H/W from their reset values.
  559. * Return Value: SUCCESS on success and
  560. * '-1' on failure (endian settings incorrect).
  561. */
  562. static int init_nic(struct s2io_nic *nic)
  563. {
  564. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  565. struct net_device *dev = nic->dev;
  566. register u64 val64 = 0;
  567. void __iomem *add;
  568. u32 time;
  569. int i, j;
  570. mac_info_t *mac_control;
  571. struct config_param *config;
  572. int mdio_cnt = 0, dtx_cnt = 0;
  573. unsigned long long mem_share;
  574. mac_control = &nic->mac_control;
  575. config = &nic->config;
  576. /* Initialize swapper control register */
  577. if (s2io_set_swapper(nic)) {
  578. DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
  579. return -1;
  580. }
  581. /* Remove XGXS from reset state */
  582. val64 = 0;
  583. writeq(val64, &bar0->sw_reset);
  584. val64 = readq(&bar0->sw_reset);
  585. msleep(500);
  586. /* Enable Receiving broadcasts */
  587. add = &bar0->mac_cfg;
  588. val64 = readq(&bar0->mac_cfg);
  589. val64 |= MAC_RMAC_BCAST_ENABLE;
  590. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  591. writel((u32) val64, add);
  592. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  593. writel((u32) (val64 >> 32), (add + 4));
  594. /* Read registers in all blocks */
  595. val64 = readq(&bar0->mac_int_mask);
  596. val64 = readq(&bar0->mc_int_mask);
  597. val64 = readq(&bar0->xgxs_int_mask);
  598. /* Set MTU */
  599. val64 = dev->mtu;
  600. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  601. /*
  602. * Configuring the XAUI Interface of Xena.
  603. * ***************************************
  604. * To Configure the Xena's XAUI, one has to write a series
  605. * of 64 bit values into two registers in a particular
  606. * sequence. Hence a macro 'SWITCH_SIGN' has been defined
  607. * which will be defined in the array of configuration values
  608. * (default_dtx_cfg & default_mdio_cfg) at appropriate places
  609. * to switch writing from one regsiter to another. We continue
  610. * writing these values until we encounter the 'END_SIGN' macro.
  611. * For example, After making a series of 21 writes into
  612. * dtx_control register the 'SWITCH_SIGN' appears and hence we
  613. * start writing into mdio_control until we encounter END_SIGN.
  614. */
  615. while (1) {
  616. dtx_cfg:
  617. while (default_dtx_cfg[dtx_cnt] != END_SIGN) {
  618. if (default_dtx_cfg[dtx_cnt] == SWITCH_SIGN) {
  619. dtx_cnt++;
  620. goto mdio_cfg;
  621. }
  622. SPECIAL_REG_WRITE(default_dtx_cfg[dtx_cnt],
  623. &bar0->dtx_control, UF);
  624. val64 = readq(&bar0->dtx_control);
  625. dtx_cnt++;
  626. }
  627. mdio_cfg:
  628. while (default_mdio_cfg[mdio_cnt] != END_SIGN) {
  629. if (default_mdio_cfg[mdio_cnt] == SWITCH_SIGN) {
  630. mdio_cnt++;
  631. goto dtx_cfg;
  632. }
  633. SPECIAL_REG_WRITE(default_mdio_cfg[mdio_cnt],
  634. &bar0->mdio_control, UF);
  635. val64 = readq(&bar0->mdio_control);
  636. mdio_cnt++;
  637. }
  638. if ((default_dtx_cfg[dtx_cnt] == END_SIGN) &&
  639. (default_mdio_cfg[mdio_cnt] == END_SIGN)) {
  640. break;
  641. } else {
  642. goto dtx_cfg;
  643. }
  644. }
  645. /* Tx DMA Initialization */
  646. val64 = 0;
  647. writeq(val64, &bar0->tx_fifo_partition_0);
  648. writeq(val64, &bar0->tx_fifo_partition_1);
  649. writeq(val64, &bar0->tx_fifo_partition_2);
  650. writeq(val64, &bar0->tx_fifo_partition_3);
  651. for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
  652. val64 |=
  653. vBIT(config->tx_cfg[i].fifo_len - 1, ((i * 32) + 19),
  654. 13) | vBIT(config->tx_cfg[i].fifo_priority,
  655. ((i * 32) + 5), 3);
  656. if (i == (config->tx_fifo_num - 1)) {
  657. if (i % 2 == 0)
  658. i++;
  659. }
  660. switch (i) {
  661. case 1:
  662. writeq(val64, &bar0->tx_fifo_partition_0);
  663. val64 = 0;
  664. break;
  665. case 3:
  666. writeq(val64, &bar0->tx_fifo_partition_1);
  667. val64 = 0;
  668. break;
  669. case 5:
  670. writeq(val64, &bar0->tx_fifo_partition_2);
  671. val64 = 0;
  672. break;
  673. case 7:
  674. writeq(val64, &bar0->tx_fifo_partition_3);
  675. break;
  676. }
  677. }
  678. /* Enable Tx FIFO partition 0. */
  679. val64 = readq(&bar0->tx_fifo_partition_0);
  680. val64 |= BIT(0); /* To enable the FIFO partition. */
  681. writeq(val64, &bar0->tx_fifo_partition_0);
  682. val64 = readq(&bar0->tx_fifo_partition_0);
  683. DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
  684. &bar0->tx_fifo_partition_0, (unsigned long long) val64);
  685. /*
  686. * Initialization of Tx_PA_CONFIG register to ignore packet
  687. * integrity checking.
  688. */
  689. val64 = readq(&bar0->tx_pa_cfg);
  690. val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
  691. TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
  692. writeq(val64, &bar0->tx_pa_cfg);
  693. /* Rx DMA intialization. */
  694. val64 = 0;
  695. for (i = 0; i < config->rx_ring_num; i++) {
  696. val64 |=
  697. vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
  698. 3);
  699. }
  700. writeq(val64, &bar0->rx_queue_priority);
  701. /*
  702. * Allocating equal share of memory to all the
  703. * configured Rings.
  704. */
  705. val64 = 0;
  706. for (i = 0; i < config->rx_ring_num; i++) {
  707. switch (i) {
  708. case 0:
  709. mem_share = (64 / config->rx_ring_num +
  710. 64 % config->rx_ring_num);
  711. val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
  712. continue;
  713. case 1:
  714. mem_share = (64 / config->rx_ring_num);
  715. val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
  716. continue;
  717. case 2:
  718. mem_share = (64 / config->rx_ring_num);
  719. val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
  720. continue;
  721. case 3:
  722. mem_share = (64 / config->rx_ring_num);
  723. val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
  724. continue;
  725. case 4:
  726. mem_share = (64 / config->rx_ring_num);
  727. val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
  728. continue;
  729. case 5:
  730. mem_share = (64 / config->rx_ring_num);
  731. val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
  732. continue;
  733. case 6:
  734. mem_share = (64 / config->rx_ring_num);
  735. val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
  736. continue;
  737. case 7:
  738. mem_share = (64 / config->rx_ring_num);
  739. val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
  740. continue;
  741. }
  742. }
  743. writeq(val64, &bar0->rx_queue_cfg);
  744. /*
  745. * Initializing the Tx round robin registers to 0.
  746. * Filling Tx and Rx round robin registers as per the
  747. * number of FIFOs and Rings is still TODO.
  748. */
  749. writeq(0, &bar0->tx_w_round_robin_0);
  750. writeq(0, &bar0->tx_w_round_robin_1);
  751. writeq(0, &bar0->tx_w_round_robin_2);
  752. writeq(0, &bar0->tx_w_round_robin_3);
  753. writeq(0, &bar0->tx_w_round_robin_4);
  754. /*
  755. * TODO
  756. * Disable Rx steering. Hard coding all packets be steered to
  757. * Queue 0 for now.
  758. */
  759. val64 = 0x8080808080808080ULL;
  760. writeq(val64, &bar0->rts_qos_steering);
  761. /* UDP Fix */
  762. val64 = 0;
  763. for (i = 1; i < 8; i++)
  764. writeq(val64, &bar0->rts_frm_len_n[i]);
  765. /* Set rts_frm_len register for fifo 0 */
  766. writeq(MAC_RTS_FRM_LEN_SET(dev->mtu + 22),
  767. &bar0->rts_frm_len_n[0]);
  768. /* Enable statistics */
  769. writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
  770. val64 = SET_UPDT_PERIOD(Stats_refresh_time) |
  771. STAT_CFG_STAT_RO | STAT_CFG_STAT_EN;
  772. writeq(val64, &bar0->stat_cfg);
  773. /*
  774. * Initializing the sampling rate for the device to calculate the
  775. * bandwidth utilization.
  776. */
  777. val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
  778. MAC_RX_LINK_UTIL_VAL(rmac_util_period);
  779. writeq(val64, &bar0->mac_link_util);
  780. /*
  781. * Initializing the Transmit and Receive Traffic Interrupt
  782. * Scheme.
  783. */
  784. /* TTI Initialization. Default Tx timer gets us about
  785. * 250 interrupts per sec. Continuous interrupts are enabled
  786. * by default.
  787. */
  788. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078) |
  789. TTI_DATA1_MEM_TX_URNG_A(0xA) |
  790. TTI_DATA1_MEM_TX_URNG_B(0x10) |
  791. TTI_DATA1_MEM_TX_URNG_C(0x30) | TTI_DATA1_MEM_TX_TIMER_AC_EN |
  792. TTI_DATA1_MEM_TX_TIMER_CI_EN;
  793. writeq(val64, &bar0->tti_data1_mem);
  794. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  795. TTI_DATA2_MEM_TX_UFC_B(0x20) |
  796. TTI_DATA2_MEM_TX_UFC_C(0x40) | TTI_DATA2_MEM_TX_UFC_D(0x80);
  797. writeq(val64, &bar0->tti_data2_mem);
  798. val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
  799. writeq(val64, &bar0->tti_command_mem);
  800. /*
  801. * Once the operation completes, the Strobe bit of the command
  802. * register will be reset. We poll for this particular condition
  803. * We wait for a maximum of 500ms for the operation to complete,
  804. * if it's not complete by then we return error.
  805. */
  806. time = 0;
  807. while (TRUE) {
  808. val64 = readq(&bar0->tti_command_mem);
  809. if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
  810. break;
  811. }
  812. if (time > 10) {
  813. DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
  814. dev->name);
  815. return -1;
  816. }
  817. msleep(50);
  818. time++;
  819. }
  820. /* RTI Initialization */
  821. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF) |
  822. RTI_DATA1_MEM_RX_URNG_A(0xA) |
  823. RTI_DATA1_MEM_RX_URNG_B(0x10) |
  824. RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
  825. writeq(val64, &bar0->rti_data1_mem);
  826. val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
  827. RTI_DATA2_MEM_RX_UFC_B(0x2) |
  828. RTI_DATA2_MEM_RX_UFC_C(0x40) | RTI_DATA2_MEM_RX_UFC_D(0x80);
  829. writeq(val64, &bar0->rti_data2_mem);
  830. val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD;
  831. writeq(val64, &bar0->rti_command_mem);
  832. /*
  833. * Once the operation completes, the Strobe bit of the command
  834. * register will be reset. We poll for this particular condition
  835. * We wait for a maximum of 500ms for the operation to complete,
  836. * if it's not complete by then we return error.
  837. */
  838. time = 0;
  839. while (TRUE) {
  840. val64 = readq(&bar0->rti_command_mem);
  841. if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
  842. break;
  843. }
  844. if (time > 10) {
  845. DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
  846. dev->name);
  847. return -1;
  848. }
  849. time++;
  850. msleep(50);
  851. }
  852. /*
  853. * Initializing proper values as Pause threshold into all
  854. * the 8 Queues on Rx side.
  855. */
  856. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
  857. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
  858. /* Disable RMAC PAD STRIPPING */
  859. add = &bar0->mac_cfg;
  860. val64 = readq(&bar0->mac_cfg);
  861. val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
  862. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  863. writel((u32) (val64), add);
  864. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  865. writel((u32) (val64 >> 32), (add + 4));
  866. val64 = readq(&bar0->mac_cfg);
  867. /*
  868. * Set the time value to be inserted in the pause frame
  869. * generated by xena.
  870. */
  871. val64 = readq(&bar0->rmac_pause_cfg);
  872. val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
  873. val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
  874. writeq(val64, &bar0->rmac_pause_cfg);
  875. /*
  876. * Set the Threshold Limit for Generating the pause frame
  877. * If the amount of data in any Queue exceeds ratio of
  878. * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
  879. * pause frame is generated
  880. */
  881. val64 = 0;
  882. for (i = 0; i < 4; i++) {
  883. val64 |=
  884. (((u64) 0xFF00 | nic->mac_control.
  885. mc_pause_threshold_q0q3)
  886. << (i * 2 * 8));
  887. }
  888. writeq(val64, &bar0->mc_pause_thresh_q0q3);
  889. val64 = 0;
  890. for (i = 0; i < 4; i++) {
  891. val64 |=
  892. (((u64) 0xFF00 | nic->mac_control.
  893. mc_pause_threshold_q4q7)
  894. << (i * 2 * 8));
  895. }
  896. writeq(val64, &bar0->mc_pause_thresh_q4q7);
  897. /*
  898. * TxDMA will stop Read request if the number of read split has
  899. * exceeded the limit pointed by shared_splits
  900. */
  901. val64 = readq(&bar0->pic_control);
  902. val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
  903. writeq(val64, &bar0->pic_control);
  904. return SUCCESS;
  905. }
  906. /**
  907. * en_dis_able_nic_intrs - Enable or Disable the interrupts
  908. * @nic: device private variable,
  909. * @mask: A mask indicating which Intr block must be modified and,
  910. * @flag: A flag indicating whether to enable or disable the Intrs.
  911. * Description: This function will either disable or enable the interrupts
  912. * depending on the flag argument. The mask argument can be used to
  913. * enable/disable any Intr block.
  914. * Return Value: NONE.
  915. */
  916. static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
  917. {
  918. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  919. register u64 val64 = 0, temp64 = 0;
  920. /* Top level interrupt classification */
  921. /* PIC Interrupts */
  922. if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
  923. /* Enable PIC Intrs in the general intr mask register */
  924. val64 = TXPIC_INT_M | PIC_RX_INT_M;
  925. if (flag == ENABLE_INTRS) {
  926. temp64 = readq(&bar0->general_int_mask);
  927. temp64 &= ~((u64) val64);
  928. writeq(temp64, &bar0->general_int_mask);
  929. /*
  930. * Disabled all PCIX, Flash, MDIO, IIC and GPIO
  931. * interrupts for now.
  932. * TODO
  933. */
  934. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  935. /*
  936. * No MSI Support is available presently, so TTI and
  937. * RTI interrupts are also disabled.
  938. */
  939. } else if (flag == DISABLE_INTRS) {
  940. /*
  941. * Disable PIC Intrs in the general
  942. * intr mask register
  943. */
  944. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  945. temp64 = readq(&bar0->general_int_mask);
  946. val64 |= temp64;
  947. writeq(val64, &bar0->general_int_mask);
  948. }
  949. }
  950. /* DMA Interrupts */
  951. /* Enabling/Disabling Tx DMA interrupts */
  952. if (mask & TX_DMA_INTR) {
  953. /* Enable TxDMA Intrs in the general intr mask register */
  954. val64 = TXDMA_INT_M;
  955. if (flag == ENABLE_INTRS) {
  956. temp64 = readq(&bar0->general_int_mask);
  957. temp64 &= ~((u64) val64);
  958. writeq(temp64, &bar0->general_int_mask);
  959. /*
  960. * Keep all interrupts other than PFC interrupt
  961. * and PCC interrupt disabled in DMA level.
  962. */
  963. val64 = DISABLE_ALL_INTRS & ~(TXDMA_PFC_INT_M |
  964. TXDMA_PCC_INT_M);
  965. writeq(val64, &bar0->txdma_int_mask);
  966. /*
  967. * Enable only the MISC error 1 interrupt in PFC block
  968. */
  969. val64 = DISABLE_ALL_INTRS & (~PFC_MISC_ERR_1);
  970. writeq(val64, &bar0->pfc_err_mask);
  971. /*
  972. * Enable only the FB_ECC error interrupt in PCC block
  973. */
  974. val64 = DISABLE_ALL_INTRS & (~PCC_FB_ECC_ERR);
  975. writeq(val64, &bar0->pcc_err_mask);
  976. } else if (flag == DISABLE_INTRS) {
  977. /*
  978. * Disable TxDMA Intrs in the general intr mask
  979. * register
  980. */
  981. writeq(DISABLE_ALL_INTRS, &bar0->txdma_int_mask);
  982. writeq(DISABLE_ALL_INTRS, &bar0->pfc_err_mask);
  983. temp64 = readq(&bar0->general_int_mask);
  984. val64 |= temp64;
  985. writeq(val64, &bar0->general_int_mask);
  986. }
  987. }
  988. /* Enabling/Disabling Rx DMA interrupts */
  989. if (mask & RX_DMA_INTR) {
  990. /* Enable RxDMA Intrs in the general intr mask register */
  991. val64 = RXDMA_INT_M;
  992. if (flag == ENABLE_INTRS) {
  993. temp64 = readq(&bar0->general_int_mask);
  994. temp64 &= ~((u64) val64);
  995. writeq(temp64, &bar0->general_int_mask);
  996. /*
  997. * All RxDMA block interrupts are disabled for now
  998. * TODO
  999. */
  1000. writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
  1001. } else if (flag == DISABLE_INTRS) {
  1002. /*
  1003. * Disable RxDMA Intrs in the general intr mask
  1004. * register
  1005. */
  1006. writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
  1007. temp64 = readq(&bar0->general_int_mask);
  1008. val64 |= temp64;
  1009. writeq(val64, &bar0->general_int_mask);
  1010. }
  1011. }
  1012. /* MAC Interrupts */
  1013. /* Enabling/Disabling MAC interrupts */
  1014. if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
  1015. val64 = TXMAC_INT_M | RXMAC_INT_M;
  1016. if (flag == ENABLE_INTRS) {
  1017. temp64 = readq(&bar0->general_int_mask);
  1018. temp64 &= ~((u64) val64);
  1019. writeq(temp64, &bar0->general_int_mask);
  1020. /*
  1021. * All MAC block error interrupts are disabled for now
  1022. * except the link status change interrupt.
  1023. * TODO
  1024. */
  1025. val64 = MAC_INT_STATUS_RMAC_INT;
  1026. temp64 = readq(&bar0->mac_int_mask);
  1027. temp64 &= ~((u64) val64);
  1028. writeq(temp64, &bar0->mac_int_mask);
  1029. val64 = readq(&bar0->mac_rmac_err_mask);
  1030. val64 &= ~((u64) RMAC_LINK_STATE_CHANGE_INT);
  1031. writeq(val64, &bar0->mac_rmac_err_mask);
  1032. } else if (flag == DISABLE_INTRS) {
  1033. /*
  1034. * Disable MAC Intrs in the general intr mask register
  1035. */
  1036. writeq(DISABLE_ALL_INTRS, &bar0->mac_int_mask);
  1037. writeq(DISABLE_ALL_INTRS,
  1038. &bar0->mac_rmac_err_mask);
  1039. temp64 = readq(&bar0->general_int_mask);
  1040. val64 |= temp64;
  1041. writeq(val64, &bar0->general_int_mask);
  1042. }
  1043. }
  1044. /* XGXS Interrupts */
  1045. if (mask & (TX_XGXS_INTR | RX_XGXS_INTR)) {
  1046. val64 = TXXGXS_INT_M | RXXGXS_INT_M;
  1047. if (flag == ENABLE_INTRS) {
  1048. temp64 = readq(&bar0->general_int_mask);
  1049. temp64 &= ~((u64) val64);
  1050. writeq(temp64, &bar0->general_int_mask);
  1051. /*
  1052. * All XGXS block error interrupts are disabled for now
  1053. * TODO
  1054. */
  1055. writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
  1056. } else if (flag == DISABLE_INTRS) {
  1057. /*
  1058. * Disable MC Intrs in the general intr mask register
  1059. */
  1060. writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
  1061. temp64 = readq(&bar0->general_int_mask);
  1062. val64 |= temp64;
  1063. writeq(val64, &bar0->general_int_mask);
  1064. }
  1065. }
  1066. /* Memory Controller(MC) interrupts */
  1067. if (mask & MC_INTR) {
  1068. val64 = MC_INT_M;
  1069. if (flag == ENABLE_INTRS) {
  1070. temp64 = readq(&bar0->general_int_mask);
  1071. temp64 &= ~((u64) val64);
  1072. writeq(temp64, &bar0->general_int_mask);
  1073. /*
  1074. * All MC block error interrupts are disabled for now
  1075. * TODO
  1076. */
  1077. writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
  1078. } else if (flag == DISABLE_INTRS) {
  1079. /*
  1080. * Disable MC Intrs in the general intr mask register
  1081. */
  1082. writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
  1083. temp64 = readq(&bar0->general_int_mask);
  1084. val64 |= temp64;
  1085. writeq(val64, &bar0->general_int_mask);
  1086. }
  1087. }
  1088. /* Tx traffic interrupts */
  1089. if (mask & TX_TRAFFIC_INTR) {
  1090. val64 = TXTRAFFIC_INT_M;
  1091. if (flag == ENABLE_INTRS) {
  1092. temp64 = readq(&bar0->general_int_mask);
  1093. temp64 &= ~((u64) val64);
  1094. writeq(temp64, &bar0->general_int_mask);
  1095. /*
  1096. * Enable all the Tx side interrupts
  1097. * writing 0 Enables all 64 TX interrupt levels
  1098. */
  1099. writeq(0x0, &bar0->tx_traffic_mask);
  1100. } else if (flag == DISABLE_INTRS) {
  1101. /*
  1102. * Disable Tx Traffic Intrs in the general intr mask
  1103. * register.
  1104. */
  1105. writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
  1106. temp64 = readq(&bar0->general_int_mask);
  1107. val64 |= temp64;
  1108. writeq(val64, &bar0->general_int_mask);
  1109. }
  1110. }
  1111. /* Rx traffic interrupts */
  1112. if (mask & RX_TRAFFIC_INTR) {
  1113. val64 = RXTRAFFIC_INT_M;
  1114. if (flag == ENABLE_INTRS) {
  1115. temp64 = readq(&bar0->general_int_mask);
  1116. temp64 &= ~((u64) val64);
  1117. writeq(temp64, &bar0->general_int_mask);
  1118. /* writing 0 Enables all 8 RX interrupt levels */
  1119. writeq(0x0, &bar0->rx_traffic_mask);
  1120. } else if (flag == DISABLE_INTRS) {
  1121. /*
  1122. * Disable Rx Traffic Intrs in the general intr mask
  1123. * register.
  1124. */
  1125. writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
  1126. temp64 = readq(&bar0->general_int_mask);
  1127. val64 |= temp64;
  1128. writeq(val64, &bar0->general_int_mask);
  1129. }
  1130. }
  1131. }
  1132. /**
  1133. * verify_xena_quiescence - Checks whether the H/W is ready
  1134. * @val64 : Value read from adapter status register.
  1135. * @flag : indicates if the adapter enable bit was ever written once
  1136. * before.
  1137. * Description: Returns whether the H/W is ready to go or not. Depending
  1138. * on whether adapter enable bit was written or not the comparison
  1139. * differs and the calling function passes the input argument flag to
  1140. * indicate this.
  1141. * Return: 1 If xena is quiescence
  1142. * 0 If Xena is not quiescence
  1143. */
  1144. static int verify_xena_quiescence(u64 val64, int flag)
  1145. {
  1146. int ret = 0;
  1147. u64 tmp64 = ~((u64) val64);
  1148. if (!
  1149. (tmp64 &
  1150. (ADAPTER_STATUS_TDMA_READY | ADAPTER_STATUS_RDMA_READY |
  1151. ADAPTER_STATUS_PFC_READY | ADAPTER_STATUS_TMAC_BUF_EMPTY |
  1152. ADAPTER_STATUS_PIC_QUIESCENT | ADAPTER_STATUS_MC_DRAM_READY |
  1153. ADAPTER_STATUS_MC_QUEUES_READY | ADAPTER_STATUS_M_PLL_LOCK |
  1154. ADAPTER_STATUS_P_PLL_LOCK))) {
  1155. if (flag == FALSE) {
  1156. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) &&
  1157. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1158. ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
  1159. ret = 1;
  1160. }
  1161. } else {
  1162. if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
  1163. ADAPTER_STATUS_RMAC_PCC_IDLE) &&
  1164. (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
  1165. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1166. ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
  1167. ret = 1;
  1168. }
  1169. }
  1170. }
  1171. return ret;
  1172. }
  1173. /**
  1174. * fix_mac_address - Fix for Mac addr problem on Alpha platforms
  1175. * @sp: Pointer to device specifc structure
  1176. * Description :
  1177. * New procedure to clear mac address reading problems on Alpha platforms
  1178. *
  1179. */
  1180. static void fix_mac_address(nic_t * sp)
  1181. {
  1182. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  1183. u64 val64;
  1184. int i = 0;
  1185. while (fix_mac[i] != END_SIGN) {
  1186. writeq(fix_mac[i++], &bar0->gpio_control);
  1187. val64 = readq(&bar0->gpio_control);
  1188. }
  1189. }
  1190. /**
  1191. * start_nic - Turns the device on
  1192. * @nic : device private variable.
  1193. * Description:
  1194. * This function actually turns the device on. Before this function is
  1195. * called,all Registers are configured from their reset states
  1196. * and shared memory is allocated but the NIC is still quiescent. On
  1197. * calling this function, the device interrupts are cleared and the NIC is
  1198. * literally switched on by writing into the adapter control register.
  1199. * Return Value:
  1200. * SUCCESS on success and -1 on failure.
  1201. */
  1202. static int start_nic(struct s2io_nic *nic)
  1203. {
  1204. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1205. struct net_device *dev = nic->dev;
  1206. register u64 val64 = 0;
  1207. u16 interruptible, i;
  1208. u16 subid;
  1209. mac_info_t *mac_control;
  1210. struct config_param *config;
  1211. mac_control = &nic->mac_control;
  1212. config = &nic->config;
  1213. /* PRC Initialization and configuration */
  1214. for (i = 0; i < config->rx_ring_num; i++) {
  1215. writeq((u64) nic->rx_blocks[i][0].block_dma_addr,
  1216. &bar0->prc_rxd0_n[i]);
  1217. val64 = readq(&bar0->prc_ctrl_n[i]);
  1218. #ifndef CONFIG_2BUFF_MODE
  1219. val64 |= PRC_CTRL_RC_ENABLED;
  1220. #else
  1221. val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
  1222. #endif
  1223. writeq(val64, &bar0->prc_ctrl_n[i]);
  1224. }
  1225. #ifdef CONFIG_2BUFF_MODE
  1226. /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
  1227. val64 = readq(&bar0->rx_pa_cfg);
  1228. val64 |= RX_PA_CFG_IGNORE_L2_ERR;
  1229. writeq(val64, &bar0->rx_pa_cfg);
  1230. #endif
  1231. /*
  1232. * Enabling MC-RLDRAM. After enabling the device, we timeout
  1233. * for around 100ms, which is approximately the time required
  1234. * for the device to be ready for operation.
  1235. */
  1236. val64 = readq(&bar0->mc_rldram_mrs);
  1237. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
  1238. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  1239. val64 = readq(&bar0->mc_rldram_mrs);
  1240. msleep(100); /* Delay by around 100 ms. */
  1241. /* Enabling ECC Protection. */
  1242. val64 = readq(&bar0->adapter_control);
  1243. val64 &= ~ADAPTER_ECC_EN;
  1244. writeq(val64, &bar0->adapter_control);
  1245. /*
  1246. * Clearing any possible Link state change interrupts that
  1247. * could have popped up just before Enabling the card.
  1248. */
  1249. val64 = readq(&bar0->mac_rmac_err_reg);
  1250. if (val64)
  1251. writeq(val64, &bar0->mac_rmac_err_reg);
  1252. /*
  1253. * Verify if the device is ready to be enabled, if so enable
  1254. * it.
  1255. */
  1256. val64 = readq(&bar0->adapter_status);
  1257. if (!verify_xena_quiescence(val64, nic->device_enabled_once)) {
  1258. DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
  1259. DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
  1260. (unsigned long long) val64);
  1261. return FAILURE;
  1262. }
  1263. /* Enable select interrupts */
  1264. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR | TX_MAC_INTR |
  1265. RX_MAC_INTR;
  1266. en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
  1267. /*
  1268. * With some switches, link might be already up at this point.
  1269. * Because of this weird behavior, when we enable laser,
  1270. * we may not get link. We need to handle this. We cannot
  1271. * figure out which switch is misbehaving. So we are forced to
  1272. * make a global change.
  1273. */
  1274. /* Enabling Laser. */
  1275. val64 = readq(&bar0->adapter_control);
  1276. val64 |= ADAPTER_EOI_TX_ON;
  1277. writeq(val64, &bar0->adapter_control);
  1278. /* SXE-002: Initialize link and activity LED */
  1279. subid = nic->pdev->subsystem_device;
  1280. if ((subid & 0xFF) >= 0x07) {
  1281. val64 = readq(&bar0->gpio_control);
  1282. val64 |= 0x0000800000000000ULL;
  1283. writeq(val64, &bar0->gpio_control);
  1284. val64 = 0x0411040400000000ULL;
  1285. writeq(val64, (void __iomem *) bar0 + 0x2700);
  1286. }
  1287. /*
  1288. * Don't see link state interrupts on certain switches, so
  1289. * directly scheduling a link state task from here.
  1290. */
  1291. schedule_work(&nic->set_link_task);
  1292. /*
  1293. * Here we are performing soft reset on XGXS to
  1294. * force link down. Since link is already up, we will get
  1295. * link state change interrupt after this reset
  1296. */
  1297. SPECIAL_REG_WRITE(0x80010515001E0000ULL, &bar0->dtx_control, UF);
  1298. val64 = readq(&bar0->dtx_control);
  1299. udelay(50);
  1300. SPECIAL_REG_WRITE(0x80010515001E00E0ULL, &bar0->dtx_control, UF);
  1301. val64 = readq(&bar0->dtx_control);
  1302. udelay(50);
  1303. SPECIAL_REG_WRITE(0x80070515001F00E4ULL, &bar0->dtx_control, UF);
  1304. val64 = readq(&bar0->dtx_control);
  1305. udelay(50);
  1306. return SUCCESS;
  1307. }
  1308. /**
  1309. * free_tx_buffers - Free all queued Tx buffers
  1310. * @nic : device private variable.
  1311. * Description:
  1312. * Free all queued Tx buffers.
  1313. * Return Value: void
  1314. */
  1315. static void free_tx_buffers(struct s2io_nic *nic)
  1316. {
  1317. struct net_device *dev = nic->dev;
  1318. struct sk_buff *skb;
  1319. TxD_t *txdp;
  1320. int i, j;
  1321. mac_info_t *mac_control;
  1322. struct config_param *config;
  1323. int cnt = 0;
  1324. mac_control = &nic->mac_control;
  1325. config = &nic->config;
  1326. for (i = 0; i < config->tx_fifo_num; i++) {
  1327. for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
  1328. txdp = (TxD_t *) nic->list_info[i][j].
  1329. list_virt_addr;
  1330. skb =
  1331. (struct sk_buff *) ((unsigned long) txdp->
  1332. Host_Control);
  1333. if (skb == NULL) {
  1334. memset(txdp, 0, sizeof(TxD_t));
  1335. continue;
  1336. }
  1337. dev_kfree_skb(skb);
  1338. memset(txdp, 0, sizeof(TxD_t));
  1339. cnt++;
  1340. }
  1341. DBG_PRINT(INTR_DBG,
  1342. "%s:forcibly freeing %d skbs on FIFO%d\n",
  1343. dev->name, cnt, i);
  1344. mac_control->tx_curr_get_info[i].offset = 0;
  1345. mac_control->tx_curr_put_info[i].offset = 0;
  1346. }
  1347. }
  1348. /**
  1349. * stop_nic - To stop the nic
  1350. * @nic ; device private variable.
  1351. * Description:
  1352. * This function does exactly the opposite of what the start_nic()
  1353. * function does. This function is called to stop the device.
  1354. * Return Value:
  1355. * void.
  1356. */
  1357. static void stop_nic(struct s2io_nic *nic)
  1358. {
  1359. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1360. register u64 val64 = 0;
  1361. u16 interruptible, i;
  1362. mac_info_t *mac_control;
  1363. struct config_param *config;
  1364. mac_control = &nic->mac_control;
  1365. config = &nic->config;
  1366. /* Disable all interrupts */
  1367. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR | TX_MAC_INTR |
  1368. RX_MAC_INTR;
  1369. en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
  1370. /* Disable PRCs */
  1371. for (i = 0; i < config->rx_ring_num; i++) {
  1372. val64 = readq(&bar0->prc_ctrl_n[i]);
  1373. val64 &= ~((u64) PRC_CTRL_RC_ENABLED);
  1374. writeq(val64, &bar0->prc_ctrl_n[i]);
  1375. }
  1376. }
  1377. /**
  1378. * fill_rx_buffers - Allocates the Rx side skbs
  1379. * @nic: device private variable
  1380. * @ring_no: ring number
  1381. * Description:
  1382. * The function allocates Rx side skbs and puts the physical
  1383. * address of these buffers into the RxD buffer pointers, so that the NIC
  1384. * can DMA the received frame into these locations.
  1385. * The NIC supports 3 receive modes, viz
  1386. * 1. single buffer,
  1387. * 2. three buffer and
  1388. * 3. Five buffer modes.
  1389. * Each mode defines how many fragments the received frame will be split
  1390. * up into by the NIC. The frame is split into L3 header, L4 Header,
  1391. * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
  1392. * is split into 3 fragments. As of now only single buffer mode is
  1393. * supported.
  1394. * Return Value:
  1395. * SUCCESS on success or an appropriate -ve value on failure.
  1396. */
  1397. static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
  1398. {
  1399. struct net_device *dev = nic->dev;
  1400. struct sk_buff *skb;
  1401. RxD_t *rxdp;
  1402. int off, off1, size, block_no, block_no1;
  1403. int offset, offset1;
  1404. u32 alloc_tab = 0;
  1405. u32 alloc_cnt = nic->pkt_cnt[ring_no] -
  1406. atomic_read(&nic->rx_bufs_left[ring_no]);
  1407. mac_info_t *mac_control;
  1408. struct config_param *config;
  1409. #ifdef CONFIG_2BUFF_MODE
  1410. RxD_t *rxdpnext;
  1411. int nextblk;
  1412. unsigned long tmp;
  1413. buffAdd_t *ba;
  1414. dma_addr_t rxdpphys;
  1415. #endif
  1416. #ifndef CONFIG_S2IO_NAPI
  1417. unsigned long flags;
  1418. #endif
  1419. mac_control = &nic->mac_control;
  1420. config = &nic->config;
  1421. size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
  1422. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  1423. while (alloc_tab < alloc_cnt) {
  1424. block_no = mac_control->rx_curr_put_info[ring_no].
  1425. block_index;
  1426. block_no1 = mac_control->rx_curr_get_info[ring_no].
  1427. block_index;
  1428. off = mac_control->rx_curr_put_info[ring_no].offset;
  1429. off1 = mac_control->rx_curr_get_info[ring_no].offset;
  1430. #ifndef CONFIG_2BUFF_MODE
  1431. offset = block_no * (MAX_RXDS_PER_BLOCK + 1) + off;
  1432. offset1 = block_no1 * (MAX_RXDS_PER_BLOCK + 1) + off1;
  1433. #else
  1434. offset = block_no * (MAX_RXDS_PER_BLOCK) + off;
  1435. offset1 = block_no1 * (MAX_RXDS_PER_BLOCK) + off1;
  1436. #endif
  1437. rxdp = nic->rx_blocks[ring_no][block_no].
  1438. block_virt_addr + off;
  1439. if ((offset == offset1) && (rxdp->Host_Control)) {
  1440. DBG_PRINT(INTR_DBG, "%s: Get and Put", dev->name);
  1441. DBG_PRINT(INTR_DBG, " info equated\n");
  1442. goto end;
  1443. }
  1444. #ifndef CONFIG_2BUFF_MODE
  1445. if (rxdp->Control_1 == END_OF_BLOCK) {
  1446. mac_control->rx_curr_put_info[ring_no].
  1447. block_index++;
  1448. mac_control->rx_curr_put_info[ring_no].
  1449. block_index %= nic->block_count[ring_no];
  1450. block_no = mac_control->rx_curr_put_info
  1451. [ring_no].block_index;
  1452. off++;
  1453. off %= (MAX_RXDS_PER_BLOCK + 1);
  1454. mac_control->rx_curr_put_info[ring_no].offset =
  1455. off;
  1456. rxdp = (RxD_t *) ((unsigned long) rxdp->Control_2);
  1457. DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
  1458. dev->name, rxdp);
  1459. }
  1460. #ifndef CONFIG_S2IO_NAPI
  1461. spin_lock_irqsave(&nic->put_lock, flags);
  1462. nic->put_pos[ring_no] =
  1463. (block_no * (MAX_RXDS_PER_BLOCK + 1)) + off;
  1464. spin_unlock_irqrestore(&nic->put_lock, flags);
  1465. #endif
  1466. #else
  1467. if (rxdp->Host_Control == END_OF_BLOCK) {
  1468. mac_control->rx_curr_put_info[ring_no].
  1469. block_index++;
  1470. mac_control->rx_curr_put_info[ring_no].
  1471. block_index %= nic->block_count[ring_no];
  1472. block_no = mac_control->rx_curr_put_info
  1473. [ring_no].block_index;
  1474. off = 0;
  1475. DBG_PRINT(INTR_DBG, "%s: block%d at: 0x%llx\n",
  1476. dev->name, block_no,
  1477. (unsigned long long) rxdp->Control_1);
  1478. mac_control->rx_curr_put_info[ring_no].offset =
  1479. off;
  1480. rxdp = nic->rx_blocks[ring_no][block_no].
  1481. block_virt_addr;
  1482. }
  1483. #ifndef CONFIG_S2IO_NAPI
  1484. spin_lock_irqsave(&nic->put_lock, flags);
  1485. nic->put_pos[ring_no] = (block_no *
  1486. (MAX_RXDS_PER_BLOCK + 1)) + off;
  1487. spin_unlock_irqrestore(&nic->put_lock, flags);
  1488. #endif
  1489. #endif
  1490. #ifndef CONFIG_2BUFF_MODE
  1491. if (rxdp->Control_1 & RXD_OWN_XENA)
  1492. #else
  1493. if (rxdp->Control_2 & BIT(0))
  1494. #endif
  1495. {
  1496. mac_control->rx_curr_put_info[ring_no].
  1497. offset = off;
  1498. goto end;
  1499. }
  1500. #ifdef CONFIG_2BUFF_MODE
  1501. /*
  1502. * RxDs Spanning cache lines will be replenished only
  1503. * if the succeeding RxD is also owned by Host. It
  1504. * will always be the ((8*i)+3) and ((8*i)+6)
  1505. * descriptors for the 48 byte descriptor. The offending
  1506. * decsriptor is of-course the 3rd descriptor.
  1507. */
  1508. rxdpphys = nic->rx_blocks[ring_no][block_no].
  1509. block_dma_addr + (off * sizeof(RxD_t));
  1510. if (((u64) (rxdpphys)) % 128 > 80) {
  1511. rxdpnext = nic->rx_blocks[ring_no][block_no].
  1512. block_virt_addr + (off + 1);
  1513. if (rxdpnext->Host_Control == END_OF_BLOCK) {
  1514. nextblk = (block_no + 1) %
  1515. (nic->block_count[ring_no]);
  1516. rxdpnext = nic->rx_blocks[ring_no]
  1517. [nextblk].block_virt_addr;
  1518. }
  1519. if (rxdpnext->Control_2 & BIT(0))
  1520. goto end;
  1521. }
  1522. #endif
  1523. #ifndef CONFIG_2BUFF_MODE
  1524. skb = dev_alloc_skb(size + NET_IP_ALIGN);
  1525. #else
  1526. skb = dev_alloc_skb(dev->mtu + ALIGN_SIZE + BUF0_LEN + 4);
  1527. #endif
  1528. if (!skb) {
  1529. DBG_PRINT(ERR_DBG, "%s: Out of ", dev->name);
  1530. DBG_PRINT(ERR_DBG, "memory to allocate SKBs\n");
  1531. return -ENOMEM;
  1532. }
  1533. #ifndef CONFIG_2BUFF_MODE
  1534. skb_reserve(skb, NET_IP_ALIGN);
  1535. memset(rxdp, 0, sizeof(RxD_t));
  1536. rxdp->Buffer0_ptr = pci_map_single
  1537. (nic->pdev, skb->data, size, PCI_DMA_FROMDEVICE);
  1538. rxdp->Control_2 &= (~MASK_BUFFER0_SIZE);
  1539. rxdp->Control_2 |= SET_BUFFER0_SIZE(size);
  1540. rxdp->Host_Control = (unsigned long) (skb);
  1541. rxdp->Control_1 |= RXD_OWN_XENA;
  1542. off++;
  1543. off %= (MAX_RXDS_PER_BLOCK + 1);
  1544. mac_control->rx_curr_put_info[ring_no].offset = off;
  1545. #else
  1546. ba = &nic->ba[ring_no][block_no][off];
  1547. skb_reserve(skb, BUF0_LEN);
  1548. tmp = ((unsigned long) skb->data & ALIGN_SIZE);
  1549. if (tmp)
  1550. skb_reserve(skb, (ALIGN_SIZE + 1) - tmp);
  1551. memset(rxdp, 0, sizeof(RxD_t));
  1552. rxdp->Buffer2_ptr = pci_map_single
  1553. (nic->pdev, skb->data, dev->mtu + BUF0_LEN + 4,
  1554. PCI_DMA_FROMDEVICE);
  1555. rxdp->Buffer0_ptr =
  1556. pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
  1557. PCI_DMA_FROMDEVICE);
  1558. rxdp->Buffer1_ptr =
  1559. pci_map_single(nic->pdev, ba->ba_1, BUF1_LEN,
  1560. PCI_DMA_FROMDEVICE);
  1561. rxdp->Control_2 = SET_BUFFER2_SIZE(dev->mtu + 4);
  1562. rxdp->Control_2 |= SET_BUFFER0_SIZE(BUF0_LEN);
  1563. rxdp->Control_2 |= SET_BUFFER1_SIZE(1); /* dummy. */
  1564. rxdp->Control_2 |= BIT(0); /* Set Buffer_Empty bit. */
  1565. rxdp->Host_Control = (u64) ((unsigned long) (skb));
  1566. rxdp->Control_1 |= RXD_OWN_XENA;
  1567. off++;
  1568. mac_control->rx_curr_put_info[ring_no].offset = off;
  1569. #endif
  1570. atomic_inc(&nic->rx_bufs_left[ring_no]);
  1571. alloc_tab++;
  1572. }
  1573. end:
  1574. return SUCCESS;
  1575. }
  1576. /**
  1577. * free_rx_buffers - Frees all Rx buffers
  1578. * @sp: device private variable.
  1579. * Description:
  1580. * This function will free all Rx buffers allocated by host.
  1581. * Return Value:
  1582. * NONE.
  1583. */
  1584. static void free_rx_buffers(struct s2io_nic *sp)
  1585. {
  1586. struct net_device *dev = sp->dev;
  1587. int i, j, blk = 0, off, buf_cnt = 0;
  1588. RxD_t *rxdp;
  1589. struct sk_buff *skb;
  1590. mac_info_t *mac_control;
  1591. struct config_param *config;
  1592. #ifdef CONFIG_2BUFF_MODE
  1593. buffAdd_t *ba;
  1594. #endif
  1595. mac_control = &sp->mac_control;
  1596. config = &sp->config;
  1597. for (i = 0; i < config->rx_ring_num; i++) {
  1598. for (j = 0, blk = 0; j < config->rx_cfg[i].num_rxd; j++) {
  1599. off = j % (MAX_RXDS_PER_BLOCK + 1);
  1600. rxdp = sp->rx_blocks[i][blk].block_virt_addr + off;
  1601. #ifndef CONFIG_2BUFF_MODE
  1602. if (rxdp->Control_1 == END_OF_BLOCK) {
  1603. rxdp =
  1604. (RxD_t *) ((unsigned long) rxdp->
  1605. Control_2);
  1606. j++;
  1607. blk++;
  1608. }
  1609. #else
  1610. if (rxdp->Host_Control == END_OF_BLOCK) {
  1611. blk++;
  1612. continue;
  1613. }
  1614. #endif
  1615. if (!(rxdp->Control_1 & RXD_OWN_XENA)) {
  1616. memset(rxdp, 0, sizeof(RxD_t));
  1617. continue;
  1618. }
  1619. skb =
  1620. (struct sk_buff *) ((unsigned long) rxdp->
  1621. Host_Control);
  1622. if (skb) {
  1623. #ifndef CONFIG_2BUFF_MODE
  1624. pci_unmap_single(sp->pdev, (dma_addr_t)
  1625. rxdp->Buffer0_ptr,
  1626. dev->mtu +
  1627. HEADER_ETHERNET_II_802_3_SIZE
  1628. + HEADER_802_2_SIZE +
  1629. HEADER_SNAP_SIZE,
  1630. PCI_DMA_FROMDEVICE);
  1631. #else
  1632. ba = &sp->ba[i][blk][off];
  1633. pci_unmap_single(sp->pdev, (dma_addr_t)
  1634. rxdp->Buffer0_ptr,
  1635. BUF0_LEN,
  1636. PCI_DMA_FROMDEVICE);
  1637. pci_unmap_single(sp->pdev, (dma_addr_t)
  1638. rxdp->Buffer1_ptr,
  1639. BUF1_LEN,
  1640. PCI_DMA_FROMDEVICE);
  1641. pci_unmap_single(sp->pdev, (dma_addr_t)
  1642. rxdp->Buffer2_ptr,
  1643. dev->mtu + BUF0_LEN + 4,
  1644. PCI_DMA_FROMDEVICE);
  1645. #endif
  1646. dev_kfree_skb(skb);
  1647. atomic_dec(&sp->rx_bufs_left[i]);
  1648. buf_cnt++;
  1649. }
  1650. memset(rxdp, 0, sizeof(RxD_t));
  1651. }
  1652. mac_control->rx_curr_put_info[i].block_index = 0;
  1653. mac_control->rx_curr_get_info[i].block_index = 0;
  1654. mac_control->rx_curr_put_info[i].offset = 0;
  1655. mac_control->rx_curr_get_info[i].offset = 0;
  1656. atomic_set(&sp->rx_bufs_left[i], 0);
  1657. DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
  1658. dev->name, buf_cnt, i);
  1659. }
  1660. }
  1661. /**
  1662. * s2io_poll - Rx interrupt handler for NAPI support
  1663. * @dev : pointer to the device structure.
  1664. * @budget : The number of packets that were budgeted to be processed
  1665. * during one pass through the 'Poll" function.
  1666. * Description:
  1667. * Comes into picture only if NAPI support has been incorporated. It does
  1668. * the same thing that rx_intr_handler does, but not in a interrupt context
  1669. * also It will process only a given number of packets.
  1670. * Return value:
  1671. * 0 on success and 1 if there are No Rx packets to be processed.
  1672. */
  1673. #ifdef CONFIG_S2IO_NAPI
  1674. static int s2io_poll(struct net_device *dev, int *budget)
  1675. {
  1676. nic_t *nic = dev->priv;
  1677. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1678. int pkts_to_process = *budget, pkt_cnt = 0;
  1679. register u64 val64 = 0;
  1680. rx_curr_get_info_t get_info, put_info;
  1681. int i, get_block, put_block, get_offset, put_offset, ring_bufs;
  1682. #ifndef CONFIG_2BUFF_MODE
  1683. u16 val16, cksum;
  1684. #endif
  1685. struct sk_buff *skb;
  1686. RxD_t *rxdp;
  1687. mac_info_t *mac_control;
  1688. struct config_param *config;
  1689. #ifdef CONFIG_2BUFF_MODE
  1690. buffAdd_t *ba;
  1691. #endif
  1692. mac_control = &nic->mac_control;
  1693. config = &nic->config;
  1694. if (pkts_to_process > dev->quota)
  1695. pkts_to_process = dev->quota;
  1696. val64 = readq(&bar0->rx_traffic_int);
  1697. writeq(val64, &bar0->rx_traffic_int);
  1698. for (i = 0; i < config->rx_ring_num; i++) {
  1699. get_info = mac_control->rx_curr_get_info[i];
  1700. get_block = get_info.block_index;
  1701. put_info = mac_control->rx_curr_put_info[i];
  1702. put_block = put_info.block_index;
  1703. ring_bufs = config->rx_cfg[i].num_rxd;
  1704. rxdp = nic->rx_blocks[i][get_block].block_virt_addr +
  1705. get_info.offset;
  1706. #ifndef CONFIG_2BUFF_MODE
  1707. get_offset = (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1708. get_info.offset;
  1709. put_offset = (put_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1710. put_info.offset;
  1711. while ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  1712. (((get_offset + 1) % ring_bufs) != put_offset)) {
  1713. if (--pkts_to_process < 0) {
  1714. goto no_rx;
  1715. }
  1716. if (rxdp->Control_1 == END_OF_BLOCK) {
  1717. rxdp =
  1718. (RxD_t *) ((unsigned long) rxdp->
  1719. Control_2);
  1720. get_info.offset++;
  1721. get_info.offset %=
  1722. (MAX_RXDS_PER_BLOCK + 1);
  1723. get_block++;
  1724. get_block %= nic->block_count[i];
  1725. mac_control->rx_curr_get_info[i].
  1726. offset = get_info.offset;
  1727. mac_control->rx_curr_get_info[i].
  1728. block_index = get_block;
  1729. continue;
  1730. }
  1731. get_offset =
  1732. (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1733. get_info.offset;
  1734. skb =
  1735. (struct sk_buff *) ((unsigned long) rxdp->
  1736. Host_Control);
  1737. if (skb == NULL) {
  1738. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  1739. dev->name);
  1740. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  1741. goto no_rx;
  1742. }
  1743. val64 = RXD_GET_BUFFER0_SIZE(rxdp->Control_2);
  1744. val16 = (u16) (val64 >> 48);
  1745. cksum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  1746. pci_unmap_single(nic->pdev, (dma_addr_t)
  1747. rxdp->Buffer0_ptr,
  1748. dev->mtu +
  1749. HEADER_ETHERNET_II_802_3_SIZE +
  1750. HEADER_802_2_SIZE +
  1751. HEADER_SNAP_SIZE,
  1752. PCI_DMA_FROMDEVICE);
  1753. rx_osm_handler(nic, val16, rxdp, i);
  1754. pkt_cnt++;
  1755. get_info.offset++;
  1756. get_info.offset %= (MAX_RXDS_PER_BLOCK + 1);
  1757. rxdp =
  1758. nic->rx_blocks[i][get_block].block_virt_addr +
  1759. get_info.offset;
  1760. mac_control->rx_curr_get_info[i].offset =
  1761. get_info.offset;
  1762. }
  1763. #else
  1764. get_offset = (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1765. get_info.offset;
  1766. put_offset = (put_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1767. put_info.offset;
  1768. while (((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  1769. !(rxdp->Control_2 & BIT(0))) &&
  1770. (((get_offset + 1) % ring_bufs) != put_offset)) {
  1771. if (--pkts_to_process < 0) {
  1772. goto no_rx;
  1773. }
  1774. skb = (struct sk_buff *) ((unsigned long)
  1775. rxdp->Host_Control);
  1776. if (skb == NULL) {
  1777. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  1778. dev->name);
  1779. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  1780. goto no_rx;
  1781. }
  1782. pci_unmap_single(nic->pdev, (dma_addr_t)
  1783. rxdp->Buffer0_ptr,
  1784. BUF0_LEN, PCI_DMA_FROMDEVICE);
  1785. pci_unmap_single(nic->pdev, (dma_addr_t)
  1786. rxdp->Buffer1_ptr,
  1787. BUF1_LEN, PCI_DMA_FROMDEVICE);
  1788. pci_unmap_single(nic->pdev, (dma_addr_t)
  1789. rxdp->Buffer2_ptr,
  1790. dev->mtu + BUF0_LEN + 4,
  1791. PCI_DMA_FROMDEVICE);
  1792. ba = &nic->ba[i][get_block][get_info.offset];
  1793. rx_osm_handler(nic, rxdp, i, ba);
  1794. get_info.offset++;
  1795. mac_control->rx_curr_get_info[i].offset =
  1796. get_info.offset;
  1797. rxdp =
  1798. nic->rx_blocks[i][get_block].block_virt_addr +
  1799. get_info.offset;
  1800. if (get_info.offset &&
  1801. (!(get_info.offset % MAX_RXDS_PER_BLOCK))) {
  1802. get_info.offset = 0;
  1803. mac_control->rx_curr_get_info[i].
  1804. offset = get_info.offset;
  1805. get_block++;
  1806. get_block %= nic->block_count[i];
  1807. mac_control->rx_curr_get_info[i].
  1808. block_index = get_block;
  1809. rxdp =
  1810. nic->rx_blocks[i][get_block].
  1811. block_virt_addr;
  1812. }
  1813. get_offset =
  1814. (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1815. get_info.offset;
  1816. pkt_cnt++;
  1817. }
  1818. #endif
  1819. }
  1820. if (!pkt_cnt)
  1821. pkt_cnt = 1;
  1822. dev->quota -= pkt_cnt;
  1823. *budget -= pkt_cnt;
  1824. netif_rx_complete(dev);
  1825. for (i = 0; i < config->rx_ring_num; i++) {
  1826. if (fill_rx_buffers(nic, i) == -ENOMEM) {
  1827. DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
  1828. DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
  1829. break;
  1830. }
  1831. }
  1832. /* Re enable the Rx interrupts. */
  1833. en_dis_able_nic_intrs(nic, RX_TRAFFIC_INTR, ENABLE_INTRS);
  1834. return 0;
  1835. no_rx:
  1836. dev->quota -= pkt_cnt;
  1837. *budget -= pkt_cnt;
  1838. for (i = 0; i < config->rx_ring_num; i++) {
  1839. if (fill_rx_buffers(nic, i) == -ENOMEM) {
  1840. DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
  1841. DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
  1842. break;
  1843. }
  1844. }
  1845. return 1;
  1846. }
  1847. #else
  1848. /**
  1849. * rx_intr_handler - Rx interrupt handler
  1850. * @nic: device private variable.
  1851. * Description:
  1852. * If the interrupt is because of a received frame or if the
  1853. * receive ring contains fresh as yet un-processed frames,this function is
  1854. * called. It picks out the RxD at which place the last Rx processing had
  1855. * stopped and sends the skb to the OSM's Rx handler and then increments
  1856. * the offset.
  1857. * Return Value:
  1858. * NONE.
  1859. */
  1860. static void rx_intr_handler(struct s2io_nic *nic)
  1861. {
  1862. struct net_device *dev = (struct net_device *) nic->dev;
  1863. XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0;
  1864. rx_curr_get_info_t get_info, put_info;
  1865. RxD_t *rxdp;
  1866. struct sk_buff *skb;
  1867. #ifndef CONFIG_2BUFF_MODE
  1868. u16 val16, cksum;
  1869. #endif
  1870. register u64 val64 = 0;
  1871. int get_block, get_offset, put_block, put_offset, ring_bufs;
  1872. int i, pkt_cnt = 0;
  1873. mac_info_t *mac_control;
  1874. struct config_param *config;
  1875. #ifdef CONFIG_2BUFF_MODE
  1876. buffAdd_t *ba;
  1877. #endif
  1878. mac_control = &nic->mac_control;
  1879. config = &nic->config;
  1880. /*
  1881. * rx_traffic_int reg is an R1 register, hence we read and write back
  1882. * the samevalue in the register to clear it.
  1883. */
  1884. val64 = readq(&bar0->rx_traffic_int);
  1885. writeq(val64, &bar0->rx_traffic_int);
  1886. for (i = 0; i < config->rx_ring_num; i++) {
  1887. get_info = mac_control->rx_curr_get_info[i];
  1888. get_block = get_info.block_index;
  1889. put_info = mac_control->rx_curr_put_info[i];
  1890. put_block = put_info.block_index;
  1891. ring_bufs = config->rx_cfg[i].num_rxd;
  1892. rxdp = nic->rx_blocks[i][get_block].block_virt_addr +
  1893. get_info.offset;
  1894. #ifndef CONFIG_2BUFF_MODE
  1895. get_offset = (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1896. get_info.offset;
  1897. spin_lock(&nic->put_lock);
  1898. put_offset = nic->put_pos[i];
  1899. spin_unlock(&nic->put_lock);
  1900. while ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  1901. (((get_offset + 1) % ring_bufs) != put_offset)) {
  1902. if (rxdp->Control_1 == END_OF_BLOCK) {
  1903. rxdp = (RxD_t *) ((unsigned long)
  1904. rxdp->Control_2);
  1905. get_info.offset++;
  1906. get_info.offset %=
  1907. (MAX_RXDS_PER_BLOCK + 1);
  1908. get_block++;
  1909. get_block %= nic->block_count[i];
  1910. mac_control->rx_curr_get_info[i].
  1911. offset = get_info.offset;
  1912. mac_control->rx_curr_get_info[i].
  1913. block_index = get_block;
  1914. continue;
  1915. }
  1916. get_offset =
  1917. (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1918. get_info.offset;
  1919. skb = (struct sk_buff *) ((unsigned long)
  1920. rxdp->Host_Control);
  1921. if (skb == NULL) {
  1922. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  1923. dev->name);
  1924. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  1925. return;
  1926. }
  1927. val64 = RXD_GET_BUFFER0_SIZE(rxdp->Control_2);
  1928. val16 = (u16) (val64 >> 48);
  1929. cksum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  1930. pci_unmap_single(nic->pdev, (dma_addr_t)
  1931. rxdp->Buffer0_ptr,
  1932. dev->mtu +
  1933. HEADER_ETHERNET_II_802_3_SIZE +
  1934. HEADER_802_2_SIZE +
  1935. HEADER_SNAP_SIZE,
  1936. PCI_DMA_FROMDEVICE);
  1937. rx_osm_handler(nic, val16, rxdp, i);
  1938. get_info.offset++;
  1939. get_info.offset %= (MAX_RXDS_PER_BLOCK + 1);
  1940. rxdp =
  1941. nic->rx_blocks[i][get_block].block_virt_addr +
  1942. get_info.offset;
  1943. mac_control->rx_curr_get_info[i].offset =
  1944. get_info.offset;
  1945. pkt_cnt++;
  1946. if ((indicate_max_pkts)
  1947. && (pkt_cnt > indicate_max_pkts))
  1948. break;
  1949. }
  1950. #else
  1951. get_offset = (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  1952. get_info.offset;
  1953. spin_lock(&nic->put_lock);
  1954. put_offset = nic->put_pos[i];
  1955. spin_unlock(&nic->put_lock);
  1956. while (((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  1957. !(rxdp->Control_2 & BIT(0))) &&
  1958. (((get_offset + 1) % ring_bufs) != put_offset)) {
  1959. skb = (struct sk_buff *) ((unsigned long)
  1960. rxdp->Host_Control);
  1961. if (skb == NULL) {
  1962. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  1963. dev->name);
  1964. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  1965. return;
  1966. }
  1967. pci_unmap_single(nic->pdev, (dma_addr_t)
  1968. rxdp->Buffer0_ptr,
  1969. BUF0_LEN, PCI_DMA_FROMDEVICE);
  1970. pci_unmap_single(nic->pdev, (dma_addr_t)
  1971. rxdp->Buffer1_ptr,
  1972. BUF1_LEN, PCI_DMA_FROMDEVICE);
  1973. pci_unmap_single(nic->pdev, (dma_addr_t)
  1974. rxdp->Buffer2_ptr,
  1975. dev->mtu + BUF0_LEN + 4,
  1976. PCI_DMA_FROMDEVICE);
  1977. ba = &nic->ba[i][get_block][get_info.offset];
  1978. rx_osm_handler(nic, rxdp, i, ba);
  1979. get_info.offset++;
  1980. mac_control->rx_curr_get_info[i].offset =
  1981. get_info.offset;
  1982. rxdp =
  1983. nic->rx_blocks[i][get_block].block_virt_addr +
  1984. get_info.offset;
  1985. if (get_info.offset &&
  1986. (!(get_info.offset % MAX_RXDS_PER_BLOCK))) {
  1987. get_info.offset = 0;
  1988. mac_control->rx_curr_get_info[i].
  1989. offset = get_info.offset;
  1990. get_block++;
  1991. get_block %= nic->block_count[i];
  1992. mac_control->rx_curr_get_info[i].
  1993. block_index = get_block;
  1994. rxdp =
  1995. nic->rx_blocks[i][get_block].
  1996. block_virt_addr;
  1997. }
  1998. get_offset =
  1999. (get_block * (MAX_RXDS_PER_BLOCK + 1)) +
  2000. get_info.offset;
  2001. pkt_cnt++;
  2002. if ((indicate_max_pkts)
  2003. && (pkt_cnt > indicate_max_pkts))
  2004. break;
  2005. }
  2006. #endif
  2007. if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
  2008. break;
  2009. }
  2010. }
  2011. #endif
  2012. /**
  2013. * tx_intr_handler - Transmit interrupt handler
  2014. * @nic : device private variable
  2015. * Description:
  2016. * If an interrupt was raised to indicate DMA complete of the
  2017. * Tx packet, this function is called. It identifies the last TxD
  2018. * whose buffer was freed and frees all skbs whose data have already
  2019. * DMA'ed into the NICs internal memory.
  2020. * Return Value:
  2021. * NONE
  2022. */
  2023. static void tx_intr_handler(struct s2io_nic *nic)
  2024. {
  2025. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2026. struct net_device *dev = (struct net_device *) nic->dev;
  2027. tx_curr_get_info_t get_info, put_info;
  2028. struct sk_buff *skb;
  2029. TxD_t *txdlp;
  2030. register u64 val64 = 0;
  2031. int i;
  2032. u16 j, frg_cnt;
  2033. mac_info_t *mac_control;
  2034. struct config_param *config;
  2035. mac_control = &nic->mac_control;
  2036. config = &nic->config;
  2037. /*
  2038. * tx_traffic_int reg is an R1 register, hence we read and write
  2039. * back the samevalue in the register to clear it.
  2040. */
  2041. val64 = readq(&bar0->tx_traffic_int);
  2042. writeq(val64, &bar0->tx_traffic_int);
  2043. for (i = 0; i < config->tx_fifo_num; i++) {
  2044. get_info = mac_control->tx_curr_get_info[i];
  2045. put_info = mac_control->tx_curr_put_info[i];
  2046. txdlp = (TxD_t *) nic->list_info[i][get_info.offset].
  2047. list_virt_addr;
  2048. while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
  2049. (get_info.offset != put_info.offset) &&
  2050. (txdlp->Host_Control)) {
  2051. /* Check for TxD errors */
  2052. if (txdlp->Control_1 & TXD_T_CODE) {
  2053. unsigned long long err;
  2054. err = txdlp->Control_1 & TXD_T_CODE;
  2055. DBG_PRINT(ERR_DBG, "***TxD error %llx\n",
  2056. err);
  2057. }
  2058. skb = (struct sk_buff *) ((unsigned long)
  2059. txdlp->Host_Control);
  2060. if (skb == NULL) {
  2061. DBG_PRINT(ERR_DBG, "%s: Null skb ",
  2062. dev->name);
  2063. DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
  2064. return;
  2065. }
  2066. nic->tx_pkt_count++;
  2067. frg_cnt = skb_shinfo(skb)->nr_frags;
  2068. /* For unfragmented skb */
  2069. pci_unmap_single(nic->pdev, (dma_addr_t)
  2070. txdlp->Buffer_Pointer,
  2071. skb->len - skb->data_len,
  2072. PCI_DMA_TODEVICE);
  2073. if (frg_cnt) {
  2074. TxD_t *temp = txdlp;
  2075. txdlp++;
  2076. for (j = 0; j < frg_cnt; j++, txdlp++) {
  2077. skb_frag_t *frag =
  2078. &skb_shinfo(skb)->frags[j];
  2079. pci_unmap_page(nic->pdev,
  2080. (dma_addr_t)
  2081. txdlp->
  2082. Buffer_Pointer,
  2083. frag->size,
  2084. PCI_DMA_TODEVICE);
  2085. }
  2086. txdlp = temp;
  2087. }
  2088. memset(txdlp, 0,
  2089. (sizeof(TxD_t) * config->max_txds));
  2090. /* Updating the statistics block */
  2091. nic->stats.tx_packets++;
  2092. nic->stats.tx_bytes += skb->len;
  2093. dev_kfree_skb_irq(skb);
  2094. get_info.offset++;
  2095. get_info.offset %= get_info.fifo_len + 1;
  2096. txdlp = (TxD_t *) nic->list_info[i]
  2097. [get_info.offset].list_virt_addr;
  2098. mac_control->tx_curr_get_info[i].offset =
  2099. get_info.offset;
  2100. }
  2101. }
  2102. spin_lock(&nic->tx_lock);
  2103. if (netif_queue_stopped(dev))
  2104. netif_wake_queue(dev);
  2105. spin_unlock(&nic->tx_lock);
  2106. }
  2107. /**
  2108. * alarm_intr_handler - Alarm Interrrupt handler
  2109. * @nic: device private variable
  2110. * Description: If the interrupt was neither because of Rx packet or Tx
  2111. * complete, this function is called. If the interrupt was to indicate
  2112. * a loss of link, the OSM link status handler is invoked for any other
  2113. * alarm interrupt the block that raised the interrupt is displayed
  2114. * and a H/W reset is issued.
  2115. * Return Value:
  2116. * NONE
  2117. */
  2118. static void alarm_intr_handler(struct s2io_nic *nic)
  2119. {
  2120. struct net_device *dev = (struct net_device *) nic->dev;
  2121. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2122. register u64 val64 = 0, err_reg = 0;
  2123. /* Handling link status change error Intr */
  2124. err_reg = readq(&bar0->mac_rmac_err_reg);
  2125. writeq(err_reg, &bar0->mac_rmac_err_reg);
  2126. if (err_reg & RMAC_LINK_STATE_CHANGE_INT) {
  2127. schedule_work(&nic->set_link_task);
  2128. }
  2129. /* In case of a serious error, the device will be Reset. */
  2130. val64 = readq(&bar0->serr_source);
  2131. if (val64 & SERR_SOURCE_ANY) {
  2132. DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
  2133. DBG_PRINT(ERR_DBG, "serious error!!\n");
  2134. netif_stop_queue(dev);
  2135. schedule_work(&nic->rst_timer_task);
  2136. }
  2137. /*
  2138. * Also as mentioned in the latest Errata sheets if the PCC_FB_ECC
  2139. * Error occurs, the adapter will be recycled by disabling the
  2140. * adapter enable bit and enabling it again after the device
  2141. * becomes Quiescent.
  2142. */
  2143. val64 = readq(&bar0->pcc_err_reg);
  2144. writeq(val64, &bar0->pcc_err_reg);
  2145. if (val64 & PCC_FB_ECC_DB_ERR) {
  2146. u64 ac = readq(&bar0->adapter_control);
  2147. ac &= ~(ADAPTER_CNTL_EN);
  2148. writeq(ac, &bar0->adapter_control);
  2149. ac = readq(&bar0->adapter_control);
  2150. schedule_work(&nic->set_link_task);
  2151. }
  2152. /* Other type of interrupts are not being handled now, TODO */
  2153. }
  2154. /**
  2155. * wait_for_cmd_complete - waits for a command to complete.
  2156. * @sp : private member of the device structure, which is a pointer to the
  2157. * s2io_nic structure.
  2158. * Description: Function that waits for a command to Write into RMAC
  2159. * ADDR DATA registers to be completed and returns either success or
  2160. * error depending on whether the command was complete or not.
  2161. * Return value:
  2162. * SUCCESS on success and FAILURE on failure.
  2163. */
  2164. static int wait_for_cmd_complete(nic_t * sp)
  2165. {
  2166. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2167. int ret = FAILURE, cnt = 0;
  2168. u64 val64;
  2169. while (TRUE) {
  2170. val64 = readq(&bar0->rmac_addr_cmd_mem);
  2171. if (!(val64 & RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
  2172. ret = SUCCESS;
  2173. break;
  2174. }
  2175. msleep(50);
  2176. if (cnt++ > 10)
  2177. break;
  2178. }
  2179. return ret;
  2180. }
  2181. /**
  2182. * s2io_reset - Resets the card.
  2183. * @sp : private member of the device structure.
  2184. * Description: Function to Reset the card. This function then also
  2185. * restores the previously saved PCI configuration space registers as
  2186. * the card reset also resets the configuration space.
  2187. * Return value:
  2188. * void.
  2189. */
  2190. static void s2io_reset(nic_t * sp)
  2191. {
  2192. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2193. u64 val64;
  2194. u16 subid;
  2195. val64 = SW_RESET_ALL;
  2196. writeq(val64, &bar0->sw_reset);
  2197. /*
  2198. * At this stage, if the PCI write is indeed completed, the
  2199. * card is reset and so is the PCI Config space of the device.
  2200. * So a read cannot be issued at this stage on any of the
  2201. * registers to ensure the write into "sw_reset" register
  2202. * has gone through.
  2203. * Question: Is there any system call that will explicitly force
  2204. * all the write commands still pending on the bus to be pushed
  2205. * through?
  2206. * As of now I'am just giving a 250ms delay and hoping that the
  2207. * PCI write to sw_reset register is done by this time.
  2208. */
  2209. msleep(250);
  2210. /* Restore the PCI state saved during initializarion. */
  2211. pci_restore_state(sp->pdev);
  2212. s2io_init_pci(sp);
  2213. msleep(250);
  2214. /* SXE-002: Configure link and activity LED to turn it off */
  2215. subid = sp->pdev->subsystem_device;
  2216. if ((subid & 0xFF) >= 0x07) {
  2217. val64 = readq(&bar0->gpio_control);
  2218. val64 |= 0x0000800000000000ULL;
  2219. writeq(val64, &bar0->gpio_control);
  2220. val64 = 0x0411040400000000ULL;
  2221. writeq(val64, (void __iomem *) bar0 + 0x2700);
  2222. }
  2223. sp->device_enabled_once = FALSE;
  2224. }
  2225. /**
  2226. * s2io_set_swapper - to set the swapper controle on the card
  2227. * @sp : private member of the device structure,
  2228. * pointer to the s2io_nic structure.
  2229. * Description: Function to set the swapper control on the card
  2230. * correctly depending on the 'endianness' of the system.
  2231. * Return value:
  2232. * SUCCESS on success and FAILURE on failure.
  2233. */
  2234. static int s2io_set_swapper(nic_t * sp)
  2235. {
  2236. struct net_device *dev = sp->dev;
  2237. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2238. u64 val64, valt, valr;
  2239. /*
  2240. * Set proper endian settings and verify the same by reading
  2241. * the PIF Feed-back register.
  2242. */
  2243. val64 = readq(&bar0->pif_rd_swapper_fb);
  2244. if (val64 != 0x0123456789ABCDEFULL) {
  2245. int i = 0;
  2246. u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
  2247. 0x8100008181000081ULL, /* FE=1, SE=0 */
  2248. 0x4200004242000042ULL, /* FE=0, SE=1 */
  2249. 0}; /* FE=0, SE=0 */
  2250. while(i<4) {
  2251. writeq(value[i], &bar0->swapper_ctrl);
  2252. val64 = readq(&bar0->pif_rd_swapper_fb);
  2253. if (val64 == 0x0123456789ABCDEFULL)
  2254. break;
  2255. i++;
  2256. }
  2257. if (i == 4) {
  2258. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  2259. dev->name);
  2260. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  2261. (unsigned long long) val64);
  2262. return FAILURE;
  2263. }
  2264. valr = value[i];
  2265. } else {
  2266. valr = readq(&bar0->swapper_ctrl);
  2267. }
  2268. valt = 0x0123456789ABCDEFULL;
  2269. writeq(valt, &bar0->xmsi_address);
  2270. val64 = readq(&bar0->xmsi_address);
  2271. if(val64 != valt) {
  2272. int i = 0;
  2273. u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
  2274. 0x0081810000818100ULL, /* FE=1, SE=0 */
  2275. 0x0042420000424200ULL, /* FE=0, SE=1 */
  2276. 0}; /* FE=0, SE=0 */
  2277. while(i<4) {
  2278. writeq((value[i] | valr), &bar0->swapper_ctrl);
  2279. writeq(valt, &bar0->xmsi_address);
  2280. val64 = readq(&bar0->xmsi_address);
  2281. if(val64 == valt)
  2282. break;
  2283. i++;
  2284. }
  2285. if(i == 4) {
  2286. DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
  2287. DBG_PRINT(ERR_DBG, "reads:0x%llx\n",val64);
  2288. return FAILURE;
  2289. }
  2290. }
  2291. val64 = readq(&bar0->swapper_ctrl);
  2292. val64 &= 0xFFFF000000000000ULL;
  2293. #ifdef __BIG_ENDIAN
  2294. /*
  2295. * The device by default set to a big endian format, so a
  2296. * big endian driver need not set anything.
  2297. */
  2298. val64 |= (SWAPPER_CTRL_TXP_FE |
  2299. SWAPPER_CTRL_TXP_SE |
  2300. SWAPPER_CTRL_TXD_R_FE |
  2301. SWAPPER_CTRL_TXD_W_FE |
  2302. SWAPPER_CTRL_TXF_R_FE |
  2303. SWAPPER_CTRL_RXD_R_FE |
  2304. SWAPPER_CTRL_RXD_W_FE |
  2305. SWAPPER_CTRL_RXF_W_FE |
  2306. SWAPPER_CTRL_XMSI_FE |
  2307. SWAPPER_CTRL_XMSI_SE |
  2308. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  2309. writeq(val64, &bar0->swapper_ctrl);
  2310. #else
  2311. /*
  2312. * Initially we enable all bits to make it accessible by the
  2313. * driver, then we selectively enable only those bits that
  2314. * we want to set.
  2315. */
  2316. val64 |= (SWAPPER_CTRL_TXP_FE |
  2317. SWAPPER_CTRL_TXP_SE |
  2318. SWAPPER_CTRL_TXD_R_FE |
  2319. SWAPPER_CTRL_TXD_R_SE |
  2320. SWAPPER_CTRL_TXD_W_FE |
  2321. SWAPPER_CTRL_TXD_W_SE |
  2322. SWAPPER_CTRL_TXF_R_FE |
  2323. SWAPPER_CTRL_RXD_R_FE |
  2324. SWAPPER_CTRL_RXD_R_SE |
  2325. SWAPPER_CTRL_RXD_W_FE |
  2326. SWAPPER_CTRL_RXD_W_SE |
  2327. SWAPPER_CTRL_RXF_W_FE |
  2328. SWAPPER_CTRL_XMSI_FE |
  2329. SWAPPER_CTRL_XMSI_SE |
  2330. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  2331. writeq(val64, &bar0->swapper_ctrl);
  2332. #endif
  2333. val64 = readq(&bar0->swapper_ctrl);
  2334. /*
  2335. * Verifying if endian settings are accurate by reading a
  2336. * feedback register.
  2337. */
  2338. val64 = readq(&bar0->pif_rd_swapper_fb);
  2339. if (val64 != 0x0123456789ABCDEFULL) {
  2340. /* Endian settings are incorrect, calls for another dekko. */
  2341. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  2342. dev->name);
  2343. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  2344. (unsigned long long) val64);
  2345. return FAILURE;
  2346. }
  2347. return SUCCESS;
  2348. }
  2349. /* ********************************************************* *
  2350. * Functions defined below concern the OS part of the driver *
  2351. * ********************************************************* */
  2352. /**
  2353. * s2io_open - open entry point of the driver
  2354. * @dev : pointer to the device structure.
  2355. * Description:
  2356. * This function is the open entry point of the driver. It mainly calls a
  2357. * function to allocate Rx buffers and inserts them into the buffer
  2358. * descriptors and then enables the Rx part of the NIC.
  2359. * Return value:
  2360. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  2361. * file on failure.
  2362. */
  2363. static int s2io_open(struct net_device *dev)
  2364. {
  2365. nic_t *sp = dev->priv;
  2366. int err = 0;
  2367. /*
  2368. * Make sure you have link off by default every time
  2369. * Nic is initialized
  2370. */
  2371. netif_carrier_off(dev);
  2372. sp->last_link_state = LINK_DOWN;
  2373. /* Initialize H/W and enable interrupts */
  2374. if (s2io_card_up(sp)) {
  2375. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  2376. dev->name);
  2377. return -ENODEV;
  2378. }
  2379. /* After proper initialization of H/W, register ISR */
  2380. err = request_irq((int) sp->irq, s2io_isr, SA_SHIRQ,
  2381. sp->name, dev);
  2382. if (err) {
  2383. s2io_reset(sp);
  2384. DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
  2385. dev->name);
  2386. return err;
  2387. }
  2388. if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
  2389. DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
  2390. s2io_reset(sp);
  2391. return -ENODEV;
  2392. }
  2393. netif_start_queue(dev);
  2394. return 0;
  2395. }
  2396. /**
  2397. * s2io_close -close entry point of the driver
  2398. * @dev : device pointer.
  2399. * Description:
  2400. * This is the stop entry point of the driver. It needs to undo exactly
  2401. * whatever was done by the open entry point,thus it's usually referred to
  2402. * as the close function.Among other things this function mainly stops the
  2403. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  2404. * Return value:
  2405. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  2406. * file on failure.
  2407. */
  2408. static int s2io_close(struct net_device *dev)
  2409. {
  2410. nic_t *sp = dev->priv;
  2411. flush_scheduled_work();
  2412. netif_stop_queue(dev);
  2413. /* Reset card, kill tasklet and free Tx and Rx buffers. */
  2414. s2io_card_down(sp);
  2415. free_irq(dev->irq, dev);
  2416. sp->device_close_flag = TRUE; /* Device is shut down. */
  2417. return 0;
  2418. }
  2419. /**
  2420. * s2io_xmit - Tx entry point of te driver
  2421. * @skb : the socket buffer containing the Tx data.
  2422. * @dev : device pointer.
  2423. * Description :
  2424. * This function is the Tx entry point of the driver. S2IO NIC supports
  2425. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  2426. * NOTE: when device cant queue the pkt,just the trans_start variable will
  2427. * not be upadted.
  2428. * Return value:
  2429. * 0 on success & 1 on failure.
  2430. */
  2431. static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
  2432. {
  2433. nic_t *sp = dev->priv;
  2434. u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
  2435. register u64 val64;
  2436. TxD_t *txdp;
  2437. TxFIFO_element_t __iomem *tx_fifo;
  2438. unsigned long flags;
  2439. #ifdef NETIF_F_TSO
  2440. int mss;
  2441. #endif
  2442. mac_info_t *mac_control;
  2443. struct config_param *config;
  2444. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2445. mac_control = &sp->mac_control;
  2446. config = &sp->config;
  2447. DBG_PRINT(TX_DBG, "%s: In S2IO Tx routine\n", dev->name);
  2448. spin_lock_irqsave(&sp->tx_lock, flags);
  2449. if (atomic_read(&sp->card_state) == CARD_DOWN) {
  2450. DBG_PRINT(ERR_DBG, "%s: Card going down for reset\n",
  2451. dev->name);
  2452. spin_unlock_irqrestore(&sp->tx_lock, flags);
  2453. return 1;
  2454. }
  2455. queue = 0;
  2456. put_off = (u16) mac_control->tx_curr_put_info[queue].offset;
  2457. get_off = (u16) mac_control->tx_curr_get_info[queue].offset;
  2458. txdp = (TxD_t *) sp->list_info[queue][put_off].list_virt_addr;
  2459. queue_len = mac_control->tx_curr_put_info[queue].fifo_len + 1;
  2460. /* Avoid "put" pointer going beyond "get" pointer */
  2461. if (txdp->Host_Control || (((put_off + 1) % queue_len) == get_off)) {
  2462. DBG_PRINT(ERR_DBG, "Error in xmit, No free TXDs.\n");
  2463. netif_stop_queue(dev);
  2464. dev_kfree_skb(skb);
  2465. spin_unlock_irqrestore(&sp->tx_lock, flags);
  2466. return 0;
  2467. }
  2468. #ifdef NETIF_F_TSO
  2469. mss = skb_shinfo(skb)->tso_size;
  2470. if (mss) {
  2471. txdp->Control_1 |= TXD_TCP_LSO_EN;
  2472. txdp->Control_1 |= TXD_TCP_LSO_MSS(mss);
  2473. }
  2474. #endif
  2475. frg_cnt = skb_shinfo(skb)->nr_frags;
  2476. frg_len = skb->len - skb->data_len;
  2477. txdp->Host_Control = (unsigned long) skb;
  2478. txdp->Buffer_Pointer = pci_map_single
  2479. (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
  2480. if (skb->ip_summed == CHECKSUM_HW) {
  2481. txdp->Control_2 |=
  2482. (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
  2483. TXD_TX_CKO_UDP_EN);
  2484. }
  2485. txdp->Control_2 |= config->tx_intr_type;
  2486. txdp->Control_1 |= (TXD_BUFFER0_SIZE(frg_len) |
  2487. TXD_GATHER_CODE_FIRST);
  2488. txdp->Control_1 |= TXD_LIST_OWN_XENA;
  2489. /* For fragmented SKB. */
  2490. for (i = 0; i < frg_cnt; i++) {
  2491. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2492. txdp++;
  2493. txdp->Buffer_Pointer = (u64) pci_map_page
  2494. (sp->pdev, frag->page, frag->page_offset,
  2495. frag->size, PCI_DMA_TODEVICE);
  2496. txdp->Control_1 |= TXD_BUFFER0_SIZE(frag->size);
  2497. }
  2498. txdp->Control_1 |= TXD_GATHER_CODE_LAST;
  2499. tx_fifo = mac_control->tx_FIFO_start[queue];
  2500. val64 = sp->list_info[queue][put_off].list_phy_addr;
  2501. writeq(val64, &tx_fifo->TxDL_Pointer);
  2502. val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
  2503. TX_FIFO_LAST_LIST);
  2504. #ifdef NETIF_F_TSO
  2505. if (mss)
  2506. val64 |= TX_FIFO_SPECIAL_FUNC;
  2507. #endif
  2508. writeq(val64, &tx_fifo->List_Control);
  2509. /* Perform a PCI read to flush previous writes */
  2510. val64 = readq(&bar0->general_int_status);
  2511. put_off++;
  2512. put_off %= mac_control->tx_curr_put_info[queue].fifo_len + 1;
  2513. mac_control->tx_curr_put_info[queue].offset = put_off;
  2514. /* Avoid "put" pointer going beyond "get" pointer */
  2515. if (((put_off + 1) % queue_len) == get_off) {
  2516. DBG_PRINT(TX_DBG,
  2517. "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
  2518. put_off, get_off);
  2519. netif_stop_queue(dev);
  2520. }
  2521. dev->trans_start = jiffies;
  2522. spin_unlock_irqrestore(&sp->tx_lock, flags);
  2523. return 0;
  2524. }
  2525. /**
  2526. * s2io_isr - ISR handler of the device .
  2527. * @irq: the irq of the device.
  2528. * @dev_id: a void pointer to the dev structure of the NIC.
  2529. * @pt_regs: pointer to the registers pushed on the stack.
  2530. * Description: This function is the ISR handler of the device. It
  2531. * identifies the reason for the interrupt and calls the relevant
  2532. * service routines. As a contongency measure, this ISR allocates the
  2533. * recv buffers, if their numbers are below the panic value which is
  2534. * presently set to 25% of the original number of rcv buffers allocated.
  2535. * Return value:
  2536. * IRQ_HANDLED: will be returned if IRQ was handled by this routine
  2537. * IRQ_NONE: will be returned if interrupt is not from our device
  2538. */
  2539. static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs)
  2540. {
  2541. struct net_device *dev = (struct net_device *) dev_id;
  2542. nic_t *sp = dev->priv;
  2543. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2544. #ifndef CONFIG_S2IO_NAPI
  2545. int i, ret;
  2546. #endif
  2547. u64 reason = 0;
  2548. mac_info_t *mac_control;
  2549. struct config_param *config;
  2550. mac_control = &sp->mac_control;
  2551. config = &sp->config;
  2552. /*
  2553. * Identify the cause for interrupt and call the appropriate
  2554. * interrupt handler. Causes for the interrupt could be;
  2555. * 1. Rx of packet.
  2556. * 2. Tx complete.
  2557. * 3. Link down.
  2558. * 4. Error in any functional blocks of the NIC.
  2559. */
  2560. reason = readq(&bar0->general_int_status);
  2561. if (!reason) {
  2562. /* The interrupt was not raised by Xena. */
  2563. return IRQ_NONE;
  2564. }
  2565. /* If Intr is because of Tx Traffic */
  2566. if (reason & GEN_INTR_TXTRAFFIC) {
  2567. tx_intr_handler(sp);
  2568. }
  2569. /* If Intr is because of an error */
  2570. if (reason & (GEN_ERROR_INTR))
  2571. alarm_intr_handler(sp);
  2572. #ifdef CONFIG_S2IO_NAPI
  2573. if (reason & GEN_INTR_RXTRAFFIC) {
  2574. if (netif_rx_schedule_prep(dev)) {
  2575. en_dis_able_nic_intrs(sp, RX_TRAFFIC_INTR,
  2576. DISABLE_INTRS);
  2577. __netif_rx_schedule(dev);
  2578. }
  2579. }
  2580. #else
  2581. /* If Intr is because of Rx Traffic */
  2582. if (reason & GEN_INTR_RXTRAFFIC) {
  2583. rx_intr_handler(sp);
  2584. }
  2585. #endif
  2586. /*
  2587. * If the Rx buffer count is below the panic threshold then
  2588. * reallocate the buffers from the interrupt handler itself,
  2589. * else schedule a tasklet to reallocate the buffers.
  2590. */
  2591. #ifndef CONFIG_S2IO_NAPI
  2592. for (i = 0; i < config->rx_ring_num; i++) {
  2593. int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
  2594. int level = rx_buffer_level(sp, rxb_size, i);
  2595. if ((level == PANIC) && (!TASKLET_IN_USE)) {
  2596. DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", dev->name);
  2597. DBG_PRINT(INTR_DBG, "PANIC levels\n");
  2598. if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
  2599. DBG_PRINT(ERR_DBG, "%s:Out of memory",
  2600. dev->name);
  2601. DBG_PRINT(ERR_DBG, " in ISR!!\n");
  2602. clear_bit(0, (&sp->tasklet_status));
  2603. return IRQ_HANDLED;
  2604. }
  2605. clear_bit(0, (&sp->tasklet_status));
  2606. } else if (level == LOW) {
  2607. tasklet_schedule(&sp->task);
  2608. }
  2609. }
  2610. #endif
  2611. return IRQ_HANDLED;
  2612. }
  2613. /**
  2614. * s2io_get_stats - Updates the device statistics structure.
  2615. * @dev : pointer to the device structure.
  2616. * Description:
  2617. * This function updates the device statistics structure in the s2io_nic
  2618. * structure and returns a pointer to the same.
  2619. * Return value:
  2620. * pointer to the updated net_device_stats structure.
  2621. */
  2622. static struct net_device_stats *s2io_get_stats(struct net_device *dev)
  2623. {
  2624. nic_t *sp = dev->priv;
  2625. mac_info_t *mac_control;
  2626. struct config_param *config;
  2627. mac_control = &sp->mac_control;
  2628. config = &sp->config;
  2629. sp->stats.tx_errors = mac_control->stats_info->tmac_any_err_frms;
  2630. sp->stats.rx_errors = mac_control->stats_info->rmac_drop_frms;
  2631. sp->stats.multicast = mac_control->stats_info->rmac_vld_mcst_frms;
  2632. sp->stats.rx_length_errors =
  2633. mac_control->stats_info->rmac_long_frms;
  2634. return (&sp->stats);
  2635. }
  2636. /**
  2637. * s2io_set_multicast - entry point for multicast address enable/disable.
  2638. * @dev : pointer to the device structure
  2639. * Description:
  2640. * This function is a driver entry point which gets called by the kernel
  2641. * whenever multicast addresses must be enabled/disabled. This also gets
  2642. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  2643. * determine, if multicast address must be enabled or if promiscuous mode
  2644. * is to be disabled etc.
  2645. * Return value:
  2646. * void.
  2647. */
  2648. static void s2io_set_multicast(struct net_device *dev)
  2649. {
  2650. int i, j, prev_cnt;
  2651. struct dev_mc_list *mclist;
  2652. nic_t *sp = dev->priv;
  2653. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2654. u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
  2655. 0xfeffffffffffULL;
  2656. u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
  2657. void __iomem *add;
  2658. if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
  2659. /* Enable all Multicast addresses */
  2660. writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
  2661. &bar0->rmac_addr_data0_mem);
  2662. writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
  2663. &bar0->rmac_addr_data1_mem);
  2664. val64 = RMAC_ADDR_CMD_MEM_WE |
  2665. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  2666. RMAC_ADDR_CMD_MEM_OFFSET(MAC_MC_ALL_MC_ADDR_OFFSET);
  2667. writeq(val64, &bar0->rmac_addr_cmd_mem);
  2668. /* Wait till command completes */
  2669. wait_for_cmd_complete(sp);
  2670. sp->m_cast_flg = 1;
  2671. sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
  2672. } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
  2673. /* Disable all Multicast addresses */
  2674. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  2675. &bar0->rmac_addr_data0_mem);
  2676. val64 = RMAC_ADDR_CMD_MEM_WE |
  2677. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  2678. RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
  2679. writeq(val64, &bar0->rmac_addr_cmd_mem);
  2680. /* Wait till command completes */
  2681. wait_for_cmd_complete(sp);
  2682. sp->m_cast_flg = 0;
  2683. sp->all_multi_pos = 0;
  2684. }
  2685. if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
  2686. /* Put the NIC into promiscuous mode */
  2687. add = &bar0->mac_cfg;
  2688. val64 = readq(&bar0->mac_cfg);
  2689. val64 |= MAC_CFG_RMAC_PROM_ENABLE;
  2690. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  2691. writel((u32) val64, add);
  2692. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  2693. writel((u32) (val64 >> 32), (add + 4));
  2694. val64 = readq(&bar0->mac_cfg);
  2695. sp->promisc_flg = 1;
  2696. DBG_PRINT(ERR_DBG, "%s: entered promiscuous mode\n",
  2697. dev->name);
  2698. } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
  2699. /* Remove the NIC from promiscuous mode */
  2700. add = &bar0->mac_cfg;
  2701. val64 = readq(&bar0->mac_cfg);
  2702. val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
  2703. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  2704. writel((u32) val64, add);
  2705. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  2706. writel((u32) (val64 >> 32), (add + 4));
  2707. val64 = readq(&bar0->mac_cfg);
  2708. sp->promisc_flg = 0;
  2709. DBG_PRINT(ERR_DBG, "%s: left promiscuous mode\n",
  2710. dev->name);
  2711. }
  2712. /* Update individual M_CAST address list */
  2713. if ((!sp->m_cast_flg) && dev->mc_count) {
  2714. if (dev->mc_count >
  2715. (MAX_ADDRS_SUPPORTED - MAC_MC_ADDR_START_OFFSET - 1)) {
  2716. DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
  2717. dev->name);
  2718. DBG_PRINT(ERR_DBG, "can be added, please enable ");
  2719. DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
  2720. return;
  2721. }
  2722. prev_cnt = sp->mc_addr_count;
  2723. sp->mc_addr_count = dev->mc_count;
  2724. /* Clear out the previous list of Mc in the H/W. */
  2725. for (i = 0; i < prev_cnt; i++) {
  2726. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  2727. &bar0->rmac_addr_data0_mem);
  2728. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  2729. &bar0->rmac_addr_data1_mem);
  2730. val64 = RMAC_ADDR_CMD_MEM_WE |
  2731. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  2732. RMAC_ADDR_CMD_MEM_OFFSET
  2733. (MAC_MC_ADDR_START_OFFSET + i);
  2734. writeq(val64, &bar0->rmac_addr_cmd_mem);
  2735. /* Wait for command completes */
  2736. if (wait_for_cmd_complete(sp)) {
  2737. DBG_PRINT(ERR_DBG, "%s: Adding ",
  2738. dev->name);
  2739. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  2740. return;
  2741. }
  2742. }
  2743. /* Create the new Rx filter list and update the same in H/W. */
  2744. for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
  2745. i++, mclist = mclist->next) {
  2746. memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
  2747. ETH_ALEN);
  2748. for (j = 0; j < ETH_ALEN; j++) {
  2749. mac_addr |= mclist->dmi_addr[j];
  2750. mac_addr <<= 8;
  2751. }
  2752. mac_addr >>= 8;
  2753. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  2754. &bar0->rmac_addr_data0_mem);
  2755. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  2756. &bar0->rmac_addr_data1_mem);
  2757. val64 = RMAC_ADDR_CMD_MEM_WE |
  2758. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  2759. RMAC_ADDR_CMD_MEM_OFFSET
  2760. (i + MAC_MC_ADDR_START_OFFSET);
  2761. writeq(val64, &bar0->rmac_addr_cmd_mem);
  2762. /* Wait for command completes */
  2763. if (wait_for_cmd_complete(sp)) {
  2764. DBG_PRINT(ERR_DBG, "%s: Adding ",
  2765. dev->name);
  2766. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  2767. return;
  2768. }
  2769. }
  2770. }
  2771. }
  2772. /**
  2773. * s2io_set_mac_addr - Programs the Xframe mac address
  2774. * @dev : pointer to the device structure.
  2775. * @addr: a uchar pointer to the new mac address which is to be set.
  2776. * Description : This procedure will program the Xframe to receive
  2777. * frames with new Mac Address
  2778. * Return value: SUCCESS on success and an appropriate (-)ve integer
  2779. * as defined in errno.h file on failure.
  2780. */
  2781. int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
  2782. {
  2783. nic_t *sp = dev->priv;
  2784. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2785. register u64 val64, mac_addr = 0;
  2786. int i;
  2787. /*
  2788. * Set the new MAC address as the new unicast filter and reflect this
  2789. * change on the device address registered with the OS. It will be
  2790. * at offset 0.
  2791. */
  2792. for (i = 0; i < ETH_ALEN; i++) {
  2793. mac_addr <<= 8;
  2794. mac_addr |= addr[i];
  2795. }
  2796. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  2797. &bar0->rmac_addr_data0_mem);
  2798. val64 =
  2799. RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  2800. RMAC_ADDR_CMD_MEM_OFFSET(0);
  2801. writeq(val64, &bar0->rmac_addr_cmd_mem);
  2802. /* Wait till command completes */
  2803. if (wait_for_cmd_complete(sp)) {
  2804. DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
  2805. return FAILURE;
  2806. }
  2807. return SUCCESS;
  2808. }
  2809. /**
  2810. * s2io_ethtool_sset - Sets different link parameters.
  2811. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  2812. * @info: pointer to the structure with parameters given by ethtool to set
  2813. * link information.
  2814. * Description:
  2815. * The function sets different link parameters provided by the user onto
  2816. * the NIC.
  2817. * Return value:
  2818. * 0 on success.
  2819. */
  2820. static int s2io_ethtool_sset(struct net_device *dev,
  2821. struct ethtool_cmd *info)
  2822. {
  2823. nic_t *sp = dev->priv;
  2824. if ((info->autoneg == AUTONEG_ENABLE) ||
  2825. (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
  2826. return -EINVAL;
  2827. else {
  2828. s2io_close(sp->dev);
  2829. s2io_open(sp->dev);
  2830. }
  2831. return 0;
  2832. }
  2833. /**
  2834. * s2io_ethtol_gset - Return link specific information.
  2835. * @sp : private member of the device structure, pointer to the
  2836. * s2io_nic structure.
  2837. * @info : pointer to the structure with parameters given by ethtool
  2838. * to return link information.
  2839. * Description:
  2840. * Returns link specific information like speed, duplex etc.. to ethtool.
  2841. * Return value :
  2842. * return 0 on success.
  2843. */
  2844. static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
  2845. {
  2846. nic_t *sp = dev->priv;
  2847. info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  2848. info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  2849. info->port = PORT_FIBRE;
  2850. /* info->transceiver?? TODO */
  2851. if (netif_carrier_ok(sp->dev)) {
  2852. info->speed = 10000;
  2853. info->duplex = DUPLEX_FULL;
  2854. } else {
  2855. info->speed = -1;
  2856. info->duplex = -1;
  2857. }
  2858. info->autoneg = AUTONEG_DISABLE;
  2859. return 0;
  2860. }
  2861. /**
  2862. * s2io_ethtool_gdrvinfo - Returns driver specific information.
  2863. * @sp : private member of the device structure, which is a pointer to the
  2864. * s2io_nic structure.
  2865. * @info : pointer to the structure with parameters given by ethtool to
  2866. * return driver information.
  2867. * Description:
  2868. * Returns driver specefic information like name, version etc.. to ethtool.
  2869. * Return value:
  2870. * void
  2871. */
  2872. static void s2io_ethtool_gdrvinfo(struct net_device *dev,
  2873. struct ethtool_drvinfo *info)
  2874. {
  2875. nic_t *sp = dev->priv;
  2876. strncpy(info->driver, s2io_driver_name, sizeof(s2io_driver_name));
  2877. strncpy(info->version, s2io_driver_version,
  2878. sizeof(s2io_driver_version));
  2879. strncpy(info->fw_version, "", 32);
  2880. strncpy(info->bus_info, pci_name(sp->pdev), 32);
  2881. info->regdump_len = XENA_REG_SPACE;
  2882. info->eedump_len = XENA_EEPROM_SPACE;
  2883. info->testinfo_len = S2IO_TEST_LEN;
  2884. info->n_stats = S2IO_STAT_LEN;
  2885. }
  2886. /**
  2887. * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
  2888. * @sp: private member of the device structure, which is a pointer to the
  2889. * s2io_nic structure.
  2890. * @regs : pointer to the structure with parameters given by ethtool for
  2891. * dumping the registers.
  2892. * @reg_space: The input argumnet into which all the registers are dumped.
  2893. * Description:
  2894. * Dumps the entire register space of xFrame NIC into the user given
  2895. * buffer area.
  2896. * Return value :
  2897. * void .
  2898. */
  2899. static void s2io_ethtool_gregs(struct net_device *dev,
  2900. struct ethtool_regs *regs, void *space)
  2901. {
  2902. int i;
  2903. u64 reg;
  2904. u8 *reg_space = (u8 *) space;
  2905. nic_t *sp = dev->priv;
  2906. regs->len = XENA_REG_SPACE;
  2907. regs->version = sp->pdev->subsystem_device;
  2908. for (i = 0; i < regs->len; i += 8) {
  2909. reg = readq(sp->bar0 + i);
  2910. memcpy((reg_space + i), &reg, 8);
  2911. }
  2912. }
  2913. /**
  2914. * s2io_phy_id - timer function that alternates adapter LED.
  2915. * @data : address of the private member of the device structure, which
  2916. * is a pointer to the s2io_nic structure, provided as an u32.
  2917. * Description: This is actually the timer function that alternates the
  2918. * adapter LED bit of the adapter control bit to set/reset every time on
  2919. * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
  2920. * once every second.
  2921. */
  2922. static void s2io_phy_id(unsigned long data)
  2923. {
  2924. nic_t *sp = (nic_t *) data;
  2925. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2926. u64 val64 = 0;
  2927. u16 subid;
  2928. subid = sp->pdev->subsystem_device;
  2929. if ((subid & 0xFF) >= 0x07) {
  2930. val64 = readq(&bar0->gpio_control);
  2931. val64 ^= GPIO_CTRL_GPIO_0;
  2932. writeq(val64, &bar0->gpio_control);
  2933. } else {
  2934. val64 = readq(&bar0->adapter_control);
  2935. val64 ^= ADAPTER_LED_ON;
  2936. writeq(val64, &bar0->adapter_control);
  2937. }
  2938. mod_timer(&sp->id_timer, jiffies + HZ / 2);
  2939. }
  2940. /**
  2941. * s2io_ethtool_idnic - To physically identify the nic on the system.
  2942. * @sp : private member of the device structure, which is a pointer to the
  2943. * s2io_nic structure.
  2944. * @id : pointer to the structure with identification parameters given by
  2945. * ethtool.
  2946. * Description: Used to physically identify the NIC on the system.
  2947. * The Link LED will blink for a time specified by the user for
  2948. * identification.
  2949. * NOTE: The Link has to be Up to be able to blink the LED. Hence
  2950. * identification is possible only if it's link is up.
  2951. * Return value:
  2952. * int , returns 0 on success
  2953. */
  2954. static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
  2955. {
  2956. u64 val64 = 0, last_gpio_ctrl_val;
  2957. nic_t *sp = dev->priv;
  2958. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2959. u16 subid;
  2960. subid = sp->pdev->subsystem_device;
  2961. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  2962. if ((subid & 0xFF) < 0x07) {
  2963. val64 = readq(&bar0->adapter_control);
  2964. if (!(val64 & ADAPTER_CNTL_EN)) {
  2965. printk(KERN_ERR
  2966. "Adapter Link down, cannot blink LED\n");
  2967. return -EFAULT;
  2968. }
  2969. }
  2970. if (sp->id_timer.function == NULL) {
  2971. init_timer(&sp->id_timer);
  2972. sp->id_timer.function = s2io_phy_id;
  2973. sp->id_timer.data = (unsigned long) sp;
  2974. }
  2975. mod_timer(&sp->id_timer, jiffies);
  2976. if (data)
  2977. msleep(data * 1000);
  2978. else
  2979. msleep(0xFFFFFFFF);
  2980. del_timer_sync(&sp->id_timer);
  2981. if (CARDS_WITH_FAULTY_LINK_INDICATORS(subid)) {
  2982. writeq(last_gpio_ctrl_val, &bar0->gpio_control);
  2983. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  2984. }
  2985. return 0;
  2986. }
  2987. /**
  2988. * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
  2989. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  2990. * @ep : pointer to the structure with pause parameters given by ethtool.
  2991. * Description:
  2992. * Returns the Pause frame generation and reception capability of the NIC.
  2993. * Return value:
  2994. * void
  2995. */
  2996. static void s2io_ethtool_getpause_data(struct net_device *dev,
  2997. struct ethtool_pauseparam *ep)
  2998. {
  2999. u64 val64;
  3000. nic_t *sp = dev->priv;
  3001. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3002. val64 = readq(&bar0->rmac_pause_cfg);
  3003. if (val64 & RMAC_PAUSE_GEN_ENABLE)
  3004. ep->tx_pause = TRUE;
  3005. if (val64 & RMAC_PAUSE_RX_ENABLE)
  3006. ep->rx_pause = TRUE;
  3007. ep->autoneg = FALSE;
  3008. }
  3009. /**
  3010. * s2io_ethtool_setpause_data - set/reset pause frame generation.
  3011. * @sp : private member of the device structure, which is a pointer to the
  3012. * s2io_nic structure.
  3013. * @ep : pointer to the structure with pause parameters given by ethtool.
  3014. * Description:
  3015. * It can be used to set or reset Pause frame generation or reception
  3016. * support of the NIC.
  3017. * Return value:
  3018. * int, returns 0 on Success
  3019. */
  3020. static int s2io_ethtool_setpause_data(struct net_device *dev,
  3021. struct ethtool_pauseparam *ep)
  3022. {
  3023. u64 val64;
  3024. nic_t *sp = dev->priv;
  3025. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3026. val64 = readq(&bar0->rmac_pause_cfg);
  3027. if (ep->tx_pause)
  3028. val64 |= RMAC_PAUSE_GEN_ENABLE;
  3029. else
  3030. val64 &= ~RMAC_PAUSE_GEN_ENABLE;
  3031. if (ep->rx_pause)
  3032. val64 |= RMAC_PAUSE_RX_ENABLE;
  3033. else
  3034. val64 &= ~RMAC_PAUSE_RX_ENABLE;
  3035. writeq(val64, &bar0->rmac_pause_cfg);
  3036. return 0;
  3037. }
  3038. /**
  3039. * read_eeprom - reads 4 bytes of data from user given offset.
  3040. * @sp : private member of the device structure, which is a pointer to the
  3041. * s2io_nic structure.
  3042. * @off : offset at which the data must be written
  3043. * @data : Its an output parameter where the data read at the given
  3044. * offset is stored.
  3045. * Description:
  3046. * Will read 4 bytes of data from the user given offset and return the
  3047. * read data.
  3048. * NOTE: Will allow to read only part of the EEPROM visible through the
  3049. * I2C bus.
  3050. * Return value:
  3051. * -1 on failure and 0 on success.
  3052. */
  3053. #define S2IO_DEV_ID 5
  3054. static int read_eeprom(nic_t * sp, int off, u32 * data)
  3055. {
  3056. int ret = -1;
  3057. u32 exit_cnt = 0;
  3058. u64 val64;
  3059. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3060. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  3061. I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
  3062. I2C_CONTROL_CNTL_START;
  3063. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  3064. while (exit_cnt < 5) {
  3065. val64 = readq(&bar0->i2c_control);
  3066. if (I2C_CONTROL_CNTL_END(val64)) {
  3067. *data = I2C_CONTROL_GET_DATA(val64);
  3068. ret = 0;
  3069. break;
  3070. }
  3071. msleep(50);
  3072. exit_cnt++;
  3073. }
  3074. return ret;
  3075. }
  3076. /**
  3077. * write_eeprom - actually writes the relevant part of the data value.
  3078. * @sp : private member of the device structure, which is a pointer to the
  3079. * s2io_nic structure.
  3080. * @off : offset at which the data must be written
  3081. * @data : The data that is to be written
  3082. * @cnt : Number of bytes of the data that are actually to be written into
  3083. * the Eeprom. (max of 3)
  3084. * Description:
  3085. * Actually writes the relevant part of the data value into the Eeprom
  3086. * through the I2C bus.
  3087. * Return value:
  3088. * 0 on success, -1 on failure.
  3089. */
  3090. static int write_eeprom(nic_t * sp, int off, u32 data, int cnt)
  3091. {
  3092. int exit_cnt = 0, ret = -1;
  3093. u64 val64;
  3094. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3095. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  3096. I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA(data) |
  3097. I2C_CONTROL_CNTL_START;
  3098. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  3099. while (exit_cnt < 5) {
  3100. val64 = readq(&bar0->i2c_control);
  3101. if (I2C_CONTROL_CNTL_END(val64)) {
  3102. if (!(val64 & I2C_CONTROL_NACK))
  3103. ret = 0;
  3104. break;
  3105. }
  3106. msleep(50);
  3107. exit_cnt++;
  3108. }
  3109. return ret;
  3110. }
  3111. /**
  3112. * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
  3113. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  3114. * @eeprom : pointer to the user level structure provided by ethtool,
  3115. * containing all relevant information.
  3116. * @data_buf : user defined value to be written into Eeprom.
  3117. * Description: Reads the values stored in the Eeprom at given offset
  3118. * for a given length. Stores these values int the input argument data
  3119. * buffer 'data_buf' and returns these to the caller (ethtool.)
  3120. * Return value:
  3121. * int 0 on success
  3122. */
  3123. static int s2io_ethtool_geeprom(struct net_device *dev,
  3124. struct ethtool_eeprom *eeprom, u8 * data_buf)
  3125. {
  3126. u32 data, i, valid;
  3127. nic_t *sp = dev->priv;
  3128. eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
  3129. if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
  3130. eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
  3131. for (i = 0; i < eeprom->len; i += 4) {
  3132. if (read_eeprom(sp, (eeprom->offset + i), &data)) {
  3133. DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
  3134. return -EFAULT;
  3135. }
  3136. valid = INV(data);
  3137. memcpy((data_buf + i), &valid, 4);
  3138. }
  3139. return 0;
  3140. }
  3141. /**
  3142. * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
  3143. * @sp : private member of the device structure, which is a pointer to the
  3144. * s2io_nic structure.
  3145. * @eeprom : pointer to the user level structure provided by ethtool,
  3146. * containing all relevant information.
  3147. * @data_buf ; user defined value to be written into Eeprom.
  3148. * Description:
  3149. * Tries to write the user provided value in the Eeprom, at the offset
  3150. * given by the user.
  3151. * Return value:
  3152. * 0 on success, -EFAULT on failure.
  3153. */
  3154. static int s2io_ethtool_seeprom(struct net_device *dev,
  3155. struct ethtool_eeprom *eeprom,
  3156. u8 * data_buf)
  3157. {
  3158. int len = eeprom->len, cnt = 0;
  3159. u32 valid = 0, data;
  3160. nic_t *sp = dev->priv;
  3161. if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
  3162. DBG_PRINT(ERR_DBG,
  3163. "ETHTOOL_WRITE_EEPROM Err: Magic value ");
  3164. DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
  3165. eeprom->magic);
  3166. return -EFAULT;
  3167. }
  3168. while (len) {
  3169. data = (u32) data_buf[cnt] & 0x000000FF;
  3170. if (data) {
  3171. valid = (u32) (data << 24);
  3172. } else
  3173. valid = data;
  3174. if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
  3175. DBG_PRINT(ERR_DBG,
  3176. "ETHTOOL_WRITE_EEPROM Err: Cannot ");
  3177. DBG_PRINT(ERR_DBG,
  3178. "write into the specified offset\n");
  3179. return -EFAULT;
  3180. }
  3181. cnt++;
  3182. len--;
  3183. }
  3184. return 0;
  3185. }
  3186. /**
  3187. * s2io_register_test - reads and writes into all clock domains.
  3188. * @sp : private member of the device structure, which is a pointer to the
  3189. * s2io_nic structure.
  3190. * @data : variable that returns the result of each of the test conducted b
  3191. * by the driver.
  3192. * Description:
  3193. * Read and write into all clock domains. The NIC has 3 clock domains,
  3194. * see that registers in all the three regions are accessible.
  3195. * Return value:
  3196. * 0 on success.
  3197. */
  3198. static int s2io_register_test(nic_t * sp, uint64_t * data)
  3199. {
  3200. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3201. u64 val64 = 0;
  3202. int fail = 0;
  3203. val64 = readq(&bar0->pcc_enable);
  3204. if (val64 != 0xff00000000000000ULL) {
  3205. fail = 1;
  3206. DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
  3207. }
  3208. val64 = readq(&bar0->rmac_pause_cfg);
  3209. if (val64 != 0xc000ffff00000000ULL) {
  3210. fail = 1;
  3211. DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
  3212. }
  3213. val64 = readq(&bar0->rx_queue_cfg);
  3214. if (val64 != 0x0808080808080808ULL) {
  3215. fail = 1;
  3216. DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
  3217. }
  3218. val64 = readq(&bar0->xgxs_efifo_cfg);
  3219. if (val64 != 0x000000001923141EULL) {
  3220. fail = 1;
  3221. DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
  3222. }
  3223. val64 = 0x5A5A5A5A5A5A5A5AULL;
  3224. writeq(val64, &bar0->xmsi_data);
  3225. val64 = readq(&bar0->xmsi_data);
  3226. if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
  3227. fail = 1;
  3228. DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
  3229. }
  3230. val64 = 0xA5A5A5A5A5A5A5A5ULL;
  3231. writeq(val64, &bar0->xmsi_data);
  3232. val64 = readq(&bar0->xmsi_data);
  3233. if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
  3234. fail = 1;
  3235. DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
  3236. }
  3237. *data = fail;
  3238. return 0;
  3239. }
  3240. /**
  3241. * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
  3242. * @sp : private member of the device structure, which is a pointer to the
  3243. * s2io_nic structure.
  3244. * @data:variable that returns the result of each of the test conducted by
  3245. * the driver.
  3246. * Description:
  3247. * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
  3248. * register.
  3249. * Return value:
  3250. * 0 on success.
  3251. */
  3252. static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
  3253. {
  3254. int fail = 0;
  3255. u32 ret_data;
  3256. /* Test Write Error at offset 0 */
  3257. if (!write_eeprom(sp, 0, 0, 3))
  3258. fail = 1;
  3259. /* Test Write at offset 4f0 */
  3260. if (write_eeprom(sp, 0x4F0, 0x01234567, 3))
  3261. fail = 1;
  3262. if (read_eeprom(sp, 0x4F0, &ret_data))
  3263. fail = 1;
  3264. if (ret_data != 0x01234567)
  3265. fail = 1;
  3266. /* Reset the EEPROM data go FFFF */
  3267. write_eeprom(sp, 0x4F0, 0xFFFFFFFF, 3);
  3268. /* Test Write Request Error at offset 0x7c */
  3269. if (!write_eeprom(sp, 0x07C, 0, 3))
  3270. fail = 1;
  3271. /* Test Write Request at offset 0x7fc */
  3272. if (write_eeprom(sp, 0x7FC, 0x01234567, 3))
  3273. fail = 1;
  3274. if (read_eeprom(sp, 0x7FC, &ret_data))
  3275. fail = 1;
  3276. if (ret_data != 0x01234567)
  3277. fail = 1;
  3278. /* Reset the EEPROM data go FFFF */
  3279. write_eeprom(sp, 0x7FC, 0xFFFFFFFF, 3);
  3280. /* Test Write Error at offset 0x80 */
  3281. if (!write_eeprom(sp, 0x080, 0, 3))
  3282. fail = 1;
  3283. /* Test Write Error at offset 0xfc */
  3284. if (!write_eeprom(sp, 0x0FC, 0, 3))
  3285. fail = 1;
  3286. /* Test Write Error at offset 0x100 */
  3287. if (!write_eeprom(sp, 0x100, 0, 3))
  3288. fail = 1;
  3289. /* Test Write Error at offset 4ec */
  3290. if (!write_eeprom(sp, 0x4EC, 0, 3))
  3291. fail = 1;
  3292. *data = fail;
  3293. return 0;
  3294. }
  3295. /**
  3296. * s2io_bist_test - invokes the MemBist test of the card .
  3297. * @sp : private member of the device structure, which is a pointer to the
  3298. * s2io_nic structure.
  3299. * @data:variable that returns the result of each of the test conducted by
  3300. * the driver.
  3301. * Description:
  3302. * This invokes the MemBist test of the card. We give around
  3303. * 2 secs time for the Test to complete. If it's still not complete
  3304. * within this peiod, we consider that the test failed.
  3305. * Return value:
  3306. * 0 on success and -1 on failure.
  3307. */
  3308. static int s2io_bist_test(nic_t * sp, uint64_t * data)
  3309. {
  3310. u8 bist = 0;
  3311. int cnt = 0, ret = -1;
  3312. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  3313. bist |= PCI_BIST_START;
  3314. pci_write_config_word(sp->pdev, PCI_BIST, bist);
  3315. while (cnt < 20) {
  3316. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  3317. if (!(bist & PCI_BIST_START)) {
  3318. *data = (bist & PCI_BIST_CODE_MASK);
  3319. ret = 0;
  3320. break;
  3321. }
  3322. msleep(100);
  3323. cnt++;
  3324. }
  3325. return ret;
  3326. }
  3327. /**
  3328. * s2io-link_test - verifies the link state of the nic
  3329. * @sp ; private member of the device structure, which is a pointer to the
  3330. * s2io_nic structure.
  3331. * @data: variable that returns the result of each of the test conducted by
  3332. * the driver.
  3333. * Description:
  3334. * The function verifies the link state of the NIC and updates the input
  3335. * argument 'data' appropriately.
  3336. * Return value:
  3337. * 0 on success.
  3338. */
  3339. static int s2io_link_test(nic_t * sp, uint64_t * data)
  3340. {
  3341. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3342. u64 val64;
  3343. val64 = readq(&bar0->adapter_status);
  3344. if (val64 & ADAPTER_STATUS_RMAC_LOCAL_FAULT)
  3345. *data = 1;
  3346. return 0;
  3347. }
  3348. /**
  3349. * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
  3350. * @sp - private member of the device structure, which is a pointer to the
  3351. * s2io_nic structure.
  3352. * @data - variable that returns the result of each of the test
  3353. * conducted by the driver.
  3354. * Description:
  3355. * This is one of the offline test that tests the read and write
  3356. * access to the RldRam chip on the NIC.
  3357. * Return value:
  3358. * 0 on success.
  3359. */
  3360. static int s2io_rldram_test(nic_t * sp, uint64_t * data)
  3361. {
  3362. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3363. u64 val64;
  3364. int cnt, iteration = 0, test_pass = 0;
  3365. val64 = readq(&bar0->adapter_control);
  3366. val64 &= ~ADAPTER_ECC_EN;
  3367. writeq(val64, &bar0->adapter_control);
  3368. val64 = readq(&bar0->mc_rldram_test_ctrl);
  3369. val64 |= MC_RLDRAM_TEST_MODE;
  3370. writeq(val64, &bar0->mc_rldram_test_ctrl);
  3371. val64 = readq(&bar0->mc_rldram_mrs);
  3372. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
  3373. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  3374. val64 |= MC_RLDRAM_MRS_ENABLE;
  3375. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  3376. while (iteration < 2) {
  3377. val64 = 0x55555555aaaa0000ULL;
  3378. if (iteration == 1) {
  3379. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  3380. }
  3381. writeq(val64, &bar0->mc_rldram_test_d0);
  3382. val64 = 0xaaaa5a5555550000ULL;
  3383. if (iteration == 1) {
  3384. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  3385. }
  3386. writeq(val64, &bar0->mc_rldram_test_d1);
  3387. val64 = 0x55aaaaaaaa5a0000ULL;
  3388. if (iteration == 1) {
  3389. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  3390. }
  3391. writeq(val64, &bar0->mc_rldram_test_d2);
  3392. val64 = (u64) (0x0000003fffff0000ULL);
  3393. writeq(val64, &bar0->mc_rldram_test_add);
  3394. val64 = MC_RLDRAM_TEST_MODE;
  3395. writeq(val64, &bar0->mc_rldram_test_ctrl);
  3396. val64 |=
  3397. MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
  3398. MC_RLDRAM_TEST_GO;
  3399. writeq(val64, &bar0->mc_rldram_test_ctrl);
  3400. for (cnt = 0; cnt < 5; cnt++) {
  3401. val64 = readq(&bar0->mc_rldram_test_ctrl);
  3402. if (val64 & MC_RLDRAM_TEST_DONE)
  3403. break;
  3404. msleep(200);
  3405. }
  3406. if (cnt == 5)
  3407. break;
  3408. val64 = MC_RLDRAM_TEST_MODE;
  3409. writeq(val64, &bar0->mc_rldram_test_ctrl);
  3410. val64 |= MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
  3411. writeq(val64, &bar0->mc_rldram_test_ctrl);
  3412. for (cnt = 0; cnt < 5; cnt++) {
  3413. val64 = readq(&bar0->mc_rldram_test_ctrl);
  3414. if (val64 & MC_RLDRAM_TEST_DONE)
  3415. break;
  3416. msleep(500);
  3417. }
  3418. if (cnt == 5)
  3419. break;
  3420. val64 = readq(&bar0->mc_rldram_test_ctrl);
  3421. if (val64 & MC_RLDRAM_TEST_PASS)
  3422. test_pass = 1;
  3423. iteration++;
  3424. }
  3425. if (!test_pass)
  3426. *data = 1;
  3427. else
  3428. *data = 0;
  3429. return 0;
  3430. }
  3431. /**
  3432. * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
  3433. * @sp : private member of the device structure, which is a pointer to the
  3434. * s2io_nic structure.
  3435. * @ethtest : pointer to a ethtool command specific structure that will be
  3436. * returned to the user.
  3437. * @data : variable that returns the result of each of the test
  3438. * conducted by the driver.
  3439. * Description:
  3440. * This function conducts 6 tests ( 4 offline and 2 online) to determine
  3441. * the health of the card.
  3442. * Return value:
  3443. * void
  3444. */
  3445. static void s2io_ethtool_test(struct net_device *dev,
  3446. struct ethtool_test *ethtest,
  3447. uint64_t * data)
  3448. {
  3449. nic_t *sp = dev->priv;
  3450. int orig_state = netif_running(sp->dev);
  3451. if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
  3452. /* Offline Tests. */
  3453. if (orig_state) {
  3454. s2io_close(sp->dev);
  3455. s2io_set_swapper(sp);
  3456. } else
  3457. s2io_set_swapper(sp);
  3458. if (s2io_register_test(sp, &data[0]))
  3459. ethtest->flags |= ETH_TEST_FL_FAILED;
  3460. s2io_reset(sp);
  3461. s2io_set_swapper(sp);
  3462. if (s2io_rldram_test(sp, &data[3]))
  3463. ethtest->flags |= ETH_TEST_FL_FAILED;
  3464. s2io_reset(sp);
  3465. s2io_set_swapper(sp);
  3466. if (s2io_eeprom_test(sp, &data[1]))
  3467. ethtest->flags |= ETH_TEST_FL_FAILED;
  3468. if (s2io_bist_test(sp, &data[4]))
  3469. ethtest->flags |= ETH_TEST_FL_FAILED;
  3470. if (orig_state)
  3471. s2io_open(sp->dev);
  3472. data[2] = 0;
  3473. } else {
  3474. /* Online Tests. */
  3475. if (!orig_state) {
  3476. DBG_PRINT(ERR_DBG,
  3477. "%s: is not up, cannot run test\n",
  3478. dev->name);
  3479. data[0] = -1;
  3480. data[1] = -1;
  3481. data[2] = -1;
  3482. data[3] = -1;
  3483. data[4] = -1;
  3484. }
  3485. if (s2io_link_test(sp, &data[2]))
  3486. ethtest->flags |= ETH_TEST_FL_FAILED;
  3487. data[0] = 0;
  3488. data[1] = 0;
  3489. data[3] = 0;
  3490. data[4] = 0;
  3491. }
  3492. }
  3493. static void s2io_get_ethtool_stats(struct net_device *dev,
  3494. struct ethtool_stats *estats,
  3495. u64 * tmp_stats)
  3496. {
  3497. int i = 0;
  3498. nic_t *sp = dev->priv;
  3499. StatInfo_t *stat_info = sp->mac_control.stats_info;
  3500. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_frms);
  3501. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_data_octets);
  3502. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
  3503. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_mcst_frms);
  3504. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_bcst_frms);
  3505. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
  3506. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_any_err_frms);
  3507. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
  3508. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_vld_ip);
  3509. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_drop_ip);
  3510. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_icmp);
  3511. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_rst_tcp);
  3512. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
  3513. tmp_stats[i++] = le32_to_cpu(stat_info->tmac_udp);
  3514. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_vld_frms);
  3515. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_data_octets);
  3516. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
  3517. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
  3518. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_vld_mcst_frms);
  3519. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_vld_bcst_frms);
  3520. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
  3521. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
  3522. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
  3523. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_discarded_frms);
  3524. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_usized_frms);
  3525. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_osized_frms);
  3526. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_frag_frms);
  3527. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_jabber_frms);
  3528. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ip);
  3529. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
  3530. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
  3531. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_drop_ip);
  3532. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_icmp);
  3533. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
  3534. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_udp);
  3535. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_drp_udp);
  3536. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pause_cnt);
  3537. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_accepted_ip);
  3538. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
  3539. }
  3540. static int s2io_ethtool_get_regs_len(struct net_device *dev)
  3541. {
  3542. return (XENA_REG_SPACE);
  3543. }
  3544. static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
  3545. {
  3546. nic_t *sp = dev->priv;
  3547. return (sp->rx_csum);
  3548. }
  3549. static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
  3550. {
  3551. nic_t *sp = dev->priv;
  3552. if (data)
  3553. sp->rx_csum = 1;
  3554. else
  3555. sp->rx_csum = 0;
  3556. return 0;
  3557. }
  3558. static int s2io_get_eeprom_len(struct net_device *dev)
  3559. {
  3560. return (XENA_EEPROM_SPACE);
  3561. }
  3562. static int s2io_ethtool_self_test_count(struct net_device *dev)
  3563. {
  3564. return (S2IO_TEST_LEN);
  3565. }
  3566. static void s2io_ethtool_get_strings(struct net_device *dev,
  3567. u32 stringset, u8 * data)
  3568. {
  3569. switch (stringset) {
  3570. case ETH_SS_TEST:
  3571. memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
  3572. break;
  3573. case ETH_SS_STATS:
  3574. memcpy(data, &ethtool_stats_keys,
  3575. sizeof(ethtool_stats_keys));
  3576. }
  3577. }
  3578. static int s2io_ethtool_get_stats_count(struct net_device *dev)
  3579. {
  3580. return (S2IO_STAT_LEN);
  3581. }
  3582. static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  3583. {
  3584. if (data)
  3585. dev->features |= NETIF_F_IP_CSUM;
  3586. else
  3587. dev->features &= ~NETIF_F_IP_CSUM;
  3588. return 0;
  3589. }
  3590. static struct ethtool_ops netdev_ethtool_ops = {
  3591. .get_settings = s2io_ethtool_gset,
  3592. .set_settings = s2io_ethtool_sset,
  3593. .get_drvinfo = s2io_ethtool_gdrvinfo,
  3594. .get_regs_len = s2io_ethtool_get_regs_len,
  3595. .get_regs = s2io_ethtool_gregs,
  3596. .get_link = ethtool_op_get_link,
  3597. .get_eeprom_len = s2io_get_eeprom_len,
  3598. .get_eeprom = s2io_ethtool_geeprom,
  3599. .set_eeprom = s2io_ethtool_seeprom,
  3600. .get_pauseparam = s2io_ethtool_getpause_data,
  3601. .set_pauseparam = s2io_ethtool_setpause_data,
  3602. .get_rx_csum = s2io_ethtool_get_rx_csum,
  3603. .set_rx_csum = s2io_ethtool_set_rx_csum,
  3604. .get_tx_csum = ethtool_op_get_tx_csum,
  3605. .set_tx_csum = s2io_ethtool_op_set_tx_csum,
  3606. .get_sg = ethtool_op_get_sg,
  3607. .set_sg = ethtool_op_set_sg,
  3608. #ifdef NETIF_F_TSO
  3609. .get_tso = ethtool_op_get_tso,
  3610. .set_tso = ethtool_op_set_tso,
  3611. #endif
  3612. .self_test_count = s2io_ethtool_self_test_count,
  3613. .self_test = s2io_ethtool_test,
  3614. .get_strings = s2io_ethtool_get_strings,
  3615. .phys_id = s2io_ethtool_idnic,
  3616. .get_stats_count = s2io_ethtool_get_stats_count,
  3617. .get_ethtool_stats = s2io_get_ethtool_stats
  3618. };
  3619. /**
  3620. * s2io_ioctl - Entry point for the Ioctl
  3621. * @dev : Device pointer.
  3622. * @ifr : An IOCTL specefic structure, that can contain a pointer to
  3623. * a proprietary structure used to pass information to the driver.
  3624. * @cmd : This is used to distinguish between the different commands that
  3625. * can be passed to the IOCTL functions.
  3626. * Description:
  3627. * This function has support for ethtool, adding multiple MAC addresses on
  3628. * the NIC and some DBG commands for the util tool.
  3629. * Return value:
  3630. * Currently the IOCTL supports no operations, hence by default this
  3631. * function returns OP NOT SUPPORTED value.
  3632. */
  3633. static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  3634. {
  3635. return -EOPNOTSUPP;
  3636. }
  3637. /**
  3638. * s2io_change_mtu - entry point to change MTU size for the device.
  3639. * @dev : device pointer.
  3640. * @new_mtu : the new MTU size for the device.
  3641. * Description: A driver entry point to change MTU size for the device.
  3642. * Before changing the MTU the device must be stopped.
  3643. * Return value:
  3644. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3645. * file on failure.
  3646. */
  3647. static int s2io_change_mtu(struct net_device *dev, int new_mtu)
  3648. {
  3649. nic_t *sp = dev->priv;
  3650. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3651. register u64 val64;
  3652. if (netif_running(dev)) {
  3653. DBG_PRINT(ERR_DBG, "%s: Must be stopped to ", dev->name);
  3654. DBG_PRINT(ERR_DBG, "change its MTU \n");
  3655. return -EBUSY;
  3656. }
  3657. if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
  3658. DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
  3659. dev->name);
  3660. return -EPERM;
  3661. }
  3662. /* Set the new MTU into the PYLD register of the NIC */
  3663. val64 = new_mtu;
  3664. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  3665. dev->mtu = new_mtu;
  3666. return 0;
  3667. }
  3668. /**
  3669. * s2io_tasklet - Bottom half of the ISR.
  3670. * @dev_adr : address of the device structure in dma_addr_t format.
  3671. * Description:
  3672. * This is the tasklet or the bottom half of the ISR. This is
  3673. * an extension of the ISR which is scheduled by the scheduler to be run
  3674. * when the load on the CPU is low. All low priority tasks of the ISR can
  3675. * be pushed into the tasklet. For now the tasklet is used only to
  3676. * replenish the Rx buffers in the Rx buffer descriptors.
  3677. * Return value:
  3678. * void.
  3679. */
  3680. static void s2io_tasklet(unsigned long dev_addr)
  3681. {
  3682. struct net_device *dev = (struct net_device *) dev_addr;
  3683. nic_t *sp = dev->priv;
  3684. int i, ret;
  3685. mac_info_t *mac_control;
  3686. struct config_param *config;
  3687. mac_control = &sp->mac_control;
  3688. config = &sp->config;
  3689. if (!TASKLET_IN_USE) {
  3690. for (i = 0; i < config->rx_ring_num; i++) {
  3691. ret = fill_rx_buffers(sp, i);
  3692. if (ret == -ENOMEM) {
  3693. DBG_PRINT(ERR_DBG, "%s: Out of ",
  3694. dev->name);
  3695. DBG_PRINT(ERR_DBG, "memory in tasklet\n");
  3696. break;
  3697. } else if (ret == -EFILL) {
  3698. DBG_PRINT(ERR_DBG,
  3699. "%s: Rx Ring %d is full\n",
  3700. dev->name, i);
  3701. break;
  3702. }
  3703. }
  3704. clear_bit(0, (&sp->tasklet_status));
  3705. }
  3706. }
  3707. /**
  3708. * s2io_set_link - Set the LInk status
  3709. * @data: long pointer to device private structue
  3710. * Description: Sets the link status for the adapter
  3711. */
  3712. static void s2io_set_link(unsigned long data)
  3713. {
  3714. nic_t *nic = (nic_t *) data;
  3715. struct net_device *dev = nic->dev;
  3716. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  3717. register u64 val64;
  3718. u16 subid;
  3719. if (test_and_set_bit(0, &(nic->link_state))) {
  3720. /* The card is being reset, no point doing anything */
  3721. return;
  3722. }
  3723. subid = nic->pdev->subsystem_device;
  3724. /*
  3725. * Allow a small delay for the NICs self initiated
  3726. * cleanup to complete.
  3727. */
  3728. msleep(100);
  3729. val64 = readq(&bar0->adapter_status);
  3730. if (verify_xena_quiescence(val64, nic->device_enabled_once)) {
  3731. if (LINK_IS_UP(val64)) {
  3732. val64 = readq(&bar0->adapter_control);
  3733. val64 |= ADAPTER_CNTL_EN;
  3734. writeq(val64, &bar0->adapter_control);
  3735. if (CARDS_WITH_FAULTY_LINK_INDICATORS(subid)) {
  3736. val64 = readq(&bar0->gpio_control);
  3737. val64 |= GPIO_CTRL_GPIO_0;
  3738. writeq(val64, &bar0->gpio_control);
  3739. val64 = readq(&bar0->gpio_control);
  3740. } else {
  3741. val64 |= ADAPTER_LED_ON;
  3742. writeq(val64, &bar0->adapter_control);
  3743. }
  3744. val64 = readq(&bar0->adapter_status);
  3745. if (!LINK_IS_UP(val64)) {
  3746. DBG_PRINT(ERR_DBG, "%s:", dev->name);
  3747. DBG_PRINT(ERR_DBG, " Link down");
  3748. DBG_PRINT(ERR_DBG, "after ");
  3749. DBG_PRINT(ERR_DBG, "enabling ");
  3750. DBG_PRINT(ERR_DBG, "device \n");
  3751. }
  3752. if (nic->device_enabled_once == FALSE) {
  3753. nic->device_enabled_once = TRUE;
  3754. }
  3755. s2io_link(nic, LINK_UP);
  3756. } else {
  3757. if (CARDS_WITH_FAULTY_LINK_INDICATORS(subid)) {
  3758. val64 = readq(&bar0->gpio_control);
  3759. val64 &= ~GPIO_CTRL_GPIO_0;
  3760. writeq(val64, &bar0->gpio_control);
  3761. val64 = readq(&bar0->gpio_control);
  3762. }
  3763. s2io_link(nic, LINK_DOWN);
  3764. }
  3765. } else { /* NIC is not Quiescent. */
  3766. DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
  3767. DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
  3768. netif_stop_queue(dev);
  3769. }
  3770. clear_bit(0, &(nic->link_state));
  3771. }
  3772. static void s2io_card_down(nic_t * sp)
  3773. {
  3774. int cnt = 0;
  3775. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3776. unsigned long flags;
  3777. register u64 val64 = 0;
  3778. /* If s2io_set_link task is executing, wait till it completes. */
  3779. while (test_and_set_bit(0, &(sp->link_state)))
  3780. msleep(50);
  3781. atomic_set(&sp->card_state, CARD_DOWN);
  3782. /* disable Tx and Rx traffic on the NIC */
  3783. stop_nic(sp);
  3784. /* Kill tasklet. */
  3785. tasklet_kill(&sp->task);
  3786. /* Check if the device is Quiescent and then Reset the NIC */
  3787. do {
  3788. val64 = readq(&bar0->adapter_status);
  3789. if (verify_xena_quiescence(val64, sp->device_enabled_once)) {
  3790. break;
  3791. }
  3792. msleep(50);
  3793. cnt++;
  3794. if (cnt == 10) {
  3795. DBG_PRINT(ERR_DBG,
  3796. "s2io_close:Device not Quiescent ");
  3797. DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
  3798. (unsigned long long) val64);
  3799. break;
  3800. }
  3801. } while (1);
  3802. spin_lock_irqsave(&sp->tx_lock, flags);
  3803. s2io_reset(sp);
  3804. /* Free all unused Tx and Rx buffers */
  3805. free_tx_buffers(sp);
  3806. free_rx_buffers(sp);
  3807. spin_unlock_irqrestore(&sp->tx_lock, flags);
  3808. clear_bit(0, &(sp->link_state));
  3809. }
  3810. static int s2io_card_up(nic_t * sp)
  3811. {
  3812. int i, ret;
  3813. mac_info_t *mac_control;
  3814. struct config_param *config;
  3815. struct net_device *dev = (struct net_device *) sp->dev;
  3816. /* Initialize the H/W I/O registers */
  3817. if (init_nic(sp) != 0) {
  3818. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  3819. dev->name);
  3820. return -ENODEV;
  3821. }
  3822. /*
  3823. * Initializing the Rx buffers. For now we are considering only 1
  3824. * Rx ring and initializing buffers into 30 Rx blocks
  3825. */
  3826. mac_control = &sp->mac_control;
  3827. config = &sp->config;
  3828. for (i = 0; i < config->rx_ring_num; i++) {
  3829. if ((ret = fill_rx_buffers(sp, i))) {
  3830. DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
  3831. dev->name);
  3832. s2io_reset(sp);
  3833. free_rx_buffers(sp);
  3834. return -ENOMEM;
  3835. }
  3836. DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
  3837. atomic_read(&sp->rx_bufs_left[i]));
  3838. }
  3839. /* Setting its receive mode */
  3840. s2io_set_multicast(dev);
  3841. /* Enable tasklet for the device */
  3842. tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
  3843. /* Enable Rx Traffic and interrupts on the NIC */
  3844. if (start_nic(sp)) {
  3845. DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
  3846. tasklet_kill(&sp->task);
  3847. s2io_reset(sp);
  3848. free_irq(dev->irq, dev);
  3849. free_rx_buffers(sp);
  3850. return -ENODEV;
  3851. }
  3852. atomic_set(&sp->card_state, CARD_UP);
  3853. return 0;
  3854. }
  3855. /**
  3856. * s2io_restart_nic - Resets the NIC.
  3857. * @data : long pointer to the device private structure
  3858. * Description:
  3859. * This function is scheduled to be run by the s2io_tx_watchdog
  3860. * function after 0.5 secs to reset the NIC. The idea is to reduce
  3861. * the run time of the watch dog routine which is run holding a
  3862. * spin lock.
  3863. */
  3864. static void s2io_restart_nic(unsigned long data)
  3865. {
  3866. struct net_device *dev = (struct net_device *) data;
  3867. nic_t *sp = dev->priv;
  3868. s2io_card_down(sp);
  3869. if (s2io_card_up(sp)) {
  3870. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  3871. dev->name);
  3872. }
  3873. netif_wake_queue(dev);
  3874. DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
  3875. dev->name);
  3876. }
  3877. /**
  3878. * s2io_tx_watchdog - Watchdog for transmit side.
  3879. * @dev : Pointer to net device structure
  3880. * Description:
  3881. * This function is triggered if the Tx Queue is stopped
  3882. * for a pre-defined amount of time when the Interface is still up.
  3883. * If the Interface is jammed in such a situation, the hardware is
  3884. * reset (by s2io_close) and restarted again (by s2io_open) to
  3885. * overcome any problem that might have been caused in the hardware.
  3886. * Return value:
  3887. * void
  3888. */
  3889. static void s2io_tx_watchdog(struct net_device *dev)
  3890. {
  3891. nic_t *sp = dev->priv;
  3892. if (netif_carrier_ok(dev)) {
  3893. schedule_work(&sp->rst_timer_task);
  3894. }
  3895. }
  3896. /**
  3897. * rx_osm_handler - To perform some OS related operations on SKB.
  3898. * @sp: private member of the device structure,pointer to s2io_nic structure.
  3899. * @skb : the socket buffer pointer.
  3900. * @len : length of the packet
  3901. * @cksum : FCS checksum of the frame.
  3902. * @ring_no : the ring from which this RxD was extracted.
  3903. * Description:
  3904. * This function is called by the Tx interrupt serivce routine to perform
  3905. * some OS related operations on the SKB before passing it to the upper
  3906. * layers. It mainly checks if the checksum is OK, if so adds it to the
  3907. * SKBs cksum variable, increments the Rx packet count and passes the SKB
  3908. * to the upper layer. If the checksum is wrong, it increments the Rx
  3909. * packet error count, frees the SKB and returns error.
  3910. * Return value:
  3911. * SUCCESS on success and -1 on failure.
  3912. */
  3913. #ifndef CONFIG_2BUFF_MODE
  3914. static int rx_osm_handler(nic_t * sp, u16 len, RxD_t * rxdp, int ring_no)
  3915. #else
  3916. static int rx_osm_handler(nic_t * sp, RxD_t * rxdp, int ring_no,
  3917. buffAdd_t * ba)
  3918. #endif
  3919. {
  3920. struct net_device *dev = (struct net_device *) sp->dev;
  3921. struct sk_buff *skb =
  3922. (struct sk_buff *) ((unsigned long) rxdp->Host_Control);
  3923. u16 l3_csum, l4_csum;
  3924. #ifdef CONFIG_2BUFF_MODE
  3925. int buf0_len, buf2_len;
  3926. unsigned char *buff;
  3927. #endif
  3928. l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
  3929. if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && (sp->rx_csum)) {
  3930. l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  3931. if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
  3932. /*
  3933. * NIC verifies if the Checksum of the received
  3934. * frame is Ok or not and accordingly returns
  3935. * a flag in the RxD.
  3936. */
  3937. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3938. } else {
  3939. /*
  3940. * Packet with erroneous checksum, let the
  3941. * upper layers deal with it.
  3942. */
  3943. skb->ip_summed = CHECKSUM_NONE;
  3944. }
  3945. } else {
  3946. skb->ip_summed = CHECKSUM_NONE;
  3947. }
  3948. if (rxdp->Control_1 & RXD_T_CODE) {
  3949. unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
  3950. DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
  3951. dev->name, err);
  3952. }
  3953. #ifdef CONFIG_2BUFF_MODE
  3954. buf0_len = RXD_GET_BUFFER0_SIZE(rxdp->Control_2);
  3955. buf2_len = RXD_GET_BUFFER2_SIZE(rxdp->Control_2);
  3956. #endif
  3957. skb->dev = dev;
  3958. #ifndef CONFIG_2BUFF_MODE
  3959. skb_put(skb, len);
  3960. skb->protocol = eth_type_trans(skb, dev);
  3961. #else
  3962. buff = skb_push(skb, buf0_len);
  3963. memcpy(buff, ba->ba_0, buf0_len);
  3964. skb_put(skb, buf2_len);
  3965. skb->protocol = eth_type_trans(skb, dev);
  3966. #endif
  3967. #ifdef CONFIG_S2IO_NAPI
  3968. netif_receive_skb(skb);
  3969. #else
  3970. netif_rx(skb);
  3971. #endif
  3972. dev->last_rx = jiffies;
  3973. sp->rx_pkt_count++;
  3974. sp->stats.rx_packets++;
  3975. #ifndef CONFIG_2BUFF_MODE
  3976. sp->stats.rx_bytes += len;
  3977. #else
  3978. sp->stats.rx_bytes += buf0_len + buf2_len;
  3979. #endif
  3980. atomic_dec(&sp->rx_bufs_left[ring_no]);
  3981. rxdp->Host_Control = 0;
  3982. return SUCCESS;
  3983. }
  3984. /**
  3985. * s2io_link - stops/starts the Tx queue.
  3986. * @sp : private member of the device structure, which is a pointer to the
  3987. * s2io_nic structure.
  3988. * @link : inidicates whether link is UP/DOWN.
  3989. * Description:
  3990. * This function stops/starts the Tx queue depending on whether the link
  3991. * status of the NIC is is down or up. This is called by the Alarm
  3992. * interrupt handler whenever a link change interrupt comes up.
  3993. * Return value:
  3994. * void.
  3995. */
  3996. static void s2io_link(nic_t * sp, int link)
  3997. {
  3998. struct net_device *dev = (struct net_device *) sp->dev;
  3999. if (link != sp->last_link_state) {
  4000. if (link == LINK_DOWN) {
  4001. DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
  4002. netif_carrier_off(dev);
  4003. } else {
  4004. DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
  4005. netif_carrier_on(dev);
  4006. }
  4007. }
  4008. sp->last_link_state = link;
  4009. }
  4010. /**
  4011. * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
  4012. * @sp : private member of the device structure, which is a pointer to the
  4013. * s2io_nic structure.
  4014. * Description:
  4015. * This function initializes a few of the PCI and PCI-X configuration registers
  4016. * with recommended values.
  4017. * Return value:
  4018. * void
  4019. */
  4020. static void s2io_init_pci(nic_t * sp)
  4021. {
  4022. u16 pci_cmd = 0;
  4023. /* Enable Data Parity Error Recovery in PCI-X command register. */
  4024. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4025. &(sp->pcix_cmd));
  4026. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4027. (sp->pcix_cmd | 1));
  4028. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4029. &(sp->pcix_cmd));
  4030. /* Set the PErr Response bit in PCI command register. */
  4031. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  4032. pci_write_config_word(sp->pdev, PCI_COMMAND,
  4033. (pci_cmd | PCI_COMMAND_PARITY));
  4034. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  4035. /* Set MMRB count to 1024 in PCI-X Command register. */
  4036. sp->pcix_cmd &= 0xFFF3;
  4037. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, (sp->pcix_cmd | (0x1 << 2))); /* MMRBC 1K */
  4038. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4039. &(sp->pcix_cmd));
  4040. /* Setting Maximum outstanding splits based on system type. */
  4041. sp->pcix_cmd &= 0xFF8F;
  4042. sp->pcix_cmd |= XENA_MAX_OUTSTANDING_SPLITS(0x1); /* 2 splits. */
  4043. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4044. sp->pcix_cmd);
  4045. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4046. &(sp->pcix_cmd));
  4047. /* Forcibly disabling relaxed ordering capability of the card. */
  4048. sp->pcix_cmd &= 0xfffd;
  4049. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4050. sp->pcix_cmd);
  4051. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  4052. &(sp->pcix_cmd));
  4053. }
  4054. MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
  4055. MODULE_LICENSE("GPL");
  4056. module_param(tx_fifo_num, int, 0);
  4057. module_param_array(tx_fifo_len, int, NULL, 0);
  4058. module_param(rx_ring_num, int, 0);
  4059. module_param_array(rx_ring_sz, int, NULL, 0);
  4060. module_param(Stats_refresh_time, int, 0);
  4061. module_param(rmac_pause_time, int, 0);
  4062. module_param(mc_pause_threshold_q0q3, int, 0);
  4063. module_param(mc_pause_threshold_q4q7, int, 0);
  4064. module_param(shared_splits, int, 0);
  4065. module_param(tmac_util_period, int, 0);
  4066. module_param(rmac_util_period, int, 0);
  4067. #ifndef CONFIG_S2IO_NAPI
  4068. module_param(indicate_max_pkts, int, 0);
  4069. #endif
  4070. /**
  4071. * s2io_init_nic - Initialization of the adapter .
  4072. * @pdev : structure containing the PCI related information of the device.
  4073. * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
  4074. * Description:
  4075. * The function initializes an adapter identified by the pci_dec structure.
  4076. * All OS related initialization including memory and device structure and
  4077. * initlaization of the device private variable is done. Also the swapper
  4078. * control register is initialized to enable read and write into the I/O
  4079. * registers of the device.
  4080. * Return value:
  4081. * returns 0 on success and negative on failure.
  4082. */
  4083. static int __devinit
  4084. s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
  4085. {
  4086. nic_t *sp;
  4087. struct net_device *dev;
  4088. char *dev_name = "S2IO 10GE NIC";
  4089. int i, j, ret;
  4090. int dma_flag = FALSE;
  4091. u32 mac_up, mac_down;
  4092. u64 val64 = 0, tmp64 = 0;
  4093. XENA_dev_config_t __iomem *bar0 = NULL;
  4094. u16 subid;
  4095. mac_info_t *mac_control;
  4096. struct config_param *config;
  4097. DBG_PRINT(ERR_DBG, "Loading S2IO driver with %s\n",
  4098. s2io_driver_version);
  4099. if ((ret = pci_enable_device(pdev))) {
  4100. DBG_PRINT(ERR_DBG,
  4101. "s2io_init_nic: pci_enable_device failed\n");
  4102. return ret;
  4103. }
  4104. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  4105. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
  4106. dma_flag = TRUE;
  4107. if (pci_set_consistent_dma_mask
  4108. (pdev, DMA_64BIT_MASK)) {
  4109. DBG_PRINT(ERR_DBG,
  4110. "Unable to obtain 64bit DMA for \
  4111. consistent allocations\n");
  4112. pci_disable_device(pdev);
  4113. return -ENOMEM;
  4114. }
  4115. } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  4116. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
  4117. } else {
  4118. pci_disable_device(pdev);
  4119. return -ENOMEM;
  4120. }
  4121. if (pci_request_regions(pdev, s2io_driver_name)) {
  4122. DBG_PRINT(ERR_DBG, "Request Regions failed\n"),
  4123. pci_disable_device(pdev);
  4124. return -ENODEV;
  4125. }
  4126. dev = alloc_etherdev(sizeof(nic_t));
  4127. if (dev == NULL) {
  4128. DBG_PRINT(ERR_DBG, "Device allocation failed\n");
  4129. pci_disable_device(pdev);
  4130. pci_release_regions(pdev);
  4131. return -ENODEV;
  4132. }
  4133. pci_set_master(pdev);
  4134. pci_set_drvdata(pdev, dev);
  4135. SET_MODULE_OWNER(dev);
  4136. SET_NETDEV_DEV(dev, &pdev->dev);
  4137. /* Private member variable initialized to s2io NIC structure */
  4138. sp = dev->priv;
  4139. memset(sp, 0, sizeof(nic_t));
  4140. sp->dev = dev;
  4141. sp->pdev = pdev;
  4142. sp->vendor_id = pdev->vendor;
  4143. sp->device_id = pdev->device;
  4144. sp->high_dma_flag = dma_flag;
  4145. sp->irq = pdev->irq;
  4146. sp->device_enabled_once = FALSE;
  4147. strcpy(sp->name, dev_name);
  4148. /* Initialize some PCI/PCI-X fields of the NIC. */
  4149. s2io_init_pci(sp);
  4150. /*
  4151. * Setting the device configuration parameters.
  4152. * Most of these parameters can be specified by the user during
  4153. * module insertion as they are module loadable parameters. If
  4154. * these parameters are not not specified during load time, they
  4155. * are initialized with default values.
  4156. */
  4157. mac_control = &sp->mac_control;
  4158. config = &sp->config;
  4159. /* Tx side parameters. */
  4160. tx_fifo_len[0] = DEFAULT_FIFO_LEN; /* Default value. */
  4161. config->tx_fifo_num = tx_fifo_num;
  4162. for (i = 0; i < MAX_TX_FIFOS; i++) {
  4163. config->tx_cfg[i].fifo_len = tx_fifo_len[i];
  4164. config->tx_cfg[i].fifo_priority = i;
  4165. }
  4166. config->tx_intr_type = TXD_INT_TYPE_UTILZ;
  4167. for (i = 0; i < config->tx_fifo_num; i++) {
  4168. config->tx_cfg[i].f_no_snoop =
  4169. (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
  4170. if (config->tx_cfg[i].fifo_len < 65) {
  4171. config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
  4172. break;
  4173. }
  4174. }
  4175. config->max_txds = MAX_SKB_FRAGS;
  4176. /* Rx side parameters. */
  4177. rx_ring_sz[0] = SMALL_BLK_CNT; /* Default value. */
  4178. config->rx_ring_num = rx_ring_num;
  4179. for (i = 0; i < MAX_RX_RINGS; i++) {
  4180. config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
  4181. (MAX_RXDS_PER_BLOCK + 1);
  4182. config->rx_cfg[i].ring_priority = i;
  4183. }
  4184. for (i = 0; i < rx_ring_num; i++) {
  4185. config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
  4186. config->rx_cfg[i].f_no_snoop =
  4187. (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
  4188. }
  4189. /* Setting Mac Control parameters */
  4190. mac_control->rmac_pause_time = rmac_pause_time;
  4191. mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
  4192. mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
  4193. /* Initialize Ring buffer parameters. */
  4194. for (i = 0; i < config->rx_ring_num; i++)
  4195. atomic_set(&sp->rx_bufs_left[i], 0);
  4196. /* initialize the shared memory used by the NIC and the host */
  4197. if (init_shared_mem(sp)) {
  4198. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
  4199. dev->name);
  4200. ret = -ENOMEM;
  4201. goto mem_alloc_failed;
  4202. }
  4203. sp->bar0 = ioremap(pci_resource_start(pdev, 0),
  4204. pci_resource_len(pdev, 0));
  4205. if (!sp->bar0) {
  4206. DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",
  4207. dev->name);
  4208. ret = -ENOMEM;
  4209. goto bar0_remap_failed;
  4210. }
  4211. sp->bar1 = ioremap(pci_resource_start(pdev, 2),
  4212. pci_resource_len(pdev, 2));
  4213. if (!sp->bar1) {
  4214. DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",
  4215. dev->name);
  4216. ret = -ENOMEM;
  4217. goto bar1_remap_failed;
  4218. }
  4219. dev->irq = pdev->irq;
  4220. dev->base_addr = (unsigned long) sp->bar0;
  4221. /* Initializing the BAR1 address as the start of the FIFO pointer. */
  4222. for (j = 0; j < MAX_TX_FIFOS; j++) {
  4223. mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)
  4224. (sp->bar1 + (j * 0x00020000));
  4225. }
  4226. /* Driver entry points */
  4227. dev->open = &s2io_open;
  4228. dev->stop = &s2io_close;
  4229. dev->hard_start_xmit = &s2io_xmit;
  4230. dev->get_stats = &s2io_get_stats;
  4231. dev->set_multicast_list = &s2io_set_multicast;
  4232. dev->do_ioctl = &s2io_ioctl;
  4233. dev->change_mtu = &s2io_change_mtu;
  4234. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  4235. /*
  4236. * will use eth_mac_addr() for dev->set_mac_address
  4237. * mac address will be set every time dev->open() is called
  4238. */
  4239. #ifdef CONFIG_S2IO_NAPI
  4240. dev->poll = s2io_poll;
  4241. dev->weight = 90;
  4242. #endif
  4243. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  4244. if (sp->high_dma_flag == TRUE)
  4245. dev->features |= NETIF_F_HIGHDMA;
  4246. #ifdef NETIF_F_TSO
  4247. dev->features |= NETIF_F_TSO;
  4248. #endif
  4249. dev->tx_timeout = &s2io_tx_watchdog;
  4250. dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
  4251. INIT_WORK(&sp->rst_timer_task,
  4252. (void (*)(void *)) s2io_restart_nic, dev);
  4253. INIT_WORK(&sp->set_link_task,
  4254. (void (*)(void *)) s2io_set_link, sp);
  4255. pci_save_state(sp->pdev);
  4256. /* Setting swapper control on the NIC, for proper reset operation */
  4257. if (s2io_set_swapper(sp)) {
  4258. DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
  4259. dev->name);
  4260. ret = -EAGAIN;
  4261. goto set_swap_failed;
  4262. }
  4263. /* Fix for all "FFs" MAC address problems observed on Alpha platforms */
  4264. fix_mac_address(sp);
  4265. s2io_reset(sp);
  4266. /*
  4267. * Setting swapper control on the NIC, so the MAC address can be read.
  4268. */
  4269. if (s2io_set_swapper(sp)) {
  4270. DBG_PRINT(ERR_DBG,
  4271. "%s: S2IO: swapper settings are wrong\n",
  4272. dev->name);
  4273. ret = -EAGAIN;
  4274. goto set_swap_failed;
  4275. }
  4276. /*
  4277. * MAC address initialization.
  4278. * For now only one mac address will be read and used.
  4279. */
  4280. bar0 = sp->bar0;
  4281. val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4282. RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
  4283. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4284. wait_for_cmd_complete(sp);
  4285. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  4286. mac_down = (u32) tmp64;
  4287. mac_up = (u32) (tmp64 >> 32);
  4288. memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
  4289. sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
  4290. sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
  4291. sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
  4292. sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
  4293. sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
  4294. sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
  4295. DBG_PRINT(INIT_DBG,
  4296. "DEFAULT MAC ADDR:0x%02x-%02x-%02x-%02x-%02x-%02x\n",
  4297. sp->def_mac_addr[0].mac_addr[0],
  4298. sp->def_mac_addr[0].mac_addr[1],
  4299. sp->def_mac_addr[0].mac_addr[2],
  4300. sp->def_mac_addr[0].mac_addr[3],
  4301. sp->def_mac_addr[0].mac_addr[4],
  4302. sp->def_mac_addr[0].mac_addr[5]);
  4303. /* Set the factory defined MAC address initially */
  4304. dev->addr_len = ETH_ALEN;
  4305. memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
  4306. /*
  4307. * Initialize the tasklet status and link state flags
  4308. * and the card statte parameter
  4309. */
  4310. atomic_set(&(sp->card_state), 0);
  4311. sp->tasklet_status = 0;
  4312. sp->link_state = 0;
  4313. /* Initialize spinlocks */
  4314. spin_lock_init(&sp->tx_lock);
  4315. #ifndef CONFIG_S2IO_NAPI
  4316. spin_lock_init(&sp->put_lock);
  4317. #endif
  4318. /*
  4319. * SXE-002: Configure link and activity LED to init state
  4320. * on driver load.
  4321. */
  4322. subid = sp->pdev->subsystem_device;
  4323. if ((subid & 0xFF) >= 0x07) {
  4324. val64 = readq(&bar0->gpio_control);
  4325. val64 |= 0x0000800000000000ULL;
  4326. writeq(val64, &bar0->gpio_control);
  4327. val64 = 0x0411040400000000ULL;
  4328. writeq(val64, (void __iomem *) bar0 + 0x2700);
  4329. val64 = readq(&bar0->gpio_control);
  4330. }
  4331. sp->rx_csum = 1; /* Rx chksum verify enabled by default */
  4332. if (register_netdev(dev)) {
  4333. DBG_PRINT(ERR_DBG, "Device registration failed\n");
  4334. ret = -ENODEV;
  4335. goto register_failed;
  4336. }
  4337. /*
  4338. * Make Link state as off at this point, when the Link change
  4339. * interrupt comes the state will be automatically changed to
  4340. * the right state.
  4341. */
  4342. netif_carrier_off(dev);
  4343. sp->last_link_state = LINK_DOWN;
  4344. return 0;
  4345. register_failed:
  4346. set_swap_failed:
  4347. iounmap(sp->bar1);
  4348. bar1_remap_failed:
  4349. iounmap(sp->bar0);
  4350. bar0_remap_failed:
  4351. mem_alloc_failed:
  4352. free_shared_mem(sp);
  4353. pci_disable_device(pdev);
  4354. pci_release_regions(pdev);
  4355. pci_set_drvdata(pdev, NULL);
  4356. free_netdev(dev);
  4357. return ret;
  4358. }
  4359. /**
  4360. * s2io_rem_nic - Free the PCI device
  4361. * @pdev: structure containing the PCI related information of the device.
  4362. * Description: This function is called by the Pci subsystem to release a
  4363. * PCI device and free up all resource held up by the device. This could
  4364. * be in response to a Hot plug event or when the driver is to be removed
  4365. * from memory.
  4366. */
  4367. static void __devexit s2io_rem_nic(struct pci_dev *pdev)
  4368. {
  4369. struct net_device *dev =
  4370. (struct net_device *) pci_get_drvdata(pdev);
  4371. nic_t *sp;
  4372. if (dev == NULL) {
  4373. DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
  4374. return;
  4375. }
  4376. sp = dev->priv;
  4377. unregister_netdev(dev);
  4378. free_shared_mem(sp);
  4379. iounmap(sp->bar0);
  4380. iounmap(sp->bar1);
  4381. pci_disable_device(pdev);
  4382. pci_release_regions(pdev);
  4383. pci_set_drvdata(pdev, NULL);
  4384. free_netdev(dev);
  4385. }
  4386. /**
  4387. * s2io_starter - Entry point for the driver
  4388. * Description: This function is the entry point for the driver. It verifies
  4389. * the module loadable parameters and initializes PCI configuration space.
  4390. */
  4391. int __init s2io_starter(void)
  4392. {
  4393. return pci_module_init(&s2io_driver);
  4394. }
  4395. /**
  4396. * s2io_closer - Cleanup routine for the driver
  4397. * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
  4398. */
  4399. static void s2io_closer(void)
  4400. {
  4401. pci_unregister_driver(&s2io_driver);
  4402. DBG_PRINT(INIT_DBG, "cleanup done\n");
  4403. }
  4404. module_init(s2io_starter);
  4405. module_exit(s2io_closer);