Staging: keucr driver: fix uninitialized variable & proper memset length
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / keucr / sdscsi.c
blobd646507a361135f975b6e36b6fbd70014a0f40eb
1 #include <linux/sched.h>
2 #include <linux/errno.h>
3 #include <linux/slab.h>
5 #include <scsi/scsi.h>
6 #include <scsi/scsi_eh.h>
7 #include <scsi/scsi_device.h>
9 #include "usb.h"
10 #include "scsiglue.h"
11 #include "transport.h"
13 int SD_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb);
14 int SD_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb);
15 int SD_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb);
16 int SD_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb);
17 int SD_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb);
18 int SD_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb);
19 int SD_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb);
21 //----- SD_SCSIIrp() --------------------------------------------------
22 int SD_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb)
24 int result;
26 us->SrbStatus = SS_SUCCESS;
27 switch (srb->cmnd[0])
29 case TEST_UNIT_READY : result = SD_SCSI_Test_Unit_Ready (us, srb); break; //0x00
30 case INQUIRY : result = SD_SCSI_Inquiry (us, srb); break; //0x12
31 case MODE_SENSE : result = SD_SCSI_Mode_Sense (us, srb); break; //0x1A
32 // case START_STOP : result = SD_SCSI_Start_Stop (us, srb); break; //0x1B
33 case READ_CAPACITY : result = SD_SCSI_Read_Capacity (us, srb); break; //0x25
34 case READ_10 : result = SD_SCSI_Read (us, srb); break; //0x28
35 case WRITE_10 : result = SD_SCSI_Write (us, srb); break; //0x2A
37 default:
38 us->SrbStatus = SS_ILLEGAL_REQUEST;
39 result = USB_STOR_TRANSPORT_FAILED;
40 break;
42 return result;
45 //----- SD_SCSI_Test_Unit_Ready() --------------------------------------------------
46 int SD_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb)
48 //printk("SD_SCSI_Test_Unit_Ready\n");
49 if (us->SD_Status.Insert && us->SD_Status.Ready)
50 return USB_STOR_TRANSPORT_GOOD;
51 else
53 ENE_SDInit(us);
54 return USB_STOR_TRANSPORT_GOOD;
57 return USB_STOR_TRANSPORT_GOOD;
60 //----- SD_SCSI_Inquiry() --------------------------------------------------
61 int SD_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb)
63 //printk("SD_SCSI_Inquiry\n");
64 BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30};
66 usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF);
67 return USB_STOR_TRANSPORT_GOOD;
71 //----- SD_SCSI_Mode_Sense() --------------------------------------------------
72 int SD_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb)
74 BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
75 BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
77 if (us->SD_Status.WtP)
78 usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF);
79 else
80 usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF);
83 return USB_STOR_TRANSPORT_GOOD;
86 //----- SD_SCSI_Read_Capacity() --------------------------------------------------
87 int SD_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb)
89 unsigned int offset = 0;
90 struct scatterlist *sg = NULL;
91 DWORD bl_num;
92 WORD bl_len;
93 BYTE buf[8];
95 printk("SD_SCSI_Read_Capacity\n");
96 if ( us->SD_Status.HiCapacity )
98 bl_len = 0x200;
99 if (us->SD_Status.IsMMC)
100 bl_num = us->HC_C_SIZE-1;
101 else
102 bl_num = (us->HC_C_SIZE + 1) * 1024 - 1;
104 else
106 bl_len = 1<<(us->SD_READ_BL_LEN);
107 bl_num = us->SD_Block_Mult*(us->SD_C_SIZE+1)*(1<<(us->SD_C_SIZE_MULT+2)) - 1;
109 us->bl_num = bl_num;
110 printk("bl_len = %x\n", bl_len);
111 printk("bl_num = %x\n", bl_num);
113 //srb->request_bufflen = 8;
114 buf[0] = (bl_num>>24) & 0xff;
115 buf[1] = (bl_num>>16) & 0xff;
116 buf[2] = (bl_num>> 8) & 0xff;
117 buf[3] = (bl_num>> 0) & 0xff;
118 buf[4] = (bl_len>>24) & 0xff;
119 buf[5] = (bl_len>>16) & 0xff;
120 buf[6] = (bl_len>> 8) & 0xff;
121 buf[7] = (bl_len>> 0) & 0xff;
123 usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF);
124 //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF);
126 return USB_STOR_TRANSPORT_GOOD;
129 //----- SD_SCSI_Read() --------------------------------------------------
130 int SD_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
132 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
133 int result;
134 PBYTE Cdb = srb->cmnd;
135 DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
136 ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
137 WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
138 DWORD bnByte = bn * 0x200;
139 DWORD blenByte = blen * 0x200;
141 if (bn > us->bl_num)
142 return USB_STOR_TRANSPORT_ERROR;
144 result = ENE_LoadBinCode(us, SD_RW_PATTERN);
145 if (result != USB_STOR_XFER_GOOD)
147 printk("Load SD RW pattern Fail !!\n");
148 return USB_STOR_TRANSPORT_ERROR;
151 if ( us->SD_Status.HiCapacity )
152 bnByte = bn;
154 // set up the command wrapper
155 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
156 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
157 bcb->DataTransferLength = blenByte;
158 bcb->Flags = 0x80;
159 bcb->CDB[0] = 0xF1;
160 bcb->CDB[5] = (BYTE)(bnByte);
161 bcb->CDB[4] = (BYTE)(bnByte>>8);
162 bcb->CDB[3] = (BYTE)(bnByte>>16);
163 bcb->CDB[2] = (BYTE)(bnByte>>24);
165 result = ENE_SendScsiCmd(us, FDIR_READ, scsi_sglist(srb), 1);
166 return result;
169 //----- SD_SCSI_Write() --------------------------------------------------
170 int SD_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
172 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
173 int result;
174 PBYTE Cdb = srb->cmnd;
175 DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
176 ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
177 WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
178 DWORD bnByte = bn * 0x200;
179 DWORD blenByte = blen * 0x200;
181 if (bn > us->bl_num)
182 return USB_STOR_TRANSPORT_ERROR;
184 result = ENE_LoadBinCode(us, SD_RW_PATTERN);
185 if (result != USB_STOR_XFER_GOOD)
187 printk("Load SD RW pattern Fail !!\n");
188 return USB_STOR_TRANSPORT_ERROR;
191 if ( us->SD_Status.HiCapacity )
192 bnByte = bn;
194 // set up the command wrapper
195 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
196 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
197 bcb->DataTransferLength = blenByte;
198 bcb->Flags = 0x00;
199 bcb->CDB[0] = 0xF0;
200 bcb->CDB[5] = (BYTE)(bnByte);
201 bcb->CDB[4] = (BYTE)(bnByte>>8);
202 bcb->CDB[3] = (BYTE)(bnByte>>16);
203 bcb->CDB[2] = (BYTE)(bnByte>>24);
205 result = ENE_SendScsiCmd(us, FDIR_WRITE, scsi_sglist(srb), 1);
206 return result;