defxx.c 113 KB

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