Lines Matching +full:partition +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* vmu-flash.c
5 * Copyright (c) Adrian McMenamin 2002 - 2009
25 int partition; member
44 int partition; member
57 struct mtd_info *mtd, int partition) in ofs_to_block() argument
65 mpart = mtd->priv; in ofs_to_block()
66 mdev = mpart->mdev; in ofs_to_block()
69 if (src_ofs >= card->parts[partition].numblocks * card->blocklen) in ofs_to_block()
72 num = src_ofs / card->blocklen; in ofs_to_block()
73 if (num > card->parts[partition].numblocks) in ofs_to_block()
80 vblock->num = num; in ofs_to_block()
81 vblock->ofs = src_ofs % card->blocklen; in ofs_to_block()
94 mdev = mq->dev; in vmu_blockread()
98 if (unlikely(!card->blockread)) in vmu_blockread()
101 memcpy(card->blockread, mq->recvbuf->buf + 12, in vmu_blockread()
102 card->blocklen/card->readcnt); in vmu_blockread()
115 int partition, error = 0, x, wait; in maple_vmu_read_block() local
120 mpart = mtd->priv; in maple_vmu_read_block()
121 mdev = mpart->mdev; in maple_vmu_read_block()
122 partition = mpart->partition; in maple_vmu_read_block()
124 pcache = card->parts[partition].pcache; in maple_vmu_read_block()
125 pcache->valid = 0; in maple_vmu_read_block()
128 if (!pcache->buffer) { in maple_vmu_read_block()
129 pcache->buffer = kmalloc(card->blocklen, GFP_KERNEL); in maple_vmu_read_block()
130 if (!pcache->buffer) { in maple_vmu_read_block()
131 dev_err(&mdev->dev, "VMU at (%d, %d) - read fails due" in maple_vmu_read_block()
132 " to lack of memory\n", mdev->port, in maple_vmu_read_block()
133 mdev->unit); in maple_vmu_read_block()
134 error = -ENOMEM; in maple_vmu_read_block()
140 * Reads may be phased - again the hardware spec in maple_vmu_read_block()
141 * supports this - though may not be any devices in in maple_vmu_read_block()
144 for (x = 0; x < card->readcnt; x++) { in maple_vmu_read_block()
145 sendbuf = cpu_to_be32(partition << 24 | x << 16 | num); in maple_vmu_read_block()
147 if (atomic_read(&mdev->busy) == 1) { in maple_vmu_read_block()
148 wait_event_interruptible_timeout(mdev->maple_wait, in maple_vmu_read_block()
149 atomic_read(&mdev->busy) == 0, HZ); in maple_vmu_read_block()
150 if (atomic_read(&mdev->busy) == 1) { in maple_vmu_read_block()
151 dev_notice(&mdev->dev, "VMU at (%d, %d)" in maple_vmu_read_block()
152 " is busy\n", mdev->port, mdev->unit); in maple_vmu_read_block()
153 error = -EAGAIN; in maple_vmu_read_block()
158 atomic_set(&mdev->busy, 1); in maple_vmu_read_block()
159 blockread = kmalloc(card->blocklen/card->readcnt, GFP_KERNEL); in maple_vmu_read_block()
161 error = -ENOMEM; in maple_vmu_read_block()
162 atomic_set(&mdev->busy, 0); in maple_vmu_read_block()
165 card->blockread = blockread; in maple_vmu_read_block()
172 wait = wait_event_interruptible_timeout(mdev->maple_wait, in maple_vmu_read_block()
173 (atomic_read(&mdev->busy) == 0 || in maple_vmu_read_block()
174 atomic_read(&mdev->busy) == 2), HZ * 3); in maple_vmu_read_block()
180 if (error || atomic_read(&mdev->busy) == 2) { in maple_vmu_read_block()
181 if (atomic_read(&mdev->busy) == 2) in maple_vmu_read_block()
182 error = -ENXIO; in maple_vmu_read_block()
183 atomic_set(&mdev->busy, 0); in maple_vmu_read_block()
184 card->blockread = NULL; in maple_vmu_read_block()
187 if (wait == 0 || wait == -ERESTARTSYS) { in maple_vmu_read_block()
188 card->blockread = NULL; in maple_vmu_read_block()
189 atomic_set(&mdev->busy, 0); in maple_vmu_read_block()
190 error = -EIO; in maple_vmu_read_block()
191 list_del_init(&(mdev->mq->list)); in maple_vmu_read_block()
192 kfree(mdev->mq->sendbuf); in maple_vmu_read_block()
193 mdev->mq->sendbuf = NULL; in maple_vmu_read_block()
194 if (wait == -ERESTARTSYS) { in maple_vmu_read_block()
195 dev_warn(&mdev->dev, "VMU read on (%d, %d)" in maple_vmu_read_block()
197 mdev->port, mdev->unit, num); in maple_vmu_read_block()
199 dev_notice(&mdev->dev, "VMU read on (%d, %d)" in maple_vmu_read_block()
201 mdev->port, mdev->unit, num); in maple_vmu_read_block()
205 memcpy(buf + (card->blocklen/card->readcnt) * x, blockread, in maple_vmu_read_block()
206 card->blocklen/card->readcnt); in maple_vmu_read_block()
208 memcpy(pcache->buffer + (card->blocklen/card->readcnt) * x, in maple_vmu_read_block()
209 card->blockread, card->blocklen/card->readcnt); in maple_vmu_read_block()
210 card->blockread = NULL; in maple_vmu_read_block()
211 pcache->block = num; in maple_vmu_read_block()
212 pcache->jiffies_atc = jiffies; in maple_vmu_read_block()
213 pcache->valid = 1; in maple_vmu_read_block()
232 int partition, error, locking, x, phaselen, wait; in maple_vmu_write_block() local
235 mpart = mtd->priv; in maple_vmu_write_block()
236 mdev = mpart->mdev; in maple_vmu_write_block()
237 partition = mpart->partition; in maple_vmu_write_block()
240 phaselen = card->blocklen/card->writecnt; in maple_vmu_write_block()
244 error = -ENOMEM; in maple_vmu_write_block()
247 for (x = 0; x < card->writecnt; x++) { in maple_vmu_write_block()
248 sendbuf[0] = cpu_to_be32(partition << 24 | x << 16 | num); in maple_vmu_write_block()
251 * or 1 second - which ever is longer */ in maple_vmu_write_block()
252 if (atomic_read(&mdev->busy) == 1) { in maple_vmu_write_block()
253 wait_event_interruptible_timeout(mdev->maple_wait, in maple_vmu_write_block()
254 atomic_read(&mdev->busy) == 0, HZ); in maple_vmu_write_block()
255 if (atomic_read(&mdev->busy) == 1) { in maple_vmu_write_block()
256 error = -EBUSY; in maple_vmu_write_block()
257 dev_notice(&mdev->dev, "VMU write at (%d, %d)" in maple_vmu_write_block()
258 "failed - device is busy\n", in maple_vmu_write_block()
259 mdev->port, mdev->unit); in maple_vmu_write_block()
263 atomic_set(&mdev->busy, 1); in maple_vmu_write_block()
267 wait = wait_event_interruptible_timeout(mdev->maple_wait, in maple_vmu_write_block()
268 atomic_read(&mdev->busy) == 0, HZ/10); in maple_vmu_write_block()
270 error = -EIO; in maple_vmu_write_block()
271 atomic_set(&mdev->busy, 0); in maple_vmu_write_block()
274 if (atomic_read(&mdev->busy) == 2) { in maple_vmu_write_block()
275 atomic_set(&mdev->busy, 0); in maple_vmu_write_block()
276 } else if (wait == 0 || wait == -ERESTARTSYS) { in maple_vmu_write_block()
277 error = -EIO; in maple_vmu_write_block()
278 dev_warn(&mdev->dev, "Write at (%d, %d) of block" in maple_vmu_write_block()
280 " communicate with VMU", mdev->port, in maple_vmu_write_block()
281 mdev->unit, num, x); in maple_vmu_write_block()
282 atomic_set(&mdev->busy, 0); in maple_vmu_write_block()
283 kfree(mdev->mq->sendbuf); in maple_vmu_write_block()
284 mdev->mq->sendbuf = NULL; in maple_vmu_write_block()
285 list_del_init(&(mdev->mq->list)); in maple_vmu_write_block()
291 return card->blocklen; in maple_vmu_write_block()
296 dev_err(&mdev->dev, "VMU (%d, %d): write failed\n", mdev->port, in maple_vmu_write_block()
297 mdev->unit); in maple_vmu_write_block()
310 int partition, error; in vmu_flash_read_char() local
312 mpart = mtd->priv; in vmu_flash_read_char()
313 mdev = mpart->mdev; in vmu_flash_read_char()
314 partition = mpart->partition; in vmu_flash_read_char()
318 buf = kmalloc(card->blocklen, GFP_KERNEL); in vmu_flash_read_char()
321 ret = -ENOMEM; in vmu_flash_read_char()
325 vblock = ofs_to_block(ofs, mtd, partition); in vmu_flash_read_char()
328 ret = -ENOMEM; in vmu_flash_read_char()
332 error = maple_vmu_read_block(vblock->num, buf, mtd); in vmu_flash_read_char()
339 ret = buf[vblock->ofs]; in vmu_flash_read_char()
358 int index = 0, retval, partition, leftover, numblocks; in vmu_flash_read() local
361 mpart = mtd->priv; in vmu_flash_read()
362 mdev = mpart->mdev; in vmu_flash_read()
363 partition = mpart->partition; in vmu_flash_read()
366 numblocks = card->parts[partition].numblocks; in vmu_flash_read()
367 if (from + len > numblocks * card->blocklen) in vmu_flash_read()
368 len = numblocks * card->blocklen - from; in vmu_flash_read()
370 return -EIO; in vmu_flash_read()
372 pcache = card->parts[partition].pcache; in vmu_flash_read()
374 vblock = ofs_to_block(from + index, mtd, partition); in vmu_flash_read()
376 return -ENOMEM; in vmu_flash_read()
378 if (pcache->valid && in vmu_flash_read()
379 time_before(jiffies, pcache->jiffies_atc + HZ) && in vmu_flash_read()
380 (pcache->block == vblock->num)) { in vmu_flash_read()
382 leftover = card->blocklen - vblock->ofs; in vmu_flash_read()
383 if (vblock->ofs + len - index < card->blocklen) { in vmu_flash_read()
386 pcache->buffer + vblock->ofs, in vmu_flash_read()
387 len - index); in vmu_flash_read()
391 memcpy(buf + index, pcache->buffer + in vmu_flash_read()
392 vblock->ofs, leftover); in vmu_flash_read()
397 * Not cached so read one byte - in vmu_flash_read()
422 int index = 0, partition, error = 0, numblocks; in vmu_flash_write() local
427 mpart = mtd->priv; in vmu_flash_write()
428 mdev = mpart->mdev; in vmu_flash_write()
429 partition = mpart->partition; in vmu_flash_write()
432 numblocks = card->parts[partition].numblocks; in vmu_flash_write()
433 if (to + len > numblocks * card->blocklen) in vmu_flash_write()
434 len = numblocks * card->blocklen - to; in vmu_flash_write()
436 error = -EIO; in vmu_flash_write()
440 vblock = ofs_to_block(to, mtd, partition); in vmu_flash_write()
442 error = -ENOMEM; in vmu_flash_write()
446 buffer = kmalloc(card->blocklen, GFP_KERNEL); in vmu_flash_write()
448 error = -ENOMEM; in vmu_flash_write()
454 error = maple_vmu_read_block(vblock->num, buffer, mtd); in vmu_flash_write()
459 buffer[vblock->ofs] = buf[index]; in vmu_flash_write()
460 vblock->ofs++; in vmu_flash_write()
464 } while (vblock->ofs < card->blocklen); in vmu_flash_write()
467 error = maple_vmu_write_block(vblock->num, buffer, mtd); in vmu_flash_write()
469 pcache = card->parts[partition].pcache; in vmu_flash_write()
470 pcache->valid = 0; in vmu_flash_write()
472 if (error != card->blocklen) in vmu_flash_write()
475 vblock->num++; in vmu_flash_write()
476 vblock->ofs = 0; in vmu_flash_write()
489 dev_err(&mdev->dev, "VMU write failing with error %d\n", error); in vmu_flash_write()
511 mdev = mq->dev; in vmu_queryblocks()
513 res = (unsigned short *) (mq->recvbuf->buf); in vmu_queryblocks()
514 card->tempA = res[12]; in vmu_queryblocks()
515 card->tempB = res[6]; in vmu_queryblocks()
517 dev_info(&mdev->dev, "VMU device at partition %d has %d user " in vmu_queryblocks()
518 "blocks with a root block at %d\n", card->partition, in vmu_queryblocks()
519 card->tempA, card->tempB); in vmu_queryblocks()
521 part_cur = &card->parts[card->partition]; in vmu_queryblocks()
522 part_cur->user_blocks = card->tempA; in vmu_queryblocks()
523 part_cur->root_block = card->tempB; in vmu_queryblocks()
524 part_cur->numblocks = card->tempB + 1; in vmu_queryblocks()
525 part_cur->name = kmalloc(12, GFP_KERNEL); in vmu_queryblocks()
526 if (!part_cur->name) in vmu_queryblocks()
529 sprintf(part_cur->name, "vmu%d.%d.%d", in vmu_queryblocks()
530 mdev->port, mdev->unit, card->partition); in vmu_queryblocks()
531 mtd_cur = &card->mtd[card->partition]; in vmu_queryblocks()
532 mtd_cur->name = part_cur->name; in vmu_queryblocks()
533 mtd_cur->type = 8; in vmu_queryblocks()
534 mtd_cur->flags = MTD_WRITEABLE|MTD_NO_ERASE; in vmu_queryblocks()
535 mtd_cur->size = part_cur->numblocks * card->blocklen; in vmu_queryblocks()
536 mtd_cur->erasesize = card->blocklen; in vmu_queryblocks()
537 mtd_cur->_write = vmu_flash_write; in vmu_queryblocks()
538 mtd_cur->_read = vmu_flash_read; in vmu_queryblocks()
539 mtd_cur->_sync = vmu_flash_sync; in vmu_queryblocks()
540 mtd_cur->writesize = card->blocklen; in vmu_queryblocks()
546 mpart->mdev = mdev; in vmu_queryblocks()
547 mpart->partition = card->partition; in vmu_queryblocks()
548 mtd_cur->priv = mpart; in vmu_queryblocks()
549 mtd_cur->owner = THIS_MODULE; in vmu_queryblocks()
554 part_cur->pcache = pcache; in vmu_queryblocks()
565 * second or more partition in vmu_queryblocks()
567 if (++card->partition < card->partitions) { in vmu_queryblocks()
568 partnum = cpu_to_be32(card->partition << 24); in vmu_queryblocks()
577 dev_err(&mdev->dev, "Could not register maple device at (%d, %d)" in vmu_queryblocks()
578 "error is 0x%X\n", mdev->port, mdev->unit, error); in vmu_queryblocks()
579 for (error = 0; error <= card->partition; error++) { in vmu_queryblocks()
580 kfree(((card->parts)[error]).pcache); in vmu_queryblocks()
581 ((card->parts)[error]).pcache = NULL; in vmu_queryblocks()
585 for (error = 0; error <= card->partition; error++) { in vmu_queryblocks()
586 kfree(((card->mtd)[error]).priv); in vmu_queryblocks()
587 ((card->mtd)[error]).priv = NULL; in vmu_queryblocks()
591 kfree(part_cur->name); in vmu_queryblocks()
604 test_flash_data = be32_to_cpu(mdev->devinfo.function); in vmu_connect()
605 /* Need to count how many bits are set - to find out which in vmu_connect()
610 basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]); in vmu_connect()
614 error = -ENOMEM; in vmu_connect()
618 card->partitions = (basic_flash_data >> 24 & 0xFF) + 1; in vmu_connect()
619 card->blocklen = ((basic_flash_data >> 16 & 0xFF) + 1) << 5; in vmu_connect()
620 card->writecnt = basic_flash_data >> 12 & 0xF; in vmu_connect()
621 card->readcnt = basic_flash_data >> 8 & 0xF; in vmu_connect()
622 card->removable = basic_flash_data >> 7 & 1; in vmu_connect()
624 card->partition = 0; in vmu_connect()
627 * Not sure there are actually any multi-partition devices in the in vmu_connect()
630 card->parts = kmalloc_array(card->partitions, sizeof(struct vmupart), in vmu_connect()
632 if (!card->parts) { in vmu_connect()
633 error = -ENOMEM; in vmu_connect()
637 card->mtd = kmalloc_array(card->partitions, sizeof(struct mtd_info), in vmu_connect()
639 if (!card->mtd) { in vmu_connect()
640 error = -ENOMEM; in vmu_connect()
655 if (atomic_read(&mdev->busy) == 1) { in vmu_connect()
656 wait_event_interruptible_timeout(mdev->maple_wait, in vmu_connect()
657 atomic_read(&mdev->busy) == 0, HZ); in vmu_connect()
658 if (atomic_read(&mdev->busy) == 1) { in vmu_connect()
659 dev_notice(&mdev->dev, "VMU at (%d, %d) is busy\n", in vmu_connect()
660 mdev->port, mdev->unit); in vmu_connect()
661 error = -EAGAIN; in vmu_connect()
666 atomic_set(&mdev->busy, 1); in vmu_connect()
675 dev_err(&mdev->dev, "Could not lock VMU at (%d, %d)" in vmu_connect()
676 " error is 0x%X\n", mdev->port, mdev->unit, error); in vmu_connect()
682 kfree(card->mtd); in vmu_connect()
684 kfree(card->parts); in vmu_connect()
697 mdev->callback = NULL; in vmu_disconnect()
699 for (x = 0; x < card->partitions; x++) { in vmu_disconnect()
700 mpart = ((card->mtd)[x]).priv; in vmu_disconnect()
701 mpart->mdev = NULL; in vmu_disconnect()
702 mtd_device_unregister(&((card->mtd)[x])); in vmu_disconnect()
703 kfree(((card->parts)[x]).name); in vmu_disconnect()
705 kfree(card->parts); in vmu_disconnect()
706 kfree(card->mtd); in vmu_disconnect()
720 for (x = 0; x < card->partitions; x++) { in vmu_can_unload()
721 mtd = &((card->mtd)[x]); in vmu_can_unload()
722 if (kref_read(&mtd->refcnt)) in vmu_can_unload()
728 #define ERRSTR "VMU at (%d, %d) file error -"
737 dev_notice(&mdev->dev, ERRSTR " invalid partition number\n", in vmu_file_error()
738 mdev->port, mdev->unit); in vmu_file_error()
742 dev_notice(&mdev->dev, ERRSTR " phase error\n", in vmu_file_error()
743 mdev->port, mdev->unit); in vmu_file_error()
747 dev_notice(&mdev->dev, ERRSTR " invalid block number\n", in vmu_file_error()
748 mdev->port, mdev->unit); in vmu_file_error()
752 dev_notice(&mdev->dev, ERRSTR " write error\n", in vmu_file_error()
753 mdev->port, mdev->unit); in vmu_file_error()
757 dev_notice(&mdev->dev, ERRSTR " invalid write length\n", in vmu_file_error()
758 mdev->port, mdev->unit); in vmu_file_error()
762 dev_notice(&mdev->dev, ERRSTR " bad CRC\n", in vmu_file_error()
763 mdev->port, mdev->unit); in vmu_file_error()
767 dev_notice(&mdev->dev, ERRSTR " 0x%X\n", in vmu_file_error()
768 mdev->port, mdev->unit, error); in vmu_file_error()
776 struct maple_driver *mdrv = to_maple_driver(dev->driver); in probe_maple_vmu()
778 mdev->can_unload = vmu_can_unload; in probe_maple_vmu()
779 mdev->fileerr_handler = vmu_file_error; in probe_maple_vmu()
780 mdev->driver = mdrv; in probe_maple_vmu()