Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: IBM RamSan 70/80 driver fixes

This patch includes the following driver fixes for the
IBM RamSan 70/80 driver:

o Changed the creg_ctrl lock from a mutex to a spinlock.
o Added a count check for ioctl calls.
o Removed unnecessary casting of void pointers.
o Made every function static that needed to be.
o Added comments to explain things more thoroughly.

Signed-off-by: Philip J Kelleher <pjk1939@linux.vnet.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Philip J Kelleher and committed by
Jens Axboe
c206c709 ec8edc76

+69 -63
+2 -2
drivers/block/rsxx/config.c
··· 31 31 32 32 static void initialize_config(void *config) 33 33 { 34 - struct rsxx_card_cfg *cfg = (struct rsxx_card_cfg *) config; 34 + struct rsxx_card_cfg *cfg = config; 35 35 36 36 cfg->hdr.version = RSXX_CFG_VERSION; 37 37 ··· 97 97 98 98 99 99 /*----------------- Config Operations ------------------*/ 100 - int rsxx_save_config(struct rsxx_cardinfo *card) 100 + static int rsxx_save_config(struct rsxx_cardinfo *card) 101 101 { 102 102 struct rsxx_card_cfg cfg; 103 103 int st;
+21 -23
drivers/block/rsxx/core.c
··· 102 102 iowrite32(card->ier_mask, card->regmap + IER); 103 103 } 104 104 105 - irqreturn_t rsxx_isr(int irq, void *pdata) 105 + static irqreturn_t rsxx_isr(int irq, void *pdata) 106 106 { 107 - struct rsxx_cardinfo *card = (struct rsxx_cardinfo *) pdata; 107 + struct rsxx_cardinfo *card = pdata; 108 108 unsigned int isr; 109 109 int handled = 0; 110 110 int reread_isr; ··· 161 161 } 162 162 163 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 + 164 175 static void card_state_change(struct rsxx_cardinfo *card, 165 176 unsigned int new_state) 166 177 { ··· 262 251 rsxx_read_hw_log(card); 263 252 } 264 253 265 - 266 - char *rsxx_card_state_to_str(unsigned int state) 267 - { 268 - static char *state_strings[] = { 269 - "Unknown", "Shutdown", "Starting", "Formatting", 270 - "Uninitialized", "Good", "Shutting Down", 271 - "Fault", "Read Only Fault", "dStroying" 272 - }; 273 - 274 - return state_strings[ffs(state)]; 275 - } 276 - 277 254 /*----------------- Card Operations -------------------*/ 278 255 static int card_shutdown(struct rsxx_cardinfo *card) 279 256 { ··· 322 323 const struct pci_device_id *id) 323 324 { 324 325 struct rsxx_cardinfo *card; 325 - unsigned long flags; 326 326 int st; 327 327 328 328 dev_info(&dev->dev, "PCI-Flash SSD discovered\n"); ··· 384 386 spin_lock_init(&card->irq_lock); 385 387 card->halt = 0; 386 388 387 - spin_lock_irqsave(&card->irq_lock, flags); 389 + spin_lock_irq(&card->irq_lock); 388 390 rsxx_disable_ier_and_isr(card, CR_INTR_ALL); 389 - spin_unlock_irqrestore(&card->irq_lock, flags); 391 + spin_unlock_irq(&card->irq_lock); 390 392 391 393 if (!force_legacy) { 392 394 st = pci_enable_msi(dev); ··· 406 408 /************* Setup Processor Command Interface *************/ 407 409 rsxx_creg_setup(card); 408 410 409 - spin_lock_irqsave(&card->irq_lock, flags); 411 + spin_lock_irq(&card->irq_lock); 410 412 rsxx_enable_ier_and_isr(card, CR_INTR_CREG); 411 - spin_unlock_irqrestore(&card->irq_lock, flags); 413 + spin_unlock_irq(&card->irq_lock); 412 414 413 415 st = rsxx_compatibility_check(card); 414 416 if (st) { ··· 461 463 * we can enable the event interrupt(it kicks off actions in 462 464 * those layers so we couldn't enable it right away.) 463 465 */ 464 - spin_lock_irqsave(&card->irq_lock, flags); 466 + spin_lock_irq(&card->irq_lock); 465 467 rsxx_enable_ier_and_isr(card, CR_INTR_EVENT); 466 - spin_unlock_irqrestore(&card->irq_lock, flags); 468 + spin_unlock_irq(&card->irq_lock); 467 469 468 470 if (card->state == CARD_STATE_SHUTDOWN) { 469 471 st = rsxx_issue_card_cmd(card, CARD_CMD_STARTUP); ··· 485 487 rsxx_dma_destroy(card); 486 488 failed_dma_setup: 487 489 failed_compatiblity_check: 488 - spin_lock_irqsave(&card->irq_lock, flags); 490 + spin_lock_irq(&card->irq_lock); 489 491 rsxx_disable_ier_and_isr(card, CR_INTR_ALL); 490 - spin_unlock_irqrestore(&card->irq_lock, flags); 492 + spin_unlock_irq(&card->irq_lock); 491 493 free_irq(dev->irq, card); 492 494 if (!force_legacy) 493 495 pci_disable_msi(dev);
+37 -22
drivers/block/rsxx/cregs.c
··· 107 107 * Spin lock is needed because this can be called in atomic/interrupt 108 108 * context. 109 109 */ 110 - spin_lock_bh(&card->creg_ctrl.pop_lock); 110 + spin_lock_bh(&card->creg_ctrl.lock); 111 111 cmd = card->creg_ctrl.active_cmd; 112 112 card->creg_ctrl.active_cmd = NULL; 113 - spin_unlock_bh(&card->creg_ctrl.pop_lock); 113 + spin_unlock_bh(&card->creg_ctrl.lock); 114 114 115 115 return cmd; 116 116 } ··· 126 126 cmd->buf, cmd->stream); 127 127 } 128 128 129 - /* Data copy must complete before initiating the command. */ 129 + /* 130 + * Data copy must complete before initiating the command. This is 131 + * needed for weakly ordered processors (i.e. PowerPC), so that all 132 + * neccessary registers are written before we kick the hardware. 133 + */ 130 134 wmb(); 131 135 132 136 /* Setting the valid bit will kick off the command. */ ··· 196 192 cmd->cb_private = cb_private; 197 193 cmd->status = 0; 198 194 199 - mutex_lock(&card->creg_ctrl.lock); 195 + spin_lock(&card->creg_ctrl.lock); 200 196 list_add_tail(&cmd->list, &card->creg_ctrl.queue); 201 197 card->creg_ctrl.q_depth++; 202 198 creg_kick_queue(card); 203 - mutex_unlock(&card->creg_ctrl.lock); 199 + spin_unlock(&card->creg_ctrl.lock); 204 200 205 201 return 0; 206 202 } ··· 223 219 224 220 kmem_cache_free(creg_cmd_pool, cmd); 225 221 226 - spin_lock(&card->creg_ctrl.pop_lock); 222 + 223 + spin_lock(&card->creg_ctrl.lock); 227 224 card->creg_ctrl.active = 0; 228 225 creg_kick_queue(card); 229 - spin_unlock(&card->creg_ctrl.pop_lock); 226 + spin_unlock(&card->creg_ctrl.lock); 230 227 } 231 228 232 229 ··· 296 291 297 292 kmem_cache_free(creg_cmd_pool, cmd); 298 293 299 - mutex_lock(&card->creg_ctrl.lock); 294 + spin_lock(&card->creg_ctrl.lock); 300 295 card->creg_ctrl.active = 0; 301 296 creg_kick_queue(card); 302 - mutex_unlock(&card->creg_ctrl.lock); 297 + spin_unlock(&card->creg_ctrl.lock); 303 298 } 304 299 305 300 static void creg_reset(struct rsxx_cardinfo *card) ··· 308 303 struct creg_cmd *tmp; 309 304 unsigned long flags; 310 305 306 + /* 307 + * mutex_trylock is used here because if reset_lock is taken then a 308 + * reset is already happening. So, we can just go ahead and return. 309 + */ 311 310 if (!mutex_trylock(&card->creg_ctrl.reset_lock)) 312 311 return; 313 312 ··· 324 315 "Resetting creg interface for recovery\n"); 325 316 326 317 /* Cancel outstanding commands */ 327 - mutex_lock(&card->creg_ctrl.lock); 318 + spin_lock(&card->creg_ctrl.lock); 328 319 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { 329 320 list_del(&cmd->list); 330 321 card->creg_ctrl.q_depth--; ··· 345 336 346 337 card->creg_ctrl.active = 0; 347 338 } 348 - mutex_unlock(&card->creg_ctrl.lock); 339 + spin_unlock(&card->creg_ctrl.lock); 349 340 350 341 card->creg_ctrl.reset = 0; 351 342 spin_lock_irqsave(&card->irq_lock, flags); ··· 368 359 { 369 360 struct creg_completion *cmd_completion; 370 361 371 - cmd_completion = (struct creg_completion *)cmd->cb_private; 362 + cmd_completion = cmd->cb_private; 372 363 BUG_ON(!cmd_completion); 373 364 374 365 cmd_completion->st = st; ··· 389 380 unsigned long timeout; 390 381 int st; 391 382 392 - INIT_COMPLETION(cmd_done); 393 383 completion.cmd_done = &cmd_done; 394 384 completion.st = 0; 395 385 completion.creg_status = 0; ··· 398 390 if (st) 399 391 return st; 400 392 393 + /* 394 + * This timeout is neccessary for unresponsive hardware. The additional 395 + * 20 seconds to used to guarantee that each cregs requests has time to 396 + * complete. 397 + */ 401 398 timeout = msecs_to_jiffies((CREG_TIMEOUT_MSEC * 402 - card->creg_ctrl.q_depth) + 20000); 399 + card->creg_ctrl.q_depth) + 20000); 403 400 404 401 /* 405 402 * The creg interface is guaranteed to complete. It has a timeout ··· 456 443 if (st) 457 444 return st; 458 445 459 - data = (void *)((char *)data + xfer); 446 + data = (char *)data + xfer; 460 447 addr += xfer; 461 448 size8 -= xfer; 462 449 } while (size8); ··· 571 558 } 572 559 573 560 /* 574 - * The substrncpy() function copies to string(up to count bytes) point to by src 575 - * (including the terminating '\0' character) to dest. Returns the number of 576 - * bytes copied to dest. 561 + * The substrncpy function copies the src string (which includes the 562 + * terminating '\0' character), up to the count into the dest pointer. 563 + * Returns the number of bytes copied to dest. 577 564 */ 578 565 static int substrncpy(char *dest, const char *src, int count) 579 566 { ··· 670 657 if (st) 671 658 return -EFAULT; 672 659 660 + if (cmd.cnt > RSXX_MAX_REG_CNT) 661 + return -EFAULT; 662 + 673 663 st = issue_reg_cmd(card, &cmd, read); 674 664 if (st) 675 665 return st; ··· 698 682 INIT_WORK(&card->creg_ctrl.done_work, creg_cmd_done); 699 683 mutex_init(&card->creg_ctrl.reset_lock); 700 684 INIT_LIST_HEAD(&card->creg_ctrl.queue); 701 - mutex_init(&card->creg_ctrl.lock); 702 - spin_lock_init(&card->creg_ctrl.pop_lock); 685 + spin_lock_init(&card->creg_ctrl.lock); 703 686 setup_timer(&card->creg_ctrl.cmd_timer, creg_cmd_timed_out, 704 687 (unsigned long) card); 705 688 ··· 712 697 int cnt = 0; 713 698 714 699 /* Cancel outstanding commands */ 715 - mutex_lock(&card->creg_ctrl.lock); 700 + spin_lock(&card->creg_ctrl.lock); 716 701 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { 717 702 list_del(&cmd->list); 718 703 if (cmd->cb) ··· 737 722 "Canceled active creg command\n"); 738 723 kmem_cache_free(creg_cmd_pool, cmd); 739 724 } 740 - mutex_unlock(&card->creg_ctrl.lock); 725 + spin_unlock(&card->creg_ctrl.lock); 741 726 742 727 cancel_work_sync(&card->creg_ctrl.done_work); 743 728 }
+1 -1
drivers/block/rsxx/dev.c
··· 149 149 void *cb_data, 150 150 unsigned int error) 151 151 { 152 - struct rsxx_bio_meta *meta = (struct rsxx_bio_meta *)cb_data; 152 + struct rsxx_bio_meta *meta = cb_data; 153 153 154 154 if (error) 155 155 atomic_set(&meta->error, 1);
+5 -5
drivers/block/rsxx/dma.c
··· 102 102 103 103 104 104 /*----------------- Misc Utility Functions -------------------*/ 105 - unsigned int rsxx_addr8_to_laddr(u64 addr8, struct rsxx_cardinfo *card) 105 + static unsigned int rsxx_addr8_to_laddr(u64 addr8, struct rsxx_cardinfo *card) 106 106 { 107 107 unsigned long long tgt_addr8; 108 108 ··· 113 113 return tgt_addr8; 114 114 } 115 115 116 - unsigned int rsxx_get_dma_tgt(struct rsxx_cardinfo *card, u64 addr8) 116 + static unsigned int rsxx_get_dma_tgt(struct rsxx_cardinfo *card, u64 addr8) 117 117 { 118 118 unsigned int tgt; 119 119 ··· 757 757 INIT_LIST_HEAD(&ctrl->queue); 758 758 759 759 setup_timer(&ctrl->activity_timer, dma_engine_stalled, 760 - (unsigned long)ctrl); 760 + (unsigned long)ctrl); 761 761 762 762 ctrl->issue_wq = alloc_ordered_workqueue(DRIVER_NAME"_issue", 0); 763 763 if (!ctrl->issue_wq) ··· 803 803 return 0; 804 804 } 805 805 806 - int rsxx_dma_stripe_setup(struct rsxx_cardinfo *card, 806 + static int rsxx_dma_stripe_setup(struct rsxx_cardinfo *card, 807 807 unsigned int stripe_size8) 808 808 { 809 809 if (!is_power_of_2(stripe_size8)) { ··· 834 834 return 0; 835 835 } 836 836 837 - int rsxx_dma_configure(struct rsxx_cardinfo *card) 837 + static int rsxx_dma_configure(struct rsxx_cardinfo *card) 838 838 { 839 839 u32 intr_coal; 840 840
+2
drivers/block/rsxx/rsxx.h
··· 35 35 __u32 data[8]; 36 36 }; 37 37 38 + #define RSXX_MAX_REG_CNT (8 * (sizeof(__u32))) 39 + 38 40 #define RSXX_IOC_MAGIC 'r' 39 41 40 42 #define RSXX_GETREG _IOWR(RSXX_IOC_MAGIC, 0x20, struct rsxx_reg_access)
+1 -10
drivers/block/rsxx/rsxx_priv.h
··· 127 127 128 128 /* Embedded CPU Communication */ 129 129 struct { 130 - struct mutex lock; 130 + spinlock_t lock; 131 131 bool active; 132 132 struct creg_cmd *active_cmd; 133 133 struct work_struct done_work; ··· 141 141 } creg_stats; 142 142 struct timer_list cmd_timer; 143 143 struct mutex reset_lock; 144 - spinlock_t pop_lock; 145 144 int reset; 146 145 } creg_ctrl; 147 146 ··· 335 336 336 337 /***** config.c *****/ 337 338 int rsxx_load_config(struct rsxx_cardinfo *card); 338 - int rsxx_save_config(struct rsxx_cardinfo *card); 339 339 340 340 /***** core.c *****/ 341 341 void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr); ··· 343 345 unsigned int intr); 344 346 void rsxx_disable_ier_and_isr(struct rsxx_cardinfo *card, 345 347 unsigned int intr); 346 - char *rsxx_card_state_to_str(unsigned int state); 347 - irqreturn_t rsxx_isr(int irq, void *pdata); 348 348 349 349 /***** dev.c *****/ 350 350 int rsxx_attach_dev(struct rsxx_cardinfo *card); ··· 360 364 void rsxx_dma_destroy(struct rsxx_cardinfo *card); 361 365 int rsxx_dma_init(void); 362 366 void rsxx_dma_cleanup(void); 363 - int rsxx_dma_configure(struct rsxx_cardinfo *card); 364 367 int rsxx_dma_queue_bio(struct rsxx_cardinfo *card, 365 368 struct bio *bio, 366 369 atomic_t *n_dmas, 367 370 rsxx_dma_cb cb, 368 371 void *cb_data); 369 - int rsxx_dma_stripe_setup(struct rsxx_cardinfo *card, 370 - unsigned int stripe_size8); 371 - unsigned int rsxx_get_dma_tgt(struct rsxx_cardinfo *card, u64 addr8); 372 - unsigned int rsxx_addr8_to_laddr(u64 addr8, struct rsxx_cardinfo *card); 373 372 374 373 /***** cregs.c *****/ 375 374 int rsxx_creg_write(struct rsxx_cardinfo *card, u32 addr,