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.

natsemi.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /* -*- Mode:C; c-basic-offset:4; -*- */
  2. /*
  3. natsemi.c: An Etherboot driver for the NatSemi DP8381x series.
  4. Copyright (C) 2001 Entity Cyber, Inc.
  5. This development of this Etherboot driver was funded by
  6. Sicom Systems: http://www.sicompos.com/
  7. Author: Marty Connor (mdc@thinguin.org)
  8. Adapted from a Linux driver which was written by Donald Becker
  9. This software may be used and distributed according to the terms
  10. of the GNU Public License (GPL), incorporated herein by reference.
  11. Original Copyright Notice:
  12. Written/copyright 1999-2001 by Donald Becker.
  13. This software may be used and distributed according to the terms of
  14. the GNU General Public License (GPL), incorporated herein by reference.
  15. Drivers based on or derived from this code fall under the GPL and must
  16. retain the authorship, copyright and license notice. This file is not
  17. a complete program and may only be used when the entire operating
  18. system is licensed under the GPL. License for under other terms may be
  19. available. Contact the original author for details.
  20. The original author may be reached as becker@scyld.com, or at
  21. Scyld Computing Corporation
  22. 410 Severn Ave., Suite 210
  23. Annapolis MD 21403
  24. Support information and updates available at
  25. http://www.scyld.com/network/netsemi.html
  26. References:
  27. http://www.scyld.com/expert/100mbps.html
  28. http://www.scyld.com/expert/NWay.html
  29. Datasheet is available from:
  30. http://www.national.com/pf/DP/DP83815.html
  31. */
  32. /* Revision History */
  33. /*
  34. 13 Dec 2003 timlegge 1.1 Enabled Multicast Support
  35. 29 May 2001 mdc 1.0
  36. Initial Release. Tested with Netgear FA311 and FA312 boards
  37. */
  38. /* Includes */
  39. #include "etherboot.h"
  40. #include "nic.h"
  41. #include "pci.h"
  42. /* defines */
  43. #define OWN 0x80000000
  44. #define DSIZE 0x00000FFF
  45. #define CRC_SIZE 4
  46. /* Time in ticks before concluding the transmitter is hung. */
  47. #define TX_TIMEOUT (4*TICKS_PER_SEC)
  48. #define TX_BUF_SIZE 1536
  49. #define RX_BUF_SIZE 1536
  50. #define NUM_RX_DESC 4 /* Number of Rx descriptor registers. */
  51. typedef uint8_t u8;
  52. typedef int8_t s8;
  53. typedef uint16_t u16;
  54. typedef int16_t s16;
  55. typedef uint32_t u32;
  56. typedef int32_t s32;
  57. /* helpful macroes if on a big_endian machine for changing byte order.
  58. not strictly needed on Intel */
  59. #define get_unaligned(ptr) (*(ptr))
  60. #define put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
  61. #define get_u16(ptr) (*(u16 *)(ptr))
  62. #define virt_to_le32desc(addr) virt_to_bus(addr)
  63. enum pcistuff {
  64. PCI_USES_IO = 0x01,
  65. PCI_USES_MEM = 0x02,
  66. PCI_USES_MASTER = 0x04,
  67. PCI_ADDR0 = 0x08,
  68. PCI_ADDR1 = 0x10,
  69. };
  70. /* MMIO operations required */
  71. #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR1)
  72. /* Offsets to the device registers.
  73. Unlike software-only systems, device drivers interact with complex hardware.
  74. It's not useful to define symbolic names for every register bit in the
  75. device.
  76. */
  77. enum register_offsets {
  78. ChipCmd = 0x00,
  79. ChipConfig = 0x04,
  80. EECtrl = 0x08,
  81. PCIBusCfg = 0x0C,
  82. IntrStatus = 0x10,
  83. IntrMask = 0x14,
  84. IntrEnable = 0x18,
  85. TxRingPtr = 0x20,
  86. TxConfig = 0x24,
  87. RxRingPtr = 0x30,
  88. RxConfig = 0x34,
  89. ClkRun = 0x3C,
  90. WOLCmd = 0x40,
  91. PauseCmd = 0x44,
  92. RxFilterAddr = 0x48,
  93. RxFilterData = 0x4C,
  94. BootRomAddr = 0x50,
  95. BootRomData = 0x54,
  96. SiliconRev = 0x58,
  97. StatsCtrl = 0x5C,
  98. StatsData = 0x60,
  99. RxPktErrs = 0x60,
  100. RxMissed = 0x68,
  101. RxCRCErrs = 0x64,
  102. PCIPM = 0x44,
  103. PhyStatus = 0xC0,
  104. MIntrCtrl = 0xC4,
  105. MIntrStatus = 0xC8,
  106. /* These are from the spec, around page 78... on a separate table. */
  107. PGSEL = 0xCC,
  108. PMDCSR = 0xE4,
  109. TSTDAT = 0xFC,
  110. DSPCFG = 0xF4,
  111. SDCFG = 0x8C
  112. };
  113. /* Bit in ChipCmd. */
  114. enum ChipCmdBits {
  115. ChipReset = 0x100,
  116. RxReset = 0x20,
  117. TxReset = 0x10,
  118. RxOff = 0x08,
  119. RxOn = 0x04,
  120. TxOff = 0x02,
  121. TxOn = 0x01
  122. };
  123. /* Bits in the RxMode register. */
  124. enum rx_mode_bits {
  125. AcceptErr = 0x20,
  126. AcceptRunt = 0x10,
  127. AcceptBroadcast = 0xC0000000,
  128. AcceptMulticast = 0x00200000,
  129. AcceptAllMulticast = 0x20000000,
  130. AcceptAllPhys = 0x10000000,
  131. AcceptMyPhys = 0x08000000,
  132. RxFilterEnable = 0x80000000
  133. };
  134. typedef struct _BufferDesc {
  135. u32 link;
  136. volatile u32 cmdsts;
  137. u32 bufptr;
  138. u32 software_use;
  139. } BufferDesc;
  140. /* Bits in network_desc.status */
  141. enum desc_status_bits {
  142. DescOwn = 0x80000000,
  143. DescMore = 0x40000000,
  144. DescIntr = 0x20000000,
  145. DescNoCRC = 0x10000000,
  146. DescPktOK = 0x08000000,
  147. RxTooLong = 0x00400000
  148. };
  149. /* Globals */
  150. static struct nic_operations natsemi_operations;
  151. static struct pci_driver natsemi_driver;
  152. static int natsemi_debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
  153. const char *nic_name;
  154. static u32 SavedClkRun;
  155. static unsigned short vendor, dev_id;
  156. static unsigned long ioaddr;
  157. static unsigned int cur_rx;
  158. static unsigned int advertising;
  159. static unsigned int rx_config;
  160. static unsigned int tx_config;
  161. /* Note: transmit and receive buffers and descriptors must be
  162. longword aligned
  163. */
  164. static BufferDesc txd __attribute__ ((aligned(4)));
  165. static BufferDesc rxd[NUM_RX_DESC] __attribute__ ((aligned(4)));
  166. static unsigned char txb[TX_BUF_SIZE] __attribute__ ((aligned(4)));
  167. static unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE] __attribute__ ((aligned(4)));
  168. /* Function Prototypes */
  169. static int natsemi_probe(struct dev *dev);
  170. static int eeprom_read(long addr, int location);
  171. static int mdio_read(int phy_id, int location);
  172. static void natsemi_init(struct nic *nic);
  173. static void natsemi_reset(struct nic *nic);
  174. static void natsemi_init_rxfilter(struct nic *nic);
  175. static void natsemi_init_txd(struct nic *nic);
  176. static void natsemi_init_rxd(struct nic *nic);
  177. static void natsemi_set_rx_mode(struct nic *nic);
  178. static void natsemi_check_duplex(struct nic *nic);
  179. static void natsemi_transmit(struct nic *nic, const char *d, unsigned int t, unsigned int s, const char *p);
  180. static int natsemi_poll(struct nic *nic, int retrieve);
  181. static void natsemi_disable(struct nic *nic);
  182. static void natsemi_irq(struct nic *nic, irq_action_t action);
  183. /*
  184. * Function: natsemi_probe
  185. *
  186. * Description: Retrieves the MAC address of the card, and sets up some
  187. * globals required by other routines, and initializes the NIC, making it
  188. * ready to send and receive packets.
  189. *
  190. * Side effects:
  191. * leaves the ioaddress of the natsemi chip in the variable ioaddr.
  192. * leaves the natsemi initialized, and ready to recieve packets.
  193. *
  194. * Returns: struct nic *: pointer to NIC data structure
  195. */
  196. static int
  197. natsemi_probe ( struct dev *dev, struct pci_device *pci ) {
  198. struct nic *nic = nic_device ( dev );
  199. int i;
  200. int prev_eedata;
  201. u32 tmp;
  202. if ( ! find_pci_device ( pci, &natsemi_driver ) )
  203. return 0;
  204. if (pci->ioaddr == 0)
  205. return 0;
  206. /* initialize some commonly used globals */
  207. nic->irqno = 0;
  208. nic->ioaddr = pci->ioaddr;
  209. ioaddr = pci->ioaddr;
  210. vendor = pci->vendor;
  211. dev_id = pci->dev_id;
  212. nic_name = dev->name;
  213. /* natsemi has a non-standard PM control register
  214. * in PCI config space. Some boards apparently need
  215. * to be brought to D0 in this manner.
  216. */
  217. pci_read_config_dword(pci, PCIPM, &tmp);
  218. if (tmp & (0x03|0x100)) {
  219. /* D0 state, disable PME assertion */
  220. u32 newtmp = tmp & ~(0x03|0x100);
  221. pci_write_config_dword(pci, PCIPM, newtmp);
  222. }
  223. /* get MAC address */
  224. prev_eedata = eeprom_read(ioaddr, 6);
  225. for (i = 0; i < 3; i++) {
  226. int eedata = eeprom_read(ioaddr, i + 7);
  227. nic->node_addr[i*2] = (eedata << 1) + (prev_eedata >> 15);
  228. nic->node_addr[i*2+1] = eedata >> 7;
  229. prev_eedata = eedata;
  230. }
  231. printf("\nnatsemi_probe: MAC addr %! at ioaddr %#hX\n",
  232. nic->node_addr, ioaddr);
  233. printf("natsemi_probe: Vendor:%#hX Device:%#hX\n", vendor, dev_id);
  234. /* Reset the chip to erase any previous misconfiguration. */
  235. outl(ChipReset, ioaddr + ChipCmd);
  236. advertising = mdio_read(1, 4);
  237. {
  238. u32 chip_config = inl(ioaddr + ChipConfig);
  239. printf("%s: Transceiver default autoneg. %s "
  240. "10%s %s duplex.\n",
  241. nic_name,
  242. chip_config & 0x2000 ? "enabled, advertise" : "disabled, force",
  243. chip_config & 0x4000 ? "0" : "",
  244. chip_config & 0x8000 ? "full" : "half");
  245. }
  246. printf("%s: Transceiver status %hX advertising %hX\n",
  247. nic_name, (int)inl(ioaddr + 0x84), advertising);
  248. /* Disable PME:
  249. * The PME bit is initialized from the EEPROM contents.
  250. * PCI cards probably have PME disabled, but motherboard
  251. * implementations may have PME set to enable WakeOnLan.
  252. * With PME set the chip will scan incoming packets but
  253. * nothing will be written to memory. */
  254. SavedClkRun = inl(ioaddr + ClkRun);
  255. outl(SavedClkRun & ~0x100, ioaddr + ClkRun);
  256. /* initialize device */
  257. natsemi_init(nic);
  258. nic->nic_op = &natsemi_operations;
  259. return 1;
  260. }
  261. /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.
  262. The EEPROM code is for the common 93c06/46 EEPROMs with 6 bit addresses.
  263. */
  264. /* Delay between EEPROM clock transitions.
  265. No extra delay is needed with 33Mhz PCI, but future 66Mhz access may need
  266. a delay. */
  267. #define eeprom_delay(ee_addr) inl(ee_addr)
  268. enum EEPROM_Ctrl_Bits {
  269. EE_ShiftClk = 0x04,
  270. EE_DataIn = 0x01,
  271. EE_ChipSelect = 0x08,
  272. EE_DataOut = 0x02
  273. };
  274. #define EE_Write0 (EE_ChipSelect)
  275. #define EE_Write1 (EE_ChipSelect | EE_DataIn)
  276. /* The EEPROM commands include the alway-set leading bit. */
  277. enum EEPROM_Cmds {
  278. EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
  279. };
  280. static int eeprom_read(long addr, int location)
  281. {
  282. int i;
  283. int retval = 0;
  284. int ee_addr = addr + EECtrl;
  285. int read_cmd = location | EE_ReadCmd;
  286. outl(EE_Write0, ee_addr);
  287. /* Shift the read command bits out. */
  288. for (i = 10; i >= 0; i--) {
  289. short dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
  290. outl(dataval, ee_addr);
  291. eeprom_delay(ee_addr);
  292. outl(dataval | EE_ShiftClk, ee_addr);
  293. eeprom_delay(ee_addr);
  294. }
  295. outl(EE_ChipSelect, ee_addr);
  296. eeprom_delay(ee_addr);
  297. for (i = 0; i < 16; i++) {
  298. outl(EE_ChipSelect | EE_ShiftClk, ee_addr);
  299. eeprom_delay(ee_addr);
  300. retval |= (inl(ee_addr) & EE_DataOut) ? 1 << i : 0;
  301. outl(EE_ChipSelect, ee_addr);
  302. eeprom_delay(ee_addr);
  303. }
  304. /* Terminate the EEPROM access. */
  305. outl(EE_Write0, ee_addr);
  306. outl(0, ee_addr);
  307. return retval;
  308. }
  309. /* MII transceiver control section.
  310. The 83815 series has an internal transceiver, and we present the
  311. management registers as if they were MII connected. */
  312. static int mdio_read(int phy_id, int location)
  313. {
  314. if (phy_id == 1 && location < 32)
  315. return inl(ioaddr + 0x80 + (location<<2)) & 0xffff;
  316. else
  317. return 0xffff;
  318. }
  319. /* Function: natsemi_init
  320. *
  321. * Description: resets the ethernet controller chip and configures
  322. * registers and data structures required for sending and receiving packets.
  323. *
  324. * Arguments: struct nic *nic: NIC data structure
  325. *
  326. * returns: void.
  327. */
  328. static void
  329. natsemi_init(struct nic *nic)
  330. {
  331. natsemi_reset(nic);
  332. /* Disable PME:
  333. * The PME bit is initialized from the EEPROM contents.
  334. * PCI cards probably have PME disabled, but motherboard
  335. * implementations may have PME set to enable WakeOnLan.
  336. * With PME set the chip will scan incoming packets but
  337. * nothing will be written to memory. */
  338. outl(SavedClkRun & ~0x100, ioaddr + ClkRun);
  339. natsemi_init_rxfilter(nic);
  340. natsemi_init_txd(nic);
  341. natsemi_init_rxd(nic);
  342. /* Initialize other registers. */
  343. /* Configure the PCI bus bursts and FIFO thresholds. */
  344. /* Configure for standard, in-spec Ethernet. */
  345. if (inl(ioaddr + ChipConfig) & 0x20000000) { /* Full duplex */
  346. tx_config = 0xD0801002;
  347. rx_config = 0x10000020;
  348. } else {
  349. tx_config = 0x10801002;
  350. rx_config = 0x0020;
  351. }
  352. outl(tx_config, ioaddr + TxConfig);
  353. outl(rx_config, ioaddr + RxConfig);
  354. natsemi_check_duplex(nic);
  355. natsemi_set_rx_mode(nic);
  356. outl(RxOn, ioaddr + ChipCmd);
  357. }
  358. /*
  359. * Function: natsemi_reset
  360. *
  361. * Description: soft resets the controller chip
  362. *
  363. * Arguments: struct nic *nic: NIC data structure
  364. *
  365. * Returns: void.
  366. */
  367. static void
  368. natsemi_reset(struct nic *nic __unused)
  369. {
  370. outl(ChipReset, ioaddr + ChipCmd);
  371. /* On page 78 of the spec, they recommend some settings for "optimum
  372. performance" to be done in sequence. These settings optimize some
  373. of the 100Mbit autodetection circuitry. Also, we only want to do
  374. this for rev C of the chip.
  375. */
  376. if (inl(ioaddr + SiliconRev) == 0x302) {
  377. outw(0x0001, ioaddr + PGSEL);
  378. outw(0x189C, ioaddr + PMDCSR);
  379. outw(0x0000, ioaddr + TSTDAT);
  380. outw(0x5040, ioaddr + DSPCFG);
  381. outw(0x008C, ioaddr + SDCFG);
  382. }
  383. /* Disable interrupts using the mask. */
  384. outl(0, ioaddr + IntrMask);
  385. outl(0, ioaddr + IntrEnable);
  386. }
  387. /* Function: natsemi_init_rxfilter
  388. *
  389. * Description: sets receive filter address to our MAC address
  390. *
  391. * Arguments: struct nic *nic: NIC data structure
  392. *
  393. * returns: void.
  394. */
  395. static void
  396. natsemi_init_rxfilter(struct nic *nic)
  397. {
  398. int i;
  399. for (i = 0; i < ETH_ALEN; i += 2) {
  400. outl(i, ioaddr + RxFilterAddr);
  401. outw(nic->node_addr[i] + (nic->node_addr[i+1] << 8), ioaddr + RxFilterData);
  402. }
  403. }
  404. /*
  405. * Function: natsemi_init_txd
  406. *
  407. * Description: initializes the Tx descriptor
  408. *
  409. * Arguments: struct nic *nic: NIC data structure
  410. *
  411. * returns: void.
  412. */
  413. static void
  414. natsemi_init_txd(struct nic *nic __unused)
  415. {
  416. txd.link = (u32) 0;
  417. txd.cmdsts = (u32) 0;
  418. txd.bufptr = virt_to_bus(&txb[0]);
  419. /* load Transmit Descriptor Register */
  420. outl(virt_to_bus(&txd), ioaddr + TxRingPtr);
  421. if (natsemi_debug > 1)
  422. printf("natsemi_init_txd: TX descriptor register loaded with: %X\n",
  423. inl(ioaddr + TxRingPtr));
  424. }
  425. /* Function: natsemi_init_rxd
  426. *
  427. * Description: initializes the Rx descriptor ring
  428. *
  429. * Arguments: struct nic *nic: NIC data structure
  430. *
  431. * Returns: void.
  432. */
  433. static void
  434. natsemi_init_rxd(struct nic *nic __unused)
  435. {
  436. int i;
  437. cur_rx = 0;
  438. /* init RX descriptor */
  439. for (i = 0; i < NUM_RX_DESC; i++) {
  440. rxd[i].link = virt_to_bus((i+1 < NUM_RX_DESC) ? &rxd[i+1] : &rxd[0]);
  441. rxd[i].cmdsts = (u32) RX_BUF_SIZE;
  442. rxd[i].bufptr = virt_to_bus(&rxb[i*RX_BUF_SIZE]);
  443. if (natsemi_debug > 1)
  444. printf("natsemi_init_rxd: rxd[%d]=%X link=%X cmdsts=%X bufptr=%X\n",
  445. i, &rxd[i], rxd[i].link, rxd[i].cmdsts, rxd[i].bufptr);
  446. }
  447. /* load Receive Descriptor Register */
  448. outl(virt_to_bus(&rxd[0]), ioaddr + RxRingPtr);
  449. if (natsemi_debug > 1)
  450. printf("natsemi_init_rxd: RX descriptor register loaded with: %X\n",
  451. inl(ioaddr + RxRingPtr));
  452. }
  453. /* Function: natsemi_set_rx_mode
  454. *
  455. * Description:
  456. * sets the receive mode to accept all broadcast packets and packets
  457. * with our MAC address, and reject all multicast packets.
  458. *
  459. * Arguments: struct nic *nic: NIC data structure
  460. *
  461. * Returns: void.
  462. */
  463. static void natsemi_set_rx_mode(struct nic *nic __unused)
  464. {
  465. u32 rx_mode = RxFilterEnable | AcceptBroadcast |
  466. AcceptAllMulticast | AcceptMyPhys;
  467. outl(rx_mode, ioaddr + RxFilterAddr);
  468. }
  469. static void natsemi_check_duplex(struct nic *nic __unused)
  470. {
  471. int duplex = inl(ioaddr + ChipConfig) & 0x20000000 ? 1 : 0;
  472. if (natsemi_debug)
  473. printf("%s: Setting %s-duplex based on negotiated link"
  474. " capability.\n", nic_name,
  475. duplex ? "full" : "half");
  476. if (duplex) {
  477. rx_config |= 0x10000000;
  478. tx_config |= 0xC0000000;
  479. } else {
  480. rx_config &= ~0x10000000;
  481. tx_config &= ~0xC0000000;
  482. }
  483. outl(tx_config, ioaddr + TxConfig);
  484. outl(rx_config, ioaddr + RxConfig);
  485. }
  486. /* Function: natsemi_transmit
  487. *
  488. * Description: transmits a packet and waits for completion or timeout.
  489. *
  490. * Arguments: char d[6]: destination ethernet address.
  491. * unsigned short t: ethernet protocol type.
  492. * unsigned short s: size of the data-part of the packet.
  493. * char *p: the data for the packet.
  494. *
  495. * Returns: void.
  496. */
  497. static void
  498. natsemi_transmit(struct nic *nic,
  499. const char *d, /* Destination */
  500. unsigned int t, /* Type */
  501. unsigned int s, /* size */
  502. const char *p) /* Packet */
  503. {
  504. u32 to, nstype;
  505. u32 tx_status;
  506. /* Stop the transmitter */
  507. outl(TxOff, ioaddr + ChipCmd);
  508. /* load Transmit Descriptor Register */
  509. outl(virt_to_bus(&txd), ioaddr + TxRingPtr);
  510. if (natsemi_debug > 1)
  511. printf("natsemi_transmit: TX descriptor register loaded with: %X\n",
  512. inl(ioaddr + TxRingPtr));
  513. memcpy(txb, d, ETH_ALEN);
  514. memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
  515. nstype = htons(t);
  516. memcpy(txb + 2 * ETH_ALEN, (char*)&nstype, 2);
  517. memcpy(txb + ETH_HLEN, p, s);
  518. s += ETH_HLEN;
  519. s &= DSIZE;
  520. if (natsemi_debug > 1)
  521. printf("natsemi_transmit: sending %d bytes ethtype %hX\n", (int) s, t);
  522. /* pad to minimum packet size */
  523. while (s < ETH_ZLEN)
  524. txb[s++] = '\0';
  525. /* set the transmit buffer descriptor and enable Transmit State Machine */
  526. txd.bufptr = virt_to_bus(&txb[0]);
  527. txd.cmdsts = (u32) OWN | s;
  528. /* restart the transmitter */
  529. outl(TxOn, ioaddr + ChipCmd);
  530. if (natsemi_debug > 1)
  531. printf("natsemi_transmit: Queued Tx packet size %d.\n", (int) s);
  532. to = currticks() + TX_TIMEOUT;
  533. while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < to))
  534. /* wait */ ;
  535. if (currticks() >= to) {
  536. printf("natsemi_transmit: TX Timeout! Tx status %X.\n", tx_status);
  537. }
  538. if (!(tx_status & 0x08000000)) {
  539. printf("natsemi_transmit: Transmit error, Tx status %X.\n", tx_status);
  540. }
  541. }
  542. /* Function: natsemi_poll
  543. *
  544. * Description: checks for a received packet and returns it if found.
  545. *
  546. * Arguments: struct nic *nic: NIC data structure
  547. *
  548. * Returns: 1 if packet was received.
  549. * 0 if no packet was received.
  550. *
  551. * Side effects:
  552. * Returns (copies) the packet to the array nic->packet.
  553. * Returns the length of the packet in nic->packetlen.
  554. */
  555. static int
  556. natsemi_poll(struct nic *nic, int retrieve)
  557. {
  558. u32 rx_status = rxd[cur_rx].cmdsts;
  559. int retstat = 0;
  560. if (natsemi_debug > 2)
  561. printf("natsemi_poll: cur_rx:%d, status:%X\n", cur_rx, rx_status);
  562. if (!(rx_status & OWN))
  563. return retstat;
  564. if ( ! retrieve ) return 1;
  565. if (natsemi_debug > 1)
  566. printf("natsemi_poll: got a packet: cur_rx:%d, status:%X\n",
  567. cur_rx, rx_status);
  568. nic->packetlen = (rx_status & DSIZE) - CRC_SIZE;
  569. if ((rx_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK) {
  570. /* corrupted packet received */
  571. printf("natsemi_poll: Corrupted packet received, buffer status = %X\n",
  572. rx_status);
  573. retstat = 0;
  574. } else {
  575. /* give packet to higher level routine */
  576. memcpy(nic->packet, (rxb + cur_rx*RX_BUF_SIZE), nic->packetlen);
  577. retstat = 1;
  578. }
  579. /* return the descriptor and buffer to receive ring */
  580. rxd[cur_rx].cmdsts = RX_BUF_SIZE;
  581. rxd[cur_rx].bufptr = virt_to_bus(&rxb[cur_rx*RX_BUF_SIZE]);
  582. if (++cur_rx == NUM_RX_DESC)
  583. cur_rx = 0;
  584. /* re-enable the potentially idle receive state machine */
  585. outl(RxOn, ioaddr + ChipCmd);
  586. return retstat;
  587. }
  588. /* Function: natsemi_disable
  589. *
  590. * Description: Turns off interrupts and stops Tx and Rx engines
  591. *
  592. * Arguments: struct nic *nic: NIC data structure
  593. *
  594. * Returns: void.
  595. */
  596. static void
  597. natsemi_disable ( struct nic *nic ) {
  598. /* merge reset and disable */
  599. natsemi_init(nic);
  600. /* Disable interrupts using the mask. */
  601. outl(0, ioaddr + IntrMask);
  602. outl(0, ioaddr + IntrEnable);
  603. /* Stop the chip's Tx and Rx processes. */
  604. outl(RxOff | TxOff, ioaddr + ChipCmd);
  605. /* Restore PME enable bit */
  606. outl(SavedClkRun, ioaddr + ClkRun);
  607. }
  608. /* Function: natsemi_irq
  609. *
  610. * Description: Enable, Disable, or Force interrupts
  611. *
  612. * Arguments: struct nic *nic: NIC data structure
  613. * irq_action_t action: requested action to perform
  614. *
  615. * Returns: void.
  616. */
  617. static void
  618. natsemi_irq(struct nic *nic __unused, irq_action_t action __unused)
  619. {
  620. switch ( action ) {
  621. case DISABLE :
  622. break;
  623. case ENABLE :
  624. break;
  625. case FORCE :
  626. break;
  627. }
  628. }
  629. static struct nic_operations natsemi_operations = {
  630. .connect = dummy_connect,
  631. .poll = natsemi_poll,
  632. .transmit = natsemi_transmit,
  633. .irq = natsemi_irq,
  634. .disable = natsemi_disable,
  635. };
  636. static struct pci_id natsemi_nics[] = {
  637. PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
  638. };
  639. static struct pci_driver natsemi_driver =
  640. PCI_DRIVER ( "NATSEMI", natsemi_nics, PCI_NO_CLASS );
  641. BOOT_DRIVER ( "NATSEMI", natsemi_probe );