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.

3c515.c 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /*
  2. * 3c515.c -- 3COM 3C515 Fast Etherlink ISA 10/100BASE-TX driver for etherboot
  3. * Copyright (C) 2002 Timothy Legge <tlegge@rogers.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. *
  20. * Portions of this code:
  21. * Copyright (C) 1997-2002 Donald Becker 3c515.c: A 3Com ISA EtherLink XL "Corkscrew" ethernet driver for linux.
  22. * Copyright (C) 2001 P.J.H.Fox (fox@roestock.demon.co.uk) ISAPNP Tools
  23. * Copyright (c) 2002 Jaroslav Kysela <perex@suse.cz> ISA Plug & Play support Linux Kernel
  24. * Copyright (C) 2000 Shusuke Nisiyama <shu@athena.qe.eng.hokudai.ac.jp> etherboot-5.0.5 3c595.c
  25. * Coptright (C) 1995 Martin Renters etherboot-5.0.5 3c509.c
  26. * Copyright (C) 1999 LightSys Technology Services, Inc. etherboot-5.0.5 3c90x.c
  27. * Portions Copyright (C) 1999 Steve Smith etherboot-5.0.5 3c90x.c
  28. *
  29. * The probe and reset functions and defines are direct copies from the
  30. * Becker code modified where necessary to make it work for etherboot
  31. *
  32. * The poll and transmit functions either contain code from or were written by referencing
  33. * the above referenced etherboot drivers. This driver would not have been
  34. * possible without this prior work
  35. *
  36. * REVISION HISTORY:
  37. * ================
  38. * v0.10 4-17-2002 TJL Initial implementation.
  39. * v0.11 4-17-2002 TJL Cleanup of the code
  40. * v0.12 4-26-2002 TJL Added ISA Plug and Play for Non-PNP Bioses
  41. * v0.13 6-10-2002 TJL Fixed ISA_PNP MAC Address problem
  42. * v0.14 9-23-2003 TJL Replaced delay with currticks
  43. *
  44. * Indent Options: indent -kr -i8
  45. * *********************************************************/
  46. FILE_LICENCE ( GPL2_OR_LATER );
  47. /* to get some global routines like printf */
  48. #include "etherboot.h"
  49. /* to get the interface to the body of the program */
  50. #include "nic.h"
  51. #include <ipxe/isapnp.h>
  52. #include <ipxe/isa.h> /* for ISA_ROM */
  53. #include <ipxe/ethernet.h>
  54. static void t3c515_wait(unsigned int nticks)
  55. {
  56. unsigned int to = currticks() + nticks;
  57. while (currticks() < to)
  58. /* wait */ ;
  59. }
  60. /* TJL definations */
  61. #define HZ 100
  62. static int if_port;
  63. static struct corkscrew_private *vp;
  64. /* Brought directly from 3c515.c by Becker */
  65. #define CORKSCREW 1
  66. /* Maximum events (Rx packets, etc.) to handle at each interrupt.
  67. static int max_interrupt_work = 20;
  68. */
  69. /* Enable the automatic media selection code -- usually set. */
  70. #define AUTOMEDIA 1
  71. /* Allow the use of fragment bus master transfers instead of only
  72. programmed-I/O for Vortex cards. Full-bus-master transfers are always
  73. enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
  74. the feature may be turned on using 'options'. */
  75. #define VORTEX_BUS_MASTER
  76. /* A few values that may be tweaked. */
  77. /* Keep the ring sizes a power of two for efficiency. */
  78. #define TX_RING_SIZE 16
  79. #define RX_RING_SIZE 16
  80. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  81. /* "Knobs" for adjusting internal parameters. */
  82. /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
  83. #define DRIVER_DEBUG 1
  84. /* Some values here only for performance evaluation and path-coverage
  85. debugging.
  86. static int rx_nocopy, rx_copy, queued_packet;
  87. */
  88. #define CORKSCREW_ID 10
  89. #define EL3WINDOW(win_num) \
  90. outw(SelectWindow + (win_num), nic->ioaddr + EL3_CMD)
  91. #define EL3_CMD 0x0e
  92. #define EL3_STATUS 0x0e
  93. #define RX_BYTES_MASK (unsigned short) (0x07ff)
  94. enum corkscrew_cmd {
  95. TotalReset = 0 << 11, SelectWindow = 1 << 11, StartCoax = 2 << 11,
  96. RxDisable = 3 << 11, RxEnable = 4 << 11, RxReset = 5 << 11,
  97. UpStall = 6 << 11, UpUnstall = (6 << 11) + 1,
  98. DownStall = (6 << 11) + 2, DownUnstall = (6 << 11) + 3,
  99. RxDiscard = 8 << 11, TxEnable = 9 << 11, TxDisable =
  100. 10 << 11, TxReset = 11 << 11,
  101. FakeIntr = 12 << 11, AckIntr = 13 << 11, SetIntrEnb = 14 << 11,
  102. SetStatusEnb = 15 << 11, SetRxFilter = 16 << 11, SetRxThreshold =
  103. 17 << 11,
  104. SetTxThreshold = 18 << 11, SetTxStart = 19 << 11,
  105. StartDMAUp = 20 << 11, StartDMADown = (20 << 11) + 1, StatsEnable =
  106. 21 << 11,
  107. StatsDisable = 22 << 11, StopCoax = 23 << 11,
  108. };
  109. /* The SetRxFilter command accepts the following classes: */
  110. enum RxFilter {
  111. RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8
  112. };
  113. /* Bits in the general status register. */
  114. enum corkscrew_status {
  115. IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
  116. TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
  117. IntReq = 0x0040, StatsFull = 0x0080,
  118. DMADone = 1 << 8, DownComplete = 1 << 9, UpComplete = 1 << 10,
  119. DMAInProgress = 1 << 11, /* DMA controller is still busy. */
  120. CmdInProgress = 1 << 12, /* EL3_CMD is still busy. */
  121. };
  122. /* Register window 1 offsets, the window used in normal operation.
  123. On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
  124. enum Window1 {
  125. TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
  126. RxStatus = 0x18, Timer = 0x1A, TxStatus = 0x1B,
  127. TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
  128. };
  129. enum Window0 {
  130. Wn0IRQ = 0x08,
  131. #if defined(CORKSCREW)
  132. Wn0EepromCmd = 0x200A, /* Corkscrew EEPROM command register. */
  133. Wn0EepromData = 0x200C, /* Corkscrew EEPROM results register. */
  134. #else
  135. Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
  136. Wn0EepromData = 12, /* Window 0: EEPROM results register. */
  137. #endif
  138. };
  139. enum Win0_EEPROM_bits {
  140. EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
  141. EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
  142. EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
  143. };
  144. enum Window3 { /* Window 3: MAC/config bits. */
  145. Wn3_Config = 0, Wn3_MAC_Ctrl = 6, Wn3_Options = 8,
  146. };
  147. union wn3_config {
  148. int i;
  149. struct w3_config_fields {
  150. unsigned int ram_size:3, ram_width:1, ram_speed:2,
  151. rom_size:2;
  152. int pad8:8;
  153. unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1,
  154. autoselect:1;
  155. int pad24:7;
  156. } u;
  157. };
  158. enum Window4 {
  159. Wn4_NetDiag = 6, Wn4_Media = 10, /* Window 4: Xcvr/media bits. */
  160. };
  161. enum Win4_Media_bits {
  162. Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
  163. Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
  164. Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
  165. Media_LnkBeat = 0x0800,
  166. };
  167. enum Window7 { /* Window 7: Bus Master control. */
  168. Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
  169. };
  170. /* Boomerang-style bus master control registers. Note ISA aliases! */
  171. enum MasterCtrl {
  172. PktStatus = 0x400, DownListPtr = 0x404, FragAddr = 0x408, FragLen =
  173. 0x40c,
  174. TxFreeThreshold = 0x40f, UpPktStatus = 0x410, UpListPtr = 0x418,
  175. };
  176. /* The Rx and Tx descriptor lists.
  177. Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
  178. alignment contraint on tx_ring[] and rx_ring[]. */
  179. struct boom_rx_desc {
  180. u32 next;
  181. s32 status;
  182. u32 addr;
  183. s32 length;
  184. };
  185. /* Values for the Rx status entry. */
  186. enum rx_desc_status {
  187. RxDComplete = 0x00008000, RxDError = 0x4000,
  188. /* See boomerang_rx() for actual error bits */
  189. };
  190. struct boom_tx_desc {
  191. u32 next;
  192. s32 status;
  193. u32 addr;
  194. s32 length;
  195. };
  196. struct corkscrew_private {
  197. const char *product_name;
  198. struct net_device *next_module;
  199. /* The Rx and Tx rings are here to keep them quad-word-aligned. */
  200. struct boom_rx_desc rx_ring[RX_RING_SIZE];
  201. struct boom_tx_desc tx_ring[TX_RING_SIZE];
  202. /* The addresses of transmit- and receive-in-place skbuffs. */
  203. struct sk_buff *rx_skbuff[RX_RING_SIZE];
  204. struct sk_buff *tx_skbuff[TX_RING_SIZE];
  205. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  206. unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
  207. struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
  208. int capabilities; /* Adapter capabilities word. */
  209. int options; /* User-settable misc. driver options. */
  210. int last_rx_packets; /* For media autoselection. */
  211. unsigned int available_media:8, /* From Wn3_Options */
  212. media_override:3, /* Passed-in media type. */
  213. default_media:3, /* Read from the EEPROM. */
  214. full_duplex:1, autoselect:1, bus_master:1, /* Vortex can only do a fragment bus-m. */
  215. full_bus_master_tx:1, full_bus_master_rx:1, /* Boomerang */
  216. tx_full:1;
  217. };
  218. /* The action to take with a media selection timer tick.
  219. Note that we deviate from the 3Com order by checking 10base2 before AUI.
  220. */
  221. enum xcvr_types {
  222. XCVR_10baseT =
  223. 0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
  224. XCVR_100baseFx, XCVR_MII = 6, XCVR_Default = 8,
  225. };
  226. static struct media_table {
  227. char *name;
  228. unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
  229. mask:8, /* The transceiver-present bit in Wn3_Config. */
  230. next:8; /* The media type to try next. */
  231. short wait; /* Time before we check media status. */
  232. } media_tbl[] = {
  233. {
  234. "10baseT", Media_10TP, 0x08, XCVR_10base2, (14 * HZ) / 10}
  235. , {
  236. "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1 * HZ) / 10}
  237. , {
  238. "undefined", 0, 0x80, XCVR_10baseT, 10000}
  239. , {
  240. "10base2", 0, 0x10, XCVR_AUI, (1 * HZ) / 10}
  241. , {
  242. "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx,
  243. (14 * HZ) / 10}
  244. , {
  245. "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14 * HZ) / 10}
  246. , {
  247. "MII", 0, 0x40, XCVR_10baseT, 3 * HZ}
  248. , {
  249. "undefined", 0, 0x01, XCVR_10baseT, 10000}
  250. , {
  251. "Default", 0, 0xFF, XCVR_10baseT, 10000}
  252. ,};
  253. /* TILEG Modified to remove reference to dev */
  254. static int corkscrew_found_device(int ioaddr, int irq, int product_index,
  255. int options, struct nic *nic);
  256. static int corkscrew_probe1(int ioaddr, int irq, int product_index,
  257. struct nic *nic);
  258. /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
  259. /* Note: this is the only limit on the number of cards supported!! */
  260. static int options = -1;
  261. /* End Brought directly from 3c515.c by Becker */
  262. /**************************************************************************
  263. RESET - Reset adapter
  264. ***************************************************************************/
  265. static void t515_reset(struct nic *nic)
  266. {
  267. union wn3_config config;
  268. int i;
  269. /* Before initializing select the active media port. */
  270. EL3WINDOW(3);
  271. if (vp->full_duplex)
  272. outb(0x20, nic->ioaddr + Wn3_MAC_Ctrl); /* Set the full-duplex bit. */
  273. config.i = inl(nic->ioaddr + Wn3_Config);
  274. if (vp->media_override != 7) {
  275. DBG ( "Media override to transceiver %d (%s).\n",
  276. vp->media_override,
  277. media_tbl[vp->media_override].name);
  278. if_port = vp->media_override;
  279. } else if (vp->autoselect) {
  280. /* Find first available media type, starting with 100baseTx. */
  281. if_port = 4;
  282. while (!(vp->available_media & media_tbl[if_port].mask))
  283. if_port = media_tbl[if_port].next;
  284. DBG ( "Initial media type %s.\n",
  285. media_tbl[if_port].name);
  286. } else
  287. if_port = vp->default_media;
  288. config.u.xcvr = if_port;
  289. outl(config.i, nic->ioaddr + Wn3_Config);
  290. DBG ( "corkscrew_open() InternalConfig 0x%hX.\n",
  291. config.i);
  292. outw(TxReset, nic->ioaddr + EL3_CMD);
  293. for (i = 20; i >= 0; i--)
  294. if (!(inw(nic->ioaddr + EL3_STATUS) & CmdInProgress))
  295. break;
  296. outw(RxReset, nic->ioaddr + EL3_CMD);
  297. /* Wait a few ticks for the RxReset command to complete. */
  298. for (i = 20; i >= 0; i--)
  299. if (!(inw(nic->ioaddr + EL3_STATUS) & CmdInProgress))
  300. break;
  301. outw(SetStatusEnb | 0x00, nic->ioaddr + EL3_CMD);
  302. #ifdef debug_3c515
  303. EL3WINDOW(4);
  304. DBG ( "FIXME: fix print for irq, not 9" );
  305. DBG ( "corkscrew_open() irq %d media status 0x%hX.\n",
  306. 9, inw(nic->ioaddr + Wn4_Media) );
  307. #endif
  308. /* Set the station address and mask in window 2 each time opened. */
  309. EL3WINDOW(2);
  310. for (i = 0; i < 6; i++)
  311. outb(nic->node_addr[i], nic->ioaddr + i);
  312. for (; i < 12; i += 2)
  313. outw(0, nic->ioaddr + i);
  314. if (if_port == 3)
  315. /* Start the thinnet transceiver. We should really wait 50ms... */
  316. outw(StartCoax, nic->ioaddr + EL3_CMD);
  317. EL3WINDOW(4);
  318. outw((inw(nic->ioaddr + Wn4_Media) & ~(Media_10TP | Media_SQE)) |
  319. media_tbl[if_port].media_bits, nic->ioaddr + Wn4_Media);
  320. /* Switch to the stats window, and clear all stats by reading. */
  321. /* outw(StatsDisable, nic->ioaddr + EL3_CMD);*/
  322. EL3WINDOW(6);
  323. for (i = 0; i < 10; i++)
  324. inb(nic->ioaddr + i);
  325. inw(nic->ioaddr + 10);
  326. inw(nic->ioaddr + 12);
  327. /* New: On the Vortex we must also clear the BadSSD counter. */
  328. EL3WINDOW(4);
  329. inb(nic->ioaddr + 12);
  330. /* ..and on the Boomerang we enable the extra statistics bits. */
  331. outw(0x0040, nic->ioaddr + Wn4_NetDiag);
  332. /* Switch to register set 7 for normal use. */
  333. EL3WINDOW(7);
  334. /* Temporarily left in place. If these FIXMEs are printed
  335. it meand that special logic for that card may need to be added
  336. see Becker's 3c515.c driver */
  337. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  338. printf("FIXME: Is this if necessary");
  339. vp->cur_rx = vp->dirty_rx = 0;
  340. DBG ( " Filling in the Rx ring.\n" );
  341. for (i = 0; i < RX_RING_SIZE; i++) {
  342. printf("FIXME: Is this if necessary");
  343. }
  344. }
  345. if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
  346. vp->cur_tx = vp->dirty_tx = 0;
  347. outb(PKT_BUF_SZ >> 8, nic->ioaddr + TxFreeThreshold); /* Room for a packet. */
  348. /* Clear the Tx ring. */
  349. for (i = 0; i < TX_RING_SIZE; i++)
  350. vp->tx_skbuff[i] = NULL;
  351. outl(0, nic->ioaddr + DownListPtr);
  352. }
  353. /* Set receiver mode: presumably accept b-case and phys addr only. */
  354. outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
  355. nic->ioaddr + EL3_CMD);
  356. outw(RxEnable, nic->ioaddr + EL3_CMD); /* Enable the receiver. */
  357. outw(TxEnable, nic->ioaddr + EL3_CMD); /* Enable transmitter. */
  358. /* Allow status bits to be seen. */
  359. outw(SetStatusEnb | AdapterFailure | IntReq | StatsFull |
  360. (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
  361. (vp->full_bus_master_rx ? UpComplete : RxComplete) |
  362. (vp->bus_master ? DMADone : 0), nic->ioaddr + EL3_CMD);
  363. /* Ack all pending events, and set active indicator mask. */
  364. outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  365. nic->ioaddr + EL3_CMD);
  366. outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
  367. | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete,
  368. nic->ioaddr + EL3_CMD);
  369. }
  370. /**************************************************************************
  371. POLL - Wait for a frame
  372. ***************************************************************************/
  373. static int t515_poll(struct nic *nic, int retrieve)
  374. {
  375. short status, cst;
  376. register short rx_fifo;
  377. cst = inw(nic->ioaddr + EL3_STATUS);
  378. if ((cst & RxComplete) == 0) {
  379. /* Ack all pending events, and set active indicator mask. */
  380. outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  381. nic->ioaddr + EL3_CMD);
  382. outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete |
  383. StatsFull | (vp->
  384. bus_master ? DMADone : 0) | UpComplete |
  385. DownComplete, nic->ioaddr + EL3_CMD);
  386. return 0;
  387. }
  388. status = inw(nic->ioaddr + RxStatus);
  389. if (status & RxDError) {
  390. printf("RxDError\n");
  391. outw(RxDiscard, nic->ioaddr + EL3_CMD);
  392. return 0;
  393. }
  394. rx_fifo = status & RX_BYTES_MASK;
  395. if (rx_fifo == 0)
  396. return 0;
  397. if ( ! retrieve ) return 1;
  398. DBG ( "[l=%d", rx_fifo );
  399. insw(nic->ioaddr + RX_FIFO, nic->packet, rx_fifo / 2);
  400. if (rx_fifo & 1)
  401. nic->packet[rx_fifo - 1] = inb(nic->ioaddr + RX_FIFO);
  402. nic->packetlen = rx_fifo;
  403. while (1) {
  404. status = inw(nic->ioaddr + RxStatus);
  405. DBG ( "0x%hX*", status );
  406. rx_fifo = status & RX_BYTES_MASK;
  407. if (rx_fifo > 0) {
  408. insw(nic->ioaddr + RX_FIFO, nic->packet + nic->packetlen,
  409. rx_fifo / 2);
  410. if (rx_fifo & 1)
  411. nic->packet[nic->packetlen + rx_fifo - 1] =
  412. inb(nic->ioaddr + RX_FIFO);
  413. nic->packetlen += rx_fifo;
  414. DBG ( "+%d", rx_fifo );
  415. }
  416. if ((status & RxComplete) == 0) {
  417. DBG ( "=%d", nic->packetlen );
  418. break;
  419. }
  420. udelay(1000);
  421. }
  422. /* acknowledge reception of packet */
  423. outw(RxDiscard, nic->ioaddr + EL3_CMD);
  424. while (inw(nic->ioaddr + EL3_STATUS) & CmdInProgress);
  425. #ifdef debug_3c515
  426. {
  427. unsigned short type = 0;
  428. type = (nic->packet[12] << 8) | nic->packet[13];
  429. if (nic->packet[0] + nic->packet[1] + nic->packet[2] +
  430. nic->packet[3] + nic->packet[4] + nic->packet[5] ==
  431. 0xFF * ETH_ALEN)
  432. DBG ( ",t=0x%hX,b]", type );
  433. else
  434. DBG ( ",t=0x%hX]", type );
  435. }
  436. #endif
  437. return 1;
  438. }
  439. /*************************************************************************
  440. 3Com 515 - specific routines
  441. **************************************************************************/
  442. static char padmap[] = {
  443. 0, 3, 2, 1
  444. };
  445. /**************************************************************************
  446. TRANSMIT - Transmit a frame
  447. ***************************************************************************/
  448. static void t515_transmit(struct nic *nic, const char *d, /* Destination */
  449. unsigned int t, /* Type */
  450. unsigned int s, /* size */
  451. const char *p)
  452. { /* Packet */
  453. register int len;
  454. int pad;
  455. int status;
  456. DBG ( "{l=%d,t=0x%hX}", s + ETH_HLEN, t );
  457. /* swap bytes of type */
  458. t = htons(t);
  459. len = s + ETH_HLEN; /* actual length of packet */
  460. pad = padmap[len & 3];
  461. /*
  462. * The 3c515 automatically pads short packets to minimum ethernet length,
  463. * but we drop packets that are too large. Perhaps we should truncate
  464. * them instead?
  465. Copied from 3c595. Is this true for the 3c515?
  466. */
  467. if (len + pad > ETH_FRAME_LEN) {
  468. return;
  469. }
  470. /* drop acknowledgements */
  471. while ((status = inb(nic->ioaddr + TxStatus)) & TxComplete) {
  472. /*if(status & (TXS_UNDERRUN|0x88|TXS_STATUS_OVERFLOW)) { */
  473. outw(TxReset, nic->ioaddr + EL3_CMD);
  474. outw(TxEnable, nic->ioaddr + EL3_CMD);
  475. /* } */
  476. outb(0x0, nic->ioaddr + TxStatus);
  477. }
  478. while (inw(nic->ioaddr + TxFree) < len + pad + 4) {
  479. /* no room in FIFO */
  480. }
  481. outw(len, nic->ioaddr + TX_FIFO);
  482. outw(0x0, nic->ioaddr + TX_FIFO); /* Second dword meaningless */
  483. /* write packet */
  484. outsw(nic->ioaddr + TX_FIFO, d, ETH_ALEN / 2);
  485. outsw(nic->ioaddr + TX_FIFO, nic->node_addr, ETH_ALEN / 2);
  486. outw(t, nic->ioaddr + TX_FIFO);
  487. outsw(nic->ioaddr + TX_FIFO, p, s / 2);
  488. if (s & 1)
  489. outb(*(p + s - 1), nic->ioaddr + TX_FIFO);
  490. while (pad--)
  491. outb(0, nic->ioaddr + TX_FIFO); /* Padding */
  492. /* wait for Tx complete */
  493. while ((inw(nic->ioaddr + EL3_STATUS) & CmdInProgress) != 0);
  494. }
  495. /**************************************************************************
  496. DISABLE - Turn off ethernet interface
  497. ***************************************************************************/
  498. static void t515_disable ( struct nic *nic,
  499. struct isapnp_device *isapnp ) {
  500. t515_reset(nic);
  501. /* This is a hack. Since ltsp worked on my
  502. system without any disable functionality I
  503. have no way to determine if this works */
  504. /* Disable the receiver and transmitter. */
  505. outw(RxDisable, nic->ioaddr + EL3_CMD);
  506. outw(TxDisable, nic->ioaddr + EL3_CMD);
  507. if (if_port == XCVR_10base2)
  508. /* Turn off thinnet power. Green! */
  509. outw(StopCoax, nic->ioaddr + EL3_CMD);
  510. outw(SetIntrEnb | 0x0000, nic->ioaddr + EL3_CMD);
  511. deactivate_isapnp_device ( isapnp );
  512. return;
  513. }
  514. static void t515_irq(struct nic *nic __unused, irq_action_t action __unused)
  515. {
  516. switch ( action ) {
  517. case DISABLE :
  518. break;
  519. case ENABLE :
  520. break;
  521. case FORCE :
  522. break;
  523. }
  524. }
  525. static struct nic_operations t515_operations = {
  526. .connect = dummy_connect,
  527. .poll = t515_poll,
  528. .transmit = t515_transmit,
  529. .irq = t515_irq,
  530. };
  531. /**************************************************************************
  532. PROBE - Look for an adapter, this routine's visible to the outside
  533. You should omit the last argument struct pci_device * for a non-PCI NIC
  534. ***************************************************************************/
  535. static int t515_probe ( struct nic *nic, struct isapnp_device *isapnp ) {
  536. /* Direct copy from Beckers 3c515.c removing any ISAPNP sections */
  537. nic->ioaddr = isapnp->ioaddr;
  538. nic->irqno = isapnp->irqno;
  539. activate_isapnp_device ( isapnp );
  540. /* Check the resource configuration for a matching ioaddr. */
  541. if ((unsigned)(inw(nic->ioaddr + 0x2002) & 0x1f0)
  542. != (nic->ioaddr & 0x1f0)) {
  543. DBG ( "3c515 ioaddr mismatch\n" );
  544. return 0;
  545. }
  546. /* Verify by reading the device ID from the EEPROM. */
  547. {
  548. int timer;
  549. outw(EEPROM_Read + 7, nic->ioaddr + Wn0EepromCmd);
  550. /* Pause for at least 162 us. for the read to take place. */
  551. for (timer = 4; timer >= 0; timer--) {
  552. t3c515_wait(1);
  553. if ((inw(nic->ioaddr + Wn0EepromCmd) & 0x0200) == 0)
  554. break;
  555. }
  556. if (inw(nic->ioaddr + Wn0EepromData) != 0x6d50) {
  557. DBG ( "3c515 read incorrect vendor ID from EEPROM" );
  558. return 0;
  559. }
  560. }
  561. DBG ( "3c515 Resource configuration register 0x%X, DCR 0x%hX.\n",
  562. inl(nic->ioaddr + 0x2002), inw(nic->ioaddr + 0x2000) );
  563. corkscrew_found_device(nic->ioaddr, nic->irqno, CORKSCREW_ID,
  564. options, nic);
  565. t515_reset(nic);
  566. nic->nic_op = &t515_operations;
  567. return 1;
  568. }
  569. static int
  570. corkscrew_found_device(int ioaddr, int irq,
  571. int product_index, int options, struct nic *nic)
  572. {
  573. /* Direct copy from Becker 3c515.c with unnecessary parts removed */
  574. vp->product_name = "3c515";
  575. vp->options = options;
  576. if (options >= 0) {
  577. vp->media_override =
  578. ((options & 7) == 2) ? 0 : options & 7;
  579. vp->full_duplex = (options & 8) ? 1 : 0;
  580. vp->bus_master = (options & 16) ? 1 : 0;
  581. } else {
  582. vp->media_override = 7;
  583. vp->full_duplex = 0;
  584. vp->bus_master = 0;
  585. }
  586. corkscrew_probe1(ioaddr, irq, product_index, nic);
  587. return 0;
  588. }
  589. static int
  590. corkscrew_probe1(int ioaddr, int irq, int product_index __unused,
  591. struct nic *nic)
  592. {
  593. unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
  594. int i;
  595. printf("3Com %s at 0x%hX, ", vp->product_name, ioaddr);
  596. /* Read the station address from the EEPROM. */
  597. EL3WINDOW(0);
  598. for (i = 0; i < 0x18; i++) {
  599. short *phys_addr = (short *) nic->node_addr;
  600. int timer;
  601. outw(EEPROM_Read + i, ioaddr + Wn0EepromCmd);
  602. /* Pause for at least 162 us. for the read to take place. */
  603. for (timer = 4; timer >= 0; timer--) {
  604. t3c515_wait(1);
  605. if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
  606. break;
  607. }
  608. eeprom[i] = inw(ioaddr + Wn0EepromData);
  609. DBG ( "Value %d: %hX ", i, eeprom[i] );
  610. checksum ^= eeprom[i];
  611. if (i < 3)
  612. phys_addr[i] = htons(eeprom[i]);
  613. }
  614. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  615. if (checksum != 0x00)
  616. printf(" ***INVALID CHECKSUM 0x%hX*** ", checksum);
  617. DBG ( "%s", eth_ntoa ( nic->node_addr ) );
  618. if (eeprom[16] == 0x11c7) { /* Corkscrew */
  619. }
  620. printf(", IRQ %d\n", irq);
  621. /* Tell them about an invalid IRQ. */
  622. if ( (irq <= 0 || irq > 15) ) {
  623. DBG (" *** Warning: this IRQ is unlikely to work! ***\n" );
  624. }
  625. {
  626. char *ram_split[] = { "5:3", "3:1", "1:1", "3:5" };
  627. union wn3_config config;
  628. EL3WINDOW(3);
  629. vp->available_media = inw(ioaddr + Wn3_Options);
  630. config.i = inl(ioaddr + Wn3_Config);
  631. DBG ( " Internal config register is %4.4x, "
  632. "transceivers 0x%hX.\n",
  633. config.i, inw(ioaddr + Wn3_Options) );
  634. printf
  635. (" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
  636. 8 << config.u.ram_size,
  637. config.u.ram_width ? "word" : "byte",
  638. ram_split[config.u.ram_split],
  639. config.u.autoselect ? "autoselect/" : "",
  640. media_tbl[config.u.xcvr].name);
  641. if_port = config.u.xcvr;
  642. vp->default_media = config.u.xcvr;
  643. vp->autoselect = config.u.autoselect;
  644. }
  645. if (vp->media_override != 7) {
  646. printf(" Media override to transceiver type %d (%s).\n",
  647. vp->media_override,
  648. media_tbl[vp->media_override].name);
  649. if_port = vp->media_override;
  650. }
  651. vp->capabilities = eeprom[16];
  652. vp->full_bus_master_tx = (vp->capabilities & 0x20) ? 1 : 0;
  653. /* Rx is broken at 10mbps, so we always disable it. */
  654. /* vp->full_bus_master_rx = 0; */
  655. vp->full_bus_master_rx = (vp->capabilities & 0x20) ? 1 : 0;
  656. return 0;
  657. }
  658. static struct isapnp_device_id t515_adapters[] = {
  659. { "3c515 (ISAPnP)", ISAPNP_VENDOR('T','C','M'), 0x5051 },
  660. };
  661. ISAPNP_DRIVER ( t515_driver, t515_adapters );
  662. DRIVER ( "3c515", nic_driver, isapnp_driver, t515_driver,
  663. t515_probe, t515_disable );
  664. ISA_ROM ( "3c515", "3c515 Fast EtherLink ISAPnP" );