tlan.c 86 KB

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