Sun May 23 08:42:32 2021 UTC ()
umass(4): Use an empty function callback, not null pointer.

This stupid bug, with an `XXX Broken!' comment right above, has been
preventing NetBSD from suspend/resume with a USB drive plugged in for
longer than I want to even think about admitting.  *sigh*


(riastradh)
diff -r1.67 -r1.68 src/sys/dev/usb/umass_scsipi.c

cvs diff -r1.67 -r1.68 src/sys/dev/usb/umass_scsipi.c (expand / switch to unified diff)

--- src/sys/dev/usb/umass_scsipi.c 2021/04/24 23:36:59 1.67
+++ src/sys/dev/usb/umass_scsipi.c 2021/05/23 08:42:32 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $ */ 1/* $NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology, Charles M. Hamnnum and Matthew R. Green. 9 * Carlstedt Research & Technology, Charles M. Hamnnum and Matthew R. Green.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_usb.h" 37#include "opt_usb.h"
38#endif 38#endif
39 39
40#include "atapibus.h" 40#include "atapibus.h"
41#include "scsibus.h" 41#include "scsibus.h"
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/buf.h> 44#include <sys/buf.h>
45#include <sys/bufq.h> 45#include <sys/bufq.h>
46#include <sys/conf.h> 46#include <sys/conf.h>
47#include <sys/device.h> 47#include <sys/device.h>
@@ -91,26 +91,28 @@ struct umass_scsipi_softc { @@ -91,26 +91,28 @@ struct umass_scsipi_softc {
91 91
92#define SHORT_INQUIRY_LENGTH 36 /* XXX */ 92#define SHORT_INQUIRY_LENGTH 36 /* XXX */
93 93
94#define UMASS_ATAPI_DRIVE 0 94#define UMASS_ATAPI_DRIVE 0
95 95
96Static void umass_scsipi_request(struct scsipi_channel *, 96Static void umass_scsipi_request(struct scsipi_channel *,
97 scsipi_adapter_req_t, void *); 97 scsipi_adapter_req_t, void *);
98Static void umass_scsipi_minphys(struct buf *); 98Static void umass_scsipi_minphys(struct buf *);
99Static int umass_scsipi_ioctl(struct scsipi_channel *, u_long, 99Static int umass_scsipi_ioctl(struct scsipi_channel *, u_long,
100 void *, int, proc_t *); 100 void *, int, proc_t *);
101Static int umass_scsipi_getgeom(struct scsipi_periph *, 101Static int umass_scsipi_getgeom(struct scsipi_periph *,
102 struct disk_parms *, u_long); 102 struct disk_parms *, u_long);
103 103
 104Static void umass_null_cb(struct umass_softc *, void *,
 105 int, int);
104Static void umass_scsipi_cb(struct umass_softc *, void *, 106Static void umass_scsipi_cb(struct umass_softc *, void *,
105 int, int); 107 int, int);
106Static void umass_scsipi_sense_cb(struct umass_softc *, void *, 108Static void umass_scsipi_sense_cb(struct umass_softc *, void *,
107 int, int); 109 int, int);
108 110
109Static struct umass_scsipi_softc *umass_scsipi_setup(struct umass_softc *); 111Static struct umass_scsipi_softc *umass_scsipi_setup(struct umass_softc *);
110 112
111#if NATAPIBUS > 0 113#if NATAPIBUS > 0
112Static void umass_atapi_probe_device(struct atapibus_softc *, int); 114Static void umass_atapi_probe_device(struct atapibus_softc *, int);
113 115
114const struct scsipi_bustype umass_atapi_bustype = { 116const struct scsipi_bustype umass_atapi_bustype = {
115 .bustype_type = SCSIPI_BUSTYPE_ATAPI, 117 .bustype_type = SCSIPI_BUSTYPE_ATAPI,
116 .bustype_cmd = atapi_scsipi_cmd, 118 .bustype_cmd = atapi_scsipi_cmd,
@@ -311,27 +313,27 @@ umass_scsipi_request(struct scsipi_chann @@ -311,27 +313,27 @@ umass_scsipi_request(struct scsipi_chann
311 printf("umass_cmd: large datalen, %d\n", xs->datalen); 313 printf("umass_cmd: large datalen, %d\n", xs->datalen);
312 xs->error = XS_DRIVER_STUFFUP; 314 xs->error = XS_DRIVER_STUFFUP;
313 goto done; 315 goto done;
314 } 316 }
315 317
316 if (xs->xs_control & XS_CTL_POLL) { 318 if (xs->xs_control & XS_CTL_POLL) {
317 /* Use sync transfer. XXX Broken! */ 319 /* Use sync transfer. XXX Broken! */
318 DPRINTFM(UDMASS_SCSI, "sync dir=%jd\n", dir, 0, 0, 0); 320 DPRINTFM(UDMASS_SCSI, "sync dir=%jd\n", dir, 0, 0, 0);
319 scbus->sc_sync_status = USBD_INVAL; 321 scbus->sc_sync_status = USBD_INVAL;
320 sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd, 322 sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd,
321 cmdlen, xs->data, 323 cmdlen, xs->data,
322 xs->datalen, dir, 324 xs->datalen, dir,
323 xs->timeout, USBD_SYNCHRONOUS, 325 xs->timeout, USBD_SYNCHRONOUS,
324 0, xs); 326 umass_null_cb, xs);
325 DPRINTFM(UDMASS_SCSI, "done err=%jd", 327 DPRINTFM(UDMASS_SCSI, "done err=%jd",
326 scbus->sc_sync_status, 0, 0, 0); 328 scbus->sc_sync_status, 0, 0, 0);
327 switch (scbus->sc_sync_status) { 329 switch (scbus->sc_sync_status) {
328 case USBD_NORMAL_COMPLETION: 330 case USBD_NORMAL_COMPLETION:
329 xs->error = XS_NOERROR; 331 xs->error = XS_NOERROR;
330 break; 332 break;
331 case USBD_TIMEOUT: 333 case USBD_TIMEOUT:
332 xs->error = XS_TIMEOUT; 334 xs->error = XS_TIMEOUT;
333 break; 335 break;
334 default: 336 default:
335 xs->error = XS_DRIVER_STUFFUP; 337 xs->error = XS_DRIVER_STUFFUP;
336 break; 338 break;
337 } 339 }
@@ -411,26 +413,32 @@ umass_scsipi_getgeom(struct scsipi_perip @@ -411,26 +413,32 @@ umass_scsipi_getgeom(struct scsipi_perip
411 return 1; 413 return 1;
412 case 2880: 414 case 2880:
413 /* Most likely a double density 3.5" floppy. */ 415 /* Most likely a double density 3.5" floppy. */
414 dp->heads = 2; 416 dp->heads = 2;
415 dp->sectors = 18; 417 dp->sectors = 18;
416 dp->cyls = 80; 418 dp->cyls = 80;
417 return 1; 419 return 1;
418 default: 420 default:
419 return 0; 421 return 0;
420 } 422 }
421} 423}
422 424
423Static void 425Static void
 426umass_null_cb(struct umass_softc *sc, void *priv, int residue, int status)
 427{
 428 UMASSHIST_FUNC(); UMASSHIST_CALLED();
 429}
 430
 431Static void
424umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status) 432umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status)
425{ 433{
426 UMASSHIST_FUNC(); UMASSHIST_CALLED(); 434 UMASSHIST_FUNC(); UMASSHIST_CALLED();
427 struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus; 435 struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus;
428 struct scsipi_xfer *xs = priv; 436 struct scsipi_xfer *xs = priv;
429 struct scsipi_periph *periph = xs->xs_periph; 437 struct scsipi_periph *periph = xs->xs_periph;
430 int cmdlen, senselen; 438 int cmdlen, senselen;
431#ifdef UMASS_DEBUG 439#ifdef UMASS_DEBUG
432 struct timeval tv; 440 struct timeval tv;
433 u_int delta; 441 u_int delta;
434 microtime(&tv); 442 microtime(&tv);
435 delta = (tv.tv_sec - sc->tv.tv_sec) * 1000000 + tv.tv_usec - sc->tv.tv_usec; 443 delta = (tv.tv_sec - sc->tv.tv_sec) * 1000000 + tv.tv_usec - sc->tv.tv_usec;
436 DPRINTFM(UDMASS_CMD, "delta=%ju: xs=%#jx residue=%jd status=%jd", 444 DPRINTFM(UDMASS_CMD, "delta=%ju: xs=%#jx residue=%jd status=%jd",