tlan.c 86 KB

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