tlan.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286
  1. /*******************************************************************************
  2. *
  3. * Linux ThunderLAN Driver
  4. *
  5. * tlan.c
  6. * by James Banks
  7. *
  8. * (C) 1997-1998 Caldera, Inc.
  9. * (C) 1998 James Banks
  10. * (C) 1999-2001 Torben Mathiasen
  11. * (C) 2002 Samuel Chessman
  12. *
  13. * This software may be used and distributed according to the terms
  14. * of the GNU General Public License, incorporated herein by reference.
  15. *
  16. ** Useful (if not required) reading:
  17. *
  18. * Texas Instruments, ThunderLAN Programmer's Guide,
  19. * TI Literature Number SPWU013A
  20. * available in PDF format from www.ti.com
  21. * Level One, LXT901 and LXT970 Data Sheets
  22. * available in PDF format from www.level1.com
  23. * National Semiconductor, DP83840A Data Sheet
  24. * available in PDF format from www.national.com
  25. * Microchip Technology, 24C01A/02A/04A Data Sheet
  26. * available in PDF format from www.microchip.com
  27. *
  28. ******************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/hardirq.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/ioport.h>
  35. #include <linux/eisa.h>
  36. #include <linux/pci.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/etherdevice.h>
  40. #include <linux/delay.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/mii.h>
  44. #include "tlan.h"
  45. /* For removing EISA devices */
  46. static struct net_device *tlan_eisa_devices;
  47. static int tlan_devices_installed;
  48. /* Set speed, duplex and aui settings */
  49. static int aui[MAX_TLAN_BOARDS];
  50. static int duplex[MAX_TLAN_BOARDS];
  51. static int speed[MAX_TLAN_BOARDS];
  52. static int boards_found;
  53. module_param_array(aui, int, NULL, 0);
  54. module_param_array(duplex, int, NULL, 0);
  55. module_param_array(speed, int, NULL, 0);
  56. MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
  57. MODULE_PARM_DESC(duplex,
  58. "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
  59. MODULE_PARM_DESC(speed, "ThunderLAN port speed setting(s) (0,10,100)");
  60. MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
  61. MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
  62. MODULE_LICENSE("GPL");
  63. /* Turn on debugging. See Documentation/networking/tlan.txt for details */
  64. static int debug;
  65. module_param(debug, int, 0);
  66. MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
  67. static const char tlan_signature[] = "TLAN";
  68. static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
  69. static int tlan_have_pci;
  70. static int tlan_have_eisa;
  71. static const char * const media[] = {
  72. "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
  73. "100BaseTx-FD", "100BaseT4", NULL
  74. };
  75. static struct board {
  76. const char *device_label;
  77. u32 flags;
  78. u16 addr_ofs;
  79. } board_info[] = {
  80. { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  81. { "Compaq Netelligent 10/100 TX PCI UTP",
  82. TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  83. { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  84. { "Compaq NetFlex-3/P",
  85. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  86. { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  87. { "Compaq Netelligent Integrated 10/100 TX UTP",
  88. TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  89. { "Compaq Netelligent Dual 10/100 TX PCI UTP",
  90. TLAN_ADAPTER_NONE, 0x83 },
  91. { "Compaq Netelligent 10/100 TX Embedded UTP",
  92. TLAN_ADAPTER_NONE, 0x83 },
  93. { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
  94. { "Olicom OC-2325", TLAN_ADAPTER_ACTIVITY_LED |
  95. TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
  96. { "Olicom OC-2326", TLAN_ADAPTER_ACTIVITY_LED |
  97. TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
  98. { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  99. { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
  100. { "Compaq NetFlex-3/E",
  101. TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
  102. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  103. { "Compaq NetFlex-3/E",
  104. TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
  105. };
  106. static const struct pci_device_id tlan_pci_tbl[] = {
  107. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
  108. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  109. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
  110. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  111. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
  112. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  113. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
  114. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  115. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
  116. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  117. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
  118. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  119. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
  120. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
  121. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
  122. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
  123. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
  124. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
  125. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
  126. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
  127. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
  128. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
  129. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
  130. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
  131. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
  133. { 0,}
  134. };
  135. MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
  136. static void tlan_eisa_probe(void);
  137. static void tlan_eisa_cleanup(void);
  138. static int tlan_init(struct net_device *);
  139. static int tlan_open(struct net_device *dev);
  140. static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
  141. static irqreturn_t tlan_handle_interrupt(int, void *);
  142. static int tlan_close(struct net_device *);
  143. static struct net_device_stats *tlan_get_stats(struct net_device *);
  144. static void tlan_set_multicast_list(struct net_device *);
  145. static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  146. static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
  147. int irq, int rev, const struct pci_device_id *ent);
  148. static void tlan_tx_timeout(struct net_device *dev);
  149. static void tlan_tx_timeout_work(struct work_struct *work);
  150. static int tlan_init_one(struct pci_dev *pdev,
  151. const struct pci_device_id *ent);
  152. static u32 tlan_handle_tx_eof(struct net_device *, u16);
  153. static u32 tlan_handle_stat_overflow(struct net_device *, u16);
  154. static u32 tlan_handle_rx_eof(struct net_device *, u16);
  155. static u32 tlan_handle_dummy(struct net_device *, u16);
  156. static u32 tlan_handle_tx_eoc(struct net_device *, u16);
  157. static u32 tlan_handle_status_check(struct net_device *, u16);
  158. static u32 tlan_handle_rx_eoc(struct net_device *, u16);
  159. static void tlan_timer(struct timer_list *t);
  160. static void tlan_phy_monitor(struct timer_list *t);
  161. static void tlan_reset_lists(struct net_device *);
  162. static void tlan_free_lists(struct net_device *);
  163. static void tlan_print_dio(u16);
  164. static void tlan_print_list(struct tlan_list *, char *, int);
  165. static void tlan_read_and_clear_stats(struct net_device *, int);
  166. static void tlan_reset_adapter(struct net_device *);
  167. static void tlan_finish_reset(struct net_device *);
  168. static void tlan_set_mac(struct net_device *, int areg, char *mac);
  169. static void tlan_phy_print(struct net_device *);
  170. static void tlan_phy_detect(struct net_device *);
  171. static void tlan_phy_power_down(struct net_device *);
  172. static void tlan_phy_power_up(struct net_device *);
  173. static void tlan_phy_reset(struct net_device *);
  174. static void tlan_phy_start_link(struct net_device *);
  175. static void tlan_phy_finish_auto_neg(struct net_device *);
  176. /*
  177. static int tlan_phy_nop(struct net_device *);
  178. static int tlan_phy_internal_check(struct net_device *);
  179. static int tlan_phy_internal_service(struct net_device *);
  180. static int tlan_phy_dp83840a_check(struct net_device *);
  181. */
  182. static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
  183. static void tlan_mii_send_data(u16, u32, unsigned);
  184. static void tlan_mii_sync(u16);
  185. static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
  186. static void tlan_ee_send_start(u16);
  187. static int tlan_ee_send_byte(u16, u8, int);
  188. static void tlan_ee_receive_byte(u16, u8 *, int);
  189. static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
  190. static inline void
  191. tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
  192. {
  193. unsigned long addr = (unsigned long)skb;
  194. tag->buffer[9].address = addr;
  195. tag->buffer[8].address = upper_32_bits(addr);
  196. }
  197. static inline struct sk_buff *
  198. tlan_get_skb(const struct tlan_list *tag)
  199. {
  200. unsigned long addr;
  201. addr = tag->buffer[9].address;
  202. addr |= ((unsigned long) tag->buffer[8].address << 16) << 16;
  203. return (struct sk_buff *) addr;
  204. }
  205. static u32
  206. (*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
  207. NULL,
  208. tlan_handle_tx_eof,
  209. tlan_handle_stat_overflow,
  210. tlan_handle_rx_eof,
  211. tlan_handle_dummy,
  212. tlan_handle_tx_eoc,
  213. tlan_handle_status_check,
  214. tlan_handle_rx_eoc
  215. };
  216. static inline void
  217. tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
  218. {
  219. struct tlan_priv *priv = netdev_priv(dev);
  220. unsigned long flags = 0;
  221. if (!in_irq())
  222. spin_lock_irqsave(&priv->lock, flags);
  223. if (priv->timer.function != NULL &&
  224. priv->timer_type != TLAN_TIMER_ACTIVITY) {
  225. if (!in_irq())
  226. spin_unlock_irqrestore(&priv->lock, flags);
  227. return;
  228. }
  229. priv->timer.function = tlan_timer;
  230. if (!in_irq())
  231. spin_unlock_irqrestore(&priv->lock, flags);
  232. priv->timer_set_at = jiffies;
  233. priv->timer_type = type;
  234. mod_timer(&priv->timer, jiffies + ticks);
  235. }
  236. /*****************************************************************************
  237. ******************************************************************************
  238. ThunderLAN driver primary functions
  239. these functions are more or less common to all linux network drivers.
  240. ******************************************************************************
  241. *****************************************************************************/
  242. /***************************************************************
  243. * tlan_remove_one
  244. *
  245. * Returns:
  246. * Nothing
  247. * Parms:
  248. * None
  249. *
  250. * Goes through the TLanDevices list and frees the device
  251. * structs and memory associated with each device (lists
  252. * and buffers). It also ureserves the IO port regions
  253. * associated with this device.
  254. *
  255. **************************************************************/
  256. static void tlan_remove_one(struct pci_dev *pdev)
  257. {
  258. struct net_device *dev = pci_get_drvdata(pdev);
  259. struct tlan_priv *priv = netdev_priv(dev);
  260. unregister_netdev(dev);
  261. if (priv->dma_storage) {
  262. pci_free_consistent(priv->pci_dev,
  263. priv->dma_size, priv->dma_storage,
  264. priv->dma_storage_dma);
  265. }
  266. #ifdef CONFIG_PCI
  267. pci_release_regions(pdev);
  268. #endif
  269. free_netdev(dev);
  270. cancel_work_sync(&priv->tlan_tqueue);
  271. }
  272. static void tlan_start(struct net_device *dev)
  273. {
  274. tlan_reset_lists(dev);
  275. /* NOTE: It might not be necessary to read the stats before a
  276. reset if you don't care what the values are.
  277. */
  278. tlan_read_and_clear_stats(dev, TLAN_IGNORE);
  279. tlan_reset_adapter(dev);
  280. netif_wake_queue(dev);
  281. }
  282. static void tlan_stop(struct net_device *dev)
  283. {
  284. struct tlan_priv *priv = netdev_priv(dev);
  285. del_timer_sync(&priv->media_timer);
  286. tlan_read_and_clear_stats(dev, TLAN_RECORD);
  287. outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
  288. /* Reset and power down phy */
  289. tlan_reset_adapter(dev);
  290. if (priv->timer.function != NULL) {
  291. del_timer_sync(&priv->timer);
  292. priv->timer.function = NULL;
  293. }
  294. }
  295. #ifdef CONFIG_PM
  296. static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
  297. {
  298. struct net_device *dev = pci_get_drvdata(pdev);
  299. if (netif_running(dev))
  300. tlan_stop(dev);
  301. netif_device_detach(dev);
  302. pci_save_state(pdev);
  303. pci_disable_device(pdev);
  304. pci_wake_from_d3(pdev, false);
  305. pci_set_power_state(pdev, PCI_D3hot);
  306. return 0;
  307. }
  308. static int tlan_resume(struct pci_dev *pdev)
  309. {
  310. struct net_device *dev = pci_get_drvdata(pdev);
  311. int rc = pci_enable_device(pdev);
  312. if (rc)
  313. return rc;
  314. pci_restore_state(pdev);
  315. pci_enable_wake(pdev, PCI_D0, 0);
  316. netif_device_attach(dev);
  317. if (netif_running(dev))
  318. tlan_start(dev);
  319. return 0;
  320. }
  321. #else /* CONFIG_PM */
  322. #define tlan_suspend NULL
  323. #define tlan_resume NULL
  324. #endif /* CONFIG_PM */
  325. static struct pci_driver tlan_driver = {
  326. .name = "tlan",
  327. .id_table = tlan_pci_tbl,
  328. .probe = tlan_init_one,
  329. .remove = tlan_remove_one,
  330. .suspend = tlan_suspend,
  331. .resume = tlan_resume,
  332. };
  333. static int __init tlan_probe(void)
  334. {
  335. int rc = -ENODEV;
  336. pr_info("%s", tlan_banner);
  337. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
  338. /* Use new style PCI probing. Now the kernel will
  339. do most of this for us */
  340. rc = pci_register_driver(&tlan_driver);
  341. if (rc != 0) {
  342. pr_err("Could not register pci driver\n");
  343. goto err_out_pci_free;
  344. }
  345. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
  346. tlan_eisa_probe();
  347. pr_info("%d device%s installed, PCI: %d EISA: %d\n",
  348. tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
  349. tlan_have_pci, tlan_have_eisa);
  350. if (tlan_devices_installed == 0) {
  351. rc = -ENODEV;
  352. goto err_out_pci_unreg;
  353. }
  354. return 0;
  355. err_out_pci_unreg:
  356. pci_unregister_driver(&tlan_driver);
  357. err_out_pci_free:
  358. return rc;
  359. }
  360. static int tlan_init_one(struct pci_dev *pdev,
  361. const struct pci_device_id *ent)
  362. {
  363. return tlan_probe1(pdev, -1, -1, 0, ent);
  364. }
  365. /*
  366. ***************************************************************
  367. * tlan_probe1
  368. *
  369. * Returns:
  370. * 0 on success, error code on error
  371. * Parms:
  372. * none
  373. *
  374. * The name is lower case to fit in with all the rest of
  375. * the netcard_probe names. This function looks for
  376. * another TLan based adapter, setting it up with the
  377. * allocated device struct if one is found.
  378. * tlan_probe has been ported to the new net API and
  379. * now allocates its own device structure. This function
  380. * is also used by modules.
  381. *
  382. **************************************************************/
  383. static int tlan_probe1(struct pci_dev *pdev, long ioaddr, int irq, int rev,
  384. const struct pci_device_id *ent)
  385. {
  386. struct net_device *dev;
  387. struct tlan_priv *priv;
  388. u16 device_id;
  389. int reg, rc = -ENODEV;
  390. #ifdef CONFIG_PCI
  391. if (pdev) {
  392. rc = pci_enable_device(pdev);
  393. if (rc)
  394. return rc;
  395. rc = pci_request_regions(pdev, tlan_signature);
  396. if (rc) {
  397. pr_err("Could not reserve IO regions\n");
  398. goto err_out;
  399. }
  400. }
  401. #endif /* CONFIG_PCI */
  402. dev = alloc_etherdev(sizeof(struct tlan_priv));
  403. if (dev == NULL) {
  404. rc = -ENOMEM;
  405. goto err_out_regions;
  406. }
  407. SET_NETDEV_DEV(dev, &pdev->dev);
  408. priv = netdev_priv(dev);
  409. priv->pci_dev = pdev;
  410. priv->dev = dev;
  411. /* Is this a PCI device? */
  412. if (pdev) {
  413. u32 pci_io_base = 0;
  414. priv->adapter = &board_info[ent->driver_data];
  415. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  416. if (rc) {
  417. pr_err("No suitable PCI mapping available\n");
  418. goto err_out_free_dev;
  419. }
  420. for (reg = 0; reg <= 5; reg++) {
  421. if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
  422. pci_io_base = pci_resource_start(pdev, reg);
  423. TLAN_DBG(TLAN_DEBUG_GNRL,
  424. "IO mapping is available at %x.\n",
  425. pci_io_base);
  426. break;
  427. }
  428. }
  429. if (!pci_io_base) {
  430. pr_err("No IO mappings available\n");
  431. rc = -EIO;
  432. goto err_out_free_dev;
  433. }
  434. dev->base_addr = pci_io_base;
  435. dev->irq = pdev->irq;
  436. priv->adapter_rev = pdev->revision;
  437. pci_set_master(pdev);
  438. pci_set_drvdata(pdev, dev);
  439. } else { /* EISA card */
  440. /* This is a hack. We need to know which board structure
  441. * is suited for this adapter */
  442. device_id = inw(ioaddr + EISA_ID2);
  443. if (device_id == 0x20F1) {
  444. priv->adapter = &board_info[13]; /* NetFlex-3/E */
  445. priv->adapter_rev = 23; /* TLAN 2.3 */
  446. } else {
  447. priv->adapter = &board_info[14];
  448. priv->adapter_rev = 10; /* TLAN 1.0 */
  449. }
  450. dev->base_addr = ioaddr;
  451. dev->irq = irq;
  452. }
  453. /* Kernel parameters */
  454. if (dev->mem_start) {
  455. priv->aui = dev->mem_start & 0x01;
  456. priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
  457. : (dev->mem_start & 0x06) >> 1;
  458. priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
  459. : (dev->mem_start & 0x18) >> 3;
  460. if (priv->speed == 0x1)
  461. priv->speed = TLAN_SPEED_10;
  462. else if (priv->speed == 0x2)
  463. priv->speed = TLAN_SPEED_100;
  464. debug = priv->debug = dev->mem_end;
  465. } else {
  466. priv->aui = aui[boards_found];
  467. priv->speed = speed[boards_found];
  468. priv->duplex = duplex[boards_found];
  469. priv->debug = debug;
  470. }
  471. /* This will be used when we get an adapter error from
  472. * within our irq handler */
  473. INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
  474. spin_lock_init(&priv->lock);
  475. rc = tlan_init(dev);
  476. if (rc) {
  477. pr_err("Could not set up device\n");
  478. goto err_out_free_dev;
  479. }
  480. rc = register_netdev(dev);
  481. if (rc) {
  482. pr_err("Could not register device\n");
  483. goto err_out_uninit;
  484. }
  485. tlan_devices_installed++;
  486. boards_found++;
  487. /* pdev is NULL if this is an EISA device */
  488. if (pdev)
  489. tlan_have_pci++;
  490. else {
  491. priv->next_device = tlan_eisa_devices;
  492. tlan_eisa_devices = dev;
  493. tlan_have_eisa++;
  494. }
  495. netdev_info(dev, "irq=%2d, io=%04x, %s, Rev. %d\n",
  496. (int)dev->irq,
  497. (int)dev->base_addr,
  498. priv->adapter->device_label,
  499. priv->adapter_rev);
  500. return 0;
  501. err_out_uninit:
  502. pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
  503. priv->dma_storage_dma);
  504. err_out_free_dev:
  505. free_netdev(dev);
  506. err_out_regions:
  507. #ifdef CONFIG_PCI
  508. if (pdev)
  509. pci_release_regions(pdev);
  510. err_out:
  511. #endif
  512. if (pdev)
  513. pci_disable_device(pdev);
  514. return rc;
  515. }
  516. static void tlan_eisa_cleanup(void)
  517. {
  518. struct net_device *dev;
  519. struct tlan_priv *priv;
  520. while (tlan_have_eisa) {
  521. dev = tlan_eisa_devices;
  522. priv = netdev_priv(dev);
  523. if (priv->dma_storage) {
  524. pci_free_consistent(priv->pci_dev, priv->dma_size,
  525. priv->dma_storage,
  526. priv->dma_storage_dma);
  527. }
  528. release_region(dev->base_addr, 0x10);
  529. unregister_netdev(dev);
  530. tlan_eisa_devices = priv->next_device;
  531. free_netdev(dev);
  532. tlan_have_eisa--;
  533. }
  534. }
  535. static void __exit tlan_exit(void)
  536. {
  537. pci_unregister_driver(&tlan_driver);
  538. if (tlan_have_eisa)
  539. tlan_eisa_cleanup();
  540. }
  541. /* Module loading/unloading */
  542. module_init(tlan_probe);
  543. module_exit(tlan_exit);
  544. /**************************************************************
  545. * tlan_eisa_probe
  546. *
  547. * Returns: 0 on success, 1 otherwise
  548. *
  549. * Parms: None
  550. *
  551. *
  552. * This functions probes for EISA devices and calls
  553. * TLan_probe1 when one is found.
  554. *
  555. *************************************************************/
  556. static void __init tlan_eisa_probe(void)
  557. {
  558. long ioaddr;
  559. int rc = -ENODEV;
  560. int irq;
  561. u16 device_id;
  562. if (!EISA_bus) {
  563. TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
  564. return;
  565. }
  566. /* Loop through all slots of the EISA bus */
  567. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  568. TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
  569. (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
  570. TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
  571. (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
  572. TLAN_DBG(TLAN_DEBUG_PROBE,
  573. "Probing for EISA adapter at IO: 0x%4x : ",
  574. (int) ioaddr);
  575. if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
  576. goto out;
  577. if (inw(ioaddr + EISA_ID) != 0x110E) {
  578. release_region(ioaddr, 0x10);
  579. goto out;
  580. }
  581. device_id = inw(ioaddr + EISA_ID2);
  582. if (device_id != 0x20F1 && device_id != 0x40F1) {
  583. release_region(ioaddr, 0x10);
  584. goto out;
  585. }
  586. /* check if adapter is enabled */
  587. if (inb(ioaddr + EISA_CR) != 0x1) {
  588. release_region(ioaddr, 0x10);
  589. goto out2;
  590. }
  591. if (debug == 0x10)
  592. pr_info("Found one\n");
  593. /* Get irq from board */
  594. switch (inb(ioaddr + 0xcc0)) {
  595. case(0x10):
  596. irq = 5;
  597. break;
  598. case(0x20):
  599. irq = 9;
  600. break;
  601. case(0x40):
  602. irq = 10;
  603. break;
  604. case(0x80):
  605. irq = 11;
  606. break;
  607. default:
  608. goto out;
  609. }
  610. /* Setup the newly found eisa adapter */
  611. rc = tlan_probe1(NULL, ioaddr, irq,
  612. 12, NULL);
  613. continue;
  614. out:
  615. if (debug == 0x10)
  616. pr_info("None found\n");
  617. continue;
  618. out2:
  619. if (debug == 0x10)
  620. pr_info("Card found but it is not enabled, skipping\n");
  621. continue;
  622. }
  623. }
  624. #ifdef CONFIG_NET_POLL_CONTROLLER
  625. static void tlan_poll(struct net_device *dev)
  626. {
  627. disable_irq(dev->irq);
  628. tlan_handle_interrupt(dev->irq, dev);
  629. enable_irq(dev->irq);
  630. }
  631. #endif
  632. static const struct net_device_ops tlan_netdev_ops = {
  633. .ndo_open = tlan_open,
  634. .ndo_stop = tlan_close,
  635. .ndo_start_xmit = tlan_start_tx,
  636. .ndo_tx_timeout = tlan_tx_timeout,
  637. .ndo_get_stats = tlan_get_stats,
  638. .ndo_set_rx_mode = tlan_set_multicast_list,
  639. .ndo_do_ioctl = tlan_ioctl,
  640. .ndo_set_mac_address = eth_mac_addr,
  641. .ndo_validate_addr = eth_validate_addr,
  642. #ifdef CONFIG_NET_POLL_CONTROLLER
  643. .ndo_poll_controller = tlan_poll,
  644. #endif
  645. };
  646. static void tlan_get_drvinfo(struct net_device *dev,
  647. struct ethtool_drvinfo *info)
  648. {
  649. struct tlan_priv *priv = netdev_priv(dev);
  650. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  651. if (priv->pci_dev)
  652. strlcpy(info->bus_info, pci_name(priv->pci_dev),
  653. sizeof(info->bus_info));
  654. else
  655. strlcpy(info->bus_info, "EISA", sizeof(info->bus_info));
  656. }
  657. static int tlan_get_eeprom_len(struct net_device *dev)
  658. {
  659. return TLAN_EEPROM_SIZE;
  660. }
  661. static int tlan_get_eeprom(struct net_device *dev,
  662. struct ethtool_eeprom *eeprom, u8 *data)
  663. {
  664. int i;
  665. for (i = 0; i < TLAN_EEPROM_SIZE; i++)
  666. if (tlan_ee_read_byte(dev, i, &data[i]))
  667. return -EIO;
  668. return 0;
  669. }
  670. static const struct ethtool_ops tlan_ethtool_ops = {
  671. .get_drvinfo = tlan_get_drvinfo,
  672. .get_link = ethtool_op_get_link,
  673. .get_eeprom_len = tlan_get_eeprom_len,
  674. .get_eeprom = tlan_get_eeprom,
  675. };
  676. /***************************************************************
  677. * tlan_init
  678. *
  679. * Returns:
  680. * 0 on success, error code otherwise.
  681. * Parms:
  682. * dev The structure of the device to be
  683. * init'ed.
  684. *
  685. * This function completes the initialization of the
  686. * device structure and driver. It reserves the IO
  687. * addresses, allocates memory for the lists and bounce
  688. * buffers, retrieves the MAC address from the eeprom
  689. * and assignes the device's methods.
  690. *
  691. **************************************************************/
  692. static int tlan_init(struct net_device *dev)
  693. {
  694. int dma_size;
  695. int err;
  696. int i;
  697. struct tlan_priv *priv;
  698. priv = netdev_priv(dev);
  699. dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
  700. * (sizeof(struct tlan_list));
  701. priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
  702. dma_size,
  703. &priv->dma_storage_dma);
  704. priv->dma_size = dma_size;
  705. if (priv->dma_storage == NULL) {
  706. pr_err("Could not allocate lists and buffers for %s\n",
  707. dev->name);
  708. return -ENOMEM;
  709. }
  710. memset(priv->dma_storage, 0, dma_size);
  711. priv->rx_list = (struct tlan_list *)
  712. ALIGN((unsigned long)priv->dma_storage, 8);
  713. priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
  714. priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
  715. priv->tx_list_dma =
  716. priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
  717. err = 0;
  718. for (i = 0; i < ETH_ALEN; i++)
  719. err |= tlan_ee_read_byte(dev,
  720. (u8) priv->adapter->addr_ofs + i,
  721. (u8 *) &dev->dev_addr[i]);
  722. if (err) {
  723. pr_err("%s: Error reading MAC from eeprom: %d\n",
  724. dev->name, err);
  725. }
  726. /* Olicom OC-2325/OC-2326 have the address byte-swapped */
  727. if (priv->adapter->addr_ofs == 0xf8) {
  728. for (i = 0; i < ETH_ALEN; i += 2) {
  729. char tmp = dev->dev_addr[i];
  730. dev->dev_addr[i] = dev->dev_addr[i + 1];
  731. dev->dev_addr[i + 1] = tmp;
  732. }
  733. }
  734. netif_carrier_off(dev);
  735. /* Device methods */
  736. dev->netdev_ops = &tlan_netdev_ops;
  737. dev->ethtool_ops = &tlan_ethtool_ops;
  738. dev->watchdog_timeo = TX_TIMEOUT;
  739. return 0;
  740. }
  741. /***************************************************************
  742. * tlan_open
  743. *
  744. * Returns:
  745. * 0 on success, error code otherwise.
  746. * Parms:
  747. * dev Structure of device to be opened.
  748. *
  749. * This routine puts the driver and TLAN adapter in a
  750. * state where it is ready to send and receive packets.
  751. * It allocates the IRQ, resets and brings the adapter
  752. * out of reset, and allows interrupts. It also delays
  753. * the startup for autonegotiation or sends a Rx GO
  754. * command to the adapter, as appropriate.
  755. *
  756. **************************************************************/
  757. static int tlan_open(struct net_device *dev)
  758. {
  759. struct tlan_priv *priv = netdev_priv(dev);
  760. int err;
  761. priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
  762. err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
  763. dev->name, dev);
  764. if (err) {
  765. netdev_err(dev, "Cannot open because IRQ %d is already in use\n",
  766. dev->irq);
  767. return err;
  768. }
  769. timer_setup(&priv->timer, NULL, 0);
  770. timer_setup(&priv->media_timer, tlan_phy_monitor, 0);
  771. tlan_start(dev);
  772. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
  773. dev->name, priv->tlan_rev);
  774. return 0;
  775. }
  776. /**************************************************************
  777. * tlan_ioctl
  778. *
  779. * Returns:
  780. * 0 on success, error code otherwise
  781. * Params:
  782. * dev structure of device to receive ioctl.
  783. *
  784. * rq ifreq structure to hold userspace data.
  785. *
  786. * cmd ioctl command.
  787. *
  788. *
  789. *************************************************************/
  790. static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  791. {
  792. struct tlan_priv *priv = netdev_priv(dev);
  793. struct mii_ioctl_data *data = if_mii(rq);
  794. u32 phy = priv->phy[priv->phy_num];
  795. if (!priv->phy_online)
  796. return -EAGAIN;
  797. switch (cmd) {
  798. case SIOCGMIIPHY: /* get address of MII PHY in use. */
  799. data->phy_id = phy;
  800. /* fall through */
  801. case SIOCGMIIREG: /* read MII PHY register. */
  802. tlan_mii_read_reg(dev, data->phy_id & 0x1f,
  803. data->reg_num & 0x1f, &data->val_out);
  804. return 0;
  805. case SIOCSMIIREG: /* write MII PHY register. */
  806. tlan_mii_write_reg(dev, data->phy_id & 0x1f,
  807. data->reg_num & 0x1f, data->val_in);
  808. return 0;
  809. default:
  810. return -EOPNOTSUPP;
  811. }
  812. }
  813. /***************************************************************
  814. * tlan_tx_timeout
  815. *
  816. * Returns: nothing
  817. *
  818. * Params:
  819. * dev structure of device which timed out
  820. * during transmit.
  821. *
  822. **************************************************************/
  823. static void tlan_tx_timeout(struct net_device *dev)
  824. {
  825. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
  826. /* Ok so we timed out, lets see what we can do about it...*/
  827. tlan_free_lists(dev);
  828. tlan_reset_lists(dev);
  829. tlan_read_and_clear_stats(dev, TLAN_IGNORE);
  830. tlan_reset_adapter(dev);
  831. netif_trans_update(dev); /* prevent tx timeout */
  832. netif_wake_queue(dev);
  833. }
  834. /***************************************************************
  835. * tlan_tx_timeout_work
  836. *
  837. * Returns: nothing
  838. *
  839. * Params:
  840. * work work item of device which timed out
  841. *
  842. **************************************************************/
  843. static void tlan_tx_timeout_work(struct work_struct *work)
  844. {
  845. struct tlan_priv *priv =
  846. container_of(work, struct tlan_priv, tlan_tqueue);
  847. tlan_tx_timeout(priv->dev);
  848. }
  849. /***************************************************************
  850. * tlan_start_tx
  851. *
  852. * Returns:
  853. * 0 on success, non-zero on failure.
  854. * Parms:
  855. * skb A pointer to the sk_buff containing the
  856. * frame to be sent.
  857. * dev The device to send the data on.
  858. *
  859. * This function adds a frame to the Tx list to be sent
  860. * ASAP. First it verifies that the adapter is ready and
  861. * there is room in the queue. Then it sets up the next
  862. * available list, copies the frame to the corresponding
  863. * buffer. If the adapter Tx channel is idle, it gives
  864. * the adapter a Tx Go command on the list, otherwise it
  865. * sets the forward address of the previous list to point
  866. * to this one. Then it frees the sk_buff.
  867. *
  868. **************************************************************/
  869. static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
  870. {
  871. struct tlan_priv *priv = netdev_priv(dev);
  872. dma_addr_t tail_list_phys;
  873. struct tlan_list *tail_list;
  874. unsigned long flags;
  875. unsigned int txlen;
  876. if (!priv->phy_online) {
  877. TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
  878. dev->name);
  879. dev_kfree_skb_any(skb);
  880. return NETDEV_TX_OK;
  881. }
  882. if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
  883. return NETDEV_TX_OK;
  884. txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
  885. tail_list = priv->tx_list + priv->tx_tail;
  886. tail_list_phys =
  887. priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
  888. if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
  889. TLAN_DBG(TLAN_DEBUG_TX,
  890. "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
  891. dev->name, priv->tx_head, priv->tx_tail);
  892. netif_stop_queue(dev);
  893. priv->tx_busy_count++;
  894. return NETDEV_TX_BUSY;
  895. }
  896. tail_list->forward = 0;
  897. tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
  898. skb->data, txlen,
  899. PCI_DMA_TODEVICE);
  900. tlan_store_skb(tail_list, skb);
  901. tail_list->frame_size = (u16) txlen;
  902. tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
  903. tail_list->buffer[1].count = 0;
  904. tail_list->buffer[1].address = 0;
  905. spin_lock_irqsave(&priv->lock, flags);
  906. tail_list->c_stat = TLAN_CSTAT_READY;
  907. if (!priv->tx_in_progress) {
  908. priv->tx_in_progress = 1;
  909. TLAN_DBG(TLAN_DEBUG_TX,
  910. "TRANSMIT: Starting TX on buffer %d\n",
  911. priv->tx_tail);
  912. outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
  913. outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
  914. } else {
  915. TLAN_DBG(TLAN_DEBUG_TX,
  916. "TRANSMIT: Adding buffer %d to TX channel\n",
  917. priv->tx_tail);
  918. if (priv->tx_tail == 0) {
  919. (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
  920. = tail_list_phys;
  921. } else {
  922. (priv->tx_list + (priv->tx_tail - 1))->forward
  923. = tail_list_phys;
  924. }
  925. }
  926. spin_unlock_irqrestore(&priv->lock, flags);
  927. CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
  928. return NETDEV_TX_OK;
  929. }
  930. /***************************************************************
  931. * tlan_handle_interrupt
  932. *
  933. * Returns:
  934. * Nothing
  935. * Parms:
  936. * irq The line on which the interrupt
  937. * occurred.
  938. * dev_id A pointer to the device assigned to
  939. * this irq line.
  940. *
  941. * This function handles an interrupt generated by its
  942. * assigned TLAN adapter. The function deactivates
  943. * interrupts on its adapter, records the type of
  944. * interrupt, executes the appropriate subhandler, and
  945. * acknowdges the interrupt to the adapter (thus
  946. * re-enabling adapter interrupts.
  947. *
  948. **************************************************************/
  949. static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
  950. {
  951. struct net_device *dev = dev_id;
  952. struct tlan_priv *priv = netdev_priv(dev);
  953. u16 host_int;
  954. u16 type;
  955. spin_lock(&priv->lock);
  956. host_int = inw(dev->base_addr + TLAN_HOST_INT);
  957. type = (host_int & TLAN_HI_IT_MASK) >> 2;
  958. if (type) {
  959. u32 ack;
  960. u32 host_cmd;
  961. outw(host_int, dev->base_addr + TLAN_HOST_INT);
  962. ack = tlan_int_vector[type](dev, host_int);
  963. if (ack) {
  964. host_cmd = TLAN_HC_ACK | ack | (type << 18);
  965. outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
  966. }
  967. }
  968. spin_unlock(&priv->lock);
  969. return IRQ_RETVAL(type);
  970. }
  971. /***************************************************************
  972. * tlan_close
  973. *
  974. * Returns:
  975. * An error code.
  976. * Parms:
  977. * dev The device structure of the device to
  978. * close.
  979. *
  980. * This function shuts down the adapter. It records any
  981. * stats, puts the adapter into reset state, deactivates
  982. * its time as needed, and frees the irq it is using.
  983. *
  984. **************************************************************/
  985. static int tlan_close(struct net_device *dev)
  986. {
  987. tlan_stop(dev);
  988. free_irq(dev->irq, dev);
  989. tlan_free_lists(dev);
  990. TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
  991. return 0;
  992. }
  993. /***************************************************************
  994. * tlan_get_stats
  995. *
  996. * Returns:
  997. * A pointer to the device's statistics structure.
  998. * Parms:
  999. * dev The device structure to return the
  1000. * stats for.
  1001. *
  1002. * This function updates the devices statistics by reading
  1003. * the TLAN chip's onboard registers. Then it returns the
  1004. * address of the statistics structure.
  1005. *
  1006. **************************************************************/
  1007. static struct net_device_stats *tlan_get_stats(struct net_device *dev)
  1008. {
  1009. struct tlan_priv *priv = netdev_priv(dev);
  1010. int i;
  1011. /* Should only read stats if open ? */
  1012. tlan_read_and_clear_stats(dev, TLAN_RECORD);
  1013. TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
  1014. priv->rx_eoc_count);
  1015. TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
  1016. priv->tx_busy_count);
  1017. if (debug & TLAN_DEBUG_GNRL) {
  1018. tlan_print_dio(dev->base_addr);
  1019. tlan_phy_print(dev);
  1020. }
  1021. if (debug & TLAN_DEBUG_LIST) {
  1022. for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
  1023. tlan_print_list(priv->rx_list + i, "RX", i);
  1024. for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
  1025. tlan_print_list(priv->tx_list + i, "TX", i);
  1026. }
  1027. return &dev->stats;
  1028. }
  1029. /***************************************************************
  1030. * tlan_set_multicast_list
  1031. *
  1032. * Returns:
  1033. * Nothing
  1034. * Parms:
  1035. * dev The device structure to set the
  1036. * multicast list for.
  1037. *
  1038. * This function sets the TLAN adaptor to various receive
  1039. * modes. If the IFF_PROMISC flag is set, promiscuous
  1040. * mode is acitviated. Otherwise, promiscuous mode is
  1041. * turned off. If the IFF_ALLMULTI flag is set, then
  1042. * the hash table is set to receive all group addresses.
  1043. * Otherwise, the first three multicast addresses are
  1044. * stored in AREG_1-3, and the rest are selected via the
  1045. * hash table, as necessary.
  1046. *
  1047. **************************************************************/
  1048. static void tlan_set_multicast_list(struct net_device *dev)
  1049. {
  1050. struct netdev_hw_addr *ha;
  1051. u32 hash1 = 0;
  1052. u32 hash2 = 0;
  1053. int i;
  1054. u32 offset;
  1055. u8 tmp;
  1056. if (dev->flags & IFF_PROMISC) {
  1057. tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
  1058. tlan_dio_write8(dev->base_addr,
  1059. TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
  1060. } else {
  1061. tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
  1062. tlan_dio_write8(dev->base_addr,
  1063. TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
  1064. if (dev->flags & IFF_ALLMULTI) {
  1065. for (i = 0; i < 3; i++)
  1066. tlan_set_mac(dev, i + 1, NULL);
  1067. tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
  1068. 0xffffffff);
  1069. tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
  1070. 0xffffffff);
  1071. } else {
  1072. i = 0;
  1073. netdev_for_each_mc_addr(ha, dev) {
  1074. if (i < 3) {
  1075. tlan_set_mac(dev, i + 1,
  1076. (char *) &ha->addr);
  1077. } else {
  1078. offset =
  1079. tlan_hash_func((u8 *)&ha->addr);
  1080. if (offset < 32)
  1081. hash1 |= (1 << offset);
  1082. else
  1083. hash2 |= (1 << (offset - 32));
  1084. }
  1085. i++;
  1086. }
  1087. for ( ; i < 3; i++)
  1088. tlan_set_mac(dev, i + 1, NULL);
  1089. tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
  1090. tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
  1091. }
  1092. }
  1093. }
  1094. /*****************************************************************************
  1095. ******************************************************************************
  1096. ThunderLAN driver interrupt vectors and table
  1097. please see chap. 4, "Interrupt Handling" of the "ThunderLAN
  1098. Programmer's Guide" for more informations on handling interrupts
  1099. generated by TLAN based adapters.
  1100. ******************************************************************************
  1101. *****************************************************************************/
  1102. /***************************************************************
  1103. * tlan_handle_tx_eof
  1104. *
  1105. * Returns:
  1106. * 1
  1107. * Parms:
  1108. * dev Device assigned the IRQ that was
  1109. * raised.
  1110. * host_int The contents of the HOST_INT
  1111. * port.
  1112. *
  1113. * This function handles Tx EOF interrupts which are raised
  1114. * by the adapter when it has completed sending the
  1115. * contents of a buffer. If detemines which list/buffer
  1116. * was completed and resets it. If the buffer was the last
  1117. * in the channel (EOC), then the function checks to see if
  1118. * another buffer is ready to send, and if so, sends a Tx
  1119. * Go command. Finally, the driver activates/continues the
  1120. * activity LED.
  1121. *
  1122. **************************************************************/
  1123. static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
  1124. {
  1125. struct tlan_priv *priv = netdev_priv(dev);
  1126. int eoc = 0;
  1127. struct tlan_list *head_list;
  1128. dma_addr_t head_list_phys;
  1129. u32 ack = 0;
  1130. u16 tmp_c_stat;
  1131. TLAN_DBG(TLAN_DEBUG_TX,
  1132. "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
  1133. priv->tx_head, priv->tx_tail);
  1134. head_list = priv->tx_list + priv->tx_head;
  1135. while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
  1136. && (ack < 255)) {
  1137. struct sk_buff *skb = tlan_get_skb(head_list);
  1138. ack++;
  1139. pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
  1140. max(skb->len,
  1141. (unsigned int)TLAN_MIN_FRAME_SIZE),
  1142. PCI_DMA_TODEVICE);
  1143. dev_kfree_skb_any(skb);
  1144. head_list->buffer[8].address = 0;
  1145. head_list->buffer[9].address = 0;
  1146. if (tmp_c_stat & TLAN_CSTAT_EOC)
  1147. eoc = 1;
  1148. dev->stats.tx_bytes += head_list->frame_size;
  1149. head_list->c_stat = TLAN_CSTAT_UNUSED;
  1150. netif_start_queue(dev);
  1151. CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
  1152. head_list = priv->tx_list + priv->tx_head;
  1153. }
  1154. if (!ack)
  1155. netdev_info(dev,
  1156. "Received interrupt for uncompleted TX frame\n");
  1157. if (eoc) {
  1158. TLAN_DBG(TLAN_DEBUG_TX,
  1159. "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
  1160. priv->tx_head, priv->tx_tail);
  1161. head_list = priv->tx_list + priv->tx_head;
  1162. head_list_phys = priv->tx_list_dma
  1163. + sizeof(struct tlan_list)*priv->tx_head;
  1164. if ((head_list->c_stat & TLAN_CSTAT_READY)
  1165. == TLAN_CSTAT_READY) {
  1166. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
  1167. ack |= TLAN_HC_GO;
  1168. } else {
  1169. priv->tx_in_progress = 0;
  1170. }
  1171. }
  1172. if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
  1173. tlan_dio_write8(dev->base_addr,
  1174. TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
  1175. if (priv->timer.function == NULL) {
  1176. priv->timer.function = tlan_timer;
  1177. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1178. priv->timer_set_at = jiffies;
  1179. priv->timer_type = TLAN_TIMER_ACTIVITY;
  1180. add_timer(&priv->timer);
  1181. } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
  1182. priv->timer_set_at = jiffies;
  1183. }
  1184. }
  1185. return ack;
  1186. }
  1187. /***************************************************************
  1188. * TLan_HandleStatOverflow
  1189. *
  1190. * Returns:
  1191. * 1
  1192. * Parms:
  1193. * dev Device assigned the IRQ that was
  1194. * raised.
  1195. * host_int The contents of the HOST_INT
  1196. * port.
  1197. *
  1198. * This function handles the Statistics Overflow interrupt
  1199. * which means that one or more of the TLAN statistics
  1200. * registers has reached 1/2 capacity and needs to be read.
  1201. *
  1202. **************************************************************/
  1203. static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
  1204. {
  1205. tlan_read_and_clear_stats(dev, TLAN_RECORD);
  1206. return 1;
  1207. }
  1208. /***************************************************************
  1209. * TLan_HandleRxEOF
  1210. *
  1211. * Returns:
  1212. * 1
  1213. * Parms:
  1214. * dev Device assigned the IRQ that was
  1215. * raised.
  1216. * host_int The contents of the HOST_INT
  1217. * port.
  1218. *
  1219. * This function handles the Rx EOF interrupt which
  1220. * indicates a frame has been received by the adapter from
  1221. * the net and the frame has been transferred to memory.
  1222. * The function determines the bounce buffer the frame has
  1223. * been loaded into, creates a new sk_buff big enough to
  1224. * hold the frame, and sends it to protocol stack. It
  1225. * then resets the used buffer and appends it to the end
  1226. * of the list. If the frame was the last in the Rx
  1227. * channel (EOC), the function restarts the receive channel
  1228. * by sending an Rx Go command to the adapter. Then it
  1229. * activates/continues the activity LED.
  1230. *
  1231. **************************************************************/
  1232. static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
  1233. {
  1234. struct tlan_priv *priv = netdev_priv(dev);
  1235. u32 ack = 0;
  1236. int eoc = 0;
  1237. struct tlan_list *head_list;
  1238. struct sk_buff *skb;
  1239. struct tlan_list *tail_list;
  1240. u16 tmp_c_stat;
  1241. dma_addr_t head_list_phys;
  1242. TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
  1243. priv->rx_head, priv->rx_tail);
  1244. head_list = priv->rx_list + priv->rx_head;
  1245. head_list_phys =
  1246. priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
  1247. while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
  1248. && (ack < 255)) {
  1249. dma_addr_t frame_dma = head_list->buffer[0].address;
  1250. u32 frame_size = head_list->frame_size;
  1251. struct sk_buff *new_skb;
  1252. ack++;
  1253. if (tmp_c_stat & TLAN_CSTAT_EOC)
  1254. eoc = 1;
  1255. new_skb = netdev_alloc_skb_ip_align(dev,
  1256. TLAN_MAX_FRAME_SIZE + 5);
  1257. if (!new_skb)
  1258. goto drop_and_reuse;
  1259. skb = tlan_get_skb(head_list);
  1260. pci_unmap_single(priv->pci_dev, frame_dma,
  1261. TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1262. skb_put(skb, frame_size);
  1263. dev->stats.rx_bytes += frame_size;
  1264. skb->protocol = eth_type_trans(skb, dev);
  1265. netif_rx(skb);
  1266. head_list->buffer[0].address =
  1267. pci_map_single(priv->pci_dev, new_skb->data,
  1268. TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1269. tlan_store_skb(head_list, new_skb);
  1270. drop_and_reuse:
  1271. head_list->forward = 0;
  1272. head_list->c_stat = 0;
  1273. tail_list = priv->rx_list + priv->rx_tail;
  1274. tail_list->forward = head_list_phys;
  1275. CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
  1276. CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
  1277. head_list = priv->rx_list + priv->rx_head;
  1278. head_list_phys = priv->rx_list_dma
  1279. + sizeof(struct tlan_list)*priv->rx_head;
  1280. }
  1281. if (!ack)
  1282. netdev_info(dev,
  1283. "Received interrupt for uncompleted RX frame\n");
  1284. if (eoc) {
  1285. TLAN_DBG(TLAN_DEBUG_RX,
  1286. "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
  1287. priv->rx_head, priv->rx_tail);
  1288. head_list = priv->rx_list + priv->rx_head;
  1289. head_list_phys = priv->rx_list_dma
  1290. + sizeof(struct tlan_list)*priv->rx_head;
  1291. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
  1292. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1293. priv->rx_eoc_count++;
  1294. }
  1295. if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
  1296. tlan_dio_write8(dev->base_addr,
  1297. TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
  1298. if (priv->timer.function == NULL) {
  1299. priv->timer.function = tlan_timer;
  1300. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1301. priv->timer_set_at = jiffies;
  1302. priv->timer_type = TLAN_TIMER_ACTIVITY;
  1303. add_timer(&priv->timer);
  1304. } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
  1305. priv->timer_set_at = jiffies;
  1306. }
  1307. }
  1308. return ack;
  1309. }
  1310. /***************************************************************
  1311. * tlan_handle_dummy
  1312. *
  1313. * Returns:
  1314. * 1
  1315. * Parms:
  1316. * dev Device assigned the IRQ that was
  1317. * raised.
  1318. * host_int The contents of the HOST_INT
  1319. * port.
  1320. *
  1321. * This function handles the Dummy interrupt, which is
  1322. * raised whenever a test interrupt is generated by setting
  1323. * the Req_Int bit of HOST_CMD to 1.
  1324. *
  1325. **************************************************************/
  1326. static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
  1327. {
  1328. netdev_info(dev, "Test interrupt\n");
  1329. return 1;
  1330. }
  1331. /***************************************************************
  1332. * tlan_handle_tx_eoc
  1333. *
  1334. * Returns:
  1335. * 1
  1336. * Parms:
  1337. * dev Device assigned the IRQ that was
  1338. * raised.
  1339. * host_int The contents of the HOST_INT
  1340. * port.
  1341. *
  1342. * This driver is structured to determine EOC occurrences by
  1343. * reading the CSTAT member of the list structure. Tx EOC
  1344. * interrupts are disabled via the DIO INTDIS register.
  1345. * However, TLAN chips before revision 3.0 didn't have this
  1346. * functionality, so process EOC events if this is the
  1347. * case.
  1348. *
  1349. **************************************************************/
  1350. static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
  1351. {
  1352. struct tlan_priv *priv = netdev_priv(dev);
  1353. struct tlan_list *head_list;
  1354. dma_addr_t head_list_phys;
  1355. u32 ack = 1;
  1356. if (priv->tlan_rev < 0x30) {
  1357. TLAN_DBG(TLAN_DEBUG_TX,
  1358. "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
  1359. priv->tx_head, priv->tx_tail);
  1360. head_list = priv->tx_list + priv->tx_head;
  1361. head_list_phys = priv->tx_list_dma
  1362. + sizeof(struct tlan_list)*priv->tx_head;
  1363. if ((head_list->c_stat & TLAN_CSTAT_READY)
  1364. == TLAN_CSTAT_READY) {
  1365. netif_stop_queue(dev);
  1366. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
  1367. ack |= TLAN_HC_GO;
  1368. } else {
  1369. priv->tx_in_progress = 0;
  1370. }
  1371. }
  1372. return ack;
  1373. }
  1374. /***************************************************************
  1375. * tlan_handle_status_check
  1376. *
  1377. * Returns:
  1378. * 0 if Adapter check, 1 if Network Status check.
  1379. * Parms:
  1380. * dev Device assigned the IRQ that was
  1381. * raised.
  1382. * host_int The contents of the HOST_INT
  1383. * port.
  1384. *
  1385. * This function handles Adapter Check/Network Status
  1386. * interrupts generated by the adapter. It checks the
  1387. * vector in the HOST_INT register to determine if it is
  1388. * an Adapter Check interrupt. If so, it resets the
  1389. * adapter. Otherwise it clears the status registers
  1390. * and services the PHY.
  1391. *
  1392. **************************************************************/
  1393. static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
  1394. {
  1395. struct tlan_priv *priv = netdev_priv(dev);
  1396. u32 ack;
  1397. u32 error;
  1398. u8 net_sts;
  1399. u32 phy;
  1400. u16 tlphy_ctl;
  1401. u16 tlphy_sts;
  1402. ack = 1;
  1403. if (host_int & TLAN_HI_IV_MASK) {
  1404. netif_stop_queue(dev);
  1405. error = inl(dev->base_addr + TLAN_CH_PARM);
  1406. netdev_info(dev, "Adaptor Error = 0x%x\n", error);
  1407. tlan_read_and_clear_stats(dev, TLAN_RECORD);
  1408. outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
  1409. schedule_work(&priv->tlan_tqueue);
  1410. netif_wake_queue(dev);
  1411. ack = 0;
  1412. } else {
  1413. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
  1414. phy = priv->phy[priv->phy_num];
  1415. net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
  1416. if (net_sts) {
  1417. tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
  1418. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
  1419. dev->name, (unsigned) net_sts);
  1420. }
  1421. if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
  1422. tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
  1423. tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
  1424. if (!(tlphy_sts & TLAN_TS_POLOK) &&
  1425. !(tlphy_ctl & TLAN_TC_SWAPOL)) {
  1426. tlphy_ctl |= TLAN_TC_SWAPOL;
  1427. tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
  1428. tlphy_ctl);
  1429. } else if ((tlphy_sts & TLAN_TS_POLOK) &&
  1430. (tlphy_ctl & TLAN_TC_SWAPOL)) {
  1431. tlphy_ctl &= ~TLAN_TC_SWAPOL;
  1432. tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
  1433. tlphy_ctl);
  1434. }
  1435. if (debug)
  1436. tlan_phy_print(dev);
  1437. }
  1438. }
  1439. return ack;
  1440. }
  1441. /***************************************************************
  1442. * tlan_handle_rx_eoc
  1443. *
  1444. * Returns:
  1445. * 1
  1446. * Parms:
  1447. * dev Device assigned the IRQ that was
  1448. * raised.
  1449. * host_int The contents of the HOST_INT
  1450. * port.
  1451. *
  1452. * This driver is structured to determine EOC occurrences by
  1453. * reading the CSTAT member of the list structure. Rx EOC
  1454. * interrupts are disabled via the DIO INTDIS register.
  1455. * However, TLAN chips before revision 3.0 didn't have this
  1456. * CSTAT member or a INTDIS register, so if this chip is
  1457. * pre-3.0, process EOC interrupts normally.
  1458. *
  1459. **************************************************************/
  1460. static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
  1461. {
  1462. struct tlan_priv *priv = netdev_priv(dev);
  1463. dma_addr_t head_list_phys;
  1464. u32 ack = 1;
  1465. if (priv->tlan_rev < 0x30) {
  1466. TLAN_DBG(TLAN_DEBUG_RX,
  1467. "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
  1468. priv->rx_head, priv->rx_tail);
  1469. head_list_phys = priv->rx_list_dma
  1470. + sizeof(struct tlan_list)*priv->rx_head;
  1471. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
  1472. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1473. priv->rx_eoc_count++;
  1474. }
  1475. return ack;
  1476. }
  1477. /*****************************************************************************
  1478. ******************************************************************************
  1479. ThunderLAN driver timer function
  1480. ******************************************************************************
  1481. *****************************************************************************/
  1482. /***************************************************************
  1483. * tlan_timer
  1484. *
  1485. * Returns:
  1486. * Nothing
  1487. * Parms:
  1488. * data A value given to add timer when
  1489. * add_timer was called.
  1490. *
  1491. * This function handles timed functionality for the
  1492. * TLAN driver. The two current timer uses are for
  1493. * delaying for autonegotionation and driving the ACT LED.
  1494. * - Autonegotiation requires being allowed about
  1495. * 2 1/2 seconds before attempting to transmit a
  1496. * packet. It would be a very bad thing to hang
  1497. * the kernel this long, so the driver doesn't
  1498. * allow transmission 'til after this time, for
  1499. * certain PHYs. It would be much nicer if all
  1500. * PHYs were interrupt-capable like the internal
  1501. * PHY.
  1502. * - The ACT LED, which shows adapter activity, is
  1503. * driven by the driver, and so must be left on
  1504. * for a short period to power up the LED so it
  1505. * can be seen. This delay can be changed by
  1506. * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
  1507. * if desired. 100 ms produces a slightly
  1508. * sluggish response.
  1509. *
  1510. **************************************************************/
  1511. static void tlan_timer(struct timer_list *t)
  1512. {
  1513. struct tlan_priv *priv = from_timer(priv, t, timer);
  1514. struct net_device *dev = priv->dev;
  1515. u32 elapsed;
  1516. unsigned long flags = 0;
  1517. priv->timer.function = NULL;
  1518. switch (priv->timer_type) {
  1519. case TLAN_TIMER_PHY_PDOWN:
  1520. tlan_phy_power_down(dev);
  1521. break;
  1522. case TLAN_TIMER_PHY_PUP:
  1523. tlan_phy_power_up(dev);
  1524. break;
  1525. case TLAN_TIMER_PHY_RESET:
  1526. tlan_phy_reset(dev);
  1527. break;
  1528. case TLAN_TIMER_PHY_START_LINK:
  1529. tlan_phy_start_link(dev);
  1530. break;
  1531. case TLAN_TIMER_PHY_FINISH_AN:
  1532. tlan_phy_finish_auto_neg(dev);
  1533. break;
  1534. case TLAN_TIMER_FINISH_RESET:
  1535. tlan_finish_reset(dev);
  1536. break;
  1537. case TLAN_TIMER_ACTIVITY:
  1538. spin_lock_irqsave(&priv->lock, flags);
  1539. if (priv->timer.function == NULL) {
  1540. elapsed = jiffies - priv->timer_set_at;
  1541. if (elapsed >= TLAN_TIMER_ACT_DELAY) {
  1542. tlan_dio_write8(dev->base_addr,
  1543. TLAN_LED_REG, TLAN_LED_LINK);
  1544. } else {
  1545. priv->timer.expires = priv->timer_set_at
  1546. + TLAN_TIMER_ACT_DELAY;
  1547. spin_unlock_irqrestore(&priv->lock, flags);
  1548. add_timer(&priv->timer);
  1549. break;
  1550. }
  1551. }
  1552. spin_unlock_irqrestore(&priv->lock, flags);
  1553. break;
  1554. default:
  1555. break;
  1556. }
  1557. }
  1558. /*****************************************************************************
  1559. ******************************************************************************
  1560. ThunderLAN driver adapter related routines
  1561. ******************************************************************************
  1562. *****************************************************************************/
  1563. /***************************************************************
  1564. * tlan_reset_lists
  1565. *
  1566. * Returns:
  1567. * Nothing
  1568. * Parms:
  1569. * dev The device structure with the list
  1570. * structures to be reset.
  1571. *
  1572. * This routine sets the variables associated with managing
  1573. * the TLAN lists to their initial values.
  1574. *
  1575. **************************************************************/
  1576. static void tlan_reset_lists(struct net_device *dev)
  1577. {
  1578. struct tlan_priv *priv = netdev_priv(dev);
  1579. int i;
  1580. struct tlan_list *list;
  1581. dma_addr_t list_phys;
  1582. struct sk_buff *skb;
  1583. priv->tx_head = 0;
  1584. priv->tx_tail = 0;
  1585. for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
  1586. list = priv->tx_list + i;
  1587. list->c_stat = TLAN_CSTAT_UNUSED;
  1588. list->buffer[0].address = 0;
  1589. list->buffer[2].count = 0;
  1590. list->buffer[2].address = 0;
  1591. list->buffer[8].address = 0;
  1592. list->buffer[9].address = 0;
  1593. }
  1594. priv->rx_head = 0;
  1595. priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
  1596. for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
  1597. list = priv->rx_list + i;
  1598. list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
  1599. list->c_stat = TLAN_CSTAT_READY;
  1600. list->frame_size = TLAN_MAX_FRAME_SIZE;
  1601. list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
  1602. skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
  1603. if (!skb)
  1604. break;
  1605. list->buffer[0].address = pci_map_single(priv->pci_dev,
  1606. skb->data,
  1607. TLAN_MAX_FRAME_SIZE,
  1608. PCI_DMA_FROMDEVICE);
  1609. tlan_store_skb(list, skb);
  1610. list->buffer[1].count = 0;
  1611. list->buffer[1].address = 0;
  1612. list->forward = list_phys + sizeof(struct tlan_list);
  1613. }
  1614. /* in case ran out of memory early, clear bits */
  1615. while (i < TLAN_NUM_RX_LISTS) {
  1616. tlan_store_skb(priv->rx_list + i, NULL);
  1617. ++i;
  1618. }
  1619. list->forward = 0;
  1620. }
  1621. static void tlan_free_lists(struct net_device *dev)
  1622. {
  1623. struct tlan_priv *priv = netdev_priv(dev);
  1624. int i;
  1625. struct tlan_list *list;
  1626. struct sk_buff *skb;
  1627. for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
  1628. list = priv->tx_list + i;
  1629. skb = tlan_get_skb(list);
  1630. if (skb) {
  1631. pci_unmap_single(
  1632. priv->pci_dev,
  1633. list->buffer[0].address,
  1634. max(skb->len,
  1635. (unsigned int)TLAN_MIN_FRAME_SIZE),
  1636. PCI_DMA_TODEVICE);
  1637. dev_kfree_skb_any(skb);
  1638. list->buffer[8].address = 0;
  1639. list->buffer[9].address = 0;
  1640. }
  1641. }
  1642. for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
  1643. list = priv->rx_list + i;
  1644. skb = tlan_get_skb(list);
  1645. if (skb) {
  1646. pci_unmap_single(priv->pci_dev,
  1647. list->buffer[0].address,
  1648. TLAN_MAX_FRAME_SIZE,
  1649. PCI_DMA_FROMDEVICE);
  1650. dev_kfree_skb_any(skb);
  1651. list->buffer[8].address = 0;
  1652. list->buffer[9].address = 0;
  1653. }
  1654. }
  1655. }
  1656. /***************************************************************
  1657. * tlan_print_dio
  1658. *
  1659. * Returns:
  1660. * Nothing
  1661. * Parms:
  1662. * io_base Base IO port of the device of
  1663. * which to print DIO registers.
  1664. *
  1665. * This function prints out all the internal (DIO)
  1666. * registers of a TLAN chip.
  1667. *
  1668. **************************************************************/
  1669. static void tlan_print_dio(u16 io_base)
  1670. {
  1671. u32 data0, data1;
  1672. int i;
  1673. pr_info("Contents of internal registers for io base 0x%04hx\n",
  1674. io_base);
  1675. pr_info("Off. +0 +4\n");
  1676. for (i = 0; i < 0x4C; i += 8) {
  1677. data0 = tlan_dio_read32(io_base, i);
  1678. data1 = tlan_dio_read32(io_base, i + 0x4);
  1679. pr_info("0x%02x 0x%08x 0x%08x\n", i, data0, data1);
  1680. }
  1681. }
  1682. /***************************************************************
  1683. * TLan_PrintList
  1684. *
  1685. * Returns:
  1686. * Nothing
  1687. * Parms:
  1688. * list A pointer to the struct tlan_list structure to
  1689. * be printed.
  1690. * type A string to designate type of list,
  1691. * "Rx" or "Tx".
  1692. * num The index of the list.
  1693. *
  1694. * This function prints out the contents of the list
  1695. * pointed to by the list parameter.
  1696. *
  1697. **************************************************************/
  1698. static void tlan_print_list(struct tlan_list *list, char *type, int num)
  1699. {
  1700. int i;
  1701. pr_info("%s List %d at %p\n", type, num, list);
  1702. pr_info(" Forward = 0x%08x\n", list->forward);
  1703. pr_info(" CSTAT = 0x%04hx\n", list->c_stat);
  1704. pr_info(" Frame Size = 0x%04hx\n", list->frame_size);
  1705. /* for (i = 0; i < 10; i++) { */
  1706. for (i = 0; i < 2; i++) {
  1707. pr_info(" Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
  1708. i, list->buffer[i].count, list->buffer[i].address);
  1709. }
  1710. }
  1711. /***************************************************************
  1712. * tlan_read_and_clear_stats
  1713. *
  1714. * Returns:
  1715. * Nothing
  1716. * Parms:
  1717. * dev Pointer to device structure of adapter
  1718. * to which to read stats.
  1719. * record Flag indicating whether to add
  1720. *
  1721. * This functions reads all the internal status registers
  1722. * of the TLAN chip, which clears them as a side effect.
  1723. * It then either adds the values to the device's status
  1724. * struct, or discards them, depending on whether record
  1725. * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
  1726. *
  1727. **************************************************************/
  1728. static void tlan_read_and_clear_stats(struct net_device *dev, int record)
  1729. {
  1730. u32 tx_good, tx_under;
  1731. u32 rx_good, rx_over;
  1732. u32 def_tx, crc, code;
  1733. u32 multi_col, single_col;
  1734. u32 excess_col, late_col, loss;
  1735. outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
  1736. tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
  1737. tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
  1738. tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
  1739. tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
  1740. outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
  1741. rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
  1742. rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
  1743. rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
  1744. rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
  1745. outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
  1746. def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
  1747. def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
  1748. crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
  1749. code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
  1750. outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
  1751. multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
  1752. multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
  1753. single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
  1754. single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
  1755. outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
  1756. excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
  1757. late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
  1758. loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
  1759. if (record) {
  1760. dev->stats.rx_packets += rx_good;
  1761. dev->stats.rx_errors += rx_over + crc + code;
  1762. dev->stats.tx_packets += tx_good;
  1763. dev->stats.tx_errors += tx_under + loss;
  1764. dev->stats.collisions += multi_col
  1765. + single_col + excess_col + late_col;
  1766. dev->stats.rx_over_errors += rx_over;
  1767. dev->stats.rx_crc_errors += crc;
  1768. dev->stats.rx_frame_errors += code;
  1769. dev->stats.tx_aborted_errors += tx_under;
  1770. dev->stats.tx_carrier_errors += loss;
  1771. }
  1772. }
  1773. /***************************************************************
  1774. * TLan_Reset
  1775. *
  1776. * Returns:
  1777. * 0
  1778. * Parms:
  1779. * dev Pointer to device structure of adapter
  1780. * to be reset.
  1781. *
  1782. * This function resets the adapter and it's physical
  1783. * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
  1784. * Programmer's Guide" for details. The routine tries to
  1785. * implement what is detailed there, though adjustments
  1786. * have been made.
  1787. *
  1788. **************************************************************/
  1789. static void
  1790. tlan_reset_adapter(struct net_device *dev)
  1791. {
  1792. struct tlan_priv *priv = netdev_priv(dev);
  1793. int i;
  1794. u32 addr;
  1795. u32 data;
  1796. u8 data8;
  1797. priv->tlan_full_duplex = false;
  1798. priv->phy_online = 0;
  1799. netif_carrier_off(dev);
  1800. /* 1. Assert reset bit. */
  1801. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1802. data |= TLAN_HC_AD_RST;
  1803. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1804. udelay(1000);
  1805. /* 2. Turn off interrupts. (Probably isn't necessary) */
  1806. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1807. data |= TLAN_HC_INT_OFF;
  1808. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1809. /* 3. Clear AREGs and HASHs. */
  1810. for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
  1811. tlan_dio_write32(dev->base_addr, (u16) i, 0);
  1812. /* 4. Setup NetConfig register. */
  1813. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  1814. tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
  1815. /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
  1816. outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
  1817. outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
  1818. /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
  1819. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  1820. addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  1821. tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
  1822. /* 7. Setup the remaining registers. */
  1823. if (priv->tlan_rev >= 0x30) {
  1824. data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
  1825. tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
  1826. }
  1827. tlan_phy_detect(dev);
  1828. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
  1829. if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
  1830. data |= TLAN_NET_CFG_BIT;
  1831. if (priv->aui == 1) {
  1832. tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
  1833. } else if (priv->duplex == TLAN_DUPLEX_FULL) {
  1834. tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
  1835. priv->tlan_full_duplex = true;
  1836. } else {
  1837. tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
  1838. }
  1839. }
  1840. /* don't power down internal PHY if we're going to use it */
  1841. if (priv->phy_num == 0 ||
  1842. (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))
  1843. data |= TLAN_NET_CFG_PHY_EN;
  1844. tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
  1845. if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
  1846. tlan_finish_reset(dev);
  1847. else
  1848. tlan_phy_power_down(dev);
  1849. }
  1850. static void
  1851. tlan_finish_reset(struct net_device *dev)
  1852. {
  1853. struct tlan_priv *priv = netdev_priv(dev);
  1854. u8 data;
  1855. u32 phy;
  1856. u8 sio;
  1857. u16 status;
  1858. u16 partner;
  1859. u16 tlphy_ctl;
  1860. u16 tlphy_par;
  1861. u16 tlphy_id1, tlphy_id2;
  1862. int i;
  1863. phy = priv->phy[priv->phy_num];
  1864. data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
  1865. if (priv->tlan_full_duplex)
  1866. data |= TLAN_NET_CMD_DUPLEX;
  1867. tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
  1868. data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
  1869. if (priv->phy_num == 0)
  1870. data |= TLAN_NET_MASK_MASK7;
  1871. tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
  1872. tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
  1873. tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
  1874. tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
  1875. if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
  1876. (priv->aui)) {
  1877. status = MII_GS_LINK;
  1878. netdev_info(dev, "Link forced\n");
  1879. } else {
  1880. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
  1881. udelay(1000);
  1882. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
  1883. if (status & MII_GS_LINK) {
  1884. /* We only support link info on Nat.Sem. PHY's */
  1885. if ((tlphy_id1 == NAT_SEM_ID1) &&
  1886. (tlphy_id2 == NAT_SEM_ID2)) {
  1887. tlan_mii_read_reg(dev, phy, MII_AN_LPA,
  1888. &partner);
  1889. tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR,
  1890. &tlphy_par);
  1891. netdev_info(dev,
  1892. "Link active, %s %uMbps %s-Duplex\n",
  1893. !(tlphy_par & TLAN_PHY_AN_EN_STAT)
  1894. ? "forced" : "Autonegotiation enabled,",
  1895. tlphy_par & TLAN_PHY_SPEED_100
  1896. ? 100 : 10,
  1897. tlphy_par & TLAN_PHY_DUPLEX_FULL
  1898. ? "Full" : "Half");
  1899. if (tlphy_par & TLAN_PHY_AN_EN_STAT) {
  1900. netdev_info(dev, "Partner capability:");
  1901. for (i = 5; i < 10; i++)
  1902. if (partner & (1 << i))
  1903. pr_cont(" %s",
  1904. media[i-5]);
  1905. pr_cont("\n");
  1906. }
  1907. } else
  1908. netdev_info(dev, "Link active\n");
  1909. /* Enabling link beat monitoring */
  1910. priv->media_timer.expires = jiffies + HZ;
  1911. add_timer(&priv->media_timer);
  1912. }
  1913. }
  1914. if (priv->phy_num == 0) {
  1915. tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
  1916. tlphy_ctl |= TLAN_TC_INTEN;
  1917. tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  1918. sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
  1919. sio |= TLAN_NET_SIO_MINTEN;
  1920. tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
  1921. }
  1922. if (status & MII_GS_LINK) {
  1923. tlan_set_mac(dev, 0, dev->dev_addr);
  1924. priv->phy_online = 1;
  1925. outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
  1926. if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
  1927. outb((TLAN_HC_REQ_INT >> 8),
  1928. dev->base_addr + TLAN_HOST_CMD + 1);
  1929. outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
  1930. outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
  1931. tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
  1932. netif_carrier_on(dev);
  1933. } else {
  1934. netdev_info(dev, "Link inactive, will retry in 10 secs...\n");
  1935. tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
  1936. return;
  1937. }
  1938. tlan_set_multicast_list(dev);
  1939. }
  1940. /***************************************************************
  1941. * tlan_set_mac
  1942. *
  1943. * Returns:
  1944. * Nothing
  1945. * Parms:
  1946. * dev Pointer to device structure of adapter
  1947. * on which to change the AREG.
  1948. * areg The AREG to set the address in (0 - 3).
  1949. * mac A pointer to an array of chars. Each
  1950. * element stores one byte of the address.
  1951. * IE, it isn't in ascii.
  1952. *
  1953. * This function transfers a MAC address to one of the
  1954. * TLAN AREGs (address registers). The TLAN chip locks
  1955. * the register on writing to offset 0 and unlocks the
  1956. * register after writing to offset 5. If NULL is passed
  1957. * in mac, then the AREG is filled with 0's.
  1958. *
  1959. **************************************************************/
  1960. static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
  1961. {
  1962. int i;
  1963. areg *= 6;
  1964. if (mac != NULL) {
  1965. for (i = 0; i < 6; i++)
  1966. tlan_dio_write8(dev->base_addr,
  1967. TLAN_AREG_0 + areg + i, mac[i]);
  1968. } else {
  1969. for (i = 0; i < 6; i++)
  1970. tlan_dio_write8(dev->base_addr,
  1971. TLAN_AREG_0 + areg + i, 0);
  1972. }
  1973. }
  1974. /*****************************************************************************
  1975. ******************************************************************************
  1976. ThunderLAN driver PHY layer routines
  1977. ******************************************************************************
  1978. *****************************************************************************/
  1979. /*********************************************************************
  1980. * tlan_phy_print
  1981. *
  1982. * Returns:
  1983. * Nothing
  1984. * Parms:
  1985. * dev A pointer to the device structure of the
  1986. * TLAN device having the PHYs to be detailed.
  1987. *
  1988. * This function prints the registers a PHY (aka transceiver).
  1989. *
  1990. ********************************************************************/
  1991. static void tlan_phy_print(struct net_device *dev)
  1992. {
  1993. struct tlan_priv *priv = netdev_priv(dev);
  1994. u16 i, data0, data1, data2, data3, phy;
  1995. phy = priv->phy[priv->phy_num];
  1996. if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
  1997. netdev_info(dev, "Unmanaged PHY\n");
  1998. } else if (phy <= TLAN_PHY_MAX_ADDR) {
  1999. netdev_info(dev, "PHY 0x%02x\n", phy);
  2000. pr_info(" Off. +0 +1 +2 +3\n");
  2001. for (i = 0; i < 0x20; i += 4) {
  2002. tlan_mii_read_reg(dev, phy, i, &data0);
  2003. tlan_mii_read_reg(dev, phy, i + 1, &data1);
  2004. tlan_mii_read_reg(dev, phy, i + 2, &data2);
  2005. tlan_mii_read_reg(dev, phy, i + 3, &data3);
  2006. pr_info(" 0x%02x 0x%04hx 0x%04hx 0x%04hx 0x%04hx\n",
  2007. i, data0, data1, data2, data3);
  2008. }
  2009. } else {
  2010. netdev_info(dev, "Invalid PHY\n");
  2011. }
  2012. }
  2013. /*********************************************************************
  2014. * tlan_phy_detect
  2015. *
  2016. * Returns:
  2017. * Nothing
  2018. * Parms:
  2019. * dev A pointer to the device structure of the adapter
  2020. * for which the PHY needs determined.
  2021. *
  2022. * So far I've found that adapters which have external PHYs
  2023. * may also use the internal PHY for part of the functionality.
  2024. * (eg, AUI/Thinnet). This function finds out if this TLAN
  2025. * chip has an internal PHY, and then finds the first external
  2026. * PHY (starting from address 0) if it exists).
  2027. *
  2028. ********************************************************************/
  2029. static void tlan_phy_detect(struct net_device *dev)
  2030. {
  2031. struct tlan_priv *priv = netdev_priv(dev);
  2032. u16 control;
  2033. u16 hi;
  2034. u16 lo;
  2035. u32 phy;
  2036. if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
  2037. priv->phy_num = 0xffff;
  2038. return;
  2039. }
  2040. tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
  2041. if (hi != 0xffff)
  2042. priv->phy[0] = TLAN_PHY_MAX_ADDR;
  2043. else
  2044. priv->phy[0] = TLAN_PHY_NONE;
  2045. priv->phy[1] = TLAN_PHY_NONE;
  2046. for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
  2047. tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
  2048. tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
  2049. tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
  2050. if ((control != 0xffff) ||
  2051. (hi != 0xffff) || (lo != 0xffff)) {
  2052. TLAN_DBG(TLAN_DEBUG_GNRL,
  2053. "PHY found at %02x %04x %04x %04x\n",
  2054. phy, control, hi, lo);
  2055. if ((priv->phy[1] == TLAN_PHY_NONE) &&
  2056. (phy != TLAN_PHY_MAX_ADDR)) {
  2057. priv->phy[1] = phy;
  2058. }
  2059. }
  2060. }
  2061. if (priv->phy[1] != TLAN_PHY_NONE)
  2062. priv->phy_num = 1;
  2063. else if (priv->phy[0] != TLAN_PHY_NONE)
  2064. priv->phy_num = 0;
  2065. else
  2066. netdev_info(dev, "Cannot initialize device, no PHY was found!\n");
  2067. }
  2068. static void tlan_phy_power_down(struct net_device *dev)
  2069. {
  2070. struct tlan_priv *priv = netdev_priv(dev);
  2071. u16 value;
  2072. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
  2073. value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
  2074. tlan_mii_sync(dev->base_addr);
  2075. tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
  2076. if ((priv->phy_num == 0) && (priv->phy[1] != TLAN_PHY_NONE)) {
  2077. /* if using internal PHY, the external PHY must be powered on */
  2078. if (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10)
  2079. value = MII_GC_ISOLATE; /* just isolate it from MII */
  2080. tlan_mii_sync(dev->base_addr);
  2081. tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
  2082. }
  2083. /* Wait for 50 ms and powerup
  2084. * This is abitrary. It is intended to make sure the
  2085. * transceiver settles.
  2086. */
  2087. tlan_set_timer(dev, msecs_to_jiffies(50), TLAN_TIMER_PHY_PUP);
  2088. }
  2089. static void tlan_phy_power_up(struct net_device *dev)
  2090. {
  2091. struct tlan_priv *priv = netdev_priv(dev);
  2092. u16 value;
  2093. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
  2094. tlan_mii_sync(dev->base_addr);
  2095. value = MII_GC_LOOPBK;
  2096. tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
  2097. tlan_mii_sync(dev->base_addr);
  2098. /* Wait for 500 ms and reset the
  2099. * transceiver. The TLAN docs say both 50 ms and
  2100. * 500 ms, so do the longer, just in case.
  2101. */
  2102. tlan_set_timer(dev, msecs_to_jiffies(500), TLAN_TIMER_PHY_RESET);
  2103. }
  2104. static void tlan_phy_reset(struct net_device *dev)
  2105. {
  2106. struct tlan_priv *priv = netdev_priv(dev);
  2107. u16 phy;
  2108. u16 value;
  2109. unsigned long timeout = jiffies + HZ;
  2110. phy = priv->phy[priv->phy_num];
  2111. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Resetting PHY.\n", dev->name);
  2112. tlan_mii_sync(dev->base_addr);
  2113. value = MII_GC_LOOPBK | MII_GC_RESET;
  2114. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
  2115. do {
  2116. tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
  2117. if (time_after(jiffies, timeout)) {
  2118. netdev_err(dev, "PHY reset timeout\n");
  2119. return;
  2120. }
  2121. } while (value & MII_GC_RESET);
  2122. /* Wait for 500 ms and initialize.
  2123. * I don't remember why I wait this long.
  2124. * I've changed this to 50ms, as it seems long enough.
  2125. */
  2126. tlan_set_timer(dev, msecs_to_jiffies(50), TLAN_TIMER_PHY_START_LINK);
  2127. }
  2128. static void tlan_phy_start_link(struct net_device *dev)
  2129. {
  2130. struct tlan_priv *priv = netdev_priv(dev);
  2131. u16 ability;
  2132. u16 control;
  2133. u16 data;
  2134. u16 phy;
  2135. u16 status;
  2136. u16 tctl;
  2137. phy = priv->phy[priv->phy_num];
  2138. TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
  2139. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
  2140. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
  2141. if ((status & MII_GS_AUTONEG) &&
  2142. (!priv->aui)) {
  2143. ability = status >> 11;
  2144. if (priv->speed == TLAN_SPEED_10 &&
  2145. priv->duplex == TLAN_DUPLEX_HALF) {
  2146. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
  2147. } else if (priv->speed == TLAN_SPEED_10 &&
  2148. priv->duplex == TLAN_DUPLEX_FULL) {
  2149. priv->tlan_full_duplex = true;
  2150. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
  2151. } else if (priv->speed == TLAN_SPEED_100 &&
  2152. priv->duplex == TLAN_DUPLEX_HALF) {
  2153. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
  2154. } else if (priv->speed == TLAN_SPEED_100 &&
  2155. priv->duplex == TLAN_DUPLEX_FULL) {
  2156. priv->tlan_full_duplex = true;
  2157. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
  2158. } else {
  2159. /* Set Auto-Neg advertisement */
  2160. tlan_mii_write_reg(dev, phy, MII_AN_ADV,
  2161. (ability << 5) | 1);
  2162. /* Enablee Auto-Neg */
  2163. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
  2164. /* Restart Auto-Neg */
  2165. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
  2166. /* Wait for 4 sec for autonegotiation
  2167. * to complete. The max spec time is less than this
  2168. * but the card need additional time to start AN.
  2169. * .5 sec should be plenty extra.
  2170. */
  2171. netdev_info(dev, "Starting autonegotiation\n");
  2172. tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
  2173. return;
  2174. }
  2175. }
  2176. if ((priv->aui) && (priv->phy_num != 0)) {
  2177. priv->phy_num = 0;
  2178. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
  2179. | TLAN_NET_CFG_PHY_EN;
  2180. tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
  2181. tlan_set_timer(dev, msecs_to_jiffies(40), TLAN_TIMER_PHY_PDOWN);
  2182. return;
  2183. } else if (priv->phy_num == 0) {
  2184. control = 0;
  2185. tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
  2186. if (priv->aui) {
  2187. tctl |= TLAN_TC_AUISEL;
  2188. } else {
  2189. tctl &= ~TLAN_TC_AUISEL;
  2190. if (priv->duplex == TLAN_DUPLEX_FULL) {
  2191. control |= MII_GC_DUPLEX;
  2192. priv->tlan_full_duplex = true;
  2193. }
  2194. if (priv->speed == TLAN_SPEED_100)
  2195. control |= MII_GC_SPEEDSEL;
  2196. }
  2197. tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
  2198. tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
  2199. }
  2200. /* Wait for 2 sec to give the transceiver time
  2201. * to establish link.
  2202. */
  2203. tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
  2204. }
  2205. static void tlan_phy_finish_auto_neg(struct net_device *dev)
  2206. {
  2207. struct tlan_priv *priv = netdev_priv(dev);
  2208. u16 an_adv;
  2209. u16 an_lpa;
  2210. u16 mode;
  2211. u16 phy;
  2212. u16 status;
  2213. phy = priv->phy[priv->phy_num];
  2214. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
  2215. udelay(1000);
  2216. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
  2217. if (!(status & MII_GS_AUTOCMPLT)) {
  2218. /* Wait for 8 sec to give the process
  2219. * more time. Perhaps we should fail after a while.
  2220. */
  2221. tlan_set_timer(dev, 2 * HZ, TLAN_TIMER_PHY_FINISH_AN);
  2222. return;
  2223. }
  2224. netdev_info(dev, "Autonegotiation complete\n");
  2225. tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
  2226. tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
  2227. mode = an_adv & an_lpa & 0x03E0;
  2228. if (mode & 0x0100)
  2229. priv->tlan_full_duplex = true;
  2230. else if (!(mode & 0x0080) && (mode & 0x0040))
  2231. priv->tlan_full_duplex = true;
  2232. /* switch to internal PHY for 10 Mbps */
  2233. if ((!(mode & 0x0180)) &&
  2234. (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
  2235. (priv->phy_num != 0)) {
  2236. priv->phy_num = 0;
  2237. tlan_set_timer(dev, msecs_to_jiffies(400), TLAN_TIMER_PHY_PDOWN);
  2238. return;
  2239. }
  2240. if (priv->phy_num == 0) {
  2241. if ((priv->duplex == TLAN_DUPLEX_FULL) ||
  2242. (an_adv & an_lpa & 0x0040)) {
  2243. tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
  2244. MII_GC_AUTOENB | MII_GC_DUPLEX);
  2245. netdev_info(dev, "Starting internal PHY with FULL-DUPLEX\n");
  2246. } else {
  2247. tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
  2248. MII_GC_AUTOENB);
  2249. netdev_info(dev, "Starting internal PHY with HALF-DUPLEX\n");
  2250. }
  2251. }
  2252. /* Wait for 100 ms. No reason in partiticular.
  2253. */
  2254. tlan_set_timer(dev, msecs_to_jiffies(100), TLAN_TIMER_FINISH_RESET);
  2255. }
  2256. /*********************************************************************
  2257. *
  2258. * tlan_phy_monitor
  2259. *
  2260. * Returns:
  2261. * None
  2262. *
  2263. * Params:
  2264. * data The device structure of this device.
  2265. *
  2266. *
  2267. * This function monitors PHY condition by reading the status
  2268. * register via the MII bus, controls LINK LED and notifies the
  2269. * kernel about link state.
  2270. *
  2271. *******************************************************************/
  2272. static void tlan_phy_monitor(struct timer_list *t)
  2273. {
  2274. struct tlan_priv *priv = from_timer(priv, t, media_timer);
  2275. struct net_device *dev = priv->dev;
  2276. u16 phy;
  2277. u16 phy_status;
  2278. phy = priv->phy[priv->phy_num];
  2279. /* Get PHY status register */
  2280. tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
  2281. /* Check if link has been lost */
  2282. if (!(phy_status & MII_GS_LINK)) {
  2283. if (netif_carrier_ok(dev)) {
  2284. printk(KERN_DEBUG "TLAN: %s has lost link\n",
  2285. dev->name);
  2286. tlan_dio_write8(dev->base_addr, TLAN_LED_REG, 0);
  2287. netif_carrier_off(dev);
  2288. if (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) {
  2289. /* power down internal PHY */
  2290. u16 data = MII_GC_PDOWN | MII_GC_LOOPBK |
  2291. MII_GC_ISOLATE;
  2292. tlan_mii_sync(dev->base_addr);
  2293. tlan_mii_write_reg(dev, priv->phy[0],
  2294. MII_GEN_CTL, data);
  2295. /* set to external PHY */
  2296. priv->phy_num = 1;
  2297. /* restart autonegotiation */
  2298. tlan_set_timer(dev, msecs_to_jiffies(400),
  2299. TLAN_TIMER_PHY_PDOWN);
  2300. return;
  2301. }
  2302. }
  2303. }
  2304. /* Link restablished? */
  2305. if ((phy_status & MII_GS_LINK) && !netif_carrier_ok(dev)) {
  2306. tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
  2307. printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
  2308. dev->name);
  2309. netif_carrier_on(dev);
  2310. }
  2311. priv->media_timer.expires = jiffies + HZ;
  2312. add_timer(&priv->media_timer);
  2313. }
  2314. /*****************************************************************************
  2315. ******************************************************************************
  2316. ThunderLAN driver MII routines
  2317. these routines are based on the information in chap. 2 of the
  2318. "ThunderLAN Programmer's Guide", pp. 15-24.
  2319. ******************************************************************************
  2320. *****************************************************************************/
  2321. /***************************************************************
  2322. * tlan_mii_read_reg
  2323. *
  2324. * Returns:
  2325. * false if ack received ok
  2326. * true if no ack received or other error
  2327. *
  2328. * Parms:
  2329. * dev The device structure containing
  2330. * The io address and interrupt count
  2331. * for this device.
  2332. * phy The address of the PHY to be queried.
  2333. * reg The register whose contents are to be
  2334. * retrieved.
  2335. * val A pointer to a variable to store the
  2336. * retrieved value.
  2337. *
  2338. * This function uses the TLAN's MII bus to retrieve the contents
  2339. * of a given register on a PHY. It sends the appropriate info
  2340. * and then reads the 16-bit register value from the MII bus via
  2341. * the TLAN SIO register.
  2342. *
  2343. **************************************************************/
  2344. static bool
  2345. tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
  2346. {
  2347. u8 nack;
  2348. u16 sio, tmp;
  2349. u32 i;
  2350. bool err;
  2351. int minten;
  2352. struct tlan_priv *priv = netdev_priv(dev);
  2353. unsigned long flags = 0;
  2354. err = false;
  2355. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2356. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2357. if (!in_irq())
  2358. spin_lock_irqsave(&priv->lock, flags);
  2359. tlan_mii_sync(dev->base_addr);
  2360. minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
  2361. if (minten)
  2362. tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
  2363. tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
  2364. tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
  2365. tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
  2366. tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
  2367. tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
  2368. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
  2369. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2370. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
  2371. nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
  2372. tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
  2373. if (nack) { /* no ACK, so fake it */
  2374. for (i = 0; i < 16; i++) {
  2375. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
  2376. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2377. }
  2378. tmp = 0xffff;
  2379. err = true;
  2380. } else { /* ACK, so read data */
  2381. for (tmp = 0, i = 0x8000; i; i >>= 1) {
  2382. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
  2383. if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
  2384. tmp |= i;
  2385. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2386. }
  2387. }
  2388. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
  2389. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2390. if (minten)
  2391. tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
  2392. *val = tmp;
  2393. if (!in_irq())
  2394. spin_unlock_irqrestore(&priv->lock, flags);
  2395. return err;
  2396. }
  2397. /***************************************************************
  2398. * tlan_mii_send_data
  2399. *
  2400. * Returns:
  2401. * Nothing
  2402. * Parms:
  2403. * base_port The base IO port of the adapter in
  2404. * question.
  2405. * dev The address of the PHY to be queried.
  2406. * data The value to be placed on the MII bus.
  2407. * num_bits The number of bits in data that are to
  2408. * be placed on the MII bus.
  2409. *
  2410. * This function sends on sequence of bits on the MII
  2411. * configuration bus.
  2412. *
  2413. **************************************************************/
  2414. static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
  2415. {
  2416. u16 sio;
  2417. u32 i;
  2418. if (num_bits == 0)
  2419. return;
  2420. outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
  2421. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2422. tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
  2423. for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
  2424. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
  2425. (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
  2426. if (data & i)
  2427. tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
  2428. else
  2429. tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
  2430. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2431. (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
  2432. }
  2433. }
  2434. /***************************************************************
  2435. * TLan_MiiSync
  2436. *
  2437. * Returns:
  2438. * Nothing
  2439. * Parms:
  2440. * base_port The base IO port of the adapter in
  2441. * question.
  2442. *
  2443. * This functions syncs all PHYs in terms of the MII configuration
  2444. * bus.
  2445. *
  2446. **************************************************************/
  2447. static void tlan_mii_sync(u16 base_port)
  2448. {
  2449. int i;
  2450. u16 sio;
  2451. outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
  2452. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2453. tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
  2454. for (i = 0; i < 32; i++) {
  2455. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
  2456. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2457. }
  2458. }
  2459. /***************************************************************
  2460. * tlan_mii_write_reg
  2461. *
  2462. * Returns:
  2463. * Nothing
  2464. * Parms:
  2465. * dev The device structure for the device
  2466. * to write to.
  2467. * phy The address of the PHY to be written to.
  2468. * reg The register whose contents are to be
  2469. * written.
  2470. * val The value to be written to the register.
  2471. *
  2472. * This function uses the TLAN's MII bus to write the contents of a
  2473. * given register on a PHY. It sends the appropriate info and then
  2474. * writes the 16-bit register value from the MII configuration bus
  2475. * via the TLAN SIO register.
  2476. *
  2477. **************************************************************/
  2478. static void
  2479. tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
  2480. {
  2481. u16 sio;
  2482. int minten;
  2483. unsigned long flags = 0;
  2484. struct tlan_priv *priv = netdev_priv(dev);
  2485. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2486. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2487. if (!in_irq())
  2488. spin_lock_irqsave(&priv->lock, flags);
  2489. tlan_mii_sync(dev->base_addr);
  2490. minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
  2491. if (minten)
  2492. tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
  2493. tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
  2494. tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
  2495. tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
  2496. tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
  2497. tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
  2498. tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
  2499. tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
  2500. tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
  2501. if (minten)
  2502. tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
  2503. if (!in_irq())
  2504. spin_unlock_irqrestore(&priv->lock, flags);
  2505. }
  2506. /*****************************************************************************
  2507. ******************************************************************************
  2508. ThunderLAN driver eeprom routines
  2509. the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
  2510. EEPROM. these functions are based on information in microchip's
  2511. data sheet. I don't know how well this functions will work with
  2512. other Eeproms.
  2513. ******************************************************************************
  2514. *****************************************************************************/
  2515. /***************************************************************
  2516. * tlan_ee_send_start
  2517. *
  2518. * Returns:
  2519. * Nothing
  2520. * Parms:
  2521. * io_base The IO port base address for the
  2522. * TLAN device with the EEPROM to
  2523. * use.
  2524. *
  2525. * This function sends a start cycle to an EEPROM attached
  2526. * to a TLAN chip.
  2527. *
  2528. **************************************************************/
  2529. static void tlan_ee_send_start(u16 io_base)
  2530. {
  2531. u16 sio;
  2532. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  2533. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2534. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2535. tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
  2536. tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
  2537. tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
  2538. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2539. }
  2540. /***************************************************************
  2541. * tlan_ee_send_byte
  2542. *
  2543. * Returns:
  2544. * If the correct ack was received, 0, otherwise 1
  2545. * Parms: io_base The IO port base address for the
  2546. * TLAN device with the EEPROM to
  2547. * use.
  2548. * data The 8 bits of information to
  2549. * send to the EEPROM.
  2550. * stop If TLAN_EEPROM_STOP is passed, a
  2551. * stop cycle is sent after the
  2552. * byte is sent after the ack is
  2553. * read.
  2554. *
  2555. * This function sends a byte on the serial EEPROM line,
  2556. * driving the clock to send each bit. The function then
  2557. * reverses transmission direction and reads an acknowledge
  2558. * bit.
  2559. *
  2560. **************************************************************/
  2561. static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
  2562. {
  2563. int err;
  2564. u8 place;
  2565. u16 sio;
  2566. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  2567. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2568. /* Assume clock is low, tx is enabled; */
  2569. for (place = 0x80; place != 0; place >>= 1) {
  2570. if (place & data)
  2571. tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
  2572. else
  2573. tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
  2574. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2575. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2576. }
  2577. tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
  2578. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2579. err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
  2580. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2581. tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
  2582. if ((!err) && stop) {
  2583. /* STOP, raise data while clock is high */
  2584. tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
  2585. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2586. tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
  2587. }
  2588. return err;
  2589. }
  2590. /***************************************************************
  2591. * tlan_ee_receive_byte
  2592. *
  2593. * Returns:
  2594. * Nothing
  2595. * Parms:
  2596. * io_base The IO port base address for the
  2597. * TLAN device with the EEPROM to
  2598. * use.
  2599. * data An address to a char to hold the
  2600. * data sent from the EEPROM.
  2601. * stop If TLAN_EEPROM_STOP is passed, a
  2602. * stop cycle is sent after the
  2603. * byte is received, and no ack is
  2604. * sent.
  2605. *
  2606. * This function receives 8 bits of data from the EEPROM
  2607. * over the serial link. It then sends and ack bit, or no
  2608. * ack and a stop bit. This function is used to retrieve
  2609. * data after the address of a byte in the EEPROM has been
  2610. * sent.
  2611. *
  2612. **************************************************************/
  2613. static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
  2614. {
  2615. u8 place;
  2616. u16 sio;
  2617. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  2618. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2619. *data = 0;
  2620. /* Assume clock is low, tx is enabled; */
  2621. tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
  2622. for (place = 0x80; place; place >>= 1) {
  2623. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2624. if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
  2625. *data |= place;
  2626. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2627. }
  2628. tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
  2629. if (!stop) {
  2630. tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
  2631. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2632. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2633. } else {
  2634. tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
  2635. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2636. tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
  2637. /* STOP, raise data while clock is high */
  2638. tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
  2639. tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
  2640. tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
  2641. }
  2642. }
  2643. /***************************************************************
  2644. * tlan_ee_read_byte
  2645. *
  2646. * Returns:
  2647. * No error = 0, else, the stage at which the error
  2648. * occurred.
  2649. * Parms:
  2650. * io_base The IO port base address for the
  2651. * TLAN device with the EEPROM to
  2652. * use.
  2653. * ee_addr The address of the byte in the
  2654. * EEPROM whose contents are to be
  2655. * retrieved.
  2656. * data An address to a char to hold the
  2657. * data obtained from the EEPROM.
  2658. *
  2659. * This function reads a byte of information from an byte
  2660. * cell in the EEPROM.
  2661. *
  2662. **************************************************************/
  2663. static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
  2664. {
  2665. int err;
  2666. struct tlan_priv *priv = netdev_priv(dev);
  2667. unsigned long flags = 0;
  2668. int ret = 0;
  2669. spin_lock_irqsave(&priv->lock, flags);
  2670. tlan_ee_send_start(dev->base_addr);
  2671. err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
  2672. if (err) {
  2673. ret = 1;
  2674. goto fail;
  2675. }
  2676. err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
  2677. if (err) {
  2678. ret = 2;
  2679. goto fail;
  2680. }
  2681. tlan_ee_send_start(dev->base_addr);
  2682. err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
  2683. if (err) {
  2684. ret = 3;
  2685. goto fail;
  2686. }
  2687. tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
  2688. fail:
  2689. spin_unlock_irqrestore(&priv->lock, flags);
  2690. return ret;
  2691. }