defxx.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745
  1. /*
  2. * File Name:
  3. * defxx.c
  4. *
  5. * Copyright Information:
  6. * Copyright Digital Equipment Corporation 1996.
  7. *
  8. * This software may be used and distributed according to the terms of
  9. * the GNU General Public License, incorporated herein by reference.
  10. *
  11. * Abstract:
  12. * A Linux device driver supporting the Digital Equipment Corporation
  13. * FDDI TURBOchannel, EISA and PCI controller families. Supported
  14. * adapters include:
  15. *
  16. * DEC FDDIcontroller/TURBOchannel (DEFTA)
  17. * DEC FDDIcontroller/EISA (DEFEA)
  18. * DEC FDDIcontroller/PCI (DEFPA)
  19. *
  20. * The original author:
  21. * LVS Lawrence V. Stefani <lstefani@yahoo.com>
  22. *
  23. * Maintainers:
  24. * macro Maciej W. Rozycki <macro@linux-mips.org>
  25. *
  26. * Credits:
  27. * I'd like to thank Patricia Cross for helping me get started with
  28. * Linux, David Davies for a lot of help upgrading and configuring
  29. * my development system and for answering many OS and driver
  30. * development questions, and Alan Cox for recommendations and
  31. * integration help on getting FDDI support into Linux. LVS
  32. *
  33. * Driver Architecture:
  34. * The driver architecture is largely based on previous driver work
  35. * for other operating systems. The upper edge interface and
  36. * functions were largely taken from existing Linux device drivers
  37. * such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
  38. * driver.
  39. *
  40. * Adapter Probe -
  41. * The driver scans for supported EISA adapters by reading the
  42. * SLOT ID register for each EISA slot and making a match
  43. * against the expected value.
  44. *
  45. * Bus-Specific Initialization -
  46. * This driver currently supports both EISA and PCI controller
  47. * families. While the custom DMA chip and FDDI logic is similar
  48. * or identical, the bus logic is very different. After
  49. * initialization, the only bus-specific differences is in how the
  50. * driver enables and disables interrupts. Other than that, the
  51. * run-time critical code behaves the same on both families.
  52. * It's important to note that both adapter families are configured
  53. * to I/O map, rather than memory map, the adapter registers.
  54. *
  55. * Driver Open/Close -
  56. * In the driver open routine, the driver ISR (interrupt service
  57. * routine) is registered and the adapter is brought to an
  58. * operational state. In the driver close routine, the opposite
  59. * occurs; the driver ISR is deregistered and the adapter is
  60. * brought to a safe, but closed state. Users may use consecutive
  61. * commands to bring the adapter up and down as in the following
  62. * example:
  63. * ifconfig fddi0 up
  64. * ifconfig fddi0 down
  65. * ifconfig fddi0 up
  66. *
  67. * Driver Shutdown -
  68. * Apparently, there is no shutdown or halt routine support under
  69. * Linux. This routine would be called during "reboot" or
  70. * "shutdown" to allow the driver to place the adapter in a safe
  71. * state before a warm reboot occurs. To be really safe, the user
  72. * should close the adapter before shutdown (eg. ifconfig fddi0 down)
  73. * to ensure that the adapter DMA engine is taken off-line. However,
  74. * the current driver code anticipates this problem and always issues
  75. * a soft reset of the adapter at the beginning of driver initialization.
  76. * A future driver enhancement in this area may occur in 2.1.X where
  77. * Alan indicated that a shutdown handler may be implemented.
  78. *
  79. * Interrupt Service Routine -
  80. * The driver supports shared interrupts, so the ISR is registered for
  81. * each board with the appropriate flag and the pointer to that board's
  82. * device structure. This provides the context during interrupt
  83. * processing to support shared interrupts and multiple boards.
  84. *
  85. * Interrupt enabling/disabling can occur at many levels. At the host
  86. * end, you can disable system interrupts, or disable interrupts at the
  87. * PIC (on Intel systems). Across the bus, both EISA and PCI adapters
  88. * have a bus-logic chip interrupt enable/disable as well as a DMA
  89. * controller interrupt enable/disable.
  90. *
  91. * The driver currently enables and disables adapter interrupts at the
  92. * bus-logic chip and assumes that Linux will take care of clearing or
  93. * acknowledging any host-based interrupt chips.
  94. *
  95. * Control Functions -
  96. * Control functions are those used to support functions such as adding
  97. * or deleting multicast addresses, enabling or disabling packet
  98. * reception filters, or other custom/proprietary commands. Presently,
  99. * the driver supports the "get statistics", "set multicast list", and
  100. * "set mac address" functions defined by Linux. A list of possible
  101. * enhancements include:
  102. *
  103. * - Custom ioctl interface for executing port interface commands
  104. * - Custom ioctl interface for adding unicast addresses to
  105. * adapter CAM (to support bridge functions).
  106. * - Custom ioctl interface for supporting firmware upgrades.
  107. *
  108. * Hardware (port interface) Support Routines -
  109. * The driver function names that start with "dfx_hw_" represent
  110. * low-level port interface routines that are called frequently. They
  111. * include issuing a DMA or port control command to the adapter,
  112. * resetting the adapter, or reading the adapter state. Since the
  113. * driver initialization and run-time code must make calls into the
  114. * port interface, these routines were written to be as generic and
  115. * usable as possible.
  116. *
  117. * Receive Path -
  118. * The adapter DMA engine supports a 256 entry receive descriptor block
  119. * of which up to 255 entries can be used at any given time. The
  120. * architecture is a standard producer, consumer, completion model in
  121. * which the driver "produces" receive buffers to the adapter, the
  122. * adapter "consumes" the receive buffers by DMAing incoming packet data,
  123. * and the driver "completes" the receive buffers by servicing the
  124. * incoming packet, then "produces" a new buffer and starts the cycle
  125. * again. Receive buffers can be fragmented in up to 16 fragments
  126. * (descriptor entries). For simplicity, this driver posts
  127. * single-fragment receive buffers of 4608 bytes, then allocates a
  128. * sk_buff, copies the data, then reposts the buffer. To reduce CPU
  129. * utilization, a better approach would be to pass up the receive
  130. * buffer (no extra copy) then allocate and post a replacement buffer.
  131. * This is a performance enhancement that should be looked into at
  132. * some point.
  133. *
  134. * Transmit Path -
  135. * Like the receive path, the adapter DMA engine supports a 256 entry
  136. * transmit descriptor block of which up to 255 entries can be used at
  137. * any given time. Transmit buffers can be fragmented in up to 255
  138. * fragments (descriptor entries). This driver always posts one
  139. * fragment per transmit packet request.
  140. *
  141. * The fragment contains the entire packet from FC to end of data.
  142. * Before posting the buffer to the adapter, the driver sets a three-byte
  143. * packet request header (PRH) which is required by the Motorola MAC chip
  144. * used on the adapters. The PRH tells the MAC the type of token to
  145. * receive/send, whether or not to generate and append the CRC, whether
  146. * synchronous or asynchronous framing is used, etc. Since the PRH
  147. * definition is not necessarily consistent across all FDDI chipsets,
  148. * the driver, rather than the common FDDI packet handler routines,
  149. * sets these bytes.
  150. *
  151. * To reduce the amount of descriptor fetches needed per transmit request,
  152. * the driver takes advantage of the fact that there are at least three
  153. * bytes available before the skb->data field on the outgoing transmit
  154. * request. This is guaranteed by having fddi_setup() in net_init.c set
  155. * dev->hard_header_len to 24 bytes. 21 bytes accounts for the largest
  156. * header in an 802.2 SNAP frame. The other 3 bytes are the extra "pad"
  157. * bytes which we'll use to store the PRH.
  158. *
  159. * There's a subtle advantage to adding these pad bytes to the
  160. * hard_header_len, it ensures that the data portion of the packet for
  161. * an 802.2 SNAP frame is longword aligned. Other FDDI driver
  162. * implementations may not need the extra padding and can start copying
  163. * or DMAing directly from the FC byte which starts at skb->data. Should
  164. * another driver implementation need ADDITIONAL padding, the net_init.c
  165. * module should be updated and dev->hard_header_len should be increased.
  166. * NOTE: To maintain the alignment on the data portion of the packet,
  167. * dev->hard_header_len should always be evenly divisible by 4 and at
  168. * least 24 bytes in size.
  169. *
  170. * Modification History:
  171. * Date Name Description
  172. * 16-Aug-96 LVS Created.
  173. * 20-Aug-96 LVS Updated dfx_probe so that version information
  174. * string is only displayed if 1 or more cards are
  175. * found. Changed dfx_rcv_queue_process to copy
  176. * 3 NULL bytes before FC to ensure that data is
  177. * longword aligned in receive buffer.
  178. * 09-Sep-96 LVS Updated dfx_ctl_set_multicast_list to enable
  179. * LLC group promiscuous mode if multicast list
  180. * is too large. LLC individual/group promiscuous
  181. * mode is now disabled if IFF_PROMISC flag not set.
  182. * dfx_xmt_queue_pkt no longer checks for NULL skb
  183. * on Alan Cox recommendation. Added node address
  184. * override support.
  185. * 12-Sep-96 LVS Reset current address to factory address during
  186. * device open. Updated transmit path to post a
  187. * single fragment which includes PRH->end of data.
  188. * Mar 2000 AC Did various cleanups for 2.3.x
  189. * Jun 2000 jgarzik PCI and resource alloc cleanups
  190. * Jul 2000 tjeerd Much cleanup and some bug fixes
  191. * Sep 2000 tjeerd Fix leak on unload, cosmetic code cleanup
  192. * Feb 2001 Skb allocation fixes
  193. * Feb 2001 davej PCI enable cleanups.
  194. * 04 Aug 2003 macro Converted to the DMA API.
  195. * 14 Aug 2004 macro Fix device names reported.
  196. * 14 Jun 2005 macro Use irqreturn_t.
  197. * 23 Oct 2006 macro Big-endian host support.
  198. * 14 Dec 2006 macro TURBOchannel support.
  199. */
  200. /* Include files */
  201. #include <linux/bitops.h>
  202. #include <linux/compiler.h>
  203. #include <linux/delay.h>
  204. #include <linux/dma-mapping.h>
  205. #include <linux/eisa.h>
  206. #include <linux/errno.h>
  207. #include <linux/fddidevice.h>
  208. #include <linux/init.h>
  209. #include <linux/interrupt.h>
  210. #include <linux/ioport.h>
  211. #include <linux/kernel.h>
  212. #include <linux/module.h>
  213. #include <linux/netdevice.h>
  214. #include <linux/pci.h>
  215. #include <linux/skbuff.h>
  216. #include <linux/slab.h>
  217. #include <linux/string.h>
  218. #include <linux/tc.h>
  219. #include <asm/byteorder.h>
  220. #include <asm/io.h>
  221. #include "defxx.h"
  222. /* Version information string should be updated prior to each new release! */
  223. #define DRV_NAME "defxx"
  224. #define DRV_VERSION "v1.10"
  225. #define DRV_RELDATE "2006/12/14"
  226. static char version[] __devinitdata =
  227. DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
  228. " Lawrence V. Stefani and others\n";
  229. #define DYNAMIC_BUFFERS 1
  230. #define SKBUFF_RX_COPYBREAK 200
  231. /*
  232. * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
  233. * alignment for compatibility with old EISA boards.
  234. */
  235. #define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
  236. #ifdef CONFIG_PCI
  237. #define DFX_BUS_PCI(dev) (dev->bus == &pci_bus_type)
  238. #else
  239. #define DFX_BUS_PCI(dev) 0
  240. #endif
  241. #ifdef CONFIG_EISA
  242. #define DFX_BUS_EISA(dev) (dev->bus == &eisa_bus_type)
  243. #else
  244. #define DFX_BUS_EISA(dev) 0
  245. #endif
  246. #ifdef CONFIG_TC
  247. #define DFX_BUS_TC(dev) (dev->bus == &tc_bus_type)
  248. #else
  249. #define DFX_BUS_TC(dev) 0
  250. #endif
  251. #ifdef CONFIG_DEFXX_MMIO
  252. #define DFX_MMIO 1
  253. #else
  254. #define DFX_MMIO 0
  255. #endif
  256. /* Define module-wide (static) routines */
  257. static void dfx_bus_init(struct net_device *dev);
  258. static void dfx_bus_uninit(struct net_device *dev);
  259. static void dfx_bus_config_check(DFX_board_t *bp);
  260. static int dfx_driver_init(struct net_device *dev,
  261. const char *print_name,
  262. resource_size_t bar_start);
  263. static int dfx_adap_init(DFX_board_t *bp, int get_buffers);
  264. static int dfx_open(struct net_device *dev);
  265. static int dfx_close(struct net_device *dev);
  266. static void dfx_int_pr_halt_id(DFX_board_t *bp);
  267. static void dfx_int_type_0_process(DFX_board_t *bp);
  268. static void dfx_int_common(struct net_device *dev);
  269. static irqreturn_t dfx_interrupt(int irq, void *dev_id);
  270. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
  271. static void dfx_ctl_set_multicast_list(struct net_device *dev);
  272. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
  273. static int dfx_ctl_update_cam(DFX_board_t *bp);
  274. static int dfx_ctl_update_filters(DFX_board_t *bp);
  275. static int dfx_hw_dma_cmd_req(DFX_board_t *bp);
  276. static int dfx_hw_port_ctrl_req(DFX_board_t *bp, PI_UINT32 command, PI_UINT32 data_a, PI_UINT32 data_b, PI_UINT32 *host_data);
  277. static void dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
  278. static int dfx_hw_adap_state_rd(DFX_board_t *bp);
  279. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
  280. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers);
  281. static void dfx_rcv_queue_process(DFX_board_t *bp);
  282. static void dfx_rcv_flush(DFX_board_t *bp);
  283. static int dfx_xmt_queue_pkt(struct sk_buff *skb, struct net_device *dev);
  284. static int dfx_xmt_done(DFX_board_t *bp);
  285. static void dfx_xmt_flush(DFX_board_t *bp);
  286. /* Define module-wide (static) variables */
  287. static struct pci_driver dfx_pci_driver;
  288. static struct eisa_driver dfx_eisa_driver;
  289. static struct tc_driver dfx_tc_driver;
  290. /*
  291. * =======================
  292. * = dfx_port_write_long =
  293. * = dfx_port_read_long =
  294. * =======================
  295. *
  296. * Overview:
  297. * Routines for reading and writing values from/to adapter
  298. *
  299. * Returns:
  300. * None
  301. *
  302. * Arguments:
  303. * bp - pointer to board information
  304. * offset - register offset from base I/O address
  305. * data - for dfx_port_write_long, this is a value to write;
  306. * for dfx_port_read_long, this is a pointer to store
  307. * the read value
  308. *
  309. * Functional Description:
  310. * These routines perform the correct operation to read or write
  311. * the adapter register.
  312. *
  313. * EISA port block base addresses are based on the slot number in which the
  314. * controller is installed. For example, if the EISA controller is installed
  315. * in slot 4, the port block base address is 0x4000. If the controller is
  316. * installed in slot 2, the port block base address is 0x2000, and so on.
  317. * This port block can be used to access PDQ, ESIC, and DEFEA on-board
  318. * registers using the register offsets defined in DEFXX.H.
  319. *
  320. * PCI port block base addresses are assigned by the PCI BIOS or system
  321. * firmware. There is one 128 byte port block which can be accessed. It
  322. * allows for I/O mapping of both PDQ and PFI registers using the register
  323. * offsets defined in DEFXX.H.
  324. *
  325. * Return Codes:
  326. * None
  327. *
  328. * Assumptions:
  329. * bp->base is a valid base I/O address for this adapter.
  330. * offset is a valid register offset for this adapter.
  331. *
  332. * Side Effects:
  333. * Rather than produce macros for these functions, these routines
  334. * are defined using "inline" to ensure that the compiler will
  335. * generate inline code and not waste a procedure call and return.
  336. * This provides all the benefits of macros, but with the
  337. * advantage of strict data type checking.
  338. */
  339. static inline void dfx_writel(DFX_board_t *bp, int offset, u32 data)
  340. {
  341. writel(data, bp->base.mem + offset);
  342. mb();
  343. }
  344. static inline void dfx_outl(DFX_board_t *bp, int offset, u32 data)
  345. {
  346. outl(data, bp->base.port + offset);
  347. }
  348. static void dfx_port_write_long(DFX_board_t *bp, int offset, u32 data)
  349. {
  350. struct device __maybe_unused *bdev = bp->bus_dev;
  351. int dfx_bus_tc = DFX_BUS_TC(bdev);
  352. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  353. if (dfx_use_mmio)
  354. dfx_writel(bp, offset, data);
  355. else
  356. dfx_outl(bp, offset, data);
  357. }
  358. static inline void dfx_readl(DFX_board_t *bp, int offset, u32 *data)
  359. {
  360. mb();
  361. *data = readl(bp->base.mem + offset);
  362. }
  363. static inline void dfx_inl(DFX_board_t *bp, int offset, u32 *data)
  364. {
  365. *data = inl(bp->base.port + offset);
  366. }
  367. static void dfx_port_read_long(DFX_board_t *bp, int offset, u32 *data)
  368. {
  369. struct device __maybe_unused *bdev = bp->bus_dev;
  370. int dfx_bus_tc = DFX_BUS_TC(bdev);
  371. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  372. if (dfx_use_mmio)
  373. dfx_readl(bp, offset, data);
  374. else
  375. dfx_inl(bp, offset, data);
  376. }
  377. /*
  378. * ================
  379. * = dfx_get_bars =
  380. * ================
  381. *
  382. * Overview:
  383. * Retrieves the address range used to access control and status
  384. * registers.
  385. *
  386. * Returns:
  387. * None
  388. *
  389. * Arguments:
  390. * bdev - pointer to device information
  391. * bar_start - pointer to store the start address
  392. * bar_len - pointer to store the length of the area
  393. *
  394. * Assumptions:
  395. * I am sure there are some.
  396. *
  397. * Side Effects:
  398. * None
  399. */
  400. static void dfx_get_bars(struct device *bdev,
  401. resource_size_t *bar_start, resource_size_t *bar_len)
  402. {
  403. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  404. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  405. int dfx_bus_tc = DFX_BUS_TC(bdev);
  406. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  407. if (dfx_bus_pci) {
  408. int num = dfx_use_mmio ? 0 : 1;
  409. *bar_start = pci_resource_start(to_pci_dev(bdev), num);
  410. *bar_len = pci_resource_len(to_pci_dev(bdev), num);
  411. }
  412. if (dfx_bus_eisa) {
  413. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  414. resource_size_t bar;
  415. if (dfx_use_mmio) {
  416. bar = inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_2);
  417. bar <<= 8;
  418. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_1);
  419. bar <<= 8;
  420. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_CMP_0);
  421. bar <<= 16;
  422. *bar_start = bar;
  423. bar = inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_2);
  424. bar <<= 8;
  425. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_1);
  426. bar <<= 8;
  427. bar |= inb(base_addr + PI_ESIC_K_MEM_ADD_MASK_0);
  428. bar <<= 16;
  429. *bar_len = (bar | PI_MEM_ADD_MASK_M) + 1;
  430. } else {
  431. *bar_start = base_addr;
  432. *bar_len = PI_ESIC_K_CSR_IO_LEN;
  433. }
  434. }
  435. if (dfx_bus_tc) {
  436. *bar_start = to_tc_dev(bdev)->resource.start +
  437. PI_TC_K_CSR_OFFSET;
  438. *bar_len = PI_TC_K_CSR_LEN;
  439. }
  440. }
  441. static const struct net_device_ops dfx_netdev_ops = {
  442. .ndo_open = dfx_open,
  443. .ndo_stop = dfx_close,
  444. .ndo_start_xmit = dfx_xmt_queue_pkt,
  445. .ndo_get_stats = dfx_ctl_get_stats,
  446. .ndo_set_multicast_list = dfx_ctl_set_multicast_list,
  447. .ndo_set_mac_address = dfx_ctl_set_mac_address,
  448. };
  449. /*
  450. * ================
  451. * = dfx_register =
  452. * ================
  453. *
  454. * Overview:
  455. * Initializes a supported FDDI controller
  456. *
  457. * Returns:
  458. * Condition code
  459. *
  460. * Arguments:
  461. * bdev - pointer to device information
  462. *
  463. * Functional Description:
  464. *
  465. * Return Codes:
  466. * 0 - This device (fddi0, fddi1, etc) configured successfully
  467. * -EBUSY - Failed to get resources, or dfx_driver_init failed.
  468. *
  469. * Assumptions:
  470. * It compiles so it should work :-( (PCI cards do :-)
  471. *
  472. * Side Effects:
  473. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  474. * initialized and the board resources are read and stored in
  475. * the device structure.
  476. */
  477. static int __devinit dfx_register(struct device *bdev)
  478. {
  479. static int version_disp;
  480. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  481. int dfx_bus_tc = DFX_BUS_TC(bdev);
  482. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  483. const char *print_name = dev_name(bdev);
  484. struct net_device *dev;
  485. DFX_board_t *bp; /* board pointer */
  486. resource_size_t bar_start = 0; /* pointer to port */
  487. resource_size_t bar_len = 0; /* resource length */
  488. int alloc_size; /* total buffer size used */
  489. struct resource *region;
  490. int err = 0;
  491. if (!version_disp) { /* display version info if adapter is found */
  492. version_disp = 1; /* set display flag to TRUE so that */
  493. printk(version); /* we only display this string ONCE */
  494. }
  495. dev = alloc_fddidev(sizeof(*bp));
  496. if (!dev) {
  497. printk(KERN_ERR "%s: Unable to allocate fddidev, aborting\n",
  498. print_name);
  499. return -ENOMEM;
  500. }
  501. /* Enable PCI device. */
  502. if (dfx_bus_pci && pci_enable_device(to_pci_dev(bdev))) {
  503. printk(KERN_ERR "%s: Cannot enable PCI device, aborting\n",
  504. print_name);
  505. goto err_out;
  506. }
  507. SET_NETDEV_DEV(dev, bdev);
  508. bp = netdev_priv(dev);
  509. bp->bus_dev = bdev;
  510. dev_set_drvdata(bdev, dev);
  511. dfx_get_bars(bdev, &bar_start, &bar_len);
  512. if (dfx_use_mmio)
  513. region = request_mem_region(bar_start, bar_len, print_name);
  514. else
  515. region = request_region(bar_start, bar_len, print_name);
  516. if (!region) {
  517. printk(KERN_ERR "%s: Cannot reserve I/O resource "
  518. "0x%lx @ 0x%lx, aborting\n",
  519. print_name, (long)bar_len, (long)bar_start);
  520. err = -EBUSY;
  521. goto err_out_disable;
  522. }
  523. /* Set up I/O base address. */
  524. if (dfx_use_mmio) {
  525. bp->base.mem = ioremap_nocache(bar_start, bar_len);
  526. if (!bp->base.mem) {
  527. printk(KERN_ERR "%s: Cannot map MMIO\n", print_name);
  528. err = -ENOMEM;
  529. goto err_out_region;
  530. }
  531. } else {
  532. bp->base.port = bar_start;
  533. dev->base_addr = bar_start;
  534. }
  535. /* Initialize new device structure */
  536. dev->netdev_ops = &dfx_netdev_ops;
  537. if (dfx_bus_pci)
  538. pci_set_master(to_pci_dev(bdev));
  539. if (dfx_driver_init(dev, print_name, bar_start) != DFX_K_SUCCESS) {
  540. err = -ENODEV;
  541. goto err_out_unmap;
  542. }
  543. err = register_netdev(dev);
  544. if (err)
  545. goto err_out_kfree;
  546. printk("%s: registered as %s\n", print_name, dev->name);
  547. return 0;
  548. err_out_kfree:
  549. alloc_size = sizeof(PI_DESCR_BLOCK) +
  550. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  551. #ifndef DYNAMIC_BUFFERS
  552. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  553. #endif
  554. sizeof(PI_CONSUMER_BLOCK) +
  555. (PI_ALIGN_K_DESC_BLK - 1);
  556. if (bp->kmalloced)
  557. dma_free_coherent(bdev, alloc_size,
  558. bp->kmalloced, bp->kmalloced_dma);
  559. err_out_unmap:
  560. if (dfx_use_mmio)
  561. iounmap(bp->base.mem);
  562. err_out_region:
  563. if (dfx_use_mmio)
  564. release_mem_region(bar_start, bar_len);
  565. else
  566. release_region(bar_start, bar_len);
  567. err_out_disable:
  568. if (dfx_bus_pci)
  569. pci_disable_device(to_pci_dev(bdev));
  570. err_out:
  571. free_netdev(dev);
  572. return err;
  573. }
  574. /*
  575. * ================
  576. * = dfx_bus_init =
  577. * ================
  578. *
  579. * Overview:
  580. * Initializes the bus-specific controller logic.
  581. *
  582. * Returns:
  583. * None
  584. *
  585. * Arguments:
  586. * dev - pointer to device information
  587. *
  588. * Functional Description:
  589. * Determine and save adapter IRQ in device table,
  590. * then perform bus-specific logic initialization.
  591. *
  592. * Return Codes:
  593. * None
  594. *
  595. * Assumptions:
  596. * bp->base has already been set with the proper
  597. * base I/O address for this device.
  598. *
  599. * Side Effects:
  600. * Interrupts are enabled at the adapter bus-specific logic.
  601. * Note: Interrupts at the DMA engine (PDQ chip) are not
  602. * enabled yet.
  603. */
  604. static void __devinit dfx_bus_init(struct net_device *dev)
  605. {
  606. DFX_board_t *bp = netdev_priv(dev);
  607. struct device *bdev = bp->bus_dev;
  608. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  609. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  610. int dfx_bus_tc = DFX_BUS_TC(bdev);
  611. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  612. u8 val;
  613. DBG_printk("In dfx_bus_init...\n");
  614. /* Initialize a pointer back to the net_device struct */
  615. bp->dev = dev;
  616. /* Initialize adapter based on bus type */
  617. if (dfx_bus_tc)
  618. dev->irq = to_tc_dev(bdev)->interrupt;
  619. if (dfx_bus_eisa) {
  620. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  621. /* Get the interrupt level from the ESIC chip. */
  622. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  623. val &= PI_CONFIG_STAT_0_M_IRQ;
  624. val >>= PI_CONFIG_STAT_0_V_IRQ;
  625. switch (val) {
  626. case PI_CONFIG_STAT_0_IRQ_K_9:
  627. dev->irq = 9;
  628. break;
  629. case PI_CONFIG_STAT_0_IRQ_K_10:
  630. dev->irq = 10;
  631. break;
  632. case PI_CONFIG_STAT_0_IRQ_K_11:
  633. dev->irq = 11;
  634. break;
  635. case PI_CONFIG_STAT_0_IRQ_K_15:
  636. dev->irq = 15;
  637. break;
  638. }
  639. /*
  640. * Enable memory decoding (MEMCS0) and/or port decoding
  641. * (IOCS1/IOCS0) as appropriate in Function Control
  642. * Register. One of the port chip selects seems to be
  643. * used for the Burst Holdoff register, but this bit of
  644. * documentation is missing and as yet it has not been
  645. * determined which of the two. This is also the reason
  646. * the size of the decoded port range is twice as large
  647. * as one required by the PDQ.
  648. */
  649. /* Set the decode range of the board. */
  650. val = ((bp->base.port >> 12) << PI_IO_CMP_V_SLOT);
  651. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_1, val);
  652. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_0_0, 0);
  653. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_1, val);
  654. outb(base_addr + PI_ESIC_K_IO_ADD_CMP_1_0, 0);
  655. val = PI_ESIC_K_CSR_IO_LEN - 1;
  656. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_1, (val >> 8) & 0xff);
  657. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_0_0, val & 0xff);
  658. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_1, (val >> 8) & 0xff);
  659. outb(base_addr + PI_ESIC_K_IO_ADD_MASK_1_0, val & 0xff);
  660. /* Enable the decoders. */
  661. val = PI_FUNCTION_CNTRL_M_IOCS1 | PI_FUNCTION_CNTRL_M_IOCS0;
  662. if (dfx_use_mmio)
  663. val |= PI_FUNCTION_CNTRL_M_MEMCS0;
  664. outb(base_addr + PI_ESIC_K_FUNCTION_CNTRL, val);
  665. /*
  666. * Enable access to the rest of the module
  667. * (including PDQ and packet memory).
  668. */
  669. val = PI_SLOT_CNTRL_M_ENB;
  670. outb(base_addr + PI_ESIC_K_SLOT_CNTRL, val);
  671. /*
  672. * Map PDQ registers into memory or port space. This is
  673. * done with a bit in the Burst Holdoff register.
  674. */
  675. val = inb(base_addr + PI_DEFEA_K_BURST_HOLDOFF);
  676. if (dfx_use_mmio)
  677. val |= PI_BURST_HOLDOFF_V_MEM_MAP;
  678. else
  679. val &= ~PI_BURST_HOLDOFF_V_MEM_MAP;
  680. outb(base_addr + PI_DEFEA_K_BURST_HOLDOFF, val);
  681. /* Enable interrupts at EISA bus interface chip (ESIC) */
  682. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  683. val |= PI_CONFIG_STAT_0_M_INT_ENB;
  684. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  685. }
  686. if (dfx_bus_pci) {
  687. struct pci_dev *pdev = to_pci_dev(bdev);
  688. /* Get the interrupt level from the PCI Configuration Table */
  689. dev->irq = pdev->irq;
  690. /* Check Latency Timer and set if less than minimal */
  691. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
  692. if (val < PFI_K_LAT_TIMER_MIN) {
  693. val = PFI_K_LAT_TIMER_DEF;
  694. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
  695. }
  696. /* Enable interrupts at PCI bus interface chip (PFI) */
  697. val = PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB;
  698. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, val);
  699. }
  700. }
  701. /*
  702. * ==================
  703. * = dfx_bus_uninit =
  704. * ==================
  705. *
  706. * Overview:
  707. * Uninitializes the bus-specific controller logic.
  708. *
  709. * Returns:
  710. * None
  711. *
  712. * Arguments:
  713. * dev - pointer to device information
  714. *
  715. * Functional Description:
  716. * Perform bus-specific logic uninitialization.
  717. *
  718. * Return Codes:
  719. * None
  720. *
  721. * Assumptions:
  722. * bp->base has already been set with the proper
  723. * base I/O address for this device.
  724. *
  725. * Side Effects:
  726. * Interrupts are disabled at the adapter bus-specific logic.
  727. */
  728. static void __devexit dfx_bus_uninit(struct net_device *dev)
  729. {
  730. DFX_board_t *bp = netdev_priv(dev);
  731. struct device *bdev = bp->bus_dev;
  732. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  733. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  734. u8 val;
  735. DBG_printk("In dfx_bus_uninit...\n");
  736. /* Uninitialize adapter based on bus type */
  737. if (dfx_bus_eisa) {
  738. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  739. /* Disable interrupts at EISA bus interface chip (ESIC) */
  740. val = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  741. val &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  742. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, val);
  743. }
  744. if (dfx_bus_pci) {
  745. /* Disable interrupts at PCI bus interface chip (PFI) */
  746. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, 0);
  747. }
  748. }
  749. /*
  750. * ========================
  751. * = dfx_bus_config_check =
  752. * ========================
  753. *
  754. * Overview:
  755. * Checks the configuration (burst size, full-duplex, etc.) If any parameters
  756. * are illegal, then this routine will set new defaults.
  757. *
  758. * Returns:
  759. * None
  760. *
  761. * Arguments:
  762. * bp - pointer to board information
  763. *
  764. * Functional Description:
  765. * For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
  766. * PDQ, and all FDDI PCI controllers, all values are legal.
  767. *
  768. * Return Codes:
  769. * None
  770. *
  771. * Assumptions:
  772. * dfx_adap_init has NOT been called yet so burst size and other items have
  773. * not been set.
  774. *
  775. * Side Effects:
  776. * None
  777. */
  778. static void __devinit dfx_bus_config_check(DFX_board_t *bp)
  779. {
  780. struct device __maybe_unused *bdev = bp->bus_dev;
  781. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  782. int status; /* return code from adapter port control call */
  783. u32 host_data; /* LW data returned from port control call */
  784. DBG_printk("In dfx_bus_config_check...\n");
  785. /* Configuration check only valid for EISA adapter */
  786. if (dfx_bus_eisa) {
  787. /*
  788. * First check if revision 2 EISA controller. Rev. 1 cards used
  789. * PDQ revision B, so no workaround needed in this case. Rev. 3
  790. * cards used PDQ revision E, so no workaround needed in this
  791. * case, either. Only Rev. 2 cards used either Rev. D or E
  792. * chips, so we must verify the chip revision on Rev. 2 cards.
  793. */
  794. if (to_eisa_device(bdev)->id.driver_data == DEFEA_PROD_ID_2) {
  795. /*
  796. * Revision 2 FDDI EISA controller found,
  797. * so let's check PDQ revision of adapter.
  798. */
  799. status = dfx_hw_port_ctrl_req(bp,
  800. PI_PCTRL_M_SUB_CMD,
  801. PI_SUB_CMD_K_PDQ_REV_GET,
  802. 0,
  803. &host_data);
  804. if ((status != DFX_K_SUCCESS) || (host_data == 2))
  805. {
  806. /*
  807. * Either we couldn't determine the PDQ revision, or
  808. * we determined that it is at revision D. In either case,
  809. * we need to implement the workaround.
  810. */
  811. /* Ensure that the burst size is set to 8 longwords or less */
  812. switch (bp->burst_size)
  813. {
  814. case PI_PDATA_B_DMA_BURST_SIZE_32:
  815. case PI_PDATA_B_DMA_BURST_SIZE_16:
  816. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
  817. break;
  818. default:
  819. break;
  820. }
  821. /* Ensure that full-duplex mode is not enabled */
  822. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  823. }
  824. }
  825. }
  826. }
  827. /*
  828. * ===================
  829. * = dfx_driver_init =
  830. * ===================
  831. *
  832. * Overview:
  833. * Initializes remaining adapter board structure information
  834. * and makes sure adapter is in a safe state prior to dfx_open().
  835. *
  836. * Returns:
  837. * Condition code
  838. *
  839. * Arguments:
  840. * dev - pointer to device information
  841. * print_name - printable device name
  842. *
  843. * Functional Description:
  844. * This function allocates additional resources such as the host memory
  845. * blocks needed by the adapter (eg. descriptor and consumer blocks).
  846. * Remaining bus initialization steps are also completed. The adapter
  847. * is also reset so that it is in the DMA_UNAVAILABLE state. The OS
  848. * must call dfx_open() to open the adapter and bring it on-line.
  849. *
  850. * Return Codes:
  851. * DFX_K_SUCCESS - initialization succeeded
  852. * DFX_K_FAILURE - initialization failed - could not allocate memory
  853. * or read adapter MAC address
  854. *
  855. * Assumptions:
  856. * Memory allocated from pci_alloc_consistent() call is physically
  857. * contiguous, locked memory.
  858. *
  859. * Side Effects:
  860. * Adapter is reset and should be in DMA_UNAVAILABLE state before
  861. * returning from this routine.
  862. */
  863. static int __devinit dfx_driver_init(struct net_device *dev,
  864. const char *print_name,
  865. resource_size_t bar_start)
  866. {
  867. DFX_board_t *bp = netdev_priv(dev);
  868. struct device *bdev = bp->bus_dev;
  869. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  870. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  871. int dfx_bus_tc = DFX_BUS_TC(bdev);
  872. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  873. int alloc_size; /* total buffer size needed */
  874. char *top_v, *curr_v; /* virtual addrs into memory block */
  875. dma_addr_t top_p, curr_p; /* physical addrs into memory block */
  876. u32 data; /* host data register value */
  877. __le32 le32;
  878. char *board_name = NULL;
  879. DBG_printk("In dfx_driver_init...\n");
  880. /* Initialize bus-specific hardware registers */
  881. dfx_bus_init(dev);
  882. /*
  883. * Initialize default values for configurable parameters
  884. *
  885. * Note: All of these parameters are ones that a user may
  886. * want to customize. It'd be nice to break these
  887. * out into Space.c or someplace else that's more
  888. * accessible/understandable than this file.
  889. */
  890. bp->full_duplex_enb = PI_SNMP_K_FALSE;
  891. bp->req_ttrt = 8 * 12500; /* 8ms in 80 nanosec units */
  892. bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_DEF;
  893. bp->rcv_bufs_to_post = RCV_BUFS_DEF;
  894. /*
  895. * Ensure that HW configuration is OK
  896. *
  897. * Note: Depending on the hardware revision, we may need to modify
  898. * some of the configurable parameters to workaround hardware
  899. * limitations. We'll perform this configuration check AFTER
  900. * setting the parameters to their default values.
  901. */
  902. dfx_bus_config_check(bp);
  903. /* Disable PDQ interrupts first */
  904. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  905. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  906. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  907. /* Read the factory MAC address from the adapter then save it */
  908. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_LO, 0,
  909. &data) != DFX_K_SUCCESS) {
  910. printk("%s: Could not read adapter factory MAC address!\n",
  911. print_name);
  912. return(DFX_K_FAILURE);
  913. }
  914. le32 = cpu_to_le32(data);
  915. memcpy(&bp->factory_mac_addr[0], &le32, sizeof(u32));
  916. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_MLA, PI_PDATA_A_MLA_K_HI, 0,
  917. &data) != DFX_K_SUCCESS) {
  918. printk("%s: Could not read adapter factory MAC address!\n",
  919. print_name);
  920. return(DFX_K_FAILURE);
  921. }
  922. le32 = cpu_to_le32(data);
  923. memcpy(&bp->factory_mac_addr[4], &le32, sizeof(u16));
  924. /*
  925. * Set current address to factory address
  926. *
  927. * Note: Node address override support is handled through
  928. * dfx_ctl_set_mac_address.
  929. */
  930. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  931. if (dfx_bus_tc)
  932. board_name = "DEFTA";
  933. if (dfx_bus_eisa)
  934. board_name = "DEFEA";
  935. if (dfx_bus_pci)
  936. board_name = "DEFPA";
  937. pr_info("%s: %s at %saddr = 0x%llx, IRQ = %d, "
  938. "Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n",
  939. print_name, board_name, dfx_use_mmio ? "" : "I/O ",
  940. (long long)bar_start, dev->irq,
  941. dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
  942. dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
  943. /*
  944. * Get memory for descriptor block, consumer block, and other buffers
  945. * that need to be DMA read or written to by the adapter.
  946. */
  947. alloc_size = sizeof(PI_DESCR_BLOCK) +
  948. PI_CMD_REQ_K_SIZE_MAX +
  949. PI_CMD_RSP_K_SIZE_MAX +
  950. #ifndef DYNAMIC_BUFFERS
  951. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  952. #endif
  953. sizeof(PI_CONSUMER_BLOCK) +
  954. (PI_ALIGN_K_DESC_BLK - 1);
  955. bp->kmalloced = top_v = dma_alloc_coherent(bp->bus_dev, alloc_size,
  956. &bp->kmalloced_dma,
  957. GFP_ATOMIC);
  958. if (top_v == NULL) {
  959. printk("%s: Could not allocate memory for host buffers "
  960. "and structures!\n", print_name);
  961. return(DFX_K_FAILURE);
  962. }
  963. memset(top_v, 0, alloc_size); /* zero out memory before continuing */
  964. top_p = bp->kmalloced_dma; /* get physical address of buffer */
  965. /*
  966. * To guarantee the 8K alignment required for the descriptor block, 8K - 1
  967. * plus the amount of memory needed was allocated. The physical address
  968. * is now 8K aligned. By carving up the memory in a specific order,
  969. * we'll guarantee the alignment requirements for all other structures.
  970. *
  971. * Note: If the assumptions change regarding the non-paged, non-cached,
  972. * physically contiguous nature of the memory block or the address
  973. * alignments, then we'll need to implement a different algorithm
  974. * for allocating the needed memory.
  975. */
  976. curr_p = ALIGN(top_p, PI_ALIGN_K_DESC_BLK);
  977. curr_v = top_v + (curr_p - top_p);
  978. /* Reserve space for descriptor block */
  979. bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
  980. bp->descr_block_phys = curr_p;
  981. curr_v += sizeof(PI_DESCR_BLOCK);
  982. curr_p += sizeof(PI_DESCR_BLOCK);
  983. /* Reserve space for command request buffer */
  984. bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
  985. bp->cmd_req_phys = curr_p;
  986. curr_v += PI_CMD_REQ_K_SIZE_MAX;
  987. curr_p += PI_CMD_REQ_K_SIZE_MAX;
  988. /* Reserve space for command response buffer */
  989. bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
  990. bp->cmd_rsp_phys = curr_p;
  991. curr_v += PI_CMD_RSP_K_SIZE_MAX;
  992. curr_p += PI_CMD_RSP_K_SIZE_MAX;
  993. /* Reserve space for the LLC host receive queue buffers */
  994. bp->rcv_block_virt = curr_v;
  995. bp->rcv_block_phys = curr_p;
  996. #ifndef DYNAMIC_BUFFERS
  997. curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  998. curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
  999. #endif
  1000. /* Reserve space for the consumer block */
  1001. bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
  1002. bp->cons_block_phys = curr_p;
  1003. /* Display virtual and physical addresses if debug driver */
  1004. DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n",
  1005. print_name,
  1006. (long)bp->descr_block_virt, bp->descr_block_phys);
  1007. DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n",
  1008. print_name, (long)bp->cmd_req_virt, bp->cmd_req_phys);
  1009. DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n",
  1010. print_name, (long)bp->cmd_rsp_virt, bp->cmd_rsp_phys);
  1011. DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n",
  1012. print_name, (long)bp->rcv_block_virt, bp->rcv_block_phys);
  1013. DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n",
  1014. print_name, (long)bp->cons_block_virt, bp->cons_block_phys);
  1015. return(DFX_K_SUCCESS);
  1016. }
  1017. /*
  1018. * =================
  1019. * = dfx_adap_init =
  1020. * =================
  1021. *
  1022. * Overview:
  1023. * Brings the adapter to the link avail/link unavailable state.
  1024. *
  1025. * Returns:
  1026. * Condition code
  1027. *
  1028. * Arguments:
  1029. * bp - pointer to board information
  1030. * get_buffers - non-zero if buffers to be allocated
  1031. *
  1032. * Functional Description:
  1033. * Issues the low-level firmware/hardware calls necessary to bring
  1034. * the adapter up, or to properly reset and restore adapter during
  1035. * run-time.
  1036. *
  1037. * Return Codes:
  1038. * DFX_K_SUCCESS - Adapter brought up successfully
  1039. * DFX_K_FAILURE - Adapter initialization failed
  1040. *
  1041. * Assumptions:
  1042. * bp->reset_type should be set to a valid reset type value before
  1043. * calling this routine.
  1044. *
  1045. * Side Effects:
  1046. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1047. * upon a successful return of this routine.
  1048. */
  1049. static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
  1050. {
  1051. DBG_printk("In dfx_adap_init...\n");
  1052. /* Disable PDQ interrupts first */
  1053. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1054. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1055. if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
  1056. {
  1057. printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
  1058. return(DFX_K_FAILURE);
  1059. }
  1060. /*
  1061. * When the PDQ is reset, some false Type 0 interrupts may be pending,
  1062. * so we'll acknowledge all Type 0 interrupts now before continuing.
  1063. */
  1064. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
  1065. /*
  1066. * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
  1067. *
  1068. * Note: We only need to clear host copies of these registers. The PDQ reset
  1069. * takes care of the on-board register values.
  1070. */
  1071. bp->cmd_req_reg.lword = 0;
  1072. bp->cmd_rsp_reg.lword = 0;
  1073. bp->rcv_xmt_reg.lword = 0;
  1074. /* Clear consumer block before going to DMA_AVAILABLE state */
  1075. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1076. /* Initialize the DMA Burst Size */
  1077. if (dfx_hw_port_ctrl_req(bp,
  1078. PI_PCTRL_M_SUB_CMD,
  1079. PI_SUB_CMD_K_BURST_SIZE_SET,
  1080. bp->burst_size,
  1081. NULL) != DFX_K_SUCCESS)
  1082. {
  1083. printk("%s: Could not set adapter burst size!\n", bp->dev->name);
  1084. return(DFX_K_FAILURE);
  1085. }
  1086. /*
  1087. * Set base address of Consumer Block
  1088. *
  1089. * Assumption: 32-bit physical address of consumer block is 64 byte
  1090. * aligned. That is, bits 0-5 of the address must be zero.
  1091. */
  1092. if (dfx_hw_port_ctrl_req(bp,
  1093. PI_PCTRL_M_CONS_BLOCK,
  1094. bp->cons_block_phys,
  1095. 0,
  1096. NULL) != DFX_K_SUCCESS)
  1097. {
  1098. printk("%s: Could not set consumer block address!\n", bp->dev->name);
  1099. return(DFX_K_FAILURE);
  1100. }
  1101. /*
  1102. * Set the base address of Descriptor Block and bring adapter
  1103. * to DMA_AVAILABLE state.
  1104. *
  1105. * Note: We also set the literal and data swapping requirements
  1106. * in this command.
  1107. *
  1108. * Assumption: 32-bit physical address of descriptor block
  1109. * is 8Kbyte aligned.
  1110. */
  1111. if (dfx_hw_port_ctrl_req(bp, PI_PCTRL_M_INIT,
  1112. (u32)(bp->descr_block_phys |
  1113. PI_PDATA_A_INIT_M_BSWAP_INIT),
  1114. 0, NULL) != DFX_K_SUCCESS) {
  1115. printk("%s: Could not set descriptor block address!\n",
  1116. bp->dev->name);
  1117. return DFX_K_FAILURE;
  1118. }
  1119. /* Set transmit flush timeout value */
  1120. bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
  1121. bp->cmd_req_virt->char_set.item[0].item_code = PI_ITEM_K_FLUSH_TIME;
  1122. bp->cmd_req_virt->char_set.item[0].value = 3; /* 3 seconds */
  1123. bp->cmd_req_virt->char_set.item[0].item_index = 0;
  1124. bp->cmd_req_virt->char_set.item[1].item_code = PI_ITEM_K_EOL;
  1125. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1126. {
  1127. printk("%s: DMA command request failed!\n", bp->dev->name);
  1128. return(DFX_K_FAILURE);
  1129. }
  1130. /* Set the initial values for eFDXEnable and MACTReq MIB objects */
  1131. bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
  1132. bp->cmd_req_virt->snmp_set.item[0].item_code = PI_ITEM_K_FDX_ENB_DIS;
  1133. bp->cmd_req_virt->snmp_set.item[0].value = bp->full_duplex_enb;
  1134. bp->cmd_req_virt->snmp_set.item[0].item_index = 0;
  1135. bp->cmd_req_virt->snmp_set.item[1].item_code = PI_ITEM_K_MAC_T_REQ;
  1136. bp->cmd_req_virt->snmp_set.item[1].value = bp->req_ttrt;
  1137. bp->cmd_req_virt->snmp_set.item[1].item_index = 0;
  1138. bp->cmd_req_virt->snmp_set.item[2].item_code = PI_ITEM_K_EOL;
  1139. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1140. {
  1141. printk("%s: DMA command request failed!\n", bp->dev->name);
  1142. return(DFX_K_FAILURE);
  1143. }
  1144. /* Initialize adapter CAM */
  1145. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  1146. {
  1147. printk("%s: Adapter CAM update failed!\n", bp->dev->name);
  1148. return(DFX_K_FAILURE);
  1149. }
  1150. /* Initialize adapter filters */
  1151. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  1152. {
  1153. printk("%s: Adapter filters update failed!\n", bp->dev->name);
  1154. return(DFX_K_FAILURE);
  1155. }
  1156. /*
  1157. * Remove any existing dynamic buffers (i.e. if the adapter is being
  1158. * reinitialized)
  1159. */
  1160. if (get_buffers)
  1161. dfx_rcv_flush(bp);
  1162. /* Initialize receive descriptor block and produce buffers */
  1163. if (dfx_rcv_init(bp, get_buffers))
  1164. {
  1165. printk("%s: Receive buffer allocation failed\n", bp->dev->name);
  1166. if (get_buffers)
  1167. dfx_rcv_flush(bp);
  1168. return(DFX_K_FAILURE);
  1169. }
  1170. /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
  1171. bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
  1172. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1173. {
  1174. printk("%s: Start command failed\n", bp->dev->name);
  1175. if (get_buffers)
  1176. dfx_rcv_flush(bp);
  1177. return(DFX_K_FAILURE);
  1178. }
  1179. /* Initialization succeeded, reenable PDQ interrupts */
  1180. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
  1181. return(DFX_K_SUCCESS);
  1182. }
  1183. /*
  1184. * ============
  1185. * = dfx_open =
  1186. * ============
  1187. *
  1188. * Overview:
  1189. * Opens the adapter
  1190. *
  1191. * Returns:
  1192. * Condition code
  1193. *
  1194. * Arguments:
  1195. * dev - pointer to device information
  1196. *
  1197. * Functional Description:
  1198. * This function brings the adapter to an operational state.
  1199. *
  1200. * Return Codes:
  1201. * 0 - Adapter was successfully opened
  1202. * -EAGAIN - Could not register IRQ or adapter initialization failed
  1203. *
  1204. * Assumptions:
  1205. * This routine should only be called for a device that was
  1206. * initialized successfully.
  1207. *
  1208. * Side Effects:
  1209. * Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
  1210. * if the open is successful.
  1211. */
  1212. static int dfx_open(struct net_device *dev)
  1213. {
  1214. DFX_board_t *bp = netdev_priv(dev);
  1215. int ret;
  1216. DBG_printk("In dfx_open...\n");
  1217. /* Register IRQ - support shared interrupts by passing device ptr */
  1218. ret = request_irq(dev->irq, dfx_interrupt, IRQF_SHARED, dev->name,
  1219. dev);
  1220. if (ret) {
  1221. printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
  1222. return ret;
  1223. }
  1224. /*
  1225. * Set current address to factory MAC address
  1226. *
  1227. * Note: We've already done this step in dfx_driver_init.
  1228. * However, it's possible that a user has set a node
  1229. * address override, then closed and reopened the
  1230. * adapter. Unless we reset the device address field
  1231. * now, we'll continue to use the existing modified
  1232. * address.
  1233. */
  1234. memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
  1235. /* Clear local unicast/multicast address tables and counts */
  1236. memset(bp->uc_table, 0, sizeof(bp->uc_table));
  1237. memset(bp->mc_table, 0, sizeof(bp->mc_table));
  1238. bp->uc_count = 0;
  1239. bp->mc_count = 0;
  1240. /* Disable promiscuous filter settings */
  1241. bp->ind_group_prom = PI_FSTATE_K_BLOCK;
  1242. bp->group_prom = PI_FSTATE_K_BLOCK;
  1243. spin_lock_init(&bp->lock);
  1244. /* Reset and initialize adapter */
  1245. bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST; /* skip self-test */
  1246. if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
  1247. {
  1248. printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
  1249. free_irq(dev->irq, dev);
  1250. return -EAGAIN;
  1251. }
  1252. /* Set device structure info */
  1253. netif_start_queue(dev);
  1254. return(0);
  1255. }
  1256. /*
  1257. * =============
  1258. * = dfx_close =
  1259. * =============
  1260. *
  1261. * Overview:
  1262. * Closes the device/module.
  1263. *
  1264. * Returns:
  1265. * Condition code
  1266. *
  1267. * Arguments:
  1268. * dev - pointer to device information
  1269. *
  1270. * Functional Description:
  1271. * This routine closes the adapter and brings it to a safe state.
  1272. * The interrupt service routine is deregistered with the OS.
  1273. * The adapter can be opened again with another call to dfx_open().
  1274. *
  1275. * Return Codes:
  1276. * Always return 0.
  1277. *
  1278. * Assumptions:
  1279. * No further requests for this adapter are made after this routine is
  1280. * called. dfx_open() can be called to reset and reinitialize the
  1281. * adapter.
  1282. *
  1283. * Side Effects:
  1284. * Adapter should be in DMA_UNAVAILABLE state upon completion of this
  1285. * routine.
  1286. */
  1287. static int dfx_close(struct net_device *dev)
  1288. {
  1289. DFX_board_t *bp = netdev_priv(dev);
  1290. DBG_printk("In dfx_close...\n");
  1291. /* Disable PDQ interrupts first */
  1292. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1293. /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
  1294. (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
  1295. /*
  1296. * Flush any pending transmit buffers
  1297. *
  1298. * Note: It's important that we flush the transmit buffers
  1299. * BEFORE we clear our copy of the Type 2 register.
  1300. * Otherwise, we'll have no idea how many buffers
  1301. * we need to free.
  1302. */
  1303. dfx_xmt_flush(bp);
  1304. /*
  1305. * Clear Type 1 and Type 2 registers after adapter reset
  1306. *
  1307. * Note: Even though we're closing the adapter, it's
  1308. * possible that an interrupt will occur after
  1309. * dfx_close is called. Without some assurance to
  1310. * the contrary we want to make sure that we don't
  1311. * process receive and transmit LLC frames and update
  1312. * the Type 2 register with bad information.
  1313. */
  1314. bp->cmd_req_reg.lword = 0;
  1315. bp->cmd_rsp_reg.lword = 0;
  1316. bp->rcv_xmt_reg.lword = 0;
  1317. /* Clear consumer block for the same reason given above */
  1318. memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
  1319. /* Release all dynamically allocate skb in the receive ring. */
  1320. dfx_rcv_flush(bp);
  1321. /* Clear device structure flags */
  1322. netif_stop_queue(dev);
  1323. /* Deregister (free) IRQ */
  1324. free_irq(dev->irq, dev);
  1325. return(0);
  1326. }
  1327. /*
  1328. * ======================
  1329. * = dfx_int_pr_halt_id =
  1330. * ======================
  1331. *
  1332. * Overview:
  1333. * Displays halt id's in string form.
  1334. *
  1335. * Returns:
  1336. * None
  1337. *
  1338. * Arguments:
  1339. * bp - pointer to board information
  1340. *
  1341. * Functional Description:
  1342. * Determine current halt id and display appropriate string.
  1343. *
  1344. * Return Codes:
  1345. * None
  1346. *
  1347. * Assumptions:
  1348. * None
  1349. *
  1350. * Side Effects:
  1351. * None
  1352. */
  1353. static void dfx_int_pr_halt_id(DFX_board_t *bp)
  1354. {
  1355. PI_UINT32 port_status; /* PDQ port status register value */
  1356. PI_UINT32 halt_id; /* PDQ port status halt ID */
  1357. /* Read the latest port status */
  1358. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1359. /* Display halt state transition information */
  1360. halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
  1361. switch (halt_id)
  1362. {
  1363. case PI_HALT_ID_K_SELFTEST_TIMEOUT:
  1364. printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
  1365. break;
  1366. case PI_HALT_ID_K_PARITY_ERROR:
  1367. printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
  1368. break;
  1369. case PI_HALT_ID_K_HOST_DIR_HALT:
  1370. printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
  1371. break;
  1372. case PI_HALT_ID_K_SW_FAULT:
  1373. printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
  1374. break;
  1375. case PI_HALT_ID_K_HW_FAULT:
  1376. printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
  1377. break;
  1378. case PI_HALT_ID_K_PC_TRACE:
  1379. printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
  1380. break;
  1381. case PI_HALT_ID_K_DMA_ERROR:
  1382. printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
  1383. break;
  1384. case PI_HALT_ID_K_IMAGE_CRC_ERROR:
  1385. printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
  1386. break;
  1387. case PI_HALT_ID_K_BUS_EXCEPTION:
  1388. printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
  1389. break;
  1390. default:
  1391. printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
  1392. break;
  1393. }
  1394. }
  1395. /*
  1396. * ==========================
  1397. * = dfx_int_type_0_process =
  1398. * ==========================
  1399. *
  1400. * Overview:
  1401. * Processes Type 0 interrupts.
  1402. *
  1403. * Returns:
  1404. * None
  1405. *
  1406. * Arguments:
  1407. * bp - pointer to board information
  1408. *
  1409. * Functional Description:
  1410. * Processes all enabled Type 0 interrupts. If the reason for the interrupt
  1411. * is a serious fault on the adapter, then an error message is displayed
  1412. * and the adapter is reset.
  1413. *
  1414. * One tricky potential timing window is the rapid succession of "link avail"
  1415. * "link unavail" state change interrupts. The acknowledgement of the Type 0
  1416. * interrupt must be done before reading the state from the Port Status
  1417. * register. This is true because a state change could occur after reading
  1418. * the data, but before acknowledging the interrupt. If this state change
  1419. * does happen, it would be lost because the driver is using the old state,
  1420. * and it will never know about the new state because it subsequently
  1421. * acknowledges the state change interrupt.
  1422. *
  1423. * INCORRECT CORRECT
  1424. * read type 0 int reasons read type 0 int reasons
  1425. * read adapter state ack type 0 interrupts
  1426. * ack type 0 interrupts read adapter state
  1427. * ... process interrupt ... ... process interrupt ...
  1428. *
  1429. * Return Codes:
  1430. * None
  1431. *
  1432. * Assumptions:
  1433. * None
  1434. *
  1435. * Side Effects:
  1436. * An adapter reset may occur if the adapter has any Type 0 error interrupts
  1437. * or if the port status indicates that the adapter is halted. The driver
  1438. * is responsible for reinitializing the adapter with the current CAM
  1439. * contents and adapter filter settings.
  1440. */
  1441. static void dfx_int_type_0_process(DFX_board_t *bp)
  1442. {
  1443. PI_UINT32 type_0_status; /* Host Interrupt Type 0 register */
  1444. PI_UINT32 state; /* current adap state (from port status) */
  1445. /*
  1446. * Read host interrupt Type 0 register to determine which Type 0
  1447. * interrupts are pending. Immediately write it back out to clear
  1448. * those interrupts.
  1449. */
  1450. dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
  1451. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
  1452. /* Check for Type 0 error interrupts */
  1453. if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
  1454. PI_TYPE_0_STAT_M_PM_PAR_ERR |
  1455. PI_TYPE_0_STAT_M_BUS_PAR_ERR))
  1456. {
  1457. /* Check for Non-Existent Memory error */
  1458. if (type_0_status & PI_TYPE_0_STAT_M_NXM)
  1459. printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
  1460. /* Check for Packet Memory Parity error */
  1461. if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
  1462. printk("%s: Packet Memory Parity Error\n", bp->dev->name);
  1463. /* Check for Host Bus Parity error */
  1464. if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
  1465. printk("%s: Host Bus Parity Error\n", bp->dev->name);
  1466. /* Reset adapter and bring it back on-line */
  1467. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1468. bp->reset_type = 0; /* rerun on-board diagnostics */
  1469. printk("%s: Resetting adapter...\n", bp->dev->name);
  1470. if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  1471. {
  1472. printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
  1473. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1474. return;
  1475. }
  1476. printk("%s: Adapter reset successful!\n", bp->dev->name);
  1477. return;
  1478. }
  1479. /* Check for transmit flush interrupt */
  1480. if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
  1481. {
  1482. /* Flush any pending xmt's and acknowledge the flush interrupt */
  1483. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1484. dfx_xmt_flush(bp); /* flush any outstanding packets */
  1485. (void) dfx_hw_port_ctrl_req(bp,
  1486. PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
  1487. 0,
  1488. 0,
  1489. NULL);
  1490. }
  1491. /* Check for adapter state change */
  1492. if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
  1493. {
  1494. /* Get latest adapter state */
  1495. state = dfx_hw_adap_state_rd(bp); /* get adapter state */
  1496. if (state == PI_STATE_K_HALTED)
  1497. {
  1498. /*
  1499. * Adapter has transitioned to HALTED state, try to reset
  1500. * adapter to bring it back on-line. If reset fails,
  1501. * leave the adapter in the broken state.
  1502. */
  1503. printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
  1504. dfx_int_pr_halt_id(bp); /* display halt id as string */
  1505. /* Reset adapter and bring it back on-line */
  1506. bp->link_available = PI_K_FALSE; /* link is no longer available */
  1507. bp->reset_type = 0; /* rerun on-board diagnostics */
  1508. printk("%s: Resetting adapter...\n", bp->dev->name);
  1509. if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
  1510. {
  1511. printk("%s: Adapter reset failed! Disabling adapter interrupts.\n", bp->dev->name);
  1512. dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
  1513. return;
  1514. }
  1515. printk("%s: Adapter reset successful!\n", bp->dev->name);
  1516. }
  1517. else if (state == PI_STATE_K_LINK_AVAIL)
  1518. {
  1519. bp->link_available = PI_K_TRUE; /* set link available flag */
  1520. }
  1521. }
  1522. }
  1523. /*
  1524. * ==================
  1525. * = dfx_int_common =
  1526. * ==================
  1527. *
  1528. * Overview:
  1529. * Interrupt service routine (ISR)
  1530. *
  1531. * Returns:
  1532. * None
  1533. *
  1534. * Arguments:
  1535. * bp - pointer to board information
  1536. *
  1537. * Functional Description:
  1538. * This is the ISR which processes incoming adapter interrupts.
  1539. *
  1540. * Return Codes:
  1541. * None
  1542. *
  1543. * Assumptions:
  1544. * This routine assumes PDQ interrupts have not been disabled.
  1545. * When interrupts are disabled at the PDQ, the Port Status register
  1546. * is automatically cleared. This routine uses the Port Status
  1547. * register value to determine whether a Type 0 interrupt occurred,
  1548. * so it's important that adapter interrupts are not normally
  1549. * enabled/disabled at the PDQ.
  1550. *
  1551. * It's vital that this routine is NOT reentered for the
  1552. * same board and that the OS is not in another section of
  1553. * code (eg. dfx_xmt_queue_pkt) for the same board on a
  1554. * different thread.
  1555. *
  1556. * Side Effects:
  1557. * Pending interrupts are serviced. Depending on the type of
  1558. * interrupt, acknowledging and clearing the interrupt at the
  1559. * PDQ involves writing a register to clear the interrupt bit
  1560. * or updating completion indices.
  1561. */
  1562. static void dfx_int_common(struct net_device *dev)
  1563. {
  1564. DFX_board_t *bp = netdev_priv(dev);
  1565. PI_UINT32 port_status; /* Port Status register */
  1566. /* Process xmt interrupts - frequent case, so always call this routine */
  1567. if(dfx_xmt_done(bp)) /* free consumed xmt packets */
  1568. netif_wake_queue(dev);
  1569. /* Process rcv interrupts - frequent case, so always call this routine */
  1570. dfx_rcv_queue_process(bp); /* service received LLC frames */
  1571. /*
  1572. * Transmit and receive producer and completion indices are updated on the
  1573. * adapter by writing to the Type 2 Producer register. Since the frequent
  1574. * case is that we'll be processing either LLC transmit or receive buffers,
  1575. * we'll optimize I/O writes by doing a single register write here.
  1576. */
  1577. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  1578. /* Read PDQ Port Status register to find out which interrupts need processing */
  1579. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  1580. /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
  1581. if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
  1582. dfx_int_type_0_process(bp); /* process Type 0 interrupts */
  1583. }
  1584. /*
  1585. * =================
  1586. * = dfx_interrupt =
  1587. * =================
  1588. *
  1589. * Overview:
  1590. * Interrupt processing routine
  1591. *
  1592. * Returns:
  1593. * Whether a valid interrupt was seen.
  1594. *
  1595. * Arguments:
  1596. * irq - interrupt vector
  1597. * dev_id - pointer to device information
  1598. *
  1599. * Functional Description:
  1600. * This routine calls the interrupt processing routine for this adapter. It
  1601. * disables and reenables adapter interrupts, as appropriate. We can support
  1602. * shared interrupts since the incoming dev_id pointer provides our device
  1603. * structure context.
  1604. *
  1605. * Return Codes:
  1606. * IRQ_HANDLED - an IRQ was handled.
  1607. * IRQ_NONE - no IRQ was handled.
  1608. *
  1609. * Assumptions:
  1610. * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
  1611. * on Intel-based systems) is done by the operating system outside this
  1612. * routine.
  1613. *
  1614. * System interrupts are enabled through this call.
  1615. *
  1616. * Side Effects:
  1617. * Interrupts are disabled, then reenabled at the adapter.
  1618. */
  1619. static irqreturn_t dfx_interrupt(int irq, void *dev_id)
  1620. {
  1621. struct net_device *dev = dev_id;
  1622. DFX_board_t *bp = netdev_priv(dev);
  1623. struct device *bdev = bp->bus_dev;
  1624. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  1625. int dfx_bus_eisa = DFX_BUS_EISA(bdev);
  1626. int dfx_bus_tc = DFX_BUS_TC(bdev);
  1627. /* Service adapter interrupts */
  1628. if (dfx_bus_pci) {
  1629. u32 status;
  1630. dfx_port_read_long(bp, PFI_K_REG_STATUS, &status);
  1631. if (!(status & PFI_STATUS_M_PDQ_INT))
  1632. return IRQ_NONE;
  1633. spin_lock(&bp->lock);
  1634. /* Disable PDQ-PFI interrupts at PFI */
  1635. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
  1636. PFI_MODE_M_DMA_ENB);
  1637. /* Call interrupt service routine for this adapter */
  1638. dfx_int_common(dev);
  1639. /* Clear PDQ interrupt status bit and reenable interrupts */
  1640. dfx_port_write_long(bp, PFI_K_REG_STATUS,
  1641. PFI_STATUS_M_PDQ_INT);
  1642. dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
  1643. (PFI_MODE_M_PDQ_INT_ENB |
  1644. PFI_MODE_M_DMA_ENB));
  1645. spin_unlock(&bp->lock);
  1646. }
  1647. if (dfx_bus_eisa) {
  1648. unsigned long base_addr = to_eisa_device(bdev)->base_addr;
  1649. u8 status;
  1650. status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1651. if (!(status & PI_CONFIG_STAT_0_M_PEND))
  1652. return IRQ_NONE;
  1653. spin_lock(&bp->lock);
  1654. /* Disable interrupts at the ESIC */
  1655. status &= ~PI_CONFIG_STAT_0_M_INT_ENB;
  1656. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
  1657. /* Call interrupt service routine for this adapter */
  1658. dfx_int_common(dev);
  1659. /* Reenable interrupts at the ESIC */
  1660. status = inb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0);
  1661. status |= PI_CONFIG_STAT_0_M_INT_ENB;
  1662. outb(base_addr + PI_ESIC_K_IO_CONFIG_STAT_0, status);
  1663. spin_unlock(&bp->lock);
  1664. }
  1665. if (dfx_bus_tc) {
  1666. u32 status;
  1667. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &status);
  1668. if (!(status & (PI_PSTATUS_M_RCV_DATA_PENDING |
  1669. PI_PSTATUS_M_XMT_DATA_PENDING |
  1670. PI_PSTATUS_M_SMT_HOST_PENDING |
  1671. PI_PSTATUS_M_UNSOL_PENDING |
  1672. PI_PSTATUS_M_CMD_RSP_PENDING |
  1673. PI_PSTATUS_M_CMD_REQ_PENDING |
  1674. PI_PSTATUS_M_TYPE_0_PENDING)))
  1675. return IRQ_NONE;
  1676. spin_lock(&bp->lock);
  1677. /* Call interrupt service routine for this adapter */
  1678. dfx_int_common(dev);
  1679. spin_unlock(&bp->lock);
  1680. }
  1681. return IRQ_HANDLED;
  1682. }
  1683. /*
  1684. * =====================
  1685. * = dfx_ctl_get_stats =
  1686. * =====================
  1687. *
  1688. * Overview:
  1689. * Get statistics for FDDI adapter
  1690. *
  1691. * Returns:
  1692. * Pointer to FDDI statistics structure
  1693. *
  1694. * Arguments:
  1695. * dev - pointer to device information
  1696. *
  1697. * Functional Description:
  1698. * Gets current MIB objects from adapter, then
  1699. * returns FDDI statistics structure as defined
  1700. * in if_fddi.h.
  1701. *
  1702. * Note: Since the FDDI statistics structure is
  1703. * still new and the device structure doesn't
  1704. * have an FDDI-specific get statistics handler,
  1705. * we'll return the FDDI statistics structure as
  1706. * a pointer to an Ethernet statistics structure.
  1707. * That way, at least the first part of the statistics
  1708. * structure can be decoded properly, and it allows
  1709. * "smart" applications to perform a second cast to
  1710. * decode the FDDI-specific statistics.
  1711. *
  1712. * We'll have to pay attention to this routine as the
  1713. * device structure becomes more mature and LAN media
  1714. * independent.
  1715. *
  1716. * Return Codes:
  1717. * None
  1718. *
  1719. * Assumptions:
  1720. * None
  1721. *
  1722. * Side Effects:
  1723. * None
  1724. */
  1725. static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
  1726. {
  1727. DFX_board_t *bp = netdev_priv(dev);
  1728. /* Fill the bp->stats structure with driver-maintained counters */
  1729. bp->stats.gen.rx_packets = bp->rcv_total_frames;
  1730. bp->stats.gen.tx_packets = bp->xmt_total_frames;
  1731. bp->stats.gen.rx_bytes = bp->rcv_total_bytes;
  1732. bp->stats.gen.tx_bytes = bp->xmt_total_bytes;
  1733. bp->stats.gen.rx_errors = bp->rcv_crc_errors +
  1734. bp->rcv_frame_status_errors +
  1735. bp->rcv_length_errors;
  1736. bp->stats.gen.tx_errors = bp->xmt_length_errors;
  1737. bp->stats.gen.rx_dropped = bp->rcv_discards;
  1738. bp->stats.gen.tx_dropped = bp->xmt_discards;
  1739. bp->stats.gen.multicast = bp->rcv_multicast_frames;
  1740. bp->stats.gen.collisions = 0; /* always zero (0) for FDDI */
  1741. /* Get FDDI SMT MIB objects */
  1742. bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
  1743. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1744. return((struct net_device_stats *) &bp->stats);
  1745. /* Fill the bp->stats structure with the SMT MIB object values */
  1746. memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
  1747. bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
  1748. bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
  1749. bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
  1750. memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
  1751. bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
  1752. bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
  1753. bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
  1754. bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
  1755. bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
  1756. bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
  1757. bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
  1758. bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
  1759. bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
  1760. bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
  1761. bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
  1762. bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
  1763. bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
  1764. bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
  1765. bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
  1766. bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
  1767. bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
  1768. bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
  1769. bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
  1770. bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
  1771. bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
  1772. bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
  1773. bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
  1774. bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
  1775. memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
  1776. memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
  1777. memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
  1778. memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
  1779. bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
  1780. bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
  1781. bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
  1782. memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
  1783. bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
  1784. bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
  1785. bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
  1786. bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
  1787. bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
  1788. bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
  1789. bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
  1790. bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
  1791. bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
  1792. bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
  1793. bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
  1794. bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
  1795. bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
  1796. bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
  1797. bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
  1798. bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
  1799. memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
  1800. bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
  1801. bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
  1802. bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
  1803. bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
  1804. bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
  1805. bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
  1806. bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
  1807. bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
  1808. bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
  1809. bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
  1810. memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
  1811. memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
  1812. bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
  1813. bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
  1814. bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
  1815. bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
  1816. bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
  1817. bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
  1818. bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
  1819. bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
  1820. bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
  1821. bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
  1822. bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
  1823. bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
  1824. bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
  1825. bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
  1826. bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
  1827. bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
  1828. bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
  1829. bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
  1830. bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
  1831. bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
  1832. bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
  1833. bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
  1834. bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
  1835. bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
  1836. bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
  1837. bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
  1838. /* Get FDDI counters */
  1839. bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
  1840. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  1841. return((struct net_device_stats *) &bp->stats);
  1842. /* Fill the bp->stats structure with the FDDI counter values */
  1843. bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
  1844. bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
  1845. bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
  1846. bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
  1847. bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
  1848. bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
  1849. bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
  1850. bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
  1851. bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
  1852. bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
  1853. bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
  1854. return((struct net_device_stats *) &bp->stats);
  1855. }
  1856. /*
  1857. * ==============================
  1858. * = dfx_ctl_set_multicast_list =
  1859. * ==============================
  1860. *
  1861. * Overview:
  1862. * Enable/Disable LLC frame promiscuous mode reception
  1863. * on the adapter and/or update multicast address table.
  1864. *
  1865. * Returns:
  1866. * None
  1867. *
  1868. * Arguments:
  1869. * dev - pointer to device information
  1870. *
  1871. * Functional Description:
  1872. * This routine follows a fairly simple algorithm for setting the
  1873. * adapter filters and CAM:
  1874. *
  1875. * if IFF_PROMISC flag is set
  1876. * enable LLC individual/group promiscuous mode
  1877. * else
  1878. * disable LLC individual/group promiscuous mode
  1879. * if number of incoming multicast addresses >
  1880. * (CAM max size - number of unicast addresses in CAM)
  1881. * enable LLC group promiscuous mode
  1882. * set driver-maintained multicast address count to zero
  1883. * else
  1884. * disable LLC group promiscuous mode
  1885. * set driver-maintained multicast address count to incoming count
  1886. * update adapter CAM
  1887. * update adapter filters
  1888. *
  1889. * Return Codes:
  1890. * None
  1891. *
  1892. * Assumptions:
  1893. * Multicast addresses are presented in canonical (LSB) format.
  1894. *
  1895. * Side Effects:
  1896. * On-board adapter CAM and filters are updated.
  1897. */
  1898. static void dfx_ctl_set_multicast_list(struct net_device *dev)
  1899. {
  1900. DFX_board_t *bp = netdev_priv(dev);
  1901. int i; /* used as index in for loop */
  1902. struct dev_mc_list *dmi; /* ptr to multicast addr entry */
  1903. /* Enable LLC frame promiscuous mode, if necessary */
  1904. if (dev->flags & IFF_PROMISC)
  1905. bp->ind_group_prom = PI_FSTATE_K_PASS; /* Enable LLC ind/group prom mode */
  1906. /* Else, update multicast address table */
  1907. else
  1908. {
  1909. bp->ind_group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC ind/group prom mode */
  1910. /*
  1911. * Check whether incoming multicast address count exceeds table size
  1912. *
  1913. * Note: The adapters utilize an on-board 64 entry CAM for
  1914. * supporting perfect filtering of multicast packets
  1915. * and bridge functions when adding unicast addresses.
  1916. * There is no hash function available. To support
  1917. * additional multicast addresses, the all multicast
  1918. * filter (LLC group promiscuous mode) must be enabled.
  1919. *
  1920. * The firmware reserves two CAM entries for SMT-related
  1921. * multicast addresses, which leaves 62 entries available.
  1922. * The following code ensures that we're not being asked
  1923. * to add more than 62 addresses to the CAM. If we are,
  1924. * the driver will enable the all multicast filter.
  1925. * Should the number of multicast addresses drop below
  1926. * the high water mark, the filter will be disabled and
  1927. * perfect filtering will be used.
  1928. */
  1929. if (dev->mc_count > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
  1930. {
  1931. bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
  1932. bp->mc_count = 0; /* Don't add mc addrs to CAM */
  1933. }
  1934. else
  1935. {
  1936. bp->group_prom = PI_FSTATE_K_BLOCK; /* Disable LLC group prom mode */
  1937. bp->mc_count = dev->mc_count; /* Add mc addrs to CAM */
  1938. }
  1939. /* Copy addresses to multicast address table, then update adapter CAM */
  1940. dmi = dev->mc_list; /* point to first multicast addr */
  1941. for (i=0; i < bp->mc_count; i++)
  1942. {
  1943. memcpy(&bp->mc_table[i*FDDI_K_ALEN], dmi->dmi_addr, FDDI_K_ALEN);
  1944. dmi = dmi->next; /* point to next multicast addr */
  1945. }
  1946. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  1947. {
  1948. DBG_printk("%s: Could not update multicast address table!\n", dev->name);
  1949. }
  1950. else
  1951. {
  1952. DBG_printk("%s: Multicast address table updated! Added %d addresses.\n", dev->name, bp->mc_count);
  1953. }
  1954. }
  1955. /* Update adapter filters */
  1956. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  1957. {
  1958. DBG_printk("%s: Could not update adapter filters!\n", dev->name);
  1959. }
  1960. else
  1961. {
  1962. DBG_printk("%s: Adapter filters updated!\n", dev->name);
  1963. }
  1964. }
  1965. /*
  1966. * ===========================
  1967. * = dfx_ctl_set_mac_address =
  1968. * ===========================
  1969. *
  1970. * Overview:
  1971. * Add node address override (unicast address) to adapter
  1972. * CAM and update dev_addr field in device table.
  1973. *
  1974. * Returns:
  1975. * None
  1976. *
  1977. * Arguments:
  1978. * dev - pointer to device information
  1979. * addr - pointer to sockaddr structure containing unicast address to add
  1980. *
  1981. * Functional Description:
  1982. * The adapter supports node address overrides by adding one or more
  1983. * unicast addresses to the adapter CAM. This is similar to adding
  1984. * multicast addresses. In this routine we'll update the driver and
  1985. * device structures with the new address, then update the adapter CAM
  1986. * to ensure that the adapter will copy and strip frames destined and
  1987. * sourced by that address.
  1988. *
  1989. * Return Codes:
  1990. * Always returns zero.
  1991. *
  1992. * Assumptions:
  1993. * The address pointed to by addr->sa_data is a valid unicast
  1994. * address and is presented in canonical (LSB) format.
  1995. *
  1996. * Side Effects:
  1997. * On-board adapter CAM is updated. On-board adapter filters
  1998. * may be updated.
  1999. */
  2000. static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
  2001. {
  2002. struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
  2003. DFX_board_t *bp = netdev_priv(dev);
  2004. /* Copy unicast address to driver-maintained structs and update count */
  2005. memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN); /* update device struct */
  2006. memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN); /* update driver struct */
  2007. bp->uc_count = 1;
  2008. /*
  2009. * Verify we're not exceeding the CAM size by adding unicast address
  2010. *
  2011. * Note: It's possible that before entering this routine we've
  2012. * already filled the CAM with 62 multicast addresses.
  2013. * Since we need to place the node address override into
  2014. * the CAM, we have to check to see that we're not
  2015. * exceeding the CAM size. If we are, we have to enable
  2016. * the LLC group (multicast) promiscuous mode filter as
  2017. * in dfx_ctl_set_multicast_list.
  2018. */
  2019. if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
  2020. {
  2021. bp->group_prom = PI_FSTATE_K_PASS; /* Enable LLC group prom mode */
  2022. bp->mc_count = 0; /* Don't add mc addrs to CAM */
  2023. /* Update adapter filters */
  2024. if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
  2025. {
  2026. DBG_printk("%s: Could not update adapter filters!\n", dev->name);
  2027. }
  2028. else
  2029. {
  2030. DBG_printk("%s: Adapter filters updated!\n", dev->name);
  2031. }
  2032. }
  2033. /* Update adapter CAM with new unicast address */
  2034. if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
  2035. {
  2036. DBG_printk("%s: Could not set new MAC address!\n", dev->name);
  2037. }
  2038. else
  2039. {
  2040. DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
  2041. }
  2042. return(0); /* always return zero */
  2043. }
  2044. /*
  2045. * ======================
  2046. * = dfx_ctl_update_cam =
  2047. * ======================
  2048. *
  2049. * Overview:
  2050. * Procedure to update adapter CAM (Content Addressable Memory)
  2051. * with desired unicast and multicast address entries.
  2052. *
  2053. * Returns:
  2054. * Condition code
  2055. *
  2056. * Arguments:
  2057. * bp - pointer to board information
  2058. *
  2059. * Functional Description:
  2060. * Updates adapter CAM with current contents of board structure
  2061. * unicast and multicast address tables. Since there are only 62
  2062. * free entries in CAM, this routine ensures that the command
  2063. * request buffer is not overrun.
  2064. *
  2065. * Return Codes:
  2066. * DFX_K_SUCCESS - Request succeeded
  2067. * DFX_K_FAILURE - Request failed
  2068. *
  2069. * Assumptions:
  2070. * All addresses being added (unicast and multicast) are in canonical
  2071. * order.
  2072. *
  2073. * Side Effects:
  2074. * On-board adapter CAM is updated.
  2075. */
  2076. static int dfx_ctl_update_cam(DFX_board_t *bp)
  2077. {
  2078. int i; /* used as index */
  2079. PI_LAN_ADDR *p_addr; /* pointer to CAM entry */
  2080. /*
  2081. * Fill in command request information
  2082. *
  2083. * Note: Even though both the unicast and multicast address
  2084. * table entries are stored as contiguous 6 byte entries,
  2085. * the firmware address filter set command expects each
  2086. * entry to be two longwords (8 bytes total). We must be
  2087. * careful to only copy the six bytes of each unicast and
  2088. * multicast table entry into each command entry. This
  2089. * is also why we must first clear the entire command
  2090. * request buffer.
  2091. */
  2092. memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX); /* first clear buffer */
  2093. bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
  2094. p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
  2095. /* Now add unicast addresses to command request buffer, if any */
  2096. for (i=0; i < (int)bp->uc_count; i++)
  2097. {
  2098. if (i < PI_CMD_ADDR_FILTER_K_SIZE)
  2099. {
  2100. memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  2101. p_addr++; /* point to next command entry */
  2102. }
  2103. }
  2104. /* Now add multicast addresses to command request buffer, if any */
  2105. for (i=0; i < (int)bp->mc_count; i++)
  2106. {
  2107. if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
  2108. {
  2109. memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
  2110. p_addr++; /* point to next command entry */
  2111. }
  2112. }
  2113. /* Issue command to update adapter CAM, then return */
  2114. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  2115. return(DFX_K_FAILURE);
  2116. return(DFX_K_SUCCESS);
  2117. }
  2118. /*
  2119. * ==========================
  2120. * = dfx_ctl_update_filters =
  2121. * ==========================
  2122. *
  2123. * Overview:
  2124. * Procedure to update adapter filters with desired
  2125. * filter settings.
  2126. *
  2127. * Returns:
  2128. * Condition code
  2129. *
  2130. * Arguments:
  2131. * bp - pointer to board information
  2132. *
  2133. * Functional Description:
  2134. * Enables or disables filter using current filter settings.
  2135. *
  2136. * Return Codes:
  2137. * DFX_K_SUCCESS - Request succeeded.
  2138. * DFX_K_FAILURE - Request failed.
  2139. *
  2140. * Assumptions:
  2141. * We must always pass up packets destined to the broadcast
  2142. * address (FF-FF-FF-FF-FF-FF), so we'll always keep the
  2143. * broadcast filter enabled.
  2144. *
  2145. * Side Effects:
  2146. * On-board adapter filters are updated.
  2147. */
  2148. static int dfx_ctl_update_filters(DFX_board_t *bp)
  2149. {
  2150. int i = 0; /* used as index */
  2151. /* Fill in command request information */
  2152. bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
  2153. /* Initialize Broadcast filter - * ALWAYS ENABLED * */
  2154. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_BROADCAST;
  2155. bp->cmd_req_virt->filter_set.item[i++].value = PI_FSTATE_K_PASS;
  2156. /* Initialize LLC Individual/Group Promiscuous filter */
  2157. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_IND_GROUP_PROM;
  2158. bp->cmd_req_virt->filter_set.item[i++].value = bp->ind_group_prom;
  2159. /* Initialize LLC Group Promiscuous filter */
  2160. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_GROUP_PROM;
  2161. bp->cmd_req_virt->filter_set.item[i++].value = bp->group_prom;
  2162. /* Terminate the item code list */
  2163. bp->cmd_req_virt->filter_set.item[i].item_code = PI_ITEM_K_EOL;
  2164. /* Issue command to update adapter filters, then return */
  2165. if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
  2166. return(DFX_K_FAILURE);
  2167. return(DFX_K_SUCCESS);
  2168. }
  2169. /*
  2170. * ======================
  2171. * = dfx_hw_dma_cmd_req =
  2172. * ======================
  2173. *
  2174. * Overview:
  2175. * Sends PDQ DMA command to adapter firmware
  2176. *
  2177. * Returns:
  2178. * Condition code
  2179. *
  2180. * Arguments:
  2181. * bp - pointer to board information
  2182. *
  2183. * Functional Description:
  2184. * The command request and response buffers are posted to the adapter in the manner
  2185. * described in the PDQ Port Specification:
  2186. *
  2187. * 1. Command Response Buffer is posted to adapter.
  2188. * 2. Command Request Buffer is posted to adapter.
  2189. * 3. Command Request consumer index is polled until it indicates that request
  2190. * buffer has been DMA'd to adapter.
  2191. * 4. Command Response consumer index is polled until it indicates that response
  2192. * buffer has been DMA'd from adapter.
  2193. *
  2194. * This ordering ensures that a response buffer is already available for the firmware
  2195. * to use once it's done processing the request buffer.
  2196. *
  2197. * Return Codes:
  2198. * DFX_K_SUCCESS - DMA command succeeded
  2199. * DFX_K_OUTSTATE - Adapter is NOT in proper state
  2200. * DFX_K_HW_TIMEOUT - DMA command timed out
  2201. *
  2202. * Assumptions:
  2203. * Command request buffer has already been filled with desired DMA command.
  2204. *
  2205. * Side Effects:
  2206. * None
  2207. */
  2208. static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
  2209. {
  2210. int status; /* adapter status */
  2211. int timeout_cnt; /* used in for loops */
  2212. /* Make sure the adapter is in a state that we can issue the DMA command in */
  2213. status = dfx_hw_adap_state_rd(bp);
  2214. if ((status == PI_STATE_K_RESET) ||
  2215. (status == PI_STATE_K_HALTED) ||
  2216. (status == PI_STATE_K_DMA_UNAVAIL) ||
  2217. (status == PI_STATE_K_UPGRADE))
  2218. return(DFX_K_OUTSTATE);
  2219. /* Put response buffer on the command response queue */
  2220. bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  2221. ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  2222. bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
  2223. /* Bump (and wrap) the producer index and write out to register */
  2224. bp->cmd_rsp_reg.index.prod += 1;
  2225. bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  2226. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
  2227. /* Put request buffer on the command request queue */
  2228. bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
  2229. PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
  2230. bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
  2231. /* Bump (and wrap) the producer index and write out to register */
  2232. bp->cmd_req_reg.index.prod += 1;
  2233. bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  2234. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  2235. /*
  2236. * Here we wait for the command request consumer index to be equal
  2237. * to the producer, indicating that the adapter has DMAed the request.
  2238. */
  2239. for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  2240. {
  2241. if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
  2242. break;
  2243. udelay(100); /* wait for 100 microseconds */
  2244. }
  2245. if (timeout_cnt == 0)
  2246. return(DFX_K_HW_TIMEOUT);
  2247. /* Bump (and wrap) the completion index and write out to register */
  2248. bp->cmd_req_reg.index.comp += 1;
  2249. bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
  2250. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
  2251. /*
  2252. * Here we wait for the command response consumer index to be equal
  2253. * to the producer, indicating that the adapter has DMAed the response.
  2254. */
  2255. for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
  2256. {
  2257. if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
  2258. break;
  2259. udelay(100); /* wait for 100 microseconds */
  2260. }
  2261. if (timeout_cnt == 0)
  2262. return(DFX_K_HW_TIMEOUT);
  2263. /* Bump (and wrap) the completion index and write out to register */
  2264. bp->cmd_rsp_reg.index.comp += 1;
  2265. bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
  2266. dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
  2267. return(DFX_K_SUCCESS);
  2268. }
  2269. /*
  2270. * ========================
  2271. * = dfx_hw_port_ctrl_req =
  2272. * ========================
  2273. *
  2274. * Overview:
  2275. * Sends PDQ port control command to adapter firmware
  2276. *
  2277. * Returns:
  2278. * Host data register value in host_data if ptr is not NULL
  2279. *
  2280. * Arguments:
  2281. * bp - pointer to board information
  2282. * command - port control command
  2283. * data_a - port data A register value
  2284. * data_b - port data B register value
  2285. * host_data - ptr to host data register value
  2286. *
  2287. * Functional Description:
  2288. * Send generic port control command to adapter by writing
  2289. * to various PDQ port registers, then polling for completion.
  2290. *
  2291. * Return Codes:
  2292. * DFX_K_SUCCESS - port control command succeeded
  2293. * DFX_K_HW_TIMEOUT - port control command timed out
  2294. *
  2295. * Assumptions:
  2296. * None
  2297. *
  2298. * Side Effects:
  2299. * None
  2300. */
  2301. static int dfx_hw_port_ctrl_req(
  2302. DFX_board_t *bp,
  2303. PI_UINT32 command,
  2304. PI_UINT32 data_a,
  2305. PI_UINT32 data_b,
  2306. PI_UINT32 *host_data
  2307. )
  2308. {
  2309. PI_UINT32 port_cmd; /* Port Control command register value */
  2310. int timeout_cnt; /* used in for loops */
  2311. /* Set Command Error bit in command longword */
  2312. port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
  2313. /* Issue port command to the adapter */
  2314. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
  2315. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
  2316. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
  2317. /* Now wait for command to complete */
  2318. if (command == PI_PCTRL_M_BLAST_FLASH)
  2319. timeout_cnt = 600000; /* set command timeout count to 60 seconds */
  2320. else
  2321. timeout_cnt = 20000; /* set command timeout count to 2 seconds */
  2322. for (; timeout_cnt > 0; timeout_cnt--)
  2323. {
  2324. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
  2325. if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
  2326. break;
  2327. udelay(100); /* wait for 100 microseconds */
  2328. }
  2329. if (timeout_cnt == 0)
  2330. return(DFX_K_HW_TIMEOUT);
  2331. /*
  2332. * If the address of host_data is non-zero, assume caller has supplied a
  2333. * non NULL pointer, and return the contents of the HOST_DATA register in
  2334. * it.
  2335. */
  2336. if (host_data != NULL)
  2337. dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
  2338. return(DFX_K_SUCCESS);
  2339. }
  2340. /*
  2341. * =====================
  2342. * = dfx_hw_adap_reset =
  2343. * =====================
  2344. *
  2345. * Overview:
  2346. * Resets adapter
  2347. *
  2348. * Returns:
  2349. * None
  2350. *
  2351. * Arguments:
  2352. * bp - pointer to board information
  2353. * type - type of reset to perform
  2354. *
  2355. * Functional Description:
  2356. * Issue soft reset to adapter by writing to PDQ Port Reset
  2357. * register. Use incoming reset type to tell adapter what
  2358. * kind of reset operation to perform.
  2359. *
  2360. * Return Codes:
  2361. * None
  2362. *
  2363. * Assumptions:
  2364. * This routine merely issues a soft reset to the adapter.
  2365. * It is expected that after this routine returns, the caller
  2366. * will appropriately poll the Port Status register for the
  2367. * adapter to enter the proper state.
  2368. *
  2369. * Side Effects:
  2370. * Internal adapter registers are cleared.
  2371. */
  2372. static void dfx_hw_adap_reset(
  2373. DFX_board_t *bp,
  2374. PI_UINT32 type
  2375. )
  2376. {
  2377. /* Set Reset type and assert reset */
  2378. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type); /* tell adapter type of reset */
  2379. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
  2380. /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
  2381. udelay(20);
  2382. /* Deassert reset */
  2383. dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
  2384. }
  2385. /*
  2386. * ========================
  2387. * = dfx_hw_adap_state_rd =
  2388. * ========================
  2389. *
  2390. * Overview:
  2391. * Returns current adapter state
  2392. *
  2393. * Returns:
  2394. * Adapter state per PDQ Port Specification
  2395. *
  2396. * Arguments:
  2397. * bp - pointer to board information
  2398. *
  2399. * Functional Description:
  2400. * Reads PDQ Port Status register and returns adapter state.
  2401. *
  2402. * Return Codes:
  2403. * None
  2404. *
  2405. * Assumptions:
  2406. * None
  2407. *
  2408. * Side Effects:
  2409. * None
  2410. */
  2411. static int dfx_hw_adap_state_rd(DFX_board_t *bp)
  2412. {
  2413. PI_UINT32 port_status; /* Port Status register value */
  2414. dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
  2415. return((port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE);
  2416. }
  2417. /*
  2418. * =====================
  2419. * = dfx_hw_dma_uninit =
  2420. * =====================
  2421. *
  2422. * Overview:
  2423. * Brings adapter to DMA_UNAVAILABLE state
  2424. *
  2425. * Returns:
  2426. * Condition code
  2427. *
  2428. * Arguments:
  2429. * bp - pointer to board information
  2430. * type - type of reset to perform
  2431. *
  2432. * Functional Description:
  2433. * Bring adapter to DMA_UNAVAILABLE state by performing the following:
  2434. * 1. Set reset type bit in Port Data A Register then reset adapter.
  2435. * 2. Check that adapter is in DMA_UNAVAILABLE state.
  2436. *
  2437. * Return Codes:
  2438. * DFX_K_SUCCESS - adapter is in DMA_UNAVAILABLE state
  2439. * DFX_K_HW_TIMEOUT - adapter did not reset properly
  2440. *
  2441. * Assumptions:
  2442. * None
  2443. *
  2444. * Side Effects:
  2445. * Internal adapter registers are cleared.
  2446. */
  2447. static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
  2448. {
  2449. int timeout_cnt; /* used in for loops */
  2450. /* Set reset type bit and reset adapter */
  2451. dfx_hw_adap_reset(bp, type);
  2452. /* Now wait for adapter to enter DMA_UNAVAILABLE state */
  2453. for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
  2454. {
  2455. if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
  2456. break;
  2457. udelay(100); /* wait for 100 microseconds */
  2458. }
  2459. if (timeout_cnt == 0)
  2460. return(DFX_K_HW_TIMEOUT);
  2461. return(DFX_K_SUCCESS);
  2462. }
  2463. /*
  2464. * Align an sk_buff to a boundary power of 2
  2465. *
  2466. */
  2467. static void my_skb_align(struct sk_buff *skb, int n)
  2468. {
  2469. unsigned long x = (unsigned long)skb->data;
  2470. unsigned long v;
  2471. v = ALIGN(x, n); /* Where we want to be */
  2472. skb_reserve(skb, v - x);
  2473. }
  2474. /*
  2475. * ================
  2476. * = dfx_rcv_init =
  2477. * ================
  2478. *
  2479. * Overview:
  2480. * Produces buffers to adapter LLC Host receive descriptor block
  2481. *
  2482. * Returns:
  2483. * None
  2484. *
  2485. * Arguments:
  2486. * bp - pointer to board information
  2487. * get_buffers - non-zero if buffers to be allocated
  2488. *
  2489. * Functional Description:
  2490. * This routine can be called during dfx_adap_init() or during an adapter
  2491. * reset. It initializes the descriptor block and produces all allocated
  2492. * LLC Host queue receive buffers.
  2493. *
  2494. * Return Codes:
  2495. * Return 0 on success or -ENOMEM if buffer allocation failed (when using
  2496. * dynamic buffer allocation). If the buffer allocation failed, the
  2497. * already allocated buffers will not be released and the caller should do
  2498. * this.
  2499. *
  2500. * Assumptions:
  2501. * The PDQ has been reset and the adapter and driver maintained Type 2
  2502. * register indices are cleared.
  2503. *
  2504. * Side Effects:
  2505. * Receive buffers are posted to the adapter LLC queue and the adapter
  2506. * is notified.
  2507. */
  2508. static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
  2509. {
  2510. int i, j; /* used in for loop */
  2511. /*
  2512. * Since each receive buffer is a single fragment of same length, initialize
  2513. * first longword in each receive descriptor for entire LLC Host descriptor
  2514. * block. Also initialize second longword in each receive descriptor with
  2515. * physical address of receive buffer. We'll always allocate receive
  2516. * buffers in powers of 2 so that we can easily fill the 256 entry descriptor
  2517. * block and produce new receive buffers by simply updating the receive
  2518. * producer index.
  2519. *
  2520. * Assumptions:
  2521. * To support all shipping versions of PDQ, the receive buffer size
  2522. * must be mod 128 in length and the physical address must be 128 byte
  2523. * aligned. In other words, bits 0-6 of the length and address must
  2524. * be zero for the following descriptor field entries to be correct on
  2525. * all PDQ-based boards. We guaranteed both requirements during
  2526. * driver initialization when we allocated memory for the receive buffers.
  2527. */
  2528. if (get_buffers) {
  2529. #ifdef DYNAMIC_BUFFERS
  2530. for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  2531. for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  2532. {
  2533. struct sk_buff *newskb = __netdev_alloc_skb(bp->dev, NEW_SKB_SIZE, GFP_NOIO);
  2534. if (!newskb)
  2535. return -ENOMEM;
  2536. bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  2537. ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  2538. /*
  2539. * align to 128 bytes for compatibility with
  2540. * the old EISA boards.
  2541. */
  2542. my_skb_align(newskb, 128);
  2543. bp->descr_block_virt->rcv_data[i + j].long_1 =
  2544. (u32)dma_map_single(bp->bus_dev, newskb->data,
  2545. NEW_SKB_SIZE,
  2546. DMA_FROM_DEVICE);
  2547. /*
  2548. * p_rcv_buff_va is only used inside the
  2549. * kernel so we put the skb pointer here.
  2550. */
  2551. bp->p_rcv_buff_va[i+j] = (char *) newskb;
  2552. }
  2553. #else
  2554. for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
  2555. for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  2556. {
  2557. bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
  2558. ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
  2559. bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
  2560. bp->p_rcv_buff_va[i+j] = (char *) (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
  2561. }
  2562. #endif
  2563. }
  2564. /* Update receive producer and Type 2 register */
  2565. bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
  2566. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  2567. return 0;
  2568. }
  2569. /*
  2570. * =========================
  2571. * = dfx_rcv_queue_process =
  2572. * =========================
  2573. *
  2574. * Overview:
  2575. * Process received LLC frames.
  2576. *
  2577. * Returns:
  2578. * None
  2579. *
  2580. * Arguments:
  2581. * bp - pointer to board information
  2582. *
  2583. * Functional Description:
  2584. * Received LLC frames are processed until there are no more consumed frames.
  2585. * Once all frames are processed, the receive buffers are returned to the
  2586. * adapter. Note that this algorithm fixes the length of time that can be spent
  2587. * in this routine, because there are a fixed number of receive buffers to
  2588. * process and buffers are not produced until this routine exits and returns
  2589. * to the ISR.
  2590. *
  2591. * Return Codes:
  2592. * None
  2593. *
  2594. * Assumptions:
  2595. * None
  2596. *
  2597. * Side Effects:
  2598. * None
  2599. */
  2600. static void dfx_rcv_queue_process(
  2601. DFX_board_t *bp
  2602. )
  2603. {
  2604. PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
  2605. char *p_buff; /* ptr to start of packet receive buffer (FMC descriptor) */
  2606. u32 descr, pkt_len; /* FMC descriptor field and packet length */
  2607. struct sk_buff *skb; /* pointer to a sk_buff to hold incoming packet data */
  2608. /* Service all consumed LLC receive frames */
  2609. p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  2610. while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
  2611. {
  2612. /* Process any errors */
  2613. int entry;
  2614. entry = bp->rcv_xmt_reg.index.rcv_comp;
  2615. #ifdef DYNAMIC_BUFFERS
  2616. p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
  2617. #else
  2618. p_buff = (char *) bp->p_rcv_buff_va[entry];
  2619. #endif
  2620. memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
  2621. if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
  2622. {
  2623. if (descr & PI_FMC_DESCR_M_RCC_CRC)
  2624. bp->rcv_crc_errors++;
  2625. else
  2626. bp->rcv_frame_status_errors++;
  2627. }
  2628. else
  2629. {
  2630. int rx_in_place = 0;
  2631. /* The frame was received without errors - verify packet length */
  2632. pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
  2633. pkt_len -= 4; /* subtract 4 byte CRC */
  2634. if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  2635. bp->rcv_length_errors++;
  2636. else{
  2637. #ifdef DYNAMIC_BUFFERS
  2638. if (pkt_len > SKBUFF_RX_COPYBREAK) {
  2639. struct sk_buff *newskb;
  2640. newskb = dev_alloc_skb(NEW_SKB_SIZE);
  2641. if (newskb){
  2642. rx_in_place = 1;
  2643. my_skb_align(newskb, 128);
  2644. skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
  2645. dma_unmap_single(bp->bus_dev,
  2646. bp->descr_block_virt->rcv_data[entry].long_1,
  2647. NEW_SKB_SIZE,
  2648. DMA_FROM_DEVICE);
  2649. skb_reserve(skb, RCV_BUFF_K_PADDING);
  2650. bp->p_rcv_buff_va[entry] = (char *)newskb;
  2651. bp->descr_block_virt->rcv_data[entry].long_1 =
  2652. (u32)dma_map_single(bp->bus_dev,
  2653. newskb->data,
  2654. NEW_SKB_SIZE,
  2655. DMA_FROM_DEVICE);
  2656. } else
  2657. skb = NULL;
  2658. } else
  2659. #endif
  2660. skb = dev_alloc_skb(pkt_len+3); /* alloc new buffer to pass up, add room for PRH */
  2661. if (skb == NULL)
  2662. {
  2663. printk("%s: Could not allocate receive buffer. Dropping packet.\n", bp->dev->name);
  2664. bp->rcv_discards++;
  2665. break;
  2666. }
  2667. else {
  2668. #ifndef DYNAMIC_BUFFERS
  2669. if (! rx_in_place)
  2670. #endif
  2671. {
  2672. /* Receive buffer allocated, pass receive packet up */
  2673. skb_copy_to_linear_data(skb,
  2674. p_buff + RCV_BUFF_K_PADDING,
  2675. pkt_len + 3);
  2676. }
  2677. skb_reserve(skb,3); /* adjust data field so that it points to FC byte */
  2678. skb_put(skb, pkt_len); /* pass up packet length, NOT including CRC */
  2679. skb->protocol = fddi_type_trans(skb, bp->dev);
  2680. bp->rcv_total_bytes += skb->len;
  2681. netif_rx(skb);
  2682. /* Update the rcv counters */
  2683. bp->rcv_total_frames++;
  2684. if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
  2685. bp->rcv_multicast_frames++;
  2686. }
  2687. }
  2688. }
  2689. /*
  2690. * Advance the producer (for recycling) and advance the completion
  2691. * (for servicing received frames). Note that it is okay to
  2692. * advance the producer without checking that it passes the
  2693. * completion index because they are both advanced at the same
  2694. * rate.
  2695. */
  2696. bp->rcv_xmt_reg.index.rcv_prod += 1;
  2697. bp->rcv_xmt_reg.index.rcv_comp += 1;
  2698. }
  2699. }
  2700. /*
  2701. * =====================
  2702. * = dfx_xmt_queue_pkt =
  2703. * =====================
  2704. *
  2705. * Overview:
  2706. * Queues packets for transmission
  2707. *
  2708. * Returns:
  2709. * Condition code
  2710. *
  2711. * Arguments:
  2712. * skb - pointer to sk_buff to queue for transmission
  2713. * dev - pointer to device information
  2714. *
  2715. * Functional Description:
  2716. * Here we assume that an incoming skb transmit request
  2717. * is contained in a single physically contiguous buffer
  2718. * in which the virtual address of the start of packet
  2719. * (skb->data) can be converted to a physical address
  2720. * by using pci_map_single().
  2721. *
  2722. * Since the adapter architecture requires a three byte
  2723. * packet request header to prepend the start of packet,
  2724. * we'll write the three byte field immediately prior to
  2725. * the FC byte. This assumption is valid because we've
  2726. * ensured that dev->hard_header_len includes three pad
  2727. * bytes. By posting a single fragment to the adapter,
  2728. * we'll reduce the number of descriptor fetches and
  2729. * bus traffic needed to send the request.
  2730. *
  2731. * Also, we can't free the skb until after it's been DMA'd
  2732. * out by the adapter, so we'll queue it in the driver and
  2733. * return it in dfx_xmt_done.
  2734. *
  2735. * Return Codes:
  2736. * 0 - driver queued packet, link is unavailable, or skbuff was bad
  2737. * 1 - caller should requeue the sk_buff for later transmission
  2738. *
  2739. * Assumptions:
  2740. * First and foremost, we assume the incoming skb pointer
  2741. * is NOT NULL and is pointing to a valid sk_buff structure.
  2742. *
  2743. * The outgoing packet is complete, starting with the
  2744. * frame control byte including the last byte of data,
  2745. * but NOT including the 4 byte CRC. We'll let the
  2746. * adapter hardware generate and append the CRC.
  2747. *
  2748. * The entire packet is stored in one physically
  2749. * contiguous buffer which is not cached and whose
  2750. * 32-bit physical address can be determined.
  2751. *
  2752. * It's vital that this routine is NOT reentered for the
  2753. * same board and that the OS is not in another section of
  2754. * code (eg. dfx_int_common) for the same board on a
  2755. * different thread.
  2756. *
  2757. * Side Effects:
  2758. * None
  2759. */
  2760. static int dfx_xmt_queue_pkt(
  2761. struct sk_buff *skb,
  2762. struct net_device *dev
  2763. )
  2764. {
  2765. DFX_board_t *bp = netdev_priv(dev);
  2766. u8 prod; /* local transmit producer index */
  2767. PI_XMT_DESCR *p_xmt_descr; /* ptr to transmit descriptor block entry */
  2768. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  2769. unsigned long flags;
  2770. netif_stop_queue(dev);
  2771. /*
  2772. * Verify that incoming transmit request is OK
  2773. *
  2774. * Note: The packet size check is consistent with other
  2775. * Linux device drivers, although the correct packet
  2776. * size should be verified before calling the
  2777. * transmit routine.
  2778. */
  2779. if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
  2780. {
  2781. printk("%s: Invalid packet length - %u bytes\n",
  2782. dev->name, skb->len);
  2783. bp->xmt_length_errors++; /* bump error counter */
  2784. netif_wake_queue(dev);
  2785. dev_kfree_skb(skb);
  2786. return(0); /* return "success" */
  2787. }
  2788. /*
  2789. * See if adapter link is available, if not, free buffer
  2790. *
  2791. * Note: If the link isn't available, free buffer and return 0
  2792. * rather than tell the upper layer to requeue the packet.
  2793. * The methodology here is that by the time the link
  2794. * becomes available, the packet to be sent will be
  2795. * fairly stale. By simply dropping the packet, the
  2796. * higher layer protocols will eventually time out
  2797. * waiting for response packets which it won't receive.
  2798. */
  2799. if (bp->link_available == PI_K_FALSE)
  2800. {
  2801. if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL) /* is link really available? */
  2802. bp->link_available = PI_K_TRUE; /* if so, set flag and continue */
  2803. else
  2804. {
  2805. bp->xmt_discards++; /* bump error counter */
  2806. dev_kfree_skb(skb); /* free sk_buff now */
  2807. netif_wake_queue(dev);
  2808. return(0); /* return "success" */
  2809. }
  2810. }
  2811. spin_lock_irqsave(&bp->lock, flags);
  2812. /* Get the current producer and the next free xmt data descriptor */
  2813. prod = bp->rcv_xmt_reg.index.xmt_prod;
  2814. p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
  2815. /*
  2816. * Get pointer to auxiliary queue entry to contain information
  2817. * for this packet.
  2818. *
  2819. * Note: The current xmt producer index will become the
  2820. * current xmt completion index when we complete this
  2821. * packet later on. So, we'll get the pointer to the
  2822. * next auxiliary queue entry now before we bump the
  2823. * producer index.
  2824. */
  2825. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]); /* also bump producer index */
  2826. /* Write the three PRH bytes immediately before the FC byte */
  2827. skb_push(skb,3);
  2828. skb->data[0] = DFX_PRH0_BYTE; /* these byte values are defined */
  2829. skb->data[1] = DFX_PRH1_BYTE; /* in the Motorola FDDI MAC chip */
  2830. skb->data[2] = DFX_PRH2_BYTE; /* specification */
  2831. /*
  2832. * Write the descriptor with buffer info and bump producer
  2833. *
  2834. * Note: Since we need to start DMA from the packet request
  2835. * header, we'll add 3 bytes to the DMA buffer length,
  2836. * and we'll determine the physical address of the
  2837. * buffer from the PRH, not skb->data.
  2838. *
  2839. * Assumptions:
  2840. * 1. Packet starts with the frame control (FC) byte
  2841. * at skb->data.
  2842. * 2. The 4-byte CRC is not appended to the buffer or
  2843. * included in the length.
  2844. * 3. Packet length (skb->len) is from FC to end of
  2845. * data, inclusive.
  2846. * 4. The packet length does not exceed the maximum
  2847. * FDDI LLC frame length of 4491 bytes.
  2848. * 5. The entire packet is contained in a physically
  2849. * contiguous, non-cached, locked memory space
  2850. * comprised of a single buffer pointed to by
  2851. * skb->data.
  2852. * 6. The physical address of the start of packet
  2853. * can be determined from the virtual address
  2854. * by using pci_map_single() and is only 32-bits
  2855. * wide.
  2856. */
  2857. p_xmt_descr->long_0 = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
  2858. p_xmt_descr->long_1 = (u32)dma_map_single(bp->bus_dev, skb->data,
  2859. skb->len, DMA_TO_DEVICE);
  2860. /*
  2861. * Verify that descriptor is actually available
  2862. *
  2863. * Note: If descriptor isn't available, return 1 which tells
  2864. * the upper layer to requeue the packet for later
  2865. * transmission.
  2866. *
  2867. * We need to ensure that the producer never reaches the
  2868. * completion, except to indicate that the queue is empty.
  2869. */
  2870. if (prod == bp->rcv_xmt_reg.index.xmt_comp)
  2871. {
  2872. skb_pull(skb,3);
  2873. spin_unlock_irqrestore(&bp->lock, flags);
  2874. return(1); /* requeue packet for later */
  2875. }
  2876. /*
  2877. * Save info for this packet for xmt done indication routine
  2878. *
  2879. * Normally, we'd save the producer index in the p_xmt_drv_descr
  2880. * structure so that we'd have it handy when we complete this
  2881. * packet later (in dfx_xmt_done). However, since the current
  2882. * transmit architecture guarantees a single fragment for the
  2883. * entire packet, we can simply bump the completion index by
  2884. * one (1) for each completed packet.
  2885. *
  2886. * Note: If this assumption changes and we're presented with
  2887. * an inconsistent number of transmit fragments for packet
  2888. * data, we'll need to modify this code to save the current
  2889. * transmit producer index.
  2890. */
  2891. p_xmt_drv_descr->p_skb = skb;
  2892. /* Update Type 2 register */
  2893. bp->rcv_xmt_reg.index.xmt_prod = prod;
  2894. dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
  2895. spin_unlock_irqrestore(&bp->lock, flags);
  2896. netif_wake_queue(dev);
  2897. return(0); /* packet queued to adapter */
  2898. }
  2899. /*
  2900. * ================
  2901. * = dfx_xmt_done =
  2902. * ================
  2903. *
  2904. * Overview:
  2905. * Processes all frames that have been transmitted.
  2906. *
  2907. * Returns:
  2908. * None
  2909. *
  2910. * Arguments:
  2911. * bp - pointer to board information
  2912. *
  2913. * Functional Description:
  2914. * For all consumed transmit descriptors that have not
  2915. * yet been completed, we'll free the skb we were holding
  2916. * onto using dev_kfree_skb and bump the appropriate
  2917. * counters.
  2918. *
  2919. * Return Codes:
  2920. * None
  2921. *
  2922. * Assumptions:
  2923. * The Type 2 register is not updated in this routine. It is
  2924. * assumed that it will be updated in the ISR when dfx_xmt_done
  2925. * returns.
  2926. *
  2927. * Side Effects:
  2928. * None
  2929. */
  2930. static int dfx_xmt_done(DFX_board_t *bp)
  2931. {
  2932. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  2933. PI_TYPE_2_CONSUMER *p_type_2_cons; /* ptr to rcv/xmt consumer block register */
  2934. u8 comp; /* local transmit completion index */
  2935. int freed = 0; /* buffers freed */
  2936. /* Service all consumed transmit frames */
  2937. p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
  2938. while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
  2939. {
  2940. /* Get pointer to the transmit driver descriptor block information */
  2941. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  2942. /* Increment transmit counters */
  2943. bp->xmt_total_frames++;
  2944. bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
  2945. /* Return skb to operating system */
  2946. comp = bp->rcv_xmt_reg.index.xmt_comp;
  2947. dma_unmap_single(bp->bus_dev,
  2948. bp->descr_block_virt->xmt_data[comp].long_1,
  2949. p_xmt_drv_descr->p_skb->len,
  2950. DMA_TO_DEVICE);
  2951. dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
  2952. /*
  2953. * Move to start of next packet by updating completion index
  2954. *
  2955. * Here we assume that a transmit packet request is always
  2956. * serviced by posting one fragment. We can therefore
  2957. * simplify the completion code by incrementing the
  2958. * completion index by one. This code will need to be
  2959. * modified if this assumption changes. See comments
  2960. * in dfx_xmt_queue_pkt for more details.
  2961. */
  2962. bp->rcv_xmt_reg.index.xmt_comp += 1;
  2963. freed++;
  2964. }
  2965. return freed;
  2966. }
  2967. /*
  2968. * =================
  2969. * = dfx_rcv_flush =
  2970. * =================
  2971. *
  2972. * Overview:
  2973. * Remove all skb's in the receive ring.
  2974. *
  2975. * Returns:
  2976. * None
  2977. *
  2978. * Arguments:
  2979. * bp - pointer to board information
  2980. *
  2981. * Functional Description:
  2982. * Free's all the dynamically allocated skb's that are
  2983. * currently attached to the device receive ring. This
  2984. * function is typically only used when the device is
  2985. * initialized or reinitialized.
  2986. *
  2987. * Return Codes:
  2988. * None
  2989. *
  2990. * Side Effects:
  2991. * None
  2992. */
  2993. #ifdef DYNAMIC_BUFFERS
  2994. static void dfx_rcv_flush( DFX_board_t *bp )
  2995. {
  2996. int i, j;
  2997. for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
  2998. for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
  2999. {
  3000. struct sk_buff *skb;
  3001. skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
  3002. if (skb)
  3003. dev_kfree_skb(skb);
  3004. bp->p_rcv_buff_va[i+j] = NULL;
  3005. }
  3006. }
  3007. #else
  3008. static inline void dfx_rcv_flush( DFX_board_t *bp )
  3009. {
  3010. }
  3011. #endif /* DYNAMIC_BUFFERS */
  3012. /*
  3013. * =================
  3014. * = dfx_xmt_flush =
  3015. * =================
  3016. *
  3017. * Overview:
  3018. * Processes all frames whether they've been transmitted
  3019. * or not.
  3020. *
  3021. * Returns:
  3022. * None
  3023. *
  3024. * Arguments:
  3025. * bp - pointer to board information
  3026. *
  3027. * Functional Description:
  3028. * For all produced transmit descriptors that have not
  3029. * yet been completed, we'll free the skb we were holding
  3030. * onto using dev_kfree_skb and bump the appropriate
  3031. * counters. Of course, it's possible that some of
  3032. * these transmit requests actually did go out, but we
  3033. * won't make that distinction here. Finally, we'll
  3034. * update the consumer index to match the producer.
  3035. *
  3036. * Return Codes:
  3037. * None
  3038. *
  3039. * Assumptions:
  3040. * This routine does NOT update the Type 2 register. It
  3041. * is assumed that this routine is being called during a
  3042. * transmit flush interrupt, or a shutdown or close routine.
  3043. *
  3044. * Side Effects:
  3045. * None
  3046. */
  3047. static void dfx_xmt_flush( DFX_board_t *bp )
  3048. {
  3049. u32 prod_cons; /* rcv/xmt consumer block longword */
  3050. XMT_DRIVER_DESCR *p_xmt_drv_descr; /* ptr to transmit driver descriptor */
  3051. u8 comp; /* local transmit completion index */
  3052. /* Flush all outstanding transmit frames */
  3053. while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
  3054. {
  3055. /* Get pointer to the transmit driver descriptor block information */
  3056. p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
  3057. /* Return skb to operating system */
  3058. comp = bp->rcv_xmt_reg.index.xmt_comp;
  3059. dma_unmap_single(bp->bus_dev,
  3060. bp->descr_block_virt->xmt_data[comp].long_1,
  3061. p_xmt_drv_descr->p_skb->len,
  3062. DMA_TO_DEVICE);
  3063. dev_kfree_skb(p_xmt_drv_descr->p_skb);
  3064. /* Increment transmit error counter */
  3065. bp->xmt_discards++;
  3066. /*
  3067. * Move to start of next packet by updating completion index
  3068. *
  3069. * Here we assume that a transmit packet request is always
  3070. * serviced by posting one fragment. We can therefore
  3071. * simplify the completion code by incrementing the
  3072. * completion index by one. This code will need to be
  3073. * modified if this assumption changes. See comments
  3074. * in dfx_xmt_queue_pkt for more details.
  3075. */
  3076. bp->rcv_xmt_reg.index.xmt_comp += 1;
  3077. }
  3078. /* Update the transmit consumer index in the consumer block */
  3079. prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
  3080. prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
  3081. bp->cons_block_virt->xmt_rcv_data = prod_cons;
  3082. }
  3083. /*
  3084. * ==================
  3085. * = dfx_unregister =
  3086. * ==================
  3087. *
  3088. * Overview:
  3089. * Shuts down an FDDI controller
  3090. *
  3091. * Returns:
  3092. * Condition code
  3093. *
  3094. * Arguments:
  3095. * bdev - pointer to device information
  3096. *
  3097. * Functional Description:
  3098. *
  3099. * Return Codes:
  3100. * None
  3101. *
  3102. * Assumptions:
  3103. * It compiles so it should work :-( (PCI cards do :-)
  3104. *
  3105. * Side Effects:
  3106. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  3107. * freed.
  3108. */
  3109. static void __devexit dfx_unregister(struct device *bdev)
  3110. {
  3111. struct net_device *dev = dev_get_drvdata(bdev);
  3112. DFX_board_t *bp = netdev_priv(dev);
  3113. int dfx_bus_pci = DFX_BUS_PCI(bdev);
  3114. int dfx_bus_tc = DFX_BUS_TC(bdev);
  3115. int dfx_use_mmio = DFX_MMIO || dfx_bus_tc;
  3116. resource_size_t bar_start = 0; /* pointer to port */
  3117. resource_size_t bar_len = 0; /* resource length */
  3118. int alloc_size; /* total buffer size used */
  3119. unregister_netdev(dev);
  3120. alloc_size = sizeof(PI_DESCR_BLOCK) +
  3121. PI_CMD_REQ_K_SIZE_MAX + PI_CMD_RSP_K_SIZE_MAX +
  3122. #ifndef DYNAMIC_BUFFERS
  3123. (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
  3124. #endif
  3125. sizeof(PI_CONSUMER_BLOCK) +
  3126. (PI_ALIGN_K_DESC_BLK - 1);
  3127. if (bp->kmalloced)
  3128. dma_free_coherent(bdev, alloc_size,
  3129. bp->kmalloced, bp->kmalloced_dma);
  3130. dfx_bus_uninit(dev);
  3131. dfx_get_bars(bdev, &bar_start, &bar_len);
  3132. if (dfx_use_mmio) {
  3133. iounmap(bp->base.mem);
  3134. release_mem_region(bar_start, bar_len);
  3135. } else
  3136. release_region(bar_start, bar_len);
  3137. if (dfx_bus_pci)
  3138. pci_disable_device(to_pci_dev(bdev));
  3139. free_netdev(dev);
  3140. }
  3141. static int __devinit __maybe_unused dfx_dev_register(struct device *);
  3142. static int __devexit __maybe_unused dfx_dev_unregister(struct device *);
  3143. #ifdef CONFIG_PCI
  3144. static int __devinit dfx_pci_register(struct pci_dev *,
  3145. const struct pci_device_id *);
  3146. static void __devexit dfx_pci_unregister(struct pci_dev *);
  3147. static struct pci_device_id dfx_pci_table[] = {
  3148. { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI) },
  3149. { }
  3150. };
  3151. MODULE_DEVICE_TABLE(pci, dfx_pci_table);
  3152. static struct pci_driver dfx_pci_driver = {
  3153. .name = "defxx",
  3154. .id_table = dfx_pci_table,
  3155. .probe = dfx_pci_register,
  3156. .remove = __devexit_p(dfx_pci_unregister),
  3157. };
  3158. static __devinit int dfx_pci_register(struct pci_dev *pdev,
  3159. const struct pci_device_id *ent)
  3160. {
  3161. return dfx_register(&pdev->dev);
  3162. }
  3163. static void __devexit dfx_pci_unregister(struct pci_dev *pdev)
  3164. {
  3165. dfx_unregister(&pdev->dev);
  3166. }
  3167. #endif /* CONFIG_PCI */
  3168. #ifdef CONFIG_EISA
  3169. static struct eisa_device_id dfx_eisa_table[] = {
  3170. { "DEC3001", DEFEA_PROD_ID_1 },
  3171. { "DEC3002", DEFEA_PROD_ID_2 },
  3172. { "DEC3003", DEFEA_PROD_ID_3 },
  3173. { "DEC3004", DEFEA_PROD_ID_4 },
  3174. { }
  3175. };
  3176. MODULE_DEVICE_TABLE(eisa, dfx_eisa_table);
  3177. static struct eisa_driver dfx_eisa_driver = {
  3178. .id_table = dfx_eisa_table,
  3179. .driver = {
  3180. .name = "defxx",
  3181. .bus = &eisa_bus_type,
  3182. .probe = dfx_dev_register,
  3183. .remove = __devexit_p(dfx_dev_unregister),
  3184. },
  3185. };
  3186. #endif /* CONFIG_EISA */
  3187. #ifdef CONFIG_TC
  3188. static struct tc_device_id const dfx_tc_table[] = {
  3189. { "DEC ", "PMAF-FA " },
  3190. { "DEC ", "PMAF-FD " },
  3191. { "DEC ", "PMAF-FS " },
  3192. { "DEC ", "PMAF-FU " },
  3193. { }
  3194. };
  3195. MODULE_DEVICE_TABLE(tc, dfx_tc_table);
  3196. static struct tc_driver dfx_tc_driver = {
  3197. .id_table = dfx_tc_table,
  3198. .driver = {
  3199. .name = "defxx",
  3200. .bus = &tc_bus_type,
  3201. .probe = dfx_dev_register,
  3202. .remove = __devexit_p(dfx_dev_unregister),
  3203. },
  3204. };
  3205. #endif /* CONFIG_TC */
  3206. static int __devinit __maybe_unused dfx_dev_register(struct device *dev)
  3207. {
  3208. int status;
  3209. status = dfx_register(dev);
  3210. if (!status)
  3211. get_device(dev);
  3212. return status;
  3213. }
  3214. static int __devexit __maybe_unused dfx_dev_unregister(struct device *dev)
  3215. {
  3216. put_device(dev);
  3217. dfx_unregister(dev);
  3218. return 0;
  3219. }
  3220. static int __devinit dfx_init(void)
  3221. {
  3222. int status;
  3223. status = pci_register_driver(&dfx_pci_driver);
  3224. if (!status)
  3225. status = eisa_driver_register(&dfx_eisa_driver);
  3226. if (!status)
  3227. status = tc_register_driver(&dfx_tc_driver);
  3228. return status;
  3229. }
  3230. static void __devexit dfx_cleanup(void)
  3231. {
  3232. tc_unregister_driver(&dfx_tc_driver);
  3233. eisa_driver_unregister(&dfx_eisa_driver);
  3234. pci_unregister_driver(&dfx_pci_driver);
  3235. }
  3236. module_init(dfx_init);
  3237. module_exit(dfx_cleanup);
  3238. MODULE_AUTHOR("Lawrence V. Stefani");
  3239. MODULE_DESCRIPTION("DEC FDDIcontroller TC/EISA/PCI (DEFTA/DEFEA/DEFPA) driver "
  3240. DRV_VERSION " " DRV_RELDATE);
  3241. MODULE_LICENSE("GPL");