s2io.c 145 KB

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