aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorDavid S. Miller <davem@sunset.davemloft.net>2007-07-20 02:25:35 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-07-20 20:14:23 -0400
commit5fc986100cb253897b4e16992e805343d30a819e (patch)
treeb09d5320eb67031d005d16d0cb988c74b033ed48 /arch
parent58fb666643acee28d347de0b59bb938844c22f83 (diff)
[SPARC64]: Handle multiple domain-services-port nodes properly.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch')
-rw-r--r--arch/sparc64/kernel/ds.c251
1 files changed, 157 insertions, 94 deletions
diff --git a/arch/sparc64/kernel/ds.c b/arch/sparc64/kernel/ds.c
index 1a2062ecb0bc..8c5692e9f917 100644
--- a/arch/sparc64/kernel/ds.c
+++ b/arch/sparc64/kernel/ds.c
@@ -124,10 +124,11 @@ struct ds_data_nack {
124 __u64 result; 124 __u64 result;
125}; 125};
126 126
127struct ds_info;
127struct ds_cap_state { 128struct ds_cap_state {
128 __u64 handle; 129 __u64 handle;
129 130
130 void (*data)(struct ldc_channel *lp, 131 void (*data)(struct ds_info *dp,
131 struct ds_cap_state *cp, 132 struct ds_cap_state *cp,
132 void *buf, int len); 133 void *buf, int len);
133 134
@@ -139,27 +140,27 @@ struct ds_cap_state {
139#define CAP_STATE_REGISTERED 0x02 140#define CAP_STATE_REGISTERED 0x02
140}; 141};
141 142
142static void md_update_data(struct ldc_channel *lp, struct ds_cap_state *cp, 143static void md_update_data(struct ds_info *dp, struct ds_cap_state *cp,
143 void *buf, int len); 144 void *buf, int len);
144static void domain_shutdown_data(struct ldc_channel *lp, 145static void domain_shutdown_data(struct ds_info *dp,
145 struct ds_cap_state *cp, 146 struct ds_cap_state *cp,
146 void *buf, int len); 147 void *buf, int len);
147static void domain_panic_data(struct ldc_channel *lp, 148static void domain_panic_data(struct ds_info *dp,
148 struct ds_cap_state *cp, 149 struct ds_cap_state *cp,
149 void *buf, int len); 150 void *buf, int len);
150#ifdef CONFIG_HOTPLUG_CPU 151#ifdef CONFIG_HOTPLUG_CPU
151static void dr_cpu_data(struct ldc_channel *lp, 152static void dr_cpu_data(struct ds_info *dp,
152 struct ds_cap_state *cp, 153 struct ds_cap_state *cp,
153 void *buf, int len); 154 void *buf, int len);
154#endif 155#endif
155static void ds_pri_data(struct ldc_channel *lp, 156static void ds_pri_data(struct ds_info *dp,
156 struct ds_cap_state *cp, 157 struct ds_cap_state *cp,
157 void *buf, int len); 158 void *buf, int len);
158static void ds_var_data(struct ldc_channel *lp, 159static void ds_var_data(struct ds_info *dp,
159 struct ds_cap_state *cp, 160 struct ds_cap_state *cp,
160 void *buf, int len); 161 void *buf, int len);
161 162
162struct ds_cap_state ds_states[] = { 163struct ds_cap_state ds_states_template[] = {
163 { 164 {
164 .service_id = "md-update", 165 .service_id = "md-update",
165 .data = md_update_data, 166 .data = md_update_data,
@@ -200,30 +201,38 @@ struct ds_info {
200#define DS_HS_START 0x01 201#define DS_HS_START 0x01
201#define DS_HS_DONE 0x02 202#define DS_HS_DONE 0x02
202 203
204 u64 id;
205
203 void *rcv_buf; 206 void *rcv_buf;
204 int rcv_buf_len; 207 int rcv_buf_len;
208
209 struct ds_cap_state *ds_states;
210 int num_ds_states;
211
212 struct ds_info *next;
205}; 213};
206 214
207static struct ds_info *ds_info; 215static struct ds_info *ds_info_list;
208 216
209static struct ds_cap_state *find_cap(u64 handle) 217static struct ds_cap_state *find_cap(struct ds_info *dp, u64 handle)
210{ 218{
211 unsigned int index = handle >> 32; 219 unsigned int index = handle >> 32;
212 220
213 if (index >= ARRAY_SIZE(ds_states)) 221 if (index >= dp->num_ds_states)
214 return NULL; 222 return NULL;
215 return &ds_states[index]; 223 return &dp->ds_states[index];
216} 224}
217 225
218static struct ds_cap_state *find_cap_by_string(const char *name) 226static struct ds_cap_state *find_cap_by_string(struct ds_info *dp,
227 const char *name)
219{ 228{
220 int i; 229 int i;
221 230
222 for (i = 0; i < ARRAY_SIZE(ds_states); i++) { 231 for (i = 0; i < dp->num_ds_states; i++) {
223 if (strcmp(ds_states[i].service_id, name)) 232 if (strcmp(dp->ds_states[i].service_id, name))
224 continue; 233 continue;
225 234
226 return &ds_states[i]; 235 return &dp->ds_states[i];
227 } 236 }
228 return NULL; 237 return NULL;
229} 238}
@@ -264,10 +273,11 @@ struct ds_md_update_res {
264 __u32 result; 273 __u32 result;
265}; 274};
266 275
267static void md_update_data(struct ldc_channel *lp, 276static void md_update_data(struct ds_info *dp,
268 struct ds_cap_state *dp, 277 struct ds_cap_state *cp,
269 void *buf, int len) 278 void *buf, int len)
270{ 279{
280 struct ldc_channel *lp = dp->lp;
271 struct ds_data *dpkt = buf; 281 struct ds_data *dpkt = buf;
272 struct ds_md_update_req *rp; 282 struct ds_md_update_req *rp;
273 struct { 283 struct {
@@ -277,14 +287,14 @@ static void md_update_data(struct ldc_channel *lp,
277 287
278 rp = (struct ds_md_update_req *) (dpkt + 1); 288 rp = (struct ds_md_update_req *) (dpkt + 1);
279 289
280 printk(KERN_INFO PFX "Machine description update.\n"); 290 printk(KERN_INFO "ds-%lu: Machine description update.\n", dp->id);
281 291
282 mdesc_update(); 292 mdesc_update();
283 293
284 memset(&pkt, 0, sizeof(pkt)); 294 memset(&pkt, 0, sizeof(pkt));
285 pkt.data.tag.type = DS_DATA; 295 pkt.data.tag.type = DS_DATA;
286 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); 296 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
287 pkt.data.handle = dp->handle; 297 pkt.data.handle = cp->handle;
288 pkt.res.req_num = rp->req_num; 298 pkt.res.req_num = rp->req_num;
289 pkt.res.result = DS_OK; 299 pkt.res.result = DS_OK;
290 300
@@ -302,10 +312,11 @@ struct ds_shutdown_res {
302 char reason[1]; 312 char reason[1];
303}; 313};
304 314
305static void domain_shutdown_data(struct ldc_channel *lp, 315static void domain_shutdown_data(struct ds_info *dp,
306 struct ds_cap_state *dp, 316 struct ds_cap_state *cp,
307 void *buf, int len) 317 void *buf, int len)
308{ 318{
319 struct ldc_channel *lp = dp->lp;
309 struct ds_data *dpkt = buf; 320 struct ds_data *dpkt = buf;
310 struct ds_shutdown_req *rp; 321 struct ds_shutdown_req *rp;
311 struct { 322 struct {
@@ -315,13 +326,13 @@ static void domain_shutdown_data(struct ldc_channel *lp,
315 326
316 rp = (struct ds_shutdown_req *) (dpkt + 1); 327 rp = (struct ds_shutdown_req *) (dpkt + 1);
317 328
318 printk(KERN_ALERT PFX "Shutdown request from " 329 printk(KERN_ALERT "ds-%lu: Shutdown request from "
319 "LDOM manager received.\n"); 330 "LDOM manager received.\n", dp->id);
320 331
321 memset(&pkt, 0, sizeof(pkt)); 332 memset(&pkt, 0, sizeof(pkt));
322 pkt.data.tag.type = DS_DATA; 333 pkt.data.tag.type = DS_DATA;
323 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); 334 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
324 pkt.data.handle = dp->handle; 335 pkt.data.handle = cp->handle;
325 pkt.res.req_num = rp->req_num; 336 pkt.res.req_num = rp->req_num;
326 pkt.res.result = DS_OK; 337 pkt.res.result = DS_OK;
327 pkt.res.reason[0] = 0; 338 pkt.res.reason[0] = 0;
@@ -341,10 +352,11 @@ struct ds_panic_res {
341 char reason[1]; 352 char reason[1];
342}; 353};
343 354
344static void domain_panic_data(struct ldc_channel *lp, 355static void domain_panic_data(struct ds_info *dp,
345 struct ds_cap_state *dp, 356 struct ds_cap_state *cp,
346 void *buf, int len) 357 void *buf, int len)
347{ 358{
359 struct ldc_channel *lp = dp->lp;
348 struct ds_data *dpkt = buf; 360 struct ds_data *dpkt = buf;
349 struct ds_panic_req *rp; 361 struct ds_panic_req *rp;
350 struct { 362 struct {
@@ -354,13 +366,13 @@ static void domain_panic_data(struct ldc_channel *lp,
354 366
355 rp = (struct ds_panic_req *) (dpkt + 1); 367 rp = (struct ds_panic_req *) (dpkt + 1);
356 368
357 printk(KERN_ALERT PFX "Panic request from " 369 printk(KERN_ALERT "ds-%lu: Panic request from "
358 "LDOM manager received.\n"); 370 "LDOM manager received.\n", dp->id);
359 371
360 memset(&pkt, 0, sizeof(pkt)); 372 memset(&pkt, 0, sizeof(pkt));
361 pkt.data.tag.type = DS_DATA; 373 pkt.data.tag.type = DS_DATA;
362 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag); 374 pkt.data.tag.len = sizeof(pkt) - sizeof(struct ds_msg_tag);
363 pkt.data.handle = dp->handle; 375 pkt.data.handle = cp->handle;
364 pkt.res.req_num = rp->req_num; 376 pkt.res.req_num = rp->req_num;
365 pkt.res.result = DS_OK; 377 pkt.res.result = DS_OK;
366 pkt.res.reason[0] = 0; 378 pkt.res.reason[0] = 0;
@@ -403,10 +415,11 @@ struct dr_cpu_resp_entry {
403 __u32 str_off; 415 __u32 str_off;
404}; 416};
405 417
406static void __dr_cpu_send_error(struct ds_cap_state *cp, struct ds_data *data) 418static void __dr_cpu_send_error(struct ds_info *dp,
419 struct ds_cap_state *cp,
420 struct ds_data *data)
407{ 421{
408 struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1); 422 struct dr_cpu_tag *tag = (struct dr_cpu_tag *) (data + 1);
409 struct ds_info *dp = ds_info;
410 struct { 423 struct {
411 struct ds_data data; 424 struct ds_data data;
412 struct dr_cpu_tag tag; 425 struct dr_cpu_tag tag;
@@ -428,12 +441,14 @@ static void __dr_cpu_send_error(struct ds_cap_state *cp, struct ds_data *data)
428 __ds_send(dp->lp, &pkt, msg_len); 441 __ds_send(dp->lp, &pkt, msg_len);
429} 442}
430 443
431static void dr_cpu_send_error(struct ds_cap_state *cp, struct ds_data *data) 444static void dr_cpu_send_error(struct ds_info *dp,
445 struct ds_cap_state *cp,
446 struct ds_data *data)
432{ 447{
433 unsigned long flags; 448 unsigned long flags;
434 449
435 spin_lock_irqsave(&ds_lock, flags); 450 spin_lock_irqsave(&ds_lock, flags);
436 __dr_cpu_send_error(cp, data); 451 __dr_cpu_send_error(dp, cp, data);
437 spin_unlock_irqrestore(&ds_lock, flags); 452 spin_unlock_irqrestore(&ds_lock, flags);
438} 453}
439 454
@@ -511,7 +526,9 @@ static void dr_cpu_mark(struct ds_data *resp, int cpu, int ncpus,
511 } 526 }
512} 527}
513 528
514static int dr_cpu_configure(struct ds_cap_state *cp, u64 req_num, 529static int dr_cpu_configure(struct ds_info *dp,
530 struct ds_cap_state *cp,
531 u64 req_num,
515 cpumask_t *mask) 532 cpumask_t *mask)
516{ 533{
517 struct ds_data *resp; 534 struct ds_data *resp;
@@ -533,7 +550,8 @@ static int dr_cpu_configure(struct ds_cap_state *cp, u64 req_num,
533 for_each_cpu_mask(cpu, *mask) { 550 for_each_cpu_mask(cpu, *mask) {
534 int err; 551 int err;
535 552
536 printk(KERN_INFO PFX "Starting cpu %d...\n", cpu); 553 printk(KERN_INFO "ds-%lu: Starting cpu %d...\n",
554 dp->id, cpu);
537 err = cpu_up(cpu); 555 err = cpu_up(cpu);
538 if (err) { 556 if (err) {
539 __u32 res = DR_CPU_RES_FAILURE; 557 __u32 res = DR_CPU_RES_FAILURE;
@@ -548,14 +566,14 @@ static int dr_cpu_configure(struct ds_cap_state *cp, u64 req_num,
548 res = DR_CPU_RES_CPU_NOT_RESPONDING; 566 res = DR_CPU_RES_CPU_NOT_RESPONDING;
549 } 567 }
550 568
551 printk(KERN_INFO PFX "CPU startup failed err=%d\n", 569 printk(KERN_INFO "ds-%lu: CPU startup failed err=%d\n",
552 err); 570 dp->id, err);
553 dr_cpu_mark(resp, cpu, ncpus, res, stat); 571 dr_cpu_mark(resp, cpu, ncpus, res, stat);
554 } 572 }
555 } 573 }
556 574
557 spin_lock_irqsave(&ds_lock, flags); 575 spin_lock_irqsave(&ds_lock, flags);
558 __ds_send(ds_info->lp, resp, resp_len); 576 __ds_send(dp->lp, resp, resp_len);
559 spin_unlock_irqrestore(&ds_lock, flags); 577 spin_unlock_irqrestore(&ds_lock, flags);
560 578
561 kfree(resp); 579 kfree(resp);
@@ -566,7 +584,9 @@ static int dr_cpu_configure(struct ds_cap_state *cp, u64 req_num,
566 return 0; 584 return 0;
567} 585}
568 586
569static int dr_cpu_unconfigure(struct ds_cap_state *cp, u64 req_num, 587static int dr_cpu_unconfigure(struct ds_info *dp,
588 struct ds_cap_state *cp,
589 u64 req_num,
570 cpumask_t *mask) 590 cpumask_t *mask)
571{ 591{
572 struct ds_data *resp; 592 struct ds_data *resp;
@@ -586,8 +606,8 @@ static int dr_cpu_unconfigure(struct ds_cap_state *cp, u64 req_num,
586 for_each_cpu_mask(cpu, *mask) { 606 for_each_cpu_mask(cpu, *mask) {
587 int err; 607 int err;
588 608
589 printk(KERN_INFO PFX "CPU[%d]: Shutting down cpu %d...\n", 609 printk(KERN_INFO "ds-%lu: Shutting down cpu %d...\n",
590 smp_processor_id(), cpu); 610 dp->id, cpu);
591 err = cpu_down(cpu); 611 err = cpu_down(cpu);
592 if (err) 612 if (err)
593 dr_cpu_mark(resp, cpu, ncpus, 613 dr_cpu_mark(resp, cpu, ncpus,
@@ -596,7 +616,7 @@ static int dr_cpu_unconfigure(struct ds_cap_state *cp, u64 req_num,
596 } 616 }
597 617
598 spin_lock_irqsave(&ds_lock, flags); 618 spin_lock_irqsave(&ds_lock, flags);
599 __ds_send(ds_info->lp, resp, resp_len); 619 __ds_send(dp->lp, resp, resp_len);
600 spin_unlock_irqrestore(&ds_lock, flags); 620 spin_unlock_irqrestore(&ds_lock, flags);
601 621
602 kfree(resp); 622 kfree(resp);
@@ -604,7 +624,7 @@ static int dr_cpu_unconfigure(struct ds_cap_state *cp, u64 req_num,
604 return 0; 624 return 0;
605} 625}
606 626
607static void dr_cpu_data(struct ldc_channel *lp, 627static void dr_cpu_data(struct ds_info *dp,
608 struct ds_cap_state *cp, 628 struct ds_cap_state *cp,
609 void *buf, int len) 629 void *buf, int len)
610{ 630{
@@ -623,7 +643,7 @@ static void dr_cpu_data(struct ldc_channel *lp,
623 break; 643 break;
624 644
625 default: 645 default:
626 dr_cpu_send_error(cp, data); 646 dr_cpu_send_error(dp, cp, data);
627 return; 647 return;
628 } 648 }
629 649
@@ -639,12 +659,12 @@ static void dr_cpu_data(struct ldc_channel *lp,
639 } 659 }
640 660
641 if (tag->type == DR_CPU_CONFIGURE) 661 if (tag->type == DR_CPU_CONFIGURE)
642 err = dr_cpu_configure(cp, req_num, &mask); 662 err = dr_cpu_configure(dp, cp, req_num, &mask);
643 else 663 else
644 err = dr_cpu_unconfigure(cp, req_num, &mask); 664 err = dr_cpu_unconfigure(dp, cp, req_num, &mask);
645 665
646 if (err) 666 if (err)
647 dr_cpu_send_error(cp, data); 667 dr_cpu_send_error(dp, cp, data);
648} 668}
649#endif /* CONFIG_HOTPLUG_CPU */ 669#endif /* CONFIG_HOTPLUG_CPU */
650 670
@@ -656,8 +676,8 @@ struct ds_pri_msg {
656#define DS_PRI_UPDATE 0x02 676#define DS_PRI_UPDATE 0x02
657}; 677};
658 678
659static void ds_pri_data(struct ldc_channel *lp, 679static void ds_pri_data(struct ds_info *dp,
660 struct ds_cap_state *dp, 680 struct ds_cap_state *cp,
661 void *buf, int len) 681 void *buf, int len)
662{ 682{
663 struct ds_data *dpkt = buf; 683 struct ds_data *dpkt = buf;
@@ -665,8 +685,8 @@ static void ds_pri_data(struct ldc_channel *lp,
665 685
666 rp = (struct ds_pri_msg *) (dpkt + 1); 686 rp = (struct ds_pri_msg *) (dpkt + 1);
667 687
668 printk(KERN_INFO PFX "PRI REQ [%lx:%lx], len=%d\n", 688 printk(KERN_INFO "ds-%lu: PRI REQ [%lx:%lx], len=%d\n",
669 rp->req_num, rp->type, len); 689 dp->id, rp->req_num, rp->type, len);
670} 690}
671 691
672struct ds_var_hdr { 692struct ds_var_hdr {
@@ -701,8 +721,8 @@ static DEFINE_MUTEX(ds_var_mutex);
701static int ds_var_doorbell; 721static int ds_var_doorbell;
702static int ds_var_response; 722static int ds_var_response;
703 723
704static void ds_var_data(struct ldc_channel *lp, 724static void ds_var_data(struct ds_info *dp,
705 struct ds_cap_state *dp, 725 struct ds_cap_state *cp,
706 void *buf, int len) 726 void *buf, int len)
707{ 727{
708 struct ds_data *dpkt = buf; 728 struct ds_data *dpkt = buf;
@@ -721,14 +741,35 @@ static void ds_var_data(struct ldc_channel *lp,
721 741
722void ldom_set_var(const char *var, const char *value) 742void ldom_set_var(const char *var, const char *value)
723{ 743{
724 struct ds_info *dp = ds_info;
725 struct ds_cap_state *cp; 744 struct ds_cap_state *cp;
745 struct ds_info *dp;
746 unsigned long flags;
747
748 spin_lock_irqsave(&ds_lock, flags);
749 cp = NULL;
750 for (dp = ds_info_list; dp; dp = dp->next) {
751 struct ds_cap_state *tmp;
752
753 tmp = find_cap_by_string(dp, "var-config");
754 if (tmp && tmp->state == CAP_STATE_REGISTERED) {
755 cp = tmp;
756 break;
757 }
758 }
759 if (!cp) {
760 for (dp = ds_info_list; dp; dp = dp->next) {
761 struct ds_cap_state *tmp;
726 762
727 cp = find_cap_by_string("var-config"); 763 tmp = find_cap_by_string(dp, "var-config-backup");
728 if (cp->state != CAP_STATE_REGISTERED) 764 if (tmp && tmp->state == CAP_STATE_REGISTERED) {
729 cp = find_cap_by_string("var-config-backup"); 765 cp = tmp;
766 break;
767 }
768 }
769 }
770 spin_unlock_irqrestore(&ds_lock, flags);
730 771
731 if (cp->state == CAP_STATE_REGISTERED) { 772 if (cp) {
732 union { 773 union {
733 struct { 774 struct {
734 struct ds_data data; 775 struct ds_data data;
@@ -736,7 +777,6 @@ void ldom_set_var(const char *var, const char *value)
736 } header; 777 } header;
737 char all[512]; 778 char all[512];
738 } pkt; 779 } pkt;
739 unsigned long flags;
740 char *base, *p; 780 char *base, *p;
741 int msg_len, loops; 781 int msg_len, loops;
742 782
@@ -777,9 +817,9 @@ void ldom_set_var(const char *var, const char *value)
777 817
778 if (ds_var_doorbell == 0 || 818 if (ds_var_doorbell == 0 ||
779 ds_var_response != DS_VAR_SUCCESS) 819 ds_var_response != DS_VAR_SUCCESS)
780 printk(KERN_ERR PFX "var-config [%s:%s] " 820 printk(KERN_ERR "ds-%lu: var-config [%s:%s] "
781 "failed, response(%d).\n", 821 "failed, response(%d).\n",
782 var, value, 822 dp->id, var, value,
783 ds_var_response); 823 ds_var_response);
784 } else { 824 } else {
785 printk(KERN_ERR PFX "var-config not registered so " 825 printk(KERN_ERR PFX "var-config not registered so "
@@ -811,8 +851,8 @@ void ldom_power_off(void)
811 851
812static void ds_conn_reset(struct ds_info *dp) 852static void ds_conn_reset(struct ds_info *dp)
813{ 853{
814 printk(KERN_ERR PFX "ds_conn_reset() from %p\n", 854 printk(KERN_ERR "ds-%lu: ds_conn_reset() from %p\n",
815 __builtin_return_address(0)); 855 dp->id, __builtin_return_address(0));
816} 856}
817 857
818static int register_services(struct ds_info *dp) 858static int register_services(struct ds_info *dp)
@@ -820,12 +860,12 @@ static int register_services(struct ds_info *dp)
820 struct ldc_channel *lp = dp->lp; 860 struct ldc_channel *lp = dp->lp;
821 int i; 861 int i;
822 862
823 for (i = 0; i < ARRAY_SIZE(ds_states); i++) { 863 for (i = 0; i < dp->num_ds_states; i++) {
824 struct { 864 struct {
825 struct ds_reg_req req; 865 struct ds_reg_req req;
826 u8 id_buf[256]; 866 u8 id_buf[256];
827 } pbuf; 867 } pbuf;
828 struct ds_cap_state *cp = &ds_states[i]; 868 struct ds_cap_state *cp = &dp->ds_states[i];
829 int err, msg_len; 869 int err, msg_len;
830 u64 new_count; 870 u64 new_count;
831 871
@@ -870,28 +910,28 @@ static int ds_handshake(struct ds_info *dp, struct ds_msg_tag *pkt)
870 910
871 if (pkt->type == DS_REG_ACK) { 911 if (pkt->type == DS_REG_ACK) {
872 struct ds_reg_ack *ap = (struct ds_reg_ack *) pkt; 912 struct ds_reg_ack *ap = (struct ds_reg_ack *) pkt;
873 struct ds_cap_state *cp = find_cap(ap->handle); 913 struct ds_cap_state *cp = find_cap(dp, ap->handle);
874 914
875 if (!cp) { 915 if (!cp) {
876 printk(KERN_ERR PFX "REG ACK for unknown handle %lx\n", 916 printk(KERN_ERR "ds-%lu: REG ACK for unknown "
877 ap->handle); 917 "handle %lx\n", dp->id, ap->handle);
878 return 0; 918 return 0;
879 } 919 }
880 printk(KERN_INFO PFX "Registered %s service.\n", 920 printk(KERN_INFO "ds-%lu: Registered %s service.\n",
881 cp->service_id); 921 dp->id, cp->service_id);
882 cp->state = CAP_STATE_REGISTERED; 922 cp->state = CAP_STATE_REGISTERED;
883 } else if (pkt->type == DS_REG_NACK) { 923 } else if (pkt->type == DS_REG_NACK) {
884 struct ds_reg_nack *np = (struct ds_reg_nack *) pkt; 924 struct ds_reg_nack *np = (struct ds_reg_nack *) pkt;
885 struct ds_cap_state *cp = find_cap(np->handle); 925 struct ds_cap_state *cp = find_cap(dp, np->handle);
886 926
887 if (!cp) { 927 if (!cp) {
888 printk(KERN_ERR PFX "REG NACK for " 928 printk(KERN_ERR "ds-%lu: REG NACK for "
889 "unknown handle %lx\n", 929 "unknown handle %lx\n",
890 np->handle); 930 dp->id, np->handle);
891 return 0; 931 return 0;
892 } 932 }
893 printk(KERN_INFO PFX "Could not register %s service\n", 933 printk(KERN_INFO "ds-%lu: Could not register %s service\n",
894 cp->service_id); 934 dp->id, cp->service_id);
895 cp->state = CAP_STATE_UNKNOWN; 935 cp->state = CAP_STATE_UNKNOWN;
896 } 936 }
897 937
@@ -922,6 +962,7 @@ static DECLARE_WAIT_QUEUE_HEAD(ds_wait);
922 962
923struct ds_queue_entry { 963struct ds_queue_entry {
924 struct list_head list; 964 struct list_head list;
965 struct ds_info *dp;
925 int req_len; 966 int req_len;
926 int __pad; 967 int __pad;
927 u64 req[0]; 968 u64 req[0];
@@ -930,7 +971,6 @@ struct ds_queue_entry {
930static void process_ds_work(void) 971static void process_ds_work(void)
931{ 972{
932 struct ds_queue_entry *qp, *tmp; 973 struct ds_queue_entry *qp, *tmp;
933 static struct ds_info *dp;
934 unsigned long flags; 974 unsigned long flags;
935 LIST_HEAD(todo); 975 LIST_HEAD(todo);
936 976
@@ -939,22 +979,22 @@ static void process_ds_work(void)
939 INIT_LIST_HEAD(&ds_work_list); 979 INIT_LIST_HEAD(&ds_work_list);
940 spin_unlock_irqrestore(&ds_lock, flags); 980 spin_unlock_irqrestore(&ds_lock, flags);
941 981
942 dp = ds_info;
943
944 list_for_each_entry_safe(qp, tmp, &todo, list) { 982 list_for_each_entry_safe(qp, tmp, &todo, list) {
945 struct ds_data *dpkt = (struct ds_data *) qp->req; 983 struct ds_data *dpkt = (struct ds_data *) qp->req;
946 struct ds_cap_state *cp = find_cap(dpkt->handle); 984 struct ds_info *dp = qp->dp;
985 struct ds_cap_state *cp = find_cap(dp, dpkt->handle);
947 int req_len = qp->req_len; 986 int req_len = qp->req_len;
948 987
949 if (!cp) { 988 if (!cp) {
950 printk(KERN_ERR PFX "Data for unknown handle %lu\n", 989 printk(KERN_ERR "ds-%lu: Data for unknown "
951 dpkt->handle); 990 "handle %lu\n",
991 dp->id, dpkt->handle);
952 992
953 spin_lock_irqsave(&ds_lock, flags); 993 spin_lock_irqsave(&ds_lock, flags);
954 __send_ds_nack(dp, dpkt->handle); 994 __send_ds_nack(dp, dpkt->handle);
955 spin_unlock_irqrestore(&ds_lock, flags); 995 spin_unlock_irqrestore(&ds_lock, flags);
956 } else { 996 } else {
957 cp->data(dp->lp, cp, dpkt, req_len); 997 cp->data(dp, cp, dpkt, req_len);
958 } 998 }
959 999
960 list_del(&qp->list); 1000 list_del(&qp->list);
@@ -990,6 +1030,7 @@ static int ds_data(struct ds_info *dp, struct ds_msg_tag *pkt, int len)
990 if (!qp) { 1030 if (!qp) {
991 __send_ds_nack(dp, dpkt->handle); 1031 __send_ds_nack(dp, dpkt->handle);
992 } else { 1032 } else {
1033 qp->dp = dp;
993 memcpy(&qp->req, pkt, len); 1034 memcpy(&qp->req, pkt, len);
994 list_add_tail(&qp->list, &ds_work_list); 1035 list_add_tail(&qp->list, &ds_work_list);
995 wake_up(&ds_wait); 1036 wake_up(&ds_wait);
@@ -1019,8 +1060,8 @@ static void ds_reset(struct ds_info *dp)
1019 1060
1020 dp->hs_state = 0; 1061 dp->hs_state = 0;
1021 1062
1022 for (i = 0; i < ARRAY_SIZE(ds_states); i++) { 1063 for (i = 0; i < dp->num_ds_states; i++) {
1023 struct ds_cap_state *cp = &ds_states[i]; 1064 struct ds_cap_state *cp = &dp->ds_states[i];
1024 1065
1025 cp->state = CAP_STATE_UNKNOWN; 1066 cp->state = CAP_STATE_UNKNOWN;
1026 } 1067 }
@@ -1048,7 +1089,8 @@ static void ds_event(void *arg, int event)
1048 } 1089 }
1049 1090
1050 if (event != LDC_EVENT_DATA_READY) { 1091 if (event != LDC_EVENT_DATA_READY) {
1051 printk(KERN_WARNING PFX "Unexpected LDC event %d\n", event); 1092 printk(KERN_WARNING "ds-%lu: Unexpected LDC event %d\n",
1093 dp->id, event);
1052 spin_unlock_irqrestore(&ds_lock, flags); 1094 spin_unlock_irqrestore(&ds_lock, flags);
1053 return; 1095 return;
1054 } 1096 }
@@ -1099,9 +1141,11 @@ static int __devinit ds_probe(struct vio_dev *vdev,
1099 .mtu = 4096, 1141 .mtu = 4096,
1100 .mode = LDC_MODE_STREAM, 1142 .mode = LDC_MODE_STREAM,
1101 }; 1143 };
1144 struct mdesc_handle *hp;
1102 struct ldc_channel *lp; 1145 struct ldc_channel *lp;
1103 struct ds_info *dp; 1146 struct ds_info *dp;
1104 int err; 1147 const u64 *val;
1148 int err, i;
1105 1149
1106 if (ds_version_printed++ == 0) 1150 if (ds_version_printed++ == 0)
1107 printk(KERN_INFO "%s", version); 1151 printk(KERN_INFO "%s", version);
@@ -1111,19 +1155,37 @@ static int __devinit ds_probe(struct vio_dev *vdev,
1111 if (!dp) 1155 if (!dp)
1112 goto out_err; 1156 goto out_err;
1113 1157
1158 hp = mdesc_grab();
1159 val = mdesc_get_property(hp, vdev->mp, "id", NULL);
1160 if (val)
1161 dp->id = *val;
1162 mdesc_release(hp);
1163
1114 dp->rcv_buf = kzalloc(4096, GFP_KERNEL); 1164 dp->rcv_buf = kzalloc(4096, GFP_KERNEL);
1115 if (!dp->rcv_buf) 1165 if (!dp->rcv_buf)
1116 goto out_free_dp; 1166 goto out_free_dp;
1117 1167
1118 dp->rcv_buf_len = 4096; 1168 dp->rcv_buf_len = 4096;
1119 1169
1170 dp->ds_states = kzalloc(sizeof(ds_states_template),
1171 GFP_KERNEL);
1172 if (!dp->ds_states)
1173 goto out_free_rcv_buf;
1174
1175 memcpy(dp->ds_states, ds_states_template,
1176 sizeof(ds_states_template));
1177 dp->num_ds_states = ARRAY_SIZE(ds_states_template);
1178
1179 for (i = 0; i < dp->num_ds_states; i++)
1180 dp->ds_states[i].handle = ((u64)i << 32);
1181
1120 ds_cfg.tx_irq = vdev->tx_irq; 1182 ds_cfg.tx_irq = vdev->tx_irq;
1121 ds_cfg.rx_irq = vdev->rx_irq; 1183 ds_cfg.rx_irq = vdev->rx_irq;
1122 1184
1123 lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp); 1185 lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp);
1124 if (IS_ERR(lp)) { 1186 if (IS_ERR(lp)) {
1125 err = PTR_ERR(lp); 1187 err = PTR_ERR(lp);
1126 goto out_free_rcv_buf; 1188 goto out_free_ds_states;
1127 } 1189 }
1128 dp->lp = lp; 1190 dp->lp = lp;
1129 1191
@@ -1131,13 +1193,19 @@ static int __devinit ds_probe(struct vio_dev *vdev,
1131 if (err) 1193 if (err)
1132 goto out_free_ldc; 1194 goto out_free_ldc;
1133 1195
1134 ds_info = dp; 1196 spin_lock_irq(&ds_lock);
1197 dp->next = ds_info_list;
1198 ds_info_list = dp;
1199 spin_unlock_irq(&ds_lock);
1135 1200
1136 return err; 1201 return err;
1137 1202
1138out_free_ldc: 1203out_free_ldc:
1139 ldc_free(dp->lp); 1204 ldc_free(dp->lp);
1140 1205
1206out_free_ds_states:
1207 kfree(dp->ds_states);
1208
1141out_free_rcv_buf: 1209out_free_rcv_buf:
1142 kfree(dp->rcv_buf); 1210 kfree(dp->rcv_buf);
1143 1211
@@ -1172,11 +1240,6 @@ static struct vio_driver ds_driver = {
1172 1240
1173static int __init ds_init(void) 1241static int __init ds_init(void)
1174{ 1242{
1175 int i;
1176
1177 for (i = 0; i < ARRAY_SIZE(ds_states); i++)
1178 ds_states[i].handle = ((u64)i << 32);
1179
1180 kthread_run(ds_thread, NULL, "kldomd"); 1243 kthread_run(ds_thread, NULL, "kldomd");
1181 1244
1182 return vio_register_driver(&ds_driver); 1245 return vio_register_driver(&ds_driver);