ipmi_smic_sm.c 16 KB

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