| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <linux/highmem.h> |
| 31 |
#include <linux/export.h> |
| 32 |
#include <scsi/scsi.h> |
| 33 |
#include <scsi/scsi_cmnd.h> |
| 34 |
|
| 35 |
#include "usb.h" |
| 36 |
#include "protocol.h" |
| 37 |
#include "debug.h" |
| 38 |
#include "scsiglue.h" |
| 39 |
#include "transport.h" |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us) |
| 46 |
{ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
for (; srb->cmd_len < 12; srb->cmd_len++) |
| 55 |
srb->cmnd[srb->cmd_len] = 0; |
| 56 |
|
| 57 |
|
| 58 |
usb_stor_invoke_transport(srb, us); |
| 59 |
} |
| 60 |
|
| 61 |
void usb_stor_ufi_command(struct scsi_cmnd *srb, struct us_data *us) |
| 62 |
{ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
for (; srb->cmd_len < 12; srb->cmd_len++) |
| 73 |
srb->cmnd[srb->cmd_len] = 0; |
| 74 |
|
| 75 |
|
| 76 |
srb->cmd_len = 12; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
switch (srb->cmnd[0]) { |
| 82 |
|
| 83 |
|
| 84 |
case INQUIRY: |
| 85 |
srb->cmnd[4] = 36; |
| 86 |
break; |
| 87 |
|
| 88 |
|
| 89 |
case MODE_SENSE_10: |
| 90 |
srb->cmnd[7] = 0; |
| 91 |
srb->cmnd[8] = 8; |
| 92 |
break; |
| 93 |
|
| 94 |
|
| 95 |
case REQUEST_SENSE: |
| 96 |
srb->cmnd[4] = 18; |
| 97 |
break; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
usb_stor_invoke_transport(srb, us); |
| 102 |
} |
| 103 |
|
| 104 |
void usb_stor_transparent_scsi_command(struct scsi_cmnd *srb, |
| 105 |
struct us_data *us) |
| 106 |
{ |
| 107 |
|
| 108 |
usb_stor_invoke_transport(srb, us); |
| 109 |
} |
| 110 |
EXPORT_SYMBOL_GPL(usb_stor_transparent_scsi_command); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
unsigned int usb_stor_access_xfer_buf(unsigned char *buffer, |
| 122 |
unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **sgptr, |
| 123 |
unsigned int *offset, enum xfer_buf_dir dir) |
| 124 |
{ |
| 125 |
unsigned int cnt = 0; |
| 126 |
struct scatterlist *sg = *sgptr; |
| 127 |
struct sg_mapping_iter miter; |
| 128 |
unsigned int nents = scsi_sg_count(srb); |
| 129 |
|
| 130 |
if (sg) |
| 131 |
nents = sg_nents(sg); |
| 132 |
else |
| 133 |
sg = scsi_sglist(srb); |
| 134 |
|
| 135 |
sg_miter_start(&miter, sg, nents, dir == FROM_XFER_BUF ? |
| 136 |
SG_MITER_FROM_SG: SG_MITER_TO_SG); |
| 137 |
|
| 138 |
if (!sg_miter_skip(&miter, *offset)) |
| 139 |
return cnt; |
| 140 |
|
| 141 |
while (sg_miter_next(&miter) && cnt < buflen) { |
| 142 |
unsigned int len = min(miter.length, buflen - cnt); |
| 143 |
|
| 144 |
if (dir == FROM_XFER_BUF) |
| 145 |
memcpy(buffer + cnt, miter.addr, len); |
| 146 |
else |
| 147 |
memcpy(miter.addr, buffer + cnt, len); |
| 148 |
|
| 149 |
if (*offset + len < miter.piter.sg->length) { |
| 150 |
*offset += len; |
| 151 |
*sgptr = miter.piter.sg; |
| 152 |
} else { |
| 153 |
*offset = 0; |
| 154 |
*sgptr = sg_next(miter.piter.sg); |
| 155 |
} |
| 156 |
cnt += len; |
| 157 |
} |
| 158 |
sg_miter_stop(&miter); |
| 159 |
|
| 160 |
return cnt; |
| 161 |
} |
| 162 |
EXPORT_SYMBOL_GPL(usb_stor_access_xfer_buf); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
void usb_stor_set_xfer_buf(unsigned char *buffer, |
| 169 |
unsigned int buflen, struct scsi_cmnd *srb) |
| 170 |
{ |
| 171 |
unsigned int offset = 0; |
| 172 |
struct scatterlist *sg = NULL; |
| 173 |
|
| 174 |
buflen = min(buflen, scsi_bufflen(srb)); |
| 175 |
buflen = usb_stor_access_xfer_buf(buffer, buflen, srb, &sg, &offset, |
| 176 |
TO_XFER_BUF); |
| 177 |
if (buflen < scsi_bufflen(srb)) |
| 178 |
scsi_set_resid(srb, scsi_bufflen(srb) - buflen); |
| 179 |
} |
| 180 |
EXPORT_SYMBOL_GPL(usb_stor_set_xfer_buf); |