defxx.c 113 KB

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