Skip to content

Commit d559cb3

Browse files
author
Willy Liu
committed
[ACCTON][AS9947-72XKB] Modularize IPMI-Related functions
1. Add ipmi interface common code 2. Remove the ipmi codebase from each device driver 3. Remove ipmi PSU device index 4. Fix the each device functions because there is no PSU index 5. Fix functions of psu status and string accessing 6. Fix function of psu hwmon index accessing Signed-off-by: Willy Liu <willy@accton.com>
1 parent 6e2262b commit d559cb3

File tree

12 files changed

+84
-939
lines changed

12 files changed

+84
-939
lines changed

packages/platforms/accton/x86-64/as9947-72xkb/modules/builds/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
obj-m += accton_ipmi_intf.o
12
obj-m += x86-64-accton-as9947-72xkb-i2c-ocores.o
23
obj-m += x86-64-accton-as9947-72xkb-fpga.o
34
obj-m += x86-64-accton-as9947-72xkb-fan.o

packages/platforms/accton/x86-64/as9947-72xkb/modules/builds/src/x86-64-accton-as9947-72xkb-fan.c

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,20 @@
2929
#include <linux/sysfs.h>
3030
#include <linux/hwmon.h>
3131
#include <linux/hwmon-sysfs.h>
32-
#include <linux/ipmi.h>
33-
#include <linux/ipmi_smi.h>
3432
#include <linux/platform_device.h>
3533
#include <linux/string_helpers.h>
34+
#include "accton_ipmi_intf.h"
3635

3736
#define DRVNAME "as9947_72xkb_fan"
38-
#define ACCTON_IPMI_NETFN 0x34
3937
#define IPMI_FAN_READ_CMD 0x14
4038
#define IPMI_FAN_WRITE_CMD 0x15
4139
#define IPMI_FAN_READ_MODEL_CMD 0x10
4240
#define IPMI_FAN_READ_SERIAL_CMD 0x11
43-
#define IPMI_TIMEOUT (5 * HZ)
44-
#define IPMI_ERR_RETRY_TIMES 1
4541
#define IPMI_FAN_REG_READ_CMD 0x20
4642
#define MAX_FAN_SPEED_RPM 33000
4743
#define IPMI_FAN_MODEL_SIZE 15
4844
#define IPMI_FAN_SERIAL_SIZE 13
4945

50-
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
5146
static ssize_t set_fan(struct device *dev, struct device_attribute *da,
5247
const char *buf, size_t count);
5348
static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
@@ -90,24 +85,6 @@ enum fan_data_index {
9085
FAN_DATA_COUNT
9186
};
9287

93-
94-
struct ipmi_data {
95-
struct completion read_complete;
96-
struct ipmi_addr address;
97-
struct ipmi_user *user;
98-
int interface;
99-
100-
struct kernel_ipmi_msg tx_message;
101-
long tx_msgid;
102-
103-
void *rx_msg_data;
104-
unsigned short rx_msg_len;
105-
unsigned char rx_result;
106-
int rx_recv_type;
107-
108-
struct ipmi_user_hndl ipmi_hndlrs;
109-
};
110-
11188
struct as9947_72xkb_fan_data {
11289
struct platform_device *pdev;
11390
struct device *hwmon_dev;
@@ -246,156 +223,6 @@ static struct attribute *as9947_72xkb_fan_attrs[] = {
246223
};
247224
ATTRIBUTE_GROUPS(as9947_72xkb_fan);
248225

249-
/* Functions to talk to the IPMI layer */
250-
251-
/* Initialize IPMI address, message buffers and user data */
252-
static int init_ipmi_data(struct ipmi_data *ipmi, int iface,
253-
struct device *dev)
254-
{
255-
int err;
256-
257-
init_completion(&ipmi->read_complete);
258-
259-
/* Initialize IPMI address */
260-
ipmi->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
261-
ipmi->address.channel = IPMI_BMC_CHANNEL;
262-
ipmi->address.data[0] = 0;
263-
ipmi->interface = iface;
264-
265-
/* Initialize message buffers */
266-
ipmi->tx_msgid = 0;
267-
ipmi->tx_message.netfn = ACCTON_IPMI_NETFN;
268-
269-
ipmi->ipmi_hndlrs.ipmi_recv_hndl = ipmi_msg_handler;
270-
271-
/* Create IPMI messaging interface user */
272-
err = ipmi_create_user(ipmi->interface, &ipmi->ipmi_hndlrs,
273-
ipmi, &ipmi->user);
274-
if (err < 0) {
275-
dev_err(dev, "Unable to register user with IPMI "
276-
"interface %d\n", ipmi->interface);
277-
return -EACCES;
278-
}
279-
280-
return 0;
281-
}
282-
283-
/* Send an IPMI command */
284-
static int _ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
285-
unsigned char *tx_data, unsigned short tx_len,
286-
unsigned char *rx_data, unsigned short rx_len)
287-
{
288-
int err;
289-
290-
ipmi->tx_message.cmd = cmd;
291-
ipmi->tx_message.data = tx_data;
292-
ipmi->tx_message.data_len = tx_len;
293-
ipmi->rx_msg_data = rx_data;
294-
ipmi->rx_msg_len = rx_len;
295-
296-
err = ipmi_validate_addr(&ipmi->address, sizeof(ipmi->address));
297-
if (err)
298-
goto addr_err;
299-
300-
ipmi->tx_msgid++;
301-
err = ipmi_request_settime(ipmi->user, &ipmi->address, ipmi->tx_msgid,
302-
&ipmi->tx_message, ipmi, 0, 0, 0);
303-
if (err)
304-
goto ipmi_req_err;
305-
306-
err = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT);
307-
if (!err)
308-
goto ipmi_timeout_err;
309-
310-
return 0;
311-
312-
ipmi_timeout_err:
313-
err = -ETIMEDOUT;
314-
dev_err(&data->pdev->dev, "request_timeout=%x\n", err);
315-
return err;
316-
ipmi_req_err:
317-
dev_err(&data->pdev->dev, "request_settime=%x\n", err);
318-
return err;
319-
addr_err:
320-
dev_err(&data->pdev->dev, "validate_addr=%x\n", err);
321-
return err;
322-
}
323-
324-
/* Send an IPMI command with retry */
325-
static int ipmi_send_message(struct ipmi_data *ipmi, unsigned char cmd,
326-
unsigned char *tx_data, unsigned short tx_len,
327-
unsigned char *rx_data, unsigned short rx_len)
328-
{
329-
int status = 0, retry = 0;
330-
char *cmdline = kstrdup_quotable_cmdline(current, GFP_KERNEL);
331-
int i = 0;
332-
char raw_cmd[20] = "";
333-
334-
sprintf(raw_cmd, "0x%02x", cmd);
335-
336-
if(tx_len) {
337-
for(i = 0; i < tx_len; i++)
338-
sprintf(raw_cmd + strlen(raw_cmd), " 0x%02x", tx_data[i]);
339-
}
340-
341-
for (retry = 0; retry <= IPMI_ERR_RETRY_TIMES; retry++) {
342-
status = _ipmi_send_message(ipmi,cmd, tx_data, tx_len, rx_data, rx_len);
343-
if (unlikely(status != 0)) {
344-
dev_err(&data->pdev->dev,
345-
"ipmi_send_message_%d err status(%d)[%s] raw_cmd=[%s] tx_msgid=(%02x)\r\n",
346-
retry, status, cmdline ? cmdline : "", raw_cmd,
347-
(int)ipmi->tx_msgid);
348-
continue;
349-
}
350-
351-
if (unlikely(ipmi->rx_result != 0)) {
352-
dev_err(&data->pdev->dev,
353-
"ipmi_send_message_%d err result(%d)[%s] raw_cmd=[%s] tx_msgid=(%02x)\r\n",
354-
retry, ipmi->rx_result, cmdline ? cmdline : "", raw_cmd,
355-
(int)ipmi->tx_msgid);
356-
continue;
357-
}
358-
359-
break;
360-
}
361-
362-
return status;
363-
}
364-
365-
/* Dispatch IPMI messages to callers */
366-
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
367-
{
368-
unsigned short rx_len;
369-
struct ipmi_data *ipmi = user_msg_data;
370-
371-
if (msg->msgid != ipmi->tx_msgid) {
372-
dev_err(&data->pdev->dev, "Mismatch between received msgid "
373-
"(%02x) and transmitted msgid (%02x)!\n",
374-
(int)msg->msgid,
375-
(int)ipmi->tx_msgid);
376-
ipmi_free_recv_msg(msg);
377-
return;
378-
}
379-
380-
ipmi->rx_recv_type = msg->recv_type;
381-
if (msg->msg.data_len > 0)
382-
ipmi->rx_result = msg->msg.data[0];
383-
else
384-
ipmi->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE;
385-
386-
if (msg->msg.data_len > 1) {
387-
rx_len = msg->msg.data_len - 1;
388-
if (ipmi->rx_msg_len < rx_len)
389-
rx_len = ipmi->rx_msg_len;
390-
ipmi->rx_msg_len = rx_len;
391-
memcpy(ipmi->rx_msg_data, msg->msg.data + 1, ipmi->rx_msg_len);
392-
} else
393-
ipmi->rx_msg_len = 0;
394-
395-
ipmi_free_recv_msg(msg);
396-
complete(&ipmi->read_complete);
397-
}
398-
399226
static struct as9947_72xkb_fan_data *as9947_72xkb_fan_update_device(void)
400227
{
401228
int status = 0;

0 commit comments

Comments
 (0)