tlan.c 85 KB

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