skge.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249
  1. /******************************************************************************
  2. *
  3. * Name: skge.c
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.45 $
  6. * Date: $Date: 2004/02/12 14:41:02 $
  7. * Purpose: The main driver source module
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2002 SysKonnect GmbH.
  13. * (C)Copyright 2002-2003 Marvell.
  14. *
  15. * Driver for Marvell Yukon chipset and SysKonnect Gigabit Ethernet
  16. * Server Adapters.
  17. *
  18. * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
  19. * SysKonnects GEnesis Solaris driver
  20. * Author: Christoph Goos (cgoos@syskonnect.de)
  21. * Mirko Lindner (mlindner@syskonnect.de)
  22. *
  23. * Address all question to: linux@syskonnect.de
  24. *
  25. * The technical manual for the adapters is available from SysKonnect's
  26. * web pages: www.syskonnect.com
  27. * Goto "Support" and search Knowledge Base for "manual".
  28. *
  29. * This program is free software; you can redistribute it and/or modify
  30. * it under the terms of the GNU General Public License as published by
  31. * the Free Software Foundation; either version 2 of the License, or
  32. * (at your option) any later version.
  33. *
  34. * The information in this file is provided "AS IS" without warranty.
  35. *
  36. ******************************************************************************/
  37. /******************************************************************************
  38. *
  39. * Possible compiler options (#define xxx / -Dxxx):
  40. *
  41. * debugging can be enable by changing SK_DEBUG_CHKMOD and
  42. * SK_DEBUG_CHKCAT in makefile (described there).
  43. *
  44. ******************************************************************************/
  45. /******************************************************************************
  46. *
  47. * Description:
  48. *
  49. * This is the main module of the Linux GE driver.
  50. *
  51. * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
  52. * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
  53. * Those are used for drivers on multiple OS', so some thing may seem
  54. * unnecessary complicated on Linux. Please do not try to 'clean up'
  55. * them without VERY good reasons, because this will make it more
  56. * difficult to keep the Linux driver in synchronisation with the
  57. * other versions.
  58. *
  59. * Include file hierarchy:
  60. *
  61. * <linux/module.h>
  62. *
  63. * "h/skdrv1st.h"
  64. * <linux/types.h>
  65. * <linux/kernel.h>
  66. * <linux/string.h>
  67. * <linux/errno.h>
  68. * <linux/ioport.h>
  69. * <linux/slab.h>
  70. * <linux/interrupt.h>
  71. * <linux/pci.h>
  72. * <linux/bitops.h>
  73. * <asm/byteorder.h>
  74. * <asm/io.h>
  75. * <linux/netdevice.h>
  76. * <linux/etherdevice.h>
  77. * <linux/skbuff.h>
  78. * those three depending on kernel version used:
  79. * <linux/bios32.h>
  80. * <linux/init.h>
  81. * <asm/uaccess.h>
  82. * <net/checksum.h>
  83. *
  84. * "h/skerror.h"
  85. * "h/skdebug.h"
  86. * "h/sktypes.h"
  87. * "h/lm80.h"
  88. * "h/xmac_ii.h"
  89. *
  90. * "h/skdrv2nd.h"
  91. * "h/skqueue.h"
  92. * "h/skgehwt.h"
  93. * "h/sktimer.h"
  94. * "h/ski2c.h"
  95. * "h/skgepnmi.h"
  96. * "h/skvpd.h"
  97. * "h/skgehw.h"
  98. * "h/skgeinit.h"
  99. * "h/skaddr.h"
  100. * "h/skgesirq.h"
  101. * "h/skcsum.h"
  102. * "h/skrlmt.h"
  103. *
  104. ******************************************************************************/
  105. #include "h/skversion.h"
  106. #include <linux/module.h>
  107. #include <linux/moduleparam.h>
  108. #include <linux/init.h>
  109. #include <linux/proc_fs.h>
  110. #include "h/skdrv1st.h"
  111. #include "h/skdrv2nd.h"
  112. /*******************************************************************************
  113. *
  114. * Defines
  115. *
  116. ******************************************************************************/
  117. /* for debuging on x86 only */
  118. /* #define BREAKPOINT() asm(" int $3"); */
  119. /* use the transmit hw checksum driver functionality */
  120. #define USE_SK_TX_CHECKSUM
  121. /* use the receive hw checksum driver functionality */
  122. #define USE_SK_RX_CHECKSUM
  123. /* use the scatter-gather functionality with sendfile() */
  124. #define SK_ZEROCOPY
  125. /* use of a transmit complete interrupt */
  126. #define USE_TX_COMPLETE
  127. /*
  128. * threshold for copying small receive frames
  129. * set to 0 to avoid copying, set to 9001 to copy all frames
  130. */
  131. #define SK_COPY_THRESHOLD 50
  132. /* number of adapters that can be configured via command line params */
  133. #define SK_MAX_CARD_PARAM 16
  134. /*
  135. * use those defines for a compile-in version of the driver instead
  136. * of command line parameters
  137. */
  138. // #define LINK_SPEED_A {"Auto", }
  139. // #define LINK_SPEED_B {"Auto", }
  140. // #define AUTO_NEG_A {"Sense", }
  141. // #define AUTO_NEG_B {"Sense", }
  142. // #define DUP_CAP_A {"Both", }
  143. // #define DUP_CAP_B {"Both", }
  144. // #define FLOW_CTRL_A {"SymOrRem", }
  145. // #define FLOW_CTRL_B {"SymOrRem", }
  146. // #define ROLE_A {"Auto", }
  147. // #define ROLE_B {"Auto", }
  148. // #define PREF_PORT {"A", }
  149. // #define CON_TYPE {"Auto", }
  150. // #define RLMT_MODE {"CheckLinkState", }
  151. #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
  152. #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
  153. #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
  154. /* Set blink mode*/
  155. #define OEM_CONFIG_VALUE ( SK_ACT_LED_BLINK | \
  156. SK_DUP_LED_NORMAL | \
  157. SK_LED_LINK100_ON)
  158. /* Isr return value */
  159. #define SkIsrRetVar irqreturn_t
  160. #define SkIsrRetNone IRQ_NONE
  161. #define SkIsrRetHandled IRQ_HANDLED
  162. /*******************************************************************************
  163. *
  164. * Local Function Prototypes
  165. *
  166. ******************************************************************************/
  167. static void FreeResources(struct SK_NET_DEVICE *dev);
  168. static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
  169. static SK_BOOL BoardAllocMem(SK_AC *pAC);
  170. static void BoardFreeMem(SK_AC *pAC);
  171. static void BoardInitMem(SK_AC *pAC);
  172. static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**, int*, SK_BOOL);
  173. static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
  174. static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
  175. static int SkGeOpen(struct SK_NET_DEVICE *dev);
  176. static int SkGeClose(struct SK_NET_DEVICE *dev);
  177. static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
  178. static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
  179. static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
  180. static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
  181. static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
  182. static void GetConfiguration(SK_AC*);
  183. static void ProductStr(SK_AC*);
  184. static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
  185. static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
  186. static void FillRxRing(SK_AC*, RX_PORT*);
  187. static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
  188. static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
  189. static void ClearAndStartRx(SK_AC*, int);
  190. static void ClearTxIrq(SK_AC*, int, int);
  191. static void ClearRxRing(SK_AC*, RX_PORT*);
  192. static void ClearTxRing(SK_AC*, TX_PORT*);
  193. static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
  194. static void PortReInitBmu(SK_AC*, int);
  195. static int SkGeIocMib(DEV_NET*, unsigned int, int);
  196. static int SkGeInitPCI(SK_AC *pAC);
  197. static void StartDrvCleanupTimer(SK_AC *pAC);
  198. static void StopDrvCleanupTimer(SK_AC *pAC);
  199. static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
  200. #ifdef SK_DIAG_SUPPORT
  201. static SK_U32 ParseDeviceNbrFromSlotName(const char *SlotName);
  202. static int SkDrvInitAdapter(SK_AC *pAC, int devNbr);
  203. static int SkDrvDeInitAdapter(SK_AC *pAC, int devNbr);
  204. #endif
  205. /*******************************************************************************
  206. *
  207. * Extern Function Prototypes
  208. *
  209. ******************************************************************************/
  210. static const char SKRootName[] = "sk98lin";
  211. static struct proc_dir_entry *pSkRootDir;
  212. extern struct file_operations sk_proc_fops;
  213. static inline void SkGeProcCreate(struct net_device *dev)
  214. {
  215. struct proc_dir_entry *pe;
  216. if (pSkRootDir &&
  217. (pe = create_proc_entry(dev->name, S_IRUGO, pSkRootDir))) {
  218. pe->proc_fops = &sk_proc_fops;
  219. pe->data = dev;
  220. pe->owner = THIS_MODULE;
  221. }
  222. }
  223. static inline void SkGeProcRemove(struct net_device *dev)
  224. {
  225. if (pSkRootDir)
  226. remove_proc_entry(dev->name, pSkRootDir);
  227. }
  228. extern void SkDimEnableModerationIfNeeded(SK_AC *pAC);
  229. extern void SkDimDisplayModerationSettings(SK_AC *pAC);
  230. extern void SkDimStartModerationTimer(SK_AC *pAC);
  231. extern void SkDimModerate(SK_AC *pAC);
  232. extern void SkGeBlinkTimer(unsigned long data);
  233. #ifdef DEBUG
  234. static void DumpMsg(struct sk_buff*, char*);
  235. static void DumpData(char*, int);
  236. static void DumpLong(char*, int);
  237. #endif
  238. /* global variables *********************************************************/
  239. static SK_BOOL DoPrintInterfaceChange = SK_TRUE;
  240. extern struct ethtool_ops SkGeEthtoolOps;
  241. /* local variables **********************************************************/
  242. static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
  243. static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
  244. /*****************************************************************************
  245. *
  246. * SkGeInitPCI - Init the PCI resources
  247. *
  248. * Description:
  249. * This function initialize the PCI resources and IO
  250. *
  251. * Returns: N/A
  252. *
  253. */
  254. int SkGeInitPCI(SK_AC *pAC)
  255. {
  256. struct SK_NET_DEVICE *dev = pAC->dev[0];
  257. struct pci_dev *pdev = pAC->PciDev;
  258. int retval;
  259. if (pci_enable_device(pdev) != 0) {
  260. return 1;
  261. }
  262. dev->mem_start = pci_resource_start (pdev, 0);
  263. pci_set_master(pdev);
  264. if (pci_request_regions(pdev, pAC->Name) != 0) {
  265. retval = 2;
  266. goto out_disable;
  267. }
  268. #ifdef SK_BIG_ENDIAN
  269. /*
  270. * On big endian machines, we use the adapter's aibility of
  271. * reading the descriptors as big endian.
  272. */
  273. {
  274. SK_U32 our2;
  275. SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
  276. our2 |= PCI_REV_DESC;
  277. SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
  278. }
  279. #endif
  280. /*
  281. * Remap the regs into kernel space.
  282. */
  283. pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
  284. if (!pAC->IoBase){
  285. retval = 3;
  286. goto out_release;
  287. }
  288. return 0;
  289. out_release:
  290. pci_release_regions(pdev);
  291. out_disable:
  292. pci_disable_device(pdev);
  293. return retval;
  294. }
  295. /*****************************************************************************
  296. *
  297. * FreeResources - release resources allocated for adapter
  298. *
  299. * Description:
  300. * This function releases the IRQ, unmaps the IO and
  301. * frees the desriptor ring.
  302. *
  303. * Returns: N/A
  304. *
  305. */
  306. static void FreeResources(struct SK_NET_DEVICE *dev)
  307. {
  308. SK_U32 AllocFlag;
  309. DEV_NET *pNet;
  310. SK_AC *pAC;
  311. pNet = netdev_priv(dev);
  312. pAC = pNet->pAC;
  313. AllocFlag = pAC->AllocFlag;
  314. if (pAC->PciDev) {
  315. pci_release_regions(pAC->PciDev);
  316. }
  317. if (AllocFlag & SK_ALLOC_IRQ) {
  318. free_irq(dev->irq, dev);
  319. }
  320. if (pAC->IoBase) {
  321. iounmap(pAC->IoBase);
  322. }
  323. if (pAC->pDescrMem) {
  324. BoardFreeMem(pAC);
  325. }
  326. } /* FreeResources */
  327. MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
  328. MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
  329. MODULE_LICENSE("GPL");
  330. #ifdef LINK_SPEED_A
  331. static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
  332. #else
  333. static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
  334. #endif
  335. #ifdef LINK_SPEED_B
  336. static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
  337. #else
  338. static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
  339. #endif
  340. #ifdef AUTO_NEG_A
  341. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
  342. #else
  343. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
  344. #endif
  345. #ifdef DUP_CAP_A
  346. static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
  347. #else
  348. static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
  349. #endif
  350. #ifdef FLOW_CTRL_A
  351. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
  352. #else
  353. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
  354. #endif
  355. #ifdef ROLE_A
  356. static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
  357. #else
  358. static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
  359. #endif
  360. #ifdef AUTO_NEG_B
  361. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
  362. #else
  363. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
  364. #endif
  365. #ifdef DUP_CAP_B
  366. static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
  367. #else
  368. static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
  369. #endif
  370. #ifdef FLOW_CTRL_B
  371. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
  372. #else
  373. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
  374. #endif
  375. #ifdef ROLE_B
  376. static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
  377. #else
  378. static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
  379. #endif
  380. #ifdef CON_TYPE
  381. static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
  382. #else
  383. static char *ConType[SK_MAX_CARD_PARAM] = {"", };
  384. #endif
  385. #ifdef PREF_PORT
  386. static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
  387. #else
  388. static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
  389. #endif
  390. #ifdef RLMT_MODE
  391. static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
  392. #else
  393. static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
  394. #endif
  395. static int IntsPerSec[SK_MAX_CARD_PARAM];
  396. static char *Moderation[SK_MAX_CARD_PARAM];
  397. static char *ModerationMask[SK_MAX_CARD_PARAM];
  398. static char *AutoSizing[SK_MAX_CARD_PARAM];
  399. static char *Stats[SK_MAX_CARD_PARAM];
  400. module_param_array(Speed_A, charp, NULL, 0);
  401. module_param_array(Speed_B, charp, NULL, 0);
  402. module_param_array(AutoNeg_A, charp, NULL, 0);
  403. module_param_array(AutoNeg_B, charp, NULL, 0);
  404. module_param_array(DupCap_A, charp, NULL, 0);
  405. module_param_array(DupCap_B, charp, NULL, 0);
  406. module_param_array(FlowCtrl_A, charp, NULL, 0);
  407. module_param_array(FlowCtrl_B, charp, NULL, 0);
  408. module_param_array(Role_A, charp, NULL, 0);
  409. module_param_array(Role_B, charp, NULL, 0);
  410. module_param_array(ConType, charp, NULL, 0);
  411. module_param_array(PrefPort, charp, NULL, 0);
  412. module_param_array(RlmtMode, charp, NULL, 0);
  413. /* used for interrupt moderation */
  414. module_param_array(IntsPerSec, int, NULL, 0);
  415. module_param_array(Moderation, charp, NULL, 0);
  416. module_param_array(Stats, charp, NULL, 0);
  417. module_param_array(ModerationMask, charp, NULL, 0);
  418. module_param_array(AutoSizing, charp, NULL, 0);
  419. /*****************************************************************************
  420. *
  421. * SkGeBoardInit - do level 0 and 1 initialization
  422. *
  423. * Description:
  424. * This function prepares the board hardware for running. The desriptor
  425. * ring is set up, the IRQ is allocated and the configuration settings
  426. * are examined.
  427. *
  428. * Returns:
  429. * 0, if everything is ok
  430. * !=0, on error
  431. */
  432. static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
  433. {
  434. short i;
  435. unsigned long Flags;
  436. char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
  437. char *VerStr = VER_STRING;
  438. int Ret; /* return code of request_irq */
  439. SK_BOOL DualNet;
  440. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  441. ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
  442. for (i=0; i<SK_MAX_MACS; i++) {
  443. pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
  444. pAC->TxPort[i][0].PortIndex = i;
  445. pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
  446. pAC->RxPort[i].PortIndex = i;
  447. }
  448. /* Initialize the mutexes */
  449. for (i=0; i<SK_MAX_MACS; i++) {
  450. spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
  451. spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
  452. }
  453. spin_lock_init(&pAC->SlowPathLock);
  454. /* setup phy_id blink timer */
  455. pAC->BlinkTimer.function = SkGeBlinkTimer;
  456. pAC->BlinkTimer.data = (unsigned long) dev;
  457. init_timer(&pAC->BlinkTimer);
  458. /* level 0 init common modules here */
  459. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  460. /* Does a RESET on board ...*/
  461. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
  462. printk("HWInit (0) failed.\n");
  463. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  464. return(-EAGAIN);
  465. }
  466. SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
  467. SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
  468. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
  469. SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
  470. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
  471. SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
  472. pAC->BoardLevel = SK_INIT_DATA;
  473. pAC->RxBufSize = ETH_BUF_SIZE;
  474. SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
  475. SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
  476. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  477. /* level 1 init common modules here (HW init) */
  478. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  479. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
  480. printk("sk98lin: HWInit (1) failed.\n");
  481. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  482. return(-EAGAIN);
  483. }
  484. SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
  485. SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
  486. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
  487. SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
  488. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
  489. SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
  490. /* Set chipset type support */
  491. pAC->ChipsetType = 0;
  492. if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
  493. (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
  494. pAC->ChipsetType = 1;
  495. }
  496. GetConfiguration(pAC);
  497. if (pAC->RlmtNets == 2) {
  498. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  499. }
  500. pAC->BoardLevel = SK_INIT_IO;
  501. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  502. if (pAC->GIni.GIMacsFound == 2) {
  503. Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
  504. } else if (pAC->GIni.GIMacsFound == 1) {
  505. Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
  506. pAC->Name, dev);
  507. } else {
  508. printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
  509. pAC->GIni.GIMacsFound);
  510. return -EAGAIN;
  511. }
  512. if (Ret) {
  513. printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
  514. dev->irq);
  515. return -EAGAIN;
  516. }
  517. pAC->AllocFlag |= SK_ALLOC_IRQ;
  518. /* Alloc memory for this board (Mem for RxD/TxD) : */
  519. if(!BoardAllocMem(pAC)) {
  520. printk("No memory for descriptor rings.\n");
  521. return(-EAGAIN);
  522. }
  523. SkCsSetReceiveFlags(pAC,
  524. SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
  525. &pAC->CsOfs1, &pAC->CsOfs2, 0);
  526. pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
  527. BoardInitMem(pAC);
  528. /* tschilling: New common function with minimum size check. */
  529. DualNet = SK_FALSE;
  530. if (pAC->RlmtNets == 2) {
  531. DualNet = SK_TRUE;
  532. }
  533. if (SkGeInitAssignRamToQueues(
  534. pAC,
  535. pAC->ActivePort,
  536. DualNet)) {
  537. BoardFreeMem(pAC);
  538. printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
  539. return(-EAGAIN);
  540. }
  541. return (0);
  542. } /* SkGeBoardInit */
  543. /*****************************************************************************
  544. *
  545. * BoardAllocMem - allocate the memory for the descriptor rings
  546. *
  547. * Description:
  548. * This function allocates the memory for all descriptor rings.
  549. * Each ring is aligned for the desriptor alignment and no ring
  550. * has a 4 GByte boundary in it (because the upper 32 bit must
  551. * be constant for all descriptiors in one rings).
  552. *
  553. * Returns:
  554. * SK_TRUE, if all memory could be allocated
  555. * SK_FALSE, if not
  556. */
  557. static SK_BOOL BoardAllocMem(
  558. SK_AC *pAC)
  559. {
  560. caddr_t pDescrMem; /* pointer to descriptor memory area */
  561. size_t AllocLength; /* length of complete descriptor area */
  562. int i; /* loop counter */
  563. unsigned long BusAddr;
  564. /* rings plus one for alignment (do not cross 4 GB boundary) */
  565. /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
  566. #if (BITS_PER_LONG == 32)
  567. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  568. #else
  569. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  570. + RX_RING_SIZE + 8;
  571. #endif
  572. pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
  573. &pAC->pDescrMemDMA);
  574. if (pDescrMem == NULL) {
  575. return (SK_FALSE);
  576. }
  577. pAC->pDescrMem = pDescrMem;
  578. BusAddr = (unsigned long) pAC->pDescrMemDMA;
  579. /* Descriptors need 8 byte alignment, and this is ensured
  580. * by pci_alloc_consistent.
  581. */
  582. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  583. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  584. ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
  585. i, (unsigned long) pDescrMem,
  586. BusAddr));
  587. pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
  588. pAC->TxPort[i][0].VTxDescrRing = BusAddr;
  589. pDescrMem += TX_RING_SIZE;
  590. BusAddr += TX_RING_SIZE;
  591. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  592. ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
  593. i, (unsigned long) pDescrMem,
  594. (unsigned long)BusAddr));
  595. pAC->RxPort[i].pRxDescrRing = pDescrMem;
  596. pAC->RxPort[i].VRxDescrRing = BusAddr;
  597. pDescrMem += RX_RING_SIZE;
  598. BusAddr += RX_RING_SIZE;
  599. } /* for */
  600. return (SK_TRUE);
  601. } /* BoardAllocMem */
  602. /****************************************************************************
  603. *
  604. * BoardFreeMem - reverse of BoardAllocMem
  605. *
  606. * Description:
  607. * Free all memory allocated in BoardAllocMem: adapter context,
  608. * descriptor rings, locks.
  609. *
  610. * Returns: N/A
  611. */
  612. static void BoardFreeMem(
  613. SK_AC *pAC)
  614. {
  615. size_t AllocLength; /* length of complete descriptor area */
  616. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  617. ("BoardFreeMem\n"));
  618. #if (BITS_PER_LONG == 32)
  619. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  620. #else
  621. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  622. + RX_RING_SIZE + 8;
  623. #endif
  624. pci_free_consistent(pAC->PciDev, AllocLength,
  625. pAC->pDescrMem, pAC->pDescrMemDMA);
  626. pAC->pDescrMem = NULL;
  627. } /* BoardFreeMem */
  628. /*****************************************************************************
  629. *
  630. * BoardInitMem - initiate the descriptor rings
  631. *
  632. * Description:
  633. * This function sets the descriptor rings up in memory.
  634. * The adapter is initialized with the descriptor start addresses.
  635. *
  636. * Returns: N/A
  637. */
  638. static void BoardInitMem(
  639. SK_AC *pAC) /* pointer to adapter context */
  640. {
  641. int i; /* loop counter */
  642. int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
  643. int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
  644. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  645. ("BoardInitMem\n"));
  646. RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  647. pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
  648. TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  649. pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
  650. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  651. SetupRing(
  652. pAC,
  653. pAC->TxPort[i][0].pTxDescrRing,
  654. pAC->TxPort[i][0].VTxDescrRing,
  655. (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
  656. (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
  657. (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
  658. &pAC->TxPort[i][0].TxdRingFree,
  659. SK_TRUE);
  660. SetupRing(
  661. pAC,
  662. pAC->RxPort[i].pRxDescrRing,
  663. pAC->RxPort[i].VRxDescrRing,
  664. &pAC->RxPort[i].pRxdRingHead,
  665. &pAC->RxPort[i].pRxdRingTail,
  666. &pAC->RxPort[i].pRxdRingPrev,
  667. &pAC->RxPort[i].RxdRingFree,
  668. SK_FALSE);
  669. }
  670. } /* BoardInitMem */
  671. /*****************************************************************************
  672. *
  673. * SetupRing - create one descriptor ring
  674. *
  675. * Description:
  676. * This function creates one descriptor ring in the given memory area.
  677. * The head, tail and number of free descriptors in the ring are set.
  678. *
  679. * Returns:
  680. * none
  681. */
  682. static void SetupRing(
  683. SK_AC *pAC,
  684. void *pMemArea, /* a pointer to the memory area for the ring */
  685. uintptr_t VMemArea, /* the virtual bus address of the memory area */
  686. RXD **ppRingHead, /* address where the head should be written */
  687. RXD **ppRingTail, /* address where the tail should be written */
  688. RXD **ppRingPrev, /* address where the tail should be written */
  689. int *pRingFree, /* address where the # of free descr. goes */
  690. SK_BOOL IsTx) /* flag: is this a tx ring */
  691. {
  692. int i; /* loop counter */
  693. int DescrSize; /* the size of a descriptor rounded up to alignment*/
  694. int DescrNum; /* number of descriptors per ring */
  695. RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
  696. RXD *pNextDescr; /* pointer to the next descriptor */
  697. RXD *pPrevDescr; /* pointer to the previous descriptor */
  698. uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
  699. if (IsTx == SK_TRUE) {
  700. DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
  701. DESCR_ALIGN;
  702. DescrNum = TX_RING_SIZE / DescrSize;
  703. } else {
  704. DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
  705. DESCR_ALIGN;
  706. DescrNum = RX_RING_SIZE / DescrSize;
  707. }
  708. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  709. ("Descriptor size: %d Descriptor Number: %d\n",
  710. DescrSize,DescrNum));
  711. pDescr = (RXD*) pMemArea;
  712. pPrevDescr = NULL;
  713. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  714. VNextDescr = VMemArea + DescrSize;
  715. for(i=0; i<DescrNum; i++) {
  716. /* set the pointers right */
  717. pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
  718. pDescr->pNextRxd = pNextDescr;
  719. pDescr->TcpSumStarts = pAC->CsOfs;
  720. /* advance one step */
  721. pPrevDescr = pDescr;
  722. pDescr = pNextDescr;
  723. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  724. VNextDescr += DescrSize;
  725. }
  726. pPrevDescr->pNextRxd = (RXD*) pMemArea;
  727. pPrevDescr->VNextRxd = VMemArea;
  728. pDescr = (RXD*) pMemArea;
  729. *ppRingHead = (RXD*) pMemArea;
  730. *ppRingTail = *ppRingHead;
  731. *ppRingPrev = pPrevDescr;
  732. *pRingFree = DescrNum;
  733. } /* SetupRing */
  734. /*****************************************************************************
  735. *
  736. * PortReInitBmu - re-initiate the descriptor rings for one port
  737. *
  738. * Description:
  739. * This function reinitializes the descriptor rings of one port
  740. * in memory. The port must be stopped before.
  741. * The HW is initialized with the descriptor start addresses.
  742. *
  743. * Returns:
  744. * none
  745. */
  746. static void PortReInitBmu(
  747. SK_AC *pAC, /* pointer to adapter context */
  748. int PortIndex) /* index of the port for which to re-init */
  749. {
  750. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  751. ("PortReInitBmu "));
  752. /* set address of first descriptor of ring in BMU */
  753. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
  754. (uint32_t)(((caddr_t)
  755. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  756. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  757. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
  758. 0xFFFFFFFF));
  759. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
  760. (uint32_t)(((caddr_t)
  761. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  762. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  763. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
  764. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
  765. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  766. pAC->RxPort[PortIndex].pRxDescrRing +
  767. pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
  768. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
  769. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  770. pAC->RxPort[PortIndex].pRxDescrRing +
  771. pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
  772. } /* PortReInitBmu */
  773. /****************************************************************************
  774. *
  775. * SkGeIsr - handle adapter interrupts
  776. *
  777. * Description:
  778. * The interrupt routine is called when the network adapter
  779. * generates an interrupt. It may also be called if another device
  780. * shares this interrupt vector with the driver.
  781. *
  782. * Returns: N/A
  783. *
  784. */
  785. static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
  786. {
  787. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  788. DEV_NET *pNet;
  789. SK_AC *pAC;
  790. SK_U32 IntSrc; /* interrupts source register contents */
  791. pNet = netdev_priv(dev);
  792. pAC = pNet->pAC;
  793. /*
  794. * Check and process if its our interrupt
  795. */
  796. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  797. if (IntSrc == 0) {
  798. return SkIsrRetNone;
  799. }
  800. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  801. #if 0 /* software irq currently not used */
  802. if (IntSrc & IS_IRQ_SW) {
  803. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  804. SK_DBGCAT_DRV_INT_SRC,
  805. ("Software IRQ\n"));
  806. }
  807. #endif
  808. if (IntSrc & IS_R1_F) {
  809. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  810. SK_DBGCAT_DRV_INT_SRC,
  811. ("EOF RX1 IRQ\n"));
  812. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  813. SK_PNMI_CNT_RX_INTR(pAC, 0);
  814. }
  815. if (IntSrc & IS_R2_F) {
  816. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  817. SK_DBGCAT_DRV_INT_SRC,
  818. ("EOF RX2 IRQ\n"));
  819. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  820. SK_PNMI_CNT_RX_INTR(pAC, 1);
  821. }
  822. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  823. if (IntSrc & IS_XA1_F) {
  824. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  825. SK_DBGCAT_DRV_INT_SRC,
  826. ("EOF AS TX1 IRQ\n"));
  827. SK_PNMI_CNT_TX_INTR(pAC, 0);
  828. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  829. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  830. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  831. }
  832. if (IntSrc & IS_XA2_F) {
  833. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  834. SK_DBGCAT_DRV_INT_SRC,
  835. ("EOF AS TX2 IRQ\n"));
  836. SK_PNMI_CNT_TX_INTR(pAC, 1);
  837. spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  838. FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
  839. spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  840. }
  841. #if 0 /* only if sync. queues used */
  842. if (IntSrc & IS_XS1_F) {
  843. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  844. SK_DBGCAT_DRV_INT_SRC,
  845. ("EOF SY TX1 IRQ\n"));
  846. SK_PNMI_CNT_TX_INTR(pAC, 1);
  847. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  848. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  849. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  850. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  851. }
  852. if (IntSrc & IS_XS2_F) {
  853. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  854. SK_DBGCAT_DRV_INT_SRC,
  855. ("EOF SY TX2 IRQ\n"));
  856. SK_PNMI_CNT_TX_INTR(pAC, 1);
  857. spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  858. FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
  859. spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  860. ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
  861. }
  862. #endif
  863. #endif
  864. /* do all IO at once */
  865. if (IntSrc & IS_R1_F)
  866. ClearAndStartRx(pAC, 0);
  867. if (IntSrc & IS_R2_F)
  868. ClearAndStartRx(pAC, 1);
  869. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  870. if (IntSrc & IS_XA1_F)
  871. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  872. if (IntSrc & IS_XA2_F)
  873. ClearTxIrq(pAC, 1, TX_PRIO_LOW);
  874. #endif
  875. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  876. } /* while (IntSrc & IRQ_MASK != 0) */
  877. IntSrc &= pAC->GIni.GIValIrqMask;
  878. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  879. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  880. ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
  881. pAC->CheckQueue = SK_FALSE;
  882. spin_lock(&pAC->SlowPathLock);
  883. if (IntSrc & SPECIAL_IRQS)
  884. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  885. SkEventDispatcher(pAC, pAC->IoBase);
  886. spin_unlock(&pAC->SlowPathLock);
  887. }
  888. /*
  889. * do it all again is case we cleared an interrupt that
  890. * came in after handling the ring (OUTs may be delayed
  891. * in hardware buffers, but are through after IN)
  892. *
  893. * rroesler: has been commented out and shifted to
  894. * SkGeDrvEvent(), because it is timer
  895. * guarded now
  896. *
  897. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  898. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  899. */
  900. if (pAC->CheckQueue) {
  901. pAC->CheckQueue = SK_FALSE;
  902. spin_lock(&pAC->SlowPathLock);
  903. SkEventDispatcher(pAC, pAC->IoBase);
  904. spin_unlock(&pAC->SlowPathLock);
  905. }
  906. /* IRQ is processed - Enable IRQs again*/
  907. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  908. return SkIsrRetHandled;
  909. } /* SkGeIsr */
  910. /****************************************************************************
  911. *
  912. * SkGeIsrOnePort - handle adapter interrupts for single port adapter
  913. *
  914. * Description:
  915. * The interrupt routine is called when the network adapter
  916. * generates an interrupt. It may also be called if another device
  917. * shares this interrupt vector with the driver.
  918. * This is the same as above, but handles only one port.
  919. *
  920. * Returns: N/A
  921. *
  922. */
  923. static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
  924. {
  925. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  926. DEV_NET *pNet;
  927. SK_AC *pAC;
  928. SK_U32 IntSrc; /* interrupts source register contents */
  929. pNet = netdev_priv(dev);
  930. pAC = pNet->pAC;
  931. /*
  932. * Check and process if its our interrupt
  933. */
  934. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  935. if (IntSrc == 0) {
  936. return SkIsrRetNone;
  937. }
  938. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  939. #if 0 /* software irq currently not used */
  940. if (IntSrc & IS_IRQ_SW) {
  941. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  942. SK_DBGCAT_DRV_INT_SRC,
  943. ("Software IRQ\n"));
  944. }
  945. #endif
  946. if (IntSrc & IS_R1_F) {
  947. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  948. SK_DBGCAT_DRV_INT_SRC,
  949. ("EOF RX1 IRQ\n"));
  950. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  951. SK_PNMI_CNT_RX_INTR(pAC, 0);
  952. }
  953. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  954. if (IntSrc & IS_XA1_F) {
  955. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  956. SK_DBGCAT_DRV_INT_SRC,
  957. ("EOF AS TX1 IRQ\n"));
  958. SK_PNMI_CNT_TX_INTR(pAC, 0);
  959. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  960. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  961. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  962. }
  963. #if 0 /* only if sync. queues used */
  964. if (IntSrc & IS_XS1_F) {
  965. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  966. SK_DBGCAT_DRV_INT_SRC,
  967. ("EOF SY TX1 IRQ\n"));
  968. SK_PNMI_CNT_TX_INTR(pAC, 0);
  969. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  970. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  971. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  972. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  973. }
  974. #endif
  975. #endif
  976. /* do all IO at once */
  977. if (IntSrc & IS_R1_F)
  978. ClearAndStartRx(pAC, 0);
  979. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  980. if (IntSrc & IS_XA1_F)
  981. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  982. #endif
  983. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  984. } /* while (IntSrc & IRQ_MASK != 0) */
  985. IntSrc &= pAC->GIni.GIValIrqMask;
  986. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  987. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  988. ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
  989. pAC->CheckQueue = SK_FALSE;
  990. spin_lock(&pAC->SlowPathLock);
  991. if (IntSrc & SPECIAL_IRQS)
  992. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  993. SkEventDispatcher(pAC, pAC->IoBase);
  994. spin_unlock(&pAC->SlowPathLock);
  995. }
  996. /*
  997. * do it all again is case we cleared an interrupt that
  998. * came in after handling the ring (OUTs may be delayed
  999. * in hardware buffers, but are through after IN)
  1000. *
  1001. * rroesler: has been commented out and shifted to
  1002. * SkGeDrvEvent(), because it is timer
  1003. * guarded now
  1004. *
  1005. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1006. */
  1007. /* IRQ is processed - Enable IRQs again*/
  1008. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  1009. return SkIsrRetHandled;
  1010. } /* SkGeIsrOnePort */
  1011. #ifdef CONFIG_NET_POLL_CONTROLLER
  1012. /****************************************************************************
  1013. *
  1014. * SkGePollController - polling receive, for netconsole
  1015. *
  1016. * Description:
  1017. * Polling receive - used by netconsole and other diagnostic tools
  1018. * to allow network i/o with interrupts disabled.
  1019. *
  1020. * Returns: N/A
  1021. */
  1022. static void SkGePollController(struct net_device *dev)
  1023. {
  1024. disable_irq(dev->irq);
  1025. SkGeIsr(dev->irq, dev, NULL);
  1026. enable_irq(dev->irq);
  1027. }
  1028. #endif
  1029. /****************************************************************************
  1030. *
  1031. * SkGeOpen - handle start of initialized adapter
  1032. *
  1033. * Description:
  1034. * This function starts the initialized adapter.
  1035. * The board level variable is set and the adapter is
  1036. * brought to full functionality.
  1037. * The device flags are set for operation.
  1038. * Do all necessary level 2 initialization, enable interrupts and
  1039. * give start command to RLMT.
  1040. *
  1041. * Returns:
  1042. * 0 on success
  1043. * != 0 on error
  1044. */
  1045. static int SkGeOpen(
  1046. struct SK_NET_DEVICE *dev)
  1047. {
  1048. DEV_NET *pNet;
  1049. SK_AC *pAC;
  1050. unsigned long Flags; /* for spin lock */
  1051. int i;
  1052. SK_EVPARA EvPara; /* an event parameter union */
  1053. pNet = netdev_priv(dev);
  1054. pAC = pNet->pAC;
  1055. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1056. ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
  1057. #ifdef SK_DIAG_SUPPORT
  1058. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  1059. if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
  1060. return (-1); /* still in use by diag; deny actions */
  1061. }
  1062. }
  1063. #endif
  1064. /* Set blink mode */
  1065. if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
  1066. pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
  1067. if (pAC->BoardLevel == SK_INIT_DATA) {
  1068. /* level 1 init common modules here */
  1069. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
  1070. printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
  1071. return (-1);
  1072. }
  1073. SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
  1074. SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
  1075. SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
  1076. SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
  1077. SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
  1078. SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
  1079. pAC->BoardLevel = SK_INIT_IO;
  1080. }
  1081. if (pAC->BoardLevel != SK_INIT_RUN) {
  1082. /* tschilling: Level 2 init modules here, check return value. */
  1083. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
  1084. printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
  1085. return (-1);
  1086. }
  1087. SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1088. SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1089. SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1090. SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1091. SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1092. SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1093. pAC->BoardLevel = SK_INIT_RUN;
  1094. }
  1095. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1096. /* Enable transmit descriptor polling. */
  1097. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  1098. FillRxRing(pAC, &pAC->RxPort[i]);
  1099. }
  1100. SkGeYellowLED(pAC, pAC->IoBase, 1);
  1101. StartDrvCleanupTimer(pAC);
  1102. SkDimEnableModerationIfNeeded(pAC);
  1103. SkDimDisplayModerationSettings(pAC);
  1104. pAC->GIni.GIValIrqMask &= IRQ_MASK;
  1105. /* enable Interrupts */
  1106. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  1107. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  1108. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1109. if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
  1110. EvPara.Para32[0] = pAC->RlmtNets;
  1111. EvPara.Para32[1] = -1;
  1112. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
  1113. EvPara);
  1114. EvPara.Para32[0] = pAC->RlmtMode;
  1115. EvPara.Para32[1] = 0;
  1116. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
  1117. EvPara);
  1118. }
  1119. EvPara.Para32[0] = pNet->NetNr;
  1120. EvPara.Para32[1] = -1;
  1121. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  1122. SkEventDispatcher(pAC, pAC->IoBase);
  1123. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1124. pAC->MaxPorts++;
  1125. pNet->Up = 1;
  1126. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1127. ("SkGeOpen suceeded\n"));
  1128. return (0);
  1129. } /* SkGeOpen */
  1130. /****************************************************************************
  1131. *
  1132. * SkGeClose - Stop initialized adapter
  1133. *
  1134. * Description:
  1135. * Close initialized adapter.
  1136. *
  1137. * Returns:
  1138. * 0 - on success
  1139. * error code - on error
  1140. */
  1141. static int SkGeClose(
  1142. struct SK_NET_DEVICE *dev)
  1143. {
  1144. DEV_NET *pNet;
  1145. DEV_NET *newPtrNet;
  1146. SK_AC *pAC;
  1147. unsigned long Flags; /* for spin lock */
  1148. int i;
  1149. int PortIdx;
  1150. SK_EVPARA EvPara;
  1151. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1152. ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
  1153. pNet = netdev_priv(dev);
  1154. pAC = pNet->pAC;
  1155. #ifdef SK_DIAG_SUPPORT
  1156. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  1157. if (pAC->DiagFlowCtrl == SK_FALSE) {
  1158. /*
  1159. ** notify that the interface which has been closed
  1160. ** by operator interaction must not be started up
  1161. ** again when the DIAG has finished.
  1162. */
  1163. newPtrNet = netdev_priv(pAC->dev[0]);
  1164. if (newPtrNet == pNet) {
  1165. pAC->WasIfUp[0] = SK_FALSE;
  1166. } else {
  1167. pAC->WasIfUp[1] = SK_FALSE;
  1168. }
  1169. return 0; /* return to system everything is fine... */
  1170. } else {
  1171. pAC->DiagFlowCtrl = SK_FALSE;
  1172. }
  1173. }
  1174. #endif
  1175. netif_stop_queue(dev);
  1176. if (pAC->RlmtNets == 1)
  1177. PortIdx = pAC->ActivePort;
  1178. else
  1179. PortIdx = pNet->NetNr;
  1180. StopDrvCleanupTimer(pAC);
  1181. /*
  1182. * Clear multicast table, promiscuous mode ....
  1183. */
  1184. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  1185. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  1186. SK_PROM_MODE_NONE);
  1187. if (pAC->MaxPorts == 1) {
  1188. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1189. /* disable interrupts */
  1190. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1191. EvPara.Para32[0] = pNet->NetNr;
  1192. EvPara.Para32[1] = -1;
  1193. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1194. SkEventDispatcher(pAC, pAC->IoBase);
  1195. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1196. /* stop the hardware */
  1197. SkGeDeInit(pAC, pAC->IoBase);
  1198. pAC->BoardLevel = SK_INIT_DATA;
  1199. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1200. } else {
  1201. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1202. EvPara.Para32[0] = pNet->NetNr;
  1203. EvPara.Para32[1] = -1;
  1204. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1205. SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
  1206. SkEventDispatcher(pAC, pAC->IoBase);
  1207. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1208. /* Stop port */
  1209. spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
  1210. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1211. SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
  1212. SK_STOP_ALL, SK_HARD_RST);
  1213. spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
  1214. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1215. }
  1216. if (pAC->RlmtNets == 1) {
  1217. /* clear all descriptor rings */
  1218. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1219. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  1220. ClearRxRing(pAC, &pAC->RxPort[i]);
  1221. ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
  1222. }
  1223. } else {
  1224. /* clear port descriptor rings */
  1225. ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
  1226. ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
  1227. ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
  1228. }
  1229. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1230. ("SkGeClose: done "));
  1231. SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
  1232. SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
  1233. sizeof(SK_PNMI_STRUCT_DATA));
  1234. pAC->MaxPorts--;
  1235. pNet->Up = 0;
  1236. return (0);
  1237. } /* SkGeClose */
  1238. /*****************************************************************************
  1239. *
  1240. * SkGeXmit - Linux frame transmit function
  1241. *
  1242. * Description:
  1243. * The system calls this function to send frames onto the wire.
  1244. * It puts the frame in the tx descriptor ring. If the ring is
  1245. * full then, the 'tbusy' flag is set.
  1246. *
  1247. * Returns:
  1248. * 0, if everything is ok
  1249. * !=0, on error
  1250. * WARNING: returning 1 in 'tbusy' case caused system crashes (double
  1251. * allocated skb's) !!!
  1252. */
  1253. static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
  1254. {
  1255. DEV_NET *pNet;
  1256. SK_AC *pAC;
  1257. int Rc; /* return code of XmitFrame */
  1258. pNet = netdev_priv(dev);
  1259. pAC = pNet->pAC;
  1260. if ((!skb_shinfo(skb)->nr_frags) ||
  1261. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
  1262. /* Don't activate scatter-gather and hardware checksum */
  1263. if (pAC->RlmtNets == 2)
  1264. Rc = XmitFrame(
  1265. pAC,
  1266. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1267. skb);
  1268. else
  1269. Rc = XmitFrame(
  1270. pAC,
  1271. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1272. skb);
  1273. } else {
  1274. /* scatter-gather and hardware TCP checksumming anabled*/
  1275. if (pAC->RlmtNets == 2)
  1276. Rc = XmitFrameSG(
  1277. pAC,
  1278. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1279. skb);
  1280. else
  1281. Rc = XmitFrameSG(
  1282. pAC,
  1283. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1284. skb);
  1285. }
  1286. /* Transmitter out of resources? */
  1287. if (Rc <= 0) {
  1288. netif_stop_queue(dev);
  1289. }
  1290. /* If not taken, give buffer ownership back to the
  1291. * queueing layer.
  1292. */
  1293. if (Rc < 0)
  1294. return (1);
  1295. dev->trans_start = jiffies;
  1296. return (0);
  1297. } /* SkGeXmit */
  1298. /*****************************************************************************
  1299. *
  1300. * XmitFrame - fill one socket buffer into the transmit ring
  1301. *
  1302. * Description:
  1303. * This function puts a message into the transmit descriptor ring
  1304. * if there is a descriptors left.
  1305. * Linux skb's consist of only one continuous buffer.
  1306. * The first step locks the ring. It is held locked
  1307. * all time to avoid problems with SWITCH_../PORT_RESET.
  1308. * Then the descriptoris allocated.
  1309. * The second part is linking the buffer to the descriptor.
  1310. * At the very last, the Control field of the descriptor
  1311. * is made valid for the BMU and a start TX command is given
  1312. * if necessary.
  1313. *
  1314. * Returns:
  1315. * > 0 - on succes: the number of bytes in the message
  1316. * = 0 - on resource shortage: this frame sent or dropped, now
  1317. * the ring is full ( -> set tbusy)
  1318. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1319. */
  1320. static int XmitFrame(
  1321. SK_AC *pAC, /* pointer to adapter context */
  1322. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1323. struct sk_buff *pMessage) /* pointer to send-message */
  1324. {
  1325. TXD *pTxd; /* the rxd to fill */
  1326. TXD *pOldTxd;
  1327. unsigned long Flags;
  1328. SK_U64 PhysAddr;
  1329. int Protocol;
  1330. int IpHeaderLength;
  1331. int BytesSend = pMessage->len;
  1332. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
  1333. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1334. #ifndef USE_TX_COMPLETE
  1335. FreeTxDescriptors(pAC, pTxPort);
  1336. #endif
  1337. if (pTxPort->TxdRingFree == 0) {
  1338. /*
  1339. ** no enough free descriptors in ring at the moment.
  1340. ** Maybe free'ing some old one help?
  1341. */
  1342. FreeTxDescriptors(pAC, pTxPort);
  1343. if (pTxPort->TxdRingFree == 0) {
  1344. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1345. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1346. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1347. SK_DBGCAT_DRV_TX_PROGRESS,
  1348. ("XmitFrame failed\n"));
  1349. /*
  1350. ** the desired message can not be sent
  1351. ** Because tbusy seems to be set, the message
  1352. ** should not be freed here. It will be used
  1353. ** by the scheduler of the ethernet handler
  1354. */
  1355. return (-1);
  1356. }
  1357. }
  1358. /*
  1359. ** If the passed socket buffer is of smaller MTU-size than 60,
  1360. ** copy everything into new buffer and fill all bytes between
  1361. ** the original packet end and the new packet end of 60 with 0x00.
  1362. ** This is to resolve faulty padding by the HW with 0xaa bytes.
  1363. */
  1364. if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
  1365. if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
  1366. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1367. return 0;
  1368. }
  1369. pMessage->len = C_LEN_ETHERNET_MINSIZE;
  1370. }
  1371. /*
  1372. ** advance head counter behind descriptor needed for this frame,
  1373. ** so that needed descriptor is reserved from that on. The next
  1374. ** action will be to add the passed buffer to the TX-descriptor
  1375. */
  1376. pTxd = pTxPort->pTxdRingHead;
  1377. pTxPort->pTxdRingHead = pTxd->pNextTxd;
  1378. pTxPort->TxdRingFree--;
  1379. #ifdef SK_DUMP_TX
  1380. DumpMsg(pMessage, "XmitFrame");
  1381. #endif
  1382. /*
  1383. ** First step is to map the data to be sent via the adapter onto
  1384. ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
  1385. ** and 2.6 need to use pci_map_page() for that mapping.
  1386. */
  1387. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1388. virt_to_page(pMessage->data),
  1389. ((unsigned long) pMessage->data & ~PAGE_MASK),
  1390. pMessage->len,
  1391. PCI_DMA_TODEVICE);
  1392. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1393. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1394. pTxd->pMBuf = pMessage;
  1395. if (pMessage->ip_summed == CHECKSUM_HW) {
  1396. Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
  1397. if ((Protocol == C_PROTO_ID_UDP) &&
  1398. (pAC->GIni.GIChipRev == 0) &&
  1399. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1400. pTxd->TBControl = BMU_TCP_CHECK;
  1401. } else {
  1402. pTxd->TBControl = BMU_UDP_CHECK;
  1403. }
  1404. IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
  1405. IpHeaderLength = (IpHeaderLength & 0xf) * 4;
  1406. pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
  1407. pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
  1408. (Protocol == C_PROTO_ID_UDP ?
  1409. C_OFFSET_UDPHEADER_UDPCS :
  1410. C_OFFSET_TCPHEADER_TCPCS);
  1411. pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
  1412. pTxd->TBControl |= BMU_OWN | BMU_STF |
  1413. BMU_SW | BMU_EOF |
  1414. #ifdef USE_TX_COMPLETE
  1415. BMU_IRQ_EOF |
  1416. #endif
  1417. pMessage->len;
  1418. } else {
  1419. pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
  1420. BMU_SW | BMU_EOF |
  1421. #ifdef USE_TX_COMPLETE
  1422. BMU_IRQ_EOF |
  1423. #endif
  1424. pMessage->len;
  1425. }
  1426. /*
  1427. ** If previous descriptor already done, give TX start cmd
  1428. */
  1429. pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
  1430. if ((pOldTxd->TBControl & BMU_OWN) == 0) {
  1431. SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
  1432. }
  1433. /*
  1434. ** after releasing the lock, the skb may immediately be free'd
  1435. */
  1436. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1437. if (pTxPort->TxdRingFree != 0) {
  1438. return (BytesSend);
  1439. } else {
  1440. return (0);
  1441. }
  1442. } /* XmitFrame */
  1443. /*****************************************************************************
  1444. *
  1445. * XmitFrameSG - fill one socket buffer into the transmit ring
  1446. * (use SG and TCP/UDP hardware checksumming)
  1447. *
  1448. * Description:
  1449. * This function puts a message into the transmit descriptor ring
  1450. * if there is a descriptors left.
  1451. *
  1452. * Returns:
  1453. * > 0 - on succes: the number of bytes in the message
  1454. * = 0 - on resource shortage: this frame sent or dropped, now
  1455. * the ring is full ( -> set tbusy)
  1456. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1457. */
  1458. static int XmitFrameSG(
  1459. SK_AC *pAC, /* pointer to adapter context */
  1460. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1461. struct sk_buff *pMessage) /* pointer to send-message */
  1462. {
  1463. TXD *pTxd;
  1464. TXD *pTxdFst;
  1465. TXD *pTxdLst;
  1466. int CurrFrag;
  1467. int BytesSend;
  1468. int IpHeaderLength;
  1469. int Protocol;
  1470. skb_frag_t *sk_frag;
  1471. SK_U64 PhysAddr;
  1472. unsigned long Flags;
  1473. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1474. #ifndef USE_TX_COMPLETE
  1475. FreeTxDescriptors(pAC, pTxPort);
  1476. #endif
  1477. if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
  1478. FreeTxDescriptors(pAC, pTxPort);
  1479. if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
  1480. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1481. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1482. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1483. SK_DBGCAT_DRV_TX_PROGRESS,
  1484. ("XmitFrameSG failed - Ring full\n"));
  1485. /* this message can not be sent now */
  1486. return(-1);
  1487. }
  1488. }
  1489. pTxd = pTxPort->pTxdRingHead;
  1490. pTxdFst = pTxd;
  1491. pTxdLst = pTxd;
  1492. BytesSend = 0;
  1493. Protocol = 0;
  1494. /*
  1495. ** Map the first fragment (header) into the DMA-space
  1496. */
  1497. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1498. virt_to_page(pMessage->data),
  1499. ((unsigned long) pMessage->data & ~PAGE_MASK),
  1500. skb_headlen(pMessage),
  1501. PCI_DMA_TODEVICE);
  1502. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1503. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1504. /*
  1505. ** Does the HW need to evaluate checksum for TCP or UDP packets?
  1506. */
  1507. if (pMessage->ip_summed == CHECKSUM_HW) {
  1508. pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
  1509. /*
  1510. ** We have to use the opcode for tcp here, because the
  1511. ** opcode for udp is not working in the hardware yet
  1512. ** (Revision 2.0)
  1513. */
  1514. Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
  1515. if ((Protocol == C_PROTO_ID_UDP) &&
  1516. (pAC->GIni.GIChipRev == 0) &&
  1517. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1518. pTxd->TBControl |= BMU_TCP_CHECK;
  1519. } else {
  1520. pTxd->TBControl |= BMU_UDP_CHECK;
  1521. }
  1522. IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
  1523. pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
  1524. pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
  1525. (Protocol == C_PROTO_ID_UDP ?
  1526. C_OFFSET_UDPHEADER_UDPCS :
  1527. C_OFFSET_TCPHEADER_TCPCS);
  1528. pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
  1529. } else {
  1530. pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
  1531. skb_headlen(pMessage);
  1532. }
  1533. pTxd = pTxd->pNextTxd;
  1534. pTxPort->TxdRingFree--;
  1535. BytesSend += skb_headlen(pMessage);
  1536. /*
  1537. ** Browse over all SG fragments and map each of them into the DMA space
  1538. */
  1539. for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
  1540. sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
  1541. /*
  1542. ** we already have the proper value in entry
  1543. */
  1544. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1545. sk_frag->page,
  1546. sk_frag->page_offset,
  1547. sk_frag->size,
  1548. PCI_DMA_TODEVICE);
  1549. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1550. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1551. pTxd->pMBuf = pMessage;
  1552. /*
  1553. ** Does the HW need to evaluate checksum for TCP or UDP packets?
  1554. */
  1555. if (pMessage->ip_summed == CHECKSUM_HW) {
  1556. pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
  1557. /*
  1558. ** We have to use the opcode for tcp here because the
  1559. ** opcode for udp is not working in the hardware yet
  1560. ** (revision 2.0)
  1561. */
  1562. if ((Protocol == C_PROTO_ID_UDP) &&
  1563. (pAC->GIni.GIChipRev == 0) &&
  1564. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1565. pTxd->TBControl |= BMU_TCP_CHECK;
  1566. } else {
  1567. pTxd->TBControl |= BMU_UDP_CHECK;
  1568. }
  1569. } else {
  1570. pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
  1571. }
  1572. /*
  1573. ** Do we have the last fragment?
  1574. */
  1575. if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
  1576. #ifdef USE_TX_COMPLETE
  1577. pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
  1578. #else
  1579. pTxd->TBControl |= BMU_EOF | sk_frag->size;
  1580. #endif
  1581. pTxdFst->TBControl |= BMU_OWN | BMU_SW;
  1582. } else {
  1583. pTxd->TBControl |= sk_frag->size;
  1584. }
  1585. pTxdLst = pTxd;
  1586. pTxd = pTxd->pNextTxd;
  1587. pTxPort->TxdRingFree--;
  1588. BytesSend += sk_frag->size;
  1589. }
  1590. /*
  1591. ** If previous descriptor already done, give TX start cmd
  1592. */
  1593. if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
  1594. SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
  1595. }
  1596. pTxPort->pTxdRingPrev = pTxdLst;
  1597. pTxPort->pTxdRingHead = pTxd;
  1598. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1599. if (pTxPort->TxdRingFree > 0) {
  1600. return (BytesSend);
  1601. } else {
  1602. return (0);
  1603. }
  1604. }
  1605. /*****************************************************************************
  1606. *
  1607. * FreeTxDescriptors - release descriptors from the descriptor ring
  1608. *
  1609. * Description:
  1610. * This function releases descriptors from a transmit ring if they
  1611. * have been sent by the BMU.
  1612. * If a descriptors is sent, it can be freed and the message can
  1613. * be freed, too.
  1614. * The SOFTWARE controllable bit is used to prevent running around a
  1615. * completely free ring for ever. If this bit is no set in the
  1616. * frame (by XmitFrame), this frame has never been sent or is
  1617. * already freed.
  1618. * The Tx descriptor ring lock must be held while calling this function !!!
  1619. *
  1620. * Returns:
  1621. * none
  1622. */
  1623. static void FreeTxDescriptors(
  1624. SK_AC *pAC, /* pointer to the adapter context */
  1625. TX_PORT *pTxPort) /* pointer to destination port structure */
  1626. {
  1627. TXD *pTxd; /* pointer to the checked descriptor */
  1628. TXD *pNewTail; /* pointer to 'end' of the ring */
  1629. SK_U32 Control; /* TBControl field of descriptor */
  1630. SK_U64 PhysAddr; /* address of DMA mapping */
  1631. pNewTail = pTxPort->pTxdRingTail;
  1632. pTxd = pNewTail;
  1633. /*
  1634. ** loop forever; exits if BMU_SW bit not set in start frame
  1635. ** or BMU_OWN bit set in any frame
  1636. */
  1637. while (1) {
  1638. Control = pTxd->TBControl;
  1639. if ((Control & BMU_SW) == 0) {
  1640. /*
  1641. ** software controllable bit is set in first
  1642. ** fragment when given to BMU. Not set means that
  1643. ** this fragment was never sent or is already
  1644. ** freed ( -> ring completely free now).
  1645. */
  1646. pTxPort->pTxdRingTail = pTxd;
  1647. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  1648. return;
  1649. }
  1650. if (Control & BMU_OWN) {
  1651. pTxPort->pTxdRingTail = pTxd;
  1652. if (pTxPort->TxdRingFree > 0) {
  1653. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  1654. }
  1655. return;
  1656. }
  1657. /*
  1658. ** release the DMA mapping, because until not unmapped
  1659. ** this buffer is considered being under control of the
  1660. ** adapter card!
  1661. */
  1662. PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
  1663. PhysAddr |= (SK_U64) pTxd->VDataLow;
  1664. pci_unmap_page(pAC->PciDev, PhysAddr,
  1665. pTxd->pMBuf->len,
  1666. PCI_DMA_TODEVICE);
  1667. if (Control & BMU_EOF)
  1668. DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
  1669. pTxPort->TxdRingFree++;
  1670. pTxd->TBControl &= ~BMU_SW;
  1671. pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
  1672. } /* while(forever) */
  1673. } /* FreeTxDescriptors */
  1674. /*****************************************************************************
  1675. *
  1676. * FillRxRing - fill the receive ring with valid descriptors
  1677. *
  1678. * Description:
  1679. * This function fills the receive ring descriptors with data
  1680. * segments and makes them valid for the BMU.
  1681. * The active ring is filled completely, if possible.
  1682. * The non-active ring is filled only partial to save memory.
  1683. *
  1684. * Description of rx ring structure:
  1685. * head - points to the descriptor which will be used next by the BMU
  1686. * tail - points to the next descriptor to give to the BMU
  1687. *
  1688. * Returns: N/A
  1689. */
  1690. static void FillRxRing(
  1691. SK_AC *pAC, /* pointer to the adapter context */
  1692. RX_PORT *pRxPort) /* ptr to port struct for which the ring
  1693. should be filled */
  1694. {
  1695. unsigned long Flags;
  1696. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  1697. while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
  1698. if(!FillRxDescriptor(pAC, pRxPort))
  1699. break;
  1700. }
  1701. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  1702. } /* FillRxRing */
  1703. /*****************************************************************************
  1704. *
  1705. * FillRxDescriptor - fill one buffer into the receive ring
  1706. *
  1707. * Description:
  1708. * The function allocates a new receive buffer and
  1709. * puts it into the next descriptor.
  1710. *
  1711. * Returns:
  1712. * SK_TRUE - a buffer was added to the ring
  1713. * SK_FALSE - a buffer could not be added
  1714. */
  1715. static SK_BOOL FillRxDescriptor(
  1716. SK_AC *pAC, /* pointer to the adapter context struct */
  1717. RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
  1718. {
  1719. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  1720. RXD *pRxd; /* the rxd to fill */
  1721. SK_U16 Length; /* data fragment length */
  1722. SK_U64 PhysAddr; /* physical address of a rx buffer */
  1723. pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
  1724. if (pMsgBlock == NULL) {
  1725. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1726. SK_DBGCAT_DRV_ENTRY,
  1727. ("%s: Allocation of rx buffer failed !\n",
  1728. pAC->dev[pRxPort->PortIndex]->name));
  1729. SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
  1730. return(SK_FALSE);
  1731. }
  1732. skb_reserve(pMsgBlock, 2); /* to align IP frames */
  1733. /* skb allocated ok, so add buffer */
  1734. pRxd = pRxPort->pRxdRingTail;
  1735. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  1736. pRxPort->RxdRingFree--;
  1737. Length = pAC->RxBufSize;
  1738. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1739. virt_to_page(pMsgBlock->data),
  1740. ((unsigned long) pMsgBlock->data &
  1741. ~PAGE_MASK),
  1742. pAC->RxBufSize - 2,
  1743. PCI_DMA_FROMDEVICE);
  1744. pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1745. pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1746. pRxd->pMBuf = pMsgBlock;
  1747. pRxd->RBControl = BMU_OWN |
  1748. BMU_STF |
  1749. BMU_IRQ_EOF |
  1750. BMU_TCP_CHECK |
  1751. Length;
  1752. return (SK_TRUE);
  1753. } /* FillRxDescriptor */
  1754. /*****************************************************************************
  1755. *
  1756. * ReQueueRxBuffer - fill one buffer back into the receive ring
  1757. *
  1758. * Description:
  1759. * Fill a given buffer back into the rx ring. The buffer
  1760. * has been previously allocated and aligned, and its phys.
  1761. * address calculated, so this is no more necessary.
  1762. *
  1763. * Returns: N/A
  1764. */
  1765. static void ReQueueRxBuffer(
  1766. SK_AC *pAC, /* pointer to the adapter context struct */
  1767. RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
  1768. struct sk_buff *pMsg, /* pointer to the buffer */
  1769. SK_U32 PhysHigh, /* phys address high dword */
  1770. SK_U32 PhysLow) /* phys address low dword */
  1771. {
  1772. RXD *pRxd; /* the rxd to fill */
  1773. SK_U16 Length; /* data fragment length */
  1774. pRxd = pRxPort->pRxdRingTail;
  1775. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  1776. pRxPort->RxdRingFree--;
  1777. Length = pAC->RxBufSize;
  1778. pRxd->VDataLow = PhysLow;
  1779. pRxd->VDataHigh = PhysHigh;
  1780. pRxd->pMBuf = pMsg;
  1781. pRxd->RBControl = BMU_OWN |
  1782. BMU_STF |
  1783. BMU_IRQ_EOF |
  1784. BMU_TCP_CHECK |
  1785. Length;
  1786. return;
  1787. } /* ReQueueRxBuffer */
  1788. /*****************************************************************************
  1789. *
  1790. * ReceiveIrq - handle a receive IRQ
  1791. *
  1792. * Description:
  1793. * This function is called when a receive IRQ is set.
  1794. * It walks the receive descriptor ring and sends up all
  1795. * frames that are complete.
  1796. *
  1797. * Returns: N/A
  1798. */
  1799. static void ReceiveIrq(
  1800. SK_AC *pAC, /* pointer to adapter context */
  1801. RX_PORT *pRxPort, /* pointer to receive port struct */
  1802. SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
  1803. {
  1804. RXD *pRxd; /* pointer to receive descriptors */
  1805. SK_U32 Control; /* control field of descriptor */
  1806. struct sk_buff *pMsg; /* pointer to message holding frame */
  1807. struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
  1808. int FrameLength; /* total length of received frame */
  1809. int IpFrameLength;
  1810. SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
  1811. SK_EVPARA EvPara; /* an event parameter union */
  1812. unsigned long Flags; /* for spin lock */
  1813. int PortIndex = pRxPort->PortIndex;
  1814. unsigned int Offset;
  1815. unsigned int NumBytes;
  1816. unsigned int ForRlmt;
  1817. SK_BOOL IsBc;
  1818. SK_BOOL IsMc;
  1819. SK_BOOL IsBadFrame; /* Bad frame */
  1820. SK_U32 FrameStat;
  1821. unsigned short Csum1;
  1822. unsigned short Csum2;
  1823. unsigned short Type;
  1824. int Result;
  1825. SK_U64 PhysAddr;
  1826. rx_start:
  1827. /* do forever; exit if BMU_OWN found */
  1828. for ( pRxd = pRxPort->pRxdRingHead ;
  1829. pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
  1830. pRxd = pRxd->pNextRxd,
  1831. pRxPort->pRxdRingHead = pRxd,
  1832. pRxPort->RxdRingFree ++) {
  1833. /*
  1834. * For a better understanding of this loop
  1835. * Go through every descriptor beginning at the head
  1836. * Please note: the ring might be completely received so the OWN bit
  1837. * set is not a good crirteria to leave that loop.
  1838. * Therefore the RingFree counter is used.
  1839. * On entry of this loop pRxd is a pointer to the Rxd that needs
  1840. * to be checked next.
  1841. */
  1842. Control = pRxd->RBControl;
  1843. /* check if this descriptor is ready */
  1844. if ((Control & BMU_OWN) != 0) {
  1845. /* this descriptor is not yet ready */
  1846. /* This is the usual end of the loop */
  1847. /* We don't need to start the ring again */
  1848. FillRxRing(pAC, pRxPort);
  1849. return;
  1850. }
  1851. pAC->DynIrqModInfo.NbrProcessedDescr++;
  1852. /* get length of frame and check it */
  1853. FrameLength = Control & BMU_BBC;
  1854. if (FrameLength > pAC->RxBufSize) {
  1855. goto rx_failed;
  1856. }
  1857. /* check for STF and EOF */
  1858. if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
  1859. goto rx_failed;
  1860. }
  1861. /* here we have a complete frame in the ring */
  1862. pMsg = pRxd->pMBuf;
  1863. FrameStat = pRxd->FrameStat;
  1864. /* check for frame length mismatch */
  1865. #define XMR_FS_LEN_SHIFT 18
  1866. #define GMR_FS_LEN_SHIFT 16
  1867. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1868. if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
  1869. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1870. SK_DBGCAT_DRV_RX_PROGRESS,
  1871. ("skge: Frame length mismatch (%u/%u).\n",
  1872. FrameLength,
  1873. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  1874. goto rx_failed;
  1875. }
  1876. }
  1877. else {
  1878. if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
  1879. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1880. SK_DBGCAT_DRV_RX_PROGRESS,
  1881. ("skge: Frame length mismatch (%u/%u).\n",
  1882. FrameLength,
  1883. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  1884. goto rx_failed;
  1885. }
  1886. }
  1887. /* Set Rx Status */
  1888. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1889. IsBc = (FrameStat & XMR_FS_BC) != 0;
  1890. IsMc = (FrameStat & XMR_FS_MC) != 0;
  1891. IsBadFrame = (FrameStat &
  1892. (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
  1893. } else {
  1894. IsBc = (FrameStat & GMR_FS_BC) != 0;
  1895. IsMc = (FrameStat & GMR_FS_MC) != 0;
  1896. IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
  1897. ((FrameStat & GMR_FS_RX_OK) == 0));
  1898. }
  1899. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  1900. ("Received frame of length %d on port %d\n",
  1901. FrameLength, PortIndex));
  1902. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  1903. ("Number of free rx descriptors: %d\n",
  1904. pRxPort->RxdRingFree));
  1905. /* DumpMsg(pMsg, "Rx"); */
  1906. if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
  1907. #if 0
  1908. (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
  1909. #endif
  1910. /* there is a receive error in this frame */
  1911. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1912. SK_DBGCAT_DRV_RX_PROGRESS,
  1913. ("skge: Error in received frame, dropped!\n"
  1914. "Control: %x\nRxStat: %x\n",
  1915. Control, FrameStat));
  1916. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  1917. pRxd->VDataHigh, pRxd->VDataLow);
  1918. continue;
  1919. }
  1920. /*
  1921. * if short frame then copy data to reduce memory waste
  1922. */
  1923. if ((FrameLength < SK_COPY_THRESHOLD) &&
  1924. ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
  1925. /*
  1926. * Short frame detected and allocation successfull
  1927. */
  1928. /* use new skb and copy data */
  1929. skb_reserve(pNewMsg, 2);
  1930. skb_put(pNewMsg, FrameLength);
  1931. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  1932. PhysAddr |= (SK_U64) pRxd->VDataLow;
  1933. pci_dma_sync_single_for_cpu(pAC->PciDev,
  1934. (dma_addr_t) PhysAddr,
  1935. FrameLength,
  1936. PCI_DMA_FROMDEVICE);
  1937. eth_copy_and_sum(pNewMsg, pMsg->data,
  1938. FrameLength, 0);
  1939. pci_dma_sync_single_for_device(pAC->PciDev,
  1940. (dma_addr_t) PhysAddr,
  1941. FrameLength,
  1942. PCI_DMA_FROMDEVICE);
  1943. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  1944. pRxd->VDataHigh, pRxd->VDataLow);
  1945. pMsg = pNewMsg;
  1946. }
  1947. else {
  1948. /*
  1949. * if large frame, or SKB allocation failed, pass
  1950. * the SKB directly to the networking
  1951. */
  1952. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  1953. PhysAddr |= (SK_U64) pRxd->VDataLow;
  1954. /* release the DMA mapping */
  1955. pci_unmap_single(pAC->PciDev,
  1956. PhysAddr,
  1957. pAC->RxBufSize - 2,
  1958. PCI_DMA_FROMDEVICE);
  1959. /* set length in message */
  1960. skb_put(pMsg, FrameLength);
  1961. /* hardware checksum */
  1962. Type = ntohs(*((short*)&pMsg->data[12]));
  1963. #ifdef USE_SK_RX_CHECKSUM
  1964. if (Type == 0x800) {
  1965. Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
  1966. Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
  1967. IpFrameLength = (int) ntohs((unsigned short)
  1968. ((unsigned short *) pMsg->data)[8]);
  1969. /*
  1970. * Test: If frame is padded, a check is not possible!
  1971. * Frame not padded? Length difference must be 14 (0xe)!
  1972. */
  1973. if ((FrameLength - IpFrameLength) != 0xe) {
  1974. /* Frame padded => TCP offload not possible! */
  1975. pMsg->ip_summed = CHECKSUM_NONE;
  1976. } else {
  1977. /* Frame not padded => TCP offload! */
  1978. if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
  1979. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
  1980. (pAC->ChipsetType)) {
  1981. Result = SkCsGetReceiveInfo(pAC,
  1982. &pMsg->data[14],
  1983. Csum1, Csum2, pRxPort->PortIndex);
  1984. if (Result ==
  1985. SKCS_STATUS_IP_FRAGMENT ||
  1986. Result ==
  1987. SKCS_STATUS_IP_CSUM_OK ||
  1988. Result ==
  1989. SKCS_STATUS_TCP_CSUM_OK ||
  1990. Result ==
  1991. SKCS_STATUS_UDP_CSUM_OK) {
  1992. pMsg->ip_summed =
  1993. CHECKSUM_UNNECESSARY;
  1994. }
  1995. else if (Result ==
  1996. SKCS_STATUS_TCP_CSUM_ERROR ||
  1997. Result ==
  1998. SKCS_STATUS_UDP_CSUM_ERROR ||
  1999. Result ==
  2000. SKCS_STATUS_IP_CSUM_ERROR_UDP ||
  2001. Result ==
  2002. SKCS_STATUS_IP_CSUM_ERROR_TCP ||
  2003. Result ==
  2004. SKCS_STATUS_IP_CSUM_ERROR ) {
  2005. /* HW Checksum error */
  2006. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2007. SK_DBGCAT_DRV_RX_PROGRESS,
  2008. ("skge: CRC error. Frame dropped!\n"));
  2009. goto rx_failed;
  2010. } else {
  2011. pMsg->ip_summed =
  2012. CHECKSUM_NONE;
  2013. }
  2014. }/* checksumControl calculation valid */
  2015. } /* Frame length check */
  2016. } /* IP frame */
  2017. #else
  2018. pMsg->ip_summed = CHECKSUM_NONE;
  2019. #endif
  2020. } /* frame > SK_COPY_TRESHOLD */
  2021. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
  2022. ForRlmt = SK_RLMT_RX_PROTOCOL;
  2023. #if 0
  2024. IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
  2025. #endif
  2026. SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
  2027. IsBc, &Offset, &NumBytes);
  2028. if (NumBytes != 0) {
  2029. #if 0
  2030. IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
  2031. #endif
  2032. SK_RLMT_LOOKAHEAD(pAC, PortIndex,
  2033. &pMsg->data[Offset],
  2034. IsBc, IsMc, &ForRlmt);
  2035. }
  2036. if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
  2037. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
  2038. /* send up only frames from active port */
  2039. if ((PortIndex == pAC->ActivePort) ||
  2040. (pAC->RlmtNets == 2)) {
  2041. /* frame for upper layer */
  2042. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
  2043. #ifdef xDEBUG
  2044. DumpMsg(pMsg, "Rx");
  2045. #endif
  2046. SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
  2047. FrameLength, pRxPort->PortIndex);
  2048. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2049. pMsg->protocol = eth_type_trans(pMsg,
  2050. pAC->dev[pRxPort->PortIndex]);
  2051. netif_rx(pMsg);
  2052. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2053. }
  2054. else {
  2055. /* drop frame */
  2056. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2057. SK_DBGCAT_DRV_RX_PROGRESS,
  2058. ("D"));
  2059. DEV_KFREE_SKB(pMsg);
  2060. }
  2061. } /* if not for rlmt */
  2062. else {
  2063. /* packet for rlmt */
  2064. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2065. SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
  2066. pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
  2067. pAC->IoBase, FrameLength);
  2068. if (pRlmtMbuf != NULL) {
  2069. pRlmtMbuf->pNext = NULL;
  2070. pRlmtMbuf->Length = FrameLength;
  2071. pRlmtMbuf->PortIdx = PortIndex;
  2072. EvPara.pParaPtr = pRlmtMbuf;
  2073. memcpy((char*)(pRlmtMbuf->pData),
  2074. (char*)(pMsg->data),
  2075. FrameLength);
  2076. /* SlowPathLock needed? */
  2077. if (SlowPathLock == SK_TRUE) {
  2078. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2079. SkEventQueue(pAC, SKGE_RLMT,
  2080. SK_RLMT_PACKET_RECEIVED,
  2081. EvPara);
  2082. pAC->CheckQueue = SK_TRUE;
  2083. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2084. } else {
  2085. SkEventQueue(pAC, SKGE_RLMT,
  2086. SK_RLMT_PACKET_RECEIVED,
  2087. EvPara);
  2088. pAC->CheckQueue = SK_TRUE;
  2089. }
  2090. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2091. SK_DBGCAT_DRV_RX_PROGRESS,
  2092. ("Q"));
  2093. }
  2094. if ((pAC->dev[pRxPort->PortIndex]->flags &
  2095. (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
  2096. (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
  2097. SK_RLMT_RX_PROTOCOL) {
  2098. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2099. pMsg->protocol = eth_type_trans(pMsg,
  2100. pAC->dev[pRxPort->PortIndex]);
  2101. netif_rx(pMsg);
  2102. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2103. }
  2104. else {
  2105. DEV_KFREE_SKB(pMsg);
  2106. }
  2107. } /* if packet for rlmt */
  2108. } /* for ... scanning the RXD ring */
  2109. /* RXD ring is empty -> fill and restart */
  2110. FillRxRing(pAC, pRxPort);
  2111. /* do not start if called from Close */
  2112. if (pAC->BoardLevel > SK_INIT_DATA) {
  2113. ClearAndStartRx(pAC, PortIndex);
  2114. }
  2115. return;
  2116. rx_failed:
  2117. /* remove error frame */
  2118. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  2119. ("Schrottdescriptor, length: 0x%x\n", FrameLength));
  2120. /* release the DMA mapping */
  2121. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2122. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2123. pci_unmap_page(pAC->PciDev,
  2124. PhysAddr,
  2125. pAC->RxBufSize - 2,
  2126. PCI_DMA_FROMDEVICE);
  2127. DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
  2128. pRxd->pMBuf = NULL;
  2129. pRxPort->RxdRingFree++;
  2130. pRxPort->pRxdRingHead = pRxd->pNextRxd;
  2131. goto rx_start;
  2132. } /* ReceiveIrq */
  2133. /*****************************************************************************
  2134. *
  2135. * ClearAndStartRx - give a start receive command to BMU, clear IRQ
  2136. *
  2137. * Description:
  2138. * This function sends a start command and a clear interrupt
  2139. * command for one receive queue to the BMU.
  2140. *
  2141. * Returns: N/A
  2142. * none
  2143. */
  2144. static void ClearAndStartRx(
  2145. SK_AC *pAC, /* pointer to the adapter context */
  2146. int PortIndex) /* index of the receive port (XMAC) */
  2147. {
  2148. SK_OUT8(pAC->IoBase,
  2149. RxQueueAddr[PortIndex]+Q_CSR,
  2150. CSR_START | CSR_IRQ_CL_F);
  2151. } /* ClearAndStartRx */
  2152. /*****************************************************************************
  2153. *
  2154. * ClearTxIrq - give a clear transmit IRQ command to BMU
  2155. *
  2156. * Description:
  2157. * This function sends a clear tx IRQ command for one
  2158. * transmit queue to the BMU.
  2159. *
  2160. * Returns: N/A
  2161. */
  2162. static void ClearTxIrq(
  2163. SK_AC *pAC, /* pointer to the adapter context */
  2164. int PortIndex, /* index of the transmit port (XMAC) */
  2165. int Prio) /* priority or normal queue */
  2166. {
  2167. SK_OUT8(pAC->IoBase,
  2168. TxQueueAddr[PortIndex][Prio]+Q_CSR,
  2169. CSR_IRQ_CL_F);
  2170. } /* ClearTxIrq */
  2171. /*****************************************************************************
  2172. *
  2173. * ClearRxRing - remove all buffers from the receive ring
  2174. *
  2175. * Description:
  2176. * This function removes all receive buffers from the ring.
  2177. * The receive BMU must be stopped before calling this function.
  2178. *
  2179. * Returns: N/A
  2180. */
  2181. static void ClearRxRing(
  2182. SK_AC *pAC, /* pointer to adapter context */
  2183. RX_PORT *pRxPort) /* pointer to rx port struct */
  2184. {
  2185. RXD *pRxd; /* pointer to the current descriptor */
  2186. unsigned long Flags;
  2187. SK_U64 PhysAddr;
  2188. if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
  2189. return;
  2190. }
  2191. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  2192. pRxd = pRxPort->pRxdRingHead;
  2193. do {
  2194. if (pRxd->pMBuf != NULL) {
  2195. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2196. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2197. pci_unmap_page(pAC->PciDev,
  2198. PhysAddr,
  2199. pAC->RxBufSize - 2,
  2200. PCI_DMA_FROMDEVICE);
  2201. DEV_KFREE_SKB(pRxd->pMBuf);
  2202. pRxd->pMBuf = NULL;
  2203. }
  2204. pRxd->RBControl &= BMU_OWN;
  2205. pRxd = pRxd->pNextRxd;
  2206. pRxPort->RxdRingFree++;
  2207. } while (pRxd != pRxPort->pRxdRingTail);
  2208. pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
  2209. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  2210. } /* ClearRxRing */
  2211. /*****************************************************************************
  2212. *
  2213. * ClearTxRing - remove all buffers from the transmit ring
  2214. *
  2215. * Description:
  2216. * This function removes all transmit buffers from the ring.
  2217. * The transmit BMU must be stopped before calling this function
  2218. * and transmitting at the upper level must be disabled.
  2219. * The BMU own bit of all descriptors is cleared, the rest is
  2220. * done by calling FreeTxDescriptors.
  2221. *
  2222. * Returns: N/A
  2223. */
  2224. static void ClearTxRing(
  2225. SK_AC *pAC, /* pointer to adapter context */
  2226. TX_PORT *pTxPort) /* pointer to tx prt struct */
  2227. {
  2228. TXD *pTxd; /* pointer to the current descriptor */
  2229. int i;
  2230. unsigned long Flags;
  2231. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  2232. pTxd = pTxPort->pTxdRingHead;
  2233. for (i=0; i<pAC->TxDescrPerRing; i++) {
  2234. pTxd->TBControl &= ~BMU_OWN;
  2235. pTxd = pTxd->pNextTxd;
  2236. }
  2237. FreeTxDescriptors(pAC, pTxPort);
  2238. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  2239. } /* ClearTxRing */
  2240. /*****************************************************************************
  2241. *
  2242. * SkGeSetMacAddr - Set the hardware MAC address
  2243. *
  2244. * Description:
  2245. * This function sets the MAC address used by the adapter.
  2246. *
  2247. * Returns:
  2248. * 0, if everything is ok
  2249. * !=0, on error
  2250. */
  2251. static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
  2252. {
  2253. DEV_NET *pNet = netdev_priv(dev);
  2254. SK_AC *pAC = pNet->pAC;
  2255. struct sockaddr *addr = p;
  2256. unsigned long Flags;
  2257. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2258. ("SkGeSetMacAddr starts now...\n"));
  2259. if(netif_running(dev))
  2260. return -EBUSY;
  2261. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2262. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2263. if (pAC->RlmtNets == 2)
  2264. SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
  2265. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2266. else
  2267. SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
  2268. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2269. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2270. return 0;
  2271. } /* SkGeSetMacAddr */
  2272. /*****************************************************************************
  2273. *
  2274. * SkGeSetRxMode - set receive mode
  2275. *
  2276. * Description:
  2277. * This function sets the receive mode of an adapter. The adapter
  2278. * supports promiscuous mode, allmulticast mode and a number of
  2279. * multicast addresses. If more multicast addresses the available
  2280. * are selected, a hash function in the hardware is used.
  2281. *
  2282. * Returns:
  2283. * 0, if everything is ok
  2284. * !=0, on error
  2285. */
  2286. static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
  2287. {
  2288. DEV_NET *pNet;
  2289. SK_AC *pAC;
  2290. struct dev_mc_list *pMcList;
  2291. int i;
  2292. int PortIdx;
  2293. unsigned long Flags;
  2294. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2295. ("SkGeSetRxMode starts now... "));
  2296. pNet = netdev_priv(dev);
  2297. pAC = pNet->pAC;
  2298. if (pAC->RlmtNets == 1)
  2299. PortIdx = pAC->ActivePort;
  2300. else
  2301. PortIdx = pNet->NetNr;
  2302. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2303. if (dev->flags & IFF_PROMISC) {
  2304. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2305. ("PROMISCUOUS mode\n"));
  2306. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2307. SK_PROM_MODE_LLC);
  2308. } else if (dev->flags & IFF_ALLMULTI) {
  2309. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2310. ("ALLMULTI mode\n"));
  2311. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2312. SK_PROM_MODE_ALL_MC);
  2313. } else {
  2314. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2315. SK_PROM_MODE_NONE);
  2316. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  2317. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2318. ("Number of MC entries: %d ", dev->mc_count));
  2319. pMcList = dev->mc_list;
  2320. for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
  2321. SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
  2322. (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
  2323. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
  2324. ("%02x:%02x:%02x:%02x:%02x:%02x\n",
  2325. pMcList->dmi_addr[0],
  2326. pMcList->dmi_addr[1],
  2327. pMcList->dmi_addr[2],
  2328. pMcList->dmi_addr[3],
  2329. pMcList->dmi_addr[4],
  2330. pMcList->dmi_addr[5]));
  2331. }
  2332. SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
  2333. }
  2334. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2335. return;
  2336. } /* SkGeSetRxMode */
  2337. /*****************************************************************************
  2338. *
  2339. * SkGeChangeMtu - set the MTU to another value
  2340. *
  2341. * Description:
  2342. * This function sets is called whenever the MTU size is changed
  2343. * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
  2344. * ethernet MTU size, long frame support is activated.
  2345. *
  2346. * Returns:
  2347. * 0, if everything is ok
  2348. * !=0, on error
  2349. */
  2350. static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
  2351. {
  2352. DEV_NET *pNet;
  2353. DEV_NET *pOtherNet;
  2354. SK_AC *pAC;
  2355. unsigned long Flags;
  2356. int i;
  2357. SK_EVPARA EvPara;
  2358. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2359. ("SkGeChangeMtu starts now...\n"));
  2360. pNet = netdev_priv(dev);
  2361. pAC = pNet->pAC;
  2362. if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
  2363. return -EINVAL;
  2364. }
  2365. if(pAC->BoardLevel != SK_INIT_RUN) {
  2366. return -EINVAL;
  2367. }
  2368. #ifdef SK_DIAG_SUPPORT
  2369. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  2370. if (pAC->DiagFlowCtrl == SK_FALSE) {
  2371. return -1; /* still in use, deny any actions of MTU */
  2372. } else {
  2373. pAC->DiagFlowCtrl = SK_FALSE;
  2374. }
  2375. }
  2376. #endif
  2377. pNet->Mtu = NewMtu;
  2378. pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
  2379. if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
  2380. return(0);
  2381. }
  2382. pAC->RxBufSize = NewMtu + 32;
  2383. dev->mtu = NewMtu;
  2384. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2385. ("New MTU: %d\n", NewMtu));
  2386. /*
  2387. ** Prevent any reconfiguration while changing the MTU
  2388. ** by disabling any interrupts
  2389. */
  2390. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  2391. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2392. /*
  2393. ** Notify RLMT that any ports are to be stopped
  2394. */
  2395. EvPara.Para32[0] = 0;
  2396. EvPara.Para32[1] = -1;
  2397. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2398. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2399. EvPara.Para32[0] = 1;
  2400. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2401. } else {
  2402. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2403. }
  2404. /*
  2405. ** After calling the SkEventDispatcher(), RLMT is aware about
  2406. ** the stopped ports -> configuration can take place!
  2407. */
  2408. SkEventDispatcher(pAC, pAC->IoBase);
  2409. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2410. spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
  2411. netif_stop_queue(pAC->dev[i]);
  2412. }
  2413. /*
  2414. ** Depending on the desired MTU size change, a different number of
  2415. ** RX buffers need to be allocated
  2416. */
  2417. if (NewMtu > 1500) {
  2418. /*
  2419. ** Use less rx buffers
  2420. */
  2421. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2422. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2423. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2424. (pAC->RxDescrPerRing / 4);
  2425. } else {
  2426. if (i == pAC->ActivePort) {
  2427. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2428. (pAC->RxDescrPerRing / 4);
  2429. } else {
  2430. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2431. (pAC->RxDescrPerRing / 10);
  2432. }
  2433. }
  2434. }
  2435. } else {
  2436. /*
  2437. ** Use the normal amount of rx buffers
  2438. */
  2439. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2440. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2441. pAC->RxPort[i].RxFillLimit = 1;
  2442. } else {
  2443. if (i == pAC->ActivePort) {
  2444. pAC->RxPort[i].RxFillLimit = 1;
  2445. } else {
  2446. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2447. (pAC->RxDescrPerRing / 4);
  2448. }
  2449. }
  2450. }
  2451. }
  2452. SkGeDeInit(pAC, pAC->IoBase);
  2453. /*
  2454. ** enable/disable hardware support for long frames
  2455. */
  2456. if (NewMtu > 1500) {
  2457. // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
  2458. pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
  2459. } else {
  2460. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2461. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  2462. } else {
  2463. pAC->GIni.GIPortUsage = SK_RED_LINK;
  2464. }
  2465. }
  2466. SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
  2467. SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
  2468. SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
  2469. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
  2470. SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
  2471. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
  2472. SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
  2473. /*
  2474. ** tschilling:
  2475. ** Speed and others are set back to default in level 1 init!
  2476. */
  2477. GetConfiguration(pAC);
  2478. SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2479. SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2480. SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
  2481. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2482. SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2483. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2484. SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
  2485. /*
  2486. ** clear and reinit the rx rings here
  2487. */
  2488. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2489. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  2490. ClearRxRing(pAC, &pAC->RxPort[i]);
  2491. FillRxRing(pAC, &pAC->RxPort[i]);
  2492. /*
  2493. ** Enable transmit descriptor polling
  2494. */
  2495. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  2496. FillRxRing(pAC, &pAC->RxPort[i]);
  2497. };
  2498. SkGeYellowLED(pAC, pAC->IoBase, 1);
  2499. SkDimEnableModerationIfNeeded(pAC);
  2500. SkDimDisplayModerationSettings(pAC);
  2501. netif_start_queue(pAC->dev[pNet->PortNr]);
  2502. for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
  2503. spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
  2504. }
  2505. /*
  2506. ** Enable Interrupts again
  2507. */
  2508. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  2509. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  2510. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2511. SkEventDispatcher(pAC, pAC->IoBase);
  2512. /*
  2513. ** Notify RLMT about the changing and restarting one (or more) ports
  2514. */
  2515. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2516. EvPara.Para32[0] = pAC->RlmtNets;
  2517. EvPara.Para32[1] = -1;
  2518. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
  2519. EvPara.Para32[0] = pNet->PortNr;
  2520. EvPara.Para32[1] = -1;
  2521. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2522. if (pOtherNet->Up) {
  2523. EvPara.Para32[0] = pOtherNet->PortNr;
  2524. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2525. }
  2526. } else {
  2527. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2528. }
  2529. SkEventDispatcher(pAC, pAC->IoBase);
  2530. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2531. /*
  2532. ** While testing this driver with latest kernel 2.5 (2.5.70), it
  2533. ** seems as if upper layers have a problem to handle a successful
  2534. ** return value of '0'. If such a zero is returned, the complete
  2535. ** system hangs for several minutes (!), which is in acceptable.
  2536. **
  2537. ** Currently it is not clear, what the exact reason for this problem
  2538. ** is. The implemented workaround for 2.5 is to return the desired
  2539. ** new MTU size if all needed changes for the new MTU size where
  2540. ** performed. In kernels 2.2 and 2.4, a zero value is returned,
  2541. ** which indicates the successful change of the mtu-size.
  2542. */
  2543. return NewMtu;
  2544. } /* SkGeChangeMtu */
  2545. /*****************************************************************************
  2546. *
  2547. * SkGeStats - return ethernet device statistics
  2548. *
  2549. * Description:
  2550. * This function return statistic data about the ethernet device
  2551. * to the operating system.
  2552. *
  2553. * Returns:
  2554. * pointer to the statistic structure.
  2555. */
  2556. static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
  2557. {
  2558. DEV_NET *pNet = netdev_priv(dev);
  2559. SK_AC *pAC = pNet->pAC;
  2560. SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
  2561. SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
  2562. SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
  2563. unsigned int Size; /* size of pnmi struct */
  2564. unsigned long Flags; /* for spin lock */
  2565. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2566. ("SkGeStats starts now...\n"));
  2567. pPnmiStruct = &pAC->PnmiStruct;
  2568. #ifdef SK_DIAG_SUPPORT
  2569. if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
  2570. (pAC->BoardLevel == SK_INIT_RUN)) {
  2571. #endif
  2572. SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
  2573. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2574. Size = SK_PNMI_STRUCT_SIZE;
  2575. SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
  2576. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2577. #ifdef SK_DIAG_SUPPORT
  2578. }
  2579. #endif
  2580. pPnmiStat = &pPnmiStruct->Stat[0];
  2581. pPnmiConf = &pPnmiStruct->Conf[0];
  2582. pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
  2583. pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
  2584. pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
  2585. pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
  2586. if (pNet->Mtu <= 1500) {
  2587. pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
  2588. } else {
  2589. pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
  2590. pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
  2591. }
  2592. if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
  2593. pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
  2594. pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  2595. pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
  2596. pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
  2597. pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
  2598. pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  2599. /* detailed rx_errors: */
  2600. pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
  2601. pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  2602. pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
  2603. pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
  2604. pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  2605. pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
  2606. /* detailed tx_errors */
  2607. pAC->stats.tx_aborted_errors = (SK_U32) 0;
  2608. pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  2609. pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
  2610. pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  2611. pAC->stats.tx_window_errors = (SK_U32) 0;
  2612. return(&pAC->stats);
  2613. } /* SkGeStats */
  2614. /*****************************************************************************
  2615. *
  2616. * SkGeIoctl - IO-control function
  2617. *
  2618. * Description:
  2619. * This function is called if an ioctl is issued on the device.
  2620. * There are three subfunction for reading, writing and test-writing
  2621. * the private MIB data structure (usefull for SysKonnect-internal tools).
  2622. *
  2623. * Returns:
  2624. * 0, if everything is ok
  2625. * !=0, on error
  2626. */
  2627. static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
  2628. {
  2629. DEV_NET *pNet;
  2630. SK_AC *pAC;
  2631. void *pMemBuf;
  2632. struct pci_dev *pdev = NULL;
  2633. SK_GE_IOCTL Ioctl;
  2634. unsigned int Err = 0;
  2635. int Size = 0;
  2636. int Ret = 0;
  2637. unsigned int Length = 0;
  2638. int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
  2639. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2640. ("SkGeIoctl starts now...\n"));
  2641. pNet = netdev_priv(dev);
  2642. pAC = pNet->pAC;
  2643. if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
  2644. return -EFAULT;
  2645. }
  2646. switch(cmd) {
  2647. case SK_IOCTL_SETMIB:
  2648. case SK_IOCTL_PRESETMIB:
  2649. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2650. case SK_IOCTL_GETMIB:
  2651. if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
  2652. Ioctl.Len<sizeof(pAC->PnmiStruct)?
  2653. Ioctl.Len : sizeof(pAC->PnmiStruct))) {
  2654. return -EFAULT;
  2655. }
  2656. Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
  2657. if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
  2658. Ioctl.Len<Size? Ioctl.Len : Size)) {
  2659. return -EFAULT;
  2660. }
  2661. Ioctl.Len = Size;
  2662. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2663. return -EFAULT;
  2664. }
  2665. break;
  2666. case SK_IOCTL_GEN:
  2667. if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
  2668. Length = Ioctl.Len;
  2669. } else {
  2670. Length = sizeof(pAC->PnmiStruct) + HeaderLength;
  2671. }
  2672. if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
  2673. return -ENOMEM;
  2674. }
  2675. if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
  2676. Err = -EFAULT;
  2677. goto fault_gen;
  2678. }
  2679. if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
  2680. Err = -EFAULT;
  2681. goto fault_gen;
  2682. }
  2683. if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
  2684. Err = -EFAULT;
  2685. goto fault_gen;
  2686. }
  2687. Ioctl.Len = Length;
  2688. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2689. Err = -EFAULT;
  2690. goto fault_gen;
  2691. }
  2692. fault_gen:
  2693. kfree(pMemBuf); /* cleanup everything */
  2694. break;
  2695. #ifdef SK_DIAG_SUPPORT
  2696. case SK_IOCTL_DIAG:
  2697. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2698. if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
  2699. Length = Ioctl.Len;
  2700. } else {
  2701. Length = sizeof(pAC->PnmiStruct) + HeaderLength;
  2702. }
  2703. if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
  2704. return -ENOMEM;
  2705. }
  2706. if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
  2707. Err = -EFAULT;
  2708. goto fault_diag;
  2709. }
  2710. pdev = pAC->PciDev;
  2711. Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
  2712. /*
  2713. ** While coding this new IOCTL interface, only a few lines of code
  2714. ** are to to be added. Therefore no dedicated function has been
  2715. ** added. If more functionality is added, a separate function
  2716. ** should be used...
  2717. */
  2718. * ((SK_U32 *)pMemBuf) = 0;
  2719. * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
  2720. * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
  2721. if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
  2722. Err = -EFAULT;
  2723. goto fault_diag;
  2724. }
  2725. Ioctl.Len = Length;
  2726. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2727. Err = -EFAULT;
  2728. goto fault_diag;
  2729. }
  2730. fault_diag:
  2731. kfree(pMemBuf); /* cleanup everything */
  2732. break;
  2733. #endif
  2734. default:
  2735. Err = -EOPNOTSUPP;
  2736. }
  2737. return(Err);
  2738. } /* SkGeIoctl */
  2739. /*****************************************************************************
  2740. *
  2741. * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
  2742. *
  2743. * Description:
  2744. * This function reads/writes the MIB data using PNMI (Private Network
  2745. * Management Interface).
  2746. * The destination for the data must be provided with the
  2747. * ioctl call and is given to the driver in the form of
  2748. * a user space address.
  2749. * Copying from the user-provided data area into kernel messages
  2750. * and back is done by copy_from_user and copy_to_user calls in
  2751. * SkGeIoctl.
  2752. *
  2753. * Returns:
  2754. * returned size from PNMI call
  2755. */
  2756. static int SkGeIocMib(
  2757. DEV_NET *pNet, /* pointer to the adapter context */
  2758. unsigned int Size, /* length of ioctl data */
  2759. int mode) /* flag for set/preset */
  2760. {
  2761. unsigned long Flags; /* for spin lock */
  2762. SK_AC *pAC;
  2763. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2764. ("SkGeIocMib starts now...\n"));
  2765. pAC = pNet->pAC;
  2766. /* access MIB */
  2767. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2768. switch(mode) {
  2769. case SK_IOCTL_GETMIB:
  2770. SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2771. pNet->NetNr);
  2772. break;
  2773. case SK_IOCTL_PRESETMIB:
  2774. SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2775. pNet->NetNr);
  2776. break;
  2777. case SK_IOCTL_SETMIB:
  2778. SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2779. pNet->NetNr);
  2780. break;
  2781. default:
  2782. break;
  2783. }
  2784. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2785. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2786. ("MIB data access succeeded\n"));
  2787. return (Size);
  2788. } /* SkGeIocMib */
  2789. /*****************************************************************************
  2790. *
  2791. * GetConfiguration - read configuration information
  2792. *
  2793. * Description:
  2794. * This function reads per-adapter configuration information from
  2795. * the options provided on the command line.
  2796. *
  2797. * Returns:
  2798. * none
  2799. */
  2800. static void GetConfiguration(
  2801. SK_AC *pAC) /* pointer to the adapter context structure */
  2802. {
  2803. SK_I32 Port; /* preferred port */
  2804. SK_BOOL AutoSet;
  2805. SK_BOOL DupSet;
  2806. int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
  2807. int AutoNeg = 1; /* autoneg off (0) or on (1) */
  2808. int DuplexCap = 0; /* 0=both,1=full,2=half */
  2809. int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
  2810. int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
  2811. SK_BOOL IsConTypeDefined = SK_TRUE;
  2812. SK_BOOL IsLinkSpeedDefined = SK_TRUE;
  2813. SK_BOOL IsFlowCtrlDefined = SK_TRUE;
  2814. SK_BOOL IsRoleDefined = SK_TRUE;
  2815. SK_BOOL IsModeDefined = SK_TRUE;
  2816. /*
  2817. * The two parameters AutoNeg. and DuplexCap. map to one configuration
  2818. * parameter. The mapping is described by this table:
  2819. * DuplexCap -> | both | full | half |
  2820. * AutoNeg | | | |
  2821. * -----------------------------------------------------------------
  2822. * Off | illegal | Full | Half |
  2823. * -----------------------------------------------------------------
  2824. * On | AutoBoth | AutoFull | AutoHalf |
  2825. * -----------------------------------------------------------------
  2826. * Sense | AutoSense | AutoSense | AutoSense |
  2827. */
  2828. int Capabilities[3][3] =
  2829. { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
  2830. {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
  2831. {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
  2832. #define DC_BOTH 0
  2833. #define DC_FULL 1
  2834. #define DC_HALF 2
  2835. #define AN_OFF 0
  2836. #define AN_ON 1
  2837. #define AN_SENS 2
  2838. #define M_CurrPort pAC->GIni.GP[Port]
  2839. /*
  2840. ** Set the default values first for both ports!
  2841. */
  2842. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2843. M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
  2844. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  2845. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2846. M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
  2847. }
  2848. /*
  2849. ** Check merged parameter ConType. If it has not been used,
  2850. ** verify any other parameter (e.g. AutoNeg) and use default values.
  2851. **
  2852. ** Stating both ConType and other lowlevel link parameters is also
  2853. ** possible. If this is the case, the passed ConType-parameter is
  2854. ** overwritten by the lowlevel link parameter.
  2855. **
  2856. ** The following settings are used for a merged ConType-parameter:
  2857. **
  2858. ** ConType DupCap AutoNeg FlowCtrl Role Speed
  2859. ** ------- ------ ------- -------- ---------- -----
  2860. ** Auto Both On SymOrRem Auto Auto
  2861. ** 100FD Full Off None <ignored> 100
  2862. ** 100HD Half Off None <ignored> 100
  2863. ** 10FD Full Off None <ignored> 10
  2864. ** 10HD Half Off None <ignored> 10
  2865. **
  2866. ** This ConType parameter is used for all ports of the adapter!
  2867. */
  2868. if ( (ConType != NULL) &&
  2869. (pAC->Index < SK_MAX_CARD_PARAM) &&
  2870. (ConType[pAC->Index] != NULL) ) {
  2871. /* Check chipset family */
  2872. if ((!pAC->ChipsetType) &&
  2873. (strcmp(ConType[pAC->Index],"Auto")!=0) &&
  2874. (strcmp(ConType[pAC->Index],"")!=0)) {
  2875. /* Set the speed parameter back */
  2876. printk("sk98lin: Illegal value \"%s\" "
  2877. "for ConType."
  2878. " Using Auto.\n",
  2879. ConType[pAC->Index]);
  2880. sprintf(ConType[pAC->Index], "Auto");
  2881. }
  2882. if (strcmp(ConType[pAC->Index],"")==0) {
  2883. IsConTypeDefined = SK_FALSE; /* No ConType defined */
  2884. } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
  2885. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2886. M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
  2887. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  2888. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2889. M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
  2890. }
  2891. } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
  2892. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2893. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
  2894. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2895. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2896. M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
  2897. }
  2898. } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
  2899. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2900. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
  2901. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2902. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2903. M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
  2904. }
  2905. } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
  2906. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2907. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
  2908. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2909. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2910. M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
  2911. }
  2912. } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
  2913. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2914. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
  2915. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2916. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2917. M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
  2918. }
  2919. } else {
  2920. printk("sk98lin: Illegal value \"%s\" for ConType\n",
  2921. ConType[pAC->Index]);
  2922. IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
  2923. }
  2924. } else {
  2925. IsConTypeDefined = SK_FALSE; /* No ConType defined */
  2926. }
  2927. /*
  2928. ** Parse any parameter settings for port A:
  2929. ** a) any LinkSpeed stated?
  2930. */
  2931. if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  2932. Speed_A[pAC->Index] != NULL) {
  2933. if (strcmp(Speed_A[pAC->Index],"")==0) {
  2934. IsLinkSpeedDefined = SK_FALSE;
  2935. } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
  2936. LinkSpeed = SK_LSPEED_AUTO;
  2937. } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
  2938. LinkSpeed = SK_LSPEED_10MBPS;
  2939. } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
  2940. LinkSpeed = SK_LSPEED_100MBPS;
  2941. } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
  2942. LinkSpeed = SK_LSPEED_1000MBPS;
  2943. } else {
  2944. printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
  2945. Speed_A[pAC->Index]);
  2946. IsLinkSpeedDefined = SK_FALSE;
  2947. }
  2948. } else {
  2949. IsLinkSpeedDefined = SK_FALSE;
  2950. }
  2951. /*
  2952. ** Check speed parameter:
  2953. ** Only copper type adapter and GE V2 cards
  2954. */
  2955. if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
  2956. ((LinkSpeed != SK_LSPEED_AUTO) &&
  2957. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  2958. printk("sk98lin: Illegal value for Speed_A. "
  2959. "Not a copper card or GE V2 card\n Using "
  2960. "speed 1000\n");
  2961. LinkSpeed = SK_LSPEED_1000MBPS;
  2962. }
  2963. /*
  2964. ** Decide whether to set new config value if somethig valid has
  2965. ** been received.
  2966. */
  2967. if (IsLinkSpeedDefined) {
  2968. pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
  2969. }
  2970. /*
  2971. ** b) Any Autonegotiation and DuplexCapabilities set?
  2972. ** Please note that both belong together...
  2973. */
  2974. AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
  2975. AutoSet = SK_FALSE;
  2976. if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  2977. AutoNeg_A[pAC->Index] != NULL) {
  2978. AutoSet = SK_TRUE;
  2979. if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
  2980. AutoSet = SK_FALSE;
  2981. } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
  2982. AutoNeg = AN_ON;
  2983. } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
  2984. AutoNeg = AN_OFF;
  2985. } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
  2986. AutoNeg = AN_SENS;
  2987. } else {
  2988. printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
  2989. AutoNeg_A[pAC->Index]);
  2990. }
  2991. }
  2992. DuplexCap = DC_BOTH;
  2993. DupSet = SK_FALSE;
  2994. if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  2995. DupCap_A[pAC->Index] != NULL) {
  2996. DupSet = SK_TRUE;
  2997. if (strcmp(DupCap_A[pAC->Index],"")==0) {
  2998. DupSet = SK_FALSE;
  2999. } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
  3000. DuplexCap = DC_BOTH;
  3001. } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
  3002. DuplexCap = DC_FULL;
  3003. } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
  3004. DuplexCap = DC_HALF;
  3005. } else {
  3006. printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
  3007. DupCap_A[pAC->Index]);
  3008. }
  3009. }
  3010. /*
  3011. ** Check for illegal combinations
  3012. */
  3013. if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
  3014. ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
  3015. (DuplexCap == SK_LMODE_STAT_HALF)) &&
  3016. (pAC->ChipsetType)) {
  3017. printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
  3018. " Using Full Duplex.\n");
  3019. DuplexCap = DC_FULL;
  3020. }
  3021. if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
  3022. printk("sk98lin, Port A: DuplexCapabilities"
  3023. " ignored using Sense mode\n");
  3024. }
  3025. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3026. printk("sk98lin: Port A: Illegal combination"
  3027. " of values AutoNeg. and DuplexCap.\n Using "
  3028. "Full Duplex\n");
  3029. DuplexCap = DC_FULL;
  3030. }
  3031. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3032. DuplexCap = DC_FULL;
  3033. }
  3034. if (!AutoSet && DupSet) {
  3035. printk("sk98lin: Port A: Duplex setting not"
  3036. " possible in\n default AutoNegotiation mode"
  3037. " (Sense).\n Using AutoNegotiation On\n");
  3038. AutoNeg = AN_ON;
  3039. }
  3040. /*
  3041. ** set the desired mode
  3042. */
  3043. if (AutoSet || DupSet) {
  3044. pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
  3045. }
  3046. /*
  3047. ** c) Any Flowcontrol-parameter set?
  3048. */
  3049. if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3050. FlowCtrl_A[pAC->Index] != NULL) {
  3051. if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
  3052. IsFlowCtrlDefined = SK_FALSE;
  3053. } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
  3054. FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
  3055. } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
  3056. FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
  3057. } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
  3058. FlowCtrl = SK_FLOW_MODE_LOC_SEND;
  3059. } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
  3060. FlowCtrl = SK_FLOW_MODE_NONE;
  3061. } else {
  3062. printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
  3063. FlowCtrl_A[pAC->Index]);
  3064. IsFlowCtrlDefined = SK_FALSE;
  3065. }
  3066. } else {
  3067. IsFlowCtrlDefined = SK_FALSE;
  3068. }
  3069. if (IsFlowCtrlDefined) {
  3070. if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
  3071. printk("sk98lin: Port A: FlowControl"
  3072. " impossible without AutoNegotiation,"
  3073. " disabled\n");
  3074. FlowCtrl = SK_FLOW_MODE_NONE;
  3075. }
  3076. pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
  3077. }
  3078. /*
  3079. ** d) What is with the RoleParameter?
  3080. */
  3081. if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3082. Role_A[pAC->Index] != NULL) {
  3083. if (strcmp(Role_A[pAC->Index],"")==0) {
  3084. IsRoleDefined = SK_FALSE;
  3085. } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
  3086. MSMode = SK_MS_MODE_AUTO;
  3087. } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
  3088. MSMode = SK_MS_MODE_MASTER;
  3089. } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
  3090. MSMode = SK_MS_MODE_SLAVE;
  3091. } else {
  3092. printk("sk98lin: Illegal value \"%s\" for Role_A\n",
  3093. Role_A[pAC->Index]);
  3094. IsRoleDefined = SK_FALSE;
  3095. }
  3096. } else {
  3097. IsRoleDefined = SK_FALSE;
  3098. }
  3099. if (IsRoleDefined == SK_TRUE) {
  3100. pAC->GIni.GP[0].PMSMode = MSMode;
  3101. }
  3102. /*
  3103. ** Parse any parameter settings for port B:
  3104. ** a) any LinkSpeed stated?
  3105. */
  3106. IsConTypeDefined = SK_TRUE;
  3107. IsLinkSpeedDefined = SK_TRUE;
  3108. IsFlowCtrlDefined = SK_TRUE;
  3109. IsModeDefined = SK_TRUE;
  3110. if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3111. Speed_B[pAC->Index] != NULL) {
  3112. if (strcmp(Speed_B[pAC->Index],"")==0) {
  3113. IsLinkSpeedDefined = SK_FALSE;
  3114. } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
  3115. LinkSpeed = SK_LSPEED_AUTO;
  3116. } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
  3117. LinkSpeed = SK_LSPEED_10MBPS;
  3118. } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
  3119. LinkSpeed = SK_LSPEED_100MBPS;
  3120. } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
  3121. LinkSpeed = SK_LSPEED_1000MBPS;
  3122. } else {
  3123. printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
  3124. Speed_B[pAC->Index]);
  3125. IsLinkSpeedDefined = SK_FALSE;
  3126. }
  3127. } else {
  3128. IsLinkSpeedDefined = SK_FALSE;
  3129. }
  3130. /*
  3131. ** Check speed parameter:
  3132. ** Only copper type adapter and GE V2 cards
  3133. */
  3134. if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
  3135. ((LinkSpeed != SK_LSPEED_AUTO) &&
  3136. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  3137. printk("sk98lin: Illegal value for Speed_B. "
  3138. "Not a copper card or GE V2 card\n Using "
  3139. "speed 1000\n");
  3140. LinkSpeed = SK_LSPEED_1000MBPS;
  3141. }
  3142. /*
  3143. ** Decide whether to set new config value if somethig valid has
  3144. ** been received.
  3145. */
  3146. if (IsLinkSpeedDefined) {
  3147. pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
  3148. }
  3149. /*
  3150. ** b) Any Autonegotiation and DuplexCapabilities set?
  3151. ** Please note that both belong together...
  3152. */
  3153. AutoNeg = AN_SENS; /* default: do auto Sense */
  3154. AutoSet = SK_FALSE;
  3155. if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3156. AutoNeg_B[pAC->Index] != NULL) {
  3157. AutoSet = SK_TRUE;
  3158. if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
  3159. AutoSet = SK_FALSE;
  3160. } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
  3161. AutoNeg = AN_ON;
  3162. } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
  3163. AutoNeg = AN_OFF;
  3164. } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
  3165. AutoNeg = AN_SENS;
  3166. } else {
  3167. printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
  3168. AutoNeg_B[pAC->Index]);
  3169. }
  3170. }
  3171. DuplexCap = DC_BOTH;
  3172. DupSet = SK_FALSE;
  3173. if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3174. DupCap_B[pAC->Index] != NULL) {
  3175. DupSet = SK_TRUE;
  3176. if (strcmp(DupCap_B[pAC->Index],"")==0) {
  3177. DupSet = SK_FALSE;
  3178. } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
  3179. DuplexCap = DC_BOTH;
  3180. } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
  3181. DuplexCap = DC_FULL;
  3182. } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
  3183. DuplexCap = DC_HALF;
  3184. } else {
  3185. printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
  3186. DupCap_B[pAC->Index]);
  3187. }
  3188. }
  3189. /*
  3190. ** Check for illegal combinations
  3191. */
  3192. if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
  3193. ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
  3194. (DuplexCap == SK_LMODE_STAT_HALF)) &&
  3195. (pAC->ChipsetType)) {
  3196. printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
  3197. " Using Full Duplex.\n");
  3198. DuplexCap = DC_FULL;
  3199. }
  3200. if (AutoSet && AutoNeg==AN_SENS && DupSet) {
  3201. printk("sk98lin, Port B: DuplexCapabilities"
  3202. " ignored using Sense mode\n");
  3203. }
  3204. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3205. printk("sk98lin: Port B: Illegal combination"
  3206. " of values AutoNeg. and DuplexCap.\n Using "
  3207. "Full Duplex\n");
  3208. DuplexCap = DC_FULL;
  3209. }
  3210. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3211. DuplexCap = DC_FULL;
  3212. }
  3213. if (!AutoSet && DupSet) {
  3214. printk("sk98lin: Port B: Duplex setting not"
  3215. " possible in\n default AutoNegotiation mode"
  3216. " (Sense).\n Using AutoNegotiation On\n");
  3217. AutoNeg = AN_ON;
  3218. }
  3219. /*
  3220. ** set the desired mode
  3221. */
  3222. if (AutoSet || DupSet) {
  3223. pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
  3224. }
  3225. /*
  3226. ** c) Any FlowCtrl parameter set?
  3227. */
  3228. if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3229. FlowCtrl_B[pAC->Index] != NULL) {
  3230. if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
  3231. IsFlowCtrlDefined = SK_FALSE;
  3232. } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
  3233. FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
  3234. } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
  3235. FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
  3236. } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
  3237. FlowCtrl = SK_FLOW_MODE_LOC_SEND;
  3238. } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
  3239. FlowCtrl = SK_FLOW_MODE_NONE;
  3240. } else {
  3241. printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
  3242. FlowCtrl_B[pAC->Index]);
  3243. IsFlowCtrlDefined = SK_FALSE;
  3244. }
  3245. } else {
  3246. IsFlowCtrlDefined = SK_FALSE;
  3247. }
  3248. if (IsFlowCtrlDefined) {
  3249. if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
  3250. printk("sk98lin: Port B: FlowControl"
  3251. " impossible without AutoNegotiation,"
  3252. " disabled\n");
  3253. FlowCtrl = SK_FLOW_MODE_NONE;
  3254. }
  3255. pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
  3256. }
  3257. /*
  3258. ** d) What is the RoleParameter?
  3259. */
  3260. if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3261. Role_B[pAC->Index] != NULL) {
  3262. if (strcmp(Role_B[pAC->Index],"")==0) {
  3263. IsRoleDefined = SK_FALSE;
  3264. } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
  3265. MSMode = SK_MS_MODE_AUTO;
  3266. } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
  3267. MSMode = SK_MS_MODE_MASTER;
  3268. } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
  3269. MSMode = SK_MS_MODE_SLAVE;
  3270. } else {
  3271. printk("sk98lin: Illegal value \"%s\" for Role_B\n",
  3272. Role_B[pAC->Index]);
  3273. IsRoleDefined = SK_FALSE;
  3274. }
  3275. } else {
  3276. IsRoleDefined = SK_FALSE;
  3277. }
  3278. if (IsRoleDefined) {
  3279. pAC->GIni.GP[1].PMSMode = MSMode;
  3280. }
  3281. /*
  3282. ** Evaluate settings for both ports
  3283. */
  3284. pAC->ActivePort = 0;
  3285. if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3286. PrefPort[pAC->Index] != NULL) {
  3287. if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
  3288. pAC->ActivePort = 0;
  3289. pAC->Rlmt.Net[0].Preference = -1; /* auto */
  3290. pAC->Rlmt.Net[0].PrefPort = 0;
  3291. } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
  3292. /*
  3293. ** do not set ActivePort here, thus a port
  3294. ** switch is issued after net up.
  3295. */
  3296. Port = 0;
  3297. pAC->Rlmt.Net[0].Preference = Port;
  3298. pAC->Rlmt.Net[0].PrefPort = Port;
  3299. } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
  3300. /*
  3301. ** do not set ActivePort here, thus a port
  3302. ** switch is issued after net up.
  3303. */
  3304. if (pAC->GIni.GIMacsFound == 1) {
  3305. printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
  3306. " Port B not available on single port adapters.\n");
  3307. pAC->ActivePort = 0;
  3308. pAC->Rlmt.Net[0].Preference = -1; /* auto */
  3309. pAC->Rlmt.Net[0].PrefPort = 0;
  3310. } else {
  3311. Port = 1;
  3312. pAC->Rlmt.Net[0].Preference = Port;
  3313. pAC->Rlmt.Net[0].PrefPort = Port;
  3314. }
  3315. } else {
  3316. printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
  3317. PrefPort[pAC->Index]);
  3318. }
  3319. }
  3320. pAC->RlmtNets = 1;
  3321. if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3322. RlmtMode[pAC->Index] != NULL) {
  3323. if (strcmp(RlmtMode[pAC->Index], "") == 0) {
  3324. pAC->RlmtMode = 0;
  3325. } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
  3326. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3327. } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
  3328. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3329. SK_RLMT_CHECK_LOC_LINK;
  3330. } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
  3331. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3332. SK_RLMT_CHECK_LOC_LINK |
  3333. SK_RLMT_CHECK_SEG;
  3334. } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
  3335. (pAC->GIni.GIMacsFound == 2)) {
  3336. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3337. pAC->RlmtNets = 2;
  3338. } else {
  3339. printk("sk98lin: Illegal value \"%s\" for"
  3340. " RlmtMode, using default\n",
  3341. RlmtMode[pAC->Index]);
  3342. pAC->RlmtMode = 0;
  3343. }
  3344. } else {
  3345. pAC->RlmtMode = 0;
  3346. }
  3347. /*
  3348. ** Check the interrupt moderation parameters
  3349. */
  3350. if (Moderation[pAC->Index] != NULL) {
  3351. if (strcmp(Moderation[pAC->Index], "") == 0) {
  3352. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3353. } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
  3354. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
  3355. } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
  3356. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
  3357. } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
  3358. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3359. } else {
  3360. printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
  3361. " Disable interrupt moderation.\n",
  3362. Moderation[pAC->Index]);
  3363. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3364. }
  3365. } else {
  3366. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3367. }
  3368. if (Stats[pAC->Index] != NULL) {
  3369. if (strcmp(Stats[pAC->Index], "Yes") == 0) {
  3370. pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
  3371. } else {
  3372. pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
  3373. }
  3374. } else {
  3375. pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
  3376. }
  3377. if (ModerationMask[pAC->Index] != NULL) {
  3378. if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
  3379. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
  3380. } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
  3381. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
  3382. } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
  3383. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
  3384. } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
  3385. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
  3386. } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
  3387. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
  3388. } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
  3389. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3390. } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
  3391. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3392. } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
  3393. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
  3394. } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
  3395. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
  3396. } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
  3397. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3398. } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
  3399. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3400. } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
  3401. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3402. } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
  3403. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3404. } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
  3405. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3406. } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
  3407. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3408. } else { /* some rubbish */
  3409. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
  3410. }
  3411. } else { /* operator has stated nothing */
  3412. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3413. }
  3414. if (AutoSizing[pAC->Index] != NULL) {
  3415. if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
  3416. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3417. } else {
  3418. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3419. }
  3420. } else { /* operator has stated nothing */
  3421. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3422. }
  3423. if (IntsPerSec[pAC->Index] != 0) {
  3424. if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
  3425. (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
  3426. printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
  3427. " Using default value of %i.\n",
  3428. IntsPerSec[pAC->Index],
  3429. C_INT_MOD_IPS_LOWER_RANGE,
  3430. C_INT_MOD_IPS_UPPER_RANGE,
  3431. C_INTS_PER_SEC_DEFAULT);
  3432. pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
  3433. } else {
  3434. pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
  3435. }
  3436. } else {
  3437. pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
  3438. }
  3439. /*
  3440. ** Evaluate upper and lower moderation threshold
  3441. */
  3442. pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
  3443. pAC->DynIrqModInfo.MaxModIntsPerSec +
  3444. (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
  3445. pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
  3446. pAC->DynIrqModInfo.MaxModIntsPerSec -
  3447. (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
  3448. pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
  3449. } /* GetConfiguration */
  3450. /*****************************************************************************
  3451. *
  3452. * ProductStr - return a adapter identification string from vpd
  3453. *
  3454. * Description:
  3455. * This function reads the product name string from the vpd area
  3456. * and puts it the field pAC->DeviceString.
  3457. *
  3458. * Returns: N/A
  3459. */
  3460. static void ProductStr(
  3461. SK_AC *pAC /* pointer to adapter context */
  3462. )
  3463. {
  3464. int StrLen = 80; /* length of the string, defined in SK_AC */
  3465. char Keyword[] = VPD_NAME; /* vpd productname identifier */
  3466. int ReturnCode; /* return code from vpd_read */
  3467. unsigned long Flags;
  3468. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  3469. ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
  3470. &StrLen);
  3471. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3472. if (ReturnCode != 0) {
  3473. /* there was an error reading the vpd data */
  3474. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  3475. ("Error reading VPD data: %d\n", ReturnCode));
  3476. pAC->DeviceStr[0] = '\0';
  3477. }
  3478. } /* ProductStr */
  3479. /*****************************************************************************
  3480. *
  3481. * StartDrvCleanupTimer - Start timer to check for descriptors which
  3482. * might be placed in descriptor ring, but
  3483. * havent been handled up to now
  3484. *
  3485. * Description:
  3486. * This function requests a HW-timer fo the Yukon card. The actions to
  3487. * perform when this timer expires, are located in the SkDrvEvent().
  3488. *
  3489. * Returns: N/A
  3490. */
  3491. static void
  3492. StartDrvCleanupTimer(SK_AC *pAC) {
  3493. SK_EVPARA EventParam; /* Event struct for timer event */
  3494. SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
  3495. EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
  3496. SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
  3497. SK_DRV_RX_CLEANUP_TIMER_LENGTH,
  3498. SKGE_DRV, SK_DRV_TIMER, EventParam);
  3499. }
  3500. /*****************************************************************************
  3501. *
  3502. * StopDrvCleanupTimer - Stop timer to check for descriptors
  3503. *
  3504. * Description:
  3505. * This function requests a HW-timer fo the Yukon card. The actions to
  3506. * perform when this timer expires, are located in the SkDrvEvent().
  3507. *
  3508. * Returns: N/A
  3509. */
  3510. static void
  3511. StopDrvCleanupTimer(SK_AC *pAC) {
  3512. SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
  3513. SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
  3514. }
  3515. /****************************************************************************/
  3516. /* functions for common modules *********************************************/
  3517. /****************************************************************************/
  3518. /*****************************************************************************
  3519. *
  3520. * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
  3521. *
  3522. * Description:
  3523. * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
  3524. * is embedded into a socket buff data area.
  3525. *
  3526. * Context:
  3527. * runtime
  3528. *
  3529. * Returns:
  3530. * NULL or pointer to Mbuf.
  3531. */
  3532. SK_MBUF *SkDrvAllocRlmtMbuf(
  3533. SK_AC *pAC, /* pointer to adapter context */
  3534. SK_IOC IoC, /* the IO-context */
  3535. unsigned BufferSize) /* size of the requested buffer */
  3536. {
  3537. SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
  3538. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  3539. pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
  3540. if (pMsgBlock == NULL) {
  3541. return (NULL);
  3542. }
  3543. pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
  3544. skb_reserve(pMsgBlock, sizeof(SK_MBUF));
  3545. pRlmtMbuf->pNext = NULL;
  3546. pRlmtMbuf->pOs = pMsgBlock;
  3547. pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
  3548. pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
  3549. pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
  3550. return (pRlmtMbuf);
  3551. } /* SkDrvAllocRlmtMbuf */
  3552. /*****************************************************************************
  3553. *
  3554. * SkDrvFreeRlmtMbuf - free an RLMT mbuf
  3555. *
  3556. * Description:
  3557. * This routine frees one or more RLMT mbuf(s).
  3558. *
  3559. * Context:
  3560. * runtime
  3561. *
  3562. * Returns:
  3563. * Nothing
  3564. */
  3565. void SkDrvFreeRlmtMbuf(
  3566. SK_AC *pAC, /* pointer to adapter context */
  3567. SK_IOC IoC, /* the IO-context */
  3568. SK_MBUF *pMbuf) /* size of the requested buffer */
  3569. {
  3570. SK_MBUF *pFreeMbuf;
  3571. SK_MBUF *pNextMbuf;
  3572. pFreeMbuf = pMbuf;
  3573. do {
  3574. pNextMbuf = pFreeMbuf->pNext;
  3575. DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
  3576. pFreeMbuf = pNextMbuf;
  3577. } while ( pFreeMbuf != NULL );
  3578. } /* SkDrvFreeRlmtMbuf */
  3579. /*****************************************************************************
  3580. *
  3581. * SkOsGetTime - provide a time value
  3582. *
  3583. * Description:
  3584. * This routine provides a time value. The unit is 1/HZ (defined by Linux).
  3585. * It is not used for absolute time, but only for time differences.
  3586. *
  3587. *
  3588. * Returns:
  3589. * Time value
  3590. */
  3591. SK_U64 SkOsGetTime(SK_AC *pAC)
  3592. {
  3593. SK_U64 PrivateJiffies;
  3594. SkOsGetTimeCurrent(pAC, &PrivateJiffies);
  3595. return PrivateJiffies;
  3596. } /* SkOsGetTime */
  3597. /*****************************************************************************
  3598. *
  3599. * SkPciReadCfgDWord - read a 32 bit value from pci config space
  3600. *
  3601. * Description:
  3602. * This routine reads a 32 bit value from the pci configuration
  3603. * space.
  3604. *
  3605. * Returns:
  3606. * 0 - indicate everything worked ok.
  3607. * != 0 - error indication
  3608. */
  3609. int SkPciReadCfgDWord(
  3610. SK_AC *pAC, /* Adapter Control structure pointer */
  3611. int PciAddr, /* PCI register address */
  3612. SK_U32 *pVal) /* pointer to store the read value */
  3613. {
  3614. pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
  3615. return(0);
  3616. } /* SkPciReadCfgDWord */
  3617. /*****************************************************************************
  3618. *
  3619. * SkPciReadCfgWord - read a 16 bit value from pci config space
  3620. *
  3621. * Description:
  3622. * This routine reads a 16 bit value from the pci configuration
  3623. * space.
  3624. *
  3625. * Returns:
  3626. * 0 - indicate everything worked ok.
  3627. * != 0 - error indication
  3628. */
  3629. int SkPciReadCfgWord(
  3630. SK_AC *pAC, /* Adapter Control structure pointer */
  3631. int PciAddr, /* PCI register address */
  3632. SK_U16 *pVal) /* pointer to store the read value */
  3633. {
  3634. pci_read_config_word(pAC->PciDev, PciAddr, pVal);
  3635. return(0);
  3636. } /* SkPciReadCfgWord */
  3637. /*****************************************************************************
  3638. *
  3639. * SkPciReadCfgByte - read a 8 bit value from pci config space
  3640. *
  3641. * Description:
  3642. * This routine reads a 8 bit value from the pci configuration
  3643. * space.
  3644. *
  3645. * Returns:
  3646. * 0 - indicate everything worked ok.
  3647. * != 0 - error indication
  3648. */
  3649. int SkPciReadCfgByte(
  3650. SK_AC *pAC, /* Adapter Control structure pointer */
  3651. int PciAddr, /* PCI register address */
  3652. SK_U8 *pVal) /* pointer to store the read value */
  3653. {
  3654. pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
  3655. return(0);
  3656. } /* SkPciReadCfgByte */
  3657. /*****************************************************************************
  3658. *
  3659. * SkPciWriteCfgDWord - write a 32 bit value to pci config space
  3660. *
  3661. * Description:
  3662. * This routine writes a 32 bit value to the pci configuration
  3663. * space.
  3664. *
  3665. * Returns:
  3666. * 0 - indicate everything worked ok.
  3667. * != 0 - error indication
  3668. */
  3669. int SkPciWriteCfgDWord(
  3670. SK_AC *pAC, /* Adapter Control structure pointer */
  3671. int PciAddr, /* PCI register address */
  3672. SK_U32 Val) /* pointer to store the read value */
  3673. {
  3674. pci_write_config_dword(pAC->PciDev, PciAddr, Val);
  3675. return(0);
  3676. } /* SkPciWriteCfgDWord */
  3677. /*****************************************************************************
  3678. *
  3679. * SkPciWriteCfgWord - write a 16 bit value to pci config space
  3680. *
  3681. * Description:
  3682. * This routine writes a 16 bit value to the pci configuration
  3683. * space. The flag PciConfigUp indicates whether the config space
  3684. * is accesible or must be set up first.
  3685. *
  3686. * Returns:
  3687. * 0 - indicate everything worked ok.
  3688. * != 0 - error indication
  3689. */
  3690. int SkPciWriteCfgWord(
  3691. SK_AC *pAC, /* Adapter Control structure pointer */
  3692. int PciAddr, /* PCI register address */
  3693. SK_U16 Val) /* pointer to store the read value */
  3694. {
  3695. pci_write_config_word(pAC->PciDev, PciAddr, Val);
  3696. return(0);
  3697. } /* SkPciWriteCfgWord */
  3698. /*****************************************************************************
  3699. *
  3700. * SkPciWriteCfgWord - write a 8 bit value to pci config space
  3701. *
  3702. * Description:
  3703. * This routine writes a 8 bit value to the pci configuration
  3704. * space. The flag PciConfigUp indicates whether the config space
  3705. * is accesible or must be set up first.
  3706. *
  3707. * Returns:
  3708. * 0 - indicate everything worked ok.
  3709. * != 0 - error indication
  3710. */
  3711. int SkPciWriteCfgByte(
  3712. SK_AC *pAC, /* Adapter Control structure pointer */
  3713. int PciAddr, /* PCI register address */
  3714. SK_U8 Val) /* pointer to store the read value */
  3715. {
  3716. pci_write_config_byte(pAC->PciDev, PciAddr, Val);
  3717. return(0);
  3718. } /* SkPciWriteCfgByte */
  3719. /*****************************************************************************
  3720. *
  3721. * SkDrvEvent - handle driver events
  3722. *
  3723. * Description:
  3724. * This function handles events from all modules directed to the driver
  3725. *
  3726. * Context:
  3727. * Is called under protection of slow path lock.
  3728. *
  3729. * Returns:
  3730. * 0 if everything ok
  3731. * < 0 on error
  3732. *
  3733. */
  3734. int SkDrvEvent(
  3735. SK_AC *pAC, /* pointer to adapter context */
  3736. SK_IOC IoC, /* io-context */
  3737. SK_U32 Event, /* event-id */
  3738. SK_EVPARA Param) /* event-parameter */
  3739. {
  3740. SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
  3741. struct sk_buff *pMsg; /* pointer to a message block */
  3742. int FromPort; /* the port from which we switch away */
  3743. int ToPort; /* the port we switch to */
  3744. SK_EVPARA NewPara; /* parameter for further events */
  3745. int Stat;
  3746. unsigned long Flags;
  3747. SK_BOOL DualNet;
  3748. switch (Event) {
  3749. case SK_DRV_ADAP_FAIL:
  3750. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3751. ("ADAPTER FAIL EVENT\n"));
  3752. printk("%s: Adapter failed.\n", pAC->dev[0]->name);
  3753. /* disable interrupts */
  3754. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  3755. /* cgoos */
  3756. break;
  3757. case SK_DRV_PORT_FAIL:
  3758. FromPort = Param.Para32[0];
  3759. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3760. ("PORT FAIL EVENT, Port: %d\n", FromPort));
  3761. if (FromPort == 0) {
  3762. printk("%s: Port A failed.\n", pAC->dev[0]->name);
  3763. } else {
  3764. printk("%s: Port B failed.\n", pAC->dev[1]->name);
  3765. }
  3766. /* cgoos */
  3767. break;
  3768. case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
  3769. /* action list 4 */
  3770. FromPort = Param.Para32[0];
  3771. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3772. ("PORT RESET EVENT, Port: %d ", FromPort));
  3773. NewPara.Para64 = FromPort;
  3774. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  3775. spin_lock_irqsave(
  3776. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3777. Flags);
  3778. SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
  3779. pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
  3780. spin_unlock_irqrestore(
  3781. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3782. Flags);
  3783. /* clear rx ring from received frames */
  3784. ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
  3785. ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
  3786. spin_lock_irqsave(
  3787. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3788. Flags);
  3789. /* tschilling: Handling of return value inserted. */
  3790. if (SkGeInitPort(pAC, IoC, FromPort)) {
  3791. if (FromPort == 0) {
  3792. printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
  3793. } else {
  3794. printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
  3795. }
  3796. }
  3797. SkAddrMcUpdate(pAC,IoC, FromPort);
  3798. PortReInitBmu(pAC, FromPort);
  3799. SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
  3800. ClearAndStartRx(pAC, FromPort);
  3801. spin_unlock_irqrestore(
  3802. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3803. Flags);
  3804. break;
  3805. case SK_DRV_NET_UP: /* SK_U32 PortIdx */
  3806. /* action list 5 */
  3807. FromPort = Param.Para32[0];
  3808. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3809. ("NET UP EVENT, Port: %d ", Param.Para32[0]));
  3810. /* Mac update */
  3811. SkAddrMcUpdate(pAC,IoC, FromPort);
  3812. if (DoPrintInterfaceChange) {
  3813. printk("%s: network connection up using"
  3814. " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
  3815. /* tschilling: Values changed according to LinkSpeedUsed. */
  3816. Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
  3817. if (Stat == SK_LSPEED_STAT_10MBPS) {
  3818. printk(" speed: 10\n");
  3819. } else if (Stat == SK_LSPEED_STAT_100MBPS) {
  3820. printk(" speed: 100\n");
  3821. } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
  3822. printk(" speed: 1000\n");
  3823. } else {
  3824. printk(" speed: unknown\n");
  3825. }
  3826. Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
  3827. if (Stat == SK_LMODE_STAT_AUTOHALF ||
  3828. Stat == SK_LMODE_STAT_AUTOFULL) {
  3829. printk(" autonegotiation: yes\n");
  3830. }
  3831. else {
  3832. printk(" autonegotiation: no\n");
  3833. }
  3834. if (Stat == SK_LMODE_STAT_AUTOHALF ||
  3835. Stat == SK_LMODE_STAT_HALF) {
  3836. printk(" duplex mode: half\n");
  3837. }
  3838. else {
  3839. printk(" duplex mode: full\n");
  3840. }
  3841. Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
  3842. if (Stat == SK_FLOW_STAT_REM_SEND ) {
  3843. printk(" flowctrl: remote send\n");
  3844. }
  3845. else if (Stat == SK_FLOW_STAT_LOC_SEND ){
  3846. printk(" flowctrl: local send\n");
  3847. }
  3848. else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
  3849. printk(" flowctrl: symmetric\n");
  3850. }
  3851. else {
  3852. printk(" flowctrl: none\n");
  3853. }
  3854. /* tschilling: Check against CopperType now. */
  3855. if ((pAC->GIni.GICopperType == SK_TRUE) &&
  3856. (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
  3857. SK_LSPEED_STAT_1000MBPS)) {
  3858. Stat = pAC->GIni.GP[FromPort].PMSStatus;
  3859. if (Stat == SK_MS_STAT_MASTER ) {
  3860. printk(" role: master\n");
  3861. }
  3862. else if (Stat == SK_MS_STAT_SLAVE ) {
  3863. printk(" role: slave\n");
  3864. }
  3865. else {
  3866. printk(" role: ???\n");
  3867. }
  3868. }
  3869. /*
  3870. Display dim (dynamic interrupt moderation)
  3871. informations
  3872. */
  3873. if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_STATIC)
  3874. printk(" irq moderation: static (%d ints/sec)\n",
  3875. pAC->DynIrqModInfo.MaxModIntsPerSec);
  3876. else if (pAC->DynIrqModInfo.IntModTypeSelect == C_INT_MOD_DYNAMIC)
  3877. printk(" irq moderation: dynamic (%d ints/sec)\n",
  3878. pAC->DynIrqModInfo.MaxModIntsPerSec);
  3879. else
  3880. printk(" irq moderation: disabled\n");
  3881. #ifdef SK_ZEROCOPY
  3882. if (pAC->ChipsetType)
  3883. #ifdef USE_SK_TX_CHECKSUM
  3884. printk(" scatter-gather: enabled\n");
  3885. #else
  3886. printk(" tx-checksum: disabled\n");
  3887. #endif
  3888. else
  3889. printk(" scatter-gather: disabled\n");
  3890. #else
  3891. printk(" scatter-gather: disabled\n");
  3892. #endif
  3893. #ifndef USE_SK_RX_CHECKSUM
  3894. printk(" rx-checksum: disabled\n");
  3895. #endif
  3896. } else {
  3897. DoPrintInterfaceChange = SK_TRUE;
  3898. }
  3899. if ((Param.Para32[0] != pAC->ActivePort) &&
  3900. (pAC->RlmtNets == 1)) {
  3901. NewPara.Para32[0] = pAC->ActivePort;
  3902. NewPara.Para32[1] = Param.Para32[0];
  3903. SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
  3904. NewPara);
  3905. }
  3906. /* Inform the world that link protocol is up. */
  3907. pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
  3908. break;
  3909. case SK_DRV_NET_DOWN: /* SK_U32 Reason */
  3910. /* action list 7 */
  3911. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3912. ("NET DOWN EVENT "));
  3913. if (DoPrintInterfaceChange) {
  3914. printk("%s: network connection down\n",
  3915. pAC->dev[Param.Para32[1]]->name);
  3916. } else {
  3917. DoPrintInterfaceChange = SK_TRUE;
  3918. }
  3919. pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
  3920. break;
  3921. case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  3922. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3923. ("PORT SWITCH HARD "));
  3924. case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  3925. /* action list 6 */
  3926. printk("%s: switching to port %c\n", pAC->dev[0]->name,
  3927. 'A'+Param.Para32[1]);
  3928. case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  3929. FromPort = Param.Para32[0];
  3930. ToPort = Param.Para32[1];
  3931. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3932. ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
  3933. FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
  3934. NewPara.Para64 = FromPort;
  3935. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  3936. NewPara.Para64 = ToPort;
  3937. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  3938. spin_lock_irqsave(
  3939. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3940. Flags);
  3941. spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
  3942. SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
  3943. SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
  3944. spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
  3945. spin_unlock_irqrestore(
  3946. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3947. Flags);
  3948. ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
  3949. ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
  3950. ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
  3951. ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
  3952. spin_lock_irqsave(
  3953. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3954. Flags);
  3955. spin_lock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
  3956. pAC->ActivePort = ToPort;
  3957. #if 0
  3958. SetQueueSizes(pAC);
  3959. #else
  3960. /* tschilling: New common function with minimum size check. */
  3961. DualNet = SK_FALSE;
  3962. if (pAC->RlmtNets == 2) {
  3963. DualNet = SK_TRUE;
  3964. }
  3965. if (SkGeInitAssignRamToQueues(
  3966. pAC,
  3967. pAC->ActivePort,
  3968. DualNet)) {
  3969. spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
  3970. spin_unlock_irqrestore(
  3971. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3972. Flags);
  3973. printk("SkGeInitAssignRamToQueues failed.\n");
  3974. break;
  3975. }
  3976. #endif
  3977. /* tschilling: Handling of return values inserted. */
  3978. if (SkGeInitPort(pAC, IoC, FromPort) ||
  3979. SkGeInitPort(pAC, IoC, ToPort)) {
  3980. printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
  3981. }
  3982. if (Event == SK_DRV_SWITCH_SOFT) {
  3983. SkMacRxTxEnable(pAC, IoC, FromPort);
  3984. }
  3985. SkMacRxTxEnable(pAC, IoC, ToPort);
  3986. SkAddrSwap(pAC, IoC, FromPort, ToPort);
  3987. SkAddrMcUpdate(pAC, IoC, FromPort);
  3988. SkAddrMcUpdate(pAC, IoC, ToPort);
  3989. PortReInitBmu(pAC, FromPort);
  3990. PortReInitBmu(pAC, ToPort);
  3991. SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
  3992. SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
  3993. ClearAndStartRx(pAC, FromPort);
  3994. ClearAndStartRx(pAC, ToPort);
  3995. spin_unlock(&pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock);
  3996. spin_unlock_irqrestore(
  3997. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3998. Flags);
  3999. break;
  4000. case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
  4001. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4002. ("RLS "));
  4003. pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
  4004. pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
  4005. skb_put(pMsg, pRlmtMbuf->Length);
  4006. if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
  4007. pMsg) < 0)
  4008. DEV_KFREE_SKB_ANY(pMsg);
  4009. break;
  4010. case SK_DRV_TIMER:
  4011. if (Param.Para32[0] == SK_DRV_MODERATION_TIMER) {
  4012. /*
  4013. ** expiration of the moderation timer implies that
  4014. ** dynamic moderation is to be applied
  4015. */
  4016. SkDimStartModerationTimer(pAC);
  4017. SkDimModerate(pAC);
  4018. if (pAC->DynIrqModInfo.DisplayStats) {
  4019. SkDimDisplayModerationSettings(pAC);
  4020. }
  4021. } else if (Param.Para32[0] == SK_DRV_RX_CLEANUP_TIMER) {
  4022. /*
  4023. ** check if we need to check for descriptors which
  4024. ** haven't been handled the last millisecs
  4025. */
  4026. StartDrvCleanupTimer(pAC);
  4027. if (pAC->GIni.GIMacsFound == 2) {
  4028. ReceiveIrq(pAC, &pAC->RxPort[1], SK_FALSE);
  4029. }
  4030. ReceiveIrq(pAC, &pAC->RxPort[0], SK_FALSE);
  4031. } else {
  4032. printk("Expiration of unknown timer\n");
  4033. }
  4034. break;
  4035. default:
  4036. break;
  4037. }
  4038. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4039. ("END EVENT "));
  4040. return (0);
  4041. } /* SkDrvEvent */
  4042. /*****************************************************************************
  4043. *
  4044. * SkErrorLog - log errors
  4045. *
  4046. * Description:
  4047. * This function logs errors to the system buffer and to the console
  4048. *
  4049. * Returns:
  4050. * 0 if everything ok
  4051. * < 0 on error
  4052. *
  4053. */
  4054. void SkErrorLog(
  4055. SK_AC *pAC,
  4056. int ErrClass,
  4057. int ErrNum,
  4058. char *pErrorMsg)
  4059. {
  4060. char ClassStr[80];
  4061. switch (ErrClass) {
  4062. case SK_ERRCL_OTHER:
  4063. strcpy(ClassStr, "Other error");
  4064. break;
  4065. case SK_ERRCL_CONFIG:
  4066. strcpy(ClassStr, "Configuration error");
  4067. break;
  4068. case SK_ERRCL_INIT:
  4069. strcpy(ClassStr, "Initialization error");
  4070. break;
  4071. case SK_ERRCL_NORES:
  4072. strcpy(ClassStr, "Out of resources error");
  4073. break;
  4074. case SK_ERRCL_SW:
  4075. strcpy(ClassStr, "internal Software error");
  4076. break;
  4077. case SK_ERRCL_HW:
  4078. strcpy(ClassStr, "Hardware failure");
  4079. break;
  4080. case SK_ERRCL_COMM:
  4081. strcpy(ClassStr, "Communication error");
  4082. break;
  4083. }
  4084. printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
  4085. " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
  4086. ClassStr, ErrNum, pErrorMsg);
  4087. } /* SkErrorLog */
  4088. #ifdef SK_DIAG_SUPPORT
  4089. /*****************************************************************************
  4090. *
  4091. * SkDrvEnterDiagMode - handles DIAG attach request
  4092. *
  4093. * Description:
  4094. * Notify the kernel to NOT access the card any longer due to DIAG
  4095. * Deinitialize the Card
  4096. *
  4097. * Returns:
  4098. * int
  4099. */
  4100. int SkDrvEnterDiagMode(
  4101. SK_AC *pAc) /* pointer to adapter context */
  4102. {
  4103. DEV_NET *pNet = netdev_priv(pAc->dev[0]);
  4104. SK_AC *pAC = pNet->pAC;
  4105. SK_MEMCPY(&(pAc->PnmiBackup), &(pAc->PnmiStruct),
  4106. sizeof(SK_PNMI_STRUCT_DATA));
  4107. pAC->DiagModeActive = DIAG_ACTIVE;
  4108. if (pAC->BoardLevel > SK_INIT_DATA) {
  4109. if (pNet->Up) {
  4110. pAC->WasIfUp[0] = SK_TRUE;
  4111. pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
  4112. DoPrintInterfaceChange = SK_FALSE;
  4113. SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
  4114. } else {
  4115. pAC->WasIfUp[0] = SK_FALSE;
  4116. }
  4117. if (pNet != netdev_priv(pAC->dev[1])) {
  4118. pNet = netdev_priv(pAC->dev[1]);
  4119. if (pNet->Up) {
  4120. pAC->WasIfUp[1] = SK_TRUE;
  4121. pAC->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
  4122. DoPrintInterfaceChange = SK_FALSE;
  4123. SkDrvDeInitAdapter(pAC, 1); /* do SkGeClose */
  4124. } else {
  4125. pAC->WasIfUp[1] = SK_FALSE;
  4126. }
  4127. }
  4128. pAC->BoardLevel = SK_INIT_DATA;
  4129. }
  4130. return(0);
  4131. }
  4132. /*****************************************************************************
  4133. *
  4134. * SkDrvLeaveDiagMode - handles DIAG detach request
  4135. *
  4136. * Description:
  4137. * Notify the kernel to may access the card again after use by DIAG
  4138. * Initialize the Card
  4139. *
  4140. * Returns:
  4141. * int
  4142. */
  4143. int SkDrvLeaveDiagMode(
  4144. SK_AC *pAc) /* pointer to adapter control context */
  4145. {
  4146. SK_MEMCPY(&(pAc->PnmiStruct), &(pAc->PnmiBackup),
  4147. sizeof(SK_PNMI_STRUCT_DATA));
  4148. pAc->DiagModeActive = DIAG_NOTACTIVE;
  4149. pAc->Pnmi.DiagAttached = SK_DIAG_IDLE;
  4150. if (pAc->WasIfUp[0] == SK_TRUE) {
  4151. pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
  4152. DoPrintInterfaceChange = SK_FALSE;
  4153. SkDrvInitAdapter(pAc, 0); /* first device */
  4154. }
  4155. if (pAc->WasIfUp[1] == SK_TRUE) {
  4156. pAc->DiagFlowCtrl = SK_TRUE; /* for SkGeClose */
  4157. DoPrintInterfaceChange = SK_FALSE;
  4158. SkDrvInitAdapter(pAc, 1); /* second device */
  4159. }
  4160. return(0);
  4161. }
  4162. /*****************************************************************************
  4163. *
  4164. * ParseDeviceNbrFromSlotName - Evaluate PCI device number
  4165. *
  4166. * Description:
  4167. * This function parses the PCI slot name information string and will
  4168. * retrieve the devcie number out of it. The slot_name maintianed by
  4169. * linux is in the form of '02:0a.0', whereas the first two characters
  4170. * represent the bus number in hex (in the sample above this is
  4171. * pci bus 0x02) and the next two characters the device number (0x0a).
  4172. *
  4173. * Returns:
  4174. * SK_U32: The device number from the PCI slot name
  4175. */
  4176. static SK_U32 ParseDeviceNbrFromSlotName(
  4177. const char *SlotName) /* pointer to pci slot name eg. '02:0a.0' */
  4178. {
  4179. char *CurrCharPos = (char *) SlotName;
  4180. int FirstNibble = -1;
  4181. int SecondNibble = -1;
  4182. SK_U32 Result = 0;
  4183. while (*CurrCharPos != '\0') {
  4184. if (*CurrCharPos == ':') {
  4185. while (*CurrCharPos != '.') {
  4186. CurrCharPos++;
  4187. if ( (*CurrCharPos >= '0') &&
  4188. (*CurrCharPos <= '9')) {
  4189. if (FirstNibble == -1) {
  4190. /* dec. value for '0' */
  4191. FirstNibble = *CurrCharPos - 48;
  4192. } else {
  4193. SecondNibble = *CurrCharPos - 48;
  4194. }
  4195. } else if ( (*CurrCharPos >= 'a') &&
  4196. (*CurrCharPos <= 'f') ) {
  4197. if (FirstNibble == -1) {
  4198. FirstNibble = *CurrCharPos - 87;
  4199. } else {
  4200. SecondNibble = *CurrCharPos - 87;
  4201. }
  4202. } else {
  4203. Result = 0;
  4204. }
  4205. }
  4206. Result = FirstNibble;
  4207. Result = Result << 4; /* first nibble is higher one */
  4208. Result = Result | SecondNibble;
  4209. }
  4210. CurrCharPos++; /* next character */
  4211. }
  4212. return (Result);
  4213. }
  4214. /****************************************************************************
  4215. *
  4216. * SkDrvDeInitAdapter - deinitialize adapter (this function is only
  4217. * called if Diag attaches to that card)
  4218. *
  4219. * Description:
  4220. * Close initialized adapter.
  4221. *
  4222. * Returns:
  4223. * 0 - on success
  4224. * error code - on error
  4225. */
  4226. static int SkDrvDeInitAdapter(
  4227. SK_AC *pAC, /* pointer to adapter context */
  4228. int devNbr) /* what device is to be handled */
  4229. {
  4230. struct SK_NET_DEVICE *dev;
  4231. dev = pAC->dev[devNbr];
  4232. /* On Linux 2.6 the network driver does NOT mess with reference
  4233. ** counts. The driver MUST be able to be unloaded at any time
  4234. ** due to the possibility of hotplug.
  4235. */
  4236. if (SkGeClose(dev) != 0) {
  4237. return (-1);
  4238. }
  4239. return (0);
  4240. } /* SkDrvDeInitAdapter() */
  4241. /****************************************************************************
  4242. *
  4243. * SkDrvInitAdapter - Initialize adapter (this function is only
  4244. * called if Diag deattaches from that card)
  4245. *
  4246. * Description:
  4247. * Close initialized adapter.
  4248. *
  4249. * Returns:
  4250. * 0 - on success
  4251. * error code - on error
  4252. */
  4253. static int SkDrvInitAdapter(
  4254. SK_AC *pAC, /* pointer to adapter context */
  4255. int devNbr) /* what device is to be handled */
  4256. {
  4257. struct SK_NET_DEVICE *dev;
  4258. dev = pAC->dev[devNbr];
  4259. if (SkGeOpen(dev) != 0) {
  4260. return (-1);
  4261. }
  4262. /*
  4263. ** Use correct MTU size and indicate to kernel TX queue can be started
  4264. */
  4265. if (SkGeChangeMtu(dev, dev->mtu) != 0) {
  4266. return (-1);
  4267. }
  4268. return (0);
  4269. } /* SkDrvInitAdapter */
  4270. #endif
  4271. #ifdef DEBUG
  4272. /****************************************************************************/
  4273. /* "debug only" section *****************************************************/
  4274. /****************************************************************************/
  4275. /*****************************************************************************
  4276. *
  4277. * DumpMsg - print a frame
  4278. *
  4279. * Description:
  4280. * This function prints frames to the system logfile/to the console.
  4281. *
  4282. * Returns: N/A
  4283. *
  4284. */
  4285. static void DumpMsg(struct sk_buff *skb, char *str)
  4286. {
  4287. int msglen;
  4288. if (skb == NULL) {
  4289. printk("DumpMsg(): NULL-Message\n");
  4290. return;
  4291. }
  4292. if (skb->data == NULL) {
  4293. printk("DumpMsg(): Message empty\n");
  4294. return;
  4295. }
  4296. msglen = skb->len;
  4297. if (msglen > 64)
  4298. msglen = 64;
  4299. printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
  4300. DumpData((char *)skb->data, msglen);
  4301. printk("------- End of message ---------\n");
  4302. } /* DumpMsg */
  4303. /*****************************************************************************
  4304. *
  4305. * DumpData - print a data area
  4306. *
  4307. * Description:
  4308. * This function prints a area of data to the system logfile/to the
  4309. * console.
  4310. *
  4311. * Returns: N/A
  4312. *
  4313. */
  4314. static void DumpData(char *p, int size)
  4315. {
  4316. register int i;
  4317. int haddr, addr;
  4318. char hex_buffer[180];
  4319. char asc_buffer[180];
  4320. char HEXCHAR[] = "0123456789ABCDEF";
  4321. addr = 0;
  4322. haddr = 0;
  4323. hex_buffer[0] = 0;
  4324. asc_buffer[0] = 0;
  4325. for (i=0; i < size; ) {
  4326. if (*p >= '0' && *p <='z')
  4327. asc_buffer[addr] = *p;
  4328. else
  4329. asc_buffer[addr] = '.';
  4330. addr++;
  4331. asc_buffer[addr] = 0;
  4332. hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
  4333. haddr++;
  4334. hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
  4335. haddr++;
  4336. hex_buffer[haddr] = ' ';
  4337. haddr++;
  4338. hex_buffer[haddr] = 0;
  4339. p++;
  4340. i++;
  4341. if (i%16 == 0) {
  4342. printk("%s %s\n", hex_buffer, asc_buffer);
  4343. addr = 0;
  4344. haddr = 0;
  4345. }
  4346. }
  4347. } /* DumpData */
  4348. /*****************************************************************************
  4349. *
  4350. * DumpLong - print a data area as long values
  4351. *
  4352. * Description:
  4353. * This function prints a area of data to the system logfile/to the
  4354. * console.
  4355. *
  4356. * Returns: N/A
  4357. *
  4358. */
  4359. static void DumpLong(char *pc, int size)
  4360. {
  4361. register int i;
  4362. int haddr, addr;
  4363. char hex_buffer[180];
  4364. char asc_buffer[180];
  4365. char HEXCHAR[] = "0123456789ABCDEF";
  4366. long *p;
  4367. int l;
  4368. addr = 0;
  4369. haddr = 0;
  4370. hex_buffer[0] = 0;
  4371. asc_buffer[0] = 0;
  4372. p = (long*) pc;
  4373. for (i=0; i < size; ) {
  4374. l = (long) *p;
  4375. hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
  4376. haddr++;
  4377. hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
  4378. haddr++;
  4379. hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
  4380. haddr++;
  4381. hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
  4382. haddr++;
  4383. hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
  4384. haddr++;
  4385. hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
  4386. haddr++;
  4387. hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
  4388. haddr++;
  4389. hex_buffer[haddr] = HEXCHAR[l & 0x0f];
  4390. haddr++;
  4391. hex_buffer[haddr] = ' ';
  4392. haddr++;
  4393. hex_buffer[haddr] = 0;
  4394. p++;
  4395. i++;
  4396. if (i%8 == 0) {
  4397. printk("%4x %s\n", (i-8)*4, hex_buffer);
  4398. haddr = 0;
  4399. }
  4400. }
  4401. printk("------------------------\n");
  4402. } /* DumpLong */
  4403. #endif
  4404. static int __devinit skge_probe_one(struct pci_dev *pdev,
  4405. const struct pci_device_id *ent)
  4406. {
  4407. SK_AC *pAC;
  4408. DEV_NET *pNet = NULL;
  4409. struct net_device *dev = NULL;
  4410. static int boards_found = 0;
  4411. int error = -ENODEV;
  4412. if (pci_enable_device(pdev))
  4413. goto out;
  4414. /* Configure DMA attributes. */
  4415. if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffffULL) &&
  4416. pci_set_dma_mask(pdev, (u64) 0xffffffff))
  4417. goto out_disable_device;
  4418. if ((dev = alloc_etherdev(sizeof(DEV_NET))) == NULL) {
  4419. printk(KERN_ERR "Unable to allocate etherdev "
  4420. "structure!\n");
  4421. goto out_disable_device;
  4422. }
  4423. pNet = netdev_priv(dev);
  4424. pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
  4425. if (!pNet->pAC) {
  4426. printk(KERN_ERR "Unable to allocate adapter "
  4427. "structure!\n");
  4428. goto out_free_netdev;
  4429. }
  4430. memset(pNet->pAC, 0, sizeof(SK_AC));
  4431. pAC = pNet->pAC;
  4432. pAC->PciDev = pdev;
  4433. pAC->PciDevId = pdev->device;
  4434. pAC->dev[0] = dev;
  4435. pAC->dev[1] = dev;
  4436. sprintf(pAC->Name, "SysKonnect SK-98xx");
  4437. pAC->CheckQueue = SK_FALSE;
  4438. pNet->Mtu = 1500;
  4439. pNet->Up = 0;
  4440. dev->irq = pdev->irq;
  4441. error = SkGeInitPCI(pAC);
  4442. if (error) {
  4443. printk("SKGE: PCI setup failed: %i\n", error);
  4444. goto out_free_netdev;
  4445. }
  4446. SET_MODULE_OWNER(dev);
  4447. dev->open = &SkGeOpen;
  4448. dev->stop = &SkGeClose;
  4449. dev->hard_start_xmit = &SkGeXmit;
  4450. dev->get_stats = &SkGeStats;
  4451. dev->set_multicast_list = &SkGeSetRxMode;
  4452. dev->set_mac_address = &SkGeSetMacAddr;
  4453. dev->do_ioctl = &SkGeIoctl;
  4454. dev->change_mtu = &SkGeChangeMtu;
  4455. #ifdef CONFIG_NET_POLL_CONTROLLER
  4456. dev->poll_controller = &SkGePollController;
  4457. #endif
  4458. dev->flags &= ~IFF_RUNNING;
  4459. SET_NETDEV_DEV(dev, &pdev->dev);
  4460. SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
  4461. #ifdef SK_ZEROCOPY
  4462. #ifdef USE_SK_TX_CHECKSUM
  4463. if (pAC->ChipsetType) {
  4464. /* Use only if yukon hardware */
  4465. /* SK and ZEROCOPY - fly baby... */
  4466. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  4467. }
  4468. #endif
  4469. #endif
  4470. pAC->Index = boards_found++;
  4471. if (SkGeBoardInit(dev, pAC))
  4472. goto out_free_netdev;
  4473. /* Register net device */
  4474. if (register_netdev(dev)) {
  4475. printk(KERN_ERR "SKGE: Could not register device.\n");
  4476. goto out_free_resources;
  4477. }
  4478. /* Print adapter specific string from vpd */
  4479. ProductStr(pAC);
  4480. printk("%s: %s\n", dev->name, pAC->DeviceStr);
  4481. /* Print configuration settings */
  4482. printk(" PrefPort:%c RlmtMode:%s\n",
  4483. 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
  4484. (pAC->RlmtMode==0) ? "Check Link State" :
  4485. ((pAC->RlmtMode==1) ? "Check Link State" :
  4486. ((pAC->RlmtMode==3) ? "Check Local Port" :
  4487. ((pAC->RlmtMode==7) ? "Check Segmentation" :
  4488. ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
  4489. SkGeYellowLED(pAC, pAC->IoBase, 1);
  4490. memcpy(&dev->dev_addr, &pAC->Addr.Net[0].CurrentMacAddress, 6);
  4491. SkGeProcCreate(dev);
  4492. pNet->PortNr = 0;
  4493. pNet->NetNr = 0;
  4494. boards_found++;
  4495. /* More then one port found */
  4496. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  4497. if ((dev = alloc_etherdev(sizeof(DEV_NET))) == 0) {
  4498. printk(KERN_ERR "Unable to allocate etherdev "
  4499. "structure!\n");
  4500. goto out;
  4501. }
  4502. pAC->dev[1] = dev;
  4503. pNet = netdev_priv(dev);
  4504. pNet->PortNr = 1;
  4505. pNet->NetNr = 1;
  4506. pNet->pAC = pAC;
  4507. pNet->Mtu = 1500;
  4508. pNet->Up = 0;
  4509. dev->open = &SkGeOpen;
  4510. dev->stop = &SkGeClose;
  4511. dev->hard_start_xmit = &SkGeXmit;
  4512. dev->get_stats = &SkGeStats;
  4513. dev->set_multicast_list = &SkGeSetRxMode;
  4514. dev->set_mac_address = &SkGeSetMacAddr;
  4515. dev->do_ioctl = &SkGeIoctl;
  4516. dev->change_mtu = &SkGeChangeMtu;
  4517. dev->flags &= ~IFF_RUNNING;
  4518. SET_NETDEV_DEV(dev, &pdev->dev);
  4519. SET_ETHTOOL_OPS(dev, &SkGeEthtoolOps);
  4520. #ifdef SK_ZEROCOPY
  4521. #ifdef USE_SK_TX_CHECKSUM
  4522. if (pAC->ChipsetType) {
  4523. /* SG and ZEROCOPY - fly baby... */
  4524. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  4525. }
  4526. #endif
  4527. #endif
  4528. if (register_netdev(dev)) {
  4529. printk(KERN_ERR "SKGE: Could not register device.\n");
  4530. free_netdev(dev);
  4531. pAC->dev[1] = pAC->dev[0];
  4532. } else {
  4533. SkGeProcCreate(dev);
  4534. memcpy(&dev->dev_addr,
  4535. &pAC->Addr.Net[1].CurrentMacAddress, 6);
  4536. printk("%s: %s\n", dev->name, pAC->DeviceStr);
  4537. printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
  4538. }
  4539. }
  4540. /* Save the hardware revision */
  4541. pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
  4542. (pAC->GIni.GIPciHwRev & 0x0F);
  4543. /* Set driver globals */
  4544. pAC->Pnmi.pDriverFileName = DRIVER_FILE_NAME;
  4545. pAC->Pnmi.pDriverReleaseDate = DRIVER_REL_DATE;
  4546. memset(&pAC->PnmiBackup, 0, sizeof(SK_PNMI_STRUCT_DATA));
  4547. memcpy(&pAC->PnmiBackup, &pAC->PnmiStruct, sizeof(SK_PNMI_STRUCT_DATA));
  4548. pci_set_drvdata(pdev, dev);
  4549. return 0;
  4550. out_free_resources:
  4551. FreeResources(dev);
  4552. out_free_netdev:
  4553. free_netdev(dev);
  4554. out_disable_device:
  4555. pci_disable_device(pdev);
  4556. out:
  4557. return error;
  4558. }
  4559. static void __devexit skge_remove_one(struct pci_dev *pdev)
  4560. {
  4561. struct net_device *dev = pci_get_drvdata(pdev);
  4562. DEV_NET *pNet = netdev_priv(dev);
  4563. SK_AC *pAC = pNet->pAC;
  4564. struct net_device *otherdev = pAC->dev[1];
  4565. SkGeProcRemove(dev);
  4566. unregister_netdev(dev);
  4567. if (otherdev != dev)
  4568. SkGeProcRemove(otherdev);
  4569. SkGeYellowLED(pAC, pAC->IoBase, 0);
  4570. if (pAC->BoardLevel == SK_INIT_RUN) {
  4571. SK_EVPARA EvPara;
  4572. unsigned long Flags;
  4573. /* board is still alive */
  4574. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  4575. EvPara.Para32[0] = 0;
  4576. EvPara.Para32[1] = -1;
  4577. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  4578. EvPara.Para32[0] = 1;
  4579. EvPara.Para32[1] = -1;
  4580. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  4581. SkEventDispatcher(pAC, pAC->IoBase);
  4582. /* disable interrupts */
  4583. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  4584. SkGeDeInit(pAC, pAC->IoBase);
  4585. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  4586. pAC->BoardLevel = SK_INIT_DATA;
  4587. /* We do NOT check here, if IRQ was pending, of course*/
  4588. }
  4589. if (pAC->BoardLevel == SK_INIT_IO) {
  4590. /* board is still alive */
  4591. SkGeDeInit(pAC, pAC->IoBase);
  4592. pAC->BoardLevel = SK_INIT_DATA;
  4593. }
  4594. FreeResources(dev);
  4595. free_netdev(dev);
  4596. if (otherdev != dev)
  4597. free_netdev(otherdev);
  4598. kfree(pAC);
  4599. }
  4600. #ifdef CONFIG_PM
  4601. static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
  4602. {
  4603. struct net_device *dev = pci_get_drvdata(pdev);
  4604. DEV_NET *pNet = netdev_priv(dev);
  4605. SK_AC *pAC = pNet->pAC;
  4606. struct net_device *otherdev = pAC->dev[1];
  4607. if (pNet->Up) {
  4608. pAC->WasIfUp[0] = SK_TRUE;
  4609. DoPrintInterfaceChange = SK_FALSE;
  4610. SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
  4611. }
  4612. if (otherdev != dev) {
  4613. pNet = netdev_priv(otherdev);
  4614. if (pNet->Up) {
  4615. pAC->WasIfUp[1] = SK_TRUE;
  4616. DoPrintInterfaceChange = SK_FALSE;
  4617. SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
  4618. }
  4619. }
  4620. pci_save_state(pdev);
  4621. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  4622. if (pAC->AllocFlag & SK_ALLOC_IRQ) {
  4623. free_irq(dev->irq, dev);
  4624. }
  4625. pci_disable_device(pdev);
  4626. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  4627. return 0;
  4628. }
  4629. static int skge_resume(struct pci_dev *pdev)
  4630. {
  4631. struct net_device *dev = pci_get_drvdata(pdev);
  4632. DEV_NET *pNet = netdev_priv(dev);
  4633. SK_AC *pAC = pNet->pAC;
  4634. pci_set_power_state(pdev, PCI_D0);
  4635. pci_restore_state(pdev);
  4636. pci_enable_device(pdev);
  4637. pci_set_master(pdev);
  4638. if (pAC->GIni.GIMacsFound == 2)
  4639. request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
  4640. else
  4641. request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
  4642. if (pAC->WasIfUp[0] == SK_TRUE) {
  4643. DoPrintInterfaceChange = SK_FALSE;
  4644. SkDrvInitAdapter(pAC, 0); /* first device */
  4645. }
  4646. if (pAC->dev[1] != dev && pAC->WasIfUp[1] == SK_TRUE) {
  4647. DoPrintInterfaceChange = SK_FALSE;
  4648. SkDrvInitAdapter(pAC, 1); /* first device */
  4649. }
  4650. return 0;
  4651. }
  4652. #endif
  4653. static struct pci_device_id skge_pci_tbl[] = {
  4654. { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4655. { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4656. { PCI_VENDOR_ID_SYSKONNECT, 0x4300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4657. { PCI_VENDOR_ID_SYSKONNECT, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4658. { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4659. { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4660. #if 0 /* don't handle Yukon2 cards at the moment -- mlindner@syskonnect.de */
  4661. { PCI_VENDOR_ID_MARVELL, 0x4360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4662. { PCI_VENDOR_ID_MARVELL, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4663. #endif
  4664. { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4665. { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4666. { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4667. { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4668. { 0, }
  4669. };
  4670. MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
  4671. static struct pci_driver skge_driver = {
  4672. .name = "sk98lin",
  4673. .id_table = skge_pci_tbl,
  4674. .probe = skge_probe_one,
  4675. .remove = __devexit_p(skge_remove_one),
  4676. .suspend = skge_suspend,
  4677. .resume = skge_resume,
  4678. };
  4679. static int __init skge_init(void)
  4680. {
  4681. int error;
  4682. pSkRootDir = proc_mkdir(SKRootName, proc_net);
  4683. if (pSkRootDir)
  4684. pSkRootDir->owner = THIS_MODULE;
  4685. error = pci_register_driver(&skge_driver);
  4686. if (error)
  4687. proc_net_remove(SKRootName);
  4688. return error;
  4689. }
  4690. static void __exit skge_exit(void)
  4691. {
  4692. pci_unregister_driver(&skge_driver);
  4693. proc_net_remove(SKRootName);
  4694. }
  4695. module_init(skge_init);
  4696. module_exit(skge_exit);