skge.c 147 KB

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