Commit | Line | Data |
---|---|---|
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" | |
12 | //#include "smcommon.h" | |
13 | #include "smil.h" | |
14 | ||
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); | |
22 | ||
23 | extern struct SSFDCTYPE Ssfdc; | |
24 | extern struct ADDRESS Media; | |
25 | extern PBYTE SMHostAddr; | |
26 | extern DWORD ErrXDCode; | |
27 | ||
28 | //----- SM_SCSIIrp() -------------------------------------------------- | |
29 | int SM_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb) | |
30 | { | |
31 | int result; | |
32 | ||
33 | us->SrbStatus = SS_SUCCESS; | |
34 | switch (srb->cmnd[0]) | |
35 | { | |
36 | case TEST_UNIT_READY : result = SM_SCSI_Test_Unit_Ready (us, srb); break; //0x00 | |
37 | case INQUIRY : result = SM_SCSI_Inquiry (us, srb); break; //0x12 | |
38 | case MODE_SENSE : result = SM_SCSI_Mode_Sense (us, srb); break; //0x1A | |
39 | case READ_CAPACITY : result = SM_SCSI_Read_Capacity (us, srb); break; //0x25 | |
40 | case READ_10 : result = SM_SCSI_Read (us, srb); break; //0x28 | |
41 | case WRITE_10 : result = SM_SCSI_Write (us, srb); break; //0x2A | |
42 | ||
43 | default: | |
44 | us->SrbStatus = SS_ILLEGAL_REQUEST; | |
45 | result = USB_STOR_TRANSPORT_FAILED; | |
46 | break; | |
47 | } | |
48 | return result; | |
49 | } | |
50 | ||
51 | //----- SM_SCSI_Test_Unit_Ready() -------------------------------------------------- | |
52 | int SM_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) | |
53 | { | |
54 | //printk("SM_SCSI_Test_Unit_Ready\n"); | |
55 | if (us->SM_Status.Insert && us->SM_Status.Ready) | |
56 | return USB_STOR_TRANSPORT_GOOD; | |
57 | else | |
58 | { | |
59 | ENE_SMInit(us); | |
60 | return USB_STOR_TRANSPORT_GOOD; | |
61 | } | |
62 | ||
63 | return USB_STOR_TRANSPORT_GOOD; | |
64 | } | |
65 | ||
66 | //----- SM_SCSI_Inquiry() -------------------------------------------------- | |
67 | int SM_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb) | |
68 | { | |
69 | //printk("SM_SCSI_Inquiry\n"); | |
70 | 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}; | |
71 | ||
72 | usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF); | |
73 | return USB_STOR_TRANSPORT_GOOD; | |
74 | } | |
75 | ||
76 | ||
77 | //----- SM_SCSI_Mode_Sense() -------------------------------------------------- | |
78 | int SM_SCSI_Mode_Sense(struct us_data *us, struct scsi_cmnd *srb) | |
79 | { | |
80 | BYTE mediaNoWP[12] = {0x0b,0x00,0x00,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; | |
81 | BYTE mediaWP[12] = {0x0b,0x00,0x80,0x08,0x00,0x00,0x71,0xc0,0x00,0x00,0x02,0x00}; | |
82 | ||
83 | if (us->SM_Status.WtP) | |
84 | usb_stor_set_xfer_buf(us, mediaWP, 12, srb, TO_XFER_BUF); | |
85 | else | |
86 | usb_stor_set_xfer_buf(us, mediaNoWP, 12, srb, TO_XFER_BUF); | |
87 | ||
88 | ||
89 | return USB_STOR_TRANSPORT_GOOD; | |
90 | } | |
91 | ||
92 | //----- SM_SCSI_Read_Capacity() -------------------------------------------------- | |
93 | int SM_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) | |
94 | { | |
95 | unsigned int offset = 0; | |
96 | struct scatterlist *sg = NULL; | |
97 | DWORD bl_num; | |
98 | WORD bl_len; | |
99 | BYTE buf[8]; | |
100 | ||
101 | printk("SM_SCSI_Read_Capacity\n"); | |
102 | ||
103 | bl_len = 0x200; | |
104 | bl_num = Ssfdc.MaxLogBlocks * Ssfdc.MaxSectors * Ssfdc.MaxZones - 1; | |
105 | //printk("MaxLogBlocks = %x\n", Ssfdc.MaxLogBlocks); | |
106 | //printk("MaxSectors = %x\n", Ssfdc.MaxSectors); | |
107 | //printk("MaxZones = %x\n", Ssfdc.MaxZones); | |
108 | //printk("bl_num = %x\n", bl_num); | |
109 | ||
110 | us->bl_num = bl_num; | |
111 | printk("bl_len = %x\n", bl_len); | |
112 | printk("bl_num = %x\n", bl_num); | |
113 | ||
114 | //srb->request_bufflen = 8; | |
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 | ||
124 | usb_stor_access_xfer_buf(us, buf, 8, srb, &sg, &offset, TO_XFER_BUF); | |
125 | //usb_stor_set_xfer_buf(us, buf, srb->request_bufflen, srb, TO_XFER_BUF); | |
126 | ||
127 | return USB_STOR_TRANSPORT_GOOD; | |
128 | } | |
129 | ||
130 | //----- SM_SCSI_Read() -------------------------------------------------- | |
131 | int SM_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) | |
132 | { | |
133 | //struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | |
134 | int result=0; | |
135 | PBYTE Cdb = srb->cmnd; | |
136 | DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | | |
137 | ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); | |
138 | WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); | |
139 | DWORD blenByte = blen * 0x200; | |
140 | void *buf; | |
141 | ||
142 | //printk("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); | |
143 | ||
144 | if (bn > us->bl_num) | |
145 | return USB_STOR_TRANSPORT_ERROR; | |
146 | ||
147 | buf = kmalloc(blenByte, GFP_KERNEL); | |
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); | |
151 | ||
152 | if (!result) | |
153 | return USB_STOR_TRANSPORT_GOOD; | |
154 | else | |
155 | return USB_STOR_TRANSPORT_ERROR; | |
156 | ||
157 | return USB_STOR_TRANSPORT_GOOD; | |
158 | } | |
159 | ||
160 | //----- SM_SCSI_Write() -------------------------------------------------- | |
161 | int SM_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) | |
162 | { | |
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; | |
171 | ||
172 | //printk("SCSIOP_Write --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); | |
173 | ||
174 | if (bn > us->bl_num) | |
175 | return USB_STOR_TRANSPORT_ERROR; | |
176 | ||
177 | buf = kmalloc(blenByte, GFP_KERNEL); | |
178 | usb_stor_set_xfer_buf(us, buf, blenByte, srb, FROM_XFER_BUF); | |
179 | result = Media_D_CopySector(us, bn, blen, buf); | |
180 | kfree(buf); | |
181 | ||
182 | if (!result) | |
183 | return USB_STOR_TRANSPORT_GOOD; | |
184 | else | |
185 | return USB_STOR_TRANSPORT_ERROR; | |
186 | ||
187 | return USB_STOR_TRANSPORT_GOOD; | |
188 | } | |
189 |