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 19KB

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