Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 1 | #include <linux/sched.h> |
| 2 | #include <linux/errno.h> |
| 3 | #include <linux/slab.h> |
| 4 | |
| 5 | #include <scsi/scsi.h> |
| 6 | #include <scsi/scsi_eh.h> |
| 7 | #include <scsi/scsi_device.h> |
| 8 | |
| 9 | #include "usb.h" |
| 10 | #include "scsiglue.h" |
| 11 | #include "transport.h" |
| 12 | #include "init.h" |
| 13 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 14 | /* |
| 15 | * ENE_InitMedia(): |
| 16 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 17 | int ENE_InitMedia(struct us_data *us) |
| 18 | { |
| 19 | int result; |
| 20 | BYTE MiscReg03 = 0; |
| 21 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 22 | printk(KERN_INFO "--- Init Media ---\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 23 | result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03); |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 24 | if (result != USB_STOR_XFER_GOOD) { |
| 25 | printk(KERN_ERR "Read register fail !!\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 26 | return USB_STOR_TRANSPORT_ERROR; |
| 27 | } |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 28 | printk(KERN_INFO "MiscReg03 = %x\n", MiscReg03); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 29 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 30 | if (MiscReg03 & 0x02) { |
| 31 | if (!us->SM_Status.Ready && !us->MS_Status.Ready) { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 32 | result = ENE_SMInit(us); |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 33 | if (result != USB_STOR_XFER_GOOD) { |
Cho, Yu-Chen | 20c3d7f | 2011-07-07 11:27:14 +0800 | [diff] [blame] | 34 | return USB_STOR_TRANSPORT_ERROR; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | return result; |
| 40 | } |
| 41 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 42 | /* |
| 43 | * ENE_Read_BYTE() : |
| 44 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 45 | int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf) |
| 46 | { |
| 47 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 48 | int result; |
| 49 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 50 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 51 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 52 | bcb->DataTransferLength = 0x01; |
| 53 | bcb->Flags = 0x80; |
| 54 | bcb->CDB[0] = 0xED; |
| 55 | bcb->CDB[2] = (BYTE)(index>>8); |
| 56 | bcb->CDB[3] = (BYTE)index; |
| 57 | |
| 58 | result = ENE_SendScsiCmd(us, FDIR_READ, buf, 0); |
| 59 | return result; |
| 60 | } |
| 61 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 62 | /* |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 63 | *ENE_SMInit() |
| 64 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 65 | int ENE_SMInit(struct us_data *us) |
| 66 | { |
| 67 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 68 | int result; |
| 69 | BYTE buf[0x200]; |
| 70 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 71 | printk(KERN_INFO "transport --- ENE_SMInit\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 72 | |
| 73 | result = ENE_LoadBinCode(us, SM_INIT_PATTERN); |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 74 | if (result != USB_STOR_XFER_GOOD) { |
| 75 | printk(KERN_INFO "Load SM Init Code Fail !!\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 76 | return USB_STOR_TRANSPORT_ERROR; |
| 77 | } |
| 78 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 79 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 80 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 81 | bcb->DataTransferLength = 0x200; |
| 82 | bcb->Flags = 0x80; |
| 83 | bcb->CDB[0] = 0xF1; |
| 84 | bcb->CDB[1] = 0x01; |
| 85 | |
| 86 | result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 87 | if (result != USB_STOR_XFER_GOOD) { |
| 88 | printk(KERN_ERR |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 89 | "Execution SM Init Code Fail !! result = %x\n", result); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 90 | return USB_STOR_TRANSPORT_ERROR; |
| 91 | } |
| 92 | |
| 93 | us->SM_Status = *(PSM_STATUS)&buf[0]; |
| 94 | |
| 95 | us->SM_DeviceID = buf[1]; |
| 96 | us->SM_CardID = buf[2]; |
| 97 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 98 | if (us->SM_Status.Insert && us->SM_Status.Ready) { |
| 99 | printk(KERN_INFO "Insert = %x\n", us->SM_Status.Insert); |
| 100 | printk(KERN_INFO "Ready = %x\n", us->SM_Status.Ready); |
| 101 | printk(KERN_INFO "WtP = %x\n", us->SM_Status.WtP); |
| 102 | printk(KERN_INFO "DeviceID = %x\n", us->SM_DeviceID); |
| 103 | printk(KERN_INFO "CardID = %x\n", us->SM_CardID); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 104 | MediaChange = 1; |
| 105 | Check_D_MediaFmt(us); |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 106 | } else { |
| 107 | printk(KERN_ERR "SM Card Not Ready --- %x\n", buf[0]); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 108 | return USB_STOR_TRANSPORT_ERROR; |
| 109 | } |
| 110 | |
| 111 | return USB_STOR_TRANSPORT_GOOD; |
| 112 | } |
| 113 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 114 | /* |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 115 | * ENE_LoadBinCode() |
| 116 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 117 | int ENE_LoadBinCode(struct us_data *us, BYTE flag) |
| 118 | { |
| 119 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 120 | int result; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 121 | /* void *buf; */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 122 | PBYTE buf; |
| 123 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 124 | /* printk(KERN_INFO "transport --- ENE_LoadBinCode\n"); */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 125 | if (us->BIN_FLAG == flag) |
| 126 | return USB_STOR_TRANSPORT_GOOD; |
| 127 | |
| 128 | buf = kmalloc(0x800, GFP_KERNEL); |
Vasiliy Kulikov | b1f5f54 | 2010-09-19 11:36:23 +0400 | [diff] [blame] | 129 | if (buf == NULL) |
| 130 | return USB_STOR_TRANSPORT_ERROR; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 131 | switch (flag) { |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 132 | /* For SS */ |
| 133 | case SM_INIT_PATTERN: |
| 134 | printk(KERN_INFO "SM_INIT_PATTERN\n"); |
| 135 | memcpy(buf, SM_Init, 0x800); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 136 | break; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 137 | case SM_RW_PATTERN: |
| 138 | printk(KERN_INFO "SM_RW_PATTERN\n"); |
| 139 | memcpy(buf, SM_Rdwr, 0x800); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 140 | break; |
| 141 | } |
| 142 | |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 143 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 144 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 145 | bcb->DataTransferLength = 0x800; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 146 | bcb->Flags = 0x00; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 147 | bcb->CDB[0] = 0xEF; |
| 148 | |
| 149 | result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); |
| 150 | |
| 151 | kfree(buf); |
| 152 | us->BIN_FLAG = flag; |
| 153 | return result; |
| 154 | } |
| 155 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 156 | /* |
| 157 | * ENE_SendScsiCmd(): |
| 158 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 159 | int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg) |
| 160 | { |
| 161 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 162 | struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; |
| 163 | |
| 164 | int result; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 165 | unsigned int transfer_length = bcb->DataTransferLength, |
| 166 | cswlen = 0, partial = 0; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 167 | unsigned int residue; |
| 168 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 169 | /* printk(KERN_INFO "transport --- ENE_SendScsiCmd\n"); */ |
| 170 | /* send cmd to out endpoint */ |
| 171 | result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, |
| 172 | bcb, US_BULK_CB_WRAP_LEN, NULL); |
| 173 | if (result != USB_STOR_XFER_GOOD) { |
| 174 | printk(KERN_ERR "send cmd to out endpoint fail ---\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 175 | return USB_STOR_TRANSPORT_ERROR; |
| 176 | } |
| 177 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 178 | if (buf) { |
Al Cho | 6efe04e | 2010-11-26 19:07:27 +0800 | [diff] [blame] | 179 | unsigned int pipe = fDir; |
| 180 | |
| 181 | if (fDir == FDIR_READ) |
| 182 | pipe = us->recv_bulk_pipe; |
| 183 | else |
| 184 | pipe = us->send_bulk_pipe; |
| 185 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 186 | /* Bulk */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 187 | if (use_sg) |
| 188 | result = usb_stor_bulk_srb(us, pipe, us->srb); |
| 189 | else |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 190 | result = usb_stor_bulk_transfer_sg(us, pipe, buf, |
| 191 | transfer_length, 0, &partial); |
| 192 | if (result != USB_STOR_XFER_GOOD) { |
| 193 | printk(KERN_ERR "data transfer fail ---\n"); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 194 | return USB_STOR_TRANSPORT_ERROR; |
| 195 | } |
| 196 | } |
| 197 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 198 | /* Get CSW for device status */ |
| 199 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, |
| 200 | US_BULK_CS_WRAP_LEN, &cswlen); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 201 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 202 | if (result == USB_STOR_XFER_SHORT && cswlen == 0) { |
| 203 | printk(KERN_WARNING "Received 0-length CSW; retrying...\n"); |
| 204 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, |
| 205 | bcs, US_BULK_CS_WRAP_LEN, &cswlen); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 208 | if (result == USB_STOR_XFER_STALLED) { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 209 | /* get the status again */ |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 210 | printk(KERN_WARNING "Attempting to get CSW (2nd try)...\n"); |
| 211 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, |
| 212 | bcs, US_BULK_CS_WRAP_LEN, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | if (result != USB_STOR_XFER_GOOD) |
| 216 | return USB_STOR_TRANSPORT_ERROR; |
| 217 | |
| 218 | /* check bulk status */ |
| 219 | residue = le32_to_cpu(bcs->Residue); |
| 220 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 221 | /* |
| 222 | * try to compute the actual residue, based on how much data |
| 223 | * was really transferred and what the device tells us |
| 224 | */ |
| 225 | if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 226 | residue = min(residue, transfer_length); |
huajun li | 41e568d | 2011-03-04 10:56:18 +0800 | [diff] [blame] | 227 | if (us->srb) |
| 228 | scsi_set_resid(us->srb, max(scsi_get_resid(us->srb), |
| 229 | (int) residue)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | if (bcs->Status != US_BULK_STAT_OK) |
| 233 | return USB_STOR_TRANSPORT_ERROR; |
| 234 | |
| 235 | return USB_STOR_TRANSPORT_GOOD; |
| 236 | } |
| 237 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 238 | /* |
| 239 | * ENE_Read_Data() |
| 240 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 241 | int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length) |
| 242 | { |
| 243 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 244 | struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; |
| 245 | int result; |
| 246 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 247 | /* printk(KERN_INFO "transport --- ENE_Read_Data\n"); */ |
| 248 | /* set up the command wrapper */ |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 249 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 250 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 251 | bcb->DataTransferLength = length; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 252 | bcb->Flags = 0x80; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 253 | bcb->CDB[0] = 0xED; |
| 254 | bcb->CDB[2] = 0xFF; |
| 255 | bcb->CDB[3] = 0x81; |
| 256 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 257 | /* send cmd to out endpoint */ |
| 258 | result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, |
| 259 | US_BULK_CB_WRAP_LEN, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 260 | if (result != USB_STOR_XFER_GOOD) |
| 261 | return USB_STOR_TRANSPORT_ERROR; |
| 262 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 263 | /* R/W data */ |
| 264 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, |
| 265 | buf, length, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 266 | if (result != USB_STOR_XFER_GOOD) |
| 267 | return USB_STOR_TRANSPORT_ERROR; |
| 268 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 269 | /* Get CSW for device status */ |
| 270 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, |
| 271 | US_BULK_CS_WRAP_LEN, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 272 | if (result != USB_STOR_XFER_GOOD) |
| 273 | return USB_STOR_TRANSPORT_ERROR; |
| 274 | if (bcs->Status != US_BULK_STAT_OK) |
| 275 | return USB_STOR_TRANSPORT_ERROR; |
| 276 | |
| 277 | return USB_STOR_TRANSPORT_GOOD; |
| 278 | } |
| 279 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 280 | /* |
| 281 | * ENE_Write_Data(): |
| 282 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 283 | int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length) |
| 284 | { |
| 285 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; |
| 286 | struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; |
| 287 | int result; |
| 288 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 289 | /* printk("transport --- ENE_Write_Data\n"); */ |
| 290 | /* set up the command wrapper */ |
Konstantin Katuev | 307ae1d | 2010-10-29 12:18:18 +1100 | [diff] [blame] | 291 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 292 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
| 293 | bcb->DataTransferLength = length; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 294 | bcb->Flags = 0x00; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 295 | bcb->CDB[0] = 0xEE; |
| 296 | bcb->CDB[2] = 0xFF; |
| 297 | bcb->CDB[3] = 0x81; |
| 298 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 299 | /* send cmd to out endpoint */ |
| 300 | result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, |
| 301 | US_BULK_CB_WRAP_LEN, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 302 | if (result != USB_STOR_XFER_GOOD) |
| 303 | return USB_STOR_TRANSPORT_ERROR; |
| 304 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 305 | /* R/W data */ |
| 306 | result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, |
| 307 | buf, length, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 308 | if (result != USB_STOR_XFER_GOOD) |
| 309 | return USB_STOR_TRANSPORT_ERROR; |
| 310 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 311 | /* Get CSW for device status */ |
| 312 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, |
| 313 | US_BULK_CS_WRAP_LEN, NULL); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 314 | if (result != USB_STOR_XFER_GOOD) |
| 315 | return USB_STOR_TRANSPORT_ERROR; |
| 316 | if (bcs->Status != US_BULK_STAT_OK) |
| 317 | return USB_STOR_TRANSPORT_ERROR; |
| 318 | |
| 319 | return USB_STOR_TRANSPORT_GOOD; |
| 320 | } |
| 321 | |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 322 | /* |
| 323 | * usb_stor_print_cmd(): |
| 324 | */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 325 | void usb_stor_print_cmd(struct scsi_cmnd *srb) |
| 326 | { |
| 327 | PBYTE Cdb = srb->cmnd; |
| 328 | DWORD cmd = Cdb[0]; |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 329 | DWORD bn = ((Cdb[2] << 24) & 0xff000000) | |
| 330 | ((Cdb[3] << 16) & 0x00ff0000) | |
| 331 | ((Cdb[4] << 8) & 0x0000ff00) | |
| 332 | ((Cdb[5] << 0) & 0x000000ff); |
| 333 | WORD blen = ((Cdb[7] << 8) & 0xff00) | ((Cdb[8] << 0) & 0x00ff); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 334 | |
| 335 | switch (cmd) { |
| 336 | case TEST_UNIT_READY: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 337 | /* printk(KERN_INFO |
| 338 | "scsi cmd %X --- SCSIOP_TEST_UNIT_READY\n", cmd); */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 339 | break; |
| 340 | case INQUIRY: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 341 | printk(KERN_INFO "scsi cmd %X --- SCSIOP_INQUIRY\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 342 | break; |
| 343 | case MODE_SENSE: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 344 | printk(KERN_INFO "scsi cmd %X --- SCSIOP_MODE_SENSE\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 345 | break; |
| 346 | case START_STOP: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 347 | printk(KERN_INFO "scsi cmd %X --- SCSIOP_START_STOP\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 348 | break; |
| 349 | case READ_CAPACITY: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 350 | printk(KERN_INFO "scsi cmd %X --- SCSIOP_READ_CAPACITY\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 351 | break; |
| 352 | case READ_10: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 353 | /* printk(KERN_INFO |
| 354 | "scsi cmd %X --- SCSIOP_READ,bn = %X, blen = %X\n" |
| 355 | ,cmd, bn, blen); */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 356 | break; |
| 357 | case WRITE_10: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 358 | /* printk(KERN_INFO |
| 359 | "scsi cmd %X --- SCSIOP_WRITE, |
| 360 | bn = %X, blen = %X\n" , cmd, bn, blen); */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 361 | break; |
| 362 | case ALLOW_MEDIUM_REMOVAL: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 363 | printk(KERN_INFO |
| 364 | "scsi cmd %X --- SCSIOP_ALLOW_MEDIUM_REMOVAL\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 365 | break; |
| 366 | default: |
Al Cho | e93192a | 2010-11-26 19:06:39 +0800 | [diff] [blame] | 367 | printk(KERN_INFO "scsi cmd %X --- Other cmd\n", cmd); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 368 | break; |
| 369 | } |
| 370 | bn = 0; |
| 371 | blen = 0; |
| 372 | } |
| 373 | |