ipmi_mc.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /*
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Sun Microsystems, Inc. or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * This software is provided "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <stdio.h>
  35. #include <time.h>
  36. #include <ipmitool/helper.h>
  37. #include <ipmitool/log.h>
  38. #include <ipmitool/bswap.h>
  39. #include <ipmitool/ipmi.h>
  40. #include <ipmitool/ipmi_intf.h>
  41. #include <ipmitool/ipmi_mc.h>
  42. #include <ipmitool/ipmi_strings.h>
  43. extern int verbose;
  44. static int ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv,
  45. int is_set);
  46. static void printf_sysinfo_usage(int full_help);
  47. /* ipmi_mc_reset - attempt to reset an MC
  48. *
  49. * @intf: ipmi interface
  50. * @cmd: reset command to send
  51. * BMC_WARM_RESET or
  52. * BMC_COLD_RESET
  53. *
  54. * returns 0 on success
  55. * returns -1 on error
  56. */
  57. static int
  58. ipmi_mc_reset(struct ipmi_intf * intf, int cmd)
  59. {
  60. struct ipmi_rs * rsp;
  61. struct ipmi_rq req;
  62. if( !intf->opened )
  63. intf->open(intf);
  64. memset(&req, 0, sizeof(req));
  65. req.msg.netfn = IPMI_NETFN_APP;
  66. req.msg.cmd = cmd;
  67. req.msg.data_len = 0;
  68. if (cmd == BMC_COLD_RESET)
  69. intf->noanswer = 1;
  70. rsp = intf->sendrecv(intf, &req);
  71. if (cmd == BMC_COLD_RESET)
  72. intf->abort = 1;
  73. if (cmd == BMC_COLD_RESET && rsp == NULL) {
  74. /* This is expected. See 20.2 Cold Reset Command, p.243, IPMIv2.0 rev1.0 */
  75. } else if (rsp == NULL) {
  76. lprintf(LOG_ERR, "MC reset command failed.");
  77. return (-1);
  78. } else if (rsp->ccode > 0) {
  79. lprintf(LOG_ERR, "MC reset command failed: %s",
  80. val2str(rsp->ccode, completion_code_vals));
  81. return (-1);
  82. }
  83. printf("Sent %s reset command to MC\n",
  84. (cmd == BMC_WARM_RESET) ? "warm" : "cold");
  85. return 0;
  86. }
  87. #ifdef HAVE_PRAGMA_PACK
  88. #pragma pack(1)
  89. #endif
  90. struct bmc_enables_data {
  91. #if WORDS_BIGENDIAN
  92. uint8_t oem2 : 1;
  93. uint8_t oem1 : 1;
  94. uint8_t oem0 : 1;
  95. uint8_t __reserved : 1;
  96. uint8_t system_event_log : 1;
  97. uint8_t event_msgbuf : 1;
  98. uint8_t event_msgbuf_intr : 1;
  99. uint8_t receive_msg_intr : 1;
  100. #else
  101. uint8_t receive_msg_intr : 1;
  102. uint8_t event_msgbuf_intr : 1;
  103. uint8_t event_msgbuf : 1;
  104. uint8_t system_event_log : 1;
  105. uint8_t __reserved : 1;
  106. uint8_t oem0 : 1;
  107. uint8_t oem1 : 1;
  108. uint8_t oem2 : 1;
  109. #endif
  110. } ATTRIBUTE_PACKING;
  111. #ifdef HAVE_PRAGMA_PACK
  112. #pragma pack(0)
  113. #endif
  114. struct bitfield_data {
  115. const char * name;
  116. const char * desc;
  117. uint32_t mask;
  118. } mc_enables_bf[] = {
  119. {
  120. .name = "recv_msg_intr",
  121. .desc = "Receive Message Queue Interrupt",
  122. .mask = 1<<0,
  123. },
  124. {
  125. .name = "event_msg_intr",
  126. .desc = "Event Message Buffer Full Interrupt",
  127. .mask = 1<<1,
  128. },
  129. {
  130. .name = "event_msg",
  131. .desc = "Event Message Buffer",
  132. .mask = 1<<2,
  133. },
  134. {
  135. .name = "system_event_log",
  136. .desc = "System Event Logging",
  137. .mask = 1<<3,
  138. },
  139. {
  140. .name = "oem0",
  141. .desc = "OEM 0",
  142. .mask = 1<<5,
  143. },
  144. {
  145. .name = "oem1",
  146. .desc = "OEM 1",
  147. .mask = 1<<6,
  148. },
  149. {
  150. .name = "oem2",
  151. .desc = "OEM 2",
  152. .mask = 1<<7,
  153. },
  154. { NULL },
  155. };
  156. static void
  157. printf_mc_reset_usage(void)
  158. {
  159. lprintf(LOG_NOTICE, "usage: mc reset <warm|cold>");
  160. } /* printf_mc_reset_usage(void) */
  161. static void
  162. printf_mc_usage(void)
  163. {
  164. struct bitfield_data * bf;
  165. lprintf(LOG_NOTICE, "MC Commands:");
  166. lprintf(LOG_NOTICE, " reset <warm|cold>");
  167. lprintf(LOG_NOTICE, " guid");
  168. lprintf(LOG_NOTICE, " info");
  169. lprintf(LOG_NOTICE, " watchdog <get|reset|off>");
  170. lprintf(LOG_NOTICE, " selftest");
  171. lprintf(LOG_NOTICE, " getenables");
  172. lprintf(LOG_NOTICE, " setenables <option=on|off> ...");
  173. for (bf = mc_enables_bf; bf->name != NULL; bf++) {
  174. lprintf(LOG_NOTICE, " %-20s %s", bf->name, bf->desc);
  175. }
  176. printf_sysinfo_usage(0);
  177. }
  178. static void
  179. printf_sysinfo_usage(int full_help)
  180. {
  181. if (full_help != 0)
  182. lprintf(LOG_NOTICE, "usage:");
  183. lprintf(LOG_NOTICE, " getsysinfo <argument>");
  184. if (full_help != 0) {
  185. lprintf(LOG_NOTICE,
  186. " Retrieves system info from BMC for given argument");
  187. }
  188. lprintf(LOG_NOTICE, " setsysinfo <argument> <string>");
  189. if (full_help != 0) {
  190. lprintf(LOG_NOTICE,
  191. " Stores system info string for given argument to BMC");
  192. lprintf(LOG_NOTICE, "");
  193. lprintf(LOG_NOTICE, " Valid arguments are:");
  194. }
  195. lprintf(LOG_NOTICE,
  196. " system_fw_version System firmware (e.g. BIOS) version");
  197. lprintf(LOG_NOTICE,
  198. " primary_os_name Primary operating system name");
  199. lprintf(LOG_NOTICE, " os_name Operating system name");
  200. lprintf(LOG_NOTICE,
  201. " system_name System Name of server(vendor dependent)");
  202. lprintf(LOG_NOTICE,
  203. " delloem_os_version Running version of operating system");
  204. lprintf(LOG_NOTICE, " delloem_url URL of BMC webserver");
  205. lprintf(LOG_NOTICE, "");
  206. }
  207. static void
  208. print_watchdog_usage(void)
  209. {
  210. lprintf(LOG_NOTICE, "usage: watchdog <command>:");
  211. lprintf(LOG_NOTICE, " get : Get Current Watchdog settings");
  212. lprintf(LOG_NOTICE, " reset : Restart Watchdog timer based on most recent settings");
  213. lprintf(LOG_NOTICE, " off : Shut off a running Watchdog timer");
  214. }
  215. /* ipmi_mc_get_enables - print out MC enables
  216. *
  217. * @intf: ipmi inteface
  218. *
  219. * returns 0 on success
  220. * returns -1 on error
  221. */
  222. static int
  223. ipmi_mc_get_enables(struct ipmi_intf * intf)
  224. {
  225. struct ipmi_rs * rsp;
  226. struct ipmi_rq req;
  227. struct bitfield_data * bf;
  228. memset(&req, 0, sizeof(req));
  229. req.msg.netfn = IPMI_NETFN_APP;
  230. req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
  231. rsp = intf->sendrecv(intf, &req);
  232. if (rsp == NULL) {
  233. lprintf(LOG_ERR, "Get Global Enables command failed");
  234. return -1;
  235. }
  236. if (rsp->ccode > 0) {
  237. lprintf(LOG_ERR, "Get Global Enables command failed: %s",
  238. val2str(rsp->ccode, completion_code_vals));
  239. return -1;
  240. }
  241. for (bf = mc_enables_bf; bf->name != NULL; bf++) {
  242. printf("%-40s : %sabled\n", bf->desc,
  243. rsp->data[0] & bf->mask ? "en" : "dis");
  244. }
  245. return 0;
  246. }
  247. /* ipmi_mc_set_enables - set MC enable flags
  248. *
  249. * @intf: ipmi inteface
  250. * @argc: argument count
  251. * @argv: argument list
  252. *
  253. * returns 0 on success
  254. * returns -1 on error
  255. */
  256. static int
  257. ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
  258. {
  259. struct ipmi_rs * rsp;
  260. struct ipmi_rq req;
  261. struct bitfield_data * bf;
  262. uint8_t en;
  263. int i;
  264. if (argc < 1) {
  265. printf_mc_usage();
  266. return (-1);
  267. }
  268. else if (strncmp(argv[0], "help", 4) == 0) {
  269. printf_mc_usage();
  270. return 0;
  271. }
  272. memset(&req, 0, sizeof(req));
  273. req.msg.netfn = IPMI_NETFN_APP;
  274. req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
  275. rsp = intf->sendrecv(intf, &req);
  276. if (rsp == NULL) {
  277. lprintf(LOG_ERR, "Get Global Enables command failed");
  278. return -1;
  279. }
  280. if (rsp->ccode > 0) {
  281. lprintf(LOG_ERR, "Get Global Enables command failed: %s",
  282. val2str(rsp->ccode, completion_code_vals));
  283. return -1;
  284. }
  285. en = rsp->data[0];
  286. for (i = 0; i < argc; i++) {
  287. for (bf = mc_enables_bf; bf->name != NULL; bf++) {
  288. int nl = strlen(bf->name);
  289. if (strncmp(argv[i], bf->name, nl) != 0)
  290. continue;
  291. if (strncmp(argv[i]+nl+1, "off", 3) == 0) {
  292. printf("Disabling %s\n", bf->desc);
  293. en &= ~bf->mask;
  294. }
  295. else if (strncmp(argv[i]+nl+1, "on", 2) == 0) {
  296. printf("Enabling %s\n", bf->desc);
  297. en |= bf->mask;
  298. }
  299. else {
  300. lprintf(LOG_ERR, "Unrecognized option: %s", argv[i]);
  301. }
  302. }
  303. }
  304. if (en == rsp->data[0]) {
  305. printf("\nNothing to change...\n");
  306. ipmi_mc_get_enables(intf);
  307. return 0;
  308. }
  309. req.msg.cmd = BMC_SET_GLOBAL_ENABLES;
  310. req.msg.data = &en;
  311. req.msg.data_len = 1;
  312. rsp = intf->sendrecv(intf, &req);
  313. if (rsp == NULL) {
  314. lprintf(LOG_ERR, "Set Global Enables command failed");
  315. return -1;
  316. }
  317. else if (rsp->ccode > 0) {
  318. lprintf(LOG_ERR, "Set Global Enables command failed: %s",
  319. val2str(rsp->ccode, completion_code_vals));
  320. return -1;
  321. }
  322. printf("\nVerifying...\n");
  323. ipmi_mc_get_enables(intf);
  324. return 0;
  325. }
  326. /* IPM Device, Get Device ID Command - Additional Device Support */
  327. const char *ipm_dev_adtl_dev_support[8] = {
  328. "Sensor Device", /* bit 0 */
  329. "SDR Repository Device", /* bit 1 */
  330. "SEL Device", /* bit 2 */
  331. "FRU Inventory Device", /* ... */
  332. "IPMB Event Receiver",
  333. "IPMB Event Generator",
  334. "Bridge",
  335. "Chassis Device" /* bit 7 */
  336. };
  337. /* ipmi_mc_get_deviceid - print information about this MC
  338. *
  339. * @intf: ipmi interface
  340. *
  341. * returns 0 on success
  342. * returns -1 on error
  343. */
  344. static int
  345. ipmi_mc_get_deviceid(struct ipmi_intf * intf)
  346. {
  347. struct ipmi_rs * rsp;
  348. struct ipmi_rq req;
  349. struct ipm_devid_rsp *devid;
  350. int i;
  351. const char *product=NULL;
  352. memset(&req, 0, sizeof(req));
  353. req.msg.netfn = IPMI_NETFN_APP;
  354. req.msg.cmd = BMC_GET_DEVICE_ID;
  355. req.msg.data_len = 0;
  356. rsp = intf->sendrecv(intf, &req);
  357. if (rsp == NULL) {
  358. lprintf(LOG_ERR, "Get Device ID command failed");
  359. return -1;
  360. }
  361. if (rsp->ccode > 0) {
  362. lprintf(LOG_ERR, "Get Device ID command failed: %s",
  363. val2str(rsp->ccode, completion_code_vals));
  364. return -1;
  365. }
  366. devid = (struct ipm_devid_rsp *) rsp->data;
  367. printf("Device ID : %i\n",
  368. devid->device_id);
  369. printf("Device Revision : %i\n",
  370. devid->device_revision & IPM_DEV_DEVICE_ID_REV_MASK);
  371. printf("Firmware Revision : %u.%02x\n",
  372. devid->fw_rev1 & IPM_DEV_FWREV1_MAJOR_MASK,
  373. devid->fw_rev2);
  374. printf("IPMI Version : %x.%x\n",
  375. IPM_DEV_IPMI_VERSION_MAJOR(devid->ipmi_version),
  376. IPM_DEV_IPMI_VERSION_MINOR(devid->ipmi_version));
  377. printf("Manufacturer ID : %lu\n",
  378. (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id));
  379. printf("Manufacturer Name : %s\n",
  380. val2str( (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
  381. ipmi_oem_info) );
  382. printf("Product ID : %u (0x%02x%02x)\n",
  383. buf2short((uint8_t *)(devid->product_id)),
  384. devid->product_id[1], devid->product_id[0]);
  385. product=oemval2str(IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
  386. (devid->product_id[1]<<8)+devid->product_id[0],
  387. ipmi_oem_product_info);
  388. if (product!=NULL) {
  389. printf("Product Name : %s\n", product);
  390. }
  391. printf("Device Available : %s\n",
  392. (devid->fw_rev1 & IPM_DEV_FWREV1_AVAIL_MASK) ?
  393. "no" : "yes");
  394. printf("Provides Device SDRs : %s\n",
  395. (devid->device_revision & IPM_DEV_DEVICE_ID_SDR_MASK) ?
  396. "yes" : "no");
  397. printf("Additional Device Support :\n");
  398. for (i = 0; i < IPM_DEV_ADTL_SUPPORT_BITS; i++) {
  399. if (devid->adtl_device_support & (1 << i)) {
  400. printf(" %s\n", ipm_dev_adtl_dev_support[i]);
  401. }
  402. }
  403. if (rsp->data_len == sizeof(*devid)) {
  404. printf("Aux Firmware Rev Info : \n");
  405. /* These values could be looked-up by vendor if documented,
  406. * so we put them on individual lines for better treatment later
  407. */
  408. printf(" 0x%02x\n 0x%02x\n 0x%02x\n 0x%02x\n",
  409. devid->aux_fw_rev[0],
  410. devid->aux_fw_rev[1],
  411. devid->aux_fw_rev[2],
  412. devid->aux_fw_rev[3]);
  413. }
  414. return 0;
  415. }
  416. /* _ipmi_mc_get_guid - Gets BMCs GUID according to (22.14)
  417. *
  418. * @intf: ipmi interface
  419. * @guid: pointer where to store BMC GUID
  420. *
  421. * returns - negative number means error, positive is a ccode.
  422. */
  423. int
  424. _ipmi_mc_get_guid(struct ipmi_intf *intf, struct ipmi_guid_t *guid)
  425. {
  426. struct ipmi_rs *rsp;
  427. struct ipmi_rq req;
  428. if (guid == NULL) {
  429. return (-3);
  430. }
  431. memset(guid, 0, sizeof(struct ipmi_guid_t));
  432. memset(&req, 0, sizeof(req));
  433. req.msg.netfn = IPMI_NETFN_APP;
  434. req.msg.cmd = BMC_GET_GUID;
  435. rsp = intf->sendrecv(intf, &req);
  436. if (rsp == NULL) {
  437. return (-1);
  438. } else if (rsp->ccode > 0) {
  439. return rsp->ccode;
  440. } else if (rsp->data_len != 16
  441. || rsp->data_len != sizeof(struct ipmi_guid_t)) {
  442. return (-2);
  443. }
  444. memcpy(guid, &rsp->data[0], sizeof(struct ipmi_guid_t));
  445. return 0;
  446. }
  447. /* ipmi_mc_print_guid - print-out given BMC GUID
  448. *
  449. * @guid - struct with GUID.
  450. *
  451. * returns 0
  452. */
  453. static int
  454. ipmi_mc_print_guid(struct ipmi_guid_t guid)
  455. {
  456. char tbuf[40];
  457. time_t s;
  458. memset(tbuf, 0, 40);
  459. /* Kipp - changed order of last field (node) to follow specification */
  460. printf("System GUID : %08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x\n",
  461. guid.time_low, guid.time_mid, guid.time_hi_and_version,
  462. guid.clock_seq_hi_variant << 8 | guid.clock_seq_low,
  463. guid.node[0], guid.node[1], guid.node[2],
  464. guid.node[3], guid.node[4], guid.node[5]);
  465. s = (time_t)guid.time_low; /* Kipp - removed the BSWAP_32, it was not needed here */
  466. strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&s));
  467. printf("Timestamp : %s\n", tbuf);
  468. return 0;
  469. }
  470. /* ipmi_mc_get_guid - Gets and prints-out System GUID */
  471. int
  472. ipmi_mc_get_guid(struct ipmi_intf *intf)
  473. {
  474. struct ipmi_guid_t guid;
  475. int rc;
  476. rc = _ipmi_mc_get_guid(intf, &guid);
  477. if (eval_ccode(rc) != 0) {
  478. return (-1);
  479. }
  480. rc = ipmi_mc_print_guid(guid);
  481. return rc;
  482. }
  483. /* ipmi_mc_get_selftest - returns and print selftest results
  484. *
  485. * @intf: ipmi interface
  486. */
  487. static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
  488. {
  489. int rv = 0;
  490. struct ipmi_rs * rsp;
  491. struct ipmi_rq req;
  492. struct ipm_selftest_rsp *sft_res;
  493. memset(&req, 0, sizeof(req));
  494. req.msg.netfn = IPMI_NETFN_APP;
  495. req.msg.cmd = BMC_GET_SELF_TEST;
  496. req.msg.data_len = 0;
  497. rsp = intf->sendrecv(intf, &req);
  498. if (!rsp) {
  499. lprintf(LOG_ERR, "No response from devices\n");
  500. return -1;
  501. }
  502. if (rsp->ccode) {
  503. lprintf(LOG_ERR, "Bad response: (%s)",
  504. val2str(rsp->ccode, completion_code_vals));
  505. return -1;
  506. }
  507. sft_res = (struct ipm_selftest_rsp *) rsp->data;
  508. if (sft_res->code == IPM_SFT_CODE_OK) {
  509. printf("Selftest: passed\n");
  510. rv = 0;
  511. }
  512. else if (sft_res->code == IPM_SFT_CODE_NOT_IMPLEMENTED) {
  513. printf("Selftest: not implemented\n");
  514. rv = -1;
  515. }
  516. else if (sft_res->code == IPM_SFT_CODE_DEV_CORRUPTED) {
  517. printf("Selftest: device corrupted\n");
  518. rv = -1;
  519. if (sft_res->test & IPM_SELFTEST_SEL_ERROR) {
  520. printf(" -> SEL device not accessible\n");
  521. }
  522. if (sft_res->test & IPM_SELFTEST_SDR_ERROR) {
  523. printf(" -> SDR repository not accesible\n");
  524. }
  525. if (sft_res->test & IPM_SELFTEST_FRU_ERROR) {
  526. printf("FRU device not accessible\n");
  527. }
  528. if (sft_res->test & IPM_SELFTEST_IPMB_ERROR) {
  529. printf("IPMB signal lines do not respond\n");
  530. }
  531. if (sft_res->test & IPM_SELFTEST_SDRR_EMPTY) {
  532. printf("SDR repository empty\n");
  533. }
  534. if (sft_res->test & IPM_SELFTEST_INTERNAL_USE) {
  535. printf("Internal Use Area corrupted\n");
  536. }
  537. if (sft_res->test & IPM_SELFTEST_FW_BOOTBLOCK) {
  538. printf("Controller update boot block corrupted\n");
  539. }
  540. if (sft_res->test & IPM_SELFTEST_FW_CORRUPTED) {
  541. printf("controller operational firmware corrupted\n");
  542. }
  543. }
  544. else if (sft_res->code == IPM_SFT_CODE_FATAL_ERROR) {
  545. printf("Selftest : fatal error\n");
  546. printf("Failure code : %02x\n", sft_res->test);
  547. rv = -1;
  548. }
  549. else if (sft_res->code == IPM_SFT_CODE_RESERVED) {
  550. printf("Selftest: N/A");
  551. rv = -1;
  552. }
  553. else {
  554. printf("Selftest : device specific (%02Xh)\n", sft_res->code);
  555. printf("Failure code : %02Xh\n", sft_res->test);
  556. rv = 0;
  557. }
  558. return rv;
  559. }
  560. /* ipmi_mc_get_watchdog
  561. *
  562. * @intf: ipmi interface
  563. *
  564. * returns 0 on success
  565. * returns -1 on error
  566. */
  567. const char *wdt_use_string[8] = {
  568. "Reserved",
  569. "BIOS FRB2",
  570. "BIOS/POST",
  571. "OS Load",
  572. "SMS/OS",
  573. "OEM",
  574. "Reserved",
  575. "Reserved"
  576. };
  577. const char *wdt_action_string[8] = {
  578. "No action",
  579. "Hard Reset",
  580. "Power Down",
  581. "Power Cycle",
  582. "Reserved",
  583. "Reserved",
  584. "Reserved",
  585. "Reserved"
  586. };
  587. static int
  588. ipmi_mc_get_watchdog(struct ipmi_intf * intf)
  589. {
  590. struct ipmi_rs * rsp;
  591. struct ipmi_rq req;
  592. struct ipm_get_watchdog_rsp * wdt_res;
  593. memset(&req, 0, sizeof(req));
  594. req.msg.netfn = IPMI_NETFN_APP;
  595. req.msg.cmd = BMC_GET_WATCHDOG_TIMER;
  596. req.msg.data_len = 0;
  597. rsp = intf->sendrecv(intf, &req);
  598. if (rsp == NULL) {
  599. lprintf(LOG_ERR, "Get Watchdog Timer command failed");
  600. return -1;
  601. }
  602. if (rsp->ccode) {
  603. lprintf(LOG_ERR, "Get Watchdog Timer command failed: %s",
  604. val2str(rsp->ccode, completion_code_vals));
  605. return -1;
  606. }
  607. wdt_res = (struct ipm_get_watchdog_rsp *) rsp->data;
  608. printf("Watchdog Timer Use: %s (0x%02x)\n",
  609. wdt_use_string[(wdt_res->timer_use & 0x07 )], wdt_res->timer_use);
  610. printf("Watchdog Timer Is: %s\n",
  611. wdt_res->timer_use & 0x40 ? "Started/Running" : "Stopped");
  612. printf("Watchdog Timer Actions: %s (0x%02x)\n",
  613. wdt_action_string[(wdt_res->timer_actions&0x07)], wdt_res->timer_actions);
  614. printf("Pre-timeout interval: %d seconds\n", wdt_res->pre_timeout);
  615. printf("Timer Expiration Flags: 0x%02x\n", wdt_res->timer_use_exp);
  616. printf("Initial Countdown: %i sec\n",
  617. ((wdt_res->initial_countdown_msb << 8) | wdt_res->initial_countdown_lsb)/10);
  618. printf("Present Countdown: %i sec\n",
  619. (((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10);
  620. return 0;
  621. }
  622. /* ipmi_mc_shutoff_watchdog
  623. *
  624. * @intf: ipmi interface
  625. *
  626. * returns 0 on success
  627. * returns -1 on error
  628. */
  629. static int
  630. ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
  631. {
  632. struct ipmi_rs * rsp;
  633. struct ipmi_rq req;
  634. unsigned char msg_data[6];
  635. memset(&req, 0, sizeof(req));
  636. req.msg.netfn = IPMI_NETFN_APP;
  637. req.msg.cmd = BMC_SET_WATCHDOG_TIMER;
  638. req.msg.data = msg_data;
  639. req.msg.data_len = 6;
  640. /*
  641. * The only set cmd we're allowing is to shut off the timer.
  642. * Turning on the timer should be the job of the ipmi watchdog driver.
  643. * See 'modinfo ipmi_watchdog' for more info. (NOTE: the reset
  644. * command will restart the timer if it's already been initialized.)
  645. *
  646. * Out-of-band watchdog set commands can still be sent via the raw
  647. * command interface but this is a very dangerous thing to do since
  648. * a periodic "poke"/reset over a network is unreliable. This is
  649. * not a recommended way to use the IPMI watchdog commands.
  650. */
  651. msg_data[0] = IPM_WATCHDOG_SMS_OS;
  652. msg_data[1] = IPM_WATCHDOG_NO_ACTION;
  653. msg_data[2] = 0x00; /* pretimeout interval */
  654. msg_data[3] = IPM_WATCHDOG_CLEAR_SMS_OS;
  655. msg_data[4] = 0xb8; /* countdown lsb (100 ms/count) */
  656. msg_data[5] = 0x0b; /* countdown msb - 5 mins */
  657. rsp = intf->sendrecv(intf, &req);
  658. if (rsp == NULL) {
  659. lprintf(LOG_ERR, "Watchdog Timer Shutoff command failed!");
  660. return -1;
  661. }
  662. if (rsp->ccode) {
  663. lprintf(LOG_ERR, "Watchdog Timer Shutoff command failed! %s",
  664. val2str(rsp->ccode, completion_code_vals));
  665. return -1;
  666. }
  667. printf("Watchdog Timer Shutoff successful -- timer stopped\n");
  668. return 0;
  669. }
  670. /* ipmi_mc_rst_watchdog
  671. *
  672. * @intf: ipmi interface
  673. *
  674. * returns 0 on success
  675. * returns -1 on error
  676. */
  677. static int
  678. ipmi_mc_rst_watchdog(struct ipmi_intf * intf)
  679. {
  680. struct ipmi_rs * rsp;
  681. struct ipmi_rq req;
  682. memset(&req, 0, sizeof(req));
  683. req.msg.netfn = IPMI_NETFN_APP;
  684. req.msg.cmd = BMC_RESET_WATCHDOG_TIMER;
  685. req.msg.data_len = 0;
  686. rsp = intf->sendrecv(intf, &req);
  687. if (rsp == NULL) {
  688. lprintf(LOG_ERR, "Reset Watchdog Timer command failed!");
  689. return -1;
  690. }
  691. if (rsp->ccode) {
  692. lprintf(LOG_ERR, "Reset Watchdog Timer command failed: %s",
  693. (rsp->ccode == IPM_WATCHDOG_RESET_ERROR) ?
  694. "Attempt to reset uninitialized watchdog" :
  695. val2str(rsp->ccode, completion_code_vals));
  696. return -1;
  697. }
  698. printf("IPMI Watchdog Timer Reset - countdown restarted!\n");
  699. return 0;
  700. }
  701. /* ipmi_mc_main - top-level handler for MC functions
  702. *
  703. * @intf: ipmi interface
  704. * @argc: number of arguments
  705. * @argv: argument list
  706. *
  707. * returns 0 on success
  708. * returns -1 on error
  709. */
  710. int
  711. ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
  712. {
  713. int rc = 0;
  714. if (argc < 1) {
  715. lprintf(LOG_ERR, "Not enough parameters given.");
  716. printf_mc_usage();
  717. rc = (-1);
  718. }
  719. else if (strncmp(argv[0], "help", 4) == 0) {
  720. printf_mc_usage();
  721. rc = 0;
  722. }
  723. else if (strncmp(argv[0], "reset", 5) == 0) {
  724. if (argc < 2) {
  725. lprintf(LOG_ERR, "Not enough parameters given.");
  726. printf_mc_reset_usage();
  727. rc = (-1);
  728. }
  729. else if (strncmp(argv[1], "help", 4) == 0) {
  730. printf_mc_reset_usage();
  731. rc = 0;
  732. }
  733. else if (strncmp(argv[1], "cold", 4) == 0) {
  734. rc = ipmi_mc_reset(intf, BMC_COLD_RESET);
  735. }
  736. else if (strncmp(argv[1], "warm", 4) == 0) {
  737. rc = ipmi_mc_reset(intf, BMC_WARM_RESET);
  738. }
  739. else {
  740. lprintf(LOG_ERR, "Invalid mc/bmc %s command: %s", argv[0], argv[1]);
  741. printf_mc_reset_usage();
  742. rc = (-1);
  743. }
  744. }
  745. else if (strncmp(argv[0], "info", 4) == 0) {
  746. rc = ipmi_mc_get_deviceid(intf);
  747. }
  748. else if (strncmp(argv[0], "guid", 4) == 0) {
  749. rc = ipmi_mc_get_guid(intf);
  750. }
  751. else if (strncmp(argv[0], "getenables", 10) == 0) {
  752. rc = ipmi_mc_get_enables(intf);
  753. }
  754. else if (strncmp(argv[0], "setenables", 10) == 0) {
  755. rc = ipmi_mc_set_enables(intf, argc-1, &(argv[1]));
  756. }
  757. else if (!strncmp(argv[0], "selftest", 8)) {
  758. rc = ipmi_mc_get_selftest(intf);
  759. }
  760. else if (!strncmp(argv[0], "watchdog", 8)) {
  761. if (argc < 2) {
  762. lprintf(LOG_ERR, "Not enough parameters given.");
  763. print_watchdog_usage();
  764. rc = (-1);
  765. }
  766. else if (strncmp(argv[1], "help", 4) == 0) {
  767. print_watchdog_usage();
  768. rc = 0;
  769. }
  770. else if (strncmp(argv[1], "get", 3) == 0) {
  771. rc = ipmi_mc_get_watchdog(intf);
  772. }
  773. else if(strncmp(argv[1], "off", 3) == 0) {
  774. rc = ipmi_mc_shutoff_watchdog(intf);
  775. }
  776. else if(strncmp(argv[1], "reset", 5) == 0) {
  777. rc = ipmi_mc_rst_watchdog(intf);
  778. }
  779. else {
  780. lprintf(LOG_ERR, "Invalid mc/bmc %s command: %s", argv[0], argv[1]);
  781. print_watchdog_usage();
  782. rc = (-1);
  783. }
  784. }
  785. else if (strncmp(argv[0], "getsysinfo", 10) == 0) {
  786. rc = ipmi_sysinfo_main(intf, argc, argv, 0);
  787. }
  788. else if (strncmp(argv[0], "setsysinfo", 10) == 0) {
  789. rc = ipmi_sysinfo_main(intf, argc, argv, 1);
  790. }
  791. else {
  792. lprintf(LOG_ERR, "Invalid mc/bmc command: %s", argv[0]);
  793. printf_mc_usage();
  794. rc = (-1);
  795. }
  796. return rc;
  797. }
  798. /*
  799. * sysinfo_param() - function converts sysinfo param to int
  800. *
  801. * @str - user input string
  802. * @maxset - ?
  803. *
  804. * returns (-1) on error
  805. * returns > 0 on success
  806. */
  807. static int
  808. sysinfo_param(const char *str, int *maxset)
  809. {
  810. if (!str || !maxset)
  811. return (-1);
  812. *maxset = 4;
  813. if (!strcmp(str, "system_name"))
  814. return IPMI_SYSINFO_HOSTNAME;
  815. else if (!strcmp(str, "primary_os_name"))
  816. return IPMI_SYSINFO_PRIMARY_OS_NAME;
  817. else if (!strcmp(str, "os_name"))
  818. return IPMI_SYSINFO_OS_NAME;
  819. else if (!strcmp(str, "delloem_os_version"))
  820. return IPMI_SYSINFO_DELL_OS_VERSION;
  821. else if (!strcmp(str, "delloem_url")) {
  822. *maxset = 2;
  823. return IPMI_SYSINFO_DELL_URL;
  824. } else if (!strcmp(str, "system_fw_version")) {
  825. return IPMI_SYSINFO_SYSTEM_FW_VERSION;
  826. }
  827. return (-1);
  828. }
  829. /*
  830. * ipmi_mc_getsysinfo() - function processes the IPMI Get System Info command
  831. *
  832. * @intf - ipmi interface
  833. * @param - parameter eg. 0xC0..0xFF = OEM
  834. * @block - number of block parameters
  835. * @set - number of set parameters
  836. * @len - length of buffer
  837. * @buffer - pointer to buffer
  838. *
  839. * returns (-1) on failure
  840. * returns 0 on success
  841. * returns > 0 IPMI code
  842. */
  843. int
  844. ipmi_mc_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
  845. int len, void *buffer)
  846. {
  847. uint8_t data[4];
  848. struct ipmi_rs *rsp = NULL;
  849. struct ipmi_rq req = {0};
  850. memset(buffer, 0, len);
  851. memset(data, 0, 4);
  852. req.msg.netfn = IPMI_NETFN_APP;
  853. req.msg.lun = 0;
  854. req.msg.cmd = IPMI_GET_SYS_INFO;
  855. req.msg.data_len = 4;
  856. req.msg.data = data;
  857. if (verbose > 1)
  858. printf("getsysinfo: %.2x/%.2x/%.2x\n", param, block, set);
  859. data[0] = 0; /* get/set */
  860. data[1] = param;
  861. data[2] = block;
  862. data[3] = set;
  863. /*
  864. * Format of get output is:
  865. * u8 param_rev
  866. * u8 selector
  867. * u8 encoding bit[0-3];
  868. * u8 length
  869. * u8 data0[14]
  870. */
  871. rsp = intf->sendrecv(intf, &req);
  872. if (rsp == NULL)
  873. return (-1);
  874. if (rsp->ccode == 0) {
  875. if (len > rsp->data_len)
  876. len = rsp->data_len;
  877. if (len && buffer)
  878. memcpy(buffer, rsp->data, len);
  879. }
  880. return rsp->ccode;
  881. }
  882. /*
  883. * ipmi_mc_setsysinfo() - function processes the IPMI Set System Info command
  884. *
  885. * @intf - ipmi interface
  886. * @len - length of buffer
  887. * @buffer - pointer to buffer
  888. *
  889. * returns (-1) on failure
  890. * returns 0 on success
  891. * returns > 0 IPMI code
  892. */
  893. int
  894. ipmi_mc_setsysinfo(struct ipmi_intf * intf, int len, void *buffer)
  895. {
  896. struct ipmi_rs *rsp = NULL;
  897. struct ipmi_rq req = {0};
  898. req.msg.netfn = IPMI_NETFN_APP;
  899. req.msg.lun = 0;
  900. req.msg.cmd = IPMI_SET_SYS_INFO;
  901. req.msg.data_len = len;
  902. req.msg.data = buffer;
  903. /*
  904. * Format of set input:
  905. * u8 param rev
  906. * u8 selector
  907. * u8 data1[16]
  908. */
  909. rsp = intf->sendrecv(intf, &req);
  910. if (rsp != NULL) {
  911. return rsp->ccode;
  912. }
  913. return -1;
  914. }
  915. static int
  916. ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv, int is_set)
  917. {
  918. char *str;
  919. unsigned char infostr[256];
  920. unsigned char paramdata[18];
  921. int len, maxset, param, pos, rc, set;
  922. if (argc == 2 && strcmp(argv[1], "help") == 0) {
  923. printf_sysinfo_usage(1);
  924. return 0;
  925. }
  926. else if (argc < 2 || (is_set == 1 && argc < 3)) {
  927. lprintf(LOG_ERR, "Not enough parameters given.");
  928. printf_sysinfo_usage(1);
  929. return (-1);
  930. }
  931. /* Get Parameters */
  932. if ((param = sysinfo_param(argv[1], &maxset)) < 0) {
  933. lprintf(LOG_ERR, "Invalid mc/bmc %s command: %s", argv[0], argv[1]);
  934. printf_sysinfo_usage(1);
  935. return (-1);
  936. }
  937. rc = 0;
  938. if (is_set != 0) {
  939. str = argv[2];
  940. set = pos = 0;
  941. len = strlen(str);
  942. /* first block holds 14 bytes, all others hold 16 */
  943. if ((len + 2 + 15) / 16 >= maxset)
  944. len = (maxset * 16) - 2;
  945. do {
  946. memset(paramdata, 0, sizeof(paramdata));
  947. paramdata[0] = param;
  948. paramdata[1] = set;
  949. if (set == 0) {
  950. /* First block is special case */
  951. paramdata[2] = 0; /* ascii encoding */
  952. paramdata[3] = len; /* length */
  953. strncpy(paramdata + 4, str + pos, IPMI_SYSINFO_SET0_SIZE);
  954. pos += IPMI_SYSINFO_SET0_SIZE;
  955. }
  956. else {
  957. strncpy(paramdata + 2, str + pos, IPMI_SYSINFO_SETN_SIZE);
  958. pos += IPMI_SYSINFO_SETN_SIZE;
  959. }
  960. rc = ipmi_mc_setsysinfo(intf, 18, paramdata);
  961. if (rc)
  962. break;
  963. set++;
  964. } while (pos < len);
  965. }
  966. else {
  967. memset(infostr, 0, sizeof(infostr));
  968. /* Read blocks of data */
  969. pos = 0;
  970. for (set = 0; set < maxset; set++) {
  971. rc = ipmi_mc_getsysinfo(intf, param, set, 0, 18, paramdata);
  972. if (rc)
  973. break;
  974. if (set == 0) {
  975. /* First block is special case */
  976. if ((paramdata[2] & 0xF) == 0) {
  977. /* Determine max number of blocks to read */
  978. maxset = ((paramdata[3] + 2) + 15) / 16;
  979. }
  980. memcpy(infostr + pos, paramdata + 4, IPMI_SYSINFO_SET0_SIZE);
  981. pos += IPMI_SYSINFO_SET0_SIZE;
  982. }
  983. else {
  984. memcpy(infostr + pos, paramdata + 2, IPMI_SYSINFO_SETN_SIZE);
  985. pos += IPMI_SYSINFO_SETN_SIZE;
  986. }
  987. }
  988. printf("%s\n", infostr);
  989. }
  990. if (rc < 0) {
  991. lprintf(LOG_ERR, "%s %s set %d command failed", argv[0], argv[1], set);
  992. }
  993. else if (rc == 0x80) {
  994. lprintf(LOG_ERR, "%s %s parameter not supported", argv[0], argv[1]);
  995. }
  996. else if (rc > 0) {
  997. lprintf(LOG_ERR, "%s command failed: %s", argv[0],
  998. val2str(rc, completion_code_vals));
  999. }
  1000. return rc;
  1001. }