Merge remote-tracking branch 'pm/linux-next'
[linux-2.6/next.git] / drivers / staging / keucr / smscsi.c
bloba6fa77f9c48e08f29e28133234bf66f377f1e4c7
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"
12 //#include "smcommon.h"
13 #include "smil.h"
15 int SM_SCSI_Test_Unit_Ready (struct us_data *us, struct scsi_cmnd *srb);
16 int SM_SCSI_Inquiry (struct us_data *us, struct scsi_cmnd *srb);
17 int SM_SCSI_Mode_Sense (struct us_data *us, struct scsi_cmnd *srb);
18 int SM_SCSI_Start_Stop (struct us_data *us, struct scsi_cmnd *srb);
19 int SM_SCSI_Read_Capacity (struct us_data *us, struct scsi_cmnd *srb);
20 int SM_SCSI_Read (struct us_data *us, struct scsi_cmnd *srb);
21 int SM_SCSI_Write (struct us_data *us, struct scsi_cmnd *srb);
23 extern PBYTE SMHostAddr;
24 extern DWORD ErrXDCode;
26 //----- SM_SCSIIrp() --------------------------------------------------
27 int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb)
29 int result;
31 us->SrbStatus = SS_SUCCESS;
32 switch (srb->cmnd[0])
34 case TEST_UNIT_READY : result = SM_SCSI_Test_Unit_Ready (us, srb); break; //0x00
35 case INQUIRY : result = SM_SCSI_Inquiry (us, srb); break; //0x12
36 case MODE_SENSE : result = SM_SCSI_Mode_Sense (us, srb); break; //0x1A
37 case READ_CAPACITY : result = SM_SCSI_Read_Capacity (us, srb); break; //0x25
38 case READ_10 : result = SM_SCSI_Read (us, srb); break; //0x28
39 case WRITE_10 : result = SM_SCSI_Write (us, srb); break; //0x2A
41 default:
42 us->SrbStatus = SS_ILLEGAL_REQUEST;
43 result = USB_STOR_TRANSPORT_FAILED;
44 break;
46 return result;
49 //----- SM_SCSI_Test_Unit_Ready() --------------------------------------------------
50 int SM_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb)
52 //printk("SM_SCSI_Test_Unit_Ready\n");
53 if (us->SM_Status.Insert && us->SM_Status.Ready)
54 return USB_STOR_TRANSPORT_GOOD;
55 else
57 ENE_SMInit(us);
58 return USB_STOR_TRANSPORT_GOOD;
61 return USB_STOR_TRANSPORT_GOOD;
64 //----- SM_SCSI_Inquiry() --------------------------------------------------
65 int SM_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb)
67 //printk("SM_SCSI_Inquiry\n");
68 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};
70 usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF);
71 return USB_STOR_TRANSPORT_GOOD;
75 //----- SM_SCSI_Mode_Sense() --------------------------------------------------
76 int SM_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb)
78 BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
79 BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00};
81 if (us->SM_Status.WtP)
82 usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF);
83 else
84 usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF);
87 return USB_STOR_TRANSPORT_GOOD;
90 //----- SM_SCSI_Read_Capacity() --------------------------------------------------
91 int SM_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb)
93 unsigned int offset = 0;
94 struct scatterlist *sg = NULL;
95 DWORD bl_num;
96 WORD bl_len;
97 BYTE buf[8];
99 printk("SM_SCSI_Read_Capacity\n");
101 bl_len = 0x200;
102 bl_num = Ssfdc.MaxLogBlocks * Ssfdc.MaxSectors * Ssfdc.MaxZones - 1;
103 //printk("MaxLogBlocks = %x\n", Ssfdc.MaxLogBlocks);
104 //printk("MaxSectors = %x\n", Ssfdc.MaxSectors);
105 //printk("MaxZones = %x\n", Ssfdc.MaxZones);
106 //printk("bl_num = %x\n", bl_num);
108 us->bl_num = bl_num;
109 printk("bl_len = %x\n", bl_len);
110 printk("bl_num = %x\n", bl_num);
112 //srb->request_bufflen = 8;
113 buf[0] = (bl_num>>24) & 0xff;
114 buf[1] = (bl_num>>16) & 0xff;
115 buf[2] = (bl_num>> 8) & 0xff;
116 buf[3] = (bl_num>> 0) & 0xff;
117 buf[4] = (bl_len>>24) & 0xff;
118 buf[5] = (bl_len>>16) & 0xff;
119 buf[6] = (bl_len>> 8) & 0xff;
120 buf[7] = (bl_len>> 0) & 0xff;
122 usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF);
123 //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF);
125 return USB_STOR_TRANSPORT_GOOD;
128 //----- SM_SCSI_Read() --------------------------------------------------
129 int SM_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
131 //struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
132 int result=0;
133 PBYTE Cdb = srb->cmnd;
134 DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
135 ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
136 WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
137 DWORD blenByte = blen * 0x200;
138 void *buf;
140 //printk("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg);
142 if (bn > us->bl_num)
143 return USB_STOR_TRANSPORT_ERROR;
145 buf = kmalloc(blenByte, GFP_KERNEL);
146 if (buf == NULL)
147 return USB_STOR_TRANSPORT_ERROR;
148 result = Media_D_ReadSector(us, bn, blen, buf);
149 usb_stor_set_xfer_buf(us, buf, blenByte, srb, TO_XFER_BUF);
150 kfree(buf);
152 if (!result)
153 return USB_STOR_TRANSPORT_GOOD;
154 else
155 return USB_STOR_TRANSPORT_ERROR;
157 return USB_STOR_TRANSPORT_GOOD;
160 //----- SM_SCSI_Write() --------------------------------------------------
161 int SM_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
163 //struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
164 int result=0;
165 PBYTE Cdb = srb->cmnd;
166 DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) |
167 ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff);
168 WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff);
169 DWORD blenByte = blen * 0x200;
170 void *buf;
172 //printk("SCSIOP_Write --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg);
174 if (bn > us->bl_num)
175 return USB_STOR_TRANSPORT_ERROR;
177 buf = kmalloc(blenByte, GFP_KERNEL);
178 if (buf == NULL)
179 return USB_STOR_TRANSPORT_ERROR;
180 usb_stor_set_xfer_buf(us, buf, blenByte, srb, FROM_XFER_BUF);
181 result = Media_D_CopySector(us, bn, blen, buf);
182 kfree(buf);
184 if (!result)
185 return USB_STOR_TRANSPORT_GOOD;
186 else
187 return USB_STOR_TRANSPORT_ERROR;
189 return USB_STOR_TRANSPORT_GOOD;