1 /* 2 * 3 * Intel Management Engine Interface (Intel MEI) Linux driver 4 * Copyright (c) 2003-2012, Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 */ 16 17 #ifndef _MEI_DEV_H_ 18 #define _MEI_DEV_H_ 19 20 #include <linux/types.h> 21 #include <linux/cdev.h> 22 #include <linux/poll.h> 23 #include <linux/mei.h> 24 #include <linux/mei_cl_bus.h> 25 26 #include "hw.h" 27 #include "hbm.h" 28 29 30 /* 31 * AMTHI Client UUID 32 */ 33 extern const uuid_le mei_amthif_guid; 34 35 #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) 36 37 /* 38 * Number of Maximum MEI Clients 39 */ 40 #define MEI_CLIENTS_MAX 256 41 42 /* 43 * maximum number of consecutive resets 44 */ 45 #define MEI_MAX_CONSEC_RESET 3 46 47 /* 48 * Number of File descriptors/handles 49 * that can be opened to the driver. 50 * 51 * Limit to 255: 256 Total Clients 52 * minus internal client for MEI Bus Messages 53 */ 54 #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1) 55 56 /* File state */ 57 enum file_state { 58 MEI_FILE_UNINITIALIZED = 0, 59 MEI_FILE_INITIALIZING, 60 MEI_FILE_CONNECTING, 61 MEI_FILE_CONNECTED, 62 MEI_FILE_DISCONNECTING, 63 MEI_FILE_DISCONNECT_REPLY, 64 MEI_FILE_DISCONNECT_REQUIRED, 65 MEI_FILE_DISCONNECTED, 66 }; 67 68 /* MEI device states */ 69 enum mei_dev_state { 70 MEI_DEV_INITIALIZING = 0, 71 MEI_DEV_INIT_CLIENTS, 72 MEI_DEV_ENABLED, 73 MEI_DEV_RESETTING, 74 MEI_DEV_DISABLED, 75 MEI_DEV_POWER_DOWN, 76 MEI_DEV_POWER_UP 77 }; 78 79 const char *mei_dev_state_str(int state); 80 81 enum iamthif_states { 82 MEI_IAMTHIF_IDLE, 83 MEI_IAMTHIF_WRITING, 84 MEI_IAMTHIF_READING, 85 }; 86 87 enum mei_file_transaction_states { 88 MEI_IDLE, 89 MEI_WRITING, 90 MEI_WRITE_COMPLETE, 91 }; 92 93 /** 94 * enum mei_cb_file_ops - file operation associated with the callback 95 * @MEI_FOP_READ: read 96 * @MEI_FOP_WRITE: write 97 * @MEI_FOP_CONNECT: connect 98 * @MEI_FOP_DISCONNECT: disconnect 99 * @MEI_FOP_DISCONNECT_RSP: disconnect response 100 * @MEI_FOP_NOTIFY_START: start notification 101 * @MEI_FOP_NOTIFY_STOP: stop notification 102 */ 103 enum mei_cb_file_ops { 104 MEI_FOP_READ = 0, 105 MEI_FOP_WRITE, 106 MEI_FOP_CONNECT, 107 MEI_FOP_DISCONNECT, 108 MEI_FOP_DISCONNECT_RSP, 109 MEI_FOP_NOTIFY_START, 110 MEI_FOP_NOTIFY_STOP, 111 }; 112 113 /** 114 * enum mei_cl_io_mode - io mode between driver and fw 115 * 116 * @MEI_CL_IO_TX_BLOCKING: send is blocking 117 * @MEI_CL_IO_TX_INTERNAL: internal communication between driver and FW 118 * 119 * @MEI_CL_IO_RX_NONBLOCK: recv is non-blocking 120 */ 121 enum mei_cl_io_mode { 122 MEI_CL_IO_TX_BLOCKING = BIT(0), 123 MEI_CL_IO_TX_INTERNAL = BIT(1), 124 125 MEI_CL_IO_RX_NONBLOCK = BIT(2), 126 }; 127 128 /* 129 * Intel MEI message data struct 130 */ 131 struct mei_msg_data { 132 size_t size; 133 unsigned char *data; 134 }; 135 136 /* Maximum number of processed FW status registers */ 137 #define MEI_FW_STATUS_MAX 6 138 /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */ 139 #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1)) 140 141 142 /* 143 * struct mei_fw_status - storage of FW status data 144 * 145 * @count: number of actually available elements in array 146 * @status: FW status registers 147 */ 148 struct mei_fw_status { 149 int count; 150 u32 status[MEI_FW_STATUS_MAX]; 151 }; 152 153 /** 154 * struct mei_me_client - representation of me (fw) client 155 * 156 * @list: link in me client list 157 * @refcnt: struct reference count 158 * @props: client properties 159 * @client_id: me client id 160 * @tx_flow_ctrl_creds: flow control credits 161 * @connect_count: number connections to this client 162 * @bus_added: added to bus 163 */ 164 struct mei_me_client { 165 struct list_head list; 166 struct kref refcnt; 167 struct mei_client_properties props; 168 u8 client_id; 169 u8 tx_flow_ctrl_creds; 170 u8 connect_count; 171 u8 bus_added; 172 }; 173 174 175 struct mei_cl; 176 177 /** 178 * struct mei_cl_cb - file operation callback structure 179 * 180 * @list: link in callback queue 181 * @cl: file client who is running this operation 182 * @fop_type: file operation type 183 * @buf: buffer for data associated with the callback 184 * @buf_idx: last read index 185 * @fp: pointer to file structure 186 * @status: io status of the cb 187 * @internal: communication between driver and FW flag 188 * @blocking: transmission blocking mode 189 * @completed: the transfer or reception has completed 190 */ 191 struct mei_cl_cb { 192 struct list_head list; 193 struct mei_cl *cl; 194 enum mei_cb_file_ops fop_type; 195 struct mei_msg_data buf; 196 size_t buf_idx; 197 const struct file *fp; 198 int status; 199 u32 internal:1; 200 u32 blocking:1; 201 u32 completed:1; 202 }; 203 204 /** 205 * struct mei_cl - me client host representation 206 * carried in file->private_data 207 * 208 * @link: link in the clients list 209 * @dev: mei parent device 210 * @state: file operation state 211 * @tx_wait: wait queue for tx completion 212 * @rx_wait: wait queue for rx completion 213 * @wait: wait queue for management operation 214 * @ev_wait: notification wait queue 215 * @ev_async: event async notification 216 * @status: connection status 217 * @me_cl: fw client connected 218 * @fp: file associated with client 219 * @host_client_id: host id 220 * @tx_flow_ctrl_creds: transmit flow credentials 221 * @rx_flow_ctrl_creds: receive flow credentials 222 * @timer_count: watchdog timer for operation completion 223 * @notify_en: notification - enabled/disabled 224 * @notify_ev: pending notification event 225 * @writing_state: state of the tx 226 * @rd_pending: pending read credits 227 * @rd_completed: completed read 228 * 229 * @cldev: device on the mei client bus 230 */ 231 struct mei_cl { 232 struct list_head link; 233 struct mei_device *dev; 234 enum file_state state; 235 wait_queue_head_t tx_wait; 236 wait_queue_head_t rx_wait; 237 wait_queue_head_t wait; 238 wait_queue_head_t ev_wait; 239 struct fasync_struct *ev_async; 240 int status; 241 struct mei_me_client *me_cl; 242 const struct file *fp; 243 u8 host_client_id; 244 u8 tx_flow_ctrl_creds; 245 u8 rx_flow_ctrl_creds; 246 u8 timer_count; 247 u8 notify_en; 248 u8 notify_ev; 249 enum mei_file_transaction_states writing_state; 250 struct list_head rd_pending; 251 struct list_head rd_completed; 252 253 struct mei_cl_device *cldev; 254 }; 255 256 /** 257 * struct mei_hw_ops - hw specific ops 258 * 259 * @host_is_ready : query for host readiness 260 * 261 * @hw_is_ready : query if hw is ready 262 * @hw_reset : reset hw 263 * @hw_start : start hw after reset 264 * @hw_config : configure hw 265 * 266 * @fw_status : get fw status registers 267 * @pg_state : power gating state of the device 268 * @pg_in_transition : is device now in pg transition 269 * @pg_is_enabled : is power gating enabled 270 * 271 * @intr_clear : clear pending interrupts 272 * @intr_enable : enable interrupts 273 * @intr_disable : disable interrupts 274 * @synchronize_irq : synchronize irqs 275 * 276 * @hbuf_free_slots : query for write buffer empty slots 277 * @hbuf_is_ready : query if write buffer is empty 278 * @hbuf_max_len : query for write buffer max len 279 * 280 * @write : write a message to FW 281 * 282 * @rdbuf_full_slots : query how many slots are filled 283 * 284 * @read_hdr : get first 4 bytes (header) 285 * @read : read a buffer from the FW 286 */ 287 struct mei_hw_ops { 288 289 bool (*host_is_ready)(struct mei_device *dev); 290 291 bool (*hw_is_ready)(struct mei_device *dev); 292 int (*hw_reset)(struct mei_device *dev, bool enable); 293 int (*hw_start)(struct mei_device *dev); 294 void (*hw_config)(struct mei_device *dev); 295 296 int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts); 297 enum mei_pg_state (*pg_state)(struct mei_device *dev); 298 bool (*pg_in_transition)(struct mei_device *dev); 299 bool (*pg_is_enabled)(struct mei_device *dev); 300 301 void (*intr_clear)(struct mei_device *dev); 302 void (*intr_enable)(struct mei_device *dev); 303 void (*intr_disable)(struct mei_device *dev); 304 void (*synchronize_irq)(struct mei_device *dev); 305 306 int (*hbuf_free_slots)(struct mei_device *dev); 307 bool (*hbuf_is_ready)(struct mei_device *dev); 308 size_t (*hbuf_max_len)(const struct mei_device *dev); 309 int (*write)(struct mei_device *dev, 310 struct mei_msg_hdr *hdr, 311 const unsigned char *buf); 312 313 int (*rdbuf_full_slots)(struct mei_device *dev); 314 315 u32 (*read_hdr)(const struct mei_device *dev); 316 int (*read)(struct mei_device *dev, 317 unsigned char *buf, unsigned long len); 318 }; 319 320 /* MEI bus API*/ 321 void mei_cl_bus_rescan(struct mei_device *bus); 322 void mei_cl_bus_rescan_work(struct work_struct *work); 323 void mei_cl_bus_dev_fixup(struct mei_cl_device *dev); 324 ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, 325 unsigned int mode); 326 ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length, 327 unsigned int mode); 328 bool mei_cl_bus_rx_event(struct mei_cl *cl); 329 bool mei_cl_bus_notify_event(struct mei_cl *cl); 330 void mei_cl_bus_remove_devices(struct mei_device *bus); 331 bool mei_cl_bus_module_get(struct mei_cl *cl); 332 void mei_cl_bus_module_put(struct mei_cl *cl); 333 int mei_cl_bus_init(void); 334 void mei_cl_bus_exit(void); 335 336 /** 337 * enum mei_pg_event - power gating transition events 338 * 339 * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition 340 * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete 341 * @MEI_PG_EVENT_RECEIVED: the driver received pg event 342 * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt 343 * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt 344 */ 345 enum mei_pg_event { 346 MEI_PG_EVENT_IDLE, 347 MEI_PG_EVENT_WAIT, 348 MEI_PG_EVENT_RECEIVED, 349 MEI_PG_EVENT_INTR_WAIT, 350 MEI_PG_EVENT_INTR_RECEIVED, 351 }; 352 353 /** 354 * enum mei_pg_state - device internal power gating state 355 * 356 * @MEI_PG_OFF: device is not power gated - it is active 357 * @MEI_PG_ON: device is power gated - it is in lower power state 358 */ 359 enum mei_pg_state { 360 MEI_PG_OFF = 0, 361 MEI_PG_ON = 1, 362 }; 363 364 const char *mei_pg_state_str(enum mei_pg_state state); 365 366 /** 367 * struct mei_device - MEI private device struct 368 * 369 * @dev : device on a bus 370 * @cdev : character device 371 * @minor : minor number allocated for device 372 * 373 * @write_list : write pending list 374 * @write_waiting_list : write completion list 375 * @ctrl_wr_list : pending control write list 376 * @ctrl_rd_list : pending control read list 377 * 378 * @file_list : list of opened handles 379 * @open_handle_count: number of opened handles 380 * 381 * @device_lock : big device lock 382 * @timer_work : MEI timer delayed work (timeouts) 383 * 384 * @recvd_hw_ready : hw ready message received flag 385 * 386 * @wait_hw_ready : wait queue for receive HW ready message form FW 387 * @wait_pg : wait queue for receive PG message from FW 388 * @wait_hbm_start : wait queue for receive HBM start message from FW 389 * 390 * @reset_count : number of consecutive resets 391 * @dev_state : device state 392 * @hbm_state : state of host bus message protocol 393 * @init_clients_timer : HBM init handshake timeout 394 * 395 * @pg_event : power gating event 396 * @pg_domain : runtime PM domain 397 * 398 * @rd_msg_buf : control messages buffer 399 * @rd_msg_hdr : read message header storage 400 * 401 * @hbuf_depth : depth of hardware host/write buffer is slots 402 * @hbuf_is_ready : query if the host host/write buffer is ready 403 * 404 * @version : HBM protocol version in use 405 * @hbm_f_pg_supported : hbm feature pgi protocol 406 * @hbm_f_dc_supported : hbm feature dynamic clients 407 * @hbm_f_dot_supported : hbm feature disconnect on timeout 408 * @hbm_f_ev_supported : hbm feature event notification 409 * @hbm_f_fa_supported : hbm feature fixed address client 410 * @hbm_f_ie_supported : hbm feature immediate reply to enum request 411 * @hbm_f_os_supported : hbm feature support OS ver message 412 * 413 * @me_clients_rwsem: rw lock over me_clients list 414 * @me_clients : list of FW clients 415 * @me_clients_map : FW clients bit map 416 * @host_clients_map : host clients id pool 417 * 418 * @allow_fixed_address: allow user space to connect a fixed client 419 * @override_fixed_address: force allow fixed address behavior 420 * 421 * @amthif_cmd_list : amthif list for cmd waiting 422 * @iamthif_cl : amthif host client 423 * @iamthif_open_count : number of opened amthif connections 424 * @iamthif_stall_timer : timer to detect amthif hang 425 * @iamthif_state : amthif processor state 426 * @iamthif_canceled : current amthif command is canceled 427 * 428 * @reset_work : work item for the device reset 429 * @bus_rescan_work : work item for the bus rescan 430 * 431 * @device_list : mei client bus list 432 * @cl_bus_lock : client bus list lock 433 * 434 * @dbgfs_dir : debugfs mei root directory 435 * 436 * @ops: : hw specific operations 437 * @hw : hw specific data 438 */ 439 struct mei_device { 440 struct device *dev; 441 struct cdev cdev; 442 int minor; 443 444 struct list_head write_list; 445 struct list_head write_waiting_list; 446 struct list_head ctrl_wr_list; 447 struct list_head ctrl_rd_list; 448 449 struct list_head file_list; 450 long open_handle_count; 451 452 struct mutex device_lock; 453 struct delayed_work timer_work; 454 455 bool recvd_hw_ready; 456 /* 457 * waiting queue for receive message from FW 458 */ 459 wait_queue_head_t wait_hw_ready; 460 wait_queue_head_t wait_pg; 461 wait_queue_head_t wait_hbm_start; 462 463 /* 464 * mei device states 465 */ 466 unsigned long reset_count; 467 enum mei_dev_state dev_state; 468 enum mei_hbm_state hbm_state; 469 u16 init_clients_timer; 470 471 /* 472 * Power Gating support 473 */ 474 enum mei_pg_event pg_event; 475 #ifdef CONFIG_PM 476 struct dev_pm_domain pg_domain; 477 #endif /* CONFIG_PM */ 478 479 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; 480 u32 rd_msg_hdr; 481 482 /* write buffer */ 483 u8 hbuf_depth; 484 bool hbuf_is_ready; 485 486 struct hbm_version version; 487 unsigned int hbm_f_pg_supported:1; 488 unsigned int hbm_f_dc_supported:1; 489 unsigned int hbm_f_dot_supported:1; 490 unsigned int hbm_f_ev_supported:1; 491 unsigned int hbm_f_fa_supported:1; 492 unsigned int hbm_f_ie_supported:1; 493 unsigned int hbm_f_os_supported:1; 494 495 struct rw_semaphore me_clients_rwsem; 496 struct list_head me_clients; 497 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); 498 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); 499 500 bool allow_fixed_address; 501 bool override_fixed_address; 502 503 /* amthif list for cmd waiting */ 504 struct list_head amthif_cmd_list; 505 struct mei_cl iamthif_cl; 506 long iamthif_open_count; 507 u32 iamthif_stall_timer; 508 enum iamthif_states iamthif_state; 509 bool iamthif_canceled; 510 511 struct work_struct reset_work; 512 struct work_struct bus_rescan_work; 513 514 /* List of bus devices */ 515 struct list_head device_list; 516 struct mutex cl_bus_lock; 517 518 #if IS_ENABLED(CONFIG_DEBUG_FS) 519 struct dentry *dbgfs_dir; 520 #endif /* CONFIG_DEBUG_FS */ 521 522 523 const struct mei_hw_ops *ops; 524 char hw[0] __aligned(sizeof(void *)); 525 }; 526 527 static inline unsigned long mei_secs_to_jiffies(unsigned long sec) 528 { 529 return msecs_to_jiffies(sec * MSEC_PER_SEC); 530 } 531 532 /** 533 * mei_data2slots - get slots - number of (dwords) from a message length 534 * + size of the mei header 535 * 536 * @length: size of the messages in bytes 537 * 538 * Return: number of slots 539 */ 540 static inline u32 mei_data2slots(size_t length) 541 { 542 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); 543 } 544 545 /** 546 * mei_slots2data - get data in slots - bytes from slots 547 * 548 * @slots: number of available slots 549 * 550 * Return: number of bytes in slots 551 */ 552 static inline u32 mei_slots2data(int slots) 553 { 554 return slots * 4; 555 } 556 557 /* 558 * mei init function prototypes 559 */ 560 void mei_device_init(struct mei_device *dev, 561 struct device *device, 562 const struct mei_hw_ops *hw_ops); 563 int mei_reset(struct mei_device *dev); 564 int mei_start(struct mei_device *dev); 565 int mei_restart(struct mei_device *dev); 566 void mei_stop(struct mei_device *dev); 567 void mei_cancel_work(struct mei_device *dev); 568 569 /* 570 * MEI interrupt functions prototype 571 */ 572 573 void mei_timer(struct work_struct *work); 574 void mei_schedule_stall_timer(struct mei_device *dev); 575 int mei_irq_read_handler(struct mei_device *dev, 576 struct list_head *cmpl_list, s32 *slots); 577 578 int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list); 579 void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list); 580 581 /* 582 * AMTHIF - AMT Host Interface Functions 583 */ 584 void mei_amthif_reset_params(struct mei_device *dev); 585 586 int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl); 587 588 unsigned int mei_amthif_poll(struct file *file, poll_table *wait); 589 590 int mei_amthif_release(struct mei_device *dev, struct file *file); 591 592 int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); 593 int mei_amthif_run_next_cmd(struct mei_device *dev); 594 int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 595 struct list_head *cmpl_list); 596 597 void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb); 598 int mei_amthif_irq_read_msg(struct mei_cl *cl, 599 struct mei_msg_hdr *mei_hdr, 600 struct list_head *cmpl_list); 601 int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); 602 603 /* 604 * Register Access Function 605 */ 606 607 608 static inline void mei_hw_config(struct mei_device *dev) 609 { 610 dev->ops->hw_config(dev); 611 } 612 613 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev) 614 { 615 return dev->ops->pg_state(dev); 616 } 617 618 static inline bool mei_pg_in_transition(struct mei_device *dev) 619 { 620 return dev->ops->pg_in_transition(dev); 621 } 622 623 static inline bool mei_pg_is_enabled(struct mei_device *dev) 624 { 625 return dev->ops->pg_is_enabled(dev); 626 } 627 628 static inline int mei_hw_reset(struct mei_device *dev, bool enable) 629 { 630 return dev->ops->hw_reset(dev, enable); 631 } 632 633 static inline int mei_hw_start(struct mei_device *dev) 634 { 635 return dev->ops->hw_start(dev); 636 } 637 638 static inline void mei_clear_interrupts(struct mei_device *dev) 639 { 640 dev->ops->intr_clear(dev); 641 } 642 643 static inline void mei_enable_interrupts(struct mei_device *dev) 644 { 645 dev->ops->intr_enable(dev); 646 } 647 648 static inline void mei_disable_interrupts(struct mei_device *dev) 649 { 650 dev->ops->intr_disable(dev); 651 } 652 653 static inline void mei_synchronize_irq(struct mei_device *dev) 654 { 655 dev->ops->synchronize_irq(dev); 656 } 657 658 static inline bool mei_host_is_ready(struct mei_device *dev) 659 { 660 return dev->ops->host_is_ready(dev); 661 } 662 static inline bool mei_hw_is_ready(struct mei_device *dev) 663 { 664 return dev->ops->hw_is_ready(dev); 665 } 666 667 static inline bool mei_hbuf_is_ready(struct mei_device *dev) 668 { 669 return dev->ops->hbuf_is_ready(dev); 670 } 671 672 static inline int mei_hbuf_empty_slots(struct mei_device *dev) 673 { 674 return dev->ops->hbuf_free_slots(dev); 675 } 676 677 static inline size_t mei_hbuf_max_len(const struct mei_device *dev) 678 { 679 return dev->ops->hbuf_max_len(dev); 680 } 681 682 static inline int mei_write_message(struct mei_device *dev, 683 struct mei_msg_hdr *hdr, const void *buf) 684 { 685 return dev->ops->write(dev, hdr, buf); 686 } 687 688 static inline u32 mei_read_hdr(const struct mei_device *dev) 689 { 690 return dev->ops->read_hdr(dev); 691 } 692 693 static inline void mei_read_slots(struct mei_device *dev, 694 unsigned char *buf, unsigned long len) 695 { 696 dev->ops->read(dev, buf, len); 697 } 698 699 static inline int mei_count_full_read_slots(struct mei_device *dev) 700 { 701 return dev->ops->rdbuf_full_slots(dev); 702 } 703 704 static inline int mei_fw_status(struct mei_device *dev, 705 struct mei_fw_status *fw_status) 706 { 707 return dev->ops->fw_status(dev, fw_status); 708 } 709 710 bool mei_hbuf_acquire(struct mei_device *dev); 711 712 bool mei_write_is_idle(struct mei_device *dev); 713 714 void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr); 715 716 #if IS_ENABLED(CONFIG_DEBUG_FS) 717 int mei_dbgfs_register(struct mei_device *dev, const char *name); 718 void mei_dbgfs_deregister(struct mei_device *dev); 719 #else 720 static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) 721 { 722 return 0; 723 } 724 static inline void mei_dbgfs_deregister(struct mei_device *dev) {} 725 #endif /* CONFIG_DEBUG_FS */ 726 727 int mei_register(struct mei_device *dev, struct device *parent); 728 void mei_deregister(struct mei_device *dev); 729 730 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d" 731 #define MEI_HDR_PRM(hdr) \ 732 (hdr)->host_addr, (hdr)->me_addr, \ 733 (hdr)->length, (hdr)->internal, (hdr)->msg_complete 734 735 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len); 736 /** 737 * mei_fw_status_str - fetch and convert fw status registers to printable string 738 * 739 * @dev: the device structure 740 * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ 741 * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ 742 * 743 * Return: number of bytes written or < 0 on failure 744 */ 745 static inline ssize_t mei_fw_status_str(struct mei_device *dev, 746 char *buf, size_t len) 747 { 748 struct mei_fw_status fw_status; 749 int ret; 750 751 buf[0] = '\0'; 752 753 ret = mei_fw_status(dev, &fw_status); 754 if (ret) 755 return ret; 756 757 ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ); 758 759 return ret; 760 } 761 762 763 #endif 764