Skip to content

Commit c0071c7

Browse files
Sasha NeftinJeff Kirsher
authored andcommitted
igc: Add HW initialization code
Add code for hardware initialization and reset Add code for semaphore handling Signed-off-by: Sasha Neftin <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 0507ef8 commit c0071c7

File tree

10 files changed

+819
-1
lines changed

10 files changed

+819
-1
lines changed

drivers/net/ethernet/intel/igc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
obj-$(CONFIG_IGC) += igc.o
99

10-
igc-objs := igc_main.o igc_mac.o igc_base.o
10+
igc-objs := igc_main.o igc_mac.o igc_i225.o igc_base.o

drivers/net/ethernet/intel/igc/igc_base.c

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,184 @@
55

66
#include "igc_hw.h"
77
#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+
*/
16+
static 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);
47+
out:
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+
*/
63+
static 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+
*/
114+
static 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+
131+
static 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+
145+
out:
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+
*/
155+
static 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+
}
8186

9187
/**
10188
* 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)
81259
rd32(IGC_RNBC);
82260
rd32(IGC_MPC);
83261
}
262+
263+
static struct igc_mac_operations igc_mac_ops_base = {
264+
.init_hw = igc_init_hw_base,
265+
};
266+
267+
const struct igc_info igc_base_info = {
268+
.get_invariants = igc_get_invariants_base,
269+
.mac_ops = &igc_mac_ops_base,
270+
};

drivers/net/ethernet/intel/igc/igc_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ union igc_adv_tx_desc {
3333
#define IGC_ADVTXD_DCMD_TSE 0x80000000 /* TCP Seg enable */
3434
#define IGC_ADVTXD_PAYLEN_SHIFT 14 /* Adv desc PAYLEN shift */
3535

36+
#define IGC_RAR_ENTRIES 16
37+
3638
struct igc_adv_data_desc {
3739
__le64 buffer_addr; /* Address of the descriptor's data buffer */
3840
union {

drivers/net/ethernet/intel/igc/igc_defines.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
#define PCIE_DEVICE_CONTROL2 0x28
1111
#define PCIE_DEVICE_CONTROL2_16ms 0x0005
1212

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+
1329
/* Receive Address
1430
* Number of high/low register pairs in the RAR. The RAR (Receive Address
1531
* Registers) holds the directed and multicast addresses that we monitor.
@@ -28,10 +44,23 @@
2844
#define IGC_ERR_PARAM 4
2945
#define IGC_ERR_MAC_INIT 5
3046
#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 */
3152

3253
/* PBA constants */
3354
#define IGC_PBA_34K 0x0022
3455

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+
3564
/* Device Status */
3665
#define IGC_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */
3766
#define IGC_STATUS_LU 0x00000002 /* Link up.0=no,1=link */
@@ -118,6 +147,13 @@
118147
#define IGC_CT_SHIFT 4
119148
#define IGC_COLLISION_THRESHOLD 15
120149

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+
121157
/* Management Control */
122158
#define IGC_MANC_RCV_TCO_EN 0x00020000 /* Receive TCO Packets Enabled */
123159

0 commit comments

Comments
 (0)