1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
/*
* CDDL HEADER START
*
* Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at:
* http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When using or redistributing this file, you may do so under the
* License only. No other modification of this header is permitted.
*
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms of the CDDL.
*/
#include "igb_sw.h"
/* Function prototypes */
static int igb_nd_get(queue_t *, mblk_t *, caddr_t, cred_t *);
static int igb_nd_set(queue_t *, mblk_t *, char *, caddr_t, cred_t *);
static int igb_nd_param_load(igb_t *);
static void igb_nd_get_param_val(nd_param_t *);
static int igb_nd_set_param_val(nd_param_t *, uint32_t);
/*
* Notes:
* The first character of the <name> field encodes the read/write
* status of the parameter:
* '-' => read-only
* '+' => read/write,
* '?' => read/write on copper, read-only on serdes
* '!' => invisible!
*
* For writable parameters, we check for a driver property with the
* same name; if found, and its value is in range, we initialise
* the parameter from the property, overriding the default in the
* table below.
*
* A NULL in the <name> field terminates the array.
*
* The <info> field is used here to provide the index of the
* parameter to be initialised; thus it doesn't matter whether
* this table is kept ordered or not.
*
* The <info> field in the per-instance copy, on the other hand,
* is used to count assignments so that we can tell when a magic
* parameter has been set via ndd (see igb_nd_set()).
*/
static const nd_param_t nd_template[] = {
/* igb info min max init r/w+name */
/* Our hardware capabilities */
{ NULL, PARAM_AUTONEG_CAP, 0, 1, 1, "-autoneg_cap" },
{ NULL, PARAM_PAUSE_CAP, 0, 1, 1, "-pause_cap" },
{ NULL, PARAM_ASYM_PAUSE_CAP, 0, 1, 1, "-asym_pause_cap" },
{ NULL, PARAM_1000FDX_CAP, 0, 1, 1, "-1000fdx_cap" },
{ NULL, PARAM_1000HDX_CAP, 0, 1, 1, "-1000hdx_cap" },
{ NULL, PARAM_100T4_CAP, 0, 1, 0, "-100T4_cap" },
{ NULL, PARAM_100FDX_CAP, 0, 1, 1, "-100fdx_cap" },
{ NULL, PARAM_100HDX_CAP, 0, 1, 1, "-100hdx_cap" },
{ NULL, PARAM_10FDX_CAP, 0, 1, 1, "-10fdx_cap" },
{ NULL, PARAM_10HDX_CAP, 0, 1, 1, "-10hdx_cap" },
{ NULL, PARAM_REM_FAULT, 0, 1, 0, "-rem_fault" },
/* Our advertised capabilities */
{ NULL, PARAM_ADV_AUTONEG_CAP, 0, 1, 1, "?adv_autoneg_cap" },
{ NULL, PARAM_ADV_PAUSE_CAP, 0, 1, 1, "-adv_pause_cap" },
{ NULL, PARAM_ADV_ASYM_PAUSE_CAP, 0, 1, 1, "-adv_asym_pause_cap" },
{ NULL, PARAM_ADV_1000FDX_CAP, 0, 1, 1, "?adv_1000fdx_cap" },
{ NULL, PARAM_ADV_1000HDX_CAP, 0, 1, 1, "-adv_1000hdx_cap" },
{ NULL, PARAM_ADV_100T4_CAP, 0, 1, 0, "-adv_100T4_cap" },
{ NULL, PARAM_ADV_100FDX_CAP, 0, 1, 1, "?adv_100fdx_cap" },
{ NULL, PARAM_ADV_100HDX_CAP, 0, 1, 1, "?adv_100hdx_cap" },
{ NULL, PARAM_ADV_10FDX_CAP, 0, 1, 1, "?adv_10fdx_cap" },
{ NULL, PARAM_ADV_10HDX_CAP, 0, 1, 1, "?adv_10hdx_cap" },
{ NULL, PARAM_ADV_REM_FAULT, 0, 1, 0, "-adv_rem_fault" },
/* Partner's advertised capabilities */
{ NULL, PARAM_LP_AUTONEG_CAP, 0, 1, 0, "-lp_autoneg_cap" },
{ NULL, PARAM_LP_PAUSE_CAP, 0, 1, 0, "-lp_pause_cap" },
{ NULL, PARAM_LP_ASYM_PAUSE_CAP, 0, 1, 0, "-lp_asym_pause_cap" },
{ NULL, PARAM_LP_1000FDX_CAP, 0, 1, 0, "-lp_1000fdx_cap" },
{ NULL, PARAM_LP_1000HDX_CAP, 0, 1, 0, "-lp_1000hdx_cap" },
{ NULL, PARAM_LP_100T4_CAP, 0, 1, 0, "-lp_100T4_cap" },
{ NULL, PARAM_LP_100FDX_CAP, 0, 1, 0, "-lp_100fdx_cap" },
{ NULL, PARAM_LP_100HDX_CAP, 0, 1, 0, "-lp_100hdx_cap" },
{ NULL, PARAM_LP_10FDX_CAP, 0, 1, 0, "-lp_10fdx_cap" },
{ NULL, PARAM_LP_10HDX_CAP, 0, 1, 0, "-lp_10hdx_cap" },
{ NULL, PARAM_LP_REM_FAULT, 0, 1, 0, "-lp_rem_fault" },
/* Current operating modes */
{ NULL, PARAM_LINK_STATUS, 0, 1, 0, "-link_status" },
{ NULL, PARAM_LINK_SPEED, 0, 1000, 0, "-link_speed" },
{ NULL, PARAM_LINK_DUPLEX, 0, 2, 0, "-link_duplex" },
/* Terminator */
{ NULL, PARAM_COUNT, 0, 0, 0, NULL }
};
/*
* igb_nd_get - ndd get parameter values
*/
static int
igb_nd_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *credp)
{
nd_param_t *nd = (nd_param_t *)(uintptr_t)cp;
_NOTE(ARGUNUSED(q));
_NOTE(ARGUNUSED(credp));
igb_nd_get_param_val(nd);
(void) mi_mpprintf(mp, "%d", nd->val);
return (0);
}
/*
* igb_nd_set - ndd set parameter values
*/
static int
igb_nd_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *credp)
{
nd_param_t *nd = (nd_param_t *)(uintptr_t)cp;
long new_value;
char *end;
_NOTE(ARGUNUSED(q));
_NOTE(ARGUNUSED(mp));
_NOTE(ARGUNUSED(credp));
new_value = mi_strtol(value, &end, 10);
if (end == value)
return (EINVAL);
if (new_value < nd->min || new_value > nd->max)
return (EINVAL);
if (igb_nd_set_param_val(nd, new_value) != IGB_SUCCESS)
return (EIO);
return (0);
}
/*
* igb_nd_param_load
*/
static int
igb_nd_param_load(igb_t *igb)
{
const nd_param_t *tmpnd;
nd_param_t *nd;
caddr_t *ndd;
pfi_t setfn;
char *nm;
int value;
ndd = &igb->nd_data;
ASSERT(*ndd == NULL);
for (tmpnd = nd_template; tmpnd->name != NULL; ++tmpnd) {
/*
* Copy the template from nd_template[] into the
* proper slot in the per-instance parameters,
* then register the parameter with nd_load()
*/
nd = &igb->nd_params[tmpnd->info];
*nd = *tmpnd;
nd->private = igb;
igb_nd_get_param_val(nd);
nm = &nd->name[0];
setfn = igb_nd_set;
if (igb->hw.phy.media_type != e1000_media_type_copper) {
switch (*nm) {
default:
break;
case '?':
setfn = NULL;
break;
}
}
switch (*nm) {
default:
case '!':
continue;
case '+':
case '?':
break;
case '-':
setfn = NULL;
break;
}
if (!nd_load(ndd, ++nm, igb_nd_get, setfn, (caddr_t)nd))
goto nd_fail;
/*
* If the parameter is writable, and there's a property
* with the same name, and its value is in range, we use
* it to initialise the parameter. If it exists but is
* out of range, it's ignored.
*/
if (setfn && IGB_PROP_EXISTS(igb->dip, nm)) {
value = IGB_PROP_GET_INT(igb->dip, nm);
if (value >= nd->min && value <= nd->max)
nd->val = value;
}
}
return (IGB_SUCCESS);
nd_fail:
igb_log(igb,
"igb_nd_param_load: failed at index %d [info %d]",
(tmpnd - nd_template), tmpnd->info);
nd_free(ndd);
return (IGB_FAILURE);
}
/*
* igb_nd_get_param_val
*/
static void
igb_nd_get_param_val(nd_param_t *nd)
{
igb_t *igb = (igb_t *)nd->private;
mutex_enter(&igb->gen_lock);
switch (nd->info) {
case PARAM_LINK_STATUS:
nd->val = (igb->link_state == LINK_STATE_UP) ? 1 : 0;
break;
case PARAM_LINK_SPEED:
nd->val = igb->link_speed;
break;
case PARAM_LINK_DUPLEX:
nd->val = igb->link_duplex;
break;
default:
break;
}
mutex_exit(&igb->gen_lock);
}
/*
* igb_nd_set_param_val
*/
static int
igb_nd_set_param_val(nd_param_t *nd, uint32_t value)
{
igb_t *igb = (igb_t *)nd->private;
int result = IGB_SUCCESS;
mutex_enter(&igb->gen_lock);
if (nd->val == value) {
mutex_exit(&igb->gen_lock);
return (IGB_SUCCESS);
}
switch (nd->info) {
case PARAM_ADV_AUTONEG_CAP:
case PARAM_ADV_1000FDX_CAP:
case PARAM_ADV_100FDX_CAP:
case PARAM_ADV_100HDX_CAP:
case PARAM_ADV_10FDX_CAP:
case PARAM_ADV_10HDX_CAP:
nd->val = value;
(void) igb_setup_link(igb, B_TRUE);
if (igb_check_acc_handle(igb->osdep.reg_handle) != DDI_FM_OK) {
ddi_fm_service_impact(igb->dip, DDI_SERVICE_DEGRADED);
result = IGB_FAILURE;
}
break;
default:
break;
}
mutex_exit(&igb->gen_lock);
return (result);
}
/*
* comment describing function
*/
int
igb_nd_init(igb_t *igb)
{
/*
* Register all the per-instance properties, initialising
* them from the table above or from driver properties set
* in the .conf file
*/
if (igb_nd_param_load(igb) != IGB_SUCCESS)
return (IGB_FAILURE);
return (IGB_SUCCESS);
}
/*
* Free the Named Dispatch Table by calling nd_free
*/
void
igb_nd_cleanup(igb_t *igb)
{
nd_free(&igb->nd_data);
}
/*
* comment describing function
*/
enum ioc_reply
igb_nd_ioctl(igb_t *igb, queue_t *q,
mblk_t *mp, struct iocblk *ioc)
{
boolean_t ok;
int cmd;
cmd = ioc->ioc_cmd;
switch (cmd) {
default:
/* NOTREACHED */
ASSERT(B_FALSE);
return (IOC_INVAL);
case ND_GET:
/*
* If nd_getset() returns B_FALSE, the command was
* not valid (e.g. unknown name), so we just tell the
* top-level ioctl code to send a NAK (with code EINVAL).
*
* Otherwise, nd_getset() will have built the reply to
* be sent (but not actually sent it), so we tell the
* caller to send the prepared reply.
*/
ok = nd_getset(q, igb->nd_data, mp);
return (ok ? IOC_REPLY : IOC_INVAL);
case ND_SET:
/*
* All adv_* parameters are locked (read-only) while
* the device is in any sort of loopback mode ...
*/
if (igb->loopback_mode != IGB_LB_NONE) {
ioc->ioc_error = EBUSY;
return (IOC_INVAL);
}
ok = nd_getset(q, igb->nd_data, mp);
return (ok ? IOC_REPLY : IOC_INVAL);
}
}
|