defxx.c 107 KB

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