31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/pci.h>
36 #include <linux/wait.h>
41 #define attn_on(sl) ibmphp_hpc_writeslot (sl, HPC_SLOT_ATTNON)
42 #define attn_off(sl) ibmphp_hpc_writeslot (sl, HPC_SLOT_ATTNOFF)
43 #define attn_LED_blink(sl) ibmphp_hpc_writeslot (sl, HPC_SLOT_BLINKLED)
44 #define get_ctrl_revision(sl, rev) ibmphp_hpc_readslot (sl, READ_REVLEVEL, rev)
45 #define get_hpc_options(sl, opt) ibmphp_hpc_readslot (sl, READ_HPCOPTIONS, opt)
47 #define DRIVER_VERSION "0.6"
48 #define DRIVER_DESC "IBM Hot Plug PCI Controller Driver"
74 static inline int get_cur_bus_info(
struct slot **
sl)
77 struct slot * slot_cur = *
sl;
79 debug(
"options = %x\n", slot_cur->
ctrl->options);
80 debug(
"revision = %x\n", slot_cur->
ctrl->revision);
90 slot_cur->
bus_on->current_bus_mode =
93 slot_cur->
bus_on->current_bus_mode = 0xFF;
95 debug(
"busstatus = %x, bus_speed = %x, bus_mode = %x\n",
97 slot_cur->
bus_on->current_speed,
98 slot_cur->
bus_on->current_bus_mode);
104 static inline int slot_update(
struct slot **
sl)
111 rc = get_cur_bus_info(sl);
115 static int __init get_max_slots (
void)
117 struct slot * slot_cur;
124 slot_count =
max(slot_count, slot_cur->
number);
144 err(
"no BIOS routing table...\n");
149 sizeof(struct irq_info);
155 for (loop = 0; loop < len; loop++) {
156 if ((*cur_slot)->number == rtable->
slots[loop].slot &&
157 (*cur_slot)->bus == rtable->
slots[loop].bus) {
161 for (i = 0; i < 4; i++)
163 (
int) (*cur_slot)->device, i,
166 debug(
"(*cur_slot)->irq[0] = %x\n",
167 (*cur_slot)->irq[0]);
168 debug(
"(*cur_slot)->irq[1] = %x\n",
169 (*cur_slot)->irq[1]);
170 debug(
"(*cur_slot)->irq[2] = %x\n",
171 (*cur_slot)->irq[2]);
172 debug(
"(*cur_slot)->irq[3] = %x\n",
173 (*cur_slot)->irq[3]);
175 debug(
"rtable->exlusive_irqs = %x\n",
177 debug(
"rtable->slots[loop].irq[0].bitmap = %x\n",
178 rtable->
slots[loop].irq[0].bitmap);
179 debug(
"rtable->slots[loop].irq[1].bitmap = %x\n",
180 rtable->
slots[loop].irq[1].bitmap);
181 debug(
"rtable->slots[loop].irq[2].bitmap = %x\n",
182 rtable->
slots[loop].irq[2].bitmap);
183 debug(
"rtable->slots[loop].irq[3].bitmap = %x\n",
184 rtable->
slots[loop].irq[3].bitmap);
186 debug(
"rtable->slots[loop].irq[0].link = %x\n",
187 rtable->
slots[loop].irq[0].link);
188 debug(
"rtable->slots[loop].irq[1].link = %x\n",
189 rtable->
slots[loop].irq[1].link);
190 debug(
"rtable->slots[loop].irq[2].link = %x\n",
191 rtable->
slots[loop].irq[2].link);
192 debug(
"rtable->slots[loop].irq[3].link = %x\n",
193 rtable->
slots[loop].irq[3].link);
194 debug(
"end of init_devno\n");
204 static inline int power_on(
struct slot *slot_cur)
211 err(
"power on failed\n");
215 err(
"command not completed successfully in power_on\n");
222 static inline int power_off(
struct slot *slot_cur)
229 err(
"power off failed\n");
233 err(
"command not completed successfully in power_off\n");
239 static int set_attention_status(
struct hotplug_slot *hotplug_slot,
u8 value)
245 debug(
"set_attention_status - Entry hotplug_slot[%lx] value[%x]\n",
246 (
ulong) hotplug_slot, value);
263 err(
"set_attention_status - Error : invalid input [%x]\n",
268 pslot = hotplug_slot->private;
279 debug(
"set_attention_status - Exit rc[%d]\n", rc);
283 static int get_attention_status(
struct hotplug_slot *hotplug_slot,
u8 * value)
289 debug(
"get_attention_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
294 pslot = hotplug_slot->private;
302 &(myslot.ext_status));
310 debug(
"get_attention_status - Exit rc[%d] value[%x]\n", rc, *value);
314 static int get_latch_status(
struct hotplug_slot *hotplug_slot,
u8 * value)
320 debug(
"get_latch_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
324 pslot = hotplug_slot->private;
335 debug(
"get_latch_status - Exit rc[%d] rc[%x] value[%x]\n",
341 static int get_power_status(
struct hotplug_slot *hotplug_slot,
u8 * value)
347 debug(
"get_power_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
351 pslot = hotplug_slot->private;
362 debug(
"get_power_status - Exit rc[%d] rc[%x] value[%x]\n",
367 static int get_adapter_present(
struct hotplug_slot *hotplug_slot,
u8 * value)
374 debug(
"get_adapter_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
378 pslot = hotplug_slot->private;
394 debug(
"get_adapter_present - Exit rc[%d] value[%x]\n", rc, *value);
398 static int get_max_bus_speed(
struct slot *
slot)
405 debug(
"%s - Entry slot[%p]\n", __func__, slot);
431 debug(
"%s - Exit rc[%d] speed[%x]\n", __func__, rc, speed);
503 static int __init init_ops(
void)
505 struct slot *slot_cur;
511 slot_cur =
list_entry(tmp,
struct slot, ibm_slot_list);
516 debug(
"BEFORE GETTING SLOT STATUS, slot # %x\n",
518 if (slot_cur->
ctrl->revision == 0xFF)
520 &slot_cur->
ctrl->revision))
523 if (slot_cur->
bus_on->current_speed == 0xFF)
524 if (get_cur_bus_info(&slot_cur))
526 get_max_bus_speed(slot_cur);
528 if (slot_cur->
ctrl->options == 0xFF)
532 retval = slot_update(&slot_cur);
545 debug(
"BEFORE POWER OFF COMMAND\n");
546 rc = power_off(slot_cur);
566 static int validate(
struct slot *slot_cur,
int opn)
573 number = slot_cur->
number;
574 if ((number > max_slots) || (number < 0))
576 debug(
"slot_number in validate is %d\n", slot_cur->
number);
578 retval = slot_update(&slot_cur);
598 err(
"validate failed....\n");
617 err(
"out of system memory\n");
634 bus_speed = slot_cur->
bus_on->current_speed;
635 mode = slot_cur->
bus_on->current_bus_mode;
673 struct slot *slot_cur;
676 slot_cur =
list_entry(tmp,
struct slot, ibm_slot_list);
677 if (slot_cur->
func) {
678 func_cur = slot_cur->
func;
680 if ((func_cur->
busno == busno) &&
681 (func_cur->
device == device) &&
684 func_cur = func_cur->
next;
696 static void free_slots(
void)
698 struct slot *slot_cur;
702 debug(
"%s -- enter\n", __func__);
705 slot_cur =
list_entry(tmp,
struct slot, ibm_slot_list);
708 debug(
"%s -- exit\n", __func__);
711 static void ibm_unconfigure_device(
struct pci_func *
func)
716 debug(
"inside %s\n", __func__);
717 debug(
"func->device = %x, func->function = %x\n",
719 debug(
"func->device << 3 | 0x0 = %x\n", func->
device << 3 | 0x0);
721 for (j = 0; j < 0x08; j++) {
736 static u8 bus_structure_fixup(
u8 busno)
747 err(
"%s - out of memory\n", __func__);
753 err(
"%s - out of memory\n", __func__);
758 bus->
ops = ibmphp_pci_bus->
ops;
762 (l != 0x0000) && (l != 0xffff)) {
763 debug(
"%s - Inside bus_structure_fixup()\n",
776 static int ibm_configure_device(
struct pci_func *func)
783 if (!(bus_structure_fixup(func->
busno)))
802 err(
"ERROR... : pci_dev still NULL\n");
808 child = func->
dev->subordinate;
819 static int is_bus_empty(
struct slot * slot_cur)
822 struct slot * tmp_slot;
825 while (i <= slot_cur->
bus_on->slot_max) {
826 if (i == slot_cur->
number) {
833 rc = slot_update(&tmp_slot);
850 static int set_bus(
struct slot * slot_cur)
861 debug(
"%s - entry slot # %d\n", __func__, slot_cur->
number);
863 rc = slot_update(&slot_cur);
913 err(
"Wrong bus speed\n");
918 err(
"wrong slot speed\n");
921 debug(
"setting bus speed for slot %d, cmd %x\n",
925 err(
"setting bus speed failed\n");
929 err(
"command not completed successfully in set_bus\n");
936 debug(
"%s -Exit\n", __func__);
947 static int check_limitations(
struct slot *slot_cur)
950 struct slot * tmp_slot;
954 for (i = slot_cur->
bus_on->slot_min; i <= slot_cur->
bus_on->slot_max; i++) {
962 get_cur_bus_info(&slot_cur);
963 switch (slot_cur->
bus_on->current_speed) {
965 limitation = slot_cur->
bus_on->slots_at_33_conv;
969 limitation = slot_cur->
bus_on->slots_at_66_pcix;
971 limitation = slot_cur->
bus_on->slots_at_66_conv;
974 limitation = slot_cur->
bus_on->slots_at_100_pcix;
977 limitation = slot_cur->
bus_on->slots_at_133_pcix;
981 if ((count + 1) > limitation)
986 static inline void print_card_capability(
struct slot *slot_cur)
988 info(
"capability of the card is ");
990 info(
" 133 MHz PCI-X\n");
992 info(
" 66 MHz PCI-X\n");
994 info(
" 66 MHz PCI\n");
996 info(
" 33 MHz PCI\n");
1005 static int enable_slot(
struct hotplug_slot *hs)
1008 struct slot *slot_cur;
1014 debug(
"ENABLING SLOT........\n");
1015 slot_cur = hs->private;
1018 err(
"validate function failed\n");
1024 rc = set_bus(slot_cur);
1026 err(
"was not able to set the bus\n");
1031 get_cur_bus_info(&slot_cur);
1032 debug(
"the current bus speed right after set_bus = %x\n",
1033 slot_cur->
bus_on->current_speed);
1036 rc = check_limitations(slot_cur);
1038 err(
"Adding this card exceeds the limitations of this bus.\n");
1039 err(
"(i.e., >1 133MHz cards running on same bus, or "
1040 ">2 66 PCI cards running on same bus.\n");
1041 err(
"Try hot-adding into another bus\n");
1046 rc = power_on(slot_cur);
1049 err(
"something wrong when powering up... please see below for details\n");
1053 if (slot_update(&slot_cur)) {
1062 err(
"power fault occurred trying to power up\n");
1064 err(
"bus speed mismatch occurred. please check "
1065 "current bus speed and card capability\n");
1066 print_card_capability(slot_cur);
1068 err(
"bus mode mismatch occurred. please check "
1069 "current bus mode and card capability\n");
1070 print_card_capability(slot_cur);
1075 debug(
"after power_on\n");
1077 get_cur_bus_info(&slot_cur);
1078 debug(
"the current bus speed right after power_on = %x\n",
1079 slot_cur->
bus_on->current_speed);
1082 rc = slot_update(&slot_cur);
1088 err(
"power fault occurred trying to power up...\n");
1092 err(
"bus speed mismatch occurred. please check current bus "
1093 "speed and card capability\n");
1094 print_card_capability(slot_cur);
1100 err(
"power on failed...\n");
1105 if (!slot_cur->
func) {
1108 err(
"out of system memory\n");
1112 slot_cur->
func->busno = slot_cur->
bus;
1114 for (i = 0; i < 4; i++)
1115 slot_cur->
func->irq[i] = slot_cur->
irq[i];
1117 debug(
"b4 configure_card, slot_cur->bus = %x, slot_cur->device = %x\n",
1121 err(
"configure_card was unsuccessful...\n");
1125 debug(
"after unconfigure_card\n");
1133 tmp_func = ibm_slot_find(slot_cur->
bus, slot_cur->
func->device,
1135 if (tmp_func && !(tmp_func->
dev))
1136 ibm_configure_device(tmp_func);
1140 if (slot_update(&slot_cur)) {
1154 rcpr = slot_update(&slot_cur);
1165 rcpr = power_off(slot_cur);
1179 static int ibmphp_disable_slot(
struct hotplug_slot *hotplug_slot)
1181 struct slot *slot = hotplug_slot->private;
1195 debug(
"DISABLING SLOT...\n");
1201 flag = slot_cur->
flag;
1215 if (!slot_cur->
func) {
1216 err(
"out of system memory\n");
1220 slot_cur->
func->busno = slot_cur->
bus;
1224 ibm_unconfigure_device(slot_cur->
func);
1239 debug(
"in disable_slot. after unconfigure_card\n");
1241 err(
"could not unconfigure card.\n");
1250 rc = slot_update(&slot_cur);
1263 if (slot_update(&slot_cur)) {
1275 .disable_slot = ibmphp_disable_slot,
1276 .hardware_test =
NULL,
1280 .get_adapter_status = get_adapter_present,
1286 static void ibmphp_unload(
void)
1289 debug(
"after slots\n");
1291 debug(
"after resources\n");
1293 debug(
"after bus info\n");
1295 debug(
"after ebda hpc\n");
1297 debug(
"after ebda pci rsrc\n");
1298 kfree(ibmphp_pci_bus);
1301 static int __init ibmphp_init(
void)
1312 if (!ibmphp_pci_bus) {
1313 err(
"out of memory\n");
1320 err(
"Can't find the root pci bus, can not continue\n");
1324 memcpy(ibmphp_pci_bus, bus,
sizeof(*ibmphp_pci_bus));
1330 for (i = 0; i < 16; i++)
1335 debug(
"after ibmphp_access_ebda()\n");
1339 debug(
"AFTER Resource & EBDA INITIALIZATIONS\n");
1341 max_slots = get_max_slots();
1364 static void __exit ibmphp_exit(
void)
1367 debug(
"after polling\n");