| 1 | /* |
| 2 | * Filename: core.c |
| 3 | * |
| 4 | * |
| 5 | * Authors: Joshua Morris <josh.h.morris@us.ibm.com> |
| 6 | * Philip Kelleher <pjk1939@linux.vnet.ibm.com> |
| 7 | * |
| 8 | * (C) Copyright 2013 IBM Corporation |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software Foundation, |
| 22 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/reboot.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/bitops.h> |
| 33 | |
| 34 | #include <linux/genhd.h> |
| 35 | #include <linux/idr.h> |
| 36 | |
| 37 | #include "rsxx_priv.h" |
| 38 | #include "rsxx_cfg.h" |
| 39 | |
| 40 | #define NO_LEGACY 0 |
| 41 | |
| 42 | MODULE_DESCRIPTION("IBM RamSan PCIe Flash SSD Device Driver"); |
| 43 | MODULE_AUTHOR("IBM <support@ramsan.com>"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | MODULE_VERSION(DRIVER_VERSION); |
| 46 | |
| 47 | static unsigned int force_legacy = NO_LEGACY; |
| 48 | module_param(force_legacy, uint, 0444); |
| 49 | MODULE_PARM_DESC(force_legacy, "Force the use of legacy type PCI interrupts"); |
| 50 | |
| 51 | static DEFINE_IDA(rsxx_disk_ida); |
| 52 | static DEFINE_SPINLOCK(rsxx_ida_lock); |
| 53 | |
| 54 | /*----------------- Interrupt Control & Handling -------------------*/ |
| 55 | static void __enable_intr(unsigned int *mask, unsigned int intr) |
| 56 | { |
| 57 | *mask |= intr; |
| 58 | } |
| 59 | |
| 60 | static void __disable_intr(unsigned int *mask, unsigned int intr) |
| 61 | { |
| 62 | *mask &= ~intr; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * NOTE: Disabling the IER will disable the hardware interrupt. |
| 67 | * Disabling the ISR will disable the software handling of the ISR bit. |
| 68 | * |
| 69 | * Enable/Disable interrupt functions assume the card->irq_lock |
| 70 | * is held by the caller. |
| 71 | */ |
| 72 | void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr) |
| 73 | { |
| 74 | if (unlikely(card->halt)) |
| 75 | return; |
| 76 | |
| 77 | __enable_intr(&card->ier_mask, intr); |
| 78 | iowrite32(card->ier_mask, card->regmap + IER); |
| 79 | } |
| 80 | |
| 81 | void rsxx_disable_ier(struct rsxx_cardinfo *card, unsigned int intr) |
| 82 | { |
| 83 | __disable_intr(&card->ier_mask, intr); |
| 84 | iowrite32(card->ier_mask, card->regmap + IER); |
| 85 | } |
| 86 | |
| 87 | void rsxx_enable_ier_and_isr(struct rsxx_cardinfo *card, |
| 88 | unsigned int intr) |
| 89 | { |
| 90 | if (unlikely(card->halt)) |
| 91 | return; |
| 92 | |
| 93 | __enable_intr(&card->isr_mask, intr); |
| 94 | __enable_intr(&card->ier_mask, intr); |
| 95 | iowrite32(card->ier_mask, card->regmap + IER); |
| 96 | } |
| 97 | void rsxx_disable_ier_and_isr(struct rsxx_cardinfo *card, |
| 98 | unsigned int intr) |
| 99 | { |
| 100 | __disable_intr(&card->isr_mask, intr); |
| 101 | __disable_intr(&card->ier_mask, intr); |
| 102 | iowrite32(card->ier_mask, card->regmap + IER); |
| 103 | } |
| 104 | |
| 105 | static irqreturn_t rsxx_isr(int irq, void *pdata) |
| 106 | { |
| 107 | struct rsxx_cardinfo *card = pdata; |
| 108 | unsigned int isr; |
| 109 | int handled = 0; |
| 110 | int reread_isr; |
| 111 | int i; |
| 112 | |
| 113 | spin_lock(&card->irq_lock); |
| 114 | |
| 115 | do { |
| 116 | reread_isr = 0; |
| 117 | |
| 118 | isr = ioread32(card->regmap + ISR); |
| 119 | if (isr == 0xffffffff) { |
| 120 | /* |
| 121 | * A few systems seem to have an intermittent issue |
| 122 | * where PCI reads return all Fs, but retrying the read |
| 123 | * a little later will return as expected. |
| 124 | */ |
| 125 | dev_info(CARD_TO_DEV(card), |
| 126 | "ISR = 0xFFFFFFFF, retrying later\n"); |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | isr &= card->isr_mask; |
| 131 | if (!isr) |
| 132 | break; |
| 133 | |
| 134 | for (i = 0; i < card->n_targets; i++) { |
| 135 | if (isr & CR_INTR_DMA(i)) { |
| 136 | if (card->ier_mask & CR_INTR_DMA(i)) { |
| 137 | rsxx_disable_ier(card, CR_INTR_DMA(i)); |
| 138 | reread_isr = 1; |
| 139 | } |
| 140 | queue_work(card->ctrl[i].done_wq, |
| 141 | &card->ctrl[i].dma_done_work); |
| 142 | handled++; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (isr & CR_INTR_CREG) { |
| 147 | schedule_work(&card->creg_ctrl.done_work); |
| 148 | handled++; |
| 149 | } |
| 150 | |
| 151 | if (isr & CR_INTR_EVENT) { |
| 152 | schedule_work(&card->event_work); |
| 153 | rsxx_disable_ier_and_isr(card, CR_INTR_EVENT); |
| 154 | handled++; |
| 155 | } |
| 156 | } while (reread_isr); |
| 157 | |
| 158 | spin_unlock(&card->irq_lock); |
| 159 | |
| 160 | return handled ? IRQ_HANDLED : IRQ_NONE; |
| 161 | } |
| 162 | |
| 163 | /*----------------- Card Event Handler -------------------*/ |
| 164 | static char *rsxx_card_state_to_str(unsigned int state) |
| 165 | { |
| 166 | static char *state_strings[] = { |
| 167 | "Unknown", "Shutdown", "Starting", "Formatting", |
| 168 | "Uninitialized", "Good", "Shutting Down", |
| 169 | "Fault", "Read Only Fault", "dStroying" |
| 170 | }; |
| 171 | |
| 172 | return state_strings[ffs(state)]; |
| 173 | } |
| 174 | |
| 175 | static void card_state_change(struct rsxx_cardinfo *card, |
| 176 | unsigned int new_state) |
| 177 | { |
| 178 | int st; |
| 179 | |
| 180 | dev_info(CARD_TO_DEV(card), |
| 181 | "card state change detected.(%s -> %s)\n", |
| 182 | rsxx_card_state_to_str(card->state), |
| 183 | rsxx_card_state_to_str(new_state)); |
| 184 | |
| 185 | card->state = new_state; |
| 186 | |
| 187 | /* Don't attach DMA interfaces if the card has an invalid config */ |
| 188 | if (!card->config_valid) |
| 189 | return; |
| 190 | |
| 191 | switch (new_state) { |
| 192 | case CARD_STATE_RD_ONLY_FAULT: |
| 193 | dev_crit(CARD_TO_DEV(card), |
| 194 | "Hardware has entered read-only mode!\n"); |
| 195 | /* |
| 196 | * Fall through so the DMA devices can be attached and |
| 197 | * the user can attempt to pull off their data. |
| 198 | */ |
| 199 | case CARD_STATE_GOOD: |
| 200 | st = rsxx_get_card_size8(card, &card->size8); |
| 201 | if (st) |
| 202 | dev_err(CARD_TO_DEV(card), |
| 203 | "Failed attaching DMA devices\n"); |
| 204 | |
| 205 | if (card->config_valid) |
| 206 | set_capacity(card->gendisk, card->size8 >> 9); |
| 207 | break; |
| 208 | |
| 209 | case CARD_STATE_FAULT: |
| 210 | dev_crit(CARD_TO_DEV(card), |
| 211 | "Hardware Fault reported!\n"); |
| 212 | /* Fall through. */ |
| 213 | |
| 214 | /* Everything else, detach DMA interface if it's attached. */ |
| 215 | case CARD_STATE_SHUTDOWN: |
| 216 | case CARD_STATE_STARTING: |
| 217 | case CARD_STATE_FORMATTING: |
| 218 | case CARD_STATE_UNINITIALIZED: |
| 219 | case CARD_STATE_SHUTTING_DOWN: |
| 220 | /* |
| 221 | * dStroy is a term coined by marketing to represent the low level |
| 222 | * secure erase. |
| 223 | */ |
| 224 | case CARD_STATE_DSTROYING: |
| 225 | set_capacity(card->gendisk, 0); |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static void card_event_handler(struct work_struct *work) |
| 231 | { |
| 232 | struct rsxx_cardinfo *card; |
| 233 | unsigned int state; |
| 234 | unsigned long flags; |
| 235 | int st; |
| 236 | |
| 237 | card = container_of(work, struct rsxx_cardinfo, event_work); |
| 238 | |
| 239 | if (unlikely(card->halt)) |
| 240 | return; |
| 241 | |
| 242 | /* |
| 243 | * Enable the interrupt now to avoid any weird race conditions where a |
| 244 | * state change might occur while rsxx_get_card_state() is |
| 245 | * processing a returned creg cmd. |
| 246 | */ |
| 247 | spin_lock_irqsave(&card->irq_lock, flags); |
| 248 | rsxx_enable_ier_and_isr(card, CR_INTR_EVENT); |
| 249 | spin_unlock_irqrestore(&card->irq_lock, flags); |
| 250 | |
| 251 | st = rsxx_get_card_state(card, &state); |
| 252 | if (st) { |
| 253 | dev_info(CARD_TO_DEV(card), |
| 254 | "Failed reading state after event.\n"); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (card->state != state) |
| 259 | card_state_change(card, state); |
| 260 | |
| 261 | if (card->creg_ctrl.creg_stats.stat & CREG_STAT_LOG_PENDING) |
| 262 | rsxx_read_hw_log(card); |
| 263 | } |
| 264 | |
| 265 | /*----------------- Card Operations -------------------*/ |
| 266 | static int card_shutdown(struct rsxx_cardinfo *card) |
| 267 | { |
| 268 | unsigned int state; |
| 269 | signed long start; |
| 270 | const int timeout = msecs_to_jiffies(120000); |
| 271 | int st; |
| 272 | |
| 273 | /* We can't issue a shutdown if the card is in a transition state */ |
| 274 | start = jiffies; |
| 275 | do { |
| 276 | st = rsxx_get_card_state(card, &state); |
| 277 | if (st) |
| 278 | return st; |
| 279 | } while (state == CARD_STATE_STARTING && |
| 280 | (jiffies - start < timeout)); |
| 281 | |
| 282 | if (state == CARD_STATE_STARTING) |
| 283 | return -ETIMEDOUT; |
| 284 | |
| 285 | /* Only issue a shutdown if we need to */ |
| 286 | if ((state != CARD_STATE_SHUTTING_DOWN) && |
| 287 | (state != CARD_STATE_SHUTDOWN)) { |
| 288 | st = rsxx_issue_card_cmd(card, CARD_CMD_SHUTDOWN); |
| 289 | if (st) |
| 290 | return st; |
| 291 | } |
| 292 | |
| 293 | start = jiffies; |
| 294 | do { |
| 295 | st = rsxx_get_card_state(card, &state); |
| 296 | if (st) |
| 297 | return st; |
| 298 | } while (state != CARD_STATE_SHUTDOWN && |
| 299 | (jiffies - start < timeout)); |
| 300 | |
| 301 | if (state != CARD_STATE_SHUTDOWN) |
| 302 | return -ETIMEDOUT; |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /*----------------- Driver Initialization & Setup -------------------*/ |
| 308 | /* Returns: 0 if the driver is compatible with the device |
| 309 | -1 if the driver is NOT compatible with the device */ |
| 310 | static int rsxx_compatibility_check(struct rsxx_cardinfo *card) |
| 311 | { |
| 312 | unsigned char pci_rev; |
| 313 | |
| 314 | pci_read_config_byte(card->dev, PCI_REVISION_ID, &pci_rev); |
| 315 | |
| 316 | if (pci_rev > RS70_PCI_REV_SUPPORTED) |
| 317 | return -1; |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int rsxx_pci_probe(struct pci_dev *dev, |
| 322 | const struct pci_device_id *id) |
| 323 | { |
| 324 | struct rsxx_cardinfo *card; |
| 325 | int st; |
| 326 | |
| 327 | dev_info(&dev->dev, "PCI-Flash SSD discovered\n"); |
| 328 | |
| 329 | card = kzalloc(sizeof(*card), GFP_KERNEL); |
| 330 | if (!card) |
| 331 | return -ENOMEM; |
| 332 | |
| 333 | card->dev = dev; |
| 334 | pci_set_drvdata(dev, card); |
| 335 | |
| 336 | do { |
| 337 | if (!ida_pre_get(&rsxx_disk_ida, GFP_KERNEL)) { |
| 338 | st = -ENOMEM; |
| 339 | goto failed_ida_get; |
| 340 | } |
| 341 | |
| 342 | spin_lock(&rsxx_ida_lock); |
| 343 | st = ida_get_new(&rsxx_disk_ida, &card->disk_id); |
| 344 | spin_unlock(&rsxx_ida_lock); |
| 345 | } while (st == -EAGAIN); |
| 346 | |
| 347 | if (st) |
| 348 | goto failed_ida_get; |
| 349 | |
| 350 | st = pci_enable_device(dev); |
| 351 | if (st) |
| 352 | goto failed_enable; |
| 353 | |
| 354 | pci_set_master(dev); |
| 355 | pci_set_dma_max_seg_size(dev, RSXX_HW_BLK_SIZE); |
| 356 | |
| 357 | st = pci_set_dma_mask(dev, DMA_BIT_MASK(64)); |
| 358 | if (st) { |
| 359 | dev_err(CARD_TO_DEV(card), |
| 360 | "No usable DMA configuration,aborting\n"); |
| 361 | goto failed_dma_mask; |
| 362 | } |
| 363 | |
| 364 | st = pci_request_regions(dev, DRIVER_NAME); |
| 365 | if (st) { |
| 366 | dev_err(CARD_TO_DEV(card), |
| 367 | "Failed to request memory region\n"); |
| 368 | goto failed_request_regions; |
| 369 | } |
| 370 | |
| 371 | if (pci_resource_len(dev, 0) == 0) { |
| 372 | dev_err(CARD_TO_DEV(card), "BAR0 has length 0!\n"); |
| 373 | st = -ENOMEM; |
| 374 | goto failed_iomap; |
| 375 | } |
| 376 | |
| 377 | card->regmap = pci_iomap(dev, 0, 0); |
| 378 | if (!card->regmap) { |
| 379 | dev_err(CARD_TO_DEV(card), "Failed to map BAR0\n"); |
| 380 | st = -ENOMEM; |
| 381 | goto failed_iomap; |
| 382 | } |
| 383 | |
| 384 | spin_lock_init(&card->irq_lock); |
| 385 | card->halt = 0; |
| 386 | |
| 387 | spin_lock_irq(&card->irq_lock); |
| 388 | rsxx_disable_ier_and_isr(card, CR_INTR_ALL); |
| 389 | spin_unlock_irq(&card->irq_lock); |
| 390 | |
| 391 | if (!force_legacy) { |
| 392 | st = pci_enable_msi(dev); |
| 393 | if (st) |
| 394 | dev_warn(CARD_TO_DEV(card), |
| 395 | "Failed to enable MSI\n"); |
| 396 | } |
| 397 | |
| 398 | st = request_irq(dev->irq, rsxx_isr, IRQF_DISABLED | IRQF_SHARED, |
| 399 | DRIVER_NAME, card); |
| 400 | if (st) { |
| 401 | dev_err(CARD_TO_DEV(card), |
| 402 | "Failed requesting IRQ%d\n", dev->irq); |
| 403 | goto failed_irq; |
| 404 | } |
| 405 | |
| 406 | /************* Setup Processor Command Interface *************/ |
| 407 | rsxx_creg_setup(card); |
| 408 | |
| 409 | spin_lock_irq(&card->irq_lock); |
| 410 | rsxx_enable_ier_and_isr(card, CR_INTR_CREG); |
| 411 | spin_unlock_irq(&card->irq_lock); |
| 412 | |
| 413 | st = rsxx_compatibility_check(card); |
| 414 | if (st) { |
| 415 | dev_warn(CARD_TO_DEV(card), |
| 416 | "Incompatible driver detected. Please update the driver.\n"); |
| 417 | st = -EINVAL; |
| 418 | goto failed_compatiblity_check; |
| 419 | } |
| 420 | |
| 421 | /************* Load Card Config *************/ |
| 422 | st = rsxx_load_config(card); |
| 423 | if (st) |
| 424 | dev_err(CARD_TO_DEV(card), |
| 425 | "Failed loading card config\n"); |
| 426 | |
| 427 | /************* Setup DMA Engine *************/ |
| 428 | st = rsxx_get_num_targets(card, &card->n_targets); |
| 429 | if (st) |
| 430 | dev_info(CARD_TO_DEV(card), |
| 431 | "Failed reading the number of DMA targets\n"); |
| 432 | |
| 433 | card->ctrl = kzalloc(card->n_targets * sizeof(*card->ctrl), GFP_KERNEL); |
| 434 | if (!card->ctrl) { |
| 435 | st = -ENOMEM; |
| 436 | goto failed_dma_setup; |
| 437 | } |
| 438 | |
| 439 | st = rsxx_dma_setup(card); |
| 440 | if (st) { |
| 441 | dev_info(CARD_TO_DEV(card), |
| 442 | "Failed to setup DMA engine\n"); |
| 443 | goto failed_dma_setup; |
| 444 | } |
| 445 | |
| 446 | /************* Setup Card Event Handler *************/ |
| 447 | INIT_WORK(&card->event_work, card_event_handler); |
| 448 | |
| 449 | st = rsxx_setup_dev(card); |
| 450 | if (st) |
| 451 | goto failed_create_dev; |
| 452 | |
| 453 | rsxx_get_card_state(card, &card->state); |
| 454 | |
| 455 | dev_info(CARD_TO_DEV(card), |
| 456 | "card state: %s\n", |
| 457 | rsxx_card_state_to_str(card->state)); |
| 458 | |
| 459 | /* |
| 460 | * Now that the DMA Engine and devices have been setup, |
| 461 | * we can enable the event interrupt(it kicks off actions in |
| 462 | * those layers so we couldn't enable it right away.) |
| 463 | */ |
| 464 | spin_lock_irq(&card->irq_lock); |
| 465 | rsxx_enable_ier_and_isr(card, CR_INTR_EVENT); |
| 466 | spin_unlock_irq(&card->irq_lock); |
| 467 | |
| 468 | if (card->state == CARD_STATE_SHUTDOWN) { |
| 469 | st = rsxx_issue_card_cmd(card, CARD_CMD_STARTUP); |
| 470 | if (st) |
| 471 | dev_crit(CARD_TO_DEV(card), |
| 472 | "Failed issuing card startup\n"); |
| 473 | } else if (card->state == CARD_STATE_GOOD || |
| 474 | card->state == CARD_STATE_RD_ONLY_FAULT) { |
| 475 | st = rsxx_get_card_size8(card, &card->size8); |
| 476 | if (st) |
| 477 | card->size8 = 0; |
| 478 | } |
| 479 | |
| 480 | rsxx_attach_dev(card); |
| 481 | |
| 482 | return 0; |
| 483 | |
| 484 | failed_create_dev: |
| 485 | rsxx_dma_destroy(card); |
| 486 | failed_dma_setup: |
| 487 | failed_compatiblity_check: |
| 488 | spin_lock_irq(&card->irq_lock); |
| 489 | rsxx_disable_ier_and_isr(card, CR_INTR_ALL); |
| 490 | spin_unlock_irq(&card->irq_lock); |
| 491 | free_irq(dev->irq, card); |
| 492 | if (!force_legacy) |
| 493 | pci_disable_msi(dev); |
| 494 | failed_irq: |
| 495 | pci_iounmap(dev, card->regmap); |
| 496 | failed_iomap: |
| 497 | pci_release_regions(dev); |
| 498 | failed_request_regions: |
| 499 | failed_dma_mask: |
| 500 | pci_disable_device(dev); |
| 501 | failed_enable: |
| 502 | spin_lock(&rsxx_ida_lock); |
| 503 | ida_remove(&rsxx_disk_ida, card->disk_id); |
| 504 | spin_unlock(&rsxx_ida_lock); |
| 505 | failed_ida_get: |
| 506 | kfree(card); |
| 507 | |
| 508 | return st; |
| 509 | } |
| 510 | |
| 511 | static void rsxx_pci_remove(struct pci_dev *dev) |
| 512 | { |
| 513 | struct rsxx_cardinfo *card = pci_get_drvdata(dev); |
| 514 | unsigned long flags; |
| 515 | int st; |
| 516 | int i; |
| 517 | |
| 518 | if (!card) |
| 519 | return; |
| 520 | |
| 521 | dev_info(CARD_TO_DEV(card), |
| 522 | "Removing PCI-Flash SSD.\n"); |
| 523 | |
| 524 | rsxx_detach_dev(card); |
| 525 | |
| 526 | for (i = 0; i < card->n_targets; i++) { |
| 527 | spin_lock_irqsave(&card->irq_lock, flags); |
| 528 | rsxx_disable_ier_and_isr(card, CR_INTR_DMA(i)); |
| 529 | spin_unlock_irqrestore(&card->irq_lock, flags); |
| 530 | } |
| 531 | |
| 532 | st = card_shutdown(card); |
| 533 | if (st) |
| 534 | dev_crit(CARD_TO_DEV(card), "Shutdown failed!\n"); |
| 535 | |
| 536 | /* Sync outstanding event handlers. */ |
| 537 | spin_lock_irqsave(&card->irq_lock, flags); |
| 538 | rsxx_disable_ier_and_isr(card, CR_INTR_EVENT); |
| 539 | spin_unlock_irqrestore(&card->irq_lock, flags); |
| 540 | |
| 541 | /* Prevent work_structs from re-queuing themselves. */ |
| 542 | card->halt = 1; |
| 543 | |
| 544 | cancel_work_sync(&card->event_work); |
| 545 | |
| 546 | rsxx_destroy_dev(card); |
| 547 | rsxx_dma_destroy(card); |
| 548 | |
| 549 | spin_lock_irqsave(&card->irq_lock, flags); |
| 550 | rsxx_disable_ier_and_isr(card, CR_INTR_ALL); |
| 551 | spin_unlock_irqrestore(&card->irq_lock, flags); |
| 552 | free_irq(dev->irq, card); |
| 553 | |
| 554 | if (!force_legacy) |
| 555 | pci_disable_msi(dev); |
| 556 | |
| 557 | rsxx_creg_destroy(card); |
| 558 | |
| 559 | pci_iounmap(dev, card->regmap); |
| 560 | |
| 561 | pci_disable_device(dev); |
| 562 | pci_release_regions(dev); |
| 563 | |
| 564 | kfree(card); |
| 565 | } |
| 566 | |
| 567 | static int rsxx_pci_suspend(struct pci_dev *dev, pm_message_t state) |
| 568 | { |
| 569 | /* We don't support suspend at this time. */ |
| 570 | return -ENOSYS; |
| 571 | } |
| 572 | |
| 573 | static void rsxx_pci_shutdown(struct pci_dev *dev) |
| 574 | { |
| 575 | struct rsxx_cardinfo *card = pci_get_drvdata(dev); |
| 576 | unsigned long flags; |
| 577 | int i; |
| 578 | |
| 579 | if (!card) |
| 580 | return; |
| 581 | |
| 582 | dev_info(CARD_TO_DEV(card), "Shutting down PCI-Flash SSD.\n"); |
| 583 | |
| 584 | rsxx_detach_dev(card); |
| 585 | |
| 586 | for (i = 0; i < card->n_targets; i++) { |
| 587 | spin_lock_irqsave(&card->irq_lock, flags); |
| 588 | rsxx_disable_ier_and_isr(card, CR_INTR_DMA(i)); |
| 589 | spin_unlock_irqrestore(&card->irq_lock, flags); |
| 590 | } |
| 591 | |
| 592 | card_shutdown(card); |
| 593 | } |
| 594 | |
| 595 | static DEFINE_PCI_DEVICE_TABLE(rsxx_pci_ids) = { |
| 596 | {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS70_FLASH)}, |
| 597 | {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS70D_FLASH)}, |
| 598 | {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS80_FLASH)}, |
| 599 | {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS81_FLASH)}, |
| 600 | {0,}, |
| 601 | }; |
| 602 | |
| 603 | MODULE_DEVICE_TABLE(pci, rsxx_pci_ids); |
| 604 | |
| 605 | static struct pci_driver rsxx_pci_driver = { |
| 606 | .name = DRIVER_NAME, |
| 607 | .id_table = rsxx_pci_ids, |
| 608 | .probe = rsxx_pci_probe, |
| 609 | .remove = rsxx_pci_remove, |
| 610 | .suspend = rsxx_pci_suspend, |
| 611 | .shutdown = rsxx_pci_shutdown, |
| 612 | }; |
| 613 | |
| 614 | static int __init rsxx_core_init(void) |
| 615 | { |
| 616 | int st; |
| 617 | |
| 618 | st = rsxx_dev_init(); |
| 619 | if (st) |
| 620 | return st; |
| 621 | |
| 622 | st = rsxx_dma_init(); |
| 623 | if (st) |
| 624 | goto dma_init_failed; |
| 625 | |
| 626 | st = rsxx_creg_init(); |
| 627 | if (st) |
| 628 | goto creg_init_failed; |
| 629 | |
| 630 | return pci_register_driver(&rsxx_pci_driver); |
| 631 | |
| 632 | creg_init_failed: |
| 633 | rsxx_dma_cleanup(); |
| 634 | dma_init_failed: |
| 635 | rsxx_dev_cleanup(); |
| 636 | |
| 637 | return st; |
| 638 | } |
| 639 | |
| 640 | static void __exit rsxx_core_cleanup(void) |
| 641 | { |
| 642 | pci_unregister_driver(&rsxx_pci_driver); |
| 643 | rsxx_creg_cleanup(); |
| 644 | rsxx_dma_cleanup(); |
| 645 | rsxx_dev_cleanup(); |
| 646 | } |
| 647 | |
| 648 | module_init(rsxx_core_init); |
| 649 | module_exit(rsxx_core_cleanup); |