1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2013 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 "e1000_82575.h"
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>
41 static struct proc_dir_entry *igb_top_dir = NULL;
44 bool igb_thermal_present(struct igb_adapter *adapter)
54 * Only set I2C bit-bang mode if an external thermal sensor is
55 * supported on this device.
58 status = e1000_set_i2c_bb(hw);
59 if (status != E1000_SUCCESS)
63 status = hw->mac.ops.init_thermal_sensor_thresh(hw);
64 if (status != E1000_SUCCESS)
71 static int igb_macburn(char *page, char **start, off_t off, int count,
75 struct igb_adapter *adapter = (struct igb_adapter *)data;
77 return snprintf(page, count, "error: no adapter\n");
81 return snprintf(page, count, "error: no hw data\n");
83 return snprintf(page, count, "0x%02X%02X%02X%02X%02X%02X\n",
84 (unsigned int)hw->mac.perm_addr[0],
85 (unsigned int)hw->mac.perm_addr[1],
86 (unsigned int)hw->mac.perm_addr[2],
87 (unsigned int)hw->mac.perm_addr[3],
88 (unsigned int)hw->mac.perm_addr[4],
89 (unsigned int)hw->mac.perm_addr[5]);
92 static int igb_macadmn(char *page, char **start, off_t off,
93 int count, int *eof, void *data)
96 struct igb_adapter *adapter = (struct igb_adapter *)data;
98 return snprintf(page, count, "error: no adapter\n");
102 return snprintf(page, count, "error: no hw data\n");
104 return snprintf(page, count, "0x%02X%02X%02X%02X%02X%02X\n",
105 (unsigned int)hw->mac.addr[0],
106 (unsigned int)hw->mac.addr[1],
107 (unsigned int)hw->mac.addr[2],
108 (unsigned int)hw->mac.addr[3],
109 (unsigned int)hw->mac.addr[4],
110 (unsigned int)hw->mac.addr[5]);
113 static int igb_numeports(char *page, char **start, off_t off, int count,
114 int *eof, void *data)
118 struct igb_adapter *adapter = (struct igb_adapter *)data;
120 return snprintf(page, count, "error: no adapter\n");
124 return snprintf(page, count, "error: no hw data\n");
128 return snprintf(page, count, "%d\n", ports);
131 static int igb_porttype(char *page, char **start, off_t off, int count,
132 int *eof, void *data)
134 struct igb_adapter *adapter = (struct igb_adapter *)data;
136 return snprintf(page, count, "error: no adapter\n");
138 return snprintf(page, count, "%d\n",
139 test_bit(__IGB_DOWN, &adapter->state));
142 static int igb_therm_location(char *page, char **start, off_t off,
143 int count, int *eof, void *data)
145 struct igb_therm_proc_data *therm_data =
146 (struct igb_therm_proc_data *)data;
148 if (therm_data == NULL)
149 return snprintf(page, count, "error: no therm_data\n");
151 return snprintf(page, count, "%d\n", therm_data->sensor_data->location);
154 static int igb_therm_maxopthresh(char *page, char **start, off_t off,
155 int count, int *eof, void *data)
157 struct igb_therm_proc_data *therm_data =
158 (struct igb_therm_proc_data *)data;
160 if (therm_data == NULL)
161 return snprintf(page, count, "error: no therm_data\n");
163 return snprintf(page, count, "%d\n",
164 therm_data->sensor_data->max_op_thresh);
167 static int igb_therm_cautionthresh(char *page, char **start, off_t off,
168 int count, int *eof, void *data)
170 struct igb_therm_proc_data *therm_data =
171 (struct igb_therm_proc_data *)data;
173 if (therm_data == NULL)
174 return snprintf(page, count, "error: no therm_data\n");
176 return snprintf(page, count, "%d\n",
177 therm_data->sensor_data->caution_thresh);
180 static int igb_therm_temp(char *page, char **start, off_t off,
181 int count, int *eof, void *data)
184 struct igb_therm_proc_data *therm_data =
185 (struct igb_therm_proc_data *)data;
187 if (therm_data == NULL)
188 return snprintf(page, count, "error: no therm_data\n");
190 status = e1000_get_thermal_sensor_data(therm_data->hw);
191 if (status != E1000_SUCCESS)
192 snprintf(page, count, "error: status %d returned\n", status);
194 return snprintf(page, count, "%d\n", therm_data->sensor_data->temp);
197 struct igb_proc_type{
199 int (*read)(char*, char**, off_t, int, int*, void*);
202 struct igb_proc_type igb_proc_entries[] = {
203 {"numeports", &igb_numeports},
204 {"porttype", &igb_porttype},
205 {"macburn", &igb_macburn},
206 {"macadmn", &igb_macadmn},
210 struct igb_proc_type igb_internal_entries[] = {
211 {"location", &igb_therm_location},
212 {"temp", &igb_therm_temp},
213 {"cautionthresh", &igb_therm_cautionthresh},
214 {"maxopthresh", &igb_therm_maxopthresh},
218 void igb_del_proc_entries(struct igb_adapter *adapter)
221 char buf[16]; /* much larger than the sensor number will ever be */
223 if (igb_top_dir == NULL)
226 for (i = 0; i < E1000_MAX_SENSORS; i++) {
227 if (adapter->therm_dir[i] == NULL)
230 for (index = 0; ; index++) {
231 if (igb_internal_entries[index].read == NULL)
234 remove_proc_entry(igb_internal_entries[index].name,
235 adapter->therm_dir[i]);
237 snprintf(buf, sizeof(buf), "sensor_%d", i);
238 remove_proc_entry(buf, adapter->info_dir);
241 if (adapter->info_dir != NULL) {
242 for (index = 0; ; index++) {
243 if (igb_proc_entries[index].read == NULL)
245 remove_proc_entry(igb_proc_entries[index].name,
248 remove_proc_entry("info", adapter->eth_dir);
251 if (adapter->eth_dir != NULL)
252 remove_proc_entry(pci_name(adapter->pdev), igb_top_dir);
255 /* called from igb_main.c */
256 void igb_procfs_exit(struct igb_adapter *adapter)
258 igb_del_proc_entries(adapter);
261 int igb_procfs_topdir_init(void)
263 igb_top_dir = proc_mkdir("driver/igb", NULL);
264 if (igb_top_dir == NULL)
270 void igb_procfs_topdir_exit(void)
272 remove_proc_entry("driver/igb", NULL);
275 /* called from igb_main.c */
276 int igb_procfs_init(struct igb_adapter *adapter)
281 char buf[16]; /* much larger than the sensor number will ever be */
283 adapter->eth_dir = NULL;
284 adapter->info_dir = NULL;
285 for (i = 0; i < E1000_MAX_SENSORS; i++)
286 adapter->therm_dir[i] = NULL;
288 if ( igb_top_dir == NULL ) {
293 adapter->eth_dir = proc_mkdir(pci_name(adapter->pdev), igb_top_dir);
294 if (adapter->eth_dir == NULL) {
299 adapter->info_dir = proc_mkdir("info", adapter->eth_dir);
300 if (adapter->info_dir == NULL) {
304 for (index = 0; ; index++) {
305 if (igb_proc_entries[index].read == NULL) {
308 if (!(create_proc_read_entry(igb_proc_entries[index].name,
311 igb_proc_entries[index].read,
318 if (igb_thermal_present(adapter) == false)
321 for (i = 0; i < E1000_MAX_SENSORS; i++) {
323 if (adapter->hw.mac.thermal_sensor_data.sensor[i].location== 0)
326 snprintf(buf, sizeof(buf), "sensor_%d", i);
327 adapter->therm_dir[i] = proc_mkdir(buf, adapter->info_dir);
328 if (adapter->therm_dir[i] == NULL) {
332 for (index = 0; ; index++) {
333 if (igb_internal_entries[index].read == NULL)
336 * therm_data struct contains pointer the read func
339 adapter->therm_data[i].hw = &adapter->hw;
340 adapter->therm_data[i].sensor_data =
341 &adapter->hw.mac.thermal_sensor_data.sensor[i];
343 if (!(create_proc_read_entry(
344 igb_internal_entries[index].name,
346 adapter->therm_dir[i],
347 igb_internal_entries[index].read,
348 &adapter->therm_data[i]))) {
357 igb_del_proc_entries(adapter);
362 #endif /* !IGB_HWMON */
363 #endif /* IGB_PROCFS */