skge.c 146 KB

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