19c80d176SSepherosa Ziehau /******************************************************************************
29c80d176SSepherosa Ziehau
34765c386SMichael Neumann Copyright (c) 2001-2014, Intel Corporation
49c80d176SSepherosa Ziehau All rights reserved.
59c80d176SSepherosa Ziehau
69c80d176SSepherosa Ziehau Redistribution and use in source and binary forms, with or without
79c80d176SSepherosa Ziehau modification, are permitted provided that the following conditions are met:
89c80d176SSepherosa Ziehau
99c80d176SSepherosa Ziehau 1. Redistributions of source code must retain the above copyright notice,
109c80d176SSepherosa Ziehau this list of conditions and the following disclaimer.
119c80d176SSepherosa Ziehau
129c80d176SSepherosa Ziehau 2. Redistributions in binary form must reproduce the above copyright
139c80d176SSepherosa Ziehau notice, this list of conditions and the following disclaimer in the
149c80d176SSepherosa Ziehau documentation and/or other materials provided with the distribution.
159c80d176SSepherosa Ziehau
169c80d176SSepherosa Ziehau 3. Neither the name of the Intel Corporation nor the names of its
179c80d176SSepherosa Ziehau contributors may be used to endorse or promote products derived from
189c80d176SSepherosa Ziehau this software without specific prior written permission.
199c80d176SSepherosa Ziehau
209c80d176SSepherosa Ziehau THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
219c80d176SSepherosa Ziehau AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229c80d176SSepherosa Ziehau IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
239c80d176SSepherosa Ziehau ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
249c80d176SSepherosa Ziehau LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259c80d176SSepherosa Ziehau CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269c80d176SSepherosa Ziehau SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279c80d176SSepherosa Ziehau INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289c80d176SSepherosa Ziehau CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299c80d176SSepherosa Ziehau ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309c80d176SSepherosa Ziehau POSSIBILITY OF SUCH DAMAGE.
319c80d176SSepherosa Ziehau
329c80d176SSepherosa Ziehau ******************************************************************************/
339c80d176SSepherosa Ziehau
34efd6aee8SSepherosa Ziehau #include <sys/param.h>
35188478eeSSepherosa Ziehau #include <sys/kernel.h>
36efd6aee8SSepherosa Ziehau #include <sys/sysctl.h>
37*bff82488SAaron LI #include <net/if.h>
38d2f385fbSSepherosa Ziehau #include <net/if_media.h>
39efd6aee8SSepherosa Ziehau
409c80d176SSepherosa Ziehau #include "e1000_api.h"
41efd6aee8SSepherosa Ziehau #include "e1000_dragonfly.h"
429c80d176SSepherosa Ziehau
43188478eeSSepherosa Ziehau SYSCTL_NODE(_hw, OID_AUTO, ig_hal, CTLFLAG_RW, 0, "Intel 1Ge HAL");
44188478eeSSepherosa Ziehau
45188478eeSSepherosa Ziehau int e1000_debug;
46188478eeSSepherosa Ziehau
47188478eeSSepherosa Ziehau TUNABLE_INT("hw.ig_hal.debug", &e1000_debug);
48188478eeSSepherosa Ziehau SYSCTL_INT(_hw_ig_hal, OID_AUTO, debug, CTLFLAG_RW, &e1000_debug, 0,
49188478eeSSepherosa Ziehau "Enable Intel 1Ge HAL debug");
50188478eeSSepherosa Ziehau
519c80d176SSepherosa Ziehau /*
529c80d176SSepherosa Ziehau * NOTE: the following routines using the e1000
539c80d176SSepherosa Ziehau * naming style are provided to the shared
549c80d176SSepherosa Ziehau * code but are OS specific
559c80d176SSepherosa Ziehau */
569c80d176SSepherosa Ziehau
579c80d176SSepherosa Ziehau void
e1000_write_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)589c80d176SSepherosa Ziehau e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
599c80d176SSepherosa Ziehau {
609c80d176SSepherosa Ziehau pci_write_config(((struct e1000_osdep *)hw->back)->dev, reg, *value, 2);
619c80d176SSepherosa Ziehau }
629c80d176SSepherosa Ziehau
639c80d176SSepherosa Ziehau void
e1000_read_pci_cfg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)649c80d176SSepherosa Ziehau e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
659c80d176SSepherosa Ziehau {
669c80d176SSepherosa Ziehau *value = pci_read_config(((struct e1000_osdep *)hw->back)->dev, reg, 2);
679c80d176SSepherosa Ziehau }
689c80d176SSepherosa Ziehau
699c80d176SSepherosa Ziehau void
e1000_pci_set_mwi(struct e1000_hw * hw)709c80d176SSepherosa Ziehau e1000_pci_set_mwi(struct e1000_hw *hw)
719c80d176SSepherosa Ziehau {
729c80d176SSepherosa Ziehau pci_write_config(((struct e1000_osdep *)hw->back)->dev, PCIR_COMMAND,
739c80d176SSepherosa Ziehau (hw->bus.pci_cmd_word | CMD_MEM_WRT_INVALIDATE), 2);
749c80d176SSepherosa Ziehau }
759c80d176SSepherosa Ziehau
769c80d176SSepherosa Ziehau void
e1000_pci_clear_mwi(struct e1000_hw * hw)779c80d176SSepherosa Ziehau e1000_pci_clear_mwi(struct e1000_hw *hw)
789c80d176SSepherosa Ziehau {
799c80d176SSepherosa Ziehau pci_write_config(((struct e1000_osdep *)hw->back)->dev, PCIR_COMMAND,
809c80d176SSepherosa Ziehau (hw->bus.pci_cmd_word & ~CMD_MEM_WRT_INVALIDATE), 2);
819c80d176SSepherosa Ziehau }
829c80d176SSepherosa Ziehau
839c80d176SSepherosa Ziehau /*
849c80d176SSepherosa Ziehau * Read the PCI Express capabilities
859c80d176SSepherosa Ziehau */
869c80d176SSepherosa Ziehau int32_t
e1000_read_pcie_cap_reg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)879c80d176SSepherosa Ziehau e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
889c80d176SSepherosa Ziehau {
899c80d176SSepherosa Ziehau device_t dev = ((struct e1000_osdep *)hw->back)->dev;
909c80d176SSepherosa Ziehau uint8_t pcie_ptr;
919c80d176SSepherosa Ziehau
929c80d176SSepherosa Ziehau pcie_ptr = pci_get_pciecap_ptr(dev);
939c80d176SSepherosa Ziehau if (pcie_ptr == 0)
949c80d176SSepherosa Ziehau return E1000_NOT_IMPLEMENTED;
959c80d176SSepherosa Ziehau
969c80d176SSepherosa Ziehau *value = pci_read_config(dev, pcie_ptr + reg, 2);
979c80d176SSepherosa Ziehau return E1000_SUCCESS;
989c80d176SSepherosa Ziehau }
999c80d176SSepherosa Ziehau
10062583d18SSepherosa Ziehau int32_t
e1000_write_pcie_cap_reg(struct e1000_hw * hw,uint32_t reg,uint16_t * value)10162583d18SSepherosa Ziehau e1000_write_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
10262583d18SSepherosa Ziehau {
10362583d18SSepherosa Ziehau device_t dev = ((struct e1000_osdep *)hw->back)->dev;
10462583d18SSepherosa Ziehau uint8_t pcie_ptr;
10562583d18SSepherosa Ziehau
10662583d18SSepherosa Ziehau pcie_ptr = pci_get_pciecap_ptr(dev);
10762583d18SSepherosa Ziehau if (pcie_ptr == 0)
10862583d18SSepherosa Ziehau return E1000_NOT_IMPLEMENTED;
10962583d18SSepherosa Ziehau
11062583d18SSepherosa Ziehau pci_write_config(dev, pcie_ptr + reg, *value, 2);
11162583d18SSepherosa Ziehau return E1000_SUCCESS;
11262583d18SSepherosa Ziehau }
11362583d18SSepherosa Ziehau
114efd6aee8SSepherosa Ziehau void
e1000_fc2str(enum e1000_fc_mode fc,char * str,int len)115efd6aee8SSepherosa Ziehau e1000_fc2str(enum e1000_fc_mode fc, char *str, int len)
116efd6aee8SSepherosa Ziehau {
11781ac62f7SSepherosa Ziehau const char *fc_str = IFM_ETH_FC_NONE;
118efd6aee8SSepherosa Ziehau
119efd6aee8SSepherosa Ziehau switch (fc) {
12081ac62f7SSepherosa Ziehau case e1000_fc_full:
12181ac62f7SSepherosa Ziehau fc_str = IFM_ETH_FC_FULL;
122efd6aee8SSepherosa Ziehau break;
123efd6aee8SSepherosa Ziehau
124efd6aee8SSepherosa Ziehau case e1000_fc_rx_pause:
12581ac62f7SSepherosa Ziehau fc_str = IFM_ETH_FC_RXPAUSE;
126efd6aee8SSepherosa Ziehau break;
127efd6aee8SSepherosa Ziehau
128efd6aee8SSepherosa Ziehau case e1000_fc_tx_pause:
12981ac62f7SSepherosa Ziehau fc_str = IFM_ETH_FC_TXPAUSE;
130efd6aee8SSepherosa Ziehau break;
131efd6aee8SSepherosa Ziehau
132efd6aee8SSepherosa Ziehau default:
133efd6aee8SSepherosa Ziehau break;
134efd6aee8SSepherosa Ziehau }
135efd6aee8SSepherosa Ziehau strlcpy(str, fc_str, len);
136efd6aee8SSepherosa Ziehau }
137efd6aee8SSepherosa Ziehau
138d2f385fbSSepherosa Ziehau enum e1000_fc_mode
e1000_ifmedia2fc(int ifm)139d2f385fbSSepherosa Ziehau e1000_ifmedia2fc(int ifm)
140d2f385fbSSepherosa Ziehau {
141d2f385fbSSepherosa Ziehau int fc_opt = ifm & (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
142d2f385fbSSepherosa Ziehau
143d2f385fbSSepherosa Ziehau switch (fc_opt) {
144d2f385fbSSepherosa Ziehau case (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE):
145d2f385fbSSepherosa Ziehau return e1000_fc_full;
146d2f385fbSSepherosa Ziehau
147d2f385fbSSepherosa Ziehau case IFM_ETH_RXPAUSE:
148d2f385fbSSepherosa Ziehau return e1000_fc_rx_pause;
149d2f385fbSSepherosa Ziehau
150d2f385fbSSepherosa Ziehau case IFM_ETH_TXPAUSE:
151d2f385fbSSepherosa Ziehau return e1000_fc_tx_pause;
152d2f385fbSSepherosa Ziehau
153d2f385fbSSepherosa Ziehau default:
154d2f385fbSSepherosa Ziehau return e1000_fc_none;
155d2f385fbSSepherosa Ziehau }
156d2f385fbSSepherosa Ziehau }
157d2f385fbSSepherosa Ziehau
158d2f385fbSSepherosa Ziehau int
e1000_fc2ifmedia(enum e1000_fc_mode fc)159d2f385fbSSepherosa Ziehau e1000_fc2ifmedia(enum e1000_fc_mode fc)
160d2f385fbSSepherosa Ziehau {
161d2f385fbSSepherosa Ziehau switch (fc) {
162d2f385fbSSepherosa Ziehau case e1000_fc_full:
163d2f385fbSSepherosa Ziehau return (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE);
164d2f385fbSSepherosa Ziehau
165d2f385fbSSepherosa Ziehau case e1000_fc_rx_pause:
166d2f385fbSSepherosa Ziehau return IFM_ETH_RXPAUSE;
167d2f385fbSSepherosa Ziehau
168d2f385fbSSepherosa Ziehau case e1000_fc_tx_pause:
169d2f385fbSSepherosa Ziehau return IFM_ETH_TXPAUSE;
170d2f385fbSSepherosa Ziehau
171d2f385fbSSepherosa Ziehau default:
172d2f385fbSSepherosa Ziehau return 0;
173d2f385fbSSepherosa Ziehau }
174d2f385fbSSepherosa Ziehau }
175d2f385fbSSepherosa Ziehau
1769b8968bbSSepherosa Ziehau void
e1000_force_flowctrl(struct e1000_hw * hw,int ifm)1779b8968bbSSepherosa Ziehau e1000_force_flowctrl(struct e1000_hw *hw, int ifm)
1789b8968bbSSepherosa Ziehau {
1799b8968bbSSepherosa Ziehau enum e1000_fc_mode fc;
1809b8968bbSSepherosa Ziehau
1819b8968bbSSepherosa Ziehau fc = e1000_ifmedia2fc(ifm);
1829b8968bbSSepherosa Ziehau if (hw->fc.current_mode != fc) {
1839b8968bbSSepherosa Ziehau hw->fc.requested_mode = fc;
1849b8968bbSSepherosa Ziehau hw->fc.current_mode = fc;
1859b8968bbSSepherosa Ziehau e1000_force_mac_fc(hw);
1869b8968bbSSepherosa Ziehau }
1879b8968bbSSepherosa Ziehau }
1889b8968bbSSepherosa Ziehau
1899c80d176SSepherosa Ziehau /* Module glue */
1909c80d176SSepherosa Ziehau static moduledata_t ig_hal_mod = { "ig_hal" };
1919c80d176SSepherosa Ziehau DECLARE_MODULE(ig_hal, ig_hal_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1929dfe7223SSimon Schubert MODULE_VERSION(ig_hal, 1);
193