~ubuntu-branches/ubuntu/wily/linux-backports-modules-3.2.0/wily

« back to all changes in this revision

Viewing changes to updates/net/ixgbe/src/ixgbe_sysfs.c

  • Committer: Package Import Robot
  • Author(s): Leann Ogasawara
  • Date: 2012-04-24 09:15:36 UTC
  • Revision ID: package-import@ubuntu.com-20120424091536-g1ubxt3rtf9vbtal
Tags: 3.2.0-24.7
* Bump ABI for Precise 3.2.0-24.37
* Added Intel OEM ixgbe 3.8.21 driver
  - LP: #978324

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 
 
3
  Intel 10 Gigabit PCI Express Linux driver
 
4
  Copyright(c) 1999 - 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 "ixgbe.h"
 
29
#include "ixgbe_common.h"
 
30
#include "ixgbe_type.h"
 
31
 
 
32
#ifdef IXGBE_SYSFS
 
33
 
 
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>
 
40
 
 
41
/*
 
42
 * This file provides a sysfs interface to export information from the
 
43
 * driver.  The information presented is READ-ONLY.
 
44
 */
 
45
 
 
46
static struct net_device_stats *sysfs_get_stats(struct net_device *netdev)
 
47
{
 
48
#ifndef HAVE_NETDEV_STATS_IN_NETDEV
 
49
        struct ixgbe_adapter *adapter;
 
50
#endif
 
51
        if (netdev == NULL)
 
52
                return NULL;
 
53
 
 
54
#ifdef HAVE_NETDEV_STATS_IN_NETDEV
 
55
        /* only return the current stats */
 
56
        return &netdev->stats;
 
57
#else
 
58
        adapter = netdev_priv(netdev);
 
59
 
 
60
        /* only return the current stats */
 
61
        return &adapter->net_stats;
 
62
#endif /* HAVE_NETDEV_STATS_IN_NETDEV */
 
63
}
 
64
 
 
65
static struct net_device *ixgbe_get_netdev(struct kobject *kobj)
 
66
{
 
67
        struct net_device *netdev;
 
68
        struct kobject *parent = kobj->parent;
 
69
        struct device *device_info_kobj;
 
70
 
 
71
        if (kobj == NULL)
 
72
                return NULL;
 
73
 
 
74
        device_info_kobj = container_of(parent, struct device, kobj);
 
75
        if (device_info_kobj == NULL)
 
76
                return NULL;
 
77
 
 
78
        netdev = container_of(device_info_kobj, struct net_device, dev);
 
79
        return netdev;
 
80
}
 
81
 
 
82
static struct ixgbe_adapter *ixgbe_get_adapter(struct kobject *kobj)
 
83
{
 
84
        struct ixgbe_adapter *adapter;
 
85
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
86
        if (netdev == NULL)
 
87
                return NULL;
 
88
        adapter = netdev_priv(netdev);
 
89
        return adapter;
 
90
}
 
91
 
 
92
static bool ixgbe_thermal_present(struct kobject *kobj)
 
93
{
 
94
        s32 status;
 
95
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
96
 
 
97
        if (adapter == NULL)
 
98
                return false;
 
99
 
 
100
        status = ixgbe_init_thermal_sensor_thresh_generic(&(adapter->hw));
 
101
        if (status != 0)
 
102
                return false;
 
103
 
 
104
        return true;
 
105
}
 
106
 
 
107
/*
 
108
 * ixgbe_name_to_idx - Convert the directory name to the sensor offset.
 
109
 * @ c: pointer to the directory name string
 
110
 *
 
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.
 
114
 */
 
115
static int ixgbe_name_to_idx(const char *c)
 
116
{
 
117
        /* find first digit */
 
118
        while (*c < '0' || *c > '9') {
 
119
                if (*c == '\n')
 
120
                        return -1;
 
121
                c++;
 
122
        }
 
123
 
 
124
        return ((int)(*c - '0'));
 
125
}
 
126
 
 
127
static ssize_t ixgbe_fwbanner(struct kobject *kobj,
 
128
                              struct kobj_attribute *attr, char *buf)
 
129
{
 
130
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
131
        int nvm_track_id;
 
132
 
 
133
        if (adapter == NULL)
 
134
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
135
        nvm_track_id = (adapter->eeprom_verh << 16) | adapter->eeprom_verl;
 
136
 
 
137
        return snprintf(buf, PAGE_SIZE, "0x%08x\n", nvm_track_id);
 
138
}
 
139
 
 
140
static ssize_t ixgbe_porttype(struct kobject *kobj,
 
141
                              struct kobj_attribute *attr, char *buf)
 
142
{
 
143
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
144
        if (adapter == NULL)
 
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));
 
148
}
 
149
 
 
150
static ssize_t ixgbe_portspeed(struct kobject *kobj,
 
151
                              struct kobj_attribute *attr, char *buf)
 
152
{
 
153
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
154
        int speed = 0;
 
155
 
 
156
        if (adapter == NULL)
 
157
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
158
 
 
159
        switch (adapter->link_speed) {
 
160
        case IXGBE_LINK_SPEED_100_FULL:
 
161
                speed = 1;
 
162
                break;
 
163
        case IXGBE_LINK_SPEED_1GB_FULL:
 
164
                speed = 10;
 
165
                break;
 
166
        case IXGBE_LINK_SPEED_10GB_FULL:
 
167
                speed = 100;
 
168
                break;
 
169
        }
 
170
        return snprintf(buf, PAGE_SIZE, "%d\n", speed);
 
171
}
 
172
 
 
173
static ssize_t ixgbe_wqlflag(struct kobject *kobj,
 
174
                             struct kobj_attribute *attr, char *buf)
 
175
{
 
176
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
177
        if (adapter == NULL)
 
178
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
179
 
 
180
        return snprintf(buf, PAGE_SIZE, "%d\n", adapter->wol);
 
181
}
 
182
 
 
183
static ssize_t ixgbe_xflowctl(struct kobject *kobj,
 
184
                              struct kobj_attribute *attr, char *buf)
 
185
{
 
186
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
187
        struct ixgbe_hw *hw;
 
188
 
 
189
        if (adapter == NULL)
 
190
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
191
 
 
192
        hw = &adapter->hw;
 
193
        if (hw == NULL)
 
194
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
195
 
 
196
        return snprintf(buf, PAGE_SIZE, "%d\n", hw->fc.current_mode);
 
197
}
 
198
 
 
199
static ssize_t ixgbe_rxdrops(struct kobject *kobj,
 
200
                             struct kobj_attribute *attr, char *buf)
 
201
{
 
202
        struct net_device_stats *net_stats;
 
203
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
204
        if (netdev == NULL)
 
205
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
206
 
 
207
        net_stats  = sysfs_get_stats(netdev);
 
208
        if (net_stats == NULL)
 
209
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
210
 
 
211
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
212
                        net_stats->rx_dropped);
 
213
}
 
214
 
 
215
static ssize_t ixgbe_rxerrors(struct kobject *kobj,
 
216
                              struct kobj_attribute *attr, char *buf)
 
217
{
 
218
        struct net_device_stats *net_stats;
 
219
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
220
        if (netdev == NULL)
 
221
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
222
 
 
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);
 
227
}
 
228
 
 
229
static ssize_t ixgbe_rxupacks(struct kobject *kobj,
 
230
                              struct kobj_attribute *attr, char *buf)
 
231
{
 
232
        struct ixgbe_hw *hw;
 
233
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
234
        if (adapter == NULL)
 
235
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
236
 
 
237
        hw = &adapter->hw;
 
238
        if (hw == NULL)
 
239
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
240
 
 
241
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_TPR));
 
242
}
 
243
 
 
244
static ssize_t ixgbe_rxmpacks(struct kobject *kobj,
 
245
                              struct kobj_attribute *attr, char *buf)
 
246
{
 
247
        struct ixgbe_hw *hw;
 
248
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
249
        if (adapter == NULL)
 
250
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
251
 
 
252
        hw = &adapter->hw;
 
253
        if (hw == NULL)
 
254
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
255
 
 
256
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_MPRC));
 
257
}
 
258
 
 
259
static ssize_t ixgbe_rxbpacks(struct kobject *kobj,
 
260
                              struct kobj_attribute *attr, char *buf)
 
261
{
 
262
        struct ixgbe_hw *hw;
 
263
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
264
        if (adapter == NULL)
 
265
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
266
 
 
267
        hw = &adapter->hw;
 
268
        if (hw == NULL)
 
269
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
270
 
 
271
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_BPRC));
 
272
}
 
273
 
 
274
static ssize_t ixgbe_txupacks(struct kobject *kobj,
 
275
                              struct kobj_attribute *attr, char *buf)
 
276
{
 
277
        struct ixgbe_hw *hw;
 
278
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
279
        if (adapter == NULL)
 
280
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
281
 
 
282
        hw = &adapter->hw;
 
283
        if (hw == NULL)
 
284
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
285
 
 
286
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_TPT));
 
287
}
 
288
 
 
289
static ssize_t ixgbe_txmpacks(struct kobject *kobj,
 
290
                              struct kobj_attribute *attr, char *buf)
 
291
{
 
292
        struct ixgbe_hw *hw;
 
293
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
294
        if (adapter == NULL)
 
295
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
296
 
 
297
        hw = &adapter->hw;
 
298
        if (hw == NULL)
 
299
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
300
 
 
301
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_MPTC));
 
302
}
 
303
 
 
304
static ssize_t ixgbe_txbpacks(struct kobject *kobj,
 
305
                              struct kobj_attribute *attr, char *buf)
 
306
{
 
307
        struct ixgbe_hw *hw;
 
308
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
309
        if (adapter == NULL)
 
310
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
311
 
 
312
        hw = &adapter->hw;
 
313
        if (hw == NULL)
 
314
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
315
 
 
316
        return snprintf(buf, PAGE_SIZE, "%d\n", IXGBE_READ_REG(hw, IXGBE_BPTC));
 
317
}
 
318
 
 
319
static ssize_t ixgbe_txerrors(struct kobject *kobj,
 
320
                              struct kobj_attribute *attr, char *buf)
 
321
{
 
322
        struct net_device_stats *net_stats;
 
323
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
324
        if (netdev == NULL)
 
325
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
326
 
 
327
        net_stats  = sysfs_get_stats(netdev);
 
328
        if (net_stats == NULL)
 
329
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
330
 
 
331
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
332
                        net_stats->tx_errors);
 
333
}
 
334
 
 
335
static ssize_t ixgbe_txdrops(struct kobject *kobj,
 
336
                             struct kobj_attribute *attr, char *buf)
 
337
{
 
338
        struct net_device_stats *net_stats;
 
339
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
340
        if (netdev == NULL)
 
341
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
342
 
 
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);
 
348
}
 
349
 
 
350
static ssize_t ixgbe_rxframes(struct kobject *kobj,
 
351
                              struct kobj_attribute *attr, char *buf)
 
352
{
 
353
        struct net_device_stats *net_stats;
 
354
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
355
        if (netdev == NULL)
 
356
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
357
 
 
358
        net_stats  = sysfs_get_stats(netdev);
 
359
        if (net_stats == NULL)
 
360
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
361
 
 
362
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
363
                        net_stats->rx_packets);
 
364
}
 
365
 
 
366
static ssize_t ixgbe_rxbytes(struct kobject *kobj,
 
367
                             struct kobj_attribute *attr, char *buf)
 
368
{
 
369
        struct net_device_stats *net_stats;
 
370
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
371
        if (netdev == NULL)
 
372
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
373
 
 
374
        net_stats  = sysfs_get_stats(netdev);
 
375
        if (net_stats == NULL)
 
376
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
377
 
 
378
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
379
                        net_stats->rx_bytes);
 
380
}
 
381
 
 
382
static ssize_t ixgbe_txframes(struct kobject *kobj,
 
383
                              struct kobj_attribute *attr, char *buf)
 
384
{
 
385
        struct net_device_stats *net_stats;
 
386
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
387
        if (netdev == NULL)
 
388
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
389
 
 
390
        net_stats  = sysfs_get_stats(netdev);
 
391
        if (net_stats == NULL)
 
392
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
393
 
 
394
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
395
                        net_stats->tx_packets);
 
396
}
 
397
 
 
398
static ssize_t ixgbe_txbytes(struct kobject *kobj,
 
399
                             struct kobj_attribute *attr, char *buf)
 
400
{
 
401
        struct net_device_stats *net_stats;
 
402
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
403
        if (netdev == NULL)
 
404
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
405
 
 
406
        net_stats  = sysfs_get_stats(netdev);
 
407
        if (net_stats == NULL)
 
408
                return snprintf(buf, PAGE_SIZE, "error: no net stats\n");
 
409
 
 
410
        return snprintf(buf, PAGE_SIZE, "%lu\n",
 
411
                        net_stats->tx_bytes);
 
412
}
 
413
 
 
414
static ssize_t ixgbe_linkstat(struct kobject *kobj,
 
415
                              struct kobj_attribute *attr, char *buf)
 
416
{
 
417
        u32 link_speed;
 
418
        bool link_up = false;
 
419
        int bitmask = 0;
 
420
        struct ixgbe_hw *hw;
 
421
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
422
        if (adapter == NULL)
 
423
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
424
 
 
425
        hw = &adapter->hw;
 
426
        if (hw == NULL)
 
427
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
428
 
 
429
 
 
430
        if (test_bit(__IXGBE_DOWN, &adapter->state))
 
431
                bitmask |= 1;
 
432
 
 
433
        if (hw->mac.ops.check_link)
 
434
                hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
 
435
        else
 
436
                /* always assume link is up, if no check link function */
 
437
                link_up = true;
 
438
        if (link_up)
 
439
                bitmask |= 2;
 
440
        return snprintf(buf, PAGE_SIZE, "0x%X\n", bitmask);
 
441
}
 
442
 
 
443
static ssize_t ixgbe_funcid(struct kobject *kobj,
 
444
                             struct kobj_attribute *attr, char *buf)
 
445
{
 
446
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
447
        struct ixgbe_hw *hw;
 
448
 
 
449
        if (adapter == NULL)
 
450
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
451
 
 
452
        hw = &adapter->hw;
 
453
        if (hw == NULL)
 
454
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
455
 
 
456
        return snprintf(buf, PAGE_SIZE, "0x%X\n", hw->bus.func);
 
457
}
 
458
 
 
459
static ssize_t ixgbe_funcvers(struct kobject *kobj,
 
460
                             struct kobj_attribute *attr, char *buf)
 
461
{
 
462
        return snprintf(buf, PAGE_SIZE, "%s\n", ixgbe_driver_version);
 
463
}
 
464
 
 
465
static ssize_t ixgbe_macburn(struct kobject *kobj,
 
466
                             struct kobj_attribute *attr, char *buf)
 
467
{
 
468
        struct ixgbe_hw *hw;
 
469
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
470
        if (adapter == NULL)
 
471
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
472
 
 
473
        hw = &adapter->hw;
 
474
        if (hw == NULL)
 
475
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
476
 
 
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]);
 
484
}
 
485
 
 
486
static ssize_t ixgbe_macadmn(struct kobject *kobj,
 
487
                             struct kobj_attribute *attr, char *buf)
 
488
{
 
489
        struct ixgbe_hw *hw;
 
490
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
491
        if (adapter == NULL)
 
492
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
493
 
 
494
        hw = &adapter->hw;
 
495
        if (hw == NULL)
 
496
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
497
 
 
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]);
 
505
}
 
506
 
 
507
static ssize_t ixgbe_maclla1(struct kobject *kobj,
 
508
                             struct kobj_attribute *attr, char *buf)
 
509
{
 
510
        struct ixgbe_hw *hw;
 
511
        u16 eeprom_buff[6];
 
512
        int first_word = 0x37;
 
513
        int word_count = 6;
 
514
        int rc;
 
515
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
516
        if (adapter == NULL)
 
517
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
518
 
 
519
        hw = &adapter->hw;
 
520
        if (hw == NULL)
 
521
                return snprintf(buf, PAGE_SIZE, "error: no hw data\n");
 
522
 
 
523
        rc = ixgbe_read_eeprom_buffer(hw, first_word, word_count,
 
524
                                      eeprom_buff);
 
525
        if (rc != 0)
 
526
                return snprintf(buf, PAGE_SIZE, "error: reading buffer\n");
 
527
 
 
528
        switch (hw->bus.func) {
 
529
        case 0:
 
530
                return snprintf(buf, PAGE_SIZE, "0x%04X%04X%04X\n",
 
531
                                eeprom_buff[0],
 
532
                                eeprom_buff[1],
 
533
                                eeprom_buff[2]);
 
534
        case 1:
 
535
                return snprintf(buf, PAGE_SIZE, "0x%04X%04X%04X\n",
 
536
                                eeprom_buff[3],
 
537
                                eeprom_buff[4],
 
538
                                eeprom_buff[5]);
 
539
        }
 
540
        return snprintf(buf, PAGE_SIZE, "unexpected port %d\n", hw->bus.func);
 
541
}
 
542
 
 
543
static ssize_t ixgbe_mtusize(struct kobject *kobj,
 
544
                             struct kobj_attribute *attr, char *buf)
 
545
{
 
546
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
547
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
548
        if (netdev == NULL)
 
549
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
550
 
 
551
        if (adapter == NULL)
 
552
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
553
 
 
554
        return snprintf(buf, PAGE_SIZE, "%d\n", netdev->mtu);
 
555
}
 
556
 
 
557
static ssize_t ixgbe_featflag(struct kobject *kobj,
 
558
                              struct kobj_attribute *attr, char *buf)
 
559
{
 
560
        int bitmask = 0;
 
561
#ifndef HAVE_NDO_SET_FEATURES
 
562
        struct ixgbe_ring *ring;
 
563
#endif
 
564
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
565
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
566
        if (netdev == NULL)
 
567
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
568
 
 
569
        if (adapter == NULL)
 
570
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
571
 
 
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);
 
577
#else
 
578
        if (netdev->features & NETIF_F_RXCSUM)
 
579
                bitmask |= 1;
 
580
        return snprintf(buf, PAGE_SIZE, "%d\n", bitmask);
 
581
#endif
 
582
}
 
583
 
 
584
static ssize_t ixgbe_lsominct(struct kobject *kobj,
 
585
                              struct kobj_attribute *attr, char *buf)
 
586
{
 
587
        return snprintf(buf, PAGE_SIZE, "%d\n", 1);
 
588
}
 
589
 
 
590
static ssize_t ixgbe_prommode(struct kobject *kobj,
 
591
                              struct kobj_attribute *attr, char *buf)
 
592
{
 
593
        struct net_device *netdev = ixgbe_get_netdev(kobj);
 
594
        if (netdev == NULL)
 
595
                return snprintf(buf, PAGE_SIZE, "error: no net device\n");
 
596
 
 
597
        return snprintf(buf, PAGE_SIZE, "%d\n",
 
598
                        netdev->flags & IFF_PROMISC);
 
599
}
 
600
 
 
601
static ssize_t ixgbe_txdscqsz(struct kobject *kobj,
 
602
                              struct kobj_attribute *attr, char *buf)
 
603
{
 
604
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
605
        if (adapter == NULL)
 
606
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
607
 
 
608
        return snprintf(buf, PAGE_SIZE, "%d\n", adapter->tx_ring[0]->count);
 
609
}
 
610
 
 
611
static ssize_t ixgbe_rxdscqsz(struct kobject *kobj,
 
612
                              struct kobj_attribute *attr, char *buf)
 
613
{
 
614
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
615
        if (adapter == NULL)
 
616
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
617
 
 
618
        return snprintf(buf, PAGE_SIZE, "%d\n", adapter->rx_ring[0]->count);
 
619
}
 
620
 
 
621
static ssize_t ixgbe_rxqavg(struct kobject *kobj,
 
622
                            struct kobj_attribute *attr, char *buf)
 
623
{
 
624
        int index;
 
625
        int diff = 0;
 
626
        u16 ntc;
 
627
        u16 ntu;
 
628
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
629
        if (adapter == NULL)
 
630
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
631
 
 
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;
 
635
 
 
636
                if (ntc >= ntu)
 
637
                        diff += (ntc - ntu);
 
638
                else
 
639
                        diff += (adapter->rx_ring[index]->count - ntu + ntc);
 
640
        }
 
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);
 
646
}
 
647
 
 
648
static ssize_t ixgbe_txqavg(struct kobject *kobj,
 
649
                            struct kobj_attribute *attr, char *buf)
 
650
{
 
651
        int index;
 
652
        int diff = 0;
 
653
        u16 ntc;
 
654
        u16 ntu;
 
655
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
656
        if (adapter == NULL)
 
657
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
658
 
 
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;
 
662
 
 
663
                if (ntc >= ntu)
 
664
                        diff += (ntc - ntu);
 
665
                else
 
666
                        diff += (adapter->tx_ring[index]->count - ntu + ntc);
 
667
        }
 
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);
 
674
}
 
675
 
 
676
static ssize_t ixgbe_iovotype(struct kobject *kobj,
 
677
                              struct kobj_attribute *attr, char *buf)
 
678
{
 
679
        return snprintf(buf, PAGE_SIZE, "2\n");
 
680
}
 
681
 
 
682
static ssize_t ixgbe_funcnbr(struct kobject *kobj,
 
683
                             struct kobj_attribute *attr, char *buf)
 
684
{
 
685
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
686
        if (adapter == NULL)
 
687
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
688
 
 
689
        return snprintf(buf, PAGE_SIZE, "%d\n", adapter->num_vfs);
 
690
}
 
691
 
 
692
static ssize_t ixgbe_pciebnbr(struct kobject *kobj,
 
693
                             struct kobj_attribute *attr, char *buf)
 
694
{
 
695
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj);
 
696
        if (adapter == NULL)
 
697
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
698
 
 
699
        return snprintf(buf, PAGE_SIZE, "%d\n", adapter->pdev->bus->number);
 
700
}
 
701
 
 
702
static s32 ixgbe_sysfs_get_thermal_data(struct kobject *kobj, char *buf)
 
703
{
 
704
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
 
705
        s32 status;
 
706
 
 
707
        if (adapter == NULL) {
 
708
                snprintf(buf, PAGE_SIZE, "error: missing adapter\n");
 
709
                return 0;
 
710
        }
 
711
 
 
712
        if (&adapter->hw == NULL) {
 
713
                snprintf(buf, PAGE_SIZE, "error: missing hw\n");
 
714
                return 0;
 
715
        }
 
716
 
 
717
        status = ixgbe_get_thermal_sensor_data_generic(&adapter->hw);
 
718
 
 
719
        return status;
 
720
}
 
721
 
 
722
static ssize_t ixgbe_sysfs_location(struct kobject *kobj,
 
723
                                    struct kobj_attribute *attr, char *buf)
 
724
{
 
725
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
 
726
        int idx;
 
727
 
 
728
        if (adapter == NULL)
 
729
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
730
 
 
731
        idx = ixgbe_name_to_idx(kobj->name);
 
732
        if (idx == -1)
 
733
                return snprintf(buf, PAGE_SIZE,
 
734
                                "error: invalid sensor name %s\n", kobj->name);
 
735
 
 
736
        return snprintf(buf, PAGE_SIZE, "%d\n",
 
737
                adapter->hw.mac.thermal_sensor_data.sensor[idx].location);
 
738
}
 
739
 
 
740
static ssize_t ixgbe_sysfs_temp(struct kobject *kobj,
 
741
                                struct kobj_attribute *attr, char *buf)
 
742
{
 
743
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
 
744
        int idx;
 
745
 
 
746
        s32 status = ixgbe_sysfs_get_thermal_data(kobj, buf);
 
747
 
 
748
        if (status != 0)
 
749
                return snprintf(buf, PAGE_SIZE, "error: status %d returned",
 
750
                                status);
 
751
 
 
752
        idx = ixgbe_name_to_idx(kobj->name);
 
753
        if (idx == -1)
 
754
                return snprintf(buf, PAGE_SIZE,
 
755
                                "error: invalid sensor name %s\n", kobj->name);
 
756
 
 
757
        return snprintf(buf, PAGE_SIZE, "%d\n",
 
758
                adapter->hw.mac.thermal_sensor_data.sensor[idx].temp);
 
759
}
 
760
 
 
761
static ssize_t ixgbe_sysfs_maxopthresh(struct kobject *kobj,
 
762
                                       struct kobj_attribute *attr, char *buf)
 
763
{
 
764
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
 
765
        int idx;
 
766
 
 
767
        if (adapter == NULL)
 
768
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
769
 
 
770
        idx = ixgbe_name_to_idx(kobj->name);
 
771
        if (idx == -1)
 
772
                return snprintf(buf, PAGE_SIZE,
 
773
                                "error: invalid sensor name %s\n", kobj->name);
 
774
 
 
775
        return snprintf(buf, PAGE_SIZE, "%d\n",
 
776
                adapter->hw.mac.thermal_sensor_data.sensor[idx].max_op_thresh);
 
777
}
 
778
 
 
779
static ssize_t ixgbe_sysfs_cautionthresh(struct kobject *kobj,
 
780
                                         struct kobj_attribute *attr, char *buf)
 
781
{
 
782
        struct ixgbe_adapter *adapter = ixgbe_get_adapter(kobj->parent);
 
783
        int idx;
 
784
 
 
785
        if (adapter == NULL)
 
786
                return snprintf(buf, PAGE_SIZE, "error: no adapter\n");
 
787
 
 
788
        idx = ixgbe_name_to_idx(kobj->name);
 
789
        if (idx == -1)
 
790
                return snprintf(buf, PAGE_SIZE,
 
791
                                "error: invalid sensor name %s\n", kobj->name);
 
792
 
 
793
        return snprintf(buf, PAGE_SIZE, "%d\n",
 
794
                adapter->hw.mac.thermal_sensor_data.sensor[idx].caution_thresh);
 
795
}
 
796
 
 
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);
 
806
 
 
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);
 
879
 
 
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,
 
886
        NULL
 
887
};
 
888
 
 
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,
 
926
        NULL
 
927
};
 
928
 
 
929
/* add attributes to a group */
 
930
static struct attribute_group therm_attr_group = {
 
931
        .attrs = therm_attrs,
 
932
};
 
933
 
 
934
/* add attributes to a group */
 
935
static struct attribute_group attr_group = {
 
936
        .attrs = attrs,
 
937
};
 
938
 
 
939
static void ixgbe_del_adapter(struct ixgbe_adapter *adapter)
 
940
{
 
941
        int i;
 
942
 
 
943
        if (adapter == NULL)
 
944
                return;
 
945
 
 
946
        for (i = 0; i < IXGBE_MAX_SENSORS; i++) {
 
947
                if (adapter->therm_kobj[i] == NULL)
 
948
                        continue;
 
949
                sysfs_remove_group(adapter->therm_kobj[i], &therm_attr_group);
 
950
                kobject_put(adapter->therm_kobj[i]);
 
951
        }
 
952
        if (adapter->info_kobj != NULL) {
 
953
                sysfs_remove_group(adapter->info_kobj, &attr_group);
 
954
                kobject_put(adapter->info_kobj);
 
955
        }
 
956
}
 
957
 
 
958
/* called from ixgbe_main.c */
 
959
void ixgbe_sysfs_exit(struct ixgbe_adapter *adapter)
 
960
{
 
961
        ixgbe_del_adapter(adapter);
 
962
}
 
963
 
 
964
/* called from ixgbe_main.c */
 
965
int ixgbe_sysfs_init(struct ixgbe_adapter *adapter)
 
966
{
 
967
        struct net_device *netdev;
 
968
        int rc = 0;
 
969
        int i;
 
970
        char buf[16];
 
971
 
 
972
        if (adapter == NULL)
 
973
                goto err;
 
974
        netdev = adapter->netdev;
 
975
        if (netdev == NULL)
 
976
                goto err;
 
977
 
 
978
        adapter->info_kobj = NULL;
 
979
        for (i = 0; i < IXGBE_MAX_SENSORS; i++)
 
980
                adapter->therm_kobj[i] = NULL;
 
981
 
 
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)
 
986
                goto err;
 
987
        if (sysfs_create_group(adapter->info_kobj, &attr_group))
 
988
                goto err;
 
989
 
 
990
        /* Don't create thermal subkobjs if no data present */
 
991
        if (ixgbe_thermal_present(adapter->info_kobj) != true)
 
992
                goto exit;
 
993
 
 
994
        for (i = 0; i < IXGBE_MAX_SENSORS; i++) {
 
995
 
 
996
                /*
 
997
                 * Likewise only create individual kobjs that have
 
998
                 * meaningful data.
 
999
                 */
 
1000
                if (adapter->hw.mac.thermal_sensor_data.sensor[i].location == 0)
 
1001
                        continue;
 
1002
 
 
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)
 
1008
                        goto err;
 
1009
                if (sysfs_create_group(adapter->therm_kobj[i],
 
1010
                                       &therm_attr_group))
 
1011
                        goto err;
 
1012
        }
 
1013
 
 
1014
        goto exit;
 
1015
 
 
1016
err:
 
1017
        ixgbe_del_adapter(adapter);
 
1018
        rc = -1;
 
1019
exit:
 
1020
        return rc;
 
1021
}
 
1022
 
 
1023
#endif /* IXGBE_SYSFS */