1
/*******************************************************************************
3
Intel 10 Gigabit PCI Express Linux driver
4
Copyright(c) 1999 - 2012 Intel Corporation.
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.
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
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.
19
The full GNU General Public License is included in this distribution in
20
the file called "COPYING".
23
e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
*******************************************************************************/
29
#include "ixgbe_common.h"
30
#include "ixgbe_type.h"
34
#include <linux/module.h>
35
#include <linux/types.h>
36
#include <linux/sysfs.h>
37
#include <linux/kobject.h>
38
#include <linux/device.h>
39
#include <linux/netdevice.h>
42
* This file provides a sysfs interface to export information from the
43
* driver. The information presented is READ-ONLY.
46
static struct net_device_stats *sysfs_get_stats(struct net_device *netdev)
48
#ifndef HAVE_NETDEV_STATS_IN_NETDEV
49
struct ixgbe_adapter *adapter;
54
#ifdef HAVE_NETDEV_STATS_IN_NETDEV
55
/* only return the current stats */
56
return &netdev->stats;
58
adapter = netdev_priv(netdev);
60
/* only return the current stats */
61
return &adapter->net_stats;
62
#endif /* HAVE_NETDEV_STATS_IN_NETDEV */
65
static struct net_device *ixgbe_get_netdev(struct kobject *kobj)
67
struct net_device *netdev;
68
struct kobject *parent = kobj->parent;
69
struct device *device_info_kobj;
74
device_info_kobj = container_of(parent, struct device, kobj);
75
if (device_info_kobj == NULL)
78
netdev = container_of(device_info_kobj, struct net_device, dev);
82
static struct ixgbe_adapter *ixgbe_get_adapter(struct kobject *kobj)
84
struct ixgbe_adapter *adapter;
85
struct net_device *netdev = ixgbe_get_netdev(kobj);
88
adapter = netdev_priv(netdev);
92
static bool ixgbe_thermal_present(struct kobject *kobj)
95
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
100
status = ixgbe_init_thermal_sensor_thresh_generic(&(adapter->hw));
108
* ixgbe_name_to_idx - Convert the directory name to the sensor offset.
109
* @ c: pointer to the directory name string
111
* The directory name is in the form "sensor_n" where n is '0' -
112
* 'IXGBE_MAX_SENSORS'. IXGBE_MAX_SENSORS will never be greater than
113
* 9. This function takes advantage of that to keep it simple.
115
static int ixgbe_name_to_idx(const char *c)
117
/* find first digit */
118
while (*c < '0' || *c > '9') {
124
return ((int)(*c - '0'));
127
static ssize_t ixgbe_fwbanner(struct kobject *kobj,
128
struct kobj_attribute *attr, char *buf)
130
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
134
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
135
nvm_track_id = (adapter->eeprom_verh << 16) | adapter->eeprom_verl;
137
return snprintf(buf, PAGE_SIZE, "0x%08x\n", nvm_track_id);
140
static ssize_t ixgbe_porttype(struct kobject *kobj,
141
struct kobj_attribute *attr, char *buf)
143
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
145
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
146
return snprintf(buf, PAGE_SIZE, "%d\n",
147
test_bit(__IXGBE_DOWN, &adapter->state));
150
static ssize_t ixgbe_portspeed(struct kobject *kobj,
151
struct kobj_attribute *attr, char *buf)
153
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
157
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
159
switch (adapter->link_speed) {
160
case IXGBE_LINK_SPEED_100_FULL:
163
case IXGBE_LINK_SPEED_1GB_FULL:
166
case IXGBE_LINK_SPEED_10GB_FULL:
170
return snprintf(buf, PAGE_SIZE, "%d\n", speed);
173
static ssize_t ixgbe_wqlflag(struct kobject *kobj,
174
struct kobj_attribute *attr, char *buf)
176
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
178
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
180
return snprintf(buf, PAGE_SIZE, "%d\n", adapter->wol);
183
static ssize_t ixgbe_xflowctl(struct kobject *kobj,
184
struct kobj_attribute *attr, char *buf)
186
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
190
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
194
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
196
return snprintf(buf, PAGE_SIZE, "%d\n", hw->fc.current_mode);
199
static ssize_t ixgbe_rxdrops(struct kobject *kobj,
200
struct kobj_attribute *attr, char *buf)
202
struct net_device_stats *net_stats;
203
struct net_device *netdev = ixgbe_get_netdev(kobj);
205
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
207
net_stats = sysfs_get_stats(netdev);
208
if (net_stats == NULL)
209
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
211
return snprintf(buf, PAGE_SIZE, "%lu\n",
212
net_stats->rx_dropped);
215
static ssize_t ixgbe_rxerrors(struct kobject *kobj,
216
struct kobj_attribute *attr, char *buf)
218
struct net_device_stats *net_stats;
219
struct net_device *netdev = ixgbe_get_netdev(kobj);
221
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
223
net_stats = sysfs_get_stats(netdev);
224
if (net_stats == NULL)
225
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
226
return snprintf(buf, PAGE_SIZE, "%lu\n", net_stats->rx_errors);
229
static ssize_t ixgbe_rxupacks(struct kobject *kobj,
230
struct kobj_attribute *attr, char *buf)
233
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
235
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
239
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
241
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_TPR));
244
static ssize_t ixgbe_rxmpacks(struct kobject *kobj,
245
struct kobj_attribute *attr, char *buf)
248
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
250
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
254
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
256
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_MPRC));
259
static ssize_t ixgbe_rxbpacks(struct kobject *kobj,
260
struct kobj_attribute *attr, char *buf)
263
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
265
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
269
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
271
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_BPRC));
274
static ssize_t ixgbe_txupacks(struct kobject *kobj,
275
struct kobj_attribute *attr, char *buf)
278
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
280
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
284
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
286
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_TPT));
289
static ssize_t ixgbe_txmpacks(struct kobject *kobj,
290
struct kobj_attribute *attr, char *buf)
293
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
295
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
299
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
301
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_MPTC));
304
static ssize_t ixgbe_txbpacks(struct kobject *kobj,
305
struct kobj_attribute *attr, char *buf)
308
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
310
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
314
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
316
return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_BPTC));
319
static ssize_t ixgbe_txerrors(struct kobject *kobj,
320
struct kobj_attribute *attr, char *buf)
322
struct net_device_stats *net_stats;
323
struct net_device *netdev = ixgbe_get_netdev(kobj);
325
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
327
net_stats = sysfs_get_stats(netdev);
328
if (net_stats == NULL)
329
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
331
return snprintf(buf, PAGE_SIZE, "%lu\n",
332
net_stats->tx_errors);
335
static ssize_t ixgbe_txdrops(struct kobject *kobj,
336
struct kobj_attribute *attr, char *buf)
338
struct net_device_stats *net_stats;
339
struct net_device *netdev = ixgbe_get_netdev(kobj);
341
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
343
net_stats = sysfs_get_stats(netdev);
344
if (net_stats == NULL)
345
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
346
return snprintf(buf, PAGE_SIZE, "%lu\n",
347
net_stats->tx_dropped);
350
static ssize_t ixgbe_rxframes(struct kobject *kobj,
351
struct kobj_attribute *attr, char *buf)
353
struct net_device_stats *net_stats;
354
struct net_device *netdev = ixgbe_get_netdev(kobj);
356
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
358
net_stats = sysfs_get_stats(netdev);
359
if (net_stats == NULL)
360
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
362
return snprintf(buf, PAGE_SIZE, "%lu\n",
363
net_stats->rx_packets);
366
static ssize_t ixgbe_rxbytes(struct kobject *kobj,
367
struct kobj_attribute *attr, char *buf)
369
struct net_device_stats *net_stats;
370
struct net_device *netdev = ixgbe_get_netdev(kobj);
372
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
374
net_stats = sysfs_get_stats(netdev);
375
if (net_stats == NULL)
376
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
378
return snprintf(buf, PAGE_SIZE, "%lu\n",
379
net_stats->rx_bytes);
382
static ssize_t ixgbe_txframes(struct kobject *kobj,
383
struct kobj_attribute *attr, char *buf)
385
struct net_device_stats *net_stats;
386
struct net_device *netdev = ixgbe_get_netdev(kobj);
388
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
390
net_stats = sysfs_get_stats(netdev);
391
if (net_stats == NULL)
392
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
394
return snprintf(buf, PAGE_SIZE, "%lu\n",
395
net_stats->tx_packets);
398
static ssize_t ixgbe_txbytes(struct kobject *kobj,
399
struct kobj_attribute *attr, char *buf)
401
struct net_device_stats *net_stats;
402
struct net_device *netdev = ixgbe_get_netdev(kobj);
404
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
406
net_stats = sysfs_get_stats(netdev);
407
if (net_stats == NULL)
408
return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
410
return snprintf(buf, PAGE_SIZE, "%lu\n",
411
net_stats->tx_bytes);
414
static ssize_t ixgbe_linkstat(struct kobject *kobj,
415
struct kobj_attribute *attr, char *buf)
418
bool link_up = false;
421
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
423
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
427
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
430
if (test_bit(__IXGBE_DOWN, &adapter->state))
433
if (hw->mac.ops.check_link)
434
hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
436
/* always assume link is up, if no check link function */
440
return snprintf(buf, PAGE_SIZE, "0x%X\n", bitmask);
443
static ssize_t ixgbe_funcid(struct kobject *kobj,
444
struct kobj_attribute *attr, char *buf)
446
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
450
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
454
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
456
return snprintf(buf, PAGE_SIZE, "0x%X\n", hw->bus.func);
459
static ssize_t ixgbe_funcvers(struct kobject *kobj,
460
struct kobj_attribute *attr, char *buf)
462
return snprintf(buf, PAGE_SIZE, "%s\n", ixgbe_driver_version);
465
static ssize_t ixgbe_macburn(struct kobject *kobj,
466
struct kobj_attribute *attr, char *buf)
469
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
471
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
475
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
477
return snprintf(buf, PAGE_SIZE, "0x%X%X%X%X%X%X\n",
478
(unsigned int)hw->mac.perm_addr[0],
479
(unsigned int)hw->mac.perm_addr[1],
480
(unsigned int)hw->mac.perm_addr[2],
481
(unsigned int)hw->mac.perm_addr[3],
482
(unsigned int)hw->mac.perm_addr[4],
483
(unsigned int)hw->mac.perm_addr[5]);
486
static ssize_t ixgbe_macadmn(struct kobject *kobj,
487
struct kobj_attribute *attr, char *buf)
490
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
492
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
496
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
498
return snprintf(buf, PAGE_SIZE, "0x%X%X%X%X%X%X\n",
499
(unsigned int)hw->mac.addr[0],
500
(unsigned int)hw->mac.addr[1],
501
(unsigned int)hw->mac.addr[2],
502
(unsigned int)hw->mac.addr[3],
503
(unsigned int)hw->mac.addr[4],
504
(unsigned int)hw->mac.addr[5]);
507
static ssize_t ixgbe_maclla1(struct kobject *kobj,
508
struct kobj_attribute *attr, char *buf)
512
int first_word = 0x37;
515
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
517
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
521
return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
523
rc = ixgbe_read_eeprom_buffer(hw, first_word, word_count,
526
return snprintf(buf, PAGE_SIZE, "error: reading buffer\n");
528
switch (hw->bus.func) {
530
return snprintf(buf, PAGE_SIZE, "0x%04X%04X%04X\n",
535
return snprintf(buf, PAGE_SIZE, "0x%04X%04X%04X\n",
540
return snprintf(buf, PAGE_SIZE, "unexpected port %d\n", hw->bus.func);
543
static ssize_t ixgbe_mtusize(struct kobject *kobj,
544
struct kobj_attribute *attr, char *buf)
546
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
547
struct net_device *netdev = ixgbe_get_netdev(kobj);
549
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
552
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
554
return snprintf(buf, PAGE_SIZE, "%d\n", netdev->mtu);
557
static ssize_t ixgbe_featflag(struct kobject *kobj,
558
struct kobj_attribute *attr, char *buf)
561
#ifndef HAVE_NDO_SET_FEATURES
562
struct ixgbe_ring *ring;
564
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
565
struct net_device *netdev = ixgbe_get_netdev(kobj);
567
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
570
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
572
#ifndef HAVE_NDO_SET_FEATURES
573
/* ixgbe_get_rx_csum(netdev) doesn't compile so hard code */
574
ring = adapter->rx_ring[0];
575
bitmask = test_bit(__IXGBE_RX_CSUM_ENABLED, &ring->state);
576
return snprintf(buf, PAGE_SIZE, "%d\n", bitmask);
578
if (netdev->features & NETIF_F_RXCSUM)
580
return snprintf(buf, PAGE_SIZE, "%d\n", bitmask);
584
static ssize_t ixgbe_lsominct(struct kobject *kobj,
585
struct kobj_attribute *attr, char *buf)
587
return snprintf(buf, PAGE_SIZE, "%d\n", 1);
590
static ssize_t ixgbe_prommode(struct kobject *kobj,
591
struct kobj_attribute *attr, char *buf)
593
struct net_device *netdev = ixgbe_get_netdev(kobj);
595
return snprintf(buf, PAGE_SIZE, "error: no net device\n");
597
return snprintf(buf, PAGE_SIZE, "%d\n",
598
netdev->flags & IFF_PROMISC);
601
static ssize_t ixgbe_txdscqsz(struct kobject *kobj,
602
struct kobj_attribute *attr, char *buf)
604
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
606
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
608
return snprintf(buf, PAGE_SIZE, "%d\n", adapter->tx_ring[0]->count);
611
static ssize_t ixgbe_rxdscqsz(struct kobject *kobj,
612
struct kobj_attribute *attr, char *buf)
614
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
616
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
618
return snprintf(buf, PAGE_SIZE, "%d\n", adapter->rx_ring[0]->count);
621
static ssize_t ixgbe_rxqavg(struct kobject *kobj,
622
struct kobj_attribute *attr, char *buf)
628
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
630
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
632
for (index = 0; index < adapter->num_rx_queues; index++) {
633
ntc = adapter->rx_ring[index]->next_to_clean;
634
ntu = adapter->rx_ring[index]->next_to_use;
639
diff += (adapter->rx_ring[index]->count - ntu + ntc);
641
if (adapter->num_rx_queues <= 0)
642
return snprintf(buf, PAGE_SIZE,
643
"can't calculate, number of queues %d\n",
644
adapter->num_rx_queues);
645
return snprintf(buf, PAGE_SIZE, "%d\n", diff/adapter->num_rx_queues);
648
static ssize_t ixgbe_txqavg(struct kobject *kobj,
649
struct kobj_attribute *attr, char *buf)
655
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
657
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
659
for (index = 0; index < adapter->num_tx_queues; index++) {
660
ntc = adapter->tx_ring[index]->next_to_clean;
661
ntu = adapter->tx_ring[index]->next_to_use;
666
diff += (adapter->tx_ring[index]->count - ntu + ntc);
668
if (adapter->num_tx_queues <= 0)
669
return snprintf(buf, PAGE_SIZE,
670
"can't calculate, number of queues %d\n",
671
adapter->num_tx_queues);
672
return snprintf(buf, PAGE_SIZE, "%d\n",
673
diff/adapter->num_tx_queues);
676
static ssize_t ixgbe_iovotype(struct kobject *kobj,
677
struct kobj_attribute *attr, char *buf)
679
return snprintf(buf, PAGE_SIZE, "2\n");
682
static ssize_t ixgbe_funcnbr(struct kobject *kobj,
683
struct kobj_attribute *attr, char *buf)
685
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
687
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
689
return snprintf(buf, PAGE_SIZE, "%d\n", adapter->num_vfs);
692
static ssize_t ixgbe_pciebnbr(struct kobject *kobj,
693
struct kobj_attribute *attr, char *buf)
695
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
697
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
699
return snprintf(buf, PAGE_SIZE, "%d\n", adapter->pdev->bus->number);
702
static s32 ixgbe_sysfs_get_thermal_data(struct kobject *kobj, char *buf)
704
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
707
if (adapter == NULL) {
708
snprintf(buf, PAGE_SIZE, "error: missing adapter\n");
712
if (&adapter->hw == NULL) {
713
snprintf(buf, PAGE_SIZE, "error: missing hw\n");
717
status = ixgbe_get_thermal_sensor_data_generic(&adapter->hw);
722
static ssize_t ixgbe_sysfs_location(struct kobject *kobj,
723
struct kobj_attribute *attr, char *buf)
725
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
729
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
731
idx = ixgbe_name_to_idx(kobj->name);
733
return snprintf(buf, PAGE_SIZE,
734
"error: invalid sensor name %s\n", kobj->name);
736
return snprintf(buf, PAGE_SIZE, "%d\n",
737
adapter->hw.mac.thermal_sensor_data.sensor[idx].location);
740
static ssize_t ixgbe_sysfs_temp(struct kobject *kobj,
741
struct kobj_attribute *attr, char *buf)
743
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
746
s32 status = ixgbe_sysfs_get_thermal_data(kobj, buf);
749
return snprintf(buf, PAGE_SIZE, "error: status %d returned",
752
idx = ixgbe_name_to_idx(kobj->name);
754
return snprintf(buf, PAGE_SIZE,
755
"error: invalid sensor name %s\n", kobj->name);
757
return snprintf(buf, PAGE_SIZE, "%d\n",
758
adapter->hw.mac.thermal_sensor_data.sensor[idx].temp);
761
static ssize_t ixgbe_sysfs_maxopthresh(struct kobject *kobj,
762
struct kobj_attribute *attr, char *buf)
764
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
768
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
770
idx = ixgbe_name_to_idx(kobj->name);
772
return snprintf(buf, PAGE_SIZE,
773
"error: invalid sensor name %s\n", kobj->name);
775
return snprintf(buf, PAGE_SIZE, "%d\n",
776
adapter->hw.mac.thermal_sensor_data.sensor[idx].max_op_thresh);
779
static ssize_t ixgbe_sysfs_cautionthresh(struct kobject *kobj,
780
struct kobj_attribute *attr, char *buf)
782
struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
786
return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
788
idx = ixgbe_name_to_idx(kobj->name);
790
return snprintf(buf, PAGE_SIZE,
791
"error: invalid sensor name %s\n", kobj->name);
793
return snprintf(buf, PAGE_SIZE, "%d\n",
794
adapter->hw.mac.thermal_sensor_data.sensor[idx].caution_thresh);
797
/* Initialize the attributes */
798
static struct kobj_attribute ixgbe_sysfs_location_attr =
799
__ATTR(location, 0444, ixgbe_sysfs_location, NULL);
800
static struct kobj_attribute ixgbe_sysfs_temp_attr =
801
__ATTR(temp, 0444, ixgbe_sysfs_temp, NULL);
802
static struct kobj_attribute ixgbe_sysfs_cautionthresh_attr =
803
__ATTR(cautionthresh, 0444, ixgbe_sysfs_cautionthresh, NULL);
804
static struct kobj_attribute ixgbe_sysfs_maxopthresh_attr =
805
__ATTR(maxopthresh, 0444, ixgbe_sysfs_maxopthresh, NULL);
807
static struct kobj_attribute ixgbe_sysfs_fwbanner_attr =
808
__ATTR(fwbanner, 0444, ixgbe_fwbanner, NULL);
809
static struct kobj_attribute ixgbe_sysfs_porttype_attr =
810
__ATTR(porttype, 0444, ixgbe_porttype, NULL);
811
static struct kobj_attribute ixgbe_sysfs_portspeed_attr =
812
__ATTR(portspeed, 0444, ixgbe_portspeed, NULL);
813
static struct kobj_attribute ixgbe_sysfs_wqlflag_attr =
814
__ATTR(wqlflag, 0444, ixgbe_wqlflag, NULL);
815
static struct kobj_attribute ixgbe_sysfs_xflowctl_attr =
816
__ATTR(xflowctl, 0444, ixgbe_xflowctl, NULL);
817
static struct kobj_attribute ixgbe_sysfs_rxdrops_attr =
818
__ATTR(rxdrops, 0444, ixgbe_rxdrops, NULL);
819
static struct kobj_attribute ixgbe_sysfs_rxerrors_attr =
820
__ATTR(rxerrors, 0444, ixgbe_rxerrors, NULL);
821
static struct kobj_attribute ixgbe_sysfs_rxupacks_attr =
822
__ATTR(rxupacks, 0444, ixgbe_rxupacks, NULL);
823
static struct kobj_attribute ixgbe_sysfs_rxmpacks_attr =
824
__ATTR(rxmpacks, 0444, ixgbe_rxmpacks, NULL);
825
static struct kobj_attribute ixgbe_sysfs_rxbpacks_attr =
826
__ATTR(rxbpacks, 0444, ixgbe_rxbpacks, NULL);
827
static struct kobj_attribute ixgbe_sysfs_txupacks_attr =
828
__ATTR(txupacks, 0444, ixgbe_txupacks, NULL);
829
static struct kobj_attribute ixgbe_sysfs_txmpacks_attr =
830
__ATTR(txmpacks, 0444, ixgbe_txmpacks, NULL);
831
static struct kobj_attribute ixgbe_sysfs_txbpacks_attr =
832
__ATTR(txbpacks, 0444, ixgbe_txbpacks, NULL);
833
static struct kobj_attribute ixgbe_sysfs_txerrors_attr =
834
__ATTR(txerrors, 0444, ixgbe_txerrors, NULL);
835
static struct kobj_attribute ixgbe_sysfs_txdrops_attr =
836
__ATTR(txdrops, 0444, ixgbe_txdrops, NULL);
837
static struct kobj_attribute ixgbe_sysfs_rxframes_attr =
838
__ATTR(rxframes, 0444, ixgbe_rxframes, NULL);
839
static struct kobj_attribute ixgbe_sysfs_rxbytes_attr =
840
__ATTR(rxbytes, 0444, ixgbe_rxbytes, NULL);
841
static struct kobj_attribute ixgbe_sysfs_txframes_attr =
842
__ATTR(txframes, 0444, ixgbe_txframes, NULL);
843
static struct kobj_attribute ixgbe_sysfs_txbytes_attr =
844
__ATTR(txbytes, 0444, ixgbe_txbytes, NULL);
845
static struct kobj_attribute ixgbe_sysfs_linkstat_attr =
846
__ATTR(linkstat, 0444, ixgbe_linkstat, NULL);
847
static struct kobj_attribute ixgbe_sysfs_funcid_attr =
848
__ATTR(funcid, 0444, ixgbe_funcid, NULL);
849
static struct kobj_attribute ixgbe_sysfs_funvers_attr =
850
__ATTR(funcvers, 0444, ixgbe_funcvers, NULL);
851
static struct kobj_attribute ixgbe_sysfs_macburn_attr =
852
__ATTR(macburn, 0444, ixgbe_macburn, NULL);
853
static struct kobj_attribute ixgbe_sysfs_macadmn_attr =
854
__ATTR(macadmn, 0444, ixgbe_macadmn, NULL);
855
static struct kobj_attribute ixgbe_sysfs_maclla1_attr =
856
__ATTR(maclla1, 0444, ixgbe_maclla1, NULL);
857
static struct kobj_attribute ixgbe_sysfs_mtusize_attr =
858
__ATTR(mtusize, 0444, ixgbe_mtusize, NULL);
859
static struct kobj_attribute ixgbe_sysfs_featflag_attr =
860
__ATTR(featflag, 0444, ixgbe_featflag, NULL);
861
static struct kobj_attribute ixgbe_sysfs_lsominct_attr =
862
__ATTR(lsominct, 0444, ixgbe_lsominct, NULL);
863
static struct kobj_attribute ixgbe_sysfs_prommode_attr =
864
__ATTR(prommode, 0444, ixgbe_prommode, NULL);
865
static struct kobj_attribute ixgbe_sysfs_txdscqsz_attr =
866
__ATTR(txdscqsz, 0444, ixgbe_txdscqsz, NULL);
867
static struct kobj_attribute ixgbe_sysfs_rxdscqsz_attr =
868
__ATTR(rxdscqsz, 0444, ixgbe_rxdscqsz, NULL);
869
static struct kobj_attribute ixgbe_sysfs_txqavg_attr =
870
__ATTR(txqavg, 0444, ixgbe_txqavg, NULL);
871
static struct kobj_attribute ixgbe_sysfs_rxqavg_attr =
872
__ATTR(rxqavg, 0444, ixgbe_rxqavg, NULL);
873
static struct kobj_attribute ixgbe_sysfs_iovotype_attr =
874
__ATTR(iovotype, 0444, ixgbe_iovotype, NULL);
875
static struct kobj_attribute ixgbe_sysfs_funcnbr_attr =
876
__ATTR(funcnbr, 0444, ixgbe_funcnbr, NULL);
877
static struct kobj_attribute ixgbe_sysfs_pciebnbr_attr =
878
__ATTR(pciebnbr, 0444, ixgbe_pciebnbr, NULL);
880
/* Add the attributes into an array, to be added to a group */
881
static struct attribute *therm_attrs[] = {
882
&ixgbe_sysfs_location_attr.attr,
883
&ixgbe_sysfs_temp_attr.attr,
884
&ixgbe_sysfs_cautionthresh_attr.attr,
885
&ixgbe_sysfs_maxopthresh_attr.attr,
889
static struct attribute *attrs[] = {
890
&ixgbe_sysfs_fwbanner_attr.attr,
891
&ixgbe_sysfs_porttype_attr.attr,
892
&ixgbe_sysfs_portspeed_attr.attr,
893
&ixgbe_sysfs_wqlflag_attr.attr,
894
&ixgbe_sysfs_xflowctl_attr.attr,
895
&ixgbe_sysfs_rxdrops_attr.attr,
896
&ixgbe_sysfs_rxerrors_attr.attr,
897
&ixgbe_sysfs_rxupacks_attr.attr,
898
&ixgbe_sysfs_rxmpacks_attr.attr,
899
&ixgbe_sysfs_rxbpacks_attr.attr,
900
&ixgbe_sysfs_txdrops_attr.attr,
901
&ixgbe_sysfs_txerrors_attr.attr,
902
&ixgbe_sysfs_txupacks_attr.attr,
903
&ixgbe_sysfs_txmpacks_attr.attr,
904
&ixgbe_sysfs_txbpacks_attr.attr,
905
&ixgbe_sysfs_rxframes_attr.attr,
906
&ixgbe_sysfs_rxbytes_attr.attr,
907
&ixgbe_sysfs_txframes_attr.attr,
908
&ixgbe_sysfs_txbytes_attr.attr,
909
&ixgbe_sysfs_linkstat_attr.attr,
910
&ixgbe_sysfs_funcid_attr.attr,
911
&ixgbe_sysfs_funvers_attr.attr,
912
&ixgbe_sysfs_macburn_attr.attr,
913
&ixgbe_sysfs_macadmn_attr.attr,
914
&ixgbe_sysfs_maclla1_attr.attr,
915
&ixgbe_sysfs_mtusize_attr.attr,
916
&ixgbe_sysfs_featflag_attr.attr,
917
&ixgbe_sysfs_lsominct_attr.attr,
918
&ixgbe_sysfs_prommode_attr.attr,
919
&ixgbe_sysfs_txdscqsz_attr.attr,
920
&ixgbe_sysfs_rxdscqsz_attr.attr,
921
&ixgbe_sysfs_txqavg_attr.attr,
922
&ixgbe_sysfs_rxqavg_attr.attr,
923
&ixgbe_sysfs_iovotype_attr.attr,
924
&ixgbe_sysfs_funcnbr_attr.attr,
925
&ixgbe_sysfs_pciebnbr_attr.attr,
929
/* add attributes to a group */
930
static struct attribute_group therm_attr_group = {
931
.attrs = therm_attrs,
934
/* add attributes to a group */
935
static struct attribute_group attr_group = {
939
static void ixgbe_del_adapter(struct ixgbe_adapter *adapter)
946
for (i = 0; i < IXGBE_MAX_SENSORS; i++) {
947
if (adapter->therm_kobj[i] == NULL)
949
sysfs_remove_group(adapter->therm_kobj[i], &therm_attr_group);
950
kobject_put(adapter->therm_kobj[i]);
952
if (adapter->info_kobj != NULL) {
953
sysfs_remove_group(adapter->info_kobj, &attr_group);
954
kobject_put(adapter->info_kobj);
958
/* called from ixgbe_main.c */
959
void ixgbe_sysfs_exit(struct ixgbe_adapter *adapter)
961
ixgbe_del_adapter(adapter);
964
/* called from ixgbe_main.c */
965
int ixgbe_sysfs_init(struct ixgbe_adapter *adapter)
967
struct net_device *netdev;
974
netdev = adapter->netdev;
978
adapter->info_kobj = NULL;
979
for (i = 0; i < IXGBE_MAX_SENSORS; i++)
980
adapter->therm_kobj[i] = NULL;
982
/* create info kobj and attribute listings in kobj */
983
adapter->info_kobj = kobject_create_and_add("info",
984
&(netdev->dev.kobj));
985
if (adapter->info_kobj == NULL)
987
if (sysfs_create_group(adapter->info_kobj, &attr_group))
990
/* Don't create thermal subkobjs if no data present */
991
if (ixgbe_thermal_present(adapter->info_kobj) != true)
994
for (i = 0; i < IXGBE_MAX_SENSORS; i++) {
997
* Likewise only create individual kobjs that have
1000
if (adapter->hw.mac.thermal_sensor_data.sensor[i].location == 0)
1003
/* directory named after sensor offset */
1004
snprintf(buf, sizeof(buf), "sensor_%d", i);
1005
adapter->therm_kobj[i] =
1006
kobject_create_and_add(buf, adapter->info_kobj);
1007
if (adapter->therm_kobj[i] == NULL)
1009
if (sysfs_create_group(adapter->therm_kobj[i],
1017
ixgbe_del_adapter(adapter);
1023
#endif /* IXGBE_SYSFS */