Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

natsemi.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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 int natsemi_debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */
  151. const char *nic_name;
  152. static u32 SavedClkRun;
  153. static unsigned short vendor, dev_id;
  154. static unsigned long ioaddr;
  155. static unsigned int cur_rx;
  156. static unsigned int advertising;
  157. static unsigned int rx_config;
  158. static unsigned int tx_config;
  159. /* Note: transmit and receive buffers and descriptors must be
  160. longword aligned
  161. */
  162. static BufferDesc txd __attribute__ ((aligned(4)));
  163. static BufferDesc rxd[NUM_RX_DESC] __attribute__ ((aligned(4)));
  164. static unsigned char txb[TX_BUF_SIZE] __attribute__ ((aligned(4)));
  165. static unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE] __attribute__ ((aligned(4)));
  166. /* Function Prototypes */
  167. static int natsemi_probe(struct dev *dev, struct pci_device *pci);
  168. static int eeprom_read(long addr, int location);
  169. static int mdio_read(int phy_id, int location);
  170. static void natsemi_init(struct nic *nic);
  171. static void natsemi_reset(struct nic *nic);
  172. static void natsemi_init_rxfilter(struct nic *nic);
  173. static void natsemi_init_txd(struct nic *nic);
  174. static void natsemi_init_rxd(struct nic *nic);
  175. static void natsemi_set_rx_mode(struct nic *nic);
  176. static void natsemi_check_duplex(struct nic *nic);
  177. static void natsemi_transmit(struct nic *nic, const char *d, unsigned int t, unsigned int s, const char *p);
  178. static int natsemi_poll(struct nic *nic, int retrieve);
  179. static void natsemi_disable(struct dev *dev);
  180. static void natsemi_irq(struct nic *nic, irq_action_t action);
  181. /*
  182. * Function: natsemi_probe
  183. *
  184. * Description: Retrieves the MAC address of the card, and sets up some
  185. * globals required by other routines, and initializes the NIC, making it
  186. * ready to send and receive packets.
  187. *
  188. * Side effects:
  189. * leaves the ioaddress of the natsemi chip in the variable ioaddr.
  190. * leaves the natsemi initialized, and ready to recieve packets.
  191. *
  192. * Returns: struct nic *: pointer to NIC data structure
  193. */
  194. static int
  195. natsemi_probe ( struct dev *dev ) {
  196. struct nic *nic = nic_device ( dev );
  197. struct pci_device *pci = pci_device ( dev );
  198. int i;
  199. int prev_eedata;
  200. u32 tmp;
  201. if (pci->ioaddr == 0)
  202. return 0;
  203. adjust_pci_device(pci);
  204. /* initialize some commonly used globals */
  205. nic->irqno = 0;
  206. nic->ioaddr = pci->ioaddr & ~3;
  207. ioaddr = pci->ioaddr & ~3;
  208. vendor = pci->vendor;
  209. dev_id = pci->dev_id;
  210. nic_name = pci->name;
  211. /* natsemi has a non-standard PM control register
  212. * in PCI config space. Some boards apparently need
  213. * to be brought to D0 in this manner.
  214. */
  215. pcibios_read_config_dword(pci->bus, pci->devfn, PCIPM, &tmp);
  216. if (tmp & (0x03|0x100)) {
  217. /* D0 state, disable PME assertion */
  218. u32 newtmp = tmp & ~(0x03|0x100);
  219. pcibios_write_config_dword(pci->bus, pci->devfn, PCIPM, newtmp);
  220. }
  221. /* get MAC address */
  222. prev_eedata = eeprom_read(ioaddr, 6);
  223. for (i = 0; i < 3; i++) {
  224. int eedata = eeprom_read(ioaddr, i + 7);
  225. nic->node_addr[i*2] = (eedata << 1) + (prev_eedata >> 15);
  226. nic->node_addr[i*2+1] = eedata >> 7;
  227. prev_eedata = eedata;
  228. }
  229. printf("\nnatsemi_probe: MAC addr %! at ioaddr %#hX\n",
  230. nic->node_addr, ioaddr);
  231. printf("natsemi_probe: Vendor:%#hX Device:%#hX\n", vendor, dev_id);
  232. /* Reset the chip to erase any previous misconfiguration. */
  233. outl(ChipReset, ioaddr + ChipCmd);
  234. advertising = mdio_read(1, 4);
  235. {
  236. u32 chip_config = inl(ioaddr + ChipConfig);
  237. printf("%s: Transceiver default autoneg. %s "
  238. "10%s %s duplex.\n",
  239. nic_name,
  240. chip_config & 0x2000 ? "enabled, advertise" : "disabled, force",
  241. chip_config & 0x4000 ? "0" : "",
  242. chip_config & 0x8000 ? "full" : "half");
  243. }
  244. printf("%s: Transceiver status %hX advertising %hX\n",
  245. nic_name, (int)inl(ioaddr + 0x84), advertising);
  246. /* Disable PME:
  247. * The PME bit is initialized from the EEPROM contents.
  248. * PCI cards probably have PME disabled, but motherboard
  249. * implementations may have PME set to enable WakeOnLan.
  250. * With PME set the chip will scan incoming packets but
  251. * nothing will be written to memory. */
  252. SavedClkRun = inl(ioaddr + ClkRun);
  253. outl(SavedClkRun & ~0x100, ioaddr + ClkRun);
  254. /* initialize device */
  255. natsemi_init(nic);
  256. dev->disable = natsemi_disable;
  257. nic->poll = natsemi_poll;
  258. nic->transmit = natsemi_transmit;
  259. nic->irq = natsemi_irq;
  260. return 1;
  261. }
  262. /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.
  263. The EEPROM code is for the common 93c06/46 EEPROMs with 6 bit addresses.
  264. */
  265. /* Delay between EEPROM clock transitions.
  266. No extra delay is needed with 33Mhz PCI, but future 66Mhz access may need
  267. a delay. */
  268. #define eeprom_delay(ee_addr) inl(ee_addr)
  269. enum EEPROM_Ctrl_Bits {
  270. EE_ShiftClk = 0x04,
  271. EE_DataIn = 0x01,
  272. EE_ChipSelect = 0x08,
  273. EE_DataOut = 0x02
  274. };
  275. #define EE_Write0 (EE_ChipSelect)
  276. #define EE_Write1 (EE_ChipSelect | EE_DataIn)
  277. /* The EEPROM commands include the alway-set leading bit. */
  278. enum EEPROM_Cmds {
  279. EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
  280. };
  281. static int eeprom_read(long addr, int location)
  282. {
  283. int i;
  284. int retval = 0;
  285. int ee_addr = addr + EECtrl;
  286. int read_cmd = location | EE_ReadCmd;
  287. outl(EE_Write0, ee_addr);
  288. /* Shift the read command bits out. */
  289. for (i = 10; i >= 0; i--) {
  290. short dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
  291. outl(dataval, ee_addr);
  292. eeprom_delay(ee_addr);
  293. outl(dataval | EE_ShiftClk, ee_addr);
  294. eeprom_delay(ee_addr);
  295. }
  296. outl(EE_ChipSelect, ee_addr);
  297. eeprom_delay(ee_addr);
  298. for (i = 0; i < 16; i++) {
  299. outl(EE_ChipSelect | EE_ShiftClk, ee_addr);
  300. eeprom_delay(ee_addr);
  301. retval |= (inl(ee_addr) & EE_DataOut) ? 1 << i : 0;
  302. outl(EE_ChipSelect, ee_addr);
  303. eeprom_delay(ee_addr);
  304. }
  305. /* Terminate the EEPROM access. */
  306. outl(EE_Write0, ee_addr);
  307. outl(0, ee_addr);
  308. return retval;
  309. }
  310. /* MII transceiver control section.
  311. The 83815 series has an internal transceiver, and we present the
  312. management registers as if they were MII connected. */
  313. static int mdio_read(int phy_id, int location)
  314. {
  315. if (phy_id == 1 && location < 32)
  316. return inl(ioaddr + 0x80 + (location<<2)) & 0xffff;
  317. else
  318. return 0xffff;
  319. }
  320. /* Function: natsemi_init
  321. *
  322. * Description: resets the ethernet controller chip and configures
  323. * registers and data structures required for sending and receiving packets.
  324. *
  325. * Arguments: struct nic *nic: NIC data structure
  326. *
  327. * returns: void.
  328. */
  329. static void
  330. natsemi_init(struct nic *nic)
  331. {
  332. natsemi_reset(nic);
  333. /* Disable PME:
  334. * The PME bit is initialized from the EEPROM contents.
  335. * PCI cards probably have PME disabled, but motherboard
  336. * implementations may have PME set to enable WakeOnLan.
  337. * With PME set the chip will scan incoming packets but
  338. * nothing will be written to memory. */
  339. outl(SavedClkRun & ~0x100, ioaddr + ClkRun);
  340. natsemi_init_rxfilter(nic);
  341. natsemi_init_txd(nic);
  342. natsemi_init_rxd(nic);
  343. /* Initialize other registers. */
  344. /* Configure the PCI bus bursts and FIFO thresholds. */
  345. /* Configure for standard, in-spec Ethernet. */
  346. if (inl(ioaddr + ChipConfig) & 0x20000000) { /* Full duplex */
  347. tx_config = 0xD0801002;
  348. rx_config = 0x10000020;
  349. } else {
  350. tx_config = 0x10801002;
  351. rx_config = 0x0020;
  352. }
  353. outl(tx_config, ioaddr + TxConfig);
  354. outl(rx_config, ioaddr + RxConfig);
  355. natsemi_check_duplex(nic);
  356. natsemi_set_rx_mode(nic);
  357. outl(RxOn, ioaddr + ChipCmd);
  358. }
  359. /*
  360. * Function: natsemi_reset
  361. *
  362. * Description: soft resets the controller chip
  363. *
  364. * Arguments: struct nic *nic: NIC data structure
  365. *
  366. * Returns: void.
  367. */
  368. static void
  369. natsemi_reset(struct nic *nic __unused)
  370. {
  371. outl(ChipReset, ioaddr + ChipCmd);
  372. /* On page 78 of the spec, they recommend some settings for "optimum
  373. performance" to be done in sequence. These settings optimize some
  374. of the 100Mbit autodetection circuitry. Also, we only want to do
  375. this for rev C of the chip.
  376. */
  377. if (inl(ioaddr + SiliconRev) == 0x302) {
  378. outw(0x0001, ioaddr + PGSEL);
  379. outw(0x189C, ioaddr + PMDCSR);
  380. outw(0x0000, ioaddr + TSTDAT);
  381. outw(0x5040, ioaddr + DSPCFG);
  382. outw(0x008C, ioaddr + SDCFG);
  383. }
  384. /* Disable interrupts using the mask. */
  385. outl(0, ioaddr + IntrMask);
  386. outl(0, ioaddr + IntrEnable);
  387. }
  388. /* Function: natsemi_init_rxfilter
  389. *
  390. * Description: sets receive filter address to our MAC address
  391. *
  392. * Arguments: struct nic *nic: NIC data structure
  393. *
  394. * returns: void.
  395. */
  396. static void
  397. natsemi_init_rxfilter(struct nic *nic)
  398. {
  399. int i;
  400. for (i = 0; i < ETH_ALEN; i += 2) {
  401. outl(i, ioaddr + RxFilterAddr);
  402. outw(nic->node_addr[i] + (nic->node_addr[i+1] << 8), ioaddr + RxFilterData);
  403. }
  404. }
  405. /*
  406. * Function: natsemi_init_txd
  407. *
  408. * Description: initializes the Tx descriptor
  409. *
  410. * Arguments: struct nic *nic: NIC data structure
  411. *
  412. * returns: void.
  413. */
  414. static void
  415. natsemi_init_txd(struct nic *nic __unused)
  416. {
  417. txd.link = (u32) 0;
  418. txd.cmdsts = (u32) 0;
  419. txd.bufptr = virt_to_bus(&txb[0]);
  420. /* load Transmit Descriptor Register */
  421. outl(virt_to_bus(&txd), ioaddr + TxRingPtr);
  422. if (natsemi_debug > 1)
  423. printf("natsemi_init_txd: TX descriptor register loaded with: %X\n",
  424. inl(ioaddr + TxRingPtr));
  425. }
  426. /* Function: natsemi_init_rxd
  427. *
  428. * Description: initializes the Rx descriptor ring
  429. *
  430. * Arguments: struct nic *nic: NIC data structure
  431. *
  432. * Returns: void.
  433. */
  434. static void
  435. natsemi_init_rxd(struct nic *nic __unused)
  436. {
  437. int i;
  438. cur_rx = 0;
  439. /* init RX descriptor */
  440. for (i = 0; i < NUM_RX_DESC; i++) {
  441. rxd[i].link = virt_to_bus((i+1 < NUM_RX_DESC) ? &rxd[i+1] : &rxd[0]);
  442. rxd[i].cmdsts = (u32) RX_BUF_SIZE;
  443. rxd[i].bufptr = virt_to_bus(&rxb[i*RX_BUF_SIZE]);
  444. if (natsemi_debug > 1)
  445. printf("natsemi_init_rxd: rxd[%d]=%X link=%X cmdsts=%X bufptr=%X\n",
  446. i, &rxd[i], rxd[i].link, rxd[i].cmdsts, rxd[i].bufptr);
  447. }
  448. /* load Receive Descriptor Register */
  449. outl(virt_to_bus(&rxd[0]), ioaddr + RxRingPtr);
  450. if (natsemi_debug > 1)
  451. printf("natsemi_init_rxd: RX descriptor register loaded with: %X\n",
  452. inl(ioaddr + RxRingPtr));
  453. }
  454. /* Function: natsemi_set_rx_mode
  455. *
  456. * Description:
  457. * sets the receive mode to accept all broadcast packets and packets
  458. * with our MAC address, and reject all multicast packets.
  459. *
  460. * Arguments: struct nic *nic: NIC data structure
  461. *
  462. * Returns: void.
  463. */
  464. static void natsemi_set_rx_mode(struct nic *nic __unused)
  465. {
  466. u32 rx_mode = RxFilterEnable | AcceptBroadcast |
  467. AcceptAllMulticast | AcceptMyPhys;
  468. outl(rx_mode, ioaddr + RxFilterAddr);
  469. }
  470. static void natsemi_check_duplex(struct nic *nic __unused)
  471. {
  472. int duplex = inl(ioaddr + ChipConfig) & 0x20000000 ? 1 : 0;
  473. if (natsemi_debug)
  474. printf("%s: Setting %s-duplex based on negotiated link"
  475. " capability.\n", nic_name,
  476. duplex ? "full" : "half");
  477. if (duplex) {
  478. rx_config |= 0x10000000;
  479. tx_config |= 0xC0000000;
  480. } else {
  481. rx_config &= ~0x10000000;
  482. tx_config &= ~0xC0000000;
  483. }
  484. outl(tx_config, ioaddr + TxConfig);
  485. outl(rx_config, ioaddr + RxConfig);
  486. }
  487. /* Function: natsemi_transmit
  488. *
  489. * Description: transmits a packet and waits for completion or timeout.
  490. *
  491. * Arguments: char d[6]: destination ethernet address.
  492. * unsigned short t: ethernet protocol type.
  493. * unsigned short s: size of the data-part of the packet.
  494. * char *p: the data for the packet.
  495. *
  496. * Returns: void.
  497. */
  498. static void
  499. natsemi_transmit(struct nic *nic,
  500. const char *d, /* Destination */
  501. unsigned int t, /* Type */
  502. unsigned int s, /* size */
  503. const char *p) /* Packet */
  504. {
  505. u32 to, nstype;
  506. u32 tx_status;
  507. /* Stop the transmitter */
  508. outl(TxOff, ioaddr + ChipCmd);
  509. /* load Transmit Descriptor Register */
  510. outl(virt_to_bus(&txd), ioaddr + TxRingPtr);
  511. if (natsemi_debug > 1)
  512. printf("natsemi_transmit: TX descriptor register loaded with: %X\n",
  513. inl(ioaddr + TxRingPtr));
  514. memcpy(txb, d, ETH_ALEN);
  515. memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
  516. nstype = htons(t);
  517. memcpy(txb + 2 * ETH_ALEN, (char*)&nstype, 2);
  518. memcpy(txb + ETH_HLEN, p, s);
  519. s += ETH_HLEN;
  520. s &= DSIZE;
  521. if (natsemi_debug > 1)
  522. printf("natsemi_transmit: sending %d bytes ethtype %hX\n", (int) s, t);
  523. /* pad to minimum packet size */
  524. while (s < ETH_ZLEN)
  525. txb[s++] = '\0';
  526. /* set the transmit buffer descriptor and enable Transmit State Machine */
  527. txd.bufptr = virt_to_bus(&txb[0]);
  528. txd.cmdsts = (u32) OWN | s;
  529. /* restart the transmitter */
  530. outl(TxOn, ioaddr + ChipCmd);
  531. if (natsemi_debug > 1)
  532. printf("natsemi_transmit: Queued Tx packet size %d.\n", (int) s);
  533. to = currticks() + TX_TIMEOUT;
  534. while ((((volatile u32) tx_status=txd.cmdsts) & OWN) && (currticks() < to))
  535. /* wait */ ;
  536. if (currticks() >= to) {
  537. printf("natsemi_transmit: TX Timeout! Tx status %X.\n", tx_status);
  538. }
  539. if (!(tx_status & 0x08000000)) {
  540. printf("natsemi_transmit: Transmit error, Tx status %X.\n", tx_status);
  541. }
  542. }
  543. /* Function: natsemi_poll
  544. *
  545. * Description: checks for a received packet and returns it if found.
  546. *
  547. * Arguments: struct nic *nic: NIC data structure
  548. *
  549. * Returns: 1 if packet was received.
  550. * 0 if no packet was received.
  551. *
  552. * Side effects:
  553. * Returns (copies) the packet to the array nic->packet.
  554. * Returns the length of the packet in nic->packetlen.
  555. */
  556. static int
  557. natsemi_poll(struct nic *nic, int retrieve)
  558. {
  559. u32 rx_status = rxd[cur_rx].cmdsts;
  560. int retstat = 0;
  561. if (natsemi_debug > 2)
  562. printf("natsemi_poll: cur_rx:%d, status:%X\n", cur_rx, rx_status);
  563. if (!(rx_status & OWN))
  564. return retstat;
  565. if ( ! retrieve ) return 1;
  566. if (natsemi_debug > 1)
  567. printf("natsemi_poll: got a packet: cur_rx:%d, status:%X\n",
  568. cur_rx, rx_status);
  569. nic->packetlen = (rx_status & DSIZE) - CRC_SIZE;
  570. if ((rx_status & (DescMore|DescPktOK|RxTooLong)) != DescPktOK) {
  571. /* corrupted packet received */
  572. printf("natsemi_poll: Corrupted packet received, buffer status = %X\n",
  573. rx_status);
  574. retstat = 0;
  575. } else {
  576. /* give packet to higher level routine */
  577. memcpy(nic->packet, (rxb + cur_rx*RX_BUF_SIZE), nic->packetlen);
  578. retstat = 1;
  579. }
  580. /* return the descriptor and buffer to receive ring */
  581. rxd[cur_rx].cmdsts = RX_BUF_SIZE;
  582. rxd[cur_rx].bufptr = virt_to_bus(&rxb[cur_rx*RX_BUF_SIZE]);
  583. if (++cur_rx == NUM_RX_DESC)
  584. cur_rx = 0;
  585. /* re-enable the potentially idle receive state machine */
  586. outl(RxOn, ioaddr + ChipCmd);
  587. return retstat;
  588. }
  589. /* Function: natsemi_disable
  590. *
  591. * Description: Turns off interrupts and stops Tx and Rx engines
  592. *
  593. * Arguments: struct nic *nic: NIC data structure
  594. *
  595. * Returns: void.
  596. */
  597. static void
  598. natsemi_disable ( struct nic *nic ) {
  599. /* merge reset and disable */
  600. natsemi_init(nic);
  601. /* Disable interrupts using the mask. */
  602. outl(0, ioaddr + IntrMask);
  603. outl(0, ioaddr + IntrEnable);
  604. /* Stop the chip's Tx and Rx processes. */
  605. outl(RxOff | TxOff, ioaddr + ChipCmd);
  606. /* Restore PME enable bit */
  607. outl(SavedClkRun, ioaddr + ClkRun);
  608. }
  609. /* Function: natsemi_irq
  610. *
  611. * Description: Enable, Disable, or Force interrupts
  612. *
  613. * Arguments: struct nic *nic: NIC data structure
  614. * irq_action_t action: requested action to perform
  615. *
  616. * Returns: void.
  617. */
  618. static void
  619. natsemi_irq(struct nic *nic __unused, irq_action_t action __unused)
  620. {
  621. switch ( action ) {
  622. case DISABLE :
  623. break;
  624. case ENABLE :
  625. break;
  626. case FORCE :
  627. break;
  628. }
  629. }
  630. static struct pci_id natsemi_nics[] = {
  631. PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
  632. };
  633. static struct pci_driver natsemi_driver =
  634. PCI_DRIVER ( "NATSEMI", natsemi_nics, PCI_NO_CLASS );
  635. BOOT_DRIVER ( "NATSEMI", natsemi_probe );