| .. | .. |
|---|
| 57 | 57 | static int get_adapter_status(struct hotplug_slot *slot, u8 *value); |
|---|
| 58 | 58 | static int get_latch_status(struct hotplug_slot *slot, u8 *value); |
|---|
| 59 | 59 | |
|---|
| 60 | | -static struct hotplug_slot_ops cpci_hotplug_slot_ops = { |
|---|
| 60 | +static const struct hotplug_slot_ops cpci_hotplug_slot_ops = { |
|---|
| 61 | 61 | .enable_slot = enable_slot, |
|---|
| 62 | 62 | .disable_slot = disable_slot, |
|---|
| 63 | 63 | .set_attention_status = set_attention_status, |
|---|
| .. | .. |
|---|
| 68 | 68 | }; |
|---|
| 69 | 69 | |
|---|
| 70 | 70 | static int |
|---|
| 71 | | -update_latch_status(struct hotplug_slot *hotplug_slot, u8 value) |
|---|
| 72 | | -{ |
|---|
| 73 | | - struct hotplug_slot_info info; |
|---|
| 74 | | - |
|---|
| 75 | | - memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info)); |
|---|
| 76 | | - info.latch_status = value; |
|---|
| 77 | | - return pci_hp_change_slot_info(hotplug_slot, &info); |
|---|
| 78 | | -} |
|---|
| 79 | | - |
|---|
| 80 | | -static int |
|---|
| 81 | | -update_adapter_status(struct hotplug_slot *hotplug_slot, u8 value) |
|---|
| 82 | | -{ |
|---|
| 83 | | - struct hotplug_slot_info info; |
|---|
| 84 | | - |
|---|
| 85 | | - memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info)); |
|---|
| 86 | | - info.adapter_status = value; |
|---|
| 87 | | - return pci_hp_change_slot_info(hotplug_slot, &info); |
|---|
| 88 | | -} |
|---|
| 89 | | - |
|---|
| 90 | | -static int |
|---|
| 91 | 71 | enable_slot(struct hotplug_slot *hotplug_slot) |
|---|
| 92 | 72 | { |
|---|
| 93 | | - struct slot *slot = hotplug_slot->private; |
|---|
| 73 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 94 | 74 | int retval = 0; |
|---|
| 95 | 75 | |
|---|
| 96 | 76 | dbg("%s - physical_slot = %s", __func__, slot_name(slot)); |
|---|
| .. | .. |
|---|
| 103 | 83 | static int |
|---|
| 104 | 84 | disable_slot(struct hotplug_slot *hotplug_slot) |
|---|
| 105 | 85 | { |
|---|
| 106 | | - struct slot *slot = hotplug_slot->private; |
|---|
| 86 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 107 | 87 | int retval = 0; |
|---|
| 108 | 88 | |
|---|
| 109 | 89 | dbg("%s - physical_slot = %s", __func__, slot_name(slot)); |
|---|
| .. | .. |
|---|
| 135 | 115 | goto disable_error; |
|---|
| 136 | 116 | } |
|---|
| 137 | 117 | |
|---|
| 138 | | - if (update_adapter_status(slot->hotplug_slot, 0)) |
|---|
| 139 | | - warn("failure to update adapter file"); |
|---|
| 118 | + slot->adapter_status = 0; |
|---|
| 140 | 119 | |
|---|
| 141 | 120 | if (slot->extracting) { |
|---|
| 142 | 121 | slot->extracting = 0; |
|---|
| .. | .. |
|---|
| 160 | 139 | static int |
|---|
| 161 | 140 | get_power_status(struct hotplug_slot *hotplug_slot, u8 *value) |
|---|
| 162 | 141 | { |
|---|
| 163 | | - struct slot *slot = hotplug_slot->private; |
|---|
| 142 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 164 | 143 | |
|---|
| 165 | 144 | *value = cpci_get_power_status(slot); |
|---|
| 166 | 145 | return 0; |
|---|
| .. | .. |
|---|
| 169 | 148 | static int |
|---|
| 170 | 149 | get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value) |
|---|
| 171 | 150 | { |
|---|
| 172 | | - struct slot *slot = hotplug_slot->private; |
|---|
| 151 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 173 | 152 | |
|---|
| 174 | 153 | *value = cpci_get_attention_status(slot); |
|---|
| 175 | 154 | return 0; |
|---|
| .. | .. |
|---|
| 178 | 157 | static int |
|---|
| 179 | 158 | set_attention_status(struct hotplug_slot *hotplug_slot, u8 status) |
|---|
| 180 | 159 | { |
|---|
| 181 | | - return cpci_set_attention_status(hotplug_slot->private, status); |
|---|
| 160 | + return cpci_set_attention_status(to_slot(hotplug_slot), status); |
|---|
| 182 | 161 | } |
|---|
| 183 | 162 | |
|---|
| 184 | 163 | static int |
|---|
| 185 | 164 | get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) |
|---|
| 186 | 165 | { |
|---|
| 187 | | - *value = hotplug_slot->info->adapter_status; |
|---|
| 166 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 167 | + |
|---|
| 168 | + *value = slot->adapter_status; |
|---|
| 188 | 169 | return 0; |
|---|
| 189 | 170 | } |
|---|
| 190 | 171 | |
|---|
| 191 | 172 | static int |
|---|
| 192 | 173 | get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value) |
|---|
| 193 | 174 | { |
|---|
| 194 | | - *value = hotplug_slot->info->latch_status; |
|---|
| 175 | + struct slot *slot = to_slot(hotplug_slot); |
|---|
| 176 | + |
|---|
| 177 | + *value = slot->latch_status; |
|---|
| 195 | 178 | return 0; |
|---|
| 196 | 179 | } |
|---|
| 197 | 180 | |
|---|
| 198 | 181 | static void release_slot(struct slot *slot) |
|---|
| 199 | 182 | { |
|---|
| 200 | | - kfree(slot->hotplug_slot->info); |
|---|
| 201 | | - kfree(slot->hotplug_slot); |
|---|
| 202 | 183 | pci_dev_put(slot->dev); |
|---|
| 203 | 184 | kfree(slot); |
|---|
| 204 | 185 | } |
|---|
| .. | .. |
|---|
| 209 | 190 | cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) |
|---|
| 210 | 191 | { |
|---|
| 211 | 192 | struct slot *slot; |
|---|
| 212 | | - struct hotplug_slot *hotplug_slot; |
|---|
| 213 | | - struct hotplug_slot_info *info; |
|---|
| 214 | 193 | char name[SLOT_NAME_SIZE]; |
|---|
| 215 | 194 | int status; |
|---|
| 216 | 195 | int i; |
|---|
| .. | .. |
|---|
| 229 | 208 | goto error; |
|---|
| 230 | 209 | } |
|---|
| 231 | 210 | |
|---|
| 232 | | - hotplug_slot = |
|---|
| 233 | | - kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); |
|---|
| 234 | | - if (!hotplug_slot) { |
|---|
| 235 | | - status = -ENOMEM; |
|---|
| 236 | | - goto error_slot; |
|---|
| 237 | | - } |
|---|
| 238 | | - slot->hotplug_slot = hotplug_slot; |
|---|
| 239 | | - |
|---|
| 240 | | - info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); |
|---|
| 241 | | - if (!info) { |
|---|
| 242 | | - status = -ENOMEM; |
|---|
| 243 | | - goto error_hpslot; |
|---|
| 244 | | - } |
|---|
| 245 | | - hotplug_slot->info = info; |
|---|
| 246 | | - |
|---|
| 247 | 211 | slot->bus = bus; |
|---|
| 248 | 212 | slot->number = i; |
|---|
| 249 | 213 | slot->devfn = PCI_DEVFN(i, 0); |
|---|
| 250 | 214 | |
|---|
| 251 | 215 | snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i); |
|---|
| 252 | 216 | |
|---|
| 253 | | - hotplug_slot->private = slot; |
|---|
| 254 | | - hotplug_slot->ops = &cpci_hotplug_slot_ops; |
|---|
| 255 | | - |
|---|
| 256 | | - /* |
|---|
| 257 | | - * Initialize the slot info structure with some known |
|---|
| 258 | | - * good values. |
|---|
| 259 | | - */ |
|---|
| 260 | | - dbg("initializing slot %s", name); |
|---|
| 261 | | - info->power_status = cpci_get_power_status(slot); |
|---|
| 262 | | - info->attention_status = cpci_get_attention_status(slot); |
|---|
| 217 | + slot->hotplug_slot.ops = &cpci_hotplug_slot_ops; |
|---|
| 263 | 218 | |
|---|
| 264 | 219 | dbg("registering slot %s", name); |
|---|
| 265 | | - status = pci_hp_register(slot->hotplug_slot, bus, i, name); |
|---|
| 220 | + status = pci_hp_register(&slot->hotplug_slot, bus, i, name); |
|---|
| 266 | 221 | if (status) { |
|---|
| 267 | 222 | err("pci_hp_register failed with error %d", status); |
|---|
| 268 | | - goto error_info; |
|---|
| 223 | + goto error_slot; |
|---|
| 269 | 224 | } |
|---|
| 270 | 225 | dbg("slot registered with name: %s", slot_name(slot)); |
|---|
| 271 | 226 | |
|---|
| .. | .. |
|---|
| 276 | 231 | up_write(&list_rwsem); |
|---|
| 277 | 232 | } |
|---|
| 278 | 233 | return 0; |
|---|
| 279 | | -error_info: |
|---|
| 280 | | - kfree(info); |
|---|
| 281 | | -error_hpslot: |
|---|
| 282 | | - kfree(hotplug_slot); |
|---|
| 283 | 234 | error_slot: |
|---|
| 284 | 235 | kfree(slot); |
|---|
| 285 | 236 | error: |
|---|
| .. | .. |
|---|
| 305 | 256 | slots--; |
|---|
| 306 | 257 | |
|---|
| 307 | 258 | dbg("deregistering slot %s", slot_name(slot)); |
|---|
| 308 | | - pci_hp_deregister(slot->hotplug_slot); |
|---|
| 259 | + pci_hp_deregister(&slot->hotplug_slot); |
|---|
| 309 | 260 | release_slot(slot); |
|---|
| 310 | 261 | } |
|---|
| 311 | 262 | } |
|---|
| .. | .. |
|---|
| 359 | 310 | __func__, slot_name(slot)); |
|---|
| 360 | 311 | dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0)); |
|---|
| 361 | 312 | if (dev) { |
|---|
| 362 | | - if (update_adapter_status(slot->hotplug_slot, 1)) |
|---|
| 363 | | - warn("failure to update adapter file"); |
|---|
| 364 | | - if (update_latch_status(slot->hotplug_slot, 1)) |
|---|
| 365 | | - warn("failure to update latch file"); |
|---|
| 313 | + slot->adapter_status = 1; |
|---|
| 314 | + slot->latch_status = 1; |
|---|
| 366 | 315 | slot->dev = dev; |
|---|
| 367 | 316 | } |
|---|
| 368 | 317 | } |
|---|
| .. | .. |
|---|
| 424 | 373 | dbg("%s - slot %s HS_CSR (2) = %04x", |
|---|
| 425 | 374 | __func__, slot_name(slot), hs_csr); |
|---|
| 426 | 375 | |
|---|
| 427 | | - if (update_latch_status(slot->hotplug_slot, 1)) |
|---|
| 428 | | - warn("failure to update latch file"); |
|---|
| 429 | | - |
|---|
| 430 | | - if (update_adapter_status(slot->hotplug_slot, 1)) |
|---|
| 431 | | - warn("failure to update adapter file"); |
|---|
| 376 | + slot->latch_status = 1; |
|---|
| 377 | + slot->adapter_status = 1; |
|---|
| 432 | 378 | |
|---|
| 433 | 379 | cpci_led_off(slot); |
|---|
| 434 | 380 | |
|---|
| .. | .. |
|---|
| 449 | 395 | __func__, slot_name(slot), hs_csr); |
|---|
| 450 | 396 | |
|---|
| 451 | 397 | if (!slot->extracting) { |
|---|
| 452 | | - if (update_latch_status(slot->hotplug_slot, 0)) |
|---|
| 453 | | - warn("failure to update latch file"); |
|---|
| 454 | | - |
|---|
| 398 | + slot->latch_status = 0; |
|---|
| 455 | 399 | slot->extracting = 1; |
|---|
| 456 | 400 | atomic_inc(&extracting); |
|---|
| 457 | 401 | } |
|---|
| .. | .. |
|---|
| 465 | 409 | */ |
|---|
| 466 | 410 | err("card in slot %s was improperly removed", |
|---|
| 467 | 411 | slot_name(slot)); |
|---|
| 468 | | - if (update_adapter_status(slot->hotplug_slot, 0)) |
|---|
| 469 | | - warn("failure to update adapter file"); |
|---|
| 412 | + slot->adapter_status = 0; |
|---|
| 470 | 413 | slot->extracting = 0; |
|---|
| 471 | 414 | atomic_dec(&extracting); |
|---|
| 472 | 415 | } |
|---|
| .. | .. |
|---|
| 615 | 558 | goto cleanup_null; |
|---|
| 616 | 559 | list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) { |
|---|
| 617 | 560 | list_del(&slot->slot_list); |
|---|
| 618 | | - pci_hp_deregister(slot->hotplug_slot); |
|---|
| 561 | + pci_hp_deregister(&slot->hotplug_slot); |
|---|
| 619 | 562 | release_slot(slot); |
|---|
| 620 | 563 | } |
|---|
| 621 | 564 | cleanup_null: |
|---|
| 622 | 565 | up_write(&list_rwsem); |
|---|
| 623 | | - return; |
|---|
| 624 | 566 | } |
|---|
| 625 | 567 | |
|---|
| 626 | 568 | int |
|---|