hp100.c 88 KB

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