Adding upstream version 4.01+dfsg.
[syslinux-debian/hramrach.git] / core / fs / pxe / idle.c
blob52a87c3400130d716e27a95e5c8170c866f7d7a3
1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
9 * Boston MA 02110-1301, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
14 #include <stdio.h>
15 #include <string.h>
16 #include <core.h>
17 #include <fs.h>
18 #include <minmax.h>
19 #include <sys/cpu.h>
20 #include "pxe.h"
22 static int pxe_idle_poll(void)
24 static __lowmem char junk_pkt[PKTBUF_SIZE];
25 static __lowmem t_PXENV_UDP_READ read_buf;
27 memset(&read_buf, 0, sizeof read_buf);
29 read_buf.src_ip = 0; /* Any destination */
30 read_buf.dest_ip = IPInfo.myip;
31 read_buf.s_port = 0; /* Any source port */
32 read_buf.d_port = htons(9); /* Discard port (not used...) */
33 read_buf.buffer_size = sizeof junk_pkt;
34 read_buf.buffer = FAR_PTR(junk_pkt);
36 pxe_call(PXENV_UDP_READ, &read_buf);
38 return 0;
41 static uint32_t pxe_detect_nic_type(void)
43 static __lowmem t_PXENV_UNDI_GET_NIC_TYPE nic_type;
45 if (pxe_call(PXENV_UNDI_GET_NIC_TYPE, &nic_type))
46 return -1; /* Unknown NIC */
48 if (nic_type.NicType != PCI_NIC && nic_type.NicType != CardBus_NIC)
49 return -1; /* Not a PCI NIC */
52 * Return VID:DID as a single number, with the VID in the high word
53 * -- this is opposite from the usual order, but it makes it easier to
54 * enforce that the table is sorted.
56 return (nic_type.info.pci.Vendor_ID << 16) + nic_type.info.pci.Dev_ID;
59 #define PCI_DEV(vid, did) (((vid) << 16) + (did))
61 /* This array should be sorted!! */
62 static const uint32_t pxe_need_idle_drain[] =
65 * Older Broadcom NICs: they need receive calls on idle to avoid
66 * FIFO stalls.
68 PCI_DEV(0x14e4, 0x1659), /* BCM5721 */
69 PCI_DEV(0x14e4, 0x165a), /* BCM5722 */
70 PCI_DEV(0x14e4, 0x165b), /* BCM5723 */
71 PCI_DEV(0x14e4, 0x1668), /* BCM5714 */
72 PCI_DEV(0x14e4, 0x1669), /* BCM5714S */
73 PCI_DEV(0x14e4, 0x166a), /* BCM5780 */
74 PCI_DEV(0x14e4, 0x1673), /* BCM5755M */
75 PCI_DEV(0x14e4, 0x1674), /* BCM5756ME */
76 PCI_DEV(0x14e4, 0x1678), /* BCM5715 */
77 PCI_DEV(0x14e4, 0x1679), /* BCM5715S */
78 PCI_DEV(0x14e4, 0x167b), /* BCM5755 */
81 void pxe_idle_init(void)
83 uint32_t dev_id = pxe_detect_nic_type();
84 int l, h;
85 bool found;
87 l = 0;
88 h = sizeof pxe_need_idle_drain / sizeof pxe_need_idle_drain[0] - 1;
90 found = false;
91 while (h >= l) {
92 int x = (l+h) >> 1;
93 uint32_t id = pxe_need_idle_drain[x];
95 if (id == dev_id) {
96 found = true;
97 break;
98 } else if (id < dev_id) {
99 l = x+1;
100 } else {
101 h = x-1;
105 if (found)
106 idle_hook_func = pxe_idle_poll;
109 void pxe_idle_cleanup(void)
111 idle_hook_func = NULL;