defxx.c 113 KB

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