@@ -107,6 +107,16 @@ s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
107107 return e1e_wphy (hw , M88E1000_PHY_GEN_CONTROL , 0 );
108108}
109109
110+ void e1000e_disable_phy_retry (struct e1000_hw * hw )
111+ {
112+ hw -> phy .retry_enabled = false;
113+ }
114+
115+ void e1000e_enable_phy_retry (struct e1000_hw * hw )
116+ {
117+ hw -> phy .retry_enabled = true;
118+ }
119+
110120/**
111121 * e1000e_read_phy_reg_mdic - Read MDI control register
112122 * @hw: pointer to the HW structure
@@ -118,55 +128,73 @@ s32 e1000e_phy_reset_dsp(struct e1000_hw *hw)
118128 **/
119129s32 e1000e_read_phy_reg_mdic (struct e1000_hw * hw , u32 offset , u16 * data )
120130{
131+ u32 i , mdic = 0 , retry_counter , retry_max ;
121132 struct e1000_phy_info * phy = & hw -> phy ;
122- u32 i , mdic = 0 ;
133+ bool success ;
123134
124135 if (offset > MAX_PHY_REG_ADDRESS ) {
125136 e_dbg ("PHY Address %d is out of range\n" , offset );
126137 return - E1000_ERR_PARAM ;
127138 }
128139
140+ retry_max = phy -> retry_enabled ? phy -> retry_count : 0 ;
141+
129142 /* Set up Op-code, Phy Address, and register offset in the MDI
130143 * Control register. The MAC will take care of interfacing with the
131144 * PHY to retrieve the desired data.
132145 */
133- mdic = ((offset << E1000_MDIC_REG_SHIFT ) |
134- (phy -> addr << E1000_MDIC_PHY_SHIFT ) |
135- (E1000_MDIC_OP_READ ));
146+ for (retry_counter = 0 ; retry_counter <= retry_max ; retry_counter ++ ) {
147+ success = true;
136148
137- ew32 (MDIC , mdic );
149+ mdic = ((offset << E1000_MDIC_REG_SHIFT ) |
150+ (phy -> addr << E1000_MDIC_PHY_SHIFT ) |
151+ (E1000_MDIC_OP_READ ));
138152
139- /* Poll the ready bit to see if the MDI read completed
140- * Increasing the time out as testing showed failures with
141- * the lower time out
142- */
143- for (i = 0 ; i < (E1000_GEN_POLL_TIMEOUT * 3 ); i ++ ) {
144- udelay (50 );
145- mdic = er32 (MDIC );
146- if (mdic & E1000_MDIC_READY )
147- break ;
148- }
149- if (!(mdic & E1000_MDIC_READY )) {
150- e_dbg ("MDI Read PHY Reg Address %d did not complete\n" , offset );
151- return - E1000_ERR_PHY ;
152- }
153- if (mdic & E1000_MDIC_ERROR ) {
154- e_dbg ("MDI Read PHY Reg Address %d Error\n" , offset );
155- return - E1000_ERR_PHY ;
156- }
157- if (FIELD_GET (E1000_MDIC_REG_MASK , mdic ) != offset ) {
158- e_dbg ("MDI Read offset error - requested %d, returned %d\n" ,
159- offset , FIELD_GET (E1000_MDIC_REG_MASK , mdic ));
160- return - E1000_ERR_PHY ;
153+ ew32 (MDIC , mdic );
154+
155+ /* Poll the ready bit to see if the MDI read completed
156+ * Increasing the time out as testing showed failures with
157+ * the lower time out
158+ */
159+ for (i = 0 ; i < (E1000_GEN_POLL_TIMEOUT * 3 ); i ++ ) {
160+ usleep_range (50 , 60 );
161+ mdic = er32 (MDIC );
162+ if (mdic & E1000_MDIC_READY )
163+ break ;
164+ }
165+ if (!(mdic & E1000_MDIC_READY )) {
166+ e_dbg ("MDI Read PHY Reg Address %d did not complete\n" ,
167+ offset );
168+ success = false;
169+ }
170+ if (mdic & E1000_MDIC_ERROR ) {
171+ e_dbg ("MDI Read PHY Reg Address %d Error\n" , offset );
172+ success = false;
173+ }
174+ if (FIELD_GET (E1000_MDIC_REG_MASK , mdic ) != offset ) {
175+ e_dbg ("MDI Read offset error - requested %d, returned %d\n" ,
176+ offset , FIELD_GET (E1000_MDIC_REG_MASK , mdic ));
177+ success = false;
178+ }
179+
180+ /* Allow some time after each MDIC transaction to avoid
181+ * reading duplicate data in the next MDIC transaction.
182+ */
183+ if (hw -> mac .type == e1000_pch2lan )
184+ usleep_range (100 , 150 );
185+
186+ if (success ) {
187+ * data = (u16 )mdic ;
188+ return 0 ;
189+ }
190+
191+ if (retry_counter != retry_max ) {
192+ e_dbg ("Perform retry on PHY transaction...\n" );
193+ mdelay (10 );
194+ }
161195 }
162- * data = (u16 )mdic ;
163196
164- /* Allow some time after each MDIC transaction to avoid
165- * reading duplicate data in the next MDIC transaction.
166- */
167- if (hw -> mac .type == e1000_pch2lan )
168- udelay (100 );
169- return 0 ;
197+ return - E1000_ERR_PHY ;
170198}
171199
172200/**
@@ -179,56 +207,72 @@ s32 e1000e_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
179207 **/
180208s32 e1000e_write_phy_reg_mdic (struct e1000_hw * hw , u32 offset , u16 data )
181209{
210+ u32 i , mdic = 0 , retry_counter , retry_max ;
182211 struct e1000_phy_info * phy = & hw -> phy ;
183- u32 i , mdic = 0 ;
212+ bool success ;
184213
185214 if (offset > MAX_PHY_REG_ADDRESS ) {
186215 e_dbg ("PHY Address %d is out of range\n" , offset );
187216 return - E1000_ERR_PARAM ;
188217 }
189218
219+ retry_max = phy -> retry_enabled ? phy -> retry_count : 0 ;
220+
190221 /* Set up Op-code, Phy Address, and register offset in the MDI
191222 * Control register. The MAC will take care of interfacing with the
192223 * PHY to retrieve the desired data.
193224 */
194- mdic = (((u32 )data ) |
195- (offset << E1000_MDIC_REG_SHIFT ) |
196- (phy -> addr << E1000_MDIC_PHY_SHIFT ) |
197- (E1000_MDIC_OP_WRITE ));
225+ for (retry_counter = 0 ; retry_counter <= retry_max ; retry_counter ++ ) {
226+ success = true;
198227
199- ew32 (MDIC , mdic );
228+ mdic = (((u32 )data ) |
229+ (offset << E1000_MDIC_REG_SHIFT ) |
230+ (phy -> addr << E1000_MDIC_PHY_SHIFT ) |
231+ (E1000_MDIC_OP_WRITE ));
200232
201- /* Poll the ready bit to see if the MDI read completed
202- * Increasing the time out as testing showed failures with
203- * the lower time out
204- */
205- for (i = 0 ; i < (E1000_GEN_POLL_TIMEOUT * 3 ); i ++ ) {
206- udelay (50 );
207- mdic = er32 (MDIC );
208- if (mdic & E1000_MDIC_READY )
209- break ;
210- }
211- if (!(mdic & E1000_MDIC_READY )) {
212- e_dbg ("MDI Write PHY Reg Address %d did not complete\n" , offset );
213- return - E1000_ERR_PHY ;
214- }
215- if (mdic & E1000_MDIC_ERROR ) {
216- e_dbg ("MDI Write PHY Red Address %d Error\n" , offset );
217- return - E1000_ERR_PHY ;
218- }
219- if (FIELD_GET (E1000_MDIC_REG_MASK , mdic ) != offset ) {
220- e_dbg ("MDI Write offset error - requested %d, returned %d\n" ,
221- offset , FIELD_GET (E1000_MDIC_REG_MASK , mdic ));
222- return - E1000_ERR_PHY ;
223- }
233+ ew32 (MDIC , mdic );
224234
225- /* Allow some time after each MDIC transaction to avoid
226- * reading duplicate data in the next MDIC transaction.
227- */
228- if (hw -> mac .type == e1000_pch2lan )
229- udelay (100 );
235+ /* Poll the ready bit to see if the MDI read completed
236+ * Increasing the time out as testing showed failures with
237+ * the lower time out
238+ */
239+ for (i = 0 ; i < (E1000_GEN_POLL_TIMEOUT * 3 ); i ++ ) {
240+ usleep_range (50 , 60 );
241+ mdic = er32 (MDIC );
242+ if (mdic & E1000_MDIC_READY )
243+ break ;
244+ }
245+ if (!(mdic & E1000_MDIC_READY )) {
246+ e_dbg ("MDI Write PHY Reg Address %d did not complete\n" ,
247+ offset );
248+ success = false;
249+ }
250+ if (mdic & E1000_MDIC_ERROR ) {
251+ e_dbg ("MDI Write PHY Reg Address %d Error\n" , offset );
252+ success = false;
253+ }
254+ if (FIELD_GET (E1000_MDIC_REG_MASK , mdic ) != offset ) {
255+ e_dbg ("MDI Write offset error - requested %d, returned %d\n" ,
256+ offset , FIELD_GET (E1000_MDIC_REG_MASK , mdic ));
257+ success = false;
258+ }
230259
231- return 0 ;
260+ /* Allow some time after each MDIC transaction to avoid
261+ * reading duplicate data in the next MDIC transaction.
262+ */
263+ if (hw -> mac .type == e1000_pch2lan )
264+ usleep_range (100 , 150 );
265+
266+ if (success )
267+ return 0 ;
268+
269+ if (retry_counter != retry_max ) {
270+ e_dbg ("Perform retry on PHY transaction...\n" );
271+ mdelay (10 );
272+ }
273+ }
274+
275+ return - E1000_ERR_PHY ;
232276}
233277
234278/**
0 commit comments