aic79xx_osm.c (31615ef723e0da21e895f581db7344464f924c52) aic79xx_osm.c (17d2475554610175f0673ee69aa703ce3972909b)
1/*-
2 * Bus independent FreeBSD shim for the aic79xx based Adaptec SCSI controllers
1/*
2 * Bus independent FreeBSD shim for the aic7xxx based adaptec SCSI controllers
3 *
3 *
4 * Copyright (c) 1994-2002, 2004 Justin T. Gibbs.
5 * Copyright (c) 2001-2002 Adaptec Inc.
4 * Copyright (c) 1994-2001 Justin T. Gibbs.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.

--- 10 unchanged lines hidden (view full) ---

24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.

--- 10 unchanged lines hidden (view full) ---

23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
32 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.c#35 $
31 * $Id$
32 *
33 * $FreeBSD$
33 */
34
34 */
35
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD$");
37
38#include <dev/aic7xxx/aic79xx_osm.h>
39#include <dev/aic7xxx/aic79xx_inline.h>
40
36#include <dev/aic7xxx/aic79xx_osm.h>
37#include <dev/aic7xxx/aic79xx_inline.h>
38
41#include <sys/kthread.h>
42
43#include "opt_ddb.h"
44#ifdef DDB
45#include <ddb/ddb.h>
46#endif
47
48#ifndef AHD_TMODE_ENABLE
49#define AHD_TMODE_ENABLE 0
50#endif
51
39#include "opt_ddb.h"
40#ifdef DDB
41#include <ddb/ddb.h>
42#endif
43
44#ifndef AHD_TMODE_ENABLE
45#define AHD_TMODE_ENABLE 0
46#endif
47
52#include <dev/aic7xxx/aic_osm_lib.c>
53
54#define ccb_scb_ptr spriv_ptr0
55
48#define ccb_scb_ptr spriv_ptr0
49
56#if 0
50#if UNUSED
57static void ahd_dump_targcmd(struct target_cmd *cmd);
58#endif
59static int ahd_modevent(module_t mod, int type, void *data);
60static void ahd_action(struct cam_sim *sim, union ccb *ccb);
61static void ahd_set_tran_settings(struct ahd_softc *ahd,
62 int our_id, char channel,
63 struct ccb_trans_settings *cts);
64static void ahd_get_tran_settings(struct ahd_softc *ahd,

--- 7 unchanged lines hidden (view full) ---

72static void ahd_setup_data(struct ahd_softc *ahd, struct cam_sim *sim,
73 struct ccb_scsiio *csio, struct scb *scb);
74static void ahd_abort_ccb(struct ahd_softc *ahd, struct cam_sim *sim,
75 union ccb *ccb);
76static int ahd_create_path(struct ahd_softc *ahd,
77 char channel, u_int target, u_int lun,
78 struct cam_path **path);
79
51static void ahd_dump_targcmd(struct target_cmd *cmd);
52#endif
53static int ahd_modevent(module_t mod, int type, void *data);
54static void ahd_action(struct cam_sim *sim, union ccb *ccb);
55static void ahd_set_tran_settings(struct ahd_softc *ahd,
56 int our_id, char channel,
57 struct ccb_trans_settings *cts);
58static void ahd_get_tran_settings(struct ahd_softc *ahd,

--- 7 unchanged lines hidden (view full) ---

66static void ahd_setup_data(struct ahd_softc *ahd, struct cam_sim *sim,
67 struct ccb_scsiio *csio, struct scb *scb);
68static void ahd_abort_ccb(struct ahd_softc *ahd, struct cam_sim *sim,
69 union ccb *ccb);
70static int ahd_create_path(struct ahd_softc *ahd,
71 char channel, u_int target, u_int lun,
72 struct cam_path **path);
73
80static const char *ahd_sysctl_node_elements[] = {
81 "root",
82 "summary",
83 "debug"
84};
85
86#ifndef NO_SYSCTL_DESCR
87static const char *ahd_sysctl_node_descriptions[] = {
88 "root error collection for aic79xx controllers",
89 "summary collection for aic79xx controllers",
90 "debug collection for aic79xx controllers"
91};
74#if NOT_YET
75static void ahd_set_recoveryscb(struct ahd_softc *ahd, struct scb *scb);
92#endif
93
76#endif
77
94static const char *ahd_sysctl_errors_elements[] = {
95 "Cerrors",
96 "Uerrors",
97 "Ferrors"
98};
99
100#ifndef NO_SYSCTL_DESCR
101static const char *ahd_sysctl_errors_descriptions[] = {
102 "Correctable errors",
103 "Uncorrectable errors",
104 "Fatal errors"
105};
106#endif
107
108static int
78static int
109ahd_set_debugcounters(SYSCTL_HANDLER_ARGS)
110{
111 struct ahd_softc *sc;
112 int error, tmpv;
113
114 tmpv = 0;
115 sc = arg1;
116 error = sysctl_handle_int(oidp, &tmpv, 0, req);
117 if (error != 0 || req->newptr == NULL)
118 return (error);
119 if (tmpv < 0 || tmpv >= AHD_ERRORS_NUMBER)
120 return (EINVAL);
121 sc->summerr[arg2] = tmpv;
122 return (0);
123}
124
125static int
126ahd_clear_allcounters(SYSCTL_HANDLER_ARGS)
127{
128 struct ahd_softc *sc;
129 int error, tmpv;
130
131 tmpv = 0;
132 sc = arg1;
133 error = sysctl_handle_int(oidp, &tmpv, 0, req);
134 if (error != 0 || req->newptr == NULL)
135 return (error);
136 if (tmpv != 0)
137 bzero(sc->summerr, sizeof(sc->summerr));
138 return (0);
139}
140
141static int
142ahd_create_path(struct ahd_softc *ahd, char channel, u_int target,
143 u_int lun, struct cam_path **path)
144{
145 path_id_t path_id;
146
79ahd_create_path(struct ahd_softc *ahd, char channel, u_int target,
80 u_int lun, struct cam_path **path)
81{
82 path_id_t path_id;
83
147 path_id = cam_sim_path(ahd->platform_data->sim);
84 if (channel == 'B')
85 path_id = cam_sim_path(ahd->platform_data->sim_b);
86 else
87 path_id = cam_sim_path(ahd->platform_data->sim);
88
148 return (xpt_create_path(path, /*periph*/NULL,
149 path_id, target, lun));
150}
151
89 return (xpt_create_path(path, /*periph*/NULL,
90 path_id, target, lun));
91}
92
152void
153ahd_sysctl(struct ahd_softc *ahd)
154{
155 u_int i;
156
157 for (i = 0; i < AHD_SYSCTL_NUMBER; i++)
158 sysctl_ctx_init(&ahd->sysctl_ctx[i]);
159
160 ahd->sysctl_tree[AHD_SYSCTL_ROOT] =
161 SYSCTL_ADD_NODE(&ahd->sysctl_ctx[AHD_SYSCTL_ROOT],
162 SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO,
163 device_get_nameunit(ahd->dev_softc), CTLFLAG_RD, 0,
164 ahd_sysctl_node_descriptions[AHD_SYSCTL_ROOT]);
165 SYSCTL_ADD_PROC(&ahd->sysctl_ctx[AHD_SYSCTL_ROOT],
166 SYSCTL_CHILDREN(ahd->sysctl_tree[AHD_SYSCTL_ROOT]),
167 OID_AUTO, "clear", CTLTYPE_UINT | CTLFLAG_RW, ahd,
168 0, ahd_clear_allcounters, "IU",
169 "Clear all counters");
170
171 for (i = AHD_SYSCTL_SUMMARY; i < AHD_SYSCTL_NUMBER; i++)
172 ahd->sysctl_tree[i] =
173 SYSCTL_ADD_NODE(&ahd->sysctl_ctx[i],
174 SYSCTL_CHILDREN(ahd->sysctl_tree[AHD_SYSCTL_ROOT]),
175 OID_AUTO, ahd_sysctl_node_elements[i],
176 CTLFLAG_RD, 0,
177 ahd_sysctl_node_descriptions[i]);
178
179 for (i = AHD_ERRORS_CORRECTABLE; i < AHD_ERRORS_NUMBER; i++) {
180 SYSCTL_ADD_UINT(&ahd->sysctl_ctx[AHD_SYSCTL_SUMMARY],
181 SYSCTL_CHILDREN(ahd->sysctl_tree[AHD_SYSCTL_SUMMARY]),
182 OID_AUTO, ahd_sysctl_errors_elements[i],
183 CTLFLAG_RD, &ahd->summerr[i], i,
184 ahd_sysctl_errors_descriptions[i]);
185 SYSCTL_ADD_PROC(&ahd->sysctl_ctx[AHD_SYSCTL_DEBUG],
186 SYSCTL_CHILDREN(ahd->sysctl_tree[AHD_SYSCTL_DEBUG]),
187 OID_AUTO, ahd_sysctl_errors_elements[i],
188 CTLFLAG_RW | CTLTYPE_UINT, ahd, i,
189 ahd_set_debugcounters, "IU",
190 ahd_sysctl_errors_descriptions[i]);
191 }
192}
193
194int
195ahd_map_int(struct ahd_softc *ahd)
196{
197 int error;
198
199 /* Hook up our interrupt handler */
200 error = bus_setup_intr(ahd->dev_softc, ahd->platform_data->irq,
93int
94ahd_map_int(struct ahd_softc *ahd)
95{
96 int error;
97
98 /* Hook up our interrupt handler */
99 error = bus_setup_intr(ahd->dev_softc, ahd->platform_data->irq,
201 INTR_TYPE_CAM|INTR_MPSAFE, NULL,
202 ahd_platform_intr, ahd, &ahd->platform_data->ih);
100 INTR_TYPE_CAM, ahd_platform_intr, ahd,
101 &ahd->platform_data->ih);
203 if (error != 0)
204 device_printf(ahd->dev_softc, "bus_setup_intr() failed: %d\n",
205 error);
206 return (error);
207}
208
209/*
210 * Attach all the sub-devices we can find
211 */
212int
213ahd_attach(struct ahd_softc *ahd)
214{
215 char ahd_info[256];
216 struct ccb_setasync csa;
217 struct cam_devq *devq;
218 struct cam_sim *sim;
219 struct cam_path *path;
102 if (error != 0)
103 device_printf(ahd->dev_softc, "bus_setup_intr() failed: %d\n",
104 error);
105 return (error);
106}
107
108/*
109 * Attach all the sub-devices we can find
110 */
111int
112ahd_attach(struct ahd_softc *ahd)
113{
114 char ahd_info[256];
115 struct ccb_setasync csa;
116 struct cam_devq *devq;
117 struct cam_sim *sim;
118 struct cam_path *path;
119 long s;
220 int count;
221
222 count = 0;
120 int count;
121
122 count = 0;
223 devq = NULL;
224 sim = NULL;
225
123 sim = NULL;
124
226 /*
227 * Create a thread to perform all recovery.
228 */
229 if (ahd_spawn_recovery_thread(ahd) != 0)
230 goto fail;
231
232 ahd_controller_info(ahd, ahd_info);
233 printf("%s\n", ahd_info);
125 ahd_controller_info(ahd, ahd_info);
126 printf("%s\n", ahd_info);
234 ahd_lock(ahd);
127 ahd_lock(ahd, &s);
235
236 /*
237 * Create the device queue for our SIM(s).
238 */
239 devq = cam_simq_alloc(AHD_MAX_QUEUE);
240 if (devq == NULL)
241 goto fail;
242
243 /*
244 * Construct our SIM entry
245 */
246 sim = cam_sim_alloc(ahd_action, ahd_poll, "ahd", ahd,
247 device_get_unit(ahd->dev_softc),
128
129 /*
130 * Create the device queue for our SIM(s).
131 */
132 devq = cam_simq_alloc(AHD_MAX_QUEUE);
133 if (devq == NULL)
134 goto fail;
135
136 /*
137 * Construct our SIM entry
138 */
139 sim = cam_sim_alloc(ahd_action, ahd_poll, "ahd", ahd,
140 device_get_unit(ahd->dev_softc),
248 &ahd->platform_data->mtx, 1, /*XXX*/256, devq);
141 1, /*XXX*/256, devq);
249 if (sim == NULL) {
250 cam_simq_free(devq);
251 goto fail;
252 }
253
142 if (sim == NULL) {
143 cam_simq_free(devq);
144 goto fail;
145 }
146
254 if (xpt_bus_register(sim, ahd->dev_softc, /*bus_id*/0) != CAM_SUCCESS) {
147 if (xpt_bus_register(sim, /*bus_id*/0) != CAM_SUCCESS) {
255 cam_sim_free(sim, /*free_devq*/TRUE);
256 sim = NULL;
257 goto fail;
258 }
259
260 if (xpt_create_path(&path, /*periph*/NULL,
261 cam_sim_path(sim), CAM_TARGET_WILDCARD,
262 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {

--- 9 unchanged lines hidden (view full) ---

272 csa.callback = ahd_async;
273 csa.callback_arg = sim;
274 xpt_action((union ccb *)&csa);
275 count++;
276
277fail:
278 ahd->platform_data->sim = sim;
279 ahd->platform_data->path = path;
148 cam_sim_free(sim, /*free_devq*/TRUE);
149 sim = NULL;
150 goto fail;
151 }
152
153 if (xpt_create_path(&path, /*periph*/NULL,
154 cam_sim_path(sim), CAM_TARGET_WILDCARD,
155 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {

--- 9 unchanged lines hidden (view full) ---

165 csa.callback = ahd_async;
166 csa.callback_arg = sim;
167 xpt_action((union ccb *)&csa);
168 count++;
169
170fail:
171 ahd->platform_data->sim = sim;
172 ahd->platform_data->path = path;
280 ahd_unlock(ahd);
281 if (count != 0) {
173 ahd_unlock(ahd, &s);
174
175 if (count != 0)
282 /* We have to wait until after any system dumps... */
283 ahd->platform_data->eh =
284 EVENTHANDLER_REGISTER(shutdown_final, ahd_shutdown,
285 ahd, SHUTDOWN_PRI_DEFAULT);
176 /* We have to wait until after any system dumps... */
177 ahd->platform_data->eh =
178 EVENTHANDLER_REGISTER(shutdown_final, ahd_shutdown,
179 ahd, SHUTDOWN_PRI_DEFAULT);
286 ahd_intr_enable(ahd, TRUE);
287 }
288
180
289
290 return (count);
291}
292
293/*
294 * Catch an interrupt from the adapter
295 */
296void
297ahd_platform_intr(void *arg)
298{
299 struct ahd_softc *ahd;
300
301 ahd = (struct ahd_softc *)arg;
181 return (count);
182}
183
184/*
185 * Catch an interrupt from the adapter
186 */
187void
188ahd_platform_intr(void *arg)
189{
190 struct ahd_softc *ahd;
191
192 ahd = (struct ahd_softc *)arg;
302 ahd_lock(ahd);
303 ahd_intr(ahd);
193 ahd_intr(ahd);
304 ahd_unlock(ahd);
305}
306
307/*
308 * We have an scb which has been processed by the
309 * adaptor, now we look to see how the operation
310 * went.
311 */
312void
313ahd_done(struct ahd_softc *ahd, struct scb *scb)
314{
315 union ccb *ccb;
316
317 CAM_DEBUG(scb->io_ctx->ccb_h.path, CAM_DEBUG_TRACE,
318 ("ahd_done - scb %d\n", SCB_GET_TAG(scb)));
319
320 ccb = scb->io_ctx;
321 LIST_REMOVE(scb, pending_links);
194}
195
196/*
197 * We have an scb which has been processed by the
198 * adaptor, now we look to see how the operation
199 * went.
200 */
201void
202ahd_done(struct ahd_softc *ahd, struct scb *scb)
203{
204 union ccb *ccb;
205
206 CAM_DEBUG(scb->io_ctx->ccb_h.path, CAM_DEBUG_TRACE,
207 ("ahd_done - scb %d\n", SCB_GET_TAG(scb)));
208
209 ccb = scb->io_ctx;
210 LIST_REMOVE(scb, pending_links);
322 if ((scb->flags & SCB_TIMEDOUT) != 0)
323 LIST_REMOVE(scb, timedout_links);
211 if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
212 struct scb_tailq *untagged_q;
213 int target_offset;
324
214
325 callout_stop(&scb->io_timer);
215 target_offset = SCB_GET_TARGET_OFFSET(ahd, scb);
216 untagged_q = &ahd->untagged_queues[target_offset];
217 TAILQ_REMOVE(untagged_q, scb, links.tqe);
218 scb->flags &= ~SCB_UNTAGGEDQ;
219 ahd_run_untagged_queue(ahd, untagged_q);
220 }
326
221
222 untimeout(ahd_timeout, (caddr_t)scb, ccb->ccb_h.timeout_ch);
223
327 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
328 bus_dmasync_op_t op;
329
330 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
331 op = BUS_DMASYNC_POSTREAD;
332 else
333 op = BUS_DMASYNC_POSTWRITE;
334 bus_dmamap_sync(ahd->buffer_dmat, scb->dmamap, op);

--- 18 unchanged lines hidden (view full) ---

353 ahd->pending_device = NULL;
354 } else {
355 xpt_print_path(ccb->ccb_h.path);
356 printf("Still disconnected\n");
357 ahd_freeze_ccb(ccb);
358 }
359 }
360
224 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
225 bus_dmasync_op_t op;
226
227 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
228 op = BUS_DMASYNC_POSTREAD;
229 else
230 op = BUS_DMASYNC_POSTWRITE;
231 bus_dmamap_sync(ahd->buffer_dmat, scb->dmamap, op);

--- 18 unchanged lines hidden (view full) ---

250 ahd->pending_device = NULL;
251 } else {
252 xpt_print_path(ccb->ccb_h.path);
253 printf("Still disconnected\n");
254 ahd_freeze_ccb(ccb);
255 }
256 }
257
361 if (aic_get_transaction_status(scb) == CAM_REQ_INPROG)
258 if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG)
362 ccb->ccb_h.status |= CAM_REQ_CMP;
363 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
364 ahd_free_scb(ahd, scb);
365 xpt_done(ccb);
366 return;
367 }
368#endif
369
259 ccb->ccb_h.status |= CAM_REQ_CMP;
260 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
261 ahd_free_scb(ahd, scb);
262 xpt_done(ccb);
263 return;
264 }
265#endif
266
267 /*
268 * If the recovery SCB completes, we have to be
269 * out of our timeout.
270 */
370 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
371 struct scb *list_scb;
372
271 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
272 struct scb *list_scb;
273
373 ahd->scb_data.recovery_scbs--;
274 /*
275 * We were able to complete the command successfully,
276 * so reinstate the timeouts for all other pending
277 * commands.
278 */
279 LIST_FOREACH(list_scb, &ahd->pending_scbs, pending_links) {
280 union ccb *ccb;
281 uint64_t time;
374
282
375 if (aic_get_transaction_status(scb) == CAM_BDR_SENT
376 || aic_get_transaction_status(scb) == CAM_REQ_ABORTED)
377 aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
283 ccb = list_scb->io_ctx;
284 if (ccb->ccb_h.timeout == CAM_TIME_INFINITY)
285 continue;
378
286
379 if (ahd->scb_data.recovery_scbs == 0) {
380 /*
381 * All recovery actions have completed successfully,
382 * so reinstate the timeouts for all other pending
383 * commands.
384 */
385 LIST_FOREACH(list_scb,
386 &ahd->pending_scbs, pending_links) {
387
388 aic_scb_timer_reset(list_scb,
389 aic_get_timeout(scb));
390 }
391
392 ahd_print_path(ahd, scb);
393 printf("no longer in timeout, status = %x\n",
394 ccb->ccb_h.status);
287 time = ccb->ccb_h.timeout;
288 time *= hz;
289 time /= 1000;
290 ccb->ccb_h.timeout_ch =
291 timeout(ahd_timeout, list_scb, time);
395 }
292 }
293
294 if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
295 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
296 ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
297 ahd_print_path(ahd, scb);
298 printf("no longer in timeout, status = %x\n",
299 ccb->ccb_h.status);
396 }
397
398 /* Don't clobber any existing error state */
300 }
301
302 /* Don't clobber any existing error state */
399 if (aic_get_transaction_status(scb) == CAM_REQ_INPROG) {
303 if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
400 ccb->ccb_h.status |= CAM_REQ_CMP;
401 } else if ((scb->flags & SCB_SENSE) != 0) {
402 /*
403 * We performed autosense retrieval.
404 *
405 * Zero any sense not transferred by the
406 * device. The SCSI spec mandates that any
407 * untransfered data should be assumed to be

--- 6 unchanged lines hidden (view full) ---

414 ahd_get_sense_buf(ahd, scb),
415/* XXX What size do we want to use??? */
416 sizeof(ccb->csio.sense_data)
417 - ccb->csio.sense_resid);
418 scb->io_ctx->ccb_h.status |= CAM_AUTOSNS_VALID;
419 } else if ((scb->flags & SCB_PKT_SENSE) != 0) {
420 struct scsi_status_iu_header *siu;
421 u_int sense_len;
304 ccb->ccb_h.status |= CAM_REQ_CMP;
305 } else if ((scb->flags & SCB_SENSE) != 0) {
306 /*
307 * We performed autosense retrieval.
308 *
309 * Zero any sense not transferred by the
310 * device. The SCSI spec mandates that any
311 * untransfered data should be assumed to be

--- 6 unchanged lines hidden (view full) ---

318 ahd_get_sense_buf(ahd, scb),
319/* XXX What size do we want to use??? */
320 sizeof(ccb->csio.sense_data)
321 - ccb->csio.sense_resid);
322 scb->io_ctx->ccb_h.status |= CAM_AUTOSNS_VALID;
323 } else if ((scb->flags & SCB_PKT_SENSE) != 0) {
324 struct scsi_status_iu_header *siu;
325 u_int sense_len;
326 int i;
422
423 /*
424 * Copy only the sense data into the provided buffer.
425 */
426 siu = (struct scsi_status_iu_header *)scb->sense_data;
427 sense_len = MIN(scsi_4btoul(siu->sense_length),
428 sizeof(ccb->csio.sense_data));
429 memset(&ccb->csio.sense_data, 0, sizeof(ccb->csio.sense_data));
430 memcpy(&ccb->csio.sense_data,
431 ahd_get_sense_buf(ahd, scb) + SIU_SENSE_OFFSET(siu),
432 sense_len);
327
328 /*
329 * Copy only the sense data into the provided buffer.
330 */
331 siu = (struct scsi_status_iu_header *)scb->sense_data;
332 sense_len = MIN(scsi_4btoul(siu->sense_length),
333 sizeof(ccb->csio.sense_data));
334 memset(&ccb->csio.sense_data, 0, sizeof(ccb->csio.sense_data));
335 memcpy(&ccb->csio.sense_data,
336 ahd_get_sense_buf(ahd, scb) + SIU_SENSE_OFFSET(siu),
337 sense_len);
433#ifdef AHD_DEBUG
434 if ((ahd_debug & AHD_SHOW_SENSE) != 0) {
435 uint8_t *sense_data = (uint8_t *)&ccb->csio.sense_data;
436 u_int i;
437
438 printf("Copied %d bytes of sense data offset %d:",
439 sense_len, SIU_SENSE_OFFSET(siu));
440 for (i = 0; i < sense_len; i++)
441 printf(" 0x%x", *sense_data++);
442 printf("\n");
443 }
444#endif
338 printf("Copied %d bytes of sense data offset %d:", sense_len,
339 SIU_SENSE_OFFSET(siu));
340 for (i = 0; i < sense_len; i++)
341 printf(" 0x%x", ((uint8_t *)&ccb->csio.sense_data)[i]);
342 printf("\n");
445 scb->io_ctx->ccb_h.status |= CAM_AUTOSNS_VALID;
446 }
447 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
448 ahd_free_scb(ahd, scb);
449 xpt_done(ccb);
450}
451
452static void
453ahd_action(struct cam_sim *sim, union ccb *ccb)
454{
455 struct ahd_softc *ahd;
456#ifdef AHD_TARGET_MODE
457 struct ahd_tmode_lstate *lstate;
458#endif
459 u_int target_id;
460 u_int our_id;
343 scb->io_ctx->ccb_h.status |= CAM_AUTOSNS_VALID;
344 }
345 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
346 ahd_free_scb(ahd, scb);
347 xpt_done(ccb);
348}
349
350static void
351ahd_action(struct cam_sim *sim, union ccb *ccb)
352{
353 struct ahd_softc *ahd;
354#ifdef AHD_TARGET_MODE
355 struct ahd_tmode_lstate *lstate;
356#endif
357 u_int target_id;
358 u_int our_id;
359 long s;
461
462 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("ahd_action\n"));
463
464 ahd = (struct ahd_softc *)cam_sim_softc(sim);
465
466 target_id = ccb->ccb_h.target_id;
467 our_id = SIM_SCSI_ID(ahd, sim);
468

--- 17 unchanged lines hidden (view full) ---

486 } else {
487 ccb->ccb_h.status = status;
488 xpt_done(ccb);
489 break;
490 }
491 }
492 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
493
360
361 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("ahd_action\n"));
362
363 ahd = (struct ahd_softc *)cam_sim_softc(sim);
364
365 target_id = ccb->ccb_h.target_id;
366 our_id = SIM_SCSI_ID(ahd, sim);
367

--- 17 unchanged lines hidden (view full) ---

385 } else {
386 ccb->ccb_h.status = status;
387 xpt_done(ccb);
388 break;
389 }
390 }
391 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
392
393 ahd_lock(ahd, &s);
494 SLIST_INSERT_HEAD(&lstate->accept_tios, &ccb->ccb_h,
495 sim_links.sle);
496 ccb->ccb_h.status = CAM_REQ_INPROG;
497 if ((ahd->flags & AHD_TQINFIFO_BLOCKED) != 0)
498 ahd_run_tqinfifo(ahd, /*paused*/FALSE);
394 SLIST_INSERT_HEAD(&lstate->accept_tios, &ccb->ccb_h,
395 sim_links.sle);
396 ccb->ccb_h.status = CAM_REQ_INPROG;
397 if ((ahd->flags & AHD_TQINFIFO_BLOCKED) != 0)
398 ahd_run_tqinfifo(ahd, /*paused*/FALSE);
399 ahd_unlock(ahd, &s);
499 break;
500 }
501
502 /*
503 * The target_id represents the target we attempt to
504 * select. In target mode, this is the initiator of
505 * the original command.
506 */
507 our_id = target_id;
508 target_id = ccb->csio.init_id;
509 /* FALLTHROUGH */
510 }
511#endif
512 case XPT_SCSI_IO: /* Execute the requested I/O operation */
513 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
514 {
515 struct scb *scb;
516 struct hardware_scb *hscb;
400 break;
401 }
402
403 /*
404 * The target_id represents the target we attempt to
405 * select. In target mode, this is the initiator of
406 * the original command.
407 */
408 our_id = target_id;
409 target_id = ccb->csio.init_id;
410 /* FALLTHROUGH */
411 }
412#endif
413 case XPT_SCSI_IO: /* Execute the requested I/O operation */
414 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
415 {
416 struct scb *scb;
417 struct hardware_scb *hscb;
517 struct ahd_initiator_tinfo *tinfo;
518 struct ahd_tmode_tstate *tstate;
519 u_int col_idx;
520
521 if ((ahd->flags & AHD_INITIATORROLE) == 0
522 && (ccb->ccb_h.func_code == XPT_SCSI_IO
523 || ccb->ccb_h.func_code == XPT_RESET_DEV)) {
524 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
525 xpt_done(ccb);
526 return;
527 }
528
529 /*
530 * get an scb to use.
531 */
418
419 if ((ahd->flags & AHD_INITIATORROLE) == 0
420 && (ccb->ccb_h.func_code == XPT_SCSI_IO
421 || ccb->ccb_h.func_code == XPT_RESET_DEV)) {
422 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
423 xpt_done(ccb);
424 return;
425 }
426
427 /*
428 * get an scb to use.
429 */
532 tinfo = ahd_fetch_transinfo(ahd, 'A', our_id,
533 target_id, &tstate);
534 if ((ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) == 0
535 || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0
536 || ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
537 col_idx = AHD_NEVER_COL_IDX;
538 } else {
539 col_idx = AHD_BUILD_COL_IDX(target_id,
540 ccb->ccb_h.target_lun);
541 }
542 if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
430 ahd_lock(ahd, &s);
431 if ((scb = ahd_get_scb(ahd)) == NULL) {
543
544 xpt_freeze_simq(sim, /*count*/1);
545 ahd->flags |= AHD_RESOURCE_SHORTAGE;
432
433 xpt_freeze_simq(sim, /*count*/1);
434 ahd->flags |= AHD_RESOURCE_SHORTAGE;
435 ahd_unlock(ahd, &s);
546 ccb->ccb_h.status = CAM_REQUEUE_REQ;
547 xpt_done(ccb);
548 return;
549 }
436 ccb->ccb_h.status = CAM_REQUEUE_REQ;
437 xpt_done(ccb);
438 return;
439 }
440 ahd_unlock(ahd, &s);
550
551 hscb = scb->hscb;
552
553 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_SUBTRACE,
554 ("start scb(%p)\n", scb));
555 scb->io_ctx = ccb;
556 /*
557 * So we can find the SCB when an abort is requested

--- 5 unchanged lines hidden (view full) ---

563 */
564 hscb->control = 0;
565 hscb->scsiid = BUILD_SCSIID(ahd, sim, target_id, our_id);
566 hscb->lun = ccb->ccb_h.target_lun;
567 if (ccb->ccb_h.func_code == XPT_RESET_DEV) {
568 hscb->cdb_len = 0;
569 scb->flags |= SCB_DEVICE_RESET;
570 hscb->control |= MK_MESSAGE;
441
442 hscb = scb->hscb;
443
444 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_SUBTRACE,
445 ("start scb(%p)\n", scb));
446 scb->io_ctx = ccb;
447 /*
448 * So we can find the SCB when an abort is requested

--- 5 unchanged lines hidden (view full) ---

454 */
455 hscb->control = 0;
456 hscb->scsiid = BUILD_SCSIID(ahd, sim, target_id, our_id);
457 hscb->lun = ccb->ccb_h.target_lun;
458 if (ccb->ccb_h.func_code == XPT_RESET_DEV) {
459 hscb->cdb_len = 0;
460 scb->flags |= SCB_DEVICE_RESET;
461 hscb->control |= MK_MESSAGE;
571 hscb->task_management = SIU_TASKMGMT_LUN_RESET;
572 ahd_execute_scb(scb, NULL, 0, 0);
573 } else {
574#ifdef AHD_TARGET_MODE
575 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
576 struct target_data *tdata;
577
578 tdata = &hscb->shared_data.tdata;
579 if (ahd->pending_device == lstate)

--- 7 unchanged lines hidden (view full) ---

587 }
588 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT)
589 tdata->target_phases |= NO_DISCONNECT;
590
591 tdata->initiator_tag =
592 ahd_htole16(ccb->csio.tag_id);
593 }
594#endif
462 ahd_execute_scb(scb, NULL, 0, 0);
463 } else {
464#ifdef AHD_TARGET_MODE
465 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
466 struct target_data *tdata;
467
468 tdata = &hscb->shared_data.tdata;
469 if (ahd->pending_device == lstate)

--- 7 unchanged lines hidden (view full) ---

477 }
478 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT)
479 tdata->target_phases |= NO_DISCONNECT;
480
481 tdata->initiator_tag =
482 ahd_htole16(ccb->csio.tag_id);
483 }
484#endif
595 hscb->task_management = 0;
596 if (ccb->ccb_h.flags & CAM_TAG_ACTION_VALID)
597 hscb->control |= ccb->csio.tag_action;
598
599 ahd_setup_data(ahd, sim, &ccb->csio, scb);
600 }
601 break;
602 }
603#ifdef AHD_TARGET_MODE

--- 25 unchanged lines hidden (view full) ---

629#endif
630 case XPT_ABORT: /* Abort the specified CCB */
631 {
632 ahd_abort_ccb(ahd, sim, ccb);
633 break;
634 }
635 case XPT_SET_TRAN_SETTINGS:
636 {
485 if (ccb->ccb_h.flags & CAM_TAG_ACTION_VALID)
486 hscb->control |= ccb->csio.tag_action;
487
488 ahd_setup_data(ahd, sim, &ccb->csio, scb);
489 }
490 break;
491 }
492#ifdef AHD_TARGET_MODE

--- 25 unchanged lines hidden (view full) ---

518#endif
519 case XPT_ABORT: /* Abort the specified CCB */
520 {
521 ahd_abort_ccb(ahd, sim, ccb);
522 break;
523 }
524 case XPT_SET_TRAN_SETTINGS:
525 {
526 ahd_lock(ahd, &s);
637 ahd_set_tran_settings(ahd, SIM_SCSI_ID(ahd, sim),
638 SIM_CHANNEL(ahd, sim), &ccb->cts);
527 ahd_set_tran_settings(ahd, SIM_SCSI_ID(ahd, sim),
528 SIM_CHANNEL(ahd, sim), &ccb->cts);
529 ahd_unlock(ahd, &s);
639 xpt_done(ccb);
640 break;
641 }
642 case XPT_GET_TRAN_SETTINGS:
643 /* Get default/user set transfer settings for the target */
644 {
530 xpt_done(ccb);
531 break;
532 }
533 case XPT_GET_TRAN_SETTINGS:
534 /* Get default/user set transfer settings for the target */
535 {
536 ahd_lock(ahd, &s);
645 ahd_get_tran_settings(ahd, SIM_SCSI_ID(ahd, sim),
646 SIM_CHANNEL(ahd, sim), &ccb->cts);
537 ahd_get_tran_settings(ahd, SIM_SCSI_ID(ahd, sim),
538 SIM_CHANNEL(ahd, sim), &ccb->cts);
539 ahd_unlock(ahd, &s);
647 xpt_done(ccb);
648 break;
649 }
650 case XPT_CALC_GEOMETRY:
651 {
540 xpt_done(ccb);
541 break;
542 }
543 case XPT_CALC_GEOMETRY:
544 {
652 aic_calc_geometry(&ccb->ccg, ahd->flags & AHD_EXTENDED_TRANS_A);
545 struct ccb_calc_geometry *ccg;
546 uint32_t size_mb;
547 uint32_t secs_per_cylinder;
548 int extended;
549
550 ccg = &ccb->ccg;
551 size_mb = ccg->volume_size
552 / ((1024L * 1024L) / ccg->block_size);
553 extended = ahd->flags & AHD_EXTENDED_TRANS_A;
554
555 if (size_mb > 1024 && extended) {
556 ccg->heads = 255;
557 ccg->secs_per_track = 63;
558 } else {
559 ccg->heads = 64;
560 ccg->secs_per_track = 32;
561 }
562 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
563 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
564 ccb->ccb_h.status = CAM_REQ_CMP;
653 xpt_done(ccb);
654 break;
655 }
656 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
657 {
658 int found;
659
565 xpt_done(ccb);
566 break;
567 }
568 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
569 {
570 int found;
571
572 ahd_lock(ahd, &s);
660 found = ahd_reset_channel(ahd, SIM_CHANNEL(ahd, sim),
661 /*initiate reset*/TRUE);
573 found = ahd_reset_channel(ahd, SIM_CHANNEL(ahd, sim),
574 /*initiate reset*/TRUE);
575 ahd_unlock(ahd, &s);
662 if (bootverbose) {
663 xpt_print_path(SIM_PATH(ahd, sim));
664 printf("SCSI bus reset delivered. "
665 "%d SCBs aborted.\n", found);
666 }
667 ccb->ccb_h.status = CAM_REQ_CMP;
668 xpt_done(ccb);
669 break;

--- 16 unchanged lines hidden (view full) ---

686 | PIT_DISCONNECT
687 | PIT_TERM_IO;
688 } else {
689 cpi->target_sprt = 0;
690 }
691 cpi->hba_misc = 0;
692 cpi->hba_eng_cnt = 0;
693 cpi->max_target = (ahd->features & AHD_WIDE) ? 15 : 7;
576 if (bootverbose) {
577 xpt_print_path(SIM_PATH(ahd, sim));
578 printf("SCSI bus reset delivered. "
579 "%d SCBs aborted.\n", found);
580 }
581 ccb->ccb_h.status = CAM_REQ_CMP;
582 xpt_done(ccb);
583 break;

--- 16 unchanged lines hidden (view full) ---

600 | PIT_DISCONNECT
601 | PIT_TERM_IO;
602 } else {
603 cpi->target_sprt = 0;
604 }
605 cpi->hba_misc = 0;
606 cpi->hba_eng_cnt = 0;
607 cpi->max_target = (ahd->features & AHD_WIDE) ? 15 : 7;
694 cpi->max_lun = AHD_NUM_LUNS_NONPKT - 1;
608 cpi->max_lun = AHD_NUM_LUNS - 1;
695 cpi->initiator_id = ahd->our_id;
696 if ((ahd->flags & AHD_RESET_BUS_A) == 0) {
697 cpi->hba_misc |= PIM_NOBUSRESET;
698 }
699 cpi->bus_id = cam_sim_bus(sim);
700 cpi->base_transfer_speed = 3300;
701 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
702 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
703 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
704 cpi->unit_number = cam_sim_unit(sim);
609 cpi->initiator_id = ahd->our_id;
610 if ((ahd->flags & AHD_RESET_BUS_A) == 0) {
611 cpi->hba_misc |= PIM_NOBUSRESET;
612 }
613 cpi->bus_id = cam_sim_bus(sim);
614 cpi->base_transfer_speed = 3300;
615 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
616 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
617 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
618 cpi->unit_number = cam_sim_unit(sim);
619#ifdef AHD_NEW_TRAN_SETTINGS
705 cpi->protocol = PROTO_SCSI;
706 cpi->protocol_version = SCSI_REV_2;
707 cpi->transport = XPORT_SPI;
620 cpi->protocol = PROTO_SCSI;
621 cpi->protocol_version = SCSI_REV_2;
622 cpi->transport = XPORT_SPI;
623 cpi->transport_version = 2;
624 cpi->xport_specific.spi.ppr_options = SID_SPI_CLOCK_ST;
708 cpi->transport_version = 4;
625 cpi->transport_version = 4;
709 cpi->xport_specific.spi.ppr_options = SID_SPI_CLOCK_DT_ST
710 | SID_SPI_IUS
711 | SID_SPI_QAS;
626 cpi->xport_specific.spi.ppr_options = SID_SPI_CLOCK_DT_ST;
627#endif
712 cpi->ccb_h.status = CAM_REQ_CMP;
713 xpt_done(ccb);
714 break;
715 }
716 default:
717 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
718 xpt_done(ccb);
719 break;
720 }
721}
722
723
724static void
725ahd_set_tran_settings(struct ahd_softc *ahd, int our_id, char channel,
726 struct ccb_trans_settings *cts)
727{
628 cpi->ccb_h.status = CAM_REQ_CMP;
629 xpt_done(ccb);
630 break;
631 }
632 default:
633 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
634 xpt_done(ccb);
635 break;
636 }
637}
638
639
640static void
641ahd_set_tran_settings(struct ahd_softc *ahd, int our_id, char channel,
642 struct ccb_trans_settings *cts)
643{
644#ifdef AHD_NEW_TRAN_SETTINGS
728 struct ahd_devinfo devinfo;
729 struct ccb_trans_settings_scsi *scsi;
730 struct ccb_trans_settings_spi *spi;
731 struct ahd_initiator_tinfo *tinfo;
732 struct ahd_tmode_tstate *tstate;
733 uint16_t *discenable;
734 uint16_t *tagenable;
735 u_int update_type;

--- 94 unchanged lines hidden (view full) ---

830 spi->ppr_options = 0;
831 }
832
833 ahd_set_syncrate(ahd, &devinfo, spi->sync_period,
834 spi->sync_offset, spi->ppr_options,
835 update_type, /*paused*/FALSE);
836 }
837 cts->ccb_h.status = CAM_REQ_CMP;
645 struct ahd_devinfo devinfo;
646 struct ccb_trans_settings_scsi *scsi;
647 struct ccb_trans_settings_spi *spi;
648 struct ahd_initiator_tinfo *tinfo;
649 struct ahd_tmode_tstate *tstate;
650 uint16_t *discenable;
651 uint16_t *tagenable;
652 u_int update_type;

--- 94 unchanged lines hidden (view full) ---

747 spi->ppr_options = 0;
748 }
749
750 ahd_set_syncrate(ahd, &devinfo, spi->sync_period,
751 spi->sync_offset, spi->ppr_options,
752 update_type, /*paused*/FALSE);
753 }
754 cts->ccb_h.status = CAM_REQ_CMP;
755#else
756 struct ahd_devinfo devinfo;
757 struct ahd_initiator_tinfo *tinfo;
758 struct ahd_tmode_tstate *tstate;
759 uint16_t *discenable;
760 uint16_t *tagenable;
761 u_int update_type;
762
763 ahd_compile_devinfo(&devinfo, SIM_SCSI_ID(ahd, sim),
764 cts->ccb_h.target_id,
765 cts->ccb_h.target_lun,
766 SIM_CHANNEL(ahd, sim),
767 ROLE_UNKNOWN);
768 tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
769 devinfo.our_scsiid,
770 devinfo.target, &tstate);
771 update_type = 0;
772 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) != 0) {
773 update_type |= AHD_TRANS_GOAL;
774 discenable = &tstate->discenable;
775 tagenable = &tstate->tagenable;
776 } else if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) {
777 update_type |= AHD_TRANS_USER;
778 discenable = &ahd->user_discenable;
779 tagenable = &ahd->user_tagenable;
780 } else {
781 cts->ccb_h.status = CAM_REQ_INVALID;
782 return;
783 }
784
785 if ((cts->valid & CCB_TRANS_DISC_VALID) != 0) {
786 if ((cts->flags & CCB_TRANS_DISC_ENB) != 0)
787 *discenable |= devinfo.target_mask;
788 else
789 *discenable &= ~devinfo.target_mask;
790 }
791
792 if ((cts->valid & CCB_TRANS_TQ_VALID) != 0) {
793 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0)
794 *tagenable |= devinfo.target_mask;
795 else
796 *tagenable &= ~devinfo.target_mask;
797 }
798
799 if ((cts->valid & CCB_TRANS_BUS_WIDTH_VALID) != 0) {
800 ahd_validate_width(ahd, /*tinfo limit*/NULL,
801 &cts->bus_width, ROLE_UNKNOWN);
802 ahd_set_width(ahd, &devinfo, cts->bus_width,
803 update_type, /*paused*/FALSE);
804 }
805
806 if ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) == 0) {
807 if (update_type == AHD_TRANS_USER)
808 cts->sync_offset = tinfo->user.offset;
809 else
810 cts->sync_offset = tinfo->goal.offset;
811 }
812
813 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) == 0) {
814 if (update_type == AHD_TRANS_USER)
815 cts->sync_period = tinfo->user.period;
816 else
817 cts->sync_period = tinfo->goal.period;
818 }
819
820 if (((cts->valid & CCB_TRANS_SYNC_RATE_VALID) != 0)
821 || ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0)) {
822 u_int ppr_options;
823 u_int maxsync;
824
825 maxsync = AHD_SYNCRATE_MAX;
826 ppr_options = 0;
827 if (cts->sync_period <= AHD_SYNCRATE_DT
828 && cts->bus_width == MSG_EXT_WDTR_BUS_16_BIT) {
829 ppr_options = tinfo->user.ppr_options
830 | MSG_EXT_PPR_DT_REQ;
831 }
832
833 ahd_find_syncrate(ahd, &cts->sync_period,
834 &ppr_options, maxsync);
835 ahd_validate_offset(ahd, /*tinfo limit*/NULL,
836 cts->sync_period, &cts->sync_offset,
837 MSG_EXT_WDTR_BUS_8_BIT,
838 ROLE_UNKNOWN);
839
840 /* We use a period of 0 to represent async */
841 if (cts->sync_offset == 0) {
842 cts->sync_period = 0;
843 ppr_options = 0;
844 }
845
846 if (ppr_options != 0
847 && tinfo->user.transport_version >= 3) {
848 tinfo->goal.transport_version =
849 tinfo->user.transport_version;
850 tinfo->curr.transport_version =
851 tinfo->user.transport_version;
852 }
853
854 ahd_set_syncrate(ahd, &devinfo, cts->sync_period,
855 cts->sync_offset, ppr_options,
856 update_type, /*paused*/FALSE);
857 }
858 cts->ccb_h.status = CAM_REQ_CMP;
859#endif
838}
839
840static void
841ahd_get_tran_settings(struct ahd_softc *ahd, int our_id, char channel,
842 struct ccb_trans_settings *cts)
843{
860}
861
862static void
863ahd_get_tran_settings(struct ahd_softc *ahd, int our_id, char channel,
864 struct ccb_trans_settings *cts)
865{
866#ifdef AHD_NEW_TRAN_SETTINGS
844 struct ahd_devinfo devinfo;
845 struct ccb_trans_settings_scsi *scsi;
846 struct ccb_trans_settings_spi *spi;
847 struct ahd_initiator_tinfo *targ_info;
848 struct ahd_tmode_tstate *tstate;
849 struct ahd_transinfo *tinfo;
850
851 scsi = &cts->proto_specific.scsi;

--- 44 unchanged lines hidden (view full) ---

896 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
897 scsi->valid = CTS_SCSI_VALID_TQ;
898 spi->valid |= CTS_SPI_VALID_DISC;
899 } else {
900 scsi->valid = 0;
901 }
902
903 cts->ccb_h.status = CAM_REQ_CMP;
867 struct ahd_devinfo devinfo;
868 struct ccb_trans_settings_scsi *scsi;
869 struct ccb_trans_settings_spi *spi;
870 struct ahd_initiator_tinfo *targ_info;
871 struct ahd_tmode_tstate *tstate;
872 struct ahd_transinfo *tinfo;
873
874 scsi = &cts->proto_specific.scsi;

--- 44 unchanged lines hidden (view full) ---

919 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
920 scsi->valid = CTS_SCSI_VALID_TQ;
921 spi->valid |= CTS_SPI_VALID_DISC;
922 } else {
923 scsi->valid = 0;
924 }
925
926 cts->ccb_h.status = CAM_REQ_CMP;
927#else
928 struct ahd_devinfo devinfo;
929 struct ahd_initiator_tinfo *targ_info;
930 struct ahd_tmode_tstate *tstate;
931 struct ahd_transinfo *tinfo;
932
933 ahd_compile_devinfo(&devinfo, our_id,
934 cts->ccb_h.target_id,
935 cts->ccb_h.target_lun,
936 channel, ROLE_UNKNOWN);
937 targ_info = ahd_fetch_transinfo(ahd, devinfo.channel,
938 devinfo.our_scsiid,
939 devinfo.target, &tstate);
940
941 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) != 0)
942 tinfo = &targ_info->curr;
943 else
944 tinfo = &targ_info->user;
945
946 cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB);
947 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) == 0) {
948 if ((ahd->user_discenable & devinfo.target_mask) != 0)
949 cts->flags |= CCB_TRANS_DISC_ENB;
950
951 if ((ahd->user_tagenable & devinfo.target_mask) != 0)
952 cts->flags |= CCB_TRANS_TAG_ENB;
953 } else {
954 if ((tstate->discenable & devinfo.target_mask) != 0)
955 cts->flags |= CCB_TRANS_DISC_ENB;
956
957 if ((tstate->tagenable & devinfo.target_mask) != 0)
958 cts->flags |= CCB_TRANS_TAG_ENB;
959 }
960 cts->sync_period = tinfo->period;
961 cts->sync_offset = tinfo->offset;
962 cts->bus_width = tinfo->width;
963
964 cts->valid = CCB_TRANS_SYNC_RATE_VALID
965 | CCB_TRANS_SYNC_OFFSET_VALID
966 | CCB_TRANS_BUS_WIDTH_VALID;
967
968 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD)
969 cts->valid |= CCB_TRANS_DISC_VALID|CCB_TRANS_TQ_VALID;
970
971 cts->ccb_h.status = CAM_REQ_CMP;
972#endif
904}
905
906static void
907ahd_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
908{
909 struct ahd_softc *ahd;
910 struct cam_sim *sim;
911
912 sim = (struct cam_sim *)callback_arg;
913 ahd = (struct ahd_softc *)cam_sim_softc(sim);
914 switch (code) {
915 case AC_LOST_DEVICE:
916 {
917 struct ahd_devinfo devinfo;
973}
974
975static void
976ahd_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
977{
978 struct ahd_softc *ahd;
979 struct cam_sim *sim;
980
981 sim = (struct cam_sim *)callback_arg;
982 ahd = (struct ahd_softc *)cam_sim_softc(sim);
983 switch (code) {
984 case AC_LOST_DEVICE:
985 {
986 struct ahd_devinfo devinfo;
987 long s;
918
919 ahd_compile_devinfo(&devinfo, SIM_SCSI_ID(ahd, sim),
920 xpt_path_target_id(path),
921 xpt_path_lun_id(path),
922 SIM_CHANNEL(ahd, sim),
923 ROLE_UNKNOWN);
924
925 /*
926 * Revert to async/narrow transfers
927 * for the next device.
928 */
988
989 ahd_compile_devinfo(&devinfo, SIM_SCSI_ID(ahd, sim),
990 xpt_path_target_id(path),
991 xpt_path_lun_id(path),
992 SIM_CHANNEL(ahd, sim),
993 ROLE_UNKNOWN);
994
995 /*
996 * Revert to async/narrow transfers
997 * for the next device.
998 */
999 ahd_lock(ahd, &s);
929 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
930 AHD_TRANS_GOAL|AHD_TRANS_CUR, /*paused*/FALSE);
931 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
932 /*ppr_options*/0, AHD_TRANS_GOAL|AHD_TRANS_CUR,
933 /*paused*/FALSE);
1000 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1001 AHD_TRANS_GOAL|AHD_TRANS_CUR, /*paused*/FALSE);
1002 ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
1003 /*ppr_options*/0, AHD_TRANS_GOAL|AHD_TRANS_CUR,
1004 /*paused*/FALSE);
1005 ahd_unlock(ahd, &s);
934 break;
935 }
936 default:
937 break;
938 }
939}
940
941static void
942ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
943 int error)
944{
945 struct scb *scb;
946 union ccb *ccb;
947 struct ahd_softc *ahd;
948 struct ahd_initiator_tinfo *tinfo;
949 struct ahd_tmode_tstate *tstate;
950 u_int mask;
1006 break;
1007 }
1008 default:
1009 break;
1010 }
1011}
1012
1013static void
1014ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
1015 int error)
1016{
1017 struct scb *scb;
1018 union ccb *ccb;
1019 struct ahd_softc *ahd;
1020 struct ahd_initiator_tinfo *tinfo;
1021 struct ahd_tmode_tstate *tstate;
1022 u_int mask;
1023 u_long s;
951
952 scb = (struct scb *)arg;
953 ccb = scb->io_ctx;
954 ahd = scb->ahd_softc;
955
956 if (error != 0) {
957 if (error == EFBIG)
1024
1025 scb = (struct scb *)arg;
1026 ccb = scb->io_ctx;
1027 ahd = scb->ahd_softc;
1028
1029 if (error != 0) {
1030 if (error == EFBIG)
958 aic_set_transaction_status(scb, CAM_REQ_TOO_BIG);
1031 ahd_set_transaction_status(scb, CAM_REQ_TOO_BIG);
959 else
1032 else
960 aic_set_transaction_status(scb, CAM_REQ_CMP_ERR);
1033 ahd_set_transaction_status(scb, CAM_REQ_CMP_ERR);
961 if (nsegments != 0)
962 bus_dmamap_unload(ahd->buffer_dmat, scb->dmamap);
1034 if (nsegments != 0)
1035 bus_dmamap_unload(ahd->buffer_dmat, scb->dmamap);
1036 ahd_lock(ahd, &s);
963 ahd_free_scb(ahd, scb);
1037 ahd_free_scb(ahd, scb);
1038 ahd_unlock(ahd, &s);
964 xpt_done(ccb);
965 return;
966 }
967 scb->sg_count = 0;
968 if (nsegments != 0) {
969 void *sg;
970 bus_dmasync_op_t op;
971 u_int i;

--- 21 unchanged lines hidden (view full) ---

993 tdata->target_phases |= DPHASE_PENDING;
994 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
995 tdata->data_phase = P_DATAOUT;
996 else
997 tdata->data_phase = P_DATAIN;
998 }
999 }
1000
1039 xpt_done(ccb);
1040 return;
1041 }
1042 scb->sg_count = 0;
1043 if (nsegments != 0) {
1044 void *sg;
1045 bus_dmasync_op_t op;
1046 u_int i;

--- 21 unchanged lines hidden (view full) ---

1068 tdata->target_phases |= DPHASE_PENDING;
1069 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
1070 tdata->data_phase = P_DATAOUT;
1071 else
1072 tdata->data_phase = P_DATAIN;
1073 }
1074 }
1075
1076 ahd_lock(ahd, &s);
1077
1001 /*
1002 * Last time we need to check if this SCB needs to
1003 * be aborted.
1004 */
1078 /*
1079 * Last time we need to check if this SCB needs to
1080 * be aborted.
1081 */
1005 if (aic_get_transaction_status(scb) != CAM_REQ_INPROG) {
1082 if (ahd_get_transaction_status(scb) != CAM_REQ_INPROG) {
1006 if (nsegments != 0)
1007 bus_dmamap_unload(ahd->buffer_dmat,
1008 scb->dmamap);
1009 ahd_free_scb(ahd, scb);
1083 if (nsegments != 0)
1084 bus_dmamap_unload(ahd->buffer_dmat,
1085 scb->dmamap);
1086 ahd_free_scb(ahd, scb);
1087 ahd_unlock(ahd, &s);
1010 xpt_done(ccb);
1011 return;
1012 }
1013
1014 tinfo = ahd_fetch_transinfo(ahd, SCSIID_CHANNEL(ahd, scb->hscb->scsiid),
1015 SCSIID_OUR_ID(scb->hscb->scsiid),
1016 SCSIID_TARGET(ahd, scb->hscb->scsiid),
1017 &tstate);
1018
1019 mask = SCB_GET_TARGET_MASK(ahd, scb);
1020
1021 if ((tstate->discenable & mask) != 0
1022 && (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) == 0)
1023 scb->hscb->control |= DISCENB;
1024
1088 xpt_done(ccb);
1089 return;
1090 }
1091
1092 tinfo = ahd_fetch_transinfo(ahd, SCSIID_CHANNEL(ahd, scb->hscb->scsiid),
1093 SCSIID_OUR_ID(scb->hscb->scsiid),
1094 SCSIID_TARGET(ahd, scb->hscb->scsiid),
1095 &tstate);
1096
1097 mask = SCB_GET_TARGET_MASK(ahd, scb);
1098
1099 if ((tstate->discenable & mask) != 0
1100 && (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) == 0)
1101 scb->hscb->control |= DISCENB;
1102
1025 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
1103 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
1026 scb->flags |= SCB_PACKETIZED;
1104 scb->flags |= SCB_PACKETIZED;
1027 if (scb->hscb->task_management != 0)
1028 scb->hscb->control &= ~MK_MESSAGE;
1029 }
1030
1031 if ((ccb->ccb_h.flags & CAM_NEGOTIATE) != 0
1032 && (tinfo->goal.width != 0
1033 || tinfo->goal.period != 0
1034 || tinfo->goal.ppr_options != 0)) {
1035 scb->flags |= SCB_NEGOTIATE;
1036 scb->hscb->control |= MK_MESSAGE;
1037 } else if ((tstate->auto_negotiate & mask) != 0) {
1038 scb->flags |= SCB_AUTO_NEGOTIATE;
1039 scb->hscb->control |= MK_MESSAGE;
1040 }
1041
1042 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
1043
1044 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1045
1105
1106 if ((ccb->ccb_h.flags & CAM_NEGOTIATE) != 0
1107 && (tinfo->goal.width != 0
1108 || tinfo->goal.period != 0
1109 || tinfo->goal.ppr_options != 0)) {
1110 scb->flags |= SCB_NEGOTIATE;
1111 scb->hscb->control |= MK_MESSAGE;
1112 } else if ((tstate->auto_negotiate & mask) != 0) {
1113 scb->flags |= SCB_AUTO_NEGOTIATE;
1114 scb->hscb->control |= MK_MESSAGE;
1115 }
1116
1117 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
1118
1119 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1120
1046 aic_scb_timer_start(scb);
1121 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
1122 uint64_t time;
1047
1123
1124 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT)
1125 ccb->ccb_h.timeout = 5 * 1000;
1126
1127 time = ccb->ccb_h.timeout;
1128 time *= hz;
1129 time /= 1000;
1130 ccb->ccb_h.timeout_ch =
1131 timeout(ahd_timeout, (caddr_t)scb, time);
1132 }
1133
1134 scb->flags |= SCB_ACTIVE;
1135
1048 if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) {
1049 /* Define a mapping from our tag to the SCB. */
1050 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
1051 ahd_pause(ahd);
1052 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
1053 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
1054 ahd_unpause(ahd);
1055 } else {
1056 ahd_queue_scb(ahd, scb);
1057 }
1058
1136 if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) {
1137 /* Define a mapping from our tag to the SCB. */
1138 ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
1139 ahd_pause(ahd);
1140 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
1141 ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
1142 ahd_unpause(ahd);
1143 } else {
1144 ahd_queue_scb(ahd, scb);
1145 }
1146
1147 ahd_unlock(ahd, &s);
1059}
1060
1061static void
1062ahd_poll(struct cam_sim *sim)
1063{
1064 ahd_intr(cam_sim_softc(sim));
1065}
1066

--- 10 unchanged lines hidden (view full) ---

1077 csio->resid = 0;
1078 csio->sense_resid = 0;
1079 if (ccb_h->func_code == XPT_SCSI_IO) {
1080 hscb->cdb_len = csio->cdb_len;
1081 if ((ccb_h->flags & CAM_CDB_POINTER) != 0) {
1082
1083 if (hscb->cdb_len > MAX_CDB_LEN
1084 && (ccb_h->flags & CAM_CDB_PHYS) == 0) {
1148}
1149
1150static void
1151ahd_poll(struct cam_sim *sim)
1152{
1153 ahd_intr(cam_sim_softc(sim));
1154}
1155

--- 10 unchanged lines hidden (view full) ---

1166 csio->resid = 0;
1167 csio->sense_resid = 0;
1168 if (ccb_h->func_code == XPT_SCSI_IO) {
1169 hscb->cdb_len = csio->cdb_len;
1170 if ((ccb_h->flags & CAM_CDB_POINTER) != 0) {
1171
1172 if (hscb->cdb_len > MAX_CDB_LEN
1173 && (ccb_h->flags & CAM_CDB_PHYS) == 0) {
1174 u_long s;
1085
1175
1086 /*
1087 * Should CAM start to support CDB sizes
1088 * greater than 16 bytes, we could use
1089 * the sense buffer to store the CDB.
1090 */
1091 aic_set_transaction_status(scb,
1176 ahd_set_transaction_status(scb,
1092 CAM_REQ_INVALID);
1177 CAM_REQ_INVALID);
1178 ahd_lock(ahd, &s);
1093 ahd_free_scb(ahd, scb);
1179 ahd_free_scb(ahd, scb);
1180 ahd_unlock(ahd, &s);
1094 xpt_done((union ccb *)csio);
1095 return;
1096 }
1097 if ((ccb_h->flags & CAM_CDB_PHYS) != 0) {
1181 xpt_done((union ccb *)csio);
1182 return;
1183 }
1184 if ((ccb_h->flags & CAM_CDB_PHYS) != 0) {
1098 hscb->shared_data.idata.cdb_from_host.cdbptr =
1099 aic_htole64((uintptr_t)csio->cdb_io.cdb_ptr);
1100 hscb->shared_data.idata.cdb_from_host.cdblen =
1101 csio->cdb_len;
1102 hscb->cdb_len |= SCB_CDB_LEN_PTR;
1185 hscb->shared_data.idata.cdbptr =
1186 ahd_htole64((uintptr_t)csio->cdb_io.cdb_ptr);
1103 } else {
1104 memcpy(hscb->shared_data.idata.cdb,
1105 csio->cdb_io.cdb_ptr,
1106 hscb->cdb_len);
1107 }
1108 } else {
1109 if (hscb->cdb_len > MAX_CDB_LEN) {
1187 } else {
1188 memcpy(hscb->shared_data.idata.cdb,
1189 csio->cdb_io.cdb_ptr,
1190 hscb->cdb_len);
1191 }
1192 } else {
1193 if (hscb->cdb_len > MAX_CDB_LEN) {
1194 u_long s;
1110
1195
1111 aic_set_transaction_status(scb,
1196 ahd_set_transaction_status(scb,
1112 CAM_REQ_INVALID);
1197 CAM_REQ_INVALID);
1198 ahd_lock(ahd, &s);
1113 ahd_free_scb(ahd, scb);
1199 ahd_free_scb(ahd, scb);
1200 ahd_unlock(ahd, &s);
1114 xpt_done((union ccb *)csio);
1115 return;
1116 }
1117 memcpy(hscb->shared_data.idata.cdb,
1118 csio->cdb_io.cdb_bytes, hscb->cdb_len);
1119 }
1120 }
1121

--- 28 unchanged lines hidden (view full) ---

1150 } else {
1151 struct bus_dma_segment seg;
1152
1153 /* Pointer to physical buffer */
1154 if (csio->dxfer_len > AHD_MAXTRANSFER_SIZE)
1155 panic("ahd_setup_data - Transfer size "
1156 "larger than can device max");
1157
1201 xpt_done((union ccb *)csio);
1202 return;
1203 }
1204 memcpy(hscb->shared_data.idata.cdb,
1205 csio->cdb_io.cdb_bytes, hscb->cdb_len);
1206 }
1207 }
1208

--- 28 unchanged lines hidden (view full) ---

1237 } else {
1238 struct bus_dma_segment seg;
1239
1240 /* Pointer to physical buffer */
1241 if (csio->dxfer_len > AHD_MAXTRANSFER_SIZE)
1242 panic("ahd_setup_data - Transfer size "
1243 "larger than can device max");
1244
1158 seg.ds_addr =
1159 (bus_addr_t)(vm_offset_t)csio->data_ptr;
1245 seg.ds_addr = (bus_addr_t)csio->data_ptr;
1160 seg.ds_len = csio->dxfer_len;
1161 ahd_execute_scb(scb, &seg, 1, 0);
1162 }
1163 } else {
1164 struct bus_dma_segment *segs;
1165
1166 if ((ccb_h->flags & CAM_DATA_PHYS) != 0)
1167 panic("ahd_setup_data - Physical segment "

--- 7 unchanged lines hidden (view full) ---

1175 segs = (struct bus_dma_segment *)csio->data_ptr;
1176 ahd_execute_scb(scb, segs, csio->sglist_cnt, 0);
1177 }
1178 } else {
1179 ahd_execute_scb(scb, NULL, 0, 0);
1180 }
1181}
1182
1246 seg.ds_len = csio->dxfer_len;
1247 ahd_execute_scb(scb, &seg, 1, 0);
1248 }
1249 } else {
1250 struct bus_dma_segment *segs;
1251
1252 if ((ccb_h->flags & CAM_DATA_PHYS) != 0)
1253 panic("ahd_setup_data - Physical segment "

--- 7 unchanged lines hidden (view full) ---

1261 segs = (struct bus_dma_segment *)csio->data_ptr;
1262 ahd_execute_scb(scb, segs, csio->sglist_cnt, 0);
1263 }
1264 } else {
1265 ahd_execute_scb(scb, NULL, 0, 0);
1266 }
1267}
1268
1269#if NOT_YET
1183static void
1270static void
1271ahd_set_recoveryscb(struct ahd_softc *ahd, struct scb *scb) {
1272
1273 if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
1274 struct scb *list_scb;
1275
1276 scb->flags |= SCB_RECOVERY_SCB;
1277
1278 /*
1279 * Take all queued, but not sent SCBs out of the equation.
1280 * Also ensure that no new CCBs are queued to us while we
1281 * try to fix this problem.
1282 */
1283 if ((scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
1284 xpt_freeze_simq(SCB_GET_SIM(ahd, scb), /*count*/1);
1285 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
1286 }
1287
1288 /*
1289 * Go through all of our pending SCBs and remove
1290 * any scheduled timeouts for them. We will reschedule
1291 * them after we've successfully fixed this problem.
1292 */
1293 LIST_FOREACH(list_scb, &ahd->pending_scbs, pending_links) {
1294 union ccb *ccb;
1295
1296 ccb = list_scb->io_ctx;
1297 untimeout(ahd_timeout, list_scb, ccb->ccb_h.timeout_ch);
1298 }
1299 }
1300}
1301#endif
1302
1303void
1304ahd_timeout(void *arg)
1305{
1306 struct scb *scb;
1307 struct ahd_softc *ahd;
1308 ahd_mode_state saved_modes;
1309 long s;
1310 int target;
1311 int lun;
1312 char channel;
1313
1314#if NOT_YET
1315 int i;
1316 int found;
1317 u_int last_phase;
1318#endif
1319
1320 scb = (struct scb *)arg;
1321 ahd = (struct ahd_softc *)scb->ahd_softc;
1322
1323 ahd_lock(ahd, &s);
1324
1325 ahd_pause_and_flushwork(ahd);
1326
1327 saved_modes = ahd_save_modes(ahd);
1328#if 0
1329 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1330 ahd_outb(ahd, SCSISIGO, ACKO);
1331 printf("set ACK\n");
1332 ahd_outb(ahd, SCSISIGO, 0);
1333 printf("clearing Ack\n");
1334 ahd_restore_modes(ahd, saved_modes);
1335#endif
1336 if ((scb->flags & SCB_ACTIVE) == 0) {
1337 /* Previous timeout took care of me already */
1338 printf("%s: Timedout SCB already complete. "
1339 "Interrupts may not be functioning.\n", ahd_name(ahd));
1340 ahd_unpause(ahd);
1341 ahd_unlock(ahd, &s);
1342 return;
1343 }
1344
1345 target = SCB_GET_TARGET(ahd, scb);
1346 channel = SCB_GET_CHANNEL(ahd, scb);
1347 lun = SCB_GET_LUN(scb);
1348
1349 ahd_print_path(ahd, scb);
1350 printf("SCB 0x%x - timed out\n", SCB_GET_TAG(scb));
1351 ahd_dump_card_state(ahd);
1352 ahd_reset_channel(ahd, SIM_CHANNEL(ahd, sim),
1353 /*initiate reset*/TRUE);
1354 ahd_unlock(ahd, &s);
1355 return;
1356#if NOT_YET
1357 last_phase = ahd_inb(ahd, LASTPHASE);
1358 if (scb->sg_count > 0) {
1359 for (i = 0; i < scb->sg_count; i++) {
1360 printf("sg[%d] - Addr 0x%x : Length %d\n",
1361 i,
1362 ((struct ahd_dma_seg *)scb->sg_list)[i].addr,
1363 ((struct ahd_dma_seg *)scb->sg_list)[i].len
1364 & AHD_SG_LEN_MASK);
1365 }
1366 }
1367 if (scb->flags & (SCB_DEVICE_RESET|SCB_ABORT)) {
1368 /*
1369 * Been down this road before.
1370 * Do a full bus reset.
1371 */
1372bus_reset:
1373 ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
1374 found = ahd_reset_channel(ahd, channel, /*Initiate Reset*/TRUE);
1375 printf("%s: Issued Channel %c Bus Reset. "
1376 "%d SCBs aborted\n", ahd_name(ahd), channel, found);
1377 } else {
1378 /*
1379 * If we are a target, transition to bus free and report
1380 * the timeout.
1381 *
1382 * The target/initiator that is holding up the bus may not
1383 * be the same as the one that triggered this timeout
1384 * (different commands have different timeout lengths).
1385 * If the bus is idle and we are actiing as the initiator
1386 * for this request, queue a BDR message to the timed out
1387 * target. Otherwise, if the timed out transaction is
1388 * active:
1389 * Initiator transaction:
1390 * Stuff the message buffer with a BDR message and assert
1391 * ATN in the hopes that the target will let go of the bus
1392 * and go to the mesgout phase. If this fails, we'll
1393 * get another timeout 2 seconds later which will attempt
1394 * a bus reset.
1395 *
1396 * Target transaction:
1397 * Transition to BUS FREE and report the error.
1398 * It's good to be the target!
1399 */
1400 u_int active_scb_index;
1401 u_int saved_scbptr;
1402
1403 saved_scbptr = ahd_get_scbptr(ahd);
1404 active_scb_index = saved_scbptr;
1405
1406 if (last_phase != P_BUSFREE
1407 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0
1408 && (active_scb_index < ahd->scb_data.numscbs)) {
1409 struct scb *active_scb;
1410
1411 /*
1412 * If the active SCB is not us, assume that
1413 * the active SCB has a longer timeout than
1414 * the timedout SCB, and wait for the active
1415 * SCB to timeout.
1416 */
1417 active_scb = ahd_lookup_scb(ahd, active_scb_index);
1418 if (active_scb != scb) {
1419 struct ccb_hdr *ccbh;
1420 uint64_t newtimeout;
1421
1422 ahd_print_path(ahd, scb);
1423 printf("Other SCB Timeout%s",
1424 (scb->flags & SCB_OTHERTCL_TIMEOUT) != 0
1425 ? " again\n" : "\n");
1426 scb->flags |= SCB_OTHERTCL_TIMEOUT;
1427 newtimeout =
1428 MAX(active_scb->io_ctx->ccb_h.timeout,
1429 scb->io_ctx->ccb_h.timeout);
1430 newtimeout *= hz;
1431 newtimeout /= 1000;
1432 ccbh = &scb->io_ctx->ccb_h;
1433 scb->io_ctx->ccb_h.timeout_ch =
1434 timeout(ahd_timeout, scb, newtimeout);
1435 ahd_unpause(ahd);
1436 ahd_unlock(ahd, &s);
1437 return;
1438 }
1439
1440 /* It's us */
1441 if ((scb->hscb->control & TARGET_SCB) != 0) {
1442
1443 /*
1444 * Send back any queued up transactions
1445 * and properly record the error condition.
1446 */
1447 ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
1448 SCB_GET_CHANNEL(ahd, scb),
1449 SCB_GET_LUN(scb),
1450 SCB_GET_TAG(scb),
1451 ROLE_TARGET,
1452 CAM_CMD_TIMEOUT);
1453
1454 /* Will clear us from the bus */
1455 ahd_restart(ahd);
1456 ahd_unlock(ahd, &s);
1457 return;
1458 }
1459
1460 ahd_set_recoveryscb(ahd, active_scb);
1461 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1462 ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
1463 ahd_print_path(ahd, active_scb);
1464 printf("BDR message in message buffer\n");
1465 active_scb->flags |= SCB_DEVICE_RESET;
1466 active_scb->io_ctx->ccb_h.timeout_ch =
1467 timeout(ahd_timeout, (caddr_t)active_scb, 2 * hz);
1468 ahd_unpause(ahd);
1469 } else {
1470 int disconnected;
1471
1472 /* XXX Shouldn't panic. Just punt instead? */
1473 if ((scb->hscb->control & TARGET_SCB) != 0)
1474 panic("Timed-out target SCB but bus idle");
1475
1476 if (last_phase != P_BUSFREE
1477 && (ahd_inb(ahd, SSTAT0) & TARGET) != 0) {
1478 /* XXX What happened to the SCB? */
1479 /* Hung target selection. Goto busfree */
1480 printf("%s: Hung target selection\n",
1481 ahd_name(ahd));
1482 ahd_restart(ahd);
1483 ahd_unlock(ahd, &s);
1484 return;
1485 }
1486
1487 if (ahd_search_qinfifo(ahd, target, channel, lun,
1488 SCB_GET_TAG(scb), ROLE_INITIATOR,
1489 /*status*/0, SEARCH_COUNT) > 0) {
1490 disconnected = FALSE;
1491 } else {
1492 disconnected = TRUE;
1493 }
1494
1495 if (disconnected) {
1496
1497 ahd_set_recoveryscb(ahd, scb);
1498 /*
1499 * Actually re-queue this SCB in an attempt
1500 * to select the device before it reconnects.
1501 * In either case (selection or reselection),
1502 * we will now issue a target reset to the
1503 * timed-out device.
1504 *
1505 * Set the MK_MESSAGE control bit indicating
1506 * that we desire to send a message. We
1507 * also set the disconnected flag since
1508 * in the paging case there is no guarantee
1509 * that our SCB control byte matches the
1510 * version on the card. We don't want the
1511 * sequencer to abort the command thinking
1512 * an unsolicited reselection occurred.
1513 */
1514 scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
1515 scb->flags |= SCB_DEVICE_RESET;
1516
1517 /*
1518 * The sequencer will never re-reference the
1519 * in-core SCB. To make sure we are notified
1520 * during reslection, set the MK_MESSAGE flag
1521 * in the card's copy of the SCB.
1522 */
1523 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
1524 ahd_outb(ahd, SCB_CONTROL,
1525 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
1526
1527 /*
1528 * Clear out any entries in the QINFIFO first
1529 * so we are the next SCB for this target
1530 * to run.
1531 */
1532 ahd_search_qinfifo(ahd,
1533 SCB_GET_TARGET(ahd, scb),
1534 channel, SCB_GET_LUN(scb),
1535 SCB_LIST_NULL,
1536 ROLE_INITIATOR,
1537 CAM_REQUEUE_REQ,
1538 SEARCH_COMPLETE);
1539 ahd_print_path(ahd, scb);
1540 printf("Queuing a BDR SCB\n");
1541 ahd_qinfifo_requeue_tail(ahd, scb);
1542 ahd_set_scbptr(ahd, saved_scbptr);
1543 scb->io_ctx->ccb_h.timeout_ch =
1544 timeout(ahd_timeout, (caddr_t)scb, 2 * hz);
1545 ahd_unpause(ahd);
1546 } else {
1547 /* Go "immediatly" to the bus reset */
1548 /* This shouldn't happen */
1549 ahd_set_recoveryscb(ahd, scb);
1550 ahd_print_path(ahd, scb);
1551 printf("SCB %d: Immediate reset. "
1552 "Flags = 0x%x\n", SCB_GET_TAG(scb),
1553 scb->flags);
1554 goto bus_reset;
1555 }
1556 }
1557 }
1558 ahd_unlock(ahd, &s);
1559#endif
1560}
1561
1562static void
1184ahd_abort_ccb(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
1185{
1186 union ccb *abort_ccb;
1187
1188 abort_ccb = ccb->cab.abort_ccb;
1189 switch (abort_ccb->ccb_h.func_code) {
1190#ifdef AHD_TARGET_MODE
1191 case XPT_ACCEPT_TARGET_IO:

--- 86 unchanged lines hidden (view full) ---

1278 error = ahd_create_path(ahd, channel, target, lun, &path);
1279
1280 if (error != CAM_REQ_CMP)
1281 return;
1282
1283 switch (code) {
1284 case AC_TRANSFER_NEG:
1285 {
1563ahd_abort_ccb(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
1564{
1565 union ccb *abort_ccb;
1566
1567 abort_ccb = ccb->cab.abort_ccb;
1568 switch (abort_ccb->ccb_h.func_code) {
1569#ifdef AHD_TARGET_MODE
1570 case XPT_ACCEPT_TARGET_IO:

--- 86 unchanged lines hidden (view full) ---

1657 error = ahd_create_path(ahd, channel, target, lun, &path);
1658
1659 if (error != CAM_REQ_CMP)
1660 return;
1661
1662 switch (code) {
1663 case AC_TRANSFER_NEG:
1664 {
1665#ifdef AHD_NEW_TRAN_SETTINGS
1286 struct ccb_trans_settings_scsi *scsi;
1287
1288 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1289 scsi = &cts.proto_specific.scsi;
1666 struct ccb_trans_settings_scsi *scsi;
1667
1668 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1669 scsi = &cts.proto_specific.scsi;
1670#else
1671 cts.flags = CCB_TRANS_CURRENT_SETTINGS;
1672#endif
1290 cts.ccb_h.path = path;
1291 cts.ccb_h.target_id = target;
1292 cts.ccb_h.target_lun = lun;
1293 ahd_get_tran_settings(ahd, ahd->our_id, channel, &cts);
1294 arg = &cts;
1673 cts.ccb_h.path = path;
1674 cts.ccb_h.target_id = target;
1675 cts.ccb_h.target_lun = lun;
1676 ahd_get_tran_settings(ahd, ahd->our_id, channel, &cts);
1677 arg = &cts;
1678#ifdef AHD_NEW_TRAN_SETTINGS
1295 scsi->valid &= ~CTS_SCSI_VALID_TQ;
1296 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1679 scsi->valid &= ~CTS_SCSI_VALID_TQ;
1680 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1681#else
1682 cts.valid &= ~CCB_TRANS_TQ_VALID;
1683 cts.flags &= ~CCB_TRANS_TAG_ENB;
1684#endif
1297 if (opt_arg == NULL)
1298 break;
1299 if (*((ahd_queue_alg *)opt_arg) == AHD_QUEUE_TAGGED)
1685 if (opt_arg == NULL)
1686 break;
1687 if (*((ahd_queue_alg *)opt_arg) == AHD_QUEUE_TAGGED)
1688#ifdef AHD_NEW_TRAN_SETTINGS
1300 scsi->flags |= ~CTS_SCSI_FLAGS_TAG_ENB;
1301 scsi->valid |= CTS_SCSI_VALID_TQ;
1689 scsi->flags |= ~CTS_SCSI_FLAGS_TAG_ENB;
1690 scsi->valid |= CTS_SCSI_VALID_TQ;
1691#else
1692 cts.flags |= CCB_TRANS_TAG_ENB;
1693 cts.valid |= CCB_TRANS_TQ_VALID;
1694#endif
1302 break;
1303 }
1304 case AC_SENT_BDR:
1305 case AC_BUS_RESET:
1306 break;
1307 default:
1308 panic("ahd_send_async: Unexpected async event");
1309 }

--- 36 unchanged lines hidden (view full) ---

1346 pdata->regs_res_id[1],
1347 pdata->regs[1]);
1348
1349 if (pdata->irq != NULL)
1350 bus_release_resource(ahd->dev_softc,
1351 pdata->irq_res_type,
1352 0, pdata->irq);
1353
1695 break;
1696 }
1697 case AC_SENT_BDR:
1698 case AC_BUS_RESET:
1699 break;
1700 default:
1701 panic("ahd_send_async: Unexpected async event");
1702 }

--- 36 unchanged lines hidden (view full) ---

1739 pdata->regs_res_id[1],
1740 pdata->regs[1]);
1741
1742 if (pdata->irq != NULL)
1743 bus_release_resource(ahd->dev_softc,
1744 pdata->irq_res_type,
1745 0, pdata->irq);
1746
1747 if (pdata->sim_b != NULL) {
1748 xpt_async(AC_LOST_DEVICE, pdata->path_b, NULL);
1749 xpt_free_path(pdata->path_b);
1750 xpt_bus_deregister(cam_sim_path(pdata->sim_b));
1751 cam_sim_free(pdata->sim_b, /*free_devq*/TRUE);
1752 }
1354 if (pdata->sim != NULL) {
1355 xpt_async(AC_LOST_DEVICE, pdata->path, NULL);
1356 xpt_free_path(pdata->path);
1357 xpt_bus_deregister(cam_sim_path(pdata->sim));
1358 cam_sim_free(pdata->sim, /*free_devq*/TRUE);
1359 }
1360 if (pdata->eh != NULL)
1361 EVENTHANDLER_DEREGISTER(shutdown_final, pdata->eh);

--- 7 unchanged lines hidden (view full) ---

1369 /* We don't sort softcs under FreeBSD so report equal always */
1370 return (0);
1371}
1372
1373int
1374ahd_detach(device_t dev)
1375{
1376 struct ahd_softc *ahd;
1753 if (pdata->sim != NULL) {
1754 xpt_async(AC_LOST_DEVICE, pdata->path, NULL);
1755 xpt_free_path(pdata->path);
1756 xpt_bus_deregister(cam_sim_path(pdata->sim));
1757 cam_sim_free(pdata->sim, /*free_devq*/TRUE);
1758 }
1759 if (pdata->eh != NULL)
1760 EVENTHANDLER_DEREGISTER(shutdown_final, pdata->eh);

--- 7 unchanged lines hidden (view full) ---

1768 /* We don't sort softcs under FreeBSD so report equal always */
1769 return (0);
1770}
1771
1772int
1773ahd_detach(device_t dev)
1774{
1775 struct ahd_softc *ahd;
1776 u_long l;
1777 u_long s;
1377
1778
1779 ahd_list_lock(&l);
1378 device_printf(dev, "detaching device\n");
1379 ahd = device_get_softc(dev);
1780 device_printf(dev, "detaching device\n");
1781 ahd = device_get_softc(dev);
1380 ahd_lock(ahd);
1381 TAILQ_REMOVE(&ahd_tailq, ahd, links);
1782 ahd = ahd_find_softc(ahd);
1783 if (ahd == NULL) {
1784 device_printf(dev, "aic7xxx already detached\n");
1785 ahd_list_unlock(&l);
1786 return (ENOENT);
1787 }
1788 ahd_lock(ahd, &s);
1382 ahd_intr_enable(ahd, FALSE);
1383 bus_teardown_intr(dev, ahd->platform_data->irq, ahd->platform_data->ih);
1789 ahd_intr_enable(ahd, FALSE);
1790 bus_teardown_intr(dev, ahd->platform_data->irq, ahd->platform_data->ih);
1384 ahd_unlock(ahd);
1791 ahd_unlock(ahd, &s);
1385 ahd_free(ahd);
1792 ahd_free(ahd);
1793 ahd_list_unlock(&l);
1386 return (0);
1387}
1388
1794 return (0);
1795}
1796
1389#if 0
1797#if UNUSED
1390static void
1391ahd_dump_targcmd(struct target_cmd *cmd)
1392{
1393 uint8_t *byte;
1394 uint8_t *last_byte;
1395 int i;
1396
1397 byte = &cmd->initiator_channel;

--- 15 unchanged lines hidden (view full) ---

1413 }
1414}
1415#endif
1416
1417static int
1418ahd_modevent(module_t mod, int type, void *data)
1419{
1420 /* XXX Deal with busy status on unload. */
1798static void
1799ahd_dump_targcmd(struct target_cmd *cmd)
1800{
1801 uint8_t *byte;
1802 uint8_t *last_byte;
1803 int i;
1804
1805 byte = &cmd->initiator_channel;

--- 15 unchanged lines hidden (view full) ---

1821 }
1822}
1823#endif
1824
1825static int
1826ahd_modevent(module_t mod, int type, void *data)
1827{
1828 /* XXX Deal with busy status on unload. */
1421 /* XXX Deal with unknown events */
1422 return 0;
1423}
1424
1425static moduledata_t ahd_mod = {
1426 "ahd",
1427 ahd_modevent,
1428 NULL
1429};
1430
1431/********************************** DDB Hooks *********************************/
1432#ifdef DDB
1433static struct ahd_softc *ahd_ddb_softc;
1434static int ahd_ddb_paused;
1435static int ahd_ddb_paused_on_entry;
1829 return 0;
1830}
1831
1832static moduledata_t ahd_mod = {
1833 "ahd",
1834 ahd_modevent,
1835 NULL
1836};
1837
1838/********************************** DDB Hooks *********************************/
1839#ifdef DDB
1840static struct ahd_softc *ahd_ddb_softc;
1841static int ahd_ddb_paused;
1842static int ahd_ddb_paused_on_entry;
1436DB_COMMAND(ahd_sunit, ahd_ddb_sunit)
1843DB_COMMAND(ahd_set_unit, ahd_ddb_set_unit)
1437{
1438 struct ahd_softc *list_ahd;
1439
1440 ahd_ddb_softc = NULL;
1441 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
1442 if (list_ahd->unit == addr)
1443 ahd_ddb_softc = list_ahd;
1444 }
1445 if (ahd_ddb_softc == NULL)
1446 db_error("No matching softc found!\n");
1447}
1448
1449DB_COMMAND(ahd_pause, ahd_ddb_pause)
1450{
1451 if (ahd_ddb_softc == NULL) {
1844{
1845 struct ahd_softc *list_ahd;
1846
1847 ahd_ddb_softc = NULL;
1848 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
1849 if (list_ahd->unit == addr)
1850 ahd_ddb_softc = list_ahd;
1851 }
1852 if (ahd_ddb_softc == NULL)
1853 db_error("No matching softc found!\n");
1854}
1855
1856DB_COMMAND(ahd_pause, ahd_ddb_pause)
1857{
1858 if (ahd_ddb_softc == NULL) {
1452 db_error("Must set unit with ahd_sunit first!\n");
1859 db_error("Must set unit with ahd_set_unit first!\n");
1453 return;
1454 }
1455 if (ahd_ddb_paused == 0) {
1456 ahd_ddb_paused++;
1457 if (ahd_is_paused(ahd_ddb_softc)) {
1458 ahd_ddb_paused_on_entry++;
1459 return;
1460 }
1461 ahd_pause(ahd_ddb_softc);
1462 }
1463}
1464
1465DB_COMMAND(ahd_unpause, ahd_ddb_unpause)
1466{
1467 if (ahd_ddb_softc == NULL) {
1860 return;
1861 }
1862 if (ahd_ddb_paused == 0) {
1863 ahd_ddb_paused++;
1864 if (ahd_is_paused(ahd_ddb_softc)) {
1865 ahd_ddb_paused_on_entry++;
1866 return;
1867 }
1868 ahd_pause(ahd_ddb_softc);
1869 }
1870}
1871
1872DB_COMMAND(ahd_unpause, ahd_ddb_unpause)
1873{
1874 if (ahd_ddb_softc == NULL) {
1468 db_error("Must set unit with ahd_sunit first!\n");
1875 db_error("Must set unit with ahd_set_unit first!\n");
1469 return;
1470 }
1471 if (ahd_ddb_paused != 0) {
1472 ahd_ddb_paused = 0;
1473 if (ahd_ddb_paused_on_entry)
1474 return;
1475 ahd_unpause(ahd_ddb_softc);
1476 } else if (ahd_ddb_paused_on_entry != 0) {

--- 4 unchanged lines hidden (view full) ---

1481}
1482
1483DB_COMMAND(ahd_in, ahd_ddb_in)
1484{
1485 int c;
1486 int size;
1487
1488 if (ahd_ddb_softc == NULL) {
1876 return;
1877 }
1878 if (ahd_ddb_paused != 0) {
1879 ahd_ddb_paused = 0;
1880 if (ahd_ddb_paused_on_entry)
1881 return;
1882 ahd_unpause(ahd_ddb_softc);
1883 } else if (ahd_ddb_paused_on_entry != 0) {

--- 4 unchanged lines hidden (view full) ---

1888}
1889
1890DB_COMMAND(ahd_in, ahd_ddb_in)
1891{
1892 int c;
1893 int size;
1894
1895 if (ahd_ddb_softc == NULL) {
1489 db_error("Must set unit with ahd_sunit first!\n");
1896 db_error("Must set unit with ahd_set_unit first!\n");
1490 return;
1491 }
1492 if (have_addr == 0)
1493 return;
1494
1495 size = 1;
1496 while ((c = *modif++) != '\0') {
1497 switch (c) {

--- 7 unchanged lines hidden (view full) ---

1505 size = 4;
1506 break;
1507 }
1508 }
1509
1510 if (count <= 0)
1511 count = 1;
1512 while (--count >= 0) {
1897 return;
1898 }
1899 if (have_addr == 0)
1900 return;
1901
1902 size = 1;
1903 while ((c = *modif++) != '\0') {
1904 switch (c) {

--- 7 unchanged lines hidden (view full) ---

1912 size = 4;
1913 break;
1914 }
1915 }
1916
1917 if (count <= 0)
1918 count = 1;
1919 while (--count >= 0) {
1513 db_printf("%04lx (M)%x: \t", (u_long)addr,
1920 db_printf("%04x (M)%x: \t", addr,
1514 ahd_inb(ahd_ddb_softc, MODE_PTR));
1515 switch (size) {
1516 case 1:
1517 db_printf("%02x\n", ahd_inb(ahd_ddb_softc, addr));
1518 break;
1519 case 2:
1520 db_printf("%04x\n", ahd_inw(ahd_ddb_softc, addr));
1521 break;
1522 case 4:
1523 db_printf("%08x\n", ahd_inl(ahd_ddb_softc, addr));
1524 break;
1525 }
1526 }
1527}
1528
1921 ahd_inb(ahd_ddb_softc, MODE_PTR));
1922 switch (size) {
1923 case 1:
1924 db_printf("%02x\n", ahd_inb(ahd_ddb_softc, addr));
1925 break;
1926 case 2:
1927 db_printf("%04x\n", ahd_inw(ahd_ddb_softc, addr));
1928 break;
1929 case 4:
1930 db_printf("%08x\n", ahd_inl(ahd_ddb_softc, addr));
1931 break;
1932 }
1933 }
1934}
1935
1529DB_FUNC(ahd_out, ahd_ddb_out, db_cmd_table, CS_MORE, NULL)
1936DB_SET(ahd_out, ahd_ddb_out, db_cmd_set, CS_MORE, NULL)
1530{
1531 db_expr_t old_value;
1532 db_expr_t new_value;
1533 int size;
1534
1535 if (ahd_ddb_softc == NULL) {
1937{
1938 db_expr_t old_value;
1939 db_expr_t new_value;
1940 int size;
1941
1942 if (ahd_ddb_softc == NULL) {
1536 db_error("Must set unit with ahd_sunit first!\n");
1943 db_error("Must set unit with ahd_set_unit first!\n");
1537 return;
1538 }
1539
1540 switch (modif[0]) {
1541 case '\0':
1542 case 'b':
1543 size = 1;
1544 break;

--- 19 unchanged lines hidden (view full) ---

1564 old_value = ahd_inw(ahd_ddb_softc, addr);
1565 ahd_outw(ahd_ddb_softc, addr, new_value);
1566 break;
1567 case 4:
1568 old_value = ahd_inl(ahd_ddb_softc, addr);
1569 ahd_outl(ahd_ddb_softc, addr, new_value);
1570 break;
1571 }
1944 return;
1945 }
1946
1947 switch (modif[0]) {
1948 case '\0':
1949 case 'b':
1950 size = 1;
1951 break;

--- 19 unchanged lines hidden (view full) ---

1971 old_value = ahd_inw(ahd_ddb_softc, addr);
1972 ahd_outw(ahd_ddb_softc, addr, new_value);
1973 break;
1974 case 4:
1975 old_value = ahd_inl(ahd_ddb_softc, addr);
1976 ahd_outl(ahd_ddb_softc, addr, new_value);
1977 break;
1978 }
1572 db_printf("%04lx (M)%x: \t0x%lx\t=\t0x%lx",
1573 (u_long)addr, ahd_inb(ahd_ddb_softc, MODE_PTR),
1574 (u_long)old_value, (u_long)new_value);
1979 db_printf("%04x (M)%x: \t0x%x\t=\t0x%x",
1980 addr, ahd_inb(ahd_ddb_softc, MODE_PTR),
1981 old_value, new_value);
1575 addr += size;
1576 }
1577 db_skip_to_eol();
1578}
1579
1982 addr += size;
1983 }
1984 db_skip_to_eol();
1985}
1986
1580DB_COMMAND(ahd_dump, ahd_ddb_dump)
1581{
1582 if (ahd_ddb_softc == NULL) {
1583 db_error("Must set unit with ahd_sunit first!\n");
1584 return;
1585 }
1586 ahd_dump_card_state(ahd_ddb_softc);
1587}
1588
1589#endif
1590
1591
1592DECLARE_MODULE(ahd, ahd_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1593MODULE_DEPEND(ahd, cam, 1, 1, 1);
1594MODULE_VERSION(ahd, 1);
1987#endif
1988
1989
1990DECLARE_MODULE(ahd, ahd_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1991MODULE_DEPEND(ahd, cam, 1, 1, 1);
1992MODULE_VERSION(ahd, 1);