s2io.c 141 KB

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