skge.c 145 KB

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