You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tlan.c 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /**************************************************************************
  2. *
  3. * tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
  4. * Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * Portions of this code based on:
  21. * lan.c: Linux ThunderLan Driver:
  22. *
  23. * by James Banks
  24. *
  25. * (C) 1997-1998 Caldera, Inc.
  26. * (C) 1998 James Banks
  27. * (C) 1999-2001 Torben Mathiasen
  28. * (C) 2002 Samuel Chessman
  29. *
  30. * REVISION HISTORY:
  31. * ================
  32. * v1.0 07-08-2003 timlegge Initial not quite working version
  33. * v1.1 07-27-2003 timlegge Sync 5.0 and 5.1 versions
  34. * v1.2 08-19-2003 timlegge Implement Multicast Support
  35. * v1.3 08-23-2003 timlegge Fix the transmit Function
  36. * v1.4 01-17-2004 timlegge Initial driver output cleanup
  37. *
  38. * Indent Options: indent -kr -i8
  39. ***************************************************************************/
  40. /* to get some global routines like printf */
  41. #include "etherboot.h"
  42. /* to get the interface to the body of the program */
  43. #include "nic.h"
  44. /* to get the PCI support functions, if this is a PCI NIC */
  45. #include "pci.h"
  46. #include "timer.h"
  47. #include "tlan.h"
  48. #define drv_version "v1.4"
  49. #define drv_date "01-17-2004"
  50. /* NIC specific static variables go here */
  51. #define HZ 100
  52. #define TX_TIME_OUT (6*HZ)
  53. /* Condensed operations for readability. */
  54. #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
  55. #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
  56. //#define EDEBUG
  57. #ifdef EDEBUG
  58. #define dprintf(x) printf x
  59. #else
  60. #define dprintf(x)
  61. #endif
  62. static void TLan_ResetLists(struct nic *nic __unused);
  63. static void TLan_ResetAdapter(struct nic *nic __unused);
  64. static void TLan_FinishReset(struct nic *nic __unused);
  65. static void TLan_EeSendStart(u16);
  66. static int TLan_EeSendByte(u16, u8, int);
  67. static void TLan_EeReceiveByte(u16, u8 *, int);
  68. static int TLan_EeReadByte(u16 io_base, u8, u8 *);
  69. static void TLan_PhyDetect(struct nic *nic);
  70. static void TLan_PhyPowerDown(struct nic *nic);
  71. static void TLan_PhyPowerUp(struct nic *nic);
  72. static void TLan_SetMac(struct nic *nic __unused, int areg, char *mac);
  73. static void TLan_PhyReset(struct nic *nic);
  74. static void TLan_PhyStartLink(struct nic *nic);
  75. static void TLan_PhyFinishAutoNeg(struct nic *nic);
  76. #ifdef MONITOR
  77. static void TLan_PhyMonitor(struct nic *nic);
  78. #endif
  79. static void refill_rx(struct nic *nic __unused);
  80. static int TLan_MiiReadReg(struct nic *nic __unused, u16, u16, u16 *);
  81. static void TLan_MiiSendData(u16, u32, unsigned);
  82. static void TLan_MiiSync(u16);
  83. static void TLan_MiiWriteReg(struct nic *nic __unused, u16, u16, u16);
  84. const char *media[] = {
  85. "10BaseT-HD ", "10BaseT-FD ", "100baseTx-HD ",
  86. "100baseTx-FD", "100baseT4", 0
  87. };
  88. /* This much match tlan_pci_tbl[]! */
  89. enum tlan_nics {
  90. NETEL10 = 0, NETEL100 = 1, NETFLEX3I = 2, THUNDER = 3, NETFLEX3B =
  91. 4, NETEL100PI = 5,
  92. NETEL100D = 6, NETEL100I = 7, OC2183 = 8, OC2325 = 9, OC2326 =
  93. 10, NETELLIGENT_10_100_WS_5100 = 11,
  94. NETELLIGENT_10_T2 = 12
  95. };
  96. struct pci_id_info {
  97. const char *name;
  98. int nic_id;
  99. struct match_info {
  100. u32 pci, pci_mask, subsystem, subsystem_mask;
  101. u32 revision, revision_mask; /* Only 8 bits. */
  102. } id;
  103. u32 flags;
  104. u16 addrOfs; /* Address Offset */
  105. };
  106. static struct pci_id_info tlan_pci_tbl[] = {
  107. {"Compaq Netelligent 10 T PCI UTP", NETEL10,
  108. {0xae340e11, 0xffffffff, 0, 0, 0, 0},
  109. TLAN_ADAPTER_ACTIVITY_LED, 0x83},
  110. {"Compaq Netelligent 10/100 TX PCI UTP", NETEL100,
  111. {0xae320e11, 0xffffffff, 0, 0, 0, 0},
  112. TLAN_ADAPTER_ACTIVITY_LED, 0x83},
  113. {"Compaq Integrated NetFlex-3/P", NETFLEX3I,
  114. {0xae350e11, 0xffffffff, 0, 0, 0, 0},
  115. TLAN_ADAPTER_NONE, 0x83},
  116. {"Compaq NetFlex-3/P", THUNDER,
  117. {0xf1300e11, 0xffffffff, 0, 0, 0, 0},
  118. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83},
  119. {"Compaq NetFlex-3/P", NETFLEX3B,
  120. {0xf1500e11, 0xffffffff, 0, 0, 0, 0},
  121. TLAN_ADAPTER_NONE, 0x83},
  122. {"Compaq Netelligent Integrated 10/100 TX UTP", NETEL100PI,
  123. {0xae430e11, 0xffffffff, 0, 0, 0, 0},
  124. TLAN_ADAPTER_ACTIVITY_LED, 0x83},
  125. {"Compaq Netelligent Dual 10/100 TX PCI UTP", NETEL100D,
  126. {0xae400e11, 0xffffffff, 0, 0, 0, 0},
  127. TLAN_ADAPTER_NONE, 0x83},
  128. {"Compaq Netelligent 10/100 TX Embedded UTP", NETEL100I,
  129. {0xb0110e11, 0xffffffff, 0, 0, 0, 0},
  130. TLAN_ADAPTER_NONE, 0x83},
  131. {"Olicom OC-2183/2185", OC2183,
  132. {0x0013108d, 0xffffffff, 0, 0, 0, 0},
  133. TLAN_ADAPTER_USE_INTERN_10, 0x83},
  134. {"Olicom OC-2325", OC2325,
  135. {0x0012108d, 0xffffffff, 0, 0, 0, 0},
  136. TLAN_ADAPTER_UNMANAGED_PHY, 0xF8},
  137. {"Olicom OC-2326", OC2326,
  138. {0x0014108d, 0xffffffff, 0, 0, 0, 0},
  139. TLAN_ADAPTER_USE_INTERN_10, 0xF8},
  140. {"Compaq Netelligent 10/100 TX UTP", NETELLIGENT_10_100_WS_5100,
  141. {0xb0300e11, 0xffffffff, 0, 0, 0, 0},
  142. TLAN_ADAPTER_ACTIVITY_LED, 0x83},
  143. {"Compaq Netelligent 10 T/2 PCI UTP/Coax", NETELLIGENT_10_T2,
  144. {0xb0120e11, 0xffffffff, 0, 0, 0, 0},
  145. TLAN_ADAPTER_NONE, 0x83},
  146. {"Compaq NetFlex-3/E", 0, /* EISA card */
  147. {0, 0, 0, 0, 0, 0},
  148. TLAN_ADAPTER_ACTIVITY_LED | TLAN_ADAPTER_UNMANAGED_PHY |
  149. TLAN_ADAPTER_BIT_RATE_PHY, 0x83},
  150. {"Compaq NetFlex-3/E", 0, /* EISA card */
  151. {0, 0, 0, 0, 0, 0},
  152. TLAN_ADAPTER_ACTIVITY_LED, 0x83},
  153. {0, 0,
  154. {0, 0, 0, 0, 0, 0},
  155. 0, 0},
  156. };
  157. struct TLanList {
  158. u32 forward;
  159. u16 cStat;
  160. u16 frameSize;
  161. struct {
  162. u32 count;
  163. u32 address;
  164. } buffer[TLAN_BUFFERS_PER_LIST];
  165. };
  166. struct TLanList tx_ring[TLAN_NUM_TX_LISTS];
  167. static unsigned char txb[TLAN_MAX_FRAME_SIZE * TLAN_NUM_TX_LISTS];
  168. struct TLanList rx_ring[TLAN_NUM_RX_LISTS];
  169. static unsigned char rxb[TLAN_MAX_FRAME_SIZE * TLAN_NUM_RX_LISTS];
  170. typedef u8 TLanBuffer[TLAN_MAX_FRAME_SIZE];
  171. int chip_idx;
  172. /*****************************************************************
  173. * TLAN Private Information Structure
  174. *
  175. ****************************************************************/
  176. struct tlan_private {
  177. unsigned short vendor_id; /* PCI Vendor code */
  178. unsigned short dev_id; /* PCI Device code */
  179. const char *nic_name;
  180. unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indicies */
  181. unsigned rx_buf_sz; /* Based on mtu + Slack */
  182. struct TLanList *txList;
  183. u32 txHead;
  184. u32 txInProgress;
  185. u32 txTail;
  186. int eoc;
  187. u32 phyOnline;
  188. u32 aui;
  189. u32 duplex;
  190. u32 phy[2];
  191. u32 phyNum;
  192. u32 speed;
  193. u8 tlanRev;
  194. u8 tlanFullDuplex;
  195. u8 link;
  196. u8 neg_be_verbose;
  197. } TLanPrivateInfo;
  198. static struct tlan_private *priv;
  199. u32 BASE;
  200. /***************************************************************
  201. * TLan_ResetLists
  202. *
  203. * Returns:
  204. * Nothing
  205. * Parms:
  206. * dev The device structure with the list
  207. * stuctures to be reset.
  208. *
  209. * This routine sets the variables associated with managing
  210. * the TLAN lists to their initial values.
  211. *
  212. **************************************************************/
  213. void TLan_ResetLists(struct nic *nic __unused)
  214. {
  215. int i;
  216. struct TLanList *list;
  217. priv->txHead = 0;
  218. priv->txTail = 0;
  219. for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
  220. list = &tx_ring[i];
  221. list->cStat = TLAN_CSTAT_UNUSED;
  222. list->buffer[0].address = virt_to_bus(txb +
  223. (i * TLAN_MAX_FRAME_SIZE));
  224. list->buffer[2].count = 0;
  225. list->buffer[2].address = 0;
  226. list->buffer[9].address = 0;
  227. }
  228. priv->cur_rx = 0;
  229. priv->rx_buf_sz = (TLAN_MAX_FRAME_SIZE);
  230. // priv->rx_head_desc = &rx_ring[0];
  231. /* Initialize all the Rx descriptors */
  232. for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
  233. rx_ring[i].forward = virt_to_le32desc(&rx_ring[i + 1]);
  234. rx_ring[i].cStat = TLAN_CSTAT_READY;
  235. rx_ring[i].frameSize = TLAN_MAX_FRAME_SIZE;
  236. rx_ring[i].buffer[0].count =
  237. TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
  238. rx_ring[i].buffer[0].address =
  239. virt_to_le32desc(&rxb[i * TLAN_MAX_FRAME_SIZE]);
  240. rx_ring[i].buffer[1].count = 0;
  241. rx_ring[i].buffer[1].address = 0;
  242. }
  243. /* Mark the last entry as wrapping the ring */
  244. rx_ring[i - 1].forward = virt_to_le32desc(&rx_ring[0]);
  245. priv->dirty_rx = (unsigned int) (i - TLAN_NUM_RX_LISTS);
  246. } /* TLan_ResetLists */
  247. /***************************************************************
  248. * TLan_Reset
  249. *
  250. * Returns:
  251. * 0
  252. * Parms:
  253. * dev Pointer to device structure of adapter
  254. * to be reset.
  255. *
  256. * This function resets the adapter and it's physical
  257. * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
  258. * Programmer's Guide" for details. The routine tries to
  259. * implement what is detailed there, though adjustments
  260. * have been made.
  261. *
  262. **************************************************************/
  263. void TLan_ResetAdapter(struct nic *nic __unused)
  264. {
  265. int i;
  266. u32 addr;
  267. u32 data;
  268. u8 data8;
  269. priv->tlanFullDuplex = FALSE;
  270. priv->phyOnline = 0;
  271. /* 1. Assert reset bit. */
  272. data = inl(BASE + TLAN_HOST_CMD);
  273. data |= TLAN_HC_AD_RST;
  274. outl(data, BASE + TLAN_HOST_CMD);
  275. udelay(1000);
  276. /* 2. Turn off interrupts. ( Probably isn't necessary ) */
  277. data = inl(BASE + TLAN_HOST_CMD);
  278. data |= TLAN_HC_INT_OFF;
  279. outl(data, BASE + TLAN_HOST_CMD);
  280. /* 3. Clear AREGs and HASHs. */
  281. for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4) {
  282. TLan_DioWrite32(BASE, (u16) i, 0);
  283. }
  284. /* 4. Setup NetConfig register. */
  285. data =
  286. TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  287. TLan_DioWrite16(BASE, TLAN_NET_CONFIG, (u16) data);
  288. /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
  289. outl(TLAN_HC_LD_TMR | 0x3f, BASE + TLAN_HOST_CMD);
  290. outl(TLAN_HC_LD_THR | 0x0, BASE + TLAN_HOST_CMD);
  291. /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
  292. outw(TLAN_NET_SIO, BASE + TLAN_DIO_ADR);
  293. addr = BASE + TLAN_DIO_DATA + TLAN_NET_SIO;
  294. TLan_SetBit(TLAN_NET_SIO_NMRST, addr);
  295. /* 7. Setup the remaining registers. */
  296. if (priv->tlanRev >= 0x30) {
  297. data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
  298. TLan_DioWrite8(BASE, TLAN_INT_DIS, data8);
  299. }
  300. TLan_PhyDetect(nic);
  301. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
  302. if (tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_BIT_RATE_PHY) {
  303. data |= TLAN_NET_CFG_BIT;
  304. if (priv->aui == 1) {
  305. TLan_DioWrite8(BASE, TLAN_ACOMMIT, 0x0a);
  306. } else if (priv->duplex == TLAN_DUPLEX_FULL) {
  307. TLan_DioWrite8(BASE, TLAN_ACOMMIT, 0x00);
  308. priv->tlanFullDuplex = TRUE;
  309. } else {
  310. TLan_DioWrite8(BASE, TLAN_ACOMMIT, 0x08);
  311. }
  312. }
  313. if (priv->phyNum == 0) {
  314. data |= TLAN_NET_CFG_PHY_EN;
  315. }
  316. TLan_DioWrite16(BASE, TLAN_NET_CONFIG, (u16) data);
  317. if (tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_UNMANAGED_PHY) {
  318. TLan_FinishReset(nic);
  319. } else {
  320. TLan_PhyPowerDown(nic);
  321. }
  322. } /* TLan_ResetAdapter */
  323. void TLan_FinishReset(struct nic *nic)
  324. {
  325. u8 data;
  326. u32 phy;
  327. u8 sio;
  328. u16 status;
  329. u16 partner;
  330. u16 tlphy_ctl;
  331. u16 tlphy_par;
  332. u16 tlphy_id1, tlphy_id2;
  333. int i;
  334. phy = priv->phy[priv->phyNum];
  335. data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
  336. if (priv->tlanFullDuplex) {
  337. data |= TLAN_NET_CMD_DUPLEX;
  338. }
  339. TLan_DioWrite8(BASE, TLAN_NET_CMD, data);
  340. data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
  341. if (priv->phyNum == 0) {
  342. data |= TLAN_NET_MASK_MASK7;
  343. }
  344. TLan_DioWrite8(BASE, TLAN_NET_MASK, data);
  345. TLan_DioWrite16(BASE, TLAN_MAX_RX, ((1536) + 7) & ~7);
  346. TLan_MiiReadReg(nic, phy, MII_GEN_ID_HI, &tlphy_id1);
  347. TLan_MiiReadReg(nic, phy, MII_GEN_ID_LO, &tlphy_id2);
  348. if ((tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_UNMANAGED_PHY)
  349. || (priv->aui)) {
  350. status = MII_GS_LINK;
  351. dprintf(("TLAN: %s: Link forced.\n", priv->nic_name));
  352. } else {
  353. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
  354. udelay(1000);
  355. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
  356. if ((status & MII_GS_LINK) && /* We only support link info on Nat.Sem. PHY's */
  357. (tlphy_id1 == NAT_SEM_ID1)
  358. && (tlphy_id2 == NAT_SEM_ID2)) {
  359. TLan_MiiReadReg(nic, phy, MII_AN_LPA, &partner);
  360. TLan_MiiReadReg(nic, phy, TLAN_TLPHY_PAR,
  361. &tlphy_par);
  362. dprintf(("TLAN: %s: Link active with ",
  363. priv->nic_name));
  364. if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
  365. dprintf(("forced 10%sMbps %s-Duplex\n",
  366. tlphy_par & TLAN_PHY_SPEED_100 ? ""
  367. : "0",
  368. tlphy_par & TLAN_PHY_DUPLEX_FULL ?
  369. "Full" : "Half"));
  370. } else {
  371. dprintf
  372. (("AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
  373. tlphy_par & TLAN_PHY_SPEED_100 ? "" :
  374. "0",
  375. tlphy_par & TLAN_PHY_DUPLEX_FULL ?
  376. "Full" : "Half"));
  377. dprintf(("TLAN: Partner capability: "));
  378. for (i = 5; i <= 10; i++)
  379. if (partner & (1 << i))
  380. dprintf(("%s", media[i - 5]));
  381. dprintf(("\n"));
  382. }
  383. TLan_DioWrite8(BASE, TLAN_LED_REG, TLAN_LED_LINK);
  384. #ifdef MONITOR
  385. /* We have link beat..for now anyway */
  386. priv->link = 1;
  387. /*Enabling link beat monitoring */
  388. /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_LINK_BEAT ); */
  389. mdelay(10000);
  390. TLan_PhyMonitor(nic);
  391. #endif
  392. } else if (status & MII_GS_LINK) {
  393. dprintf(("TLAN: %s: Link active\n", priv->nic_name));
  394. TLan_DioWrite8(BASE, TLAN_LED_REG, TLAN_LED_LINK);
  395. }
  396. }
  397. if (priv->phyNum == 0) {
  398. TLan_MiiReadReg(nic, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
  399. tlphy_ctl |= TLAN_TC_INTEN;
  400. TLan_MiiWriteReg(nic, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  401. sio = TLan_DioRead8(BASE, TLAN_NET_SIO);
  402. sio |= TLAN_NET_SIO_MINTEN;
  403. TLan_DioWrite8(BASE, TLAN_NET_SIO, sio);
  404. }
  405. if (status & MII_GS_LINK) {
  406. TLan_SetMac(nic, 0, nic->node_addr);
  407. priv->phyOnline = 1;
  408. outb((TLAN_HC_INT_ON >> 8), BASE + TLAN_HOST_CMD + 1);
  409. outl(virt_to_bus(&rx_ring), BASE + TLAN_CH_PARM);
  410. outl(TLAN_HC_GO | TLAN_HC_RT, BASE + TLAN_HOST_CMD);
  411. } else {
  412. dprintf
  413. (("TLAN: %s: Link inactive, will retry in 10 secs...\n",
  414. priv->nic_name));
  415. /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_FINISH_RESET ); */
  416. mdelay(10000);
  417. TLan_FinishReset(nic);
  418. return;
  419. }
  420. } /* TLan_FinishReset */
  421. /**************************************************************************
  422. POLL - Wait for a frame
  423. ***************************************************************************/
  424. static int tlan_poll(struct nic *nic, int retrieve)
  425. {
  426. /* return true if there's an ethernet packet ready to read */
  427. /* nic->packet should contain data on return */
  428. /* nic->packetlen should contain length of data */
  429. u32 framesize;
  430. u32 host_cmd = 0;
  431. u32 ack = 1;
  432. int eoc = 0;
  433. int entry = priv->cur_rx % TLAN_NUM_RX_LISTS;
  434. u16 tmpCStat = le32_to_cpu(rx_ring[entry].cStat);
  435. u16 host_int = inw(BASE + TLAN_HOST_INT);
  436. if ((tmpCStat & TLAN_CSTAT_FRM_CMP) && !retrieve)
  437. return 1;
  438. outw(host_int, BASE + TLAN_HOST_INT);
  439. if (!(tmpCStat & TLAN_CSTAT_FRM_CMP))
  440. return 0;
  441. /* printf("PI-1: 0x%hX\n", host_int); */
  442. if (tmpCStat & TLAN_CSTAT_EOC)
  443. eoc = 1;
  444. framesize = rx_ring[entry].frameSize;
  445. nic->packetlen = framesize;
  446. dprintf((".%d.", framesize));
  447. memcpy(nic->packet, rxb +
  448. (priv->cur_rx * TLAN_MAX_FRAME_SIZE), nic->packetlen);
  449. rx_ring[entry].cStat = 0;
  450. dprintf(("%d", entry));
  451. entry = (entry + 1) % TLAN_NUM_RX_LISTS;
  452. priv->cur_rx = entry;
  453. if (eoc) {
  454. if ((rx_ring[entry].cStat & TLAN_CSTAT_READY) ==
  455. TLAN_CSTAT_READY) {
  456. ack |= TLAN_HC_GO | TLAN_HC_RT;
  457. host_cmd = TLAN_HC_ACK | ack | 0x001C0000;
  458. outl(host_cmd, BASE + TLAN_HOST_CMD);
  459. }
  460. } else {
  461. host_cmd = TLAN_HC_ACK | ack | (0x000C0000);
  462. outl(host_cmd, BASE + TLAN_HOST_CMD);
  463. dprintf(("AC: 0x%hX\n", inw(BASE + TLAN_CH_PARM)));
  464. dprintf(("PI-2: 0x%hX\n", inw(BASE + TLAN_HOST_INT)));
  465. }
  466. refill_rx(nic);
  467. return (1); /* initially as this is called to flush the input */
  468. }
  469. static void refill_rx(struct nic *nic __unused)
  470. {
  471. int entry = 0;
  472. for (;
  473. (priv->cur_rx - priv->dirty_rx +
  474. TLAN_NUM_RX_LISTS) % TLAN_NUM_RX_LISTS > 0;
  475. priv->dirty_rx = (priv->dirty_rx + 1) % TLAN_NUM_RX_LISTS) {
  476. entry = priv->dirty_rx % TLAN_NUM_TX_LISTS;
  477. rx_ring[entry].frameSize = TLAN_MAX_FRAME_SIZE;
  478. rx_ring[entry].cStat = TLAN_CSTAT_READY;
  479. }
  480. }
  481. /**************************************************************************
  482. TRANSMIT - Transmit a frame
  483. ***************************************************************************/
  484. static void tlan_transmit(struct nic *nic, const char *d, /* Destination */
  485. unsigned int t, /* Type */
  486. unsigned int s, /* size */
  487. const char *p)
  488. { /* Packet */
  489. u16 nstype;
  490. u32 to;
  491. struct TLanList *tail_list;
  492. struct TLanList *head_list;
  493. u8 *tail_buffer;
  494. u32 ack = 0;
  495. u32 host_cmd;
  496. int eoc = 0;
  497. u16 tmpCStat;
  498. #ifdef EBDEBUG
  499. u16 host_int = inw(BASE + TLAN_HOST_INT);
  500. #endif
  501. int entry = 0;
  502. dprintf(("INT0-0x%hX\n", host_int));
  503. if (!priv->phyOnline) {
  504. printf("TRANSMIT: %s PHY is not ready\n", priv->nic_name);
  505. return;
  506. }
  507. tail_list = priv->txList + priv->txTail;
  508. if (tail_list->cStat != TLAN_CSTAT_UNUSED) {
  509. printf("TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
  510. priv->nic_name, priv->txList, priv->txTail);
  511. tx_ring[entry].cStat = TLAN_CSTAT_UNUSED;
  512. // priv->txBusyCount++;
  513. return;
  514. }
  515. tail_list->forward = 0;
  516. tail_buffer = txb + (priv->txTail * TLAN_MAX_FRAME_SIZE);
  517. /* send the packet to destination */
  518. memcpy(tail_buffer, d, ETH_ALEN);
  519. memcpy(tail_buffer + ETH_ALEN, nic->node_addr, ETH_ALEN);
  520. nstype = htons((u16) t);
  521. memcpy(tail_buffer + 2 * ETH_ALEN, (u8 *) & nstype, 2);
  522. memcpy(tail_buffer + ETH_HLEN, p, s);
  523. s += ETH_HLEN;
  524. s &= 0x0FFF;
  525. while (s < ETH_ZLEN)
  526. tail_buffer[s++] = '\0';
  527. /*=====================================================*/
  528. /* Receive
  529. * 0000 0000 0001 1100
  530. * 0000 0000 0000 1100
  531. * 0000 0000 0000 0011 = 0x0003
  532. *
  533. * 0000 0000 0000 0000 0000 0000 0000 0011
  534. * 0000 0000 0000 1100 0000 0000 0000 0000 = 0x000C0000
  535. *
  536. * Transmit
  537. * 0000 0000 0001 1100
  538. * 0000 0000 0000 0100
  539. * 0000 0000 0000 0001 = 0x0001
  540. *
  541. * 0000 0000 0000 0000 0000 0000 0000 0001
  542. * 0000 0000 0000 0100 0000 0000 0000 0000 = 0x00040000
  543. * */
  544. /* Setup the transmit descriptor */
  545. tail_list->frameSize = (u16) s;
  546. tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) s;
  547. tail_list->buffer[1].count = 0;
  548. tail_list->buffer[1].address = 0;
  549. tail_list->cStat = TLAN_CSTAT_READY;
  550. dprintf(("INT1-0x%hX\n", inw(BASE + TLAN_HOST_INT)));
  551. if (!priv->txInProgress) {
  552. priv->txInProgress = 1;
  553. outl(virt_to_le32desc(tail_list), BASE + TLAN_CH_PARM);
  554. outl(TLAN_HC_GO, BASE + TLAN_HOST_CMD);
  555. } else {
  556. if (priv->txTail == 0) {
  557. dprintf(("Out buffer\n"));
  558. (priv->txList + (TLAN_NUM_TX_LISTS - 1))->forward =
  559. virt_to_le32desc(tail_list);
  560. } else {
  561. dprintf(("Fix this \n"));
  562. (priv->txList + (priv->txTail - 1))->forward =
  563. virt_to_le32desc(tail_list);
  564. }
  565. }
  566. CIRC_INC(priv->txTail, TLAN_NUM_TX_LISTS);
  567. dprintf(("INT2-0x%hX\n", inw(BASE + TLAN_HOST_INT)));
  568. to = currticks() + TX_TIME_OUT;
  569. while ((tail_list->cStat == TLAN_CSTAT_READY) && currticks() < to);
  570. head_list = priv->txList + priv->txHead;
  571. while (((tmpCStat = head_list->cStat) & TLAN_CSTAT_FRM_CMP)
  572. && (ack < 255)) {
  573. ack++;
  574. if(tmpCStat & TLAN_CSTAT_EOC)
  575. eoc =1;
  576. head_list->cStat = TLAN_CSTAT_UNUSED;
  577. CIRC_INC(priv->txHead, TLAN_NUM_TX_LISTS);
  578. head_list = priv->txList + priv->txHead;
  579. }
  580. if(!ack)
  581. printf("Incomplete TX Frame\n");
  582. if(eoc) {
  583. head_list = priv->txList + priv->txHead;
  584. if ((head_list->cStat & TLAN_CSTAT_READY) == TLAN_CSTAT_READY) {
  585. outl(virt_to_le32desc(head_list), BASE + TLAN_CH_PARM);
  586. ack |= TLAN_HC_GO;
  587. } else {
  588. priv->txInProgress = 0;
  589. }
  590. }
  591. if(ack) {
  592. host_cmd = TLAN_HC_ACK | ack;
  593. outl(host_cmd, BASE + TLAN_HOST_CMD);
  594. }
  595. if(priv->tlanRev < 0x30 ) {
  596. ack = 1;
  597. head_list = priv->txList + priv->txHead;
  598. if ((head_list->cStat & TLAN_CSTAT_READY) == TLAN_CSTAT_READY) {
  599. outl(virt_to_le32desc(head_list), BASE + TLAN_CH_PARM);
  600. ack |= TLAN_HC_GO;
  601. } else {
  602. priv->txInProgress = 0;
  603. }
  604. host_cmd = TLAN_HC_ACK | ack | 0x00140000;
  605. outl(host_cmd, BASE + TLAN_HOST_CMD);
  606. }
  607. if (currticks() >= to) {
  608. printf("TX Time Out");
  609. }
  610. }
  611. /**************************************************************************
  612. DISABLE - Turn off ethernet interface
  613. ***************************************************************************/
  614. static void tlan_disable ( struct nic *nic __unused ) {
  615. /* put the card in its initial state */
  616. /* This function serves 3 purposes.
  617. * This disables DMA and interrupts so we don't receive
  618. * unexpected packets or interrupts from the card after
  619. * etherboot has finished.
  620. * This frees resources so etherboot may use
  621. * this driver on another interface
  622. * This allows etherboot to reinitialize the interface
  623. * if something is something goes wrong.
  624. *
  625. */
  626. outl(TLAN_HC_AD_RST, BASE + TLAN_HOST_CMD);
  627. }
  628. /**************************************************************************
  629. IRQ - Enable, Disable, or Force interrupts
  630. ***************************************************************************/
  631. static void tlan_irq(struct nic *nic __unused, irq_action_t action __unused)
  632. {
  633. switch ( action ) {
  634. case DISABLE :
  635. break;
  636. case ENABLE :
  637. break;
  638. case FORCE :
  639. break;
  640. }
  641. }
  642. static void TLan_SetMulticastList(struct nic *nic) {
  643. int i;
  644. u8 tmp;
  645. /* !IFF_PROMISC */
  646. tmp = TLan_DioRead8(BASE, TLAN_NET_CMD);
  647. TLan_DioWrite8(BASE, TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
  648. /* IFF_ALLMULTI */
  649. for(i = 0; i< 3; i++)
  650. TLan_SetMac(nic, i + 1, NULL);
  651. TLan_DioWrite32(BASE, TLAN_HASH_1, 0xFFFFFFFF);
  652. TLan_DioWrite32(BASE, TLAN_HASH_2, 0xFFFFFFFF);
  653. }
  654. /**************************************************************************
  655. PROBE - Look for an adapter, this routine's visible to the outside
  656. ***************************************************************************/
  657. #define board_found 1
  658. #define valid_link 0
  659. static int tlan_probe ( struct dev *dev ) {
  660. struct nic *nic = nic_device ( dev );
  661. struct pci_device *pci = pci_device ( dev );
  662. u16 data = 0;
  663. int err;
  664. int i;
  665. if (pci->ioaddr == 0)
  666. return 0;
  667. nic->irqno = 0;
  668. nic->ioaddr = pci->ioaddr & ~3;
  669. BASE = pci->ioaddr;
  670. printf("tlan.c: Found %s, Vendor 0x%hX, Device 0x%hX\n",
  671. pci->name, pci->vendor, pci->dev_id);
  672. /* Set nic as PCI bus master */
  673. adjust_pci_device(pci);
  674. /* Point to private storage */
  675. priv = &TLanPrivateInfo;
  676. /* Figure out which chip we're dealing with */
  677. i = 0;
  678. chip_idx = -1;
  679. while (tlan_pci_tbl[i].name) {
  680. if ((((u32) pci->dev_id << 16) | pci->vendor) ==
  681. (tlan_pci_tbl[i].id.pci & 0xffffffff)) {
  682. chip_idx = i;
  683. break;
  684. }
  685. i++;
  686. }
  687. priv->vendor_id = pci->vendor;
  688. priv->dev_id = pci->dev_id;
  689. priv->nic_name = pci->name;
  690. priv->eoc = 0;
  691. err = 0;
  692. for (i = 0; i < 6; i++)
  693. err |= TLan_EeReadByte(BASE,
  694. (u8) tlan_pci_tbl[chip_idx].
  695. addrOfs + i,
  696. (u8 *) & nic->node_addr[i]);
  697. if (err) {
  698. printf("TLAN: %s: Error reading MAC from eeprom: %d\n",
  699. pci->name, err);
  700. } else
  701. /* Print out some hardware info */
  702. printf("%s: %! at ioaddr %hX, ",
  703. pci->name, nic->node_addr, pci->ioaddr);
  704. priv->tlanRev = TLan_DioRead8(BASE, TLAN_DEF_REVISION);
  705. printf("revision: 0x%hX\n", priv->tlanRev);
  706. TLan_ResetLists(nic);
  707. TLan_ResetAdapter(nic);
  708. data = inl(BASE + TLAN_HOST_CMD);
  709. data |= TLAN_HC_INT_OFF;
  710. outw(data, BASE + TLAN_HOST_CMD);
  711. TLan_SetMulticastList(nic);
  712. udelay(100);
  713. priv->txList = tx_ring;
  714. /* if (board_found && valid_link)
  715. {*/
  716. /* point to NIC specific routines */
  717. static struct nic_operations tlan_operations;
  718. static struct nic_operations tlan_operations = {
  719. .connect = dummy_connect,
  720. .poll = tlan_poll,
  721. .transmit = tlan_transmit,
  722. .irq = tlan_irq,
  723. .disable = tlan_disable,
  724. };
  725. nic->nic_op = &tlan_operations;
  726. return 1;
  727. }
  728. /*****************************************************************************
  729. ******************************************************************************
  730. ThunderLAN Driver Eeprom routines
  731. The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
  732. EEPROM. These functions are based on information in Microchip's
  733. data sheet. I don't know how well this functions will work with
  734. other EEPROMs.
  735. ******************************************************************************
  736. *****************************************************************************/
  737. /***************************************************************
  738. * TLan_EeSendStart
  739. *
  740. * Returns:
  741. * Nothing
  742. * Parms:
  743. * io_base The IO port base address for the
  744. * TLAN device with the EEPROM to
  745. * use.
  746. *
  747. * This function sends a start cycle to an EEPROM attached
  748. * to a TLAN chip.
  749. *
  750. **************************************************************/
  751. void TLan_EeSendStart(u16 io_base)
  752. {
  753. u16 sio;
  754. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  755. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  756. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  757. TLan_SetBit(TLAN_NET_SIO_EDATA, sio);
  758. TLan_SetBit(TLAN_NET_SIO_ETXEN, sio);
  759. TLan_ClearBit(TLAN_NET_SIO_EDATA, sio);
  760. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  761. } /* TLan_EeSendStart */
  762. /***************************************************************
  763. * TLan_EeSendByte
  764. *
  765. * Returns:
  766. * If the correct ack was received, 0, otherwise 1
  767. * Parms: io_base The IO port base address for the
  768. * TLAN device with the EEPROM to
  769. * use.
  770. * data The 8 bits of information to
  771. * send to the EEPROM.
  772. * stop If TLAN_EEPROM_STOP is passed, a
  773. * stop cycle is sent after the
  774. * byte is sent after the ack is
  775. * read.
  776. *
  777. * This function sends a byte on the serial EEPROM line,
  778. * driving the clock to send each bit. The function then
  779. * reverses transmission direction and reads an acknowledge
  780. * bit.
  781. *
  782. **************************************************************/
  783. int TLan_EeSendByte(u16 io_base, u8 data, int stop)
  784. {
  785. int err;
  786. u8 place;
  787. u16 sio;
  788. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  789. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  790. /* Assume clock is low, tx is enabled; */
  791. for (place = 0x80; place != 0; place >>= 1) {
  792. if (place & data)
  793. TLan_SetBit(TLAN_NET_SIO_EDATA, sio);
  794. else
  795. TLan_ClearBit(TLAN_NET_SIO_EDATA, sio);
  796. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  797. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  798. }
  799. TLan_ClearBit(TLAN_NET_SIO_ETXEN, sio);
  800. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  801. err = TLan_GetBit(TLAN_NET_SIO_EDATA, sio);
  802. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  803. TLan_SetBit(TLAN_NET_SIO_ETXEN, sio);
  804. if ((!err) && stop) {
  805. TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* STOP, raise data while clock is high */
  806. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  807. TLan_SetBit(TLAN_NET_SIO_EDATA, sio);
  808. }
  809. return (err);
  810. } /* TLan_EeSendByte */
  811. /***************************************************************
  812. * TLan_EeReceiveByte
  813. *
  814. * Returns:
  815. * Nothing
  816. * Parms:
  817. * io_base The IO port base address for the
  818. * TLAN device with the EEPROM to
  819. * use.
  820. * data An address to a char to hold the
  821. * data sent from the EEPROM.
  822. * stop If TLAN_EEPROM_STOP is passed, a
  823. * stop cycle is sent after the
  824. * byte is received, and no ack is
  825. * sent.
  826. *
  827. * This function receives 8 bits of data from the EEPROM
  828. * over the serial link. It then sends and ack bit, or no
  829. * ack and a stop bit. This function is used to retrieve
  830. * data after the address of a byte in the EEPROM has been
  831. * sent.
  832. *
  833. **************************************************************/
  834. void TLan_EeReceiveByte(u16 io_base, u8 * data, int stop)
  835. {
  836. u8 place;
  837. u16 sio;
  838. outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
  839. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  840. *data = 0;
  841. /* Assume clock is low, tx is enabled; */
  842. TLan_ClearBit(TLAN_NET_SIO_ETXEN, sio);
  843. for (place = 0x80; place; place >>= 1) {
  844. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  845. if (TLan_GetBit(TLAN_NET_SIO_EDATA, sio))
  846. *data |= place;
  847. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  848. }
  849. TLan_SetBit(TLAN_NET_SIO_ETXEN, sio);
  850. if (!stop) {
  851. TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* Ack = 0 */
  852. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  853. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  854. } else {
  855. TLan_SetBit(TLAN_NET_SIO_EDATA, sio); /* No ack = 1 (?) */
  856. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  857. TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
  858. TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* STOP, raise data while clock is high */
  859. TLan_SetBit(TLAN_NET_SIO_ECLOK, sio);
  860. TLan_SetBit(TLAN_NET_SIO_EDATA, sio);
  861. }
  862. } /* TLan_EeReceiveByte */
  863. /***************************************************************
  864. * TLan_EeReadByte
  865. *
  866. * Returns:
  867. * No error = 0, else, the stage at which the error
  868. * occurred.
  869. * Parms:
  870. * io_base The IO port base address for the
  871. * TLAN device with the EEPROM to
  872. * use.
  873. * ee_addr The address of the byte in the
  874. * EEPROM whose contents are to be
  875. * retrieved.
  876. * data An address to a char to hold the
  877. * data obtained from the EEPROM.
  878. *
  879. * This function reads a byte of information from an byte
  880. * cell in the EEPROM.
  881. *
  882. **************************************************************/
  883. int TLan_EeReadByte(u16 io_base, u8 ee_addr, u8 * data)
  884. {
  885. int err;
  886. int ret = 0;
  887. TLan_EeSendStart(io_base);
  888. err = TLan_EeSendByte(io_base, 0xA0, TLAN_EEPROM_ACK);
  889. if (err) {
  890. ret = 1;
  891. goto fail;
  892. }
  893. err = TLan_EeSendByte(io_base, ee_addr, TLAN_EEPROM_ACK);
  894. if (err) {
  895. ret = 2;
  896. goto fail;
  897. }
  898. TLan_EeSendStart(io_base);
  899. err = TLan_EeSendByte(io_base, 0xA1, TLAN_EEPROM_ACK);
  900. if (err) {
  901. ret = 3;
  902. goto fail;
  903. }
  904. TLan_EeReceiveByte(io_base, data, TLAN_EEPROM_STOP);
  905. fail:
  906. return ret;
  907. } /* TLan_EeReadByte */
  908. /*****************************************************************************
  909. ******************************************************************************
  910. ThunderLAN Driver MII Routines
  911. These routines are based on the information in Chap. 2 of the
  912. "ThunderLAN Programmer's Guide", pp. 15-24.
  913. ******************************************************************************
  914. *****************************************************************************/
  915. /***************************************************************
  916. * TLan_MiiReadReg
  917. *
  918. * Returns:
  919. * 0 if ack received ok
  920. * 1 otherwise.
  921. *
  922. * Parms:
  923. * dev The device structure containing
  924. * The io address and interrupt count
  925. * for this device.
  926. * phy The address of the PHY to be queried.
  927. * reg The register whose contents are to be
  928. * retreived.
  929. * val A pointer to a variable to store the
  930. * retrieved value.
  931. *
  932. * This function uses the TLAN's MII bus to retreive the contents
  933. * of a given register on a PHY. It sends the appropriate info
  934. * and then reads the 16-bit register value from the MII bus via
  935. * the TLAN SIO register.
  936. *
  937. **************************************************************/
  938. int TLan_MiiReadReg(struct nic *nic __unused, u16 phy, u16 reg, u16 * val)
  939. {
  940. u8 nack;
  941. u16 sio, tmp;
  942. u32 i;
  943. int err;
  944. int minten;
  945. err = FALSE;
  946. outw(TLAN_NET_SIO, BASE + TLAN_DIO_ADR);
  947. sio = BASE + TLAN_DIO_DATA + TLAN_NET_SIO;
  948. TLan_MiiSync(BASE);
  949. minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
  950. if (minten)
  951. TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
  952. TLan_MiiSendData(BASE, 0x1, 2); /* Start ( 01b ) */
  953. TLan_MiiSendData(BASE, 0x2, 2); /* Read ( 10b ) */
  954. TLan_MiiSendData(BASE, phy, 5); /* Device # */
  955. TLan_MiiSendData(BASE, reg, 5); /* Register # */
  956. TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
  957. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
  958. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  959. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
  960. nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
  961. TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
  962. if (nack) { /* No ACK, so fake it */
  963. for (i = 0; i < 16; i++) {
  964. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  965. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  966. }
  967. tmp = 0xffff;
  968. err = TRUE;
  969. } else { /* ACK, so read data */
  970. for (tmp = 0, i = 0x8000; i; i >>= 1) {
  971. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  972. if (TLan_GetBit(TLAN_NET_SIO_MDATA, sio))
  973. tmp |= i;
  974. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  975. }
  976. }
  977. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
  978. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  979. if (minten)
  980. TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
  981. *val = tmp;
  982. return err;
  983. } /* TLan_MiiReadReg */
  984. /***************************************************************
  985. * TLan_MiiSendData
  986. *
  987. * Returns:
  988. * Nothing
  989. * Parms:
  990. * base_port The base IO port of the adapter in
  991. * question.
  992. * dev The address of the PHY to be queried.
  993. * data The value to be placed on the MII bus.
  994. * num_bits The number of bits in data that are to
  995. * be placed on the MII bus.
  996. *
  997. * This function sends on sequence of bits on the MII
  998. * configuration bus.
  999. *
  1000. **************************************************************/
  1001. void TLan_MiiSendData(u16 base_port, u32 data, unsigned num_bits)
  1002. {
  1003. u16 sio;
  1004. u32 i;
  1005. if (num_bits == 0)
  1006. return;
  1007. outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
  1008. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  1009. TLan_SetBit(TLAN_NET_SIO_MTXEN, sio);
  1010. for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
  1011. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  1012. (void) TLan_GetBit(TLAN_NET_SIO_MCLK, sio);
  1013. if (data & i)
  1014. TLan_SetBit(TLAN_NET_SIO_MDATA, sio);
  1015. else
  1016. TLan_ClearBit(TLAN_NET_SIO_MDATA, sio);
  1017. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  1018. (void) TLan_GetBit(TLAN_NET_SIO_MCLK, sio);
  1019. }
  1020. } /* TLan_MiiSendData */
  1021. /***************************************************************
  1022. * TLan_MiiSync
  1023. *
  1024. * Returns:
  1025. * Nothing
  1026. * Parms:
  1027. * base_port The base IO port of the adapter in
  1028. * question.
  1029. *
  1030. * This functions syncs all PHYs in terms of the MII configuration
  1031. * bus.
  1032. *
  1033. **************************************************************/
  1034. void TLan_MiiSync(u16 base_port)
  1035. {
  1036. int i;
  1037. u16 sio;
  1038. outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
  1039. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  1040. TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio);
  1041. for (i = 0; i < 32; i++) {
  1042. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  1043. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  1044. }
  1045. } /* TLan_MiiSync */
  1046. /***************************************************************
  1047. * TLan_MiiWriteReg
  1048. *
  1049. * Returns:
  1050. * Nothing
  1051. * Parms:
  1052. * dev The device structure for the device
  1053. * to write to.
  1054. * phy The address of the PHY to be written to.
  1055. * reg The register whose contents are to be
  1056. * written.
  1057. * val The value to be written to the register.
  1058. *
  1059. * This function uses the TLAN's MII bus to write the contents of a
  1060. * given register on a PHY. It sends the appropriate info and then
  1061. * writes the 16-bit register value from the MII configuration bus
  1062. * via the TLAN SIO register.
  1063. *
  1064. **************************************************************/
  1065. void TLan_MiiWriteReg(struct nic *nic __unused, u16 phy, u16 reg, u16 val)
  1066. {
  1067. u16 sio;
  1068. int minten;
  1069. outw(TLAN_NET_SIO, BASE + TLAN_DIO_ADR);
  1070. sio = BASE + TLAN_DIO_DATA + TLAN_NET_SIO;
  1071. TLan_MiiSync(BASE);
  1072. minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
  1073. if (minten)
  1074. TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
  1075. TLan_MiiSendData(BASE, 0x1, 2); /* Start ( 01b ) */
  1076. TLan_MiiSendData(BASE, 0x1, 2); /* Write ( 01b ) */
  1077. TLan_MiiSendData(BASE, phy, 5); /* Device # */
  1078. TLan_MiiSendData(BASE, reg, 5); /* Register # */
  1079. TLan_MiiSendData(BASE, 0x2, 2); /* Send ACK */
  1080. TLan_MiiSendData(BASE, val, 16); /* Send Data */
  1081. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
  1082. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  1083. if (minten)
  1084. TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
  1085. } /* TLan_MiiWriteReg */
  1086. /***************************************************************
  1087. * TLan_SetMac
  1088. *
  1089. * Returns:
  1090. * Nothing
  1091. * Parms:
  1092. * dev Pointer to device structure of adapter
  1093. * on which to change the AREG.
  1094. * areg The AREG to set the address in (0 - 3).
  1095. * mac A pointer to an array of chars. Each
  1096. * element stores one byte of the address.
  1097. * IE, it isn't in ascii.
  1098. *
  1099. * This function transfers a MAC address to one of the
  1100. * TLAN AREGs (address registers). The TLAN chip locks
  1101. * the register on writing to offset 0 and unlocks the
  1102. * register after writing to offset 5. If NULL is passed
  1103. * in mac, then the AREG is filled with 0's.
  1104. *
  1105. **************************************************************/
  1106. void TLan_SetMac(struct nic *nic __unused, int areg, char *mac)
  1107. {
  1108. int i;
  1109. areg *= 6;
  1110. if (mac != NULL) {
  1111. for (i = 0; i < 6; i++)
  1112. TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i,
  1113. mac[i]);
  1114. } else {
  1115. for (i = 0; i < 6; i++)
  1116. TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i, 0);
  1117. }
  1118. } /* TLan_SetMac */
  1119. /*********************************************************************
  1120. * TLan_PhyDetect
  1121. *
  1122. * Returns:
  1123. * Nothing
  1124. * Parms:
  1125. * dev A pointer to the device structure of the adapter
  1126. * for which the PHY needs determined.
  1127. *
  1128. * So far I've found that adapters which have external PHYs
  1129. * may also use the internal PHY for part of the functionality.
  1130. * (eg, AUI/Thinnet). This function finds out if this TLAN
  1131. * chip has an internal PHY, and then finds the first external
  1132. * PHY (starting from address 0) if it exists).
  1133. *
  1134. ********************************************************************/
  1135. void TLan_PhyDetect(struct nic *nic)
  1136. {
  1137. u16 control;
  1138. u16 hi;
  1139. u16 lo;
  1140. u32 phy;
  1141. if (tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_UNMANAGED_PHY) {
  1142. priv->phyNum = 0xFFFF;
  1143. return;
  1144. }
  1145. TLan_MiiReadReg(nic, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
  1146. if (hi != 0xFFFF) {
  1147. priv->phy[0] = TLAN_PHY_MAX_ADDR;
  1148. } else {
  1149. priv->phy[0] = TLAN_PHY_NONE;
  1150. }
  1151. priv->phy[1] = TLAN_PHY_NONE;
  1152. for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
  1153. TLan_MiiReadReg(nic, phy, MII_GEN_CTL, &control);
  1154. TLan_MiiReadReg(nic, phy, MII_GEN_ID_HI, &hi);
  1155. TLan_MiiReadReg(nic, phy, MII_GEN_ID_LO, &lo);
  1156. if ((control != 0xFFFF) || (hi != 0xFFFF)
  1157. || (lo != 0xFFFF)) {
  1158. printf("PHY found at %hX %hX %hX %hX\n", phy,
  1159. control, hi, lo);
  1160. if ((priv->phy[1] == TLAN_PHY_NONE)
  1161. && (phy != TLAN_PHY_MAX_ADDR)) {
  1162. priv->phy[1] = phy;
  1163. }
  1164. }
  1165. }
  1166. if (priv->phy[1] != TLAN_PHY_NONE) {
  1167. priv->phyNum = 1;
  1168. } else if (priv->phy[0] != TLAN_PHY_NONE) {
  1169. priv->phyNum = 0;
  1170. } else {
  1171. printf
  1172. ("TLAN: Cannot initialize device, no PHY was found!\n");
  1173. }
  1174. } /* TLan_PhyDetect */
  1175. void TLan_PhyPowerDown(struct nic *nic)
  1176. {
  1177. u16 value;
  1178. dprintf(("%s: Powering down PHY(s).\n", priv->nic_name));
  1179. value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
  1180. TLan_MiiSync(BASE);
  1181. TLan_MiiWriteReg(nic, priv->phy[priv->phyNum], MII_GEN_CTL, value);
  1182. if ((priv->phyNum == 0) && (priv->phy[1] != TLAN_PHY_NONE)
  1183. &&
  1184. (!(tlan_pci_tbl[chip_idx].
  1185. flags & TLAN_ADAPTER_USE_INTERN_10))) {
  1186. TLan_MiiSync(BASE);
  1187. TLan_MiiWriteReg(nic, priv->phy[1], MII_GEN_CTL, value);
  1188. }
  1189. /* Wait for 50 ms and powerup
  1190. * This is abitrary. It is intended to make sure the
  1191. * tranceiver settles.
  1192. */
  1193. /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP ); */
  1194. mdelay(50);
  1195. TLan_PhyPowerUp(nic);
  1196. } /* TLan_PhyPowerDown */
  1197. void TLan_PhyPowerUp(struct nic *nic)
  1198. {
  1199. u16 value;
  1200. dprintf(("%s: Powering up PHY.\n", priv->nic_name));
  1201. TLan_MiiSync(BASE);
  1202. value = MII_GC_LOOPBK;
  1203. TLan_MiiWriteReg(nic, priv->phy[priv->phyNum], MII_GEN_CTL, value);
  1204. TLan_MiiSync(BASE);
  1205. /* Wait for 500 ms and reset the
  1206. * tranceiver. The TLAN docs say both 50 ms and
  1207. * 500 ms, so do the longer, just in case.
  1208. */
  1209. mdelay(500);
  1210. TLan_PhyReset(nic);
  1211. /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET ); */
  1212. } /* TLan_PhyPowerUp */
  1213. void TLan_PhyReset(struct nic *nic)
  1214. {
  1215. u16 phy;
  1216. u16 value;
  1217. phy = priv->phy[priv->phyNum];
  1218. dprintf(("%s: Reseting PHY.\n", priv->nic_name));
  1219. TLan_MiiSync(BASE);
  1220. value = MII_GC_LOOPBK | MII_GC_RESET;
  1221. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, value);
  1222. TLan_MiiReadReg(nic, phy, MII_GEN_CTL, &value);
  1223. while (value & MII_GC_RESET) {
  1224. TLan_MiiReadReg(nic, phy, MII_GEN_CTL, &value);
  1225. }
  1226. /* Wait for 500 ms and initialize.
  1227. * I don't remember why I wait this long.
  1228. * I've changed this to 50ms, as it seems long enough.
  1229. */
  1230. /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK ); */
  1231. mdelay(50);
  1232. TLan_PhyStartLink(nic);
  1233. } /* TLan_PhyReset */
  1234. void TLan_PhyStartLink(struct nic *nic)
  1235. {
  1236. u16 ability;
  1237. u16 control;
  1238. u16 data;
  1239. u16 phy;
  1240. u16 status;
  1241. u16 tctl;
  1242. phy = priv->phy[priv->phyNum];
  1243. dprintf(("%s: Trying to activate link.\n", priv->nic_name));
  1244. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
  1245. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &ability);
  1246. if ((status & MII_GS_AUTONEG) && (!priv->aui)) {
  1247. ability = status >> 11;
  1248. if (priv->speed == TLAN_SPEED_10 &&
  1249. priv->duplex == TLAN_DUPLEX_HALF) {
  1250. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x0000);
  1251. } else if (priv->speed == TLAN_SPEED_10 &&
  1252. priv->duplex == TLAN_DUPLEX_FULL) {
  1253. priv->tlanFullDuplex = TRUE;
  1254. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x0100);
  1255. } else if (priv->speed == TLAN_SPEED_100 &&
  1256. priv->duplex == TLAN_DUPLEX_HALF) {
  1257. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x2000);
  1258. } else if (priv->speed == TLAN_SPEED_100 &&
  1259. priv->duplex == TLAN_DUPLEX_FULL) {
  1260. priv->tlanFullDuplex = TRUE;
  1261. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x2100);
  1262. } else {
  1263. /* Set Auto-Neg advertisement */
  1264. TLan_MiiWriteReg(nic, phy, MII_AN_ADV,
  1265. (ability << 5) | 1);
  1266. /* Enablee Auto-Neg */
  1267. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x1000);
  1268. /* Restart Auto-Neg */
  1269. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, 0x1200);
  1270. /* Wait for 4 sec for autonegotiation
  1271. * to complete. The max spec time is less than this
  1272. * but the card need additional time to start AN.
  1273. * .5 sec should be plenty extra.
  1274. */
  1275. dprintf(("TLAN: %s: Starting autonegotiation.\n",
  1276. priv->nic_name));
  1277. mdelay(4000);
  1278. TLan_PhyFinishAutoNeg(nic);
  1279. /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
  1280. return;
  1281. }
  1282. }
  1283. if ((priv->aui) && (priv->phyNum != 0)) {
  1284. priv->phyNum = 0;
  1285. data =
  1286. TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN |
  1287. TLAN_NET_CFG_PHY_EN;
  1288. TLan_DioWrite16(BASE, TLAN_NET_CONFIG, data);
  1289. mdelay(50);
  1290. /* TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
  1291. TLan_PhyPowerDown(nic);
  1292. return;
  1293. } else if (priv->phyNum == 0) {
  1294. control = 0;
  1295. TLan_MiiReadReg(nic, phy, TLAN_TLPHY_CTL, &tctl);
  1296. if (priv->aui) {
  1297. tctl |= TLAN_TC_AUISEL;
  1298. } else {
  1299. tctl &= ~TLAN_TC_AUISEL;
  1300. if (priv->duplex == TLAN_DUPLEX_FULL) {
  1301. control |= MII_GC_DUPLEX;
  1302. priv->tlanFullDuplex = TRUE;
  1303. }
  1304. if (priv->speed == TLAN_SPEED_100) {
  1305. control |= MII_GC_SPEEDSEL;
  1306. }
  1307. }
  1308. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL, control);
  1309. TLan_MiiWriteReg(nic, phy, TLAN_TLPHY_CTL, tctl);
  1310. }
  1311. /* Wait for 2 sec to give the tranceiver time
  1312. * to establish link.
  1313. */
  1314. /* TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET ); */
  1315. mdelay(2000);
  1316. TLan_FinishReset(nic);
  1317. } /* TLan_PhyStartLink */
  1318. void TLan_PhyFinishAutoNeg(struct nic *nic)
  1319. {
  1320. u16 an_adv;
  1321. u16 an_lpa;
  1322. u16 data;
  1323. u16 mode;
  1324. u16 phy;
  1325. u16 status;
  1326. phy = priv->phy[priv->phyNum];
  1327. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
  1328. udelay(1000);
  1329. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
  1330. if (!(status & MII_GS_AUTOCMPLT)) {
  1331. /* Wait for 8 sec to give the process
  1332. * more time. Perhaps we should fail after a while.
  1333. */
  1334. if (!priv->neg_be_verbose++) {
  1335. printf
  1336. ("TLAN: Giving autonegotiation more time.\n");
  1337. printf
  1338. ("TLAN: Please check that your adapter has\n");
  1339. printf
  1340. ("TLAN: been properly connected to a HUB or Switch.\n");
  1341. printf
  1342. ("TLAN: Trying to establish link in the background...\n");
  1343. }
  1344. mdelay(8000);
  1345. TLan_PhyFinishAutoNeg(nic);
  1346. /* TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
  1347. return;
  1348. }
  1349. dprintf(("TLAN: %s: Autonegotiation complete.\n", priv->nic_name));
  1350. TLan_MiiReadReg(nic, phy, MII_AN_ADV, &an_adv);
  1351. TLan_MiiReadReg(nic, phy, MII_AN_LPA, &an_lpa);
  1352. mode = an_adv & an_lpa & 0x03E0;
  1353. if (mode & 0x0100) {
  1354. printf("Full Duplex\n");
  1355. priv->tlanFullDuplex = TRUE;
  1356. } else if (!(mode & 0x0080) && (mode & 0x0040)) {
  1357. priv->tlanFullDuplex = TRUE;
  1358. printf("Full Duplex\n");
  1359. }
  1360. if ((!(mode & 0x0180))
  1361. && (tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_USE_INTERN_10)
  1362. && (priv->phyNum != 0)) {
  1363. priv->phyNum = 0;
  1364. data =
  1365. TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN |
  1366. TLAN_NET_CFG_PHY_EN;
  1367. TLan_DioWrite16(BASE, TLAN_NET_CONFIG, data);
  1368. /* TLan_SetTimer( nic, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
  1369. mdelay(400);
  1370. TLan_PhyPowerDown(nic);
  1371. return;
  1372. }
  1373. if (priv->phyNum == 0) {
  1374. if ((priv->duplex == TLAN_DUPLEX_FULL)
  1375. || (an_adv & an_lpa & 0x0040)) {
  1376. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL,
  1377. MII_GC_AUTOENB | MII_GC_DUPLEX);
  1378. dprintf
  1379. (("TLAN: Starting internal PHY with FULL-DUPLEX\n"));
  1380. } else {
  1381. TLan_MiiWriteReg(nic, phy, MII_GEN_CTL,
  1382. MII_GC_AUTOENB);
  1383. dprintf
  1384. (("TLAN: Starting internal PHY with HALF-DUPLEX\n"));
  1385. }
  1386. }
  1387. /* Wait for 100 ms. No reason in partiticular.
  1388. */
  1389. /* TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET ); */
  1390. mdelay(100);
  1391. TLan_FinishReset(nic);
  1392. } /* TLan_PhyFinishAutoNeg */
  1393. #ifdef MONITOR
  1394. /*********************************************************************
  1395. *
  1396. * TLan_phyMonitor
  1397. *
  1398. * Returns:
  1399. * None
  1400. *
  1401. * Params:
  1402. * dev The device structure of this device.
  1403. *
  1404. *
  1405. * This function monitors PHY condition by reading the status
  1406. * register via the MII bus. This can be used to give info
  1407. * about link changes (up/down), and possible switch to alternate
  1408. * media.
  1409. *
  1410. ********************************************************************/
  1411. void TLan_PhyMonitor(struct net_device *dev)
  1412. {
  1413. TLanPrivateInfo *priv = dev->priv;
  1414. u16 phy;
  1415. u16 phy_status;
  1416. phy = priv->phy[priv->phyNum];
  1417. /* Get PHY status register */
  1418. TLan_MiiReadReg(nic, phy, MII_GEN_STS, &phy_status);
  1419. /* Check if link has been lost */
  1420. if (!(phy_status & MII_GS_LINK)) {
  1421. if (priv->link) {
  1422. priv->link = 0;
  1423. printf("TLAN: %s has lost link\n", priv->nic_name);
  1424. priv->flags &= ~IFF_RUNNING;
  1425. mdelay(2000);
  1426. TLan_PhyMonitor(nic);
  1427. /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
  1428. return;
  1429. }
  1430. }
  1431. /* Link restablished? */
  1432. if ((phy_status & MII_GS_LINK) && !priv->link) {
  1433. priv->link = 1;
  1434. printf("TLAN: %s has reestablished link\n",
  1435. priv->nic_name);
  1436. priv->flags |= IFF_RUNNING;
  1437. }
  1438. /* Setup a new monitor */
  1439. /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
  1440. mdelay(2000);
  1441. TLan_PhyMonitor(nic);
  1442. }
  1443. #endif /* MONITOR */
  1444. static struct pci_id tlan_nics[] = {
  1445. PCI_ROM(0x0e11, 0xae34, "netel10", "Compaq Netelligent 10 T PCI UTP"),
  1446. PCI_ROM(0x0e11, 0xae32, "netel100","Compaq Netelligent 10/100 TX PCI UTP"),
  1447. PCI_ROM(0x0e11, 0xae35, "netflex3i", "Compaq Integrated NetFlex-3/P"),
  1448. PCI_ROM(0x0e11, 0xf130, "thunder", "Compaq NetFlex-3/P"),
  1449. PCI_ROM(0x0e11, 0xf150, "netflex3b", "Compaq NetFlex-3/P"),
  1450. PCI_ROM(0x0e11, 0xae43, "netel100pi", "Compaq Netelligent Integrated 10/100 TX UTP"),
  1451. PCI_ROM(0x0e11, 0xae40, "netel100d", "Compaq Netelligent Dual 10/100 TX PCI UTP"),
  1452. PCI_ROM(0x0e11, 0xb011, "netel100i", "Compaq Netelligent 10/100 TX Embedded UTP"),
  1453. PCI_ROM(0x108d, 0x0013, "oc2183", "Olicom OC-2183/2185"),
  1454. PCI_ROM(0x108d, 0x0012, "oc2325", "Olicom OC-2325"),
  1455. PCI_ROM(0x108d, 0x0014, "oc2326", "Olicom OC-2326"),
  1456. PCI_ROM(0x0e11, 0xb030, "netelligent_10_100_ws_5100", "Compaq Netelligent 10/100 TX UTP"),
  1457. PCI_ROM(0x0e11, 0xb012, "netelligent_10_t2", "Compaq Netelligent 10 T/2 PCI UTP/Coax"),
  1458. };
  1459. static struct pci_driver tlan_driver =
  1460. PCI_DRIVER ( "TLAN/PCI", tlan_nics, PCI_NO_CLASS );
  1461. BOOT_DRIVER ( "TLAN/PCI", tlan_probe );