Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus-6.3-1' of https://github.com/cminyard/linux-ipmi

Pull IPMI updates from Corey Minyard:
"Small fixes to the SMBus IPMI and IPMB driver.

Nothing big, cleanups, fixing names, and one small deviation from the
specification fixed"

* tag 'for-linus-6.3-1' of https://github.com/cminyard/linux-ipmi:
ipmi: ipmb: Fix the MODULE_PARM_DESC associated to 'retry_time_ms'
ipmi:ssif: Add a timer between request retries
ipmi:ssif: Remove rtc_us_timer
ipmi_ssif: Rename idle state and check
ipmi:ssif: resend_msg() cannot fail

+56 -59
+1 -1
drivers/char/ipmi/ipmi_ipmb.c
··· 27 27 28 28 static unsigned int retry_time_ms = 250; 29 29 module_param(retry_time_ms, uint, 0644); 30 - MODULE_PARM_DESC(max_retries, "Timeout time between retries, in milliseconds."); 30 + MODULE_PARM_DESC(retry_time_ms, "Timeout time between retries, in milliseconds."); 31 31 32 32 static unsigned int max_retries = 1; 33 33 module_param(max_retries, uint, 0644);
+55 -58
drivers/char/ipmi/ipmi_ssif.c
··· 74 74 /* 75 75 * Timer values 76 76 */ 77 - #define SSIF_MSG_USEC 60000 /* 60ms between message tries. */ 77 + #define SSIF_MSG_USEC 60000 /* 60ms between message tries (T3). */ 78 + #define SSIF_REQ_RETRY_USEC 60000 /* 60ms between send retries (T6). */ 78 79 #define SSIF_MSG_PART_USEC 5000 /* 5ms for a message part */ 79 80 80 81 /* How many times to we retry sending/receiving the message. */ ··· 83 82 #define SSIF_RECV_RETRIES 250 84 83 85 84 #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000) 85 + #define SSIF_REQ_RETRY_MSEC (SSIF_REQ_RETRY_USEC / 1000) 86 86 #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC) 87 + #define SSIF_REQ_RETRY_JIFFIES ((SSIF_REQ_RETRY_USEC * 1000) / TICK_NSEC) 87 88 #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC) 88 89 89 90 /* ··· 95 92 #define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250) 96 93 97 94 enum ssif_intf_state { 98 - SSIF_NORMAL, 95 + SSIF_IDLE, 99 96 SSIF_GETTING_FLAGS, 100 97 SSIF_GETTING_EVENTS, 101 98 SSIF_CLEARING_FLAGS, ··· 103 100 /* FIXME - add watchdog stuff. */ 104 101 }; 105 102 106 - #define SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_NORMAL \ 107 - && (ssif)->curr_msg == NULL) 103 + #define IS_SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_IDLE \ 104 + && (ssif)->curr_msg == NULL) 108 105 109 106 /* 110 107 * Indexes into stats[] in ssif_info below. ··· 232 229 bool got_alert; 233 230 bool waiting_alert; 234 231 232 + /* Used to inform the timeout that it should do a resend. */ 233 + bool do_resend; 234 + 235 235 /* 236 236 * If set to true, this will request events the next time the 237 237 * state machine is idle. ··· 246 240 * state machine is idle. 247 241 */ 248 242 bool req_flags; 249 - 250 - /* 251 - * Used to perform timer operations when run-to-completion 252 - * mode is on. This is a countdown timer. 253 - */ 254 - int rtc_us_timer; 255 243 256 244 /* Used for sending/receiving data. +1 for the length. */ 257 245 unsigned char data[IPMI_MAX_MSG_LENGTH + 1]; ··· 348 348 349 349 /* 350 350 * Must be called with the message lock held. This will release the 351 - * message lock. Note that the caller will check SSIF_IDLE and start a 352 - * new operation, so there is no need to check for new messages to 353 - * start in here. 351 + * message lock. Note that the caller will check IS_SSIF_IDLE and 352 + * start a new operation, so there is no need to check for new 353 + * messages to start in here. 354 354 */ 355 355 static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags) 356 356 { ··· 367 367 368 368 if (start_send(ssif_info, msg, 3) != 0) { 369 369 /* Error, just go to normal state. */ 370 - ssif_info->ssif_state = SSIF_NORMAL; 370 + ssif_info->ssif_state = SSIF_IDLE; 371 371 } 372 372 } 373 373 ··· 382 382 mb[0] = (IPMI_NETFN_APP_REQUEST << 2); 383 383 mb[1] = IPMI_GET_MSG_FLAGS_CMD; 384 384 if (start_send(ssif_info, mb, 2) != 0) 385 - ssif_info->ssif_state = SSIF_NORMAL; 385 + ssif_info->ssif_state = SSIF_IDLE; 386 386 } 387 387 388 388 static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags, ··· 393 393 394 394 flags = ipmi_ssif_lock_cond(ssif_info, &oflags); 395 395 ssif_info->curr_msg = NULL; 396 - ssif_info->ssif_state = SSIF_NORMAL; 396 + ssif_info->ssif_state = SSIF_IDLE; 397 397 ipmi_ssif_unlock_cond(ssif_info, flags); 398 398 ipmi_free_smi_msg(msg); 399 399 } ··· 407 407 408 408 msg = ipmi_alloc_smi_msg(); 409 409 if (!msg) { 410 - ssif_info->ssif_state = SSIF_NORMAL; 410 + ssif_info->ssif_state = SSIF_IDLE; 411 411 ipmi_ssif_unlock_cond(ssif_info, flags); 412 412 return; 413 413 } ··· 430 430 431 431 msg = ipmi_alloc_smi_msg(); 432 432 if (!msg) { 433 - ssif_info->ssif_state = SSIF_NORMAL; 433 + ssif_info->ssif_state = SSIF_IDLE; 434 434 ipmi_ssif_unlock_cond(ssif_info, flags); 435 435 return; 436 436 } ··· 448 448 449 449 /* 450 450 * Must be called with the message lock held. This will release the 451 - * message lock. Note that the caller will check SSIF_IDLE and start a 452 - * new operation, so there is no need to check for new messages to 453 - * start in here. 451 + * message lock. Note that the caller will check IS_SSIF_IDLE and 452 + * start a new operation, so there is no need to check for new 453 + * messages to start in here. 454 454 */ 455 455 static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags) 456 456 { ··· 466 466 /* Events available. */ 467 467 start_event_fetch(ssif_info, flags); 468 468 else { 469 - ssif_info->ssif_state = SSIF_NORMAL; 469 + ssif_info->ssif_state = SSIF_IDLE; 470 470 ipmi_ssif_unlock_cond(ssif_info, flags); 471 471 } 472 472 } ··· 530 530 531 531 static void start_get(struct ssif_info *ssif_info) 532 532 { 533 - ssif_info->rtc_us_timer = 0; 534 533 ssif_info->multi_pos = 0; 535 534 536 535 ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, ··· 537 538 ssif_info->recv, I2C_SMBUS_BLOCK_DATA); 538 539 } 539 540 541 + static void start_resend(struct ssif_info *ssif_info); 542 + 540 543 static void retry_timeout(struct timer_list *t) 541 544 { 542 545 struct ssif_info *ssif_info = from_timer(ssif_info, t, retry_timer); 543 546 unsigned long oflags, *flags; 544 - bool waiting; 547 + bool waiting, resend; 545 548 546 549 if (ssif_info->stopping) 547 550 return; 548 551 549 552 flags = ipmi_ssif_lock_cond(ssif_info, &oflags); 553 + resend = ssif_info->do_resend; 554 + ssif_info->do_resend = false; 550 555 waiting = ssif_info->waiting_alert; 551 556 ssif_info->waiting_alert = false; 552 557 ipmi_ssif_unlock_cond(ssif_info, flags); 553 558 554 559 if (waiting) 555 560 start_get(ssif_info); 561 + if (resend) 562 + start_resend(ssif_info); 556 563 } 557 564 558 565 static void watch_timeout(struct timer_list *t) ··· 573 568 if (ssif_info->watch_timeout) { 574 569 mod_timer(&ssif_info->watch_timer, 575 570 jiffies + ssif_info->watch_timeout); 576 - if (SSIF_IDLE(ssif_info)) { 571 + if (IS_SSIF_IDLE(ssif_info)) { 577 572 start_flag_fetch(ssif_info, flags); /* Releases lock */ 578 573 return; 579 574 } ··· 607 602 start_get(ssif_info); 608 603 } 609 604 610 - static int start_resend(struct ssif_info *ssif_info); 611 - 612 605 static void msg_done_handler(struct ssif_info *ssif_info, int result, 613 606 unsigned char *data, unsigned int len) 614 607 { ··· 625 622 626 623 flags = ipmi_ssif_lock_cond(ssif_info, &oflags); 627 624 ssif_info->waiting_alert = true; 628 - ssif_info->rtc_us_timer = SSIF_MSG_USEC; 629 625 if (!ssif_info->stopping) 630 626 mod_timer(&ssif_info->retry_timer, 631 627 jiffies + SSIF_MSG_JIFFIES); ··· 758 756 } 759 757 760 758 switch (ssif_info->ssif_state) { 761 - case SSIF_NORMAL: 759 + case SSIF_IDLE: 762 760 ipmi_ssif_unlock_cond(ssif_info, flags); 763 761 if (!msg) 764 762 break; ··· 776 774 * Error fetching flags, or invalid length, 777 775 * just give up for now. 778 776 */ 779 - ssif_info->ssif_state = SSIF_NORMAL; 777 + ssif_info->ssif_state = SSIF_IDLE; 780 778 ipmi_ssif_unlock_cond(ssif_info, flags); 781 779 dev_warn(&ssif_info->client->dev, 782 780 "Error getting flags: %d %d, %x\n", ··· 811 809 "Invalid response clearing flags: %x %x\n", 812 810 data[0], data[1]); 813 811 } 814 - ssif_info->ssif_state = SSIF_NORMAL; 812 + ssif_info->ssif_state = SSIF_IDLE; 815 813 ipmi_ssif_unlock_cond(ssif_info, flags); 816 814 break; 817 815 ··· 889 887 } 890 888 891 889 flags = ipmi_ssif_lock_cond(ssif_info, &oflags); 892 - if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) { 890 + if (IS_SSIF_IDLE(ssif_info) && !ssif_info->stopping) { 893 891 if (ssif_info->req_events) 894 892 start_event_fetch(ssif_info, flags); 895 893 else if (ssif_info->req_flags) ··· 911 909 if (result < 0) { 912 910 ssif_info->retries_left--; 913 911 if (ssif_info->retries_left > 0) { 914 - if (!start_resend(ssif_info)) { 915 - ssif_inc_stat(ssif_info, send_retries); 916 - return; 917 - } 918 - /* request failed, just return the error. */ 919 - ssif_inc_stat(ssif_info, send_errors); 920 - 921 - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) 922 - dev_dbg(&ssif_info->client->dev, 923 - "%s: Out of retries\n", __func__); 924 - msg_done_handler(ssif_info, -EIO, NULL, 0); 912 + /* 913 + * Wait the retry timeout time per the spec, 914 + * then redo the send. 915 + */ 916 + ssif_info->do_resend = true; 917 + mod_timer(&ssif_info->retry_timer, 918 + jiffies + SSIF_REQ_RETRY_JIFFIES); 925 919 return; 926 920 } 927 921 928 922 ssif_inc_stat(ssif_info, send_errors); 929 923 930 - /* 931 - * Got an error on transmit, let the done routine 932 - * handle it. 933 - */ 934 924 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) 935 925 dev_dbg(&ssif_info->client->dev, 936 - "%s: Error %d\n", __func__, result); 926 + "%s: Out of retries\n", __func__); 937 927 938 - msg_done_handler(ssif_info, result, NULL, 0); 928 + msg_done_handler(ssif_info, -EIO, NULL, 0); 939 929 return; 940 930 } 941 931 ··· 981 987 /* Wait a jiffie then request the next message */ 982 988 ssif_info->waiting_alert = true; 983 989 ssif_info->retries_left = SSIF_RECV_RETRIES; 984 - ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC; 985 990 if (!ssif_info->stopping) 986 991 mod_timer(&ssif_info->retry_timer, 987 992 jiffies + SSIF_MSG_PART_JIFFIES); ··· 989 996 } 990 997 } 991 998 992 - static int start_resend(struct ssif_info *ssif_info) 999 + static void start_resend(struct ssif_info *ssif_info) 993 1000 { 994 1001 int command; 995 1002 ··· 1014 1021 1015 1022 ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE, 1016 1023 command, ssif_info->data, I2C_SMBUS_BLOCK_DATA); 1017 - return 0; 1018 1024 } 1019 1025 1020 1026 static int start_send(struct ssif_info *ssif_info, ··· 1028 1036 ssif_info->retries_left = SSIF_SEND_RETRIES; 1029 1037 memcpy(ssif_info->data + 1, data, len); 1030 1038 ssif_info->data_len = len; 1031 - return start_resend(ssif_info); 1039 + start_resend(ssif_info); 1040 + return 0; 1032 1041 } 1033 1042 1034 1043 /* Must be called with the message lock held. */ ··· 1039 1046 unsigned long oflags; 1040 1047 1041 1048 restart: 1042 - if (!SSIF_IDLE(ssif_info)) { 1049 + if (!IS_SSIF_IDLE(ssif_info)) { 1043 1050 ipmi_ssif_unlock_cond(ssif_info, flags); 1044 1051 return; 1045 1052 } ··· 1262 1269 dev_set_drvdata(&ssif_info->client->dev, NULL); 1263 1270 1264 1271 /* make sure the driver is not looking for flags any more. */ 1265 - while (ssif_info->ssif_state != SSIF_NORMAL) 1272 + while (ssif_info->ssif_state != SSIF_IDLE) 1266 1273 schedule_timeout(1); 1267 1274 1268 1275 ssif_info->stopping = true; ··· 1327 1334 ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg); 1328 1335 if (ret) { 1329 1336 retry_cnt--; 1330 - if (retry_cnt > 0) 1337 + if (retry_cnt > 0) { 1338 + msleep(SSIF_REQ_RETRY_MSEC); 1331 1339 goto retry1; 1340 + } 1332 1341 return -ENODEV; 1333 1342 } 1334 1343 ··· 1471 1476 32, msg); 1472 1477 if (ret) { 1473 1478 retry_cnt--; 1474 - if (retry_cnt > 0) 1479 + if (retry_cnt > 0) { 1480 + msleep(SSIF_REQ_RETRY_MSEC); 1475 1481 goto retry_write; 1482 + } 1476 1483 dev_err(&client->dev, "Could not write multi-part start, though the BMC said it could handle it. Just limit sends to one part.\n"); 1477 1484 return ret; 1478 1485 } ··· 1836 1839 } 1837 1840 1838 1841 spin_lock_init(&ssif_info->lock); 1839 - ssif_info->ssif_state = SSIF_NORMAL; 1842 + ssif_info->ssif_state = SSIF_IDLE; 1840 1843 timer_setup(&ssif_info->retry_timer, retry_timeout, 0); 1841 1844 timer_setup(&ssif_info->watch_timer, watch_timeout, 0); 1842 1845