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.

pxe_undi.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /** @file
  2. *
  3. * PXE UNDI API
  4. *
  5. */
  6. /*
  7. * Copyright (C) 2004 Michael Brown <mbrown@fensystems.co.uk>.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of the
  12. * License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <stdint.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <byteswap.h>
  27. #include <basemem_packet.h>
  28. #include <gpxe/netdevice.h>
  29. #include <gpxe/iobuf.h>
  30. #include <gpxe/device.h>
  31. #include <gpxe/pci.h>
  32. #include <gpxe/if_ether.h>
  33. #include <gpxe/ip.h>
  34. #include <gpxe/arp.h>
  35. #include <gpxe/rarp.h>
  36. #include "pxe.h"
  37. /**
  38. * Count of outstanding transmitted packets
  39. *
  40. * This is incremented each time PXENV_UNDI_TRANSMIT is called, and
  41. * decremented each time that PXENV_UNDI_ISR is called with the TX
  42. * queue empty, stopping when the count reaches zero. This allows us
  43. * to provide a pessimistic approximation of TX completion events to
  44. * the PXE NBP simply by monitoring the netdev's TX queue.
  45. */
  46. static int undi_tx_count = 0;
  47. struct net_device *pxe_netdev = NULL;
  48. /**
  49. * Set network device as current PXE network device
  50. *
  51. * @v netdev Network device, or NULL
  52. */
  53. void pxe_set_netdev ( struct net_device *netdev ) {
  54. if ( pxe_netdev )
  55. netdev_put ( pxe_netdev );
  56. pxe_netdev = NULL;
  57. if ( netdev )
  58. pxe_netdev = netdev_get ( netdev );
  59. }
  60. /**
  61. * Open PXE network device
  62. *
  63. * @ret rc Return status code
  64. */
  65. static int pxe_netdev_open ( void ) {
  66. int rc;
  67. if ( ( rc = netdev_open ( pxe_netdev ) ) != 0 )
  68. return rc;
  69. netdev_irq ( pxe_netdev, 1 );
  70. return 0;
  71. }
  72. /**
  73. * Close PXE network device
  74. *
  75. */
  76. static void pxe_netdev_close ( void ) {
  77. netdev_irq ( pxe_netdev, 0 );
  78. netdev_close ( pxe_netdev );
  79. undi_tx_count = 0;
  80. }
  81. /* PXENV_UNDI_STARTUP
  82. *
  83. * Status: working
  84. */
  85. PXENV_EXIT_t pxenv_undi_startup ( struct s_PXENV_UNDI_STARTUP *undi_startup ) {
  86. DBG ( "PXENV_UNDI_STARTUP" );
  87. undi_startup->Status = PXENV_STATUS_SUCCESS;
  88. return PXENV_EXIT_SUCCESS;
  89. }
  90. /* PXENV_UNDI_CLEANUP
  91. *
  92. * Status: working
  93. */
  94. PXENV_EXIT_t pxenv_undi_cleanup ( struct s_PXENV_UNDI_CLEANUP *undi_cleanup ) {
  95. DBG ( "PXENV_UNDI_CLEANUP" );
  96. pxe_netdev_close();
  97. undi_cleanup->Status = PXENV_STATUS_SUCCESS;
  98. return PXENV_EXIT_SUCCESS;
  99. }
  100. /* PXENV_UNDI_INITIALIZE
  101. *
  102. * Status: working
  103. */
  104. PXENV_EXIT_t pxenv_undi_initialize ( struct s_PXENV_UNDI_INITIALIZE
  105. *undi_initialize ) {
  106. DBG ( "PXENV_UNDI_INITIALIZE" );
  107. undi_initialize->Status = PXENV_STATUS_SUCCESS;
  108. return PXENV_EXIT_SUCCESS;
  109. }
  110. /* PXENV_UNDI_RESET_ADAPTER
  111. *
  112. * Status: working
  113. */
  114. PXENV_EXIT_t pxenv_undi_reset_adapter ( struct s_PXENV_UNDI_RESET
  115. *undi_reset_adapter ) {
  116. int rc;
  117. DBG ( "PXENV_UNDI_RESET_ADAPTER" );
  118. pxe_netdev_close();
  119. if ( ( rc = pxe_netdev_open() ) != 0 ) {
  120. undi_reset_adapter->Status = PXENV_STATUS ( rc );
  121. return PXENV_EXIT_FAILURE;
  122. }
  123. undi_reset_adapter->Status = PXENV_STATUS_SUCCESS;
  124. return PXENV_EXIT_SUCCESS;
  125. }
  126. /* PXENV_UNDI_SHUTDOWN
  127. *
  128. * Status: working
  129. */
  130. PXENV_EXIT_t pxenv_undi_shutdown ( struct s_PXENV_UNDI_SHUTDOWN
  131. *undi_shutdown ) {
  132. DBG ( "PXENV_UNDI_SHUTDOWN" );
  133. pxe_netdev_close();
  134. undi_shutdown->Status = PXENV_STATUS_SUCCESS;
  135. return PXENV_EXIT_SUCCESS;
  136. }
  137. /* PXENV_UNDI_OPEN
  138. *
  139. * Status: working
  140. */
  141. PXENV_EXIT_t pxenv_undi_open ( struct s_PXENV_UNDI_OPEN *undi_open ) {
  142. int rc;
  143. DBG ( "PXENV_UNDI_OPEN" );
  144. if ( ( rc = pxe_netdev_open() ) != 0 ) {
  145. undi_open->Status = PXENV_STATUS ( rc );
  146. return PXENV_EXIT_FAILURE;
  147. }
  148. undi_open->Status = PXENV_STATUS_SUCCESS;
  149. return PXENV_EXIT_SUCCESS;
  150. }
  151. /* PXENV_UNDI_CLOSE
  152. *
  153. * Status: working
  154. */
  155. PXENV_EXIT_t pxenv_undi_close ( struct s_PXENV_UNDI_CLOSE *undi_close ) {
  156. DBG ( "PXENV_UNDI_CLOSE" );
  157. pxe_netdev_close();
  158. undi_close->Status = PXENV_STATUS_SUCCESS;
  159. return PXENV_EXIT_SUCCESS;
  160. }
  161. /* PXENV_UNDI_TRANSMIT
  162. *
  163. * Status: working
  164. */
  165. PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
  166. *undi_transmit ) {
  167. struct s_PXENV_UNDI_TBD tbd;
  168. struct DataBlk *datablk;
  169. struct io_buffer *iobuf;
  170. struct net_protocol *net_protocol;
  171. char destaddr[MAX_LL_ADDR_LEN];
  172. const void *ll_dest;
  173. size_t ll_hlen = pxe_netdev->ll_protocol->ll_header_len;
  174. size_t len;
  175. unsigned int i;
  176. int rc;
  177. DBG ( "PXENV_UNDI_TRANSMIT" );
  178. /* Identify network-layer protocol */
  179. switch ( undi_transmit->Protocol ) {
  180. case P_IP: net_protocol = &ipv4_protocol; break;
  181. case P_ARP: net_protocol = &arp_protocol; break;
  182. case P_RARP: net_protocol = &rarp_protocol; break;
  183. case P_UNKNOWN:
  184. net_protocol = NULL;
  185. ll_hlen = 0;
  186. break;
  187. default:
  188. undi_transmit->Status = PXENV_STATUS_UNDI_INVALID_PARAMETER;
  189. return PXENV_EXIT_FAILURE;
  190. }
  191. DBG ( " %s", ( net_protocol ? net_protocol->name : "RAW" ) );
  192. /* Calculate total packet length */
  193. copy_from_real ( &tbd, undi_transmit->TBD.segment,
  194. undi_transmit->TBD.offset, sizeof ( tbd ) );
  195. len = tbd.ImmedLength;
  196. DBG ( " %d", tbd.ImmedLength );
  197. for ( i = 0 ; i < tbd.DataBlkCount ; i++ ) {
  198. datablk = &tbd.DataBlock[i];
  199. len += datablk->TDDataLen;
  200. DBG ( "+%d", datablk->TDDataLen );
  201. }
  202. /* Allocate and fill I/O buffer */
  203. iobuf = alloc_iob ( ll_hlen + len );
  204. if ( ! iobuf ) {
  205. undi_transmit->Status = PXENV_STATUS_OUT_OF_RESOURCES;
  206. return PXENV_EXIT_FAILURE;
  207. }
  208. iob_reserve ( iobuf, ll_hlen );
  209. copy_from_real ( iob_put ( iobuf, tbd.ImmedLength ), tbd.Xmit.segment,
  210. tbd.Xmit.offset, tbd.ImmedLength );
  211. for ( i = 0 ; i < tbd.DataBlkCount ; i++ ) {
  212. datablk = &tbd.DataBlock[i];
  213. copy_from_real ( iob_put ( iobuf, datablk->TDDataLen ),
  214. datablk->TDDataPtr.segment,
  215. datablk->TDDataPtr.offset,
  216. datablk->TDDataLen );
  217. }
  218. /* Transmit packet */
  219. if ( net_protocol == NULL ) {
  220. /* Link-layer header already present */
  221. rc = netdev_tx ( pxe_netdev, iobuf );
  222. } else {
  223. /* Calculate destination address */
  224. if ( undi_transmit->XmitFlag == XMT_DESTADDR ) {
  225. copy_from_real ( destaddr,
  226. undi_transmit->DestAddr.segment,
  227. undi_transmit->DestAddr.offset,
  228. pxe_netdev->ll_protocol->ll_addr_len );
  229. ll_dest = destaddr;
  230. } else {
  231. DBG ( " BCAST" );
  232. ll_dest = pxe_netdev->ll_protocol->ll_broadcast;
  233. }
  234. rc = net_tx ( iobuf, pxe_netdev, net_protocol, ll_dest );
  235. }
  236. /* Flag transmission as in-progress */
  237. undi_tx_count++;
  238. undi_transmit->Status = PXENV_STATUS ( rc );
  239. return ( ( rc == 0 ) ? PXENV_EXIT_SUCCESS : PXENV_EXIT_FAILURE );
  240. }
  241. /* PXENV_UNDI_SET_MCAST_ADDRESS
  242. *
  243. * Status: stub (no PXE multicast support)
  244. */
  245. PXENV_EXIT_t
  246. pxenv_undi_set_mcast_address ( struct s_PXENV_UNDI_SET_MCAST_ADDRESS
  247. *undi_set_mcast_address ) {
  248. DBG ( "PXENV_UNDI_SET_MCAST_ADDRESS" );
  249. undi_set_mcast_address->Status = PXENV_STATUS_UNSUPPORTED;
  250. return PXENV_EXIT_FAILURE;
  251. }
  252. /* PXENV_UNDI_SET_STATION_ADDRESS
  253. *
  254. * Status: working
  255. */
  256. PXENV_EXIT_t
  257. pxenv_undi_set_station_address ( struct s_PXENV_UNDI_SET_STATION_ADDRESS
  258. *undi_set_station_address ) {
  259. DBG ( "PXENV_UNDI_SET_STATION_ADDRESS" );
  260. /* If adapter is open, the change will have no effect; return
  261. * an error
  262. */
  263. if ( pxe_netdev->state & NETDEV_OPEN ) {
  264. undi_set_station_address->Status =
  265. PXENV_STATUS_UNDI_INVALID_STATE;
  266. return PXENV_EXIT_FAILURE;
  267. }
  268. /* Update MAC address */
  269. memcpy ( pxe_netdev->ll_addr,
  270. &undi_set_station_address->StationAddress,
  271. pxe_netdev->ll_protocol->ll_addr_len );
  272. undi_set_station_address->Status = PXENV_STATUS_SUCCESS;
  273. return PXENV_EXIT_SUCCESS;
  274. }
  275. /* PXENV_UNDI_SET_PACKET_FILTER
  276. *
  277. * Status: won't implement (would require driver API changes for no
  278. * real benefit)
  279. */
  280. PXENV_EXIT_t
  281. pxenv_undi_set_packet_filter ( struct s_PXENV_UNDI_SET_PACKET_FILTER
  282. *undi_set_packet_filter ) {
  283. DBG ( "PXENV_UNDI_SET_PACKET_FILTER" );
  284. undi_set_packet_filter->Status = PXENV_STATUS_UNSUPPORTED;
  285. return PXENV_EXIT_FAILURE;
  286. }
  287. /* PXENV_UNDI_GET_INFORMATION
  288. *
  289. * Status: working
  290. */
  291. PXENV_EXIT_t pxenv_undi_get_information ( struct s_PXENV_UNDI_GET_INFORMATION
  292. *undi_get_information ) {
  293. struct device *dev = pxe_netdev->dev;
  294. struct ll_protocol *ll_protocol = pxe_netdev->ll_protocol;
  295. DBG ( "PXENV_UNDI_GET_INFORMATION" );
  296. undi_get_information->BaseIo = dev->desc.ioaddr;
  297. undi_get_information->IntNumber = dev->desc.irq;
  298. /* Cheat: assume all cards can cope with this */
  299. undi_get_information->MaxTranUnit = ETH_MAX_MTU;
  300. undi_get_information->HwType = ntohs ( ll_protocol->ll_proto );
  301. undi_get_information->HwAddrLen = ll_protocol->ll_addr_len;
  302. /* Cheat: assume card is always configured with its permanent
  303. * node address. This is a valid assumption within Etherboot
  304. * at the time of writing.
  305. */
  306. memcpy ( &undi_get_information->CurrentNodeAddress,
  307. pxe_netdev->ll_addr,
  308. sizeof ( undi_get_information->CurrentNodeAddress ) );
  309. memcpy ( &undi_get_information->PermNodeAddress,
  310. pxe_netdev->ll_addr,
  311. sizeof ( undi_get_information->PermNodeAddress ) );
  312. undi_get_information->ROMAddress = 0;
  313. /* nic.rom_info->rom_segment; */
  314. /* We only provide the ability to receive or transmit a single
  315. * packet at a time. This is a bootloader, not an OS.
  316. */
  317. undi_get_information->RxBufCt = 1;
  318. undi_get_information->TxBufCt = 1;
  319. undi_get_information->Status = PXENV_STATUS_SUCCESS;
  320. return PXENV_EXIT_SUCCESS;
  321. }
  322. /* PXENV_UNDI_GET_STATISTICS
  323. *
  324. * Status: working
  325. */
  326. PXENV_EXIT_t pxenv_undi_get_statistics ( struct s_PXENV_UNDI_GET_STATISTICS
  327. *undi_get_statistics ) {
  328. DBG ( "PXENV_UNDI_GET_STATISTICS" );
  329. undi_get_statistics->XmtGoodFrames = pxe_netdev->stats.tx_ok;
  330. undi_get_statistics->RcvGoodFrames = pxe_netdev->stats.rx_ok;
  331. undi_get_statistics->RcvCRCErrors = pxe_netdev->stats.rx_err;
  332. undi_get_statistics->RcvResourceErrors = pxe_netdev->stats.rx_err;
  333. undi_get_statistics->Status = PXENV_STATUS_SUCCESS;
  334. return PXENV_EXIT_SUCCESS;
  335. }
  336. /* PXENV_UNDI_CLEAR_STATISTICS
  337. *
  338. * Status: working
  339. */
  340. PXENV_EXIT_t pxenv_undi_clear_statistics ( struct s_PXENV_UNDI_CLEAR_STATISTICS
  341. *undi_clear_statistics ) {
  342. DBG ( "PXENV_UNDI_CLEAR_STATISTICS" );
  343. memset ( &pxe_netdev->stats, 0, sizeof ( pxe_netdev->stats ) );
  344. undi_clear_statistics->Status = PXENV_STATUS_SUCCESS;
  345. return PXENV_EXIT_SUCCESS;
  346. }
  347. /* PXENV_UNDI_INITIATE_DIAGS
  348. *
  349. * Status: won't implement (would require driver API changes for no
  350. * real benefit)
  351. */
  352. PXENV_EXIT_t pxenv_undi_initiate_diags ( struct s_PXENV_UNDI_INITIATE_DIAGS
  353. *undi_initiate_diags ) {
  354. DBG ( "PXENV_UNDI_INITIATE_DIAGS" );
  355. undi_initiate_diags->Status = PXENV_STATUS_UNSUPPORTED;
  356. return PXENV_EXIT_FAILURE;
  357. }
  358. /* PXENV_UNDI_FORCE_INTERRUPT
  359. *
  360. * Status: won't implement (would require driver API changes for no
  361. * perceptible benefit)
  362. */
  363. PXENV_EXIT_t pxenv_undi_force_interrupt ( struct s_PXENV_UNDI_FORCE_INTERRUPT
  364. *undi_force_interrupt ) {
  365. DBG ( "PXENV_UNDI_FORCE_INTERRUPT" );
  366. undi_force_interrupt->Status = PXENV_STATUS_UNSUPPORTED;
  367. return PXENV_EXIT_FAILURE;
  368. }
  369. /* PXENV_UNDI_GET_MCAST_ADDRESS
  370. *
  371. * Status: stub (no PXE multicast support)
  372. */
  373. PXENV_EXIT_t
  374. pxenv_undi_get_mcast_address ( struct s_PXENV_UNDI_GET_MCAST_ADDRESS
  375. *undi_get_mcast_address ) {
  376. DBG ( "PXENV_UNDI_GET_MCAST_ADDRESS" );
  377. undi_get_mcast_address->Status = PXENV_STATUS_UNSUPPORTED;
  378. return PXENV_EXIT_FAILURE;
  379. }
  380. /* PXENV_UNDI_GET_NIC_TYPE
  381. *
  382. * Status: working
  383. */
  384. PXENV_EXIT_t pxenv_undi_get_nic_type ( struct s_PXENV_UNDI_GET_NIC_TYPE
  385. *undi_get_nic_type ) {
  386. struct device *dev = pxe_netdev->dev;
  387. DBG ( "PXENV_UNDI_GET_NIC_TYPE" );
  388. memset ( &undi_get_nic_type->info, 0,
  389. sizeof ( undi_get_nic_type->info ) );
  390. switch ( dev->desc.bus_type ) {
  391. case BUS_TYPE_PCI: {
  392. struct pci_nic_info *info = &undi_get_nic_type->info.pci;
  393. undi_get_nic_type->NicType = PCI_NIC;
  394. info->Vendor_ID = dev->desc.vendor;
  395. info->Dev_ID = dev->desc.device;
  396. info->Base_Class = PCI_BASE_CLASS ( dev->desc.class );
  397. info->Sub_Class = PCI_SUB_CLASS ( dev->desc.class );
  398. info->Prog_Intf = PCI_PROG_INTF ( dev->desc.class );
  399. info->BusDevFunc = dev->desc.location;
  400. /* Cheat: remaining fields are probably unnecessary,
  401. * and would require adding extra code to pci.c.
  402. */
  403. undi_get_nic_type->info.pci.SubVendor_ID = 0xffff;
  404. undi_get_nic_type->info.pci.SubDevice_ID = 0xffff;
  405. break; }
  406. case BUS_TYPE_ISAPNP: {
  407. struct pnp_nic_info *info = &undi_get_nic_type->info.pnp;
  408. undi_get_nic_type->NicType = PnP_NIC;
  409. info->EISA_Dev_ID = ( ( dev->desc.vendor << 16 ) |
  410. dev->desc.device );
  411. info->CardSelNum = dev->desc.location;
  412. /* Cheat: remaining fields are probably unnecessary,
  413. * and would require adding extra code to isapnp.c.
  414. */
  415. break; }
  416. default:
  417. undi_get_nic_type->Status = PXENV_STATUS_FAILURE;
  418. return PXENV_EXIT_FAILURE;
  419. }
  420. undi_get_nic_type->Status = PXENV_STATUS_SUCCESS;
  421. return PXENV_EXIT_SUCCESS;
  422. }
  423. /* PXENV_UNDI_GET_IFACE_INFO
  424. *
  425. * Status: working
  426. */
  427. PXENV_EXIT_t pxenv_undi_get_iface_info ( struct s_PXENV_UNDI_GET_IFACE_INFO
  428. *undi_get_iface_info ) {
  429. DBG ( "PXENV_UNDI_GET_IFACE_INFO" );
  430. /* Just hand back some info, doesn't really matter what it is.
  431. * Most PXE stacks seem to take this approach.
  432. */
  433. snprintf ( ( char * ) undi_get_iface_info->IfaceType,
  434. sizeof ( undi_get_iface_info->IfaceType ), "gPXE" );
  435. undi_get_iface_info->LinkSpeed = 10000000; /* 10 Mbps */
  436. undi_get_iface_info->ServiceFlags = 0;
  437. memset ( undi_get_iface_info->Reserved, 0,
  438. sizeof(undi_get_iface_info->Reserved) );
  439. undi_get_iface_info->Status = PXENV_STATUS_SUCCESS;
  440. return PXENV_EXIT_SUCCESS;
  441. }
  442. /* PXENV_UNDI_GET_STATE
  443. *
  444. * Status: impossible
  445. */
  446. PXENV_EXIT_t pxenv_undi_get_state ( struct s_PXENV_UNDI_GET_STATE
  447. *undi_get_state ) {
  448. DBG ( "PXENV_UNDI_GET_STATE" );
  449. undi_get_state->Status = PXENV_STATUS_UNSUPPORTED;
  450. return PXENV_EXIT_FAILURE;
  451. };
  452. /* PXENV_UNDI_ISR
  453. *
  454. * Status: working
  455. */
  456. PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
  457. struct io_buffer *iobuf;
  458. size_t len;
  459. DBG ( "PXENV_UNDI_ISR" );
  460. /* Just in case some idiot actually looks at these fields when
  461. * we weren't meant to fill them in...
  462. */
  463. undi_isr->BufferLength = 0;
  464. undi_isr->FrameLength = 0;
  465. undi_isr->FrameHeaderLength = 0;
  466. undi_isr->ProtType = 0;
  467. undi_isr->PktType = 0;
  468. switch ( undi_isr->FuncFlag ) {
  469. case PXENV_UNDI_ISR_IN_START :
  470. DBG ( " START" );
  471. /* Call poll(). This should acknowledge the device
  472. * interrupt and queue up any received packet.
  473. */
  474. netdev_poll ( pxe_netdev );
  475. /* Disable interrupts to avoid interrupt storm */
  476. netdev_irq ( pxe_netdev, 0 );
  477. /* Always say it was ours for the sake of simplicity */
  478. undi_isr->FuncFlag = PXENV_UNDI_ISR_OUT_OURS;
  479. break;
  480. case PXENV_UNDI_ISR_IN_PROCESS :
  481. DBG ( " PROCESS" );
  482. /* Fall through */
  483. case PXENV_UNDI_ISR_IN_GET_NEXT :
  484. DBG ( " GET_NEXT" );
  485. /* Some dumb NBPs (e.g. emBoot's winBoot/i) never call
  486. * PXENV_UNDI_ISR with FuncFlag=PXENV_UNDI_ISR_START;
  487. * they just sit in a tight polling loop merrily
  488. * violating the PXE spec with repeated calls to
  489. * PXENV_UNDI_ISR_IN_PROCESS. Force extra polls to
  490. * cope with these out-of-spec clients.
  491. */
  492. netdev_poll ( pxe_netdev );
  493. /* If we have not yet marked a TX as complete, and the
  494. * netdev TX queue is empty, report the TX completion.
  495. */
  496. if ( undi_tx_count && list_empty ( &pxe_netdev->tx_queue ) ) {
  497. DBG ( " TXC" );
  498. undi_tx_count--;
  499. undi_isr->FuncFlag = PXENV_UNDI_ISR_OUT_TRANSMIT;
  500. break;
  501. }
  502. /* Remove first packet from netdev RX queue */
  503. iobuf = netdev_rx_dequeue ( pxe_netdev );
  504. if ( ! iobuf ) {
  505. DBG ( " DONE" );
  506. /* No more packets remaining */
  507. undi_isr->FuncFlag = PXENV_UNDI_ISR_OUT_DONE;
  508. /* Re-enable interrupts */
  509. netdev_irq ( pxe_netdev, 1 );
  510. break;
  511. }
  512. /* Copy packet to base memory buffer */
  513. len = iob_len ( iobuf );
  514. DBG ( " RX %zd", len );
  515. if ( len > sizeof ( basemem_packet ) ) {
  516. /* Should never happen */
  517. len = sizeof ( basemem_packet );
  518. }
  519. memcpy ( basemem_packet, iobuf->data, len );
  520. /* Fill in UNDI_ISR structure */
  521. undi_isr->FuncFlag = PXENV_UNDI_ISR_OUT_RECEIVE;
  522. undi_isr->BufferLength = len;
  523. undi_isr->FrameLength = len;
  524. undi_isr->FrameHeaderLength =
  525. pxe_netdev->ll_protocol->ll_header_len;
  526. undi_isr->Frame.segment = rm_ds;
  527. undi_isr->Frame.offset = __from_data16 ( basemem_packet );
  528. /* Probably ought to fill in packet type */
  529. undi_isr->ProtType = P_UNKNOWN;
  530. undi_isr->PktType = XMT_DESTADDR;
  531. /* Free packet */
  532. free_iob ( iobuf );
  533. break;
  534. default :
  535. DBG ( " INVALID(%04x)", undi_isr->FuncFlag );
  536. /* Should never happen */
  537. undi_isr->FuncFlag = PXENV_UNDI_ISR_OUT_DONE;
  538. undi_isr->Status = PXENV_STATUS_UNDI_INVALID_PARAMETER;
  539. return PXENV_EXIT_FAILURE;
  540. }
  541. undi_isr->Status = PXENV_STATUS_SUCCESS;
  542. return PXENV_EXIT_SUCCESS;
  543. }