Subject: scsipi changes
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-kern
Date: 07/13/2001 23:15:51
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Hi,
I'd like to add 2 functions to the scispi code:
- scsipi_target_detach(), which will detach all periphs for this target
This can be used after a seltimeout or after some fiber channel event
(Matthew can tell more about this one:), if we know that the
device is no longer here.
- a mechanism to allow a callback to be called from the channel's thread
context. This may be used for example by the adapter if it needs a thread
context to perform some tasks (busy wait, or call scsipi_target_detach()
for example).
Diffs attached. Below is what I would add to scsipi(9)
Unless anyone object I'll commit this quickly (in 3 or 4 days), as I need
this for other works (and I know Matthew needs it too).
int
scsipi_target_detach(struct scsipi_channel *chan, int target, int flags)
detach the periph associated with this I_T nexus. All accociated devices will
be removed from the device tree. flags is passed to config_detach().
Returns 0 if successfull, or error code if a device couldn't be removed.
int
scsipi_thread_call_callback(struct scsipi_channel *chan,
void (*callback) __P((struct scsipi_channel *, void *)),
void *arg)
The specified callback will be called with chan and arg as arguments, from
the channel completion thread. The callback is run at splbio.
scsipi_thread_call_callback() will freeze the channel by one, it's up
to the caller to thaw it when appropriate.
scsipi_thread_call_callback returns 0 if the callback was properly recorded,
or EBUSY if the channel has already a callback pending.
--
Manuel Bouyer <bouyer@antioche.eu.org>
--
--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff
Index: scsiconf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsiconf.c,v
retrieving revision 1.158
diff -u -r1.158 scsiconf.c
--- scsiconf.c 2001/06/11 13:58:18 1.158
+++ scsiconf.c 2001/07/13 21:14:38
@@ -257,8 +257,7 @@
{
struct scsibus_softc *sc = (void *) self;
struct scsipi_channel *chan = sc->sc_channel;
- struct scsipi_periph *periph;
- int target, lun, error;
+ int target, error;
/*
* Shut down the channel.
@@ -271,16 +270,9 @@
for (target = 0; target < chan->chan_ntargets; target++) {
if (target == chan->chan_id)
continue;
- for (lun = 0; lun < chan->chan_nluns; lun++) {
- periph = scsipi_lookup_periph(chan, target, lun);
- if (periph == NULL)
- continue;
- error = config_detach(periph->periph_dev, flags);
- if (error)
- return (error);
- scsipi_remove_periph(chan, periph);
- free(periph, M_DEVBUF);
- }
+ error = scsipi_target_detach(chan, target, flags);
+ if (error)
+ return (error);
}
return (0);
}
Index: scsipi_base.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsipi_base.c,v
retrieving revision 1.49
diff -u -r1.49 scsipi_base.c
--- scsipi_base.c 2001/07/13 20:00:23 1.49
+++ scsipi_base.c 2001/07/13 21:14:42
@@ -1947,29 +1947,41 @@
s = splbio();
xs = TAILQ_FIRST(&chan->chan_complete);
if (xs == NULL &&
- (chan->chan_flags & SCSIPI_CHAN_SHUTDOWN) == 0) {
+ (chan->chan_flags &
+ (SCSIPI_CHAN_SHUTDOWN | SCSIPI_CHAN_CALLBACK)) == 0) {
(void) tsleep(&chan->chan_complete, PRIBIO,
"sccomp", 0);
splx(s);
continue;
}
+ if (chan->chan_flags & SCSIPI_CHAN_CALLBACK) {
+ /* call chan_callback from thread context */
+ chan->chan_flags &= ~SCSIPI_CHAN_CALLBACK;
+ chan->chan_callback(chan, chan->chan_callback_arg);
+ splx(s);
+ continue;
+ }
if (chan->chan_flags & SCSIPI_CHAN_SHUTDOWN) {
splx(s);
break;
}
- TAILQ_REMOVE(&chan->chan_complete, xs, channel_q);
- splx(s);
-
- /*
- * Have an xfer with an error; process it.
- */
- (void) scsipi_complete(xs);
+ if (xs) {
+ TAILQ_REMOVE(&chan->chan_complete, xs, channel_q);
+ splx(s);
- /*
- * Kick the queue; keep it running if it was stopped
- * for some reason.
- */
- scsipi_run_queue(chan);
+ /*
+ * Have an xfer with an error; process it.
+ */
+ (void) scsipi_complete(xs);
+
+ /*
+ * Kick the queue; keep it running if it was stopped
+ * for some reason.
+ */
+ scsipi_run_queue(chan);
+ } else {
+ splx(s);
+ }
}
chan->chan_thread = NULL;
@@ -2003,6 +2015,33 @@
}
/*
+ * scsipi_thread_call_callback:
+ *
+ * request to call a callback from the completion thread
+ */
+int
+scsipi_thread_call_callback(chan, callback, arg)
+ struct scsipi_channel *chan;
+ void (*callback) __P((struct scsipi_channel *, void *));
+ void *arg;
+{
+ int s;
+
+ s = splbio();
+ if (chan->chan_flags & SCSIPI_CHAN_CALLBACK) {
+ splx(s);
+ return EBUSY;
+ }
+ scsipi_channel_freeze(chan, 1);
+ chan->chan_callback = callback;
+ chan->chan_callback_arg = arg;
+ chan->chan_flags |= SCSIPI_CHAN_CALLBACK;
+ wakeup(&chan->chan_complete);
+ splx(s);
+ return(0);
+}
+
+/*
* scsipi_async_event:
*
* Handle an asynchronous event from an adapter.
@@ -2271,6 +2310,36 @@
}
}
+/*
+ * scsipi_target_detach:
+ *
+ * detach all periph associated with a I_T
+ * must be called from valid thread context
+ */
+int
+scsipi_target_detach(chan, target, flags)
+ struct scsipi_channel *chan;
+ int target;
+ int flags;
+{
+ struct scsipi_periph *periph;
+ int lun, error;
+
+ if (target == chan->chan_id)
+ return EINVAL;
+
+ for (lun = 0; lun < chan->chan_nluns; lun++) {
+ periph = scsipi_lookup_periph(chan, target, lun);
+ if (periph == NULL)
+ continue;
+ error = config_detach(periph->periph_dev, flags);
+ if (error)
+ return (error);
+ scsipi_remove_periph(chan, periph);
+ free(periph, M_DEVBUF);
+ }
+ return(0);
+}
/*
* scsipi_adapter_addref:
Index: scsipiconf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsipiconf.h,v
retrieving revision 1.54
diff -u -r1.54 scsipiconf.h
--- scsipiconf.h 2001/06/26 15:32:02 1.54
+++ scsipiconf.h 2001/07/13 21:14:44
@@ -293,6 +293,10 @@
/* Completed (async) jobs. */
struct scsipi_xfer_queue chan_complete;
+
+ /* callback we may have to call from completion thread */
+ void (*chan_callback) __P((struct scsipi_channel *, void *));
+ void *chan_callback_arg;
};
/* chan_flags */
@@ -300,6 +304,7 @@
#define SCSIPI_CHAN_OPENINGS 0x02 /* use chan_openings */
#define SCSIPI_CHAN_CANGROW 0x04 /* channel can grow resources */
#define SCSIPI_CHAN_NOSETTLE 0x08 /* don't wait for devices to settle */
+#define SCSIPI_CHAN_CALLBACK 0x10 /* has to call chan_callback() */
#define SCSIPI_CHAN_MAX_PERIPH(chan) \
(((chan)->chan_flags & SCSIPI_CHAN_OPENINGS) ? \
@@ -641,6 +646,9 @@
void scsipi_print_sense_data __P((struct scsipi_sense_data *, int));
char *scsipi_decode_sense __P((void *, int));
#endif
+int scsipi_thread_call_callback __P((struct scsipi_channel *,
+ void (*callback) __P((struct scsipi_channel *, void *)),
+ void *));
void scsipi_async_event __P((struct scsipi_channel *,
scsipi_async_event_t, void *));
int scsipi_do_ioctl __P((struct scsipi_periph *, dev_t, u_long, caddr_t,
@@ -658,6 +666,7 @@
struct scsipi_periph *));
struct scsipi_periph *scsipi_lookup_periph __P((struct scsipi_channel *,
int, int));
+int scsipi_target_detach __P((struct scsipi_channel *, int, int));
int scsipi_adapter_addref __P((struct scsipi_adapter *));
void scsipi_adapter_delref __P((struct scsipi_adapter *));
--YZ5djTAD1cGYuMQK--