defxx.c 114 KB

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