3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright(c) 2007-2010 Intel Corporation. All rights reserved.
24 */
25
26 /*
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 */
29
30 #include "igb_sw.h"
31
32 static char ident[] = "Intel 1Gb Ethernet";
33 static char igb_version[] = "igb 1.1.17";
34
35 /*
36 * Local function protoypes
37 */
38 static int igb_register_mac(igb_t *);
39 static int igb_identify_hardware(igb_t *);
40 static int igb_regs_map(igb_t *);
41 static void igb_init_properties(igb_t *);
42 static int igb_init_driver_settings(igb_t *);
43 static void igb_init_locks(igb_t *);
44 static void igb_destroy_locks(igb_t *);
45 static int igb_init_mac_address(igb_t *);
46 static int igb_init(igb_t *);
47 static int igb_init_adapter(igb_t *);
48 static void igb_stop_adapter(igb_t *);
49 static int igb_reset(igb_t *);
50 static void igb_tx_clean(igb_t *);
51 static boolean_t igb_tx_drain(igb_t *);
52 static boolean_t igb_rx_drain(igb_t *);
53 static int igb_alloc_rings(igb_t *);
268 4, /* default number of rx queues */
269 8, /* maximum number of tx queues */
270 1, /* minimum number of tx queues */
271 4, /* default number of tx queues */
272 65535, /* maximum interrupt throttle rate */
273 0, /* minimum interrupt throttle rate */
274 200, /* default interrupt throttle rate */
275
276 /* function pointers */
277 igb_enable_adapter_interrupts_82580,
278 igb_setup_msix_82580,
279
280 /* capabilities */
281 (IGB_FLAG_HAS_DCA | /* capability flags */
282 IGB_FLAG_VMDQ_POOL |
283 IGB_FLAG_NEED_CTX_IDX),
284
285 0xffe00000 /* mask for RXDCTL register */
286 };
287
288 /*
289 * Module Initialization Functions
290 */
291
292 int
293 _init(void)
294 {
295 int status;
296
297 mac_init_ops(&igb_dev_ops, MODULE_NAME);
298
299 status = mod_install(&igb_modlinkage);
300
301 if (status != DDI_SUCCESS) {
302 mac_fini_ops(&igb_dev_ops);
303 }
304
305 return (status);
306 }
307
500 */
501 if (igb_register_mac(igb) != IGB_SUCCESS) {
502 igb_error(igb, "Failed to register MAC");
503 goto attach_fail;
504 }
505 igb->attach_progress |= ATTACH_PROGRESS_MAC;
506
507 /*
508 * Now that mutex locks are initialized, and the chip is also
509 * initialized, enable interrupts.
510 */
511 if (igb_enable_intrs(igb) != IGB_SUCCESS) {
512 igb_error(igb, "Failed to enable DDI interrupts");
513 goto attach_fail;
514 }
515 igb->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR;
516
517 igb_log(igb, "%s", igb_version);
518 atomic_or_32(&igb->igb_state, IGB_INITIALIZED);
519
520 return (DDI_SUCCESS);
521
522 attach_fail:
523 igb_unconfigure(devinfo, igb);
524 return (DDI_FAILURE);
525 }
526
527 /*
528 * igb_detach - driver detach
529 *
530 * The detach() function is the complement of the attach routine.
531 * If cmd is set to DDI_DETACH, detach() is used to remove the
532 * state associated with a given instance of a device node
533 * prior to the removal of that instance from the system.
534 *
535 * The detach() function will be called once for each instance
536 * of the device for which there has been a successful attach()
537 * once there are no longer any opens on the device.
538 *
539 * Interrupts routine are disabled, All memory allocated by this
819 /*
820 * Set the mac type of the adapter based on the device id
821 */
822 if (e1000_set_mac_type(hw) != E1000_SUCCESS) {
823 return (IGB_FAILURE);
824 }
825
826 /*
827 * Install adapter capabilities based on mac type
828 */
829 switch (hw->mac.type) {
830 case e1000_82575:
831 igb->capab = &igb_82575_cap;
832 break;
833 case e1000_82576:
834 igb->capab = &igb_82576_cap;
835 break;
836 case e1000_82580:
837 igb->capab = &igb_82580_cap;
838 break;
839 default:
840 return (IGB_FAILURE);
841 }
842
843 return (IGB_SUCCESS);
844 }
845
846 /*
847 * igb_regs_map - Map the device registers
848 */
849 static int
850 igb_regs_map(igb_t *igb)
851 {
852 dev_info_t *devinfo = igb->dip;
853 struct e1000_hw *hw = &igb->hw;
854 struct igb_osdep *osdep = &igb->osdep;
855 off_t mem_size;
856
857 /*
858 * First get the size of device registers to be mapped.
1682 igb->attach_progress |= ATTACH_PROGRESS_INIT_ADAPTER;
1683 }
1684
1685 /*
1686 * Setup the rx/tx rings
1687 */
1688 igb_setup_rings(igb);
1689
1690 /*
1691 * Enable adapter interrupts
1692 * The interrupts must be enabled after the driver state is START
1693 */
1694 igb->capab->enable_intr(igb);
1695
1696 if (igb_check_acc_handle(igb->osdep.cfg_handle) != DDI_FM_OK)
1697 goto start_failure;
1698
1699 if (igb_check_acc_handle(igb->osdep.reg_handle) != DDI_FM_OK)
1700 goto start_failure;
1701
1702 for (i = igb->num_tx_rings - 1; i >= 0; i--)
1703 mutex_exit(&igb->tx_rings[i].tx_lock);
1704 for (i = igb->num_rx_rings - 1; i >= 0; i--)
1705 mutex_exit(&igb->rx_rings[i].rx_lock);
1706
1707 return (IGB_SUCCESS);
1708
1709 start_failure:
1710 for (i = igb->num_tx_rings - 1; i >= 0; i--)
1711 mutex_exit(&igb->tx_rings[i].tx_lock);
1712 for (i = igb->num_rx_rings - 1; i >= 0; i--)
1713 mutex_exit(&igb->rx_rings[i].rx_lock);
1714
1715 ddi_fm_service_impact(igb->dip, DDI_SERVICE_LOST);
1716
1717 return (IGB_FAILURE);
1718 }
1719
1720 /*
1721 * igb_stop - Stop the driver/chipset
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2007-2012 Intel Corporation. All rights reserved.
24 */
25
26 /*
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 */
29
30 #include "igb_sw.h"
31
32 static char ident[] = "Intel 1Gb Ethernet";
33 static char igb_version[] = "igb 1.1.18";
34
35 /*
36 * Local function protoypes
37 */
38 static int igb_register_mac(igb_t *);
39 static int igb_identify_hardware(igb_t *);
40 static int igb_regs_map(igb_t *);
41 static void igb_init_properties(igb_t *);
42 static int igb_init_driver_settings(igb_t *);
43 static void igb_init_locks(igb_t *);
44 static void igb_destroy_locks(igb_t *);
45 static int igb_init_mac_address(igb_t *);
46 static int igb_init(igb_t *);
47 static int igb_init_adapter(igb_t *);
48 static void igb_stop_adapter(igb_t *);
49 static int igb_reset(igb_t *);
50 static void igb_tx_clean(igb_t *);
51 static boolean_t igb_tx_drain(igb_t *);
52 static boolean_t igb_rx_drain(igb_t *);
53 static int igb_alloc_rings(igb_t *);
268 4, /* default number of rx queues */
269 8, /* maximum number of tx queues */
270 1, /* minimum number of tx queues */
271 4, /* default number of tx queues */
272 65535, /* maximum interrupt throttle rate */
273 0, /* minimum interrupt throttle rate */
274 200, /* default interrupt throttle rate */
275
276 /* function pointers */
277 igb_enable_adapter_interrupts_82580,
278 igb_setup_msix_82580,
279
280 /* capabilities */
281 (IGB_FLAG_HAS_DCA | /* capability flags */
282 IGB_FLAG_VMDQ_POOL |
283 IGB_FLAG_NEED_CTX_IDX),
284
285 0xffe00000 /* mask for RXDCTL register */
286 };
287
288 static adapter_info_t igb_i350_cap = {
289 /* limits */
290 8, /* maximum number of rx queues */
291 1, /* minimum number of rx queues */
292 4, /* default number of rx queues */
293 8, /* maximum number of tx queues */
294 1, /* minimum number of tx queues */
295 4, /* default number of tx queues */
296 65535, /* maximum interrupt throttle rate */
297 0, /* minimum interrupt throttle rate */
298 200, /* default interrupt throttle rate */
299
300 /* function pointers */
301 igb_enable_adapter_interrupts_82580,
302 igb_setup_msix_82580,
303
304 /* capabilities */
305 (IGB_FLAG_HAS_DCA | /* capability flags */
306 IGB_FLAG_VMDQ_POOL |
307 IGB_FLAG_NEED_CTX_IDX),
308
309 0xffe00000 /* mask for RXDCTL register */
310 };
311
312 /*
313 * Module Initialization Functions
314 */
315
316 int
317 _init(void)
318 {
319 int status;
320
321 mac_init_ops(&igb_dev_ops, MODULE_NAME);
322
323 status = mod_install(&igb_modlinkage);
324
325 if (status != DDI_SUCCESS) {
326 mac_fini_ops(&igb_dev_ops);
327 }
328
329 return (status);
330 }
331
524 */
525 if (igb_register_mac(igb) != IGB_SUCCESS) {
526 igb_error(igb, "Failed to register MAC");
527 goto attach_fail;
528 }
529 igb->attach_progress |= ATTACH_PROGRESS_MAC;
530
531 /*
532 * Now that mutex locks are initialized, and the chip is also
533 * initialized, enable interrupts.
534 */
535 if (igb_enable_intrs(igb) != IGB_SUCCESS) {
536 igb_error(igb, "Failed to enable DDI interrupts");
537 goto attach_fail;
538 }
539 igb->attach_progress |= ATTACH_PROGRESS_ENABLE_INTR;
540
541 igb_log(igb, "%s", igb_version);
542 atomic_or_32(&igb->igb_state, IGB_INITIALIZED);
543
544 /*
545 * Newer models have Energy Efficient Ethernet, let's disable this by
546 * default.
547 */
548 if (igb->hw.mac.type == e1000_i350)
549 (void) e1000_set_eee_i350(&igb->hw);
550
551 return (DDI_SUCCESS);
552
553 attach_fail:
554 igb_unconfigure(devinfo, igb);
555 return (DDI_FAILURE);
556 }
557
558 /*
559 * igb_detach - driver detach
560 *
561 * The detach() function is the complement of the attach routine.
562 * If cmd is set to DDI_DETACH, detach() is used to remove the
563 * state associated with a given instance of a device node
564 * prior to the removal of that instance from the system.
565 *
566 * The detach() function will be called once for each instance
567 * of the device for which there has been a successful attach()
568 * once there are no longer any opens on the device.
569 *
570 * Interrupts routine are disabled, All memory allocated by this
850 /*
851 * Set the mac type of the adapter based on the device id
852 */
853 if (e1000_set_mac_type(hw) != E1000_SUCCESS) {
854 return (IGB_FAILURE);
855 }
856
857 /*
858 * Install adapter capabilities based on mac type
859 */
860 switch (hw->mac.type) {
861 case e1000_82575:
862 igb->capab = &igb_82575_cap;
863 break;
864 case e1000_82576:
865 igb->capab = &igb_82576_cap;
866 break;
867 case e1000_82580:
868 igb->capab = &igb_82580_cap;
869 break;
870 case e1000_i350:
871 igb->capab = &igb_i350_cap;
872 break;
873 default:
874 return (IGB_FAILURE);
875 }
876
877 return (IGB_SUCCESS);
878 }
879
880 /*
881 * igb_regs_map - Map the device registers
882 */
883 static int
884 igb_regs_map(igb_t *igb)
885 {
886 dev_info_t *devinfo = igb->dip;
887 struct e1000_hw *hw = &igb->hw;
888 struct igb_osdep *osdep = &igb->osdep;
889 off_t mem_size;
890
891 /*
892 * First get the size of device registers to be mapped.
1716 igb->attach_progress |= ATTACH_PROGRESS_INIT_ADAPTER;
1717 }
1718
1719 /*
1720 * Setup the rx/tx rings
1721 */
1722 igb_setup_rings(igb);
1723
1724 /*
1725 * Enable adapter interrupts
1726 * The interrupts must be enabled after the driver state is START
1727 */
1728 igb->capab->enable_intr(igb);
1729
1730 if (igb_check_acc_handle(igb->osdep.cfg_handle) != DDI_FM_OK)
1731 goto start_failure;
1732
1733 if (igb_check_acc_handle(igb->osdep.reg_handle) != DDI_FM_OK)
1734 goto start_failure;
1735
1736 if (igb->hw.mac.type == e1000_i350)
1737 (void) e1000_set_eee_i350(&igb->hw);
1738
1739 for (i = igb->num_tx_rings - 1; i >= 0; i--)
1740 mutex_exit(&igb->tx_rings[i].tx_lock);
1741 for (i = igb->num_rx_rings - 1; i >= 0; i--)
1742 mutex_exit(&igb->rx_rings[i].rx_lock);
1743
1744 return (IGB_SUCCESS);
1745
1746 start_failure:
1747 for (i = igb->num_tx_rings - 1; i >= 0; i--)
1748 mutex_exit(&igb->tx_rings[i].tx_lock);
1749 for (i = igb->num_rx_rings - 1; i >= 0; i--)
1750 mutex_exit(&igb->rx_rings[i].rx_lock);
1751
1752 ddi_fm_service_impact(igb->dip, DDI_SERVICE_LOST);
1753
1754 return (IGB_FAILURE);
1755 }
1756
1757 /*
1758 * igb_stop - Stop the driver/chipset
|