defxx.c 116 KB

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