1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/module.h>
29#include <linux/i2o.h>
30#include <linux/delay.h>
31#include <linux/sched.h>
32#include <linux/slab.h>
33#include "core.h"
34
35#define OSM_NAME "i2o"
36#define OSM_VERSION "1.325"
37#define OSM_DESCRIPTION "I2O subsystem"
38
39
40LIST_HEAD(i2o_controllers);
41
42
43
44
45
46static struct i2o_dma i2o_systab;
47
48static int i2o_hrt_get(struct i2o_controller *c);
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63struct i2o_message *i2o_msg_get_wait(struct i2o_controller *c, int wait)
64{
65 unsigned long timeout = jiffies + wait * HZ;
66 struct i2o_message *msg;
67
68 while (IS_ERR(msg = i2o_msg_get(c))) {
69 if (time_after(jiffies, timeout)) {
70 osm_debug("%s: Timeout waiting for message frame.\n",
71 c->name);
72 return ERR_PTR(-ETIMEDOUT);
73 }
74 schedule_timeout_uninterruptible(1);
75 }
76
77 return msg;
78};
79
80#if BITS_PER_LONG == 64
81
82
83
84
85
86
87
88
89
90
91
92u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
93{
94 struct i2o_context_list_element *entry;
95 unsigned long flags;
96
97 if (!ptr)
98 osm_err("%s: couldn't add NULL pointer to context list!\n",
99 c->name);
100
101 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
102 if (!entry) {
103 osm_err("%s: Could not allocate memory for context list element"
104 "\n", c->name);
105 return 0;
106 }
107
108 entry->ptr = ptr;
109 entry->timestamp = jiffies;
110 INIT_LIST_HEAD(&entry->list);
111
112 spin_lock_irqsave(&c->context_list_lock, flags);
113
114 if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
115 atomic_inc(&c->context_list_counter);
116
117 entry->context = atomic_read(&c->context_list_counter);
118
119 list_add(&entry->list, &c->context_list);
120
121 spin_unlock_irqrestore(&c->context_list_lock, flags);
122
123 osm_debug("%s: Add context to list %p -> %d\n", c->name, ptr, context);
124
125 return entry->context;
126};
127
128
129
130
131
132
133
134
135
136
137
138u32 i2o_cntxt_list_remove(struct i2o_controller * c, void *ptr)
139{
140 struct i2o_context_list_element *entry;
141 u32 context = 0;
142 unsigned long flags;
143
144 spin_lock_irqsave(&c->context_list_lock, flags);
145 list_for_each_entry(entry, &c->context_list, list)
146 if (entry->ptr == ptr) {
147 list_del(&entry->list);
148 context = entry->context;
149 kfree(entry);
150 break;
151 }
152 spin_unlock_irqrestore(&c->context_list_lock, flags);
153
154 if (!context)
155 osm_warn("%s: Could not remove nonexistent ptr %p\n", c->name,
156 ptr);
157
158 osm_debug("%s: remove ptr from context list %d -> %p\n", c->name,
159 context, ptr);
160
161 return context;
162};
163
164
165
166
167
168
169
170
171
172void *i2o_cntxt_list_get(struct i2o_controller *c, u32 context)
173{
174 struct i2o_context_list_element *entry;
175 unsigned long flags;
176 void *ptr = NULL;
177
178 spin_lock_irqsave(&c->context_list_lock, flags);
179 list_for_each_entry(entry, &c->context_list, list)
180 if (entry->context == context) {
181 list_del(&entry->list);
182 ptr = entry->ptr;
183 kfree(entry);
184 break;
185 }
186 spin_unlock_irqrestore(&c->context_list_lock, flags);
187
188 if (!ptr)
189 osm_warn("%s: context id %d not found\n", c->name, context);
190
191 osm_debug("%s: get ptr from context list %d -> %p\n", c->name, context,
192 ptr);
193
194 return ptr;
195};
196
197
198
199
200
201
202
203
204
205u32 i2o_cntxt_list_get_ptr(struct i2o_controller * c, void *ptr)
206{
207 struct i2o_context_list_element *entry;
208 u32 context = 0;
209 unsigned long flags;
210
211 spin_lock_irqsave(&c->context_list_lock, flags);
212 list_for_each_entry(entry, &c->context_list, list)
213 if (entry->ptr == ptr) {
214 context = entry->context;
215 break;
216 }
217 spin_unlock_irqrestore(&c->context_list_lock, flags);
218
219 if (!context)
220 osm_warn("%s: Could not find nonexistent ptr %p\n", c->name,
221 ptr);
222
223 osm_debug("%s: get context id from context list %p -> %d\n", c->name,
224 ptr, context);
225
226 return context;
227};
228#endif
229
230
231
232
233
234
235
236
237
238struct i2o_controller *i2o_find_iop(int unit)
239{
240 struct i2o_controller *c;
241
242 list_for_each_entry(c, &i2o_controllers, list) {
243 if (c->unit == unit)
244 return c;
245 }
246
247 return NULL;
248};
249
250
251
252
253
254
255
256
257
258
259
260struct i2o_device *i2o_iop_find_device(struct i2o_controller *c, u16 tid)
261{
262 struct i2o_device *dev;
263
264 list_for_each_entry(dev, &c->devices, list)
265 if (dev->lct_data.tid == tid)
266 return dev;
267
268 return NULL;
269};
270
271
272
273
274
275
276
277
278
279
280static int i2o_iop_quiesce(struct i2o_controller *c)
281{
282 struct i2o_message *msg;
283 i2o_status_block *sb = c->status_block.virt;
284 int rc;
285
286 i2o_status_get(c);
287
288
289 if ((sb->iop_state != ADAPTER_STATE_READY) &&
290 (sb->iop_state != ADAPTER_STATE_OPERATIONAL))
291 return 0;
292
293 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
294 if (IS_ERR(msg))
295 return PTR_ERR(msg);
296
297 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
298 msg->u.head[1] =
299 cpu_to_le32(I2O_CMD_SYS_QUIESCE << 24 | HOST_TID << 12 |
300 ADAPTER_TID);
301
302
303 if ((rc = i2o_msg_post_wait(c, msg, 240)))
304 osm_info("%s: Unable to quiesce (status=%#x).\n", c->name, -rc);
305 else
306 osm_debug("%s: Quiesced.\n", c->name);
307
308 i2o_status_get(c);
309
310 return rc;
311};
312
313
314
315
316
317
318
319
320
321static int i2o_iop_enable(struct i2o_controller *c)
322{
323 struct i2o_message *msg;
324 i2o_status_block *sb = c->status_block.virt;
325 int rc;
326
327 i2o_status_get(c);
328
329
330 if (sb->iop_state != ADAPTER_STATE_READY)
331 return -EINVAL;
332
333 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
334 if (IS_ERR(msg))
335 return PTR_ERR(msg);
336
337 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
338 msg->u.head[1] =
339 cpu_to_le32(I2O_CMD_SYS_ENABLE << 24 | HOST_TID << 12 |
340 ADAPTER_TID);
341
342
343 if ((rc = i2o_msg_post_wait(c, msg, 240)))
344 osm_err("%s: Could not enable (status=%#x).\n", c->name, -rc);
345 else
346 osm_debug("%s: Enabled.\n", c->name);
347
348 i2o_status_get(c);
349
350 return rc;
351};
352
353
354
355
356
357
358static inline void i2o_iop_quiesce_all(void)
359{
360 struct i2o_controller *c, *tmp;
361
362 list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
363 if (!c->no_quiesce)
364 i2o_iop_quiesce(c);
365 }
366};
367
368
369
370
371
372
373static inline void i2o_iop_enable_all(void)
374{
375 struct i2o_controller *c, *tmp;
376
377 list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
378 i2o_iop_enable(c);
379};
380
381
382
383
384
385
386
387
388
389
390
391
392static int i2o_iop_clear(struct i2o_controller *c)
393{
394 struct i2o_message *msg;
395 int rc;
396
397 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
398 if (IS_ERR(msg))
399 return PTR_ERR(msg);
400
401
402 i2o_iop_quiesce_all();
403
404 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
405 msg->u.head[1] =
406 cpu_to_le32(I2O_CMD_ADAPTER_CLEAR << 24 | HOST_TID << 12 |
407 ADAPTER_TID);
408
409 if ((rc = i2o_msg_post_wait(c, msg, 30)))
410 osm_info("%s: Unable to clear (status=%#x).\n", c->name, -rc);
411 else
412 osm_debug("%s: Cleared.\n", c->name);
413
414
415 i2o_iop_enable_all();
416
417 return rc;
418}
419
420
421
422
423
424
425
426
427
428
429static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
430{
431 u32 m;
432 volatile u8 *status = c->status.virt;
433 struct i2o_message *msg;
434 ulong timeout;
435 int i;
436
437 osm_debug("%s: Initializing Outbound Queue...\n", c->name);
438
439 memset(c->status.virt, 0, 4);
440
441 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
442 if (IS_ERR(msg))
443 return PTR_ERR(msg);
444
445 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6);
446 msg->u.head[1] =
447 cpu_to_le32(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 |
448 ADAPTER_TID);
449 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
450 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
451 msg->body[0] = cpu_to_le32(PAGE_SIZE);
452
453 msg->body[1] = cpu_to_le32(I2O_OUTBOUND_MSG_FRAME_SIZE << 16 | 0x80);
454 msg->body[2] = cpu_to_le32(0xd0000004);
455 msg->body[3] = cpu_to_le32(i2o_dma_low(c->status.phys));
456 msg->body[4] = cpu_to_le32(i2o_dma_high(c->status.phys));
457
458 i2o_msg_post(c, msg);
459
460 timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
461 while (*status <= I2O_CMD_IN_PROGRESS) {
462 if (time_after(jiffies, timeout)) {
463 osm_warn("%s: Timeout Initializing\n", c->name);
464 return -ETIMEDOUT;
465 }
466 schedule_timeout_uninterruptible(1);
467 }
468
469 m = c->out_queue.phys;
470
471
472 for (i = 0; i < I2O_MAX_OUTBOUND_MSG_FRAMES; i++) {
473 i2o_flush_reply(c, m);
474 udelay(1);
475 m += I2O_OUTBOUND_MSG_FRAME_SIZE * sizeof(u32);
476 }
477
478 return 0;
479}
480
481
482
483
484
485
486
487
488
489
490static int i2o_iop_reset(struct i2o_controller *c)
491{
492 volatile u8 *status = c->status.virt;
493 struct i2o_message *msg;
494 unsigned long timeout;
495 i2o_status_block *sb = c->status_block.virt;
496 int rc = 0;
497
498 osm_debug("%s: Resetting controller\n", c->name);
499
500 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
501 if (IS_ERR(msg))
502 return PTR_ERR(msg);
503
504 memset(c->status_block.virt, 0, 8);
505
506
507 i2o_iop_quiesce_all();
508
509 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_0);
510 msg->u.head[1] =
511 cpu_to_le32(I2O_CMD_ADAPTER_RESET << 24 | HOST_TID << 12 |
512 ADAPTER_TID);
513 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
514 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
515 msg->body[0] = cpu_to_le32(0x00000000);
516 msg->body[1] = cpu_to_le32(0x00000000);
517 msg->body[2] = cpu_to_le32(i2o_dma_low(c->status.phys));
518 msg->body[3] = cpu_to_le32(i2o_dma_high(c->status.phys));
519
520 i2o_msg_post(c, msg);
521
522
523 timeout = jiffies + I2O_TIMEOUT_RESET * HZ;
524 while (!*status) {
525 if (time_after(jiffies, timeout))
526 break;
527
528 schedule_timeout_uninterruptible(1);
529 }
530
531 switch (*status) {
532 case I2O_CMD_REJECTED:
533 osm_warn("%s: IOP reset rejected\n", c->name);
534 rc = -EPERM;
535 break;
536
537 case I2O_CMD_IN_PROGRESS:
538
539
540
541
542
543
544
545
546 osm_debug("%s: Reset in progress, waiting for reboot...\n",
547 c->name);
548
549 while (IS_ERR(msg = i2o_msg_get_wait(c, I2O_TIMEOUT_RESET))) {
550 if (time_after(jiffies, timeout)) {
551 osm_err("%s: IOP reset timeout.\n", c->name);
552 rc = PTR_ERR(msg);
553 goto exit;
554 }
555 schedule_timeout_uninterruptible(1);
556 }
557 i2o_msg_nop(c, msg);
558
559
560 c->no_quiesce = 0;
561
562
563 i2o_status_get(c);
564
565 if (!c->promise && (sb->iop_state != ADAPTER_STATE_RESET))
566 osm_warn("%s: reset completed, but adapter not in RESET"
567 " state.\n", c->name);
568 else
569 osm_debug("%s: reset completed.\n", c->name);
570
571 break;
572
573 default:
574 osm_err("%s: IOP reset timeout.\n", c->name);
575 rc = -ETIMEDOUT;
576 break;
577 }
578
579 exit:
580
581 i2o_iop_enable_all();
582
583 return rc;
584};
585
586
587
588
589
590
591
592
593
594
595static int i2o_iop_activate(struct i2o_controller *c)
596{
597 i2o_status_block *sb = c->status_block.virt;
598 int rc;
599 int state;
600
601
602
603
604 rc = i2o_status_get(c);
605 if (rc) {
606 osm_info("%s: Unable to obtain status, attempting a reset.\n",
607 c->name);
608 rc = i2o_iop_reset(c);
609 if (rc)
610 return rc;
611 }
612
613 if (sb->i2o_version > I2OVER15) {
614 osm_err("%s: Not running version 1.5 of the I2O Specification."
615 "\n", c->name);
616 return -ENODEV;
617 }
618
619 switch (sb->iop_state) {
620 case ADAPTER_STATE_FAULTED:
621 osm_err("%s: hardware fault\n", c->name);
622 return -EFAULT;
623
624 case ADAPTER_STATE_READY:
625 case ADAPTER_STATE_OPERATIONAL:
626 case ADAPTER_STATE_HOLD:
627 case ADAPTER_STATE_FAILED:
628 osm_debug("%s: already running, trying to reset...\n", c->name);
629 rc = i2o_iop_reset(c);
630 if (rc)
631 return rc;
632 }
633
634
635 state = sb->iop_state;
636
637 rc = i2o_iop_init_outbound_queue(c);
638 if (rc)
639 return rc;
640
641
642 if (state != ADAPTER_STATE_RESET)
643 i2o_iop_clear(c);
644
645 i2o_status_get(c);
646
647 if (sb->iop_state != ADAPTER_STATE_HOLD) {
648 osm_err("%s: failed to bring IOP into HOLD state\n", c->name);
649 return -EIO;
650 }
651
652 return i2o_hrt_get(c);
653};
654
655static void i2o_res_alloc(struct i2o_controller *c, unsigned long flags)
656{
657 i2o_status_block *sb = c->status_block.virt;
658 struct resource *res = &c->mem_resource;
659 resource_size_t size, align;
660 int err;
661
662 res->name = c->pdev->bus->name;
663 res->flags = flags;
664 res->start = 0;
665 res->end = 0;
666 osm_info("%s: requires private memory resources.\n", c->name);
667
668 if (flags & IORESOURCE_MEM) {
669 size = sb->desired_mem_size;
670 align = 1 << 20;
671 } else {
672 size = sb->desired_io_size;
673 align = 1 << 12;
674 }
675
676 err = pci_bus_alloc_resource(c->pdev->bus, res, size, align, 0, 0,
677 NULL, NULL);
678 if (err < 0)
679 return;
680
681 if (flags & IORESOURCE_MEM) {
682 c->mem_alloc = 1;
683 sb->current_mem_size = resource_size(res);
684 sb->current_mem_base = res->start;
685 } else if (flags & IORESOURCE_IO) {
686 c->io_alloc = 1;
687 sb->current_io_size = resource_size(res);
688 sb->current_io_base = res->start;
689 }
690 osm_info("%s: allocated PCI space %pR\n", c->name, res);
691}
692
693
694
695
696
697
698
699
700
701static int i2o_iop_systab_set(struct i2o_controller *c)
702{
703 struct i2o_message *msg;
704 i2o_status_block *sb = c->status_block.virt;
705 struct device *dev = &c->pdev->dev;
706 int rc;
707
708 if (sb->current_mem_size < sb->desired_mem_size)
709 i2o_res_alloc(c, IORESOURCE_MEM);
710
711 if (sb->current_io_size < sb->desired_io_size)
712 i2o_res_alloc(c, IORESOURCE_IO);
713
714 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
715 if (IS_ERR(msg))
716 return PTR_ERR(msg);
717
718 i2o_systab.phys = dma_map_single(dev, i2o_systab.virt, i2o_systab.len,
719 PCI_DMA_TODEVICE);
720 if (!i2o_systab.phys) {
721 i2o_msg_nop(c, msg);
722 return -ENOMEM;
723 }
724
725 msg->u.head[0] = cpu_to_le32(I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6);
726 msg->u.head[1] =
727 cpu_to_le32(I2O_CMD_SYS_TAB_SET << 24 | HOST_TID << 12 |
728 ADAPTER_TID);
729
730
731
732
733
734
735
736 msg->body[0] = cpu_to_le32(c->unit + 2);
737 msg->body[1] = cpu_to_le32(0x00000000);
738 msg->body[2] = cpu_to_le32(0x54000000 | i2o_systab.len);
739 msg->body[3] = cpu_to_le32(i2o_systab.phys);
740 msg->body[4] = cpu_to_le32(0x54000000 | sb->current_mem_size);
741 msg->body[5] = cpu_to_le32(sb->current_mem_base);
742 msg->body[6] = cpu_to_le32(0xd4000000 | sb->current_io_size);
743 msg->body[6] = cpu_to_le32(sb->current_io_base);
744
745 rc = i2o_msg_post_wait(c, msg, 120);
746
747 dma_unmap_single(dev, i2o_systab.phys, i2o_systab.len,
748 PCI_DMA_TODEVICE);
749
750 if (rc < 0)
751 osm_err("%s: Unable to set SysTab (status=%#x).\n", c->name,
752 -rc);
753 else
754 osm_debug("%s: SysTab set.\n", c->name);
755
756 return rc;
757}
758
759
760
761
762
763
764
765
766
767static int i2o_iop_online(struct i2o_controller *c)
768{
769 int rc;
770
771 rc = i2o_iop_systab_set(c);
772 if (rc)
773 return rc;
774
775
776 osm_debug("%s: Attempting to enable...\n", c->name);
777 rc = i2o_iop_enable(c);
778 if (rc)
779 return rc;
780
781 return 0;
782};
783
784
785
786
787
788
789
790
791void i2o_iop_remove(struct i2o_controller *c)
792{
793 struct i2o_device *dev, *tmp;
794
795 osm_debug("%s: deleting controller\n", c->name);
796
797 i2o_driver_notify_controller_remove_all(c);
798
799 list_del(&c->list);
800
801 list_for_each_entry_safe(dev, tmp, &c->devices, list)
802 i2o_device_remove(dev);
803
804 device_del(&c->device);
805
806
807 i2o_iop_reset(c);
808}
809
810
811
812
813
814
815
816
817
818
819
820static int i2o_systab_build(void)
821{
822 struct i2o_controller *c, *tmp;
823 int num_controllers = 0;
824 u32 change_ind = 0;
825 int count = 0;
826 struct i2o_sys_tbl *systab = i2o_systab.virt;
827
828 list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
829 num_controllers++;
830
831 if (systab) {
832 change_ind = systab->change_ind;
833 kfree(i2o_systab.virt);
834 }
835
836
837 i2o_systab.len = sizeof(struct i2o_sys_tbl) + num_controllers *
838 sizeof(struct i2o_sys_tbl_entry);
839
840 systab = i2o_systab.virt = kzalloc(i2o_systab.len, GFP_KERNEL);
841 if (!systab) {
842 osm_err("unable to allocate memory for System Table\n");
843 return -ENOMEM;
844 }
845
846 systab->version = I2OVERSION;
847 systab->change_ind = change_ind + 1;
848
849 list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
850 i2o_status_block *sb;
851
852 if (count >= num_controllers) {
853 osm_err("controller added while building system table"
854 "\n");
855 break;
856 }
857
858 sb = c->status_block.virt;
859
860
861
862
863
864
865
866
867 if (unlikely(i2o_status_get(c))) {
868 osm_err("%s: Deleting b/c could not get status while "
869 "attempting to build system table\n", c->name);
870 i2o_iop_remove(c);
871 continue;
872 }
873
874 systab->iops[count].org_id = sb->org_id;
875 systab->iops[count].iop_id = c->unit + 2;
876 systab->iops[count].seg_num = 0;
877 systab->iops[count].i2o_version = sb->i2o_version;
878 systab->iops[count].iop_state = sb->iop_state;
879 systab->iops[count].msg_type = sb->msg_type;
880 systab->iops[count].frame_size = sb->inbound_frame_size;
881 systab->iops[count].last_changed = change_ind;
882 systab->iops[count].iop_capabilities = sb->iop_capabilities;
883 systab->iops[count].inbound_low =
884 i2o_dma_low(c->base.phys + I2O_IN_PORT);
885 systab->iops[count].inbound_high =
886 i2o_dma_high(c->base.phys + I2O_IN_PORT);
887
888 count++;
889 }
890
891 systab->num_entries = count;
892
893 return 0;
894};
895
896
897
898
899
900
901
902
903
904static int i2o_parse_hrt(struct i2o_controller *c)
905{
906 i2o_dump_hrt(c);
907 return 0;
908};
909
910
911
912
913
914
915
916
917
918
919
920int i2o_status_get(struct i2o_controller *c)
921{
922 struct i2o_message *msg;
923 volatile u8 *status_block;
924 unsigned long timeout;
925
926 status_block = (u8 *) c->status_block.virt;
927 memset(c->status_block.virt, 0, sizeof(i2o_status_block));
928
929 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
930 if (IS_ERR(msg))
931 return PTR_ERR(msg);
932
933 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_0);
934 msg->u.head[1] =
935 cpu_to_le32(I2O_CMD_STATUS_GET << 24 | HOST_TID << 12 |
936 ADAPTER_TID);
937 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
938 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
939 msg->body[0] = cpu_to_le32(0x00000000);
940 msg->body[1] = cpu_to_le32(0x00000000);
941 msg->body[2] = cpu_to_le32(i2o_dma_low(c->status_block.phys));
942 msg->body[3] = cpu_to_le32(i2o_dma_high(c->status_block.phys));
943 msg->body[4] = cpu_to_le32(sizeof(i2o_status_block));
944
945 i2o_msg_post(c, msg);
946
947
948 timeout = jiffies + I2O_TIMEOUT_STATUS_GET * HZ;
949 while (status_block[87] != 0xFF) {
950 if (time_after(jiffies, timeout)) {
951 osm_err("%s: Get status timeout.\n", c->name);
952 return -ETIMEDOUT;
953 }
954
955 schedule_timeout_uninterruptible(1);
956 }
957
958#ifdef DEBUG
959 i2o_debug_state(c);
960#endif
961
962 return 0;
963}
964
965
966
967
968
969
970
971
972
973
974static int i2o_hrt_get(struct i2o_controller *c)
975{
976 int rc;
977 int i;
978 i2o_hrt *hrt = c->hrt.virt;
979 u32 size = sizeof(i2o_hrt);
980 struct device *dev = &c->pdev->dev;
981
982 for (i = 0; i < I2O_HRT_GET_TRIES; i++) {
983 struct i2o_message *msg;
984
985 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
986 if (IS_ERR(msg))
987 return PTR_ERR(msg);
988
989 msg->u.head[0] = cpu_to_le32(SIX_WORD_MSG_SIZE | SGL_OFFSET_4);
990 msg->u.head[1] =
991 cpu_to_le32(I2O_CMD_HRT_GET << 24 | HOST_TID << 12 |
992 ADAPTER_TID);
993 msg->body[0] = cpu_to_le32(0xd0000000 | c->hrt.len);
994 msg->body[1] = cpu_to_le32(c->hrt.phys);
995
996 rc = i2o_msg_post_wait_mem(c, msg, 20, &c->hrt);
997
998 if (rc < 0) {
999 osm_err("%s: Unable to get HRT (status=%#x)\n", c->name,
1000 -rc);
1001 return rc;
1002 }
1003
1004 size = hrt->num_entries * hrt->entry_len << 2;
1005 if (size > c->hrt.len) {
1006 if (i2o_dma_realloc(dev, &c->hrt, size))
1007 return -ENOMEM;
1008 else
1009 hrt = c->hrt.virt;
1010 } else
1011 return i2o_parse_hrt(c);
1012 }
1013
1014 osm_err("%s: Unable to get HRT after %d tries, giving up\n", c->name,
1015 I2O_HRT_GET_TRIES);
1016
1017 return -EBUSY;
1018}
1019
1020
1021
1022
1023
1024
1025
1026
1027static void i2o_iop_release(struct device *dev)
1028{
1029 struct i2o_controller *c = to_i2o_controller(dev);
1030
1031 i2o_iop_free(c);
1032};
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043struct i2o_controller *i2o_iop_alloc(void)
1044{
1045 static int unit = 0;
1046 struct i2o_controller *c;
1047 char poolname[32];
1048
1049 c = kzalloc(sizeof(*c), GFP_KERNEL);
1050 if (!c) {
1051 osm_err("i2o: Insufficient memory to allocate a I2O controller."
1052 "\n");
1053 return ERR_PTR(-ENOMEM);
1054 }
1055
1056 c->unit = unit++;
1057 sprintf(c->name, "iop%d", c->unit);
1058
1059 snprintf(poolname, sizeof(poolname), "i2o_%s_msg_inpool", c->name);
1060 if (i2o_pool_alloc
1061 (&c->in_msg, poolname, I2O_INBOUND_MSG_FRAME_SIZE * 4 + sizeof(u32),
1062 I2O_MSG_INPOOL_MIN)) {
1063 kfree(c);
1064 return ERR_PTR(-ENOMEM);
1065 };
1066
1067 INIT_LIST_HEAD(&c->devices);
1068 spin_lock_init(&c->lock);
1069 mutex_init(&c->lct_lock);
1070
1071 device_initialize(&c->device);
1072
1073 c->device.release = &i2o_iop_release;
1074
1075 dev_set_name(&c->device, "iop%d", c->unit);
1076
1077#if BITS_PER_LONG == 64
1078 spin_lock_init(&c->context_list_lock);
1079 atomic_set(&c->context_list_counter, 0);
1080 INIT_LIST_HEAD(&c->context_list);
1081#endif
1082
1083 return c;
1084};
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095int i2o_iop_add(struct i2o_controller *c)
1096{
1097 int rc;
1098
1099 if ((rc = device_add(&c->device))) {
1100 osm_err("%s: could not add controller\n", c->name);
1101 goto iop_reset;
1102 }
1103
1104 osm_info("%s: Activating I2O controller...\n", c->name);
1105 osm_info("%s: This may take a few minutes if there are many devices\n",
1106 c->name);
1107
1108 if ((rc = i2o_iop_activate(c))) {
1109 osm_err("%s: could not activate controller\n", c->name);
1110 goto device_del;
1111 }
1112
1113 osm_debug("%s: building sys table...\n", c->name);
1114
1115 if ((rc = i2o_systab_build()))
1116 goto device_del;
1117
1118 osm_debug("%s: online controller...\n", c->name);
1119
1120 if ((rc = i2o_iop_online(c)))
1121 goto device_del;
1122
1123 osm_debug("%s: getting LCT...\n", c->name);
1124
1125 if ((rc = i2o_exec_lct_get(c)))
1126 goto device_del;
1127
1128 list_add(&c->list, &i2o_controllers);
1129
1130 i2o_driver_notify_controller_add_all(c);
1131
1132 osm_info("%s: Controller added\n", c->name);
1133
1134 return 0;
1135
1136 device_del:
1137 device_del(&c->device);
1138
1139 iop_reset:
1140 i2o_iop_reset(c);
1141
1142 return rc;
1143};
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158int i2o_event_register(struct i2o_device *dev, struct i2o_driver *drv,
1159 int tcntxt, u32 evt_mask)
1160{
1161 struct i2o_controller *c = dev->iop;
1162 struct i2o_message *msg;
1163
1164 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
1165 if (IS_ERR(msg))
1166 return PTR_ERR(msg);
1167
1168 msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0);
1169 msg->u.head[1] =
1170 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | dev->
1171 lct_data.tid);
1172 msg->u.s.icntxt = cpu_to_le32(drv->context);
1173 msg->u.s.tcntxt = cpu_to_le32(tcntxt);
1174 msg->body[0] = cpu_to_le32(evt_mask);
1175
1176 i2o_msg_post(c, msg);
1177
1178 return 0;
1179};
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189static int __init i2o_iop_init(void)
1190{
1191 int rc = 0;
1192
1193 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
1194
1195 if ((rc = i2o_driver_init()))
1196 goto exit;
1197
1198 if ((rc = i2o_exec_init()))
1199 goto driver_exit;
1200
1201 if ((rc = i2o_pci_init()))
1202 goto exec_exit;
1203
1204 return 0;
1205
1206 exec_exit:
1207 i2o_exec_exit();
1208
1209 driver_exit:
1210 i2o_driver_exit();
1211
1212 exit:
1213 return rc;
1214}
1215
1216
1217
1218
1219
1220
1221static void __exit i2o_iop_exit(void)
1222{
1223 i2o_pci_exit();
1224 i2o_exec_exit();
1225 i2o_driver_exit();
1226};
1227
1228module_init(i2o_iop_init);
1229module_exit(i2o_iop_exit);
1230
1231MODULE_AUTHOR("Red Hat Software");
1232MODULE_LICENSE("GPL");
1233MODULE_DESCRIPTION(OSM_DESCRIPTION);
1234MODULE_VERSION(OSM_VERSION);
1235
1236#if BITS_PER_LONG == 64
1237EXPORT_SYMBOL(i2o_cntxt_list_add);
1238EXPORT_SYMBOL(i2o_cntxt_list_get);
1239EXPORT_SYMBOL(i2o_cntxt_list_remove);
1240EXPORT_SYMBOL(i2o_cntxt_list_get_ptr);
1241#endif
1242EXPORT_SYMBOL(i2o_msg_get_wait);
1243EXPORT_SYMBOL(i2o_find_iop);
1244EXPORT_SYMBOL(i2o_iop_find_device);
1245EXPORT_SYMBOL(i2o_event_register);
1246EXPORT_SYMBOL(i2o_status_get);
1247EXPORT_SYMBOL(i2o_controllers);
1248