aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasha Neftin <sasha.neftin@intel.com>2018-10-11 03:17:26 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2018-10-17 16:49:33 -0400
commitc0071c7aa5fe0a6aa4cfc8426af893307ccd276d (patch)
tree4d06a191d99c460db8158f5b328826504c666354
parent0507ef8a0372b80c30555bbeec7215f2cf874ecd (diff)
igc: Add HW initialization code
Add code for hardware initialization and reset Add code for semaphore handling Signed-off-by: Sasha Neftin <sasha.neftin@intel.com> Tested-by: Aaron Brown <aaron.f.brown@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
-rw-r--r--drivers/net/ethernet/intel/igc/Makefile2
-rw-r--r--drivers/net/ethernet/intel/igc/igc_base.c187
-rw-r--r--drivers/net/ethernet/intel/igc/igc_base.h2
-rw-r--r--drivers/net/ethernet/intel/igc/igc_defines.h36
-rw-r--r--drivers/net/ethernet/intel/igc/igc_hw.h85
-rw-r--r--drivers/net/ethernet/intel/igc/igc_i225.c141
-rw-r--r--drivers/net/ethernet/intel/igc/igc_mac.c315
-rw-r--r--drivers/net/ethernet/intel/igc/igc_mac.h11
-rw-r--r--drivers/net/ethernet/intel/igc/igc_main.c21
-rw-r--r--drivers/net/ethernet/intel/igc/igc_regs.h20
10 files changed, 819 insertions, 1 deletions
diff --git a/drivers/net/ethernet/intel/igc/Makefile b/drivers/net/ethernet/intel/igc/Makefile
index c32c45300692..8b8022ea590a 100644
--- a/drivers/net/ethernet/intel/igc/Makefile
+++ b/drivers/net/ethernet/intel/igc/Makefile
@@ -7,4 +7,4 @@
7 7
8obj-$(CONFIG_IGC) += igc.o 8obj-$(CONFIG_IGC) += igc.o
9 9
10igc-objs := igc_main.o igc_mac.o igc_base.o 10igc-objs := igc_main.o igc_mac.o igc_i225.o igc_base.o
diff --git a/drivers/net/ethernet/intel/igc/igc_base.c b/drivers/net/ethernet/intel/igc/igc_base.c
index 3425b7466017..4efb47497e6b 100644
--- a/drivers/net/ethernet/intel/igc/igc_base.c
+++ b/drivers/net/ethernet/intel/igc/igc_base.c
@@ -5,6 +5,184 @@
5 5
6#include "igc_hw.h" 6#include "igc_hw.h"
7#include "igc_i225.h" 7#include "igc_i225.h"
8#include "igc_mac.h"
9#include "igc_base.h"
10#include "igc.h"
11
12/**
13 * igc_set_pcie_completion_timeout - set pci-e completion timeout
14 * @hw: pointer to the HW structure
15 */
16static s32 igc_set_pcie_completion_timeout(struct igc_hw *hw)
17{
18 u32 gcr = rd32(IGC_GCR);
19 u16 pcie_devctl2;
20 s32 ret_val = 0;
21
22 /* only take action if timeout value is defaulted to 0 */
23 if (gcr & IGC_GCR_CMPL_TMOUT_MASK)
24 goto out;
25
26 /* if capabilities version is type 1 we can write the
27 * timeout of 10ms to 200ms through the GCR register
28 */
29 if (!(gcr & IGC_GCR_CAP_VER2)) {
30 gcr |= IGC_GCR_CMPL_TMOUT_10ms;
31 goto out;
32 }
33
34 /* for version 2 capabilities we need to write the config space
35 * directly in order to set the completion timeout value for
36 * 16ms to 55ms
37 */
38 ret_val = igc_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
39 &pcie_devctl2);
40 if (ret_val)
41 goto out;
42
43 pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
44
45 ret_val = igc_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
46 &pcie_devctl2);
47out:
48 /* disable completion timeout resend */
49 gcr &= ~IGC_GCR_CMPL_TMOUT_RESEND;
50
51 wr32(IGC_GCR, gcr);
52
53 return ret_val;
54}
55
56/**
57 * igc_reset_hw_base - Reset hardware
58 * @hw: pointer to the HW structure
59 *
60 * This resets the hardware into a known state. This is a
61 * function pointer entry point called by the api module.
62 */
63static s32 igc_reset_hw_base(struct igc_hw *hw)
64{
65 s32 ret_val;
66 u32 ctrl;
67
68 /* Prevent the PCI-E bus from sticking if there is no TLP connection
69 * on the last TLP read/write transaction when MAC is reset.
70 */
71 ret_val = igc_disable_pcie_master(hw);
72 if (ret_val)
73 hw_dbg("PCI-E Master disable polling has failed.\n");
74
75 /* set the completion timeout for interface */
76 ret_val = igc_set_pcie_completion_timeout(hw);
77 if (ret_val)
78 hw_dbg("PCI-E Set completion timeout has failed.\n");
79
80 hw_dbg("Masking off all interrupts\n");
81 wr32(IGC_IMC, 0xffffffff);
82
83 wr32(IGC_RCTL, 0);
84 wr32(IGC_TCTL, IGC_TCTL_PSP);
85 wrfl();
86
87 usleep_range(10000, 20000);
88
89 ctrl = rd32(IGC_CTRL);
90
91 hw_dbg("Issuing a global reset to MAC\n");
92 wr32(IGC_CTRL, ctrl | IGC_CTRL_RST);
93
94 ret_val = igc_get_auto_rd_done(hw);
95 if (ret_val) {
96 /* When auto config read does not complete, do not
97 * return with an error. This can happen in situations
98 * where there is no eeprom and prevents getting link.
99 */
100 hw_dbg("Auto Read Done did not complete\n");
101 }
102
103 /* Clear any pending interrupt events. */
104 wr32(IGC_IMC, 0xffffffff);
105 rd32(IGC_ICR);
106
107 return ret_val;
108}
109
110/**
111 * igc_init_mac_params_base - Init MAC func ptrs.
112 * @hw: pointer to the HW structure
113 */
114static s32 igc_init_mac_params_base(struct igc_hw *hw)
115{
116 struct igc_mac_info *mac = &hw->mac;
117
118 /* Set mta register count */
119 mac->mta_reg_count = 128;
120 mac->rar_entry_count = IGC_RAR_ENTRIES;
121
122 /* reset */
123 mac->ops.reset_hw = igc_reset_hw_base;
124
125 mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
126 mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
127
128 return 0;
129}
130
131static s32 igc_get_invariants_base(struct igc_hw *hw)
132{
133 u32 link_mode = 0;
134 u32 ctrl_ext = 0;
135 s32 ret_val = 0;
136
137 ctrl_ext = rd32(IGC_CTRL_EXT);
138 link_mode = ctrl_ext & IGC_CTRL_EXT_LINK_MODE_MASK;
139
140 /* mac initialization and operations */
141 ret_val = igc_init_mac_params_base(hw);
142 if (ret_val)
143 goto out;
144
145out:
146 return ret_val;
147}
148
149/**
150 * igc_init_hw_base - Initialize hardware
151 * @hw: pointer to the HW structure
152 *
153 * This inits the hardware readying it for operation.
154 */
155static s32 igc_init_hw_base(struct igc_hw *hw)
156{
157 struct igc_mac_info *mac = &hw->mac;
158 u16 i, rar_count = mac->rar_entry_count;
159 s32 ret_val = 0;
160
161 /* Setup the receive address */
162 igc_init_rx_addrs(hw, rar_count);
163
164 /* Zero out the Multicast HASH table */
165 hw_dbg("Zeroing the MTA\n");
166 for (i = 0; i < mac->mta_reg_count; i++)
167 array_wr32(IGC_MTA, i, 0);
168
169 /* Zero out the Unicast HASH table */
170 hw_dbg("Zeroing the UTA\n");
171 for (i = 0; i < mac->uta_reg_count; i++)
172 array_wr32(IGC_UTA, i, 0);
173
174 /* Setup link and flow control */
175 ret_val = igc_setup_link(hw);
176
177 /* Clear all of the statistics registers (clear on read). It is
178 * important that we do this after we have tried to establish link
179 * because the symbol error count will increment wildly if there
180 * is no link.
181 */
182 igc_clear_hw_cntrs_base(hw);
183
184 return ret_val;
185}
8 186
9/** 187/**
10 * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable 188 * igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
@@ -81,3 +259,12 @@ void igc_rx_fifo_flush_base(struct igc_hw *hw)
81 rd32(IGC_RNBC); 259 rd32(IGC_RNBC);
82 rd32(IGC_MPC); 260 rd32(IGC_MPC);
83} 261}
262
263static struct igc_mac_operations igc_mac_ops_base = {
264 .init_hw = igc_init_hw_base,
265};
266
267const struct igc_info igc_base_info = {
268 .get_invariants = igc_get_invariants_base,
269 .mac_ops = &igc_mac_ops_base,
270};
diff --git a/drivers/net/ethernet/intel/igc/igc_base.h b/drivers/net/ethernet/intel/igc/igc_base.h
index 3078a18f70a9..802a0cbd3123 100644
--- a/drivers/net/ethernet/intel/igc/igc_base.h
+++ b/drivers/net/ethernet/intel/igc/igc_base.h
@@ -33,6 +33,8 @@ union igc_adv_tx_desc {
33#define IGC_ADVTXD_DCMD_TSE 0x80000000 /* TCP Seg enable */ 33#define IGC_ADVTXD_DCMD_TSE 0x80000000 /* TCP Seg enable */
34#define IGC_ADVTXD_PAYLEN_SHIFT 14 /* Adv desc PAYLEN shift */ 34#define IGC_ADVTXD_PAYLEN_SHIFT 14 /* Adv desc PAYLEN shift */
35 35
36#define IGC_RAR_ENTRIES 16
37
36struct igc_adv_data_desc { 38struct igc_adv_data_desc {
37 __le64 buffer_addr; /* Address of the descriptor's data buffer */ 39 __le64 buffer_addr; /* Address of the descriptor's data buffer */
38 union { 40 union {
diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h
index c8a321358cf6..3d6c2cee0ad3 100644
--- a/drivers/net/ethernet/intel/igc/igc_defines.h
+++ b/drivers/net/ethernet/intel/igc/igc_defines.h
@@ -10,6 +10,22 @@
10#define PCIE_DEVICE_CONTROL2 0x28 10#define PCIE_DEVICE_CONTROL2 0x28
11#define PCIE_DEVICE_CONTROL2_16ms 0x0005 11#define PCIE_DEVICE_CONTROL2_16ms 0x0005
12 12
13/* Physical Func Reset Done Indication */
14#define IGC_CTRL_EXT_LINK_MODE_MASK 0x00C00000
15
16/* Number of 100 microseconds we wait for PCI Express master disable */
17#define MASTER_DISABLE_TIMEOUT 800
18/*Blocks new Master requests */
19#define IGC_CTRL_GIO_MASTER_DISABLE 0x00000004
20/* Status of Master requests. */
21#define IGC_STATUS_GIO_MASTER_ENABLE 0x00080000
22
23/* PCI Express Control */
24#define IGC_GCR_CMPL_TMOUT_MASK 0x0000F000
25#define IGC_GCR_CMPL_TMOUT_10ms 0x00001000
26#define IGC_GCR_CMPL_TMOUT_RESEND 0x00010000
27#define IGC_GCR_CAP_VER2 0x00040000
28
13/* Receive Address 29/* Receive Address
14 * Number of high/low register pairs in the RAR. The RAR (Receive Address 30 * Number of high/low register pairs in the RAR. The RAR (Receive Address
15 * Registers) holds the directed and multicast addresses that we monitor. 31 * Registers) holds the directed and multicast addresses that we monitor.
@@ -28,10 +44,23 @@
28#define IGC_ERR_PARAM 4 44#define IGC_ERR_PARAM 4
29#define IGC_ERR_MAC_INIT 5 45#define IGC_ERR_MAC_INIT 5
30#define IGC_ERR_RESET 9 46#define IGC_ERR_RESET 9
47#define IGC_ERR_MASTER_REQUESTS_PENDING 10
48#define IGC_ERR_SWFW_SYNC 13
49
50/* Device Control */
51#define IGC_CTRL_RST 0x04000000 /* Global reset */
31 52
32/* PBA constants */ 53/* PBA constants */
33#define IGC_PBA_34K 0x0022 54#define IGC_PBA_34K 0x0022
34 55
56/* SW Semaphore Register */
57#define IGC_SWSM_SMBI 0x00000001 /* Driver Semaphore bit */
58#define IGC_SWSM_SWESMBI 0x00000002 /* FW Semaphore bit */
59
60/* Number of milliseconds for NVM auto read done after MAC reset. */
61#define AUTO_READ_DONE_TIMEOUT 10
62#define IGC_EECD_AUTO_RD 0x00000200 /* NVM Auto Read done */
63
35/* Device Status */ 64/* Device Status */
36#define IGC_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */ 65#define IGC_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */
37#define IGC_STATUS_LU 0x00000002 /* Link up.0=no,1=link */ 66#define IGC_STATUS_LU 0x00000002 /* Link up.0=no,1=link */
@@ -118,6 +147,13 @@
118#define IGC_CT_SHIFT 4 147#define IGC_CT_SHIFT 4
119#define IGC_COLLISION_THRESHOLD 15 148#define IGC_COLLISION_THRESHOLD 15
120 149
150/* Flow Control Constants */
151#define FLOW_CONTROL_ADDRESS_LOW 0x00C28001
152#define FLOW_CONTROL_ADDRESS_HIGH 0x00000100
153#define FLOW_CONTROL_TYPE 0x8808
154/* Enable XON frame transmission */
155#define IGC_FCRTL_XONE 0x80000000
156
121/* Management Control */ 157/* Management Control */
122#define IGC_MANC_RCV_TCO_EN 0x00020000 /* Receive TCO Packets Enabled */ 158#define IGC_MANC_RCV_TCO_EN 0x00020000 /* Receive TCO Packets Enabled */
123 159
diff --git a/drivers/net/ethernet/intel/igc/igc_hw.h b/drivers/net/ethernet/intel/igc/igc_hw.h
index a032495a0479..e31d85f1ee12 100644
--- a/drivers/net/ethernet/intel/igc/igc_hw.h
+++ b/drivers/net/ethernet/intel/igc/igc_hw.h
@@ -6,6 +6,8 @@
6 6
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/if_ether.h> 8#include <linux/if_ether.h>
9#include <linux/netdevice.h>
10
9#include "igc_regs.h" 11#include "igc_regs.h"
10#include "igc_defines.h" 12#include "igc_defines.h"
11#include "igc_mac.h" 13#include "igc_mac.h"
@@ -17,6 +19,16 @@
17 19
18/* Function pointers for the MAC. */ 20/* Function pointers for the MAC. */
19struct igc_mac_operations { 21struct igc_mac_operations {
22 s32 (*check_for_link)(struct igc_hw *hw);
23 s32 (*reset_hw)(struct igc_hw *hw);
24 s32 (*init_hw)(struct igc_hw *hw);
25 s32 (*setup_physical_interface)(struct igc_hw *hw);
26 void (*rar_set)(struct igc_hw *hw, u8 *address, u32 index);
27 s32 (*read_mac_addr)(struct igc_hw *hw);
28 s32 (*get_speed_and_duplex)(struct igc_hw *hw, u16 *speed,
29 u16 *duplex);
30 s32 (*acquire_swfw_sync)(struct igc_hw *hw, u16 mask);
31 void (*release_swfw_sync)(struct igc_hw *hw, u16 mask);
20}; 32};
21 33
22enum igc_mac_type { 34enum igc_mac_type {
@@ -31,6 +43,19 @@ enum igc_phy_type {
31 igc_phy_i225, 43 igc_phy_i225,
32}; 44};
33 45
46enum igc_nvm_type {
47 igc_nvm_unknown = 0,
48 igc_nvm_flash_hw,
49 igc_nvm_invm,
50};
51
52struct igc_info {
53 s32 (*get_invariants)(struct igc_hw *hw);
54 struct igc_mac_operations *mac_ops;
55 const struct igc_phy_operations *phy_ops;
56 struct igc_nvm_operations *nvm_ops;
57};
58
34struct igc_mac_info { 59struct igc_mac_info {
35 struct igc_mac_operations ops; 60 struct igc_mac_operations ops;
36 61
@@ -63,11 +88,61 @@ struct igc_mac_info {
63 bool get_link_status; 88 bool get_link_status;
64}; 89};
65 90
91struct igc_nvm_operations {
92 s32 (*acquire)(struct igc_hw *hw);
93 s32 (*read)(struct igc_hw *hw, u16 offset, u16 i, u16 *data);
94 void (*release)(struct igc_hw *hw);
95 s32 (*write)(struct igc_hw *hw, u16 offset, u16 i, u16 *data);
96 s32 (*update)(struct igc_hw *hw);
97 s32 (*validate)(struct igc_hw *hw);
98 s32 (*valid_led_default)(struct igc_hw *hw, u16 *data);
99};
100
101struct igc_nvm_info {
102 struct igc_nvm_operations ops;
103 enum igc_nvm_type type;
104
105 u32 flash_bank_size;
106 u32 flash_base_addr;
107
108 u16 word_size;
109 u16 delay_usec;
110 u16 address_bits;
111 u16 opcode_bits;
112 u16 page_size;
113};
114
66struct igc_bus_info { 115struct igc_bus_info {
67 u16 func; 116 u16 func;
68 u16 pci_cmd_word; 117 u16 pci_cmd_word;
69}; 118};
70 119
120enum igc_fc_mode {
121 igc_fc_none = 0,
122 igc_fc_rx_pause,
123 igc_fc_tx_pause,
124 igc_fc_full,
125 igc_fc_default = 0xFF
126};
127
128struct igc_fc_info {
129 u32 high_water; /* Flow control high-water mark */
130 u32 low_water; /* Flow control low-water mark */
131 u16 pause_time; /* Flow control pause timer */
132 bool send_xon; /* Flow control send XON */
133 bool strict_ieee; /* Strict IEEE mode */
134 enum igc_fc_mode current_mode; /* Type of flow control */
135 enum igc_fc_mode requested_mode;
136};
137
138struct igc_dev_spec_base {
139 bool global_device_reset;
140 bool eee_disable;
141 bool clear_semaphore_once;
142 bool module_plugged;
143 u8 media_port;
144};
145
71struct igc_hw { 146struct igc_hw {
72 void *back; 147 void *back;
73 148
@@ -75,9 +150,15 @@ struct igc_hw {
75 unsigned long io_base; 150 unsigned long io_base;
76 151
77 struct igc_mac_info mac; 152 struct igc_mac_info mac;
153 struct igc_fc_info fc;
154 struct igc_nvm_info nvm;
78 155
79 struct igc_bus_info bus; 156 struct igc_bus_info bus;
80 157
158 union {
159 struct igc_dev_spec_base _base;
160 } dev_spec;
161
81 u16 device_id; 162 u16 device_id;
82 u16 subsystem_vendor_id; 163 u16 subsystem_vendor_id;
83 u16 subsystem_device_id; 164 u16 subsystem_device_id;
@@ -170,6 +251,10 @@ struct igc_hw_stats {
170 u64 b2ogprc; 251 u64 b2ogprc;
171}; 252};
172 253
254struct net_device *igc_get_hw_dev(struct igc_hw *hw);
255#define hw_dbg(format, arg...) \
256 netdev_dbg(igc_get_hw_dev(hw), format, ##arg)
257
173s32 igc_read_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value); 258s32 igc_read_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value);
174s32 igc_write_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value); 259s32 igc_write_pcie_cap_reg(struct igc_hw *hw, u32 reg, u16 *value);
175void igc_read_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value); 260void igc_read_pci_cfg(struct igc_hw *hw, u32 reg, u16 *value);
diff --git a/drivers/net/ethernet/intel/igc/igc_i225.c b/drivers/net/ethernet/intel/igc/igc_i225.c
new file mode 100644
index 000000000000..fb1487727d79
--- /dev/null
+++ b/drivers/net/ethernet/intel/igc/igc_i225.c
@@ -0,0 +1,141 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2018 Intel Corporation */
3
4#include <linux/delay.h>
5
6#include "igc_hw.h"
7
8/**
9 * igc_get_hw_semaphore_i225 - Acquire hardware semaphore
10 * @hw: pointer to the HW structure
11 *
12 * Acquire the HW semaphore to access the PHY or NVM
13 */
14static s32 igc_get_hw_semaphore_i225(struct igc_hw *hw)
15{
16 s32 timeout = hw->nvm.word_size + 1;
17 s32 i = 0;
18 u32 swsm;
19
20 /* Get the SW semaphore */
21 while (i < timeout) {
22 swsm = rd32(IGC_SWSM);
23 if (!(swsm & IGC_SWSM_SMBI))
24 break;
25
26 usleep_range(500, 600);
27 i++;
28 }
29
30 if (i == timeout) {
31 /* In rare circumstances, the SW semaphore may already be held
32 * unintentionally. Clear the semaphore once before giving up.
33 */
34 if (hw->dev_spec._base.clear_semaphore_once) {
35 hw->dev_spec._base.clear_semaphore_once = false;
36 igc_put_hw_semaphore(hw);
37 for (i = 0; i < timeout; i++) {
38 swsm = rd32(IGC_SWSM);
39 if (!(swsm & IGC_SWSM_SMBI))
40 break;
41
42 usleep_range(500, 600);
43 }
44 }
45
46 /* If we do not have the semaphore here, we have to give up. */
47 if (i == timeout) {
48 hw_dbg("Driver can't access device - SMBI bit is set.\n");
49 return -IGC_ERR_NVM;
50 }
51 }
52
53 /* Get the FW semaphore. */
54 for (i = 0; i < timeout; i++) {
55 swsm = rd32(IGC_SWSM);
56 wr32(IGC_SWSM, swsm | IGC_SWSM_SWESMBI);
57
58 /* Semaphore acquired if bit latched */
59 if (rd32(IGC_SWSM) & IGC_SWSM_SWESMBI)
60 break;
61
62 usleep_range(500, 600);
63 }
64
65 if (i == timeout) {
66 /* Release semaphores */
67 igc_put_hw_semaphore(hw);
68 hw_dbg("Driver can't access the NVM\n");
69 return -IGC_ERR_NVM;
70 }
71
72 return 0;
73}
74
75/**
76 * igc_acquire_swfw_sync_i225 - Acquire SW/FW semaphore
77 * @hw: pointer to the HW structure
78 * @mask: specifies which semaphore to acquire
79 *
80 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
81 * will also specify which port we're acquiring the lock for.
82 */
83s32 igc_acquire_swfw_sync_i225(struct igc_hw *hw, u16 mask)
84{
85 s32 i = 0, timeout = 200;
86 u32 fwmask = mask << 16;
87 u32 swmask = mask;
88 s32 ret_val = 0;
89 u32 swfw_sync;
90
91 while (i < timeout) {
92 if (igc_get_hw_semaphore_i225(hw)) {
93 ret_val = -IGC_ERR_SWFW_SYNC;
94 goto out;
95 }
96
97 swfw_sync = rd32(IGC_SW_FW_SYNC);
98 if (!(swfw_sync & (fwmask | swmask)))
99 break;
100
101 /* Firmware currently using resource (fwmask) */
102 igc_put_hw_semaphore(hw);
103 mdelay(5);
104 i++;
105 }
106
107 if (i == timeout) {
108 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
109 ret_val = -IGC_ERR_SWFW_SYNC;
110 goto out;
111 }
112
113 swfw_sync |= swmask;
114 wr32(IGC_SW_FW_SYNC, swfw_sync);
115
116 igc_put_hw_semaphore(hw);
117out:
118 return ret_val;
119}
120
121/**
122 * igc_release_swfw_sync_i225 - Release SW/FW semaphore
123 * @hw: pointer to the HW structure
124 * @mask: specifies which semaphore to acquire
125 *
126 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
127 * will also specify which port we're releasing the lock for.
128 */
129void igc_release_swfw_sync_i225(struct igc_hw *hw, u16 mask)
130{
131 u32 swfw_sync;
132
133 while (igc_get_hw_semaphore_i225(hw))
134 ; /* Empty */
135
136 swfw_sync = rd32(IGC_SW_FW_SYNC);
137 swfw_sync &= ~mask;
138 wr32(IGC_SW_FW_SYNC, swfw_sync);
139
140 igc_put_hw_semaphore(hw);
141}
diff --git a/drivers/net/ethernet/intel/igc/igc_mac.c b/drivers/net/ethernet/intel/igc/igc_mac.c
index 9976943df51c..90a98ee14550 100644
--- a/drivers/net/ethernet/intel/igc/igc_mac.c
+++ b/drivers/net/ethernet/intel/igc/igc_mac.c
@@ -2,4 +2,319 @@
2/* Copyright (c) 2018 Intel Corporation */ 2/* Copyright (c) 2018 Intel Corporation */
3 3
4#include <linux/pci.h> 4#include <linux/pci.h>
5#include <linux/delay.h>
6
7#include "igc_mac.h"
5#include "igc_hw.h" 8#include "igc_hw.h"
9
10/* forward declaration */
11static s32 igc_set_default_fc(struct igc_hw *hw);
12static s32 igc_set_fc_watermarks(struct igc_hw *hw);
13
14/**
15 * igc_disable_pcie_master - Disables PCI-express master access
16 * @hw: pointer to the HW structure
17 *
18 * Returns 0 (0) if successful, else returns -10
19 * (-IGC_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
20 * the master requests to be disabled.
21 *
22 * Disables PCI-Express master access and verifies there are no pending
23 * requests.
24 */
25s32 igc_disable_pcie_master(struct igc_hw *hw)
26{
27 s32 timeout = MASTER_DISABLE_TIMEOUT;
28 s32 ret_val = 0;
29 u32 ctrl;
30
31 ctrl = rd32(IGC_CTRL);
32 ctrl |= IGC_CTRL_GIO_MASTER_DISABLE;
33 wr32(IGC_CTRL, ctrl);
34
35 while (timeout) {
36 if (!(rd32(IGC_STATUS) &
37 IGC_STATUS_GIO_MASTER_ENABLE))
38 break;
39 usleep_range(2000, 3000);
40 timeout--;
41 }
42
43 if (!timeout) {
44 hw_dbg("Master requests are pending.\n");
45 ret_val = -IGC_ERR_MASTER_REQUESTS_PENDING;
46 goto out;
47 }
48
49out:
50 return ret_val;
51}
52
53/**
54 * igc_init_rx_addrs - Initialize receive addresses
55 * @hw: pointer to the HW structure
56 * @rar_count: receive address registers
57 *
58 * Setup the receive address registers by setting the base receive address
59 * register to the devices MAC address and clearing all the other receive
60 * address registers to 0.
61 */
62void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count)
63{
64 u8 mac_addr[ETH_ALEN] = {0};
65 u32 i;
66
67 /* Setup the receive address */
68 hw_dbg("Programming MAC Address into RAR[0]\n");
69
70 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
71
72 /* Zero out the other (rar_entry_count - 1) receive addresses */
73 hw_dbg("Clearing RAR[1-%u]\n", rar_count - 1);
74 for (i = 1; i < rar_count; i++)
75 hw->mac.ops.rar_set(hw, mac_addr, i);
76}
77
78/**
79 * igc_setup_link - Setup flow control and link settings
80 * @hw: pointer to the HW structure
81 *
82 * Determines which flow control settings to use, then configures flow
83 * control. Calls the appropriate media-specific link configuration
84 * function. Assuming the adapter has a valid link partner, a valid link
85 * should be established. Assumes the hardware has previously been reset
86 * and the transmitter and receiver are not enabled.
87 */
88s32 igc_setup_link(struct igc_hw *hw)
89{
90 s32 ret_val = 0;
91
92 /* In the case of the phy reset being blocked, we already have a link.
93 * We do not need to set it up again.
94 */
95
96 /* If requested flow control is set to default, set flow control
97 * based on the EEPROM flow control settings.
98 */
99 if (hw->fc.requested_mode == igc_fc_default) {
100 ret_val = igc_set_default_fc(hw);
101 if (ret_val)
102 goto out;
103 }
104
105 /* We want to save off the original Flow Control configuration just
106 * in case we get disconnected and then reconnected into a different
107 * hub or switch with different Flow Control capabilities.
108 */
109 hw->fc.current_mode = hw->fc.requested_mode;
110
111 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
112
113 /* Call the necessary media_type subroutine to configure the link. */
114 ret_val = hw->mac.ops.setup_physical_interface(hw);
115 if (ret_val)
116 goto out;
117
118 /* Initialize the flow control address, type, and PAUSE timer
119 * registers to their default values. This is done even if flow
120 * control is disabled, because it does not hurt anything to
121 * initialize these registers.
122 */
123 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
124 wr32(IGC_FCT, FLOW_CONTROL_TYPE);
125 wr32(IGC_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
126 wr32(IGC_FCAL, FLOW_CONTROL_ADDRESS_LOW);
127
128 wr32(IGC_FCTTV, hw->fc.pause_time);
129
130 ret_val = igc_set_fc_watermarks(hw);
131
132out:
133 return ret_val;
134}
135
136/**
137 * igc_set_default_fc - Set flow control default values
138 * @hw: pointer to the HW structure
139 *
140 * Read the EEPROM for the default values for flow control and store the
141 * values.
142 */
143static s32 igc_set_default_fc(struct igc_hw *hw)
144{
145 return 0;
146}
147
148/**
149 * igc_set_fc_watermarks - Set flow control high/low watermarks
150 * @hw: pointer to the HW structure
151 *
152 * Sets the flow control high/low threshold (watermark) registers. If
153 * flow control XON frame transmission is enabled, then set XON frame
154 * transmission as well.
155 */
156static s32 igc_set_fc_watermarks(struct igc_hw *hw)
157{
158 u32 fcrtl = 0, fcrth = 0;
159
160 /* Set the flow control receive threshold registers. Normally,
161 * these registers will be set to a default threshold that may be
162 * adjusted later by the driver's runtime code. However, if the
163 * ability to transmit pause frames is not enabled, then these
164 * registers will be set to 0.
165 */
166 if (hw->fc.current_mode & igc_fc_tx_pause) {
167 /* We need to set up the Receive Threshold high and low water
168 * marks as well as (optionally) enabling the transmission of
169 * XON frames.
170 */
171 fcrtl = hw->fc.low_water;
172 if (hw->fc.send_xon)
173 fcrtl |= IGC_FCRTL_XONE;
174
175 fcrth = hw->fc.high_water;
176 }
177 wr32(IGC_FCRTL, fcrtl);
178 wr32(IGC_FCRTH, fcrth);
179
180 return 0;
181}
182
183/**
184 * igc_clear_hw_cntrs_base - Clear base hardware counters
185 * @hw: pointer to the HW structure
186 *
187 * Clears the base hardware counters by reading the counter registers.
188 */
189void igc_clear_hw_cntrs_base(struct igc_hw *hw)
190{
191 rd32(IGC_CRCERRS);
192 rd32(IGC_SYMERRS);
193 rd32(IGC_MPC);
194 rd32(IGC_SCC);
195 rd32(IGC_ECOL);
196 rd32(IGC_MCC);
197 rd32(IGC_LATECOL);
198 rd32(IGC_COLC);
199 rd32(IGC_DC);
200 rd32(IGC_SEC);
201 rd32(IGC_RLEC);
202 rd32(IGC_XONRXC);
203 rd32(IGC_XONTXC);
204 rd32(IGC_XOFFRXC);
205 rd32(IGC_XOFFTXC);
206 rd32(IGC_FCRUC);
207 rd32(IGC_GPRC);
208 rd32(IGC_BPRC);
209 rd32(IGC_MPRC);
210 rd32(IGC_GPTC);
211 rd32(IGC_GORCL);
212 rd32(IGC_GORCH);
213 rd32(IGC_GOTCL);
214 rd32(IGC_GOTCH);
215 rd32(IGC_RNBC);
216 rd32(IGC_RUC);
217 rd32(IGC_RFC);
218 rd32(IGC_ROC);
219 rd32(IGC_RJC);
220 rd32(IGC_TORL);
221 rd32(IGC_TORH);
222 rd32(IGC_TOTL);
223 rd32(IGC_TOTH);
224 rd32(IGC_TPR);
225 rd32(IGC_TPT);
226 rd32(IGC_MPTC);
227 rd32(IGC_BPTC);
228
229 rd32(IGC_PRC64);
230 rd32(IGC_PRC127);
231 rd32(IGC_PRC255);
232 rd32(IGC_PRC511);
233 rd32(IGC_PRC1023);
234 rd32(IGC_PRC1522);
235 rd32(IGC_PTC64);
236 rd32(IGC_PTC127);
237 rd32(IGC_PTC255);
238 rd32(IGC_PTC511);
239 rd32(IGC_PTC1023);
240 rd32(IGC_PTC1522);
241
242 rd32(IGC_ALGNERRC);
243 rd32(IGC_RXERRC);
244 rd32(IGC_TNCRS);
245 rd32(IGC_CEXTERR);
246 rd32(IGC_TSCTC);
247 rd32(IGC_TSCTFC);
248
249 rd32(IGC_MGTPRC);
250 rd32(IGC_MGTPDC);
251 rd32(IGC_MGTPTC);
252
253 rd32(IGC_IAC);
254 rd32(IGC_ICRXOC);
255
256 rd32(IGC_ICRXPTC);
257 rd32(IGC_ICRXATC);
258 rd32(IGC_ICTXPTC);
259 rd32(IGC_ICTXATC);
260 rd32(IGC_ICTXQEC);
261 rd32(IGC_ICTXQMTC);
262 rd32(IGC_ICRXDMTC);
263
264 rd32(IGC_CBTMPC);
265 rd32(IGC_HTDPMC);
266 rd32(IGC_CBRMPC);
267 rd32(IGC_RPTHC);
268 rd32(IGC_HGPTC);
269 rd32(IGC_HTCBDPC);
270 rd32(IGC_HGORCL);
271 rd32(IGC_HGORCH);
272 rd32(IGC_HGOTCL);
273 rd32(IGC_HGOTCH);
274 rd32(IGC_LENERRS);
275}
276
277/**
278 * igc_get_auto_rd_done - Check for auto read completion
279 * @hw: pointer to the HW structure
280 *
281 * Check EEPROM for Auto Read done bit.
282 */
283s32 igc_get_auto_rd_done(struct igc_hw *hw)
284{
285 s32 ret_val = 0;
286 s32 i = 0;
287
288 while (i < AUTO_READ_DONE_TIMEOUT) {
289 if (rd32(IGC_EECD) & IGC_EECD_AUTO_RD)
290 break;
291 usleep_range(1000, 2000);
292 i++;
293 }
294
295 if (i == AUTO_READ_DONE_TIMEOUT) {
296 hw_dbg("Auto read by HW from NVM has not completed.\n");
297 ret_val = -IGC_ERR_RESET;
298 goto out;
299 }
300
301out:
302 return ret_val;
303}
304
305/**
306 * igc_put_hw_semaphore - Release hardware semaphore
307 * @hw: pointer to the HW structure
308 *
309 * Release hardware semaphore used to access the PHY or NVM
310 */
311void igc_put_hw_semaphore(struct igc_hw *hw)
312{
313 u32 swsm;
314
315 swsm = rd32(IGC_SWSM);
316
317 swsm &= ~(IGC_SWSM_SMBI | IGC_SWSM_SWESMBI);
318
319 wr32(IGC_SWSM, swsm);
320}
diff --git a/drivers/net/ethernet/intel/igc/igc_mac.h b/drivers/net/ethernet/intel/igc/igc_mac.h
index 25b79a240d60..88bdb8dd6f3f 100644
--- a/drivers/net/ethernet/intel/igc/igc_mac.h
+++ b/drivers/net/ethernet/intel/igc/igc_mac.h
@@ -4,8 +4,19 @@
4#ifndef _IGC_MAC_H_ 4#ifndef _IGC_MAC_H_
5#define _IGC_MAC_H_ 5#define _IGC_MAC_H_
6 6
7#include "igc_hw.h"
8#include "igc_defines.h"
9
7#ifndef IGC_REMOVED 10#ifndef IGC_REMOVED
8#define IGC_REMOVED(a) (0) 11#define IGC_REMOVED(a) (0)
9#endif /* IGC_REMOVED */ 12#endif /* IGC_REMOVED */
10 13
14/* forward declaration */
15s32 igc_disable_pcie_master(struct igc_hw *hw);
16void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count);
17s32 igc_setup_link(struct igc_hw *hw);
18void igc_clear_hw_cntrs_base(struct igc_hw *hw);
19s32 igc_get_auto_rd_done(struct igc_hw *hw);
20void igc_put_hw_semaphore(struct igc_hw *hw);
21
11#endif 22#endif
diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c
index db7b6820e0f0..f2ad49fcd39b 100644
--- a/drivers/net/ethernet/intel/igc/igc_main.c
+++ b/drivers/net/ethernet/intel/igc/igc_main.c
@@ -64,6 +64,14 @@ enum latency_range {
64 64
65static void igc_reset(struct igc_adapter *adapter) 65static void igc_reset(struct igc_adapter *adapter)
66{ 66{
67 struct pci_dev *pdev = adapter->pdev;
68 struct igc_hw *hw = &adapter->hw;
69
70 hw->mac.ops.reset_hw(hw);
71
72 if (hw->mac.ops.init_hw(hw))
73 dev_err(&pdev->dev, "Hardware Error\n");
74
67 if (!netif_running(adapter->netdev)) 75 if (!netif_running(adapter->netdev))
68 igc_power_down_link(adapter); 76 igc_power_down_link(adapter);
69} 77}
@@ -3556,6 +3564,19 @@ static int igc_sw_init(struct igc_adapter *adapter)
3556} 3564}
3557 3565
3558/** 3566/**
3567 * igc_get_hw_dev - return device
3568 * @hw: pointer to hardware structure
3569 *
3570 * used by hardware layer to print debugging information
3571 */
3572struct net_device *igc_get_hw_dev(struct igc_hw *hw)
3573{
3574 struct igc_adapter *adapter = hw->back;
3575
3576 return adapter->netdev;
3577}
3578
3579/**
3559 * igc_init_module - Driver Registration Routine 3580 * igc_init_module - Driver Registration Routine
3560 * 3581 *
3561 * igc_init_module is the first routine called when the driver is 3582 * igc_init_module is the first routine called when the driver is
diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethernet/intel/igc/igc_regs.h
index e268986eeb9f..c57f573fb864 100644
--- a/drivers/net/ethernet/intel/igc/igc_regs.h
+++ b/drivers/net/ethernet/intel/igc/igc_regs.h
@@ -7,6 +7,7 @@
7/* General Register Descriptions */ 7/* General Register Descriptions */
8#define IGC_CTRL 0x00000 /* Device Control - RW */ 8#define IGC_CTRL 0x00000 /* Device Control - RW */
9#define IGC_STATUS 0x00008 /* Device Status - RO */ 9#define IGC_STATUS 0x00008 /* Device Status - RO */
10#define IGC_EECD 0x00010 /* EEPROM/Flash Control - RW */
10#define IGC_CTRL_EXT 0x00018 /* Extended Device Control - RW */ 11#define IGC_CTRL_EXT 0x00018 /* Extended Device Control - RW */
11#define IGC_MDIC 0x00020 /* MDI Control - RW */ 12#define IGC_MDIC 0x00020 /* MDI Control - RW */
12#define IGC_MDICNFG 0x00E04 /* MDC/MDIO Configuration - RW */ 13#define IGC_MDICNFG 0x00E04 /* MDC/MDIO Configuration - RW */
@@ -56,6 +57,23 @@
56#define IGC_IVAR_MISC 0x01740 /* IVAR for "other" causes - RW */ 57#define IGC_IVAR_MISC 0x01740 /* IVAR for "other" causes - RW */
57#define IGC_GPIE 0x01514 /* General Purpose Intr Enable - RW */ 58#define IGC_GPIE 0x01514 /* General Purpose Intr Enable - RW */
58 59
60/* Interrupt Cause */
61#define IGC_ICRXPTC 0x04104 /* Rx Packet Timer Expire Count */
62#define IGC_ICRXATC 0x04108 /* Rx Absolute Timer Expire Count */
63#define IGC_ICTXPTC 0x0410C /* Tx Packet Timer Expire Count */
64#define IGC_ICTXATC 0x04110 /* Tx Absolute Timer Expire Count */
65#define IGC_ICTXQEC 0x04118 /* Tx Queue Empty Count */
66#define IGC_ICTXQMTC 0x0411C /* Tx Queue Min Threshold Count */
67#define IGC_ICRXDMTC 0x04120 /* Rx Descriptor Min Threshold Count */
68#define IGC_ICRXOC 0x04124 /* Receiver Overrun Count */
69
70#define IGC_CBTMPC 0x0402C /* Circuit Breaker TX Packet Count */
71#define IGC_HTDPMC 0x0403C /* Host Transmit Discarded Packets */
72#define IGC_CBRMPC 0x040FC /* Circuit Breaker RX Packet Count */
73#define IGC_RPTHC 0x04104 /* Rx Packets To Host */
74#define IGC_HGPTC 0x04118 /* Host Good Packets TX Count */
75#define IGC_HTCBDPC 0x04124 /* Host TX Circ.Breaker Drop Count */
76
59/* MSI-X Table Register Descriptions */ 77/* MSI-X Table Register Descriptions */
60#define IGC_PBACL 0x05B68 /* MSIx PBA Clear - R/W 1 to clear */ 78#define IGC_PBACL 0x05B68 /* MSIx PBA Clear - R/W 1 to clear */
61 79
@@ -73,6 +91,8 @@
73#define IGC_RXCSUM 0x05000 /* Rx Checksum Control - RW */ 91#define IGC_RXCSUM 0x05000 /* Rx Checksum Control - RW */
74#define IGC_RLPML 0x05004 /* Rx Long Packet Max Length */ 92#define IGC_RLPML 0x05004 /* Rx Long Packet Max Length */
75#define IGC_RFCTL 0x05008 /* Receive Filter Control*/ 93#define IGC_RFCTL 0x05008 /* Receive Filter Control*/
94#define IGC_MTA 0x05200 /* Multicast Table Array - RW Array */
95#define IGC_UTA 0x0A000 /* Unicast Table Array - RW */
76#define IGC_RAL(_n) (0x05400 + ((_n) * 0x08)) 96#define IGC_RAL(_n) (0x05400 + ((_n) * 0x08))
77#define IGC_RAH(_n) (0x05404 + ((_n) * 0x08)) 97#define IGC_RAH(_n) (0x05404 + ((_n) * 0x08))
78 98