vpo.c (55205) | vpo.c (55939) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1997, 1998 Nicolas Souchu | 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 --- 7 unchanged lines hidden (view full) --- 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 * | 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 --- 7 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/sys/dev/ppbus/vpo.c 55205 1999-12-29 04:46:21Z peter $ | 26 * $FreeBSD: head/sys/dev/ppbus/vpo.c 55939 2000-01-14 00:18:06Z nsouch $ |
27 * 28 */ 29 30#ifdef _KERNEL 31#include <sys/param.h> 32#include <sys/systm.h> | 27 * 28 */ 29 30#ifdef _KERNEL 31#include <sys/param.h> 32#include <sys/systm.h> |
33#include <sys/malloc.h> 34#include <sys/buf.h> | 33#include <sys/module.h> 34#include <sys/bus.h> |
35 36#include <machine/clock.h> 37 38#endif /* _KERNEL */ 39 40#include <cam/cam.h> 41#include <cam/cam_ccb.h> 42#include <cam/cam_sim.h> --- 8 unchanged lines hidden (view full) --- 51#include <sys/kernel.h> 52#endif 53 54#include "opt_vpo.h" 55 56#include <dev/ppbus/ppbconf.h> 57#include <dev/ppbus/vpoio.h> 58 | 35 36#include <machine/clock.h> 37 38#endif /* _KERNEL */ 39 40#include <cam/cam.h> 41#include <cam/cam_ccb.h> 42#include <cam/cam_sim.h> --- 8 unchanged lines hidden (view full) --- 51#include <sys/kernel.h> 52#endif 53 54#include "opt_vpo.h" 55 56#include <dev/ppbus/ppbconf.h> 57#include <dev/ppbus/vpoio.h> 58 |
59#include "ppbus_if.h" 60 |
|
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; --- 7 unchanged lines hidden (view full) --- 74 struct cam_sim *sim; 75 struct cam_path *path; 76 77 struct vpo_sense vpo_sense; 78 79 struct vpoio_data vpo_io; /* interface to low level functions */ 80}; 81 | 61struct vpo_sense { 62 struct scsi_sense cmd; 63 unsigned int stat; 64 unsigned int count; 65}; 66 67struct vpo_data { 68 unsigned short vpo_unit; --- 7 unchanged lines hidden (view full) --- 76 struct cam_sim *sim; 77 struct cam_path *path; 78 79 struct vpo_sense vpo_sense; 80 81 struct vpoio_data vpo_io; /* interface to low level functions */ 82}; 83 |
82/* cam related functions */ 83static void vpo_action(struct cam_sim *sim, union ccb *ccb); 84static void vpo_poll(struct cam_sim *sim); | 84static int vpo_probe(device_t); 85static int vpo_attach(device_t); |
85 | 86 |
86static int nvpo = 0; 87#define MAXVP0 8 /* XXX not much better! */ 88static struct vpo_data *vpodata[MAXVP0]; | 87#define DEVTOSOFTC(dev) \ 88 ((struct vpo_data *)device_get_softc(dev)) |
89 | 89 |
90#ifdef _KERNEL | 90static devclass_t vpo_devclass; |
91 | 91 |
92/* 93 * Make ourselves visible as a ppbus driver 94 */ 95static struct ppb_device *vpoprobe(struct ppb_data *ppb); 96static int vpoattach(struct ppb_device *dev); | 92static device_method_t vpo_methods[] = { 93 /* device interface */ 94 DEVMETHOD(device_probe, vpo_probe), 95 DEVMETHOD(device_attach, vpo_attach), |
97 | 96 |
98static struct ppb_driver vpodriver = { 99 vpoprobe, vpoattach, "vpo" | 97 { 0, 0 } |
100}; | 98}; |
101DATA_SET(ppbdriver_set, vpodriver); | |
102 | 99 |
103#endif | 100static driver_t vpo_driver = { 101 "vpo", 102 vpo_methods, 103 sizeof(struct vpo_data), 104}; |
104 | 105 |
106/* cam related functions */ 107static void vpo_action(struct cam_sim *sim, union ccb *ccb); 108static void vpo_poll(struct cam_sim *sim); 109 |
|
105/* | 110/* |
106 * vpoprobe() 107 * 108 * Called by ppb_attachdevs(). | 111 * vpo_probe() |
109 */ | 112 */ |
110static struct ppb_device * 111vpoprobe(struct ppb_data *ppb) | 113static int 114vpo_probe(device_t dev) |
112{ 113 struct vpo_data *vpo; | 115{ 116 struct vpo_data *vpo; |
114 struct ppb_device *dev; | 117 int error; |
115 | 118 |
116 if (nvpo >= MAXVP0) { 117 printf("vpo: Too many devices (max %d)\n", MAXVP0); 118 return(NULL); 119 } 120 121 vpo = (struct vpo_data *)malloc(sizeof(struct vpo_data), 122 M_DEVBUF, M_NOWAIT); 123 if (!vpo) { 124 printf("vpo: cannot malloc!\n"); 125 return(NULL); 126 } | 119 vpo = DEVTOSOFTC(dev); |
127 bzero(vpo, sizeof(struct vpo_data)); 128 | 120 bzero(vpo, sizeof(struct vpo_data)); 121 |
129 vpodata[nvpo] = vpo; 130 | |
131 /* vpo dependent initialisation */ | 122 /* vpo dependent initialisation */ |
132 vpo->vpo_unit = nvpo; | 123 vpo->vpo_unit = device_get_unit(dev); |
133 | 124 |
134 /* ok, go to next device on next probe */ 135 nvpo ++; 136 | |
137 /* low level probe */ 138 vpoio_set_unit(&vpo->vpo_io, vpo->vpo_unit); 139 140 /* check ZIP before ZIP+ or imm_probe() will send controls to 141 * the printer or whatelse connected to the port */ | 125 /* low level probe */ 126 vpoio_set_unit(&vpo->vpo_io, vpo->vpo_unit); 127 128 /* check ZIP before ZIP+ or imm_probe() will send controls to 129 * the printer or whatelse connected to the port */ |
142 if ((dev = vpoio_probe(ppb, &vpo->vpo_io))) { | 130 if ((error = vpoio_probe(dev, &vpo->vpo_io)) == 0) { |
143 vpo->vpo_isplus = 0; | 131 vpo->vpo_isplus = 0; |
144 } else if ((dev = imm_probe(ppb, &vpo->vpo_io))) { | 132 device_set_desc(dev, 133 "Iomega VPI0 Parallel to SCSI interface"); 134 } else if ((error = imm_probe(dev, &vpo->vpo_io)) == 0) { |
145 vpo->vpo_isplus = 1; | 135 vpo->vpo_isplus = 1; |
136 device_set_desc(dev, 137 "Iomega Matchmaker Parallel to SCSI interface"); |
|
146 } else { | 138 } else { |
147 free(vpo, M_DEVBUF); 148 return (NULL); | 139 return (error); |
149 } 150 | 140 } 141 |
151 return (dev); | 142 return (0); |
152} 153 154/* | 143} 144 145/* |
155 * vpoattach() 156 * 157 * Called by ppb_attachdevs(). | 146 * vpo_attach() |
158 */ 159static int | 147 */ 148static int |
160vpoattach(struct ppb_device *dev) | 149vpo_attach(device_t dev) |
161{ | 150{ |
162 struct vpo_data *vpo = vpodata[dev->id_unit]; | 151 struct vpo_data *vpo = DEVTOSOFTC(dev); |
163 struct cam_devq *devq; | 152 struct cam_devq *devq; |
153 int error; |
|
164 165 /* low level attachment */ 166 if (vpo->vpo_isplus) { | 154 155 /* low level attachment */ 156 if (vpo->vpo_isplus) { |
167 if (!imm_attach(&vpo->vpo_io)) 168 return (0); | 157 if ((error = imm_attach(&vpo->vpo_io))) 158 return (error); |
169 } else { | 159 } else { |
170 if (!vpoio_attach(&vpo->vpo_io)) 171 return (0); | 160 if ((error = vpoio_attach(&vpo->vpo_io))) 161 return (error); |
172 } 173 174 /* 175 ** Now tell the generic SCSI layer 176 ** about our bus. 177 */ 178 devq = cam_simq_alloc(/*maxopenings*/1); 179 /* XXX What about low-level detach on error? */ 180 if (devq == NULL) | 162 } 163 164 /* 165 ** Now tell the generic SCSI layer 166 ** about our bus. 167 */ 168 devq = cam_simq_alloc(/*maxopenings*/1); 169 /* XXX What about low-level detach on error? */ 170 if (devq == NULL) |
181 return (0); | 171 return (ENXIO); |
182 | 172 |
183 vpo->sim = cam_sim_alloc(vpo_action, vpo_poll, "vpo", vpo, dev->id_unit, | 173 vpo->sim = cam_sim_alloc(vpo_action, vpo_poll, "vpo", vpo, 174 device_get_unit(dev), |
184 /*untagged*/1, /*tagged*/0, devq); 185 if (vpo->sim == NULL) { 186 cam_simq_free(devq); | 175 /*untagged*/1, /*tagged*/0, devq); 176 if (vpo->sim == NULL) { 177 cam_simq_free(devq); |
187 return (0); | 178 return (ENXIO); |
188 } 189 190 if (xpt_bus_register(vpo->sim, /*bus*/0) != CAM_SUCCESS) { 191 cam_sim_free(vpo->sim, /*free_devq*/TRUE); | 179 } 180 181 if (xpt_bus_register(vpo->sim, /*bus*/0) != CAM_SUCCESS) { 182 cam_sim_free(vpo->sim, /*free_devq*/TRUE); |
192 return (0); | 183 return (ENXIO); |
193 } 194 195 if (xpt_create_path(&vpo->path, /*periph*/NULL, 196 cam_sim_path(vpo->sim), CAM_TARGET_WILDCARD, 197 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 198 xpt_bus_deregister(cam_sim_path(vpo->sim)); 199 cam_sim_free(vpo->sim, /*free_devq*/TRUE); | 184 } 185 186 if (xpt_create_path(&vpo->path, /*periph*/NULL, 187 cam_sim_path(vpo->sim), CAM_TARGET_WILDCARD, 188 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 189 xpt_bus_deregister(cam_sim_path(vpo->sim)); 190 cam_sim_free(vpo->sim, /*free_devq*/TRUE); |
200 return (0); | 191 return (ENXIO); |
201 } 202 203 /* all went ok */ 204 | 192 } 193 194 /* all went ok */ 195 |
205 return (1); | 196 return (0); |
206} 207 208/* 209 * vpo_intr() 210 */ 211static void 212vpo_intr(struct vpo_data *vpo, struct ccb_scsiio *csio) 213{ --- 226 unchanged lines hidden (view full) --- 440} 441 442static void 443vpo_poll(struct cam_sim *sim) 444{ 445 /* The ZIP is actually always polled throw vpo_action() */ 446 return; 447} | 197} 198 199/* 200 * vpo_intr() 201 */ 202static void 203vpo_intr(struct vpo_data *vpo, struct ccb_scsiio *csio) 204{ --- 226 unchanged lines hidden (view full) --- 431} 432 433static void 434vpo_poll(struct cam_sim *sim) 435{ 436 /* The ZIP is actually always polled throw vpo_action() */ 437 return; 438} |
439 440DRIVER_MODULE(vpo, ppbus, vpo_driver, vpo_devclass, 0, 0); |
|