skge.c 146 KB

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