| .. | .. |
|---|
| 22 | 22 | * and drives the real SSIF state machine. |
|---|
| 23 | 23 | */ |
|---|
| 24 | 24 | |
|---|
| 25 | | -/* |
|---|
| 26 | | - * TODO: Figure out how to use SMB alerts. This will require a new |
|---|
| 27 | | - * interface into the I2C driver, I believe. |
|---|
| 28 | | - */ |
|---|
| 25 | +#define pr_fmt(fmt) "ipmi_ssif: " fmt |
|---|
| 26 | +#define dev_fmt(fmt) "ipmi_ssif: " fmt |
|---|
| 29 | 27 | |
|---|
| 30 | 28 | #if defined(MODVERSIONS) |
|---|
| 31 | 29 | #include <linux/modversions.h> |
|---|
| .. | .. |
|---|
| 49 | 47 | #include <linux/acpi.h> |
|---|
| 50 | 48 | #include <linux/ctype.h> |
|---|
| 51 | 49 | #include <linux/time64.h> |
|---|
| 52 | | -#include "ipmi_si_sm.h" |
|---|
| 53 | 50 | #include "ipmi_dmi.h" |
|---|
| 54 | 51 | |
|---|
| 55 | | -#define PFX "ipmi_ssif: " |
|---|
| 56 | 52 | #define DEVICE_NAME "ipmi_ssif" |
|---|
| 57 | 53 | |
|---|
| 58 | 54 | #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD 0x57 |
|---|
| .. | .. |
|---|
| 60 | 56 | #define SSIF_IPMI_REQUEST 2 |
|---|
| 61 | 57 | #define SSIF_IPMI_MULTI_PART_REQUEST_START 6 |
|---|
| 62 | 58 | #define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7 |
|---|
| 59 | +#define SSIF_IPMI_MULTI_PART_REQUEST_END 8 |
|---|
| 63 | 60 | #define SSIF_IPMI_RESPONSE 3 |
|---|
| 64 | 61 | #define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9 |
|---|
| 65 | 62 | |
|---|
| .. | .. |
|---|
| 77 | 74 | /* |
|---|
| 78 | 75 | * Timer values |
|---|
| 79 | 76 | */ |
|---|
| 80 | | -#define SSIF_MSG_USEC 20000 /* 20ms 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). */ |
|---|
| 81 | 79 | #define SSIF_MSG_PART_USEC 5000 /* 5ms for a message part */ |
|---|
| 82 | 80 | |
|---|
| 83 | 81 | /* How many times to we retry sending/receiving the message. */ |
|---|
| .. | .. |
|---|
| 85 | 83 | #define SSIF_RECV_RETRIES 250 |
|---|
| 86 | 84 | |
|---|
| 87 | 85 | #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000) |
|---|
| 86 | +#define SSIF_REQ_RETRY_MSEC (SSIF_REQ_RETRY_USEC / 1000) |
|---|
| 88 | 87 | #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC) |
|---|
| 88 | +#define SSIF_REQ_RETRY_JIFFIES ((SSIF_REQ_RETRY_USEC * 1000) / TICK_NSEC) |
|---|
| 89 | 89 | #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC) |
|---|
| 90 | 90 | |
|---|
| 91 | +/* |
|---|
| 92 | + * Timeout for the watch, only used for get flag timer. |
|---|
| 93 | + */ |
|---|
| 94 | +#define SSIF_WATCH_MSG_TIMEOUT msecs_to_jiffies(10) |
|---|
| 95 | +#define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250) |
|---|
| 96 | + |
|---|
| 91 | 97 | enum ssif_intf_state { |
|---|
| 92 | | - SSIF_NORMAL, |
|---|
| 98 | + SSIF_IDLE, |
|---|
| 93 | 99 | SSIF_GETTING_FLAGS, |
|---|
| 94 | 100 | SSIF_GETTING_EVENTS, |
|---|
| 95 | 101 | SSIF_CLEARING_FLAGS, |
|---|
| .. | .. |
|---|
| 97 | 103 | /* FIXME - add watchdog stuff. */ |
|---|
| 98 | 104 | }; |
|---|
| 99 | 105 | |
|---|
| 100 | | -#define SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_NORMAL \ |
|---|
| 101 | | - && (ssif)->curr_msg == NULL) |
|---|
| 106 | +#define IS_SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_IDLE \ |
|---|
| 107 | + && (ssif)->curr_msg == NULL) |
|---|
| 102 | 108 | |
|---|
| 103 | 109 | /* |
|---|
| 104 | 110 | * Indexes into stats[] in ssif_info below. |
|---|
| .. | .. |
|---|
| 181 | 187 | struct device *dev; |
|---|
| 182 | 188 | struct i2c_client *client; |
|---|
| 183 | 189 | |
|---|
| 184 | | - struct i2c_client *added_client; |
|---|
| 185 | | - |
|---|
| 186 | 190 | struct mutex clients_mutex; |
|---|
| 187 | 191 | struct list_head clients; |
|---|
| 188 | 192 | |
|---|
| .. | .. |
|---|
| 228 | 232 | bool got_alert; |
|---|
| 229 | 233 | bool waiting_alert; |
|---|
| 230 | 234 | |
|---|
| 235 | + /* Used to inform the timeout that it should do a resend. */ |
|---|
| 236 | + bool do_resend; |
|---|
| 237 | + |
|---|
| 231 | 238 | /* |
|---|
| 232 | 239 | * If set to true, this will request events the next time the |
|---|
| 233 | 240 | * state machine is idle. |
|---|
| .. | .. |
|---|
| 268 | 275 | struct timer_list retry_timer; |
|---|
| 269 | 276 | int retries_left; |
|---|
| 270 | 277 | |
|---|
| 278 | + long watch_timeout; /* Timeout for flags check, 0 if off. */ |
|---|
| 279 | + struct timer_list watch_timer; /* Flag fetch timer. */ |
|---|
| 280 | + |
|---|
| 271 | 281 | /* Info from SSIF cmd */ |
|---|
| 272 | 282 | unsigned char max_xmit_msg_size; |
|---|
| 273 | 283 | unsigned char max_recv_msg_size; |
|---|
| 284 | + bool cmd8_works; /* See test_multipart_messages() for details. */ |
|---|
| 274 | 285 | unsigned int multi_support; |
|---|
| 275 | 286 | int supports_pec; |
|---|
| 276 | 287 | |
|---|
| .. | .. |
|---|
| 290 | 301 | ((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat])) |
|---|
| 291 | 302 | |
|---|
| 292 | 303 | static bool initialized; |
|---|
| 304 | +static bool platform_registered; |
|---|
| 293 | 305 | |
|---|
| 294 | 306 | static void return_hosed_msg(struct ssif_info *ssif_info, |
|---|
| 295 | 307 | struct ipmi_smi_msg *msg); |
|---|
| .. | .. |
|---|
| 300 | 312 | |
|---|
| 301 | 313 | static unsigned long *ipmi_ssif_lock_cond(struct ssif_info *ssif_info, |
|---|
| 302 | 314 | unsigned long *flags) |
|---|
| 315 | + __acquires(&ssif_info->lock) |
|---|
| 303 | 316 | { |
|---|
| 304 | 317 | spin_lock_irqsave(&ssif_info->lock, *flags); |
|---|
| 305 | 318 | return flags; |
|---|
| .. | .. |
|---|
| 307 | 320 | |
|---|
| 308 | 321 | static void ipmi_ssif_unlock_cond(struct ssif_info *ssif_info, |
|---|
| 309 | 322 | unsigned long *flags) |
|---|
| 323 | + __releases(&ssif_info->lock) |
|---|
| 310 | 324 | { |
|---|
| 311 | 325 | spin_unlock_irqrestore(&ssif_info->lock, *flags); |
|---|
| 312 | 326 | } |
|---|
| .. | .. |
|---|
| 316 | 330 | { |
|---|
| 317 | 331 | if (msg->rsp_size < 0) { |
|---|
| 318 | 332 | return_hosed_msg(ssif_info, msg); |
|---|
| 319 | | - pr_err(PFX |
|---|
| 320 | | - "Malformed message in deliver_recv_msg: rsp_size = %d\n", |
|---|
| 321 | | - msg->rsp_size); |
|---|
| 333 | + dev_err(&ssif_info->client->dev, |
|---|
| 334 | + "%s: Malformed message: rsp_size = %d\n", |
|---|
| 335 | + __func__, msg->rsp_size); |
|---|
| 322 | 336 | } else { |
|---|
| 323 | 337 | ipmi_smi_msg_received(ssif_info->intf, msg); |
|---|
| 324 | 338 | } |
|---|
| .. | .. |
|---|
| 340 | 354 | |
|---|
| 341 | 355 | /* |
|---|
| 342 | 356 | * Must be called with the message lock held. This will release the |
|---|
| 343 | | - * message lock. Note that the caller will check SSIF_IDLE and start a |
|---|
| 344 | | - * new operation, so there is no need to check for new messages to |
|---|
| 345 | | - * start in here. |
|---|
| 357 | + * message lock. Note that the caller will check IS_SSIF_IDLE and |
|---|
| 358 | + * start a new operation, so there is no need to check for new |
|---|
| 359 | + * messages to start in here. |
|---|
| 346 | 360 | */ |
|---|
| 347 | 361 | static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags) |
|---|
| 348 | 362 | { |
|---|
| .. | .. |
|---|
| 359 | 373 | |
|---|
| 360 | 374 | if (start_send(ssif_info, msg, 3) != 0) { |
|---|
| 361 | 375 | /* Error, just go to normal state. */ |
|---|
| 362 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 376 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 363 | 377 | } |
|---|
| 364 | 378 | } |
|---|
| 365 | 379 | |
|---|
| .. | .. |
|---|
| 374 | 388 | mb[0] = (IPMI_NETFN_APP_REQUEST << 2); |
|---|
| 375 | 389 | mb[1] = IPMI_GET_MSG_FLAGS_CMD; |
|---|
| 376 | 390 | if (start_send(ssif_info, mb, 2) != 0) |
|---|
| 377 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 391 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 378 | 392 | } |
|---|
| 379 | 393 | |
|---|
| 380 | 394 | static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags, |
|---|
| .. | .. |
|---|
| 385 | 399 | |
|---|
| 386 | 400 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 387 | 401 | ssif_info->curr_msg = NULL; |
|---|
| 388 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 402 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 389 | 403 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 390 | 404 | ipmi_free_smi_msg(msg); |
|---|
| 391 | 405 | } |
|---|
| .. | .. |
|---|
| 399 | 413 | |
|---|
| 400 | 414 | msg = ipmi_alloc_smi_msg(); |
|---|
| 401 | 415 | if (!msg) { |
|---|
| 402 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 416 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 403 | 417 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 404 | 418 | return; |
|---|
| 405 | 419 | } |
|---|
| .. | .. |
|---|
| 422 | 436 | |
|---|
| 423 | 437 | msg = ipmi_alloc_smi_msg(); |
|---|
| 424 | 438 | if (!msg) { |
|---|
| 425 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 439 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 426 | 440 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 427 | 441 | return; |
|---|
| 428 | 442 | } |
|---|
| .. | .. |
|---|
| 440 | 454 | |
|---|
| 441 | 455 | /* |
|---|
| 442 | 456 | * Must be called with the message lock held. This will release the |
|---|
| 443 | | - * message lock. Note that the caller will check SSIF_IDLE and start a |
|---|
| 444 | | - * new operation, so there is no need to check for new messages to |
|---|
| 445 | | - * start in here. |
|---|
| 457 | + * message lock. Note that the caller will check IS_SSIF_IDLE and |
|---|
| 458 | + * start a new operation, so there is no need to check for new |
|---|
| 459 | + * messages to start in here. |
|---|
| 446 | 460 | */ |
|---|
| 447 | 461 | static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags) |
|---|
| 448 | 462 | { |
|---|
| .. | .. |
|---|
| 458 | 472 | /* Events available. */ |
|---|
| 459 | 473 | start_event_fetch(ssif_info, flags); |
|---|
| 460 | 474 | else { |
|---|
| 461 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 475 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 462 | 476 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 463 | 477 | } |
|---|
| 464 | 478 | } |
|---|
| .. | .. |
|---|
| 502 | 516 | return 0; |
|---|
| 503 | 517 | } |
|---|
| 504 | 518 | |
|---|
| 505 | | -static int ssif_i2c_send(struct ssif_info *ssif_info, |
|---|
| 519 | +static void ssif_i2c_send(struct ssif_info *ssif_info, |
|---|
| 506 | 520 | ssif_i2c_done handler, |
|---|
| 507 | 521 | int read_write, int command, |
|---|
| 508 | 522 | unsigned char *data, unsigned int size) |
|---|
| .. | .. |
|---|
| 514 | 528 | ssif_info->i2c_data = data; |
|---|
| 515 | 529 | ssif_info->i2c_size = size; |
|---|
| 516 | 530 | complete(&ssif_info->wake_thread); |
|---|
| 517 | | - return 0; |
|---|
| 518 | 531 | } |
|---|
| 519 | 532 | |
|---|
| 520 | 533 | |
|---|
| .. | .. |
|---|
| 523 | 536 | |
|---|
| 524 | 537 | static void start_get(struct ssif_info *ssif_info) |
|---|
| 525 | 538 | { |
|---|
| 526 | | - int rv; |
|---|
| 527 | | - |
|---|
| 528 | 539 | ssif_info->rtc_us_timer = 0; |
|---|
| 529 | 540 | ssif_info->multi_pos = 0; |
|---|
| 530 | 541 | |
|---|
| 531 | | - rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, |
|---|
| 532 | | - SSIF_IPMI_RESPONSE, |
|---|
| 533 | | - ssif_info->recv, I2C_SMBUS_BLOCK_DATA); |
|---|
| 534 | | - if (rv < 0) { |
|---|
| 535 | | - /* request failed, just return the error. */ |
|---|
| 536 | | - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 537 | | - pr_info("Error from i2c_non_blocking_op(5)\n"); |
|---|
| 538 | | - |
|---|
| 539 | | - msg_done_handler(ssif_info, -EIO, NULL, 0); |
|---|
| 540 | | - } |
|---|
| 542 | + ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, |
|---|
| 543 | + SSIF_IPMI_RESPONSE, |
|---|
| 544 | + ssif_info->recv, I2C_SMBUS_BLOCK_DATA); |
|---|
| 541 | 545 | } |
|---|
| 546 | + |
|---|
| 547 | +static void start_resend(struct ssif_info *ssif_info); |
|---|
| 542 | 548 | |
|---|
| 543 | 549 | static void retry_timeout(struct timer_list *t) |
|---|
| 544 | 550 | { |
|---|
| 545 | 551 | struct ssif_info *ssif_info = from_timer(ssif_info, t, retry_timer); |
|---|
| 546 | 552 | unsigned long oflags, *flags; |
|---|
| 547 | | - bool waiting; |
|---|
| 553 | + bool waiting, resend; |
|---|
| 548 | 554 | |
|---|
| 549 | 555 | if (ssif_info->stopping) |
|---|
| 550 | 556 | return; |
|---|
| 551 | 557 | |
|---|
| 552 | 558 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 559 | + resend = ssif_info->do_resend; |
|---|
| 560 | + ssif_info->do_resend = false; |
|---|
| 553 | 561 | waiting = ssif_info->waiting_alert; |
|---|
| 554 | 562 | ssif_info->waiting_alert = false; |
|---|
| 555 | 563 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 556 | 564 | |
|---|
| 557 | 565 | if (waiting) |
|---|
| 558 | 566 | start_get(ssif_info); |
|---|
| 567 | + if (resend) { |
|---|
| 568 | + start_resend(ssif_info); |
|---|
| 569 | + ssif_inc_stat(ssif_info, send_retries); |
|---|
| 570 | + } |
|---|
| 559 | 571 | } |
|---|
| 560 | 572 | |
|---|
| 573 | +static void watch_timeout(struct timer_list *t) |
|---|
| 574 | +{ |
|---|
| 575 | + struct ssif_info *ssif_info = from_timer(ssif_info, t, watch_timer); |
|---|
| 576 | + unsigned long oflags, *flags; |
|---|
| 577 | + |
|---|
| 578 | + if (ssif_info->stopping) |
|---|
| 579 | + return; |
|---|
| 580 | + |
|---|
| 581 | + flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 582 | + if (ssif_info->watch_timeout) { |
|---|
| 583 | + mod_timer(&ssif_info->watch_timer, |
|---|
| 584 | + jiffies + ssif_info->watch_timeout); |
|---|
| 585 | + if (IS_SSIF_IDLE(ssif_info)) { |
|---|
| 586 | + start_flag_fetch(ssif_info, flags); /* Releases lock */ |
|---|
| 587 | + return; |
|---|
| 588 | + } |
|---|
| 589 | + ssif_info->req_flags = true; |
|---|
| 590 | + } |
|---|
| 591 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 592 | +} |
|---|
| 561 | 593 | |
|---|
| 562 | 594 | static void ssif_alert(struct i2c_client *client, enum i2c_alert_protocol type, |
|---|
| 563 | 595 | unsigned int data) |
|---|
| .. | .. |
|---|
| 584 | 616 | start_get(ssif_info); |
|---|
| 585 | 617 | } |
|---|
| 586 | 618 | |
|---|
| 587 | | -static int start_resend(struct ssif_info *ssif_info); |
|---|
| 588 | | - |
|---|
| 589 | 619 | static void msg_done_handler(struct ssif_info *ssif_info, int result, |
|---|
| 590 | 620 | unsigned char *data, unsigned int len) |
|---|
| 591 | 621 | { |
|---|
| 592 | 622 | struct ipmi_smi_msg *msg; |
|---|
| 593 | 623 | unsigned long oflags, *flags; |
|---|
| 594 | | - int rv; |
|---|
| 595 | 624 | |
|---|
| 596 | 625 | /* |
|---|
| 597 | 626 | * We are single-threaded here, so no need for a lock until we |
|---|
| .. | .. |
|---|
| 616 | 645 | ssif_inc_stat(ssif_info, receive_errors); |
|---|
| 617 | 646 | |
|---|
| 618 | 647 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 619 | | - pr_info("Error in msg_done_handler: %d\n", result); |
|---|
| 648 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 649 | + "%s: Error %d\n", __func__, result); |
|---|
| 620 | 650 | len = 0; |
|---|
| 621 | 651 | goto continue_op; |
|---|
| 622 | 652 | } |
|---|
| .. | .. |
|---|
| 636 | 666 | ssif_info->multi_len = len; |
|---|
| 637 | 667 | ssif_info->multi_pos = 1; |
|---|
| 638 | 668 | |
|---|
| 639 | | - rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, |
|---|
| 640 | | - SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE, |
|---|
| 641 | | - ssif_info->recv, I2C_SMBUS_BLOCK_DATA); |
|---|
| 642 | | - if (rv < 0) { |
|---|
| 643 | | - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 644 | | - pr_info("Error from i2c_non_blocking_op(1)\n"); |
|---|
| 645 | | - |
|---|
| 646 | | - result = -EIO; |
|---|
| 647 | | - } else |
|---|
| 648 | | - return; |
|---|
| 669 | + ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ, |
|---|
| 670 | + SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE, |
|---|
| 671 | + ssif_info->recv, I2C_SMBUS_BLOCK_DATA); |
|---|
| 672 | + return; |
|---|
| 649 | 673 | } else if (ssif_info->multi_pos) { |
|---|
| 650 | 674 | /* Middle of multi-part read. Start the next transaction. */ |
|---|
| 651 | 675 | int i; |
|---|
| .. | .. |
|---|
| 654 | 678 | if (len == 0) { |
|---|
| 655 | 679 | result = -EIO; |
|---|
| 656 | 680 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 657 | | - pr_info(PFX "Middle message with no data\n"); |
|---|
| 681 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 682 | + "Middle message with no data\n"); |
|---|
| 658 | 683 | |
|---|
| 659 | 684 | goto continue_op; |
|---|
| 660 | 685 | } |
|---|
| .. | .. |
|---|
| 667 | 692 | /* All blocks but the last must have 31 data bytes. */ |
|---|
| 668 | 693 | result = -EIO; |
|---|
| 669 | 694 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 670 | | - pr_info("Received middle message <31\n"); |
|---|
| 695 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 696 | + "Received middle message <31\n"); |
|---|
| 671 | 697 | |
|---|
| 672 | 698 | goto continue_op; |
|---|
| 673 | 699 | } |
|---|
| .. | .. |
|---|
| 676 | 702 | /* Received message too big, abort the operation. */ |
|---|
| 677 | 703 | result = -E2BIG; |
|---|
| 678 | 704 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 679 | | - pr_info("Received message too big\n"); |
|---|
| 705 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 706 | + "Received message too big\n"); |
|---|
| 680 | 707 | |
|---|
| 681 | 708 | goto continue_op; |
|---|
| 682 | 709 | } |
|---|
| .. | .. |
|---|
| 704 | 731 | |
|---|
| 705 | 732 | ssif_info->multi_pos++; |
|---|
| 706 | 733 | |
|---|
| 707 | | - rv = ssif_i2c_send(ssif_info, msg_done_handler, |
|---|
| 708 | | - I2C_SMBUS_READ, |
|---|
| 709 | | - SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE, |
|---|
| 710 | | - ssif_info->recv, |
|---|
| 711 | | - I2C_SMBUS_BLOCK_DATA); |
|---|
| 712 | | - if (rv < 0) { |
|---|
| 713 | | - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 714 | | - pr_info(PFX |
|---|
| 715 | | - "Error from ssif_i2c_send\n"); |
|---|
| 716 | | - |
|---|
| 717 | | - result = -EIO; |
|---|
| 718 | | - } else |
|---|
| 719 | | - return; |
|---|
| 734 | + ssif_i2c_send(ssif_info, msg_done_handler, |
|---|
| 735 | + I2C_SMBUS_READ, |
|---|
| 736 | + SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE, |
|---|
| 737 | + ssif_info->recv, |
|---|
| 738 | + I2C_SMBUS_BLOCK_DATA); |
|---|
| 739 | + return; |
|---|
| 720 | 740 | } |
|---|
| 721 | 741 | } |
|---|
| 722 | 742 | |
|---|
| .. | .. |
|---|
| 729 | 749 | } |
|---|
| 730 | 750 | |
|---|
| 731 | 751 | if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) |
|---|
| 732 | | - pr_info(PFX "DONE 1: state = %d, result=%d.\n", |
|---|
| 752 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 753 | + "DONE 1: state = %d, result=%d\n", |
|---|
| 733 | 754 | ssif_info->ssif_state, result); |
|---|
| 734 | 755 | |
|---|
| 735 | 756 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| .. | .. |
|---|
| 747 | 768 | } |
|---|
| 748 | 769 | |
|---|
| 749 | 770 | switch (ssif_info->ssif_state) { |
|---|
| 750 | | - case SSIF_NORMAL: |
|---|
| 771 | + case SSIF_IDLE: |
|---|
| 751 | 772 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 752 | 773 | if (!msg) |
|---|
| 753 | 774 | break; |
|---|
| .. | .. |
|---|
| 765 | 786 | * Error fetching flags, or invalid length, |
|---|
| 766 | 787 | * just give up for now. |
|---|
| 767 | 788 | */ |
|---|
| 768 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 789 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 769 | 790 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 770 | | - pr_warn(PFX "Error getting flags: %d %d, %x\n", |
|---|
| 771 | | - result, len, (len >= 3) ? data[2] : 0); |
|---|
| 791 | + dev_warn(&ssif_info->client->dev, |
|---|
| 792 | + "Error getting flags: %d %d, %x\n", |
|---|
| 793 | + result, len, (len >= 3) ? data[2] : 0); |
|---|
| 772 | 794 | } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
|---|
| 773 | 795 | || data[1] != IPMI_GET_MSG_FLAGS_CMD) { |
|---|
| 774 | 796 | /* |
|---|
| 775 | | - * Don't abort here, maybe it was a queued |
|---|
| 776 | | - * response to a previous command. |
|---|
| 797 | + * Recv error response, give up. |
|---|
| 777 | 798 | */ |
|---|
| 799 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 778 | 800 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 779 | | - pr_warn(PFX "Invalid response getting flags: %x %x\n", |
|---|
| 780 | | - data[0], data[1]); |
|---|
| 801 | + dev_warn(&ssif_info->client->dev, |
|---|
| 802 | + "Invalid response getting flags: %x %x\n", |
|---|
| 803 | + data[0], data[1]); |
|---|
| 781 | 804 | } else { |
|---|
| 782 | 805 | ssif_inc_stat(ssif_info, flag_fetches); |
|---|
| 783 | 806 | ssif_info->msg_flags = data[3]; |
|---|
| .. | .. |
|---|
| 789 | 812 | /* We cleared the flags. */ |
|---|
| 790 | 813 | if ((result < 0) || (len < 3) || (data[2] != 0)) { |
|---|
| 791 | 814 | /* Error clearing flags */ |
|---|
| 792 | | - pr_warn(PFX "Error clearing flags: %d %d, %x\n", |
|---|
| 793 | | - result, len, (len >= 3) ? data[2] : 0); |
|---|
| 815 | + dev_warn(&ssif_info->client->dev, |
|---|
| 816 | + "Error clearing flags: %d %d, %x\n", |
|---|
| 817 | + result, len, (len >= 3) ? data[2] : 0); |
|---|
| 794 | 818 | } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
|---|
| 795 | 819 | || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) { |
|---|
| 796 | | - pr_warn(PFX "Invalid response clearing flags: %x %x\n", |
|---|
| 797 | | - data[0], data[1]); |
|---|
| 820 | + dev_warn(&ssif_info->client->dev, |
|---|
| 821 | + "Invalid response clearing flags: %x %x\n", |
|---|
| 822 | + data[0], data[1]); |
|---|
| 798 | 823 | } |
|---|
| 799 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 824 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 800 | 825 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 801 | 826 | break; |
|---|
| 802 | 827 | |
|---|
| 803 | 828 | case SSIF_GETTING_EVENTS: |
|---|
| 829 | + if (!msg) { |
|---|
| 830 | + /* Should never happen, but just in case. */ |
|---|
| 831 | + dev_warn(&ssif_info->client->dev, |
|---|
| 832 | + "No message set while getting events\n"); |
|---|
| 833 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 834 | + break; |
|---|
| 835 | + } |
|---|
| 836 | + |
|---|
| 804 | 837 | if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { |
|---|
| 805 | 838 | /* Error getting event, probably done. */ |
|---|
| 806 | 839 | msg->done(msg); |
|---|
| .. | .. |
|---|
| 810 | 843 | handle_flags(ssif_info, flags); |
|---|
| 811 | 844 | } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
|---|
| 812 | 845 | || msg->rsp[1] != IPMI_READ_EVENT_MSG_BUFFER_CMD) { |
|---|
| 813 | | - pr_warn(PFX "Invalid response getting events: %x %x\n", |
|---|
| 814 | | - msg->rsp[0], msg->rsp[1]); |
|---|
| 846 | + dev_warn(&ssif_info->client->dev, |
|---|
| 847 | + "Invalid response getting events: %x %x\n", |
|---|
| 848 | + msg->rsp[0], msg->rsp[1]); |
|---|
| 815 | 849 | msg->done(msg); |
|---|
| 816 | 850 | /* Take off the event flag. */ |
|---|
| 817 | 851 | ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL; |
|---|
| .. | .. |
|---|
| 824 | 858 | break; |
|---|
| 825 | 859 | |
|---|
| 826 | 860 | case SSIF_GETTING_MESSAGES: |
|---|
| 861 | + if (!msg) { |
|---|
| 862 | + /* Should never happen, but just in case. */ |
|---|
| 863 | + dev_warn(&ssif_info->client->dev, |
|---|
| 864 | + "No message set while getting messages\n"); |
|---|
| 865 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 866 | + break; |
|---|
| 867 | + } |
|---|
| 868 | + |
|---|
| 827 | 869 | if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { |
|---|
| 828 | 870 | /* Error getting event, probably done. */ |
|---|
| 829 | 871 | msg->done(msg); |
|---|
| .. | .. |
|---|
| 833 | 875 | handle_flags(ssif_info, flags); |
|---|
| 834 | 876 | } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
|---|
| 835 | 877 | || msg->rsp[1] != IPMI_GET_MSG_CMD) { |
|---|
| 836 | | - pr_warn(PFX "Invalid response clearing flags: %x %x\n", |
|---|
| 837 | | - msg->rsp[0], msg->rsp[1]); |
|---|
| 878 | + dev_warn(&ssif_info->client->dev, |
|---|
| 879 | + "Invalid response clearing flags: %x %x\n", |
|---|
| 880 | + msg->rsp[0], msg->rsp[1]); |
|---|
| 838 | 881 | msg->done(msg); |
|---|
| 839 | 882 | |
|---|
| 840 | 883 | /* Take off the msg flag. */ |
|---|
| .. | .. |
|---|
| 846 | 889 | deliver_recv_msg(ssif_info, msg); |
|---|
| 847 | 890 | } |
|---|
| 848 | 891 | break; |
|---|
| 892 | + |
|---|
| 893 | + default: |
|---|
| 894 | + /* Should never happen, but just in case. */ |
|---|
| 895 | + dev_warn(&ssif_info->client->dev, |
|---|
| 896 | + "Invalid state in message done handling: %d\n", |
|---|
| 897 | + ssif_info->ssif_state); |
|---|
| 898 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 849 | 899 | } |
|---|
| 850 | 900 | |
|---|
| 851 | 901 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 852 | | - if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) { |
|---|
| 902 | + if (IS_SSIF_IDLE(ssif_info) && !ssif_info->stopping) { |
|---|
| 853 | 903 | if (ssif_info->req_events) |
|---|
| 854 | 904 | start_event_fetch(ssif_info, flags); |
|---|
| 855 | 905 | else if (ssif_info->req_flags) |
|---|
| .. | .. |
|---|
| 860 | 910 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 861 | 911 | |
|---|
| 862 | 912 | if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) |
|---|
| 863 | | - pr_info(PFX "DONE 2: state = %d.\n", ssif_info->ssif_state); |
|---|
| 913 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 914 | + "DONE 2: state = %d.\n", ssif_info->ssif_state); |
|---|
| 864 | 915 | } |
|---|
| 865 | 916 | |
|---|
| 866 | 917 | static void msg_written_handler(struct ssif_info *ssif_info, int result, |
|---|
| 867 | 918 | unsigned char *data, unsigned int len) |
|---|
| 868 | 919 | { |
|---|
| 869 | | - int rv; |
|---|
| 870 | | - |
|---|
| 871 | 920 | /* We are single-threaded here, so no need for a lock. */ |
|---|
| 872 | 921 | if (result < 0) { |
|---|
| 873 | 922 | ssif_info->retries_left--; |
|---|
| 874 | 923 | if (ssif_info->retries_left > 0) { |
|---|
| 875 | | - if (!start_resend(ssif_info)) { |
|---|
| 876 | | - ssif_inc_stat(ssif_info, send_retries); |
|---|
| 877 | | - return; |
|---|
| 878 | | - } |
|---|
| 879 | | - /* request failed, just return the error. */ |
|---|
| 880 | | - ssif_inc_stat(ssif_info, send_errors); |
|---|
| 881 | | - |
|---|
| 882 | | - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 883 | | - pr_info(PFX |
|---|
| 884 | | - "Out of retries in msg_written_handler\n"); |
|---|
| 885 | | - msg_done_handler(ssif_info, -EIO, NULL, 0); |
|---|
| 924 | + /* |
|---|
| 925 | + * Wait the retry timeout time per the spec, |
|---|
| 926 | + * then redo the send. |
|---|
| 927 | + */ |
|---|
| 928 | + ssif_info->do_resend = true; |
|---|
| 929 | + mod_timer(&ssif_info->retry_timer, |
|---|
| 930 | + jiffies + SSIF_REQ_RETRY_JIFFIES); |
|---|
| 886 | 931 | return; |
|---|
| 887 | 932 | } |
|---|
| 888 | 933 | |
|---|
| 889 | 934 | ssif_inc_stat(ssif_info, send_errors); |
|---|
| 890 | 935 | |
|---|
| 891 | | - /* |
|---|
| 892 | | - * Got an error on transmit, let the done routine |
|---|
| 893 | | - * handle it. |
|---|
| 894 | | - */ |
|---|
| 895 | 936 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 896 | | - pr_info("Error in msg_written_handler: %d\n", result); |
|---|
| 937 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 938 | + "%s: Out of retries\n", __func__); |
|---|
| 897 | 939 | |
|---|
| 898 | | - msg_done_handler(ssif_info, result, NULL, 0); |
|---|
| 940 | + msg_done_handler(ssif_info, -EIO, NULL, 0); |
|---|
| 899 | 941 | return; |
|---|
| 900 | 942 | } |
|---|
| 901 | 943 | |
|---|
| .. | .. |
|---|
| 905 | 947 | * in the SSIF_MULTI_n_PART case in the probe function |
|---|
| 906 | 948 | * for details on the intricacies of this. |
|---|
| 907 | 949 | */ |
|---|
| 908 | | - int left; |
|---|
| 950 | + int left, to_write; |
|---|
| 909 | 951 | unsigned char *data_to_send; |
|---|
| 952 | + unsigned char cmd; |
|---|
| 910 | 953 | |
|---|
| 911 | 954 | ssif_inc_stat(ssif_info, sent_messages_parts); |
|---|
| 912 | 955 | |
|---|
| 913 | 956 | left = ssif_info->multi_len - ssif_info->multi_pos; |
|---|
| 914 | | - if (left > 32) |
|---|
| 915 | | - left = 32; |
|---|
| 957 | + to_write = left; |
|---|
| 958 | + if (to_write > 32) |
|---|
| 959 | + to_write = 32; |
|---|
| 916 | 960 | /* Length byte. */ |
|---|
| 917 | | - ssif_info->multi_data[ssif_info->multi_pos] = left; |
|---|
| 961 | + ssif_info->multi_data[ssif_info->multi_pos] = to_write; |
|---|
| 918 | 962 | data_to_send = ssif_info->multi_data + ssif_info->multi_pos; |
|---|
| 919 | | - ssif_info->multi_pos += left; |
|---|
| 920 | | - if (left < 32) |
|---|
| 921 | | - /* |
|---|
| 922 | | - * Write is finished. Note that we must end |
|---|
| 923 | | - * with a write of less than 32 bytes to |
|---|
| 924 | | - * complete the transaction, even if it is |
|---|
| 925 | | - * zero bytes. |
|---|
| 926 | | - */ |
|---|
| 963 | + ssif_info->multi_pos += to_write; |
|---|
| 964 | + cmd = SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE; |
|---|
| 965 | + if (ssif_info->cmd8_works) { |
|---|
| 966 | + if (left == to_write) { |
|---|
| 967 | + cmd = SSIF_IPMI_MULTI_PART_REQUEST_END; |
|---|
| 968 | + ssif_info->multi_data = NULL; |
|---|
| 969 | + } |
|---|
| 970 | + } else if (to_write < 32) { |
|---|
| 927 | 971 | ssif_info->multi_data = NULL; |
|---|
| 928 | | - |
|---|
| 929 | | - rv = ssif_i2c_send(ssif_info, msg_written_handler, |
|---|
| 930 | | - I2C_SMBUS_WRITE, |
|---|
| 931 | | - SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, |
|---|
| 932 | | - data_to_send, |
|---|
| 933 | | - I2C_SMBUS_BLOCK_DATA); |
|---|
| 934 | | - if (rv < 0) { |
|---|
| 935 | | - /* request failed, just return the error. */ |
|---|
| 936 | | - ssif_inc_stat(ssif_info, send_errors); |
|---|
| 937 | | - |
|---|
| 938 | | - if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
|---|
| 939 | | - pr_info("Error from i2c_non_blocking_op(3)\n"); |
|---|
| 940 | | - msg_done_handler(ssif_info, -EIO, NULL, 0); |
|---|
| 941 | 972 | } |
|---|
| 973 | + |
|---|
| 974 | + ssif_i2c_send(ssif_info, msg_written_handler, |
|---|
| 975 | + I2C_SMBUS_WRITE, cmd, |
|---|
| 976 | + data_to_send, I2C_SMBUS_BLOCK_DATA); |
|---|
| 942 | 977 | } else { |
|---|
| 943 | 978 | /* Ready to request the result. */ |
|---|
| 944 | 979 | unsigned long oflags, *flags; |
|---|
| .. | .. |
|---|
| 965 | 1000 | } |
|---|
| 966 | 1001 | } |
|---|
| 967 | 1002 | |
|---|
| 968 | | -static int start_resend(struct ssif_info *ssif_info) |
|---|
| 1003 | +static void start_resend(struct ssif_info *ssif_info) |
|---|
| 969 | 1004 | { |
|---|
| 970 | | - int rv; |
|---|
| 971 | 1005 | int command; |
|---|
| 972 | 1006 | |
|---|
| 973 | 1007 | ssif_info->got_alert = false; |
|---|
| .. | .. |
|---|
| 989 | 1023 | ssif_info->data[0] = ssif_info->data_len; |
|---|
| 990 | 1024 | } |
|---|
| 991 | 1025 | |
|---|
| 992 | | - rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE, |
|---|
| 993 | | - command, ssif_info->data, I2C_SMBUS_BLOCK_DATA); |
|---|
| 994 | | - if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG)) |
|---|
| 995 | | - pr_info("Error from i2c_non_blocking_op(4)\n"); |
|---|
| 996 | | - return rv; |
|---|
| 1026 | + ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE, |
|---|
| 1027 | + command, ssif_info->data, I2C_SMBUS_BLOCK_DATA); |
|---|
| 997 | 1028 | } |
|---|
| 998 | 1029 | |
|---|
| 999 | 1030 | static int start_send(struct ssif_info *ssif_info, |
|---|
| .. | .. |
|---|
| 1008 | 1039 | ssif_info->retries_left = SSIF_SEND_RETRIES; |
|---|
| 1009 | 1040 | memcpy(ssif_info->data + 1, data, len); |
|---|
| 1010 | 1041 | ssif_info->data_len = len; |
|---|
| 1011 | | - return start_resend(ssif_info); |
|---|
| 1042 | + start_resend(ssif_info); |
|---|
| 1043 | + return 0; |
|---|
| 1012 | 1044 | } |
|---|
| 1013 | 1045 | |
|---|
| 1014 | 1046 | /* Must be called with the message lock held. */ |
|---|
| .. | .. |
|---|
| 1018 | 1050 | unsigned long oflags; |
|---|
| 1019 | 1051 | |
|---|
| 1020 | 1052 | restart: |
|---|
| 1021 | | - if (!SSIF_IDLE(ssif_info)) { |
|---|
| 1053 | + if (!IS_SSIF_IDLE(ssif_info)) { |
|---|
| 1022 | 1054 | ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 1023 | 1055 | return; |
|---|
| 1024 | 1056 | } |
|---|
| .. | .. |
|---|
| 1061 | 1093 | struct timespec64 t; |
|---|
| 1062 | 1094 | |
|---|
| 1063 | 1095 | ktime_get_real_ts64(&t); |
|---|
| 1064 | | - pr_info("**Enqueue %02x %02x: %lld.%6.6ld\n", |
|---|
| 1065 | | - msg->data[0], msg->data[1], |
|---|
| 1066 | | - (long long) t.tv_sec, (long) t.tv_nsec / NSEC_PER_USEC); |
|---|
| 1096 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 1097 | + "**Enqueue %02x %02x: %lld.%6.6ld\n", |
|---|
| 1098 | + msg->data[0], msg->data[1], |
|---|
| 1099 | + (long long)t.tv_sec, (long)t.tv_nsec / NSEC_PER_USEC); |
|---|
| 1067 | 1100 | } |
|---|
| 1068 | 1101 | } |
|---|
| 1069 | 1102 | |
|---|
| .. | .. |
|---|
| 1080 | 1113 | } |
|---|
| 1081 | 1114 | |
|---|
| 1082 | 1115 | /* |
|---|
| 1083 | | - * Instead of having our own timer to periodically check the message |
|---|
| 1084 | | - * flags, we let the message handler drive us. |
|---|
| 1116 | + * Upper layer wants us to request events. |
|---|
| 1085 | 1117 | */ |
|---|
| 1086 | 1118 | static void request_events(void *send_info) |
|---|
| 1087 | 1119 | { |
|---|
| .. | .. |
|---|
| 1092 | 1124 | return; |
|---|
| 1093 | 1125 | |
|---|
| 1094 | 1126 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 1095 | | - /* |
|---|
| 1096 | | - * Request flags first, not events, because the lower layer |
|---|
| 1097 | | - * doesn't have a way to send an attention. But make sure |
|---|
| 1098 | | - * event checking still happens. |
|---|
| 1099 | | - */ |
|---|
| 1100 | 1127 | ssif_info->req_events = true; |
|---|
| 1101 | | - if (SSIF_IDLE(ssif_info)) |
|---|
| 1102 | | - start_flag_fetch(ssif_info, flags); |
|---|
| 1103 | | - else { |
|---|
| 1104 | | - ssif_info->req_flags = true; |
|---|
| 1105 | | - ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 1128 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 1129 | +} |
|---|
| 1130 | + |
|---|
| 1131 | +/* |
|---|
| 1132 | + * Upper layer is changing the flag saying whether we need to request |
|---|
| 1133 | + * flags periodically or not. |
|---|
| 1134 | + */ |
|---|
| 1135 | +static void ssif_set_need_watch(void *send_info, unsigned int watch_mask) |
|---|
| 1136 | +{ |
|---|
| 1137 | + struct ssif_info *ssif_info = (struct ssif_info *) send_info; |
|---|
| 1138 | + unsigned long oflags, *flags; |
|---|
| 1139 | + long timeout = 0; |
|---|
| 1140 | + |
|---|
| 1141 | + if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES) |
|---|
| 1142 | + timeout = SSIF_WATCH_MSG_TIMEOUT; |
|---|
| 1143 | + else if (watch_mask) |
|---|
| 1144 | + timeout = SSIF_WATCH_WATCHDOG_TIMEOUT; |
|---|
| 1145 | + |
|---|
| 1146 | + flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
|---|
| 1147 | + if (timeout != ssif_info->watch_timeout) { |
|---|
| 1148 | + ssif_info->watch_timeout = timeout; |
|---|
| 1149 | + if (ssif_info->watch_timeout) |
|---|
| 1150 | + mod_timer(&ssif_info->watch_timer, |
|---|
| 1151 | + jiffies + ssif_info->watch_timeout); |
|---|
| 1106 | 1152 | } |
|---|
| 1153 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
|---|
| 1107 | 1154 | } |
|---|
| 1108 | 1155 | |
|---|
| 1109 | 1156 | static int ssif_start_processing(void *send_info, |
|---|
| .. | .. |
|---|
| 1226 | 1273 | dev_set_drvdata(&ssif_info->client->dev, NULL); |
|---|
| 1227 | 1274 | |
|---|
| 1228 | 1275 | /* make sure the driver is not looking for flags any more. */ |
|---|
| 1229 | | - while (ssif_info->ssif_state != SSIF_NORMAL) |
|---|
| 1276 | + while (ssif_info->ssif_state != SSIF_IDLE) |
|---|
| 1230 | 1277 | schedule_timeout(1); |
|---|
| 1231 | 1278 | |
|---|
| 1232 | 1279 | ssif_info->stopping = true; |
|---|
| 1280 | + del_timer_sync(&ssif_info->watch_timer); |
|---|
| 1233 | 1281 | del_timer_sync(&ssif_info->retry_timer); |
|---|
| 1234 | 1282 | if (ssif_info->thread) { |
|---|
| 1235 | 1283 | complete(&ssif_info->wake_thread); |
|---|
| .. | .. |
|---|
| 1263 | 1311 | return 0; |
|---|
| 1264 | 1312 | } |
|---|
| 1265 | 1313 | |
|---|
| 1266 | | -static int do_cmd(struct i2c_client *client, int len, unsigned char *msg, |
|---|
| 1267 | | - int *resp_len, unsigned char *resp) |
|---|
| 1314 | +static int read_response(struct i2c_client *client, unsigned char *resp) |
|---|
| 1268 | 1315 | { |
|---|
| 1269 | | - int retry_cnt; |
|---|
| 1270 | | - int ret; |
|---|
| 1316 | + int ret = -ENODEV, retry_cnt = SSIF_RECV_RETRIES; |
|---|
| 1271 | 1317 | |
|---|
| 1272 | | - retry_cnt = SSIF_SEND_RETRIES; |
|---|
| 1273 | | - retry1: |
|---|
| 1274 | | - ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg); |
|---|
| 1275 | | - if (ret) { |
|---|
| 1276 | | - retry_cnt--; |
|---|
| 1277 | | - if (retry_cnt > 0) |
|---|
| 1278 | | - goto retry1; |
|---|
| 1279 | | - return -ENODEV; |
|---|
| 1280 | | - } |
|---|
| 1281 | | - |
|---|
| 1282 | | - ret = -ENODEV; |
|---|
| 1283 | | - retry_cnt = SSIF_RECV_RETRIES; |
|---|
| 1284 | 1318 | while (retry_cnt > 0) { |
|---|
| 1285 | 1319 | ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE, |
|---|
| 1286 | 1320 | resp); |
|---|
| .. | .. |
|---|
| 1292 | 1326 | break; |
|---|
| 1293 | 1327 | } |
|---|
| 1294 | 1328 | |
|---|
| 1329 | + return ret; |
|---|
| 1330 | +} |
|---|
| 1331 | + |
|---|
| 1332 | +static int do_cmd(struct i2c_client *client, int len, unsigned char *msg, |
|---|
| 1333 | + int *resp_len, unsigned char *resp) |
|---|
| 1334 | +{ |
|---|
| 1335 | + int retry_cnt; |
|---|
| 1336 | + int ret; |
|---|
| 1337 | + |
|---|
| 1338 | + retry_cnt = SSIF_SEND_RETRIES; |
|---|
| 1339 | + retry1: |
|---|
| 1340 | + ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg); |
|---|
| 1341 | + if (ret) { |
|---|
| 1342 | + retry_cnt--; |
|---|
| 1343 | + if (retry_cnt > 0) { |
|---|
| 1344 | + msleep(SSIF_REQ_RETRY_MSEC); |
|---|
| 1345 | + goto retry1; |
|---|
| 1346 | + } |
|---|
| 1347 | + return -ENODEV; |
|---|
| 1348 | + } |
|---|
| 1349 | + |
|---|
| 1350 | + ret = read_response(client, resp); |
|---|
| 1295 | 1351 | if (ret > 0) { |
|---|
| 1296 | 1352 | /* Validate that the response is correct. */ |
|---|
| 1297 | 1353 | if (ret < 3 || |
|---|
| 1298 | 1354 | (resp[0] != (msg[0] | (1 << 2))) || |
|---|
| 1299 | 1355 | (resp[1] != msg[1])) |
|---|
| 1300 | 1356 | ret = -EINVAL; |
|---|
| 1301 | | - else { |
|---|
| 1357 | + else if (ret > IPMI_MAX_MSG_LENGTH) { |
|---|
| 1358 | + ret = -E2BIG; |
|---|
| 1359 | + } else { |
|---|
| 1302 | 1360 | *resp_len = ret; |
|---|
| 1303 | 1361 | ret = 0; |
|---|
| 1304 | 1362 | } |
|---|
| .. | .. |
|---|
| 1356 | 1414 | restart: |
|---|
| 1357 | 1415 | list_for_each_entry(info, &ssif_infos, link) { |
|---|
| 1358 | 1416 | if (info->binfo.addr == addr) { |
|---|
| 1417 | + if (info->addr_src == SI_SMBIOS && !info->adapter_name) |
|---|
| 1418 | + info->adapter_name = kstrdup(adapter_name, |
|---|
| 1419 | + GFP_KERNEL); |
|---|
| 1420 | + |
|---|
| 1359 | 1421 | if (info->adapter_name || adapter_name) { |
|---|
| 1360 | 1422 | if (!info->adapter_name != !adapter_name) { |
|---|
| 1361 | 1423 | /* One is NULL and one is not */ |
|---|
| .. | .. |
|---|
| 1391 | 1453 | if (acpi_handle) { |
|---|
| 1392 | 1454 | ssif_info->addr_source = SI_ACPI; |
|---|
| 1393 | 1455 | ssif_info->addr_info.acpi_info.acpi_handle = acpi_handle; |
|---|
| 1456 | + request_module("acpi_ipmi"); |
|---|
| 1394 | 1457 | return true; |
|---|
| 1395 | 1458 | } |
|---|
| 1396 | 1459 | #endif |
|---|
| .. | .. |
|---|
| 1410 | 1473 | return slave_addr; |
|---|
| 1411 | 1474 | } |
|---|
| 1412 | 1475 | |
|---|
| 1476 | +static int start_multipart_test(struct i2c_client *client, |
|---|
| 1477 | + unsigned char *msg, bool do_middle) |
|---|
| 1478 | +{ |
|---|
| 1479 | + int retry_cnt = SSIF_SEND_RETRIES, ret; |
|---|
| 1480 | + |
|---|
| 1481 | +retry_write: |
|---|
| 1482 | + ret = i2c_smbus_write_block_data(client, |
|---|
| 1483 | + SSIF_IPMI_MULTI_PART_REQUEST_START, |
|---|
| 1484 | + 32, msg); |
|---|
| 1485 | + if (ret) { |
|---|
| 1486 | + retry_cnt--; |
|---|
| 1487 | + if (retry_cnt > 0) { |
|---|
| 1488 | + msleep(SSIF_REQ_RETRY_MSEC); |
|---|
| 1489 | + goto retry_write; |
|---|
| 1490 | + } |
|---|
| 1491 | + 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"); |
|---|
| 1492 | + return ret; |
|---|
| 1493 | + } |
|---|
| 1494 | + |
|---|
| 1495 | + if (!do_middle) |
|---|
| 1496 | + return 0; |
|---|
| 1497 | + |
|---|
| 1498 | + ret = i2c_smbus_write_block_data(client, |
|---|
| 1499 | + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, |
|---|
| 1500 | + 32, msg + 32); |
|---|
| 1501 | + if (ret) { |
|---|
| 1502 | + dev_err(&client->dev, "Could not write multi-part middle, though the BMC said it could handle it. Just limit sends to one part.\n"); |
|---|
| 1503 | + return ret; |
|---|
| 1504 | + } |
|---|
| 1505 | + |
|---|
| 1506 | + return 0; |
|---|
| 1507 | +} |
|---|
| 1508 | + |
|---|
| 1509 | +static void test_multipart_messages(struct i2c_client *client, |
|---|
| 1510 | + struct ssif_info *ssif_info, |
|---|
| 1511 | + unsigned char *resp) |
|---|
| 1512 | +{ |
|---|
| 1513 | + unsigned char msg[65]; |
|---|
| 1514 | + int ret; |
|---|
| 1515 | + bool do_middle; |
|---|
| 1516 | + |
|---|
| 1517 | + if (ssif_info->max_xmit_msg_size <= 32) |
|---|
| 1518 | + return; |
|---|
| 1519 | + |
|---|
| 1520 | + do_middle = ssif_info->max_xmit_msg_size > 63; |
|---|
| 1521 | + |
|---|
| 1522 | + memset(msg, 0, sizeof(msg)); |
|---|
| 1523 | + msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
|---|
| 1524 | + msg[1] = IPMI_GET_DEVICE_ID_CMD; |
|---|
| 1525 | + |
|---|
| 1526 | + /* |
|---|
| 1527 | + * The specification is all messed up dealing with sending |
|---|
| 1528 | + * multi-part messages. Per what the specification says, it |
|---|
| 1529 | + * is impossible to send a message that is a multiple of 32 |
|---|
| 1530 | + * bytes, except for 32 itself. It talks about a "start" |
|---|
| 1531 | + * transaction (cmd=6) that must be 32 bytes, "middle" |
|---|
| 1532 | + * transaction (cmd=7) that must be 32 bytes, and an "end" |
|---|
| 1533 | + * transaction. The "end" transaction is shown as cmd=7 in |
|---|
| 1534 | + * the text, but if that's the case there is no way to |
|---|
| 1535 | + * differentiate between a middle and end part except the |
|---|
| 1536 | + * length being less than 32. But there is a table at the far |
|---|
| 1537 | + * end of the section (that I had never noticed until someone |
|---|
| 1538 | + * pointed it out to me) that mentions it as cmd=8. |
|---|
| 1539 | + * |
|---|
| 1540 | + * After some thought, I think the example is wrong and the |
|---|
| 1541 | + * end transaction should be cmd=8. But some systems don't |
|---|
| 1542 | + * implement cmd=8, they use a zero-length end transaction, |
|---|
| 1543 | + * even though that violates the SMBus specification. |
|---|
| 1544 | + * |
|---|
| 1545 | + * So, to work around this, this code tests if cmd=8 works. |
|---|
| 1546 | + * If it does, then we use that. If not, it tests zero- |
|---|
| 1547 | + * byte end transactions. If that works, good. If not, |
|---|
| 1548 | + * we only allow 63-byte transactions max. |
|---|
| 1549 | + */ |
|---|
| 1550 | + |
|---|
| 1551 | + ret = start_multipart_test(client, msg, do_middle); |
|---|
| 1552 | + if (ret) |
|---|
| 1553 | + goto out_no_multi_part; |
|---|
| 1554 | + |
|---|
| 1555 | + ret = i2c_smbus_write_block_data(client, |
|---|
| 1556 | + SSIF_IPMI_MULTI_PART_REQUEST_END, |
|---|
| 1557 | + 1, msg + 64); |
|---|
| 1558 | + |
|---|
| 1559 | + if (!ret) |
|---|
| 1560 | + ret = read_response(client, resp); |
|---|
| 1561 | + |
|---|
| 1562 | + if (ret > 0) { |
|---|
| 1563 | + /* End transactions work, we are good. */ |
|---|
| 1564 | + ssif_info->cmd8_works = true; |
|---|
| 1565 | + return; |
|---|
| 1566 | + } |
|---|
| 1567 | + |
|---|
| 1568 | + ret = start_multipart_test(client, msg, do_middle); |
|---|
| 1569 | + if (ret) { |
|---|
| 1570 | + dev_err(&client->dev, "Second multipart test failed.\n"); |
|---|
| 1571 | + goto out_no_multi_part; |
|---|
| 1572 | + } |
|---|
| 1573 | + |
|---|
| 1574 | + ret = i2c_smbus_write_block_data(client, |
|---|
| 1575 | + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, |
|---|
| 1576 | + 0, msg + 64); |
|---|
| 1577 | + if (!ret) |
|---|
| 1578 | + ret = read_response(client, resp); |
|---|
| 1579 | + if (ret > 0) |
|---|
| 1580 | + /* Zero-size end parts work, use those. */ |
|---|
| 1581 | + return; |
|---|
| 1582 | + |
|---|
| 1583 | + /* Limit to 63 bytes and use a short middle command to mark the end. */ |
|---|
| 1584 | + if (ssif_info->max_xmit_msg_size > 63) |
|---|
| 1585 | + ssif_info->max_xmit_msg_size = 63; |
|---|
| 1586 | + return; |
|---|
| 1587 | + |
|---|
| 1588 | +out_no_multi_part: |
|---|
| 1589 | + ssif_info->max_xmit_msg_size = 32; |
|---|
| 1590 | + return; |
|---|
| 1591 | +} |
|---|
| 1592 | + |
|---|
| 1413 | 1593 | /* |
|---|
| 1414 | 1594 | * Global enables we care about. |
|---|
| 1415 | 1595 | */ |
|---|
| 1416 | 1596 | #define GLOBAL_ENABLES_MASK (IPMI_BMC_EVT_MSG_BUFF | IPMI_BMC_RCV_MSG_INTR | \ |
|---|
| 1417 | 1597 | IPMI_BMC_EVT_MSG_INTR) |
|---|
| 1598 | + |
|---|
| 1599 | +static void ssif_remove_dup(struct i2c_client *client) |
|---|
| 1600 | +{ |
|---|
| 1601 | + struct ssif_info *ssif_info = i2c_get_clientdata(client); |
|---|
| 1602 | + |
|---|
| 1603 | + ipmi_unregister_smi(ssif_info->intf); |
|---|
| 1604 | + kfree(ssif_info); |
|---|
| 1605 | +} |
|---|
| 1606 | + |
|---|
| 1607 | +static int ssif_add_infos(struct i2c_client *client) |
|---|
| 1608 | +{ |
|---|
| 1609 | + struct ssif_addr_info *info; |
|---|
| 1610 | + |
|---|
| 1611 | + info = kzalloc(sizeof(*info), GFP_KERNEL); |
|---|
| 1612 | + if (!info) |
|---|
| 1613 | + return -ENOMEM; |
|---|
| 1614 | + info->addr_src = SI_ACPI; |
|---|
| 1615 | + info->client = client; |
|---|
| 1616 | + info->adapter_name = kstrdup(client->adapter->name, GFP_KERNEL); |
|---|
| 1617 | + if (!info->adapter_name) { |
|---|
| 1618 | + kfree(info); |
|---|
| 1619 | + return -ENOMEM; |
|---|
| 1620 | + } |
|---|
| 1621 | + |
|---|
| 1622 | + info->binfo.addr = client->addr; |
|---|
| 1623 | + list_add_tail(&info->link, &ssif_infos); |
|---|
| 1624 | + return 0; |
|---|
| 1625 | +} |
|---|
| 1626 | + |
|---|
| 1627 | +/* |
|---|
| 1628 | + * Prefer ACPI over SMBIOS, if both are available. |
|---|
| 1629 | + * So if we get an ACPI interface and have already registered a SMBIOS |
|---|
| 1630 | + * interface at the same address, remove the SMBIOS and add the ACPI one. |
|---|
| 1631 | + */ |
|---|
| 1632 | +static int ssif_check_and_remove(struct i2c_client *client, |
|---|
| 1633 | + struct ssif_info *ssif_info) |
|---|
| 1634 | +{ |
|---|
| 1635 | + struct ssif_addr_info *info; |
|---|
| 1636 | + |
|---|
| 1637 | + list_for_each_entry(info, &ssif_infos, link) { |
|---|
| 1638 | + if (!info->client) |
|---|
| 1639 | + return 0; |
|---|
| 1640 | + if (!strcmp(info->adapter_name, client->adapter->name) && |
|---|
| 1641 | + info->binfo.addr == client->addr) { |
|---|
| 1642 | + if (info->addr_src == SI_ACPI) |
|---|
| 1643 | + return -EEXIST; |
|---|
| 1644 | + |
|---|
| 1645 | + if (ssif_info->addr_source == SI_ACPI && |
|---|
| 1646 | + info->addr_src == SI_SMBIOS) { |
|---|
| 1647 | + dev_info(&client->dev, |
|---|
| 1648 | + "Removing %s-specified SSIF interface in favor of ACPI\n", |
|---|
| 1649 | + ipmi_addr_src_to_str(info->addr_src)); |
|---|
| 1650 | + ssif_remove_dup(info->client); |
|---|
| 1651 | + return 0; |
|---|
| 1652 | + } |
|---|
| 1653 | + } |
|---|
| 1654 | + } |
|---|
| 1655 | + return 0; |
|---|
| 1656 | +} |
|---|
| 1418 | 1657 | |
|---|
| 1419 | 1658 | static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) |
|---|
| 1420 | 1659 | { |
|---|
| .. | .. |
|---|
| 1427 | 1666 | u8 slave_addr = 0; |
|---|
| 1428 | 1667 | struct ssif_addr_info *addr_info = NULL; |
|---|
| 1429 | 1668 | |
|---|
| 1669 | + mutex_lock(&ssif_infos_mutex); |
|---|
| 1430 | 1670 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
|---|
| 1431 | | - if (!resp) |
|---|
| 1671 | + if (!resp) { |
|---|
| 1672 | + mutex_unlock(&ssif_infos_mutex); |
|---|
| 1432 | 1673 | return -ENOMEM; |
|---|
| 1674 | + } |
|---|
| 1433 | 1675 | |
|---|
| 1434 | 1676 | ssif_info = kzalloc(sizeof(*ssif_info), GFP_KERNEL); |
|---|
| 1435 | 1677 | if (!ssif_info) { |
|---|
| 1436 | 1678 | kfree(resp); |
|---|
| 1679 | + mutex_unlock(&ssif_infos_mutex); |
|---|
| 1437 | 1680 | return -ENOMEM; |
|---|
| 1438 | 1681 | } |
|---|
| 1439 | 1682 | |
|---|
| .. | .. |
|---|
| 1452 | 1695 | } |
|---|
| 1453 | 1696 | } |
|---|
| 1454 | 1697 | |
|---|
| 1455 | | - slave_addr = find_slave_address(client, slave_addr); |
|---|
| 1456 | | - |
|---|
| 1457 | | - pr_info(PFX "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n", |
|---|
| 1458 | | - ipmi_addr_src_to_str(ssif_info->addr_source), |
|---|
| 1459 | | - client->addr, client->adapter->name, slave_addr); |
|---|
| 1460 | | - |
|---|
| 1461 | 1698 | ssif_info->client = client; |
|---|
| 1462 | 1699 | i2c_set_clientdata(client, ssif_info); |
|---|
| 1700 | + |
|---|
| 1701 | + rv = ssif_check_and_remove(client, ssif_info); |
|---|
| 1702 | + /* If rv is 0 and addr source is not SI_ACPI, continue probing */ |
|---|
| 1703 | + if (!rv && ssif_info->addr_source == SI_ACPI) { |
|---|
| 1704 | + rv = ssif_add_infos(client); |
|---|
| 1705 | + if (rv) { |
|---|
| 1706 | + dev_err(&client->dev, "Out of memory!, exiting ..\n"); |
|---|
| 1707 | + goto out; |
|---|
| 1708 | + } |
|---|
| 1709 | + } else if (rv) { |
|---|
| 1710 | + dev_err(&client->dev, "Not probing, Interface already present\n"); |
|---|
| 1711 | + goto out; |
|---|
| 1712 | + } |
|---|
| 1713 | + |
|---|
| 1714 | + slave_addr = find_slave_address(client, slave_addr); |
|---|
| 1715 | + |
|---|
| 1716 | + dev_info(&client->dev, |
|---|
| 1717 | + "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n", |
|---|
| 1718 | + ipmi_addr_src_to_str(ssif_info->addr_source), |
|---|
| 1719 | + client->addr, client->adapter->name, slave_addr); |
|---|
| 1463 | 1720 | |
|---|
| 1464 | 1721 | /* Now check for system interface capabilities */ |
|---|
| 1465 | 1722 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
|---|
| .. | .. |
|---|
| 1469 | 1726 | if (!rv && (len >= 3) && (resp[2] == 0)) { |
|---|
| 1470 | 1727 | if (len < 7) { |
|---|
| 1471 | 1728 | if (ssif_dbg_probe) |
|---|
| 1472 | | - pr_info(PFX "SSIF info too short: %d\n", len); |
|---|
| 1729 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 1730 | + "SSIF info too short: %d\n", len); |
|---|
| 1473 | 1731 | goto no_support; |
|---|
| 1474 | 1732 | } |
|---|
| 1475 | 1733 | |
|---|
| .. | .. |
|---|
| 1496 | 1754 | break; |
|---|
| 1497 | 1755 | |
|---|
| 1498 | 1756 | case SSIF_MULTI_n_PART: |
|---|
| 1499 | | - /* |
|---|
| 1500 | | - * The specification is rather confusing at |
|---|
| 1501 | | - * this point, but I think I understand what |
|---|
| 1502 | | - * is meant. At least I have a workable |
|---|
| 1503 | | - * solution. With multi-part messages, you |
|---|
| 1504 | | - * cannot send a message that is a multiple of |
|---|
| 1505 | | - * 32-bytes in length, because the start and |
|---|
| 1506 | | - * middle messages are 32-bytes and the end |
|---|
| 1507 | | - * message must be at least one byte. You |
|---|
| 1508 | | - * can't fudge on an extra byte, that would |
|---|
| 1509 | | - * screw up things like fru data writes. So |
|---|
| 1510 | | - * we limit the length to 63 bytes. That way |
|---|
| 1511 | | - * a 32-byte message gets sent as a single |
|---|
| 1512 | | - * part. A larger message will be a 32-byte |
|---|
| 1513 | | - * start and the next message is always going |
|---|
| 1514 | | - * to be 1-31 bytes in length. Not ideal, but |
|---|
| 1515 | | - * it should work. |
|---|
| 1516 | | - */ |
|---|
| 1517 | | - if (ssif_info->max_xmit_msg_size > 63) |
|---|
| 1518 | | - ssif_info->max_xmit_msg_size = 63; |
|---|
| 1757 | + /* We take whatever size given, but do some testing. */ |
|---|
| 1519 | 1758 | break; |
|---|
| 1520 | 1759 | |
|---|
| 1521 | 1760 | default: |
|---|
| .. | .. |
|---|
| 1525 | 1764 | } else { |
|---|
| 1526 | 1765 | no_support: |
|---|
| 1527 | 1766 | /* Assume no multi-part or PEC support */ |
|---|
| 1528 | | - pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", |
|---|
| 1529 | | - rv, len, resp[2]); |
|---|
| 1767 | + dev_info(&ssif_info->client->dev, |
|---|
| 1768 | + "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", |
|---|
| 1769 | + rv, len, resp[2]); |
|---|
| 1530 | 1770 | |
|---|
| 1531 | 1771 | ssif_info->max_xmit_msg_size = 32; |
|---|
| 1532 | 1772 | ssif_info->max_recv_msg_size = 32; |
|---|
| .. | .. |
|---|
| 1534 | 1774 | ssif_info->supports_pec = 0; |
|---|
| 1535 | 1775 | } |
|---|
| 1536 | 1776 | |
|---|
| 1777 | + test_multipart_messages(client, ssif_info, resp); |
|---|
| 1778 | + |
|---|
| 1537 | 1779 | /* Make sure the NMI timeout is cleared. */ |
|---|
| 1538 | 1780 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
|---|
| 1539 | 1781 | msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; |
|---|
| 1540 | 1782 | msg[2] = WDT_PRE_TIMEOUT_INT; |
|---|
| 1541 | 1783 | rv = do_cmd(client, 3, msg, &len, resp); |
|---|
| 1542 | 1784 | if (rv || (len < 3) || (resp[2] != 0)) |
|---|
| 1543 | | - pr_warn(PFX "Unable to clear message flags: %d %d %2.2x\n", |
|---|
| 1544 | | - rv, len, resp[2]); |
|---|
| 1785 | + dev_warn(&ssif_info->client->dev, |
|---|
| 1786 | + "Unable to clear message flags: %d %d %2.2x\n", |
|---|
| 1787 | + rv, len, resp[2]); |
|---|
| 1545 | 1788 | |
|---|
| 1546 | 1789 | /* Attempt to enable the event buffer. */ |
|---|
| 1547 | 1790 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
|---|
| 1548 | 1791 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
|---|
| 1549 | 1792 | rv = do_cmd(client, 2, msg, &len, resp); |
|---|
| 1550 | 1793 | if (rv || (len < 4) || (resp[2] != 0)) { |
|---|
| 1551 | | - pr_warn(PFX "Error getting global enables: %d %d %2.2x\n", |
|---|
| 1552 | | - rv, len, resp[2]); |
|---|
| 1794 | + dev_warn(&ssif_info->client->dev, |
|---|
| 1795 | + "Error getting global enables: %d %d %2.2x\n", |
|---|
| 1796 | + rv, len, resp[2]); |
|---|
| 1553 | 1797 | rv = 0; /* Not fatal */ |
|---|
| 1554 | 1798 | goto found; |
|---|
| 1555 | 1799 | } |
|---|
| .. | .. |
|---|
| 1567 | 1811 | msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF; |
|---|
| 1568 | 1812 | rv = do_cmd(client, 3, msg, &len, resp); |
|---|
| 1569 | 1813 | if (rv || (len < 2)) { |
|---|
| 1570 | | - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", |
|---|
| 1571 | | - rv, len, resp[2]); |
|---|
| 1814 | + dev_warn(&ssif_info->client->dev, |
|---|
| 1815 | + "Error setting global enables: %d %d %2.2x\n", |
|---|
| 1816 | + rv, len, resp[2]); |
|---|
| 1572 | 1817 | rv = 0; /* Not fatal */ |
|---|
| 1573 | 1818 | goto found; |
|---|
| 1574 | 1819 | } |
|---|
| .. | .. |
|---|
| 1588 | 1833 | msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR; |
|---|
| 1589 | 1834 | rv = do_cmd(client, 3, msg, &len, resp); |
|---|
| 1590 | 1835 | if (rv || (len < 2)) { |
|---|
| 1591 | | - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", |
|---|
| 1592 | | - rv, len, resp[2]); |
|---|
| 1836 | + dev_warn(&ssif_info->client->dev, |
|---|
| 1837 | + "Error setting global enables: %d %d %2.2x\n", |
|---|
| 1838 | + rv, len, resp[2]); |
|---|
| 1593 | 1839 | rv = 0; /* Not fatal */ |
|---|
| 1594 | 1840 | goto found; |
|---|
| 1595 | 1841 | } |
|---|
| .. | .. |
|---|
| 1602 | 1848 | |
|---|
| 1603 | 1849 | found: |
|---|
| 1604 | 1850 | if (ssif_dbg_probe) { |
|---|
| 1605 | | - pr_info("ssif_probe: i2c_probe found device at i2c address %x\n", |
|---|
| 1606 | | - client->addr); |
|---|
| 1851 | + dev_dbg(&ssif_info->client->dev, |
|---|
| 1852 | + "%s: i2c_probe found device at i2c address %x\n", |
|---|
| 1853 | + __func__, client->addr); |
|---|
| 1607 | 1854 | } |
|---|
| 1608 | 1855 | |
|---|
| 1609 | 1856 | spin_lock_init(&ssif_info->lock); |
|---|
| 1610 | | - ssif_info->ssif_state = SSIF_NORMAL; |
|---|
| 1857 | + ssif_info->ssif_state = SSIF_IDLE; |
|---|
| 1611 | 1858 | timer_setup(&ssif_info->retry_timer, retry_timeout, 0); |
|---|
| 1859 | + timer_setup(&ssif_info->watch_timer, watch_timeout, 0); |
|---|
| 1612 | 1860 | |
|---|
| 1613 | 1861 | for (i = 0; i < SSIF_NUM_STATS; i++) |
|---|
| 1614 | 1862 | atomic_set(&ssif_info->stats[i], 0); |
|---|
| .. | .. |
|---|
| 1622 | 1870 | ssif_info->handlers.get_smi_info = get_smi_info; |
|---|
| 1623 | 1871 | ssif_info->handlers.sender = sender; |
|---|
| 1624 | 1872 | ssif_info->handlers.request_events = request_events; |
|---|
| 1873 | + ssif_info->handlers.set_need_watch = ssif_set_need_watch; |
|---|
| 1625 | 1874 | |
|---|
| 1626 | 1875 | { |
|---|
| 1627 | 1876 | unsigned int thread_num; |
|---|
| .. | .. |
|---|
| 1655 | 1904 | ssif_info, |
|---|
| 1656 | 1905 | &ssif_info->client->dev, |
|---|
| 1657 | 1906 | slave_addr); |
|---|
| 1658 | | - if (rv) { |
|---|
| 1659 | | - pr_err(PFX "Unable to register device: error %d\n", rv); |
|---|
| 1907 | + if (rv) { |
|---|
| 1908 | + dev_err(&ssif_info->client->dev, |
|---|
| 1909 | + "Unable to register device: error %d\n", rv); |
|---|
| 1660 | 1910 | goto out_remove_attr; |
|---|
| 1661 | 1911 | } |
|---|
| 1662 | 1912 | |
|---|
| .. | .. |
|---|
| 1665 | 1915 | if (addr_info) |
|---|
| 1666 | 1916 | addr_info->client = NULL; |
|---|
| 1667 | 1917 | |
|---|
| 1668 | | - dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv); |
|---|
| 1918 | + dev_err(&ssif_info->client->dev, |
|---|
| 1919 | + "Unable to start IPMI SSIF: %d\n", rv); |
|---|
| 1920 | + i2c_set_clientdata(client, NULL); |
|---|
| 1669 | 1921 | kfree(ssif_info); |
|---|
| 1670 | 1922 | } |
|---|
| 1671 | 1923 | kfree(resp); |
|---|
| 1924 | + mutex_unlock(&ssif_infos_mutex); |
|---|
| 1672 | 1925 | return rv; |
|---|
| 1673 | 1926 | |
|---|
| 1674 | 1927 | out_remove_attr: |
|---|
| 1675 | 1928 | device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group); |
|---|
| 1676 | 1929 | dev_set_drvdata(&ssif_info->client->dev, NULL); |
|---|
| 1677 | 1930 | goto out; |
|---|
| 1678 | | -} |
|---|
| 1679 | | - |
|---|
| 1680 | | -static int ssif_adapter_handler(struct device *adev, void *opaque) |
|---|
| 1681 | | -{ |
|---|
| 1682 | | - struct ssif_addr_info *addr_info = opaque; |
|---|
| 1683 | | - |
|---|
| 1684 | | - if (adev->type != &i2c_adapter_type) |
|---|
| 1685 | | - return 0; |
|---|
| 1686 | | - |
|---|
| 1687 | | - addr_info->added_client = i2c_new_device(to_i2c_adapter(adev), |
|---|
| 1688 | | - &addr_info->binfo); |
|---|
| 1689 | | - |
|---|
| 1690 | | - if (!addr_info->adapter_name) |
|---|
| 1691 | | - return 1; /* Only try the first I2C adapter by default. */ |
|---|
| 1692 | | - return 0; |
|---|
| 1693 | 1931 | } |
|---|
| 1694 | 1932 | |
|---|
| 1695 | 1933 | static int new_ssif_client(int addr, char *adapter_name, |
|---|
| .. | .. |
|---|
| 1735 | 1973 | |
|---|
| 1736 | 1974 | list_add_tail(&addr_info->link, &ssif_infos); |
|---|
| 1737 | 1975 | |
|---|
| 1738 | | - if (initialized) |
|---|
| 1739 | | - i2c_for_each_dev(addr_info, ssif_adapter_handler); |
|---|
| 1740 | | - /* Otherwise address list will get it */ |
|---|
| 1976 | + /* Address list will get it */ |
|---|
| 1741 | 1977 | |
|---|
| 1742 | 1978 | out_unlock: |
|---|
| 1743 | 1979 | mutex_unlock(&ssif_infos_mutex); |
|---|
| .. | .. |
|---|
| 1760 | 1996 | static unsigned short *ssif_address_list(void) |
|---|
| 1761 | 1997 | { |
|---|
| 1762 | 1998 | struct ssif_addr_info *info; |
|---|
| 1763 | | - unsigned int count = 0, i; |
|---|
| 1999 | + unsigned int count = 0, i = 0; |
|---|
| 1764 | 2000 | unsigned short *address_list; |
|---|
| 1765 | 2001 | |
|---|
| 1766 | 2002 | list_for_each_entry(info, &ssif_infos, link) |
|---|
| .. | .. |
|---|
| 1771 | 2007 | if (!address_list) |
|---|
| 1772 | 2008 | return NULL; |
|---|
| 1773 | 2009 | |
|---|
| 1774 | | - i = 0; |
|---|
| 1775 | 2010 | list_for_each_entry(info, &ssif_infos, link) { |
|---|
| 1776 | 2011 | unsigned short addr = info->binfo.addr; |
|---|
| 1777 | 2012 | int j; |
|---|
| 1778 | 2013 | |
|---|
| 1779 | 2014 | for (j = 0; j < i; j++) { |
|---|
| 1780 | 2015 | if (address_list[j] == addr) |
|---|
| 1781 | | - goto skip_addr; |
|---|
| 2016 | + /* Found a dup. */ |
|---|
| 2017 | + break; |
|---|
| 1782 | 2018 | } |
|---|
| 1783 | | - address_list[i] = addr; |
|---|
| 1784 | | -skip_addr: |
|---|
| 1785 | | - i++; |
|---|
| 2019 | + if (j == i) /* Didn't find it in the list. */ |
|---|
| 2020 | + address_list[i++] = addr; |
|---|
| 1786 | 2021 | } |
|---|
| 1787 | 2022 | address_list[i] = I2C_CLIENT_END; |
|---|
| 1788 | 2023 | |
|---|
| .. | .. |
|---|
| 1809 | 2044 | |
|---|
| 1810 | 2045 | rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr); |
|---|
| 1811 | 2046 | if (rv) { |
|---|
| 1812 | | - dev_warn(&pdev->dev, PFX "No i2c-addr property\n"); |
|---|
| 2047 | + dev_warn(&pdev->dev, "No i2c-addr property\n"); |
|---|
| 1813 | 2048 | return -ENODEV; |
|---|
| 1814 | 2049 | } |
|---|
| 1815 | 2050 | |
|---|
| 1816 | 2051 | rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr); |
|---|
| 1817 | 2052 | if (rv) |
|---|
| 1818 | | - dev_warn(&pdev->dev, "device has no slave-addr property"); |
|---|
| 2053 | + slave_addr = 0x20; |
|---|
| 1819 | 2054 | |
|---|
| 1820 | 2055 | return new_ssif_client(i2c_addr, NULL, 0, |
|---|
| 1821 | 2056 | slave_addr, SI_SMBIOS, &pdev->dev); |
|---|
| .. | .. |
|---|
| 1858 | 2093 | return 0; |
|---|
| 1859 | 2094 | |
|---|
| 1860 | 2095 | mutex_lock(&ssif_infos_mutex); |
|---|
| 1861 | | - i2c_unregister_device(addr_info->added_client); |
|---|
| 1862 | | - |
|---|
| 1863 | 2096 | list_del(&addr_info->link); |
|---|
| 1864 | 2097 | kfree(addr_info); |
|---|
| 1865 | 2098 | mutex_unlock(&ssif_infos_mutex); |
|---|
| 1866 | 2099 | return 0; |
|---|
| 1867 | 2100 | } |
|---|
| 2101 | + |
|---|
| 2102 | +static const struct platform_device_id ssif_plat_ids[] = { |
|---|
| 2103 | + { "dmi-ipmi-ssif", 0 }, |
|---|
| 2104 | + { } |
|---|
| 2105 | +}; |
|---|
| 1868 | 2106 | |
|---|
| 1869 | 2107 | static struct platform_driver ipmi_driver = { |
|---|
| 1870 | 2108 | .driver = { |
|---|
| .. | .. |
|---|
| 1872 | 2110 | }, |
|---|
| 1873 | 2111 | .probe = ssif_platform_probe, |
|---|
| 1874 | 2112 | .remove = ssif_platform_remove, |
|---|
| 2113 | + .id_table = ssif_plat_ids |
|---|
| 1875 | 2114 | }; |
|---|
| 1876 | 2115 | |
|---|
| 1877 | 2116 | static int init_ipmi_ssif(void) |
|---|
| .. | .. |
|---|
| 1890 | 2129 | dbg[i], slave_addrs[i], |
|---|
| 1891 | 2130 | SI_HARDCODED, NULL); |
|---|
| 1892 | 2131 | if (rv) |
|---|
| 1893 | | - pr_err(PFX |
|---|
| 1894 | | - "Couldn't add hardcoded device at addr 0x%x\n", |
|---|
| 2132 | + pr_err("Couldn't add hardcoded device at addr 0x%x\n", |
|---|
| 1895 | 2133 | addr[i]); |
|---|
| 1896 | 2134 | } |
|---|
| 1897 | 2135 | |
|---|
| .. | .. |
|---|
| 1902 | 2140 | if (ssif_trydmi) { |
|---|
| 1903 | 2141 | rv = platform_driver_register(&ipmi_driver); |
|---|
| 1904 | 2142 | if (rv) |
|---|
| 1905 | | - pr_err(PFX "Unable to register driver: %d\n", rv); |
|---|
| 2143 | + pr_err("Unable to register driver: %d\n", rv); |
|---|
| 2144 | + else |
|---|
| 2145 | + platform_registered = true; |
|---|
| 1906 | 2146 | } |
|---|
| 1907 | 2147 | |
|---|
| 1908 | 2148 | ssif_i2c_driver.address_list = ssif_address_list(); |
|---|
| .. | .. |
|---|
| 1924 | 2164 | |
|---|
| 1925 | 2165 | i2c_del_driver(&ssif_i2c_driver); |
|---|
| 1926 | 2166 | |
|---|
| 1927 | | - platform_driver_unregister(&ipmi_driver); |
|---|
| 2167 | + kfree(ssif_i2c_driver.address_list); |
|---|
| 2168 | + |
|---|
| 2169 | + if (ssif_trydmi && platform_registered) |
|---|
| 2170 | + platform_driver_unregister(&ipmi_driver); |
|---|
| 1928 | 2171 | |
|---|
| 1929 | 2172 | free_ssif_clients(); |
|---|
| 1930 | 2173 | } |
|---|