defxx.c 113 KB

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