kni: initial import
[dpdk.git] / lib / librte_eal / linuxapp / kni / ethtool / igb / igb_procfs.c
1 /*******************************************************************************
2
3   Intel(R) Gigabit Ethernet Linux driver
4   Copyright(c) 2007-2012 Intel Corporation.
5
6   This program is free software; you can redistribute it and/or modify it
7   under the terms and conditions of the GNU General Public License,
8   version 2, as published by the Free Software Foundation.
9
10   This program is distributed in the hope it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13   more details.
14
15   You should have received a copy of the GNU General Public License along with
16   this program; if not, write to the Free Software Foundation, Inc.,
17   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21
22   Contact Information:
23   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26 *******************************************************************************/
27
28 #include "igb.h"
29 #include "e1000_82575.h"
30 #include "e1000_hw.h"
31
32 #ifdef IGB_PROCFS
33 #ifndef IGB_SYSFS
34
35 #include <linux/module.h>
36 #include <linux/types.h>
37 #include <linux/proc_fs.h>
38 #include <linux/device.h>
39 #include <linux/netdevice.h>
40
41 static struct proc_dir_entry *igb_top_dir = NULL;
42
43 static struct net_device_stats *procfs_get_stats(struct net_device *netdev)
44 {
45 #ifndef HAVE_NETDEV_STATS_IN_NETDEV
46         struct igb_adapter *adapter;
47 #endif
48         if (netdev == NULL)
49                 return NULL;
50
51 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
52         /* only return the current stats */
53         return &netdev->stats;
54 #else
55         adapter = netdev_priv(netdev);
56
57         /* only return the current stats */
58         return &adapter->net_stats;
59 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
60 }
61
62 bool igb_thermal_present(struct igb_adapter *adapter)
63 {
64         s32 status;
65         struct e1000_hw *hw;
66
67         if (adapter == NULL)
68                 return false;
69         hw = &adapter->hw;
70
71         /*
72          * Only set I2C bit-bang mode if an external thermal sensor is
73          * supported on this device.
74          */
75         if (adapter->ets) {
76                 status = e1000_set_i2c_bb(hw);
77                 if (status != E1000_SUCCESS)
78                         return false;
79         }
80
81         status = hw->mac.ops.init_thermal_sensor_thresh(hw);
82         if (status != E1000_SUCCESS)
83                 return false;
84         
85         return true;
86 }
87
88 static int igb_fwbanner(char *page, char **start, off_t off, int count, 
89                          int *eof, void *data)
90 {
91         struct igb_adapter *adapter = (struct igb_adapter *)data;
92         if (adapter == NULL)
93                 return snprintf(page, count, "error: no adapter\n");
94
95         return snprintf(page, count, "%d.%d-%d\n", 
96                         (adapter->fw_version & 0xF000) >> 12,
97                         (adapter->fw_version & 0x0FF0) >> 4,
98                         adapter->fw_version & 0x000F);
99 }
100
101 static int igb_numeports(char *page, char **start, off_t off, int count, 
102                           int *eof, void *data)
103 {
104         struct e1000_hw *hw;
105         int ports;
106         struct igb_adapter *adapter = (struct igb_adapter *)data;
107         if (adapter == NULL)
108                 return snprintf(page, count, "error: no adapter\n");
109
110         hw = &adapter->hw;
111         if (hw == NULL)
112                 return snprintf(page, count, "error: no hw data\n");
113
114         ports = 4;
115
116         return snprintf(page, count, "%d\n", ports);
117 }
118
119 static int igb_porttype(char *page, char **start, off_t off, int count, 
120                          int *eof, void *data)
121 {
122         struct igb_adapter *adapter = (struct igb_adapter *)data;
123         if (adapter == NULL)
124                 return snprintf(page, count, "error: no adapter\n");
125
126         return snprintf(page, count, "%d\n", 
127                         test_bit(__IGB_DOWN, &adapter->state)); 
128 }
129
130 static int igb_portspeed(char *page, char **start, off_t off, 
131                          int count, int *eof, void *data)
132 {
133         struct igb_adapter *adapter = (struct igb_adapter *)data;
134         int speed = 0;  
135         if (adapter == NULL)
136                 return snprintf(page, count, "error: no adapter\n");
137         
138         switch (adapter->link_speed) {
139         case E1000_STATUS_SPEED_10:
140                 speed = 10;
141                 break;
142         case E1000_STATUS_SPEED_100:
143                 speed = 100;
144                 break;
145         case E1000_STATUS_SPEED_1000:
146                 speed = 1000;
147                 break;
148         }       
149         return snprintf(page, count, "%d\n", speed);
150 }
151
152 static int igb_wqlflag(char *page, char **start, off_t off, int count, 
153                         int *eof, void *data)
154 {
155         struct igb_adapter *adapter = (struct igb_adapter *)data;
156         if (adapter == NULL)
157                 return snprintf(page, count, "error: no adapter\n");
158
159         return snprintf(page, count, "%d\n", adapter->wol);
160 }
161
162 static int igb_xflowctl(char *page, char **start, off_t off, int count, 
163                          int *eof, void *data)
164 {
165         struct e1000_hw *hw;
166         struct igb_adapter *adapter = (struct igb_adapter *)data;
167         if (adapter == NULL)
168                 return snprintf(page, count, "error: no adapter\n");
169
170         hw = &adapter->hw;
171         if (hw == NULL)
172                 return snprintf(page, count, "error: no hw data\n");
173
174         return snprintf(page, count, "%d\n", hw->fc.current_mode);
175 }
176
177 static int igb_rxdrops(char *page, char **start, off_t off, int count, 
178                         int *eof, void *data)
179 {
180         struct igb_adapter *adapter = (struct igb_adapter *)data;
181         struct net_device_stats *net_stats;
182
183         if (adapter == NULL)
184                 return snprintf(page, count, "error: no adapter\n");
185         net_stats  = procfs_get_stats(adapter->netdev);
186         if (net_stats == NULL)
187                 return snprintf(page, count, "error: no net stats\n");
188
189         return snprintf(page, count, "%lu\n", 
190                         net_stats->rx_dropped);
191 }
192
193 static int igb_rxerrors(char *page, char **start, off_t off, int count, 
194                          int *eof, void *data)
195 {
196         struct igb_adapter *adapter = (struct igb_adapter *)data;
197         struct net_device_stats *net_stats;
198
199         if (adapter == NULL)
200                 return snprintf(page, count, "error: no adapter\n");
201         net_stats  = procfs_get_stats(adapter->netdev);
202         if (net_stats == NULL)
203                 return snprintf(page, count, "error: no net stats\n");
204
205         return snprintf(page, count, "%lu\n", net_stats->rx_errors);
206 }
207
208 static int igb_rxupacks(char *page, char **start, off_t off, int count, 
209                          int *eof, void *data)
210 {
211         struct e1000_hw *hw;
212         struct igb_adapter *adapter = (struct igb_adapter *)data;
213         if (adapter == NULL)
214                 return snprintf(page, count, "error: no adapter\n");
215
216         hw = &adapter->hw;
217         if (hw == NULL)
218                 return snprintf(page, count, "error: no hw data\n");
219
220         return snprintf(page, count, "%d\n", E1000_READ_REG(hw, E1000_TPR));
221 }
222
223 static int igb_rxmpacks(char *page, char **start, off_t off, int count, 
224                          int *eof, void *data)
225 {
226         struct e1000_hw *hw;
227         struct igb_adapter *adapter = (struct igb_adapter *)data;
228         if (adapter == NULL)
229                 return snprintf(page, count, "error: no adapter\n");
230
231         hw = &adapter->hw;
232         if (hw == NULL)
233                 return snprintf(page, count, "error: no hw data\n");
234
235         return snprintf(page, count, "%d\n", 
236                         E1000_READ_REG(hw, E1000_MPRC));
237 }
238
239 static int igb_rxbpacks(char *page, char **start, off_t off, int count, 
240                          int *eof, void *data)
241 {
242         struct e1000_hw *hw;
243         struct igb_adapter *adapter = (struct igb_adapter *)data;
244         if (adapter == NULL)
245                 return snprintf(page, count, "error: no adapter\n");
246
247         hw = &adapter->hw;
248         if (hw == NULL)
249                 return snprintf(page, count, "error: no hw data\n");
250
251         return snprintf(page, count, "%d\n", 
252                         E1000_READ_REG(hw, E1000_BPRC));
253 }
254
255 static int igb_txupacks(char *page, char **start, off_t off, int count, 
256                          int *eof, void *data)
257 {
258         struct e1000_hw *hw;
259         struct igb_adapter *adapter = (struct igb_adapter *)data;
260         if (adapter == NULL)
261                 return snprintf(page, count, "error: no adapter\n");
262
263         hw = &adapter->hw;
264         if (hw == NULL)
265                 return snprintf(page, count, "error: no hw data\n");
266
267         return snprintf(page, count, "%d\n", E1000_READ_REG(hw, E1000_TPT));
268 }
269
270 static int igb_txmpacks(char *page, char **start, off_t off, int count, 
271                          int *eof, void *data)
272 {
273         struct e1000_hw *hw;
274         struct igb_adapter *adapter = (struct igb_adapter *)data;
275         if (adapter == NULL)
276                 return snprintf(page, count, "error: no adapter\n");
277
278         hw = &adapter->hw;
279         if (hw == NULL)
280                 return snprintf(page, count, "error: no hw data\n");
281
282         return snprintf(page, count, "%d\n", 
283                         E1000_READ_REG(hw, E1000_MPTC));
284 }
285
286 static int igb_txbpacks(char *page, char **start, off_t off, int count, 
287                          int *eof, void *data)
288 {
289         struct e1000_hw *hw;
290         struct igb_adapter *adapter = (struct igb_adapter *)data;
291         if (adapter == NULL)
292                 return snprintf(page, count, "error: no adapter\n");
293
294         hw = &adapter->hw;
295         if (hw == NULL)
296                 return snprintf(page, count, "error: no hw data\n");
297
298         return snprintf(page, count, "%d\n", 
299                         E1000_READ_REG(hw, E1000_BPTC));
300
301 }
302
303 static int igb_txerrors(char *page, char **start, off_t off, int count, 
304                          int *eof, void *data)
305 {
306         struct igb_adapter *adapter = (struct igb_adapter *)data;
307         struct net_device_stats *net_stats;
308
309         if (adapter == NULL)
310                 return snprintf(page, count, "error: no adapter\n");
311         net_stats  = procfs_get_stats(adapter->netdev);
312         if (net_stats == NULL)
313                 return snprintf(page, count, "error: no net stats\n");
314
315         return snprintf(page, count, "%lu\n", 
316                         net_stats->tx_errors);
317 }
318
319 static int igb_txdrops(char *page, char **start, off_t off, int count, 
320                         int *eof, void *data)
321 {
322         struct igb_adapter *adapter = (struct igb_adapter *)data;
323         struct net_device_stats *net_stats;
324
325         if (adapter == NULL)
326                 return snprintf(page, count, "error: no adapter\n");
327         net_stats  = procfs_get_stats(adapter->netdev);
328         if (net_stats == NULL)
329                 return snprintf(page, count, "error: no net stats\n");
330
331         return snprintf(page, count, "%lu\n", 
332                         net_stats->tx_dropped);
333 }
334
335 static int igb_rxframes(char *page, char **start, off_t off, int count, 
336                          int *eof, void *data)
337 {
338         struct igb_adapter *adapter = (struct igb_adapter *)data;
339         struct net_device_stats *net_stats;
340
341         if (adapter == NULL)
342                 return snprintf(page, count, "error: no adapter\n");
343         net_stats  = procfs_get_stats(adapter->netdev);
344         if (net_stats == NULL)
345                 return snprintf(page, count, "error: no net stats\n");
346
347         return snprintf(page, count, "%lu\n", 
348                         net_stats->rx_packets);
349 }
350
351 static int igb_rxbytes(char *page, char **start, off_t off, int count, 
352                         int *eof, void *data)
353 {
354         struct igb_adapter *adapter = (struct igb_adapter *)data;
355         struct net_device_stats *net_stats;
356
357         if (adapter == NULL)
358                 return snprintf(page, count, "error: no adapter\n");
359         net_stats  = procfs_get_stats(adapter->netdev);
360         if (net_stats == NULL)
361                 return snprintf(page, count, "error: no net stats\n");
362
363         return snprintf(page, count, "%lu\n", 
364                         net_stats->rx_bytes);
365 }
366
367 static int igb_txframes(char *page, char **start, off_t off, int count, 
368                          int *eof, void *data)
369 {
370         struct igb_adapter *adapter = (struct igb_adapter *)data;
371         struct net_device_stats *net_stats;
372
373         if (adapter == NULL)
374                 return snprintf(page, count, "error: no adapter\n");
375         net_stats  = procfs_get_stats(adapter->netdev);
376         if (net_stats == NULL)
377                 return snprintf(page, count, "error: no net stats\n");
378
379         return snprintf(page, count, "%lu\n", 
380                         net_stats->tx_packets);
381 }
382
383 static int igb_txbytes(char *page, char **start, off_t off, int count, 
384                         int *eof, void *data)
385 {
386         struct igb_adapter *adapter = (struct igb_adapter *)data;
387         struct net_device_stats *net_stats;
388
389         if (adapter == NULL)
390                 return snprintf(page, count, "error: no adapter\n");
391         net_stats  = procfs_get_stats(adapter->netdev);
392         if (net_stats == NULL)
393                 return snprintf(page, count, "error: no net stats\n");
394
395         return snprintf(page, count, "%lu\n", 
396                         net_stats->tx_bytes);
397 }
398
399 static int igb_linkstat(char *page, char **start, off_t off, int count, 
400                          int *eof, void *data)
401 {
402         int bitmask = 0;
403         struct e1000_hw *hw;
404         struct igb_adapter *adapter = (struct igb_adapter *)data;
405         if (adapter == NULL)
406                 return snprintf(page, count, "error: no adapter\n");
407
408         hw = &adapter->hw;
409         if (hw == NULL)
410                 return snprintf(page, count, "error: no hw data\n");
411
412         if (test_bit(__IGB_DOWN, &adapter->state)) 
413                 bitmask |= 1;
414
415         if (igb_has_link(adapter))
416                 bitmask |= 2;
417         return snprintf(page, count, "0x%X\n", bitmask);
418 }
419
420 static int igb_funcid(char *page, char **start, off_t off, 
421                       int count, int *eof, void *data)
422 {
423         struct igb_adapter *adapter = (struct igb_adapter *)data;
424         struct net_device* netdev;
425
426         if (adapter == NULL)
427                 return snprintf(page, count, "error: no adapter\n");
428         netdev = adapter->netdev;
429         if (netdev == NULL)
430                 return snprintf(page, count, "error: no net device\n");
431
432         return snprintf(page, count, "0x%lX\n", netdev->base_addr);
433 }
434
435 static int igb_funcvers(char *page, char **start, off_t off, 
436                         int count, int *eof, void *data)
437 {
438         struct igb_adapter *adapter = (struct igb_adapter *)data;
439         struct net_device* netdev;
440
441         if (adapter == NULL)
442                 return snprintf(page, count, "error: no adapter\n");
443         netdev = adapter->netdev;
444         if (netdev == NULL)
445                 return snprintf(page, count, "error: no net device\n");
446
447         return snprintf(page, count, "%s\n", igb_driver_version);
448 }
449
450 static int igb_macburn(char *page, char **start, off_t off, int count, 
451                         int *eof, void *data)
452 {
453         struct e1000_hw *hw;
454         struct igb_adapter *adapter = (struct igb_adapter *)data;
455         if (adapter == NULL)
456                 return snprintf(page, count, "error: no adapter\n");
457
458         hw = &adapter->hw;
459         if (hw == NULL)
460                 return snprintf(page, count, "error: no hw data\n");
461
462         return snprintf(page, count, "0x%X%X%X%X%X%X\n",
463                        (unsigned int)hw->mac.perm_addr[0],
464                        (unsigned int)hw->mac.perm_addr[1],
465                        (unsigned int)hw->mac.perm_addr[2],
466                        (unsigned int)hw->mac.perm_addr[3],
467                        (unsigned int)hw->mac.perm_addr[4],
468                        (unsigned int)hw->mac.perm_addr[5]);
469 }
470
471 static int igb_macadmn(char *page, char **start, off_t off, 
472                        int count, int *eof, void *data)
473 {
474         struct e1000_hw *hw;
475         struct igb_adapter *adapter = (struct igb_adapter *)data;
476         if (adapter == NULL)
477                 return snprintf(page, count, "error: no adapter\n");
478
479         hw = &adapter->hw;
480         if (hw == NULL)
481                 return snprintf(page, count, "error: no hw data\n");
482
483         return snprintf(page, count, "0x%X%X%X%X%X%X\n",
484                        (unsigned int)hw->mac.addr[0],
485                        (unsigned int)hw->mac.addr[1],
486                        (unsigned int)hw->mac.addr[2],
487                        (unsigned int)hw->mac.addr[3],
488                        (unsigned int)hw->mac.addr[4],
489                        (unsigned int)hw->mac.addr[5]);
490 }
491
492 static int igb_maclla1(char *page, char **start, off_t off, int count, 
493                        int *eof, void *data)
494 {
495         struct e1000_hw *hw;
496         u16 eeprom_buff[6];
497         int first_word = 0x37;
498         int word_count = 6;
499         int rc;
500
501         struct igb_adapter *adapter = (struct igb_adapter *)data;
502         if (adapter == NULL)
503                 return snprintf(page, count, "error: no adapter\n");
504
505         hw = &adapter->hw;
506         if (hw == NULL)
507                 return snprintf(page, count, "error: no hw data\n");
508
509         rc = e1000_read_nvm(hw, first_word, word_count, 
510                                            eeprom_buff);
511         if (rc != E1000_SUCCESS)
512                 return 0;
513
514         switch (hw->bus.func) {
515         case 0:
516                 return snprintf(page, count, "0x%04X%04X%04X\n", 
517                                 eeprom_buff[0],
518                                 eeprom_buff[1],
519                                 eeprom_buff[2]);
520         case 1:
521                 return snprintf(page, count, "0x%04X%04X%04X\n", 
522                                 eeprom_buff[3],
523                                 eeprom_buff[4],
524                                 eeprom_buff[5]);
525         }
526         return snprintf(page, count, "unexpected port %d\n", hw->bus.func);
527 }
528
529 static int igb_mtusize(char *page, char **start, off_t off, 
530                        int count, int *eof, void *data)
531 {
532         struct igb_adapter *adapter = (struct igb_adapter *)data;
533         struct net_device* netdev;
534
535         if (adapter == NULL)
536                 return snprintf(page, count, "error: no adapter\n");
537         netdev = adapter->netdev;
538         if (netdev == NULL)
539                 return snprintf(page, count, "error: no net device\n");
540
541         return snprintf(page, count, "%d\n", netdev->mtu);
542 }
543
544 static int igb_featflag(char *page, char **start, off_t off, int count, 
545                          int *eof, void *data)
546 {
547         int bitmask = 0;
548 #ifndef HAVE_NDO_SET_FEATURES
549         struct igb_ring *ring;
550 #endif
551         struct igb_adapter *adapter = (struct igb_adapter *)data;
552         struct net_device *netdev;      
553
554         if (adapter == NULL)
555                 return snprintf(page, count, "error: no adapter\n");
556         netdev = adapter->netdev;
557         if (netdev == NULL)
558                 return snprintf(page, count, "error: no net device\n");
559
560 #ifndef HAVE_NDO_SET_FEATURES
561         /* igb_get_rx_csum(netdev) doesn't compile so hard code */
562         ring = adapter->rx_ring[0];
563         bitmask = test_bit(IGB_RING_FLAG_RX_CSUM, &ring->flags);        
564         return snprintf(page, count, "%d\n", bitmask);
565 #else
566         if (netdev->features & NETIF_F_RXCSUM)
567                 bitmask |= 1;
568         return snprintf(page, count, "%d\n", bitmask);
569 #endif
570 }
571
572 static int igb_lsominct(char *page, char **start, off_t off, int count, 
573                          int *eof, void *data)
574 {
575         return snprintf(page, count, "%d\n", 1);
576 }
577
578 static int igb_prommode(char *page, char **start, off_t off, int count, 
579                          int *eof, void *data)
580 {
581         struct igb_adapter *adapter = (struct igb_adapter *)data;
582         struct net_device *netdev;      
583
584         if (adapter == NULL)
585                 return snprintf(page, count, "error: no adapter\n");
586         netdev = adapter->netdev;
587         if (netdev == NULL)
588                 return snprintf(page, count, "error: no net device\n");
589
590         return snprintf(page, count, "%d\n", 
591                         netdev->flags & IFF_PROMISC);
592 }
593
594 static int igb_txdscqsz(char *page, char **start, off_t off, int count, 
595                             int *eof, void *data)
596 {
597         struct igb_adapter *adapter = (struct igb_adapter *)data;
598         if (adapter == NULL)
599                 return snprintf(page, count, "error: no adapter\n");
600
601         return snprintf(page, count, "%d\n", adapter->tx_ring[0]->count);
602 }
603
604 static int igb_rxdscqsz(char *page, char **start, off_t off, int count, 
605                             int *eof, void *data)
606 {
607         struct igb_adapter *adapter = (struct igb_adapter *)data;
608         if (adapter == NULL)
609                 return snprintf(page, count, "error: no adapter\n");
610
611         return snprintf(page, count, "%d\n", adapter->rx_ring[0]->count);
612 }
613
614 static int igb_rxqavg(char *page, char **start, off_t off, int count, 
615                        int *eof, void *data)
616 {
617         int index;
618         int totaldiff = 0;
619         u16 ntc;
620         u16 ntu;
621         struct igb_adapter *adapter = (struct igb_adapter *)data;
622         if (adapter == NULL)
623                 return snprintf(page, count, "error: no adapter\n");
624
625         if (adapter->num_rx_queues <= 0)
626                 return snprintf(page, count,
627                                 "can't calculate, number of queues %d\n",
628                                 adapter->num_rx_queues);
629
630         for (index = 0; index < adapter->num_rx_queues; index++) {
631                 ntc = adapter->rx_ring[index]->next_to_clean;
632                 ntu = adapter->rx_ring[index]->next_to_use;
633
634                 if (ntc >= ntu)
635                         totaldiff += (ntc - ntu);
636                 else
637                         totaldiff += (adapter->rx_ring[index]->count 
638                                       - ntu + ntc);
639         }
640         if (adapter->num_rx_queues <= 0)
641                 return snprintf(page, count, 
642                                 "can't calculate, number of queues %d\n", 
643                                 adapter->num_rx_queues);                
644         return snprintf(page, count, "%d\n", totaldiff/adapter->num_rx_queues);
645 }
646
647 static int igb_txqavg(char *page, char **start, off_t off, int count, 
648                        int *eof, void *data)
649 {
650         int index;
651         int totaldiff = 0;
652         u16 ntc;
653         u16 ntu;
654         struct igb_adapter *adapter = (struct igb_adapter *)data;
655         if (adapter == NULL)
656                 return snprintf(page, count, "error: no adapter\n");
657
658         if (adapter->num_tx_queues <= 0)
659                 return snprintf(page, count,
660                                 "can't calculate, number of queues %d\n",
661                                 adapter->num_tx_queues);
662
663         for (index = 0; index < adapter->num_tx_queues; index++) {
664                 ntc = adapter->tx_ring[index]->next_to_clean;
665                 ntu = adapter->tx_ring[index]->next_to_use;
666
667                 if (ntc >= ntu)
668                         totaldiff += (ntc - ntu);
669                 else
670                         totaldiff += (adapter->tx_ring[index]->count 
671                                       - ntu + ntc);
672         }
673         if (adapter->num_tx_queues <= 0)
674                 return snprintf(page, count, 
675                                 "can't calculate, number of queues %d\n", 
676                                 adapter->num_tx_queues);                
677         return snprintf(page, count, "%d\n", 
678                         totaldiff/adapter->num_tx_queues);
679 }
680
681 static int igb_iovotype(char *page, char **start, off_t off, int count, 
682                           int *eof, void *data)
683 {
684         return snprintf(page, count, "2\n");
685 }
686
687 static int igb_funcnbr(char *page, char **start, off_t off, int count, 
688                          int *eof, void *data)
689 {
690         struct igb_adapter *adapter = (struct igb_adapter *)data;
691         if (adapter == NULL)
692                 return snprintf(page, count, "error: no adapter\n");
693
694         return snprintf(page, count, "%d\n", adapter->vfs_allocated_count);
695 }
696
697 static int igb_therm_location(char *page, char **start, off_t off, 
698                                      int count, int *eof, void *data)
699 {
700         struct igb_therm_proc_data *therm_data =
701                 (struct igb_therm_proc_data *)data;
702
703         if (therm_data == NULL)
704                 return snprintf(page, count, "error: no therm_data\n");
705
706         return snprintf(page, count, "%d\n", therm_data->sensor_data->location);
707 }
708
709 static int igb_therm_maxopthresh(char *page, char **start, off_t off, 
710                                     int count, int *eof, void *data)
711 {
712         struct igb_therm_proc_data *therm_data =
713                 (struct igb_therm_proc_data *)data;
714
715         if (therm_data == NULL)
716                 return snprintf(page, count, "error: no therm_data\n");
717
718         return snprintf(page, count, "%d\n",
719                         therm_data->sensor_data->max_op_thresh);
720 }
721
722 static int igb_therm_cautionthresh(char *page, char **start, off_t off, 
723                                       int count, int *eof, void *data)
724 {
725         struct igb_therm_proc_data *therm_data =
726                 (struct igb_therm_proc_data *)data;
727
728         if (therm_data == NULL)
729                 return snprintf(page, count, "error: no therm_data\n");
730
731         return snprintf(page, count, "%d\n",
732                         therm_data->sensor_data->caution_thresh);
733 }
734
735 static int igb_therm_temp(char *page, char **start, off_t off, 
736                              int count, int *eof, void *data)
737 {
738         s32 status;
739         struct igb_therm_proc_data *therm_data =
740                 (struct igb_therm_proc_data *)data;
741
742         if (therm_data == NULL)
743                 return snprintf(page, count, "error: no therm_data\n");
744
745         status = e1000_get_thermal_sensor_data(therm_data->hw);
746         if (status != E1000_SUCCESS)
747                 snprintf(page, count, "error: status %d returned\n", status);
748
749         return snprintf(page, count, "%d\n", therm_data->sensor_data->temp);
750 }
751
752 struct igb_proc_type{
753         char name[32];
754         int (*read)(char*, char**, off_t, int, int*, void*);
755 };
756
757 struct igb_proc_type igb_proc_entries[] = {
758         {"fwbanner", &igb_fwbanner},
759         {"numeports", &igb_numeports},
760         {"porttype", &igb_porttype},
761         {"portspeed", &igb_portspeed},
762         {"wqlflag", &igb_wqlflag},
763         {"xflowctl", &igb_xflowctl},
764         {"rxdrops", &igb_rxdrops},
765         {"rxerrors", &igb_rxerrors},
766         {"rxupacks", &igb_rxupacks},
767         {"rxmpacks", &igb_rxmpacks},
768         {"rxbpacks", &igb_rxbpacks}, 
769         {"txdrops", &igb_txdrops},
770         {"txerrors", &igb_txerrors},
771         {"txupacks", &igb_txupacks},
772         {"txmpacks", &igb_txmpacks},
773         {"txbpacks", &igb_txbpacks},
774         {"rxframes", &igb_rxframes},
775         {"rxbytes", &igb_rxbytes},
776         {"txframes", &igb_txframes},
777         {"txbytes", &igb_txbytes},
778         {"linkstat", &igb_linkstat},
779         {"funcid", &igb_funcid},
780         {"funcvers", &igb_funcvers},
781         {"macburn", &igb_macburn},
782         {"macadmn", &igb_macadmn},
783         {"maclla1", &igb_maclla1},
784         {"mtusize", &igb_mtusize},
785         {"featflag", &igb_featflag},
786         {"lsominct", &igb_lsominct},
787         {"prommode", &igb_prommode},
788         {"txdscqsz", &igb_txdscqsz},
789         {"rxdscqsz", &igb_rxdscqsz},
790         {"txqavg", &igb_txqavg},
791         {"rxqavg", &igb_rxqavg},
792         {"iovotype", &igb_iovotype},
793         {"funcnbr", &igb_funcnbr},
794         {"", NULL}
795 };
796
797 struct igb_proc_type igb_internal_entries[] = {
798         {"location", &igb_therm_location},
799         {"temp", &igb_therm_temp},
800         {"cautionthresh", &igb_therm_cautionthresh},
801         {"maxopthresh", &igb_therm_maxopthresh},        
802         {"", NULL}
803 };
804
805 void igb_del_proc_entries(struct igb_adapter *adapter)
806 {
807         int index, i;
808         char buf[16];   /* much larger than the sensor number will ever be */
809
810         if (igb_top_dir == NULL)
811                 return;
812
813         for (i = 0; i < E1000_MAX_SENSORS; i++) {
814                 if (adapter->therm_dir[i] == NULL)
815                         continue;
816
817                 for (index = 0; ; index++) {
818                         if (igb_internal_entries[index].read == NULL)
819                                 break;
820
821                          remove_proc_entry(igb_internal_entries[index].name,
822                                            adapter->therm_dir[i]);
823                 }
824                 snprintf(buf, sizeof(buf), "sensor_%d", i);
825                 remove_proc_entry(buf, adapter->info_dir);
826         }
827
828         if (adapter->info_dir != NULL) {
829                 for (index = 0; ; index++) {
830                         if (igb_proc_entries[index].read == NULL)
831                                 break;
832                         remove_proc_entry(igb_proc_entries[index].name,
833                                           adapter->info_dir); 
834                 }
835                 remove_proc_entry("info", adapter->eth_dir);
836         }
837
838         if (adapter->eth_dir != NULL)
839                 remove_proc_entry(pci_name(adapter->pdev), igb_top_dir);
840 }
841
842 /* called from igb_main.c */
843 void igb_procfs_exit(struct igb_adapter *adapter) 
844 {
845         igb_del_proc_entries(adapter);
846 }
847
848 int igb_procfs_topdir_init(void) 
849 {
850         igb_top_dir = proc_mkdir("driver/igb", NULL);
851         if (igb_top_dir == NULL)
852                 return (-ENOMEM);
853
854         return 0;
855 }
856
857 void igb_procfs_topdir_exit(void) 
858 {
859 //      remove_proc_entry("driver", proc_root_driver);
860         remove_proc_entry("driver/igb", NULL);
861 }
862
863 /* called from igb_main.c */
864 int igb_procfs_init(struct igb_adapter *adapter) 
865 {
866         int rc = 0;
867         int i;
868         int index;
869         char buf[16];   /* much larger than the sensor number will ever be */
870
871         adapter->eth_dir = NULL;
872         adapter->info_dir = NULL;
873         for (i = 0; i < E1000_MAX_SENSORS; i++)
874                 adapter->therm_dir[i] = NULL;
875
876         if ( igb_top_dir == NULL ) {
877                 rc = -ENOMEM;
878                 goto fail;
879         }
880
881         adapter->eth_dir = proc_mkdir(pci_name(adapter->pdev), igb_top_dir);
882         if (adapter->eth_dir == NULL) {
883                 rc = -ENOMEM;
884                 goto fail;
885         }
886
887         adapter->info_dir = proc_mkdir("info", adapter->eth_dir);
888         if (adapter->info_dir == NULL) {
889                 rc = -ENOMEM;
890                 goto fail;
891         }
892         for (index = 0; ; index++) {
893                 if (igb_proc_entries[index].read == NULL) {
894                         break;
895                 }
896                 if (!(create_proc_read_entry(igb_proc_entries[index].name, 
897                                            0444, 
898                                            adapter->info_dir, 
899                                            igb_proc_entries[index].read, 
900                                            adapter))) {
901
902                         rc = -ENOMEM;
903                         goto fail;
904                 }
905         }
906         if (igb_thermal_present(adapter) == false)
907                 goto exit;
908
909         for (i = 0; i < E1000_MAX_SENSORS; i++) {
910
911                  if (adapter->hw.mac.thermal_sensor_data.sensor[i].location== 0)
912                         continue;
913
914                 snprintf(buf, sizeof(buf), "sensor_%d", i);
915                 adapter->therm_dir[i] = proc_mkdir(buf, adapter->info_dir);
916                 if (adapter->therm_dir[i] == NULL) {
917                         rc = -ENOMEM;
918                         goto fail;
919                 }
920                 for (index = 0; ; index++) {
921                         if (igb_internal_entries[index].read == NULL)
922                                 break;
923                         /*
924                          * therm_data struct contains pointer the read func
925                          * will be needing
926                          */
927                         adapter->therm_data[i].hw = &adapter->hw;
928                         adapter->therm_data[i].sensor_data = 
929                                 &adapter->hw.mac.thermal_sensor_data.sensor[i];
930
931                         if (!(create_proc_read_entry(
932                                            igb_internal_entries[index].name, 
933                                            0444, 
934                                            adapter->therm_dir[i], 
935                                            igb_internal_entries[index].read, 
936                                            &adapter->therm_data[i]))) {
937                                 rc = -ENOMEM;
938                                 goto fail;
939                         }
940                 }
941         }
942         goto exit;
943
944 fail:
945         igb_del_proc_entries(adapter);
946 exit:
947         return rc;
948 }
949
950 #endif /* !IGB_SYSFS */
951 #endif /* IGB_PROCFS */