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

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