ipmi_smic_sm.c 16 KB

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