block: IBM RamSan 70/80 device driver.
PATCH v2 1/1 block: IBM RamSan 70/80 device driver.
From: Joshua H Morris <[email protected]>
Philip J Kelleher <[email protected]>
This patch includes the device driver for the IBM RamSan family of PCI SSD flash storage cards. This driver will inlcude support for the RamSan 70 and 80. The driver presents a block device for device I/O.
-------------------------------------------------------------------------------
This update addresses all issues raised thus far. Changes include:
o Moved blk_queue_max_discard_sectors into the 'discard supported' if statement.
o Changed email address to linux.vnet.ibm.com
drivers/block/Kconfig +10 -0
@@ -544,4 +544,14 @@ config BLK_DEV_RBD If unsure, say N. +config BLK_DEV_RSXX + tristate "RamSam PCIe Flash SSD Device Driver" + depends on PCI + help + Device driver for IBM's high speed PCIe SSD + storage devices: RamSan-70 and RamSan-80. + + To compile this driver as a module, choose M here: the + module will be called rsxx. + endif # BLK_DEV
drivers/block/Makefile +2 -0
@@ -41,4 +41,6 @@ obj-$(CONFIG_BLK_DEV_DRBD) += drbd/ obj-$(CONFIG_BLK_DEV_RBD) += rbd.o obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/ +obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ + swim_mod-y := swim.o swim_asm.o
drivers/block/rsxx/config.c +213 -0
213 lines not on this page · raw message
drivers/block/rsxx/core.c +651 -0
651 lines not on this page · raw message
drivers/block/rsxx/cregs.c +743 -0
743 lines not on this page · raw message
drivers/block/rsxx/dev.c +367 -0
367 lines not on this page · raw message
drivers/block/rsxx/dma.c +997 -0
997 lines not on this page · raw message
drivers/block/rsxx/Makefile +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_BLK_DEV_RSXX) += rsxx.o +rsxx-y := config.o core.o cregs.o dev.o dma.o
drivers/block/rsxx/rsxx_cfg.h +72 -0
7 lines not on this page · raw message
drivers/block/rsxx/rsxx.h +43 -0
43 lines not on this page · raw message
drivers/block/rsxx/rsxx_priv.h +408 -0
408 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Jens Axboe
maintainerQuoted 7 lines · Philip J. Kelleher
From: Joshua H Morris <[email protected]>
Philip J Kelleher <[email protected]>This patch includes the device driver for the IBM RamSan family of PCI SSD flash storage cards. This driver will inlcude support for the RamSan 70 and 80. The driver presents a block device for device I/O.
Quoted 6 lines
Signed-off-by Philip J Kelleher <[email protected]>-------------------------------------------------------------------------------
This update addresses all issues raised thus far. Changes include:
o Movedblk_queue_max_discard_sectorsinto the 'discard supported' if statement.
o Changed email address to linux.vnet.ibm.com
Tentatively applied for 3.9.
Signature · 1 line
Jens Axboe
drivers/block/rsxx/config.c line 34
Quoted 13 lines · On Fri, 1 Feb 2013 15:41:39 -0600 "Philip J. Kelleher"…
From: Joshua H Morris <[email protected]>
Philip J Kelleher <[email protected]>This patch includes the device driver for the IBM RamSan family of PCI SSD flash storage cards. This driver will inlcude support for the RamSan 70 and 80. The driver presents a block device for device I/O.
...
drivers/block/rsxx/config.c +3
-0+static void initialize_config (void *config) +{ +struct rsxx_card_cfg *cfg = (struct rsxx_card_cfg *) config;
Unneeded and undesirable cast of void*.
Quoted 6 lines
drivers/block/rsxx/config.c +6
-0+ cfg->hdr.version =RSXX_CFG_VERSION ; + + cfg->data.block_size =RSXX_HW_BLK_SIZE ; + cfg->data.stripe_size =RSXX_HW_BLK_SIZE ; + cfg->data.vendor_id =RSXX_VENDOR_ID_TMS_IBM ; + cfg->data.cache_order = (-1 );
drivers/block/rsxx/config.c line 100
Quoted 10 lines
drivers/block/rsxx/config.c +7
-0+ cfg->data.intr_coal.mode =RSXX_INTR_COAL_DISABLED ; + cfg->data.intr_coal.count =0 ; + cfg->data.intr_coal.latency =0 ; +} + +/*----------------- Config Operations ------------------*/ +int rsxx_save_config (struct rsxx_cardinfo *card)
static
Quoted 34 lines
drivers/block/rsxx/config.c +32
-0+{ +struct rsxx_card_cfg cfg; +int st; + +memcpy (&cfg, &card->config,sizeof (cfg)); + +if (unlikely (cfg.hdr.version !=RSXX_CFG_VERSION )) { +dev_err (CARD_TO_DEV (card), +"Cannot save config with invalid version %d\n" , + cfg.hdr.version); +return -EINVAL ; + } + +/* Convert data to little endian for the CRC calculation. */ +config_data_cpu_to_le (&cfg); + + cfg.hdr.crc =config_data_crc32 (&cfg); + +/* +* Swap the data from little endian to big endian so it can be +* stored. +*/ +config_data_swab (&cfg); +config_hdr_cpu_to_be (&cfg.hdr); + + st =rsxx_creg_write (card,CREG_ADD_CONFIG ,sizeof (cfg), &cfg,1 ); +if (st) +return st; + +return 0 ; +} +
drivers/block/rsxx/config.c
Quoted 10 lines
drivers/block/rsxx/config.c +9
-0+void rsxx_disable_ier_and_isr (struct rsxx_cardinfo *card, +unsigned int intr) +{ +__disable_intr (&card->isr_mask, intr); +__disable_intr (&card->ier_mask, intr); +iowrite32 (card->ier_mask, card->regmap +IER ); +} + +irqreturn_t rsxx_isr (int irq,void *pdata)
make static, remove from rsxx_priv.h
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + struct rsxx_cardinfo *card = (struct rsxx_cardinfo *) pdata;
cast of void*
Quoted 47 lines
drivers/block/rsxx/core.c +47
-0+unsigned int isr; +int handled =0 ; +int reread_isr; +int i; + +spin_lock (&card->irq_lock); + + do { + reread_isr = 0; + + isr = ioread32(card->regmap + ISR); + if (isr == 0xffffffff) { + /* + * A few systems seem to have an intermittent issue + * where PCI reads return all Fs, but retrying the read + * a little later will return as expected. + */ + dev_info(CARD_TO_DEV(card), + "ISR = 0xFFFFFFFF, retrying later\n"); + break; + } + + isr &= card->isr_mask; + if (!isr) + break; + + for (i = 0; i < card->n_targets; i++) { + if (isr & CR_INTR_DMA(i)) { + if (card->ier_mask & CR_INTR_DMA(i)) { + rsxx_disable_ier(card, CR_INTR_DMA(i)); + reread_isr = 1; + } + queue_work(card->ctrl[i].done_wq, + &card->ctrl[i].dma_done_work); + handled++; + } + } + + if (isr & CR_INTR_CREG) { + schedule_work(&card->creg_ctrl.done_work); + handled++; + } + + if (isr & CR_INTR_EVENT) { + schedule_work(&card->event_work); + rsxx_disable_ier_and_isr(card, CR_INTR_EVENT); + handled++;
drivers/block/rsxx/core.c
Quoted 10 lines
drivers/block/rsxx/core.c +7
-0+ } + }while (reread_isr); + +spin_unlock (&card->irq_lock); +return handled ?IRQ_HANDLED :IRQ_NONE ; +} +char *rsxx_card_state_to_str (unsigned int state)
static
Quoted 14 lines
drivers/block/rsxx/core.c +11
-0+{ +static char *state_strings[] = { +"Unknown" ,"Shutdown" ,"Starting" ,"Formatting" , +"Uninitialized" ,"Good" ,"Shutting Down" , +"Fault" ,"Read Only Fault" ,"dStroying" + }; + +return state_strings[ffs (state)]; +} +static int rsxx_compatibility_check (struct rsxx_cardinfo *card) +{
drivers/block/rsxx/core.c line 322
Quoted 10 lines
drivers/block/rsxx/core.c +10
-0+unsigned char pci_rev; + +pci_read_config_byte (card->dev,PCI_REVISION_ID , &pci_rev); + +if (pci_rev >RS70_PCI_REV_SUPPORTED ) +return -1 ; +return 0 ; +} + +static int __devinit rsxx_pci_probe(struct pci_dev *dev,
__devexit and __devinit are obsolete.
Quoted 57 lines
drivers/block/rsxx/core.c +57
-0+ const struct pci_device_id *id) +{ +struct rsxx_cardinfo *card; +unsigned long flags; +int st; + +dev_info (&dev->dev,"PCI-Flash SSD discovered\n" ); + + card =kzalloc (sizeof (*card),GFP_KERNEL ); +if (!card) +return -ENOMEM ; + + card->dev = dev; +pci_set_drvdata (dev, card); + +do { +if (!ida_pre_get (&rsxx_disk_ida,GFP_KERNEL )) { + st = -ENOMEM ; + goto failed_ida_get; + } + +spin_lock (&rsxx_ida_lock); + st =ida_get_new (&rsxx_disk_ida, &card->disk_id); +spin_unlock (&rsxx_ida_lock); + }while (st == -EAGAIN ); + +if (st) + goto failed_ida_get; + + st =pci_enable_device (dev); +if (st) + goto failed_enable; + +pci_set_master (dev); +pci_set_dma_max_seg_size (dev,RSXX_HW_BLK_SIZE ); + + st =pci_set_dma_mask (dev,DMA_BIT_MASK (64 )); +if (st) { +dev_err (CARD_TO_DEV (card), +"No usable DMA configuration,aborting\n" ); + goto failed_dma_mask; + } + + st =pci_request_regions (dev,DRIVER_NAME ); +if (st) { +dev_err (CARD_TO_DEV (card), +"Failed to request memory region\n" ); + goto failed_request_regions; + } + +if (pci_resource_len (dev,0 ) ==0 ) { +dev_err (CARD_TO_DEV (card),"BAR0 has length 0!\n" ); + st = -ENOMEM ; + goto failed_iomap; + } + + card->regmap =pci_iomap (dev,0 ,0 );
drivers/block/rsxx/core.c line 389
Quoted 10 lines
drivers/block/rsxx/core.c +10
-0+if (!card->regmap) { +dev_err (CARD_TO_DEV (card),"Failed to map BAR0\n" ); + st = -ENOMEM ; + goto failed_iomap; + } + +spin_lock_init (&card->irq_lock); + card->halt =0 ; + +spin_lock_irqsave (&card->irq_lock, flags);
Can use plain old spin_lock_irq() in a probe function.
Quoted 12 lines
drivers/block/rsxx/core.c +12
-0+rsxx_disable_ier_and_isr (card,CR_INTR_ALL ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +if (!force_legacy) { + st =pci_enable_msi (dev); +if (st) +dev_warn (CARD_TO_DEV (card), +"Failed to enable MSI\n" ); + } + + st =request_irq (dev->irq, rsxx_isr,IRQF_DISABLED |IRQF_SHARED , +DRIVER_NAME , card);
drivers/block/rsxx/core.c line 411
Quoted 10 lines
drivers/block/rsxx/core.c +10
-0+if (st) { +dev_err (CARD_TO_DEV (card), +"Failed requesting IRQ%d\n" , dev->irq); + goto failed_irq; + } + +/************* Setup Processor Command Interface *************/ +rsxx_creg_setup (card); + +spin_lock_irqsave (&card->irq_lock, flags);
Ditto(es)
Quoted 100 lines
drivers/block/rsxx/core.c +100
-0+rsxx_enable_ier_and_isr (card,CR_INTR_CREG ); +spin_unlock_irqrestore (&card->irq_lock, flags); + + st =rsxx_compatibility_check (card); +if (st) { +dev_warn (CARD_TO_DEV (card), +"Incompatible driver detected. Please update the driver.\n" ); + st = -EINVAL ; + goto failed_compatiblity_check; + } + +/************* Load Card Config *************/ + st =rsxx_load_config (card); +if (st) +dev_err (CARD_TO_DEV (card), +"Failed loading card config\n" ); + +/************* Setup DMA Engine *************/ + st =rsxx_get_num_targets (card, &card->n_targets); +if (st) +dev_info (CARD_TO_DEV (card), +"Failed reading the number of DMA targets\n" ); + + card->ctrl =kzalloc (card->n_targets *sizeof (*card->ctrl),GFP_KERNEL ); +if (!card->ctrl) { + st = -ENOMEM ; + goto failed_dma_setup; + } + + st =rsxx_dma_setup (card); +if (st) { +dev_info (CARD_TO_DEV (card), +"Failed to setup DMA engine\n" ); + goto failed_dma_setup; + } + +/************* Setup Card Event Handler *************/ +INIT_WORK (&card->event_work, card_event_handler); + + st =rsxx_setup_dev (card); +if (st) + goto failed_create_dev; + +rsxx_get_card_state (card, &card->state); + +dev_info (CARD_TO_DEV (card), +"card state: %s\n" , +rsxx_card_state_to_str (card->state)); + +/* +* Now that the DMA Engine and devices have been setup, +* we can enable the event interrupt(it kicks off actions in +* those layers so we couldn't enable it right away.) +*/ +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_enable_ier_and_isr (card,CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +if (card->state ==CARD_STATE_SHUTDOWN ) { + st =rsxx_issue_card_cmd (card,CARD_CMD_STARTUP ); +if (st) +dev_crit (CARD_TO_DEV (card), +"Failed issuing card startup\n" ); + }else if (card->state ==CARD_STATE_GOOD || + card->state ==CARD_STATE_RD_ONLY_FAULT ) { + st =rsxx_get_card_size8 (card, &card->size8); +if (st) + card->size8 =0 ; + } + +rsxx_attach_dev (card); + +return 0 ; + +failed_create_dev: +rsxx_dma_destroy (card); +failed_dma_setup: +failed_compatiblity_check: +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_disable_ier_and_isr (card,CR_INTR_ALL ); +spin_unlock_irqrestore (&card->irq_lock, flags); +free_irq (dev->irq, card); +if (!force_legacy) +pci_disable_msi (dev); +failed_irq: +pci_iounmap (dev, card->regmap); +failed_iomap: +pci_release_regions (dev); +failed_request_regions: +failed_dma_mask: +pci_disable_device (dev); +failed_enable: +spin_lock (&rsxx_ida_lock); +ida_remove (&rsxx_disk_ida, card->disk_id); +spin_unlock (&rsxx_ida_lock); +failed_ida_get: +kfree (card); + +return st; +}
drivers/block/rsxx/core.c
Quoted 10 lines
drivers/block/rsxx/core.c +7
-0+#if defined(__LITTLE_ENDIAN) +#define LITTLE_ENDIAN 1 +#elif defined(__BIG_ENDIAN) +#define LITTLE_ENDIAN 0 +#else +#error Unknown endianess!!! Aborting... +#endif
Can we nuke all this stuff and use cpu_to_be32() and friends?
Quoted 6 lines
...
drivers/block/rsxx/cregs.c +3
-0+static void creg_issue_cmd (struct rsxx_cardinfo *card,struct creg_cmd *cmd) +{ +iowrite32 (cmd->addr, card->regmap +CREG_ADD );
drivers/block/rsxx/cregs.c line 130
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+iowrite32 (cmd->cnt8, card->regmap +CREG_CNT ); + +if (cmd->op ==CREG_OP_WRITE ) { +if (cmd->buf) +copy_to_creg_data (card, cmd->cnt8, + cmd->buf, cmd->stream); + } + +/* Data copy must complete before initiating the command. */ +wmb ();
I don't think a wmb() is the way to ensure that an iowrite() has completed. I forget the rules here - I unreliably recall that an iowrite() is synchronous.
Quoted 16 lines
drivers/block/rsxx/cregs.c +16
-0+/* Setting the valid bit will kick off the command. */ +iowrite32 (cmd->op, card->regmap +CREG_CMD ); +} + +static void creg_kick_queue (struct rsxx_cardinfo *card) +{ +if (card->creg_ctrl.active ||list_empty (&card->creg_ctrl.queue)) +return ; + + card->creg_ctrl.active =1 ; + card->creg_ctrl.active_cmd =list_first_entry (&card->creg_ctrl.queue, + struct creg_cmd, list); +list_del (&card->creg_ctrl.active_cmd->list); + card->creg_ctrl.q_depth--; + +/*
drivers/block/rsxx/cregs.c line 157
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+* We have to set the timer before we push the new command. Otherwise, +* we could create a race condition that would occur if the timer +* was not canceled, and expired after the new command was pushed, +* but before the command was issued to hardware. +*/ +mod_timer (&card->creg_ctrl.cmd_timer, + jiffies +msecs_to_jiffies (CREG_TIMEOUT_MSEC )); + +creg_issue_cmd (card, card->creg_ctrl.active_cmd); +}
The function should document its caller-imposed locking rules. Most callers hold mutex_lock(&card->creg_ctrl.lock), but creg_cmd_timed_out() does not and cannot. Looks buggy.
drivers/block/rsxx/cregs.c line 307
Quoted 11 lines
...
drivers/block/rsxx/cregs.c +8
-0+static void creg_reset (struct rsxx_cardinfo *card) +{ +struct creg_cmd *cmd =NULL ; +struct creg_cmd *tmp; +unsigned long flags; + +if (!mutex_trylock (&card->creg_ctrl.reset_lock)) +return ;
mutex_trylock() is ugly, and is always obscure. This site should have a code comment explaining why we're doing this extraordinary thing, and why it is acceptable to simply bail out if the attempt failed.
Quoted 44 lines
drivers/block/rsxx/cregs.c +44
-0+ card->creg_ctrl.reset =1 ; +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_disable_ier_and_isr (card,CR_INTR_CREG |CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +dev_warn (CARD_TO_DEV (card), +"Resetting creg interface for recovery\n" ); + +/* Cancel outstanding commands */ +mutex_lock (&card->creg_ctrl.lock); +list_for_each_entry_safe (cmd, tmp, &card->creg_ctrl.queue, list) { +list_del (&cmd->list); + card->creg_ctrl.q_depth--; +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + } + + cmd = card->creg_ctrl.active_cmd; + card->creg_ctrl.active_cmd =NULL ; +if (cmd) { +if (timer_pending (&card->creg_ctrl.cmd_timer)) +del_timer_sync (&card->creg_ctrl.cmd_timer); + +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + + card->creg_ctrl.active =0 ; + } +mutex_unlock (&card->creg_ctrl.lock); + + card->creg_ctrl.reset =0 ; +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_enable_ier_and_isr (card,CR_INTR_CREG |CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +mutex_unlock (&card->creg_ctrl.reset_lock); +} + +/* Used for synchronous accesses */ +struct creg_completion { +struct completion *cmd_done; +int st;
drivers/block/rsxx/cregs.c line 362
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+u32 creg_status; +}; + +static void creg_cmd_done_cb (struct rsxx_cardinfo *card, +struct creg_cmd *cmd, +int st) +{ +struct creg_completion *cmd_completion; + + cmd_completion = (struct creg_completion *)cmd->cb_private;
unneeded cast of void*.
Quoted 11 lines
drivers/block/rsxx/cregs.c +11
-0+BUG_ON (!cmd_completion); + + cmd_completion->st = st; + cmd_completion->creg_status = cmd->status; +complete (cmd_completion->cmd_done); +} + +static int __issue_creg_rw(struct rsxx_cardinfo *card, + unsigned int op, + unsigned int addr, + unsigned int cnt8,
drivers/block/rsxx/cregs.c line 383
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+void *buf, + int stream, + unsigned int *hw_stat) +{ +DECLARE_COMPLETION_ONSTACK (cmd_done ); +struct creg_completion completion; +unsigned long timeout; +int st; + +INIT_COMPLETION (cmd_done);
DECLARE_COMPLETION_ONSTACK() already did that?
drivers/block/rsxx/cregs.c line 394
Quoted 11 lines
drivers/block/rsxx/cregs.c +11
-0+ completion.cmd_done = &cmd_done; + completion.st =0 ; + completion.creg_status =0 ; + + st =creg_queue_cmd (card, op, addr, cnt8, buf, stream, creg_cmd_done_cb, + &completion); +if (st) +return st; + + timeout =msecs_to_jiffies ((CREG_TIMEOUT_MSEC * + card->creg_ctrl.q_depth) +20000 );
This is, what? A minute? That sounds nutty. Chances are the user has hit the big red button before this expires.
Quoted 41 lines
drivers/block/rsxx/cregs.c +41
-0+/* +* The creg interface is guaranteed to complete. It has a timeout +* mechanism that will kick in if hardware does not respond. +*/ + st =wait_for_completion_timeout (completion.cmd_done, timeout); +if (st ==0 ) { +/* +* This is really bad, because the kernel timer did not +* expire and notify us of a timeout! +*/ +dev_crit (CARD_TO_DEV (card), +"cregs timer failed\n" ); +creg_reset (card); +return -EIO ; + } + + *hw_stat = completion.creg_status; + +if (completion.st) { +dev_warn (CARD_TO_DEV (card), +"creg command failed(%d x%08x)\n" , + completion.st, addr); +return completion.st; + } + +return 0 ; +} + +static int issue_creg_rw (struct rsxx_cardinfo *card, +u32 addr, +unsigned int size8, +void *data, +int stream, +int read) +{ +unsigned int hw_stat; +unsigned int xfer; +unsigned int op; +int st; + + op = read ?CREG_OP_READ :CREG_OP_WRITE ;
drivers/block/rsxx/cregs.c line 446
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+ + do { + xfer = min_t(unsigned int, size8, MAX_CREG_DATA8); + + st = __issue_creg_rw(card, op, addr, xfer, + data, stream, &hw_stat); + if (st) + return st; + + data = (void *)((char *)data + xfer);
unneeded cast to void*.
Quoted 13 lines
drivers/block/rsxx/cregs.c +10
-0+ addr += xfer; + size8 -= xfer; + }while (size8); + +return 0 ; +} + +static void hw_log_msg (struct rsxx_cardinfo *card,const char *str,int len) +{ +static char level;
drivers/block/rsxx/cregs.c line 527
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+ +/* +* New messages start with "<#>", where # is the log level. Messages +* that extend past the log buffer will use the previous level +*/ +if ((len >3 ) && (str[0 ] =='<' ) && (str[2 ] =='>' )) { + level = str[1 ]; + str +=3 ;/* Skip past the log level. */ + len -=3 ; + }
hm, what's going on here? We're translating log messages which were read from the controller into kernel printk form?
If so, OK.
If not, the recent change from <n> to \001n broke things.
Quoted 26 lines
drivers/block/rsxx/cregs.c +26
-0+switch (level) { +case '0' : +dev_emerg (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '1' : +dev_alert (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '2' : +dev_crit (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '3' : +dev_err (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '4' : +dev_warn (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '5' : +dev_notice (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '6' : +dev_info (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '7' : +dev_dbg (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +default :
drivers/block/rsxx/cregs.c line 564
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+dev_info (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; + } +} + +/* +* The substrncpy() function copies to string(up to count bytes) point to by src +* (including the terminating '\0' character) to dest. Returns the number of +* bytes copied to dest. +*/
This description isn't very grammatical.
Quoted 4 lines
drivers/block/rsxx/cregs.c +4
-0+static int substrncpy (char *dest,const char *src,int count) +{ +int max_cnt = count; +
drivers/block/rsxx/cregs.c line 578
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+while (count) { + count--; + *dest = *src; +if (*dest =='\0' ) +break ; + src++; + dest++; + } +return max_cnt - count; +}
Does this really need to exist? You're sure none of the standard facilities suit?
Quoted 14 lines
...
drivers/block/rsxx/cregs.c +11
-0+int rsxx_reg_access (struct rsxx_cardinfo *card, +struct rsxx_reg_access __user *ucmd, +int read) +{ +struct rsxx_reg_access cmd; +int st; + + st =copy_from_user (&cmd, ucmd,sizeof (cmd)); +if (st) +return -EFAULT ; +
drivers/block/rsxx/cregs.c line 669
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+ st =issue_reg_cmd (card, &cmd, read); +if (st) +return st; + + st =put_user (cmd.stat, &ucmd->stat); +if (st) +return -EFAULT ; + +if (read) { + st =copy_to_user (ucmd->data, cmd.data, cmd.cnt);
I think we just handed the user a way of reading unlimited amounts of kernel memory.
Quoted 151 lines
drivers/block/rsxx/cregs.c +74
-0+if (st) +return -EFAULT ; + } + +return 0 ; +} + +/*------------ Initialization & Setup --------------*/ +int rsxx_creg_setup (struct rsxx_cardinfo *card) +{ + card->creg_ctrl.active_cmd =NULL ; + +INIT_WORK (&card->creg_ctrl.done_work, creg_cmd_done); +mutex_init (&card->creg_ctrl.reset_lock); +INIT_LIST_HEAD (&card->creg_ctrl.queue); +mutex_init (&card->creg_ctrl.lock); +spin_lock_init (&card->creg_ctrl.pop_lock); +setup_timer (&card->creg_ctrl.cmd_timer, creg_cmd_timed_out, + (unsigned long ) card); + +return 0 ; +} + +void rsxx_creg_destroy (struct rsxx_cardinfo *card) +{ +struct creg_cmd *cmd; +struct creg_cmd *tmp; +int cnt =0 ; + +/* Cancel outstanding commands */ +mutex_lock (&card->creg_ctrl.lock); +list_for_each_entry_safe (cmd, tmp, &card->creg_ctrl.queue, list) { +list_del (&cmd->list); +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + cnt++; + } + +if (cnt) +dev_info (CARD_TO_DEV (card), +"Canceled %d queue creg commands\n" , cnt); + + cmd = card->creg_ctrl.active_cmd; + card->creg_ctrl.active_cmd =NULL ; +if (cmd) { +if (timer_pending (&card->creg_ctrl.cmd_timer)) +del_timer_sync (&card->creg_ctrl.cmd_timer); + +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +dev_info (CARD_TO_DEV (card), +"Canceled active creg command\n" ); +kmem_cache_free (creg_cmd_pool, cmd); + } +mutex_unlock (&card->creg_ctrl.lock); + +cancel_work_sync (&card->creg_ctrl.done_work); +} + + +int rsxx_creg_init (void ) +{ + creg_cmd_pool =KMEM_CACHE (creg_cmd,SLAB_HWCACHE_ALIGN ); +if (!creg_cmd_pool) +return -ENOMEM ; + +return 0 ; +} + +void rsxx_creg_cleanup (void ) +{ +kmem_cache_destroy (creg_cmd_pool); +}diff -uprN -X linux-3.7.5-vanilla/Documentation/dontdiff
linux-3.7.5-vanilla/drivers/block/rsxx/dev.clinux-3.7.5/drivers/block/rsxx/dev.cdrivers/block/rsxx/dev.c +73
-0@@ -0,0 +1,367 @@ +/* +* Filename: dev.c +* +* +* Authors: Joshua Morris <[email protected]> +* Philip Kelleher <[email protected]> +* +* (C) Copyright 2013 IBM Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> + +#include <linux/hdreg.h> +#include <linux/genhd.h> +#include <linux/blkdev.h> +#include <linux/bio.h> + +#include <linux/fs.h> + +#include "rsxx_priv.h" + +static unsigned int blkdev_minors =64 ; +module_param (blkdev_minors, uint,0444 ); +MODULE_PARM_DESC (blkdev_minors,"Number of minors(partitions)" ); + +/* +* For now I'm making this tweakable in case any applications hit this limit. +* If you see a "bio too big" error in the log you will need to raise this +* value. +*/ +static unsigned int blkdev_max_hw_sectors =1024 ; +module_param (blkdev_max_hw_sectors, uint,0444 ); +MODULE_PARM_DESC (blkdev_max_hw_sectors,"Max hw sectors for a single BIO" ); + +static unsigned int enable_blkdev =1 ; +module_param (enable_blkdev , uint,0444 ); +MODULE_PARM_DESC (enable_blkdev,"Enable block device interfaces" ); + + +struct rsxx_bio_meta { +struct bio *bio; +atomic_t pending_dmas; +atomic_t error; +unsigned long start_time; +}; + +static struct kmem_cache *bio_meta_pool; + +/*----------------- Block Device Operations -----------------*/ +static int rsxx_blkdev_ioctl (struct block_device *bdev, +fmode_t mode, +unsigned int cmd, +unsigned long arg) +{ +struct rsxx_cardinfo *card = bdev->bd_disk->private_data;
drivers/block/rsxx/dev.c line 83
Quoted 10 lines
drivers/block/rsxx/dev.c +10
-0+ +switch (cmd) { +case RSXX_GETREG : +return rsxx_reg_access (card, (void __user *)arg,1 ); +case RSXX_SETREG : +return rsxx_reg_access (card, (void __user *)arg,0 ); + } + +return -ENOTTY ; +}
<attention span expired 48% of the way through, sorry>
Thank You for your response.
Comments inline.
I will throughly inspect the other 52% that wasn't reviewed for the same simple mistakes that were missed :)
Testing changes before submitting.
A patch will be coming soon.
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Fri, 1 Feb 2013 15:41:39 -0600 "Philip J. Kelleher"…
From: Joshua H Morris <[email protected]>
Philip J Kelleher <[email protected]>This patch includes the device driver for the IBM RamSan family of PCI SSD flash storage cards. This driver will inlcude support for the RamSan 70 and 80. The driver presents a block device for device I/O.
Quoted 8 lines
drivers/block/rsxx/config.c line 34
Quoted 5 lines
...
drivers/block/rsxx/config.c +3
-0+static void initialize_config (void *config) +{ +struct rsxx_card_cfg *cfg = (struct rsxx_card_cfg *) config;Unneeded and undesirable cast of void*.
Something that I have always done. They will be removed.
Quoted 12 lines
Quoted 12 lines
drivers/block/rsxx/config.c +11
-0+ cfg->hdr.version =RSXX_CFG_VERSION ; + + cfg->data.block_size =RSXX_HW_BLK_SIZE ; + cfg->data.stripe_size =RSXX_HW_BLK_SIZE ; + cfg->data.vendor_id =RSXX_VENDOR_ID_TMS_IBM ; + cfg->data.cache_order = (-1 ); + cfg->data.intr_coal.mode =RSXX_INTR_COAL_DISABLED ; + cfg->data.intr_coal.count =0 ; + cfg->data.intr_coal.latency =0 ; +} +
Quoted 7 lines
drivers/block/rsxx/config.c line 100
Quoted 4 lines
...
drivers/block/rsxx/config.c +2
-0+/*----------------- Config Operations ------------------*/ +int rsxx_save_config (struct rsxx_cardinfo *card)static
Fixed.
Quoted 35 lines
Quoted 35 lines
drivers/block/rsxx/config.c +32
-0+{ +struct rsxx_card_cfg cfg; +int st; + +memcpy (&cfg, &card->config,sizeof (cfg)); + +if (unlikely (cfg.hdr.version !=RSXX_CFG_VERSION )) { +dev_err (CARD_TO_DEV (card), +"Cannot save config with invalid version %d\n" , + cfg.hdr.version); +return -EINVAL ; + } + +/* Convert data to little endian for the CRC calculation. */ +config_data_cpu_to_le (&cfg); + + cfg.hdr.crc =config_data_crc32 (&cfg); + +/* +* Swap the data from little endian to big endian so it can be +* stored. +*/ +config_data_swab (&cfg); +config_hdr_cpu_to_be (&cfg.hdr); + + st =rsxx_creg_write (card,CREG_ADD_CONFIG ,sizeof (cfg), &cfg,1 ); +if (st) +return st; + +return 0 ; +} +
Quoted 12 lines
drivers/block/rsxx/core.c line 105
Quoted 9 lines
drivers/block/rsxx/core.c +9
-0+void rsxx_disable_ier_and_isr (struct rsxx_cardinfo *card, +unsigned int intr) +{ +__disable_intr (&card->isr_mask, intr); +__disable_intr (&card->ier_mask, intr); +iowrite32 (card->ier_mask, card->regmap +IER ); +} + +irqreturn_t rsxx_isr (int irq,void *pdata)make static, remove from
rsxx_priv.h
Fixed.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + struct rsxx_cardinfo *card = (struct rsxx_cardinfo *) pdata;cast of void*
Fixed.
Quoted 54 lines
Quoted 54 lines
drivers/block/rsxx/core.c +53
-0+unsigned int isr; +int handled =0 ; +int reread_isr; +int i; + +spin_lock (&card->irq_lock); + +do { + reread_isr =0 ; + + isr =ioread32 (card->regmap +ISR ); +if (isr ==0xffffffff ) { +/* +* A few systems seem to have an intermittent issue +* where PCI reads return all Fs, but retrying the read +* a little later will return as expected. +*/ +dev_info (CARD_TO_DEV (card), +"ISR = 0xFFFFFFFF, retrying later\n" ); +break ; + } + + isr &= card->isr_mask; +if (!isr) +break ; + +for (i =0 ; i < card->n_targets; i++) { +if (isr &CR_INTR_DMA (i)) { +if (card->ier_mask &CR_INTR_DMA (i)) { +rsxx_disable_ier (card,CR_INTR_DMA (i)); + reread_isr =1 ; + } +queue_work (card->ctrl[i].done_wq, + &card->ctrl[i].dma_done_work); + handled++; + } + } + +if (isr &CR_INTR_CREG ) { +schedule_work (&card->creg_ctrl.done_work); + handled++; + } + +if (isr &CR_INTR_EVENT ) { +schedule_work (&card->event_work); +rsxx_disable_ier_and_isr (card,CR_INTR_EVENT ); + handled++; + } + }while (reread_isr); + +spin_unlock (&card->irq_lock); +return handled ?IRQ_HANDLED :IRQ_NONE ; +}
Quoted 6 lines
Quoted 3 lines
...
+char *rsxx_card_state_to_str(unsigned int state)
static
Fixed.
Quoted 12 lines
Quoted 12 lines
drivers/block/rsxx/core.c +9
-0+{ +static char *state_strings[] = { +"Unknown" ,"Shutdown" ,"Starting" ,"Formatting" , +"Uninitialized" ,"Good" ,"Shutting Down" , +"Fault" ,"Read Only Fault" ,"dStroying" + }; + +return state_strings[ffs (state)]; +}
Quoted 15 lines
drivers/block/rsxx/core.c line 322
Quoted 12 lines
drivers/block/rsxx/core.c +12
-0+static int rsxx_compatibility_check (struct rsxx_cardinfo *card) +{ +unsigned char pci_rev; + +pci_read_config_byte (card->dev,PCI_REVISION_ID , &pci_rev); + +if (pci_rev >RS70_PCI_REV_SUPPORTED ) +return -1 ; +return 0 ; +} + +static int __devinit rsxx_pci_probe(struct pci_dev *dev,
__devexitand__devinitare obsolete.
This has already been patched up.
Quoted 61 lines
Quoted 61 lines
drivers/block/rsxx/core.c +61
-0+ const struct pci_device_id *id) +{ +struct rsxx_cardinfo *card; +unsigned long flags; +int st; + +dev_info (&dev->dev,"PCI-Flash SSD discovered\n" ); + + card =kzalloc (sizeof (*card),GFP_KERNEL ); +if (!card) +return -ENOMEM ; + + card->dev = dev; +pci_set_drvdata (dev, card); + +do { +if (!ida_pre_get (&rsxx_disk_ida,GFP_KERNEL )) { + st = -ENOMEM ; + goto failed_ida_get; + } + +spin_lock (&rsxx_ida_lock); + st =ida_get_new (&rsxx_disk_ida, &card->disk_id); +spin_unlock (&rsxx_ida_lock); + }while (st == -EAGAIN ); + +if (st) + goto failed_ida_get; + + st =pci_enable_device (dev); +if (st) + goto failed_enable; + +pci_set_master (dev); +pci_set_dma_max_seg_size (dev,RSXX_HW_BLK_SIZE ); + + st =pci_set_dma_mask (dev,DMA_BIT_MASK (64 )); +if (st) { +dev_err (CARD_TO_DEV (card), +"No usable DMA configuration,aborting\n" ); + goto failed_dma_mask; + } + + st =pci_request_regions (dev,DRIVER_NAME ); +if (st) { +dev_err (CARD_TO_DEV (card), +"Failed to request memory region\n" ); + goto failed_request_regions; + } + +if (pci_resource_len (dev,0 ) ==0 ) { +dev_err (CARD_TO_DEV (card),"BAR0 has length 0!\n" ); + st = -ENOMEM ; + goto failed_iomap; + } + + card->regmap =pci_iomap (dev,0 ,0 ); +if (!card->regmap) { +dev_err (CARD_TO_DEV (card),"Failed to map BAR0\n" ); + st = -ENOMEM ; + goto failed_iomap;
Quoted 9 lines
drivers/block/rsxx/core.c line 389
Quoted 6 lines
drivers/block/rsxx/core.c +6
-0+ } + +spin_lock_init (&card->irq_lock); + card->halt =0 ; + +spin_lock_irqsave (&card->irq_lock, flags);Can use plain old
spin_lock_irq()in a probe function.
Fixed.
Quoted 16 lines
Quoted 16 lines
drivers/block/rsxx/core.c +16
-0+rsxx_disable_ier_and_isr (card,CR_INTR_ALL ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +if (!force_legacy) { + st =pci_enable_msi (dev); +if (st) +dev_warn (CARD_TO_DEV (card), +"Failed to enable MSI\n" ); + } + + st =request_irq (dev->irq, rsxx_isr,IRQF_DISABLED |IRQF_SHARED , +DRIVER_NAME , card); +if (st) { +dev_err (CARD_TO_DEV (card), +"Failed requesting IRQ%d\n" , dev->irq); + goto failed_irq;
Quoted 9 lines
drivers/block/rsxx/core.c line 411
Quoted 6 lines
drivers/block/rsxx/core.c +6
-0+ } + +/************* Setup Processor Command Interface *************/ +rsxx_creg_setup (card); + +spin_lock_irqsave (&card->irq_lock, flags);Ditto(es)
Fixed.
Quoted 103 lines
Quoted 103 lines
drivers/block/rsxx/core.c +100
-0+rsxx_enable_ier_and_isr (card,CR_INTR_CREG ); +spin_unlock_irqrestore (&card->irq_lock, flags); + + st =rsxx_compatibility_check (card); +if (st) { +dev_warn (CARD_TO_DEV (card), +"Incompatible driver detected. Please update the driver.\n" ); + st = -EINVAL ; + goto failed_compatiblity_check; + } + +/************* Load Card Config *************/ + st =rsxx_load_config (card); +if (st) +dev_err (CARD_TO_DEV (card), +"Failed loading card config\n" ); + +/************* Setup DMA Engine *************/ + st =rsxx_get_num_targets (card, &card->n_targets); +if (st) +dev_info (CARD_TO_DEV (card), +"Failed reading the number of DMA targets\n" ); + + card->ctrl =kzalloc (card->n_targets *sizeof (*card->ctrl),GFP_KERNEL ); +if (!card->ctrl) { + st = -ENOMEM ; + goto failed_dma_setup; + } + + st =rsxx_dma_setup (card); +if (st) { +dev_info (CARD_TO_DEV (card), +"Failed to setup DMA engine\n" ); + goto failed_dma_setup; + } + +/************* Setup Card Event Handler *************/ +INIT_WORK (&card->event_work, card_event_handler); + + st =rsxx_setup_dev (card); +if (st) + goto failed_create_dev; + +rsxx_get_card_state (card, &card->state); + +dev_info (CARD_TO_DEV (card), +"card state: %s\n" , +rsxx_card_state_to_str (card->state)); + +/* +* Now that the DMA Engine and devices have been setup, +* we can enable the event interrupt(it kicks off actions in +* those layers so we couldn't enable it right away.) +*/ +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_enable_ier_and_isr (card,CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +if (card->state ==CARD_STATE_SHUTDOWN ) { + st =rsxx_issue_card_cmd (card,CARD_CMD_STARTUP ); +if (st) +dev_crit (CARD_TO_DEV (card), +"Failed issuing card startup\n" ); + }else if (card->state ==CARD_STATE_GOOD || + card->state ==CARD_STATE_RD_ONLY_FAULT ) { + st =rsxx_get_card_size8 (card, &card->size8); +if (st) + card->size8 =0 ; + } + +rsxx_attach_dev (card); + +return 0 ; + +failed_create_dev: +rsxx_dma_destroy (card); +failed_dma_setup: +failed_compatiblity_check: +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_disable_ier_and_isr (card,CR_INTR_ALL ); +spin_unlock_irqrestore (&card->irq_lock, flags); +free_irq (dev->irq, card); +if (!force_legacy) +pci_disable_msi (dev); +failed_irq: +pci_iounmap (dev, card->regmap); +failed_iomap: +pci_release_regions (dev); +failed_request_regions: +failed_dma_mask: +pci_disable_device (dev); +failed_enable: +spin_lock (&rsxx_ida_lock); +ida_remove (&rsxx_disk_ida, card->disk_id); +spin_unlock (&rsxx_ida_lock); +failed_ida_get: +kfree (card); + +return st; +}
Quoted 10 lines
drivers/block/rsxx/cregs.c line 59
Quoted 7 lines
drivers/block/rsxx/cregs.c +7
-0+#if defined(__LITTLE_ENDIAN) +#define LITTLE_ENDIAN 1 +#elif defined(__BIG_ENDIAN) +#define LITTLE_ENDIAN 0 +#else +#error Unknown endianess!!! Aborting... +#endif Can we nuke all this stuff and use
cpu_to_be32()and friends?
Sadly, we are unable to because the stream is an endianless value.
Quoted 12 lines
Quoted 12 lines
...
drivers/block/rsxx/cregs.c +9
-0+static void creg_issue_cmd (struct rsxx_cardinfo *card,struct creg_cmd *cmd) +{ +iowrite32 (cmd->addr, card->regmap +CREG_ADD ); +iowrite32 (cmd->cnt8, card->regmap +CREG_CNT ); + +if (cmd->op ==CREG_OP_WRITE ) { +if (cmd->buf) +copy_to_creg_data (card, cmd->cnt8, + cmd->buf, cmd->stream);
Quoted 9 lines
drivers/block/rsxx/cregs.c line 130
Quoted 4 lines
drivers/block/rsxx/cregs.c +4
-0+ } + +/* Data copy must complete before initiating the command. */ +wmb ();I don't think a
wmb()is the way to ensure that aniowrite()has completed. I forget the rules here - I unreliably recall that aniowrite()is synchronous.
Well the wmb() is there for PowerPC support. I basically want to make sure my writes aren't reordered. Does iowrite have an implicit barrier included?
Quoted 22 lines
Quoted 22 lines
drivers/block/rsxx/cregs.c +22
-0+/* Setting the valid bit will kick off the command. */ +iowrite32 (cmd->op, card->regmap +CREG_CMD ); +} + +static void creg_kick_queue (struct rsxx_cardinfo *card) +{ +if (card->creg_ctrl.active ||list_empty (&card->creg_ctrl.queue)) +return ; + + card->creg_ctrl.active =1 ; + card->creg_ctrl.active_cmd =list_first_entry (&card->creg_ctrl.queue, + struct creg_cmd, list); +list_del (&card->creg_ctrl.active_cmd->list); + card->creg_ctrl.q_depth--; + +/* +* We have to set the timer before we push the new command. Otherwise, +* we could create a race condition that would occur if the timer +* was not canceled, and expired after the new command was pushed, +* but before the command was issued to hardware. +*/ + mod_timer(&card->creg_ctrl.cmd_timer,
Quoted 9 lines
drivers/block/rsxx/cregs.c line 157
Quoted 4 lines
drivers/block/rsxx/cregs.c +4
-0+ jiffies + msecs_to_jiffies(CREG_TIMEOUT_MSEC)); + +creg_issue_cmd (card, card->creg_ctrl.active_cmd); +}The function should document its caller-imposed locking rules. Most callers hold
mutex_lock(&card->creg_ctrl.lock), butcreg_cmd_timed_out()does not and cannot. Looks buggy.
Agreed, Fixing.
Quoted 16 lines
drivers/block/rsxx/cregs.c line 307
Quoted 11 lines
...
drivers/block/rsxx/cregs.c +8
-0+static void creg_reset (struct rsxx_cardinfo *card) +{ +struct creg_cmd *cmd =NULL ; +struct creg_cmd *tmp; +unsigned long flags; + +if (!mutex_trylock (&card->creg_ctrl.reset_lock)) +return ;
mutex_trylock()is ugly, and is always obscure. This site should have a code comment explaining why we're doing this extraordinary thing, and why it is acceptable to simply bail out if the attempt failed.
Comment added.
Quoted 48 lines
Quoted 48 lines
drivers/block/rsxx/cregs.c +48
-0+ card->creg_ctrl.reset =1 ; +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_disable_ier_and_isr (card,CR_INTR_CREG |CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +dev_warn (CARD_TO_DEV (card), +"Resetting creg interface for recovery\n" ); + +/* Cancel outstanding commands */ +mutex_lock (&card->creg_ctrl.lock); +list_for_each_entry_safe (cmd, tmp, &card->creg_ctrl.queue, list) { +list_del (&cmd->list); + card->creg_ctrl.q_depth--; +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + } + + cmd = card->creg_ctrl.active_cmd; + card->creg_ctrl.active_cmd =NULL ; +if (cmd) { +if (timer_pending (&card->creg_ctrl.cmd_timer)) +del_timer_sync (&card->creg_ctrl.cmd_timer); + +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + + card->creg_ctrl.active =0 ; + } +mutex_unlock (&card->creg_ctrl.lock); + + card->creg_ctrl.reset =0 ; +spin_lock_irqsave (&card->irq_lock, flags); +rsxx_enable_ier_and_isr (card,CR_INTR_CREG |CR_INTR_EVENT ); +spin_unlock_irqrestore (&card->irq_lock, flags); + +mutex_unlock (&card->creg_ctrl.reset_lock); +} + +/* Used for synchronous accesses */ +struct creg_completion { +struct completion *cmd_done; +int st; +u32 creg_status; +}; + +static void creg_cmd_done_cb(struct rsxx_cardinfo *card,
Quoted 9 lines
drivers/block/rsxx/cregs.c line 362
Quoted 6 lines
drivers/block/rsxx/cregs.c +6
-0+ struct creg_cmd *cmd, + int st) +{ +struct creg_completion *cmd_completion; + + cmd_completion = (struct creg_completion *)cmd->cb_private;unneeded cast of void*.
Fixed.
Quoted 15 lines
Quoted 15 lines
drivers/block/rsxx/cregs.c +15
-0+BUG_ON (!cmd_completion); + + cmd_completion->st = st; + cmd_completion->creg_status = cmd->status; +complete (cmd_completion->cmd_done); +} + +static int __issue_creg_rw (struct rsxx_cardinfo *card, +unsigned int op, +unsigned int addr, +unsigned int cnt8, +void *buf, +int stream, +unsigned int *hw_stat) +{
Quoted 9 lines
drivers/block/rsxx/cregs.c line 383
Quoted 6 lines
drivers/block/rsxx/cregs.c +6
-0+DECLARE_COMPLETION_ONSTACK (cmd_done); +struct creg_completion completion; +unsigned long timeout; +int st; + +INIT_COMPLETION (cmd_done);
DECLARE_COMPLETION_ONSTACK()already did that?
Fixed.
Quoted 6 lines
Quoted 6 lines
drivers/block/rsxx/cregs.c +6
-0+ completion.cmd_done = &cmd_done; + completion.st =0 ; + completion.creg_status =0 ; + + st =creg_queue_cmd (card, op, addr, cnt8, buf, stream, creg_cmd_done_cb, + &completion);
Quoted 9 lines
drivers/block/rsxx/cregs.c line 394
Quoted 5 lines
drivers/block/rsxx/cregs.c +5
-0+if (st) +return st; + + timeout =msecs_to_jiffies ((CREG_TIMEOUT_MSEC * + card->creg_ctrl.q_depth) +20000 );This is, what? A minute? That sounds nutty. Chances are the user has hit the big red button before this expires.
Fixed.
Quoted 45 lines
Quoted 45 lines
drivers/block/rsxx/cregs.c +45
-0+/* +* The creg interface is guaranteed to complete. It has a timeout +* mechanism that will kick in if hardware does not respond. +*/ + st =wait_for_completion_timeout (completion.cmd_done, timeout); +if (st ==0 ) { +/* +* This is really bad, because the kernel timer did not +* expire and notify us of a timeout! +*/ +dev_crit (CARD_TO_DEV (card), +"cregs timer failed\n" ); +creg_reset (card); +return -EIO ; + } + + *hw_stat = completion.creg_status; + +if (completion.st) { +dev_warn (CARD_TO_DEV (card), +"creg command failed(%d x%08x)\n" , + completion.st, addr); +return completion.st; + } + +return 0 ; +} + +static int issue_creg_rw (struct rsxx_cardinfo *card, +u32 addr, +unsigned int size8, +void *data, +int stream, +int read) +{ +unsigned int hw_stat; +unsigned int xfer; +unsigned int op; +int st; + + op = read ?CREG_OP_READ :CREG_OP_WRITE ; + + do { + xfer = min_t(unsigned int, size8, MAX_CREG_DATA8); +
Quoted 9 lines
drivers/block/rsxx/cregs.c line 446
Quoted 6 lines
drivers/block/rsxx/cregs.c +6
-0+ st =__issue_creg_rw (card, op, addr, xfer, + data, stream, &hw_stat); +if (st) +return st; + + data = (void *)((char *)data + xfer);unneeded cast to void*.
Fixed.
Quoted 27 lines
Quoted 13 lines
drivers/block/rsxx/cregs.c +10
-0+ addr += xfer; + size8 -= xfer; + }while (size8); + +return 0 ; +} + +static void hw_log_msg (struct rsxx_cardinfo *card,const char *str,int len) +{ +static char level;drivers/block/rsxx/cregs.c line 527
Quoted 10 lines
drivers/block/rsxx/cregs.c +10
-0+ +/* +* New messages start with "<#>", where # is the log level. Messages +* that extend past the log buffer will use the previous level +*/ +if ((len >3 ) && (str[0 ] =='<' ) && (str[2 ] =='>' )) { + level = str[1 ]; + str +=3 ;/* Skip past the log level. */ + len -=3 ; + }hm, what's going on here? We're translating log messages which were read from the controller into kernel printk form?
Quoted 4 lines
If so, OK.
If not, the recent change from <n> to \001n broke things.
Yep, that's correct.
Quoted 30 lines
Quoted 30 lines
drivers/block/rsxx/cregs.c +30
-0+switch (level) { +case '0' : +dev_emerg (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '1' : +dev_alert (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '2' : +dev_crit (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '3' : +dev_err (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '4' : +dev_warn (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '5' : +dev_notice (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '6' : +dev_info (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +case '7' : +dev_dbg (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; +default : +dev_info (CARD_TO_DEV (card),"HW: %.*s" , len, str); +break ; + } +}
Quoted 9 lines
drivers/block/rsxx/cregs.c line 564
Quoted 6 lines
drivers/block/rsxx/cregs.c +6
-0+ +/* +* The substrncpy() function copies to string(up to count bytes) point to by src +* (including the terminating '\0' character) to dest. Returns the number of +* bytes copied to dest. +*/ This description isn't very grammatical.
Haha, Comment has been reworked.
Quoted 9 lines
Quoted 9 lines
drivers/block/rsxx/cregs.c +9
-0+static int substrncpy (char *dest,const char *src,int count) +{ +int max_cnt = count; + +while (count) { + count--; + *dest = *src; +if (*dest =='\0' ) +break ;
Quoted 9 lines
drivers/block/rsxx/cregs.c line 578
Quoted 5 lines
drivers/block/rsxx/cregs.c +5
-0+ src++; + dest++; + } +return max_cnt - count; +}Does this really need to exist? You're sure none of the standard facilities suit?
It doesn't look like it. I'll continue to look for another means if need be.
Quoted 19 lines
Quoted 19 lines
...
drivers/block/rsxx/cregs.c +16
-0+int rsxx_reg_access (struct rsxx_cardinfo *card, +struct rsxx_reg_access __user *ucmd, +int read) +{ +struct rsxx_reg_access cmd; +int st; + + st =copy_from_user (&cmd, ucmd,sizeof (cmd)); +if (st) +return -EFAULT ; + + st =issue_reg_cmd (card, &cmd, read); +if (st) +return st; + + st =put_user (cmd.stat, &ucmd->stat);
Quoted 9 lines
drivers/block/rsxx/cregs.c line 669
Quoted 5 lines
drivers/block/rsxx/cregs.c +5
-0+if (st) +return -EFAULT ; + +if (read) { + st =copy_to_user (ucmd->data, cmd.data, cmd.cnt);I think we just handed the user a way of reading unlimited amounts of kernel memory.
Alright, it does look as though there needs to be a check for the cnt.
Quoted 155 lines
Quoted 155 lines
drivers/block/rsxx/cregs.c +74
-0+if (st) +return -EFAULT ; + } + +return 0 ; +} + +/*------------ Initialization & Setup --------------*/ +int rsxx_creg_setup (struct rsxx_cardinfo *card) +{ + card->creg_ctrl.active_cmd =NULL ; + +INIT_WORK (&card->creg_ctrl.done_work, creg_cmd_done); +mutex_init (&card->creg_ctrl.reset_lock); +INIT_LIST_HEAD (&card->creg_ctrl.queue); +mutex_init (&card->creg_ctrl.lock); +spin_lock_init (&card->creg_ctrl.pop_lock); +setup_timer (&card->creg_ctrl.cmd_timer, creg_cmd_timed_out, + (unsigned long ) card); + +return 0 ; +} + +void rsxx_creg_destroy (struct rsxx_cardinfo *card) +{ +struct creg_cmd *cmd; +struct creg_cmd *tmp; +int cnt =0 ; + +/* Cancel outstanding commands */ +mutex_lock (&card->creg_ctrl.lock); +list_for_each_entry_safe (cmd, tmp, &card->creg_ctrl.queue, list) { +list_del (&cmd->list); +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +kmem_cache_free (creg_cmd_pool, cmd); + cnt++; + } + +if (cnt) +dev_info (CARD_TO_DEV (card), +"Canceled %d queue creg commands\n" , cnt); + + cmd = card->creg_ctrl.active_cmd; + card->creg_ctrl.active_cmd =NULL ; +if (cmd) { +if (timer_pending (&card->creg_ctrl.cmd_timer)) +del_timer_sync (&card->creg_ctrl.cmd_timer); + +if (cmd->cb) + cmd->cb (card, cmd, -ECANCELED ); +dev_info (CARD_TO_DEV (card), +"Canceled active creg command\n" ); +kmem_cache_free (creg_cmd_pool, cmd); + } +mutex_unlock (&card->creg_ctrl.lock); + +cancel_work_sync (&card->creg_ctrl.done_work); +} + + +int rsxx_creg_init (void ) +{ + creg_cmd_pool =KMEM_CACHE (creg_cmd,SLAB_HWCACHE_ALIGN ); +if (!creg_cmd_pool) +return -ENOMEM ; + +return 0 ; +} + +void rsxx_creg_cleanup (void ) +{ +kmem_cache_destroy (creg_cmd_pool); +}diff -uprN -X linux-3.7.5-vanilla/Documentation/dontdiff
linux-3.7.5-vanilla/drivers/block/rsxx/dev.clinux-3.7.5/drivers/block/rsxx/dev.cdrivers/block/rsxx/dev.c +77
-0@@ -0,0 +1,367 @@ +/* +* Filename: dev.c +* +* +* Authors: Joshua Morris <[email protected]> +* Philip Kelleher <[email protected]> +* +* (C) Copyright 2013 IBM Corporation +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/slab.h> + +#include <linux/hdreg.h> +#include <linux/genhd.h> +#include <linux/blkdev.h> +#include <linux/bio.h> + +#include <linux/fs.h> + +#include "rsxx_priv.h" + +static unsigned int blkdev_minors =64 ; +module_param (blkdev_minors, uint,0444 ); +MODULE_PARM_DESC (blkdev_minors,"Number of minors(partitions)" ); + +/* +* For now I'm making this tweakable in case any applications hit this limit. +* If you see a "bio too big" error in the log you will need to raise this +* value. +*/ +static unsigned int blkdev_max_hw_sectors =1024 ; +module_param (blkdev_max_hw_sectors, uint,0444 ); +MODULE_PARM_DESC (blkdev_max_hw_sectors,"Max hw sectors for a single BIO" ); + +static unsigned int enable_blkdev =1 ; +module_param (enable_blkdev , uint,0444 ); +MODULE_PARM_DESC (enable_blkdev,"Enable block device interfaces" ); + + +struct rsxx_bio_meta { +struct bio *bio; +atomic_t pending_dmas; +atomic_t error; +unsigned long start_time; +}; + +static struct kmem_cache *bio_meta_pool; + +/*----------------- Block Device Operations -----------------*/ +static int rsxx_blkdev_ioctl (struct block_device *bdev, +fmode_t mode, +unsigned int cmd, +unsigned long arg) +{ +struct rsxx_cardinfo *card = bdev->bd_disk->private_data; + +switch (cmd) { +case RSXX_GETREG : +return rsxx_reg_access (card, (void __user *)arg,1 );
Quoted 9 lines
drivers/block/rsxx/dev.c line 83
Quoted 6 lines
drivers/block/rsxx/dev.c +6
-0+case RSXX_SETREG : +return rsxx_reg_access (card, (void __user *)arg,0 ); + } + +return -ENOTTY ; +}<attention span expired 48% of the way through, sorry>
Sorry.