defxx.c 107 KB

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