defxx.c 113 KB

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