2005-01-05 22:34:37 +00:00
|
|
|
/*-
|
1998-09-15 06:33:23 +00:00
|
|
|
* Data structures and definitions for CAM peripheral ("type") drivers.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997, 1998 Justin T. Gibbs.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-09-15 06:33:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CAM_CAM_PERIPH_H
|
|
|
|
#define _CAM_CAM_PERIPH_H 1
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
1999-12-29 05:07:58 +00:00
|
|
|
#ifdef _KERNEL
|
1998-09-15 06:33:23 +00:00
|
|
|
|
2003-03-08 08:01:31 +00:00
|
|
|
struct devstat;
|
|
|
|
|
2000-05-07 18:04:50 +00:00
|
|
|
extern struct cam_periph *xpt_periph;
|
2000-04-03 11:11:12 +00:00
|
|
|
|
2001-02-07 07:05:59 +00:00
|
|
|
extern struct periph_driver **periph_drivers;
|
|
|
|
void periphdriver_register(void *);
|
|
|
|
|
|
|
|
#include <sys/module.h>
|
|
|
|
#define PERIPHDRIVER_DECLARE(name, driver) \
|
|
|
|
static int name ## _modevent(module_t mod, int type, void *data) \
|
|
|
|
{ \
|
|
|
|
switch (type) { \
|
|
|
|
case MOD_LOAD: \
|
|
|
|
periphdriver_register(data); \
|
|
|
|
break; \
|
|
|
|
case MOD_UNLOAD: \
|
|
|
|
printf(#name " module unload - not possible for this module type\n"); \
|
|
|
|
return EINVAL; \
|
2004-07-15 08:26:07 +00:00
|
|
|
default: \
|
|
|
|
return EOPNOTSUPP; \
|
2001-02-07 07:05:59 +00:00
|
|
|
} \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
static moduledata_t name ## _mod = { \
|
|
|
|
#name, \
|
|
|
|
name ## _modevent, \
|
|
|
|
(void *)&driver \
|
|
|
|
}; \
|
|
|
|
DECLARE_MODULE(name, name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); \
|
|
|
|
MODULE_DEPEND(name, cam, 1, 1, 1)
|
1998-09-15 06:33:23 +00:00
|
|
|
|
|
|
|
typedef void (periph_init_t)(void); /*
|
|
|
|
* Callback informing the peripheral driver
|
|
|
|
* it can perform it's initialization since
|
|
|
|
* the XPT is now fully initialized.
|
|
|
|
*/
|
|
|
|
typedef periph_init_t *periph_init_func_t;
|
|
|
|
|
|
|
|
struct periph_driver {
|
|
|
|
periph_init_func_t init;
|
|
|
|
char *driver_name;
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(,cam_periph) units;
|
1998-09-15 06:33:23 +00:00
|
|
|
u_int generation;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
2004-10-05 04:22:20 +00:00
|
|
|
CAM_PERIPH_BIO
|
1998-09-15 06:33:23 +00:00
|
|
|
} cam_periph_type;
|
|
|
|
|
|
|
|
/* Generically usefull offsets into the peripheral private area */
|
|
|
|
#define ppriv_ptr0 periph_priv.entries[0].ptr
|
|
|
|
#define ppriv_ptr1 periph_priv.entries[1].ptr
|
|
|
|
#define ppriv_field0 periph_priv.entries[0].field
|
|
|
|
#define ppriv_field1 periph_priv.entries[1].field
|
|
|
|
|
|
|
|
typedef void periph_start_t (struct cam_periph *periph,
|
|
|
|
union ccb *start_ccb);
|
|
|
|
typedef cam_status periph_ctor_t (struct cam_periph *periph,
|
|
|
|
void *arg);
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
typedef void periph_oninv_t (struct cam_periph *periph);
|
1998-09-15 06:33:23 +00:00
|
|
|
typedef void periph_dtor_t (struct cam_periph *periph);
|
|
|
|
struct cam_periph {
|
|
|
|
cam_pinfo pinfo;
|
|
|
|
periph_start_t *periph_start;
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
periph_oninv_t *periph_oninval;
|
1998-09-15 06:33:23 +00:00
|
|
|
periph_dtor_t *periph_dtor;
|
|
|
|
char *periph_name;
|
|
|
|
struct cam_path *path; /* Compiled path to device */
|
|
|
|
void *softc;
|
|
|
|
u_int32_t unit_number;
|
|
|
|
cam_periph_type type;
|
|
|
|
u_int32_t flags;
|
|
|
|
#define CAM_PERIPH_RUNNING 0x01
|
|
|
|
#define CAM_PERIPH_LOCKED 0x02
|
|
|
|
#define CAM_PERIPH_LOCK_WANTED 0x04
|
|
|
|
#define CAM_PERIPH_INVALID 0x08
|
|
|
|
#define CAM_PERIPH_NEW_DEV_FOUND 0x10
|
Fix a bug in the error recovery code. It was possible to have more than
one error recovery action oustanding for a given peripheral.
This is bad for several reasons. The first problem is that the error
recovery actions would likely be to fix the same problem. (e.g., we
queue 5 CCBs to a disk, and the first one comes back with 0x04,0x02. We
start error recovery, and the second one comes back with the same status.
Then the third one comes back, and so on. Each one causes the drive to get
nailed with a start unit, when we really only need one.)
The other problem is that we only have space to store one CCB while we're
doing error recovery. The subsequent error recovery actions that got
started were over-writing the CCBs from previous error recovery actions,
but we still tried to call the done routine N times for N error recovery
actions. Each call to dadone() was done with the same CCB, though. So on
the second one, we got a "biodone: buffer not busy" panic, since the buffer
in question had already been through biodone().
In any case, this fixes things so that any any given time, there's only one
error recovery action outstanding for any given peripheral driver.
Reviewed by: gibbs
Reported by: Philippe Regnauld <regnauld@deepo.prosa.dk>
[ Philippe wins the "bug finder of the week" award ]
1998-10-13 21:41:32 +00:00
|
|
|
#define CAM_PERIPH_RECOVERY_INPROG 0x20
|
1998-09-15 06:33:23 +00:00
|
|
|
u_int32_t immediate_priority;
|
|
|
|
u_int32_t refcount;
|
2000-05-26 02:09:24 +00:00
|
|
|
SLIST_HEAD(, ccb_hdr) ccb_list; /* For "immediate" requests */
|
|
|
|
SLIST_ENTRY(cam_periph) periph_links;
|
|
|
|
TAILQ_ENTRY(cam_periph) unit_links;
|
1998-09-15 06:33:23 +00:00
|
|
|
ac_callback_t *deferred_callback;
|
|
|
|
ac_code deferred_ac;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CAM_PERIPH_MAXMAPS 2
|
|
|
|
|
|
|
|
struct cam_periph_map_info {
|
|
|
|
int num_bufs_used;
|
|
|
|
struct buf *bp[CAM_PERIPH_MAXMAPS];
|
|
|
|
};
|
|
|
|
|
Fix a problem with the way we handled device invalidation when attaching
to a device failed.
In theory, the same steps that happen when we get an AC_LOST_DEVICE async
notification should have been taken when a driver fails to attach. In
practice, that wasn't the case.
This only affected the da, cd and ch drivers, but the fix affects all
peripheral drivers.
There were several possible problems:
- In the da driver, we didn't remove the peripheral's softc from the da
driver's linked list of softcs. Once the peripheral and softc got
removed, we'd get a kernel panic the next time the timeout routine
called dasendorderedtag().
- In the da, cd and possibly ch drivers, we didn't remove the
peripheral's devstat structure from the devstat queue. Once the
peripheral and softc were removed, this could cause a panic if anyone
tried to access device statistics. (one component of the linked list
wouldn't exist anymore)
- In the cd driver, we didn't take the peripheral off the changer run
queue if it was scheduled to run. In practice, it's highly unlikely,
and maybe impossible that the peripheral would have been on the
changer run queue at that stage of the probe process.
The fix is:
- Add a new peripheral callback function (the "oninvalidate" function)
that is called the first time cam_periph_invalidate() is called for a
peripheral.
- Create new foooninvalidate() routines for each peripheral driver. This
routine is always called at splsoftcam(), and contains all the stuff
that used to be in the AC_LOST_DEVICE case of the async callback
handler.
- Move the devstat cleanup call to the destructor/cleanup routines, since
some of the drivers do I/O in their close routines.
- Make sure that when we're flushing the buffer queue, we traverse it at
splbio().
- Add a check for the invalid flag in the pt driver's open routine.
Reviewed by: gibbs
1998-10-22 22:16:56 +00:00
|
|
|
cam_status cam_periph_alloc(periph_ctor_t *periph_ctor,
|
|
|
|
periph_oninv_t *periph_oninvalidate,
|
|
|
|
periph_dtor_t *periph_dtor,
|
|
|
|
periph_start_t *periph_start,
|
2000-03-15 21:55:48 +00:00
|
|
|
char *name, cam_periph_type type, struct cam_path *,
|
|
|
|
ac_callback_t *, ac_code, void *arg);
|
1998-09-15 06:33:23 +00:00
|
|
|
struct cam_periph *cam_periph_find(struct cam_path *path, char *name);
|
|
|
|
int cam_periph_lock(struct cam_periph *periph, int priority);
|
|
|
|
void cam_periph_unlock(struct cam_periph *periph);
|
|
|
|
cam_status cam_periph_acquire(struct cam_periph *periph);
|
|
|
|
void cam_periph_release(struct cam_periph *periph);
|
|
|
|
void cam_periph_invalidate(struct cam_periph *periph);
|
|
|
|
int cam_periph_mapmem(union ccb *ccb,
|
|
|
|
struct cam_periph_map_info *mapinfo);
|
|
|
|
void cam_periph_unmapmem(union ccb *ccb,
|
|
|
|
struct cam_periph_map_info *mapinfo);
|
|
|
|
union ccb *cam_periph_getccb(struct cam_periph *periph,
|
|
|
|
u_int32_t priority);
|
|
|
|
void cam_periph_ccbwait(union ccb *ccb);
|
|
|
|
int cam_periph_runccb(union ccb *ccb,
|
|
|
|
int (*error_routine)(union ccb *ccb,
|
|
|
|
cam_flags camflags,
|
|
|
|
u_int32_t sense_flags),
|
|
|
|
cam_flags camflags, u_int32_t sense_flags,
|
|
|
|
struct devstat *ds);
|
|
|
|
int cam_periph_ioctl(struct cam_periph *periph, int cmd,
|
|
|
|
caddr_t addr,
|
|
|
|
int (*error_routine)(union ccb *ccb,
|
|
|
|
cam_flags camflags,
|
|
|
|
u_int32_t sense_flags));
|
1999-05-22 21:58:47 +00:00
|
|
|
void cam_freeze_devq(struct cam_path *path);
|
1998-09-15 06:33:23 +00:00
|
|
|
u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags,
|
|
|
|
u_int32_t opening_reduction, u_int32_t timeout,
|
|
|
|
int getcount_only);
|
1999-05-22 21:58:47 +00:00
|
|
|
void cam_periph_async(struct cam_periph *periph, u_int32_t code,
|
|
|
|
struct cam_path *path, void *arg);
|
|
|
|
void cam_periph_bus_settle(struct cam_periph *periph,
|
|
|
|
u_int bus_settle_ms);
|
|
|
|
void cam_periph_freeze_after_event(struct cam_periph *periph,
|
|
|
|
struct timeval* event_time,
|
|
|
|
u_int duration_ms);
|
1998-09-15 06:33:23 +00:00
|
|
|
int cam_periph_error(union ccb *ccb, cam_flags camflags,
|
|
|
|
u_int32_t sense_flags, union ccb *save_ccb);
|
|
|
|
|
1999-12-29 05:07:58 +00:00
|
|
|
#endif /* _KERNEL */
|
1998-09-15 06:33:23 +00:00
|
|
|
#endif /* _CAM_CAM_PERIPH_H */
|