hp100.c 89 KB

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