Lines 1-277
Link Here
|
1 |
--- os_freebsd.cpp.orig 2013-07-05 12:40:38.000000000 +0200 |
|
|
2 |
+++ os_freebsd.cpp 2014-03-03 19:16:11.000000000 +0100 |
3 |
@@ -75,7 +75,7 @@ |
4 |
#define PATHINQ_SETTINGS_SIZE 128 |
5 |
#endif |
6 |
|
7 |
-const char *os_XXXX_c_cvsid="$Id: os_freebsd.cpp 3824 2013-07-05 10:40:38Z samm2 $" \ |
8 |
+const char *os_XXXX_c_cvsid="$Id: os_freebsd.cpp 3874 2014-02-18 00:47:23Z samm2 $" \ |
9 |
ATACMDS_H_CVSID CCISS_H_CVSID CONFIG_H_CVSID INT64_H_CVSID OS_FREEBSD_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID; |
10 |
|
11 |
#define NO_RETURN 0 |
12 |
@@ -135,9 +135,9 @@ |
13 |
: virtual public /*implements*/ smart_device |
14 |
{ |
15 |
public: |
16 |
- explicit freebsd_smart_device(const char * mode) |
17 |
+ explicit freebsd_smart_device() |
18 |
: smart_device(never_called), |
19 |
- m_fd(-1), m_mode(mode) { } |
20 |
+ m_fd(-1) { } |
21 |
|
22 |
virtual ~freebsd_smart_device() throw(); |
23 |
|
24 |
@@ -157,7 +157,6 @@ |
25 |
|
26 |
private: |
27 |
int m_fd; ///< filedesc, -1 if not open. |
28 |
- const char * m_mode; ///< Mode string for deviceopen(). |
29 |
}; |
30 |
|
31 |
#ifdef __GLIBC__ |
32 |
@@ -249,7 +248,7 @@ |
33 |
|
34 |
freebsd_ata_device::freebsd_ata_device(smart_interface * intf, const char * dev_name, const char * req_type) |
35 |
: smart_device(intf, dev_name, "ata", req_type), |
36 |
- freebsd_smart_device("ATA") |
37 |
+ freebsd_smart_device() |
38 |
{ |
39 |
} |
40 |
|
41 |
@@ -445,7 +444,8 @@ |
42 |
} |
43 |
|
44 |
if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { |
45 |
- cam_error_print(m_camdev, &ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); |
46 |
+ if(scsi_debugmode > 0) |
47 |
+ cam_error_print(m_camdev, &ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); |
48 |
set_err(EIO); |
49 |
return -1; |
50 |
} |
51 |
@@ -489,10 +489,7 @@ |
52 |
freebsd_escalade_device::freebsd_escalade_device(smart_interface * intf, const char * dev_name, |
53 |
int escalade_type, int disknum) |
54 |
: smart_device(intf, dev_name, "3ware", "3ware"), |
55 |
- freebsd_smart_device( |
56 |
- escalade_type==CONTROLLER_3WARE_9000_CHAR ? "ATA_3WARE_9000" : |
57 |
- escalade_type==CONTROLLER_3WARE_678K_CHAR ? "ATA_3WARE_678K" : |
58 |
- /* CONTROLLER_3WARE_678K */ "ATA" ), |
59 |
+ freebsd_smart_device(), |
60 |
m_escalade_type(escalade_type), m_disknum(disknum) |
61 |
{ |
62 |
set_info().info_name = strprintf("%s [3ware_disk_%02d]", dev_name, disknum); |
63 |
@@ -704,7 +701,7 @@ |
64 |
freebsd_highpoint_device::freebsd_highpoint_device(smart_interface * intf, const char * dev_name, |
65 |
unsigned char controller, unsigned char channel, unsigned char port) |
66 |
: smart_device(intf, dev_name, "hpt", "hpt"), |
67 |
- freebsd_smart_device("ATA") |
68 |
+ freebsd_smart_device() |
69 |
{ |
70 |
m_hpt_data[0] = controller; m_hpt_data[1] = channel; m_hpt_data[2] = port; |
71 |
set_info().info_name = strprintf("%s [hpt_disk_%u/%u/%u]", dev_name, m_hpt_data[0], m_hpt_data[1], m_hpt_data[2]); |
72 |
@@ -897,7 +894,6 @@ |
73 |
virtual bool close(); |
74 |
|
75 |
private: |
76 |
- int m_fd; |
77 |
struct cam_device *m_camdev; |
78 |
}; |
79 |
|
80 |
@@ -921,17 +917,16 @@ |
81 |
freebsd_scsi_device::freebsd_scsi_device(smart_interface * intf, |
82 |
const char * dev_name, const char * req_type) |
83 |
: smart_device(intf, dev_name, "scsi", req_type), |
84 |
- freebsd_smart_device("SCSI") |
85 |
+ freebsd_smart_device() |
86 |
{ |
87 |
} |
88 |
|
89 |
|
90 |
bool freebsd_scsi_device::scsi_pass_through(scsi_cmnd_io * iop) |
91 |
{ |
92 |
- int report=scsi_debugmode; |
93 |
union ccb *ccb; |
94 |
|
95 |
- if (report > 0) { |
96 |
+ if (scsi_debugmode) { |
97 |
unsigned int k; |
98 |
const unsigned char * ucp = iop->cmnd; |
99 |
const char * np; |
100 |
@@ -940,7 +935,7 @@ |
101 |
pout(" [%s: ", np ? np : "<unknown opcode>"); |
102 |
for (k = 0; k < iop->cmnd_len; ++k) |
103 |
pout("%02x ", ucp[k]); |
104 |
- if ((report > 1) && |
105 |
+ if ((scsi_debugmode > 1) && |
106 |
(DXFER_TO_DEVICE == iop->dxfer_dir) && (iop->dxferp)) { |
107 |
int trunc = (iop->dxfer_len > 256) ? 1 : 0; |
108 |
|
109 |
@@ -949,18 +944,21 @@ |
110 |
dStrHex(iop->dxferp, (trunc ? 256 : iop->dxfer_len) , 1); |
111 |
} |
112 |
else |
113 |
- pout("]"); |
114 |
+ pout("]\n"); |
115 |
} |
116 |
|
117 |
if(m_camdev==NULL) { |
118 |
- warnx("error: camdev=0!"); |
119 |
- return -ENOTTY; |
120 |
+ if (scsi_debugmode) |
121 |
+ pout(" error: camdev=0!\n"); |
122 |
+ return set_err(ENOTTY); |
123 |
} |
124 |
|
125 |
if (!(ccb = cam_getccb(m_camdev))) { |
126 |
- warnx("error allocating ccb"); |
127 |
- return -ENOMEM; |
128 |
+ if (scsi_debugmode) |
129 |
+ pout(" error allocating ccb\n"); |
130 |
+ return set_err(ENOMEM); |
131 |
} |
132 |
+ |
133 |
// mfi SAT layer is known to be buggy |
134 |
if(!strcmp("mfi",m_camdev->sim_name)) { |
135 |
if (iop->cmnd[0] == SAT_ATA_PASSTHROUGH_12 || iop->cmnd[0] == SAT_ATA_PASSTHROUGH_16) { |
136 |
@@ -984,8 +982,8 @@ |
137 |
sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); |
138 |
|
139 |
cam_fill_csio(&ccb->csio, |
140 |
- /*retrires*/ 1, |
141 |
- /*cbfcnp*/ NULL, |
142 |
+ /* retries */ 1, |
143 |
+ /* cbfcnp */ NULL, |
144 |
/* flags */ (iop->dxfer_dir == DXFER_NONE ? CAM_DIR_NONE :(iop->dxfer_dir == DXFER_FROM_DEVICE ? CAM_DIR_IN : CAM_DIR_OUT)), |
145 |
/* tagaction */ MSG_SIMPLE_Q_TAG, |
146 |
/* dataptr */ iop->dxferp, |
147 |
@@ -996,44 +994,81 @@ |
148 |
memcpy(ccb->csio.cdb_io.cdb_bytes,iop->cmnd,iop->cmnd_len); |
149 |
|
150 |
if (cam_send_ccb(m_camdev,ccb) < 0) { |
151 |
- warn("error sending SCSI ccb"); |
152 |
- cam_error_print(m_camdev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr); |
153 |
+ if (scsi_debugmode) { |
154 |
+ pout(" error sending SCSI ccb\n"); |
155 |
+ cam_error_print(m_camdev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr); |
156 |
+ } |
157 |
cam_freeccb(ccb); |
158 |
- return -EIO; |
159 |
+ return set_err(EIO); |
160 |
+ } |
161 |
+ |
162 |
+ if (scsi_debugmode) { |
163 |
+ pout(" CAM status=0x%x, SCSI status=0x%x, resid=0x%x\n", |
164 |
+ ccb->ccb_h.status, ccb->csio.scsi_status, ccb->csio.resid); |
165 |
+ if ((scsi_debugmode > 1) && (DXFER_FROM_DEVICE == iop->dxfer_dir)) { |
166 |
+ int trunc, len; |
167 |
+ |
168 |
+ len = iop->dxfer_len - ccb->csio.resid; |
169 |
+ trunc = (len > 256) ? 1 : 0; |
170 |
+ if (len > 0) { |
171 |
+ pout(" Incoming data, len=%d%s:\n", len, |
172 |
+ (trunc ? " [only first 256 bytes shown]" : "")); |
173 |
+ dStrHex(iop->dxferp, (trunc ? 256 : len), 1); |
174 |
+ } |
175 |
+ else |
176 |
+ pout(" Incoming data trimmed to nothing by resid\n"); |
177 |
+ } |
178 |
} |
179 |
|
180 |
if (((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) && ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR)) { |
181 |
- cam_error_print(m_camdev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr); |
182 |
+ if (scsi_debugmode) |
183 |
+ cam_error_print(m_camdev,ccb,CAM_ESF_ALL,CAM_EPF_ALL,stderr); |
184 |
cam_freeccb(ccb); |
185 |
- return -EIO; |
186 |
+ return set_err(EIO); |
187 |
} |
188 |
|
189 |
- if (iop->sensep) { |
190 |
+ iop->resid = ccb->csio.resid; |
191 |
+ iop->scsi_status = ccb->csio.scsi_status; |
192 |
+ if (iop->sensep && (ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0) { |
193 |
+ if (scsi_debugmode) |
194 |
+ pout(" sense_len=0x%x, sense_resid=0x%x\n", |
195 |
+ ccb->csio.sense_len, ccb->csio.sense_resid); |
196 |
iop->resp_sense_len = ccb->csio.sense_len - ccb->csio.sense_resid; |
197 |
- memcpy(iop->sensep,&(ccb->csio.sense_data),iop->resp_sense_len); |
198 |
+ /* Some SCSI controller device drivers miscalculate the sense_resid |
199 |
+ field so cap resp_sense_len on max_sense_len. */ |
200 |
+ if (iop->resp_sense_len > iop->max_sense_len) |
201 |
+ iop->resp_sense_len = iop->max_sense_len; |
202 |
+ if (iop->resp_sense_len > 0) { |
203 |
+ memcpy(iop->sensep, &(ccb->csio.sense_data), iop->resp_sense_len); |
204 |
+ if (scsi_debugmode) { |
205 |
+ if (scsi_debugmode > 1) { |
206 |
+ pout(" >>> Sense buffer, len=%zu:\n", iop->resp_sense_len); |
207 |
+ dStrHex(iop->sensep, iop->resp_sense_len, 1); |
208 |
+ } |
209 |
+ if ((iop->sensep[0] & 0x7f) > 0x71) |
210 |
+ pout(" status=0x%x: [desc] sense_key=0x%x asc=0x%x ascq=0x%x\n", |
211 |
+ iop->scsi_status, iop->sensep[1] & 0xf, |
212 |
+ iop->sensep[2], iop->sensep[3]); |
213 |
+ else |
214 |
+ pout(" status=0x%x: sense_key=0x%x asc=0x%x ascq=0x%x\n", |
215 |
+ iop->scsi_status, iop->sensep[2] & 0xf, |
216 |
+ iop->sensep[12], iop->sensep[13]); |
217 |
+ } |
218 |
+ } |
219 |
+ else if (scsi_debugmode) |
220 |
+ pout(" status=0x%x\n", iop->scsi_status); |
221 |
} |
222 |
- |
223 |
- iop->scsi_status = ccb->csio.scsi_status; |
224 |
+ else if (scsi_debugmode) |
225 |
+ pout(" status=0x%x\n", iop->scsi_status); |
226 |
|
227 |
cam_freeccb(ccb); |
228 |
|
229 |
- if (report > 0) { |
230 |
- int trunc; |
231 |
- |
232 |
- pout(" status=0\n"); |
233 |
- trunc = (iop->dxfer_len > 256) ? 1 : 0; |
234 |
- |
235 |
- pout(" Incoming data, len=%d%s:\n", (int)iop->dxfer_len, |
236 |
- (trunc ? " [only first 256 bytes shown]" : "")); |
237 |
- dStrHex(iop->dxferp, (trunc ? 256 : iop->dxfer_len) , 1); |
238 |
- } |
239 |
- |
240 |
// mfip replacing PDT of the device so response does not make a sense |
241 |
// this sets PDT to 00h - direct-access block device |
242 |
if((!strcmp("mfi", m_camdev->sim_name) || !strcmp("mpt", m_camdev->sim_name)) |
243 |
&& iop->cmnd[0] == INQUIRY) { |
244 |
- if (report > 0) { |
245 |
- pout("device on %s controller, patching PDT\n", m_camdev->sim_name); |
246 |
+ if (scsi_debugmode) { |
247 |
+ pout(" device on %s controller, patching PDT\n", m_camdev->sim_name); |
248 |
} |
249 |
iop->dxferp[0] = iop->dxferp[0] & 0xe0; |
250 |
} |
251 |
@@ -1077,7 +1112,7 @@ |
252 |
// Areca RAID Controller(SATA Disk) |
253 |
freebsd_areca_ata_device::freebsd_areca_ata_device(smart_interface * intf, const char * dev_name, int disknum, int encnum) |
254 |
: smart_device(intf, dev_name, "areca", "areca"), |
255 |
- freebsd_smart_device("ATA") |
256 |
+ freebsd_smart_device() |
257 |
{ |
258 |
set_disknum(disknum); |
259 |
set_encnum(encnum); |
260 |
@@ -1146,7 +1181,7 @@ |
261 |
// Areca RAID Controller(SAS Device) |
262 |
freebsd_areca_scsi_device::freebsd_areca_scsi_device(smart_interface * intf, const char * dev_name, int disknum, int encnum) |
263 |
: smart_device(intf, dev_name, "areca", "areca"), |
264 |
- freebsd_smart_device("SCSI") |
265 |
+ freebsd_smart_device() |
266 |
{ |
267 |
set_disknum(disknum); |
268 |
set_encnum(encnum); |
269 |
@@ -1220,7 +1255,7 @@ |
270 |
freebsd_cciss_device::freebsd_cciss_device(smart_interface * intf, |
271 |
const char * dev_name, unsigned char disknum) |
272 |
: smart_device(intf, dev_name, "cciss", "cciss"), |
273 |
- freebsd_smart_device("SCSI"), |
274 |
+ freebsd_smart_device(), |
275 |
m_disknum(disknum) |
276 |
{ |
277 |
set_info().info_name = strprintf("%s [cciss_disk_%02d]", dev_name, disknum); |