Lines Matching full:data

139 	void (*update)(struct aem_data *data);
173 /* Data structures returned by the AEM firmware */
225 /* Data structures to talk to the IPMI layer */
236 static void aem_remove_sensors(struct aem_data *data);
237 static int aem1_find_sensors(struct aem_data *data);
238 static int aem2_find_sensors(struct aem_data *data);
239 static void update_aem1_sensors(struct aem_data *data);
240 static void update_aem2_sensors(struct aem_data *data);
256 /* Initialize IPMI address, message buffers and user data */
257 static int aem_init_ipmi_data(struct aem_ipmi_data *data, int iface, in aem_init_ipmi_data() argument
262 init_completion(&data->read_complete); in aem_init_ipmi_data()
263 data->bmc_device = bmc; in aem_init_ipmi_data()
266 data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; in aem_init_ipmi_data()
267 data->address.channel = IPMI_BMC_CHANNEL; in aem_init_ipmi_data()
268 data->address.data[0] = 0; in aem_init_ipmi_data()
269 data->interface = iface; in aem_init_ipmi_data()
272 data->tx_msgid = 0; in aem_init_ipmi_data()
273 data->tx_message.netfn = AEM_NETFN; in aem_init_ipmi_data()
276 err = ipmi_create_user(data->interface, &driver_data.ipmi_hndlrs, in aem_init_ipmi_data()
277 data, &data->user); in aem_init_ipmi_data()
281 data->interface); in aem_init_ipmi_data()
289 static int aem_send_message(struct aem_ipmi_data *data) in aem_send_message() argument
293 err = ipmi_validate_addr(&data->address, sizeof(data->address)); in aem_send_message()
297 data->tx_msgid++; in aem_send_message()
298 err = ipmi_request_settime(data->user, &data->address, data->tx_msgid, in aem_send_message()
299 &data->tx_message, data, 0, 0, 0); in aem_send_message()
305 dev_err(data->bmc_device, "request_settime=%x\n", err); in aem_send_message()
308 dev_err(data->bmc_device, "validate_addr=%x\n", err); in aem_send_message()
316 struct aem_ipmi_data *data = user_msg_data; in aem_msg_handler() local
318 if (msg->msgid != data->tx_msgid) { in aem_msg_handler()
319 dev_err(data->bmc_device, in aem_msg_handler()
322 (int)data->tx_msgid); in aem_msg_handler()
327 data->rx_recv_type = msg->recv_type; in aem_msg_handler()
329 data->rx_result = msg->msg.data[0]; in aem_msg_handler()
331 data->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE; in aem_msg_handler()
335 if (data->rx_msg_len < rx_len) in aem_msg_handler()
336 rx_len = data->rx_msg_len; in aem_msg_handler()
337 data->rx_msg_len = rx_len; in aem_msg_handler()
338 memcpy(data->rx_msg_data, msg->msg.data + 1, data->rx_msg_len); in aem_msg_handler()
340 data->rx_msg_len = 0; in aem_msg_handler()
343 complete(&data->read_complete); in aem_msg_handler()
348 /* Read a sensor value; must be called with data->lock held */
349 static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg, in aem_read_sensor() argument
355 struct aem_read_sensor_resp *rs_resp = data->rs_resp; in aem_read_sensor()
356 struct aem_ipmi_data *ipmi = &data->ipmi; in aem_read_sensor()
370 rs_req.module_handle = data->module_handle; in aem_read_sensor()
377 ipmi->tx_message.data = (char *)&rs_req; in aem_read_sensor()
427 static void update_aem_energy_one(struct aem_data *data, int which) in update_aem_energy_one() argument
429 aem_read_sensor(data, AEM_ENERGY_ELEMENT, which, in update_aem_energy_one()
430 &data->energy[which], 8); in update_aem_energy_one()
433 static void update_aem_energy(struct aem_data *data) in update_aem_energy() argument
435 update_aem_energy_one(data, 0); in update_aem_energy()
436 if (data->ver_major < 2) in update_aem_energy()
438 update_aem_energy_one(data, 1); in update_aem_energy()
442 static void update_aem1_sensors(struct aem_data *data) in update_aem1_sensors() argument
444 mutex_lock(&data->lock); in update_aem1_sensors()
445 if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && in update_aem1_sensors()
446 data->valid) in update_aem1_sensors()
449 update_aem_energy(data); in update_aem1_sensors()
451 mutex_unlock(&data->lock); in update_aem1_sensors()
455 static void update_aem2_sensors(struct aem_data *data) in update_aem2_sensors() argument
459 mutex_lock(&data->lock); in update_aem2_sensors()
460 if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && in update_aem2_sensors()
461 data->valid) in update_aem2_sensors()
464 update_aem_energy(data); in update_aem2_sensors()
465 aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 0, &data->temp[0], 1); in update_aem2_sensors()
466 aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 1, &data->temp[1], 1); in update_aem2_sensors()
469 aem_read_sensor(data, AEM_POWER_CAP_ELEMENT, i, in update_aem2_sensors()
470 &data->pcap[i], 2); in update_aem2_sensors()
472 mutex_unlock(&data->lock); in update_aem2_sensors()
476 static void aem_delete(struct aem_data *data) in aem_delete() argument
478 list_del(&data->list); in aem_delete()
479 aem_remove_sensors(data); in aem_delete()
480 kfree(data->rs_resp); in aem_delete()
481 hwmon_device_unregister(data->hwmon_dev); in aem_delete()
482 ipmi_destroy_user(data->ipmi.user); in aem_delete()
483 platform_set_drvdata(data->pdev, NULL); in aem_delete()
484 platform_device_unregister(data->pdev); in aem_delete()
485 ida_free(&aem_ida, data->id); in aem_delete()
486 kfree(data); in aem_delete()
492 static int aem_find_aem1_count(struct aem_ipmi_data *data) in aem_find_aem1_count() argument
502 data->tx_message.cmd = AEM_FIND_FW_CMD; in aem_find_aem1_count()
503 data->tx_message.data = (char *)&ff_req; in aem_find_aem1_count()
504 data->tx_message.data_len = sizeof(ff_req); in aem_find_aem1_count()
506 data->rx_msg_data = &ff_resp; in aem_find_aem1_count()
507 data->rx_msg_len = sizeof(ff_resp); in aem_find_aem1_count()
509 aem_send_message(data); in aem_find_aem1_count()
511 res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); in aem_find_aem1_count()
515 if (data->rx_result || data->rx_msg_len != sizeof(ff_resp) || in aem_find_aem1_count()
525 struct aem_data *data; in aem_init_aem1_inst() local
529 data = kzalloc(sizeof(*data), GFP_KERNEL); in aem_init_aem1_inst()
530 if (!data) in aem_init_aem1_inst()
532 mutex_init(&data->lock); in aem_init_aem1_inst()
534 /* Copy instance data */ in aem_init_aem1_inst()
535 data->ver_major = 1; in aem_init_aem1_inst()
536 data->ver_minor = 0; in aem_init_aem1_inst()
537 data->module_handle = module_handle; in aem_init_aem1_inst()
539 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; in aem_init_aem1_inst()
542 data->id = ida_alloc(&aem_ida, GFP_KERNEL); in aem_init_aem1_inst()
543 if (data->id < 0) in aem_init_aem1_inst()
546 data->pdev = platform_device_alloc(DRVNAME, data->id); in aem_init_aem1_inst()
547 if (!data->pdev) in aem_init_aem1_inst()
549 data->pdev->dev.driver = &aem_driver.driver; in aem_init_aem1_inst()
551 res = platform_device_add(data->pdev); in aem_init_aem1_inst()
555 platform_set_drvdata(data->pdev, data); in aem_init_aem1_inst()
558 res = aem_init_ipmi_data(&data->ipmi, probe->interface, in aem_init_aem1_inst()
564 data->hwmon_dev = hwmon_device_register(&data->pdev->dev); in aem_init_aem1_inst()
565 if (IS_ERR(data->hwmon_dev)) { in aem_init_aem1_inst()
566 dev_err(&data->pdev->dev, in aem_init_aem1_inst()
569 res = PTR_ERR(data->hwmon_dev); in aem_init_aem1_inst()
573 data->update = update_aem1_sensors; in aem_init_aem1_inst()
574 data->rs_resp = kzalloc(sizeof(*(data->rs_resp)) + 8, GFP_KERNEL); in aem_init_aem1_inst()
575 if (!data->rs_resp) { in aem_init_aem1_inst()
581 res = aem1_find_sensors(data); in aem_init_aem1_inst()
586 list_add_tail(&data->list, &driver_data.aem_devices); in aem_init_aem1_inst()
588 dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", in aem_init_aem1_inst()
589 data->ver_major, data->ver_minor, in aem_init_aem1_inst()
590 data->module_handle); in aem_init_aem1_inst()
594 kfree(data->rs_resp); in aem_init_aem1_inst()
596 hwmon_device_unregister(data->hwmon_dev); in aem_init_aem1_inst()
598 ipmi_destroy_user(data->ipmi.user); in aem_init_aem1_inst()
600 platform_set_drvdata(data->pdev, NULL); in aem_init_aem1_inst()
601 platform_device_del(data->pdev); in aem_init_aem1_inst()
603 platform_device_put(data->pdev); in aem_init_aem1_inst()
605 ida_free(&aem_ida, data->id); in aem_init_aem1_inst()
607 kfree(data); in aem_init_aem1_inst()
631 static int aem_find_aem2(struct aem_ipmi_data *data, in aem_find_aem2() argument
642 data->tx_message.cmd = AEM_FW_INSTANCE_CMD; in aem_find_aem2()
643 data->tx_message.data = (char *)&fi_req; in aem_find_aem2()
644 data->tx_message.data_len = sizeof(fi_req); in aem_find_aem2()
646 data->rx_msg_data = fi_resp; in aem_find_aem2()
647 data->rx_msg_len = sizeof(*fi_resp); in aem_find_aem2()
649 aem_send_message(data); in aem_find_aem2()
651 res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); in aem_find_aem2()
655 if (data->rx_result || data->rx_msg_len != sizeof(*fi_resp) || in aem_find_aem2()
667 struct aem_data *data; in aem_init_aem2_inst() local
671 data = kzalloc(sizeof(*data), GFP_KERNEL); in aem_init_aem2_inst()
672 if (!data) in aem_init_aem2_inst()
674 mutex_init(&data->lock); in aem_init_aem2_inst()
676 /* Copy instance data */ in aem_init_aem2_inst()
677 data->ver_major = fi_resp->major; in aem_init_aem2_inst()
678 data->ver_minor = fi_resp->minor; in aem_init_aem2_inst()
679 data->module_handle = fi_resp->module_handle; in aem_init_aem2_inst()
681 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; in aem_init_aem2_inst()
684 data->id = ida_alloc(&aem_ida, GFP_KERNEL); in aem_init_aem2_inst()
685 if (data->id < 0) in aem_init_aem2_inst()
688 data->pdev = platform_device_alloc(DRVNAME, data->id); in aem_init_aem2_inst()
689 if (!data->pdev) in aem_init_aem2_inst()
691 data->pdev->dev.driver = &aem_driver.driver; in aem_init_aem2_inst()
693 res = platform_device_add(data->pdev); in aem_init_aem2_inst()
697 platform_set_drvdata(data->pdev, data); in aem_init_aem2_inst()
700 res = aem_init_ipmi_data(&data->ipmi, probe->interface, in aem_init_aem2_inst()
706 data->hwmon_dev = hwmon_device_register(&data->pdev->dev); in aem_init_aem2_inst()
707 if (IS_ERR(data->hwmon_dev)) { in aem_init_aem2_inst()
708 dev_err(&data->pdev->dev, in aem_init_aem2_inst()
711 res = PTR_ERR(data->hwmon_dev); in aem_init_aem2_inst()
715 data->update = update_aem2_sensors; in aem_init_aem2_inst()
716 data->rs_resp = kzalloc(sizeof(*(data->rs_resp)) + 8, GFP_KERNEL); in aem_init_aem2_inst()
717 if (!data->rs_resp) { in aem_init_aem2_inst()
723 res = aem2_find_sensors(data); in aem_init_aem2_inst()
728 list_add_tail(&data->list, &driver_data.aem_devices); in aem_init_aem2_inst()
730 dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", in aem_init_aem2_inst()
731 data->ver_major, data->ver_minor, in aem_init_aem2_inst()
732 data->module_handle); in aem_init_aem2_inst()
736 kfree(data->rs_resp); in aem_init_aem2_inst()
738 hwmon_device_unregister(data->hwmon_dev); in aem_init_aem2_inst()
740 ipmi_destroy_user(data->ipmi.user); in aem_init_aem2_inst()
742 platform_set_drvdata(data->pdev, NULL); in aem_init_aem2_inst()
743 platform_device_del(data->pdev); in aem_init_aem2_inst()
745 platform_device_put(data->pdev); in aem_init_aem2_inst()
747 ida_free(&aem_ida, data->id); in aem_init_aem2_inst()
749 kfree(data); in aem_init_aem2_inst()
810 struct aem_data *data = dev_get_drvdata(dev); in name_show() local
812 return sprintf(buf, "%s%d\n", DRVNAME, data->ver_major); in name_show()
820 struct aem_data *data = dev_get_drvdata(dev); in version_show() local
822 return sprintf(buf, "%d.%d\n", data->ver_major, data->ver_minor); in version_show()
832 struct aem_data *data = dev_get_drvdata(dev); in aem_show_power() local
836 mutex_lock(&data->lock); in aem_show_power()
837 update_aem_energy_one(data, attr->index); in aem_show_power()
839 before = data->energy[attr->index]; in aem_show_power()
842 msecs_to_jiffies(data->power_period[attr->index]) in aem_show_power()
845 mutex_unlock(&data->lock); in aem_show_power()
849 update_aem_energy_one(data, attr->index); in aem_show_power()
851 after = data->energy[attr->index]; in aem_show_power()
852 mutex_unlock(&data->lock); in aem_show_power()
912 static int aem_register_sensors(struct aem_data *data, in aem_register_sensors() argument
916 struct device *dev = &data->pdev->dev; in aem_register_sensors()
917 struct sensor_device_attribute *sensors = data->sensors; in aem_register_sensors()
962 aem_remove_sensors(data); in aem_register_sensors()
993 static void aem_remove_sensors(struct aem_data *data) in aem_remove_sensors() argument
998 if (!data->sensors[i].dev_attr.attr.name) in aem_remove_sensors()
1000 device_remove_file(&data->pdev->dev, in aem_remove_sensors()
1001 &data->sensors[i].dev_attr); in aem_remove_sensors()
1004 device_remove_file(&data->pdev->dev, in aem_remove_sensors()
1006 device_remove_file(&data->pdev->dev, in aem_remove_sensors()
1050 static int aem1_find_sensors(struct aem_data *data) in aem1_find_sensors() argument
1052 return aem_register_sensors(data, aem1_ro_sensors, aem1_rw_sensors); in aem1_find_sensors()
1056 static int aem2_find_sensors(struct aem_data *data) in aem2_find_sensors() argument
1058 return aem_register_sensors(data, aem2_ro_sensors, aem2_rw_sensors); in aem2_find_sensors()