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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
/*
* CDDL HEADER START
*
* 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 usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* 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.
*/
#include <hxge_impl.h>
#include <hxge_vmac.h>
hxge_status_t hxge_vmac_init(p_hxge_t hxgep);
hxge_status_t hxge_tx_vmac_init(p_hxge_t hxgep);
hxge_status_t hxge_rx_vmac_init(p_hxge_t hxgep);
hxge_status_t hxge_tx_vmac_enable(p_hxge_t hxgep);
hxge_status_t hxge_tx_vmac_disable(p_hxge_t hxgep);
hxge_status_t hxge_rx_vmac_enable(p_hxge_t hxgep);
hxge_status_t hxge_rx_vmac_disable(p_hxge_t hxgep);
hxge_status_t hxge_tx_vmac_reset(p_hxge_t hxgep);
hxge_status_t hxge_rx_vmac_reset(p_hxge_t hxgep);
uint_t hxge_vmac_intr(caddr_t arg1, caddr_t arg2);
hxge_status_t hxge_set_promisc(p_hxge_t hxgep, boolean_t on);
hxge_status_t
hxge_link_init(p_hxge_t hxgep)
{
p_hxge_stats_t statsp;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_link_init>"));
statsp = hxgep->statsp;
statsp->mac_stats.cap_10gfdx = 1;
statsp->mac_stats.lp_cap_10gfdx = 1;
/*
* The driver doesn't control the link.
* It is always 10Gb full duplex.
*/
statsp->mac_stats.link_duplex = 2;
statsp->mac_stats.link_speed = 10000;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_link_init"));
return (HXGE_OK);
}
hxge_status_t
hxge_vmac_init(p_hxge_t hxgep)
{
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_vmac_init:"));
if ((status = hxge_tx_vmac_reset(hxgep)) != HXGE_OK)
goto fail;
if ((status = hxge_rx_vmac_reset(hxgep)) != HXGE_OK)
goto fail;
if ((status = hxge_tx_vmac_enable(hxgep)) != HXGE_OK)
goto fail;
if ((status = hxge_rx_vmac_enable(hxgep)) != HXGE_OK)
goto fail;
/* Clear the interrupt status registers */
(void) hpi_vmac_clear_rx_int_stat(hxgep->hpi_handle);
(void) hpi_vmac_clear_tx_int_stat(hxgep->hpi_handle);
/*
* Take the masks off the overflow counters. Interrupt the system when
* any counts overflow. Don't interrupt the system for each frame.
* The current counts are retrieved when the "kstat" command is used.
*/
(void) hpi_pfc_set_rx_int_stat_mask(hxgep->hpi_handle, 0, 1);
(void) hpi_pfc_set_tx_int_stat_mask(hxgep->hpi_handle, 0, 1);
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_vmac_init:"));
return (HXGE_OK);
fail:
HXGE_DEBUG_MSG((hxgep, MAC_CTL,
"hxge_vmac_init: failed to initialize VMAC>"));
return (status);
}
/* Initialize the TxVMAC sub-block */
hxge_status_t
hxge_tx_vmac_init(p_hxge_t hxgep)
{
uint64_t config;
hpi_handle_t handle = hxgep->hpi_handle;
/* CFG_VMAC_TX_EN is done separately */
config = CFG_VMAC_TX_CRC_INSERT | CFG_VMAC_TX_PAD;
if (hpi_vmac_tx_config(handle, INIT, config,
hxgep->vmac.maxframesize) != HPI_SUCCESS)
return (HXGE_ERROR);
hxgep->vmac.tx_config = config;
return (HXGE_OK);
}
/* Initialize the RxVMAC sub-block */
hxge_status_t
hxge_rx_vmac_init(p_hxge_t hxgep)
{
uint64_t xconfig;
hpi_handle_t handle = hxgep->hpi_handle;
uint16_t max_frame_length = hxgep->vmac.maxframesize;
/*
* NOTE: CFG_VMAC_RX_ENABLE is done separately. Do not enable
* strip CRC. Bug ID 11451 -- enable strip CRC will cause
* rejection on minimum sized packets.
*/
xconfig = CFG_VMAC_RX_PASS_FLOW_CTRL_FR;
if (hxgep->filter.all_phys_cnt != 0)
xconfig |= CFG_VMAC_RX_PROMISCUOUS_MODE;
if (hxgep->filter.all_multicast_cnt != 0)
xconfig |= CFG_VMAC_RX_PROMIXCUOUS_GROUP;
if (hxgep->statsp->port_stats.lb_mode != hxge_lb_normal)
xconfig |= CFG_VMAC_RX_LOOP_BACK;
if (hpi_vmac_rx_config(handle, INIT, xconfig,
max_frame_length) != HPI_SUCCESS)
return (HXGE_ERROR);
hxgep->vmac.rx_config = xconfig;
return (HXGE_OK);
}
/* Enable TxVMAC */
hxge_status_t
hxge_tx_vmac_enable(p_hxge_t hxgep)
{
hpi_status_t rv;
hxge_status_t status = HXGE_OK;
hpi_handle_t handle = hxgep->hpi_handle;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_tx_vmac_enable"));
rv = hxge_tx_vmac_init(hxgep);
if (rv != HXGE_OK)
return (rv);
/* Based on speed */
hxgep->msg_min = ETHERMIN;
rv = hpi_vmac_tx_config(handle, ENABLE, CFG_VMAC_TX_EN, 0);
status = (rv == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_tx_vmac_enable"));
return (status);
}
/* Disable TxVMAC */
hxge_status_t
hxge_tx_vmac_disable(p_hxge_t hxgep)
{
hpi_status_t rv;
hxge_status_t status = HXGE_OK;
hpi_handle_t handle = hxgep->hpi_handle;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_tx_vmac_disable"));
rv = hpi_vmac_tx_config(handle, DISABLE, CFG_VMAC_TX_EN, 0);
status = (rv == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_tx_vmac_disable"));
return (status);
}
/* Enable RxVMAC */
hxge_status_t
hxge_rx_vmac_enable(p_hxge_t hxgep)
{
hpi_status_t rv;
hxge_status_t status = HXGE_OK;
hpi_handle_t handle = hxgep->hpi_handle;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_rx_vmac_enable"));
/*
* Because of hardware bug document with CR6770577, need
* reprogram max framesize when enabling/disabling RX
* vmac. Max framesize is programed here in
* hxge_rx_vmac_init().
*/
rv = hpi_vmac_rx_set_framesize(HXGE_DEV_HPI_HANDLE(hxgep),
(uint16_t)hxgep->vmac.maxframesize);
if (rv != HPI_SUCCESS) {
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_rx_vmac_enable"));
return (HXGE_ERROR);
}
/*
* Wait for a period of time.
*/
HXGE_DELAY(10);
/*
* Enable the vmac.
*/
rv = hpi_vmac_rx_config(handle, ENABLE, CFG_VMAC_RX_EN, 0);
status = (rv == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_rx_vmac_enable"));
return (status);
}
/* Disable RxVMAC */
hxge_status_t
hxge_rx_vmac_disable(p_hxge_t hxgep)
{
hpi_status_t rv;
hxge_status_t status = HXGE_OK;
hpi_handle_t handle = hxgep->hpi_handle;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_rx_vmac_disable"));
/*
* Because of hardware bug document with CR6770577, need
* reprogram max framesize when enabling/disabling RX
* vmac. Max framesize is programed here in
* hxge_rx_vmac_init().
*/
(void) hpi_vmac_rx_set_framesize(HXGE_DEV_HPI_HANDLE(hxgep),
(uint16_t)0);
/*
* Wait for 10us before doing disable.
*/
HXGE_DELAY(10);
rv = hpi_vmac_rx_config(handle, DISABLE, CFG_VMAC_RX_EN, 0);
status = (rv == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_rx_vmac_disable"));
return (status);
}
/* Reset TxVMAC */
hxge_status_t
hxge_tx_vmac_reset(p_hxge_t hxgep)
{
hpi_handle_t handle = hxgep->hpi_handle;
(void) hpi_tx_vmac_reset(handle);
return (HXGE_OK);
}
/* Reset RxVMAC */
hxge_status_t
hxge_rx_vmac_reset(p_hxge_t hxgep)
{
hpi_handle_t handle = hxgep->hpi_handle;
(void) hpi_vmac_rx_set_framesize(HXGE_DEV_HPI_HANDLE(hxgep),
(uint16_t)0);
/*
* Wait for 10us before doing reset.
*/
HXGE_DELAY(10);
(void) hpi_rx_vmac_reset(handle);
return (HXGE_OK);
}
/*ARGSUSED*/
uint_t
hxge_vmac_intr(caddr_t arg1, caddr_t arg2)
{
p_hxge_t hxgep = (p_hxge_t)arg2;
hpi_handle_t handle;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_vmac_intr"));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
hxge_save_cntrs(hxgep);
/* Clear the interrupt status registers */
(void) hpi_vmac_clear_rx_int_stat(handle);
(void) hpi_vmac_clear_tx_int_stat(handle);
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_vmac_intr"));
return (DDI_INTR_CLAIMED);
}
/*
* Set promiscous mode
*/
hxge_status_t
hxge_set_promisc(p_hxge_t hxgep, boolean_t on)
{
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "==> hxge_set_promisc: on %d", on));
hxgep->filter.all_phys_cnt = ((on) ? 1 : 0);
RW_ENTER_WRITER(&hxgep->filter_lock);
if ((status = hxge_rx_vmac_disable(hxgep)) != HXGE_OK)
goto fail;
if ((status = hxge_rx_vmac_enable(hxgep)) != HXGE_OK)
goto fail;
RW_EXIT(&hxgep->filter_lock);
if (on)
hxgep->statsp->mac_stats.promisc = B_TRUE;
else
hxgep->statsp->mac_stats.promisc = B_FALSE;
HXGE_DEBUG_MSG((hxgep, MAC_CTL, "<== hxge_set_promisc"));
return (HXGE_OK);
fail:
RW_EXIT(&hxgep->filter_lock);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "hxge_set_promisc: "
"Unable to set promisc (%d)", on));
return (status);
}
void
hxge_save_cntrs(p_hxge_t hxgep)
{
p_hxge_stats_t statsp;
hpi_handle_t handle;
vmac_tx_frame_cnt_t tx_frame_cnt;
vmac_tx_byte_cnt_t tx_byte_cnt;
vmac_rx_frame_cnt_t rx_frame_cnt;
vmac_rx_byte_cnt_t rx_byte_cnt;
vmac_rx_drop_fr_cnt_t rx_drop_fr_cnt;
vmac_rx_drop_byte_cnt_t rx_drop_byte_cnt;
vmac_rx_crc_cnt_t rx_crc_cnt;
vmac_rx_pause_cnt_t rx_pause_cnt;
vmac_rx_bcast_fr_cnt_t rx_bcast_fr_cnt;
vmac_rx_mcast_fr_cnt_t rx_mcast_fr_cnt;
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_save_cntrs"));
statsp = (p_hxge_stats_t)hxgep->statsp;
handle = hxgep->hpi_handle;
HXGE_REG_RD64(handle, VMAC_TX_FRAME_CNT, &tx_frame_cnt.value);
HXGE_REG_RD64(handle, VMAC_TX_BYTE_CNT, &tx_byte_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_FRAME_CNT, &rx_frame_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_BYTE_CNT, &rx_byte_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_DROP_FR_CNT, &rx_drop_fr_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_DROP_BYTE_CNT, &rx_drop_byte_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_CRC_CNT, &rx_crc_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_PAUSE_CNT, &rx_pause_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_BCAST_FR_CNT, &rx_bcast_fr_cnt.value);
HXGE_REG_RD64(handle, VMAC_RX_MCAST_FR_CNT, &rx_mcast_fr_cnt.value);
statsp->vmac_stats.tx_frame_cnt += tx_frame_cnt.bits.tx_frame_cnt;
statsp->vmac_stats.tx_byte_cnt += tx_byte_cnt.bits.tx_byte_cnt;
statsp->vmac_stats.rx_frame_cnt += rx_frame_cnt.bits.rx_frame_cnt;
statsp->vmac_stats.rx_byte_cnt += rx_byte_cnt.bits.rx_byte_cnt;
statsp->vmac_stats.rx_drop_frame_cnt +=
rx_drop_fr_cnt.bits.rx_drop_frame_cnt;
statsp->vmac_stats.rx_drop_byte_cnt +=
rx_drop_byte_cnt.bits.rx_drop_byte_cnt;
statsp->vmac_stats.rx_crc_cnt += rx_crc_cnt.bits.rx_crc_cnt;
statsp->vmac_stats.rx_pause_cnt += rx_pause_cnt.bits.rx_pause_cnt;
statsp->vmac_stats.rx_bcast_fr_cnt +=
rx_bcast_fr_cnt.bits.rx_bcast_fr_cnt;
statsp->vmac_stats.rx_mcast_fr_cnt +=
rx_mcast_fr_cnt.bits.rx_mcast_fr_cnt;
hxge_save_cntrs_exit:
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_save_cntrs"));
}
int
hxge_vmac_set_framesize(p_hxge_t hxgep)
{
int status = 0;
HXGE_DEBUG_MSG((hxgep, NDD_CTL, "==> hxge_vmac_set_framesize"));
RW_ENTER_WRITER(&hxgep->filter_lock);
(void) hxge_rx_vmac_disable(hxgep);
(void) hxge_tx_vmac_disable(hxgep);
/*
* Apply the new jumbo parameter here which is contained in hxgep
* data structure (hxgep->vmac.maxframesize);
* The order of the following two calls is important.
*/
(void) hxge_tx_vmac_enable(hxgep);
(void) hxge_rx_vmac_enable(hxgep);
RW_EXIT(&hxgep->filter_lock);
HXGE_DEBUG_MSG((hxgep, NDD_CTL, "<== hxge_vmac_set_framesize"));
return (status);
}
|