Lines Matching refs:data

30 static inline u16 extract_value(const char *data, int offset)  in extract_value()  argument
32 return be16_to_cpup((__be16 *)&data[offset]); in extract_value()
111 static int ibmpex_send_message(struct ibmpex_bmc_data *data) in ibmpex_send_message() argument
115 err = ipmi_validate_addr(&data->address, sizeof(data->address)); in ibmpex_send_message()
119 data->tx_msgid++; in ibmpex_send_message()
120 err = ipmi_request_settime(data->user, &data->address, data->tx_msgid, in ibmpex_send_message()
121 &data->tx_message, data, 0, 0, 0); in ibmpex_send_message()
127 dev_err(data->bmc_device, "request_settime=%x\n", err); in ibmpex_send_message()
130 dev_err(data->bmc_device, "validate_addr=%x\n", err); in ibmpex_send_message()
134 static int ibmpex_ver_check(struct ibmpex_bmc_data *data) in ibmpex_ver_check() argument
136 data->tx_msg_data[0] = PEX_GET_VERSION; in ibmpex_ver_check()
137 data->tx_message.data_len = 1; in ibmpex_ver_check()
138 ibmpex_send_message(data); in ibmpex_ver_check()
140 wait_for_completion(&data->read_complete); in ibmpex_ver_check()
142 if (data->rx_result || data->rx_msg_len != 6) in ibmpex_ver_check()
145 data->sensor_major = data->rx_msg_data[0]; in ibmpex_ver_check()
146 data->sensor_minor = data->rx_msg_data[1]; in ibmpex_ver_check()
148 dev_info(data->bmc_device, in ibmpex_ver_check()
150 data->sensor_major, in ibmpex_ver_check()
151 data->sensor_minor, in ibmpex_ver_check()
152 extract_value(data->rx_msg_data, 2), in ibmpex_ver_check()
153 data->rx_msg_data[4], in ibmpex_ver_check()
154 data->rx_msg_data[5], in ibmpex_ver_check()
155 data->interface); in ibmpex_ver_check()
160 static int ibmpex_query_sensor_count(struct ibmpex_bmc_data *data) in ibmpex_query_sensor_count() argument
162 data->tx_msg_data[0] = PEX_GET_SENSOR_COUNT; in ibmpex_query_sensor_count()
163 data->tx_message.data_len = 1; in ibmpex_query_sensor_count()
164 ibmpex_send_message(data); in ibmpex_query_sensor_count()
166 wait_for_completion(&data->read_complete); in ibmpex_query_sensor_count()
168 if (data->rx_result || data->rx_msg_len != 1) in ibmpex_query_sensor_count()
171 return data->rx_msg_data[0]; in ibmpex_query_sensor_count()
174 static int ibmpex_query_sensor_name(struct ibmpex_bmc_data *data, int sensor) in ibmpex_query_sensor_name() argument
176 data->tx_msg_data[0] = PEX_GET_SENSOR_NAME; in ibmpex_query_sensor_name()
177 data->tx_msg_data[1] = sensor; in ibmpex_query_sensor_name()
178 data->tx_message.data_len = 2; in ibmpex_query_sensor_name()
179 ibmpex_send_message(data); in ibmpex_query_sensor_name()
181 wait_for_completion(&data->read_complete); in ibmpex_query_sensor_name()
183 if (data->rx_result || data->rx_msg_len < 1) in ibmpex_query_sensor_name()
189 static int ibmpex_query_sensor_data(struct ibmpex_bmc_data *data, int sensor) in ibmpex_query_sensor_data() argument
191 data->tx_msg_data[0] = PEX_GET_SENSOR_DATA; in ibmpex_query_sensor_data()
192 data->tx_msg_data[1] = sensor; in ibmpex_query_sensor_data()
193 data->tx_message.data_len = 2; in ibmpex_query_sensor_data()
194 ibmpex_send_message(data); in ibmpex_query_sensor_data()
196 wait_for_completion(&data->read_complete); in ibmpex_query_sensor_data()
198 if (data->rx_result || data->rx_msg_len < 26) { in ibmpex_query_sensor_data()
199 dev_err(data->bmc_device, "Error reading sensor %d.\n", in ibmpex_query_sensor_data()
207 static int ibmpex_reset_high_low_data(struct ibmpex_bmc_data *data) in ibmpex_reset_high_low_data() argument
209 data->tx_msg_data[0] = PEX_RESET_HIGH_LOW; in ibmpex_reset_high_low_data()
210 data->tx_message.data_len = 1; in ibmpex_reset_high_low_data()
211 ibmpex_send_message(data); in ibmpex_reset_high_low_data()
213 wait_for_completion(&data->read_complete); in ibmpex_reset_high_low_data()
218 static void ibmpex_update_device(struct ibmpex_bmc_data *data) in ibmpex_update_device() argument
222 mutex_lock(&data->lock); in ibmpex_update_device()
223 if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && in ibmpex_update_device()
224 data->valid) in ibmpex_update_device()
227 for (i = 0; i < data->num_sensors; i++) { in ibmpex_update_device()
228 if (!data->sensors[i].in_use) in ibmpex_update_device()
230 err = ibmpex_query_sensor_data(data, i); in ibmpex_update_device()
233 data->sensors[i].values[0] = in ibmpex_update_device()
234 extract_value(data->rx_msg_data, 16); in ibmpex_update_device()
235 data->sensors[i].values[1] = in ibmpex_update_device()
236 extract_value(data->rx_msg_data, 18); in ibmpex_update_device()
237 data->sensors[i].values[2] = in ibmpex_update_device()
238 extract_value(data->rx_msg_data, 20); in ibmpex_update_device()
241 data->last_updated = jiffies; in ibmpex_update_device()
242 data->valid = true; in ibmpex_update_device()
245 mutex_unlock(&data->lock); in ibmpex_update_device()
271 struct ibmpex_bmc_data *data = dev_get_drvdata(dev); in ibmpex_show_sensor() local
272 int mult = data->sensors[attr->index].multiplier; in ibmpex_show_sensor()
273 ibmpex_update_device(data); in ibmpex_show_sensor()
276 data->sensors[attr->index].values[attr->nr] * mult); in ibmpex_show_sensor()
283 struct ibmpex_bmc_data *data = dev_get_drvdata(dev); in ibmpex_high_low_store() local
285 ibmpex_reset_high_low_data(data); in ibmpex_high_low_store()
312 static int power_sensor_multiplier(struct ibmpex_bmc_data *data, in power_sensor_multiplier() argument
317 if (data->sensor_major == 2) in power_sensor_multiplier()
327 static int create_sensor(struct ibmpex_bmc_data *data, int type, in create_sensor() argument
344 sysfs_attr_init(&data->sensors[sensor].attr[func].dev_attr.attr); in create_sensor()
345 data->sensors[sensor].attr[func].dev_attr.attr.name = n; in create_sensor()
346 data->sensors[sensor].attr[func].dev_attr.attr.mode = 0444; in create_sensor()
347 data->sensors[sensor].attr[func].dev_attr.show = ibmpex_show_sensor; in create_sensor()
348 data->sensors[sensor].attr[func].index = sensor; in create_sensor()
349 data->sensors[sensor].attr[func].nr = func; in create_sensor()
351 err = device_create_file(data->bmc_device, in create_sensor()
352 &data->sensors[sensor].attr[func].dev_attr); in create_sensor()
354 data->sensors[sensor].attr[func].dev_attr.attr.name = NULL; in create_sensor()
362 static int ibmpex_find_sensors(struct ibmpex_bmc_data *data) in ibmpex_find_sensors() argument
370 err = ibmpex_query_sensor_count(data); in ibmpex_find_sensors()
373 data->num_sensors = err; in ibmpex_find_sensors()
375 data->sensors = kcalloc(data->num_sensors, sizeof(*data->sensors), in ibmpex_find_sensors()
377 if (!data->sensors) in ibmpex_find_sensors()
380 for (i = 0; i < data->num_sensors; i++) { in ibmpex_find_sensors()
381 err = ibmpex_query_sensor_name(data, i); in ibmpex_find_sensors()
385 if (is_power_sensor(data->rx_msg_data, data->rx_msg_len)) { in ibmpex_find_sensors()
389 data->sensors[i].multiplier = in ibmpex_find_sensors()
390 power_sensor_multiplier(data, in ibmpex_find_sensors()
391 data->rx_msg_data, in ibmpex_find_sensors()
392 data->rx_msg_len); in ibmpex_find_sensors()
393 } else if (is_temp_sensor(data->rx_msg_data, in ibmpex_find_sensors()
394 data->rx_msg_len)) { in ibmpex_find_sensors()
398 data->sensors[i].multiplier = 1000; in ibmpex_find_sensors()
402 data->sensors[i].in_use = 1; in ibmpex_find_sensors()
406 err = create_sensor(data, sensor_type, sensor_counter, in ibmpex_find_sensors()
413 err = device_create_file(data->bmc_device, in ibmpex_find_sensors()
418 err = device_create_file(data->bmc_device, in ibmpex_find_sensors()
426 device_remove_file(data->bmc_device, in ibmpex_find_sensors()
428 device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); in ibmpex_find_sensors()
429 for (i = 0; i < data->num_sensors; i++) in ibmpex_find_sensors()
431 if (!data->sensors[i].attr[j].dev_attr.attr.name) in ibmpex_find_sensors()
433 device_remove_file(data->bmc_device, in ibmpex_find_sensors()
434 &data->sensors[i].attr[j].dev_attr); in ibmpex_find_sensors()
435 kfree(data->sensors[i].attr[j].dev_attr.attr.name); in ibmpex_find_sensors()
438 kfree(data->sensors); in ibmpex_find_sensors()
444 struct ibmpex_bmc_data *data; in ibmpex_register_bmc() local
447 data = kzalloc(sizeof(*data), GFP_KERNEL); in ibmpex_register_bmc()
448 if (!data) in ibmpex_register_bmc()
451 data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; in ibmpex_register_bmc()
452 data->address.channel = IPMI_BMC_CHANNEL; in ibmpex_register_bmc()
453 data->address.data[0] = 0; in ibmpex_register_bmc()
454 data->interface = iface; in ibmpex_register_bmc()
455 data->bmc_device = dev; in ibmpex_register_bmc()
458 err = ipmi_create_user(data->interface, &driver_data.ipmi_hndlrs, in ibmpex_register_bmc()
459 data, &data->user); in ibmpex_register_bmc()
463 data->interface); in ibmpex_register_bmc()
467 mutex_init(&data->lock); in ibmpex_register_bmc()
470 data->tx_msgid = 0; in ibmpex_register_bmc()
471 init_completion(&data->read_complete); in ibmpex_register_bmc()
472 data->tx_message.netfn = PEX_NET_FUNCTION; in ibmpex_register_bmc()
473 data->tx_message.cmd = PEX_COMMAND; in ibmpex_register_bmc()
474 data->tx_message.data = data->tx_msg_data; in ibmpex_register_bmc()
477 err = ibmpex_ver_check(data); in ibmpex_register_bmc()
482 data->hwmon_dev = hwmon_device_register(data->bmc_device); in ibmpex_register_bmc()
484 if (IS_ERR(data->hwmon_dev)) { in ibmpex_register_bmc()
485 dev_err(data->bmc_device, in ibmpex_register_bmc()
487 data->interface); in ibmpex_register_bmc()
492 dev_set_drvdata(dev, data); in ibmpex_register_bmc()
493 list_add_tail(&data->list, &driver_data.bmc_data); in ibmpex_register_bmc()
496 err = ibmpex_find_sensors(data); in ibmpex_register_bmc()
498 dev_err(data->bmc_device, "Error %d finding sensors\n", err); in ibmpex_register_bmc()
505 list_del(&data->list); in ibmpex_register_bmc()
506 hwmon_device_unregister(data->hwmon_dev); in ibmpex_register_bmc()
508 ipmi_destroy_user(data->user); in ibmpex_register_bmc()
510 kfree(data); in ibmpex_register_bmc()
513 static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data) in ibmpex_bmc_delete() argument
517 device_remove_file(data->bmc_device, in ibmpex_bmc_delete()
519 device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr); in ibmpex_bmc_delete()
520 for (i = 0; i < data->num_sensors; i++) in ibmpex_bmc_delete()
522 if (!data->sensors[i].attr[j].dev_attr.attr.name) in ibmpex_bmc_delete()
524 device_remove_file(data->bmc_device, in ibmpex_bmc_delete()
525 &data->sensors[i].attr[j].dev_attr); in ibmpex_bmc_delete()
526 kfree(data->sensors[i].attr[j].dev_attr.attr.name); in ibmpex_bmc_delete()
529 list_del(&data->list); in ibmpex_bmc_delete()
530 dev_set_drvdata(data->bmc_device, NULL); in ibmpex_bmc_delete()
531 hwmon_device_unregister(data->hwmon_dev); in ibmpex_bmc_delete()
532 ipmi_destroy_user(data->user); in ibmpex_bmc_delete()
533 kfree(data->sensors); in ibmpex_bmc_delete()
534 kfree(data); in ibmpex_bmc_delete()
539 struct ibmpex_bmc_data *data = get_bmc_data(iface); in ibmpex_bmc_gone() local
541 if (!data) in ibmpex_bmc_gone()
544 ibmpex_bmc_delete(data); in ibmpex_bmc_gone()
549 struct ibmpex_bmc_data *data = user_msg_data; in ibmpex_msg_handler() local
551 if (msg->msgid != data->tx_msgid) { in ibmpex_msg_handler()
552 dev_err(data->bmc_device, in ibmpex_msg_handler()
555 (int)data->tx_msgid); in ibmpex_msg_handler()
560 data->rx_recv_type = msg->recv_type; in ibmpex_msg_handler()
562 data->rx_result = msg->msg.data[0]; in ibmpex_msg_handler()
564 data->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE; in ibmpex_msg_handler()
567 data->rx_msg_len = msg->msg.data_len - 1; in ibmpex_msg_handler()
568 memcpy(data->rx_msg_data, msg->msg.data + 1, data->rx_msg_len); in ibmpex_msg_handler()
570 data->rx_msg_len = 0; in ibmpex_msg_handler()
573 complete(&data->read_complete); in ibmpex_msg_handler()