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.

undinet.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <pxe.h>
  21. #include <realmode.h>
  22. #include <pic8259.h>
  23. #include <biosint.h>
  24. #include <pnpbios.h>
  25. #include <basemem_packet.h>
  26. #include <ipxe/io.h>
  27. #include <ipxe/iobuf.h>
  28. #include <ipxe/netdevice.h>
  29. #include <ipxe/if_ether.h>
  30. #include <ipxe/ethernet.h>
  31. #include <undi.h>
  32. #include <undinet.h>
  33. #include <pxeparent.h>
  34. /** @file
  35. *
  36. * UNDI network device driver
  37. *
  38. */
  39. /** An UNDI NIC */
  40. struct undi_nic {
  41. /** Assigned IRQ number */
  42. unsigned int irq;
  43. /** Currently processing ISR */
  44. int isr_processing;
  45. /** Bug workarounds */
  46. int hacks;
  47. };
  48. /**
  49. * @defgroup undi_hacks UNDI workarounds
  50. * @{
  51. */
  52. /** Work around Etherboot 5.4 bugs */
  53. #define UNDI_HACK_EB54 0x0001
  54. /** @} */
  55. static void undinet_close ( struct net_device *netdev );
  56. /** Address of UNDI entry point */
  57. static SEGOFF16_t undinet_entry;
  58. /*****************************************************************************
  59. *
  60. * UNDI interrupt service routine
  61. *
  62. *****************************************************************************
  63. */
  64. /**
  65. * UNDI interrupt service routine
  66. *
  67. * The UNDI ISR increments a counter (@c trigger_count) and exits.
  68. */
  69. extern void undiisr ( void );
  70. /** IRQ number */
  71. uint8_t __data16 ( undiisr_irq );
  72. #define undiisr_irq __use_data16 ( undiisr_irq )
  73. /** IRQ chain vector */
  74. struct segoff __data16 ( undiisr_next_handler );
  75. #define undiisr_next_handler __use_data16 ( undiisr_next_handler )
  76. /** IRQ trigger count */
  77. volatile uint8_t __data16 ( undiisr_trigger_count ) = 0;
  78. #define undiisr_trigger_count __use_data16 ( undiisr_trigger_count )
  79. /** Last observed trigger count */
  80. static unsigned int last_trigger_count = 0;
  81. /**
  82. * Hook UNDI interrupt service routine
  83. *
  84. * @v irq IRQ number
  85. */
  86. static void undinet_hook_isr ( unsigned int irq ) {
  87. assert ( irq <= IRQ_MAX );
  88. assert ( undiisr_irq == 0 );
  89. undiisr_irq = irq;
  90. hook_bios_interrupt ( IRQ_INT ( irq ),
  91. ( ( unsigned int ) undiisr ),
  92. &undiisr_next_handler );
  93. }
  94. /**
  95. * Unhook UNDI interrupt service routine
  96. *
  97. * @v irq IRQ number
  98. */
  99. static void undinet_unhook_isr ( unsigned int irq ) {
  100. assert ( irq <= IRQ_MAX );
  101. unhook_bios_interrupt ( IRQ_INT ( irq ),
  102. ( ( unsigned int ) undiisr ),
  103. &undiisr_next_handler );
  104. undiisr_irq = 0;
  105. }
  106. /**
  107. * Test to see if UNDI ISR has been triggered
  108. *
  109. * @ret triggered ISR has been triggered since last check
  110. */
  111. static int undinet_isr_triggered ( void ) {
  112. unsigned int this_trigger_count;
  113. /* Read trigger_count. Do this only once; it is volatile */
  114. this_trigger_count = undiisr_trigger_count;
  115. if ( this_trigger_count == last_trigger_count ) {
  116. /* Not triggered */
  117. return 0;
  118. } else {
  119. /* Triggered */
  120. last_trigger_count = this_trigger_count;
  121. return 1;
  122. }
  123. }
  124. /*****************************************************************************
  125. *
  126. * UNDI network device interface
  127. *
  128. *****************************************************************************
  129. */
  130. /** UNDI transmit buffer descriptor */
  131. static struct s_PXENV_UNDI_TBD __data16 ( undinet_tbd );
  132. #define undinet_tbd __use_data16 ( undinet_tbd )
  133. /**
  134. * Transmit packet
  135. *
  136. * @v netdev Network device
  137. * @v iobuf I/O buffer
  138. * @ret rc Return status code
  139. */
  140. static int undinet_transmit ( struct net_device *netdev,
  141. struct io_buffer *iobuf ) {
  142. struct s_PXENV_UNDI_TRANSMIT undi_transmit;
  143. size_t len = iob_len ( iobuf );
  144. int rc;
  145. /* Technically, we ought to make sure that the previous
  146. * transmission has completed before we re-use the buffer.
  147. * However, many PXE stacks (including at least some Intel PXE
  148. * stacks and Etherboot 5.4) fail to generate TX completions.
  149. * In practice this won't be a problem, since our TX datapath
  150. * has a very low packet volume and we can get away with
  151. * assuming that a TX will be complete by the time we want to
  152. * transmit the next packet.
  153. */
  154. /* Copy packet to UNDI I/O buffer */
  155. if ( len > sizeof ( basemem_packet ) )
  156. len = sizeof ( basemem_packet );
  157. memcpy ( &basemem_packet, iobuf->data, len );
  158. /* Create PXENV_UNDI_TRANSMIT data structure */
  159. memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
  160. undi_transmit.DestAddr.segment = rm_ds;
  161. undi_transmit.DestAddr.offset = __from_data16 ( &undinet_tbd );
  162. undi_transmit.TBD.segment = rm_ds;
  163. undi_transmit.TBD.offset = __from_data16 ( &undinet_tbd );
  164. /* Create PXENV_UNDI_TBD data structure */
  165. undinet_tbd.ImmedLength = len;
  166. undinet_tbd.Xmit.segment = rm_ds;
  167. undinet_tbd.Xmit.offset = __from_data16 ( basemem_packet );
  168. /* Issue PXE API call */
  169. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_TRANSMIT,
  170. &undi_transmit,
  171. sizeof ( undi_transmit ) ) ) != 0 )
  172. goto done;
  173. /* Free I/O buffer */
  174. netdev_tx_complete ( netdev, iobuf );
  175. done:
  176. return rc;
  177. }
  178. /**
  179. * Poll for received packets
  180. *
  181. * @v netdev Network device
  182. *
  183. * Fun, fun, fun. UNDI drivers don't use polling; they use
  184. * interrupts. We therefore cheat and pretend that an interrupt has
  185. * occurred every time undinet_poll() is called. This isn't too much
  186. * of a hack; PCI devices share IRQs and so the first thing that a
  187. * proper ISR should do is call PXENV_UNDI_ISR to determine whether or
  188. * not the UNDI NIC generated the interrupt; there is no harm done by
  189. * spurious calls to PXENV_UNDI_ISR. Similarly, we wouldn't be
  190. * handling them any more rapidly than the usual rate of
  191. * undinet_poll() being called even if we did implement a full ISR.
  192. * So it should work. Ha!
  193. *
  194. * Addendum (21/10/03). Some cards don't play nicely with this trick,
  195. * so instead of doing it the easy way we have to go to all the hassle
  196. * of installing a genuine interrupt service routine and dealing with
  197. * the wonderful 8259 Programmable Interrupt Controller. Joy.
  198. *
  199. * Addendum (10/07/07). When doing things such as iSCSI boot, in
  200. * which we have to co-operate with a running OS, we can't get away
  201. * with the "ISR-just-increments-a-counter-and-returns" trick at all,
  202. * because it involves tying up the PIC for far too long, and other
  203. * interrupt-dependent components (e.g. local disks) start breaking.
  204. * We therefore implement a "proper" ISR which calls PXENV_UNDI_ISR
  205. * from within interrupt context in order to deassert the device
  206. * interrupt, and sends EOI if applicable.
  207. */
  208. static void undinet_poll ( struct net_device *netdev ) {
  209. struct undi_nic *undinic = netdev->priv;
  210. struct s_PXENV_UNDI_ISR undi_isr;
  211. struct io_buffer *iobuf = NULL;
  212. size_t len;
  213. size_t frag_len;
  214. size_t max_frag_len;
  215. int rc;
  216. if ( ! undinic->isr_processing ) {
  217. /* Do nothing unless ISR has been triggered */
  218. if ( ! undinet_isr_triggered() ) {
  219. /* Allow interrupt to occur */
  220. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  221. "nop\n\t"
  222. "nop\n\t"
  223. "cli\n\t" ) : : );
  224. return;
  225. }
  226. /* Start ISR processing */
  227. undinic->isr_processing = 1;
  228. undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_PROCESS;
  229. } else {
  230. /* Continue ISR processing */
  231. undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
  232. }
  233. /* Run through the ISR loop */
  234. while ( 1 ) {
  235. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_ISR,
  236. &undi_isr,
  237. sizeof ( undi_isr ) ) ) != 0 )
  238. break;
  239. switch ( undi_isr.FuncFlag ) {
  240. case PXENV_UNDI_ISR_OUT_TRANSMIT:
  241. /* We don't care about transmit completions */
  242. break;
  243. case PXENV_UNDI_ISR_OUT_RECEIVE:
  244. /* Packet fragment received */
  245. len = undi_isr.FrameLength;
  246. frag_len = undi_isr.BufferLength;
  247. if ( ( len == 0 ) || ( len < frag_len ) ) {
  248. /* Don't laugh. VMWare does it. */
  249. DBGC ( undinic, "UNDINIC %p reported insane "
  250. "fragment (%zd of %zd bytes)\n",
  251. undinic, frag_len, len );
  252. netdev_rx_err ( netdev, NULL, -EINVAL );
  253. break;
  254. }
  255. if ( ! iobuf )
  256. iobuf = alloc_iob ( len );
  257. if ( ! iobuf ) {
  258. DBGC ( undinic, "UNDINIC %p could not "
  259. "allocate %zd bytes for RX buffer\n",
  260. undinic, len );
  261. /* Fragment will be dropped */
  262. netdev_rx_err ( netdev, NULL, -ENOMEM );
  263. goto done;
  264. }
  265. max_frag_len = iob_tailroom ( iobuf );
  266. if ( frag_len > max_frag_len ) {
  267. DBGC ( undinic, "UNDINIC %p fragment too big "
  268. "(%zd+%zd does not fit into %zd)\n",
  269. undinic, iob_len ( iobuf ), frag_len,
  270. ( iob_len ( iobuf ) + max_frag_len ) );
  271. frag_len = max_frag_len;
  272. }
  273. copy_from_real ( iob_put ( iobuf, frag_len ),
  274. undi_isr.Frame.segment,
  275. undi_isr.Frame.offset, frag_len );
  276. if ( iob_len ( iobuf ) == len ) {
  277. /* Whole packet received; deliver it */
  278. netdev_rx ( netdev, iob_disown ( iobuf ) );
  279. /* Etherboot 5.4 fails to return all packets
  280. * under mild load; pretend it retriggered.
  281. */
  282. if ( undinic->hacks & UNDI_HACK_EB54 )
  283. --last_trigger_count;
  284. }
  285. break;
  286. case PXENV_UNDI_ISR_OUT_DONE:
  287. /* Processing complete */
  288. undinic->isr_processing = 0;
  289. goto done;
  290. default:
  291. /* Should never happen. VMWare does it routinely. */
  292. DBGC ( undinic, "UNDINIC %p ISR returned invalid "
  293. "FuncFlag %04x\n", undinic, undi_isr.FuncFlag );
  294. undinic->isr_processing = 0;
  295. goto done;
  296. }
  297. undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
  298. }
  299. done:
  300. if ( iobuf ) {
  301. DBGC ( undinic, "UNDINIC %p returned incomplete packet "
  302. "(%zd of %zd)\n", undinic, iob_len ( iobuf ),
  303. ( iob_len ( iobuf ) + iob_tailroom ( iobuf ) ) );
  304. netdev_rx_err ( netdev, iobuf, -EINVAL );
  305. }
  306. }
  307. /**
  308. * Open NIC
  309. *
  310. * @v netdev Net device
  311. * @ret rc Return status code
  312. */
  313. static int undinet_open ( struct net_device *netdev ) {
  314. struct undi_nic *undinic = netdev->priv;
  315. struct s_PXENV_UNDI_SET_STATION_ADDRESS undi_set_address;
  316. struct s_PXENV_UNDI_OPEN undi_open;
  317. int rc;
  318. /* Hook interrupt service routine and enable interrupt */
  319. undinet_hook_isr ( undinic->irq );
  320. enable_irq ( undinic->irq );
  321. send_eoi ( undinic->irq );
  322. /* Set station address. Required for some PXE stacks; will
  323. * spuriously fail on others. Ignore failures. We only ever
  324. * use it to set the MAC address to the card's permanent value
  325. * anyway.
  326. */
  327. memcpy ( undi_set_address.StationAddress, netdev->ll_addr,
  328. sizeof ( undi_set_address.StationAddress ) );
  329. pxeparent_call ( undinet_entry, PXENV_UNDI_SET_STATION_ADDRESS,
  330. &undi_set_address, sizeof ( undi_set_address ) );
  331. /* Open NIC. We ask for promiscuous operation, since it's the
  332. * only way to ask for all multicast addresses. On any
  333. * switched network, it shouldn't really make a difference to
  334. * performance.
  335. */
  336. memset ( &undi_open, 0, sizeof ( undi_open ) );
  337. undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST | FLTR_PRMSCS );
  338. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_OPEN,
  339. &undi_open, sizeof ( undi_open ) ) ) != 0 )
  340. goto err;
  341. DBGC ( undinic, "UNDINIC %p opened\n", undinic );
  342. return 0;
  343. err:
  344. undinet_close ( netdev );
  345. return rc;
  346. }
  347. /**
  348. * Close NIC
  349. *
  350. * @v netdev Net device
  351. */
  352. static void undinet_close ( struct net_device *netdev ) {
  353. struct undi_nic *undinic = netdev->priv;
  354. struct s_PXENV_UNDI_ISR undi_isr;
  355. struct s_PXENV_UNDI_CLOSE undi_close;
  356. int rc;
  357. /* Ensure ISR has exited cleanly */
  358. while ( undinic->isr_processing ) {
  359. undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
  360. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_ISR,
  361. &undi_isr,
  362. sizeof ( undi_isr ) ) ) != 0 )
  363. break;
  364. switch ( undi_isr.FuncFlag ) {
  365. case PXENV_UNDI_ISR_OUT_TRANSMIT:
  366. case PXENV_UNDI_ISR_OUT_RECEIVE:
  367. /* Continue draining */
  368. break;
  369. default:
  370. /* Stop processing */
  371. undinic->isr_processing = 0;
  372. break;
  373. }
  374. }
  375. /* Close NIC */
  376. pxeparent_call ( undinet_entry, PXENV_UNDI_CLOSE,
  377. &undi_close, sizeof ( undi_close ) );
  378. /* Disable interrupt and unhook ISR */
  379. disable_irq ( undinic->irq );
  380. undinet_unhook_isr ( undinic->irq );
  381. DBGC ( undinic, "UNDINIC %p closed\n", undinic );
  382. }
  383. /**
  384. * Enable/disable interrupts
  385. *
  386. * @v netdev Net device
  387. * @v enable Interrupts should be enabled
  388. */
  389. static void undinet_irq ( struct net_device *netdev, int enable ) {
  390. struct undi_nic *undinic = netdev->priv;
  391. /* Cannot support interrupts yet */
  392. DBGC ( undinic, "UNDINIC %p cannot %s interrupts\n",
  393. undinic, ( enable ? "enable" : "disable" ) );
  394. }
  395. /** UNDI network device operations */
  396. static struct net_device_operations undinet_operations = {
  397. .open = undinet_open,
  398. .close = undinet_close,
  399. .transmit = undinet_transmit,
  400. .poll = undinet_poll,
  401. .irq = undinet_irq,
  402. };
  403. /**
  404. * Probe UNDI device
  405. *
  406. * @v undi UNDI device
  407. * @ret rc Return status code
  408. */
  409. int undinet_probe ( struct undi_device *undi ) {
  410. struct net_device *netdev;
  411. struct undi_nic *undinic;
  412. struct s_PXENV_START_UNDI start_undi;
  413. struct s_PXENV_UNDI_STARTUP undi_startup;
  414. struct s_PXENV_UNDI_INITIALIZE undi_initialize;
  415. struct s_PXENV_UNDI_GET_INFORMATION undi_info;
  416. struct s_PXENV_UNDI_GET_IFACE_INFO undi_iface;
  417. struct s_PXENV_UNDI_SHUTDOWN undi_shutdown;
  418. struct s_PXENV_UNDI_CLEANUP undi_cleanup;
  419. struct s_PXENV_STOP_UNDI stop_undi;
  420. int rc;
  421. /* Allocate net device */
  422. netdev = alloc_etherdev ( sizeof ( *undinic ) );
  423. if ( ! netdev )
  424. return -ENOMEM;
  425. netdev_init ( netdev, &undinet_operations );
  426. undinic = netdev->priv;
  427. undi_set_drvdata ( undi, netdev );
  428. netdev->dev = &undi->dev;
  429. memset ( undinic, 0, sizeof ( *undinic ) );
  430. undinet_entry = undi->entry;
  431. DBGC ( undinic, "UNDINIC %p using UNDI %p\n", undinic, undi );
  432. /* Hook in UNDI stack */
  433. if ( ! ( undi->flags & UNDI_FL_STARTED ) ) {
  434. memset ( &start_undi, 0, sizeof ( start_undi ) );
  435. start_undi.AX = undi->pci_busdevfn;
  436. start_undi.BX = undi->isapnp_csn;
  437. start_undi.DX = undi->isapnp_read_port;
  438. start_undi.ES = BIOS_SEG;
  439. start_undi.DI = find_pnp_bios();
  440. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_START_UNDI,
  441. &start_undi,
  442. sizeof ( start_undi ) ) ) != 0 )
  443. goto err_start_undi;
  444. }
  445. undi->flags |= UNDI_FL_STARTED;
  446. /* Bring up UNDI stack */
  447. if ( ! ( undi->flags & UNDI_FL_INITIALIZED ) ) {
  448. memset ( &undi_startup, 0, sizeof ( undi_startup ) );
  449. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_STARTUP,
  450. &undi_startup,
  451. sizeof ( undi_startup ) ) ) != 0 )
  452. goto err_undi_startup;
  453. memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
  454. if ( ( rc = pxeparent_call ( undinet_entry,
  455. PXENV_UNDI_INITIALIZE,
  456. &undi_initialize,
  457. sizeof ( undi_initialize ))) != 0 )
  458. goto err_undi_initialize;
  459. }
  460. undi->flags |= UNDI_FL_INITIALIZED;
  461. /* Get device information */
  462. memset ( &undi_info, 0, sizeof ( undi_info ) );
  463. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_GET_INFORMATION,
  464. &undi_info, sizeof ( undi_info ) ) ) != 0 )
  465. goto err_undi_get_information;
  466. memcpy ( netdev->hw_addr, undi_info.PermNodeAddress, ETH_ALEN );
  467. undinic->irq = undi_info.IntNumber;
  468. if ( undinic->irq > IRQ_MAX ) {
  469. DBGC ( undinic, "UNDINIC %p invalid IRQ %d\n",
  470. undinic, undinic->irq );
  471. goto err_bad_irq;
  472. }
  473. DBGC ( undinic, "UNDINIC %p is %s on IRQ %d\n",
  474. undinic, eth_ntoa ( netdev->hw_addr ), undinic->irq );
  475. /* Get interface information */
  476. memset ( &undi_iface, 0, sizeof ( undi_iface ) );
  477. if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_GET_IFACE_INFO,
  478. &undi_iface,
  479. sizeof ( undi_iface ) ) ) != 0 )
  480. goto err_undi_get_iface_info;
  481. DBGC ( undinic, "UNDINIC %p has type %s, speed %d, flags %08x\n",
  482. undinic, undi_iface.IfaceType, undi_iface.LinkSpeed,
  483. undi_iface.ServiceFlags );
  484. if ( strncmp ( ( ( char * ) undi_iface.IfaceType ), "Etherboot",
  485. sizeof ( undi_iface.IfaceType ) ) == 0 ) {
  486. DBGC ( undinic, "UNDINIC %p Etherboot 5.4 workaround enabled\n",
  487. undinic );
  488. undinic->hacks |= UNDI_HACK_EB54;
  489. }
  490. /* Mark as link up; we don't handle link state */
  491. netdev_link_up ( netdev );
  492. /* Register network device */
  493. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  494. goto err_register;
  495. DBGC ( undinic, "UNDINIC %p added\n", undinic );
  496. return 0;
  497. err_register:
  498. err_undi_get_iface_info:
  499. err_bad_irq:
  500. err_undi_get_information:
  501. err_undi_initialize:
  502. /* Shut down UNDI stack */
  503. memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
  504. pxeparent_call ( undinet_entry, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
  505. sizeof ( undi_shutdown ) );
  506. memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
  507. pxeparent_call ( undinet_entry, PXENV_UNDI_CLEANUP, &undi_cleanup,
  508. sizeof ( undi_cleanup ) );
  509. undi->flags &= ~UNDI_FL_INITIALIZED;
  510. err_undi_startup:
  511. /* Unhook UNDI stack */
  512. memset ( &stop_undi, 0, sizeof ( stop_undi ) );
  513. pxeparent_call ( undinet_entry, PXENV_STOP_UNDI, &stop_undi,
  514. sizeof ( stop_undi ) );
  515. undi->flags &= ~UNDI_FL_STARTED;
  516. err_start_undi:
  517. netdev_nullify ( netdev );
  518. netdev_put ( netdev );
  519. undi_set_drvdata ( undi, NULL );
  520. return rc;
  521. }
  522. /**
  523. * Remove UNDI device
  524. *
  525. * @v undi UNDI device
  526. */
  527. void undinet_remove ( struct undi_device *undi ) {
  528. struct net_device *netdev = undi_get_drvdata ( undi );
  529. struct undi_nic *undinic = netdev->priv;
  530. struct s_PXENV_UNDI_SHUTDOWN undi_shutdown;
  531. struct s_PXENV_UNDI_CLEANUP undi_cleanup;
  532. struct s_PXENV_STOP_UNDI stop_undi;
  533. /* Unregister net device */
  534. unregister_netdev ( netdev );
  535. /* If we are preparing for an OS boot, or if we cannot exit
  536. * via the PXE stack, then shut down the PXE stack.
  537. */
  538. if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
  539. /* Shut down UNDI stack */
  540. memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
  541. pxeparent_call ( undinet_entry, PXENV_UNDI_SHUTDOWN,
  542. &undi_shutdown, sizeof ( undi_shutdown ) );
  543. memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
  544. pxeparent_call ( undinet_entry, PXENV_UNDI_CLEANUP,
  545. &undi_cleanup, sizeof ( undi_cleanup ) );
  546. undi->flags &= ~UNDI_FL_INITIALIZED;
  547. /* Unhook UNDI stack */
  548. memset ( &stop_undi, 0, sizeof ( stop_undi ) );
  549. pxeparent_call ( undinet_entry, PXENV_STOP_UNDI, &stop_undi,
  550. sizeof ( stop_undi ) );
  551. undi->flags &= ~UNDI_FL_STARTED;
  552. }
  553. /* Clear entry point */
  554. memset ( &undinet_entry, 0, sizeof ( undinet_entry ) );
  555. /* Free network device */
  556. netdev_nullify ( netdev );
  557. netdev_put ( netdev );
  558. DBGC ( undinic, "UNDINIC %p removed\n", undinic );
  559. }