hp100.c 89 KB

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