Deleted Added
full compact
vpo.c (165102) vpo.c (168752)
1/*-
2 * Copyright (c) 1997, 1998, 1999 Nicolas Souchu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997, 1998, 1999 Nicolas Souchu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/ppbus/vpo.c 165102 2006-12-11 18:28:31Z mjacob $");
29__FBSDID("$FreeBSD: head/sys/dev/ppbus/vpo.c 168752 2007-04-15 08:49:19Z scottl $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/module.h>
34#include <sys/bus.h>
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/module.h>
34#include <sys/bus.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>
35#include <sys/malloc.h>
36
37#include <cam/cam.h>
38#include <cam/cam_ccb.h>
39#include <cam/cam_sim.h>
40#include <cam/cam_xpt_sim.h>
41#include <cam/cam_debug.h>
42#include <cam/cam_periph.h>
43
44#include <cam/scsi/scsi_all.h>
45#include <cam/scsi/scsi_message.h>
46#include <cam/scsi/scsi_da.h>
47
48#include <sys/kernel.h>
49
50#include "opt_vpo.h"
51
52#include <dev/ppbus/ppbconf.h>
53#include <dev/ppbus/vpoio.h>
54
55#include "ppbus_if.h"
56
57struct vpo_sense {
58 struct scsi_sense cmd;
59 unsigned int stat;
60 unsigned int count;
61};
62
63struct vpo_data {
64 unsigned short vpo_unit;
65
66 int vpo_stat;
67 int vpo_count;
68 int vpo_error;
69
70 int vpo_isplus;
71
72 struct cam_sim *sim;
73
74 struct vpo_sense vpo_sense;
75
76 struct vpoio_data vpo_io; /* interface to low level functions */
77};
78
79#define DEVTOSOFTC(dev) \
80 ((struct vpo_data *)device_get_softc(dev))
81
82/* cam related functions */
83static void vpo_action(struct cam_sim *sim, union ccb *ccb);
84static void vpo_poll(struct cam_sim *sim);
85static void vpo_cam_rescan_callback(struct cam_periph *periph,
86 union ccb *ccb);
87static void vpo_cam_rescan(struct vpo_data *vpo);
88
89static void
90vpo_identify(driver_t *driver, device_t parent)
91{
92
93 device_t dev;
94
95 dev = device_find_child(parent, "vpo", 0);
96 if (!dev)
97 BUS_ADD_CHILD(parent, 0, "vpo", -1);
98}
99
100/*
101 * vpo_probe()
102 */
103static int
104vpo_probe(device_t dev)
105{
106 struct vpo_data *vpo;
107 int error;
108
109 vpo = DEVTOSOFTC(dev);
110
111 /* vpo dependent initialisation */
112 vpo->vpo_unit = device_get_unit(dev);
113
114 /* low level probe */
115 vpoio_set_unit(&vpo->vpo_io, vpo->vpo_unit);
116
117 /* check ZIP before ZIP+ or imm_probe() will send controls to
118 * the printer or whatelse connected to the port */
119 if ((error = vpoio_probe(dev, &vpo->vpo_io)) == 0) {
120 vpo->vpo_isplus = 0;
121 device_set_desc(dev,
122 "Iomega VPI0 Parallel to SCSI interface");
123 } else if ((error = imm_probe(dev, &vpo->vpo_io)) == 0) {
124 vpo->vpo_isplus = 1;
125 device_set_desc(dev,
126 "Iomega Matchmaker Parallel to SCSI interface");
127 } else {
128 return (error);
129 }
130
131 return (0);
132}
133
134/*
135 * vpo_attach()
136 */
137static int
138vpo_attach(device_t dev)
139{
140 struct vpo_data *vpo = DEVTOSOFTC(dev);
141 struct cam_devq *devq;
142 int error;
143
144 /* low level attachment */
145 if (vpo->vpo_isplus) {
146 if ((error = imm_attach(&vpo->vpo_io)))
147 return (error);
148 } else {
149 if ((error = vpoio_attach(&vpo->vpo_io)))
150 return (error);
151 }
152
153 /*
154 ** Now tell the generic SCSI layer
155 ** about our bus.
156 */
157 devq = cam_simq_alloc(/*maxopenings*/1);
158 /* XXX What about low-level detach on error? */
159 if (devq == NULL)
160 return (ENXIO);
161
162 vpo->sim = cam_sim_alloc(vpo_action, vpo_poll, "vpo", vpo,
37#include <sys/malloc.h>
38
39#include <cam/cam.h>
40#include <cam/cam_ccb.h>
41#include <cam/cam_sim.h>
42#include <cam/cam_xpt_sim.h>
43#include <cam/cam_debug.h>
44#include <cam/cam_periph.h>
45
46#include <cam/scsi/scsi_all.h>
47#include <cam/scsi/scsi_message.h>
48#include <cam/scsi/scsi_da.h>
49
50#include <sys/kernel.h>
51
52#include "opt_vpo.h"
53
54#include <dev/ppbus/ppbconf.h>
55#include <dev/ppbus/vpoio.h>
56
57#include "ppbus_if.h"
58
59struct vpo_sense {
60 struct scsi_sense cmd;
61 unsigned int stat;
62 unsigned int count;
63};
64
65struct vpo_data {
66 unsigned short vpo_unit;
67
68 int vpo_stat;
69 int vpo_count;
70 int vpo_error;
71
72 int vpo_isplus;
73
74 struct cam_sim *sim;
75
76 struct vpo_sense vpo_sense;
77
78 struct vpoio_data vpo_io; /* interface to low level functions */
79};
80
81#define DEVTOSOFTC(dev) \
82 ((struct vpo_data *)device_get_softc(dev))
83
84/* cam related functions */
85static void vpo_action(struct cam_sim *sim, union ccb *ccb);
86static void vpo_poll(struct cam_sim *sim);
87static void vpo_cam_rescan_callback(struct cam_periph *periph,
88 union ccb *ccb);
89static void vpo_cam_rescan(struct vpo_data *vpo);
90
91static void
92vpo_identify(driver_t *driver, device_t parent)
93{
94
95 device_t dev;
96
97 dev = device_find_child(parent, "vpo", 0);
98 if (!dev)
99 BUS_ADD_CHILD(parent, 0, "vpo", -1);
100}
101
102/*
103 * vpo_probe()
104 */
105static int
106vpo_probe(device_t dev)
107{
108 struct vpo_data *vpo;
109 int error;
110
111 vpo = DEVTOSOFTC(dev);
112
113 /* vpo dependent initialisation */
114 vpo->vpo_unit = device_get_unit(dev);
115
116 /* low level probe */
117 vpoio_set_unit(&vpo->vpo_io, vpo->vpo_unit);
118
119 /* check ZIP before ZIP+ or imm_probe() will send controls to
120 * the printer or whatelse connected to the port */
121 if ((error = vpoio_probe(dev, &vpo->vpo_io)) == 0) {
122 vpo->vpo_isplus = 0;
123 device_set_desc(dev,
124 "Iomega VPI0 Parallel to SCSI interface");
125 } else if ((error = imm_probe(dev, &vpo->vpo_io)) == 0) {
126 vpo->vpo_isplus = 1;
127 device_set_desc(dev,
128 "Iomega Matchmaker Parallel to SCSI interface");
129 } else {
130 return (error);
131 }
132
133 return (0);
134}
135
136/*
137 * vpo_attach()
138 */
139static int
140vpo_attach(device_t dev)
141{
142 struct vpo_data *vpo = DEVTOSOFTC(dev);
143 struct cam_devq *devq;
144 int error;
145
146 /* low level attachment */
147 if (vpo->vpo_isplus) {
148 if ((error = imm_attach(&vpo->vpo_io)))
149 return (error);
150 } else {
151 if ((error = vpoio_attach(&vpo->vpo_io)))
152 return (error);
153 }
154
155 /*
156 ** Now tell the generic SCSI layer
157 ** about our bus.
158 */
159 devq = cam_simq_alloc(/*maxopenings*/1);
160 /* XXX What about low-level detach on error? */
161 if (devq == NULL)
162 return (ENXIO);
163
164 vpo->sim = cam_sim_alloc(vpo_action, vpo_poll, "vpo", vpo,
163 device_get_unit(dev),
165 device_get_unit(dev), &Giant,
164 /*untagged*/1, /*tagged*/0, devq);
165 if (vpo->sim == NULL) {
166 cam_simq_free(devq);
167 return (ENXIO);
168 }
169
170 if (xpt_bus_register(vpo->sim, /*bus*/0) != CAM_SUCCESS) {
171 cam_sim_free(vpo->sim, /*free_devq*/TRUE);
172 return (ENXIO);
173 }
174
175 /* all went ok */
176
177 vpo_cam_rescan(vpo); /* have CAM rescan the bus */
178
179 return (0);
180}
181
182static void
183vpo_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
184{
185 free(ccb, M_TEMP);
186}
187
188static void
189vpo_cam_rescan(struct vpo_data *vpo)
190{
191 struct cam_path *path;
192 union ccb *ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO);
193
194 if (xpt_create_path(&path, xpt_periph, cam_sim_path(vpo->sim), 0, 0)
195 != CAM_REQ_CMP) {
196 /* A failure is benign as the user can do a manual rescan */
197 free(ccb, M_TEMP);
198 return;
199 }
200
201 xpt_setup_ccb(&ccb->ccb_h, path, 5/*priority (low)*/);
202 ccb->ccb_h.func_code = XPT_SCAN_BUS;
203 ccb->ccb_h.cbfcnp = vpo_cam_rescan_callback;
204 ccb->crcn.flags = CAM_FLAG_NONE;
205 xpt_action(ccb);
206
207 /* The scan is in progress now. */
208}
209
210/*
211 * vpo_intr()
212 */
213static void
214vpo_intr(struct vpo_data *vpo, struct ccb_scsiio *csio)
215{
216 int errno; /* error in errno.h */
217 int s;
218#ifdef VP0_DEBUG
219 int i;
220#endif
221
222 s = splcam();
223
224 if (vpo->vpo_isplus) {
225 errno = imm_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
226 csio->ccb_h.target_id,
227 (char *)&csio->cdb_io.cdb_bytes, csio->cdb_len,
228 (char *)csio->data_ptr, csio->dxfer_len,
229 &vpo->vpo_stat, &vpo->vpo_count, &vpo->vpo_error);
230 } else {
231 errno = vpoio_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
232 csio->ccb_h.target_id,
233 (char *)&csio->cdb_io.cdb_bytes, csio->cdb_len,
234 (char *)csio->data_ptr, csio->dxfer_len,
235 &vpo->vpo_stat, &vpo->vpo_count, &vpo->vpo_error);
236 }
237
238#ifdef VP0_DEBUG
239 printf("vpo_do_scsi = %d, status = 0x%x, count = %d, vpo_error = %d\n",
240 errno, vpo->vpo_stat, vpo->vpo_count, vpo->vpo_error);
241
242 /* dump of command */
243 for (i=0; i<csio->cdb_len; i++)
244 printf("%x ", ((char *)&csio->cdb_io.cdb_bytes)[i]);
245
246 printf("\n");
247#endif
248
249 if (errno) {
250 /* connection to ppbus interrupted */
251 csio->ccb_h.status = CAM_CMD_TIMEOUT;
252 goto error;
253 }
254
255 /* if a timeout occured, no sense */
256 if (vpo->vpo_error) {
257 if (vpo->vpo_error != VP0_ESELECT_TIMEOUT)
258 printf("vpo%d: VP0 error/timeout (%d)\n",
259 vpo->vpo_unit, vpo->vpo_error);
260
261 csio->ccb_h.status = CAM_CMD_TIMEOUT;
262 goto error;
263 }
264
265 /* check scsi status */
266 if (vpo->vpo_stat != SCSI_STATUS_OK) {
267 csio->scsi_status = vpo->vpo_stat;
268
269 /* check if we have to sense the drive */
270 if ((vpo->vpo_stat & SCSI_STATUS_CHECK_COND) != 0) {
271
272 vpo->vpo_sense.cmd.opcode = REQUEST_SENSE;
273 vpo->vpo_sense.cmd.length = csio->sense_len;
274 vpo->vpo_sense.cmd.control = 0;
275
276 if (vpo->vpo_isplus) {
277 errno = imm_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
278 csio->ccb_h.target_id,
279 (char *)&vpo->vpo_sense.cmd,
280 sizeof(vpo->vpo_sense.cmd),
281 (char *)&csio->sense_data, csio->sense_len,
282 &vpo->vpo_sense.stat, &vpo->vpo_sense.count,
283 &vpo->vpo_error);
284 } else {
285 errno = vpoio_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
286 csio->ccb_h.target_id,
287 (char *)&vpo->vpo_sense.cmd,
288 sizeof(vpo->vpo_sense.cmd),
289 (char *)&csio->sense_data, csio->sense_len,
290 &vpo->vpo_sense.stat, &vpo->vpo_sense.count,
291 &vpo->vpo_error);
292 }
293
294
295#ifdef VP0_DEBUG
296 printf("(sense) vpo_do_scsi = %d, status = 0x%x, count = %d, vpo_error = %d\n",
297 errno, vpo->vpo_sense.stat, vpo->vpo_sense.count, vpo->vpo_error);
298#endif
299
300 /* check sense return status */
301 if (errno == 0 && vpo->vpo_sense.stat == SCSI_STATUS_OK) {
302 /* sense ok */
303 csio->ccb_h.status = CAM_AUTOSNS_VALID | CAM_SCSI_STATUS_ERROR;
304 csio->sense_resid = csio->sense_len - vpo->vpo_sense.count;
305
306#ifdef VP0_DEBUG
307 /* dump of sense info */
308 printf("(sense) ");
309 for (i=0; i<vpo->vpo_sense.count; i++)
310 printf("%x ", ((char *)&csio->sense_data)[i]);
311 printf("\n");
312#endif
313
314 } else {
315 /* sense failed */
316 csio->ccb_h.status = CAM_AUTOSENSE_FAIL;
317 }
318 } else {
319 /* no sense */
320 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
321 }
322
323 goto error;
324 }
325
326 csio->resid = csio->dxfer_len - vpo->vpo_count;
327 csio->ccb_h.status = CAM_REQ_CMP;
328
329error:
330 splx(s);
331
332 return;
333}
334
335static void
336vpo_action(struct cam_sim *sim, union ccb *ccb)
337{
338
339 struct vpo_data *vpo = (struct vpo_data *)sim->softc;
340
341 switch (ccb->ccb_h.func_code) {
342 case XPT_SCSI_IO:
343 {
344 struct ccb_scsiio *csio;
345
346 csio = &ccb->csio;
347
348#ifdef VP0_DEBUG
349 printf("vpo%d: XPT_SCSI_IO (0x%x) request\n",
350 vpo->vpo_unit, csio->cdb_io.cdb_bytes[0]);
351#endif
352
353 vpo_intr(vpo, csio);
354
355 xpt_done(ccb);
356
357 break;
358 }
359 case XPT_CALC_GEOMETRY:
360 {
361 struct ccb_calc_geometry *ccg;
362
363 ccg = &ccb->ccg;
364
365#ifdef VP0_DEBUG
366 printf("vpo%d: XPT_CALC_GEOMETRY (bs=%d,vs=%jd,c=%d,h=%d,spt=%d) request\n",
367 vpo->vpo_unit,
368 ccg->block_size,
369 (intmax_t)ccg->volume_size,
370 ccg->cylinders,
371 ccg->heads,
372 ccg->secs_per_track);
373#endif
374
375 ccg->heads = 64;
376 ccg->secs_per_track = 32;
377 ccg->cylinders = ccg->volume_size /
378 (ccg->heads * ccg->secs_per_track);
379
380 ccb->ccb_h.status = CAM_REQ_CMP;
381 xpt_done(ccb);
382 break;
383 }
384 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
385 {
386
387#ifdef VP0_DEBUG
388 printf("vpo%d: XPT_RESET_BUS request\n", vpo->vpo_unit);
389#endif
390
391 if (vpo->vpo_isplus) {
392 if (imm_reset_bus(&vpo->vpo_io)) {
393 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
394 xpt_done(ccb);
395 return;
396 }
397 } else {
398 if (vpoio_reset_bus(&vpo->vpo_io)) {
399 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
400 xpt_done(ccb);
401 return;
402 }
403 }
404
405 ccb->ccb_h.status = CAM_REQ_CMP;
406 xpt_done(ccb);
407 break;
408 }
409 case XPT_PATH_INQ: /* Path routing inquiry */
410 {
411 struct ccb_pathinq *cpi = &ccb->cpi;
412
413#ifdef VP0_DEBUG
414 printf("vpo%d: XPT_PATH_INQ request\n", vpo->vpo_unit);
415#endif
416 cpi->version_num = 1; /* XXX??? */
417 cpi->hba_inquiry = 0;
418 cpi->target_sprt = 0;
419 cpi->hba_misc = 0;
420 cpi->hba_eng_cnt = 0;
421 cpi->max_target = 7;
422 cpi->max_lun = 0;
423 cpi->initiator_id = VP0_INITIATOR;
424 cpi->bus_id = sim->bus_id;
425 cpi->base_transfer_speed = 93;
426 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
427 strncpy(cpi->hba_vid, "Iomega", HBA_IDLEN);
428 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
429 cpi->unit_number = sim->unit_number;
430
431 cpi->ccb_h.status = CAM_REQ_CMP;
432 xpt_done(ccb);
433 break;
434 }
435 default:
436 ccb->ccb_h.status = CAM_REQ_INVALID;
437 xpt_done(ccb);
438 break;
439 }
440
441 return;
442}
443
444static void
445vpo_poll(struct cam_sim *sim)
446{
447 /* The ZIP is actually always polled throw vpo_action() */
448 return;
449}
450
451static devclass_t vpo_devclass;
452
453static device_method_t vpo_methods[] = {
454 /* device interface */
455 DEVMETHOD(device_identify, vpo_identify),
456 DEVMETHOD(device_probe, vpo_probe),
457 DEVMETHOD(device_attach, vpo_attach),
458
459 { 0, 0 }
460};
461
462static driver_t vpo_driver = {
463 "vpo",
464 vpo_methods,
465 sizeof(struct vpo_data),
466};
467DRIVER_MODULE(vpo, ppbus, vpo_driver, vpo_devclass, 0, 0);
468MODULE_DEPEND(vpo, ppbus, 1, 1, 1);
469MODULE_DEPEND(vpo, cam, 1, 1, 1);
166 /*untagged*/1, /*tagged*/0, devq);
167 if (vpo->sim == NULL) {
168 cam_simq_free(devq);
169 return (ENXIO);
170 }
171
172 if (xpt_bus_register(vpo->sim, /*bus*/0) != CAM_SUCCESS) {
173 cam_sim_free(vpo->sim, /*free_devq*/TRUE);
174 return (ENXIO);
175 }
176
177 /* all went ok */
178
179 vpo_cam_rescan(vpo); /* have CAM rescan the bus */
180
181 return (0);
182}
183
184static void
185vpo_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb)
186{
187 free(ccb, M_TEMP);
188}
189
190static void
191vpo_cam_rescan(struct vpo_data *vpo)
192{
193 struct cam_path *path;
194 union ccb *ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO);
195
196 if (xpt_create_path(&path, xpt_periph, cam_sim_path(vpo->sim), 0, 0)
197 != CAM_REQ_CMP) {
198 /* A failure is benign as the user can do a manual rescan */
199 free(ccb, M_TEMP);
200 return;
201 }
202
203 xpt_setup_ccb(&ccb->ccb_h, path, 5/*priority (low)*/);
204 ccb->ccb_h.func_code = XPT_SCAN_BUS;
205 ccb->ccb_h.cbfcnp = vpo_cam_rescan_callback;
206 ccb->crcn.flags = CAM_FLAG_NONE;
207 xpt_action(ccb);
208
209 /* The scan is in progress now. */
210}
211
212/*
213 * vpo_intr()
214 */
215static void
216vpo_intr(struct vpo_data *vpo, struct ccb_scsiio *csio)
217{
218 int errno; /* error in errno.h */
219 int s;
220#ifdef VP0_DEBUG
221 int i;
222#endif
223
224 s = splcam();
225
226 if (vpo->vpo_isplus) {
227 errno = imm_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
228 csio->ccb_h.target_id,
229 (char *)&csio->cdb_io.cdb_bytes, csio->cdb_len,
230 (char *)csio->data_ptr, csio->dxfer_len,
231 &vpo->vpo_stat, &vpo->vpo_count, &vpo->vpo_error);
232 } else {
233 errno = vpoio_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
234 csio->ccb_h.target_id,
235 (char *)&csio->cdb_io.cdb_bytes, csio->cdb_len,
236 (char *)csio->data_ptr, csio->dxfer_len,
237 &vpo->vpo_stat, &vpo->vpo_count, &vpo->vpo_error);
238 }
239
240#ifdef VP0_DEBUG
241 printf("vpo_do_scsi = %d, status = 0x%x, count = %d, vpo_error = %d\n",
242 errno, vpo->vpo_stat, vpo->vpo_count, vpo->vpo_error);
243
244 /* dump of command */
245 for (i=0; i<csio->cdb_len; i++)
246 printf("%x ", ((char *)&csio->cdb_io.cdb_bytes)[i]);
247
248 printf("\n");
249#endif
250
251 if (errno) {
252 /* connection to ppbus interrupted */
253 csio->ccb_h.status = CAM_CMD_TIMEOUT;
254 goto error;
255 }
256
257 /* if a timeout occured, no sense */
258 if (vpo->vpo_error) {
259 if (vpo->vpo_error != VP0_ESELECT_TIMEOUT)
260 printf("vpo%d: VP0 error/timeout (%d)\n",
261 vpo->vpo_unit, vpo->vpo_error);
262
263 csio->ccb_h.status = CAM_CMD_TIMEOUT;
264 goto error;
265 }
266
267 /* check scsi status */
268 if (vpo->vpo_stat != SCSI_STATUS_OK) {
269 csio->scsi_status = vpo->vpo_stat;
270
271 /* check if we have to sense the drive */
272 if ((vpo->vpo_stat & SCSI_STATUS_CHECK_COND) != 0) {
273
274 vpo->vpo_sense.cmd.opcode = REQUEST_SENSE;
275 vpo->vpo_sense.cmd.length = csio->sense_len;
276 vpo->vpo_sense.cmd.control = 0;
277
278 if (vpo->vpo_isplus) {
279 errno = imm_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
280 csio->ccb_h.target_id,
281 (char *)&vpo->vpo_sense.cmd,
282 sizeof(vpo->vpo_sense.cmd),
283 (char *)&csio->sense_data, csio->sense_len,
284 &vpo->vpo_sense.stat, &vpo->vpo_sense.count,
285 &vpo->vpo_error);
286 } else {
287 errno = vpoio_do_scsi(&vpo->vpo_io, VP0_INITIATOR,
288 csio->ccb_h.target_id,
289 (char *)&vpo->vpo_sense.cmd,
290 sizeof(vpo->vpo_sense.cmd),
291 (char *)&csio->sense_data, csio->sense_len,
292 &vpo->vpo_sense.stat, &vpo->vpo_sense.count,
293 &vpo->vpo_error);
294 }
295
296
297#ifdef VP0_DEBUG
298 printf("(sense) vpo_do_scsi = %d, status = 0x%x, count = %d, vpo_error = %d\n",
299 errno, vpo->vpo_sense.stat, vpo->vpo_sense.count, vpo->vpo_error);
300#endif
301
302 /* check sense return status */
303 if (errno == 0 && vpo->vpo_sense.stat == SCSI_STATUS_OK) {
304 /* sense ok */
305 csio->ccb_h.status = CAM_AUTOSNS_VALID | CAM_SCSI_STATUS_ERROR;
306 csio->sense_resid = csio->sense_len - vpo->vpo_sense.count;
307
308#ifdef VP0_DEBUG
309 /* dump of sense info */
310 printf("(sense) ");
311 for (i=0; i<vpo->vpo_sense.count; i++)
312 printf("%x ", ((char *)&csio->sense_data)[i]);
313 printf("\n");
314#endif
315
316 } else {
317 /* sense failed */
318 csio->ccb_h.status = CAM_AUTOSENSE_FAIL;
319 }
320 } else {
321 /* no sense */
322 csio->ccb_h.status = CAM_SCSI_STATUS_ERROR;
323 }
324
325 goto error;
326 }
327
328 csio->resid = csio->dxfer_len - vpo->vpo_count;
329 csio->ccb_h.status = CAM_REQ_CMP;
330
331error:
332 splx(s);
333
334 return;
335}
336
337static void
338vpo_action(struct cam_sim *sim, union ccb *ccb)
339{
340
341 struct vpo_data *vpo = (struct vpo_data *)sim->softc;
342
343 switch (ccb->ccb_h.func_code) {
344 case XPT_SCSI_IO:
345 {
346 struct ccb_scsiio *csio;
347
348 csio = &ccb->csio;
349
350#ifdef VP0_DEBUG
351 printf("vpo%d: XPT_SCSI_IO (0x%x) request\n",
352 vpo->vpo_unit, csio->cdb_io.cdb_bytes[0]);
353#endif
354
355 vpo_intr(vpo, csio);
356
357 xpt_done(ccb);
358
359 break;
360 }
361 case XPT_CALC_GEOMETRY:
362 {
363 struct ccb_calc_geometry *ccg;
364
365 ccg = &ccb->ccg;
366
367#ifdef VP0_DEBUG
368 printf("vpo%d: XPT_CALC_GEOMETRY (bs=%d,vs=%jd,c=%d,h=%d,spt=%d) request\n",
369 vpo->vpo_unit,
370 ccg->block_size,
371 (intmax_t)ccg->volume_size,
372 ccg->cylinders,
373 ccg->heads,
374 ccg->secs_per_track);
375#endif
376
377 ccg->heads = 64;
378 ccg->secs_per_track = 32;
379 ccg->cylinders = ccg->volume_size /
380 (ccg->heads * ccg->secs_per_track);
381
382 ccb->ccb_h.status = CAM_REQ_CMP;
383 xpt_done(ccb);
384 break;
385 }
386 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
387 {
388
389#ifdef VP0_DEBUG
390 printf("vpo%d: XPT_RESET_BUS request\n", vpo->vpo_unit);
391#endif
392
393 if (vpo->vpo_isplus) {
394 if (imm_reset_bus(&vpo->vpo_io)) {
395 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
396 xpt_done(ccb);
397 return;
398 }
399 } else {
400 if (vpoio_reset_bus(&vpo->vpo_io)) {
401 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
402 xpt_done(ccb);
403 return;
404 }
405 }
406
407 ccb->ccb_h.status = CAM_REQ_CMP;
408 xpt_done(ccb);
409 break;
410 }
411 case XPT_PATH_INQ: /* Path routing inquiry */
412 {
413 struct ccb_pathinq *cpi = &ccb->cpi;
414
415#ifdef VP0_DEBUG
416 printf("vpo%d: XPT_PATH_INQ request\n", vpo->vpo_unit);
417#endif
418 cpi->version_num = 1; /* XXX??? */
419 cpi->hba_inquiry = 0;
420 cpi->target_sprt = 0;
421 cpi->hba_misc = 0;
422 cpi->hba_eng_cnt = 0;
423 cpi->max_target = 7;
424 cpi->max_lun = 0;
425 cpi->initiator_id = VP0_INITIATOR;
426 cpi->bus_id = sim->bus_id;
427 cpi->base_transfer_speed = 93;
428 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
429 strncpy(cpi->hba_vid, "Iomega", HBA_IDLEN);
430 strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
431 cpi->unit_number = sim->unit_number;
432
433 cpi->ccb_h.status = CAM_REQ_CMP;
434 xpt_done(ccb);
435 break;
436 }
437 default:
438 ccb->ccb_h.status = CAM_REQ_INVALID;
439 xpt_done(ccb);
440 break;
441 }
442
443 return;
444}
445
446static void
447vpo_poll(struct cam_sim *sim)
448{
449 /* The ZIP is actually always polled throw vpo_action() */
450 return;
451}
452
453static devclass_t vpo_devclass;
454
455static device_method_t vpo_methods[] = {
456 /* device interface */
457 DEVMETHOD(device_identify, vpo_identify),
458 DEVMETHOD(device_probe, vpo_probe),
459 DEVMETHOD(device_attach, vpo_attach),
460
461 { 0, 0 }
462};
463
464static driver_t vpo_driver = {
465 "vpo",
466 vpo_methods,
467 sizeof(struct vpo_data),
468};
469DRIVER_MODULE(vpo, ppbus, vpo_driver, vpo_devclass, 0, 0);
470MODULE_DEPEND(vpo, ppbus, 1, 1, 1);
471MODULE_DEPEND(vpo, cam, 1, 1, 1);