defxx.c 107 KB

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