hp100.c 89 KB

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