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 int mei_cl_bus_init(void); 332 void mei_cl_bus_exit(void); 333 334 /** 335 * enum mei_pg_event - power gating transition events 336 * 337 * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition 338 * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete 339 * @MEI_PG_EVENT_RECEIVED: the driver received pg event 340 * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt 341 * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt 342 */ 343 enum mei_pg_event { 344 MEI_PG_EVENT_IDLE, 345 MEI_PG_EVENT_WAIT, 346 MEI_PG_EVENT_RECEIVED, 347 MEI_PG_EVENT_INTR_WAIT, 348 MEI_PG_EVENT_INTR_RECEIVED, 349 }; 350 351 /** 352 * enum mei_pg_state - device internal power gating state 353 * 354 * @MEI_PG_OFF: device is not power gated - it is active 355 * @MEI_PG_ON: device is power gated - it is in lower power state 356 */ 357 enum mei_pg_state { 358 MEI_PG_OFF = 0, 359 MEI_PG_ON = 1, 360 }; 361 362 const char *mei_pg_state_str(enum mei_pg_state state); 363 364 /** 365 * struct mei_device - MEI private device struct 366 * 367 * @dev : device on a bus 368 * @cdev : character device 369 * @minor : minor number allocated for device 370 * 371 * @write_list : write pending list 372 * @write_waiting_list : write completion list 373 * @ctrl_wr_list : pending control write list 374 * @ctrl_rd_list : pending control read list 375 * 376 * @file_list : list of opened handles 377 * @open_handle_count: number of opened handles 378 * 379 * @device_lock : big device lock 380 * @timer_work : MEI timer delayed work (timeouts) 381 * 382 * @recvd_hw_ready : hw ready message received flag 383 * 384 * @wait_hw_ready : wait queue for receive HW ready message form FW 385 * @wait_pg : wait queue for receive PG message from FW 386 * @wait_hbm_start : wait queue for receive HBM start message from FW 387 * 388 * @reset_count : number of consecutive resets 389 * @dev_state : device state 390 * @hbm_state : state of host bus message protocol 391 * @init_clients_timer : HBM init handshake timeout 392 * 393 * @pg_event : power gating event 394 * @pg_domain : runtime PM domain 395 * 396 * @rd_msg_buf : control messages buffer 397 * @rd_msg_hdr : read message header storage 398 * 399 * @hbuf_depth : depth of hardware host/write buffer is slots 400 * @hbuf_is_ready : query if the host host/write buffer is ready 401 * 402 * @version : HBM protocol version in use 403 * @hbm_f_pg_supported : hbm feature pgi protocol 404 * @hbm_f_dc_supported : hbm feature dynamic clients 405 * @hbm_f_dot_supported : hbm feature disconnect on timeout 406 * @hbm_f_ev_supported : hbm feature event notification 407 * @hbm_f_fa_supported : hbm feature fixed address client 408 * @hbm_f_ie_supported : hbm feature immediate reply to enum request 409 * @hbm_f_os_supported : hbm feature support OS ver message 410 * 411 * @me_clients_rwsem: rw lock over me_clients list 412 * @me_clients : list of FW clients 413 * @me_clients_map : FW clients bit map 414 * @host_clients_map : host clients id pool 415 * 416 * @allow_fixed_address: allow user space to connect a fixed client 417 * @override_fixed_address: force allow fixed address behavior 418 * 419 * @amthif_cmd_list : amthif list for cmd waiting 420 * @iamthif_cl : amthif host client 421 * @iamthif_open_count : number of opened amthif connections 422 * @iamthif_stall_timer : timer to detect amthif hang 423 * @iamthif_state : amthif processor state 424 * @iamthif_canceled : current amthif command is canceled 425 * 426 * @reset_work : work item for the device reset 427 * @bus_rescan_work : work item for the bus rescan 428 * 429 * @device_list : mei client bus list 430 * @cl_bus_lock : client bus list lock 431 * 432 * @dbgfs_dir : debugfs mei root directory 433 * 434 * @ops: : hw specific operations 435 * @hw : hw specific data 436 */ 437 struct mei_device { 438 struct device *dev; 439 struct cdev cdev; 440 int minor; 441 442 struct mei_cl_cb write_list; 443 struct mei_cl_cb write_waiting_list; 444 struct mei_cl_cb ctrl_wr_list; 445 struct mei_cl_cb ctrl_rd_list; 446 447 struct list_head file_list; 448 long open_handle_count; 449 450 struct mutex device_lock; 451 struct delayed_work timer_work; 452 453 bool recvd_hw_ready; 454 /* 455 * waiting queue for receive message from FW 456 */ 457 wait_queue_head_t wait_hw_ready; 458 wait_queue_head_t wait_pg; 459 wait_queue_head_t wait_hbm_start; 460 461 /* 462 * mei device states 463 */ 464 unsigned long reset_count; 465 enum mei_dev_state dev_state; 466 enum mei_hbm_state hbm_state; 467 u16 init_clients_timer; 468 469 /* 470 * Power Gating support 471 */ 472 enum mei_pg_event pg_event; 473 #ifdef CONFIG_PM 474 struct dev_pm_domain pg_domain; 475 #endif /* CONFIG_PM */ 476 477 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; 478 u32 rd_msg_hdr; 479 480 /* write buffer */ 481 u8 hbuf_depth; 482 bool hbuf_is_ready; 483 484 struct hbm_version version; 485 unsigned int hbm_f_pg_supported:1; 486 unsigned int hbm_f_dc_supported:1; 487 unsigned int hbm_f_dot_supported:1; 488 unsigned int hbm_f_ev_supported:1; 489 unsigned int hbm_f_fa_supported:1; 490 unsigned int hbm_f_ie_supported:1; 491 unsigned int hbm_f_os_supported:1; 492 493 struct rw_semaphore me_clients_rwsem; 494 struct list_head me_clients; 495 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); 496 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); 497 498 bool allow_fixed_address; 499 bool override_fixed_address; 500 501 /* amthif list for cmd waiting */ 502 struct mei_cl_cb amthif_cmd_list; 503 struct mei_cl iamthif_cl; 504 long iamthif_open_count; 505 u32 iamthif_stall_timer; 506 enum iamthif_states iamthif_state; 507 bool iamthif_canceled; 508 509 struct work_struct reset_work; 510 struct work_struct bus_rescan_work; 511 512 /* List of bus devices */ 513 struct list_head device_list; 514 struct mutex cl_bus_lock; 515 516 #if IS_ENABLED(CONFIG_DEBUG_FS) 517 struct dentry *dbgfs_dir; 518 #endif /* CONFIG_DEBUG_FS */ 519 520 521 const struct mei_hw_ops *ops; 522 char hw[0] __aligned(sizeof(void *)); 523 }; 524 525 static inline unsigned long mei_secs_to_jiffies(unsigned long sec) 526 { 527 return msecs_to_jiffies(sec * MSEC_PER_SEC); 528 } 529 530 /** 531 * mei_data2slots - get slots - number of (dwords) from a message length 532 * + size of the mei header 533 * 534 * @length: size of the messages in bytes 535 * 536 * Return: number of slots 537 */ 538 static inline u32 mei_data2slots(size_t length) 539 { 540 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); 541 } 542 543 /** 544 * mei_slots2data - get data in slots - bytes from slots 545 * 546 * @slots: number of available slots 547 * 548 * Return: number of bytes in slots 549 */ 550 static inline u32 mei_slots2data(int slots) 551 { 552 return slots * 4; 553 } 554 555 /* 556 * mei init function prototypes 557 */ 558 void mei_device_init(struct mei_device *dev, 559 struct device *device, 560 const struct mei_hw_ops *hw_ops); 561 int mei_reset(struct mei_device *dev); 562 int mei_start(struct mei_device *dev); 563 int mei_restart(struct mei_device *dev); 564 void mei_stop(struct mei_device *dev); 565 void mei_cancel_work(struct mei_device *dev); 566 567 /* 568 * MEI interrupt functions prototype 569 */ 570 571 void mei_timer(struct work_struct *work); 572 void mei_schedule_stall_timer(struct mei_device *dev); 573 int mei_irq_read_handler(struct mei_device *dev, 574 struct mei_cl_cb *cmpl_list, s32 *slots); 575 576 int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); 577 void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); 578 579 /* 580 * AMTHIF - AMT Host Interface Functions 581 */ 582 void mei_amthif_reset_params(struct mei_device *dev); 583 584 int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl); 585 586 unsigned int mei_amthif_poll(struct file *file, poll_table *wait); 587 588 int mei_amthif_release(struct mei_device *dev, struct file *file); 589 590 int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); 591 int mei_amthif_run_next_cmd(struct mei_device *dev); 592 int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 593 struct mei_cl_cb *cmpl_list); 594 595 void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb); 596 int mei_amthif_irq_read_msg(struct mei_cl *cl, 597 struct mei_msg_hdr *mei_hdr, 598 struct mei_cl_cb *complete_list); 599 int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); 600 601 /* 602 * Register Access Function 603 */ 604 605 606 static inline void mei_hw_config(struct mei_device *dev) 607 { 608 dev->ops->hw_config(dev); 609 } 610 611 static inline enum mei_pg_state mei_pg_state(struct mei_device *dev) 612 { 613 return dev->ops->pg_state(dev); 614 } 615 616 static inline bool mei_pg_in_transition(struct mei_device *dev) 617 { 618 return dev->ops->pg_in_transition(dev); 619 } 620 621 static inline bool mei_pg_is_enabled(struct mei_device *dev) 622 { 623 return dev->ops->pg_is_enabled(dev); 624 } 625 626 static inline int mei_hw_reset(struct mei_device *dev, bool enable) 627 { 628 return dev->ops->hw_reset(dev, enable); 629 } 630 631 static inline int mei_hw_start(struct mei_device *dev) 632 { 633 return dev->ops->hw_start(dev); 634 } 635 636 static inline void mei_clear_interrupts(struct mei_device *dev) 637 { 638 dev->ops->intr_clear(dev); 639 } 640 641 static inline void mei_enable_interrupts(struct mei_device *dev) 642 { 643 dev->ops->intr_enable(dev); 644 } 645 646 static inline void mei_disable_interrupts(struct mei_device *dev) 647 { 648 dev->ops->intr_disable(dev); 649 } 650 651 static inline void mei_synchronize_irq(struct mei_device *dev) 652 { 653 dev->ops->synchronize_irq(dev); 654 } 655 656 static inline bool mei_host_is_ready(struct mei_device *dev) 657 { 658 return dev->ops->host_is_ready(dev); 659 } 660 static inline bool mei_hw_is_ready(struct mei_device *dev) 661 { 662 return dev->ops->hw_is_ready(dev); 663 } 664 665 static inline bool mei_hbuf_is_ready(struct mei_device *dev) 666 { 667 return dev->ops->hbuf_is_ready(dev); 668 } 669 670 static inline int mei_hbuf_empty_slots(struct mei_device *dev) 671 { 672 return dev->ops->hbuf_free_slots(dev); 673 } 674 675 static inline size_t mei_hbuf_max_len(const struct mei_device *dev) 676 { 677 return dev->ops->hbuf_max_len(dev); 678 } 679 680 static inline int mei_write_message(struct mei_device *dev, 681 struct mei_msg_hdr *hdr, const void *buf) 682 { 683 return dev->ops->write(dev, hdr, buf); 684 } 685 686 static inline u32 mei_read_hdr(const struct mei_device *dev) 687 { 688 return dev->ops->read_hdr(dev); 689 } 690 691 static inline void mei_read_slots(struct mei_device *dev, 692 unsigned char *buf, unsigned long len) 693 { 694 dev->ops->read(dev, buf, len); 695 } 696 697 static inline int mei_count_full_read_slots(struct mei_device *dev) 698 { 699 return dev->ops->rdbuf_full_slots(dev); 700 } 701 702 static inline int mei_fw_status(struct mei_device *dev, 703 struct mei_fw_status *fw_status) 704 { 705 return dev->ops->fw_status(dev, fw_status); 706 } 707 708 bool mei_hbuf_acquire(struct mei_device *dev); 709 710 bool mei_write_is_idle(struct mei_device *dev); 711 712 void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr); 713 714 #if IS_ENABLED(CONFIG_DEBUG_FS) 715 int mei_dbgfs_register(struct mei_device *dev, const char *name); 716 void mei_dbgfs_deregister(struct mei_device *dev); 717 #else 718 static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) 719 { 720 return 0; 721 } 722 static inline void mei_dbgfs_deregister(struct mei_device *dev) {} 723 #endif /* CONFIG_DEBUG_FS */ 724 725 int mei_register(struct mei_device *dev, struct device *parent); 726 void mei_deregister(struct mei_device *dev); 727 728 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d" 729 #define MEI_HDR_PRM(hdr) \ 730 (hdr)->host_addr, (hdr)->me_addr, \ 731 (hdr)->length, (hdr)->internal, (hdr)->msg_complete 732 733 ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len); 734 /** 735 * mei_fw_status_str - fetch and convert fw status registers to printable string 736 * 737 * @dev: the device structure 738 * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ 739 * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ 740 * 741 * Return: number of bytes written or < 0 on failure 742 */ 743 static inline ssize_t mei_fw_status_str(struct mei_device *dev, 744 char *buf, size_t len) 745 { 746 struct mei_fw_status fw_status; 747 int ret; 748 749 buf[0] = '\0'; 750 751 ret = mei_fw_status(dev, &fw_status); 752 if (ret) 753 return ret; 754 755 ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ); 756 757 return ret; 758 } 759 760 761 #endif 762