hp100.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056
  1. /*
  2. ** hp100.c
  3. ** HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters
  4. **
  5. ** $Id: hp100.c,v 1.58 2001/09/24 18:03:01 perex Exp perex $
  6. **
  7. ** Based on the HP100 driver written by Jaroslav Kysela <perex@jcu.cz>
  8. ** Extended for new busmaster capable chipsets by
  9. ** Siegfried "Frieder" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>
  10. **
  11. ** Maintained by: Jaroslav Kysela <perex@perex.cz>
  12. **
  13. ** This driver has only been tested with
  14. ** -- HP J2585B 10/100 Mbit/s PCI Busmaster
  15. ** -- HP J2585A 10/100 Mbit/s PCI
  16. ** -- HP J2970A 10 Mbit/s PCI Combo 10base-T/BNC
  17. ** -- HP J2973A 10 Mbit/s PCI 10base-T
  18. ** -- HP J2573 10/100 ISA
  19. ** -- Compex ReadyLink ENET100-VG4 10/100 Mbit/s PCI / EISA
  20. ** -- Compex FreedomLine 100/VG 10/100 Mbit/s ISA / EISA / PCI
  21. **
  22. ** but it should also work with the other CASCADE based adapters.
  23. **
  24. ** TODO:
  25. ** - J2573 seems to hang sometimes when in shared memory mode.
  26. ** - Mode for Priority TX
  27. ** - Check PCI registers, performance might be improved?
  28. ** - To reduce interrupt load in busmaster, one could switch off
  29. ** the interrupts that are used to refill the queues whenever the
  30. ** queues are filled up to more than a certain threshold.
  31. ** - some updates for EISA version of card
  32. **
  33. **
  34. ** This code is free software; you can redistribute it and/or modify
  35. ** it under the terms of the GNU General Public License as published by
  36. ** the Free Software Foundation; either version 2 of the License, or
  37. ** (at your option) any later version.
  38. **
  39. ** This code is distributed in the hope that it will be useful,
  40. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  42. ** GNU General Public License for more details.
  43. **
  44. ** You should have received a copy of the GNU General Public License
  45. ** along with this program; if not, write to the Free Software
  46. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47. **
  48. ** 1.57c -> 1.58
  49. ** - used indent to change coding-style
  50. ** - added KTI DP-200 EISA ID
  51. ** - ioremap is also used for low (<1MB) memory (multi-architecture support)
  52. **
  53. ** 1.57b -> 1.57c - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  54. ** - release resources on failure in init_module
  55. **
  56. ** 1.57 -> 1.57b - Jean II
  57. ** - fix spinlocks, SMP is now working !
  58. **
  59. ** 1.56 -> 1.57
  60. ** - updates for new PCI interface for 2.1 kernels
  61. **
  62. ** 1.55 -> 1.56
  63. ** - removed printk in misc. interrupt and update statistics to allow
  64. ** monitoring of card status
  65. ** - timing changes in xmit routines, relogin to 100VG hub added when
  66. ** driver does reset
  67. ** - included fix for Compex FreedomLine PCI adapter
  68. **
  69. ** 1.54 -> 1.55
  70. ** - fixed bad initialization in init_module
  71. ** - added Compex FreedomLine adapter
  72. ** - some fixes in card initialization
  73. **
  74. ** 1.53 -> 1.54
  75. ** - added hardware multicast filter support (doesn't work)
  76. ** - little changes in hp100_sense_lan routine
  77. ** - added support for Coax and AUI (J2970)
  78. ** - fix for multiple cards and hp100_mode parameter (insmod)
  79. ** - fix for shared IRQ
  80. **
  81. ** 1.52 -> 1.53
  82. ** - fixed bug in multicast support
  83. **
  84. */
  85. #define HP100_DEFAULT_PRIORITY_TX 0
  86. #undef HP100_DEBUG
  87. #undef HP100_DEBUG_B /* Trace */
  88. #undef HP100_DEBUG_BM /* Debug busmaster code (PDL stuff) */
  89. #undef HP100_DEBUG_TRAINING /* Debug login-to-hub procedure */
  90. #undef HP100_DEBUG_TX
  91. #undef HP100_DEBUG_IRQ
  92. #undef HP100_DEBUG_RX
  93. #undef HP100_MULTICAST_FILTER /* Need to be debugged... */
  94. #include <linux/module.h>
  95. #include <linux/kernel.h>
  96. #include <linux/string.h>
  97. #include <linux/errno.h>
  98. #include <linux/ioport.h>
  99. #include <linux/slab.h>
  100. #include <linux/interrupt.h>
  101. #include <linux/eisa.h>
  102. #include <linux/pci.h>
  103. #include <linux/dma-mapping.h>
  104. #include <linux/spinlock.h>
  105. #include <linux/netdevice.h>
  106. #include <linux/etherdevice.h>
  107. #include <linux/skbuff.h>
  108. #include <linux/types.h>
  109. #include <linux/delay.h>
  110. #include <linux/init.h>
  111. #include <linux/bitops.h>
  112. #include <linux/jiffies.h>
  113. #include <asm/io.h>
  114. #include "hp100.h"
  115. /*
  116. * defines
  117. */
  118. #define HP100_BUS_ISA 0
  119. #define HP100_BUS_EISA 1
  120. #define HP100_BUS_PCI 2
  121. #define HP100_REGION_SIZE 0x20 /* for ioports */
  122. #define HP100_SIG_LEN 8 /* same as EISA_SIG_LEN */
  123. #define HP100_MAX_PACKET_SIZE (1536+4)
  124. #define HP100_MIN_PACKET_SIZE 60
  125. #ifndef HP100_DEFAULT_RX_RATIO
  126. /* default - 75% onboard memory on the card are used for RX packets */
  127. #define HP100_DEFAULT_RX_RATIO 75
  128. #endif
  129. #ifndef HP100_DEFAULT_PRIORITY_TX
  130. /* default - don't enable transmit outgoing packets as priority */
  131. #define HP100_DEFAULT_PRIORITY_TX 0
  132. #endif
  133. /*
  134. * structures
  135. */
  136. struct hp100_private {
  137. spinlock_t lock;
  138. char id[HP100_SIG_LEN];
  139. u_short chip;
  140. u_short soft_model;
  141. u_int memory_size;
  142. u_int virt_memory_size;
  143. u_short rx_ratio; /* 1 - 99 */
  144. u_short priority_tx; /* != 0 - priority tx */
  145. u_short mode; /* PIO, Shared Mem or Busmaster */
  146. u_char bus;
  147. struct pci_dev *pci_dev;
  148. short mem_mapped; /* memory mapped access */
  149. void __iomem *mem_ptr_virt; /* virtual memory mapped area, maybe NULL */
  150. unsigned long mem_ptr_phys; /* physical memory mapped area */
  151. short lan_type; /* 10Mb/s, 100Mb/s or -1 (error) */
  152. int hub_status; /* was login to hub successful? */
  153. u_char mac1_mode;
  154. u_char mac2_mode;
  155. u_char hash_bytes[8];
  156. struct net_device_stats stats;
  157. /* Rings for busmaster mode: */
  158. hp100_ring_t *rxrhead; /* Head (oldest) index into rxring */
  159. hp100_ring_t *rxrtail; /* Tail (newest) index into rxring */
  160. hp100_ring_t *txrhead; /* Head (oldest) index into txring */
  161. hp100_ring_t *txrtail; /* Tail (newest) index into txring */
  162. hp100_ring_t rxring[MAX_RX_PDL];
  163. hp100_ring_t txring[MAX_TX_PDL];
  164. u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */
  165. u_long whatever_offset; /* Offset to bus/phys/dma address */
  166. int rxrcommit; /* # Rx PDLs commited to adapter */
  167. int txrcommit; /* # Tx PDLs commited to adapter */
  168. };
  169. /*
  170. * variables
  171. */
  172. #ifdef CONFIG_ISA
  173. static const char *hp100_isa_tbl[] = {
  174. "HWPF150", /* HP J2573 rev A */
  175. "HWP1950", /* HP J2573 */
  176. };
  177. #endif
  178. #ifdef CONFIG_EISA
  179. static struct eisa_device_id hp100_eisa_tbl[] = {
  180. { "HWPF180" }, /* HP J2577 rev A */
  181. { "HWP1920" }, /* HP 27248B */
  182. { "HWP1940" }, /* HP J2577 */
  183. { "HWP1990" }, /* HP J2577 */
  184. { "CPX0301" }, /* ReadyLink ENET100-VG4 */
  185. { "CPX0401" }, /* FreedomLine 100/VG */
  186. { "" } /* Mandatory final entry ! */
  187. };
  188. MODULE_DEVICE_TABLE(eisa, hp100_eisa_tbl);
  189. #endif
  190. #ifdef CONFIG_PCI
  191. static struct pci_device_id hp100_pci_tbl[] = {
  192. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A, PCI_ANY_ID, PCI_ANY_ID,},
  193. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B, PCI_ANY_ID, PCI_ANY_ID,},
  194. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2970A, PCI_ANY_ID, PCI_ANY_ID,},
  195. {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2973A, PCI_ANY_ID, PCI_ANY_ID,},
  196. {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4, PCI_ANY_ID, PCI_ANY_ID,},
  197. {PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG, PCI_ANY_ID, PCI_ANY_ID,},
  198. /* {PCI_VENDOR_ID_KTI, PCI_DEVICE_ID_KTI_DP200, PCI_ANY_ID, PCI_ANY_ID }, */
  199. {} /* Terminating entry */
  200. };
  201. MODULE_DEVICE_TABLE(pci, hp100_pci_tbl);
  202. #endif
  203. static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
  204. static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
  205. static int hp100_mode = 1;
  206. module_param(hp100_rx_ratio, int, 0);
  207. module_param(hp100_priority_tx, int, 0);
  208. module_param(hp100_mode, int, 0);
  209. /*
  210. * prototypes
  211. */
  212. static int hp100_probe1(struct net_device *dev, int ioaddr, u_char bus,
  213. struct pci_dev *pci_dev);
  214. static int hp100_open(struct net_device *dev);
  215. static int hp100_close(struct net_device *dev);
  216. static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev);
  217. static int hp100_start_xmit_bm(struct sk_buff *skb,
  218. struct net_device *dev);
  219. static void hp100_rx(struct net_device *dev);
  220. static struct net_device_stats *hp100_get_stats(struct net_device *dev);
  221. static void hp100_misc_interrupt(struct net_device *dev);
  222. static void hp100_update_stats(struct net_device *dev);
  223. static void hp100_clear_stats(struct hp100_private *lp, int ioaddr);
  224. static void hp100_set_multicast_list(struct net_device *dev);
  225. static irqreturn_t hp100_interrupt(int irq, void *dev_id);
  226. static void hp100_start_interface(struct net_device *dev);
  227. static void hp100_stop_interface(struct net_device *dev);
  228. static void hp100_load_eeprom(struct net_device *dev, u_short ioaddr);
  229. static int hp100_sense_lan(struct net_device *dev);
  230. static int hp100_login_to_vg_hub(struct net_device *dev,
  231. u_short force_relogin);
  232. static int hp100_down_vg_link(struct net_device *dev);
  233. static void hp100_cascade_reset(struct net_device *dev, u_short enable);
  234. static void hp100_BM_shutdown(struct net_device *dev);
  235. static void hp100_mmuinit(struct net_device *dev);
  236. static void hp100_init_pdls(struct net_device *dev);
  237. static int hp100_init_rxpdl(struct net_device *dev,
  238. register hp100_ring_t * ringptr,
  239. register u_int * pdlptr);
  240. static int hp100_init_txpdl(struct net_device *dev,
  241. register hp100_ring_t * ringptr,
  242. register u_int * pdlptr);
  243. static void hp100_rxfill(struct net_device *dev);
  244. static void hp100_hwinit(struct net_device *dev);
  245. static void hp100_clean_txring(struct net_device *dev);
  246. #ifdef HP100_DEBUG
  247. static void hp100_RegisterDump(struct net_device *dev);
  248. #endif
  249. /* Conversion to new PCI API :
  250. * Convert an address in a kernel buffer to a bus/phys/dma address.
  251. * This work *only* for memory fragments part of lp->page_vaddr,
  252. * because it was properly DMA allocated via pci_alloc_consistent(),
  253. * so we just need to "retrieve" the original mapping to bus/phys/dma
  254. * address - Jean II */
  255. static inline dma_addr_t virt_to_whatever(struct net_device *dev, u32 * ptr)
  256. {
  257. struct hp100_private *lp = netdev_priv(dev);
  258. return ((u_long) ptr) + lp->whatever_offset;
  259. }
  260. static inline u_int pdl_map_data(struct hp100_private *lp, void *data)
  261. {
  262. return pci_map_single(lp->pci_dev, data,
  263. MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE);
  264. }
  265. /* TODO: This function should not really be needed in a good design... */
  266. static void wait(void)
  267. {
  268. mdelay(1);
  269. }
  270. /*
  271. * probe functions
  272. * These functions should - if possible - avoid doing write operations
  273. * since this could cause problems when the card is not installed.
  274. */
  275. /*
  276. * Read board id and convert to string.
  277. * Effectively same code as decode_eisa_sig
  278. */
  279. static __devinit const char *hp100_read_id(int ioaddr)
  280. {
  281. int i;
  282. static char str[HP100_SIG_LEN];
  283. unsigned char sig[4], sum;
  284. unsigned short rev;
  285. hp100_page(ID_MAC_ADDR);
  286. sum = 0;
  287. for (i = 0; i < 4; i++) {
  288. sig[i] = hp100_inb(BOARD_ID + i);
  289. sum += sig[i];
  290. }
  291. sum += hp100_inb(BOARD_ID + i);
  292. if (sum != 0xff)
  293. return NULL; /* bad checksum */
  294. str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
  295. str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
  296. str[2] = (sig[1] & 0x1f) + ('A' - 1);
  297. rev = (sig[2] << 8) | sig[3];
  298. sprintf(str + 3, "%04X", rev);
  299. return str;
  300. }
  301. #ifdef CONFIG_ISA
  302. static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
  303. {
  304. const char *sig;
  305. int i;
  306. if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100"))
  307. goto err;
  308. if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) {
  309. release_region(ioaddr, HP100_REGION_SIZE);
  310. goto err;
  311. }
  312. sig = hp100_read_id(ioaddr);
  313. release_region(ioaddr, HP100_REGION_SIZE);
  314. if (sig == NULL)
  315. goto err;
  316. for (i = 0; i < ARRAY_SIZE(hp100_isa_tbl); i++) {
  317. if (!strcmp(hp100_isa_tbl[i], sig))
  318. break;
  319. }
  320. if (i < ARRAY_SIZE(hp100_isa_tbl))
  321. return hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL);
  322. err:
  323. return -ENODEV;
  324. }
  325. /*
  326. * Probe for ISA board.
  327. * EISA and PCI are handled by device infrastructure.
  328. */
  329. static int __init hp100_isa_probe(struct net_device *dev, int addr)
  330. {
  331. int err = -ENODEV;
  332. /* Probe for a specific ISA address */
  333. if (addr > 0xff && addr < 0x400)
  334. err = hp100_isa_probe1(dev, addr);
  335. else if (addr != 0)
  336. err = -ENXIO;
  337. else {
  338. /* Probe all ISA possible port regions */
  339. for (addr = 0x100; addr < 0x400; addr += 0x20) {
  340. err = hp100_isa_probe1(dev, addr);
  341. if (!err)
  342. break;
  343. }
  344. }
  345. return err;
  346. }
  347. #endif /* CONFIG_ISA */
  348. #if !defined(MODULE) && defined(CONFIG_ISA)
  349. struct net_device * __init hp100_probe(int unit)
  350. {
  351. struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private));
  352. int err;
  353. if (!dev)
  354. return ERR_PTR(-ENODEV);
  355. #ifdef HP100_DEBUG_B
  356. hp100_outw(0x4200, TRACE);
  357. printk("hp100: %s: probe\n", dev->name);
  358. #endif
  359. if (unit >= 0) {
  360. sprintf(dev->name, "eth%d", unit);
  361. netdev_boot_setup_check(dev);
  362. }
  363. err = hp100_isa_probe(dev, dev->base_addr);
  364. if (err)
  365. goto out;
  366. return dev;
  367. out:
  368. free_netdev(dev);
  369. return ERR_PTR(err);
  370. }
  371. #endif /* !MODULE && CONFIG_ISA */
  372. static int __devinit hp100_probe1(struct net_device *dev, int ioaddr,
  373. u_char bus, struct pci_dev *pci_dev)
  374. {
  375. int i;
  376. int err = -ENODEV;
  377. const char *eid;
  378. u_int chip;
  379. u_char uc;
  380. u_int memory_size = 0, virt_memory_size = 0;
  381. u_short local_mode, lsw;
  382. short mem_mapped;
  383. unsigned long mem_ptr_phys;
  384. void __iomem *mem_ptr_virt;
  385. struct hp100_private *lp;
  386. #ifdef HP100_DEBUG_B
  387. hp100_outw(0x4201, TRACE);
  388. printk("hp100: %s: probe1\n", dev->name);
  389. #endif
  390. /* memory region for programmed i/o */
  391. if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100"))
  392. goto out1;
  393. if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE)
  394. goto out2;
  395. chip = hp100_inw(PAGING) & HP100_CHIPID_MASK;
  396. #ifdef HP100_DEBUG
  397. if (chip == HP100_CHIPID_SHASTA)
  398. printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name);
  399. else if (chip == HP100_CHIPID_RAINIER)
  400. printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name);
  401. else if (chip == HP100_CHIPID_LASSEN)
  402. printk("hp100: %s: Lassen Chip detected.\n", dev->name);
  403. else
  404. printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n", dev->name, chip);
  405. #endif
  406. dev->base_addr = ioaddr;
  407. eid = hp100_read_id(ioaddr);
  408. if (eid == NULL) { /* bad checksum? */
  409. printk(KERN_WARNING "hp100_probe: bad ID checksum at base port 0x%x\n", ioaddr);
  410. goto out2;
  411. }
  412. hp100_page(ID_MAC_ADDR);
  413. for (i = uc = 0; i < 7; i++)
  414. uc += hp100_inb(LAN_ADDR + i);
  415. if (uc != 0xff) {
  416. printk(KERN_WARNING "hp100_probe: bad lan address checksum at port 0x%x)\n", ioaddr);
  417. err = -EIO;
  418. goto out2;
  419. }
  420. /* Make sure, that all registers are correctly updated... */
  421. hp100_load_eeprom(dev, ioaddr);
  422. wait();
  423. /*
  424. * Determine driver operation mode
  425. *
  426. * Use the variable "hp100_mode" upon insmod or as kernel parameter to
  427. * force driver modes:
  428. * hp100_mode=1 -> default, use busmaster mode if configured.
  429. * hp100_mode=2 -> enable shared memory mode
  430. * hp100_mode=3 -> force use of i/o mapped mode.
  431. * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.
  432. */
  433. /*
  434. * LSW values:
  435. * 0x2278 -> J2585B, PnP shared memory mode
  436. * 0x2270 -> J2585B, shared memory mode, 0xdc000
  437. * 0xa23c -> J2585B, I/O mapped mode
  438. * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)
  439. * 0x2220 -> EISA HP, I/O (Shasta Chip)
  440. * 0x2260 -> EISA HP, BusMaster (Shasta Chip)
  441. */
  442. #if 0
  443. local_mode = 0x2270;
  444. hp100_outw(0xfefe, OPTION_LSW);
  445. hp100_outw(local_mode | HP100_SET_LB | HP100_SET_HB, OPTION_LSW);
  446. #endif
  447. /* hp100_mode value maybe used in future by another card */
  448. local_mode = hp100_mode;
  449. if (local_mode < 1 || local_mode > 4)
  450. local_mode = 1; /* default */
  451. #ifdef HP100_DEBUG
  452. printk("hp100: %s: original LSW = 0x%x\n", dev->name,
  453. hp100_inw(OPTION_LSW));
  454. #endif
  455. if (local_mode == 3) {
  456. hp100_outw(HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);
  457. hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
  458. hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
  459. printk("hp100: IO mapped mode forced.\n");
  460. } else if (local_mode == 2) {
  461. hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
  462. hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
  463. hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
  464. printk("hp100: Shared memory mode requested.\n");
  465. } else if (local_mode == 4) {
  466. if (chip == HP100_CHIPID_LASSEN) {
  467. hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_SET_HB, OPTION_LSW);
  468. hp100_outw(HP100_IO_EN | HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);
  469. printk("hp100: Busmaster mode requested.\n");
  470. }
  471. local_mode = 1;
  472. }
  473. if (local_mode == 1) { /* default behaviour */
  474. lsw = hp100_inw(OPTION_LSW);
  475. if ((lsw & HP100_IO_EN) && (~lsw & HP100_MEM_EN) &&
  476. (~lsw & (HP100_BM_WRITE | HP100_BM_READ))) {
  477. #ifdef HP100_DEBUG
  478. printk("hp100: %s: IO_EN bit is set on card.\n", dev->name);
  479. #endif
  480. local_mode = 3;
  481. } else if (chip == HP100_CHIPID_LASSEN &&
  482. (lsw & (HP100_BM_WRITE | HP100_BM_READ)) == (HP100_BM_WRITE | HP100_BM_READ)) {
  483. /* Conversion to new PCI API :
  484. * I don't have the doc, but I assume that the card
  485. * can map the full 32bit address space.
  486. * Also, we can have EISA Busmaster cards (not tested),
  487. * so beware !!! - Jean II */
  488. if((bus == HP100_BUS_PCI) &&
  489. (pci_set_dma_mask(pci_dev, DMA_32BIT_MASK))) {
  490. /* Gracefully fallback to shared memory */
  491. goto busmasterfail;
  492. }
  493. printk("hp100: Busmaster mode enabled.\n");
  494. hp100_outw(HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);
  495. } else {
  496. busmasterfail:
  497. #ifdef HP100_DEBUG
  498. printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name);
  499. printk("hp100: %s: Trying shared memory mode.\n", dev->name);
  500. #endif
  501. /* In this case, try shared memory mode */
  502. local_mode = 2;
  503. hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
  504. /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */
  505. }
  506. }
  507. #ifdef HP100_DEBUG
  508. printk("hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW));
  509. #endif
  510. /* Check for shared memory on the card, eventually remap it */
  511. hp100_page(HW_MAP);
  512. mem_mapped = ((hp100_inw(OPTION_LSW) & (HP100_MEM_EN)) != 0);
  513. mem_ptr_phys = 0UL;
  514. mem_ptr_virt = NULL;
  515. memory_size = (8192 << ((hp100_inb(SRAM) >> 5) & 0x07));
  516. virt_memory_size = 0;
  517. /* For memory mapped or busmaster mode, we want the memory address */
  518. if (mem_mapped || (local_mode == 1)) {
  519. mem_ptr_phys = (hp100_inw(MEM_MAP_LSW) | (hp100_inw(MEM_MAP_MSW) << 16));
  520. mem_ptr_phys &= ~0x1fff; /* 8k alignment */
  521. if (bus == HP100_BUS_ISA && (mem_ptr_phys & ~0xfffff) != 0) {
  522. printk("hp100: Can only use programmed i/o mode.\n");
  523. mem_ptr_phys = 0;
  524. mem_mapped = 0;
  525. local_mode = 3; /* Use programmed i/o */
  526. }
  527. /* We do not need access to shared memory in busmaster mode */
  528. /* However in slave mode we need to remap high (>1GB) card memory */
  529. if (local_mode != 1) { /* = not busmaster */
  530. /* We try with smaller memory sizes, if ioremap fails */
  531. for (virt_memory_size = memory_size; virt_memory_size > 16383; virt_memory_size >>= 1) {
  532. if ((mem_ptr_virt = ioremap((u_long) mem_ptr_phys, virt_memory_size)) == NULL) {
  533. #ifdef HP100_DEBUG
  534. printk("hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, mem_ptr_phys);
  535. #endif
  536. } else {
  537. #ifdef HP100_DEBUG
  538. printk("hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to %p.\n", dev->name, virt_memory_size, mem_ptr_phys, mem_ptr_virt);
  539. #endif
  540. break;
  541. }
  542. }
  543. if (mem_ptr_virt == NULL) { /* all ioremap tries failed */
  544. printk("hp100: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n");
  545. local_mode = 3;
  546. virt_memory_size = 0;
  547. }
  548. }
  549. }
  550. if (local_mode == 3) { /* io mapped forced */
  551. mem_mapped = 0;
  552. mem_ptr_phys = 0;
  553. mem_ptr_virt = NULL;
  554. printk("hp100: Using (slow) programmed i/o mode.\n");
  555. }
  556. /* Initialise the "private" data structure for this card. */
  557. lp = netdev_priv(dev);
  558. spin_lock_init(&lp->lock);
  559. strlcpy(lp->id, eid, HP100_SIG_LEN);
  560. lp->chip = chip;
  561. lp->mode = local_mode;
  562. lp->bus = bus;
  563. lp->pci_dev = pci_dev;
  564. lp->priority_tx = hp100_priority_tx;
  565. lp->rx_ratio = hp100_rx_ratio;
  566. lp->mem_ptr_phys = mem_ptr_phys;
  567. lp->mem_ptr_virt = mem_ptr_virt;
  568. hp100_page(ID_MAC_ADDR);
  569. lp->soft_model = hp100_inb(SOFT_MODEL);
  570. lp->mac1_mode = HP100_MAC1MODE3;
  571. lp->mac2_mode = HP100_MAC2MODE3;
  572. memset(&lp->hash_bytes, 0x00, 8);
  573. dev->base_addr = ioaddr;
  574. lp->memory_size = memory_size;
  575. lp->virt_memory_size = virt_memory_size;
  576. lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */
  577. dev->open = hp100_open;
  578. dev->stop = hp100_close;
  579. if (lp->mode == 1) /* busmaster */
  580. dev->hard_start_xmit = hp100_start_xmit_bm;
  581. else
  582. dev->hard_start_xmit = hp100_start_xmit;
  583. dev->get_stats = hp100_get_stats;
  584. dev->set_multicast_list = &hp100_set_multicast_list;
  585. /* Ask the card for which IRQ line it is configured */
  586. if (bus == HP100_BUS_PCI) {
  587. dev->irq = pci_dev->irq;
  588. } else {
  589. hp100_page(HW_MAP);
  590. dev->irq = hp100_inb(IRQ_CHANNEL) & HP100_IRQMASK;
  591. if (dev->irq == 2)
  592. dev->irq = 9;
  593. }
  594. if (lp->mode == 1) /* busmaster */
  595. dev->dma = 4;
  596. /* Ask the card for its MAC address and store it for later use. */
  597. hp100_page(ID_MAC_ADDR);
  598. for (i = uc = 0; i < 6; i++)
  599. dev->dev_addr[i] = hp100_inb(LAN_ADDR + i);
  600. /* Reset statistics (counters) */
  601. hp100_clear_stats(lp, ioaddr);
  602. /* If busmaster mode is wanted, a dma-capable memory area is needed for
  603. * the rx and tx PDLs
  604. * PCI cards can access the whole PC memory. Therefore GFP_DMA is not
  605. * needed for the allocation of the memory area.
  606. */
  607. /* TODO: We do not need this with old cards, where PDLs are stored
  608. * in the cards shared memory area. But currently, busmaster has been
  609. * implemented/tested only with the lassen chip anyway... */
  610. if (lp->mode == 1) { /* busmaster */
  611. dma_addr_t page_baddr;
  612. /* Get physically continous memory for TX & RX PDLs */
  613. /* Conversion to new PCI API :
  614. * Pages are always aligned and zeroed, no need to it ourself.
  615. * Doc says should be OK for EISA bus as well - Jean II */
  616. if ((lp->page_vaddr_algn = pci_alloc_consistent(lp->pci_dev, MAX_RINGSIZE, &page_baddr)) == NULL) {
  617. err = -ENOMEM;
  618. goto out2;
  619. }
  620. lp->whatever_offset = ((u_long) page_baddr) - ((u_long) lp->page_vaddr_algn);
  621. #ifdef HP100_DEBUG_BM
  622. printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n", dev->name, (u_int) lp->page_vaddr_algn, (u_int) lp->page_vaddr_algn + MAX_RINGSIZE);
  623. #endif
  624. lp->rxrcommit = lp->txrcommit = 0;
  625. lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);
  626. lp->txrhead = lp->txrtail = &(lp->txring[0]);
  627. }
  628. /* Initialise the card. */
  629. /* (I'm not really sure if it's a good idea to do this during probing, but
  630. * like this it's assured that the lan connection type can be sensed
  631. * correctly)
  632. */
  633. hp100_hwinit(dev);
  634. /* Try to find out which kind of LAN the card is connected to. */
  635. lp->lan_type = hp100_sense_lan(dev);
  636. /* Print out a message what about what we think we have probed. */
  637. printk("hp100: at 0x%x, IRQ %d, ", ioaddr, dev->irq);
  638. switch (bus) {
  639. case HP100_BUS_EISA:
  640. printk("EISA");
  641. break;
  642. case HP100_BUS_PCI:
  643. printk("PCI");
  644. break;
  645. default:
  646. printk("ISA");
  647. break;
  648. }
  649. printk(" bus, %dk SRAM (rx/tx %d%%).\n", lp->memory_size >> 10, lp->rx_ratio);
  650. if (lp->mode == 2) { /* memory mapped */
  651. printk("hp100: Memory area at 0x%lx-0x%lx", mem_ptr_phys,
  652. (mem_ptr_phys + (mem_ptr_phys > 0x100000 ? (u_long) lp->memory_size : 16 * 1024)) - 1);
  653. if (mem_ptr_virt)
  654. printk(" (virtual base %p)", mem_ptr_virt);
  655. printk(".\n");
  656. /* Set for info when doing ifconfig */
  657. dev->mem_start = mem_ptr_phys;
  658. dev->mem_end = mem_ptr_phys + lp->memory_size;
  659. }
  660. printk("hp100: ");
  661. if (lp->lan_type != HP100_LAN_ERR)
  662. printk("Adapter is attached to ");
  663. switch (lp->lan_type) {
  664. case HP100_LAN_100:
  665. printk("100Mb/s Voice Grade AnyLAN network.\n");
  666. break;
  667. case HP100_LAN_10:
  668. printk("10Mb/s network (10baseT).\n");
  669. break;
  670. case HP100_LAN_COAX:
  671. printk("10Mb/s network (coax).\n");
  672. break;
  673. default:
  674. printk("Warning! Link down.\n");
  675. }
  676. err = register_netdev(dev);
  677. if (err)
  678. goto out3;
  679. return 0;
  680. out3:
  681. if (local_mode == 1)
  682. pci_free_consistent(lp->pci_dev, MAX_RINGSIZE + 0x0f,
  683. lp->page_vaddr_algn,
  684. virt_to_whatever(dev, lp->page_vaddr_algn));
  685. if (mem_ptr_virt)
  686. iounmap(mem_ptr_virt);
  687. out2:
  688. release_region(ioaddr, HP100_REGION_SIZE);
  689. out1:
  690. return err;
  691. }
  692. /* This procedure puts the card into a stable init state */
  693. static void hp100_hwinit(struct net_device *dev)
  694. {
  695. int ioaddr = dev->base_addr;
  696. struct hp100_private *lp = netdev_priv(dev);
  697. #ifdef HP100_DEBUG_B
  698. hp100_outw(0x4202, TRACE);
  699. printk("hp100: %s: hwinit\n", dev->name);
  700. #endif
  701. /* Initialise the card. -------------------------------------------- */
  702. /* Clear all pending Ints and disable Ints */
  703. hp100_page(PERFORMANCE);
  704. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  705. hp100_outw(0xffff, IRQ_STATUS); /* clear all pending ints */
  706. hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
  707. hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
  708. if (lp->mode == 1) {
  709. hp100_BM_shutdown(dev); /* disables BM, puts cascade in reset */
  710. wait();
  711. } else {
  712. hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
  713. hp100_cascade_reset(dev, 1);
  714. hp100_page(MAC_CTRL);
  715. hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);
  716. }
  717. /* Initiate EEPROM reload */
  718. hp100_load_eeprom(dev, 0);
  719. wait();
  720. /* Go into reset again. */
  721. hp100_cascade_reset(dev, 1);
  722. /* Set Option Registers to a safe state */
  723. hp100_outw(HP100_DEBUG_EN |
  724. HP100_RX_HDR |
  725. HP100_EE_EN |
  726. HP100_BM_WRITE |
  727. HP100_BM_READ | HP100_RESET_HB |
  728. HP100_FAKE_INT |
  729. HP100_INT_EN |
  730. HP100_MEM_EN |
  731. HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);
  732. hp100_outw(HP100_TRI_INT |
  733. HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW);
  734. hp100_outb(HP100_PRIORITY_TX |
  735. HP100_ADV_NXT_PKT |
  736. HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW);
  737. /* TODO: Configure MMU for Ram Test. */
  738. /* TODO: Ram Test. */
  739. /* Re-check if adapter is still at same i/o location */
  740. /* (If the base i/o in eeprom has been changed but the */
  741. /* registers had not been changed, a reload of the eeprom */
  742. /* would move the adapter to the address stored in eeprom */
  743. /* TODO: Code to implement. */
  744. /* Until here it was code from HWdiscover procedure. */
  745. /* Next comes code from mmuinit procedure of SCO BM driver which is
  746. * called from HWconfigure in the SCO driver. */
  747. /* Initialise MMU, eventually switch on Busmaster Mode, initialise
  748. * multicast filter...
  749. */
  750. hp100_mmuinit(dev);
  751. /* We don't turn the interrupts on here - this is done by start_interface. */
  752. wait(); /* TODO: Do we really need this? */
  753. /* Enable Hardware (e.g. unreset) */
  754. hp100_cascade_reset(dev, 0);
  755. /* ------- initialisation complete ----------- */
  756. /* Finally try to log in the Hub if there may be a VG connection. */
  757. if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR))
  758. hp100_login_to_vg_hub(dev, 0); /* relogin */
  759. }
  760. /*
  761. * mmuinit - Reinitialise Cascade MMU and MAC settings.
  762. * Note: Must already be in reset and leaves card in reset.
  763. */
  764. static void hp100_mmuinit(struct net_device *dev)
  765. {
  766. int ioaddr = dev->base_addr;
  767. struct hp100_private *lp = netdev_priv(dev);
  768. int i;
  769. #ifdef HP100_DEBUG_B
  770. hp100_outw(0x4203, TRACE);
  771. printk("hp100: %s: mmuinit\n", dev->name);
  772. #endif
  773. #ifdef HP100_DEBUG
  774. if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) {
  775. printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n", dev->name);
  776. return;
  777. }
  778. #endif
  779. /* Make sure IRQs are masked off and ack'ed. */
  780. hp100_page(PERFORMANCE);
  781. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  782. hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
  783. /*
  784. * Enable Hardware
  785. * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En
  786. * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable
  787. * - Clear Priority, Advance Pkt and Xmit Cmd
  788. */
  789. hp100_outw(HP100_DEBUG_EN |
  790. HP100_RX_HDR |
  791. HP100_EE_EN | HP100_RESET_HB |
  792. HP100_IO_EN |
  793. HP100_FAKE_INT |
  794. HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
  795. hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);
  796. if (lp->mode == 1) { /* busmaster */
  797. hp100_outw(HP100_BM_WRITE |
  798. HP100_BM_READ |
  799. HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW);
  800. } else if (lp->mode == 2) { /* memory mapped */
  801. hp100_outw(HP100_BM_WRITE |
  802. HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);
  803. hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW);
  804. hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);
  805. hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
  806. } else if (lp->mode == 3) { /* i/o mapped mode */
  807. hp100_outw(HP100_MMAP_DIS | HP100_SET_HB |
  808. HP100_IO_EN | HP100_SET_LB, OPTION_LSW);
  809. }
  810. hp100_page(HW_MAP);
  811. hp100_outb(0, EARLYRXCFG);
  812. hp100_outw(0, EARLYTXCFG);
  813. /*
  814. * Enable Bus Master mode
  815. */
  816. if (lp->mode == 1) { /* busmaster */
  817. /* Experimental: Set some PCI configuration bits */
  818. hp100_page(HW_MAP);
  819. hp100_andb(~HP100_PDL_USE3, MODECTRL1); /* BM engine read maximum */
  820. hp100_andb(~HP100_TX_DUALQ, MODECTRL1); /* No Queue for Priority TX */
  821. /* PCI Bus failures should result in a Misc. Interrupt */
  822. hp100_orb(HP100_EN_BUS_FAIL, MODECTRL2);
  823. hp100_outw(HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW);
  824. hp100_page(HW_MAP);
  825. /* Use Burst Mode and switch on PAGE_CK */
  826. hp100_orb(HP100_BM_BURST_RD | HP100_BM_BURST_WR, BM);
  827. if ((lp->chip == HP100_CHIPID_RAINIER) || (lp->chip == HP100_CHIPID_SHASTA))
  828. hp100_orb(HP100_BM_PAGE_CK, BM);
  829. hp100_orb(HP100_BM_MASTER, BM);
  830. } else { /* not busmaster */
  831. hp100_page(HW_MAP);
  832. hp100_andb(~HP100_BM_MASTER, BM);
  833. }
  834. /*
  835. * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs
  836. */
  837. hp100_page(MMU_CFG);
  838. if (lp->mode == 1) { /* only needed for Busmaster */
  839. int xmit_stop, recv_stop;
  840. if ((lp->chip == HP100_CHIPID_RAINIER)
  841. || (lp->chip == HP100_CHIPID_SHASTA)) {
  842. int pdl_stop;
  843. /*
  844. * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and
  845. * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded
  846. * to the next higher 1k boundary) bytes for the rx-pdl's
  847. * Note: For non-etr chips the transmit stop register must be
  848. * programmed on a 1k boundary, i.e. bits 9:0 must be zero.
  849. */
  850. pdl_stop = lp->memory_size;
  851. xmit_stop = (pdl_stop - 508 * (MAX_RX_PDL) - 16) & ~(0x03ff);
  852. recv_stop = (xmit_stop * (lp->rx_ratio) / 100) & ~(0x03ff);
  853. hp100_outw((pdl_stop >> 4) - 1, PDL_MEM_STOP);
  854. #ifdef HP100_DEBUG_BM
  855. printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop);
  856. #endif
  857. } else {
  858. /* ETR chip (Lassen) in busmaster mode */
  859. xmit_stop = (lp->memory_size) - 1;
  860. recv_stop = ((lp->memory_size * lp->rx_ratio) / 100) & ~(0x03ff);
  861. }
  862. hp100_outw(xmit_stop >> 4, TX_MEM_STOP);
  863. hp100_outw(recv_stop >> 4, RX_MEM_STOP);
  864. #ifdef HP100_DEBUG_BM
  865. printk("hp100: %s: TX_STOP = 0x%x\n", dev->name, xmit_stop >> 4);
  866. printk("hp100: %s: RX_STOP = 0x%x\n", dev->name, recv_stop >> 4);
  867. #endif
  868. } else {
  869. /* Slave modes (memory mapped and programmed io) */
  870. hp100_outw((((lp->memory_size * lp->rx_ratio) / 100) >> 4), RX_MEM_STOP);
  871. hp100_outw(((lp->memory_size - 1) >> 4), TX_MEM_STOP);
  872. #ifdef HP100_DEBUG
  873. printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(TX_MEM_STOP));
  874. printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(RX_MEM_STOP));
  875. #endif
  876. }
  877. /* Write MAC address into page 1 */
  878. hp100_page(MAC_ADDRESS);
  879. for (i = 0; i < 6; i++)
  880. hp100_outb(dev->dev_addr[i], MAC_ADDR + i);
  881. /* Zero the multicast hash registers */
  882. for (i = 0; i < 8; i++)
  883. hp100_outb(0x0, HASH_BYTE0 + i);
  884. /* Set up MAC defaults */
  885. hp100_page(MAC_CTRL);
  886. /* Go to LAN Page and zero all filter bits */
  887. /* Zero accept error, accept multicast, accept broadcast and accept */
  888. /* all directed packet bits */
  889. hp100_andb(~(HP100_RX_EN |
  890. HP100_TX_EN |
  891. HP100_ACC_ERRORED |
  892. HP100_ACC_MC |
  893. HP100_ACC_BC | HP100_ACC_PHY), MAC_CFG_1);
  894. hp100_outb(0x00, MAC_CFG_2);
  895. /* Zero the frame format bit. This works around a training bug in the */
  896. /* new hubs. */
  897. hp100_outb(0x00, VG_LAN_CFG_2); /* (use 802.3) */
  898. if (lp->priority_tx)
  899. hp100_outb(HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW);
  900. else
  901. hp100_outb(HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW);
  902. hp100_outb(HP100_ADV_NXT_PKT |
  903. HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW);
  904. /* If busmaster, initialize the PDLs */
  905. if (lp->mode == 1)
  906. hp100_init_pdls(dev);
  907. /* Go to performance page and initalize isr and imr registers */
  908. hp100_page(PERFORMANCE);
  909. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  910. hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
  911. }
  912. /*
  913. * open/close functions
  914. */
  915. static int hp100_open(struct net_device *dev)
  916. {
  917. struct hp100_private *lp = netdev_priv(dev);
  918. #ifdef HP100_DEBUG_B
  919. int ioaddr = dev->base_addr;
  920. #endif
  921. #ifdef HP100_DEBUG_B
  922. hp100_outw(0x4204, TRACE);
  923. printk("hp100: %s: open\n", dev->name);
  924. #endif
  925. /* New: if bus is PCI or EISA, interrupts might be shared interrupts */
  926. if (request_irq(dev->irq, hp100_interrupt,
  927. lp->bus == HP100_BUS_PCI || lp->bus ==
  928. HP100_BUS_EISA ? IRQF_SHARED : IRQF_DISABLED,
  929. "hp100", dev)) {
  930. printk("hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq);
  931. return -EAGAIN;
  932. }
  933. dev->trans_start = jiffies;
  934. netif_start_queue(dev);
  935. lp->lan_type = hp100_sense_lan(dev);
  936. lp->mac1_mode = HP100_MAC1MODE3;
  937. lp->mac2_mode = HP100_MAC2MODE3;
  938. memset(&lp->hash_bytes, 0x00, 8);
  939. hp100_stop_interface(dev);
  940. hp100_hwinit(dev);
  941. hp100_start_interface(dev); /* sets mac modes, enables interrupts */
  942. return 0;
  943. }
  944. /* The close function is called when the interface is to be brought down */
  945. static int hp100_close(struct net_device *dev)
  946. {
  947. int ioaddr = dev->base_addr;
  948. struct hp100_private *lp = netdev_priv(dev);
  949. #ifdef HP100_DEBUG_B
  950. hp100_outw(0x4205, TRACE);
  951. printk("hp100: %s: close\n", dev->name);
  952. #endif
  953. hp100_page(PERFORMANCE);
  954. hp100_outw(0xfefe, IRQ_MASK); /* mask off all IRQs */
  955. hp100_stop_interface(dev);
  956. if (lp->lan_type == HP100_LAN_100)
  957. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  958. netif_stop_queue(dev);
  959. free_irq(dev->irq, dev);
  960. #ifdef HP100_DEBUG
  961. printk("hp100: %s: close LSW = 0x%x\n", dev->name,
  962. hp100_inw(OPTION_LSW));
  963. #endif
  964. return 0;
  965. }
  966. /*
  967. * Configure the PDL Rx rings and LAN
  968. */
  969. static void hp100_init_pdls(struct net_device *dev)
  970. {
  971. struct hp100_private *lp = netdev_priv(dev);
  972. hp100_ring_t *ringptr;
  973. u_int *pageptr; /* Warning : increment by 4 - Jean II */
  974. int i;
  975. #ifdef HP100_DEBUG_B
  976. int ioaddr = dev->base_addr;
  977. #endif
  978. #ifdef HP100_DEBUG_B
  979. hp100_outw(0x4206, TRACE);
  980. printk("hp100: %s: init pdls\n", dev->name);
  981. #endif
  982. if (!lp->page_vaddr_algn)
  983. printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n", dev->name);
  984. else {
  985. /* pageptr shall point into the DMA accessible memory region */
  986. /* we use this pointer to status the upper limit of allocated */
  987. /* memory in the allocated page. */
  988. /* note: align the pointers to the pci cache line size */
  989. memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero Rx/Tx ring page */
  990. pageptr = lp->page_vaddr_algn;
  991. lp->rxrcommit = 0;
  992. ringptr = lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);
  993. /* Initialise Rx Ring */
  994. for (i = MAX_RX_PDL - 1; i >= 0; i--) {
  995. lp->rxring[i].next = ringptr;
  996. ringptr = &(lp->rxring[i]);
  997. pageptr += hp100_init_rxpdl(dev, ringptr, pageptr);
  998. }
  999. /* Initialise Tx Ring */
  1000. lp->txrcommit = 0;
  1001. ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]);
  1002. for (i = MAX_TX_PDL - 1; i >= 0; i--) {
  1003. lp->txring[i].next = ringptr;
  1004. ringptr = &(lp->txring[i]);
  1005. pageptr += hp100_init_txpdl(dev, ringptr, pageptr);
  1006. }
  1007. }
  1008. }
  1009. /* These functions "format" the entries in the pdl structure */
  1010. /* They return how much memory the fragments need. */
  1011. static int hp100_init_rxpdl(struct net_device *dev,
  1012. register hp100_ring_t * ringptr,
  1013. register u32 * pdlptr)
  1014. {
  1015. /* pdlptr is starting address for this pdl */
  1016. if (0 != (((unsigned long) pdlptr) & 0xf))
  1017. printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%lx.\n",
  1018. dev->name, (unsigned long) pdlptr);
  1019. ringptr->pdl = pdlptr + 1;
  1020. ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr + 1);
  1021. ringptr->skb = (void *) NULL;
  1022. /*
  1023. * Write address and length of first PDL Fragment (which is used for
  1024. * storing the RX-Header
  1025. * We use the 4 bytes _before_ the PDH in the pdl memory area to
  1026. * store this information. (PDH is at offset 0x04)
  1027. */
  1028. /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */
  1029. *(pdlptr + 2) = (u_int) virt_to_whatever(dev, pdlptr); /* Address Frag 1 */
  1030. *(pdlptr + 3) = 4; /* Length Frag 1 */
  1031. return roundup(MAX_RX_FRAG * 2 + 2, 4);
  1032. }
  1033. static int hp100_init_txpdl(struct net_device *dev,
  1034. register hp100_ring_t * ringptr,
  1035. register u32 * pdlptr)
  1036. {
  1037. if (0 != (((unsigned long) pdlptr) & 0xf))
  1038. printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%lx.\n", dev->name, (unsigned long) pdlptr);
  1039. ringptr->pdl = pdlptr; /* +1; */
  1040. ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr); /* +1 */
  1041. ringptr->skb = (void *) NULL;
  1042. return roundup(MAX_TX_FRAG * 2 + 2, 4);
  1043. }
  1044. /*
  1045. * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes
  1046. * for possible odd word alignment rounding up to next dword and set PDL
  1047. * address for fragment#2
  1048. * Returns: 0 if unable to allocate skb_buff
  1049. * 1 if successful
  1050. */
  1051. static int hp100_build_rx_pdl(hp100_ring_t * ringptr,
  1052. struct net_device *dev)
  1053. {
  1054. #ifdef HP100_DEBUG_B
  1055. int ioaddr = dev->base_addr;
  1056. #endif
  1057. #ifdef HP100_DEBUG_BM
  1058. u_int *p;
  1059. #endif
  1060. #ifdef HP100_DEBUG_B
  1061. hp100_outw(0x4207, TRACE);
  1062. printk("hp100: %s: build rx pdl\n", dev->name);
  1063. #endif
  1064. /* Allocate skb buffer of maximum size */
  1065. /* Note: This depends on the alloc_skb functions allocating more
  1066. * space than requested, i.e. aligning to 16bytes */
  1067. ringptr->skb = dev_alloc_skb(roundup(MAX_ETHER_SIZE + 2, 4));
  1068. if (NULL != ringptr->skb) {
  1069. /*
  1070. * Reserve 2 bytes at the head of the buffer to land the IP header
  1071. * on a long word boundary (According to the Network Driver section
  1072. * in the Linux KHG, this should help to increase performance.)
  1073. */
  1074. skb_reserve(ringptr->skb, 2);
  1075. ringptr->skb->dev = dev;
  1076. ringptr->skb->data = (u_char *) skb_put(ringptr->skb, MAX_ETHER_SIZE);
  1077. /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */
  1078. /* Note: 1st Fragment is used for the 4 byte packet status
  1079. * (receive header). Its PDL entries are set up by init_rxpdl. So
  1080. * here we only have to set up the PDL fragment entries for the data
  1081. * part. Those 4 bytes will be stored in the DMA memory region
  1082. * directly before the PDL.
  1083. */
  1084. #ifdef HP100_DEBUG_BM
  1085. printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n",
  1086. dev->name, (u_int) ringptr->pdl,
  1087. roundup(MAX_ETHER_SIZE + 2, 4),
  1088. (unsigned int) ringptr->skb->data);
  1089. #endif
  1090. /* Conversion to new PCI API : map skbuf data to PCI bus.
  1091. * Doc says it's OK for EISA as well - Jean II */
  1092. ringptr->pdl[0] = 0x00020000; /* Write PDH */
  1093. ringptr->pdl[3] = pdl_map_data(netdev_priv(dev),
  1094. ringptr->skb->data);
  1095. ringptr->pdl[4] = MAX_ETHER_SIZE; /* Length of Data */
  1096. #ifdef HP100_DEBUG_BM
  1097. for (p = (ringptr->pdl); p < (ringptr->pdl + 5); p++)
  1098. printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n", dev->name, (u_int) p, (u_int) * p);
  1099. #endif
  1100. return (1);
  1101. }
  1102. /* else: */
  1103. /* alloc_skb failed (no memory) -> still can receive the header
  1104. * fragment into PDL memory. make PDL safe by clearing msgptr and
  1105. * making the PDL only 1 fragment (i.e. the 4 byte packet status)
  1106. */
  1107. #ifdef HP100_DEBUG_BM
  1108. printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n", dev->name, (u_int) ringptr->pdl);
  1109. #endif
  1110. ringptr->pdl[0] = 0x00010000; /* PDH: Count=1 Fragment */
  1111. return (0);
  1112. }
  1113. /*
  1114. * hp100_rxfill - attempt to fill the Rx Ring will empty skb's
  1115. *
  1116. * Makes assumption that skb's are always contiguous memory areas and
  1117. * therefore PDLs contain only 2 physical fragments.
  1118. * - While the number of Rx PDLs with buffers is less than maximum
  1119. * a. Get a maximum packet size skb
  1120. * b. Put the physical address of the buffer into the PDL.
  1121. * c. Output physical address of PDL to adapter.
  1122. */
  1123. static void hp100_rxfill(struct net_device *dev)
  1124. {
  1125. int ioaddr = dev->base_addr;
  1126. struct hp100_private *lp = netdev_priv(dev);
  1127. hp100_ring_t *ringptr;
  1128. #ifdef HP100_DEBUG_B
  1129. hp100_outw(0x4208, TRACE);
  1130. printk("hp100: %s: rxfill\n", dev->name);
  1131. #endif
  1132. hp100_page(PERFORMANCE);
  1133. while (lp->rxrcommit < MAX_RX_PDL) {
  1134. /*
  1135. ** Attempt to get a buffer and build a Rx PDL.
  1136. */
  1137. ringptr = lp->rxrtail;
  1138. if (0 == hp100_build_rx_pdl(ringptr, dev)) {
  1139. return; /* None available, return */
  1140. }
  1141. /* Hand this PDL over to the card */
  1142. /* Note: This needs performance page selected! */
  1143. #ifdef HP100_DEBUG_BM
  1144. printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n",
  1145. dev->name, lp->rxrcommit, (u_int) ringptr->pdl,
  1146. (u_int) ringptr->pdl_paddr, (u_int) ringptr->pdl[3]);
  1147. #endif
  1148. hp100_outl((u32) ringptr->pdl_paddr, RX_PDA);
  1149. lp->rxrcommit += 1;
  1150. lp->rxrtail = ringptr->next;
  1151. }
  1152. }
  1153. /*
  1154. * BM_shutdown - shutdown bus mastering and leave chip in reset state
  1155. */
  1156. static void hp100_BM_shutdown(struct net_device *dev)
  1157. {
  1158. int ioaddr = dev->base_addr;
  1159. struct hp100_private *lp = netdev_priv(dev);
  1160. unsigned long time;
  1161. #ifdef HP100_DEBUG_B
  1162. hp100_outw(0x4209, TRACE);
  1163. printk("hp100: %s: bm shutdown\n", dev->name);
  1164. #endif
  1165. hp100_page(PERFORMANCE);
  1166. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  1167. hp100_outw(0xffff, IRQ_STATUS); /* Ack all ints */
  1168. /* Ensure Interrupts are off */
  1169. hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
  1170. /* Disable all MAC activity */
  1171. hp100_page(MAC_CTRL);
  1172. hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */
  1173. /* If cascade MMU is not already in reset */
  1174. if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) {
  1175. /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so
  1176. * MMU pointers will not be reset out from underneath
  1177. */
  1178. hp100_page(MAC_CTRL);
  1179. for (time = 0; time < 5000; time++) {
  1180. if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE))
  1181. break;
  1182. }
  1183. /* Shutdown algorithm depends on the generation of Cascade */
  1184. if (lp->chip == HP100_CHIPID_LASSEN) { /* ETR shutdown/reset */
  1185. /* Disable Busmaster mode and wait for bit to go to zero. */
  1186. hp100_page(HW_MAP);
  1187. hp100_andb(~HP100_BM_MASTER, BM);
  1188. /* 100 ms timeout */
  1189. for (time = 0; time < 32000; time++) {
  1190. if (0 == (hp100_inb(BM) & HP100_BM_MASTER))
  1191. break;
  1192. }
  1193. } else { /* Shasta or Rainier Shutdown/Reset */
  1194. /* To ensure all bus master inloading activity has ceased,
  1195. * wait for no Rx PDAs or no Rx packets on card.
  1196. */
  1197. hp100_page(PERFORMANCE);
  1198. /* 100 ms timeout */
  1199. for (time = 0; time < 10000; time++) {
  1200. /* RX_PDL: PDLs not executed. */
  1201. /* RX_PKT_CNT: RX'd packets on card. */
  1202. if ((hp100_inb(RX_PDL) == 0) && (hp100_inb(RX_PKT_CNT) == 0))
  1203. break;
  1204. }
  1205. if (time >= 10000)
  1206. printk("hp100: %s: BM shutdown error.\n", dev->name);
  1207. /* To ensure all bus master outloading activity has ceased,
  1208. * wait until the Tx PDA count goes to zero or no more Tx space
  1209. * available in the Tx region of the card.
  1210. */
  1211. /* 100 ms timeout */
  1212. for (time = 0; time < 10000; time++) {
  1213. if ((0 == hp100_inb(TX_PKT_CNT)) &&
  1214. (0 != (hp100_inb(TX_MEM_FREE) & HP100_AUTO_COMPARE)))
  1215. break;
  1216. }
  1217. /* Disable Busmaster mode */
  1218. hp100_page(HW_MAP);
  1219. hp100_andb(~HP100_BM_MASTER, BM);
  1220. } /* end of shutdown procedure for non-etr parts */
  1221. hp100_cascade_reset(dev, 1);
  1222. }
  1223. hp100_page(PERFORMANCE);
  1224. /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
  1225. /* Busmaster mode should be shut down now. */
  1226. }
  1227. static int hp100_check_lan(struct net_device *dev)
  1228. {
  1229. struct hp100_private *lp = netdev_priv(dev);
  1230. if (lp->lan_type < 0) { /* no LAN type detected yet? */
  1231. hp100_stop_interface(dev);
  1232. if ((lp->lan_type = hp100_sense_lan(dev)) < 0) {
  1233. printk("hp100: %s: no connection found - check wire\n", dev->name);
  1234. hp100_start_interface(dev); /* 10Mb/s RX packets maybe handled */
  1235. return -EIO;
  1236. }
  1237. if (lp->lan_type == HP100_LAN_100)
  1238. lp->hub_status = hp100_login_to_vg_hub(dev, 0); /* relogin */
  1239. hp100_start_interface(dev);
  1240. }
  1241. return 0;
  1242. }
  1243. /*
  1244. * transmit functions
  1245. */
  1246. /* tx function for busmaster mode */
  1247. static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev)
  1248. {
  1249. unsigned long flags;
  1250. int i, ok_flag;
  1251. int ioaddr = dev->base_addr;
  1252. struct hp100_private *lp = netdev_priv(dev);
  1253. hp100_ring_t *ringptr;
  1254. #ifdef HP100_DEBUG_B
  1255. hp100_outw(0x4210, TRACE);
  1256. printk("hp100: %s: start_xmit_bm\n", dev->name);
  1257. #endif
  1258. if (skb == NULL) {
  1259. return 0;
  1260. }
  1261. if (skb->len <= 0)
  1262. return 0;
  1263. if (lp->chip == HP100_CHIPID_SHASTA && skb_padto(skb, ETH_ZLEN))
  1264. return 0;
  1265. /* Get Tx ring tail pointer */
  1266. if (lp->txrtail->next == lp->txrhead) {
  1267. /* No memory. */
  1268. #ifdef HP100_DEBUG
  1269. printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name);
  1270. #endif
  1271. /* not waited long enough since last tx? */
  1272. if (time_before(jiffies, dev->trans_start + HZ))
  1273. return -EAGAIN;
  1274. if (hp100_check_lan(dev))
  1275. return -EIO;
  1276. if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) {
  1277. /* we have a 100Mb/s adapter but it isn't connected to hub */
  1278. printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
  1279. hp100_stop_interface(dev);
  1280. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1281. hp100_start_interface(dev);
  1282. } else {
  1283. spin_lock_irqsave(&lp->lock, flags);
  1284. hp100_ints_off(); /* Useful ? Jean II */
  1285. i = hp100_sense_lan(dev);
  1286. hp100_ints_on();
  1287. spin_unlock_irqrestore(&lp->lock, flags);
  1288. if (i == HP100_LAN_ERR)
  1289. printk("hp100: %s: link down detected\n", dev->name);
  1290. else if (lp->lan_type != i) { /* cable change! */
  1291. /* it's very hard - all network settings must be changed!!! */
  1292. printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name);
  1293. lp->lan_type = i;
  1294. hp100_stop_interface(dev);
  1295. if (lp->lan_type == HP100_LAN_100)
  1296. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1297. hp100_start_interface(dev);
  1298. } else {
  1299. printk("hp100: %s: interface reset\n", dev->name);
  1300. hp100_stop_interface(dev);
  1301. if (lp->lan_type == HP100_LAN_100)
  1302. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1303. hp100_start_interface(dev);
  1304. }
  1305. }
  1306. dev->trans_start = jiffies;
  1307. return -EAGAIN;
  1308. }
  1309. /*
  1310. * we have to turn int's off before modifying this, otherwise
  1311. * a tx_pdl_cleanup could occur at the same time
  1312. */
  1313. spin_lock_irqsave(&lp->lock, flags);
  1314. ringptr = lp->txrtail;
  1315. lp->txrtail = ringptr->next;
  1316. /* Check whether packet has minimal packet size */
  1317. ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
  1318. i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
  1319. ringptr->skb = skb;
  1320. ringptr->pdl[0] = ((1 << 16) | i); /* PDH: 1 Fragment & length */
  1321. if (lp->chip == HP100_CHIPID_SHASTA) {
  1322. /* TODO:Could someone who has the EISA card please check if this works? */
  1323. ringptr->pdl[2] = i;
  1324. } else { /* Lassen */
  1325. /* In the PDL, don't use the padded size but the real packet size: */
  1326. ringptr->pdl[2] = skb->len; /* 1st Frag: Length of frag */
  1327. }
  1328. /* Conversion to new PCI API : map skbuf data to PCI bus.
  1329. * Doc says it's OK for EISA as well - Jean II */
  1330. ringptr->pdl[1] = ((u32) pci_map_single(lp->pci_dev, skb->data, ringptr->pdl[2], PCI_DMA_TODEVICE)); /* 1st Frag: Adr. of data */
  1331. /* Hand this PDL to the card. */
  1332. hp100_outl(ringptr->pdl_paddr, TX_PDA_L); /* Low Prio. Queue */
  1333. lp->txrcommit++;
  1334. spin_unlock_irqrestore(&lp->lock, flags);
  1335. /* Update statistics */
  1336. lp->stats.tx_packets++;
  1337. lp->stats.tx_bytes += skb->len;
  1338. dev->trans_start = jiffies;
  1339. return 0;
  1340. }
  1341. /* clean_txring checks if packets have been sent by the card by reading
  1342. * the TX_PDL register from the performance page and comparing it to the
  1343. * number of commited packets. It then frees the skb's of the packets that
  1344. * obviously have been sent to the network.
  1345. *
  1346. * Needs the PERFORMANCE page selected.
  1347. */
  1348. static void hp100_clean_txring(struct net_device *dev)
  1349. {
  1350. struct hp100_private *lp = netdev_priv(dev);
  1351. int ioaddr = dev->base_addr;
  1352. int donecount;
  1353. #ifdef HP100_DEBUG_B
  1354. hp100_outw(0x4211, TRACE);
  1355. printk("hp100: %s: clean txring\n", dev->name);
  1356. #endif
  1357. /* How many PDLs have been transmitted? */
  1358. donecount = (lp->txrcommit) - hp100_inb(TX_PDL);
  1359. #ifdef HP100_DEBUG
  1360. if (donecount > MAX_TX_PDL)
  1361. printk("hp100: %s: Warning: More PDLs transmitted than commited to card???\n", dev->name);
  1362. #endif
  1363. for (; 0 != donecount; donecount--) {
  1364. #ifdef HP100_DEBUG_BM
  1365. printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n",
  1366. dev->name, (u_int) lp->txrhead->skb->data,
  1367. lp->txrcommit, hp100_inb(TX_PDL), donecount);
  1368. #endif
  1369. /* Conversion to new PCI API : NOP */
  1370. pci_unmap_single(lp->pci_dev, (dma_addr_t) lp->txrhead->pdl[1], lp->txrhead->pdl[2], PCI_DMA_TODEVICE);
  1371. dev_kfree_skb_any(lp->txrhead->skb);
  1372. lp->txrhead->skb = (void *) NULL;
  1373. lp->txrhead = lp->txrhead->next;
  1374. lp->txrcommit--;
  1375. }
  1376. }
  1377. /* tx function for slave modes */
  1378. static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1379. {
  1380. unsigned long flags;
  1381. int i, ok_flag;
  1382. int ioaddr = dev->base_addr;
  1383. u_short val;
  1384. struct hp100_private *lp = netdev_priv(dev);
  1385. #ifdef HP100_DEBUG_B
  1386. hp100_outw(0x4212, TRACE);
  1387. printk("hp100: %s: start_xmit\n", dev->name);
  1388. #endif
  1389. if (skb == NULL) {
  1390. return 0;
  1391. }
  1392. if (skb->len <= 0)
  1393. return 0;
  1394. if (hp100_check_lan(dev))
  1395. return -EIO;
  1396. /* If there is not enough free memory on the card... */
  1397. i = hp100_inl(TX_MEM_FREE) & 0x7fffffff;
  1398. if (!(((i / 2) - 539) > (skb->len + 16) && (hp100_inb(TX_PKT_CNT) < 255))) {
  1399. #ifdef HP100_DEBUG
  1400. printk("hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i);
  1401. #endif
  1402. /* not waited long enough since last failed tx try? */
  1403. if (time_before(jiffies, dev->trans_start + HZ)) {
  1404. #ifdef HP100_DEBUG
  1405. printk("hp100: %s: trans_start timing problem\n",
  1406. dev->name);
  1407. #endif
  1408. return -EAGAIN;
  1409. }
  1410. if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) {
  1411. /* we have a 100Mb/s adapter but it isn't connected to hub */
  1412. printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
  1413. hp100_stop_interface(dev);
  1414. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1415. hp100_start_interface(dev);
  1416. } else {
  1417. spin_lock_irqsave(&lp->lock, flags);
  1418. hp100_ints_off(); /* Useful ? Jean II */
  1419. i = hp100_sense_lan(dev);
  1420. hp100_ints_on();
  1421. spin_unlock_irqrestore(&lp->lock, flags);
  1422. if (i == HP100_LAN_ERR)
  1423. printk("hp100: %s: link down detected\n", dev->name);
  1424. else if (lp->lan_type != i) { /* cable change! */
  1425. /* it's very hard - all network setting must be changed!!! */
  1426. printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name);
  1427. lp->lan_type = i;
  1428. hp100_stop_interface(dev);
  1429. if (lp->lan_type == HP100_LAN_100)
  1430. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1431. hp100_start_interface(dev);
  1432. } else {
  1433. printk("hp100: %s: interface reset\n", dev->name);
  1434. hp100_stop_interface(dev);
  1435. if (lp->lan_type == HP100_LAN_100)
  1436. lp->hub_status = hp100_login_to_vg_hub(dev, 0);
  1437. hp100_start_interface(dev);
  1438. mdelay(1);
  1439. }
  1440. }
  1441. dev->trans_start = jiffies;
  1442. return -EAGAIN;
  1443. }
  1444. for (i = 0; i < 6000 && (hp100_inb(OPTION_MSW) & HP100_TX_CMD); i++) {
  1445. #ifdef HP100_DEBUG_TX
  1446. printk("hp100: %s: start_xmit: busy\n", dev->name);
  1447. #endif
  1448. }
  1449. spin_lock_irqsave(&lp->lock, flags);
  1450. hp100_ints_off();
  1451. val = hp100_inw(IRQ_STATUS);
  1452. /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set
  1453. * when the current packet being transmitted on the wire is completed. */
  1454. hp100_outw(HP100_TX_COMPLETE, IRQ_STATUS);
  1455. #ifdef HP100_DEBUG_TX
  1456. printk("hp100: %s: start_xmit: irq_status=0x%.4x, irqmask=0x%.4x, len=%d\n",
  1457. dev->name, val, hp100_inw(IRQ_MASK), (int) skb->len);
  1458. #endif
  1459. ok_flag = skb->len >= HP100_MIN_PACKET_SIZE;
  1460. i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE;
  1461. hp100_outw(i, DATA32); /* tell card the total packet length */
  1462. hp100_outw(i, FRAGMENT_LEN); /* and first/only fragment length */
  1463. if (lp->mode == 2) { /* memory mapped */
  1464. /* Note: The J2585B needs alignment to 32bits here! */
  1465. memcpy_toio(lp->mem_ptr_virt, skb->data, (skb->len + 3) & ~3);
  1466. if (!ok_flag)
  1467. memset_io(lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len);
  1468. } else { /* programmed i/o */
  1469. outsl(ioaddr + HP100_REG_DATA32, skb->data,
  1470. (skb->len + 3) >> 2);
  1471. if (!ok_flag)
  1472. for (i = (skb->len + 3) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4)
  1473. hp100_outl(0, DATA32);
  1474. }
  1475. hp100_outb(HP100_TX_CMD | HP100_SET_LB, OPTION_MSW); /* send packet */
  1476. lp->stats.tx_packets++;
  1477. lp->stats.tx_bytes += skb->len;
  1478. dev->trans_start = jiffies;
  1479. hp100_ints_on();
  1480. spin_unlock_irqrestore(&lp->lock, flags);
  1481. dev_kfree_skb_any(skb);
  1482. #ifdef HP100_DEBUG_TX
  1483. printk("hp100: %s: start_xmit: end\n", dev->name);
  1484. #endif
  1485. return 0;
  1486. }
  1487. /*
  1488. * Receive Function (Non-Busmaster mode)
  1489. * Called when an "Receive Packet" interrupt occurs, i.e. the receive
  1490. * packet counter is non-zero.
  1491. * For non-busmaster, this function does the whole work of transfering
  1492. * the packet to the host memory and then up to higher layers via skb
  1493. * and netif_rx.
  1494. */
  1495. static void hp100_rx(struct net_device *dev)
  1496. {
  1497. int packets, pkt_len;
  1498. int ioaddr = dev->base_addr;
  1499. struct hp100_private *lp = netdev_priv(dev);
  1500. u_int header;
  1501. struct sk_buff *skb;
  1502. #ifdef DEBUG_B
  1503. hp100_outw(0x4213, TRACE);
  1504. printk("hp100: %s: rx\n", dev->name);
  1505. #endif
  1506. /* First get indication of received lan packet */
  1507. /* RX_PKT_CND indicates the number of packets which have been fully */
  1508. /* received onto the card but have not been fully transferred of the card */
  1509. packets = hp100_inb(RX_PKT_CNT);
  1510. #ifdef HP100_DEBUG_RX
  1511. if (packets > 1)
  1512. printk("hp100: %s: rx: waiting packets = %d\n", dev->name, packets);
  1513. #endif
  1514. while (packets-- > 0) {
  1515. /* If ADV_NXT_PKT is still set, we have to wait until the card has */
  1516. /* really advanced to the next packet. */
  1517. for (pkt_len = 0; pkt_len < 6000 && (hp100_inb(OPTION_MSW) & HP100_ADV_NXT_PKT); pkt_len++) {
  1518. #ifdef HP100_DEBUG_RX
  1519. printk ("hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets);
  1520. #endif
  1521. }
  1522. /* First we get the header, which contains information about the */
  1523. /* actual length of the received packet. */
  1524. if (lp->mode == 2) { /* memory mapped mode */
  1525. header = readl(lp->mem_ptr_virt);
  1526. } else /* programmed i/o */
  1527. header = hp100_inl(DATA32);
  1528. pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3;
  1529. #ifdef HP100_DEBUG_RX
  1530. printk("hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n",
  1531. dev->name, header & HP100_PKT_LEN_MASK,
  1532. (header >> 16) & 0xfff8, (header >> 16) & 7);
  1533. #endif
  1534. /* Now we allocate the skb and transfer the data into it. */
  1535. skb = dev_alloc_skb(pkt_len+2);
  1536. if (skb == NULL) { /* Not enough memory->drop packet */
  1537. #ifdef HP100_DEBUG
  1538. printk("hp100: %s: rx: couldn't allocate a sk_buff of size %d\n",
  1539. dev->name, pkt_len);
  1540. #endif
  1541. lp->stats.rx_dropped++;
  1542. } else { /* skb successfully allocated */
  1543. u_char *ptr;
  1544. skb_reserve(skb,2);
  1545. /* ptr to start of the sk_buff data area */
  1546. skb_put(skb, pkt_len);
  1547. ptr = skb->data;
  1548. /* Now transfer the data from the card into that area */
  1549. if (lp->mode == 2)
  1550. memcpy_fromio(ptr, lp->mem_ptr_virt,pkt_len);
  1551. else /* io mapped */
  1552. insl(ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2);
  1553. skb->protocol = eth_type_trans(skb, dev);
  1554. #ifdef HP100_DEBUG_RX
  1555. printk("hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  1556. dev->name, ptr[0], ptr[1], ptr[2], ptr[3],
  1557. ptr[4], ptr[5], ptr[6], ptr[7], ptr[8],
  1558. ptr[9], ptr[10], ptr[11]);
  1559. #endif
  1560. netif_rx(skb);
  1561. lp->stats.rx_packets++;
  1562. lp->stats.rx_bytes += pkt_len;
  1563. }
  1564. /* Indicate the card that we have got the packet */
  1565. hp100_outb(HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW);
  1566. switch (header & 0x00070000) {
  1567. case (HP100_MULTI_ADDR_HASH << 16):
  1568. case (HP100_MULTI_ADDR_NO_HASH << 16):
  1569. lp->stats.multicast++;
  1570. break;
  1571. }
  1572. } /* end of while(there are packets) loop */
  1573. #ifdef HP100_DEBUG_RX
  1574. printk("hp100_rx: %s: end\n", dev->name);
  1575. #endif
  1576. }
  1577. /*
  1578. * Receive Function for Busmaster Mode
  1579. */
  1580. static void hp100_rx_bm(struct net_device *dev)
  1581. {
  1582. int ioaddr = dev->base_addr;
  1583. struct hp100_private *lp = netdev_priv(dev);
  1584. hp100_ring_t *ptr;
  1585. u_int header;
  1586. int pkt_len;
  1587. #ifdef HP100_DEBUG_B
  1588. hp100_outw(0x4214, TRACE);
  1589. printk("hp100: %s: rx_bm\n", dev->name);
  1590. #endif
  1591. #ifdef HP100_DEBUG
  1592. if (0 == lp->rxrcommit) {
  1593. printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name);
  1594. return;
  1595. } else
  1596. /* RX_PKT_CNT states how many PDLs are currently formatted and available to
  1597. * the cards BM engine */
  1598. if ((hp100_inw(RX_PKT_CNT) & 0x00ff) >= lp->rxrcommit) {
  1599. printk("hp100: %s: More packets received than commited? RX_PKT_CNT=0x%x, commit=0x%x\n",
  1600. dev->name, hp100_inw(RX_PKT_CNT) & 0x00ff,
  1601. lp->rxrcommit);
  1602. return;
  1603. }
  1604. #endif
  1605. while ((lp->rxrcommit > hp100_inb(RX_PDL))) {
  1606. /*
  1607. * The packet was received into the pdl pointed to by lp->rxrhead (
  1608. * the oldest pdl in the ring
  1609. */
  1610. /* First we get the header, which contains information about the */
  1611. /* actual length of the received packet. */
  1612. ptr = lp->rxrhead;
  1613. header = *(ptr->pdl - 1);
  1614. pkt_len = (header & HP100_PKT_LEN_MASK);
  1615. /* Conversion to new PCI API : NOP */
  1616. pci_unmap_single(lp->pci_dev, (dma_addr_t) ptr->pdl[3], MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE);
  1617. #ifdef HP100_DEBUG_BM
  1618. printk("hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n",
  1619. dev->name, (u_int) (ptr->pdl - 1), (u_int) header,
  1620. pkt_len, (header >> 16) & 0xfff8, (header >> 16) & 7);
  1621. printk("hp100: %s: RX_PDL_COUNT:0x%x TX_PDL_COUNT:0x%x, RX_PKT_CNT=0x%x PDH=0x%x, Data@0x%x len=0x%x\n",
  1622. dev->name, hp100_inb(RX_PDL), hp100_inb(TX_PDL),
  1623. hp100_inb(RX_PKT_CNT), (u_int) * (ptr->pdl),
  1624. (u_int) * (ptr->pdl + 3), (u_int) * (ptr->pdl + 4));
  1625. #endif
  1626. if ((pkt_len >= MIN_ETHER_SIZE) &&
  1627. (pkt_len <= MAX_ETHER_SIZE)) {
  1628. if (ptr->skb == NULL) {
  1629. printk("hp100: %s: rx_bm: skb null\n", dev->name);
  1630. /* can happen if we only allocated room for the pdh due to memory shortage. */
  1631. lp->stats.rx_dropped++;
  1632. } else {
  1633. skb_trim(ptr->skb, pkt_len); /* Shorten it */
  1634. ptr->skb->protocol =
  1635. eth_type_trans(ptr->skb, dev);
  1636. netif_rx(ptr->skb); /* Up and away... */
  1637. lp->stats.rx_packets++;
  1638. lp->stats.rx_bytes += pkt_len;
  1639. }
  1640. switch (header & 0x00070000) {
  1641. case (HP100_MULTI_ADDR_HASH << 16):
  1642. case (HP100_MULTI_ADDR_NO_HASH << 16):
  1643. lp->stats.multicast++;
  1644. break;
  1645. }
  1646. } else {
  1647. #ifdef HP100_DEBUG
  1648. printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n", dev->name, pkt_len);
  1649. #endif
  1650. if (ptr->skb != NULL)
  1651. dev_kfree_skb_any(ptr->skb);
  1652. lp->stats.rx_errors++;
  1653. }
  1654. lp->rxrhead = lp->rxrhead->next;
  1655. /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */
  1656. if (0 == hp100_build_rx_pdl(lp->rxrtail, dev)) {
  1657. /* No space for skb, header can still be received. */
  1658. #ifdef HP100_DEBUG
  1659. printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name);
  1660. #endif
  1661. return;
  1662. } else { /* successfully allocated new PDL - put it in ringlist at tail. */
  1663. hp100_outl((u32) lp->rxrtail->pdl_paddr, RX_PDA);
  1664. lp->rxrtail = lp->rxrtail->next;
  1665. }
  1666. }
  1667. }
  1668. /*
  1669. * statistics
  1670. */
  1671. static struct net_device_stats *hp100_get_stats(struct net_device *dev)
  1672. {
  1673. unsigned long flags;
  1674. int ioaddr = dev->base_addr;
  1675. struct hp100_private *lp = netdev_priv(dev);
  1676. #ifdef HP100_DEBUG_B
  1677. hp100_outw(0x4215, TRACE);
  1678. #endif
  1679. spin_lock_irqsave(&lp->lock, flags);
  1680. hp100_ints_off(); /* Useful ? Jean II */
  1681. hp100_update_stats(dev);
  1682. hp100_ints_on();
  1683. spin_unlock_irqrestore(&lp->lock, flags);
  1684. return &(lp->stats);
  1685. }
  1686. static void hp100_update_stats(struct net_device *dev)
  1687. {
  1688. int ioaddr = dev->base_addr;
  1689. u_short val;
  1690. struct hp100_private *lp = netdev_priv(dev);
  1691. #ifdef HP100_DEBUG_B
  1692. hp100_outw(0x4216, TRACE);
  1693. printk("hp100: %s: update-stats\n", dev->name);
  1694. #endif
  1695. /* Note: Statistics counters clear when read. */
  1696. hp100_page(MAC_CTRL);
  1697. val = hp100_inw(DROPPED) & 0x0fff;
  1698. lp->stats.rx_errors += val;
  1699. lp->stats.rx_over_errors += val;
  1700. val = hp100_inb(CRC);
  1701. lp->stats.rx_errors += val;
  1702. lp->stats.rx_crc_errors += val;
  1703. val = hp100_inb(ABORT);
  1704. lp->stats.tx_errors += val;
  1705. lp->stats.tx_aborted_errors += val;
  1706. hp100_page(PERFORMANCE);
  1707. }
  1708. static void hp100_misc_interrupt(struct net_device *dev)
  1709. {
  1710. #ifdef HP100_DEBUG_B
  1711. int ioaddr = dev->base_addr;
  1712. #endif
  1713. struct hp100_private *lp = netdev_priv(dev);
  1714. #ifdef HP100_DEBUG_B
  1715. int ioaddr = dev->base_addr;
  1716. hp100_outw(0x4216, TRACE);
  1717. printk("hp100: %s: misc_interrupt\n", dev->name);
  1718. #endif
  1719. /* Note: Statistics counters clear when read. */
  1720. lp->stats.rx_errors++;
  1721. lp->stats.tx_errors++;
  1722. }
  1723. static void hp100_clear_stats(struct hp100_private *lp, int ioaddr)
  1724. {
  1725. unsigned long flags;
  1726. #ifdef HP100_DEBUG_B
  1727. hp100_outw(0x4217, TRACE);
  1728. printk("hp100: %s: clear_stats\n", dev->name);
  1729. #endif
  1730. spin_lock_irqsave(&lp->lock, flags);
  1731. hp100_page(MAC_CTRL); /* get all statistics bytes */
  1732. hp100_inw(DROPPED);
  1733. hp100_inb(CRC);
  1734. hp100_inb(ABORT);
  1735. hp100_page(PERFORMANCE);
  1736. spin_unlock_irqrestore(&lp->lock, flags);
  1737. }
  1738. /*
  1739. * multicast setup
  1740. */
  1741. /*
  1742. * Set or clear the multicast filter for this adapter.
  1743. */
  1744. static void hp100_set_multicast_list(struct net_device *dev)
  1745. {
  1746. unsigned long flags;
  1747. int ioaddr = dev->base_addr;
  1748. struct hp100_private *lp = netdev_priv(dev);
  1749. #ifdef HP100_DEBUG_B
  1750. hp100_outw(0x4218, TRACE);
  1751. printk("hp100: %s: set_mc_list\n", dev->name);
  1752. #endif
  1753. spin_lock_irqsave(&lp->lock, flags);
  1754. hp100_ints_off();
  1755. hp100_page(MAC_CTRL);
  1756. hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */
  1757. if (dev->flags & IFF_PROMISC) {
  1758. lp->mac2_mode = HP100_MAC2MODE6; /* promiscuous mode = get all good */
  1759. lp->mac1_mode = HP100_MAC1MODE6; /* packets on the net */
  1760. memset(&lp->hash_bytes, 0xff, 8);
  1761. } else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
  1762. lp->mac2_mode = HP100_MAC2MODE5; /* multicast mode = get packets for */
  1763. lp->mac1_mode = HP100_MAC1MODE5; /* me, broadcasts and all multicasts */
  1764. #ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */
  1765. if (dev->flags & IFF_ALLMULTI) {
  1766. /* set hash filter to receive all multicast packets */
  1767. memset(&lp->hash_bytes, 0xff, 8);
  1768. } else {
  1769. int i, j, idx;
  1770. u_char *addrs;
  1771. struct dev_mc_list *dmi;
  1772. memset(&lp->hash_bytes, 0x00, 8);
  1773. #ifdef HP100_DEBUG
  1774. printk("hp100: %s: computing hash filter - mc_count = %i\n", dev->name, dev->mc_count);
  1775. #endif
  1776. for (i = 0, dmi = dev->mc_list; i < dev->mc_count; i++, dmi = dmi->next) {
  1777. addrs = dmi->dmi_addr;
  1778. if ((*addrs & 0x01) == 0x01) { /* multicast address? */
  1779. #ifdef HP100_DEBUG
  1780. printk("hp100: %s: multicast = %pM, ",
  1781. dev->name, addrs);
  1782. #endif
  1783. for (j = idx = 0; j < 6; j++) {
  1784. idx ^= *addrs++ & 0x3f;
  1785. printk(":%02x:", idx);
  1786. }
  1787. #ifdef HP100_DEBUG
  1788. printk("idx = %i\n", idx);
  1789. #endif
  1790. lp->hash_bytes[idx >> 3] |= (1 << (idx & 7));
  1791. }
  1792. }
  1793. }
  1794. #else
  1795. memset(&lp->hash_bytes, 0xff, 8);
  1796. #endif
  1797. } else {
  1798. lp->mac2_mode = HP100_MAC2MODE3; /* normal mode = get packets for me */
  1799. lp->mac1_mode = HP100_MAC1MODE3; /* and broadcasts */
  1800. memset(&lp->hash_bytes, 0x00, 8);
  1801. }
  1802. if (((hp100_inb(MAC_CFG_1) & 0x0f) != lp->mac1_mode) ||
  1803. (hp100_inb(MAC_CFG_2) != lp->mac2_mode)) {
  1804. int i;
  1805. hp100_outb(lp->mac2_mode, MAC_CFG_2);
  1806. hp100_andb(HP100_MAC1MODEMASK, MAC_CFG_1); /* clear mac1 mode bits */
  1807. hp100_orb(lp->mac1_mode, MAC_CFG_1); /* and set the new mode */
  1808. hp100_page(MAC_ADDRESS);
  1809. for (i = 0; i < 8; i++)
  1810. hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i);
  1811. #ifdef HP100_DEBUG
  1812. printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  1813. dev->name, lp->mac1_mode, lp->mac2_mode,
  1814. lp->hash_bytes[0], lp->hash_bytes[1],
  1815. lp->hash_bytes[2], lp->hash_bytes[3],
  1816. lp->hash_bytes[4], lp->hash_bytes[5],
  1817. lp->hash_bytes[6], lp->hash_bytes[7]);
  1818. #endif
  1819. if (lp->lan_type == HP100_LAN_100) {
  1820. #ifdef HP100_DEBUG
  1821. printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
  1822. #endif
  1823. lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */
  1824. }
  1825. } else {
  1826. int i;
  1827. u_char old_hash_bytes[8];
  1828. hp100_page(MAC_ADDRESS);
  1829. for (i = 0; i < 8; i++)
  1830. old_hash_bytes[i] = hp100_inb(HASH_BYTE0 + i);
  1831. if (memcmp(old_hash_bytes, &lp->hash_bytes, 8)) {
  1832. for (i = 0; i < 8; i++)
  1833. hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i);
  1834. #ifdef HP100_DEBUG
  1835. printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  1836. dev->name, lp->hash_bytes[0],
  1837. lp->hash_bytes[1], lp->hash_bytes[2],
  1838. lp->hash_bytes[3], lp->hash_bytes[4],
  1839. lp->hash_bytes[5], lp->hash_bytes[6],
  1840. lp->hash_bytes[7]);
  1841. #endif
  1842. if (lp->lan_type == HP100_LAN_100) {
  1843. #ifdef HP100_DEBUG
  1844. printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
  1845. #endif
  1846. lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */
  1847. }
  1848. }
  1849. }
  1850. hp100_page(MAC_CTRL);
  1851. hp100_orb(HP100_RX_EN | HP100_RX_IDLE | /* enable rx */
  1852. HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1); /* enable tx */
  1853. hp100_page(PERFORMANCE);
  1854. hp100_ints_on();
  1855. spin_unlock_irqrestore(&lp->lock, flags);
  1856. }
  1857. /*
  1858. * hardware interrupt handling
  1859. */
  1860. static irqreturn_t hp100_interrupt(int irq, void *dev_id)
  1861. {
  1862. struct net_device *dev = (struct net_device *) dev_id;
  1863. struct hp100_private *lp = netdev_priv(dev);
  1864. int ioaddr;
  1865. u_int val;
  1866. if (dev == NULL)
  1867. return IRQ_NONE;
  1868. ioaddr = dev->base_addr;
  1869. spin_lock(&lp->lock);
  1870. hp100_ints_off();
  1871. #ifdef HP100_DEBUG_B
  1872. hp100_outw(0x4219, TRACE);
  1873. #endif
  1874. /* hp100_page( PERFORMANCE ); */
  1875. val = hp100_inw(IRQ_STATUS);
  1876. #ifdef HP100_DEBUG_IRQ
  1877. printk("hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n",
  1878. dev->name, lp->mode, (u_int) val, hp100_inb(RX_PKT_CNT),
  1879. hp100_inb(RX_PDL), hp100_inb(TX_PKT_CNT), hp100_inb(TX_PDL));
  1880. #endif
  1881. if (val == 0) { /* might be a shared interrupt */
  1882. spin_unlock(&lp->lock);
  1883. hp100_ints_on();
  1884. return IRQ_NONE;
  1885. }
  1886. /* We're only interested in those interrupts we really enabled. */
  1887. /* val &= hp100_inw( IRQ_MASK ); */
  1888. /*
  1889. * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL
  1890. * is considered executed whenever the RX_PDL data structure is no longer
  1891. * needed.
  1892. */
  1893. if (val & HP100_RX_PDL_FILL_COMPL) {
  1894. if (lp->mode == 1)
  1895. hp100_rx_bm(dev);
  1896. else {
  1897. printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name);
  1898. }
  1899. }
  1900. /*
  1901. * The RX_PACKET interrupt is set, when the receive packet counter is
  1902. * non zero. We use this interrupt for receiving in slave mode. In
  1903. * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill
  1904. * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then
  1905. * we somehow have missed a rx_pdl_fill_compl interrupt.
  1906. */
  1907. if (val & HP100_RX_PACKET) { /* Receive Packet Counter is non zero */
  1908. if (lp->mode != 1) /* non busmaster */
  1909. hp100_rx(dev);
  1910. else if (!(val & HP100_RX_PDL_FILL_COMPL)) {
  1911. /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt? */
  1912. hp100_rx_bm(dev);
  1913. }
  1914. }
  1915. /*
  1916. * Ack. that we have noticed the interrupt and thereby allow next one.
  1917. * Note that this is now done after the slave rx function, since first
  1918. * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt
  1919. * on the J2573.
  1920. */
  1921. hp100_outw(val, IRQ_STATUS);
  1922. /*
  1923. * RX_ERROR is set when a packet is dropped due to no memory resources on
  1924. * the card or when a RCV_ERR occurs.
  1925. * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists
  1926. * only in the 802.3 MAC and happens when 16 collisions occur during a TX
  1927. */
  1928. if (val & (HP100_TX_ERROR | HP100_RX_ERROR)) {
  1929. #ifdef HP100_DEBUG_IRQ
  1930. printk("hp100: %s: TX/RX Error IRQ\n", dev->name);
  1931. #endif
  1932. hp100_update_stats(dev);
  1933. if (lp->mode == 1) {
  1934. hp100_rxfill(dev);
  1935. hp100_clean_txring(dev);
  1936. }
  1937. }
  1938. /*
  1939. * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero.
  1940. */
  1941. if ((lp->mode == 1) && (val & (HP100_RX_PDA_ZERO)))
  1942. hp100_rxfill(dev);
  1943. /*
  1944. * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire
  1945. * is completed
  1946. */
  1947. if ((lp->mode == 1) && (val & (HP100_TX_COMPLETE)))
  1948. hp100_clean_txring(dev);
  1949. /*
  1950. * MISC_ERROR is set when either the LAN link goes down or a detected
  1951. * bus error occurs.
  1952. */
  1953. if (val & HP100_MISC_ERROR) { /* New for J2585B */
  1954. #ifdef HP100_DEBUG_IRQ
  1955. printk
  1956. ("hp100: %s: Misc. Error Interrupt - Check cabling.\n",
  1957. dev->name);
  1958. #endif
  1959. if (lp->mode == 1) {
  1960. hp100_clean_txring(dev);
  1961. hp100_rxfill(dev);
  1962. }
  1963. hp100_misc_interrupt(dev);
  1964. }
  1965. spin_unlock(&lp->lock);
  1966. hp100_ints_on();
  1967. return IRQ_HANDLED;
  1968. }
  1969. /*
  1970. * some misc functions
  1971. */
  1972. static void hp100_start_interface(struct net_device *dev)
  1973. {
  1974. unsigned long flags;
  1975. int ioaddr = dev->base_addr;
  1976. struct hp100_private *lp = netdev_priv(dev);
  1977. #ifdef HP100_DEBUG_B
  1978. hp100_outw(0x4220, TRACE);
  1979. printk("hp100: %s: hp100_start_interface\n", dev->name);
  1980. #endif
  1981. spin_lock_irqsave(&lp->lock, flags);
  1982. /* Ensure the adapter does not want to request an interrupt when */
  1983. /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */
  1984. hp100_page(PERFORMANCE);
  1985. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  1986. hp100_outw(0xffff, IRQ_STATUS); /* ack all IRQs */
  1987. hp100_outw(HP100_FAKE_INT | HP100_INT_EN | HP100_RESET_LB,
  1988. OPTION_LSW);
  1989. /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */
  1990. hp100_outw(HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW);
  1991. if (lp->mode == 1) {
  1992. /* Make sure BM bit is set... */
  1993. hp100_page(HW_MAP);
  1994. hp100_orb(HP100_BM_MASTER, BM);
  1995. hp100_rxfill(dev);
  1996. } else if (lp->mode == 2) {
  1997. /* Enable memory mapping. Note: Don't do this when busmaster. */
  1998. hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW);
  1999. }
  2000. hp100_page(PERFORMANCE);
  2001. hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */
  2002. hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */
  2003. /* enable a few interrupts: */
  2004. if (lp->mode == 1) { /* busmaster mode */
  2005. hp100_outw(HP100_RX_PDL_FILL_COMPL |
  2006. HP100_RX_PDA_ZERO | HP100_RX_ERROR |
  2007. /* HP100_RX_PACKET | */
  2008. /* HP100_RX_EARLY_INT | */ HP100_SET_HB |
  2009. /* HP100_TX_PDA_ZERO | */
  2010. HP100_TX_COMPLETE |
  2011. /* HP100_MISC_ERROR | */
  2012. HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK);
  2013. } else {
  2014. hp100_outw(HP100_RX_PACKET |
  2015. HP100_RX_ERROR | HP100_SET_HB |
  2016. HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK);
  2017. }
  2018. /* Note : before hp100_set_multicast_list(), because it will play with
  2019. * spinlock itself... Jean II */
  2020. spin_unlock_irqrestore(&lp->lock, flags);
  2021. /* Enable MAC Tx and RX, set MAC modes, ... */
  2022. hp100_set_multicast_list(dev);
  2023. }
  2024. static void hp100_stop_interface(struct net_device *dev)
  2025. {
  2026. struct hp100_private *lp = netdev_priv(dev);
  2027. int ioaddr = dev->base_addr;
  2028. u_int val;
  2029. #ifdef HP100_DEBUG_B
  2030. printk("hp100: %s: hp100_stop_interface\n", dev->name);
  2031. hp100_outw(0x4221, TRACE);
  2032. #endif
  2033. if (lp->mode == 1)
  2034. hp100_BM_shutdown(dev);
  2035. else {
  2036. /* Note: MMAP_DIS will be reenabled by start_interface */
  2037. hp100_outw(HP100_INT_EN | HP100_RESET_LB |
  2038. HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB,
  2039. OPTION_LSW);
  2040. val = hp100_inw(OPTION_LSW);
  2041. hp100_page(MAC_CTRL);
  2042. hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);
  2043. if (!(val & HP100_HW_RST))
  2044. return; /* If reset, imm. return ... */
  2045. /* ... else: busy wait until idle */
  2046. for (val = 0; val < 6000; val++)
  2047. if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) {
  2048. hp100_page(PERFORMANCE);
  2049. return;
  2050. }
  2051. printk("hp100: %s: hp100_stop_interface - timeout\n", dev->name);
  2052. hp100_page(PERFORMANCE);
  2053. }
  2054. }
  2055. static void hp100_load_eeprom(struct net_device *dev, u_short probe_ioaddr)
  2056. {
  2057. int i;
  2058. int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr;
  2059. #ifdef HP100_DEBUG_B
  2060. hp100_outw(0x4222, TRACE);
  2061. #endif
  2062. hp100_page(EEPROM_CTRL);
  2063. hp100_andw(~HP100_EEPROM_LOAD, EEPROM_CTRL);
  2064. hp100_orw(HP100_EEPROM_LOAD, EEPROM_CTRL);
  2065. for (i = 0; i < 10000; i++)
  2066. if (!(hp100_inb(OPTION_MSW) & HP100_EE_LOAD))
  2067. return;
  2068. printk("hp100: %s: hp100_load_eeprom - timeout\n", dev->name);
  2069. }
  2070. /* Sense connection status.
  2071. * return values: LAN_10 - Connected to 10Mbit/s network
  2072. * LAN_100 - Connected to 100Mbit/s network
  2073. * LAN_ERR - not connected or 100Mbit/s Hub down
  2074. */
  2075. static int hp100_sense_lan(struct net_device *dev)
  2076. {
  2077. int ioaddr = dev->base_addr;
  2078. u_short val_VG, val_10;
  2079. struct hp100_private *lp = netdev_priv(dev);
  2080. #ifdef HP100_DEBUG_B
  2081. hp100_outw(0x4223, TRACE);
  2082. #endif
  2083. hp100_page(MAC_CTRL);
  2084. val_10 = hp100_inb(10_LAN_CFG_1);
  2085. val_VG = hp100_inb(VG_LAN_CFG_1);
  2086. hp100_page(PERFORMANCE);
  2087. #ifdef HP100_DEBUG
  2088. printk("hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n",
  2089. dev->name, val_VG, val_10);
  2090. #endif
  2091. if (val_10 & HP100_LINK_BEAT_ST) /* 10Mb connection is active */
  2092. return HP100_LAN_10;
  2093. if (val_10 & HP100_AUI_ST) { /* have we BNC or AUI onboard? */
  2094. /*
  2095. * This can be overriden by dos utility, so if this has no effect,
  2096. * perhaps you need to download that utility from HP and set card
  2097. * back to "auto detect".
  2098. */
  2099. val_10 |= HP100_AUI_SEL | HP100_LOW_TH;
  2100. hp100_page(MAC_CTRL);
  2101. hp100_outb(val_10, 10_LAN_CFG_1);
  2102. hp100_page(PERFORMANCE);
  2103. return HP100_LAN_COAX;
  2104. }
  2105. /* Those cards don't have a 100 Mbit connector */
  2106. if ( !strcmp(lp->id, "HWP1920") ||
  2107. (lp->pci_dev &&
  2108. lp->pci_dev->vendor == PCI_VENDOR_ID &&
  2109. (lp->pci_dev->device == PCI_DEVICE_ID_HP_J2970A ||
  2110. lp->pci_dev->device == PCI_DEVICE_ID_HP_J2973A)))
  2111. return HP100_LAN_ERR;
  2112. if (val_VG & HP100_LINK_CABLE_ST) /* Can hear the HUBs tone. */
  2113. return HP100_LAN_100;
  2114. return HP100_LAN_ERR;
  2115. }
  2116. static int hp100_down_vg_link(struct net_device *dev)
  2117. {
  2118. struct hp100_private *lp = netdev_priv(dev);
  2119. int ioaddr = dev->base_addr;
  2120. unsigned long time;
  2121. long savelan, newlan;
  2122. #ifdef HP100_DEBUG_B
  2123. hp100_outw(0x4224, TRACE);
  2124. printk("hp100: %s: down_vg_link\n", dev->name);
  2125. #endif
  2126. hp100_page(MAC_CTRL);
  2127. time = jiffies + (HZ / 4);
  2128. do {
  2129. if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
  2130. break;
  2131. if (!in_interrupt())
  2132. schedule_timeout_interruptible(1);
  2133. } while (time_after(time, jiffies));
  2134. if (time_after_eq(jiffies, time)) /* no signal->no logout */
  2135. return 0;
  2136. /* Drop the VG Link by clearing the link up cmd and load addr. */
  2137. hp100_andb(~(HP100_LOAD_ADDR | HP100_LINK_CMD), VG_LAN_CFG_1);
  2138. hp100_orb(HP100_VG_SEL, VG_LAN_CFG_1);
  2139. /* Conditionally stall for >250ms on Link-Up Status (to go down) */
  2140. time = jiffies + (HZ / 2);
  2141. do {
  2142. if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
  2143. break;
  2144. if (!in_interrupt())
  2145. schedule_timeout_interruptible(1);
  2146. } while (time_after(time, jiffies));
  2147. #ifdef HP100_DEBUG
  2148. if (time_after_eq(jiffies, time))
  2149. printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name);
  2150. #endif
  2151. /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */
  2152. /* logout under traffic (even though all the status bits are cleared), */
  2153. /* do this workaround to get the Rev 1 MAC in its idle state */
  2154. if (lp->chip == HP100_CHIPID_LASSEN) {
  2155. /* Reset VG MAC to insure it leaves the logoff state even if */
  2156. /* the Hub is still emitting tones */
  2157. hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1);
  2158. udelay(1500); /* wait for >1ms */
  2159. hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */
  2160. udelay(1500);
  2161. }
  2162. /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */
  2163. /* to get the VG mac to full reset. This is not req.d with later chips */
  2164. /* Note: It will take the between 1 and 2 seconds for the VG mac to be */
  2165. /* selected again! This will be left to the connect hub function to */
  2166. /* perform if desired. */
  2167. if (lp->chip == HP100_CHIPID_LASSEN) {
  2168. /* Have to write to 10 and 100VG control registers simultaneously */
  2169. savelan = newlan = hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */
  2170. newlan &= ~(HP100_VG_SEL << 16);
  2171. newlan |= (HP100_DOT3_MAC) << 8;
  2172. hp100_andb(~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */
  2173. hp100_outl(newlan, 10_LAN_CFG_1);
  2174. /* Conditionally stall for 5sec on VG selected. */
  2175. time = jiffies + (HZ * 5);
  2176. do {
  2177. if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST))
  2178. break;
  2179. if (!in_interrupt())
  2180. schedule_timeout_interruptible(1);
  2181. } while (time_after(time, jiffies));
  2182. hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */
  2183. hp100_outl(savelan, 10_LAN_CFG_1);
  2184. }
  2185. time = jiffies + (3 * HZ); /* Timeout 3s */
  2186. do {
  2187. if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0)
  2188. break;
  2189. if (!in_interrupt())
  2190. schedule_timeout_interruptible(1);
  2191. } while (time_after(time, jiffies));
  2192. if (time_before_eq(time, jiffies)) {
  2193. #ifdef HP100_DEBUG
  2194. printk("hp100: %s: down_vg_link: timeout\n", dev->name);
  2195. #endif
  2196. return -EIO;
  2197. }
  2198. time = jiffies + (2 * HZ); /* This seems to take a while.... */
  2199. do {
  2200. if (!in_interrupt())
  2201. schedule_timeout_interruptible(1);
  2202. } while (time_after(time, jiffies));
  2203. return 0;
  2204. }
  2205. static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin)
  2206. {
  2207. int ioaddr = dev->base_addr;
  2208. struct hp100_private *lp = netdev_priv(dev);
  2209. u_short val = 0;
  2210. unsigned long time;
  2211. int startst;
  2212. #ifdef HP100_DEBUG_B
  2213. hp100_outw(0x4225, TRACE);
  2214. printk("hp100: %s: login_to_vg_hub\n", dev->name);
  2215. #endif
  2216. /* Initiate a login sequence iff VG MAC is enabled and either Load Address
  2217. * bit is zero or the force relogin flag is set (e.g. due to MAC address or
  2218. * promiscuous mode change)
  2219. */
  2220. hp100_page(MAC_CTRL);
  2221. startst = hp100_inb(VG_LAN_CFG_1);
  2222. if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) {
  2223. #ifdef HP100_DEBUG_TRAINING
  2224. printk("hp100: %s: Start training\n", dev->name);
  2225. #endif
  2226. /* Ensure VG Reset bit is 1 (i.e., do not reset) */
  2227. hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1);
  2228. /* If Lassen AND auto-select-mode AND VG tones were sensed on */
  2229. /* entry then temporarily put them into force 100Mbit mode */
  2230. if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST))
  2231. hp100_andb(~HP100_DOT3_MAC, 10_LAN_CFG_2);
  2232. /* Drop the VG link by zeroing Link Up Command and Load Address */
  2233. hp100_andb(~(HP100_LINK_CMD /* |HP100_LOAD_ADDR */ ), VG_LAN_CFG_1);
  2234. #ifdef HP100_DEBUG_TRAINING
  2235. printk("hp100: %s: Bring down the link\n", dev->name);
  2236. #endif
  2237. /* Wait for link to drop */
  2238. time = jiffies + (HZ / 10);
  2239. do {
  2240. if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
  2241. break;
  2242. if (!in_interrupt())
  2243. schedule_timeout_interruptible(1);
  2244. } while (time_after(time, jiffies));
  2245. /* Start an addressed training and optionally request promiscuous port */
  2246. if ((dev->flags) & IFF_PROMISC) {
  2247. hp100_orb(HP100_PROM_MODE, VG_LAN_CFG_2);
  2248. if (lp->chip == HP100_CHIPID_LASSEN)
  2249. hp100_orw(HP100_MACRQ_PROMSC, TRAIN_REQUEST);
  2250. } else {
  2251. hp100_andb(~HP100_PROM_MODE, VG_LAN_CFG_2);
  2252. /* For ETR parts we need to reset the prom. bit in the training
  2253. * register, otherwise promiscious mode won't be disabled.
  2254. */
  2255. if (lp->chip == HP100_CHIPID_LASSEN) {
  2256. hp100_andw(~HP100_MACRQ_PROMSC, TRAIN_REQUEST);
  2257. }
  2258. }
  2259. /* With ETR parts, frame format request bits can be set. */
  2260. if (lp->chip == HP100_CHIPID_LASSEN)
  2261. hp100_orb(HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST);
  2262. hp100_orb(HP100_LINK_CMD | HP100_LOAD_ADDR | HP100_VG_RESET, VG_LAN_CFG_1);
  2263. /* Note: Next wait could be omitted for Hood and earlier chips under */
  2264. /* certain circumstances */
  2265. /* TODO: check if hood/earlier and skip wait. */
  2266. /* Wait for either short timeout for VG tones or long for login */
  2267. /* Wait for the card hardware to signalise link cable status ok... */
  2268. hp100_page(MAC_CTRL);
  2269. time = jiffies + (1 * HZ); /* 1 sec timeout for cable st */
  2270. do {
  2271. if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
  2272. break;
  2273. if (!in_interrupt())
  2274. schedule_timeout_interruptible(1);
  2275. } while (time_before(jiffies, time));
  2276. if (time_after_eq(jiffies, time)) {
  2277. #ifdef HP100_DEBUG_TRAINING
  2278. printk("hp100: %s: Link cable status not ok? Training aborted.\n", dev->name);
  2279. #endif
  2280. } else {
  2281. #ifdef HP100_DEBUG_TRAINING
  2282. printk
  2283. ("hp100: %s: HUB tones detected. Trying to train.\n",
  2284. dev->name);
  2285. #endif
  2286. time = jiffies + (2 * HZ); /* again a timeout */
  2287. do {
  2288. val = hp100_inb(VG_LAN_CFG_1);
  2289. if ((val & (HP100_LINK_UP_ST))) {
  2290. #ifdef HP100_DEBUG_TRAINING
  2291. printk("hp100: %s: Passed training.\n", dev->name);
  2292. #endif
  2293. break;
  2294. }
  2295. if (!in_interrupt())
  2296. schedule_timeout_interruptible(1);
  2297. } while (time_after(time, jiffies));
  2298. }
  2299. /* If LINK_UP_ST is set, then we are logged into the hub. */
  2300. if (time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST)) {
  2301. #ifdef HP100_DEBUG_TRAINING
  2302. printk("hp100: %s: Successfully logged into the HUB.\n", dev->name);
  2303. if (lp->chip == HP100_CHIPID_LASSEN) {
  2304. val = hp100_inw(TRAIN_ALLOW);
  2305. printk("hp100: %s: Card supports 100VG MAC Version \"%s\" ",
  2306. dev->name, (hp100_inw(TRAIN_REQUEST) & HP100_CARD_MACVER) ? "802.12" : "Pre");
  2307. printk("Driver will use MAC Version \"%s\"\n", (val & HP100_HUB_MACVER) ? "802.12" : "Pre");
  2308. printk("hp100: %s: Frame format is %s.\n", dev->name, (val & HP100_MALLOW_FRAMEFMT) ? "802.5" : "802.3");
  2309. }
  2310. #endif
  2311. } else {
  2312. /* If LINK_UP_ST is not set, login was not successful */
  2313. printk("hp100: %s: Problem logging into the HUB.\n", dev->name);
  2314. if (lp->chip == HP100_CHIPID_LASSEN) {
  2315. /* Check allowed Register to find out why there is a problem. */
  2316. val = hp100_inw(TRAIN_ALLOW); /* won't work on non-ETR card */
  2317. #ifdef HP100_DEBUG_TRAINING
  2318. printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val);
  2319. #endif
  2320. if (val & HP100_MALLOW_ACCDENIED)
  2321. printk("hp100: %s: HUB access denied.\n", dev->name);
  2322. if (val & HP100_MALLOW_CONFIGURE)
  2323. printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name);
  2324. if (val & HP100_MALLOW_DUPADDR)
  2325. printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name);
  2326. }
  2327. }
  2328. /* If we have put the chip into forced 100 Mbit mode earlier, go back */
  2329. /* to auto-select mode */
  2330. if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) {
  2331. hp100_page(MAC_CTRL);
  2332. hp100_orb(HP100_DOT3_MAC, 10_LAN_CFG_2);
  2333. }
  2334. val = hp100_inb(VG_LAN_CFG_1);
  2335. /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */
  2336. hp100_page(PERFORMANCE);
  2337. hp100_outw(HP100_MISC_ERROR, IRQ_STATUS);
  2338. if (val & HP100_LINK_UP_ST)
  2339. return (0); /* login was ok */
  2340. else {
  2341. printk("hp100: %s: Training failed.\n", dev->name);
  2342. hp100_down_vg_link(dev);
  2343. return -EIO;
  2344. }
  2345. }
  2346. /* no forced relogin & already link there->no training. */
  2347. return -EIO;
  2348. }
  2349. static void hp100_cascade_reset(struct net_device *dev, u_short enable)
  2350. {
  2351. int ioaddr = dev->base_addr;
  2352. struct hp100_private *lp = netdev_priv(dev);
  2353. #ifdef HP100_DEBUG_B
  2354. hp100_outw(0x4226, TRACE);
  2355. printk("hp100: %s: cascade_reset\n", dev->name);
  2356. #endif
  2357. if (enable) {
  2358. hp100_outw(HP100_HW_RST | HP100_RESET_LB, OPTION_LSW);
  2359. if (lp->chip == HP100_CHIPID_LASSEN) {
  2360. /* Lassen requires a PCI transmit fifo reset */
  2361. hp100_page(HW_MAP);
  2362. hp100_andb(~HP100_PCI_RESET, PCICTRL2);
  2363. hp100_orb(HP100_PCI_RESET, PCICTRL2);
  2364. /* Wait for min. 300 ns */
  2365. /* we can't use jiffies here, because it may be */
  2366. /* that we have disabled the timer... */
  2367. udelay(400);
  2368. hp100_andb(~HP100_PCI_RESET, PCICTRL2);
  2369. hp100_page(PERFORMANCE);
  2370. }
  2371. } else { /* bring out of reset */
  2372. hp100_outw(HP100_HW_RST | HP100_SET_LB, OPTION_LSW);
  2373. udelay(400);
  2374. hp100_page(PERFORMANCE);
  2375. }
  2376. }
  2377. #ifdef HP100_DEBUG
  2378. void hp100_RegisterDump(struct net_device *dev)
  2379. {
  2380. int ioaddr = dev->base_addr;
  2381. int Page;
  2382. int Register;
  2383. /* Dump common registers */
  2384. printk("hp100: %s: Cascade Register Dump\n", dev->name);
  2385. printk("hardware id #1: 0x%.2x\n", hp100_inb(HW_ID));
  2386. printk("hardware id #2/paging: 0x%.2x\n", hp100_inb(PAGING));
  2387. printk("option #1: 0x%.4x\n", hp100_inw(OPTION_LSW));
  2388. printk("option #2: 0x%.4x\n", hp100_inw(OPTION_MSW));
  2389. /* Dump paged registers */
  2390. for (Page = 0; Page < 8; Page++) {
  2391. /* Dump registers */
  2392. printk("page: 0x%.2x\n", Page);
  2393. outw(Page, ioaddr + 0x02);
  2394. for (Register = 0x8; Register < 0x22; Register += 2) {
  2395. /* Display Register contents except data port */
  2396. if (((Register != 0x10) && (Register != 0x12)) || (Page > 0)) {
  2397. printk("0x%.2x = 0x%.4x\n", Register, inw(ioaddr + Register));
  2398. }
  2399. }
  2400. }
  2401. hp100_page(PERFORMANCE);
  2402. }
  2403. #endif
  2404. static void cleanup_dev(struct net_device *d)
  2405. {
  2406. struct hp100_private *p = netdev_priv(d);
  2407. unregister_netdev(d);
  2408. release_region(d->base_addr, HP100_REGION_SIZE);
  2409. if (p->mode == 1) /* busmaster */
  2410. pci_free_consistent(p->pci_dev, MAX_RINGSIZE + 0x0f,
  2411. p->page_vaddr_algn,
  2412. virt_to_whatever(d, p->page_vaddr_algn));
  2413. if (p->mem_ptr_virt)
  2414. iounmap(p->mem_ptr_virt);
  2415. free_netdev(d);
  2416. }
  2417. #ifdef CONFIG_EISA
  2418. static int __init hp100_eisa_probe (struct device *gendev)
  2419. {
  2420. struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private));
  2421. struct eisa_device *edev = to_eisa_device(gendev);
  2422. int err;
  2423. if (!dev)
  2424. return -ENOMEM;
  2425. SET_NETDEV_DEV(dev, &edev->dev);
  2426. err = hp100_probe1(dev, edev->base_addr + 0xC38, HP100_BUS_EISA, NULL);
  2427. if (err)
  2428. goto out1;
  2429. #ifdef HP100_DEBUG
  2430. printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name,
  2431. dev->base_addr);
  2432. #endif
  2433. gendev->driver_data = dev;
  2434. return 0;
  2435. out1:
  2436. free_netdev(dev);
  2437. return err;
  2438. }
  2439. static int __devexit hp100_eisa_remove (struct device *gendev)
  2440. {
  2441. struct net_device *dev = gendev->driver_data;
  2442. cleanup_dev(dev);
  2443. return 0;
  2444. }
  2445. static struct eisa_driver hp100_eisa_driver = {
  2446. .id_table = hp100_eisa_tbl,
  2447. .driver = {
  2448. .name = "hp100",
  2449. .probe = hp100_eisa_probe,
  2450. .remove = __devexit_p (hp100_eisa_remove),
  2451. }
  2452. };
  2453. #endif
  2454. #ifdef CONFIG_PCI
  2455. static int __devinit hp100_pci_probe (struct pci_dev *pdev,
  2456. const struct pci_device_id *ent)
  2457. {
  2458. struct net_device *dev;
  2459. int ioaddr;
  2460. u_short pci_command;
  2461. int err;
  2462. if (pci_enable_device(pdev))
  2463. return -ENODEV;
  2464. dev = alloc_etherdev(sizeof(struct hp100_private));
  2465. if (!dev) {
  2466. err = -ENOMEM;
  2467. goto out0;
  2468. }
  2469. SET_NETDEV_DEV(dev, &pdev->dev);
  2470. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  2471. if (!(pci_command & PCI_COMMAND_IO)) {
  2472. #ifdef HP100_DEBUG
  2473. printk("hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name);
  2474. #endif
  2475. pci_command |= PCI_COMMAND_IO;
  2476. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  2477. }
  2478. if (!(pci_command & PCI_COMMAND_MASTER)) {
  2479. #ifdef HP100_DEBUG
  2480. printk("hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name);
  2481. #endif
  2482. pci_command |= PCI_COMMAND_MASTER;
  2483. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  2484. }
  2485. ioaddr = pci_resource_start(pdev, 0);
  2486. err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev);
  2487. if (err)
  2488. goto out1;
  2489. #ifdef HP100_DEBUG
  2490. printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr);
  2491. #endif
  2492. pci_set_drvdata(pdev, dev);
  2493. return 0;
  2494. out1:
  2495. free_netdev(dev);
  2496. out0:
  2497. pci_disable_device(pdev);
  2498. return err;
  2499. }
  2500. static void __devexit hp100_pci_remove (struct pci_dev *pdev)
  2501. {
  2502. struct net_device *dev = pci_get_drvdata(pdev);
  2503. cleanup_dev(dev);
  2504. pci_disable_device(pdev);
  2505. }
  2506. static struct pci_driver hp100_pci_driver = {
  2507. .name = "hp100",
  2508. .id_table = hp100_pci_tbl,
  2509. .probe = hp100_pci_probe,
  2510. .remove = __devexit_p(hp100_pci_remove),
  2511. };
  2512. #endif
  2513. /*
  2514. * module section
  2515. */
  2516. MODULE_LICENSE("GPL");
  2517. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, "
  2518. "Siegfried \"Frieder\" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>");
  2519. MODULE_DESCRIPTION("HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters");
  2520. /*
  2521. * Note: to register three isa devices, use:
  2522. * option hp100 hp100_port=0,0,0
  2523. * to register one card at io 0x280 as eth239, use:
  2524. * option hp100 hp100_port=0x280
  2525. */
  2526. #if defined(MODULE) && defined(CONFIG_ISA)
  2527. #define HP100_DEVICES 5
  2528. /* Parameters set by insmod */
  2529. static int hp100_port[HP100_DEVICES] = { 0, [1 ... (HP100_DEVICES-1)] = -1 };
  2530. module_param_array(hp100_port, int, NULL, 0);
  2531. /* List of devices */
  2532. static struct net_device *hp100_devlist[HP100_DEVICES];
  2533. static int __init hp100_isa_init(void)
  2534. {
  2535. struct net_device *dev;
  2536. int i, err, cards = 0;
  2537. /* Don't autoprobe ISA bus */
  2538. if (hp100_port[0] == 0)
  2539. return -ENODEV;
  2540. /* Loop on all possible base addresses */
  2541. for (i = 0; i < HP100_DEVICES && hp100_port[i] != -1; ++i) {
  2542. dev = alloc_etherdev(sizeof(struct hp100_private));
  2543. if (!dev) {
  2544. printk(KERN_WARNING "hp100: no memory for network device\n");
  2545. while (cards > 0)
  2546. cleanup_dev(hp100_devlist[--cards]);
  2547. return -ENOMEM;
  2548. }
  2549. err = hp100_isa_probe(dev, hp100_port[i]);
  2550. if (!err)
  2551. hp100_devlist[cards++] = dev;
  2552. else
  2553. free_netdev(dev);
  2554. }
  2555. return cards > 0 ? 0 : -ENODEV;
  2556. }
  2557. static void hp100_isa_cleanup(void)
  2558. {
  2559. int i;
  2560. for (i = 0; i < HP100_DEVICES; i++) {
  2561. struct net_device *dev = hp100_devlist[i];
  2562. if (dev)
  2563. cleanup_dev(dev);
  2564. }
  2565. }
  2566. #else
  2567. #define hp100_isa_init() (0)
  2568. #define hp100_isa_cleanup() do { } while(0)
  2569. #endif
  2570. static int __init hp100_module_init(void)
  2571. {
  2572. int err;
  2573. err = hp100_isa_init();
  2574. if (err && err != -ENODEV)
  2575. goto out;
  2576. #ifdef CONFIG_EISA
  2577. err = eisa_driver_register(&hp100_eisa_driver);
  2578. if (err && err != -ENODEV)
  2579. goto out2;
  2580. #endif
  2581. #ifdef CONFIG_PCI
  2582. err = pci_register_driver(&hp100_pci_driver);
  2583. if (err && err != -ENODEV)
  2584. goto out3;
  2585. #endif
  2586. out:
  2587. return err;
  2588. out3:
  2589. #ifdef CONFIG_EISA
  2590. eisa_driver_unregister (&hp100_eisa_driver);
  2591. out2:
  2592. #endif
  2593. hp100_isa_cleanup();
  2594. goto out;
  2595. }
  2596. static void __exit hp100_module_exit(void)
  2597. {
  2598. hp100_isa_cleanup();
  2599. #ifdef CONFIG_EISA
  2600. eisa_driver_unregister (&hp100_eisa_driver);
  2601. #endif
  2602. #ifdef CONFIG_PCI
  2603. pci_unregister_driver (&hp100_pci_driver);
  2604. #endif
  2605. }
  2606. module_init(hp100_module_init)
  2607. module_exit(hp100_module_exit)