Started fixing up compilation warnings.
[people/dverkamp/gpxe.git] / src / drivers / net / mlx_ipoib / mt23108.c
1 /**************************************************************************
2 Etherboot -  BOOTP/TFTP Bootstrap Program
3 Skeleton NIC driver for Etherboot
4 ***************************************************************************/
5
6 /*
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2, or (at
10  * your option) any later version.
11  */
12
13 /* to get some global routines like printf */
14 #include "etherboot.h"
15 /* to get the interface to the body of the program */
16 #include "nic.h"
17
18 #include "mt_version.c"
19 #include "mt23108_imp.c"
20
21 /* NIC specific static variables go here */
22
23 int prompt_key(int secs, unsigned char *ch_p)
24 {
25         unsigned long tmo;
26         unsigned char ch;
27
28         for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
29                 if (iskey()) {
30                         ch = getchar();
31                         /* toupper does not work ... */
32                         if (ch == 'v')
33                                 ch = 'V';
34                         if (ch == 'i')
35                                 ch = 'I';
36                         if ((ch=='V') || (ch=='I')) {
37                                 *ch_p = ch;
38                                 return 1;
39                         }
40                 }
41         }
42
43         return 0;
44 }
45
46 /**************************************************************************
47 IRQ - handle interrupts
48 ***************************************************************************/
49 static void tavor_irq(struct nic *nic, irq_action_t action)
50 {
51         /* This routine is somewhat optional.  Etherboot itself
52          * doesn't use interrupts, but they are required under some
53          * circumstances when we're acting as a PXE stack.
54          *
55          * If you don't implement this routine, the only effect will
56          * be that your driver cannot be used via Etherboot's UNDI
57          * API.  This won't affect programs that use only the UDP
58          * portion of the PXE API, such as pxelinux.
59          */
60
61         if (0) {
62                 nic = NULL;
63         }
64         switch (action) {
65         case DISABLE:
66         case ENABLE:
67                 /* Set receive interrupt enabled/disabled state */
68                 /*
69                    outb ( action == ENABLE ? IntrMaskEnabled : IntrMaskDisabled,
70                    nic->ioaddr + IntrMaskRegister );
71                  */
72                 break;
73         case FORCE:
74                 /* Force NIC to generate a receive interrupt */
75                 /*
76                    outb ( ForceInterrupt, nic->ioaddr + IntrForceRegister );
77                  */
78                 break;
79         }
80 }
81
82 /**************************************************************************
83 POLL - Wait for a frame
84 ***************************************************************************/
85 static int tavor_poll(struct nic *nic, int retrieve)
86 {
87         /* Work out whether or not there's an ethernet packet ready to
88          * read.  Return 0 if not.
89          */
90         /* 
91            if ( ! <packet_ready> ) return 0;
92          */
93
94         /* retrieve==0 indicates that we are just checking for the
95          * presence of a packet but don't want to read it just yet.
96          */
97         /*
98            if ( ! retrieve ) return 1;
99          */
100
101         /* Copy data to nic->packet.  Data should include the
102          * link-layer header (dest MAC, source MAC, type).
103          * Store length of data in nic->packetlen.
104          * Return true to indicate a packet has been read.
105          */
106         /* 
107            nic->packetlen = <packet_length>;
108            memcpy ( nic->packet, <packet_data>, <packet_length> );
109            return 1;
110          */
111         unsigned int size;
112         int rc;
113         rc = poll_imp(nic, retrieve, &size);
114         if (rc) {
115                 return 0;
116         }
117
118         if (size == 0) {
119                 return 0;
120         }
121
122         nic->packetlen = size;
123
124         return 1;
125 }
126
127 /**************************************************************************
128 TRANSMIT - Transmit a frame
129 ***************************************************************************/
130 static void tavor_transmit(struct nic *nic, const char *dest,   /* Destination */
131                            unsigned int type,   /* Type */
132                            unsigned int size,   /* size */
133                            const char *packet)
134 {                               /* Packet */
135         int rc;
136
137         /* Transmit packet to dest MAC address.  You will need to
138          * construct the link-layer header (dest MAC, source MAC,
139          * type).
140          */
141         if (nic) {
142                 rc = transmit_imp(dest, type, packet, size);
143                 if (rc)
144                         eprintf("tranmit error");
145         }
146 }
147
148 /**************************************************************************
149 DISABLE - Turn off ethernet interface
150 ***************************************************************************/
151 static void tavor_disable(struct dev *dev)
152 {
153         /* put the card in its initial state */
154         /* This function serves 3 purposes.
155          * This disables DMA and interrupts so we don't receive
156          *  unexpected packets or interrupts from the card after
157          *  etherboot has finished. 
158          * This frees resources so etherboot may use
159          *  this driver on another interface
160          * This allows etherboot to reinitialize the interface
161          *  if something is something goes wrong.
162          */
163         if (dev || 1) {         // ????
164                 disable_imp();
165         }
166 }
167
168 /**************************************************************************
169 PROBE - Look for an adapter, this routine's visible to the outside
170 ***************************************************************************/
171
172 static int tavor_probe(struct dev *dev, struct pci_device *pci)
173 {
174         struct nic *nic = (struct nic *)dev;
175         int rc;
176         unsigned char user_request;
177
178         if (pci->vendor != MELLANOX_VENDOR_ID) {
179                 eprintf("");
180                 return 0;
181         }
182
183         printf("\n");
184         printf("Mellanox Technologies LTD - Boot over IB implementaion\n");
185         printf("Build version = %s\n\n", build_revision);
186
187         verbose_messages = 0;
188         print_info = 0;
189         printf("Press within 3 seconds:\n");
190         printf("V - to increase verbosity\n");
191         printf("I - to print information\n");
192         if (prompt_key(3, &user_request)) {
193                 if (user_request == 'V') {
194                         printf("User selected verbose messages\n");
195                         verbose_messages = 1;
196                 }
197                 else if (user_request == 'I') {
198                         printf("User selected to print information\n");
199                         print_info = 1;
200                 }
201         }
202         printf("\n");
203
204         adjust_pci_device(pci);
205
206         nic->priv_data = NULL;
207         rc = probe_imp(pci, nic);
208
209         /* give the user a chance to look at the info */
210         if (print_info)
211                 sleep(5);
212
213         if (!rc) {
214                 /* store NIC parameters */
215                 nic->ioaddr = pci->ioaddr & ~3;
216                 nic->irqno = pci->irq;
217                 /* point to NIC specific routines */
218                 dev->disable = tavor_disable;
219                 nic->poll = tavor_poll;
220                 nic->transmit = tavor_transmit;
221                 nic->irq = tavor_irq;
222
223                 return 1;
224         }
225         /* else */
226         return 0;
227 }
228
229 static struct pci_id tavor_nics[] = {
230         PCI_ROM(0x15b3, 0x5a44, "MT23108", "MT23108 HCA driver"),
231         PCI_ROM(0x15b3, 0x6278, "MT25208", "MT25208 HCA driver"),
232 };
233
234 static struct pci_driver tavor_driver __pci_driver = {
235         .type = NIC_DRIVER,
236         .name = "MT23108/MT25208",
237         .probe = tavor_probe,
238         .ids = tavor_nics,
239         .id_count = sizeof(tavor_nics) / sizeof(tavor_nics[0]),
240         .class = 0,
241 };