Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
[deliverable/linux.git] / drivers / staging / keucr / smscsi.c
CommitLineData
126bb03b
AC
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"
126bb03b
AC
12#include "smil.h"
13
e1d94ecc
RP
14int SM_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb);
15int SM_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb);
16int SM_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb);
17int SM_SCSI_Start_Stop(struct us_data *us, struct scsi_cmnd *srb);
18int SM_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb);
19int SM_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb);
20int SM_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb);
126bb03b 21
126bb03b
AC
22extern PBYTE SMHostAddr;
23extern DWORD ErrXDCode;
24
e1d94ecc 25/* ----- SM_SCSIIrp() -------------------------------------------------- */
126bb03b
AC
26int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb)
27{
28 int result;
29
30 us->SrbStatus = SS_SUCCESS;
e1d94ecc
RP
31 switch (srb->cmnd[0]) {
32 case TEST_UNIT_READY:
33 result = SM_SCSI_Test_Unit_Ready(us, srb);
34 break; /* 0x00 */
35 case INQUIRY:
36 result = SM_SCSI_Inquiry(us, srb);
37 break; /* 0x12 */
38 case MODE_SENSE:
39 result = SM_SCSI_Mode_Sense(us, srb);
40 break; /* 0x1A */
41 case READ_CAPACITY:
42 result = SM_SCSI_Read_Capacity(us, srb);
43 break; /* 0x25 */
44 case READ_10:
45 result = SM_SCSI_Read(us, srb);
46 break; /* 0x28 */
47 case WRITE_10:
48 result = SM_SCSI_Write(us, srb);
49 break; /* 0x2A */
50
51 default:
126bb03b
AC
52 us->SrbStatus = SS_ILLEGAL_REQUEST;
53 result = USB_STOR_TRANSPORT_FAILED;
54 break;
55 }
56 return result;
57}
58
e1d94ecc 59/* ----- SM_SCSI_Test_Unit_Ready() -------------------------------------------------- */
126bb03b
AC
60int SM_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb)
61{
126bb03b
AC
62 if (us->SM_Status.Insert && us->SM_Status.Ready)
63 return USB_STOR_TRANSPORT_GOOD;
e1d94ecc 64 else {
126bb03b
AC
65 ENE_SMInit(us);
66 return USB_STOR_TRANSPORT_GOOD;
67 }
e1d94ecc 68
126bb03b
AC
69 return USB_STOR_TRANSPORT_GOOD;
70}
71
e1d94ecc 72/* ----- SM_SCSI_Inquiry() -------------------------------------------------- */
126bb03b
AC
73int SM_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb)
74{
126bb03b
AC
75 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};
76
77 usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF);
78 return USB_STOR_TRANSPORT_GOOD;
79}
80
81
e1d94ecc 82/* ----- SM_SCSI_Mode_Sense() -------------------------------------------------- */
126bb03b
AC
83int SM_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb)
84{
e1d94ecc
RP
85 BYTE mediaNoWP[12] = {0x0b, 0x00, 0x00, 0x08, 0x00, 0x00, 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00};
86 BYTE mediaWP[12] = {0x0b, 0x00, 0x80, 0x08, 0x00, 0x00, 0x71, 0xc0, 0x00, 0x00, 0x02, 0x00};
126bb03b
AC
87
88 if (us->SM_Status.WtP)
89 usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF);
90 else
91 usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF);
92
93
94 return USB_STOR_TRANSPORT_GOOD;
95}
96
e1d94ecc 97/* ----- SM_SCSI_Read_Capacity() -------------------------------------------------- */
126bb03b
AC
98int SM_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb)
99{
100 unsigned int offset = 0;
101 struct scatterlist *sg = NULL;
102 DWORD bl_num;
103 WORD bl_len;
104 BYTE buf[8];
105
106 printk("SM_SCSI_Read_Capacity\n");
107
108 bl_len = 0x200;
109 bl_num = Ssfdc.MaxLogBlocks * Ssfdc.MaxSectors * Ssfdc.MaxZones - 1;
126bb03b
AC
110
111 us->bl_num = bl_num;
112 printk("bl_len = %x\n", bl_len);
113 printk("bl_num = %x\n", bl_num);
114
e1d94ecc
RP
115 buf[0] = (bl_num >> 24) & 0xff;
116 buf[1] = (bl_num >> 16) & 0xff;
117 buf[2] = (bl_num >> 8) & 0xff;
118 buf[3] = (bl_num >> 0) & 0xff;
119 buf[4] = (bl_len >> 24) & 0xff;
120 buf[5] = (bl_len >> 16) & 0xff;
121 buf[6] = (bl_len >> 8) & 0xff;
122 buf[7] = (bl_len >> 0) & 0xff;
123
126bb03b 124 usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF);
126bb03b
AC
125
126 return USB_STOR_TRANSPORT_GOOD;
127}
128
e1d94ecc 129/* ----- SM_SCSI_Read() -------------------------------------------------- */
126bb03b
AC
130int SM_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb)
131{
e1d94ecc 132 int result = 0;
126bb03b 133 PBYTE Cdb = srb->cmnd;
e1d94ecc
RP
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);
126bb03b
AC
137 DWORD blenByte = blen * 0x200;
138 void *buf;
139
e1d94ecc 140
126bb03b
AC
141 if (bn > us->bl_num)
142 return USB_STOR_TRANSPORT_ERROR;
143
144 buf = kmalloc(blenByte, GFP_KERNEL);
b1f5f54e
VK
145 if (buf == NULL)
146 return USB_STOR_TRANSPORT_ERROR;
126bb03b
AC
147 result = Media_D_ReadSector(us, bn, blen, buf);
148 usb_stor_set_xfer_buf(us, buf, blenByte, srb, TO_XFER_BUF);
149 kfree(buf);
150
151 if (!result)
152 return USB_STOR_TRANSPORT_GOOD;
153 else
154 return USB_STOR_TRANSPORT_ERROR;
155
156 return USB_STOR_TRANSPORT_GOOD;
157}
158
e1d94ecc 159/* ----- SM_SCSI_Write() -------------------------------------------------- */
126bb03b
AC
160int SM_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb)
161{
e1d94ecc 162 int result = 0;
126bb03b 163 PBYTE Cdb = srb->cmnd;
e1d94ecc
RP
164 DWORD bn = ((Cdb[2] << 24) & 0xff000000) | ((Cdb[3] << 16) & 0x00ff0000) |
165 ((Cdb[4] << 8) & 0x0000ff00) | ((Cdb[5] << 0) & 0x000000ff);
166 WORD blen = ((Cdb[7] << 8) & 0xff00) | ((Cdb[8] << 0) & 0x00ff);
126bb03b
AC
167 DWORD blenByte = blen * 0x200;
168 void *buf;
169
126bb03b
AC
170
171 if (bn > us->bl_num)
172 return USB_STOR_TRANSPORT_ERROR;
173
174 buf = kmalloc(blenByte, GFP_KERNEL);
b1f5f54e
VK
175 if (buf == NULL)
176 return USB_STOR_TRANSPORT_ERROR;
126bb03b
AC
177 usb_stor_set_xfer_buf(us, buf, blenByte, srb, FROM_XFER_BUF);
178 result = Media_D_CopySector(us, bn, blen, buf);
179 kfree(buf);
180
181 if (!result)
182 return USB_STOR_TRANSPORT_GOOD;
183 else
184 return USB_STOR_TRANSPORT_ERROR;
185
186 return USB_STOR_TRANSPORT_GOOD;
187}
188
This page took 0.22982 seconds and 5 git commands to generate.