Skip to content

Commit ab40561

Browse files
Sasha NeftinJeff Kirsher
authored andcommitted
igc: Add NVM support
Add code for NVM support and get MAC address, complete probe method. Signed-off-by: Sasha Neftin <[email protected]> Signed-off-by: Alexander Duyck <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent c0071c7 commit ab40561

File tree

13 files changed

+949
-3
lines changed

13 files changed

+949
-3
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_i225.o igc_base.o
10+
igc-objs := igc_main.o igc_mac.o igc_i225.o igc_base.o igc_nvm.o

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ enum igc_tx_flags {
131131
IGC_TX_FLAGS_CSUM = 0x20,
132132
};
133133

134+
enum igc_boards {
135+
board_base,
136+
};
137+
134138
/* The largest size we can write to the descriptor is 65535. In order to
135139
* maintain a power of two alignment we have to limit ourselves to 32K.
136140
*/
@@ -342,6 +346,8 @@ struct igc_adapter {
342346
spinlock_t nfc_lock;
343347

344348
struct igc_mac_addr *mac_table;
349+
350+
struct igc_info ei;
345351
};
346352

347353
/* igc_desc_unused - calculate if we have unused descriptors */

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ static s32 igc_set_pcie_completion_timeout(struct igc_hw *hw)
5353
return ret_val;
5454
}
5555

56+
/**
57+
* igc_check_for_link_base - Check for link
58+
* @hw: pointer to the HW structure
59+
*
60+
* If sgmii is enabled, then use the pcs register to determine link, otherwise
61+
* use the generic interface for determining link.
62+
*/
63+
static s32 igc_check_for_link_base(struct igc_hw *hw)
64+
{
65+
s32 ret_val = 0;
66+
67+
ret_val = igc_check_for_copper_link(hw);
68+
69+
return ret_val;
70+
}
71+
5672
/**
5773
* igc_reset_hw_base - Reset hardware
5874
* @hw: pointer to the HW structure
@@ -107,12 +123,51 @@ static s32 igc_reset_hw_base(struct igc_hw *hw)
107123
return ret_val;
108124
}
109125

126+
/**
127+
* igc_init_nvm_params_base - Init NVM func ptrs.
128+
* @hw: pointer to the HW structure
129+
*/
130+
static s32 igc_init_nvm_params_base(struct igc_hw *hw)
131+
{
132+
struct igc_nvm_info *nvm = &hw->nvm;
133+
u32 eecd = rd32(IGC_EECD);
134+
u16 size;
135+
136+
size = (u16)((eecd & IGC_EECD_SIZE_EX_MASK) >>
137+
IGC_EECD_SIZE_EX_SHIFT);
138+
139+
/* Added to a constant, "size" becomes the left-shift value
140+
* for setting word_size.
141+
*/
142+
size += NVM_WORD_SIZE_BASE_SHIFT;
143+
144+
/* Just in case size is out of range, cap it to the largest
145+
* EEPROM size supported
146+
*/
147+
if (size > 15)
148+
size = 15;
149+
150+
nvm->word_size = BIT(size);
151+
nvm->opcode_bits = 8;
152+
nvm->delay_usec = 1;
153+
154+
nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
155+
nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ?
156+
16 : 8;
157+
158+
if (nvm->word_size == BIT(15))
159+
nvm->page_size = 128;
160+
161+
return 0;
162+
}
163+
110164
/**
111165
* igc_init_mac_params_base - Init MAC func ptrs.
112166
* @hw: pointer to the HW structure
113167
*/
114168
static s32 igc_init_mac_params_base(struct igc_hw *hw)
115169
{
170+
struct igc_dev_spec_base *dev_spec = &hw->dev_spec._base;
116171
struct igc_mac_info *mac = &hw->mac;
117172

118173
/* Set mta register count */
@@ -125,6 +180,10 @@ static s32 igc_init_mac_params_base(struct igc_hw *hw)
125180
mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
126181
mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
127182

183+
/* Allow a single clear of the SW semaphore on I225 */
184+
if (mac->type == igc_i225)
185+
dev_spec->clear_semaphore_once = true;
186+
128187
return 0;
129188
}
130189

@@ -142,10 +201,43 @@ static s32 igc_get_invariants_base(struct igc_hw *hw)
142201
if (ret_val)
143202
goto out;
144203

204+
/* NVM initialization */
205+
ret_val = igc_init_nvm_params_base(hw);
206+
switch (hw->mac.type) {
207+
case igc_i225:
208+
ret_val = igc_init_nvm_params_i225(hw);
209+
break;
210+
default:
211+
break;
212+
}
213+
214+
if (ret_val)
215+
goto out;
216+
145217
out:
146218
return ret_val;
147219
}
148220

221+
/**
222+
* igc_get_link_up_info_base - Get link speed/duplex info
223+
* @hw: pointer to the HW structure
224+
* @speed: stores the current speed
225+
* @duplex: stores the current duplex
226+
*
227+
* This is a wrapper function, if using the serial gigabit media independent
228+
* interface, use PCS to retrieve the link speed and duplex information.
229+
* Otherwise, use the generic function to get the link speed and duplex info.
230+
*/
231+
static s32 igc_get_link_up_info_base(struct igc_hw *hw, u16 *speed,
232+
u16 *duplex)
233+
{
234+
s32 ret_val;
235+
236+
ret_val = igc_get_speed_and_duplex_copper(hw, speed, duplex);
237+
238+
return ret_val;
239+
}
240+
149241
/**
150242
* igc_init_hw_base - Initialize hardware
151243
* @hw: pointer to the HW structure
@@ -184,6 +276,19 @@ static s32 igc_init_hw_base(struct igc_hw *hw)
184276
return ret_val;
185277
}
186278

279+
/**
280+
* igc_read_mac_addr_base - Read device MAC address
281+
* @hw: pointer to the HW structure
282+
*/
283+
static s32 igc_read_mac_addr_base(struct igc_hw *hw)
284+
{
285+
s32 ret_val = 0;
286+
287+
ret_val = igc_read_mac_addr(hw);
288+
289+
return ret_val;
290+
}
291+
187292
/**
188293
* igc_rx_fifo_flush_base - Clean rx fifo after Rx enable
189294
* @hw: pointer to the HW structure
@@ -262,6 +367,10 @@ void igc_rx_fifo_flush_base(struct igc_hw *hw)
262367

263368
static struct igc_mac_operations igc_mac_ops_base = {
264369
.init_hw = igc_init_hw_base,
370+
.check_for_link = igc_check_for_link_base,
371+
.rar_set = igc_rar_set,
372+
.read_mac_addr = igc_read_mac_addr_base,
373+
.get_speed_and_duplex = igc_get_link_up_info_base,
265374
};
266375

267376
const struct igc_info igc_base_info = {

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
#define IGC_RAH_AV 0x80000000 /* Receive descriptor valid */
3737
#define IGC_RAH_POOL_1 0x00040000
38+
#define IGC_RAL_MAC_ADDR_LEN 4
39+
#define IGC_RAH_MAC_ADDR_LEN 2
3840

3941
/* Error Codes */
4042
#define IGC_SUCCESS 0
@@ -57,9 +59,51 @@
5759
#define IGC_SWSM_SMBI 0x00000001 /* Driver Semaphore bit */
5860
#define IGC_SWSM_SWESMBI 0x00000002 /* FW Semaphore bit */
5961

62+
/* SWFW_SYNC Definitions */
63+
#define IGC_SWFW_EEP_SM 0x1
64+
#define IGC_SWFW_PHY0_SM 0x2
65+
66+
/* NVM Control */
6067
/* Number of milliseconds for NVM auto read done after MAC reset. */
6168
#define AUTO_READ_DONE_TIMEOUT 10
6269
#define IGC_EECD_AUTO_RD 0x00000200 /* NVM Auto Read done */
70+
#define IGC_EECD_REQ 0x00000040 /* NVM Access Request */
71+
#define IGC_EECD_GNT 0x00000080 /* NVM Access Grant */
72+
/* NVM Addressing bits based on type 0=small, 1=large */
73+
#define IGC_EECD_ADDR_BITS 0x00000400
74+
#define IGC_NVM_GRANT_ATTEMPTS 1000 /* NVM # attempts to gain grant */
75+
#define IGC_EECD_SIZE_EX_MASK 0x00007800 /* NVM Size */
76+
#define IGC_EECD_SIZE_EX_SHIFT 11
77+
#define IGC_EECD_FLUPD_I225 0x00800000 /* Update FLASH */
78+
#define IGC_EECD_FLUDONE_I225 0x04000000 /* Update FLASH done*/
79+
#define IGC_EECD_FLASH_DETECTED_I225 0x00080000 /* FLASH detected */
80+
#define IGC_FLUDONE_ATTEMPTS 20000
81+
#define IGC_EERD_EEWR_MAX_COUNT 512 /* buffered EEPROM words rw */
82+
83+
/* Offset to data in NVM read/write registers */
84+
#define IGC_NVM_RW_REG_DATA 16
85+
#define IGC_NVM_RW_REG_DONE 2 /* Offset to READ/WRITE done bit */
86+
#define IGC_NVM_RW_REG_START 1 /* Start operation */
87+
#define IGC_NVM_RW_ADDR_SHIFT 2 /* Shift to the address bits */
88+
#define IGC_NVM_POLL_READ 0 /* Flag for polling for read complete */
89+
90+
/* NVM Word Offsets */
91+
#define NVM_CHECKSUM_REG 0x003F
92+
93+
/* For checksumming, the sum of all words in the NVM should equal 0xBABA. */
94+
#define NVM_SUM 0xBABA
95+
96+
#define NVM_PBA_OFFSET_0 8
97+
#define NVM_PBA_OFFSET_1 9
98+
#define NVM_RESERVED_WORD 0xFFFF
99+
#define NVM_PBA_PTR_GUARD 0xFAFA
100+
#define NVM_WORD_SIZE_BASE_SHIFT 6
101+
102+
/* Collision related configuration parameters */
103+
#define IGC_COLLISION_THRESHOLD 15
104+
#define IGC_CT_SHIFT 4
105+
#define IGC_COLLISION_DISTANCE 63
106+
#define IGC_COLD_SHIFT 12
63107

64108
/* Device Status */
65109
#define IGC_STATUS_FD 0x00000001 /* Full duplex.0=half,1=full */
@@ -70,6 +114,14 @@
70114
#define IGC_STATUS_TXOFF 0x00000010 /* transmission paused */
71115
#define IGC_STATUS_SPEED_100 0x00000040 /* Speed 100Mb/s */
72116
#define IGC_STATUS_SPEED_1000 0x00000080 /* Speed 1000Mb/s */
117+
#define IGC_STATUS_SPEED_2500 0x00400000 /* Speed 2.5Gb/s */
118+
119+
#define SPEED_10 10
120+
#define SPEED_100 100
121+
#define SPEED_1000 1000
122+
#define SPEED_2500 2500
123+
#define HALF_DUPLEX 1
124+
#define FULL_DUPLEX 2
73125

74126
/* Interrupt Cause Read */
75127
#define IGC_ICR_TXDW BIT(0) /* Transmit desc written back */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "igc_regs.h"
1212
#include "igc_defines.h"
1313
#include "igc_mac.h"
14+
#include "igc_nvm.h"
1415
#include "igc_i225.h"
1516
#include "igc_base.h"
1617

@@ -56,6 +57,8 @@ struct igc_info {
5657
struct igc_nvm_operations *nvm_ops;
5758
};
5859

60+
extern const struct igc_info igc_base_info;
61+
5962
struct igc_mac_info {
6063
struct igc_mac_operations ops;
6164

0 commit comments

Comments
 (0)