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

Merge tag 'char-misc-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc

Pull char/misc patches from Greg Kroah-Hartman:
"Here's the "big" pull request for 3.6-rc1 for the char/misc drivers.

It's really just a few updates to the mei driver, plus 4 other tiny
patches, nothing big at all.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"

* tag 'char-misc-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
mei: use module_pci_driver
powerpc/BSR: cleanup the error path of bsr_init
mei: mei_irq_thread_write_handler - line break fix
mei: streamline the _mei_irq_thread_close/ioctol functions
mei: introduce mei_data2slots wrapper
mei: mei_wd_host_init: update the comment
mei: remove write only wariable wd_due_counter
mei: mei_device can be const for mei register access functions
mei: revamp host buffer interface function
mei: don't query HCSR for host buffer depth
mei: group wd_interface_reg with watchdog variables within struct mei_device
mei: mei_irq_thread_write_handler check for overflow
mei: make mei_write_message more readable
mei: check for error codes that mei_flow_ctrl_creds retuns
misc: at25: Parse dt settings
misc: hpilo: increase number of max supported channels
mei: mei.txt: minor grammar fixes

+244 -261
+21
Documentation/devicetree/bindings/misc/at25.txt
··· 1 + Atmel AT25 eeprom 2 + 3 + Required properties: 4 + - compatible : "atmel,at25". 5 + - reg : chip select number 6 + - spi-max-frequency : max spi frequency to use 7 + 8 + - at25,byte-len : total eeprom size in bytes 9 + - at25,addr-mode : addr-mode flags, as defined in include/linux/spi/eeprom.h 10 + - at25,page-size : size of the eeprom page 11 + 12 + Examples: 13 + at25@0 { 14 + compatible = "atmel,at25"; 15 + reg = <0> 16 + spi-max-frequency = <5000000>; 17 + 18 + at25,byte-len = <0x8000>; 19 + at25,addr-mode = <2>; 20 + at25,page-size = <64>; 21 + };
+7 -7
Documentation/misc-devices/mei/mei.txt
··· 50 50 The driver exposes a misc device called /dev/mei. 51 51 52 52 An application maintains communication with an Intel ME feature while 53 - /dev/mei is open. The binding to a specific features is performed by calling 53 + /dev/mei is open. The binding to a specific feature is performed by calling 54 54 MEI_CONNECT_CLIENT_IOCTL, which passes the desired UUID. 55 55 The number of instances of an Intel ME feature that can be opened 56 56 at the same time depends on the Intel ME feature, but most of the 57 57 features allow only a single instance. 58 58 59 59 The Intel AMT Host Interface (Intel AMTHI) feature supports multiple 60 - simultaneous user applications. Therefore, the Intel MEI driver handles 61 - this internally by maintaining request queues for the applications. 60 + simultaneous user connected applications. The Intel MEI driver 61 + handles this internally by maintaining request queues for the applications. 62 62 63 - The driver is oblivious to data that is passed between firmware feature 63 + The driver is transparent to data that are passed between firmware feature 64 64 and host application. 65 65 66 66 Because some of the Intel ME features can change the system 67 67 configuration, the driver by default allows only a privileged 68 68 user to access it. 69 69 70 - A code snippet for an application communicating with 71 - Intel AMTHI client: 70 + A code snippet for an application communicating with Intel AMTHI client: 71 + 72 72 struct mei_connect_client_data data; 73 73 fd = open(MEI_DEVICE); 74 74 ··· 185 185 2) Intel MEI driver - connects to the watchdog feature, configures the 186 186 watchdog and sends the heartbeats. 187 187 188 - The Intel MEI driver uses the kernel watchdog to configure the Intel AMT 188 + The Intel MEI driver uses the kernel watchdog API to configure the Intel AMT 189 189 Watchdog and to send heartbeats to it. The default timeout of the 190 190 watchdog is 120 seconds. 191 191
+3 -3
drivers/char/bsr.c
··· 297 297 struct device_node *np; 298 298 dev_t bsr_dev; 299 299 int ret = -ENODEV; 300 - int result; 301 300 302 301 np = of_find_compatible_node(NULL, NULL, "ibm,bsr"); 303 302 if (!np) ··· 305 306 bsr_class = class_create(THIS_MODULE, "bsr"); 306 307 if (IS_ERR(bsr_class)) { 307 308 printk(KERN_ERR "class_create() failed for bsr_class\n"); 309 + ret = PTR_ERR(bsr_class); 308 310 goto out_err_1; 309 311 } 310 312 bsr_class->dev_attrs = bsr_dev_attrs; 311 313 312 - result = alloc_chrdev_region(&bsr_dev, 0, BSR_MAX_DEVS, "bsr"); 314 + ret = alloc_chrdev_region(&bsr_dev, 0, BSR_MAX_DEVS, "bsr"); 313 315 bsr_major = MAJOR(bsr_dev); 314 - if (result < 0) { 316 + if (ret < 0) { 315 317 printk(KERN_ERR "alloc_chrdev_region() failed for bsr\n"); 316 318 goto out_err_2; 317 319 }
+45 -16
drivers/misc/eeprom/at25.c
··· 19 19 20 20 #include <linux/spi/spi.h> 21 21 #include <linux/spi/eeprom.h> 22 - 22 + #include <linux/of.h> 23 23 24 24 /* 25 25 * NOTE: this is an *EEPROM* driver. The vagaries of product naming ··· 305 305 static int at25_probe(struct spi_device *spi) 306 306 { 307 307 struct at25_data *at25 = NULL; 308 - const struct spi_eeprom *chip; 308 + struct spi_eeprom chip; 309 + struct device_node *np = spi->dev.of_node; 309 310 int err; 310 311 int sr; 311 312 int addrlen; 312 313 313 314 /* Chip description */ 314 - chip = spi->dev.platform_data; 315 - if (!chip) { 316 - dev_dbg(&spi->dev, "no chip description\n"); 317 - err = -ENODEV; 318 - goto fail; 319 - } 315 + if (!spi->dev.platform_data) { 316 + if (np) { 317 + u32 val; 318 + 319 + memset(&chip, 0, sizeof(chip)); 320 + strncpy(chip.name, np->name, 10); 321 + 322 + err = of_property_read_u32(np, "at25,byte-len", &val); 323 + if (err) { 324 + dev_dbg(&spi->dev, "invalid chip dt description\n"); 325 + goto fail; 326 + } 327 + chip.byte_len = val; 328 + 329 + err = of_property_read_u32(np, "at25,addr-mode", &val); 330 + if (err) { 331 + dev_dbg(&spi->dev, "invalid chip dt description\n"); 332 + goto fail; 333 + } 334 + chip.flags = (u16)val; 335 + 336 + err = of_property_read_u32(np, "at25,page-size", &val); 337 + if (err) { 338 + dev_dbg(&spi->dev, "invalid chip dt description\n"); 339 + goto fail; 340 + } 341 + chip.page_size = (u16)val; 342 + } else { 343 + dev_dbg(&spi->dev, "no chip description\n"); 344 + err = -ENODEV; 345 + goto fail; 346 + } 347 + } else 348 + chip = *(struct spi_eeprom *)spi->dev.platform_data; 320 349 321 350 /* For now we only support 8/16/24 bit addressing */ 322 - if (chip->flags & EE_ADDR1) 351 + if (chip.flags & EE_ADDR1) 323 352 addrlen = 1; 324 - else if (chip->flags & EE_ADDR2) 353 + else if (chip.flags & EE_ADDR2) 325 354 addrlen = 2; 326 - else if (chip->flags & EE_ADDR3) 355 + else if (chip.flags & EE_ADDR3) 327 356 addrlen = 3; 328 357 else { 329 358 dev_dbg(&spi->dev, "unsupported address type\n"); ··· 377 348 } 378 349 379 350 mutex_init(&at25->lock); 380 - at25->chip = *chip; 351 + at25->chip = chip; 381 352 at25->spi = spi_dev_get(spi); 382 353 dev_set_drvdata(&spi->dev, at25); 383 354 at25->addrlen = addrlen; ··· 398 369 at25->mem.read = at25_mem_read; 399 370 400 371 at25->bin.size = at25->chip.byte_len; 401 - if (!(chip->flags & EE_READONLY)) { 372 + if (!(chip.flags & EE_READONLY)) { 402 373 at25->bin.write = at25_bin_write; 403 374 at25->bin.attr.mode |= S_IWUSR; 404 375 at25->mem.write = at25_mem_write; ··· 408 379 if (err) 409 380 goto fail; 410 381 411 - if (chip->setup) 412 - chip->setup(&at25->mem, chip->context); 382 + if (chip.setup) 383 + chip.setup(&at25->mem, chip.context); 413 384 414 385 dev_info(&spi->dev, "%Zd %s %s eeprom%s, pagesize %u\n", 415 386 (at25->bin.size < 1024) ··· 417 388 : (at25->bin.size / 1024), 418 389 (at25->bin.size < 1024) ? "Byte" : "KByte", 419 390 at25->chip.name, 420 - (chip->flags & EE_READONLY) ? " (readonly)" : "", 391 + (chip.flags & EE_READONLY) ? " (readonly)" : "", 421 392 at25->chip.page_size); 422 393 return 0; 423 394 fail:
+21 -12
drivers/misc/hpilo.c
··· 30 30 31 31 static struct class *ilo_class; 32 32 static unsigned int ilo_major; 33 + static unsigned int max_ccb = MIN_CCB; 33 34 static char ilo_hwdev[MAX_ILO_DEV]; 34 35 35 36 static inline int get_entry_id(int entry) ··· 425 424 * Mapped memory is zeroed on ilo reset, so set a per ccb flag 426 425 * to indicate that this ccb needs to be closed and reopened. 427 426 */ 428 - for (slot = 0; slot < MAX_CCB; slot++) { 427 + for (slot = 0; slot < max_ccb; slot++) { 429 428 if (!hw->ccb_alloc[slot]) 430 429 continue; 431 430 set_channel_reset(&hw->ccb_alloc[slot]->driver_ccb); ··· 536 535 struct ilo_hwinfo *hw; 537 536 unsigned long flags; 538 537 539 - slot = iminor(ip) % MAX_CCB; 538 + slot = iminor(ip) % max_ccb; 540 539 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev); 541 540 542 541 spin_lock(&hw->open_lock); ··· 567 566 struct ilo_hwinfo *hw; 568 567 unsigned long flags; 569 568 570 - slot = iminor(ip) % MAX_CCB; 569 + slot = iminor(ip) % max_ccb; 571 570 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev); 572 571 573 572 /* new ccb allocation */ ··· 664 663 ilo_set_reset(hw); 665 664 } 666 665 667 - for (i = 0; i < MAX_CCB; i++) { 666 + for (i = 0; i < max_ccb; i++) { 668 667 if (!hw->ccb_alloc[i]) 669 668 continue; 670 669 if (pending & (1 << i)) ··· 698 697 } 699 698 700 699 /* map the adapter shared memory region */ 701 - hw->ram_vaddr = pci_iomap(pdev, 2, MAX_CCB * ILOHW_CCB_SZ); 700 + hw->ram_vaddr = pci_iomap(pdev, 2, max_ccb * ILOHW_CCB_SZ); 702 701 if (hw->ram_vaddr == NULL) { 703 702 dev_err(&pdev->dev, "Error mapping shared mem\n"); 704 703 goto mmio_free; 705 704 } 706 705 707 706 /* map the doorbell aperture */ 708 - hw->db_vaddr = pci_iomap(pdev, 3, MAX_CCB * ONE_DB_SIZE); 707 + hw->db_vaddr = pci_iomap(pdev, 3, max_ccb * ONE_DB_SIZE); 709 708 if (hw->db_vaddr == NULL) { 710 709 dev_err(&pdev->dev, "Error mapping doorbell\n"); 711 710 goto ram_free; ··· 728 727 clear_device(ilo_hw); 729 728 730 729 minor = MINOR(ilo_hw->cdev.dev); 731 - for (i = minor; i < minor + MAX_CCB; i++) 730 + for (i = minor; i < minor + max_ccb; i++) 732 731 device_destroy(ilo_class, MKDEV(ilo_major, i)); 733 732 734 733 cdev_del(&ilo_hw->cdev); ··· 738 737 pci_release_regions(pdev); 739 738 pci_disable_device(pdev); 740 739 kfree(ilo_hw); 741 - ilo_hwdev[(minor / MAX_CCB)] = 0; 740 + ilo_hwdev[(minor / max_ccb)] = 0; 742 741 } 743 742 744 743 static int __devinit ilo_probe(struct pci_dev *pdev, ··· 746 745 { 747 746 int devnum, minor, start, error; 748 747 struct ilo_hwinfo *ilo_hw; 748 + 749 + if (max_ccb > MAX_CCB) 750 + max_ccb = MAX_CCB; 751 + else if (max_ccb < MIN_CCB) 752 + max_ccb = MIN_CCB; 749 753 750 754 /* find a free range for device files */ 751 755 for (devnum = 0; devnum < MAX_ILO_DEV; devnum++) { ··· 801 795 802 796 cdev_init(&ilo_hw->cdev, &ilo_fops); 803 797 ilo_hw->cdev.owner = THIS_MODULE; 804 - start = devnum * MAX_CCB; 805 - error = cdev_add(&ilo_hw->cdev, MKDEV(ilo_major, start), MAX_CCB); 798 + start = devnum * max_ccb; 799 + error = cdev_add(&ilo_hw->cdev, MKDEV(ilo_major, start), max_ccb); 806 800 if (error) { 807 801 dev_err(&pdev->dev, "Could not add cdev\n"); 808 802 goto remove_isr; 809 803 } 810 804 811 - for (minor = 0 ; minor < MAX_CCB; minor++) { 805 + for (minor = 0 ; minor < max_ccb; minor++) { 812 806 struct device *dev; 813 807 dev = device_create(ilo_class, &pdev->dev, 814 808 MKDEV(ilo_major, minor), NULL, ··· 885 879 class_destroy(ilo_class); 886 880 } 887 881 888 - MODULE_VERSION("1.2"); 882 + MODULE_VERSION("1.3"); 889 883 MODULE_ALIAS(ILO_NAME); 890 884 MODULE_DESCRIPTION(ILO_NAME); 891 885 MODULE_AUTHOR("David Altobelli <david.altobelli@hp.com>"); 892 886 MODULE_LICENSE("GPL v2"); 887 + 888 + module_param(max_ccb, uint, 0444); 889 + MODULE_PARM_DESC(max_ccb, "Maximum number of HP iLO channels to attach (8)"); 893 890 894 891 module_init(ilo_init); 895 892 module_exit(ilo_exit);
+3 -1
drivers/misc/hpilo.h
··· 14 14 #define ILO_NAME "hpilo" 15 15 16 16 /* max number of open channel control blocks per device, hw limited to 32 */ 17 - #define MAX_CCB 8 17 + #define MAX_CCB 24 18 + /* min number of open channel control blocks per device, hw limited to 32 */ 19 + #define MIN_CCB 8 18 20 /* max number of supported devices */ 19 21 #define MAX_ILO_DEV 1 20 22 /* max number of files */
+3 -1
drivers/misc/mei/init.c
··· 162 162 if ((dev->host_hw_state & H_IS) == H_IS) 163 163 mei_reg_write(dev, H_CSR, dev->host_hw_state); 164 164 165 + /* Doesn't change in runtime */ 166 + dev->hbuf_depth = (dev->host_hw_state & H_CBD) >> 24; 167 + 165 168 dev->recvd_msg = false; 166 169 dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); 167 170 ··· 306 303 dev->iamthif_cl.host_client_id); 307 304 308 305 mei_reset_iamthif_params(dev); 309 - dev->wd_due_counter = 0; 310 306 dev->extra_write_index = 0; 311 307 } 312 308
+33 -54
drivers/misc/mei/interface.c
··· 58 58 } 59 59 60 60 /** 61 - * _host_get_filled_slots - gets number of device filled buffer slots 61 + * mei_hbuf_filled_slots - gets number of device filled buffer slots 62 62 * 63 63 * @device: the device structure 64 64 * 65 65 * returns number of filled slots 66 66 */ 67 - static unsigned char _host_get_filled_slots(const struct mei_device *dev) 67 + static unsigned char mei_hbuf_filled_slots(struct mei_device *dev) 68 68 { 69 69 char read_ptr, write_ptr; 70 + 71 + dev->host_hw_state = mei_hcsr_read(dev); 70 72 71 73 read_ptr = (char) ((dev->host_hw_state & H_CBRP) >> 8); 72 74 write_ptr = (char) ((dev->host_hw_state & H_CBWP) >> 16); ··· 77 75 } 78 76 79 77 /** 80 - * mei_host_buffer_is_empty - checks if host buffer is empty. 78 + * mei_hbuf_is_empty - checks if host buffer is empty. 81 79 * 82 80 * @dev: the device structure 83 81 * 84 - * returns 1 if empty, 0 - otherwise. 82 + * returns true if empty, false - otherwise. 85 83 */ 86 - int mei_host_buffer_is_empty(struct mei_device *dev) 84 + bool mei_hbuf_is_empty(struct mei_device *dev) 87 85 { 88 - unsigned char filled_slots; 89 - 90 - dev->host_hw_state = mei_hcsr_read(dev); 91 - filled_slots = _host_get_filled_slots(dev); 92 - 93 - if (filled_slots == 0) 94 - return 1; 95 - 96 - return 0; 86 + return mei_hbuf_filled_slots(dev) == 0; 97 87 } 98 88 99 89 /** 100 - * mei_count_empty_write_slots - counts write empty slots. 90 + * mei_hbuf_empty_slots - counts write empty slots. 101 91 * 102 92 * @dev: the device structure 103 93 * 104 94 * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count 105 95 */ 106 - int mei_count_empty_write_slots(struct mei_device *dev) 96 + int mei_hbuf_empty_slots(struct mei_device *dev) 107 97 { 108 - unsigned char buffer_depth, filled_slots, empty_slots; 98 + unsigned char filled_slots, empty_slots; 109 99 110 - dev->host_hw_state = mei_hcsr_read(dev); 111 - buffer_depth = (unsigned char) ((dev->host_hw_state & H_CBD) >> 24); 112 - filled_slots = _host_get_filled_slots(dev); 113 - empty_slots = buffer_depth - filled_slots; 100 + filled_slots = mei_hbuf_filled_slots(dev); 101 + empty_slots = dev->hbuf_depth - filled_slots; 114 102 115 103 /* check for overflow */ 116 - if (filled_slots > buffer_depth) 104 + if (filled_slots > dev->hbuf_depth) 117 105 return -EOVERFLOW; 118 106 119 107 return empty_slots; ··· 119 127 * 120 128 * This function returns -EIO if write has failed 121 129 */ 122 - int mei_write_message(struct mei_device *dev, 123 - struct mei_msg_hdr *header, 124 - unsigned char *write_buffer, 125 - unsigned long write_length) 130 + int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, 131 + unsigned char *buf, unsigned long length) 126 132 { 127 - u32 temp_msg = 0; 128 - unsigned long bytes_written = 0; 129 - unsigned char buffer_depth, filled_slots, empty_slots; 130 - unsigned long dw_to_write; 133 + unsigned long rem, dw_cnt; 134 + u32 *reg_buf = (u32 *)buf; 135 + int i; 136 + int empty_slots; 131 137 132 - dev->host_hw_state = mei_hcsr_read(dev); 133 - 134 - dev_dbg(&dev->pdev->dev, 135 - "host_hw_state = 0x%08x.\n", 136 - dev->host_hw_state); 137 138 138 139 dev_dbg(&dev->pdev->dev, 139 140 "mei_write_message header=%08x.\n", 140 141 *((u32 *) header)); 141 142 142 - buffer_depth = (unsigned char) ((dev->host_hw_state & H_CBD) >> 24); 143 - filled_slots = _host_get_filled_slots(dev); 144 - empty_slots = buffer_depth - filled_slots; 145 - dev_dbg(&dev->pdev->dev, 146 - "filled = %hu, empty = %hu.\n", 147 - filled_slots, empty_slots); 143 + empty_slots = mei_hbuf_empty_slots(dev); 144 + dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots); 148 145 149 - dw_to_write = ((write_length + 3) / 4); 150 - 151 - if (dw_to_write > empty_slots) 146 + dw_cnt = mei_data2slots(length); 147 + if (empty_slots < 0 || dw_cnt > empty_slots) 152 148 return -EIO; 153 149 154 150 mei_reg_write(dev, H_CB_WW, *((u32 *) header)); 155 151 156 - while (write_length >= 4) { 157 - mei_reg_write(dev, H_CB_WW, 158 - *(u32 *) (write_buffer + bytes_written)); 159 - bytes_written += 4; 160 - write_length -= 4; 152 + for (i = 0; i < length / 4; i++) 153 + mei_reg_write(dev, H_CB_WW, reg_buf[i]); 154 + 155 + rem = length & 0x3; 156 + if (rem > 0) { 157 + u32 reg = 0; 158 + memcpy(&reg, &buf[length - rem], rem); 159 + mei_reg_write(dev, H_CB_WW, reg); 161 160 } 162 161 163 - if (write_length > 0) { 164 - memcpy(&temp_msg, &write_buffer[bytes_written], write_length); 165 - mei_reg_write(dev, H_CB_WW, temp_msg); 166 - } 167 - 162 + dev->host_hw_state = mei_hcsr_read(dev); 168 163 dev->host_hw_state |= H_IG; 169 164 mei_hcsr_set(dev); 170 165 dev->me_hw_state = mei_mecsr_read(dev);
+16 -2
drivers/misc/mei/interface.h
··· 41 41 unsigned char *write_buffer, 42 42 unsigned long write_length); 43 43 44 - int mei_host_buffer_is_empty(struct mei_device *dev); 44 + bool mei_hbuf_is_empty(struct mei_device *dev); 45 + 46 + int mei_hbuf_empty_slots(struct mei_device *dev); 47 + 48 + static inline size_t mei_hbuf_max_data(const struct mei_device *dev) 49 + { 50 + return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr); 51 + } 52 + 53 + /* get slots (dwords) from a message length + header (bytes) */ 54 + static inline unsigned char mei_data2slots(size_t length) 55 + { 56 + return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); 57 + } 45 58 46 59 int mei_count_full_read_slots(struct mei_device *dev); 47 60 48 - int mei_count_empty_write_slots(struct mei_device *dev); 49 61 50 62 int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl); 63 + 64 + 51 65 52 66 int mei_wd_send(struct mei_device *dev); 53 67 int mei_wd_stop(struct mei_device *dev, bool preserve);
+72 -99
drivers/misc/mei/interrupt.c
··· 267 267 + sizeof(struct hbm_flow_control))) { 268 268 return -EMSGSIZE; 269 269 } 270 - *slots -= (sizeof(struct mei_msg_hdr) + 271 - sizeof(struct hbm_flow_control) + 3) / 4; 270 + *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); 272 271 if (mei_send_flow_control(dev, &dev->iamthif_cl)) { 273 272 dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); 274 273 return -EIO; ··· 279 280 dev->iamthif_msg_buf_index = 0; 280 281 dev->iamthif_msg_buf_size = 0; 281 282 dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER; 282 - dev->mei_host_buffer_is_empty = mei_host_buffer_is_empty(dev); 283 + dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev); 283 284 return 0; 284 285 } 285 286 ··· 299 300 struct mei_cl *cl, 300 301 struct mei_io_list *cmpl_list) 301 302 { 302 - if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + 303 - sizeof(struct hbm_client_disconnect_request))) { 304 - *slots -= (sizeof(struct mei_msg_hdr) + 305 - sizeof(struct hbm_client_disconnect_request) + 3) / 4; 306 - 307 - if (mei_disconnect(dev, cl)) { 308 - cl->status = 0; 309 - cb_pos->information = 0; 310 - list_move_tail(&cb_pos->cb_list, 311 - &cmpl_list->mei_cb.cb_list); 312 - return -EMSGSIZE; 313 - } else { 314 - cl->state = MEI_FILE_DISCONNECTING; 315 - cl->status = 0; 316 - cb_pos->information = 0; 317 - list_move_tail(&cb_pos->cb_list, 318 - &dev->ctrl_rd_list.mei_cb.cb_list); 319 - cl->timer_count = MEI_CONNECT_TIMEOUT; 320 - } 321 - } else { 322 - /* return the cancel routine */ 303 + if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + 304 + sizeof(struct hbm_client_disconnect_request))) 323 305 return -EBADMSG; 306 + 307 + *slots -= mei_data2slots(sizeof(struct hbm_client_disconnect_request)); 308 + 309 + if (mei_disconnect(dev, cl)) { 310 + cl->status = 0; 311 + cb_pos->information = 0; 312 + list_move_tail(&cb_pos->cb_list, 313 + &cmpl_list->mei_cb.cb_list); 314 + return -EMSGSIZE; 315 + } else { 316 + cl->state = MEI_FILE_DISCONNECTING; 317 + cl->status = 0; 318 + cb_pos->information = 0; 319 + list_move_tail(&cb_pos->cb_list, 320 + &dev->ctrl_rd_list.mei_cb.cb_list); 321 + cl->timer_count = MEI_CONNECT_TIMEOUT; 324 322 } 325 323 326 324 return 0; ··· 571 575 disconnect_req->me_addr); 572 576 cl_pos->state = MEI_FILE_DISCONNECTED; 573 577 cl_pos->timer_count = 0; 574 - if (cl_pos == &dev->wd_cl) { 575 - dev->wd_due_counter = 0; 578 + if (cl_pos == &dev->wd_cl) 576 579 dev->wd_pending = false; 577 - } else if (cl_pos == &dev->iamthif_cl) 580 + else if (cl_pos == &dev->iamthif_cl) 578 581 dev->iamthif_timer = 0; 579 582 580 583 /* prepare disconnect response */ ··· 837 842 return -EBADMSG; 838 843 } 839 844 840 - *slots -= (sizeof(struct mei_msg_hdr) + 841 - sizeof(struct hbm_flow_control) + 3) / 4; 845 + *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); 846 + 842 847 if (mei_send_flow_control(dev, cl)) { 843 848 cl->status = -ENODEV; 844 849 cb_pos->information = 0; ··· 867 872 struct mei_cl *cl, 868 873 struct mei_io_list *cmpl_list) 869 874 { 870 - if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + 875 + if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + 871 876 sizeof(struct hbm_client_connect_request))) { 872 - cl->state = MEI_FILE_CONNECTING; 873 - *slots -= (sizeof(struct mei_msg_hdr) + 874 - sizeof(struct hbm_client_connect_request) + 3) / 4; 875 - if (mei_connect(dev, cl)) { 876 - cl->status = -ENODEV; 877 - cb_pos->information = 0; 878 - list_del(&cb_pos->cb_list); 879 - return -ENODEV; 880 - } else { 881 - list_move_tail(&cb_pos->cb_list, 882 - &dev->ctrl_rd_list.mei_cb.cb_list); 883 - cl->timer_count = MEI_CONNECT_TIMEOUT; 884 - } 885 - } else { 886 877 /* return the cancel routine */ 887 878 list_del(&cb_pos->cb_list); 888 879 return -EBADMSG; 889 880 } 890 881 882 + cl->state = MEI_FILE_CONNECTING; 883 + *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); 884 + if (mei_connect(dev, cl)) { 885 + cl->status = -ENODEV; 886 + cb_pos->information = 0; 887 + list_del(&cb_pos->cb_list); 888 + return -ENODEV; 889 + } else { 890 + list_move_tail(&cb_pos->cb_list, 891 + &dev->ctrl_rd_list.mei_cb.cb_list); 892 + cl->timer_count = MEI_CONNECT_TIMEOUT; 893 + } 891 894 return 0; 892 895 } 893 896 ··· 925 932 cb_pos->information); 926 933 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", 927 934 mei_hdr->length); 928 - *slots -= (sizeof(struct mei_msg_hdr) + 929 - mei_hdr->length + 3) / 4; 935 + *slots -= mei_data2slots(mei_hdr->length); 930 936 if (mei_write_message(dev, mei_hdr, 931 937 (unsigned char *) 932 938 (cb_pos->request_buffer.data + ··· 943 951 list_move_tail(&cb_pos->cb_list, 944 952 &dev->write_waiting_list.mei_cb.cb_list); 945 953 } 946 - } else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) { 954 + } else if (*slots == dev->hbuf_depth) { 947 955 /* buffer is still empty */ 948 956 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 949 957 mei_hdr->host_addr = cl->host_client_id; ··· 952 960 (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); 953 961 mei_hdr->msg_complete = 0; 954 962 mei_hdr->reserved = 0; 955 - 956 - (*slots) -= (sizeof(struct mei_msg_hdr) + 957 - mei_hdr->length + 3) / 4; 963 + *slots -= mei_data2slots(mei_hdr->length); 958 964 if (mei_write_message(dev, mei_hdr, 959 965 (unsigned char *) 960 966 (cb_pos->request_buffer.data + ··· 1011 1021 mei_hdr->msg_complete = 1; 1012 1022 mei_hdr->reserved = 0; 1013 1023 1014 - *slots -= (sizeof(struct mei_msg_hdr) + 1015 - mei_hdr->length + 3) / 4; 1024 + *slots -= mei_data2slots(mei_hdr->length); 1016 1025 1017 1026 if (mei_write_message(dev, mei_hdr, 1018 1027 (dev->iamthif_msg_buf + ··· 1035 1046 &dev->write_waiting_list.mei_cb.cb_list); 1036 1047 1037 1048 } 1038 - } else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) { 1039 - /* buffer is still empty */ 1049 + } else if (*slots == dev->hbuf_depth) { 1050 + /* buffer is still empty */ 1040 1051 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 1041 1052 mei_hdr->host_addr = cl->host_client_id; 1042 1053 mei_hdr->me_addr = cl->me_client_id; ··· 1045 1056 mei_hdr->msg_complete = 0; 1046 1057 mei_hdr->reserved = 0; 1047 1058 1048 - *slots -= (sizeof(struct mei_msg_hdr) + 1049 - mei_hdr->length + 3) / 4; 1059 + *slots -= mei_data2slots(mei_hdr->length); 1050 1060 1051 1061 if (mei_write_message(dev, mei_hdr, 1052 1062 (dev->iamthif_msg_buf + ··· 1187 1199 struct mei_io_list *list; 1188 1200 int ret; 1189 1201 1190 - if (!mei_host_buffer_is_empty(dev)) { 1202 + if (!mei_hbuf_is_empty(dev)) { 1191 1203 dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n"); 1192 1204 return 0; 1193 1205 } 1194 - *slots = mei_count_empty_write_slots(dev); 1206 + *slots = mei_hbuf_empty_slots(dev); 1207 + if (*slots <= 0) 1208 + return -EMSGSIZE; 1209 + 1195 1210 /* complete all waiting for write CB */ 1196 1211 dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n"); 1197 1212 1198 1213 list = &dev->write_waiting_list; 1199 - list_for_each_entry_safe(pos, next, 1200 - &list->mei_cb.cb_list, cb_list) { 1214 + list_for_each_entry_safe(pos, next, &list->mei_cb.cb_list, cb_list) { 1201 1215 cl = (struct mei_cl *)pos->file_private; 1202 1216 if (cl == NULL) 1203 1217 continue; ··· 1209 1219 if (MEI_WRITING == cl->writing_state && 1210 1220 (pos->major_file_operations == MEI_WRITE) && 1211 1221 (cl != &dev->iamthif_cl)) { 1212 - dev_dbg(&dev->pdev->dev, 1213 - "MEI WRITE COMPLETE\n"); 1222 + dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n"); 1214 1223 cl->writing_state = MEI_WRITE_COMPLETE; 1215 1224 list_add_tail(&pos->cb_list, 1216 - &cmpl_list->mei_cb.cb_list); 1225 + &cmpl_list->mei_cb.cb_list); 1217 1226 } 1218 1227 if (cl == &dev->iamthif_cl) { 1219 1228 dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n"); 1220 1229 if (dev->iamthif_flow_control_pending) { 1221 - ret = _mei_irq_thread_iamthif_read( 1222 - dev, slots); 1230 + ret = _mei_irq_thread_iamthif_read(dev, slots); 1223 1231 if (ret) 1224 1232 return ret; 1225 1233 } ··· 1242 1254 } 1243 1255 if (dev->mei_state == MEI_ENABLED) { 1244 1256 if (dev->wd_pending && 1245 - mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 1257 + mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 1246 1258 if (mei_wd_send(dev)) 1247 1259 dev_dbg(&dev->pdev->dev, "wd send failed.\n"); 1248 - else 1249 - if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) 1250 - return -ENODEV; 1260 + else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl)) 1261 + return -ENODEV; 1251 1262 1252 1263 dev->wd_pending = false; 1253 1264 1254 - if (dev->wd_timeout) { 1255 - *slots -= (sizeof(struct mei_msg_hdr) + 1256 - MEI_START_WD_DATA_SIZE + 3) / 4; 1257 - dev->wd_due_counter = 2; 1258 - } else { 1259 - *slots -= (sizeof(struct mei_msg_hdr) + 1260 - MEI_WD_PARAMS_SIZE + 3) / 4; 1261 - dev->wd_due_counter = 0; 1262 - } 1263 - 1265 + if (dev->wd_timeout) 1266 + *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE); 1267 + else 1268 + *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE); 1264 1269 } 1265 1270 } 1266 1271 if (dev->stop) ··· 1301 1320 /* complete write list CB */ 1302 1321 dev_dbg(&dev->pdev->dev, "complete write list cb.\n"); 1303 1322 list_for_each_entry_safe(pos, next, 1304 - &dev->write_list.mei_cb.cb_list, cb_list) { 1323 + &dev->write_list.mei_cb.cb_list, cb_list) { 1305 1324 cl = (struct mei_cl *)pos->file_private; 1306 1325 if (cl == NULL) 1307 1326 continue; 1308 1327 1309 1328 if (cl != &dev->iamthif_cl) { 1310 - if (!mei_flow_ctrl_creds(dev, cl)) { 1329 + if (mei_flow_ctrl_creds(dev, cl) <= 0) { 1311 1330 dev_dbg(&dev->pdev->dev, 1312 - "No flow control" 1313 - " credentials for client" 1314 - " %d, not sending.\n", 1315 - cl->host_client_id); 1331 + "No flow control credentials for client %d, not sending.\n", 1332 + cl->host_client_id); 1316 1333 continue; 1317 1334 } 1318 - ret = _mei_irq_thread_cmpl(dev, slots, 1319 - pos, 1320 - cl, cmpl_list); 1335 + ret = _mei_irq_thread_cmpl(dev, slots, pos, 1336 + cl, cmpl_list); 1321 1337 if (ret) 1322 1338 return ret; 1323 1339 1324 1340 } else if (cl == &dev->iamthif_cl) { 1325 1341 /* IAMTHIF IOCTL */ 1326 1342 dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n"); 1327 - if (!mei_flow_ctrl_creds(dev, cl)) { 1343 + if (mei_flow_ctrl_creds(dev, cl) <= 0) { 1328 1344 dev_dbg(&dev->pdev->dev, 1329 - "No flow control" 1330 - " credentials for amthi" 1331 - " client %d.\n", 1332 - cl->host_client_id); 1345 + "No flow control credentials for amthi client %d.\n", 1346 + cl->host_client_id); 1333 1347 continue; 1334 1348 } 1335 - ret = _mei_irq_thread_cmpl_iamthif(dev, 1336 - slots, 1337 - pos, 1338 - cl, 1339 - cmpl_list); 1349 + ret = _mei_irq_thread_cmpl_iamthif(dev, slots, pos, 1350 + cl, cmpl_list); 1340 1351 if (ret) 1341 1352 return ret; 1342 1353 ··· 1528 1555 end: 1529 1556 dev_dbg(&dev->pdev->dev, "end of bottom half function.\n"); 1530 1557 dev->host_hw_state = mei_hcsr_read(dev); 1531 - dev->mei_host_buffer_is_empty = mei_host_buffer_is_empty(dev); 1558 + dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev); 1532 1559 1533 1560 bus_message_received = false; 1534 1561 if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) {
+2 -6
drivers/misc/mei/iorw.c
··· 481 481 if (ret && dev->mei_host_buffer_is_empty) { 482 482 ret = 0; 483 483 dev->mei_host_buffer_is_empty = false; 484 - if (cb->request_buffer.size > 485 - (((dev->host_hw_state & H_CBD) >> 24) * sizeof(u32)) 486 - -sizeof(struct mei_msg_hdr)) { 487 - mei_hdr.length = 488 - (((dev->host_hw_state & H_CBD) >> 24) * 489 - sizeof(u32)) - sizeof(struct mei_msg_hdr); 484 + if (cb->request_buffer.size > mei_hbuf_max_data(dev)) { 485 + mei_hdr.length = mei_hbuf_max_data(dev); 490 486 mei_hdr.msg_complete = 0; 491 487 } else { 492 488 mei_hdr.length = cb->request_buffer.size;
+3 -45
drivers/misc/mei/main.c
··· 714 714 if (rets && dev->mei_host_buffer_is_empty) { 715 715 rets = 0; 716 716 dev->mei_host_buffer_is_empty = false; 717 - if (length > ((((dev->host_hw_state & H_CBD) >> 24) * 718 - sizeof(u32)) - sizeof(struct mei_msg_hdr))) { 719 - 720 - mei_hdr.length = 721 - (((dev->host_hw_state & H_CBD) >> 24) * 722 - sizeof(u32)) - 723 - sizeof(struct mei_msg_hdr); 717 + if (length > mei_hbuf_max_data(dev)) { 718 + mei_hdr.length = mei_hbuf_max_data(dev); 724 719 mei_hdr.msg_complete = 0; 725 720 } else { 726 721 mei_hdr.length = length; ··· 1182 1187 .driver.pm = MEI_PM_OPS, 1183 1188 }; 1184 1189 1185 - /** 1186 - * mei_init_module - Driver Registration Routine 1187 - * 1188 - * mei_init_module is the first routine called when the driver is 1189 - * loaded. All it does is to register with the PCI subsystem. 1190 - * 1191 - * returns 0 on success, <0 on failure. 1192 - */ 1193 - static int __init mei_init_module(void) 1194 - { 1195 - int ret; 1196 - 1197 - pr_debug("loading.\n"); 1198 - /* init pci module */ 1199 - ret = pci_register_driver(&mei_driver); 1200 - if (ret < 0) 1201 - pr_err("error registering driver.\n"); 1202 - 1203 - return ret; 1204 - } 1205 - 1206 - module_init(mei_init_module); 1207 - 1208 - /** 1209 - * mei_exit_module - Driver Exit Cleanup Routine 1210 - * 1211 - * mei_exit_module is called just before the driver is removed 1212 - * from memory. 1213 - */ 1214 - static void __exit mei_exit_module(void) 1215 - { 1216 - pci_unregister_driver(&mei_driver); 1217 - 1218 - pr_debug("unloaded successfully.\n"); 1219 - } 1220 - 1221 - module_exit(mei_exit_module); 1222 - 1190 + module_pci_driver(mei_driver); 1223 1191 1224 1192 MODULE_AUTHOR("Intel Corporation"); 1225 1193 MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
+13 -11
drivers/misc/mei/mei_dev.h
··· 167 167 struct mei_cl_cb mei_cb; 168 168 }; 169 169 170 - /* MEI private device struct */ 170 + /** 171 + * struct mei_deive - MEI private device struct 172 + * @hbuf_depth - depth of host(write) buffer 173 + */ 171 174 struct mei_device { 172 175 struct pci_dev *pdev; /* pointer to pci device struct */ 173 176 /* ··· 208 205 */ 209 206 u32 host_hw_state; 210 207 u32 me_hw_state; 208 + u8 hbuf_depth; 211 209 /* 212 210 * waiting queue for receive message from FW 213 211 */ ··· 241 237 bool mei_host_buffer_is_empty; 242 238 243 239 struct mei_cl wd_cl; 240 + bool wd_interface_reg; 244 241 bool wd_pending; 245 242 bool wd_stopped; 246 243 bool wd_bypass; /* if false, don't refresh watchdog ME client */ 247 244 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */ 248 - u16 wd_due_counter; 249 245 unsigned char wd_data[MEI_START_WD_DATA_SIZE]; 250 - 251 246 252 247 253 248 struct file *iamthif_file_object; ··· 262 259 bool iamthif_flow_control_pending; 263 260 bool iamthif_ioctl; 264 261 bool iamthif_canceled; 265 - 266 - bool wd_interface_reg; 267 262 }; 268 263 269 264 ··· 362 361 * 363 362 * returns register value (u32) 364 363 */ 365 - static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset) 364 + static inline u32 mei_reg_read(const struct mei_device *dev, 365 + unsigned long offset) 366 366 { 367 367 return ioread32(dev->mem_addr + offset); 368 368 } ··· 375 373 * @offset: offset from which to write the data 376 374 * @value: register value to write (u32) 377 375 */ 378 - static inline void mei_reg_write(struct mei_device *dev, 379 - unsigned long offset, u32 value) 376 + static inline void mei_reg_write(const struct mei_device *dev, 377 + unsigned long offset, u32 value) 380 378 { 381 379 iowrite32(value, dev->mem_addr + offset); 382 380 } ··· 388 386 * 389 387 * returns the byte read. 390 388 */ 391 - static inline u32 mei_hcsr_read(struct mei_device *dev) 389 + static inline u32 mei_hcsr_read(const struct mei_device *dev) 392 390 { 393 391 return mei_reg_read(dev, H_CSR); 394 392 } ··· 400 398 * 401 399 * returns ME_CSR_HA register value (u32) 402 400 */ 403 - static inline u32 mei_mecsr_read(struct mei_device *dev) 401 + static inline u32 mei_mecsr_read(const struct mei_device *dev) 404 402 { 405 403 return mei_reg_read(dev, ME_CSR_HA); 406 404 } ··· 412 410 * 413 411 * returns ME_CB_RW register value (u32) 414 412 */ 415 - static inline u32 mei_mecbrw_read(struct mei_device *dev) 413 + static inline u32 mei_mecbrw_read(const struct mei_device *dev) 416 414 { 417 415 return mei_reg_read(dev, ME_CB_RW); 418 416 }
+2 -4
drivers/misc/mei/wd.c
··· 53 53 } 54 54 55 55 /** 56 - * host_init_wd - mei initialization wd. 56 + * mei_wd_host_init - connect to the watchdog client 57 57 * 58 58 * @dev: the device structure 59 59 * returns -ENENT if wd client cannot be found 60 60 * -EIO if write has failed 61 + * 0 on success 61 62 */ 62 63 int mei_wd_host_init(struct mei_device *dev) 63 64 { ··· 138 137 return 0; 139 138 140 139 dev->wd_timeout = 0; 141 - dev->wd_due_counter = 0; 142 140 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE); 143 141 dev->stop = true; 144 142 ··· 356 356 void mei_watchdog_register(struct mei_device *dev) 357 357 { 358 358 dev_dbg(&dev->pdev->dev, "dev->wd_timeout =%d.\n", dev->wd_timeout); 359 - 360 - dev->wd_due_counter = !!dev->wd_timeout; 361 359 362 360 if (watchdog_register_device(&amt_wd_dev)) { 363 361 dev_err(&dev->pdev->dev,