MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pcmd_eeprom_callback

Function pcmd_eeprom_callback

dpdk/examples/ethtool/ethtool-app/ethapp.c:260–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258
259
260static void
261pcmd_eeprom_callback(void *ptr_params,
262 __rte_unused struct cmdline *ctx,
263 __rte_unused void *ptr_data)
264{
265 struct pcmd_intstr_params *params = ptr_params;
266 struct ethtool_eeprom info_eeprom;
267 int len_eeprom;
268 int pos_eeprom;
269 int stat;
270 unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE];
271 FILE *fp_eeprom;
272
273 if (!rte_eth_dev_is_valid_port(params->port)) {
274 printf("Error: Invalid port number %i\n", params->port);
275 return;
276 }
277 len_eeprom = rte_ethtool_get_eeprom_len(params->port);
278 if (len_eeprom > 0) {
279 fp_eeprom = fopen(params->opt, "wb");
280 if (fp_eeprom == NULL) {
281 printf("Error opening '%s' for writing\n",
282 params->opt);
283 return;
284 }
285 printf("Total EEPROM length: %i bytes\n", len_eeprom);
286 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
287 for (pos_eeprom = 0;
288 pos_eeprom < len_eeprom;
289 pos_eeprom += EEPROM_DUMP_CHUNKSIZE) {
290 info_eeprom.offset = pos_eeprom;
291 if (pos_eeprom + EEPROM_DUMP_CHUNKSIZE > len_eeprom)
292 info_eeprom.len = len_eeprom - pos_eeprom;
293 else
294 info_eeprom.len = EEPROM_DUMP_CHUNKSIZE;
295 stat = rte_ethtool_get_eeprom(
296 params->port, &info_eeprom, bytes_eeprom
297 );
298 if (stat != 0) {
299 printf("EEPROM read error %i\n", stat);
300 break;
301 }
302 if (fwrite(bytes_eeprom,
303 1, info_eeprom.len,
304 fp_eeprom) != info_eeprom.len) {
305 printf("Error writing '%s'\n", params->opt);
306 break;
307 }
308 }
309 fclose(fp_eeprom);
310 } else if (len_eeprom == 0)
311 printf("Port %i: Device does not have EEPROM\n", params->port);
312 else if (len_eeprom == -ENOTSUP)
313 printf("Port %i: Operation not supported\n", params->port);
314 else
315 printf("Port %i: Error getting EEPROM\n", params->port);
316}
317

Callers

nothing calls this directly

Calls 4

rte_ethtool_get_eepromFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected