s2io.c 153 KB

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