Deleted Added
full compact
ata_xpt.c (199263) ata_xpt.c (199747)
1/*-
2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

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
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
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

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
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
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/cam/ata/ata_xpt.c 199263 2009-11-14 08:08:49Z mav $");
28__FBSDID("$FreeBSD: head/sys/cam/ata/ata_xpt.c 199747 2009-11-24 12:47:58Z mav $");
29
30#include <sys/param.h>
31#include <sys/bus.h>
32#include <sys/endian.h>
33#include <sys/systm.h>
34#include <sys/types.h>
35#include <sys/malloc.h>
36#include <sys/kernel.h>

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

270 softc->flags &= ~PROBE_NO_ANNOUNCE;
271
272 xpt_schedule(periph, ccb->ccb_h.pinfo.priority);
273}
274
275static void
276probestart(struct cam_periph *periph, union ccb *start_ccb)
277{
29
30#include <sys/param.h>
31#include <sys/bus.h>
32#include <sys/endian.h>
33#include <sys/systm.h>
34#include <sys/types.h>
35#include <sys/malloc.h>
36#include <sys/kernel.h>

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

270 softc->flags &= ~PROBE_NO_ANNOUNCE;
271
272 xpt_schedule(periph, ccb->ccb_h.pinfo.priority);
273}
274
275static void
276probestart(struct cam_periph *periph, union ccb *start_ccb)
277{
278 /* Probe the device that our peripheral driver points to */
278 struct ccb_trans_settings cts;
279 struct ccb_ataio *ataio;
280 struct ccb_scsiio *csio;
281 probe_softc *softc;
282 struct cam_path *path;
283 struct ata_params *ident_buf;
284
285 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
286

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

328 /*dxfer_len*/sizeof(struct ata_params),
329 30 * 1000);
330 if (periph->path->device->protocol == PROTO_ATA)
331 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
332 else
333 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
334 break;
335 case PROBE_SETMODE:
279 struct ccb_ataio *ataio;
280 struct ccb_scsiio *csio;
281 probe_softc *softc;
282 struct cam_path *path;
283 struct ata_params *ident_buf;
284
285 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
286

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

328 /*dxfer_len*/sizeof(struct ata_params),
329 30 * 1000);
330 if (periph->path->device->protocol == PROTO_ATA)
331 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
332 else
333 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
334 break;
335 case PROBE_SETMODE:
336 {
337 int mode, wantmode;
338
339 mode = 0;
340 /* Fetch user modes from SIM. */
341 bzero(&cts, sizeof(cts));
342 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
343 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
344 cts.type = CTS_TYPE_USER_SETTINGS;
345 xpt_action((union ccb *)&cts);
346 if (path->device->transport == XPORT_ATA) {
347 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
348 mode = cts.xport_specific.ata.mode;
349 } else {
350 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
351 mode = cts.xport_specific.sata.mode;
352 }
353negotiate:
354 /* Honor device capabilities. */
355 wantmode = mode = ata_max_mode(ident_buf, mode);
356 /* Report modes to SIM. */
357 bzero(&cts, sizeof(cts));
358 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
359 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
360 cts.type = CTS_TYPE_CURRENT_SETTINGS;
361 if (path->device->transport == XPORT_ATA) {
362 cts.xport_specific.ata.mode = mode;
363 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
364 } else {
365 cts.xport_specific.sata.mode = mode;
366 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
367 }
368 xpt_action((union ccb *)&cts);
369 /* Fetch user modes from SIM. */
370 bzero(&cts, sizeof(cts));
371 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
372 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
373 cts.type = CTS_TYPE_CURRENT_SETTINGS;
374 xpt_action((union ccb *)&cts);
375 if (path->device->transport == XPORT_ATA) {
376 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
377 mode = cts.xport_specific.ata.mode;
378 } else {
379 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
380 mode = cts.xport_specific.sata.mode;
381 }
382 /* If SIM disagree - renegotiate. */
383 if (mode != wantmode)
384 goto negotiate;
336 cam_fill_ataio(ataio,
337 1,
338 probedone,
339 /*flags*/CAM_DIR_NONE,
340 0,
341 /*data_ptr*/NULL,
342 /*dxfer_len*/0,
343 30 * 1000);
385 cam_fill_ataio(ataio,
386 1,
387 probedone,
388 /*flags*/CAM_DIR_NONE,
389 0,
390 /*data_ptr*/NULL,
391 /*dxfer_len*/0,
392 30 * 1000);
344 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0,
345 ata_max_mode(ident_buf, ATA_UDMA6, ATA_UDMA6));
393 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
346 break;
394 break;
395 }
347 case PROBE_SET_MULTI:
348 {
396 case PROBE_SET_MULTI:
397 {
349 struct ccb_trans_settings cts;
350 u_int sectors;
351
352 sectors = max(1, min(ident_buf->sectors_intr & 0xff, 16));
353
354 /* Report bytecount to SIM. */
355 bzero(&cts, sizeof(cts));
356 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
357 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;

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

559 }
560 }
561 return (1);
562}
563#endif
564static void
565probedone(struct cam_periph *periph, union ccb *done_ccb)
566{
398 u_int sectors;
399
400 sectors = max(1, min(ident_buf->sectors_intr & 0xff, 16));
401
402 /* Report bytecount to SIM. */
403 bzero(&cts, sizeof(cts));
404 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
405 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;

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

607 }
608 }
609 return (1);
610}
611#endif
612static void
613probedone(struct cam_periph *periph, union ccb *done_ccb)
614{
615 struct ccb_trans_settings cts;
567 struct ata_params *ident_buf;
568 probe_softc *softc;
569 struct cam_path *path;
570 u_int32_t priority;
571 int found = 1;
572
573 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
574

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

614 done_ccb->ataio.res.lba_mid;
615 xpt_print(path, "SIGNATURE: %04x\n", sign);
616 if (sign == 0x0000 &&
617 done_ccb->ccb_h.target_id != 15) {
618 path->device->protocol = PROTO_ATA;
619 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
620 } else if (sign == 0x9669 &&
621 done_ccb->ccb_h.target_id == 15) {
616 struct ata_params *ident_buf;
617 probe_softc *softc;
618 struct cam_path *path;
619 u_int32_t priority;
620 int found = 1;
621
622 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
623

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

663 done_ccb->ataio.res.lba_mid;
664 xpt_print(path, "SIGNATURE: %04x\n", sign);
665 if (sign == 0x0000 &&
666 done_ccb->ccb_h.target_id != 15) {
667 path->device->protocol = PROTO_ATA;
668 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
669 } else if (sign == 0x9669 &&
670 done_ccb->ccb_h.target_id == 15) {
622 struct ccb_trans_settings cts;
623
624 /* Report SIM that PM is present. */
671 /* Report SIM that PM is present. */
625 bzero(&cts, sizeof(cts));
626 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
627 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
628 cts.type = CTS_TYPE_CURRENT_SETTINGS;
629 cts.xport_specific.sata.pm_present = 1;
630 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
631 xpt_action((union ccb *)&cts);
632 path->device->protocol = PROTO_SATAPM;

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

711
712 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
713 }
714 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
715 path->device->mintags = path->device->maxtags =
716 ATA_QUEUE_LEN(ident_buf->queue) + 1;
717 }
718 ata_find_quirk(path->device);
672 bzero(&cts, sizeof(cts));
673 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
674 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
675 cts.type = CTS_TYPE_CURRENT_SETTINGS;
676 cts.xport_specific.sata.pm_present = 1;
677 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
678 xpt_action((union ccb *)&cts);
679 path->device->protocol = PROTO_SATAPM;

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

758
759 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
760 }
761 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
762 path->device->mintags = path->device->maxtags =
763 ATA_QUEUE_LEN(ident_buf->queue) + 1;
764 }
765 ata_find_quirk(path->device);
719 /* XXX: If not all tags allowed, we must to tell SIM which are. */
720 if (path->device->mintags < path->bus->sim->max_tagged_dev_openings)
721 path->device->mintags = path->device->maxtags = 0;
722 if (path->device->mintags != 0 &&
723 path->bus->sim->max_tagged_dev_openings != 0) {
766 if (path->device->mintags != 0 &&
767 path->bus->sim->max_tagged_dev_openings != 0) {
768 /* Report SIM which tags are allowed. */
769 bzero(&cts, sizeof(cts));
770 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
771 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
772 cts.type = CTS_TYPE_CURRENT_SETTINGS;
773 cts.xport_specific.sata.tags = path->device->maxtags;
774 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
775 xpt_action((union ccb *)&cts);
776 /* Reconfigure queues for tagged queueing. */
724 xpt_start_tags(path);
725 }
726 ata_device_transport(path);
727 PROBE_SET_ACTION(softc, PROBE_SETMODE);
728 xpt_release_ccb(done_ccb);
729 xpt_schedule(periph, priority);
730 return;
731 }

--- 719 unchanged lines hidden ---
777 xpt_start_tags(path);
778 }
779 ata_device_transport(path);
780 PROBE_SET_ACTION(softc, PROBE_SETMODE);
781 xpt_release_ccb(done_ccb);
782 xpt_schedule(periph, priority);
783 return;
784 }

--- 719 unchanged lines hidden ---