summaryrefslogtreecommitdiff
path: root/xpp/xbus-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'xpp/xbus-core.c')
-rw-r--r--xpp/xbus-core.c255
1 files changed, 78 insertions, 177 deletions
diff --git a/xpp/xbus-core.c b/xpp/xbus-core.c
index cbec226..b15ab4c 100644
--- a/xpp/xbus-core.c
+++ b/xpp/xbus-core.c
@@ -61,19 +61,6 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer,
extern int print_dbg;
DEF_PARM(uint, poll_timeout, POLL_TIMEOUT, 0644, "Timeout (in jiffies) waiting for units to reply");
-/* Forward declarations */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
-#define DEVICE_ATTR_FUNC(name,dev,buf) \
- ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
-#else
-#define DEVICE_ATTR_FUNC(name,dev,buf) \
- ssize_t name(struct device *dev, char *buf)
-#endif
-
-static DEVICE_ATTR_FUNC(connector_show, dev, buf);
-static DEVICE_ATTR_FUNC(status_show, dev, buf);
-
-static void xbus_release(struct device *dev);
static int xbus_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data);
static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count, int *eof, void *data);
static int read_proc_xmitter(char *page, char **start, off_t off, int count, int *eof, void *data);
@@ -85,9 +72,6 @@ static xbus_t *xbuses_array[MAX_BUSES] = {};
static int bus_count = 0;
static struct proc_dir_entry *proc_xbuses = NULL;
-static DEVICE_ATTR(connector, S_IRUGO, connector_show, NULL);
-static DEVICE_ATTR(status, S_IRUGO, status_show, NULL);
-
/*
* Command Statistics
*/
@@ -135,7 +119,7 @@ int xbus_log(xbus_t *xbus, xpd_t *xpd, int direction, const void *buf, unsigned
spin_lock_irqsave(&d->lock, flags);
if (sizeof(struct log_header) + len > DEBUGFS_BUFSIZ - (d->tail - d->head)) {
ret = -ENOSPC;
- DBG("Dropping debugfs data of len %lu, free space is %lu\n", sizeof(struct log_header) + len,
+ XPD_DBG(xpd, "Dropping debugfs data of len %lu, free space is %lu\n", sizeof(struct log_header) + len,
DEBUGFS_BUFSIZ - (d->tail - d->head));
goto out;
}
@@ -183,7 +167,7 @@ static int debugfs_open(struct inode *inode, struct file *file)
struct log_global_header gheader;
BUG_ON(!xbus);
- DBG("%s\n", xbus->busname);
+ XBUS_DBG(xbus, "\n");
if (xbus->debugfs_data)
return -EBUSY;
d = kmalloc(sizeof(struct debugfs_data), GFP_KERNEL);
@@ -212,7 +196,7 @@ static ssize_t debugfs_read(struct file *file, char __user *buf, size_t nbytes,
BUG_ON(!d);
BUG_ON(!d->xbus);
- DBG("%s\n", d->xbus->busname);
+ XBUS_DBG(d->xbus, "\n");
while (d->head == d->tail) {
if (wait_event_interruptible(d->queue, d->head != d->tail))
return -EAGAIN;
@@ -238,7 +222,7 @@ static int debugfs_release(struct inode *inode, struct file *file)
BUG_ON(!d);
BUG_ON(!d->xbus);
- DBG("%s\n", d->xbus->busname);
+ XBUS_DBG(d->xbus, "\n");
d->xbus->debugfs_data = NULL;
kfree(d);
module_put(THIS_MODULE);
@@ -321,7 +305,7 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe)
do {
if(pos >= XFRAME_DATASIZE) {
if(printk_ratelimit()) {
- NOTICE("%s: xframe overflow (%d bytes)\n",
+ XBUS_NOTICE(xbus, "%s: xframe overflow (%d bytes)\n",
msg, frame_len);
do_hexdump(msg, xframe->packets, frame_len);
}
@@ -329,7 +313,7 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe)
}
if(pos > frame_len) {
if(printk_ratelimit()) {
- NOTICE("%s: packet overflow pos=%d frame_len=%d\n",
+ XBUS_NOTICE(xbus, "%s: packet overflow pos=%d frame_len=%d\n",
msg, pos, frame_len);
do_hexdump(msg, xframe->packets, frame_len);
}
@@ -338,7 +322,7 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe)
pack = (xpacket_t *)&xframe->packets[pos];
if(pack->datalen <= 0) {
if(printk_ratelimit()) {
- NOTICE("%s: xframe -- bad datalen=%d pos=%d frame_len=%d\n",
+ XBUS_NOTICE(xbus, "%s: xframe -- bad datalen=%d pos=%d frame_len=%d\n",
msg, pack->datalen, pos, frame_len);
do_hexdump(msg, xframe->packets, frame_len);
}
@@ -347,7 +331,7 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe)
nextpos = pos + pack->datalen;
if(nextpos > frame_len) {
if(printk_ratelimit()) {
- NOTICE("%s: packet overflow nextpos=%d frame_len=%d\n",
+ XBUS_NOTICE(xbus, "%s: packet overflow nextpos=%d frame_len=%d\n",
msg, nextpos, frame_len);
do_hexdump(msg, xframe->packets, frame_len);
}
@@ -361,9 +345,9 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe)
do_print = 1;
if(do_print) {
if(num == 1)
- DBG("%s: %s: frame_len=%d.\n",
- msg, xbus->busname, frame_len);
- DBG(" %3d. DATALEN=%d OP=0x%02X XPD-%d%d (pos=%d)\n",
+ XBUS_DBG(xbus, "%s: frame_len=%d.\n",
+ msg, frame_len);
+ XBUS_DBG(xbus, " %3d. DATALEN=%d OP=0x%02X XPD-%d%d (pos=%d)\n",
num, pack->datalen, pack->opcode,
pack->addr.unit, pack->addr.subunit, pos);
dump_packet(" ", pack, print_dbg);
@@ -396,7 +380,7 @@ int xframe_send(xbus_t *xbus, xframe_t *xframe)
goto error;
}
if (!xbus->hardware_exists) {
- DBG("xbus %s Dropped a xframe -- NO HARDWARE.", xbus->busname);
+ XBUS_DBG(xbus, "Dropped a xframe -- NO HARDWARE.");
ret = -ENODEV;
goto error;
}
@@ -405,7 +389,7 @@ int xframe_send(xbus_t *xbus, xframe_t *xframe)
XBUS_COUNTER(xbus, TX_BYTES) += XFRAME_LEN(xframe);
up_read(&xbus->in_use);
} else {
- DBG("Dropped xframe. %s is in_use\n", xbus->busname);
+ XBUS_DBG(xbus, "Dropped xframe. Is in_use\n");
}
return ret;
@@ -420,7 +404,6 @@ int send_cmd_frame(xbus_t *xbus, xframe_t *xframe)
struct timeval *created = &xframe->tv_created;
ulong usec_diff;
- DBG("%s:\n", xbus->busname);
command_count++;
do_gettimeofday(&now);
usec_diff =
@@ -460,15 +443,15 @@ int xbus_register_xpd(xbus_t *xbus, xpd_t *xpd)
spin_lock_irqsave(&xbus->lock, flags);
if(!VALID_XPD_NUM(xpd_num)) {
- ERR("%s: Bad xpd_num = %d\n", xbus->busname, xpd_num);
+ XBUS_ERR(xbus, "Bad xpd_num = %d\n", xpd_num);
ret = -EINVAL;
goto out;
}
if(xbus->xpds[xpd_num] != NULL) {
xpd_t *other = xbus->xpds[xpd_num];
- ERR("%s: xpd_num=%d is occupied by %p (%s)\n",
- xbus->busname, xpd_num, other, other->xpdname);
+ XBUS_ERR(xbus, "xpd_num=%d is occupied by %p (%s)\n",
+ xpd_num, other, other->xpdname);
ret = -EINVAL;
goto out;
}
@@ -488,19 +471,18 @@ int xbus_unregister_xpd(xbus_t *xbus, xpd_t *xpd)
spin_lock_irqsave(&xbus->lock, flags);
if(!VALID_XPD_NUM(xpd_num)) {
- ERR("%s: %s: Bad xpd_num = %d\n", __FUNCTION__, xbus->busname, xpd_num);
+ XBUS_ERR(xbus, "%s: Bad xpd_num = %d\n", __FUNCTION__, xpd_num);
goto out;
}
if(xbus->xpds[xpd_num] == NULL) {
- ERR("%s: %s: slot xpd_num=%d is empty\n",
- __FUNCTION__, xbus->busname, xpd_num);
+ XBUS_ERR(xbus, "%s: slot xpd_num=%d is empty\n", __FUNCTION__, xpd_num);
goto out;
}
if(xbus->xpds[xpd_num] != xpd) {
xpd_t *other = xbus->xpds[xpd_num];
- ERR("%s: %s: slot xpd_num=%d is occupied by %p (%s)\n",
- __FUNCTION__, xbus->busname, xpd_num, other, other->xpdname);
+ XBUS_ERR(xbus, "%s: slot xpd_num=%d is occupied by %p (%s)\n",
+ __FUNCTION__, xpd_num, other, other->xpdname);
goto out;
}
xbus->xpds[xpd_num] = NULL;
@@ -541,12 +523,12 @@ static void xbus_poll(void *data)
xbus = poller->xbus;
BUG_ON(!xbus);
if(!down_read_trylock(&xbus->in_use)) {
- ERR("%s is being removed...\n", xbus->busname);
+ XBUS_ERR(xbus, "Is being removed...\n");
return;
}
msleep(2); /* roundtrip for older polls */
spin_lock_irqsave(&xbus->lock, flags);
- DBG("%s\n", xbus->busname);
+ XBUS_DBG(xbus, "\n");
poller->is_polling = 1;
/*
@@ -555,12 +537,12 @@ static void xbus_poll(void *data)
for(id = 0; id < MAX_XPDS; id++) {
if(!xbus->hardware_exists)
break;
- // DBG(" Polling slot %d %s\n", id, xbus->busname);
+ // XBUS_DBG(xbus, "Polling slot %d\n", id);
spin_unlock_irqrestore(&xbus->lock, flags);
ret = CALL_PROTO(GLOBAL, DESC_REQ, xbus, NULL, id);
spin_lock_irqsave(&xbus->lock, flags);
if(ret < 0) {
- ERR("xpp: %s: Failed sending DESC_REQ to XPD #%d\n", __FUNCTION__, id);
+ XBUS_ERR(xbus, "Failed sending DESC_REQ to XPD #%d\n", id);
goto out;
}
}
@@ -568,18 +550,18 @@ static void xbus_poll(void *data)
/*
* Wait for replies
*/
- DBG("%s: Polled %d XPD's. Waiting for replies max %d jiffies\n", xbus->busname, MAX_XPDS, poll_timeout);
+ XBUS_DBG(xbus, "Polled %d XPD's. Waiting for replies max %d jiffies\n", MAX_XPDS, poll_timeout);
ret = wait_event_interruptible_timeout(poller->wait_for_polls, atomic_read(&poller->count_poll_answers) >= MAX_XPDS, poll_timeout);
if(ret == 0) {
- ERR("%s: Poll timeout. Continuing anyway.\n", xbus->busname);
+ XBUS_ERR(xbus, "Poll timeout. Continuing anyway.\n");
/*
* Continue processing. Maybe some units did reply.
*/
} else if(ret < 0) {
- ERR("%s: Poll interrupted %d\n", xbus->busname, ret);
+ XBUS_ERR(xbus, "Poll interrupted %d\n", ret);
goto out;
} else
- DBG("%s: Poll finished in %d jiffies.\n", xbus->busname, poll_timeout - ret);
+ XBUS_DBG(xbus, "Poll finished in %d jiffies.\n", poll_timeout - ret);
/*
* Build removals/additions lists
*/
@@ -613,7 +595,7 @@ static void xbus_poll(void *data)
*/
atomic_set(&poller->count_xpds_to_initialize, count_added);
spin_unlock_irqrestore(&xbus->lock, flags);
- INFO("%s: Poll results: removals=%d additions=%d\n", xbus->busname, count_removed, count_added);
+ XBUS_INFO(xbus, "Poll results: removals=%d additions=%d\n", count_removed, count_added);
/*
* Process removals first
*/
@@ -638,6 +620,11 @@ static void xbus_poll(void *data)
card_detected(card_desc);
atomic_inc(&poller->count_xpds_initialized);
}
+ /* Device-Model */
+ if((ret = xbus_sysfs_create(xbus)) < 0) {
+ XBUS_ERR(xbus, "%s: xbus_sysfs_create() failed: %d\n", __FUNCTION__, ret);
+ goto out;
+ }
wake_up(&poller->wait_for_xpd_initialization);
out:
poller->is_polling = 0;
@@ -654,8 +641,7 @@ void xbus_poller_notify(xbus_t *xbus, struct card_desc_struct *card_desc)
poller = xbus->poller;
BUG_ON(!poller);
if(!poller->is_polling) {
- NOTICE("%s: %d%d replied not during poll. Ignore\n",
- xbus->busname,
+ XBUS_NOTICE(xbus, "%d%d replied not during poll. Ignore\n",
card_desc->xpd_addr.unit,
card_desc->xpd_addr.subunit);
kfree(card_desc);
@@ -683,11 +669,11 @@ static void poller_destroy(struct xbus_poller *poller)
if(!poller)
return;
if(poller->xbus) {
- DBG("%s: detach poller\n", poller->xbus->busname);
+ XBUS_DBG(poller->xbus, "detach poller\n");
poller->xbus->poller = NULL;
}
if (poller->wq) {
- DBG("%s: destroy workqueue\n", poller->xbus->busname);
+ XBUS_DBG(poller->xbus, "destroy workqueue\n");
flush_workqueue(poller->wq);
destroy_workqueue(poller->wq);
poller->wq = NULL;
@@ -706,7 +692,7 @@ static struct xbus_poller *poller_new(xbus_t *xbus)
BUG_ON(xbus->busname[0] == '\0'); /* No name? */
BUG_ON(xbus->poller); /* Hmmm... overrun pollers? */
- DBG("%s\n", xbus->busname);
+ XBUS_DBG(xbus, "\n");
poller = kmalloc(sizeof(*poller), GFP_KERNEL);
if(!poller)
goto err;
@@ -722,7 +708,7 @@ static struct xbus_poller *poller_new(xbus_t *xbus)
init_waitqueue_head(&poller->wait_for_xpd_initialization);
poller->wq = create_singlethread_workqueue(xbus->busname);
if(!poller->wq) {
- ERR("%s: Failed to create poller workqueue.\n", xbus->busname);
+ XBUS_ERR(xbus, "Failed to create poller workqueue.\n");
goto err;
}
return poller;
@@ -739,7 +725,7 @@ static int poller_dispatch(xbus_t *xbus)
struct xbus_poller *poller = xbus->poller;
if(!poller) {
- ERR("%s: missing poller\n", xbus->busname);
+ XBUS_ERR(xbus, "missing poller\n");
return 0;
}
/* Initialize the work. (adapt to kernel API changes). */
@@ -750,8 +736,7 @@ static int poller_dispatch(xbus_t *xbus)
#endif
/* Now send it */
if(!queue_work(poller->wq, &poller->xpds_init_work)) {
- ERR("%s: Failed to queue xpd initialization work\n",
- xbus->busname);
+ XBUS_ERR(xbus, "Failed to queue xpd initialization work\n");
return 0;
}
return 1;
@@ -771,7 +756,7 @@ void xbus_activate(xbus_t *xbus)
BUG_ON(!ops->xframe_send);
BUG_ON(!ops->xframe_new || !ops->xframe_free);
xbus->hardware_exists = 1;
- DBG("Activating: %s\n", xbus->busname);
+ XBUS_DBG(xbus, "Activating\n");
/* Poll it */
poller_dispatch(xbus);
}
@@ -781,19 +766,19 @@ void xbus_disconnect(xbus_t *xbus)
int i;
BUG_ON(!xbus);
- DBG("%s\n", xbus->busname);
+ XBUS_DBG(xbus, "\n");
xbus->hardware_exists = 0;
for(i = 0; i < MAX_XPDS; i++) {
xpd_t *xpd = xpd_of(xbus, i);
if(!xpd)
continue;
if(xpd->xbus_idx != i) {
- ERR("%s: BUG: xpd->xbus_idx=%d != i=%d\n", __FUNCTION__, xpd->xbus_idx, i);
+ XBUS_ERR(xbus, "BUG: xpd->xbus_idx=%d != i=%d\n", xpd->xbus_idx, i);
continue;
}
xpd_disconnect(xpd);
}
- DBG("%s (deactivated)\n", xbus->busname);
+ XBUS_DBG(xbus, "Deactivated\n");
if(xbus->open_counter == 0) {
xbus_remove(xbus);
}
@@ -844,53 +829,41 @@ static void xbus_free(xbus_t *xbus)
#ifdef XPP_DEBUGFS
if(xbus->debugfs_dir) {
if(xbus->debugfs_file) {
- DBG("Removing debugfs file for %s\n", xbus->busname);
+ XBUS_DBG(xbus, "Removing debugfs file\n");
debugfs_remove(xbus->debugfs_file);
}
- DBG("Removing debugfs directory for %s\n", xbus->busname);
+ XBUS_DBG(xbus, "Removing debugfs directory\n");
debugfs_remove(xbus->debugfs_dir);
}
#endif
#ifdef CONFIG_PROC_FS
if(xbus->proc_xbus_dir) {
if(xbus->proc_xbus_summary) {
- DBG("Removing proc '%s' for %s\n", PROC_XBUS_SUMMARY, xbus->busname);
+ XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_SUMMARY);
remove_proc_entry(PROC_XBUS_SUMMARY, xbus->proc_xbus_dir);
xbus->proc_xbus_summary = NULL;
}
if(xbus->proc_xbus_waitfor_xpds) {
- DBG("Removing proc '%s' for %s\n", PROC_XBUS_WAITFOR_XPDS, xbus->busname);
+ XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_WAITFOR_XPDS);
remove_proc_entry(PROC_XBUS_WAITFOR_XPDS, xbus->proc_xbus_dir);
xbus->proc_xbus_waitfor_xpds = NULL;
}
#ifdef PROTOCOL_DEBUG
if(xbus->proc_xbus_command) {
- DBG("Removing proc '%s' for %s\n", PROC_XBUS_COMMAND, xbus->busname);
+ XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_COMMAND);
remove_proc_entry(PROC_XBUS_COMMAND, xbus->proc_xbus_dir);
xbus->proc_xbus_command = NULL;
}
#endif
- DBG("Removing proc directory %s\n", xbus->busname);
+ XBUS_DBG(xbus, "Removing proc directory\n");
remove_proc_entry(xbus->busname, xpp_proc_toplevel);
xbus->proc_xbus_dir = NULL;
}
#endif
- device_remove_file(&xbus->the_bus, &dev_attr_status);
- device_remove_file(&xbus->the_bus, &dev_attr_connector);
- device_unregister(&xbus->the_bus);
poller_destroy(xbus->poller);
kfree(xbus);
}
-static void xbus_release(struct device *dev)
-{
- xbus_t *xbus;
-
- BUG_ON(!dev);
- xbus = dev->driver_data;
- DBG("%s\n", xbus->busname);
-}
-
xbus_t *xbus_new(xbus_ops_t *ops)
{
int err;
@@ -904,7 +877,7 @@ xbus_t *xbus_new(xbus_ops_t *ops)
/* Init data structures */
spin_lock_init(&xbus->lock);
snprintf(xbus->busname, XBUS_NAMELEN, "XBUS-%02d", xbus->num);
- INFO("New xbus: %s\n", xbus->busname);
+ XBUS_INFO(xbus, "New xbus\n");
init_waitqueue_head(&xbus->packet_cache_empty);
atomic_set(&xbus->packet_counter, 0);
atomic_set(&xbus->pcm_nesting, 1);
@@ -920,40 +893,18 @@ xbus_t *xbus_new(xbus_ops_t *ops)
}
init_rwsem(&xbus->in_use);
xbus_reset_counters(xbus);
-
- /* Device-Model */
- snprintf(xbus->the_bus.bus_id, BUS_ID_SIZE, "xbus-%d", xbus->num);
- xbus->the_bus.driver_data = xbus;
- xbus->the_bus.release = xbus_release;
-
- err = device_register(&xbus->the_bus);
- if(err) {
- ERR("%s: device_register failed: %d\n", __FUNCTION__, err);
- goto nobus;
- }
- err = device_create_file(&xbus->the_bus, &dev_attr_connector);
- if(err) {
- ERR("%s: device_create_file failed: %d\n", __FUNCTION__, err);
- goto nobus;
- }
- err = device_create_file(&xbus->the_bus, &dev_attr_status);
- if(err) {
- ERR("%s: device_create_file failed: %d\n", __FUNCTION__, err);
- goto nobus;
- }
-
#ifdef CONFIG_PROC_FS
- DBG("Creating xbus proc directory %s.\n",xbus->busname);
+ XBUS_DBG(xbus, "Creating xbus proc directory\n");
xbus->proc_xbus_dir = proc_mkdir(xbus->busname, xpp_proc_toplevel);
if(!xbus->proc_xbus_dir) {
- ERR("Failed to create proc directory for xbus %s\n", xbus->busname);
+ XBUS_ERR(xbus, "Failed to create proc directory\n");
err = -EIO;
goto nobus;
}
xbus->proc_xbus_summary = create_proc_read_entry(PROC_XBUS_SUMMARY, 0444, xbus->proc_xbus_dir,
xbus_read_proc, xbus);
if (!xbus->proc_xbus_summary) {
- ERR("Failed to create '%s' proc file for xbus %s\n", PROC_XBUS_SUMMARY, xbus->busname);
+ XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_XBUS_SUMMARY);
err = -EIO;
goto nobus;
}
@@ -961,7 +912,7 @@ xbus_t *xbus_new(xbus_ops_t *ops)
xbus->proc_xbus_waitfor_xpds = create_proc_read_entry(PROC_XBUS_WAITFOR_XPDS, 0444, xbus->proc_xbus_dir,
xbus_read_waitfor_xpds, xbus);
if (!xbus->proc_xbus_waitfor_xpds) {
- ERR("Failed to create '%s' proc file for xbus %s\n", PROC_XBUS_WAITFOR_XPDS, xbus->busname);
+ XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_XBUS_WAITFOR_XPDS);
err = -EIO;
goto nobus;
}
@@ -969,7 +920,7 @@ xbus_t *xbus_new(xbus_ops_t *ops)
#ifdef PROTOCOL_DEBUG
xbus->proc_xbus_command = create_proc_entry(PROC_XBUS_COMMAND, 0200, xbus->proc_xbus_dir);
if (!xbus->proc_xbus_command) {
- ERR("Failed to create '%s' proc file for xbus %s\n", PROC_XBUS_COMMAND, xbus->busname);
+ XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_XBUS_COMMAND);
err = -EIO;
goto nobus;
}
@@ -981,22 +932,22 @@ xbus_t *xbus_new(xbus_ops_t *ops)
#ifdef XPP_DEBUGFS
xbus->debugfs_dir = debugfs_create_dir(xbus->busname, debugfs_root);
if(!xbus->debugfs_dir) {
- ERR("Failed to create debugfs directory for %s\n", xbus->busname);
+ XBUS_ERR(xbus, "Failed to create debugfs directory\n");
goto nobus;
}
xbus->debugfs_file = debugfs_create_file("dchannel", S_IFREG|S_IRUGO|S_IWUSR, xbus->debugfs_dir, xbus, &debugfs_operations);
if(!xbus->debugfs_file) {
- ERR("Failed to create dchannel file for %s\n", xbus->busname);
+ XBUS_ERR(xbus, "Failed to create dchannel file\n");
goto nobus;
}
#endif
/* Sanity checks */
if(!ops->xframe_send) {
- ERR("%s: missing mandatory handler: xframe_send\n", __FUNCTION__);
+ XBUS_ERR(xbus, "missing mandatory handler: xframe_send\n");
goto nobus;
}
if(!ops->xframe_new || !ops->xframe_free) {
- NOTICE("%s: Using default packet allocators\n", __FUNCTION__);
+ XBUS_NOTICE(xbus, "Using default packet allocators\n");
ops->xframe_new = xbus_xframe_new;
ops->xframe_free = xbus_xframe_free;
}
@@ -1018,21 +969,22 @@ void xbus_remove(xbus_t *xbus)
DBG("XBUS #%d was already removed. Skip.\n", xbus->num);
return;
}
- DBG("%s\n", xbus->busname);
+ XBUS_DBG(xbus, "\n");
/* Block until no one use */
down_write(&xbus->in_use);
- INFO("Removing xbus(%d) %s\n", xbus->num, xbus->busname);
+ XBUS_INFO(xbus, "Removing xbus\n");
+ xbus_sysfs_remove(xbus); /* Device-Model */
for(i = 0; i < MAX_XPDS; i++) {
xpd_t *xpd = xpd_of(xbus, i);
if(xpd) {
if(xpd->xbus_idx != i) {
- ERR("%s: BUG: xpd->xbus_idx=%d != i=%d\n", __FUNCTION__, xpd->xbus_idx, i);
+ XBUS_ERR(xbus, "BUG: xpd->xbus_idx=%d != i=%d\n", xpd->xbus_idx, i);
continue;
}
- DBG(" Removing xpd xbus_idx=%d\n", xpd->xbus_idx);
+ XBUS_DBG(xbus, " Removing xpd #%d\n", i);
xpd_remove(xpd);
}
xbus->xpds[i] = NULL;
@@ -1040,7 +992,7 @@ void xbus_remove(xbus_t *xbus)
ret = wait_event_interruptible(xbus->packet_cache_empty,
atomic_read(&xbus->packet_counter) == 0);
if(ret) {
- ERR("waiting for packet_cache_empty interrupted!!!\n");
+ XBUS_ERR(xbus, "waiting for packet_cache_empty interrupted!!!\n");
}
xbus_free(xbus);
}
@@ -1051,7 +1003,7 @@ void xbus_reset_counters(xbus_t *xbus)
{
int i;
- DBG("Reseting counters of %s\n", xbus->busname);
+ XBUS_DBG(xbus, "Reseting counters\n");
for(i = 0; i < XBUS_COUNTER_MAX; i++) {
xbus->counters[i] = 0;
}
@@ -1129,7 +1081,7 @@ static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count
if(!xbus)
goto out;
poller = xbus->poller;
- DBG("%s: Waiting for card initialization of %d XPD's max %d seconds\n", xbus->busname, MAX_XPDS, INITIALIZATION_TIMEOUT/HZ);
+ XBUS_DBG(xbus, "Waiting for card initialization of %d XPD's max %d seconds\n", MAX_XPDS, INITIALIZATION_TIMEOUT/HZ);
/*
* xbus_poll sets count_xpds_to_initialize only when polling is finished.
* To prevent race conditions we test both:
@@ -1141,13 +1093,13 @@ static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count
atomic_read(&poller->count_xpds_initialized) >= atomic_read(&poller->count_xpds_to_initialize),
INITIALIZATION_TIMEOUT);
if(ret == 0) {
- ERR("%s: Card Initialization Timeout\n", xbus->busname);
+ XBUS_ERR(xbus, "Card Initialization Timeout\n");
return ret;
} else if(ret < 0) {
- ERR("%s: Card Initialization Interrupted %d\n", xbus->busname, ret);
+ XBUS_ERR(xbus, "Card Initialization Interrupted %d\n", ret);
return ret;
}
- DBG("%s: Finished initialization of %d XPD's in %d seconds.\n", xbus->busname, MAX_XPDS, (INITIALIZATION_TIMEOUT - ret)/HZ);
+ XBUS_DBG(xbus, "Finished initialization of %d XPD's in %d seconds.\n", MAX_XPDS, (INITIALIZATION_TIMEOUT - ret)/HZ);
spin_lock_irqsave(&xbus->lock, flags);
len += sprintf(page + len, "XPDS_READY: %s: %d/%d\n",
xbus->busname,
@@ -1179,7 +1131,7 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer,
xframe_t *xframe;
if(count >= MAX_PROC_WRITE) {
- ERR("%s: line too long\n", __FUNCTION__);
+ XBUS_ERR(xbus, "%s: line too long\n", __FUNCTION__);
return -EFBIG;
}
if(copy_from_user(buf, buffer, count))
@@ -1210,7 +1162,7 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer,
return -EINVAL;
}
*q++ = val;
- // DBG("%s: %s: '%s' val=%d\n", __FUNCTION__, xbus->busname, hexdigit, val);
+ // XBUS_DBG(xbus, "'%s' val=%d\n", hexdigit, val);
}
xframe = xbus->ops->xframe_new(xbus, GFP_KERNEL);
if(!xframe)
@@ -1290,54 +1242,6 @@ static int read_proc_xmitter(char *page, char **start, off_t off, int count, int
#endif
/*------------------------- Initialization -------------------------*/
-
-static DEVICE_ATTR_FUNC(connector_show, dev, buf)
-{
- xbus_t *xbus;
- int ret;
-
- xbus = dev->driver_data;
- ret = snprintf(buf, PAGE_SIZE, "%s\n", xbus->busdesc);
- return ret;
-}
-
-static DEVICE_ATTR_FUNC(status_show, dev, buf)
-{
- xbus_t *xbus;
- int ret;
-
- xbus = dev->driver_data;
- ret = snprintf(buf, PAGE_SIZE, "%s\n", (xbus->hardware_exists)?"connected":"missing");
- return ret;
-}
-
-static int xbus_match(struct device *dev, struct device_driver *driver)
-{
- DBG("dev->bus_id = %s, driver->name = %s\n", dev->bus_id, driver->name);
- return strncmp(dev->bus_id, driver->name, strlen(driver->name)) == 0;
-}
-
-#if 0
-/* Hotplug replaced with uevent in 2.6.16 */
-static int xbus_hotplug(struct device *device, char **envp, int envnum, char *buff, int bufsize)
-{
- envp[0] = buff;
- if(snprintf(buff, bufsize, "XBUS_VERSION=%s", revision) >= bufsize)
- return -ENOMEM;
- envp[1] = NULL;
- return 0;
-}
-#endif
-
-struct bus_type xbus_bus_type = {
- .name = "xbus",
- .match = xbus_match,
-/* FIXME: Hotplug replaced with uevent in 2.6.16 */
-#if 0
- .hotplug = xbus_hotplug,
-#endif
-};
-
static void xbus_core_cleanup(void)
{
#ifdef XPP_DEBUGFS
@@ -1369,10 +1273,10 @@ int __init xbus_core_init(void)
int ret = 0;
#ifdef PROTOCOL_DEBUG
- INFO("FEATURE: %s with PROTOCOL_DEBUG\n", THIS_MODULE->name);
+ INFO("FEATURE: with PROTOCOL_DEBUG\n");
#endif
#ifdef XPP_DEBUGFS
- INFO("FEATURE: %s with XPP_DEBUGFS support\n", THIS_MODULE->name);
+ INFO("FEATURE: with XPP_DEBUGFS support\n");
#endif
xframes_cache = kmem_cache_create("xpp_frames",
sizeof(xframe_t) + XFRAME_DATASIZE,
@@ -1409,11 +1313,8 @@ int __init xbus_core_init(void)
goto err;
}
#endif
- ret = bus_register(&xbus_bus_type);
- if(ret) {
- ERR("%s: bus_register failed. Error number %d", __FUNCTION__, ret);
+ if((ret = register_xpp_bus()) < 0)
goto err;
- }
return 0;
err:
xbus_core_cleanup();
@@ -1431,7 +1332,7 @@ void __exit xbus_core_shutdown(void)
xbus_remove(xbus);
}
BUG_ON(bus_count);
- bus_unregister(&xbus_bus_type);
+ unregister_xpp_bus();
xbus_core_cleanup();
}