hp100.c 89 KB

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