Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(96)

Delta Between Two Patch Sets: scsi_base.c

Issue 4279046: SCSI DMA correctness
Left Patch Set: diff #2 Created 14 years ago
Right Patch Set: diff #7 Created 14 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « safte.c ('k') | scsi_ioctl.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* $OpenBSD: scsi_base.c,v 1.198 2011/03/02 04:38:01 krw Exp $ */ 1 /* $OpenBSD: scsi_base.c,v 1.198 2011/03/02 04:38:01 krw Exp $ */
2 /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ 2 /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */
3 3
4 /* 4 /*
5 * Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved. 5 * Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 23 matching lines...) Expand all
34 * Originally written by Julian Elischer (julian@dialix.oz.au) 34 * Originally written by Julian Elischer (julian@dialix.oz.au)
35 * Detailed SCSI error printing Copyright 1997 by Matthew Jacob. 35 * Detailed SCSI error printing Copyright 1997 by Matthew Jacob.
36 */ 36 */
37 37
38 #include <sys/types.h> 38 #include <sys/types.h>
39 #include <sys/param.h> 39 #include <sys/param.h>
40 #include <sys/systm.h> 40 #include <sys/systm.h>
41 #include <sys/kernel.h> 41 #include <sys/kernel.h>
42 #include <sys/buf.h> 42 #include <sys/buf.h>
43 #include <sys/uio.h> 43 #include <sys/uio.h>
44 #include <sys/malloc.h>
45 #include <sys/errno.h> 44 #include <sys/errno.h>
46 #include <sys/device.h> 45 #include <sys/device.h>
47 #include <sys/proc.h> 46 #include <sys/proc.h>
48 #include <sys/pool.h> 47 #include <sys/pool.h>
49 48
50 #include <scsi/scsi_all.h> 49 #include <scsi/scsi_all.h>
51 #include <scsi/scsi_disk.h> 50 #include <scsi/scsi_disk.h>
52 #include <scsi/scsiconf.h> 51 #include <scsi/scsiconf.h>
53 52
54 static __inline void asc2ascii(u_int8_t, u_int8_t ascq, char *result, 53 static __inline void asc2ascii(u_int8_t, u_int8_t ascq, char *result,
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 int error; 775 int error;
777 776
778 if (blksize != NULL) 777 if (blksize != NULL)
779 *blksize = 0; 778 *blksize = 0;
780 779
781 CLR(flags, SCSI_IGNORE_ILLEGAL_REQUEST); 780 CLR(flags, SCSI_IGNORE_ILLEGAL_REQUEST);
782 781
783 /* 782 /*
784 * Start with a READ CAPACITY(10). 783 * Start with a READ CAPACITY(10).
785 */ 784 */
786 » rdcap = malloc(sizeof(*rdcap), M_TEMP, ((flags & SCSI_NOSLEEP) ? 785 » rdcap = dma_alloc(sizeof(*rdcap), ((flags & SCSI_NOSLEEP) ?
787 » M_NOWAIT : M_WAITOK) | M_ZERO); 786 » PR_NOWAIT : PR_WAITOK) | PR_ZERO);
788 if (rdcap == NULL) 787 if (rdcap == NULL)
789 return (0); 788 return (0);
790 789
791 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT); 790 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT);
792 if (xs == NULL) { 791 if (xs == NULL) {
793 » » free(rdcap, M_TEMP); 792 » » dma_free(rdcap, sizeof(*rdcap));
794 return (0); 793 return (0);
795 } 794 }
796 xs->cmdlen = sizeof(*cmd10); 795 xs->cmdlen = sizeof(*cmd10);
797 xs->data = (void *)rdcap; 796 xs->data = (void *)rdcap;
798 xs->datalen = sizeof(*rdcap); 797 xs->datalen = sizeof(*rdcap);
799 xs->timeout = 20000; 798 xs->timeout = 20000;
800 799
801 cmd10 = (struct scsi_read_capacity *)xs->cmd; 800 cmd10 = (struct scsi_read_capacity *)xs->cmd;
802 cmd10->opcode = READ_CAPACITY; 801 cmd10->opcode = READ_CAPACITY;
803 802
804 error = scsi_xs_sync(xs); 803 error = scsi_xs_sync(xs);
805 scsi_xs_put(xs); 804 scsi_xs_put(xs);
806 805
807 if (error) { 806 if (error) {
808 SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY error (%#x)\n", 807 SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY error (%#x)\n",
809 error)); 808 error));
810 » » free(rdcap, M_TEMP); 809 » » dma_free(rdcap, sizeof(*rdcap));
811 return (0); 810 return (0);
812 } 811 }
813 812
814 max_addr = _4btol(rdcap->addr); 813 max_addr = _4btol(rdcap->addr);
815 if (blksize != NULL) 814 if (blksize != NULL)
816 *blksize = _4btol(rdcap->length); 815 *blksize = _4btol(rdcap->length);
817 » free(rdcap, M_TEMP); 816 » dma_free(rdcap, sizeof(*rdcap));
818 817
819 if (SCSISPC(sc_link->inqdata.version) < 3 && max_addr != 0xffffffff) 818 if (SCSISPC(sc_link->inqdata.version) < 3 && max_addr != 0xffffffff)
820 goto exit; 819 goto exit;
821 820
822 /* 821 /*
823 * SCSI-3 devices, or devices reporting more than 2^32-1 sectors can 822 * SCSI-3 devices, or devices reporting more than 2^32-1 sectors can
824 * try READ CAPACITY(16). 823 * try READ CAPACITY(16).
825 */ 824 */
826 » rdcap16 = malloc(sizeof(*rdcap16), M_TEMP, ((flags & SCSI_NOSLEEP) ? 825 » rdcap16 = dma_alloc(sizeof(*rdcap16), ((flags & SCSI_NOSLEEP) ?
827 » M_NOWAIT : M_WAITOK) | M_ZERO); 826 » PR_NOWAIT : PR_WAITOK) | PR_ZERO);
828 if (rdcap16 == NULL) 827 if (rdcap16 == NULL)
829 goto exit; 828 goto exit;
830 829
831 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT); 830 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT);
832 if (xs == NULL) { 831 if (xs == NULL) {
833 » » free(rdcap16, M_TEMP); 832 » » dma_free(rdcap16, sizeof(*rdcap16));
834 goto exit; 833 goto exit;
835 } 834 }
836 xs->cmdlen = sizeof(*cmd); 835 xs->cmdlen = sizeof(*cmd);
837 xs->data = (void *)rdcap16; 836 xs->data = (void *)rdcap16;
838 xs->datalen = sizeof(*rdcap16); 837 xs->datalen = sizeof(*rdcap16);
839 xs->timeout = 20000; 838 xs->timeout = 20000;
840 839
841 cmd = (struct scsi_read_capacity_16 *)xs->cmd; 840 cmd = (struct scsi_read_capacity_16 *)xs->cmd;
842 cmd->opcode = READ_CAPACITY_16; 841 cmd->opcode = READ_CAPACITY_16;
843 cmd->byte2 = SRC16_SERVICE_ACTION; 842 cmd->byte2 = SRC16_SERVICE_ACTION;
844 _lto4b(sizeof(*rdcap16), cmd->length); 843 _lto4b(sizeof(*rdcap16), cmd->length);
845 844
846 error = scsi_xs_sync(xs); 845 error = scsi_xs_sync(xs);
847 scsi_xs_put(xs); 846 scsi_xs_put(xs);
848 if (error) { 847 if (error) {
849 SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY 16 error (%#x)\n", 848 SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY 16 error (%#x)\n",
850 error)); 849 error));
851 » » free(rdcap16, M_TEMP); 850 » » dma_free(rdcap16, sizeof(*rdcap16));
852 goto exit; 851 goto exit;
853 } 852 }
854 853
855 max_addr = _8btol(rdcap16->addr); 854 max_addr = _8btol(rdcap16->addr);
856 if (blksize != NULL) 855 if (blksize != NULL)
857 *blksize = _4btol(rdcap16->length); 856 *blksize = _4btol(rdcap16->length);
858 /* XXX The other READ CAPACITY(16) info could be stored away. */ 857 /* XXX The other READ CAPACITY(16) info could be stored away. */
859 » free(rdcap16, M_TEMP); 858 » dma_free(rdcap16, sizeof(*rdcap16));
860 859
861 return (max_addr + 1); 860 return (max_addr + 1);
862 861
863 exit: 862 exit:
864 /* Return READ CAPACITY 10 values. */ 863 /* Return READ CAPACITY 10 values. */
865 if (max_addr != 0xffffffff) 864 if (max_addr != 0xffffffff)
866 return (max_addr + 1); 865 return (max_addr + 1);
867 else if (blksize != NULL) 866 else if (blksize != NULL)
868 *blksize = 0; 867 *blksize = 0;
869 return (0); 868 return (0);
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 case WRITE_16: { 2637 case WRITE_16: {
2639 struct scsi_rw_16 *rw16 = (struct scsi_rw_16 *)cmd; 2638 struct scsi_rw_16 *rw16 = (struct scsi_rw_16 *)cmd;
2640 *blkno = _8btol(rw16->addr); 2639 *blkno = _8btol(rw16->addr);
2641 *nblks = _4btol(rw16->length); 2640 *nblks = _4btol(rw16->length);
2642 break; 2641 break;
2643 } 2642 }
2644 default: 2643 default:
2645 panic("scsi_cmd_rw_decode: bad opcode 0x%02x", cmd->opcode); 2644 panic("scsi_cmd_rw_decode: bad opcode 0x%02x", cmd->opcode);
2646 } 2645 }
2647 } 2646 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b