[image] Allow for zero embedded images
[people/asdlkf/gpxe.git] / src / drivers / net / mlx_ipoib / mt23108_imp.c
1 typedef uint32_t __u32;
2 typedef uint16_t __u16;
3 typedef uint8_t __u8;
4
5 static int verbose_messages=0;
6 static int print_info=0;
7 static int fatal_condition=0;
8 static int fw_fatal;
9
10 #define tprintf(fmt, a...) \
11                  do {    \
12                         if ( verbose_messages ) { \
13                                 printf("%s:%d: " fmt "\n", __func__, __LINE__,  ##a); \
14                         } \
15                  } \
16                  while(0)
17
18 #define eprintf(fmt, a...) \
19                  printf("%s:%d: " fmt "\n", __func__, __LINE__,  ##a)
20
21 static void cpu_to_be_buf(void *buf, int size)
22 {
23         int dw_sz = size >> 2, i;
24
25         for (i = 0; i < dw_sz; ++i) {
26                 ((__u32 *) buf)[i] = cpu_to_be32(((__u32 *) buf)[i]);
27         }
28 }
29
30 static void be_to_cpu_buf(void *buf, int size)
31 {
32         int dw_sz = size >> 2, i;
33         u32 *p = buf;
34
35         for (i = 0; i < dw_sz; ++i) {
36                 p[i] = be32_to_cpu(p[i]);
37         }
38 }
39
40 #include "cmdif_mt23108.c"
41 #include "cmdif_comm.c"
42 #include "ib_mt23108.c"
43 #include "ib_mad.c"
44 #include "ib_driver.c"
45 #include "ipoib.c"
46
47 static int probe_imp(struct pci_device *pci, struct nic *nic)
48 {
49         int rc;
50
51         if (0 && nic) {         /* just to supress warning */
52                 return 0;
53         }
54
55         fatal_condition= 0;
56         fw_fatal= 0;
57
58         tprintf("");
59         rc = ipoib_init(pci);
60         if (rc)
61                 return rc;
62
63         tprintf("");
64
65         return rc;
66 }
67
68 static int disable_imp(void)
69 {
70         int rc;
71
72         rc = ipoib_close(fw_fatal);
73
74         return rc;
75 }
76
77 static int transmit_imp(const char *dest,       /* Destination */
78                         unsigned int type,      /* Type */
79                         const char *packet,     /* Packet */
80                         unsigned int size)
81 {                               /* size */
82         int rc;
83
84         if (fatal_condition) {
85                 /* since the transmit function does not return a value
86                    we return success but do nothing to suppress error messages */
87                 return 0;
88         }
89
90         rc = ipoib_send_packet(dest, type, packet, size);
91         if (rc) {
92                 printf("*** ERROR IN SEND FLOW ***\n");
93                 printf("restarting Etherboot\n");
94                 sleep(1);
95                 longjmp(restart_etherboot, -1);
96                 /* we should not be here ... */
97                 return -1; 
98         }
99
100         return rc;
101 }
102
103 static void hd(void *where, int n)
104 {
105         int i;
106
107         while (n > 0) {
108                 printf("%X ", where);
109                 for (i = 0; i < ((n > 16) ? 16 : n); i++)
110                         printf(" %hhX", ((char *)where)[i]);
111                 printf("\n");
112                 n -= 16;
113                 where += 16;
114         }
115 }
116
117 static int poll_imp(struct nic *nic, int retrieve, unsigned int *size_p)
118 {
119         static char packet[2048];
120         static char *last_packet_p = NULL;
121         static unsigned long last_packet_size;
122         char *packet_p;
123         const int eth_header_len = 14;
124         unsigned int packet_len;
125         int is_bcast = 0;
126         __u16 prot, *ptr;
127         int rc;
128
129         if (0 && nic) {         /* just to supress warning */
130                 return -1;
131         }
132
133         if (fatal_condition) {
134                 *size_p = 0;
135                 return 0;
136         }
137
138         if (poll_error_buf()) {
139                 fatal_condition= 1;
140                 fw_fatal= 1;
141                 printf("\n *** DEVICE FATAL ERROR ***\n");
142                 goto fatal_handling;
143         }
144         else if (drain_eq()) {
145                 fatal_condition= 1;
146                 printf("\n *** FATAL ERROR ***\n");
147                 goto fatal_handling;
148         }
149
150
151         if (retrieve) {
152                 /* we actually want to read the packet */
153                 if (last_packet_p) {
154                         eprintf("");
155                         /* there is already a packet that was previously read */
156                         memcpy(nic->packet, last_packet_p, last_packet_size);
157                         *size_p = last_packet_size;
158                         last_packet_p = NULL;
159                         return 0;
160                 }
161                 packet_p = nic->packet;
162         } else {
163                 /* we don't want to read the packet,
164                    just know if there is one. so we
165                    read the packet to a local buffer and
166                    we will return that buffer when the ip layer wants
167                    another packet */
168                 if (last_packet_p) {
169                         /* there is already a packet that
170                            was not consumend */
171                         eprintf("overflow receive packets");
172                         return -1;
173                 }
174                 packet_p = packet;
175         }
176
177         rc = ipoib_read_packet(&prot, packet_p + eth_header_len, &packet_len,
178                                &is_bcast);
179         if (rc) {
180                 printf("*** FATAL IN RECEIVE FLOW ****\n");
181                 goto fatal_handling;
182         }
183
184         if (packet_len == 0) {
185                 *size_p = 0;
186                 return 0;
187         }
188
189         if (is_bcast) {
190                 int i;
191                 for (i = 0; i < 6; ++i) {
192                         packet_p[i] = 0xff;
193                 }
194         } else {
195                 packet_p[0] = MLX_ETH_BYTE0;
196                 packet_p[1] = MLX_ETH_BYTE1;
197                 packet_p[2] = MLX_ETH_BYTE2;
198                 packet_p[3] = 0;
199                 packet_p[4] = 0;
200                 packet_p[5] = 0;
201         }
202
203         memset(packet_p + 6, 0, 6);
204
205         ptr = (__u16 *) (packet_p + 12);
206         *ptr = htons(prot);
207
208         if (!retrieve) {
209                 last_packet_p = packet;
210                 last_packet_size = packet_len + eth_header_len;
211                 *size_p = 0;
212         }
213
214         *size_p = packet_len + eth_header_len;
215         tprintf("packet size=%d, prot=%x\n", *size_p, prot);
216         if (0) {
217                 hd(nic->packet, 42);
218         }
219
220         return 0;
221
222 fatal_handling:
223         printf("restarting Etherboot\n");
224         sleep(1);
225         longjmp(restart_etherboot, -1);
226         /* we should not be here ... */
227         return -1; 
228         
229 }