ipmi_smic_sm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. pr_cont(" %02x", data[i]);
  120. pr_cont("\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. pr_cont(" %02x", smic->read_data[i]);
  140. pr_cont("\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. pr_warn("ipmi_smic_drv: smic hosed: %s\n", reason);
  190. smic->state = SMIC_HOSED;
  191. } else {
  192. smic->write_count = smic->orig_write_count;
  193. smic->write_pos = 0;
  194. smic->read_pos = 0;
  195. smic->state = SMIC_START_OP;
  196. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  197. }
  198. }
  199. static inline void write_next_byte(struct si_sm_data *smic)
  200. {
  201. write_si_sm_data(smic, smic->write_data[smic->write_pos]);
  202. (smic->write_pos)++;
  203. (smic->write_count)--;
  204. }
  205. static inline void read_next_byte(struct si_sm_data *smic)
  206. {
  207. if (smic->read_pos >= MAX_SMIC_READ_SIZE) {
  208. read_smic_data(smic);
  209. smic->truncated = 1;
  210. } else {
  211. smic->read_data[smic->read_pos] = read_smic_data(smic);
  212. smic->read_pos++;
  213. }
  214. }
  215. /* SMIC Control/Status Code Components */
  216. #define SMIC_GET_STATUS 0x00 /* Control form's name */
  217. #define SMIC_READY 0x00 /* Status form's name */
  218. #define SMIC_WR_START 0x01 /* Unified Control/Status names... */
  219. #define SMIC_WR_NEXT 0x02
  220. #define SMIC_WR_END 0x03
  221. #define SMIC_RD_START 0x04
  222. #define SMIC_RD_NEXT 0x05
  223. #define SMIC_RD_END 0x06
  224. #define SMIC_CODE_MASK 0x0f
  225. #define SMIC_CONTROL 0x00
  226. #define SMIC_STATUS 0x80
  227. #define SMIC_CS_MASK 0x80
  228. #define SMIC_SMS 0x40
  229. #define SMIC_SMM 0x60
  230. #define SMIC_STREAM_MASK 0x60
  231. /* SMIC Control Codes */
  232. #define SMIC_CC_SMS_GET_STATUS (SMIC_CONTROL|SMIC_SMS|SMIC_GET_STATUS)
  233. #define SMIC_CC_SMS_WR_START (SMIC_CONTROL|SMIC_SMS|SMIC_WR_START)
  234. #define SMIC_CC_SMS_WR_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_WR_NEXT)
  235. #define SMIC_CC_SMS_WR_END (SMIC_CONTROL|SMIC_SMS|SMIC_WR_END)
  236. #define SMIC_CC_SMS_RD_START (SMIC_CONTROL|SMIC_SMS|SMIC_RD_START)
  237. #define SMIC_CC_SMS_RD_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_RD_NEXT)
  238. #define SMIC_CC_SMS_RD_END (SMIC_CONTROL|SMIC_SMS|SMIC_RD_END)
  239. #define SMIC_CC_SMM_GET_STATUS (SMIC_CONTROL|SMIC_SMM|SMIC_GET_STATUS)
  240. #define SMIC_CC_SMM_WR_START (SMIC_CONTROL|SMIC_SMM|SMIC_WR_START)
  241. #define SMIC_CC_SMM_WR_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_WR_NEXT)
  242. #define SMIC_CC_SMM_WR_END (SMIC_CONTROL|SMIC_SMM|SMIC_WR_END)
  243. #define SMIC_CC_SMM_RD_START (SMIC_CONTROL|SMIC_SMM|SMIC_RD_START)
  244. #define SMIC_CC_SMM_RD_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_RD_NEXT)
  245. #define SMIC_CC_SMM_RD_END (SMIC_CONTROL|SMIC_SMM|SMIC_RD_END)
  246. /* SMIC Status Codes */
  247. #define SMIC_SC_SMS_READY (SMIC_STATUS|SMIC_SMS|SMIC_READY)
  248. #define SMIC_SC_SMS_WR_START (SMIC_STATUS|SMIC_SMS|SMIC_WR_START)
  249. #define SMIC_SC_SMS_WR_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_WR_NEXT)
  250. #define SMIC_SC_SMS_WR_END (SMIC_STATUS|SMIC_SMS|SMIC_WR_END)
  251. #define SMIC_SC_SMS_RD_START (SMIC_STATUS|SMIC_SMS|SMIC_RD_START)
  252. #define SMIC_SC_SMS_RD_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_RD_NEXT)
  253. #define SMIC_SC_SMS_RD_END (SMIC_STATUS|SMIC_SMS|SMIC_RD_END)
  254. #define SMIC_SC_SMM_READY (SMIC_STATUS|SMIC_SMM|SMIC_READY)
  255. #define SMIC_SC_SMM_WR_START (SMIC_STATUS|SMIC_SMM|SMIC_WR_START)
  256. #define SMIC_SC_SMM_WR_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_WR_NEXT)
  257. #define SMIC_SC_SMM_WR_END (SMIC_STATUS|SMIC_SMM|SMIC_WR_END)
  258. #define SMIC_SC_SMM_RD_START (SMIC_STATUS|SMIC_SMM|SMIC_RD_START)
  259. #define SMIC_SC_SMM_RD_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_RD_NEXT)
  260. #define SMIC_SC_SMM_RD_END (SMIC_STATUS|SMIC_SMM|SMIC_RD_END)
  261. /* these are the control/status codes we actually use
  262. SMIC_CC_SMS_GET_STATUS 0x40
  263. SMIC_CC_SMS_WR_START 0x41
  264. SMIC_CC_SMS_WR_NEXT 0x42
  265. SMIC_CC_SMS_WR_END 0x43
  266. SMIC_CC_SMS_RD_START 0x44
  267. SMIC_CC_SMS_RD_NEXT 0x45
  268. SMIC_CC_SMS_RD_END 0x46
  269. SMIC_SC_SMS_READY 0xC0
  270. SMIC_SC_SMS_WR_START 0xC1
  271. SMIC_SC_SMS_WR_NEXT 0xC2
  272. SMIC_SC_SMS_WR_END 0xC3
  273. SMIC_SC_SMS_RD_START 0xC4
  274. SMIC_SC_SMS_RD_NEXT 0xC5
  275. SMIC_SC_SMS_RD_END 0xC6
  276. */
  277. static enum si_sm_result smic_event(struct si_sm_data *smic, long time)
  278. {
  279. unsigned char status;
  280. unsigned char flags;
  281. unsigned char data;
  282. if (smic->state == SMIC_HOSED) {
  283. init_smic_data(smic, smic->io);
  284. return SI_SM_HOSED;
  285. }
  286. if (smic->state != SMIC_IDLE) {
  287. if (smic_debug & SMIC_DEBUG_STATES)
  288. printk(KERN_DEBUG
  289. "smic_event - smic->smic_timeout = %ld, time = %ld\n",
  290. smic->smic_timeout, time);
  291. /*
  292. * FIXME: smic_event is sometimes called with time >
  293. * SMIC_RETRY_TIMEOUT
  294. */
  295. if (time < SMIC_RETRY_TIMEOUT) {
  296. smic->smic_timeout -= time;
  297. if (smic->smic_timeout < 0) {
  298. start_error_recovery(smic, "smic timed out.");
  299. return SI_SM_CALL_WITH_DELAY;
  300. }
  301. }
  302. }
  303. flags = read_smic_flags(smic);
  304. if (flags & SMIC_FLAG_BSY)
  305. return SI_SM_CALL_WITH_DELAY;
  306. status = read_smic_status(smic);
  307. if (smic_debug & SMIC_DEBUG_STATES)
  308. printk(KERN_DEBUG "smic_event - state = %d, flags = 0x%02x, status = 0x%02x\n",
  309. smic->state, flags, status);
  310. switch (smic->state) {
  311. case SMIC_IDLE:
  312. /* in IDLE we check for available messages */
  313. if (flags & SMIC_SMS_DATA_AVAIL)
  314. return SI_SM_ATTN;
  315. return SI_SM_IDLE;
  316. case SMIC_START_OP:
  317. /* sanity check whether smic is really idle */
  318. write_smic_control(smic, SMIC_CC_SMS_GET_STATUS);
  319. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  320. smic->state = SMIC_OP_OK;
  321. break;
  322. case SMIC_OP_OK:
  323. if (status != SMIC_SC_SMS_READY) {
  324. /* this should not happen */
  325. start_error_recovery(smic,
  326. "state = SMIC_OP_OK,"
  327. " status != SMIC_SC_SMS_READY");
  328. return SI_SM_CALL_WITH_DELAY;
  329. }
  330. /* OK so far; smic is idle let us start ... */
  331. write_smic_control(smic, SMIC_CC_SMS_WR_START);
  332. write_next_byte(smic);
  333. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  334. smic->state = SMIC_WRITE_START;
  335. break;
  336. case SMIC_WRITE_START:
  337. if (status != SMIC_SC_SMS_WR_START) {
  338. start_error_recovery(smic,
  339. "state = SMIC_WRITE_START, "
  340. "status != SMIC_SC_SMS_WR_START");
  341. return SI_SM_CALL_WITH_DELAY;
  342. }
  343. /*
  344. * we must not issue WR_(NEXT|END) unless
  345. * TX_DATA_READY is set
  346. * */
  347. if (flags & SMIC_TX_DATA_READY) {
  348. if (smic->write_count == 1) {
  349. /* last byte */
  350. write_smic_control(smic, SMIC_CC_SMS_WR_END);
  351. smic->state = SMIC_WRITE_END;
  352. } else {
  353. write_smic_control(smic, SMIC_CC_SMS_WR_NEXT);
  354. smic->state = SMIC_WRITE_NEXT;
  355. }
  356. write_next_byte(smic);
  357. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  358. } else
  359. return SI_SM_CALL_WITH_DELAY;
  360. break;
  361. case SMIC_WRITE_NEXT:
  362. if (status != SMIC_SC_SMS_WR_NEXT) {
  363. start_error_recovery(smic,
  364. "state = SMIC_WRITE_NEXT, "
  365. "status != SMIC_SC_SMS_WR_NEXT");
  366. return SI_SM_CALL_WITH_DELAY;
  367. }
  368. /* this is the same code as in SMIC_WRITE_START */
  369. if (flags & SMIC_TX_DATA_READY) {
  370. if (smic->write_count == 1) {
  371. write_smic_control(smic, SMIC_CC_SMS_WR_END);
  372. smic->state = SMIC_WRITE_END;
  373. } else {
  374. write_smic_control(smic, SMIC_CC_SMS_WR_NEXT);
  375. smic->state = SMIC_WRITE_NEXT;
  376. }
  377. write_next_byte(smic);
  378. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  379. } else
  380. return SI_SM_CALL_WITH_DELAY;
  381. break;
  382. case SMIC_WRITE_END:
  383. if (status != SMIC_SC_SMS_WR_END) {
  384. start_error_recovery(smic,
  385. "state = SMIC_WRITE_END, "
  386. "status != SMIC_SC_SMS_WR_END");
  387. return SI_SM_CALL_WITH_DELAY;
  388. }
  389. /* data register holds an error code */
  390. data = read_smic_data(smic);
  391. if (data != 0) {
  392. if (smic_debug & SMIC_DEBUG_ENABLE)
  393. printk(KERN_DEBUG "SMIC_WRITE_END: data = %02x\n",
  394. data);
  395. start_error_recovery(smic,
  396. "state = SMIC_WRITE_END, "
  397. "data != SUCCESS");
  398. return SI_SM_CALL_WITH_DELAY;
  399. } else
  400. smic->state = SMIC_WRITE2READ;
  401. break;
  402. case SMIC_WRITE2READ:
  403. /*
  404. * we must wait for RX_DATA_READY to be set before we
  405. * can continue
  406. */
  407. if (flags & SMIC_RX_DATA_READY) {
  408. write_smic_control(smic, SMIC_CC_SMS_RD_START);
  409. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  410. smic->state = SMIC_READ_START;
  411. } else
  412. return SI_SM_CALL_WITH_DELAY;
  413. break;
  414. case SMIC_READ_START:
  415. if (status != SMIC_SC_SMS_RD_START) {
  416. start_error_recovery(smic,
  417. "state = SMIC_READ_START, "
  418. "status != SMIC_SC_SMS_RD_START");
  419. return SI_SM_CALL_WITH_DELAY;
  420. }
  421. if (flags & SMIC_RX_DATA_READY) {
  422. read_next_byte(smic);
  423. write_smic_control(smic, SMIC_CC_SMS_RD_NEXT);
  424. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  425. smic->state = SMIC_READ_NEXT;
  426. } else
  427. return SI_SM_CALL_WITH_DELAY;
  428. break;
  429. case SMIC_READ_NEXT:
  430. switch (status) {
  431. /*
  432. * smic tells us that this is the last byte to be read
  433. * --> clean up
  434. */
  435. case SMIC_SC_SMS_RD_END:
  436. read_next_byte(smic);
  437. write_smic_control(smic, SMIC_CC_SMS_RD_END);
  438. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  439. smic->state = SMIC_READ_END;
  440. break;
  441. case SMIC_SC_SMS_RD_NEXT:
  442. if (flags & SMIC_RX_DATA_READY) {
  443. read_next_byte(smic);
  444. write_smic_control(smic, SMIC_CC_SMS_RD_NEXT);
  445. write_smic_flags(smic, flags | SMIC_FLAG_BSY);
  446. smic->state = SMIC_READ_NEXT;
  447. } else
  448. return SI_SM_CALL_WITH_DELAY;
  449. break;
  450. default:
  451. start_error_recovery(
  452. smic,
  453. "state = SMIC_READ_NEXT, "
  454. "status != SMIC_SC_SMS_RD_(NEXT|END)");
  455. return SI_SM_CALL_WITH_DELAY;
  456. }
  457. break;
  458. case SMIC_READ_END:
  459. if (status != SMIC_SC_SMS_READY) {
  460. start_error_recovery(smic,
  461. "state = SMIC_READ_END, "
  462. "status != SMIC_SC_SMS_READY");
  463. return SI_SM_CALL_WITH_DELAY;
  464. }
  465. data = read_smic_data(smic);
  466. /* data register holds an error code */
  467. if (data != 0) {
  468. if (smic_debug & SMIC_DEBUG_ENABLE)
  469. printk(KERN_DEBUG "SMIC_READ_END: data = %02x\n",
  470. data);
  471. start_error_recovery(smic,
  472. "state = SMIC_READ_END, "
  473. "data != SUCCESS");
  474. return SI_SM_CALL_WITH_DELAY;
  475. } else {
  476. smic->state = SMIC_IDLE;
  477. return SI_SM_TRANSACTION_COMPLETE;
  478. }
  479. case SMIC_HOSED:
  480. init_smic_data(smic, smic->io);
  481. return SI_SM_HOSED;
  482. default:
  483. if (smic_debug & SMIC_DEBUG_ENABLE) {
  484. printk(KERN_DEBUG "smic->state = %d\n", smic->state);
  485. start_error_recovery(smic, "state = UNKNOWN");
  486. return SI_SM_CALL_WITH_DELAY;
  487. }
  488. }
  489. smic->smic_timeout = SMIC_RETRY_TIMEOUT;
  490. return SI_SM_CALL_WITHOUT_DELAY;
  491. }
  492. static int smic_detect(struct si_sm_data *smic)
  493. {
  494. /*
  495. * It's impossible for the SMIC fnags register to be all 1's,
  496. * (assuming a properly functioning, self-initialized BMC)
  497. * but that's what you get from reading a bogus address, so we
  498. * test that first.
  499. */
  500. if (read_smic_flags(smic) == 0xff)
  501. return 1;
  502. return 0;
  503. }
  504. static void smic_cleanup(struct si_sm_data *kcs)
  505. {
  506. }
  507. static int smic_size(void)
  508. {
  509. return sizeof(struct si_sm_data);
  510. }
  511. const struct si_sm_handlers smic_smi_handlers = {
  512. .init_data = init_smic_data,
  513. .start_transaction = start_smic_transaction,
  514. .get_result = smic_get_result,
  515. .event = smic_event,
  516. .detect = smic_detect,
  517. .cleanup = smic_cleanup,
  518. .size = smic_size,
  519. };