Skip to content

Commit e961b67

Browse files
jacob-kellerJeff Kirsher
authored andcommitted
ice: add board identifier info to devlink .info_get
Export a unique board identifier using "board.id" for devlink's .info_get command. Obtain this by reading the NVM for the PBA identification string. Signed-off-by: Jacob Keller <[email protected]> Reviewed-by: Jesse Brandeburg <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent ff2e5c7 commit e961b67

File tree

7 files changed

+150
-70
lines changed

7 files changed

+150
-70
lines changed

Documentation/networking/devlink/ice.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ The ``ice`` driver reports the following versions
1919
- Type
2020
- Example
2121
- Description
22+
* - ``board.id``
23+
- fixed
24+
- K65390-000
25+
- The Product Board Assembly (PBA) identifier of the board.
2226
* - ``fw.mgmt``
2327
- running
2428
- 2.1.7

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -934,72 +934,6 @@ enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
934934
return ice_check_reset(hw);
935935
}
936936

937-
/**
938-
* ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA
939-
* @hw: pointer to hardware structure
940-
* @module_tlv: pointer to module TLV to return
941-
* @module_tlv_len: pointer to module TLV length to return
942-
* @module_type: module type requested
943-
*
944-
* Finds the requested sub module TLV type from the Preserved Field
945-
* Area (PFA) and returns the TLV pointer and length. The caller can
946-
* use these to read the variable length TLV value.
947-
*/
948-
enum ice_status
949-
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
950-
u16 module_type)
951-
{
952-
enum ice_status status;
953-
u16 pfa_len, pfa_ptr;
954-
u16 next_tlv;
955-
956-
status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr);
957-
if (status) {
958-
ice_debug(hw, ICE_DBG_INIT, "Preserved Field Array pointer.\n");
959-
return status;
960-
}
961-
status = ice_read_sr_word(hw, pfa_ptr, &pfa_len);
962-
if (status) {
963-
ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n");
964-
return status;
965-
}
966-
/* Starting with first TLV after PFA length, iterate through the list
967-
* of TLVs to find the requested one.
968-
*/
969-
next_tlv = pfa_ptr + 1;
970-
while (next_tlv < pfa_ptr + pfa_len) {
971-
u16 tlv_sub_module_type;
972-
u16 tlv_len;
973-
974-
/* Read TLV type */
975-
status = ice_read_sr_word(hw, next_tlv, &tlv_sub_module_type);
976-
if (status) {
977-
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV type.\n");
978-
break;
979-
}
980-
/* Read TLV length */
981-
status = ice_read_sr_word(hw, next_tlv + 1, &tlv_len);
982-
if (status) {
983-
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV length.\n");
984-
break;
985-
}
986-
if (tlv_sub_module_type == module_type) {
987-
if (tlv_len) {
988-
*module_tlv = next_tlv;
989-
*module_tlv_len = tlv_len;
990-
return 0;
991-
}
992-
return ICE_ERR_INVAL_SIZE;
993-
}
994-
/* Check next TLV, i.e. current TLV pointer + length + 2 words
995-
* (for current TLV's type and length)
996-
*/
997-
next_tlv = next_tlv + tlv_len + 2;
998-
}
999-
/* Module does not exist */
1000-
return ICE_ERR_DOES_NOT_EXIST;
1001-
}
1002-
1003937
/**
1004938
* ice_copy_rxq_ctx_to_hw
1005939
* @hw: pointer to the hardware structure

drivers/net/ethernet/intel/ice/ice_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw);
1515

1616
enum ice_status ice_init_hw(struct ice_hw *hw);
1717
void ice_deinit_hw(struct ice_hw *hw);
18-
enum ice_status
19-
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
20-
u16 module_type);
2118
enum ice_status ice_check_reset(struct ice_hw *hw);
2219
enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req);
2320
enum ice_status ice_create_all_ctrlq(struct ice_hw *hw);

drivers/net/ethernet/intel/ice/ice_devlink.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ static int ice_info_get_dsn(struct ice_pf *pf, char *buf, size_t len)
1919
return 0;
2020
}
2121

22+
static int ice_info_pba(struct ice_pf *pf, char *buf, size_t len)
23+
{
24+
struct ice_hw *hw = &pf->hw;
25+
enum ice_status status;
26+
27+
status = ice_read_pba_string(hw, (u8 *)buf, len);
28+
if (status)
29+
return -EIO;
30+
31+
return 0;
32+
}
33+
2234
static int ice_info_fw_mgmt(struct ice_pf *pf, char *buf, size_t len)
2335
{
2436
struct ice_hw *hw = &pf->hw;
@@ -93,6 +105,7 @@ static int ice_info_ddp_pkg_version(struct ice_pf *pf, char *buf, size_t len)
93105
return 0;
94106
}
95107

108+
#define fixed(key, getter) { ICE_VERSION_FIXED, key, getter }
96109
#define running(key, getter) { ICE_VERSION_RUNNING, key, getter }
97110

98111
enum ice_version_type {
@@ -106,6 +119,7 @@ static const struct ice_devlink_version {
106119
const char *key;
107120
int (*getter)(struct ice_pf *pf, char *buf, size_t len);
108121
} ice_devlink_versions[] = {
122+
fixed(DEVLINK_INFO_VERSION_GENERIC_BOARD_ID, ice_info_pba),
109123
running(DEVLINK_INFO_VERSION_GENERIC_FW_MGMT, ice_info_fw_mgmt),
110124
running("fw.mgmt.api", ice_info_fw_api),
111125
running("fw.mgmt.build", ice_info_fw_build),
@@ -125,7 +139,7 @@ static const struct ice_devlink_version {
125139
* Callback for the devlink .info_get operation. Reports information about the
126140
* device.
127141
*
128-
* @returns zero on success or an error code on failure.
142+
* Return: zero on success or an error code on failure.
129143
*/
130144
static int ice_devlink_info_get(struct devlink *devlink,
131145
struct devlink_info_req *req,

drivers/net/ethernet/intel/ice/ice_nvm.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,131 @@ enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data)
185185
return status;
186186
}
187187

188+
/**
189+
* ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA
190+
* @hw: pointer to hardware structure
191+
* @module_tlv: pointer to module TLV to return
192+
* @module_tlv_len: pointer to module TLV length to return
193+
* @module_type: module type requested
194+
*
195+
* Finds the requested sub module TLV type from the Preserved Field
196+
* Area (PFA) and returns the TLV pointer and length. The caller can
197+
* use these to read the variable length TLV value.
198+
*/
199+
enum ice_status
200+
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
201+
u16 module_type)
202+
{
203+
enum ice_status status;
204+
u16 pfa_len, pfa_ptr;
205+
u16 next_tlv;
206+
207+
status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr);
208+
if (status) {
209+
ice_debug(hw, ICE_DBG_INIT, "Preserved Field Array pointer.\n");
210+
return status;
211+
}
212+
status = ice_read_sr_word(hw, pfa_ptr, &pfa_len);
213+
if (status) {
214+
ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n");
215+
return status;
216+
}
217+
/* Starting with first TLV after PFA length, iterate through the list
218+
* of TLVs to find the requested one.
219+
*/
220+
next_tlv = pfa_ptr + 1;
221+
while (next_tlv < pfa_ptr + pfa_len) {
222+
u16 tlv_sub_module_type;
223+
u16 tlv_len;
224+
225+
/* Read TLV type */
226+
status = ice_read_sr_word(hw, next_tlv, &tlv_sub_module_type);
227+
if (status) {
228+
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV type.\n");
229+
break;
230+
}
231+
/* Read TLV length */
232+
status = ice_read_sr_word(hw, next_tlv + 1, &tlv_len);
233+
if (status) {
234+
ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV length.\n");
235+
break;
236+
}
237+
if (tlv_sub_module_type == module_type) {
238+
if (tlv_len) {
239+
*module_tlv = next_tlv;
240+
*module_tlv_len = tlv_len;
241+
return 0;
242+
}
243+
return ICE_ERR_INVAL_SIZE;
244+
}
245+
/* Check next TLV, i.e. current TLV pointer + length + 2 words
246+
* (for current TLV's type and length)
247+
*/
248+
next_tlv = next_tlv + tlv_len + 2;
249+
}
250+
/* Module does not exist */
251+
return ICE_ERR_DOES_NOT_EXIST;
252+
}
253+
254+
/**
255+
* ice_read_pba_string - Reads part number string from NVM
256+
* @hw: pointer to hardware structure
257+
* @pba_num: stores the part number string from the NVM
258+
* @pba_num_size: part number string buffer length
259+
*
260+
* Reads the part number string from the NVM.
261+
*/
262+
enum ice_status
263+
ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size)
264+
{
265+
u16 pba_tlv, pba_tlv_len;
266+
enum ice_status status;
267+
u16 pba_word, pba_size;
268+
u16 i;
269+
270+
status = ice_get_pfa_module_tlv(hw, &pba_tlv, &pba_tlv_len,
271+
ICE_SR_PBA_BLOCK_PTR);
272+
if (status) {
273+
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block TLV.\n");
274+
return status;
275+
}
276+
277+
/* pba_size is the next word */
278+
status = ice_read_sr_word(hw, (pba_tlv + 2), &pba_size);
279+
if (status) {
280+
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Section size.\n");
281+
return status;
282+
}
283+
284+
if (pba_tlv_len < pba_size) {
285+
ice_debug(hw, ICE_DBG_INIT, "Invalid PBA Block TLV size.\n");
286+
return ICE_ERR_INVAL_SIZE;
287+
}
288+
289+
/* Subtract one to get PBA word count (PBA Size word is included in
290+
* total size)
291+
*/
292+
pba_size--;
293+
if (pba_num_size < (((u32)pba_size * 2) + 1)) {
294+
ice_debug(hw, ICE_DBG_INIT, "Buffer too small for PBA data.\n");
295+
return ICE_ERR_PARAM;
296+
}
297+
298+
for (i = 0; i < pba_size; i++) {
299+
status = ice_read_sr_word(hw, (pba_tlv + 2 + 1) + i, &pba_word);
300+
if (status) {
301+
ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block word %d.\n", i);
302+
return status;
303+
}
304+
305+
pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
306+
pba_num[(i * 2) + 1] = pba_word & 0xFF;
307+
}
308+
pba_num[(pba_size * 2)] = '\0';
309+
310+
return status;
311+
}
312+
188313
/**
189314
* ice_get_orom_ver_info - Read Option ROM version information
190315
* @hw: pointer to the HW struct

drivers/net/ethernet/intel/ice/ice_nvm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ void ice_release_nvm(struct ice_hw *hw);
1010
enum ice_status
1111
ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data,
1212
bool read_shadow_ram);
13+
enum ice_status
14+
ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
15+
u16 module_type);
16+
enum ice_status
17+
ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size);
1318
enum ice_status ice_init_nvm(struct ice_hw *hw);
1419
enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data);
1520
#endif /* _ICE_NVM_H_ */

drivers/net/ethernet/intel/ice/ice_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ struct ice_hw_port_stats {
636636
/* Checksum and Shadow RAM pointers */
637637
#define ICE_SR_BOOT_CFG_PTR 0x132
638638
#define ICE_NVM_OROM_VER_OFF 0x02
639+
#define ICE_SR_PBA_BLOCK_PTR 0x16
639640
#define ICE_SR_NVM_DEV_STARTER_VER 0x18
640641
#define ICE_SR_NVM_EETRACK_LO 0x2D
641642
#define ICE_SR_NVM_EETRACK_HI 0x2E

0 commit comments

Comments
 (0)