Skip to content

Commit ead7077

Browse files
oakadtorvalds
authored andcommitted
memstick: automatically retrieve "INT" value from command response
MemoryStick storage cards, when in parallel mode, send several meaningful bits of their "INT" register as part of command response. This data is stored by host and can be used to spare invocation of "GET_INT" TPC on each data page transferred between host and card. Signed-off-by: Alex Dubov <oakad@yahoo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9df1303 commit ead7077

5 files changed

Lines changed: 49 additions & 41 deletions

File tree

‎drivers/memstick/core/memstick.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ void memstick_init_req_sg(struct memstick_request *mrq, unsigned char tpc,
276276
mrq->need_card_int = 1;
277277
else
278278
mrq->need_card_int = 0;
279-
280-
mrq->get_int_reg = 0;
281279
}
282280
EXPORT_SYMBOL(memstick_init_req_sg);
283281

@@ -311,8 +309,6 @@ void memstick_init_req(struct memstick_request *mrq, unsigned char tpc,
311309
mrq->need_card_int = 1;
312310
else
313311
mrq->need_card_int = 0;
314-
315-
mrq->get_int_reg = 0;
316312
}
317313
EXPORT_SYMBOL(memstick_init_req);
318314

@@ -342,6 +338,7 @@ static int h_memstick_read_dev_id(struct memstick_dev *card,
342338
card->id.class = id_reg.class;
343339
}
344340
complete(&card->mrq_complete);
341+
dev_dbg(&card->dev, "if_mode = %02x\n", id_reg.if_mode);
345342
return -EAGAIN;
346343
}
347344
}
@@ -422,7 +419,6 @@ static void memstick_power_on(struct memstick_host *host)
422419
{
423420
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON);
424421
host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL);
425-
msleep(1);
426422
}
427423

428424
static void memstick_check(struct work_struct *work)
@@ -579,7 +575,8 @@ EXPORT_SYMBOL(memstick_suspend_host);
579575
void memstick_resume_host(struct memstick_host *host)
580576
{
581577
mutex_lock(&host->lock);
582-
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON);
578+
if (host->card)
579+
memstick_power_on(host);
583580
mutex_unlock(&host->lock);
584581
memstick_detect_change(host);
585582
}

‎drivers/memstick/core/mspro_block.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ struct mspro_devinfo {
133133
struct mspro_block_data {
134134
struct memstick_dev *card;
135135
unsigned int usage_count;
136+
unsigned int caps;
136137
struct gendisk *disk;
137138
struct request_queue *queue;
138139
spinlock_t q_lock;
@@ -577,7 +578,6 @@ static int h_mspro_block_wait_for_ced(struct memstick_dev *card,
577578
static int h_mspro_block_transfer_data(struct memstick_dev *card,
578579
struct memstick_request **mrq)
579580
{
580-
struct memstick_host *host = card->host;
581581
struct mspro_block_data *msb = memstick_get_drvdata(card);
582582
unsigned char t_val = 0;
583583
struct scatterlist t_sg = { 0 };
@@ -591,12 +591,12 @@ static int h_mspro_block_transfer_data(struct memstick_dev *card,
591591
switch ((*mrq)->tpc) {
592592
case MS_TPC_WRITE_REG:
593593
memstick_init_req(*mrq, MS_TPC_SET_CMD, &msb->transfer_cmd, 1);
594-
(*mrq)->get_int_reg = 1;
594+
(*mrq)->need_card_int = 1;
595595
return 0;
596596
case MS_TPC_SET_CMD:
597597
t_val = (*mrq)->int_reg;
598598
memstick_init_req(*mrq, MS_TPC_GET_INT, NULL, 1);
599-
if (host->caps & MEMSTICK_CAP_AUTO_GET_INT)
599+
if (msb->caps & MEMSTICK_CAP_AUTO_GET_INT)
600600
goto has_int_reg;
601601
return 0;
602602
case MS_TPC_GET_INT:
@@ -646,12 +646,12 @@ static int h_mspro_block_transfer_data(struct memstick_dev *card,
646646
? MS_TPC_READ_LONG_DATA
647647
: MS_TPC_WRITE_LONG_DATA,
648648
&t_sg);
649-
(*mrq)->get_int_reg = 1;
649+
(*mrq)->need_card_int = 1;
650650
return 0;
651651
case MS_TPC_READ_LONG_DATA:
652652
case MS_TPC_WRITE_LONG_DATA:
653653
msb->current_page++;
654-
if (host->caps & MEMSTICK_CAP_AUTO_GET_INT) {
654+
if (msb->caps & MEMSTICK_CAP_AUTO_GET_INT) {
655655
t_val = (*mrq)->int_reg;
656656
goto has_int_reg;
657657
} else {
@@ -1052,7 +1052,8 @@ static int mspro_block_init_card(struct memstick_dev *card)
10521052
if (memstick_set_rw_addr(card))
10531053
return -EIO;
10541054

1055-
if (host->caps & MEMSTICK_CAP_PAR4) {
1055+
msb->caps = host->caps;
1056+
if (msb->caps & MEMSTICK_CAP_PAR4) {
10561057
if (mspro_block_switch_to_parallel(card))
10571058
printk(KERN_WARNING "%s: could not switch to "
10581059
"parallel interface\n", card->dev.bus_id);
@@ -1062,6 +1063,8 @@ static int mspro_block_init_card(struct memstick_dev *card)
10621063
if (rc)
10631064
return rc;
10641065
dev_dbg(&card->dev, "card activated\n");
1066+
if (msb->system != MEMSTICK_SYS_SERIAL)
1067+
msb->caps |= MEMSTICK_CAP_AUTO_GET_INT;
10651068

10661069
card->next_request = h_mspro_block_req_init;
10671070
msb->mrq_handler = h_mspro_block_get_ro;

‎drivers/memstick/host/jmb38x_ms.c‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ struct jmb38x_ms_host {
5757
unsigned long timeout_jiffies;
5858
struct timer_list timer;
5959
struct memstick_request *req;
60-
unsigned char eject:1,
61-
use_dma:1;
6260
unsigned char cmd_flags;
6361
unsigned char io_pos;
6462
unsigned int io_word[2];
@@ -95,9 +93,22 @@ struct jmb38x_ms {
9593
#define HOST_CONTROL_IF_PAR4 0x1
9694
#define HOST_CONTROL_IF_PAR8 0x3
9795

96+
#define STATUS_BUSY 0x00080000
97+
#define STATUS_MS_DAT7 0x00040000
98+
#define STATUS_MS_DAT6 0x00020000
99+
#define STATUS_MS_DAT5 0x00010000
100+
#define STATUS_MS_DAT4 0x00008000
101+
#define STATUS_MS_DAT3 0x00004000
102+
#define STATUS_MS_DAT2 0x00002000
103+
#define STATUS_MS_DAT1 0x00001000
104+
#define STATUS_MS_DAT0 0x00000800
98105
#define STATUS_HAS_MEDIA 0x00000400
99106
#define STATUS_FIFO_EMPTY 0x00000200
100107
#define STATUS_FIFO_FULL 0x00000100
108+
#define STATUS_MS_CED 0x00000080
109+
#define STATUS_MS_ERR 0x00000040
110+
#define STATUS_MS_BRQ 0x00000020
111+
#define STATUS_MS_CNK 0x00000001
101112

102113
#define INT_STATUS_TPC_ERR 0x00080000
103114
#define INT_STATUS_CRC_ERR 0x00040000
@@ -124,7 +135,7 @@ enum {
124135
CMD_READY = 0x01,
125136
FIFO_READY = 0x02,
126137
REG_DATA = 0x04,
127-
AUTO_GET_INT = 0x08
138+
DMA_DATA = 0x08
128139
};
129140

130141
static unsigned int jmb38x_ms_read_data(struct jmb38x_ms_host *host,
@@ -367,28 +378,27 @@ static int jmb38x_ms_issue_cmd(struct memstick_host *msh)
367378
cmd |= TPC_DIR;
368379
if (host->req->need_card_int)
369380
cmd |= TPC_WAIT_INT;
370-
if (host->req->get_int_reg)
371-
cmd |= TPC_GET_INT;
372381

373382
data = host->req->data;
374383

375-
host->use_dma = !no_dma;
384+
if (!no_dma)
385+
host->cmd_flags |= DMA_DATA;
376386

377387
if (host->req->long_data) {
378388
data_len = host->req->sg.length;
379389
} else {
380390
data_len = host->req->data_len;
381-
host->use_dma = 0;
391+
host->cmd_flags &= ~DMA_DATA;
382392
}
383393

384394
if (data_len <= 8) {
385395
cmd &= ~(TPC_DATA_SEL | 0xf);
386396
host->cmd_flags |= REG_DATA;
387397
cmd |= data_len & 0xf;
388-
host->use_dma = 0;
398+
host->cmd_flags &= ~DMA_DATA;
389399
}
390400

391-
if (host->use_dma) {
401+
if (host->cmd_flags & DMA_DATA) {
392402
if (1 != pci_map_sg(host->chip->pdev, &host->req->sg, 1,
393403
host->req->data_dir == READ
394404
? PCI_DMA_FROMDEVICE
@@ -451,13 +461,12 @@ static void jmb38x_ms_complete_cmd(struct memstick_host *msh, int last)
451461
readl(host->addr + INT_STATUS));
452462
dev_dbg(msh->cdev.dev, "c hstatus %08x\n", readl(host->addr + STATUS));
453463

454-
if (host->req->get_int_reg) {
455-
t_val = readl(host->addr + TPC_P0);
456-
host->req->int_reg = (t_val & 0xff);
457-
}
464+
host->req->int_reg = readl(host->addr + STATUS) & 0xff;
465+
466+
writel(0, host->addr + BLOCK);
467+
writel(0, host->addr + DMA_CONTROL);
458468

459-
if (host->use_dma) {
460-
writel(0, host->addr + DMA_CONTROL);
469+
if (host->cmd_flags & DMA_DATA) {
461470
pci_unmap_sg(host->chip->pdev, &host->req->sg, 1,
462471
host->req->data_dir == READ
463472
? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
@@ -509,7 +518,7 @@ static irqreturn_t jmb38x_ms_isr(int irq, void *dev_id)
509518
else
510519
host->req->error = -ETIME;
511520
} else {
512-
if (host->use_dma) {
521+
if (host->cmd_flags & DMA_DATA) {
513522
if (irq_status & INT_STATUS_EOTRAN)
514523
host->cmd_flags |= FIFO_READY;
515524
} else {
@@ -775,13 +784,10 @@ static struct memstick_host *jmb38x_ms_alloc_host(struct jmb38x_ms *jm, int cnt)
775784
snprintf(host->host_id, DEVICE_ID_SIZE, DRIVER_NAME ":slot%d",
776785
host->id);
777786
host->irq = jm->pdev->irq;
778-
host->timeout_jiffies = msecs_to_jiffies(4000);
787+
host->timeout_jiffies = msecs_to_jiffies(1000);
779788
msh->request = jmb38x_ms_request;
780789
msh->set_param = jmb38x_ms_set_param;
781-
/*
782-
msh->caps = MEMSTICK_CAP_AUTO_GET_INT | MEMSTICK_CAP_PAR4
783-
| MEMSTICK_CAP_PAR8;
784-
*/
790+
785791
msh->caps = MEMSTICK_CAP_PAR4 | MEMSTICK_CAP_PAR8;
786792

787793
setup_timer(&host->timer, jmb38x_ms_abort, (unsigned long)msh);

‎drivers/memstick/host/tifm_ms.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,20 @@ static void tifm_ms_complete_cmd(struct tifm_ms *host)
340340

341341
del_timer(&host->timer);
342342

343-
if (host->use_dma)
343+
host->req->int_reg = readl(sock->addr + SOCK_MS_STATUS) & 0xff;
344+
host->req->int_reg = (host->req->int_reg & 1)
345+
| ((host->req->int_reg << 4) & 0xe0);
346+
347+
writel(TIFM_FIFO_INT_SETALL,
348+
sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
349+
writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL);
350+
351+
if (host->use_dma) {
344352
tifm_unmap_sg(sock, &host->req->sg, 1,
345353
host->req->data_dir == READ
346354
? PCI_DMA_FROMDEVICE
347355
: PCI_DMA_TODEVICE);
356+
}
348357

349358
writel((~TIFM_CTRL_LED) & readl(sock->addr + SOCK_CONTROL),
350359
sock->addr + SOCK_CONTROL);
@@ -424,12 +433,6 @@ static void tifm_ms_card_event(struct tifm_dev *sock)
424433
else if (host_status & TIFM_MS_STAT_CRC)
425434
host->req->error = -EILSEQ;
426435

427-
if (host->req->error) {
428-
writel(TIFM_FIFO_INT_SETALL,
429-
sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
430-
writel(TIFM_DMA_RESET, sock->addr + SOCK_DMA_CONTROL);
431-
}
432-
433436
if (host_status & TIFM_MS_STAT_RDY)
434437
host->cmd_flags |= CMD_READY;
435438

‎include/linux/memstick.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ struct memstick_request {
239239
unsigned char tpc;
240240
unsigned char data_dir:1,
241241
need_card_int:1,
242-
get_int_reg:1,
243242
long_data:1;
244243
unsigned char int_reg;
245244
int error;

0 commit comments

Comments
 (0)