s2io.c 159 KB

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