hp100.c 88 KB

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