skge.c 145 KB

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