1 /* ds.c: Domain Services driver for Logical Domains
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
14 #include <linux/mutex.h>
15 #include <linux/kthread.h>
16 #include <linux/cpu.h>
20 #include <asm/power.h>
21 #include <asm/mdesc.h>
25 #define DRV_MODULE_NAME "ds"
26 #define PFX DRV_MODULE_NAME ": "
27 #define DRV_MODULE_VERSION "1.0"
28 #define DRV_MODULE_RELDATE "Jul 11, 2007"
30 static char version[] __devinitdata =
31 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
32 MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
33 MODULE_DESCRIPTION("Sun LDOM domain services driver");
34 MODULE_LICENSE("GPL");
35 MODULE_VERSION(DRV_MODULE_VERSION);
39 #define DS_INIT_REQ 0x00
40 #define DS_INIT_ACK 0x01
41 #define DS_INIT_NACK 0x02
42 #define DS_REG_REQ 0x03
43 #define DS_REG_ACK 0x04
44 #define DS_REG_NACK 0x05
45 #define DS_UNREG_REQ 0x06
46 #define DS_UNREG_ACK 0x07
47 #define DS_UNREG_NACK 0x08
56 #define DS_REG_VER_NACK 0x01
57 #define DS_REG_DUP 0x02
58 #define DS_INV_HDL 0x03
59 #define DS_TYPE_UNKNOWN 0x04
67 struct ds_msg_tag tag;
68 struct ds_version ver;
72 struct ds_msg_tag tag;
77 struct ds_msg_tag tag;
82 struct ds_msg_tag tag;
90 struct ds_msg_tag tag;
96 struct ds_msg_tag tag;
101 struct ds_unreg_req {
102 struct ds_msg_tag tag;
106 struct ds_unreg_ack {
107 struct ds_msg_tag tag;
111 struct ds_unreg_nack {
112 struct ds_msg_tag tag;
117 struct ds_msg_tag tag;
121 struct ds_data_nack {
122 struct ds_msg_tag tag;
127 struct ds_cap_state {
130 void (*data)(struct ldc_channel *lp,
131 struct ds_cap_state *cp,
134 const char *service_id;
137 #define CAP_STATE_UNKNOWN 0x00
138 #define CAP_STATE_REG_SENT 0x01
139 #define CAP_STATE_REGISTERED 0x02
142 static void md_update_data(struct ldc_channel *lp, struct ds_cap_state *cp,
144 static void domain_shutdown_data(struct ldc_channel *lp,
145 struct ds_cap_state *cp,
147 static void domain_panic_data(struct ldc_channel *lp,
148 struct ds_cap_state *cp,
150 #ifdef CONFIG_HOTPLUG_CPU
151 static void dr_cpu_data(struct ldc_channel *lp,
152 struct ds_cap_state *cp,
155 static void ds_pri_data(struct ldc_channel *lp,
156 struct ds_cap_state *cp,
158 static void ds_var_data(struct ldc_channel *lp,
159 struct ds_cap_state *cp,
162 struct ds_cap_state ds_states[] = {
164 .service_id = "md-update",
165 .data = md_update_data,
168 .service_id = "domain-shutdown",
169 .data = domain_shutdown_data,
172 .service_id = "domain-panic",
173 .data = domain_panic_data,
175 #ifdef CONFIG_HOTPLUG_CPU
177 .service_id = "dr-cpu",
186 .service_id = "var-config",
190 .service_id = "var-config-backup",
195 static DEFINE_SPINLOCK(ds_lock);
198 struct ldc_channel *lp;
200 #define DS_HS_START 0x01
201 #define DS_HS_DONE 0x02
207 static struct ds_info *ds_info;
209 static struct ds_cap_state *find_cap(u64 handle)
211 unsigned int index = handle >> 32;
213 if (index >= ARRAY_SIZE(ds_states))
215 return &ds_states[index];
218 static struct ds_cap_state *find_cap_by_string(const char *name)
222 for (i = 0; i < ARRAY_SIZE(ds_states); i++) {
223 if (strcmp(ds_states[i].service_id, name))
226 return &ds_states[i];
231 static int __ds_send(struct ldc_channel *lp, void *data, int len)
233 int err, limit = 1000;
236 while (limit-- > 0) {
237 err = ldc_write(lp, data, len);
238 if (!err || (err != -EAGAIN))
246 static int ds_send(struct ldc_channel *lp, void *data, int len)
251 spin_lock_irqsave(&ds_lock, flags);
252 err = __ds_send(lp, data, len);
253 spin_unlock_irqrestore(&ds_lock, flags);
258 struct ds_md_update_req {
262 struct ds_md_update_res {
267 static void md_update_data(struct ldc_channel *lp,
268 struct ds_cap_state *dp,
271 struct ds_data *dpkt = buf;
272 struct ds_md_update_req *rp;
275 struct ds_md_update_res res;
278 rp = (struct ds_md_update_req *) (dpkt + 1);
280 printk(KERN_INFO PFX "Machine description update.\n");
284 memset(&pkt, 0, sizeof(pkt));
285 pkt.data.tag.type = DS_DATA;
286 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
287 pkt.data.handle = dp->handle;
288 pkt.res.req_num = rp->req_num;
289 pkt.res.result = DS_OK;
291 ds_send(lp, &pkt, sizeof(pkt));
294 struct ds_shutdown_req {
299 struct ds_shutdown_res {
305 static void domain_shutdown_data(struct ldc_channel *lp,
306 struct ds_cap_state *dp,
309 struct ds_data *dpkt = buf;
310 struct ds_shutdown_req *rp;
313 struct ds_shutdown_res res;
316 rp = (struct ds_shutdown_req *) (dpkt + 1);
318 printk(KERN_ALERT PFX "Shutdown request from "
319 "LDOM manager received.\n");
321 memset(&pkt, 0, sizeof(pkt));
322 pkt.data.tag.type = DS_DATA;
323 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
324 pkt.data.handle = dp->handle;
325 pkt.res.req_num = rp->req_num;
326 pkt.res.result = DS_OK;
327 pkt.res.reason[0] = 0;
329 ds_send(lp, &pkt, sizeof(pkt));
334 struct ds_panic_req {
338 struct ds_panic_res {
344 static void domain_panic_data(struct ldc_channel *lp,
345 struct ds_cap_state *dp,
348 struct ds_data *dpkt = buf;
349 struct ds_panic_req *rp;
352 struct ds_panic_res res;
355 rp = (struct ds_panic_req *) (dpkt + 1);
357 printk(KERN_ALERT PFX "Panic request from "
358 "LDOM manager received.\n");
360 memset(&pkt, 0, sizeof(pkt));
361 pkt.data.tag.type = DS_DATA;
362 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
363 pkt.data.handle = dp->handle;
364 pkt.res.req_num = rp->req_num;
365 pkt.res.result = DS_OK;
366 pkt.res.reason[0] = 0;
368 ds_send(lp, &pkt, sizeof(pkt));
370 panic("PANIC requested by LDOM manager.");
373 #ifdef CONFIG_HOTPLUG_CPU
377 #define DR_CPU_CONFIGURE 0x43
378 #define DR_CPU_UNCONFIGURE 0x55
379 #define DR_CPU_FORCE_UNCONFIGURE 0x46
380 #define DR_CPU_STATUS 0x53
383 #define DR_CPU_OK 0x6f
384 #define DR_CPU_ERROR 0x65
389 struct dr_cpu_resp_entry {
392 #define DR_CPU_RES_OK 0x00
393 #define DR_CPU_RES_FAILURE 0x01
394 #define DR_CPU_RES_BLOCKED 0x02
395 #define DR_CPU_RES_CPU_NOT_RESPONDING 0x03
396 #define DR_CPU_RES_NOT_IN_MD 0x04
399 #define DR_CPU_STAT_NOT_PRESENT 0x00
400 #define DR_CPU_STAT_UNCONFIGURED 0x01
401 #define DR_CPU_STAT_CONFIGURED 0x02
406 static void __dr_cpu_send_error(struct ds_cap_state *cp, struct ds_data *data)
408 struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1);
409 struct ds_info *dp = ds_info;
412 struct dr_cpu_tag tag;
416 memset(&pkt, 0, sizeof(pkt));
417 pkt.data.tag.type = DS_DATA;
418 pkt.data.handle = cp->handle;
419 pkt.tag.req_num = tag->req_num;
420 pkt.tag.type = DR_CPU_ERROR;
421 pkt.tag.num_records = 0;
423 msg_len = (sizeof(struct ds_data) +
424 sizeof(struct dr_cpu_tag));
426 pkt.data.tag.len = msg_len - sizeof(struct ds_msg_tag);
428 __ds_send(dp->lp, &pkt, msg_len);
431 static void dr_cpu_send_error(struct ds_cap_state *cp, struct ds_data *data)
435 spin_lock_irqsave(&ds_lock, flags);
436 __dr_cpu_send_error(cp, data);
437 spin_unlock_irqrestore(&ds_lock, flags);
440 #define CPU_SENTINEL 0xffffffff
442 static void purge_dups(u32 *list, u32 num_ents)
446 for (i = 0; i < num_ents; i++) {
450 if (cpu == CPU_SENTINEL)
453 for (j = i + 1; j < num_ents; j++) {
455 list[j] = CPU_SENTINEL;
460 static int dr_cpu_size_response(int ncpus)
462 return (sizeof(struct ds_data) +
463 sizeof(struct dr_cpu_tag) +
464 (sizeof(struct dr_cpu_resp_entry) * ncpus));
467 static void dr_cpu_init_response(struct ds_data *resp, u64 req_num,
468 u64 handle, int resp_len, int ncpus,
469 cpumask_t *mask, u32 default_stat)
471 struct dr_cpu_resp_entry *ent;
472 struct dr_cpu_tag *tag;
475 tag = (struct dr_cpu_tag *) (resp + 1);
476 ent = (struct dr_cpu_resp_entry *) (tag + 1);
478 resp->tag.type = DS_DATA;
479 resp->tag.len = resp_len - sizeof(struct ds_msg_tag);
480 resp->handle = handle;
481 tag->req_num = req_num;
482 tag->type = DR_CPU_OK;
483 tag->num_records = ncpus;
486 for_each_cpu_mask(cpu, *mask) {
488 ent[i].result = DR_CPU_RES_OK;
489 ent[i].stat = default_stat;
495 static void dr_cpu_mark(struct ds_data *resp, int cpu, int ncpus,
498 struct dr_cpu_resp_entry *ent;
499 struct dr_cpu_tag *tag;
502 tag = (struct dr_cpu_tag *) (resp + 1);
503 ent = (struct dr_cpu_resp_entry *) (tag + 1);
505 for (i = 0; i < ncpus; i++) {
506 if (ent[i].cpu != cpu)
514 static int dr_cpu_configure(struct ds_cap_state *cp, u64 req_num,
517 struct ds_data *resp;
518 int resp_len, ncpus, cpu;
521 ncpus = cpus_weight(*mask);
522 resp_len = dr_cpu_size_response(ncpus);
523 resp = kzalloc(resp_len, GFP_KERNEL);
527 dr_cpu_init_response(resp, req_num, cp->handle,
528 resp_len, ncpus, mask,
529 DR_CPU_STAT_CONFIGURED);
531 mdesc_fill_in_cpu_data(*mask);
533 for_each_cpu_mask(cpu, *mask) {
536 printk(KERN_INFO PFX "Starting cpu %d...\n", cpu);
539 __u32 res = DR_CPU_RES_FAILURE;
540 __u32 stat = DR_CPU_STAT_UNCONFIGURED;
542 if (!cpu_present(cpu)) {
543 /* CPU not present in MD */
544 res = DR_CPU_RES_NOT_IN_MD;
545 stat = DR_CPU_STAT_NOT_PRESENT;
546 } else if (err == -ENODEV) {
547 /* CPU did not call in successfully */
548 res = DR_CPU_RES_CPU_NOT_RESPONDING;
551 printk(KERN_INFO PFX "CPU startup failed err=%d\n",
553 dr_cpu_mark(resp, cpu, ncpus, res, stat);
557 spin_lock_irqsave(&ds_lock, flags);
558 __ds_send(ds_info->lp, resp, resp_len);
559 spin_unlock_irqrestore(&ds_lock, flags);
563 /* Redistribute IRQs, taking into account the new cpus. */
569 static int dr_cpu_unconfigure(struct ds_cap_state *cp, u64 req_num,
572 struct ds_data *resp;
573 int resp_len, ncpus, cpu;
576 ncpus = cpus_weight(*mask);
577 resp_len = dr_cpu_size_response(ncpus);
578 resp = kzalloc(resp_len, GFP_KERNEL);
582 dr_cpu_init_response(resp, req_num, cp->handle,
583 resp_len, ncpus, mask,
584 DR_CPU_STAT_UNCONFIGURED);
586 for_each_cpu_mask(cpu, *mask) {
589 printk(KERN_INFO PFX "CPU[%d]: Shutting down cpu %d...\n",
590 smp_processor_id(), cpu);
593 dr_cpu_mark(resp, cpu, ncpus,
595 DR_CPU_STAT_CONFIGURED);
598 spin_lock_irqsave(&ds_lock, flags);
599 __ds_send(ds_info->lp, resp, resp_len);
600 spin_unlock_irqrestore(&ds_lock, flags);
607 static void dr_cpu_data(struct ldc_channel *lp,
608 struct ds_cap_state *cp,
611 struct ds_data *data = buf;
612 struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1);
613 u32 *cpu_list = (u32 *) (tag + 1);
614 u64 req_num = tag->req_num;
620 case DR_CPU_CONFIGURE:
621 case DR_CPU_UNCONFIGURE:
622 case DR_CPU_FORCE_UNCONFIGURE:
626 dr_cpu_send_error(cp, data);
630 purge_dups(cpu_list, tag->num_records);
633 for (i = 0; i < tag->num_records; i++) {
634 if (cpu_list[i] == CPU_SENTINEL)
637 if (cpu_list[i] < NR_CPUS)
638 cpu_set(cpu_list[i], mask);
641 if (tag->type == DR_CPU_CONFIGURE)
642 err = dr_cpu_configure(cp, req_num, &mask);
644 err = dr_cpu_unconfigure(cp, req_num, &mask);
647 dr_cpu_send_error(cp, data);
649 #endif /* CONFIG_HOTPLUG_CPU */
654 #define DS_PRI_REQUEST 0x00
655 #define DS_PRI_DATA 0x01
656 #define DS_PRI_UPDATE 0x02
659 static void ds_pri_data(struct ldc_channel *lp,
660 struct ds_cap_state *dp,
663 struct ds_data *dpkt = buf;
664 struct ds_pri_msg *rp;
666 rp = (struct ds_pri_msg *) (dpkt + 1);
668 printk(KERN_INFO PFX "PRI REQ [%lx:%lx], len=%d\n",
669 rp->req_num, rp->type, len);
674 #define DS_VAR_SET_REQ 0x00
675 #define DS_VAR_DELETE_REQ 0x01
676 #define DS_VAR_SET_RESP 0x02
677 #define DS_VAR_DELETE_RESP 0x03
680 struct ds_var_set_msg {
681 struct ds_var_hdr hdr;
682 char name_and_value[0];
685 struct ds_var_delete_msg {
686 struct ds_var_hdr hdr;
691 struct ds_var_hdr hdr;
693 #define DS_VAR_SUCCESS 0x00
694 #define DS_VAR_NO_SPACE 0x01
695 #define DS_VAR_INVALID_VAR 0x02
696 #define DS_VAR_INVALID_VAL 0x03
697 #define DS_VAR_NOT_PRESENT 0x04
700 static DEFINE_MUTEX(ds_var_mutex);
701 static int ds_var_doorbell;
702 static int ds_var_response;
704 static void ds_var_data(struct ldc_channel *lp,
705 struct ds_cap_state *dp,
708 struct ds_data *dpkt = buf;
709 struct ds_var_resp *rp;
711 rp = (struct ds_var_resp *) (dpkt + 1);
713 if (rp->hdr.type != DS_VAR_SET_RESP &&
714 rp->hdr.type != DS_VAR_DELETE_RESP)
717 ds_var_response = rp->result;
722 void ldom_set_var(const char *var, const char *value)
724 struct ds_info *dp = ds_info;
725 struct ds_cap_state *cp;
727 cp = find_cap_by_string("var-config");
728 if (cp->state != CAP_STATE_REGISTERED)
729 cp = find_cap_by_string("var-config-backup");
731 if (cp->state == CAP_STATE_REGISTERED) {
735 struct ds_var_set_msg msg;
743 memset(&pkt, 0, sizeof(pkt));
744 pkt.header.data.tag.type = DS_DATA;
745 pkt.header.data.handle = cp->handle;
746 pkt.header.msg.hdr.type = DS_VAR_SET_REQ;
747 base = p = &pkt.header.msg.name_and_value[0];
749 p += strlen(var) + 1;
751 p += strlen(value) + 1;
753 msg_len = (sizeof(struct ds_data) +
754 sizeof(struct ds_var_set_msg) +
756 msg_len = (msg_len + 3) & ~3;
757 pkt.header.data.tag.len = msg_len - sizeof(struct ds_msg_tag);
759 mutex_lock(&ds_var_mutex);
761 spin_lock_irqsave(&ds_lock, flags);
763 ds_var_response = -1;
765 __ds_send(dp->lp, &pkt, msg_len);
766 spin_unlock_irqrestore(&ds_lock, flags);
769 while (ds_var_doorbell == 0) {
776 mutex_unlock(&ds_var_mutex);
778 if (ds_var_doorbell == 0 ||
779 ds_var_response != DS_VAR_SUCCESS)
780 printk(KERN_ERR PFX "var-config [%s:%s] "
781 "failed, response(%d).\n",
785 printk(KERN_ERR PFX "var-config not registered so "
786 "could not set (%s) variable to (%s).\n",
791 void ldom_reboot(const char *boot_command)
793 /* Don't bother with any of this if the boot_command
796 if (boot_command && strlen(boot_command)) {
797 char full_boot_str[256];
799 strcpy(full_boot_str, "boot ");
800 strcpy(full_boot_str + strlen("boot "), boot_command);
802 ldom_set_var("reboot-command", full_boot_str);
807 void ldom_power_off(void)
812 static void ds_conn_reset(struct ds_info *dp)
814 printk(KERN_ERR PFX "ds_conn_reset() from %p\n",
815 __builtin_return_address(0));
818 static int register_services(struct ds_info *dp)
820 struct ldc_channel *lp = dp->lp;
823 for (i = 0; i < ARRAY_SIZE(ds_states); i++) {
825 struct ds_reg_req req;
828 struct ds_cap_state *cp = &ds_states[i];
832 if (cp->state == CAP_STATE_REGISTERED)
835 new_count = sched_clock() & 0xffffffff;
836 cp->handle = ((u64) i << 32) | new_count;
838 msg_len = (sizeof(struct ds_reg_req) +
839 strlen(cp->service_id));
841 memset(&pbuf, 0, sizeof(pbuf));
842 pbuf.req.tag.type = DS_REG_REQ;
843 pbuf.req.tag.len = (msg_len - sizeof(struct ds_msg_tag));
844 pbuf.req.handle = cp->handle;
847 strcpy(pbuf.req.svc_id, cp->service_id);
849 err = __ds_send(lp, &pbuf, msg_len);
851 cp->state = CAP_STATE_REG_SENT;
856 static int ds_handshake(struct ds_info *dp, struct ds_msg_tag *pkt)
859 if (dp->hs_state == DS_HS_START) {
860 if (pkt->type != DS_INIT_ACK)
863 dp->hs_state = DS_HS_DONE;
865 return register_services(dp);
868 if (dp->hs_state != DS_HS_DONE)
871 if (pkt->type == DS_REG_ACK) {
872 struct ds_reg_ack *ap = (struct ds_reg_ack *) pkt;
873 struct ds_cap_state *cp = find_cap(ap->handle);
876 printk(KERN_ERR PFX "REG ACK for unknown handle %lx\n",
880 printk(KERN_INFO PFX "Registered %s service.\n",
882 cp->state = CAP_STATE_REGISTERED;
883 } else if (pkt->type == DS_REG_NACK) {
884 struct ds_reg_nack *np = (struct ds_reg_nack *) pkt;
885 struct ds_cap_state *cp = find_cap(np->handle);
888 printk(KERN_ERR PFX "REG NACK for "
889 "unknown handle %lx\n",
893 printk(KERN_INFO PFX "Could not register %s service\n",
895 cp->state = CAP_STATE_UNKNOWN;
905 static void __send_ds_nack(struct ds_info *dp, u64 handle)
907 struct ds_data_nack nack = {
910 .len = (sizeof(struct ds_data_nack) -
911 sizeof(struct ds_msg_tag)),
914 .result = DS_INV_HDL,
917 __ds_send(dp->lp, &nack, sizeof(nack));
920 static LIST_HEAD(ds_work_list);
921 static DECLARE_WAIT_QUEUE_HEAD(ds_wait);
923 struct ds_queue_entry {
924 struct list_head list;
930 static void process_ds_work(void)
932 struct ds_queue_entry *qp, *tmp;
933 static struct ds_info *dp;
937 spin_lock_irqsave(&ds_lock, flags);
938 list_splice(&ds_work_list, &todo);
939 INIT_LIST_HEAD(&ds_work_list);
940 spin_unlock_irqrestore(&ds_lock, flags);
944 list_for_each_entry_safe(qp, tmp, &todo, list) {
945 struct ds_data *dpkt = (struct ds_data *) qp->req;
946 struct ds_cap_state *cp = find_cap(dpkt->handle);
947 int req_len = qp->req_len;
950 printk(KERN_ERR PFX "Data for unknown handle %lu\n",
953 spin_lock_irqsave(&ds_lock, flags);
954 __send_ds_nack(dp, dpkt->handle);
955 spin_unlock_irqrestore(&ds_lock, flags);
957 cp->data(dp->lp, cp, dpkt, req_len);
965 static int ds_thread(void *__unused)
970 prepare_to_wait(&ds_wait, &wait, TASK_INTERRUPTIBLE);
971 if (list_empty(&ds_work_list))
973 finish_wait(&ds_wait, &wait);
975 if (kthread_should_stop())
984 static int ds_data(struct ds_info *dp, struct ds_msg_tag *pkt, int len)
986 struct ds_data *dpkt = (struct ds_data *) pkt;
987 struct ds_queue_entry *qp;
989 qp = kmalloc(sizeof(struct ds_queue_entry) + len, GFP_ATOMIC);
991 __send_ds_nack(dp, dpkt->handle);
993 memcpy(&qp->req, pkt, len);
994 list_add_tail(&qp->list, &ds_work_list);
1000 static void ds_up(struct ds_info *dp)
1002 struct ldc_channel *lp = dp->lp;
1003 struct ds_ver_req req;
1006 req.tag.type = DS_INIT_REQ;
1007 req.tag.len = sizeof(req) - sizeof(struct ds_msg_tag);
1011 err = __ds_send(lp, &req, sizeof(req));
1013 dp->hs_state = DS_HS_START;
1016 static void ds_reset(struct ds_info *dp)
1022 for (i = 0; i < ARRAY_SIZE(ds_states); i++) {
1023 struct ds_cap_state *cp = &ds_states[i];
1025 cp->state = CAP_STATE_UNKNOWN;
1029 static void ds_event(void *arg, int event)
1031 struct ds_info *dp = arg;
1032 struct ldc_channel *lp = dp->lp;
1033 unsigned long flags;
1036 spin_lock_irqsave(&ds_lock, flags);
1038 if (event == LDC_EVENT_UP) {
1040 spin_unlock_irqrestore(&ds_lock, flags);
1044 if (event == LDC_EVENT_RESET) {
1046 spin_unlock_irqrestore(&ds_lock, flags);
1050 if (event != LDC_EVENT_DATA_READY) {
1051 printk(KERN_WARNING PFX "Unexpected LDC event %d\n", event);
1052 spin_unlock_irqrestore(&ds_lock, flags);
1058 struct ds_msg_tag *tag;
1060 err = ldc_read(lp, dp->rcv_buf, sizeof(*tag));
1062 if (unlikely(err < 0)) {
1063 if (err == -ECONNRESET)
1071 err = ldc_read(lp, tag + 1, tag->len);
1073 if (unlikely(err < 0)) {
1074 if (err == -ECONNRESET)
1081 if (tag->type < DS_DATA)
1082 err = ds_handshake(dp, dp->rcv_buf);
1084 err = ds_data(dp, dp->rcv_buf,
1085 sizeof(*tag) + err);
1086 if (err == -ECONNRESET)
1090 spin_unlock_irqrestore(&ds_lock, flags);
1093 static int __devinit ds_probe(struct vio_dev *vdev,
1094 const struct vio_device_id *id)
1096 static int ds_version_printed;
1097 struct ldc_channel_config ds_cfg = {
1100 .mode = LDC_MODE_STREAM,
1102 struct ldc_channel *lp;
1106 if (ds_version_printed++ == 0)
1107 printk(KERN_INFO "%s", version);
1109 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
1114 dp->rcv_buf = kzalloc(4096, GFP_KERNEL);
1118 dp->rcv_buf_len = 4096;
1120 ds_cfg.tx_irq = vdev->tx_irq;
1121 ds_cfg.rx_irq = vdev->rx_irq;
1123 lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp);
1126 goto out_free_rcv_buf;
1130 err = ldc_bind(lp, "DS");
1153 static int ds_remove(struct vio_dev *vdev)
1158 static struct vio_device_id ds_match[] = {
1160 .type = "domain-services-port",
1165 static struct vio_driver ds_driver = {
1166 .id_table = ds_match,
1168 .remove = ds_remove,
1171 .owner = THIS_MODULE,
1175 static int __init ds_init(void)
1179 for (i = 0; i < ARRAY_SIZE(ds_states); i++)
1180 ds_states[i].handle = ((u64)i << 32);
1182 kthread_run(ds_thread, NULL, "kldomd");
1184 return vio_register_driver(&ds_driver);
1187 subsys_initcall(ds_init);