tlan.c 85 KB

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