Sat Aug 12 14:41:54 2017 UTC ()
convert the atabus thread to use the channel lock and a condvar, adjust
code which sets the relevant channel flags to take the lock while doing so


(jdolecek)
diff -r1.1.2.33 -r1.1.2.34 src/sys/dev/ata/TODO.ncq
diff -r1.132.8.25 -r1.132.8.26 src/sys/dev/ata/ata.c
diff -r1.105.6.7 -r1.105.6.8 src/sys/dev/ata/ata_wdc.c
diff -r1.92.8.22 -r1.92.8.23 src/sys/dev/ata/atavar.h
diff -r1.35.6.20 -r1.35.6.21 src/sys/dev/ic/mvsata.c
diff -r1.283.2.12 -r1.283.2.13 src/sys/dev/ic/wdc.c
diff -r1.123.4.11 -r1.123.4.12 src/sys/dev/scsipi/atapi_wdc.c

cvs diff -r1.1.2.33 -r1.1.2.34 src/sys/dev/ata/Attic/TODO.ncq (expand / switch to unified diff)

--- src/sys/dev/ata/Attic/TODO.ncq 2017/08/12 09:52:28 1.1.2.33
+++ src/sys/dev/ata/Attic/TODO.ncq 2017/08/12 14:41:54 1.1.2.34
@@ -5,28 +5,26 @@ siisata - fix all new XXX and unmergable @@ -5,28 +5,26 @@ siisata - fix all new XXX and unmergable
5 5
6test wd* at umass?, confirm the ata_channel kludge works 6test wd* at umass?, confirm the ata_channel kludge works
7 7
8do proper NCQ error recovery 8do proper NCQ error recovery
9- update mvsata to do same as ahcisata/siisata (read log ext, timeouts, et.al) 9- update mvsata to do same as ahcisata/siisata (read log ext, timeouts, et.al)
10 10
11do biodone() in wddone() starting the dump to not leak bufs when dumping from 11do biodone() in wddone() starting the dump to not leak bufs when dumping from
12active system? make sure to not trigger atastart() 12active system? make sure to not trigger atastart()
13- call ata_kill_active() + ata_kill_pending() when dumping 13- call ata_kill_active() + ata_kill_pending() when dumping
14 14
15kill active transfers after software drive reset - race timeout vs. 15kill active transfers after software drive reset - race timeout vs.
16error recovery 16error recovery
17 17
18atabus_thread() protect run by mutex/condvar 
19 
20Other random notes (do outside the NCQ branch): 18Other random notes (do outside the NCQ branch):
21----------------------------------------------------- 19-----------------------------------------------------
22implement support for PM FIS-based switching, remove restriction in atastart() 20implement support for PM FIS-based switching, remove restriction in atastart()
23for hw which supports it, adjust error handling in controller drivers to handle 21for hw which supports it, adjust error handling in controller drivers to handle
24xfers for several different drives 22xfers for several different drives
25 23
26maybe do device error handling in not-interrupt-context (maybe this should be 24maybe do device error handling in not-interrupt-context (maybe this should be
27done on a mpata branch?) 25done on a mpata branch?)
28 26
29queue is allocated regardless if there are any drives, fix?  27queue is allocated regardless if there are any drives, fix?
30 28
31change wd(4) to use dksubr 29change wd(4) to use dksubr
32 30

cvs diff -r1.132.8.25 -r1.132.8.26 src/sys/dev/ata/ata.c (expand / switch to unified diff)

--- src/sys/dev/ata/ata.c 2017/08/12 09:52:28 1.132.8.25
+++ src/sys/dev/ata/ata.c 2017/08/12 14:41:54 1.132.8.26
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1/* $NetBSD: ata.c,v 1.132.8.25 2017/08/12 09:52:28 jdolecek Exp $ */ 1/* $NetBSD: ata.c,v 1.132.8.26 2017/08/12 14:41:54 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. 4 * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.25 2017/08/12 09:52:28 jdolecek Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.26 2017/08/12 14:41:54 jdolecek Exp $");
29 29
30#include "opt_ata.h" 30#include "opt_ata.h"
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/kernel.h> 34#include <sys/kernel.h>
35#include <sys/malloc.h> 35#include <sys/malloc.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/conf.h> 37#include <sys/conf.h>
38#include <sys/fcntl.h> 38#include <sys/fcntl.h>
39#include <sys/proc.h> 39#include <sys/proc.h>
40#include <sys/kthread.h> 40#include <sys/kthread.h>
41#include <sys/errno.h> 41#include <sys/errno.h>
@@ -121,27 +121,27 @@ const struct cdevsw atabus_cdevsw = { @@ -121,27 +121,27 @@ const struct cdevsw atabus_cdevsw = {
121 .d_flag = D_OTHER 121 .d_flag = D_OTHER
122}; 122};
123 123
124extern struct cfdriver atabus_cd; 124extern struct cfdriver atabus_cd;
125 125
126static void atabus_childdetached(device_t, device_t); 126static void atabus_childdetached(device_t, device_t);
127static int atabus_rescan(device_t, const char *, const int *); 127static int atabus_rescan(device_t, const char *, const int *);
128static bool atabus_resume(device_t, const pmf_qual_t *); 128static bool atabus_resume(device_t, const pmf_qual_t *);
129static bool atabus_suspend(device_t, const pmf_qual_t *); 129static bool atabus_suspend(device_t, const pmf_qual_t *);
130static void atabusconfig_thread(void *); 130static void atabusconfig_thread(void *);
131 131
132static void ata_channel_idle(struct ata_channel *); 132static void ata_channel_idle(struct ata_channel *);
133static void ata_activate_xfer_locked(struct ata_channel *, struct ata_xfer *); 133static void ata_activate_xfer_locked(struct ata_channel *, struct ata_xfer *);
134 134static void ata_channel_freeze_locked(struct ata_channel *);
135/* 135/*
136 * atabus_init: 136 * atabus_init:
137 * 137 *
138 * Initialize ATA subsystem structures. 138 * Initialize ATA subsystem structures.
139 */ 139 */
140static int 140static int
141atabus_init(void) 141atabus_init(void)
142{ 142{
143 143
144 TAILQ_INIT(&atabus_initq_head); 144 TAILQ_INIT(&atabus_initq_head);
145 mutex_init(&atabus_qlock, MUTEX_DEFAULT, IPL_NONE); 145 mutex_init(&atabus_qlock, MUTEX_DEFAULT, IPL_NONE);
146 cv_init(&atabus_qcv, "atainitq"); 146 cv_init(&atabus_qcv, "atainitq");
147 return 0; 147 return 0;
@@ -312,131 +312,139 @@ ata_queue_free(struct ata_queue *chq) @@ -312,131 +312,139 @@ ata_queue_free(struct ata_queue *chq)
312 for (uint8_t i = 0; i < chq->queue_openings; i++) 312 for (uint8_t i = 0; i < chq->queue_openings; i++)
313 ata_xfer_destroy(&chq->queue_xfers[i]); 313 ata_xfer_destroy(&chq->queue_xfers[i]);
314 314
315 cv_destroy(&chq->queue_busy); 315 cv_destroy(&chq->queue_busy);
316 cv_destroy(&chq->queue_drain); 316 cv_destroy(&chq->queue_drain);
317 317
318 free(chq, M_DEVBUF); 318 free(chq, M_DEVBUF);
319} 319}
320 320
321void 321void
322ata_channel_init(struct ata_channel *chp) 322ata_channel_init(struct ata_channel *chp)
323{ 323{
324 mutex_init(&chp->ch_lock, MUTEX_DEFAULT, IPL_BIO); 324 mutex_init(&chp->ch_lock, MUTEX_DEFAULT, IPL_BIO);
 325 cv_init(&chp->ch_thr_idle, "atath");
325} 326}
326 327
327/* 328/*
328 * ata_channel_attach: 329 * ata_channel_attach:
329 * 330 *
330 * Common parts of attaching an atabus to an ATA controller channel. 331 * Common parts of attaching an atabus to an ATA controller channel.
331 */ 332 */
332void 333void
333ata_channel_attach(struct ata_channel *chp) 334ata_channel_attach(struct ata_channel *chp)
334{ 335{
335 if (chp->ch_flags & ATACH_DISABLED) 336 if (chp->ch_flags & ATACH_DISABLED)
336 return; 337 return;
337 338
338 KASSERT(chp->ch_queue != NULL); 339 KASSERT(chp->ch_queue != NULL);
339 340
340 ata_channel_init(chp); 341 ata_channel_init(chp);
341 342
342 chp->atabus = config_found_ia(chp->ch_atac->atac_dev, "ata", chp, 343 chp->atabus = config_found_ia(chp->ch_atac->atac_dev, "ata", chp,
343 atabusprint); 344 atabusprint);
344} 345}
345 346
346void 347void
347ata_channel_destroy(struct ata_channel *chp) 348ata_channel_destroy(struct ata_channel *chp)
348{ 349{
349 mutex_destroy(&chp->ch_lock); 350 mutex_destroy(&chp->ch_lock);
 351 cv_destroy(&chp->ch_thr_idle);
350} 352}
351 353
352/* 354/*
353 * ata_channel_detach: 355 * ata_channel_detach:
354 * 356 *
355 * Common parts of detaching an atabus to an ATA controller channel. 357 * Common parts of detaching an atabus to an ATA controller channel.
356 */ 358 */
357void 359void
358ata_channel_detach(struct ata_channel *chp) 360ata_channel_detach(struct ata_channel *chp)
359{ 361{
360 if (chp->ch_flags & ATACH_DISABLED) 362 if (chp->ch_flags & ATACH_DISABLED)
361 return; 363 return;
362 364
363 ata_channel_destroy(chp); 365 ata_channel_destroy(chp);
364} 366}
365 367
366static void 368static void
367atabusconfig(struct atabus_softc *atabus_sc) 369atabusconfig(struct atabus_softc *atabus_sc)
368{ 370{
369 struct ata_channel *chp = atabus_sc->sc_chan; 371 struct ata_channel *chp = atabus_sc->sc_chan;
370 struct atac_softc *atac = chp->ch_atac; 372 struct atac_softc *atac = chp->ch_atac;
371 struct atabus_initq *atabus_initq = NULL; 373 struct atabus_initq *atabus_initq = NULL;
372 int i, s, error; 374 int i, error;
373 375
374 /* we are in the atabus's thread context */ 376 /* we are in the atabus's thread context */
375 s = splbio(); 377 mutex_enter(&chp->ch_lock);
376 chp->ch_flags |= ATACH_TH_RUN; 378 chp->ch_flags |= ATACH_TH_RUN;
377 splx(s); 379 mutex_exit(&chp->ch_lock);
378 380
379 /* 381 /*
380 * Probe for the drives attached to controller, unless a PMP 382 * Probe for the drives attached to controller, unless a PMP
381 * is already known 383 * is already known
382 */ 384 */
383 /* XXX for SATA devices we will power up all drives at once */ 385 /* XXX for SATA devices we will power up all drives at once */
384 if (chp->ch_satapmp_nports == 0) 386 if (chp->ch_satapmp_nports == 0)
385 (*atac->atac_probe)(chp); 387 (*atac->atac_probe)(chp);
386 388
387 if (chp->ch_ndrives >= 2) { 389 if (chp->ch_ndrives >= 2) {
388 ATADEBUG_PRINT(("atabusattach: ch_drive_type 0x%x 0x%x\n", 390 ATADEBUG_PRINT(("atabusattach: ch_drive_type 0x%x 0x%x\n",
389 chp->ch_drive[0].drive_type, chp->ch_drive[1].drive_type), 391 chp->ch_drive[0].drive_type, chp->ch_drive[1].drive_type),
390 DEBUG_PROBE); 392 DEBUG_PROBE);
391 } 393 }
392 394
393 /* next operations will occurs in a separate thread */ 395 /* next operations will occurs in a separate thread */
394 s = splbio(); 396 mutex_enter(&chp->ch_lock);
395 chp->ch_flags &= ~ATACH_TH_RUN; 397 chp->ch_flags &= ~ATACH_TH_RUN;
396 splx(s); 398 mutex_exit(&chp->ch_lock);
397 399
398 /* Make sure the devices probe in atabus order to avoid jitter. */ 400 /* Make sure the devices probe in atabus order to avoid jitter. */
399 mutex_enter(&atabus_qlock); 401 mutex_enter(&atabus_qlock);
400 for (;;) { 402 for (;;) {
401 atabus_initq = TAILQ_FIRST(&atabus_initq_head); 403 atabus_initq = TAILQ_FIRST(&atabus_initq_head);
402 if (atabus_initq->atabus_sc == atabus_sc) 404 if (atabus_initq->atabus_sc == atabus_sc)
403 break; 405 break;
404 cv_wait(&atabus_qcv, &atabus_qlock); 406 cv_wait(&atabus_qcv, &atabus_qlock);
405 } 407 }
406 mutex_exit(&atabus_qlock); 408 mutex_exit(&atabus_qlock);
407 409
 410 mutex_enter(&chp->ch_lock);
 411
408 /* If no drives, abort here */ 412 /* If no drives, abort here */
409 if (chp->ch_drive == NULL) 413 if (chp->ch_drive == NULL)
410 goto out; 414 goto out;
411 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL); 415 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL);
412 for (i = 0; i < chp->ch_ndrives; i++) 416 for (i = 0; i < chp->ch_ndrives; i++)
413 if (chp->ch_drive[i].drive_type != ATA_DRIVET_NONE) 417 if (chp->ch_drive[i].drive_type != ATA_DRIVET_NONE)
414 break; 418 break;
415 if (i == chp->ch_ndrives) 419 if (i == chp->ch_ndrives)
416 goto out; 420 goto out;
417 421
418 /* Shortcut in case we've been shutdown */ 422 /* Shortcut in case we've been shutdown */
419 if (chp->ch_flags & ATACH_SHUTDOWN) 423 if (chp->ch_flags & ATACH_SHUTDOWN)
420 goto out; 424 goto out;
421 425
 426 mutex_exit(&chp->ch_lock);
 427
422 if ((error = kthread_create(PRI_NONE, 0, NULL, atabusconfig_thread, 428 if ((error = kthread_create(PRI_NONE, 0, NULL, atabusconfig_thread,
423 atabus_sc, &atabus_cfg_lwp, 429 atabus_sc, &atabus_cfg_lwp,
424 "%scnf", device_xname(atac->atac_dev))) != 0) 430 "%scnf", device_xname(atac->atac_dev))) != 0)
425 aprint_error_dev(atac->atac_dev, 431 aprint_error_dev(atac->atac_dev,
426 "unable to create config thread: error %d\n", error); 432 "unable to create config thread: error %d\n", error);
427 return; 433 return;
428 434
429 out: 435 out:
 436 mutex_exit(&chp->ch_lock);
 437
430 mutex_enter(&atabus_qlock); 438 mutex_enter(&atabus_qlock);
431 TAILQ_REMOVE(&atabus_initq_head, atabus_initq, atabus_initq); 439 TAILQ_REMOVE(&atabus_initq_head, atabus_initq, atabus_initq);
432 cv_broadcast(&atabus_qcv); 440 cv_broadcast(&atabus_qcv);
433 mutex_exit(&atabus_qlock); 441 mutex_exit(&atabus_qlock);
434 442
435 free(atabus_initq, M_DEVBUF); 443 free(atabus_initq, M_DEVBUF);
436 444
437 ata_delref(chp); 445 ata_delref(chp);
438 446
439 config_pending_decr(atac->atac_dev); 447 config_pending_decr(atac->atac_dev);
440} 448}
441 449
442/* 450/*
@@ -568,89 +576,104 @@ atabusconfig_thread(void *arg) @@ -568,89 +576,104 @@ atabusconfig_thread(void *arg)
568 576
569/* 577/*
570 * atabus_thread: 578 * atabus_thread:
571 * 579 *
572 * Worker thread for the ATA bus. 580 * Worker thread for the ATA bus.
573 */ 581 */
574static void 582static void
575atabus_thread(void *arg) 583atabus_thread(void *arg)
576{ 584{
577 struct atabus_softc *sc = arg; 585 struct atabus_softc *sc = arg;
578 struct ata_channel *chp = sc->sc_chan; 586 struct ata_channel *chp = sc->sc_chan;
579 struct ata_queue *chq = chp->ch_queue; 587 struct ata_queue *chq = chp->ch_queue;
580 struct ata_xfer *xfer; 588 struct ata_xfer *xfer;
581 int i, s; 589 int i;
582 590
583 s = splbio(); 591 mutex_enter(&chp->ch_lock);
584 chp->ch_flags |= ATACH_TH_RUN; 592 chp->ch_flags |= ATACH_TH_RUN;
585 593
586 /* 594 /*
587 * Probe the drives. Reset type to indicate to controllers 595 * Probe the drives. Reset type to indicate to controllers
588 * that can re-probe that all drives must be probed.. 596 * that can re-probe that all drives must be probed..
589 * 597 *
590 * Note: ch_ndrives may be changed during the probe. 598 * Note: ch_ndrives may be changed during the probe.
591 */ 599 */
592 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL); 600 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL);
593 for (i = 0; i < chp->ch_ndrives; i++) { 601 for (i = 0; i < chp->ch_ndrives; i++) {
594 chp->ch_drive[i].drive_flags = 0; 602 chp->ch_drive[i].drive_flags = 0;
595 chp->ch_drive[i].drive_type = ATA_DRIVET_NONE; 603 chp->ch_drive[i].drive_type = ATA_DRIVET_NONE;
596 } 604 }
597 splx(s); 605 mutex_exit(&chp->ch_lock);
598 606
599 atabusconfig(sc); 607 atabusconfig(sc);
600 608
601 s = splbio(); 609 mutex_enter(&chp->ch_lock);
602 for (;;) { 610 for (;;) {
603 if ((chp->ch_flags & (ATACH_TH_RESET | ATACH_SHUTDOWN)) == 0 && 611 if ((chp->ch_flags & (ATACH_TH_RESET | ATACH_SHUTDOWN)) == 0 &&
604 (chq->queue_active == 0 || chq->queue_freeze == 0)) { 612 (chq->queue_active == 0 || chq->queue_freeze == 0)) {
605 chp->ch_flags &= ~ATACH_TH_RUN; 613 chp->ch_flags &= ~ATACH_TH_RUN;
606 (void) tsleep(&chp->ch_thread, PRIBIO, "atath", 0); 614 cv_wait(&chp->ch_thr_idle, &chp->ch_lock);
607 chp->ch_flags |= ATACH_TH_RUN; 615 chp->ch_flags |= ATACH_TH_RUN;
608 } 616 }
609 if (chp->ch_flags & ATACH_SHUTDOWN) { 617 if (chp->ch_flags & ATACH_SHUTDOWN) {
610 break; 618 break;
611 } 619 }
612 if (chp->ch_flags & ATACH_TH_RESCAN) { 620 if (chp->ch_flags & ATACH_TH_RESCAN) {
613 atabusconfig(sc); 
614 chp->ch_flags &= ~ATACH_TH_RESCAN; 621 chp->ch_flags &= ~ATACH_TH_RESCAN;
 622 mutex_exit(&chp->ch_lock);
 623 atabusconfig(sc);
 624 mutex_enter(&chp->ch_lock);
615 } 625 }
616 if (chp->ch_flags & ATACH_TH_RESET) { 626 if (chp->ch_flags & ATACH_TH_RESET) {
617 /* 627 /*
618 * ata_reset_channel() will freeze 2 times, so 628 * ata_reset_channel() will freeze 2 times, so
619 * unfreeze one time. Not a problem as we're at splbio 629 * unfreeze one time. Not a problem as we're at splbio
620 */ 630 */
 631 mutex_exit(&chp->ch_lock);
621 ata_channel_thaw(chp); 632 ata_channel_thaw(chp);
622 ata_reset_channel(chp, AT_WAIT | chp->ch_reset_flags); 633 ata_reset_channel(chp, AT_WAIT | chp->ch_reset_flags);
 634 mutex_enter(&chp->ch_lock);
623 } else if (chq->queue_active > 0 && chq->queue_freeze == 1) { 635 } else if (chq->queue_active > 0 && chq->queue_freeze == 1) {
624 /* 636 /*
625 * Caller has bumped queue_freeze, decrease it. This 637 * Caller has bumped queue_freeze, decrease it. This
626 * flow shalt never be executed for NCQ commands. 638 * flow shalt never be executed for NCQ commands.
627 */ 639 */
628 KASSERT((chp->ch_flags & ATACH_NCQ) == 0); 640 KASSERT((chp->ch_flags & ATACH_NCQ) == 0);
629 KASSERT(chq->queue_active == 1); 641 KASSERT(chq->queue_active == 1);
 642 mutex_exit(&chp->ch_lock);
630 643
631 ata_channel_thaw(chp); 644 ata_channel_thaw(chp);
632 xfer = ata_queue_get_active_xfer(chp); 645 xfer = ata_queue_get_active_xfer(chp);
633 KASSERT(xfer != NULL); 646 KASSERT(xfer != NULL);
634 (*xfer->c_start)(xfer->c_chp, xfer); 647 (*xfer->c_start)(xfer->c_chp, xfer);
 648 mutex_enter(&chp->ch_lock);
635 } else if (chq->queue_freeze > 1) 649 } else if (chq->queue_freeze > 1)
636 panic("ata_thread: queue_freeze"); 650 panic("%s: queue_freeze", __func__);
637 } 651 }
638 splx(s); 
639 chp->ch_thread = NULL; 652 chp->ch_thread = NULL;
640 wakeup(&chp->ch_flags); 653 cv_signal(&chp->ch_thr_idle);
 654 mutex_exit(&chp->ch_lock);
641 kthread_exit(0); 655 kthread_exit(0);
642} 656}
643 657
 658void
 659ata_thread_wake(struct ata_channel *chp)
 660{
 661 mutex_enter(&chp->ch_lock);
 662 ata_channel_freeze_locked(chp);
 663 cv_signal(&chp->ch_thr_idle);
 664 mutex_exit(&chp->ch_lock);
 665}
 666
644/* 667/*
645 * atabus_match: 668 * atabus_match:
646 * 669 *
647 * Autoconfiguration match routine. 670 * Autoconfiguration match routine.
648 */ 671 */
649static int 672static int
650atabus_match(device_t parent, cfdata_t cf, void *aux) 673atabus_match(device_t parent, cfdata_t cf, void *aux)
651{ 674{
652 struct ata_channel *chp = aux; 675 struct ata_channel *chp = aux;
653 676
654 if (chp == NULL) 677 if (chp == NULL)
655 return (0); 678 return (0);
656 679
@@ -701,38 +724,36 @@ atabus_attach(device_t parent, device_t  @@ -701,38 +724,36 @@ atabus_attach(device_t parent, device_t
701} 724}
702 725
703/* 726/*
704 * atabus_detach: 727 * atabus_detach:
705 * 728 *
706 * Autoconfiguration detach routine. 729 * Autoconfiguration detach routine.
707 */ 730 */
708static int 731static int
709atabus_detach(device_t self, int flags) 732atabus_detach(device_t self, int flags)
710{ 733{
711 struct atabus_softc *sc = device_private(self); 734 struct atabus_softc *sc = device_private(self);
712 struct ata_channel *chp = sc->sc_chan; 735 struct ata_channel *chp = sc->sc_chan;
713 device_t dev = NULL; 736 device_t dev = NULL;
714 int s, i, error = 0; 737 int i, error = 0;
715 738
716 /* Shutdown the channel. */ 739 /* Shutdown the channel. */
717 s = splbio(); /* XXX ALSO NEED AN INTERLOCK HERE. */ 740 mutex_enter(&chp->ch_lock);
718 chp->ch_flags |= ATACH_SHUTDOWN; 741 chp->ch_flags |= ATACH_SHUTDOWN;
719 splx(s); 742 while (chp->ch_thread != NULL) {
720 743 cv_signal(&chp->ch_thr_idle);
721 wakeup(&chp->ch_thread); 744 cv_wait(&chp->ch_thr_idle, &chp->ch_lock);
722 745 }
723 while (chp->ch_thread != NULL) 746 mutex_exit(&chp->ch_lock);
724 (void) tsleep(&chp->ch_flags, PRIBIO, "atadown", 0); 
725 
726 747
727 /* 748 /*
728 * Detach atapibus and its children. 749 * Detach atapibus and its children.
729 */ 750 */
730 if ((dev = chp->atapibus) != NULL) { 751 if ((dev = chp->atapibus) != NULL) {
731 ATADEBUG_PRINT(("atabus_detach: %s: detaching %s\n", 752 ATADEBUG_PRINT(("atabus_detach: %s: detaching %s\n",
732 device_xname(self), device_xname(dev)), DEBUG_DETACH); 753 device_xname(self), device_xname(dev)), DEBUG_DETACH);
733 754
734 error = config_detach(dev, flags); 755 error = config_detach(dev, flags);
735 if (error) 756 if (error)
736 goto out; 757 goto out;
737 KASSERT(chp->atapibus == NULL); 758 KASSERT(chp->atapibus == NULL);
738 } 759 }
@@ -1653,36 +1674,46 @@ ata_kill_pending(struct ata_drive_datas  @@ -1653,36 +1674,46 @@ ata_kill_pending(struct ata_drive_datas
1653  1674
1654 if (!drv_active) { 1675 if (!drv_active) {
1655 /* all finished */ 1676 /* all finished */
1656 break; 1677 break;
1657 } 1678 }
1658 1679
1659 drvp->drive_flags |= ATA_DRIVE_WAITDRAIN; 1680 drvp->drive_flags |= ATA_DRIVE_WAITDRAIN;
1660 cv_wait(&chq->queue_drain, &chp->ch_lock); 1681 cv_wait(&chq->queue_drain, &chp->ch_lock);
1661 } 1682 }
1662 1683
1663 mutex_exit(&chp->ch_lock); 1684 mutex_exit(&chp->ch_lock);
1664} 1685}
1665 1686
 1687static void
 1688ata_channel_freeze_locked(struct ata_channel *chp)
 1689{
 1690 chp->ch_queue->queue_freeze++;
 1691}
 1692
1666void 1693void
1667ata_channel_freeze(struct ata_channel *chp) 1694ata_channel_freeze(struct ata_channel *chp)
1668{ 1695{
1669 chp->ch_queue->queue_freeze++; /* XXX MPSAFE */ 1696 mutex_enter(&chp->ch_lock);
 1697 ata_channel_freeze_locked(chp);
 1698 mutex_exit(&chp->ch_lock);
1670} 1699}
1671 1700
1672void 1701void
1673ata_channel_thaw(struct ata_channel *chp) 1702ata_channel_thaw(struct ata_channel *chp)
1674{ 1703{
1675 chp->ch_queue->queue_freeze--; /* XXX MPSAFE */ 1704 mutex_enter(&chp->ch_lock);
 1705 chp->ch_queue->queue_freeze--;
 1706 mutex_exit(&chp->ch_lock);
1676} 1707}
1677 1708
1678/* 1709/*
1679 * ata_reset_channel: 1710 * ata_reset_channel:
1680 * 1711 *
1681 * Reset and ATA channel. 1712 * Reset and ATA channel.
1682 * 1713 *
1683 * MUST BE CALLED AT splbio()! 1714 * MUST BE CALLED AT splbio()!
1684 */ 1715 */
1685void 1716void
1686ata_reset_channel(struct ata_channel *chp, int flags) 1717ata_reset_channel(struct ata_channel *chp, int flags)
1687{ 1718{
1688 struct atac_softc *atac = chp->ch_atac; 1719 struct atac_softc *atac = chp->ch_atac;
@@ -1705,39 +1736,44 @@ ata_reset_channel(struct ata_channel *ch @@ -1705,39 +1736,44 @@ ata_reset_channel(struct ata_channel *ch
1705 1736
1706 /* 1737 /*
1707 * If we can poll or wait it's OK, otherwise wake up the 1738 * If we can poll or wait it's OK, otherwise wake up the
1708 * kernel thread to do it for us. 1739 * kernel thread to do it for us.
1709 */ 1740 */
1710 ATADEBUG_PRINT(("ata_reset_channel flags 0x%x ch_flags 0x%x\n", 1741 ATADEBUG_PRINT(("ata_reset_channel flags 0x%x ch_flags 0x%x\n",
1711 flags, chp->ch_flags), DEBUG_FUNCS | DEBUG_XFERS); 1742 flags, chp->ch_flags), DEBUG_FUNCS | DEBUG_XFERS);
1712 if ((flags & (AT_POLL | AT_WAIT)) == 0) { 1743 if ((flags & (AT_POLL | AT_WAIT)) == 0) {
1713 if (chp->ch_flags & ATACH_TH_RESET) { 1744 if (chp->ch_flags & ATACH_TH_RESET) {
1714 /* No need to schedule a reset more than one time. */ 1745 /* No need to schedule a reset more than one time. */
1715 ata_channel_thaw(chp); 1746 ata_channel_thaw(chp);
1716 return; 1747 return;
1717 } 1748 }
 1749 mutex_enter(&chp->ch_lock);
1718 chp->ch_flags |= ATACH_TH_RESET; 1750 chp->ch_flags |= ATACH_TH_RESET;
1719 chp->ch_reset_flags = flags & AT_RST_EMERG; 1751 chp->ch_reset_flags = flags & AT_RST_EMERG;
1720 wakeup(&chp->ch_thread); 1752 cv_signal(&chp->ch_thr_idle);
 1753 mutex_exit(&chp->ch_lock);
1721 return; 1754 return;
1722 } 1755 }
1723 1756
1724 (*atac->atac_bustype_ata->ata_reset_channel)(chp, flags); 1757 (*atac->atac_bustype_ata->ata_reset_channel)(chp, flags);
1725 1758
 1759 mutex_enter(&chp->ch_lock);
1726 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL); 1760 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL);
1727 for (drive = 0; drive < chp->ch_ndrives; drive++) 1761 for (drive = 0; drive < chp->ch_ndrives; drive++)
1728 chp->ch_drive[drive].state = 0; 1762 chp->ch_drive[drive].state = 0;
1729 1763
1730 chp->ch_flags &= ~ATACH_TH_RESET; 1764 chp->ch_flags &= ~ATACH_TH_RESET;
 1765 mutex_exit(&chp->ch_lock);
 1766
1731 if (flags & AT_RST_EMERG) { 1767 if (flags & AT_RST_EMERG) {
1732 /* make sure that we can use polled commands */ 1768 /* make sure that we can use polled commands */
1733 ata_queue_reset(chp->ch_queue); 1769 ata_queue_reset(chp->ch_queue);
1734 } else { 1770 } else {
1735 ata_channel_thaw(chp); 1771 ata_channel_thaw(chp);
1736 atastart(chp); 1772 atastart(chp);
1737 } 1773 }
1738} 1774}
1739 1775
1740int 1776int
1741ata_addref(struct ata_channel *chp) 1777ata_addref(struct ata_channel *chp)
1742{ 1778{
1743 struct atac_softc *atac = chp->ch_atac; 1779 struct atac_softc *atac = chp->ch_atac;
@@ -2293,46 +2329,47 @@ atabus_suspend(device_t dv, const pmf_qu @@ -2293,46 +2329,47 @@ atabus_suspend(device_t dv, const pmf_qu
2293 struct atabus_softc *sc = device_private(dv); 2329 struct atabus_softc *sc = device_private(dv);
2294 struct ata_channel *chp = sc->sc_chan; 2330 struct ata_channel *chp = sc->sc_chan;
2295 2331
2296 ata_channel_idle(chp); 2332 ata_channel_idle(chp);
2297 2333
2298 return true; 2334 return true;
2299} 2335}
2300 2336
2301static bool 2337static bool
2302atabus_resume(device_t dv, const pmf_qual_t *qual) 2338atabus_resume(device_t dv, const pmf_qual_t *qual)
2303{ 2339{
2304 struct atabus_softc *sc = device_private(dv); 2340 struct atabus_softc *sc = device_private(dv);
2305 struct ata_channel *chp = sc->sc_chan; 2341 struct ata_channel *chp = sc->sc_chan;
2306 int s; 
2307 2342
2308 /* 2343 /*
2309 * XXX joerg: with wdc, the first channel unfreezes the controler. 2344 * XXX joerg: with wdc, the first channel unfreezes the controler.
2310 * Move this the reset and queue idling into wdc. 2345 * Move this the reset and queue idling into wdc.
2311 */ 2346 */
2312 s = splbio(); 2347 mutex_enter(&chp->ch_lock);
2313 if (chp->ch_queue->queue_freeze == 0) { 2348 if (chp->ch_queue->queue_freeze == 0) {
2314 splx(s); 2349 mutex_exit(&chp->ch_lock);
2315 return true; 2350 goto out;
2316 } 2351 }
2317 KASSERT(chp->ch_queue->queue_freeze > 0); 2352 KASSERT(chp->ch_queue->queue_freeze > 0);
 2353 mutex_exit(&chp->ch_lock);
 2354
2318 /* unfreeze the queue and reset drives */ 2355 /* unfreeze the queue and reset drives */
2319 ata_channel_thaw(chp); 2356 ata_channel_thaw(chp);
2320 2357
2321 /* reset channel only if there are drives attached */ 2358 /* reset channel only if there are drives attached */
2322 if (chp->ch_ndrives > 0) 2359 if (chp->ch_ndrives > 0)
2323 ata_reset_channel(chp, AT_WAIT); 2360 ata_reset_channel(chp, AT_WAIT);
2324 splx(s); 
2325 2361
 2362out:
2326 return true; 2363 return true;
2327} 2364}
2328 2365
2329static int 2366static int
2330atabus_rescan(device_t self, const char *ifattr, const int *locators) 2367atabus_rescan(device_t self, const char *ifattr, const int *locators)
2331{ 2368{
2332 struct atabus_softc *sc = device_private(self); 2369 struct atabus_softc *sc = device_private(self);
2333 struct ata_channel *chp = sc->sc_chan; 2370 struct ata_channel *chp = sc->sc_chan;
2334 struct atabus_initq *initq; 2371 struct atabus_initq *initq;
2335 int i; 2372 int i;
2336 2373
2337 /* 2374 /*
2338 * we can rescan a port multiplier atabus, even if some devices are 2375 * we can rescan a port multiplier atabus, even if some devices are
@@ -2346,38 +2383,40 @@ atabus_rescan(device_t self, const char  @@ -2346,38 +2383,40 @@ atabus_rescan(device_t self, const char
2346 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL); 2383 KASSERT(chp->ch_ndrives == 0 || chp->ch_drive != NULL);
2347 for (i = 0; i < chp->ch_ndrives; i++) { 2384 for (i = 0; i < chp->ch_ndrives; i++) {
2348 if (chp->ch_drive[i].drv_softc != NULL) { 2385 if (chp->ch_drive[i].drv_softc != NULL) {
2349 return EBUSY; 2386 return EBUSY;
2350 } 2387 }
2351 } 2388 }
2352 } 2389 }
2353 2390
2354 initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK); 2391 initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK);
2355 initq->atabus_sc = sc; 2392 initq->atabus_sc = sc;
2356 TAILQ_INSERT_TAIL(&atabus_initq_head, initq, atabus_initq); 2393 TAILQ_INSERT_TAIL(&atabus_initq_head, initq, atabus_initq);
2357 config_pending_incr(sc->sc_dev); 2394 config_pending_incr(sc->sc_dev);
2358 2395
 2396 mutex_enter(&chp->ch_lock);
2359 chp->ch_flags |= ATACH_TH_RESCAN; 2397 chp->ch_flags |= ATACH_TH_RESCAN;
2360 wakeup(&chp->ch_thread); 2398 cv_signal(&chp->ch_thr_idle);
 2399 mutex_exit(&chp->ch_lock);
2361 2400
2362 return 0; 2401 return 0;
2363} 2402}
2364 2403
2365void 2404void
2366ata_delay(int ms, const char *msg, int flags) 2405ata_delay(int ms, const char *msg, int flags)
2367{ 2406{
2368 if ((flags & (AT_WAIT | AT_POLL)) == AT_POLL) { 2407 if ((flags & (AT_WAIT | AT_POLL)) == AT_POLL) {
2369 /* 2408 /*
2370 * can't use tsleep(), we may be in interrupt context 2409 * can't use kpause(), we may be in interrupt context
2371 * or taking a crash dump 2410 * or taking a crash dump
2372 */ 2411 */
2373 delay(ms * 1000); 2412 delay(ms * 1000);
2374 } else { 2413 } else {
2375 int pause = mstohz(ms); 2414 int pause = mstohz(ms);
2376 kpause(msg, false, pause > 0 ? pause : 1, NULL); 2415 kpause(msg, false, pause > 0 ? pause : 1, NULL);
2377 } 2416 }
2378} 2417}
2379 2418
2380void 2419void
2381atacmd_toncq(struct ata_xfer *xfer, uint8_t *cmd, uint16_t *count, 2420atacmd_toncq(struct ata_xfer *xfer, uint8_t *cmd, uint16_t *count,
2382 uint16_t *features, uint8_t *device) 2421 uint16_t *features, uint8_t *device)
2383{ 2422{

cvs diff -r1.105.6.7 -r1.105.6.8 src/sys/dev/ata/ata_wdc.c (expand / switch to unified diff)

--- src/sys/dev/ata/ata_wdc.c 2017/08/12 09:52:28 1.105.6.7
+++ src/sys/dev/ata/ata_wdc.c 2017/08/12 14:41:54 1.105.6.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ata_wdc.c,v 1.105.6.7 2017/08/12 09:52:28 jdolecek Exp $ */ 1/* $NetBSD: ata_wdc.c,v 1.105.6.8 2017/08/12 14:41:54 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001, 2003 Manuel Bouyer. 4 * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -44,27 +44,27 @@ @@ -44,27 +44,27 @@
44 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 44 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
45 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 45 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 46 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
47 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 47 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 * POSSIBILITY OF SUCH DAMAGE. 53 * POSSIBILITY OF SUCH DAMAGE.
54 */ 54 */
55 55
56#include <sys/cdefs.h> 56#include <sys/cdefs.h>
57__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.105.6.7 2017/08/12 09:52:28 jdolecek Exp $"); 57__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.105.6.8 2017/08/12 14:41:54 jdolecek Exp $");
58 58
59#include "opt_ata.h" 59#include "opt_ata.h"
60#include "opt_wdc.h" 60#include "opt_wdc.h"
61 61
62#include <sys/param.h> 62#include <sys/param.h>
63#include <sys/systm.h> 63#include <sys/systm.h>
64#include <sys/kernel.h> 64#include <sys/kernel.h>
65#include <sys/file.h> 65#include <sys/file.h>
66#include <sys/stat.h> 66#include <sys/stat.h>
67#include <sys/buf.h> 67#include <sys/buf.h>
68#include <sys/bufq.h> 68#include <sys/bufq.h>
69#include <sys/malloc.h> 69#include <sys/malloc.h>
70#include <sys/device.h> 70#include <sys/device.h>
@@ -189,28 +189,27 @@ wdc_ata_bio_start(struct ata_channel *ch @@ -189,28 +189,27 @@ wdc_ata_bio_start(struct ata_channel *ch
189 drvp->state, drvp->drive_flags, xfer->c_flags, chp->ch_flags), 189 drvp->state, drvp->drive_flags, xfer->c_flags, chp->ch_flags),
190 DEBUG_XFERS); 190 DEBUG_XFERS);
191 191
192 /* Do control operations specially. */ 192 /* Do control operations specially. */
193 if (__predict_false(drvp->state < READY)) { 193 if (__predict_false(drvp->state < READY)) {
194 /* 194 /*
195 * Actually, we want to be careful not to mess with the control 195 * Actually, we want to be careful not to mess with the control
196 * state if the device is currently busy, but we can assume 196 * state if the device is currently busy, but we can assume
197 * that we never get to this point if that's the case. 197 * that we never get to this point if that's the case.
198 */ 198 */
199 /* If it's not a polled command, we need the kernel thread */ 199 /* If it's not a polled command, we need the kernel thread */
200 if ((xfer->c_flags & C_POLL) == 0 && 200 if ((xfer->c_flags & C_POLL) == 0 &&
201 (chp->ch_flags & ATACH_TH_RUN) == 0) { 201 (chp->ch_flags & ATACH_TH_RUN) == 0) {
202 ata_channel_freeze(chp); 202 ata_thread_wake(chp);
203 wakeup(&chp->ch_thread); 
204 return; 203 return;
205 } 204 }
206 /* 205 /*
207 * disable interrupts, all commands here should be quick 206 * disable interrupts, all commands here should be quick
208 * enough to be able to poll, and we don't go here that often 207 * enough to be able to poll, and we don't go here that often
209 */ 208 */
210 if (! (wdc->cap & WDC_CAPABILITY_NO_AUXCTL)) 209 if (! (wdc->cap & WDC_CAPABILITY_NO_AUXCTL))
211 bus_space_write_1(wdr->ctl_iot, wdr->ctl_ioh,  210 bus_space_write_1(wdr->ctl_iot, wdr->ctl_ioh,
212 wd_aux_ctlr, WDCTL_4BIT | WDCTL_IDS); 211 wd_aux_ctlr, WDCTL_4BIT | WDCTL_IDS);
213 if (wdc->select) 212 if (wdc->select)
214 wdc->select(chp, xfer->c_drive); 213 wdc->select(chp, xfer->c_drive);
215 bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0, 214 bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0,
216 WDSD_IBM | (xfer->c_drive << 4)); 215 WDSD_IBM | (xfer->c_drive << 4));

cvs diff -r1.92.8.22 -r1.92.8.23 src/sys/dev/ata/atavar.h (expand / switch to unified diff)

--- src/sys/dev/ata/atavar.h 2017/08/12 09:52:28 1.92.8.22
+++ src/sys/dev/ata/atavar.h 2017/08/12 14:41:54 1.92.8.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: atavar.h,v 1.92.8.22 2017/08/12 09:52:28 jdolecek Exp $ */ 1/* $NetBSD: atavar.h,v 1.92.8.23 2017/08/12 14:41:54 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001 Manuel Bouyer. 4 * Copyright (c) 1998, 2001 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -407,26 +407,27 @@ struct ata_channel { @@ -407,26 +407,27 @@ struct ata_channel {
407 407
408 /* ATAPI children */ 408 /* ATAPI children */
409 device_t atapibus; 409 device_t atapibus;
410 struct scsipi_channel ch_atapi_channel; 410 struct scsipi_channel ch_atapi_channel;
411 411
412 /* 412 /*
413 * Channel queues. May be the same for all channels, if hw 413 * Channel queues. May be the same for all channels, if hw
414 * channels are not independent. 414 * channels are not independent.
415 */ 415 */
416 struct ata_queue *ch_queue; 416 struct ata_queue *ch_queue;
417 417
418 /* The channel kernel thread */ 418 /* The channel kernel thread */
419 struct lwp *ch_thread; 419 struct lwp *ch_thread;
 420 kcondvar_t ch_thr_idle; /* thread waiting for work */
420 421
421 /* Number of sata PMP ports, if any */ 422 /* Number of sata PMP ports, if any */
422 int ch_satapmp_nports; 423 int ch_satapmp_nports;
423}; 424};
424 425
425/* 426/*
426 * ATA controller softc. 427 * ATA controller softc.
427 * 428 *
428 * This contains a bunch of generic info that all ATA controllers need 429 * This contains a bunch of generic info that all ATA controllers need
429 * to have. 430 * to have.
430 * 431 *
431 * XXX There is still some lingering wdc-centricity here. 432 * XXX There is still some lingering wdc-centricity here.
432 */ 433 */
@@ -505,26 +506,27 @@ struct ata_xfer *ata_get_xfer_ext(struct @@ -505,26 +506,27 @@ struct ata_xfer *ata_get_xfer_ext(struct
505#define ata_get_xfer(chp) ata_get_xfer_ext((chp), C_WAIT, 0); 506#define ata_get_xfer(chp) ata_get_xfer_ext((chp), C_WAIT, 0);
506void ata_free_xfer(struct ata_channel *, struct ata_xfer *); 507void ata_free_xfer(struct ata_channel *, struct ata_xfer *);
507void ata_deactivate_xfer(struct ata_channel *, struct ata_xfer *); 508void ata_deactivate_xfer(struct ata_channel *, struct ata_xfer *);
508void ata_exec_xfer(struct ata_channel *, struct ata_xfer *); 509void ata_exec_xfer(struct ata_channel *, struct ata_xfer *);
509 510
510void ata_timeout(void *); 511void ata_timeout(void *);
511bool ata_timo_xfer_check(struct ata_xfer *); 512bool ata_timo_xfer_check(struct ata_xfer *);
512void ata_kill_pending(struct ata_drive_datas *); 513void ata_kill_pending(struct ata_drive_datas *);
513void ata_kill_active(struct ata_channel *, int, int); 514void ata_kill_active(struct ata_channel *, int, int);
514void ata_reset_channel(struct ata_channel *, int); 515void ata_reset_channel(struct ata_channel *, int);
515void ata_channel_freeze(struct ata_channel *); 516void ata_channel_freeze(struct ata_channel *);
516void ata_channel_thaw(struct ata_channel *); 517void ata_channel_thaw(struct ata_channel *);
517void ata_channel_start(struct ata_channel *, int); 518void ata_channel_start(struct ata_channel *, int);
 519void ata_thread_wake(struct ata_channel *);
518 520
519int ata_addref(struct ata_channel *); 521int ata_addref(struct ata_channel *);
520void ata_delref(struct ata_channel *); 522void ata_delref(struct ata_channel *);
521void atastart(struct ata_channel *); 523void atastart(struct ata_channel *);
522void ata_print_modes(struct ata_channel *); 524void ata_print_modes(struct ata_channel *);
523#if NATA_DMA 525#if NATA_DMA
524int ata_downgrade_mode(struct ata_drive_datas *, int); 526int ata_downgrade_mode(struct ata_drive_datas *, int);
525#endif 527#endif
526void ata_probe_caps(struct ata_drive_datas *); 528void ata_probe_caps(struct ata_drive_datas *);
527 529
528#if NATA_DMA 530#if NATA_DMA
529void ata_dmaerr(struct ata_drive_datas *, int); 531void ata_dmaerr(struct ata_drive_datas *, int);
530#endif 532#endif

cvs diff -r1.35.6.20 -r1.35.6.21 src/sys/dev/ic/mvsata.c (expand / switch to unified diff)

--- src/sys/dev/ic/mvsata.c 2017/08/12 09:52:28 1.35.6.20
+++ src/sys/dev/ic/mvsata.c 2017/08/12 14:41:54 1.35.6.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mvsata.c,v 1.35.6.20 2017/08/12 09:52:28 jdolecek Exp $ */ 1/* $NetBSD: mvsata.c,v 1.35.6.21 2017/08/12 14:41:54 jdolecek Exp $ */
2/* 2/*
3 * Copyright (c) 2008 KIYOHARA Takashi 3 * Copyright (c) 2008 KIYOHARA Takashi
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.20 2017/08/12 09:52:28 jdolecek Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.21 2017/08/12 14:41:54 jdolecek Exp $");
30 30
31#include "opt_mvsata.h" 31#include "opt_mvsata.h"
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/buf.h> 34#include <sys/buf.h>
35#include <sys/bus.h> 35#include <sys/bus.h>
36#include <sys/cpu.h> 36#include <sys/cpu.h>
37#include <sys/device.h> 37#include <sys/device.h>
38#include <sys/disklabel.h> 38#include <sys/disklabel.h>
39#include <sys/errno.h> 39#include <sys/errno.h>
40#include <sys/kernel.h> 40#include <sys/kernel.h>
41#include <sys/malloc.h> 41#include <sys/malloc.h>
42#include <sys/proc.h> 42#include <sys/proc.h>
@@ -1209,28 +1209,27 @@ do_pio: @@ -1209,28 +1209,27 @@ do_pio:
1209 if (__predict_false(drvp->state < READY)) { 1209 if (__predict_false(drvp->state < READY)) {
1210 /* 1210 /*
1211 * Actually, we want to be careful not to mess with 1211 * Actually, we want to be careful not to mess with
1212 * the control state if the device is currently busy, 1212 * the control state if the device is currently busy,
1213 * but we can assume that we never get to this point 1213 * but we can assume that we never get to this point
1214 * if that's the case. 1214 * if that's the case.
1215 */ 1215 */
1216 /* 1216 /*
1217 * If it's not a polled command, we need the kernel 1217 * If it's not a polled command, we need the kernel
1218 * thread 1218 * thread
1219 */ 1219 */
1220 if ((xfer->c_flags & C_POLL) == 0 && 1220 if ((xfer->c_flags & C_POLL) == 0 &&
1221 (chp->ch_flags & ATACH_TH_RUN) == 0) { 1221 (chp->ch_flags & ATACH_TH_RUN) == 0) {
1222 ata_channel_freeze(chp); 1222 ata_thread_wake(chp);
1223 wakeup(&chp->ch_thread); 
1224 return; 1223 return;
1225 } 1224 }
1226 if (mvsata_bio_ready(mvport, ata_bio, xfer->c_drive, 1225 if (mvsata_bio_ready(mvport, ata_bio, xfer->c_drive,
1227 (xfer->c_flags & C_POLL) ? AT_POLL : 0) != 0) { 1226 (xfer->c_flags & C_POLL) ? AT_POLL : 0) != 0) {
1228 mvsata_bio_done(chp, xfer); 1227 mvsata_bio_done(chp, xfer);
1229 return; 1228 return;
1230 } 1229 }
1231 } 1230 }
1232 1231
1233 /* Initiate command! */ 1232 /* Initiate command! */
1234 MVSATA_WDC_WRITE_1(mvport, SRB_H, WDSD_IBM); 1233 MVSATA_WDC_WRITE_1(mvport, SRB_H, WDSD_IBM);
1235 switch(wdc_wait_for_ready(chp, ATA_DELAY, wait_flags, &tfd)) { 1234 switch(wdc_wait_for_ready(chp, ATA_DELAY, wait_flags, &tfd)) {
1236 case WDCWAIT_OK: 1235 case WDCWAIT_OK:
@@ -1901,28 +1900,27 @@ mvsata_atapi_start(struct ata_channel *c @@ -1901,28 +1900,27 @@ mvsata_atapi_start(struct ata_channel *c
1901 if (mvport->port_edmamode_curr != nodma) 1900 if (mvport->port_edmamode_curr != nodma)
1902 mvsata_edma_disable(mvport, 10 /* ms */, wait_flags); 1901 mvsata_edma_disable(mvport, 10 /* ms */, wait_flags);
1903 1902
1904 mvsata_pmp_select(mvport, xfer->c_drive); 1903 mvsata_pmp_select(mvport, xfer->c_drive);
1905 1904
1906 if ((xfer->c_flags & C_DMA) && (drvp->n_xfers <= NXFER)) 1905 if ((xfer->c_flags & C_DMA) && (drvp->n_xfers <= NXFER))
1907 drvp->n_xfers++; 1906 drvp->n_xfers++;
1908 1907
1909 /* Do control operations specially. */ 1908 /* Do control operations specially. */
1910 if (__predict_false(drvp->state < READY)) { 1909 if (__predict_false(drvp->state < READY)) {
1911 /* If it's not a polled command, we need the kernel thread */ 1910 /* If it's not a polled command, we need the kernel thread */
1912 if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 && 1911 if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 &&
1913 (chp->ch_flags & ATACH_TH_RUN) == 0) { 1912 (chp->ch_flags & ATACH_TH_RUN) == 0) {
1914 ata_channel_freeze(chp); 1913 ata_thread_wake(chp);
1915 wakeup(&chp->ch_thread); 
1916 return; 1914 return;
1917 } 1915 }
1918 /* 1916 /*
1919 * disable interrupts, all commands here should be quick 1917 * disable interrupts, all commands here should be quick
1920 * enough to be able to poll, and we don't go here that often 1918 * enough to be able to poll, and we don't go here that often
1921 */ 1919 */
1922 MVSATA_WDC_WRITE_1(mvport, SRB_CAS, WDCTL_4BIT | WDCTL_IDS); 1920 MVSATA_WDC_WRITE_1(mvport, SRB_CAS, WDCTL_4BIT | WDCTL_IDS);
1923 1921
1924 MVSATA_WDC_WRITE_1(mvport, SRB_H, WDSD_IBM); 1922 MVSATA_WDC_WRITE_1(mvport, SRB_H, WDSD_IBM);
1925 /* Don't try to set mode if controller can't be adjusted */ 1923 /* Don't try to set mode if controller can't be adjusted */
1926 if (atac->atac_set_modes == NULL) 1924 if (atac->atac_set_modes == NULL)
1927 goto ready; 1925 goto ready;
1928 /* Also don't try if the drive didn't report its mode */ 1926 /* Also don't try if the drive didn't report its mode */

cvs diff -r1.283.2.12 -r1.283.2.13 src/sys/dev/ic/wdc.c (expand / switch to unified diff)

--- src/sys/dev/ic/wdc.c 2017/08/12 13:41:46 1.283.2.12
+++ src/sys/dev/ic/wdc.c 2017/08/12 14:41:54 1.283.2.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wdc.c,v 1.283.2.12 2017/08/12 13:41:46 jdolecek Exp $ */ 1/* $NetBSD: wdc.c,v 1.283.2.13 2017/08/12 14:41:54 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001, 2003 Manuel Bouyer. All rights reserved. 4 * Copyright (c) 1998, 2001, 2003 Manuel Bouyer. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -48,27 +48,27 @@ @@ -48,27 +48,27 @@
48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 * POSSIBILITY OF SUCH DAMAGE. 53 * POSSIBILITY OF SUCH DAMAGE.
54 */ 54 */
55 55
56/* 56/*
57 * CODE UNTESTED IN THE CURRENT REVISION: 57 * CODE UNTESTED IN THE CURRENT REVISION:
58 */ 58 */
59 59
60#include <sys/cdefs.h> 60#include <sys/cdefs.h>
61__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.12 2017/08/12 13:41:46 jdolecek Exp $"); 61__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.13 2017/08/12 14:41:54 jdolecek Exp $");
62 62
63#include "opt_ata.h" 63#include "opt_ata.h"
64#include "opt_wdc.h" 64#include "opt_wdc.h"
65 65
66#include <sys/param.h> 66#include <sys/param.h>
67#include <sys/systm.h> 67#include <sys/systm.h>
68#include <sys/kernel.h> 68#include <sys/kernel.h>
69#include <sys/conf.h> 69#include <sys/conf.h>
70#include <sys/buf.h> 70#include <sys/buf.h>
71#include <sys/device.h> 71#include <sys/device.h>
72#include <sys/malloc.h> 72#include <sys/malloc.h>
73#include <sys/syslog.h> 73#include <sys/syslog.h>
74#include <sys/proc.h> 74#include <sys/proc.h>
@@ -1242,28 +1242,27 @@ wdcwait(struct ata_channel *chp, int mas @@ -1242,28 +1242,27 @@ wdcwait(struct ata_channel *chp, int mas
1242 for (i = 0; i < timeout_hz; i++) { 1242 for (i = 0; i < timeout_hz; i++) {
1243 if (__wdcwait(chp, mask, bits, 1243 if (__wdcwait(chp, mask, bits,
1244 WDCDELAY_POLL, tfd) == 0) { 1244 WDCDELAY_POLL, tfd) == 0) {
1245 error = 0; 1245 error = 0;
1246 break; 1246 break;
1247 } 1247 }
1248 tsleep(&chp, PRIBIO, "atapoll", 1); 1248 tsleep(&chp, PRIBIO, "atapoll", 1);
1249 } 1249 }
1250 } else { 1250 } else {
1251 /* 1251 /*
1252 * we're probably in interrupt context, 1252 * we're probably in interrupt context,
1253 * ask the thread to come back here 1253 * ask the thread to come back here
1254 */ 1254 */
1255 ata_channel_freeze(chp); 1255 ata_thread_wake(chp);
1256 wakeup(&chp->ch_thread); 
1257 return(WDCWAIT_THR); 1256 return(WDCWAIT_THR);
1258 } 1257 }
1259 } 1258 }
1260 } 1259 }
1261 return (error); 1260 return (error);
1262} 1261}
1263 1262
1264 1263
1265#if NATA_DMA 1264#if NATA_DMA
1266/* 1265/*
1267 * Busy-wait for DMA to complete 1266 * Busy-wait for DMA to complete
1268 */ 1267 */
1269int 1268int

cvs diff -r1.123.4.11 -r1.123.4.12 src/sys/dev/scsipi/atapi_wdc.c (expand / switch to unified diff)

--- src/sys/dev/scsipi/atapi_wdc.c 2017/08/12 09:52:28 1.123.4.11
+++ src/sys/dev/scsipi/atapi_wdc.c 2017/08/12 14:41:54 1.123.4.12
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1/* $NetBSD: atapi_wdc.c,v 1.123.4.11 2017/08/12 09:52:28 jdolecek Exp $ */ 1/* $NetBSD: atapi_wdc.c,v 1.123.4.12 2017/08/12 14:41:54 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2001 Manuel Bouyer. 4 * Copyright (c) 1998, 2001 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#include <sys/cdefs.h> 27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.123.4.11 2017/08/12 09:52:28 jdolecek Exp $"); 28__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.123.4.12 2017/08/12 14:41:54 jdolecek Exp $");
29 29
30#ifndef ATADEBUG 30#ifndef ATADEBUG
31#define ATADEBUG 31#define ATADEBUG
32#endif /* ATADEBUG */ 32#endif /* ATADEBUG */
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/systm.h> 35#include <sys/systm.h>
36#include <sys/kernel.h> 36#include <sys/kernel.h>
37#include <sys/file.h> 37#include <sys/file.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <sys/buf.h> 39#include <sys/buf.h>
40#include <sys/malloc.h> 40#include <sys/malloc.h>
41#include <sys/device.h> 41#include <sys/device.h>
@@ -486,28 +486,27 @@ wdc_atapi_start(struct ata_channel *chp, @@ -486,28 +486,27 @@ wdc_atapi_start(struct ata_channel *chp,
486 486
487 ATADEBUG_PRINT(("wdc_atapi_start %s:%d:%d, scsi flags 0x%x \n", 487 ATADEBUG_PRINT(("wdc_atapi_start %s:%d:%d, scsi flags 0x%x \n",
488 device_xname(atac->atac_dev), chp->ch_channel, drvp->drive, 488 device_xname(atac->atac_dev), chp->ch_channel, drvp->drive,
489 sc_xfer->xs_control), DEBUG_XFERS); 489 sc_xfer->xs_control), DEBUG_XFERS);
490#if NATA_DMA 490#if NATA_DMA
491 if ((xfer->c_flags & C_DMA) && (drvp->n_xfers <= NXFER)) 491 if ((xfer->c_flags & C_DMA) && (drvp->n_xfers <= NXFER))
492 drvp->n_xfers++; 492 drvp->n_xfers++;
493#endif 493#endif
494 /* Do control operations specially. */ 494 /* Do control operations specially. */
495 if (__predict_false(drvp->state < READY)) { 495 if (__predict_false(drvp->state < READY)) {
496 /* If it's not a polled command, we need the kernel thread */ 496 /* If it's not a polled command, we need the kernel thread */
497 if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 && 497 if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 &&
498 (chp->ch_flags & ATACH_TH_RUN) == 0) { 498 (chp->ch_flags & ATACH_TH_RUN) == 0) {
499 ata_channel_freeze(chp); 499 ata_thread_wake(chp);
500 wakeup(&chp->ch_thread); 
501 return; 500 return;
502 } 501 }
503 /* 502 /*
504 * disable interrupts, all commands here should be quick 503 * disable interrupts, all commands here should be quick
505 * enough to be able to poll, and we don't go here that often 504 * enough to be able to poll, and we don't go here that often
506 */ 505 */
507 bus_space_write_1(wdr->ctl_iot, wdr->ctl_ioh, wd_aux_ctlr, 506 bus_space_write_1(wdr->ctl_iot, wdr->ctl_ioh, wd_aux_ctlr,
508 WDCTL_4BIT | WDCTL_IDS); 507 WDCTL_4BIT | WDCTL_IDS);
509 if (wdc->select) 508 if (wdc->select)
510 wdc->select(chp, xfer->c_drive); 509 wdc->select(chp, xfer->c_drive);
511 bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0, 510 bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0,
512 WDSD_IBM | (xfer->c_drive << 4)); 511 WDSD_IBM | (xfer->c_drive << 4));
513 /* Don't try to set mode if controller can't be adjusted */ 512 /* Don't try to set mode if controller can't be adjusted */