s2io.c 158 KB

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