xref: /illumos-gate/usr/src/uts/common/io/igb/igb_gld.c (revision b6c3f786)
1 /*
2  * CDDL HEADER START
3  *
4  * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at:
10  *	http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When using or redistributing this file, you may do so under the
15  * License only. No other modification of this header is permitted.
16  *
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms of the CDDL.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include "igb_sw.h"
32 
33 int
34 igb_m_stat(void *arg, uint_t stat, uint64_t *val)
35 {
36 	igb_t *igb = (igb_t *)arg;
37 	struct e1000_hw *hw = &igb->hw;
38 	igb_stat_t *igb_ks;
39 	uint32_t low_val, high_val;
40 
41 	igb_ks = (igb_stat_t *)igb->igb_ks->ks_data;
42 
43 	mutex_enter(&igb->gen_lock);
44 
45 	if (igb->igb_state & IGB_SUSPENDED) {
46 		mutex_exit(&igb->gen_lock);
47 		return (ECANCELED);
48 	}
49 
50 	switch (stat) {
51 	case MAC_STAT_IFSPEED:
52 		*val = igb->link_speed * 1000000ull;
53 		break;
54 
55 	case MAC_STAT_MULTIRCV:
56 		igb_ks->mprc.value.ui64 +=
57 		    E1000_READ_REG(hw, E1000_MPRC);
58 		*val = igb_ks->mprc.value.ui64;
59 		break;
60 
61 	case MAC_STAT_BRDCSTRCV:
62 		igb_ks->bprc.value.ui64 +=
63 		    E1000_READ_REG(hw, E1000_BPRC);
64 		*val = igb_ks->bprc.value.ui64;
65 		break;
66 
67 	case MAC_STAT_MULTIXMT:
68 		igb_ks->mptc.value.ui64 +=
69 		    E1000_READ_REG(hw, E1000_MPTC);
70 		*val = igb_ks->mptc.value.ui64;
71 		break;
72 
73 	case MAC_STAT_BRDCSTXMT:
74 		igb_ks->bptc.value.ui64 +=
75 		    E1000_READ_REG(hw, E1000_BPTC);
76 		*val = igb_ks->bptc.value.ui64;
77 		break;
78 
79 	case MAC_STAT_NORCVBUF:
80 		igb_ks->rnbc.value.ui64 +=
81 		    E1000_READ_REG(hw, E1000_RNBC);
82 		*val = igb_ks->rnbc.value.ui64;
83 		break;
84 
85 	case MAC_STAT_IERRORS:
86 		igb_ks->rxerrc.value.ui64 +=
87 		    E1000_READ_REG(hw, E1000_RXERRC);
88 		igb_ks->algnerrc.value.ui64 +=
89 		    E1000_READ_REG(hw, E1000_ALGNERRC);
90 		igb_ks->rlec.value.ui64 +=
91 		    E1000_READ_REG(hw, E1000_RLEC);
92 		igb_ks->crcerrs.value.ui64 +=
93 		    E1000_READ_REG(hw, E1000_CRCERRS);
94 		igb_ks->cexterr.value.ui64 +=
95 		    E1000_READ_REG(hw, E1000_CEXTERR);
96 		*val = igb_ks->rxerrc.value.ui64 +
97 		    igb_ks->algnerrc.value.ui64 +
98 		    igb_ks->rlec.value.ui64 +
99 		    igb_ks->crcerrs.value.ui64 +
100 		    igb_ks->cexterr.value.ui64;
101 		break;
102 
103 	case MAC_STAT_NOXMTBUF:
104 		*val = 0;
105 		break;
106 
107 	case MAC_STAT_OERRORS:
108 		igb_ks->ecol.value.ui64 +=
109 		    E1000_READ_REG(hw, E1000_ECOL);
110 		*val = igb_ks->ecol.value.ui64;
111 		break;
112 
113 	case MAC_STAT_COLLISIONS:
114 		igb_ks->colc.value.ui64 +=
115 		    E1000_READ_REG(hw, E1000_COLC);
116 		*val = igb_ks->colc.value.ui64;
117 		break;
118 
119 	case MAC_STAT_RBYTES:
120 		/*
121 		 * The 64-bit register will reset whenever the upper
122 		 * 32 bits are read. So we need to read the lower
123 		 * 32 bits first, then read the upper 32 bits.
124 		 */
125 		low_val = E1000_READ_REG(hw, E1000_TORL);
126 		high_val = E1000_READ_REG(hw, E1000_TORH);
127 		igb_ks->tor.value.ui64 +=
128 		    (uint64_t)high_val << 32 | (uint64_t)low_val;
129 		*val = igb_ks->tor.value.ui64;
130 		break;
131 
132 	case MAC_STAT_IPACKETS:
133 		igb_ks->tpr.value.ui64 +=
134 		    E1000_READ_REG(hw, E1000_TPR);
135 		*val = igb_ks->tpr.value.ui64;
136 		break;
137 
138 	case MAC_STAT_OBYTES:
139 		/*
140 		 * The 64-bit register will reset whenever the upper
141 		 * 32 bits are read. So we need to read the lower
142 		 * 32 bits first, then read the upper 32 bits.
143 		 */
144 		low_val = E1000_READ_REG(hw, E1000_TOTL);
145 		high_val = E1000_READ_REG(hw, E1000_TOTH);
146 		igb_ks->tot.value.ui64 +=
147 		    (uint64_t)high_val << 32 | (uint64_t)low_val;
148 		*val = igb_ks->tot.value.ui64;
149 		break;
150 
151 	case MAC_STAT_OPACKETS:
152 		igb_ks->tpt.value.ui64 +=
153 		    E1000_READ_REG(hw, E1000_TPT);
154 		*val = igb_ks->tpt.value.ui64;
155 		break;
156 
157 	/* RFC 1643 stats */
158 	case ETHER_STAT_ALIGN_ERRORS:
159 		igb_ks->algnerrc.value.ui64 +=
160 		    E1000_READ_REG(hw, E1000_ALGNERRC);
161 		*val = igb_ks->algnerrc.value.ui64;
162 		break;
163 
164 	case ETHER_STAT_FCS_ERRORS:
165 		igb_ks->crcerrs.value.ui64 +=
166 		    E1000_READ_REG(hw, E1000_CRCERRS);
167 		*val = igb_ks->crcerrs.value.ui64;
168 		break;
169 
170 	case ETHER_STAT_FIRST_COLLISIONS:
171 		igb_ks->scc.value.ui64 +=
172 		    E1000_READ_REG(hw, E1000_SCC);
173 		*val = igb_ks->scc.value.ui64;
174 		break;
175 
176 	case ETHER_STAT_MULTI_COLLISIONS:
177 		igb_ks->mcc.value.ui64 +=
178 		    E1000_READ_REG(hw, E1000_MCC);
179 		*val = igb_ks->mcc.value.ui64;
180 		break;
181 
182 	case ETHER_STAT_SQE_ERRORS:
183 		igb_ks->sec.value.ui64 +=
184 		    E1000_READ_REG(hw, E1000_SEC);
185 		*val = igb_ks->sec.value.ui64;
186 		break;
187 
188 	case ETHER_STAT_DEFER_XMTS:
189 		igb_ks->dc.value.ui64 +=
190 		    E1000_READ_REG(hw, E1000_DC);
191 		*val = igb_ks->dc.value.ui64;
192 		break;
193 
194 	case ETHER_STAT_TX_LATE_COLLISIONS:
195 		igb_ks->latecol.value.ui64 +=
196 		    E1000_READ_REG(hw, E1000_LATECOL);
197 		*val = igb_ks->latecol.value.ui64;
198 		break;
199 
200 	case ETHER_STAT_EX_COLLISIONS:
201 		igb_ks->ecol.value.ui64 +=
202 		    E1000_READ_REG(hw, E1000_ECOL);
203 		*val = igb_ks->ecol.value.ui64;
204 		break;
205 
206 	case ETHER_STAT_MACXMT_ERRORS:
207 		igb_ks->ecol.value.ui64 +=
208 		    E1000_READ_REG(hw, E1000_ECOL);
209 		*val = igb_ks->ecol.value.ui64;
210 		break;
211 
212 	case ETHER_STAT_CARRIER_ERRORS:
213 		igb_ks->cexterr.value.ui64 +=
214 		    E1000_READ_REG(hw, E1000_CEXTERR);
215 		*val = igb_ks->cexterr.value.ui64;
216 		break;
217 
218 	case ETHER_STAT_TOOLONG_ERRORS:
219 		igb_ks->roc.value.ui64 +=
220 		    E1000_READ_REG(hw, E1000_ROC);
221 		*val = igb_ks->roc.value.ui64;
222 		break;
223 
224 	case ETHER_STAT_MACRCV_ERRORS:
225 		igb_ks->rxerrc.value.ui64 +=
226 		    E1000_READ_REG(hw, E1000_RXERRC);
227 		*val = igb_ks->rxerrc.value.ui64;
228 		break;
229 
230 	/* MII/GMII stats */
231 	case ETHER_STAT_XCVR_ADDR:
232 		/* The Internal PHY's MDI address for each MAC is 1 */
233 		*val = 1;
234 		break;
235 
236 	case ETHER_STAT_XCVR_ID:
237 		*val = hw->phy.id | hw->phy.revision;
238 		break;
239 
240 	case ETHER_STAT_XCVR_INUSE:
241 		switch (igb->link_speed) {
242 		case SPEED_1000:
243 			*val =
244 			    (hw->phy.media_type == e1000_media_type_copper) ?
245 			    XCVR_1000T : XCVR_1000X;
246 			break;
247 		case SPEED_100:
248 			*val =
249 			    (hw->phy.media_type == e1000_media_type_copper) ?
250 			    (igb->param_100t4_cap == 1) ?
251 			    XCVR_100T4 : XCVR_100T2 : XCVR_100X;
252 			break;
253 		case SPEED_10:
254 			*val = XCVR_10;
255 			break;
256 		default:
257 			*val = XCVR_NONE;
258 			break;
259 		}
260 		break;
261 
262 	case ETHER_STAT_CAP_1000FDX:
263 		*val = igb->param_1000fdx_cap;
264 		break;
265 
266 	case ETHER_STAT_CAP_1000HDX:
267 		*val = igb->param_1000hdx_cap;
268 		break;
269 
270 	case ETHER_STAT_CAP_100FDX:
271 		*val = igb->param_100fdx_cap;
272 		break;
273 
274 	case ETHER_STAT_CAP_100HDX:
275 		*val = igb->param_100hdx_cap;
276 		break;
277 
278 	case ETHER_STAT_CAP_10FDX:
279 		*val = igb->param_10fdx_cap;
280 		break;
281 
282 	case ETHER_STAT_CAP_10HDX:
283 		*val = igb->param_10hdx_cap;
284 		break;
285 
286 	case ETHER_STAT_CAP_ASMPAUSE:
287 		*val = igb->param_asym_pause_cap;
288 		break;
289 
290 	case ETHER_STAT_CAP_PAUSE:
291 		*val = igb->param_pause_cap;
292 		break;
293 
294 	case ETHER_STAT_CAP_AUTONEG:
295 		*val = igb->param_autoneg_cap;
296 		break;
297 
298 	case ETHER_STAT_ADV_CAP_1000FDX:
299 		*val = igb->param_adv_1000fdx_cap;
300 		break;
301 
302 	case ETHER_STAT_ADV_CAP_1000HDX:
303 		*val = igb->param_adv_1000hdx_cap;
304 		break;
305 
306 	case ETHER_STAT_ADV_CAP_100FDX:
307 		*val = igb->param_adv_100fdx_cap;
308 		break;
309 
310 	case ETHER_STAT_ADV_CAP_100HDX:
311 		*val = igb->param_adv_100hdx_cap;
312 		break;
313 
314 	case ETHER_STAT_ADV_CAP_10FDX:
315 		*val = igb->param_adv_10fdx_cap;
316 		break;
317 
318 	case ETHER_STAT_ADV_CAP_10HDX:
319 		*val = igb->param_adv_10hdx_cap;
320 		break;
321 
322 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
323 		*val = igb->param_adv_asym_pause_cap;
324 		break;
325 
326 	case ETHER_STAT_ADV_CAP_PAUSE:
327 		*val = igb->param_adv_pause_cap;
328 		break;
329 
330 	case ETHER_STAT_ADV_CAP_AUTONEG:
331 		*val = hw->mac.autoneg;
332 		break;
333 
334 	case ETHER_STAT_LP_CAP_1000FDX:
335 		*val = igb->param_lp_1000fdx_cap;
336 		break;
337 
338 	case ETHER_STAT_LP_CAP_1000HDX:
339 		*val = igb->param_lp_1000hdx_cap;
340 		break;
341 
342 	case ETHER_STAT_LP_CAP_100FDX:
343 		*val = igb->param_lp_100fdx_cap;
344 		break;
345 
346 	case ETHER_STAT_LP_CAP_100HDX:
347 		*val = igb->param_lp_100hdx_cap;
348 		break;
349 
350 	case ETHER_STAT_LP_CAP_10FDX:
351 		*val = igb->param_lp_10fdx_cap;
352 		break;
353 
354 	case ETHER_STAT_LP_CAP_10HDX:
355 		*val = igb->param_lp_10hdx_cap;
356 		break;
357 
358 	case ETHER_STAT_LP_CAP_ASMPAUSE:
359 		*val = igb->param_lp_asym_pause_cap;
360 		break;
361 
362 	case ETHER_STAT_LP_CAP_PAUSE:
363 		*val = igb->param_lp_pause_cap;
364 		break;
365 
366 	case ETHER_STAT_LP_CAP_AUTONEG:
367 		*val = igb->param_lp_autoneg_cap;
368 		break;
369 
370 	case ETHER_STAT_LINK_ASMPAUSE:
371 		*val = igb->param_asym_pause_cap;
372 		break;
373 
374 	case ETHER_STAT_LINK_PAUSE:
375 		*val = igb->param_pause_cap;
376 		break;
377 
378 	case ETHER_STAT_LINK_AUTONEG:
379 		*val = hw->mac.autoneg;
380 		break;
381 
382 	case ETHER_STAT_LINK_DUPLEX:
383 		*val = (igb->link_duplex == FULL_DUPLEX) ?
384 		    LINK_DUPLEX_FULL : LINK_DUPLEX_HALF;
385 		break;
386 
387 	case ETHER_STAT_TOOSHORT_ERRORS:
388 		igb_ks->ruc.value.ui64 +=
389 		    E1000_READ_REG(hw, E1000_RUC);
390 		*val = igb_ks->ruc.value.ui64;
391 		break;
392 
393 	case ETHER_STAT_CAP_REMFAULT:
394 		*val = igb->param_rem_fault;
395 		break;
396 
397 	case ETHER_STAT_ADV_REMFAULT:
398 		*val = igb->param_adv_rem_fault;
399 		break;
400 
401 	case ETHER_STAT_LP_REMFAULT:
402 		*val = igb->param_lp_rem_fault;
403 		break;
404 
405 	case ETHER_STAT_JABBER_ERRORS:
406 		igb_ks->rjc.value.ui64 +=
407 		    E1000_READ_REG(hw, E1000_RJC);
408 		*val = igb_ks->rjc.value.ui64;
409 		break;
410 
411 	case ETHER_STAT_CAP_100T4:
412 		*val = igb->param_100t4_cap;
413 		break;
414 
415 	case ETHER_STAT_ADV_CAP_100T4:
416 		*val = igb->param_adv_100t4_cap;
417 		break;
418 
419 	case ETHER_STAT_LP_CAP_100T4:
420 		*val = igb->param_lp_100t4_cap;
421 		break;
422 
423 	default:
424 		mutex_exit(&igb->gen_lock);
425 		return (ENOTSUP);
426 	}
427 
428 	mutex_exit(&igb->gen_lock);
429 
430 	return (0);
431 }
432 
433 /*
434  * Bring the device out of the reset/quiesced state that it
435  * was in when the interface was registered.
436  */
437 int
438 igb_m_start(void *arg)
439 {
440 	igb_t *igb = (igb_t *)arg;
441 
442 	mutex_enter(&igb->gen_lock);
443 
444 	if (igb->igb_state & IGB_SUSPENDED) {
445 		mutex_exit(&igb->gen_lock);
446 		return (ECANCELED);
447 	}
448 
449 	if (igb_start(igb) != IGB_SUCCESS) {
450 		mutex_exit(&igb->gen_lock);
451 		return (EIO);
452 	}
453 
454 	igb->igb_state |= IGB_STARTED;
455 
456 	mutex_exit(&igb->gen_lock);
457 
458 	/*
459 	 * Enable and start the watchdog timer
460 	 */
461 	igb_enable_watchdog_timer(igb);
462 
463 	return (0);
464 }
465 
466 /*
467  * Stop the device and put it in a reset/quiesced state such
468  * that the interface can be unregistered.
469  */
470 void
471 igb_m_stop(void *arg)
472 {
473 	igb_t *igb = (igb_t *)arg;
474 
475 	mutex_enter(&igb->gen_lock);
476 
477 	if (igb->igb_state & IGB_SUSPENDED) {
478 		mutex_exit(&igb->gen_lock);
479 		return;
480 	}
481 
482 	igb->igb_state &= ~IGB_STARTED;
483 
484 	igb_stop(igb);
485 
486 	mutex_exit(&igb->gen_lock);
487 
488 	/*
489 	 * Disable and stop the watchdog timer
490 	 */
491 	igb_disable_watchdog_timer(igb);
492 }
493 
494 /*
495  * Set the promiscuity of the device.
496  */
497 int
498 igb_m_promisc(void *arg, boolean_t on)
499 {
500 	igb_t *igb = (igb_t *)arg;
501 	uint32_t reg_val;
502 
503 	mutex_enter(&igb->gen_lock);
504 
505 	if (igb->igb_state & IGB_SUSPENDED) {
506 		mutex_exit(&igb->gen_lock);
507 		return (ECANCELED);
508 	}
509 
510 	reg_val = E1000_READ_REG(&igb->hw, E1000_RCTL);
511 
512 	if (on)
513 		reg_val |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
514 	else
515 		reg_val &= (~(E1000_RCTL_UPE | E1000_RCTL_MPE));
516 
517 	E1000_WRITE_REG(&igb->hw, E1000_RCTL, reg_val);
518 
519 	mutex_exit(&igb->gen_lock);
520 
521 	return (0);
522 }
523 
524 /*
525  * Add/remove the addresses to/from the set of multicast
526  * addresses for which the device will receive packets.
527  */
528 int
529 igb_m_multicst(void *arg, boolean_t add, const uint8_t *mcst_addr)
530 {
531 	igb_t *igb = (igb_t *)arg;
532 	int result;
533 
534 	mutex_enter(&igb->gen_lock);
535 
536 	if (igb->igb_state & IGB_SUSPENDED) {
537 		mutex_exit(&igb->gen_lock);
538 		return (ECANCELED);
539 	}
540 
541 	result = (add) ? igb_multicst_add(igb, mcst_addr)
542 	    : igb_multicst_remove(igb, mcst_addr);
543 
544 	mutex_exit(&igb->gen_lock);
545 
546 	return (result);
547 }
548 
549 /*
550  * Set a new device unicast address.
551  */
552 int
553 igb_m_unicst(void *arg, const uint8_t *mac_addr)
554 {
555 	igb_t *igb = (igb_t *)arg;
556 	int result;
557 
558 	mutex_enter(&igb->gen_lock);
559 
560 	if (igb->igb_state & IGB_SUSPENDED) {
561 		mutex_exit(&igb->gen_lock);
562 		return (ECANCELED);
563 	}
564 
565 	/*
566 	 * Store the new MAC address.
567 	 */
568 	bcopy(mac_addr, igb->hw.mac.addr, ETHERADDRL);
569 
570 	/*
571 	 * Set MAC address in address slot 0, which is the default address.
572 	 */
573 	result = igb_unicst_set(igb, mac_addr, 0);
574 
575 	mutex_exit(&igb->gen_lock);
576 
577 	return (result);
578 }
579 
580 /*
581  * Pass on M_IOCTL messages passed to the DLD, and support
582  * private IOCTLs for debugging and ndd.
583  */
584 void
585 igb_m_ioctl(void *arg, queue_t *q, mblk_t *mp)
586 {
587 	igb_t *igb = (igb_t *)arg;
588 	struct iocblk *iocp;
589 	enum ioc_reply status;
590 
591 	iocp = (struct iocblk *)(uintptr_t)mp->b_rptr;
592 	iocp->ioc_error = 0;
593 
594 	switch (iocp->ioc_cmd) {
595 	case LB_GET_INFO_SIZE:
596 	case LB_GET_INFO:
597 	case LB_GET_MODE:
598 	case LB_SET_MODE:
599 		status = igb_loopback_ioctl(igb, iocp, mp);
600 		break;
601 
602 	case ND_GET:
603 	case ND_SET:
604 		status = igb_nd_ioctl(igb, q, mp, iocp);
605 		break;
606 
607 	default:
608 		status = IOC_INVAL;
609 		break;
610 	}
611 
612 	/*
613 	 * Decide how to reply
614 	 */
615 	switch (status) {
616 	default:
617 	case IOC_INVAL:
618 		/*
619 		 * Error, reply with a NAK and EINVAL or the specified error
620 		 */
621 		miocnak(q, mp, 0, iocp->ioc_error == 0 ?
622 		    EINVAL : iocp->ioc_error);
623 		break;
624 
625 	case IOC_DONE:
626 		/*
627 		 * OK, reply already sent
628 		 */
629 		break;
630 
631 	case IOC_ACK:
632 		/*
633 		 * OK, reply with an ACK
634 		 */
635 		miocack(q, mp, 0, 0);
636 		break;
637 
638 	case IOC_REPLY:
639 		/*
640 		 * OK, send prepared reply as ACK or NAK
641 		 */
642 		mp->b_datap->db_type = iocp->ioc_error == 0 ?
643 		    M_IOCACK : M_IOCNAK;
644 		qreply(q, mp);
645 		break;
646 	}
647 }
648 
649 
650 /*
651  * Find an unused address slot, set the address to it, reserve
652  * this slot and enable the device to start filtering on the
653  * new address.
654  */
655 int
656 igb_m_unicst_add(void *arg, mac_multi_addr_t *maddr)
657 {
658 	igb_t *igb = (igb_t *)arg;
659 	mac_addr_slot_t slot;
660 	int err;
661 
662 	mutex_enter(&igb->gen_lock);
663 
664 	if (igb->igb_state & IGB_SUSPENDED) {
665 		mutex_exit(&igb->gen_lock);
666 		return (ECANCELED);
667 	}
668 
669 	if (mac_unicst_verify(igb->mac_hdl,
670 	    maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) {
671 		mutex_exit(&igb->gen_lock);
672 		return (EINVAL);
673 	}
674 
675 	if (igb->unicst_avail == 0) {
676 		/* no slots available */
677 		mutex_exit(&igb->gen_lock);
678 		return (ENOSPC);
679 	}
680 
681 	/*
682 	 * Primary/default address is in slot 0. The next addresses
683 	 * are the multiple MAC addresses. So multiple MAC address 0
684 	 * is in slot 1, 1 in slot 2, and so on. So the first multiple
685 	 * MAC address resides in slot 1.
686 	 */
687 	for (slot = 1; slot < igb->unicst_total; slot++) {
688 		if (igb->unicst_addr[slot].mac.set == 0) {
689 			igb->unicst_addr[slot].mac.set = 1;
690 			break;
691 		}
692 	}
693 
694 	ASSERT((slot > 0) && (slot < igb->unicst_total));
695 
696 	igb->unicst_avail--;
697 	mutex_exit(&igb->gen_lock);
698 
699 	maddr->mma_slot = slot;
700 
701 	if ((err = igb_unicst_set(igb, maddr->mma_addr, slot)) != 0) {
702 		mutex_enter(&igb->gen_lock);
703 		igb->unicst_addr[slot].mac.set = 0;
704 		igb->unicst_avail++;
705 		mutex_exit(&igb->gen_lock);
706 	}
707 
708 	return (err);
709 }
710 
711 
712 /*
713  * Removes a MAC address that was added before.
714  */
715 int
716 igb_m_unicst_remove(void *arg, mac_addr_slot_t slot)
717 {
718 	igb_t *igb = (igb_t *)arg;
719 	int err;
720 
721 	mutex_enter(&igb->gen_lock);
722 
723 	if (igb->igb_state & IGB_SUSPENDED) {
724 		mutex_exit(&igb->gen_lock);
725 		return (ECANCELED);
726 	}
727 
728 	if ((slot <= 0) || (slot >= igb->unicst_total)) {
729 		mutex_exit(&igb->gen_lock);
730 		return (EINVAL);
731 	}
732 
733 	if (igb->unicst_addr[slot].mac.set == 1) {
734 		igb->unicst_addr[slot].mac.set = 0;
735 		igb->unicst_avail++;
736 
737 		/* Copy the default address to the passed slot */
738 		if ((err = igb_unicst_set(igb,
739 		    igb->unicst_addr[0].mac.addr, slot)) != 0) {
740 			igb->unicst_addr[slot].mac.set = 1;
741 			igb->unicst_avail--;
742 		}
743 
744 		mutex_exit(&igb->gen_lock);
745 
746 		return (err);
747 	}
748 	mutex_exit(&igb->gen_lock);
749 
750 	return (EINVAL);
751 }
752 
753 /*
754  * Modifies the value of an address that has been added before.
755  * The new address length and the slot number that was returned
756  * in the call to add should be passed in. mma_flags should be
757  * set to 0.
758  * Returns 0 on success.
759  */
760 int
761 igb_m_unicst_modify(void *arg, mac_multi_addr_t *maddr)
762 {
763 	igb_t *igb = (igb_t *)arg;
764 	mac_addr_slot_t slot;
765 
766 	mutex_enter(&igb->gen_lock);
767 
768 	if (igb->igb_state & IGB_SUSPENDED) {
769 		mutex_exit(&igb->gen_lock);
770 		return (ECANCELED);
771 	}
772 
773 	if (mac_unicst_verify(igb->mac_hdl,
774 	    maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) {
775 		mutex_exit(&igb->gen_lock);
776 		return (EINVAL);
777 	}
778 
779 	slot = maddr->mma_slot;
780 
781 	if ((slot <= 0) || (slot >= igb->unicst_total)) {
782 		mutex_exit(&igb->gen_lock);
783 		return (EINVAL);
784 	}
785 
786 	if (igb->unicst_addr[slot].mac.set == 1) {
787 		mutex_exit(&igb->gen_lock);
788 
789 		return (igb_unicst_set(igb, maddr->mma_addr, slot));
790 	}
791 	mutex_exit(&igb->gen_lock);
792 
793 	return (EINVAL);
794 }
795 
796 /*
797  * Get the MAC address and all other information related to
798  * the address slot passed in mac_multi_addr_t.
799  * mma_flags should be set to 0 in the call.
800  * On return, mma_flags can take the following values:
801  * 1) MMAC_SLOT_UNUSED
802  * 2) MMAC_SLOT_USED | MMAC_VENDOR_ADDR
803  * 3) MMAC_SLOT_UNUSED | MMAC_VENDOR_ADDR
804  * 4) MMAC_SLOT_USED
805  */
806 int
807 igb_m_unicst_get(void *arg, mac_multi_addr_t *maddr)
808 {
809 	igb_t *igb = (igb_t *)arg;
810 	mac_addr_slot_t slot;
811 
812 	mutex_enter(&igb->gen_lock);
813 
814 	if (igb->igb_state & IGB_SUSPENDED) {
815 		mutex_exit(&igb->gen_lock);
816 		return (ECANCELED);
817 	}
818 
819 	slot = maddr->mma_slot;
820 
821 	if ((slot <= 0) || (slot >= igb->unicst_total)) {
822 		mutex_exit(&igb->gen_lock);
823 		return (EINVAL);
824 	}
825 
826 	if (igb->unicst_addr[slot].mac.set == 1) {
827 		bcopy(igb->unicst_addr[slot].mac.addr,
828 		    maddr->mma_addr, ETHERADDRL);
829 		maddr->mma_flags = MMAC_SLOT_USED;
830 	} else {
831 		maddr->mma_flags = MMAC_SLOT_UNUSED;
832 	}
833 	mutex_exit(&igb->gen_lock);
834 
835 	return (0);
836 }
837 
838 /*
839  * Obtain the MAC's capabilities and associated data from
840  * the driver.
841  */
842 boolean_t
843 igb_m_getcapab(void *arg, mac_capab_t cap, void *cap_data)
844 {
845 	igb_t *igb = (igb_t *)arg;
846 
847 	switch (cap) {
848 	case MAC_CAPAB_HCKSUM: {
849 		uint32_t *tx_hcksum_flags = cap_data;
850 
851 		/*
852 		 * We advertise our capabilities only if tx hcksum offload is
853 		 * enabled.  On receive, the stack will accept checksummed
854 		 * packets anyway, even if we haven't said we can deliver
855 		 * them.
856 		 */
857 		if (!igb->tx_hcksum_enable)
858 			return (B_FALSE);
859 
860 		*tx_hcksum_flags = HCKSUM_INET_PARTIAL | HCKSUM_IPHDRCKSUM;
861 		break;
862 	}
863 	case MAC_CAPAB_MULTIADDRESS: {
864 		multiaddress_capab_t *mmacp = cap_data;
865 
866 		/*
867 		 * The number of MAC addresses made available by
868 		 * this capability is one less than the total as
869 		 * the primary address in slot 0 is counted in
870 		 * the total.
871 		 */
872 		mmacp->maddr_naddr = igb->unicst_total - 1;
873 		mmacp->maddr_naddrfree = igb->unicst_avail;
874 		/* No multiple factory addresses, set mma_flag to 0 */
875 		mmacp->maddr_flag = 0;
876 		mmacp->maddr_handle = igb;
877 		mmacp->maddr_add = igb_m_unicst_add;
878 		mmacp->maddr_remove = igb_m_unicst_remove;
879 		mmacp->maddr_modify = igb_m_unicst_modify;
880 		mmacp->maddr_get = igb_m_unicst_get;
881 		mmacp->maddr_reserve = NULL;
882 		break;
883 	}
884 	default:
885 		return (B_FALSE);
886 	}
887 	return (B_TRUE);
888 }
889