skge.c 146 KB

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