ipmi_smic_sm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * ipmi_smic_sm.c
  4. *
  5. * The state-machine driver for an IPMI SMIC driver
  6. *
  7. * It started as a copy of Corey Minyard's driver for the KSC interface
  8. * and the kernel patch "mmcdev-patch-245" by HP
  9. *
  10. * modified by: Hannes Schulz <schulz@schwaar.com>
  11. * ipmi@schwaar.com
  12. *
  13. *
  14. * Corey Minyard's driver for the KSC interface has the following
  15. * copyright notice:
  16. * Copyright 2002 MontaVista Software Inc.
  17. *
  18. * the kernel patch "mmcdev-patch-245" by HP has the following
  19. * copyright notice:
  20. * (c) Copyright 2001 Grant Grundler (c) Copyright
  21. * 2001 Hewlett-Packard Company
  22. */
  23. #include <linux/kernel.h> /* For printk. */
  24. #include <linux/string.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/ipmi_msgdefs.h> /* for completion codes */
  28. #include "ipmi_si_sm.h"
  29. /* smic_debug is a bit-field
  30. * SMIC_DEBUG_ENABLE - turned on for now
  31. * SMIC_DEBUG_MSG - commands and their responses
  32. * SMIC_DEBUG_STATES - state machine
  33. */
  34. #define SMIC_DEBUG_STATES 4
  35. #define SMIC_DEBUG_MSG 2
  36. #define SMIC_DEBUG_ENABLE 1
  37. static int smic_debug = 1;
  38. module_param(smic_debug, int, 0644);
  39. MODULE_PARM_DESC(smic_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
  40. enum smic_states {
  41. SMIC_IDLE,
  42. SMIC_START_OP,
  43. SMIC_OP_OK,
  44. SMIC_WRITE_START,
  45. SMIC_WRITE_NEXT,
  46. SMIC_WRITE_END,
  47. SMIC_WRITE2READ,
  48. SMIC_READ_START,
  49. SMIC_READ_NEXT,
  50. SMIC_READ_END,
  51. SMIC_HOSED
  52. };
  53. #define MAX_SMIC_READ_SIZE 80
  54. #define MAX_SMIC_WRITE_SIZE 80
  55. #define SMIC_MAX_ERROR_RETRIES 3
  56. /* Timeouts in microseconds. */
  57. #define SMIC_RETRY_TIMEOUT (2*USEC_PER_SEC)
  58. /* SMIC Flags Register Bits */
  59. #define SMIC_RX_DATA_READY 0x80
  60. #define SMIC_TX_DATA_READY 0x40
  61. /*
  62. * SMIC_SMI and SMIC_EVM_DATA_AVAIL are only used by
  63. * a few systems, and then only by Systems Management
  64. * Interrupts, not by the OS. Always ignore these bits.
  65. *
  66. */
  67. #define SMIC_SMI 0x10
  68. #define SMIC_EVM_DATA_AVAIL 0x08
  69. #define SMIC_SMS_DATA_AVAIL 0x04
  70. #define SMIC_FLAG_BSY 0x01
  71. /* SMIC Error Codes */
  72. #define EC_NO_ERROR 0x00
  73. #define EC_ABORTED 0x01
  74. #define EC_ILLEGAL_CONTROL 0x02
  75. #define EC_NO_RESPONSE 0x03
  76. #define EC_ILLEGAL_COMMAND 0x04
  77. #define EC_BUFFER_FULL 0x05
  78. struct si_sm_data {
  79. enum smic_states state;
  80. struct si_sm_io *io;
  81. unsigned char write_data[MAX_SMIC_WRITE_SIZE];
  82. int write_pos;
  83. int write_count;
  84. int orig_write_count;
  85. unsigned char read_data[MAX_SMIC_READ_SIZE];
  86. int read_pos;
  87. int truncated;
  88. unsigned int error_retries;
  89. long smic_timeout;
  90. };
  91. static unsigned int init_smic_data(struct si_sm_data *smic,
  92. struct si_sm_io *io)
  93. {
  94. smic->state = SMIC_IDLE;
  95. smic->io = io;
  96. smic->write_pos = 0;
  97. smic->write_count = 0;
  98. smic->orig_write_count = 0;
  99. smic->read_pos = 0;
  100. smic->error_retries = 0;
  101. smic->truncated = 0;
  102. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  103. /* We use 3 bytes of I/O. */
  104. return 3;
  105. }
  106. static int start_smic_transaction(struct si_sm_data *smic,
  107. unsigned char *data, unsigned int size)
  108. {
  109. unsigned int i;
  110. if (size < 2)
  111. return IPMI_REQ_LEN_INVALID_ERR;
  112. if (size > MAX_SMIC_WRITE_SIZE)
  113. return IPMI_REQ_LEN_EXCEEDED_ERR;
  114. if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED))
  115. return IPMI_NOT_IN_MY_STATE_ERR;
  116. if (smic_debug & SMIC_DEBUG_MSG) {
  117. printk(KERN_DEBUG "start_smic_transaction -");
  118. for (i = 0; i < size; i++)
  119. printk(" %02x", (unsigned char) data[i]);
  120. printk("\n");
  121. }
  122. smic->error_retries = 0;
  123. memcpy(smic->write_data, data, size);
  124. smic->write_count = size;
  125. smic->orig_write_count = size;
  126. smic->write_pos = 0;
  127. smic->read_pos = 0;
  128. smic->state = SMIC_START_OP;
  129. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  130. return 0;
  131. }
  132. static int smic_get_result(struct si_sm_data *smic,
  133. unsigned char *data, unsigned int length)
  134. {
  135. int i;
  136. if (smic_debug & SMIC_DEBUG_MSG) {
  137. printk(KERN_DEBUG "smic_get result -");
  138. for (i = 0; i < smic->read_pos; i++)
  139. printk(" %02x", smic->read_data[i]);
  140. printk("\n");
  141. }
  142. if (length < smic->read_pos) {
  143. smic->read_pos = length;
  144. smic->truncated = 1;
  145. }
  146. memcpy(data, smic->read_data, smic->read_pos);
  147. if ((length >= 3) && (smic->read_pos < 3)) {
  148. data[2] = IPMI_ERR_UNSPECIFIED;
  149. smic->read_pos = 3;
  150. }
  151. if (smic->truncated) {
  152. data[2] = IPMI_ERR_MSG_TRUNCATED;
  153. smic->truncated = 0;
  154. }
  155. return smic->read_pos;
  156. }
  157. static inline unsigned char read_smic_flags(struct si_sm_data *smic)
  158. {
  159. return smic->io->inputb(smic->io, 2);
  160. }
  161. static inline unsigned char read_smic_status(struct si_sm_data *smic)
  162. {
  163. return smic->io->inputb(smic->io, 1);
  164. }
  165. static inline unsigned char read_smic_data(struct si_sm_data *smic)
  166. {
  167. return smic->io->inputb(smic->io, 0);
  168. }
  169. static inline void write_smic_flags(struct si_sm_data *smic,
  170. unsigned char flags)
  171. {
  172. smic->io->outputb(smic->io, 2, flags);
  173. }
  174. static inline void write_smic_control(struct si_sm_data *smic,
  175. unsigned char control)
  176. {
  177. smic->io->outputb(smic->io, 1, control);
  178. }
  179. static inline void write_si_sm_data(struct si_sm_data *smic,
  180. unsigned char data)
  181. {
  182. smic->io->outputb(smic->io, 0, data);
  183. }
  184. static inline void start_error_recovery(struct si_sm_data *smic, char *reason)
  185. {
  186. (smic->error_retries)++;
  187. if (smic->error_retries > SMIC_MAX_ERROR_RETRIES) {
  188. if (smic_debug & SMIC_DEBUG_ENABLE)
  189. printk(KERN_WARNING
  190. "ipmi_smic_drv: smic hosed: %s\n", reason);
  191. smic->state = SMIC_HOSED;
  192. } else {
  193. smic->write_count = smic->orig_write_count;
  194. smic->write_pos = 0;
  195. smic->read_pos = 0;
  196. smic->state = SMIC_START_OP;
  197. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  198. }
  199. }
  200. static inline void write_next_byte(struct si_sm_data *smic)
  201. {
  202. write_si_sm_data(smic, smic->write_data[smic->write_pos]);
  203. (smic->write_pos)++;
  204. (smic->write_count)--;
  205. }
  206. static inline void read_next_byte(struct si_sm_data *smic)
  207. {
  208. if (smic->read_pos >= MAX_SMIC_READ_SIZE) {
  209. read_smic_data(smic);
  210. smic->truncated = 1;
  211. } else {
  212. smic->read_data[smic->read_pos] = read_smic_data(smic);
  213. smic->read_pos++;
  214. }
  215. }
  216. /* SMIC Control/Status Code Components */
  217. #define SMIC_GET_STATUS 0x00 /* Control form's name */
  218. #define SMIC_READY 0x00 /* Status form's name */
  219. #define SMIC_WR_START 0x01 /* Unified Control/Status names... */
  220. #define SMIC_WR_NEXT 0x02
  221. #define SMIC_WR_END 0x03
  222. #define SMIC_RD_START 0x04
  223. #define SMIC_RD_NEXT 0x05
  224. #define SMIC_RD_END 0x06
  225. #define SMIC_CODE_MASK 0x0f
  226. #define SMIC_CONTROL 0x00
  227. #define SMIC_STATUS 0x80
  228. #define SMIC_CS_MASK 0x80
  229. #define SMIC_SMS 0x40
  230. #define SMIC_SMM 0x60
  231. #define SMIC_STREAM_MASK 0x60
  232. /* SMIC Control Codes */
  233. #define SMIC_CC_SMS_GET_STATUS (SMIC_CONTROL|SMIC_SMS|SMIC_GET_STATUS)
  234. #define SMIC_CC_SMS_WR_START (SMIC_CONTROL|SMIC_SMS|SMIC_WR_START)
  235. #define SMIC_CC_SMS_WR_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_WR_NEXT)
  236. #define SMIC_CC_SMS_WR_END (SMIC_CONTROL|SMIC_SMS|SMIC_WR_END)
  237. #define SMIC_CC_SMS_RD_START (SMIC_CONTROL|SMIC_SMS|SMIC_RD_START)
  238. #define SMIC_CC_SMS_RD_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_RD_NEXT)
  239. #define SMIC_CC_SMS_RD_END (SMIC_CONTROL|SMIC_SMS|SMIC_RD_END)
  240. #define SMIC_CC_SMM_GET_STATUS (SMIC_CONTROL|SMIC_SMM|SMIC_GET_STATUS)
  241. #define SMIC_CC_SMM_WR_START (SMIC_CONTROL|SMIC_SMM|SMIC_WR_START)
  242. #define SMIC_CC_SMM_WR_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_WR_NEXT)
  243. #define SMIC_CC_SMM_WR_END (SMIC_CONTROL|SMIC_SMM|SMIC_WR_END)
  244. #define SMIC_CC_SMM_RD_START (SMIC_CONTROL|SMIC_SMM|SMIC_RD_START)
  245. #define SMIC_CC_SMM_RD_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_RD_NEXT)
  246. #define SMIC_CC_SMM_RD_END (SMIC_CONTROL|SMIC_SMM|SMIC_RD_END)
  247. /* SMIC Status Codes */
  248. #define SMIC_SC_SMS_READY (SMIC_STATUS|SMIC_SMS|SMIC_READY)
  249. #define SMIC_SC_SMS_WR_START (SMIC_STATUS|SMIC_SMS|SMIC_WR_START)
  250. #define SMIC_SC_SMS_WR_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_WR_NEXT)
  251. #define SMIC_SC_SMS_WR_END (SMIC_STATUS|SMIC_SMS|SMIC_WR_END)
  252. #define SMIC_SC_SMS_RD_START (SMIC_STATUS|SMIC_SMS|SMIC_RD_START)
  253. #define SMIC_SC_SMS_RD_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_RD_NEXT)
  254. #define SMIC_SC_SMS_RD_END (SMIC_STATUS|SMIC_SMS|SMIC_RD_END)
  255. #define SMIC_SC_SMM_READY (SMIC_STATUS|SMIC_SMM|SMIC_READY)
  256. #define SMIC_SC_SMM_WR_START (SMIC_STATUS|SMIC_SMM|SMIC_WR_START)
  257. #define SMIC_SC_SMM_WR_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_WR_NEXT)
  258. #define SMIC_SC_SMM_WR_END (SMIC_STATUS|SMIC_SMM|SMIC_WR_END)
  259. #define SMIC_SC_SMM_RD_START (SMIC_STATUS|SMIC_SMM|SMIC_RD_START)
  260. #define SMIC_SC_SMM_RD_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_RD_NEXT)
  261. #define SMIC_SC_SMM_RD_END (SMIC_STATUS|SMIC_SMM|SMIC_RD_END)
  262. /* these are the control/status codes we actually use
  263. SMIC_CC_SMS_GET_STATUS 0x40
  264. SMIC_CC_SMS_WR_START 0x41
  265. SMIC_CC_SMS_WR_NEXT 0x42
  266. SMIC_CC_SMS_WR_END 0x43
  267. SMIC_CC_SMS_RD_START 0x44
  268. SMIC_CC_SMS_RD_NEXT 0x45
  269. SMIC_CC_SMS_RD_END 0x46
  270. SMIC_SC_SMS_READY 0xC0
  271. SMIC_SC_SMS_WR_START 0xC1
  272. SMIC_SC_SMS_WR_NEXT 0xC2
  273. SMIC_SC_SMS_WR_END 0xC3
  274. SMIC_SC_SMS_RD_START 0xC4
  275. SMIC_SC_SMS_RD_NEXT 0xC5
  276. SMIC_SC_SMS_RD_END 0xC6
  277. */
  278. static enum si_sm_result smic_event(struct si_sm_data *smic, long time)
  279. {
  280. unsigned char status;
  281. unsigned char flags;
  282. unsigned char data;
  283. if (smic->state == SMIC_HOSED) {
  284. init_smic_data(smic, smic->io);
  285. return SI_SM_HOSED;
  286. }
  287. if (smic->state != SMIC_IDLE) {
  288. if (smic_debug & SMIC_DEBUG_STATES)
  289. printk(KERN_DEBUG
  290. "smic_event - smic->smic_timeout = %ld,"
  291. " time = %ld\n",
  292. smic->smic_timeout, time);
  293. /*
  294. * FIXME: smic_event is sometimes called with time >
  295. * SMIC_RETRY_TIMEOUT
  296. */
  297. if (time < SMIC_RETRY_TIMEOUT) {
  298. smic->smic_timeout -= time;
  299. if (smic->smic_timeout < 0) {
  300. start_error_recovery(smic, "smic timed out.");
  301. return SI_SM_CALL_WITH_DELAY;
  302. }
  303. }
  304. }
  305. flags = read_smic_flags(smic);
  306. if (flags & SMIC_FLAG_BSY)
  307. return SI_SM_CALL_WITH_DELAY;
  308. status = read_smic_status(smic);
  309. if (smic_debug & SMIC_DEBUG_STATES)
  310. printk(KERN_DEBUG
  311. "smic_event - state = %d, flags = 0x%02x,"
  312. " status = 0x%02x\n",
  313. smic->state, flags, status);
  314. switch (smic->state) {
  315. case SMIC_IDLE:
  316. /* in IDLE we check for available messages */
  317. if (flags & SMIC_SMS_DATA_AVAIL)
  318. return SI_SM_ATTN;
  319. return SI_SM_IDLE;
  320. case SMIC_START_OP:
  321. /* sanity check whether smic is really idle */
  322. write_smic_control(smic, SMIC_CC_SMS_GET_STATUS);
  323. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  324. smic->state = SMIC_OP_OK;
  325. break;
  326. case SMIC_OP_OK:
  327. if (status != SMIC_SC_SMS_READY) {
  328. /* this should not happen */
  329. start_error_recovery(smic,
  330. "state = SMIC_OP_OK,"
  331. " status != SMIC_SC_SMS_READY");
  332. return SI_SM_CALL_WITH_DELAY;
  333. }
  334. /* OK so far; smic is idle let us start ... */
  335. write_smic_control(smic, SMIC_CC_SMS_WR_START);
  336. write_next_byte(smic);
  337. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  338. smic->state = SMIC_WRITE_START;
  339. break;
  340. case SMIC_WRITE_START:
  341. if (status != SMIC_SC_SMS_WR_START) {
  342. start_error_recovery(smic,
  343. "state = SMIC_WRITE_START, "
  344. "status != SMIC_SC_SMS_WR_START");
  345. return SI_SM_CALL_WITH_DELAY;
  346. }
  347. /*
  348. * we must not issue WR_(NEXT|END) unless
  349. * TX_DATA_READY is set
  350. * */
  351. if (flags & SMIC_TX_DATA_READY) {
  352. if (smic->write_count == 1) {
  353. /* last byte */
  354. write_smic_control(smic, SMIC_CC_SMS_WR_END);
  355. smic->state = SMIC_WRITE_END;
  356. } else {
  357. write_smic_control(smic, SMIC_CC_SMS_WR_NEXT);
  358. smic->state = SMIC_WRITE_NEXT;
  359. }
  360. write_next_byte(smic);
  361. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  362. } else
  363. return SI_SM_CALL_WITH_DELAY;
  364. break;
  365. case SMIC_WRITE_NEXT:
  366. if (status != SMIC_SC_SMS_WR_NEXT) {
  367. start_error_recovery(smic,
  368. "state = SMIC_WRITE_NEXT, "
  369. "status != SMIC_SC_SMS_WR_NEXT");
  370. return SI_SM_CALL_WITH_DELAY;
  371. }
  372. /* this is the same code as in SMIC_WRITE_START */
  373. if (flags & SMIC_TX_DATA_READY) {
  374. if (smic->write_count == 1) {
  375. write_smic_control(smic, SMIC_CC_SMS_WR_END);
  376. smic->state = SMIC_WRITE_END;
  377. } else {
  378. write_smic_control(smic, SMIC_CC_SMS_WR_NEXT);
  379. smic->state = SMIC_WRITE_NEXT;
  380. }
  381. write_next_byte(smic);
  382. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  383. } else
  384. return SI_SM_CALL_WITH_DELAY;
  385. break;
  386. case SMIC_WRITE_END:
  387. if (status != SMIC_SC_SMS_WR_END) {
  388. start_error_recovery(smic,
  389. "state = SMIC_WRITE_END, "
  390. "status != SMIC_SC_SMS_WR_END");
  391. return SI_SM_CALL_WITH_DELAY;
  392. }
  393. /* data register holds an error code */
  394. data = read_smic_data(smic);
  395. if (data != 0) {
  396. if (smic_debug & SMIC_DEBUG_ENABLE)
  397. printk(KERN_DEBUG
  398. "SMIC_WRITE_END: data = %02x\n", data);
  399. start_error_recovery(smic,
  400. "state = SMIC_WRITE_END, "
  401. "data != SUCCESS");
  402. return SI_SM_CALL_WITH_DELAY;
  403. } else
  404. smic->state = SMIC_WRITE2READ;
  405. break;
  406. case SMIC_WRITE2READ:
  407. /*
  408. * we must wait for RX_DATA_READY to be set before we
  409. * can continue
  410. */
  411. if (flags & SMIC_RX_DATA_READY) {
  412. write_smic_control(smic, SMIC_CC_SMS_RD_START);
  413. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  414. smic->state = SMIC_READ_START;
  415. } else
  416. return SI_SM_CALL_WITH_DELAY;
  417. break;
  418. case SMIC_READ_START:
  419. if (status != SMIC_SC_SMS_RD_START) {
  420. start_error_recovery(smic,
  421. "state = SMIC_READ_START, "
  422. "status != SMIC_SC_SMS_RD_START");
  423. return SI_SM_CALL_WITH_DELAY;
  424. }
  425. if (flags & SMIC_RX_DATA_READY) {
  426. read_next_byte(smic);
  427. write_smic_control(smic, SMIC_CC_SMS_RD_NEXT);
  428. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  429. smic->state = SMIC_READ_NEXT;
  430. } else
  431. return SI_SM_CALL_WITH_DELAY;
  432. break;
  433. case SMIC_READ_NEXT:
  434. switch (status) {
  435. /*
  436. * smic tells us that this is the last byte to be read
  437. * --> clean up
  438. */
  439. case SMIC_SC_SMS_RD_END:
  440. read_next_byte(smic);
  441. write_smic_control(smic, SMIC_CC_SMS_RD_END);
  442. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  443. smic->state = SMIC_READ_END;
  444. break;
  445. case SMIC_SC_SMS_RD_NEXT:
  446. if (flags & SMIC_RX_DATA_READY) {
  447. read_next_byte(smic);
  448. write_smic_control(smic, SMIC_CC_SMS_RD_NEXT);
  449. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  450. smic->state = SMIC_READ_NEXT;
  451. } else
  452. return SI_SM_CALL_WITH_DELAY;
  453. break;
  454. default:
  455. start_error_recovery(
  456. smic,
  457. "state = SMIC_READ_NEXT, "
  458. "status != SMIC_SC_SMS_RD_(NEXT|END)");
  459. return SI_SM_CALL_WITH_DELAY;
  460. }
  461. break;
  462. case SMIC_READ_END:
  463. if (status != SMIC_SC_SMS_READY) {
  464. start_error_recovery(smic,
  465. "state = SMIC_READ_END, "
  466. "status != SMIC_SC_SMS_READY");
  467. return SI_SM_CALL_WITH_DELAY;
  468. }
  469. data = read_smic_data(smic);
  470. /* data register holds an error code */
  471. if (data != 0) {
  472. if (smic_debug & SMIC_DEBUG_ENABLE)
  473. printk(KERN_DEBUG
  474. "SMIC_READ_END: data = %02x\n", data);
  475. start_error_recovery(smic,
  476. "state = SMIC_READ_END, "
  477. "data != SUCCESS");
  478. return SI_SM_CALL_WITH_DELAY;
  479. } else {
  480. smic->state = SMIC_IDLE;
  481. return SI_SM_TRANSACTION_COMPLETE;
  482. }
  483. case SMIC_HOSED:
  484. init_smic_data(smic, smic->io);
  485. return SI_SM_HOSED;
  486. default:
  487. if (smic_debug & SMIC_DEBUG_ENABLE) {
  488. printk(KERN_DEBUG "smic->state = %d\n", smic->state);
  489. start_error_recovery(smic, "state = UNKNOWN");
  490. return SI_SM_CALL_WITH_DELAY;
  491. }
  492. }
  493. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  494. return SI_SM_CALL_WITHOUT_DELAY;
  495. }
  496. static int smic_detect(struct si_sm_data *smic)
  497. {
  498. /*
  499. * It's impossible for the SMIC fnags register to be all 1's,
  500. * (assuming a properly functioning, self-initialized BMC)
  501. * but that's what you get from reading a bogus address, so we
  502. * test that first.
  503. */
  504. if (read_smic_flags(smic) == 0xff)
  505. return 1;
  506. return 0;
  507. }
  508. static void smic_cleanup(struct si_sm_data *kcs)
  509. {
  510. }
  511. static int smic_size(void)
  512. {
  513. return sizeof(struct si_sm_data);
  514. }
  515. const struct si_sm_handlers smic_smi_handlers = {
  516. .init_data = init_smic_data,
  517. .start_transaction = start_smic_transaction,
  518. .get_result = smic_get_result,
  519. .event = smic_event,
  520. .detect = smic_detect,
  521. .cleanup = smic_cleanup,
  522. .size = smic_size,
  523. };