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 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 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 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 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 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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> 37#include <sys/time.h> 38#include <sys/conf.h> 39#include <sys/fcntl.h> 40#include <sys/md5.h> 41#include <sys/interrupt.h> 42#include <sys/sbuf.h> 43 44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/sysctl.h> 47 48#ifdef PC98 49#include <pc98/pc98/pc98_machdep.h> /* geometry translation */ 50#endif 51 52#include <cam/cam.h> 53#include <cam/cam_ccb.h> 54#include <cam/cam_queue.h> 55#include <cam/cam_periph.h> 56#include <cam/cam_sim.h> 57#include <cam/cam_xpt.h> 58#include <cam/cam_xpt_sim.h> 59#include <cam/cam_xpt_periph.h> 60#include <cam/cam_xpt_internal.h> 61#include <cam/cam_debug.h> 62 63#include <cam/scsi/scsi_all.h> 64#include <cam/scsi/scsi_message.h> 65#include <cam/ata/ata_all.h> 66#include <machine/stdarg.h> /* for xpt_print below */ 67#include "opt_cam.h" 68 69struct ata_quirk_entry { 70 struct scsi_inquiry_pattern inq_pat; 71 u_int8_t quirks; 72#define CAM_QUIRK_MAXTAGS 0x01 73 u_int maxtags; 74}; 75 76static periph_init_t probe_periph_init; 77 78static struct periph_driver probe_driver = 79{ 80 probe_periph_init, "aprobe", 81 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0, 82 CAM_PERIPH_DRV_EARLY 83}; 84 85PERIPHDRIVER_DECLARE(aprobe, probe_driver); 86 87typedef enum { 88 PROBE_RESET, 89 PROBE_IDENTIFY, 90 PROBE_SETMODE, 91 PROBE_SET_MULTI, 92 PROBE_INQUIRY, 93 PROBE_FULL_INQUIRY, 94 PROBE_PM_PID, 95 PROBE_PM_PRV, 96 PROBE_INVALID 97} probe_action; 98 99static char *probe_action_text[] = { 100 "PROBE_RESET", 101 "PROBE_IDENTIFY", 102 "PROBE_SETMODE", 103 "PROBE_SET_MULTI", 104 "PROBE_INQUIRY", 105 "PROBE_FULL_INQUIRY", 106 "PROBE_PM_PID", 107 "PROBE_PM_PRV", 108 "PROBE_INVALID" 109}; 110 111#define PROBE_SET_ACTION(softc, newaction) \ 112do { \ 113 char **text; \ 114 text = probe_action_text; \ 115 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \ 116 ("Probe %s to %s\n", text[(softc)->action], \ 117 text[(newaction)])); \ 118 (softc)->action = (newaction); \ 119} while(0) 120 121typedef enum { 122 PROBE_NO_ANNOUNCE = 0x04 123} probe_flags; 124 125typedef struct { 126 TAILQ_HEAD(, ccb_hdr) request_ccbs; 127 probe_action action; 128 union ccb saved_ccb; 129 probe_flags flags; 130 u_int8_t digest[16]; 131 uint32_t pm_pid; 132 uint32_t pm_prv; 133 struct cam_periph *periph; 134} probe_softc; 135 136static struct ata_quirk_entry ata_quirk_table[] = 137{ 138 { 139 /* Default tagged queuing parameters for all devices */ 140 { 141 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, 142 /*vendor*/"*", /*product*/"*", /*revision*/"*" 143 }, 144 /*quirks*/0, /*maxtags*/0 145 }, 146}; 147 148static const int ata_quirk_table_size = 149 sizeof(ata_quirk_table) / sizeof(*ata_quirk_table); 150 151static cam_status proberegister(struct cam_periph *periph, 152 void *arg); 153static void probeschedule(struct cam_periph *probe_periph); 154static void probestart(struct cam_periph *periph, union ccb *start_ccb); 155//static void proberequestdefaultnegotiation(struct cam_periph *periph); 156//static int proberequestbackoff(struct cam_periph *periph, 157// struct cam_ed *device); 158static void probedone(struct cam_periph *periph, union ccb *done_ccb); 159static void probecleanup(struct cam_periph *periph); 160static void ata_find_quirk(struct cam_ed *device); 161static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb); 162static void ata_scan_lun(struct cam_periph *periph, 163 struct cam_path *path, cam_flags flags, 164 union ccb *ccb); 165static void xptscandone(struct cam_periph *periph, union ccb *done_ccb); 166static struct cam_ed * 167 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, 168 lun_id_t lun_id); 169static void ata_device_transport(struct cam_path *path); 170static void ata_set_transfer_settings(struct ccb_trans_settings *cts, 171 struct cam_ed *device, 172 int async_update); 173static void ata_dev_async(u_int32_t async_code, 174 struct cam_eb *bus, 175 struct cam_et *target, 176 struct cam_ed *device, 177 void *async_arg); 178static void ata_action(union ccb *start_ccb); 179 180static struct xpt_xport ata_xport = { 181 .alloc_device = ata_alloc_device, 182 .action = ata_action, 183 .async = ata_dev_async, 184}; 185 186struct xpt_xport * 187ata_get_xport(void) 188{ 189 return (&ata_xport); 190} 191 192static void 193probe_periph_init() 194{ 195} 196 197static cam_status 198proberegister(struct cam_periph *periph, void *arg) 199{ 200 union ccb *request_ccb; /* CCB representing the probe request */ 201 cam_status status; 202 probe_softc *softc; 203 204 request_ccb = (union ccb *)arg; 205 if (periph == NULL) { 206 printf("proberegister: periph was NULL!!\n"); 207 return(CAM_REQ_CMP_ERR); 208 } 209 210 if (request_ccb == NULL) { 211 printf("proberegister: no probe CCB, " 212 "can't register device\n"); 213 return(CAM_REQ_CMP_ERR); 214 } 215 216 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT); 217 218 if (softc == NULL) { 219 printf("proberegister: Unable to probe new device. " 220 "Unable to allocate softc\n"); 221 return(CAM_REQ_CMP_ERR); 222 } 223 TAILQ_INIT(&softc->request_ccbs); 224 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 225 periph_links.tqe); 226 softc->flags = 0; 227 periph->softc = softc; 228 softc->periph = periph; 229 softc->action = PROBE_INVALID; 230 status = cam_periph_acquire(periph); 231 if (status != CAM_REQ_CMP) { 232 return (status); 233 } 234 235 236 /* 237 * Ensure we've waited at least a bus settle 238 * delay before attempting to probe the device. 239 * For HBAs that don't do bus resets, this won't make a difference. 240 */ 241 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset, 242 scsi_delay); 243 probeschedule(periph); 244 return(CAM_REQ_CMP); 245} 246 247static void 248probeschedule(struct cam_periph *periph) 249{ 250 struct ccb_pathinq cpi; 251 union ccb *ccb; 252 probe_softc *softc; 253 254 softc = (probe_softc *)periph->softc; 255 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 256 257 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 258 cpi.ccb_h.func_code = XPT_PATH_INQ; 259 xpt_action((union ccb *)&cpi); 260 261 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) || 262 periph->path->device->protocol == PROTO_SATAPM) 263 PROBE_SET_ACTION(softc, PROBE_RESET); 264 else 265 PROBE_SET_ACTION(softc, PROBE_IDENTIFY); 266 267 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE) 268 softc->flags |= PROBE_NO_ANNOUNCE; 269 else 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> 37#include <sys/time.h> 38#include <sys/conf.h> 39#include <sys/fcntl.h> 40#include <sys/md5.h> 41#include <sys/interrupt.h> 42#include <sys/sbuf.h> 43 44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/sysctl.h> 47 48#ifdef PC98 49#include <pc98/pc98/pc98_machdep.h> /* geometry translation */ 50#endif 51 52#include <cam/cam.h> 53#include <cam/cam_ccb.h> 54#include <cam/cam_queue.h> 55#include <cam/cam_periph.h> 56#include <cam/cam_sim.h> 57#include <cam/cam_xpt.h> 58#include <cam/cam_xpt_sim.h> 59#include <cam/cam_xpt_periph.h> 60#include <cam/cam_xpt_internal.h> 61#include <cam/cam_debug.h> 62 63#include <cam/scsi/scsi_all.h> 64#include <cam/scsi/scsi_message.h> 65#include <cam/ata/ata_all.h> 66#include <machine/stdarg.h> /* for xpt_print below */ 67#include "opt_cam.h" 68 69struct ata_quirk_entry { 70 struct scsi_inquiry_pattern inq_pat; 71 u_int8_t quirks; 72#define CAM_QUIRK_MAXTAGS 0x01 73 u_int maxtags; 74}; 75 76static periph_init_t probe_periph_init; 77 78static struct periph_driver probe_driver = 79{ 80 probe_periph_init, "aprobe", 81 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0, 82 CAM_PERIPH_DRV_EARLY 83}; 84 85PERIPHDRIVER_DECLARE(aprobe, probe_driver); 86 87typedef enum { 88 PROBE_RESET, 89 PROBE_IDENTIFY, 90 PROBE_SETMODE, 91 PROBE_SET_MULTI, 92 PROBE_INQUIRY, 93 PROBE_FULL_INQUIRY, 94 PROBE_PM_PID, 95 PROBE_PM_PRV, 96 PROBE_INVALID 97} probe_action; 98 99static char *probe_action_text[] = { 100 "PROBE_RESET", 101 "PROBE_IDENTIFY", 102 "PROBE_SETMODE", 103 "PROBE_SET_MULTI", 104 "PROBE_INQUIRY", 105 "PROBE_FULL_INQUIRY", 106 "PROBE_PM_PID", 107 "PROBE_PM_PRV", 108 "PROBE_INVALID" 109}; 110 111#define PROBE_SET_ACTION(softc, newaction) \ 112do { \ 113 char **text; \ 114 text = probe_action_text; \ 115 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \ 116 ("Probe %s to %s\n", text[(softc)->action], \ 117 text[(newaction)])); \ 118 (softc)->action = (newaction); \ 119} while(0) 120 121typedef enum { 122 PROBE_NO_ANNOUNCE = 0x04 123} probe_flags; 124 125typedef struct { 126 TAILQ_HEAD(, ccb_hdr) request_ccbs; 127 probe_action action; 128 union ccb saved_ccb; 129 probe_flags flags; 130 u_int8_t digest[16]; 131 uint32_t pm_pid; 132 uint32_t pm_prv; 133 struct cam_periph *periph; 134} probe_softc; 135 136static struct ata_quirk_entry ata_quirk_table[] = 137{ 138 { 139 /* Default tagged queuing parameters for all devices */ 140 { 141 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, 142 /*vendor*/"*", /*product*/"*", /*revision*/"*" 143 }, 144 /*quirks*/0, /*maxtags*/0 145 }, 146}; 147 148static const int ata_quirk_table_size = 149 sizeof(ata_quirk_table) / sizeof(*ata_quirk_table); 150 151static cam_status proberegister(struct cam_periph *periph, 152 void *arg); 153static void probeschedule(struct cam_periph *probe_periph); 154static void probestart(struct cam_periph *periph, union ccb *start_ccb); 155//static void proberequestdefaultnegotiation(struct cam_periph *periph); 156//static int proberequestbackoff(struct cam_periph *periph, 157// struct cam_ed *device); 158static void probedone(struct cam_periph *periph, union ccb *done_ccb); 159static void probecleanup(struct cam_periph *periph); 160static void ata_find_quirk(struct cam_ed *device); 161static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb); 162static void ata_scan_lun(struct cam_periph *periph, 163 struct cam_path *path, cam_flags flags, 164 union ccb *ccb); 165static void xptscandone(struct cam_periph *periph, union ccb *done_ccb); 166static struct cam_ed * 167 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, 168 lun_id_t lun_id); 169static void ata_device_transport(struct cam_path *path); 170static void ata_set_transfer_settings(struct ccb_trans_settings *cts, 171 struct cam_ed *device, 172 int async_update); 173static void ata_dev_async(u_int32_t async_code, 174 struct cam_eb *bus, 175 struct cam_et *target, 176 struct cam_ed *device, 177 void *async_arg); 178static void ata_action(union ccb *start_ccb); 179 180static struct xpt_xport ata_xport = { 181 .alloc_device = ata_alloc_device, 182 .action = ata_action, 183 .async = ata_dev_async, 184}; 185 186struct xpt_xport * 187ata_get_xport(void) 188{ 189 return (&ata_xport); 190} 191 192static void 193probe_periph_init() 194{ 195} 196 197static cam_status 198proberegister(struct cam_periph *periph, void *arg) 199{ 200 union ccb *request_ccb; /* CCB representing the probe request */ 201 cam_status status; 202 probe_softc *softc; 203 204 request_ccb = (union ccb *)arg; 205 if (periph == NULL) { 206 printf("proberegister: periph was NULL!!\n"); 207 return(CAM_REQ_CMP_ERR); 208 } 209 210 if (request_ccb == NULL) { 211 printf("proberegister: no probe CCB, " 212 "can't register device\n"); 213 return(CAM_REQ_CMP_ERR); 214 } 215 216 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT); 217 218 if (softc == NULL) { 219 printf("proberegister: Unable to probe new device. " 220 "Unable to allocate softc\n"); 221 return(CAM_REQ_CMP_ERR); 222 } 223 TAILQ_INIT(&softc->request_ccbs); 224 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 225 periph_links.tqe); 226 softc->flags = 0; 227 periph->softc = softc; 228 softc->periph = periph; 229 softc->action = PROBE_INVALID; 230 status = cam_periph_acquire(periph); 231 if (status != CAM_REQ_CMP) { 232 return (status); 233 } 234 235 236 /* 237 * Ensure we've waited at least a bus settle 238 * delay before attempting to probe the device. 239 * For HBAs that don't do bus resets, this won't make a difference. 240 */ 241 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset, 242 scsi_delay); 243 probeschedule(periph); 244 return(CAM_REQ_CMP); 245} 246 247static void 248probeschedule(struct cam_periph *periph) 249{ 250 struct ccb_pathinq cpi; 251 union ccb *ccb; 252 probe_softc *softc; 253 254 softc = (probe_softc *)periph->softc; 255 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 256 257 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 258 cpi.ccb_h.func_code = XPT_PATH_INQ; 259 xpt_action((union ccb *)&cpi); 260 261 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) || 262 periph->path->device->protocol == PROTO_SATAPM) 263 PROBE_SET_ACTION(softc, PROBE_RESET); 264 else 265 PROBE_SET_ACTION(softc, PROBE_IDENTIFY); 266 267 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE) 268 softc->flags |= PROBE_NO_ANNOUNCE; 269 else 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 287 softc = (probe_softc *)periph->softc; 288 path = start_ccb->ccb_h.path; 289 ataio = &start_ccb->ataio; 290 csio = &start_ccb->csio; 291 ident_buf = &periph->path->device->ident_data; 292 293 switch (softc->action) { 294 case PROBE_RESET: 295 cam_fill_ataio(ataio, 296 0, 297 probedone, 298 /*flags*/CAM_DIR_NONE, 299 0, 300 /*data_ptr*/NULL, 301 /*dxfer_len*/0, 302 (start_ccb->ccb_h.target_id == 15 ? 3 : 15) * 1000); 303 ata_reset_cmd(ataio); 304 break; 305 case PROBE_IDENTIFY: 306 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 307 /* Prepare check that it is the same device. */ 308 MD5_CTX context; 309 310 MD5Init(&context); 311 MD5Update(&context, 312 (unsigned char *)ident_buf->model, 313 sizeof(ident_buf->model)); 314 MD5Update(&context, 315 (unsigned char *)ident_buf->revision, 316 sizeof(ident_buf->revision)); 317 MD5Update(&context, 318 (unsigned char *)ident_buf->serial, 319 sizeof(ident_buf->serial)); 320 MD5Final(softc->digest, &context); 321 } 322 cam_fill_ataio(ataio, 323 1, 324 probedone, 325 /*flags*/CAM_DIR_IN, 326 0, 327 /*data_ptr*/(u_int8_t *)ident_buf, 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 287 softc = (probe_softc *)periph->softc; 288 path = start_ccb->ccb_h.path; 289 ataio = &start_ccb->ataio; 290 csio = &start_ccb->csio; 291 ident_buf = &periph->path->device->ident_data; 292 293 switch (softc->action) { 294 case PROBE_RESET: 295 cam_fill_ataio(ataio, 296 0, 297 probedone, 298 /*flags*/CAM_DIR_NONE, 299 0, 300 /*data_ptr*/NULL, 301 /*dxfer_len*/0, 302 (start_ccb->ccb_h.target_id == 15 ? 3 : 15) * 1000); 303 ata_reset_cmd(ataio); 304 break; 305 case PROBE_IDENTIFY: 306 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 307 /* Prepare check that it is the same device. */ 308 MD5_CTX context; 309 310 MD5Init(&context); 311 MD5Update(&context, 312 (unsigned char *)ident_buf->model, 313 sizeof(ident_buf->model)); 314 MD5Update(&context, 315 (unsigned char *)ident_buf->revision, 316 sizeof(ident_buf->revision)); 317 MD5Update(&context, 318 (unsigned char *)ident_buf->serial, 319 sizeof(ident_buf->serial)); 320 MD5Final(softc->digest, &context); 321 } 322 cam_fill_ataio(ataio, 323 1, 324 probedone, 325 /*flags*/CAM_DIR_IN, 326 0, 327 /*data_ptr*/(u_int8_t *)ident_buf, 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; 358 cts.type = CTS_TYPE_CURRENT_SETTINGS; 359 if (path->device->transport == XPORT_ATA) { 360 cts.xport_specific.ata.bytecount = sectors * 361 ata_logical_sector_size(ident_buf); 362 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT; 363 } else { 364 cts.xport_specific.sata.bytecount = sectors * 365 ata_logical_sector_size(ident_buf); 366 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT; 367 } 368 xpt_action((union ccb *)&cts); 369 370 cam_fill_ataio(ataio, 371 1, 372 probedone, 373 CAM_DIR_NONE, 374 0, 375 NULL, 376 0, 377 30*1000); 378 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors); 379 break; 380 } 381 case PROBE_INQUIRY: 382 case PROBE_FULL_INQUIRY: 383 { 384 u_int inquiry_len; 385 struct scsi_inquiry_data *inq_buf = 386 &periph->path->device->inq_data; 387 388 if (softc->action == PROBE_INQUIRY) 389 inquiry_len = SHORT_INQUIRY_LENGTH; 390 else 391 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf); 392 /* 393 * Some parallel SCSI devices fail to send an 394 * ignore wide residue message when dealing with 395 * odd length inquiry requests. Round up to be 396 * safe. 397 */ 398 inquiry_len = roundup2(inquiry_len, 2); 399 scsi_inquiry(csio, 400 /*retries*/1, 401 probedone, 402 MSG_SIMPLE_Q_TAG, 403 (u_int8_t *)inq_buf, 404 inquiry_len, 405 /*evpd*/FALSE, 406 /*page_code*/0, 407 SSD_MIN_SIZE, 408 /*timeout*/60 * 1000); 409 break; 410 } 411 case PROBE_PM_PID: 412 cam_fill_ataio(ataio, 413 1, 414 probedone, 415 /*flags*/CAM_DIR_NONE, 416 0, 417 /*data_ptr*/NULL, 418 /*dxfer_len*/0, 419 10 * 1000); 420 ata_pm_read_cmd(ataio, 0, 15); 421 break; 422 case PROBE_PM_PRV: 423 cam_fill_ataio(ataio, 424 1, 425 probedone, 426 /*flags*/CAM_DIR_NONE, 427 0, 428 /*data_ptr*/NULL, 429 /*dxfer_len*/0, 430 10 * 1000); 431 ata_pm_read_cmd(ataio, 1, 15); 432 break; 433 case PROBE_INVALID: 434 CAM_DEBUG(path, CAM_DEBUG_INFO, 435 ("probestart: invalid action state\n")); 436 default: 437 break; 438 } 439 xpt_action(start_ccb); 440} 441#if 0 442static void 443proberequestdefaultnegotiation(struct cam_periph *periph) 444{ 445 struct ccb_trans_settings cts; 446 447 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 448 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 449 cts.type = CTS_TYPE_USER_SETTINGS; 450 xpt_action((union ccb *)&cts); 451 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 452 return; 453 } 454 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 455 cts.type = CTS_TYPE_CURRENT_SETTINGS; 456 xpt_action((union ccb *)&cts); 457} 458 459/* 460 * Backoff Negotiation Code- only pertinent for SPI devices. 461 */ 462static int 463proberequestbackoff(struct cam_periph *periph, struct cam_ed *device) 464{ 465 struct ccb_trans_settings cts; 466 struct ccb_trans_settings_spi *spi; 467 468 memset(&cts, 0, sizeof (cts)); 469 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 470 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 471 cts.type = CTS_TYPE_CURRENT_SETTINGS; 472 xpt_action((union ccb *)&cts); 473 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 474 if (bootverbose) { 475 xpt_print(periph->path, 476 "failed to get current device settings\n"); 477 } 478 return (0); 479 } 480 if (cts.transport != XPORT_SPI) { 481 if (bootverbose) { 482 xpt_print(periph->path, "not SPI transport\n"); 483 } 484 return (0); 485 } 486 spi = &cts.xport_specific.spi; 487 488 /* 489 * We cannot renegotiate sync rate if we don't have one. 490 */ 491 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) { 492 if (bootverbose) { 493 xpt_print(periph->path, "no sync rate known\n"); 494 } 495 return (0); 496 } 497 498 /* 499 * We'll assert that we don't have to touch PPR options- the 500 * SIM will see what we do with period and offset and adjust 501 * the PPR options as appropriate. 502 */ 503 504 /* 505 * A sync rate with unknown or zero offset is nonsensical. 506 * A sync period of zero means Async. 507 */ 508 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0 509 || spi->sync_offset == 0 || spi->sync_period == 0) { 510 if (bootverbose) { 511 xpt_print(periph->path, "no sync rate available\n"); 512 } 513 return (0); 514 } 515 516 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) { 517 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 518 ("hit async: giving up on DV\n")); 519 return (0); 520 } 521 522 523 /* 524 * Jump sync_period up by one, but stop at 5MHz and fall back to Async. 525 * We don't try to remember 'last' settings to see if the SIM actually 526 * gets into the speed we want to set. We check on the SIM telling 527 * us that a requested speed is bad, but otherwise don't try and 528 * check the speed due to the asynchronous and handshake nature 529 * of speed setting. 530 */ 531 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET; 532 for (;;) { 533 spi->sync_period++; 534 if (spi->sync_period >= 0xf) { 535 spi->sync_period = 0; 536 spi->sync_offset = 0; 537 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 538 ("setting to async for DV\n")); 539 /* 540 * Once we hit async, we don't want to try 541 * any more settings. 542 */ 543 device->flags |= CAM_DEV_DV_HIT_BOTTOM; 544 } else if (bootverbose) { 545 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 546 ("DV: period 0x%x\n", spi->sync_period)); 547 printf("setting period to 0x%x\n", spi->sync_period); 548 } 549 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 550 cts.type = CTS_TYPE_CURRENT_SETTINGS; 551 xpt_action((union ccb *)&cts); 552 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 553 break; 554 } 555 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 556 ("DV: failed to set period 0x%x\n", spi->sync_period)); 557 if (spi->sync_period == 0) { 558 return (0); 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; 406 cts.type = CTS_TYPE_CURRENT_SETTINGS; 407 if (path->device->transport == XPORT_ATA) { 408 cts.xport_specific.ata.bytecount = sectors * 409 ata_logical_sector_size(ident_buf); 410 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT; 411 } else { 412 cts.xport_specific.sata.bytecount = sectors * 413 ata_logical_sector_size(ident_buf); 414 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT; 415 } 416 xpt_action((union ccb *)&cts); 417 418 cam_fill_ataio(ataio, 419 1, 420 probedone, 421 CAM_DIR_NONE, 422 0, 423 NULL, 424 0, 425 30*1000); 426 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors); 427 break; 428 } 429 case PROBE_INQUIRY: 430 case PROBE_FULL_INQUIRY: 431 { 432 u_int inquiry_len; 433 struct scsi_inquiry_data *inq_buf = 434 &periph->path->device->inq_data; 435 436 if (softc->action == PROBE_INQUIRY) 437 inquiry_len = SHORT_INQUIRY_LENGTH; 438 else 439 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf); 440 /* 441 * Some parallel SCSI devices fail to send an 442 * ignore wide residue message when dealing with 443 * odd length inquiry requests. Round up to be 444 * safe. 445 */ 446 inquiry_len = roundup2(inquiry_len, 2); 447 scsi_inquiry(csio, 448 /*retries*/1, 449 probedone, 450 MSG_SIMPLE_Q_TAG, 451 (u_int8_t *)inq_buf, 452 inquiry_len, 453 /*evpd*/FALSE, 454 /*page_code*/0, 455 SSD_MIN_SIZE, 456 /*timeout*/60 * 1000); 457 break; 458 } 459 case PROBE_PM_PID: 460 cam_fill_ataio(ataio, 461 1, 462 probedone, 463 /*flags*/CAM_DIR_NONE, 464 0, 465 /*data_ptr*/NULL, 466 /*dxfer_len*/0, 467 10 * 1000); 468 ata_pm_read_cmd(ataio, 0, 15); 469 break; 470 case PROBE_PM_PRV: 471 cam_fill_ataio(ataio, 472 1, 473 probedone, 474 /*flags*/CAM_DIR_NONE, 475 0, 476 /*data_ptr*/NULL, 477 /*dxfer_len*/0, 478 10 * 1000); 479 ata_pm_read_cmd(ataio, 1, 15); 480 break; 481 case PROBE_INVALID: 482 CAM_DEBUG(path, CAM_DEBUG_INFO, 483 ("probestart: invalid action state\n")); 484 default: 485 break; 486 } 487 xpt_action(start_ccb); 488} 489#if 0 490static void 491proberequestdefaultnegotiation(struct cam_periph *periph) 492{ 493 struct ccb_trans_settings cts; 494 495 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 496 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 497 cts.type = CTS_TYPE_USER_SETTINGS; 498 xpt_action((union ccb *)&cts); 499 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 500 return; 501 } 502 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 503 cts.type = CTS_TYPE_CURRENT_SETTINGS; 504 xpt_action((union ccb *)&cts); 505} 506 507/* 508 * Backoff Negotiation Code- only pertinent for SPI devices. 509 */ 510static int 511proberequestbackoff(struct cam_periph *periph, struct cam_ed *device) 512{ 513 struct ccb_trans_settings cts; 514 struct ccb_trans_settings_spi *spi; 515 516 memset(&cts, 0, sizeof (cts)); 517 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 518 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 519 cts.type = CTS_TYPE_CURRENT_SETTINGS; 520 xpt_action((union ccb *)&cts); 521 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 522 if (bootverbose) { 523 xpt_print(periph->path, 524 "failed to get current device settings\n"); 525 } 526 return (0); 527 } 528 if (cts.transport != XPORT_SPI) { 529 if (bootverbose) { 530 xpt_print(periph->path, "not SPI transport\n"); 531 } 532 return (0); 533 } 534 spi = &cts.xport_specific.spi; 535 536 /* 537 * We cannot renegotiate sync rate if we don't have one. 538 */ 539 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) { 540 if (bootverbose) { 541 xpt_print(periph->path, "no sync rate known\n"); 542 } 543 return (0); 544 } 545 546 /* 547 * We'll assert that we don't have to touch PPR options- the 548 * SIM will see what we do with period and offset and adjust 549 * the PPR options as appropriate. 550 */ 551 552 /* 553 * A sync rate with unknown or zero offset is nonsensical. 554 * A sync period of zero means Async. 555 */ 556 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0 557 || spi->sync_offset == 0 || spi->sync_period == 0) { 558 if (bootverbose) { 559 xpt_print(periph->path, "no sync rate available\n"); 560 } 561 return (0); 562 } 563 564 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) { 565 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 566 ("hit async: giving up on DV\n")); 567 return (0); 568 } 569 570 571 /* 572 * Jump sync_period up by one, but stop at 5MHz and fall back to Async. 573 * We don't try to remember 'last' settings to see if the SIM actually 574 * gets into the speed we want to set. We check on the SIM telling 575 * us that a requested speed is bad, but otherwise don't try and 576 * check the speed due to the asynchronous and handshake nature 577 * of speed setting. 578 */ 579 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET; 580 for (;;) { 581 spi->sync_period++; 582 if (spi->sync_period >= 0xf) { 583 spi->sync_period = 0; 584 spi->sync_offset = 0; 585 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 586 ("setting to async for DV\n")); 587 /* 588 * Once we hit async, we don't want to try 589 * any more settings. 590 */ 591 device->flags |= CAM_DEV_DV_HIT_BOTTOM; 592 } else if (bootverbose) { 593 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 594 ("DV: period 0x%x\n", spi->sync_period)); 595 printf("setting period to 0x%x\n", spi->sync_period); 596 } 597 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 598 cts.type = CTS_TYPE_CURRENT_SETTINGS; 599 xpt_action((union ccb *)&cts); 600 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 601 break; 602 } 603 CAM_DEBUG(periph->path, CAM_DEBUG_INFO, 604 ("DV: failed to set period 0x%x\n", spi->sync_period)); 605 if (spi->sync_period == 0) { 606 return (0); 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 575 softc = (probe_softc *)periph->softc; 576 path = done_ccb->ccb_h.path; 577 priority = done_ccb->ccb_h.pinfo.priority; 578 ident_buf = &path->device->ident_data; 579 580 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 581device_fail: if (cam_periph_error(done_ccb, 0, 0, 582 &softc->saved_ccb) == ERESTART) { 583 return; 584 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 585 /* Don't wedge the queue */ 586 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 587 /*run_queue*/TRUE); 588 } 589 /* Old PIO2 devices may not support mode setting. */ 590 if (softc->action == PROBE_SETMODE && 591 ata_max_pmode(ident_buf) <= ATA_PIO2 && 592 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) 593 goto noerror; 594 /* 595 * If we get to this point, we got an error status back 596 * from the inquiry and the error status doesn't require 597 * automatically retrying the command. Therefore, the 598 * inquiry failed. If we had inquiry information before 599 * for this device, but this latest inquiry command failed, 600 * the device has probably gone away. If this device isn't 601 * already marked unconfigured, notify the peripheral 602 * drivers that this device is no more. 603 */ 604 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 605 xpt_async(AC_LOST_DEVICE, path, NULL); 606 found = 0; 607 goto done; 608 } 609noerror: 610 switch (softc->action) { 611 case PROBE_RESET: 612 { 613 int sign = (done_ccb->ataio.res.lba_high << 8) + 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 624 softc = (probe_softc *)periph->softc; 625 path = done_ccb->ccb_h.path; 626 priority = done_ccb->ccb_h.pinfo.priority; 627 ident_buf = &path->device->ident_data; 628 629 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 630device_fail: if (cam_periph_error(done_ccb, 0, 0, 631 &softc->saved_ccb) == ERESTART) { 632 return; 633 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 634 /* Don't wedge the queue */ 635 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 636 /*run_queue*/TRUE); 637 } 638 /* Old PIO2 devices may not support mode setting. */ 639 if (softc->action == PROBE_SETMODE && 640 ata_max_pmode(ident_buf) <= ATA_PIO2 && 641 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) 642 goto noerror; 643 /* 644 * If we get to this point, we got an error status back 645 * from the inquiry and the error status doesn't require 646 * automatically retrying the command. Therefore, the 647 * inquiry failed. If we had inquiry information before 648 * for this device, but this latest inquiry command failed, 649 * the device has probably gone away. If this device isn't 650 * already marked unconfigured, notify the peripheral 651 * drivers that this device is no more. 652 */ 653 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 654 xpt_async(AC_LOST_DEVICE, path, NULL); 655 found = 0; 656 goto done; 657 } 658noerror: 659 switch (softc->action) { 660 case PROBE_RESET: 661 { 662 int sign = (done_ccb->ataio.res.lba_high << 8) + 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; 633 PROBE_SET_ACTION(softc, PROBE_PM_PID); 634 } else if (sign == 0xeb14 && 635 done_ccb->ccb_h.target_id != 15) { 636 path->device->protocol = PROTO_SCSI; 637 PROBE_SET_ACTION(softc, PROBE_IDENTIFY); 638 } else { 639 if (done_ccb->ccb_h.target_id != 15) { 640 xpt_print(path, 641 "Unexpected signature 0x%04x\n", sign); 642 } 643 goto device_fail; 644 } 645 xpt_release_ccb(done_ccb); 646 xpt_schedule(periph, priority); 647 return; 648 } 649 case PROBE_IDENTIFY: 650 { 651 int16_t *ptr; 652 653 for (ptr = (int16_t *)ident_buf; 654 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) { 655 *ptr = le16toh(*ptr); 656 } 657 if (strncmp(ident_buf->model, "FX", 2) && 658 strncmp(ident_buf->model, "NEC", 3) && 659 strncmp(ident_buf->model, "Pioneer", 7) && 660 strncmp(ident_buf->model, "SHARP", 5)) { 661 ata_bswap(ident_buf->model, sizeof(ident_buf->model)); 662 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision)); 663 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial)); 664 } 665 ata_btrim(ident_buf->model, sizeof(ident_buf->model)); 666 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model)); 667 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision)); 668 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision)); 669 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial)); 670 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial)); 671 672 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 673 /* Check that it is the same device. */ 674 MD5_CTX context; 675 u_int8_t digest[16]; 676 677 MD5Init(&context); 678 MD5Update(&context, 679 (unsigned char *)ident_buf->model, 680 sizeof(ident_buf->model)); 681 MD5Update(&context, 682 (unsigned char *)ident_buf->revision, 683 sizeof(ident_buf->revision)); 684 MD5Update(&context, 685 (unsigned char *)ident_buf->serial, 686 sizeof(ident_buf->serial)); 687 MD5Final(digest, &context); 688 if (bcmp(digest, softc->digest, sizeof(digest))) { 689 /* Device changed. */ 690 xpt_async(AC_LOST_DEVICE, path, NULL); 691 } 692 } else { 693 /* Clean up from previous instance of this device */ 694 if (path->device->serial_num != NULL) { 695 free(path->device->serial_num, M_CAMXPT); 696 path->device->serial_num = NULL; 697 path->device->serial_num_len = 0; 698 } 699 path->device->serial_num = 700 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1), 701 M_CAMXPT, M_NOWAIT); 702 if (path->device->serial_num != NULL) { 703 bcopy(ident_buf->serial, 704 path->device->serial_num, 705 sizeof(ident_buf->serial)); 706 path->device->serial_num[sizeof(ident_buf->serial)] 707 = '\0'; 708 path->device->serial_num_len = 709 strlen(path->device->serial_num); 710 } 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; 680 PROBE_SET_ACTION(softc, PROBE_PM_PID); 681 } else if (sign == 0xeb14 && 682 done_ccb->ccb_h.target_id != 15) { 683 path->device->protocol = PROTO_SCSI; 684 PROBE_SET_ACTION(softc, PROBE_IDENTIFY); 685 } else { 686 if (done_ccb->ccb_h.target_id != 15) { 687 xpt_print(path, 688 "Unexpected signature 0x%04x\n", sign); 689 } 690 goto device_fail; 691 } 692 xpt_release_ccb(done_ccb); 693 xpt_schedule(periph, priority); 694 return; 695 } 696 case PROBE_IDENTIFY: 697 { 698 int16_t *ptr; 699 700 for (ptr = (int16_t *)ident_buf; 701 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) { 702 *ptr = le16toh(*ptr); 703 } 704 if (strncmp(ident_buf->model, "FX", 2) && 705 strncmp(ident_buf->model, "NEC", 3) && 706 strncmp(ident_buf->model, "Pioneer", 7) && 707 strncmp(ident_buf->model, "SHARP", 5)) { 708 ata_bswap(ident_buf->model, sizeof(ident_buf->model)); 709 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision)); 710 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial)); 711 } 712 ata_btrim(ident_buf->model, sizeof(ident_buf->model)); 713 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model)); 714 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision)); 715 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision)); 716 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial)); 717 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial)); 718 719 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 720 /* Check that it is the same device. */ 721 MD5_CTX context; 722 u_int8_t digest[16]; 723 724 MD5Init(&context); 725 MD5Update(&context, 726 (unsigned char *)ident_buf->model, 727 sizeof(ident_buf->model)); 728 MD5Update(&context, 729 (unsigned char *)ident_buf->revision, 730 sizeof(ident_buf->revision)); 731 MD5Update(&context, 732 (unsigned char *)ident_buf->serial, 733 sizeof(ident_buf->serial)); 734 MD5Final(digest, &context); 735 if (bcmp(digest, softc->digest, sizeof(digest))) { 736 /* Device changed. */ 737 xpt_async(AC_LOST_DEVICE, path, NULL); 738 } 739 } else { 740 /* Clean up from previous instance of this device */ 741 if (path->device->serial_num != NULL) { 742 free(path->device->serial_num, M_CAMXPT); 743 path->device->serial_num = NULL; 744 path->device->serial_num_len = 0; 745 } 746 path->device->serial_num = 747 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1), 748 M_CAMXPT, M_NOWAIT); 749 if (path->device->serial_num != NULL) { 750 bcopy(ident_buf->serial, 751 path->device->serial_num, 752 sizeof(ident_buf->serial)); 753 path->device->serial_num[sizeof(ident_buf->serial)] 754 = '\0'; 755 path->device->serial_num_len = 756 strlen(path->device->serial_num); 757 } 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 } 732 case PROBE_SETMODE: 733 if (path->device->protocol == PROTO_ATA) { 734 PROBE_SET_ACTION(softc, PROBE_SET_MULTI); 735 } else { 736 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 737 } 738 xpt_release_ccb(done_ccb); 739 xpt_schedule(periph, priority); 740 return; 741 case PROBE_SET_MULTI: 742 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 743 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 744 xpt_acquire_device(path->device); 745 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 746 xpt_action(done_ccb); 747 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 748 done_ccb); 749 } 750 break; 751 case PROBE_INQUIRY: 752 case PROBE_FULL_INQUIRY: 753 { 754 struct scsi_inquiry_data *inq_buf; 755 u_int8_t periph_qual, len; 756 757 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; 758 inq_buf = &path->device->inq_data; 759 760 periph_qual = SID_QUAL(inq_buf); 761 762 if (periph_qual != SID_QUAL_LU_CONNECTED) 763 break; 764 765 /* 766 * We conservatively request only 767 * SHORT_INQUIRY_LEN bytes of inquiry 768 * information during our first try 769 * at sending an INQUIRY. If the device 770 * has more information to give, 771 * perform a second request specifying 772 * the amount of information the device 773 * is willing to give. 774 */ 775 len = inq_buf->additional_length 776 + offsetof(struct scsi_inquiry_data, additional_length) + 1; 777 if (softc->action == PROBE_INQUIRY 778 && len > SHORT_INQUIRY_LENGTH) { 779 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY); 780 xpt_release_ccb(done_ccb); 781 xpt_schedule(periph, priority); 782 return; 783 } 784 785 ata_device_transport(path); 786 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 787 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 788 xpt_acquire_device(path->device); 789 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 790 xpt_action(done_ccb); 791 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb); 792 } 793 break; 794 } 795 case PROBE_PM_PID: 796 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0) 797 bzero(ident_buf, sizeof(*ident_buf)); 798 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) + 799 (done_ccb->ataio.res.lba_mid << 16) + 800 (done_ccb->ataio.res.lba_low << 8) + 801 done_ccb->ataio.res.sector_count; 802 ((uint32_t *)ident_buf)[0] = softc->pm_pid; 803 printf("PM Product ID: %08x\n", softc->pm_pid); 804 snprintf(ident_buf->model, sizeof(ident_buf->model), 805 "Port Multiplier %08x", softc->pm_pid); 806 PROBE_SET_ACTION(softc, PROBE_PM_PRV); 807 xpt_release_ccb(done_ccb); 808 xpt_schedule(periph, priority); 809 return; 810 case PROBE_PM_PRV: 811 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) + 812 (done_ccb->ataio.res.lba_mid << 16) + 813 (done_ccb->ataio.res.lba_low << 8) + 814 done_ccb->ataio.res.sector_count; 815 ((uint32_t *)ident_buf)[1] = softc->pm_prv; 816 printf("PM Revision: %08x\n", softc->pm_prv); 817 snprintf(ident_buf->revision, sizeof(ident_buf->revision), 818 "%04x", softc->pm_prv); 819 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID; 820 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 821 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 822 xpt_acquire_device(path->device); 823 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 824 xpt_action(done_ccb); 825 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 826 done_ccb); 827 } else { 828 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 829 xpt_action(done_ccb); 830 xpt_async(AC_SCSI_AEN, done_ccb->ccb_h.path, done_ccb); 831 } 832 break; 833 case PROBE_INVALID: 834 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO, 835 ("probedone: invalid action state\n")); 836 default: 837 break; 838 } 839done: 840 xpt_release_ccb(done_ccb); 841 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 842 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); 843 done_ccb->ccb_h.status = CAM_REQ_CMP; 844 done_ccb->ccb_h.ppriv_field1 = found; 845 xpt_done(done_ccb); 846 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { 847 cam_periph_invalidate(periph); 848 cam_periph_release_locked(periph); 849 } else { 850 probeschedule(periph); 851 } 852} 853 854static void 855probecleanup(struct cam_periph *periph) 856{ 857 free(periph->softc, M_CAMXPT); 858} 859 860static void 861ata_find_quirk(struct cam_ed *device) 862{ 863 struct ata_quirk_entry *quirk; 864 caddr_t match; 865 866 match = cam_quirkmatch((caddr_t)&device->ident_data, 867 (caddr_t)ata_quirk_table, 868 ata_quirk_table_size, 869 sizeof(*ata_quirk_table), ata_identify_match); 870 871 if (match == NULL) 872 panic("xpt_find_quirk: device didn't match wildcard entry!!"); 873 874 quirk = (struct ata_quirk_entry *)match; 875 device->quirk = quirk; 876 if (quirk->quirks & CAM_QUIRK_MAXTAGS) 877 device->mintags = device->maxtags = quirk->maxtags; 878} 879 880typedef struct { 881 union ccb *request_ccb; 882 struct ccb_pathinq *cpi; 883 int counter; 884 int found; 885} ata_scan_bus_info; 886 887/* 888 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. 889 * As the scan progresses, xpt_scan_bus is used as the 890 * callback on completion function. 891 */ 892static void 893ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb) 894{ 895 struct cam_path *path; 896 ata_scan_bus_info *scan_info; 897 union ccb *work_ccb; 898 cam_status status; 899 900 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 901 ("xpt_scan_bus\n")); 902 switch (request_ccb->ccb_h.func_code) { 903 case XPT_SCAN_BUS: 904 /* Find out the characteristics of the bus */ 905 work_ccb = xpt_alloc_ccb_nowait(); 906 if (work_ccb == NULL) { 907 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 908 xpt_done(request_ccb); 909 return; 910 } 911 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path, 912 request_ccb->ccb_h.pinfo.priority); 913 work_ccb->ccb_h.func_code = XPT_PATH_INQ; 914 xpt_action(work_ccb); 915 if (work_ccb->ccb_h.status != CAM_REQ_CMP) { 916 request_ccb->ccb_h.status = work_ccb->ccb_h.status; 917 xpt_free_ccb(work_ccb); 918 xpt_done(request_ccb); 919 return; 920 } 921 922 /* Save some state for use while we probe for devices */ 923 scan_info = (ata_scan_bus_info *) 924 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT); 925 if (scan_info == NULL) { 926 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 927 xpt_done(request_ccb); 928 return; 929 } 930 scan_info->request_ccb = request_ccb; 931 scan_info->cpi = &work_ccb->cpi; 932 if (scan_info->cpi->transport == XPORT_ATA) 933 scan_info->found = 0x0003; 934 else 935 scan_info->found = 0x8001; 936 scan_info->counter = 0; 937 /* If PM supported, probe it first. */ 938 if (scan_info->cpi->hba_inquiry & PI_SATAPM) 939 scan_info->counter = 15; 940 941 work_ccb = xpt_alloc_ccb_nowait(); 942 if (work_ccb == NULL) { 943 free(scan_info, M_CAMXPT); 944 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 945 xpt_done(request_ccb); 946 break; 947 } 948 goto scan_next; 949 case XPT_SCAN_LUN: 950 work_ccb = request_ccb; 951 /* Reuse the same CCB to query if a device was really found */ 952 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0; 953 /* Free the current request path- we're done with it. */ 954 xpt_free_path(work_ccb->ccb_h.path); 955 /* If there is PMP... */ 956 if (scan_info->counter == 15) { 957 if (work_ccb->ccb_h.ppriv_field1 != 0) { 958 /* everything else willbe probed by it */ 959 scan_info->found = 0x8000; 960 } else { 961 struct ccb_trans_settings cts; 962 963 /* Report SIM that PM is absent. */ 964 bzero(&cts, sizeof(cts)); 965 xpt_setup_ccb(&cts.ccb_h, 966 scan_info->request_ccb->ccb_h.path, 1); 967 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 968 cts.type = CTS_TYPE_CURRENT_SETTINGS; 969 cts.xport_specific.sata.pm_present = 0; 970 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM; 971 xpt_action((union ccb *)&cts); 972 } 973 } 974take_next: 975 /* Take next device. Wrap from 15 (PM) to 0. */ 976 scan_info->counter = (scan_info->counter + 1 ) & 0x0f; 977 if (scan_info->counter > scan_info->cpi->max_target - 978 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ? 1 : 0)) { 979 xpt_free_ccb(work_ccb); 980 xpt_free_ccb((union ccb *)scan_info->cpi); 981 request_ccb = scan_info->request_ccb; 982 free(scan_info, M_CAMXPT); 983 request_ccb->ccb_h.status = CAM_REQ_CMP; 984 xpt_done(request_ccb); 985 break; 986 } 987scan_next: 988 if ((scan_info->found & (1 << scan_info->counter)) == 0) 989 goto take_next; 990 status = xpt_create_path(&path, xpt_periph, 991 scan_info->request_ccb->ccb_h.path_id, 992 scan_info->counter, 0); 993 if (status != CAM_REQ_CMP) { 994 printf("xpt_scan_bus: xpt_create_path failed" 995 " with status %#x, bus scan halted\n", 996 status); 997 xpt_free_ccb(work_ccb); 998 xpt_free_ccb((union ccb *)scan_info->cpi); 999 request_ccb = scan_info->request_ccb; 1000 free(scan_info, M_CAMXPT); 1001 request_ccb->ccb_h.status = status; 1002 xpt_done(request_ccb); 1003 break; 1004 } 1005 xpt_setup_ccb(&work_ccb->ccb_h, path, 1006 scan_info->request_ccb->ccb_h.pinfo.priority); 1007 work_ccb->ccb_h.func_code = XPT_SCAN_LUN; 1008 work_ccb->ccb_h.cbfcnp = ata_scan_bus; 1009 work_ccb->ccb_h.ppriv_ptr0 = scan_info; 1010 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags; 1011 xpt_action(work_ccb); 1012 break; 1013 default: 1014 break; 1015 } 1016} 1017 1018static void 1019ata_scan_lun(struct cam_periph *periph, struct cam_path *path, 1020 cam_flags flags, union ccb *request_ccb) 1021{ 1022 struct ccb_pathinq cpi; 1023 cam_status status; 1024 struct cam_path *new_path; 1025 struct cam_periph *old_periph; 1026 1027 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1028 ("xpt_scan_lun\n")); 1029 1030 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL); 1031 cpi.ccb_h.func_code = XPT_PATH_INQ; 1032 xpt_action((union ccb *)&cpi); 1033 1034 if (cpi.ccb_h.status != CAM_REQ_CMP) { 1035 if (request_ccb != NULL) { 1036 request_ccb->ccb_h.status = cpi.ccb_h.status; 1037 xpt_done(request_ccb); 1038 } 1039 return; 1040 } 1041 1042 if (request_ccb == NULL) { 1043 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT); 1044 if (request_ccb == NULL) { 1045 xpt_print(path, "xpt_scan_lun: can't allocate CCB, " 1046 "can't continue\n"); 1047 return; 1048 } 1049 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT); 1050 if (new_path == NULL) { 1051 xpt_print(path, "xpt_scan_lun: can't allocate path, " 1052 "can't continue\n"); 1053 free(request_ccb, M_CAMXPT); 1054 return; 1055 } 1056 status = xpt_compile_path(new_path, xpt_periph, 1057 path->bus->path_id, 1058 path->target->target_id, 1059 path->device->lun_id); 1060 1061 if (status != CAM_REQ_CMP) { 1062 xpt_print(path, "xpt_scan_lun: can't compile path, " 1063 "can't continue\n"); 1064 free(request_ccb, M_CAMXPT); 1065 free(new_path, M_CAMXPT); 1066 return; 1067 } 1068 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_NORMAL); 1069 request_ccb->ccb_h.cbfcnp = xptscandone; 1070 request_ccb->ccb_h.func_code = XPT_SCAN_LUN; 1071 request_ccb->crcn.flags = flags; 1072 } 1073 1074 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) { 1075 probe_softc *softc; 1076 1077 softc = (probe_softc *)old_periph->softc; 1078 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 1079 periph_links.tqe); 1080 } else { 1081 status = cam_periph_alloc(proberegister, NULL, probecleanup, 1082 probestart, "aprobe", 1083 CAM_PERIPH_BIO, 1084 request_ccb->ccb_h.path, NULL, 0, 1085 request_ccb); 1086 1087 if (status != CAM_REQ_CMP) { 1088 xpt_print(path, "xpt_scan_lun: cam_alloc_periph " 1089 "returned an error, can't continue probe\n"); 1090 request_ccb->ccb_h.status = status; 1091 xpt_done(request_ccb); 1092 } 1093 } 1094} 1095 1096static void 1097xptscandone(struct cam_periph *periph, union ccb *done_ccb) 1098{ 1099 xpt_release_path(done_ccb->ccb_h.path); 1100 free(done_ccb->ccb_h.path, M_CAMXPT); 1101 free(done_ccb, M_CAMXPT); 1102} 1103 1104static struct cam_ed * 1105ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id) 1106{ 1107 struct cam_path path; 1108 struct ata_quirk_entry *quirk; 1109 struct cam_ed *device; 1110 struct cam_ed *cur_device; 1111 1112 device = xpt_alloc_device(bus, target, lun_id); 1113 if (device == NULL) 1114 return (NULL); 1115 1116 /* 1117 * Take the default quirk entry until we have inquiry 1118 * data and can determine a better quirk to use. 1119 */ 1120 quirk = &ata_quirk_table[ata_quirk_table_size - 1]; 1121 device->quirk = (void *)quirk; 1122 device->mintags = 0; 1123 device->maxtags = 0; 1124 bzero(&device->inq_data, sizeof(device->inq_data)); 1125 device->inq_flags = 0; 1126 device->queue_flags = 0; 1127 device->serial_num = NULL; 1128 device->serial_num_len = 0; 1129 1130 /* 1131 * XXX should be limited by number of CCBs this bus can 1132 * do. 1133 */ 1134 bus->sim->max_ccbs += device->ccbq.devq_openings; 1135 /* Insertion sort into our target's device list */ 1136 cur_device = TAILQ_FIRST(&target->ed_entries); 1137 while (cur_device != NULL && cur_device->lun_id < lun_id) 1138 cur_device = TAILQ_NEXT(cur_device, links); 1139 if (cur_device != NULL) { 1140 TAILQ_INSERT_BEFORE(cur_device, device, links); 1141 } else { 1142 TAILQ_INSERT_TAIL(&target->ed_entries, device, links); 1143 } 1144 target->generation++; 1145 if (lun_id != CAM_LUN_WILDCARD) { 1146 xpt_compile_path(&path, 1147 NULL, 1148 bus->path_id, 1149 target->target_id, 1150 lun_id); 1151 ata_device_transport(&path); 1152 xpt_release_path(&path); 1153 } 1154 1155 return (device); 1156} 1157 1158static void 1159ata_device_transport(struct cam_path *path) 1160{ 1161 struct ccb_pathinq cpi; 1162 struct ccb_trans_settings cts; 1163 struct scsi_inquiry_data *inq_buf = NULL; 1164 struct ata_params *ident_buf = NULL; 1165 1166 /* Get transport information from the SIM */ 1167 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL); 1168 cpi.ccb_h.func_code = XPT_PATH_INQ; 1169 xpt_action((union ccb *)&cpi); 1170 1171 path->device->transport = cpi.transport; 1172 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) 1173 inq_buf = &path->device->inq_data; 1174 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0) 1175 ident_buf = &path->device->ident_data; 1176 if (path->device->protocol == PROTO_ATA) { 1177 path->device->protocol_version = ident_buf ? 1178 ata_version(ident_buf->version_major) : cpi.protocol_version; 1179 } else if (path->device->protocol == PROTO_SCSI) { 1180 path->device->protocol_version = inq_buf ? 1181 SID_ANSI_REV(inq_buf) : cpi.protocol_version; 1182 } 1183 path->device->transport_version = ident_buf ? 1184 ata_version(ident_buf->version_major) : cpi.transport_version; 1185 1186 /* Tell the controller what we think */ 1187 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); 1188 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 1189 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1190 cts.transport = path->device->transport; 1191 cts.transport_version = path->device->transport_version; 1192 cts.protocol = path->device->protocol; 1193 cts.protocol_version = path->device->protocol_version; 1194 cts.proto_specific.valid = 0; 1195 cts.xport_specific.valid = 0; 1196 xpt_action((union ccb *)&cts); 1197} 1198 1199static void 1200ata_action(union ccb *start_ccb) 1201{ 1202 1203 switch (start_ccb->ccb_h.func_code) { 1204 case XPT_SET_TRAN_SETTINGS: 1205 { 1206 ata_set_transfer_settings(&start_ccb->cts, 1207 start_ccb->ccb_h.path->device, 1208 /*async_update*/FALSE); 1209 break; 1210 } 1211 case XPT_SCAN_BUS: 1212 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb); 1213 break; 1214 case XPT_SCAN_LUN: 1215 ata_scan_lun(start_ccb->ccb_h.path->periph, 1216 start_ccb->ccb_h.path, start_ccb->crcn.flags, 1217 start_ccb); 1218 break; 1219 case XPT_GET_TRAN_SETTINGS: 1220 { 1221 struct cam_sim *sim; 1222 1223 sim = start_ccb->ccb_h.path->bus->sim; 1224 (*(sim->sim_action))(sim, start_ccb); 1225 break; 1226 } 1227 default: 1228 xpt_action_default(start_ccb); 1229 break; 1230 } 1231} 1232 1233static void 1234ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device, 1235 int async_update) 1236{ 1237 struct ccb_pathinq cpi; 1238 struct ccb_trans_settings cur_cts; 1239 struct ccb_trans_settings_scsi *scsi; 1240 struct ccb_trans_settings_scsi *cur_scsi; 1241 struct cam_sim *sim; 1242 struct scsi_inquiry_data *inq_data; 1243 1244 if (device == NULL) { 1245 cts->ccb_h.status = CAM_PATH_INVALID; 1246 xpt_done((union ccb *)cts); 1247 return; 1248 } 1249 1250 if (cts->protocol == PROTO_UNKNOWN 1251 || cts->protocol == PROTO_UNSPECIFIED) { 1252 cts->protocol = device->protocol; 1253 cts->protocol_version = device->protocol_version; 1254 } 1255 1256 if (cts->protocol_version == PROTO_VERSION_UNKNOWN 1257 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED) 1258 cts->protocol_version = device->protocol_version; 1259 1260 if (cts->protocol != device->protocol) { 1261 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n", 1262 cts->protocol, device->protocol); 1263 cts->protocol = device->protocol; 1264 } 1265 1266 if (cts->protocol_version > device->protocol_version) { 1267 if (bootverbose) { 1268 xpt_print(cts->ccb_h.path, "Down reving Protocol " 1269 "Version from %d to %d?\n", cts->protocol_version, 1270 device->protocol_version); 1271 } 1272 cts->protocol_version = device->protocol_version; 1273 } 1274 1275 if (cts->transport == XPORT_UNKNOWN 1276 || cts->transport == XPORT_UNSPECIFIED) { 1277 cts->transport = device->transport; 1278 cts->transport_version = device->transport_version; 1279 } 1280 1281 if (cts->transport_version == XPORT_VERSION_UNKNOWN 1282 || cts->transport_version == XPORT_VERSION_UNSPECIFIED) 1283 cts->transport_version = device->transport_version; 1284 1285 if (cts->transport != device->transport) { 1286 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n", 1287 cts->transport, device->transport); 1288 cts->transport = device->transport; 1289 } 1290 1291 if (cts->transport_version > device->transport_version) { 1292 if (bootverbose) { 1293 xpt_print(cts->ccb_h.path, "Down reving Transport " 1294 "Version from %d to %d?\n", cts->transport_version, 1295 device->transport_version); 1296 } 1297 cts->transport_version = device->transport_version; 1298 } 1299 1300 sim = cts->ccb_h.path->bus->sim; 1301 1302 /* 1303 * Nothing more of interest to do unless 1304 * this is a device connected via the 1305 * SCSI protocol. 1306 */ 1307 if (cts->protocol != PROTO_SCSI) { 1308 if (async_update == FALSE) 1309 (*(sim->sim_action))(sim, (union ccb *)cts); 1310 return; 1311 } 1312 1313 inq_data = &device->inq_data; 1314 scsi = &cts->proto_specific.scsi; 1315 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NORMAL); 1316 cpi.ccb_h.func_code = XPT_PATH_INQ; 1317 xpt_action((union ccb *)&cpi); 1318 1319 /* SCSI specific sanity checking */ 1320 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0 1321 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0 1322 || (device->queue_flags & SCP_QUEUE_DQUE) != 0 1323 || (device->mintags == 0)) { 1324 /* 1325 * Can't tag on hardware that doesn't support tags, 1326 * doesn't have it enabled, or has broken tag support. 1327 */ 1328 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1329 } 1330 1331 if (async_update == FALSE) { 1332 /* 1333 * Perform sanity checking against what the 1334 * controller and device can do. 1335 */ 1336 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NORMAL); 1337 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 1338 cur_cts.type = cts->type; 1339 xpt_action((union ccb *)&cur_cts); 1340 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1341 return; 1342 } 1343 cur_scsi = &cur_cts.proto_specific.scsi; 1344 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) { 1345 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1346 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB; 1347 } 1348 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0) 1349 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1350 } 1351 1352 if (cts->type == CTS_TYPE_CURRENT_SETTINGS 1353 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) { 1354 int device_tagenb; 1355 1356 /* 1357 * If we are transitioning from tags to no-tags or 1358 * vice-versa, we need to carefully freeze and restart 1359 * the queue so that we don't overlap tagged and non-tagged 1360 * commands. We also temporarily stop tags if there is 1361 * a change in transfer negotiation settings to allow 1362 * "tag-less" negotiation. 1363 */ 1364 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 1365 || (device->inq_flags & SID_CmdQue) != 0) 1366 device_tagenb = TRUE; 1367 else 1368 device_tagenb = FALSE; 1369 1370 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0 1371 && device_tagenb == FALSE) 1372 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0 1373 && device_tagenb == TRUE)) { 1374 1375 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) { 1376 /* 1377 * Delay change to use tags until after a 1378 * few commands have gone to this device so 1379 * the controller has time to perform transfer 1380 * negotiations without tagged messages getting 1381 * in the way. 1382 */ 1383 device->tag_delay_count = CAM_TAG_DELAY_COUNT; 1384 device->flags |= CAM_DEV_TAG_AFTER_COUNT; 1385 } else { 1386 xpt_stop_tags(cts->ccb_h.path); 1387 } 1388 } 1389 } 1390 if (async_update == FALSE) 1391 (*(sim->sim_action))(sim, (union ccb *)cts); 1392} 1393 1394/* 1395 * Handle any per-device event notifications that require action by the XPT. 1396 */ 1397static void 1398ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, 1399 struct cam_ed *device, void *async_arg) 1400{ 1401 cam_status status; 1402 struct cam_path newpath; 1403 1404 /* 1405 * We only need to handle events for real devices. 1406 */ 1407 if (target->target_id == CAM_TARGET_WILDCARD 1408 || device->lun_id == CAM_LUN_WILDCARD) 1409 return; 1410 1411 /* 1412 * We need our own path with wildcards expanded to 1413 * handle certain types of events. 1414 */ 1415 if ((async_code == AC_SENT_BDR) 1416 || (async_code == AC_BUS_RESET) 1417 || (async_code == AC_INQ_CHANGED)) 1418 status = xpt_compile_path(&newpath, NULL, 1419 bus->path_id, 1420 target->target_id, 1421 device->lun_id); 1422 else 1423 status = CAM_REQ_CMP_ERR; 1424 1425 if (status == CAM_REQ_CMP) { 1426 if (async_code == AC_INQ_CHANGED) { 1427 /* 1428 * We've sent a start unit command, or 1429 * something similar to a device that 1430 * may have caused its inquiry data to 1431 * change. So we re-scan the device to 1432 * refresh the inquiry data for it. 1433 */ 1434 ata_scan_lun(newpath.periph, &newpath, 1435 CAM_EXPECT_INQ_CHANGE, NULL); 1436 } 1437 xpt_release_path(&newpath); 1438 } else if (async_code == AC_LOST_DEVICE && 1439 (device->flags & CAM_DEV_UNCONFIGURED) == 0) { 1440 device->flags |= CAM_DEV_UNCONFIGURED; 1441 xpt_release_device(device); 1442 } else if (async_code == AC_TRANSFER_NEG) { 1443 struct ccb_trans_settings *settings; 1444 1445 settings = (struct ccb_trans_settings *)async_arg; 1446 ata_set_transfer_settings(settings, device, 1447 /*async_update*/TRUE); 1448 } 1449} 1450
| 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 } 785 case PROBE_SETMODE: 786 if (path->device->protocol == PROTO_ATA) { 787 PROBE_SET_ACTION(softc, PROBE_SET_MULTI); 788 } else { 789 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 790 } 791 xpt_release_ccb(done_ccb); 792 xpt_schedule(periph, priority); 793 return; 794 case PROBE_SET_MULTI: 795 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 796 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 797 xpt_acquire_device(path->device); 798 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 799 xpt_action(done_ccb); 800 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 801 done_ccb); 802 } 803 break; 804 case PROBE_INQUIRY: 805 case PROBE_FULL_INQUIRY: 806 { 807 struct scsi_inquiry_data *inq_buf; 808 u_int8_t periph_qual, len; 809 810 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; 811 inq_buf = &path->device->inq_data; 812 813 periph_qual = SID_QUAL(inq_buf); 814 815 if (periph_qual != SID_QUAL_LU_CONNECTED) 816 break; 817 818 /* 819 * We conservatively request only 820 * SHORT_INQUIRY_LEN bytes of inquiry 821 * information during our first try 822 * at sending an INQUIRY. If the device 823 * has more information to give, 824 * perform a second request specifying 825 * the amount of information the device 826 * is willing to give. 827 */ 828 len = inq_buf->additional_length 829 + offsetof(struct scsi_inquiry_data, additional_length) + 1; 830 if (softc->action == PROBE_INQUIRY 831 && len > SHORT_INQUIRY_LENGTH) { 832 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY); 833 xpt_release_ccb(done_ccb); 834 xpt_schedule(periph, priority); 835 return; 836 } 837 838 ata_device_transport(path); 839 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 840 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 841 xpt_acquire_device(path->device); 842 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 843 xpt_action(done_ccb); 844 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb); 845 } 846 break; 847 } 848 case PROBE_PM_PID: 849 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0) 850 bzero(ident_buf, sizeof(*ident_buf)); 851 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) + 852 (done_ccb->ataio.res.lba_mid << 16) + 853 (done_ccb->ataio.res.lba_low << 8) + 854 done_ccb->ataio.res.sector_count; 855 ((uint32_t *)ident_buf)[0] = softc->pm_pid; 856 printf("PM Product ID: %08x\n", softc->pm_pid); 857 snprintf(ident_buf->model, sizeof(ident_buf->model), 858 "Port Multiplier %08x", softc->pm_pid); 859 PROBE_SET_ACTION(softc, PROBE_PM_PRV); 860 xpt_release_ccb(done_ccb); 861 xpt_schedule(periph, priority); 862 return; 863 case PROBE_PM_PRV: 864 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) + 865 (done_ccb->ataio.res.lba_mid << 16) + 866 (done_ccb->ataio.res.lba_low << 8) + 867 done_ccb->ataio.res.sector_count; 868 ((uint32_t *)ident_buf)[1] = softc->pm_prv; 869 printf("PM Revision: %08x\n", softc->pm_prv); 870 snprintf(ident_buf->revision, sizeof(ident_buf->revision), 871 "%04x", softc->pm_prv); 872 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID; 873 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) { 874 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 875 xpt_acquire_device(path->device); 876 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 877 xpt_action(done_ccb); 878 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 879 done_ccb); 880 } else { 881 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 882 xpt_action(done_ccb); 883 xpt_async(AC_SCSI_AEN, done_ccb->ccb_h.path, done_ccb); 884 } 885 break; 886 case PROBE_INVALID: 887 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO, 888 ("probedone: invalid action state\n")); 889 default: 890 break; 891 } 892done: 893 xpt_release_ccb(done_ccb); 894 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 895 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); 896 done_ccb->ccb_h.status = CAM_REQ_CMP; 897 done_ccb->ccb_h.ppriv_field1 = found; 898 xpt_done(done_ccb); 899 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { 900 cam_periph_invalidate(periph); 901 cam_periph_release_locked(periph); 902 } else { 903 probeschedule(periph); 904 } 905} 906 907static void 908probecleanup(struct cam_periph *periph) 909{ 910 free(periph->softc, M_CAMXPT); 911} 912 913static void 914ata_find_quirk(struct cam_ed *device) 915{ 916 struct ata_quirk_entry *quirk; 917 caddr_t match; 918 919 match = cam_quirkmatch((caddr_t)&device->ident_data, 920 (caddr_t)ata_quirk_table, 921 ata_quirk_table_size, 922 sizeof(*ata_quirk_table), ata_identify_match); 923 924 if (match == NULL) 925 panic("xpt_find_quirk: device didn't match wildcard entry!!"); 926 927 quirk = (struct ata_quirk_entry *)match; 928 device->quirk = quirk; 929 if (quirk->quirks & CAM_QUIRK_MAXTAGS) 930 device->mintags = device->maxtags = quirk->maxtags; 931} 932 933typedef struct { 934 union ccb *request_ccb; 935 struct ccb_pathinq *cpi; 936 int counter; 937 int found; 938} ata_scan_bus_info; 939 940/* 941 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. 942 * As the scan progresses, xpt_scan_bus is used as the 943 * callback on completion function. 944 */ 945static void 946ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb) 947{ 948 struct cam_path *path; 949 ata_scan_bus_info *scan_info; 950 union ccb *work_ccb; 951 cam_status status; 952 953 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 954 ("xpt_scan_bus\n")); 955 switch (request_ccb->ccb_h.func_code) { 956 case XPT_SCAN_BUS: 957 /* Find out the characteristics of the bus */ 958 work_ccb = xpt_alloc_ccb_nowait(); 959 if (work_ccb == NULL) { 960 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 961 xpt_done(request_ccb); 962 return; 963 } 964 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path, 965 request_ccb->ccb_h.pinfo.priority); 966 work_ccb->ccb_h.func_code = XPT_PATH_INQ; 967 xpt_action(work_ccb); 968 if (work_ccb->ccb_h.status != CAM_REQ_CMP) { 969 request_ccb->ccb_h.status = work_ccb->ccb_h.status; 970 xpt_free_ccb(work_ccb); 971 xpt_done(request_ccb); 972 return; 973 } 974 975 /* Save some state for use while we probe for devices */ 976 scan_info = (ata_scan_bus_info *) 977 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT); 978 if (scan_info == NULL) { 979 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 980 xpt_done(request_ccb); 981 return; 982 } 983 scan_info->request_ccb = request_ccb; 984 scan_info->cpi = &work_ccb->cpi; 985 if (scan_info->cpi->transport == XPORT_ATA) 986 scan_info->found = 0x0003; 987 else 988 scan_info->found = 0x8001; 989 scan_info->counter = 0; 990 /* If PM supported, probe it first. */ 991 if (scan_info->cpi->hba_inquiry & PI_SATAPM) 992 scan_info->counter = 15; 993 994 work_ccb = xpt_alloc_ccb_nowait(); 995 if (work_ccb == NULL) { 996 free(scan_info, M_CAMXPT); 997 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 998 xpt_done(request_ccb); 999 break; 1000 } 1001 goto scan_next; 1002 case XPT_SCAN_LUN: 1003 work_ccb = request_ccb; 1004 /* Reuse the same CCB to query if a device was really found */ 1005 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0; 1006 /* Free the current request path- we're done with it. */ 1007 xpt_free_path(work_ccb->ccb_h.path); 1008 /* If there is PMP... */ 1009 if (scan_info->counter == 15) { 1010 if (work_ccb->ccb_h.ppriv_field1 != 0) { 1011 /* everything else willbe probed by it */ 1012 scan_info->found = 0x8000; 1013 } else { 1014 struct ccb_trans_settings cts; 1015 1016 /* Report SIM that PM is absent. */ 1017 bzero(&cts, sizeof(cts)); 1018 xpt_setup_ccb(&cts.ccb_h, 1019 scan_info->request_ccb->ccb_h.path, 1); 1020 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 1021 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1022 cts.xport_specific.sata.pm_present = 0; 1023 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM; 1024 xpt_action((union ccb *)&cts); 1025 } 1026 } 1027take_next: 1028 /* Take next device. Wrap from 15 (PM) to 0. */ 1029 scan_info->counter = (scan_info->counter + 1 ) & 0x0f; 1030 if (scan_info->counter > scan_info->cpi->max_target - 1031 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ? 1 : 0)) { 1032 xpt_free_ccb(work_ccb); 1033 xpt_free_ccb((union ccb *)scan_info->cpi); 1034 request_ccb = scan_info->request_ccb; 1035 free(scan_info, M_CAMXPT); 1036 request_ccb->ccb_h.status = CAM_REQ_CMP; 1037 xpt_done(request_ccb); 1038 break; 1039 } 1040scan_next: 1041 if ((scan_info->found & (1 << scan_info->counter)) == 0) 1042 goto take_next; 1043 status = xpt_create_path(&path, xpt_periph, 1044 scan_info->request_ccb->ccb_h.path_id, 1045 scan_info->counter, 0); 1046 if (status != CAM_REQ_CMP) { 1047 printf("xpt_scan_bus: xpt_create_path failed" 1048 " with status %#x, bus scan halted\n", 1049 status); 1050 xpt_free_ccb(work_ccb); 1051 xpt_free_ccb((union ccb *)scan_info->cpi); 1052 request_ccb = scan_info->request_ccb; 1053 free(scan_info, M_CAMXPT); 1054 request_ccb->ccb_h.status = status; 1055 xpt_done(request_ccb); 1056 break; 1057 } 1058 xpt_setup_ccb(&work_ccb->ccb_h, path, 1059 scan_info->request_ccb->ccb_h.pinfo.priority); 1060 work_ccb->ccb_h.func_code = XPT_SCAN_LUN; 1061 work_ccb->ccb_h.cbfcnp = ata_scan_bus; 1062 work_ccb->ccb_h.ppriv_ptr0 = scan_info; 1063 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags; 1064 xpt_action(work_ccb); 1065 break; 1066 default: 1067 break; 1068 } 1069} 1070 1071static void 1072ata_scan_lun(struct cam_periph *periph, struct cam_path *path, 1073 cam_flags flags, union ccb *request_ccb) 1074{ 1075 struct ccb_pathinq cpi; 1076 cam_status status; 1077 struct cam_path *new_path; 1078 struct cam_periph *old_periph; 1079 1080 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1081 ("xpt_scan_lun\n")); 1082 1083 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL); 1084 cpi.ccb_h.func_code = XPT_PATH_INQ; 1085 xpt_action((union ccb *)&cpi); 1086 1087 if (cpi.ccb_h.status != CAM_REQ_CMP) { 1088 if (request_ccb != NULL) { 1089 request_ccb->ccb_h.status = cpi.ccb_h.status; 1090 xpt_done(request_ccb); 1091 } 1092 return; 1093 } 1094 1095 if (request_ccb == NULL) { 1096 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT); 1097 if (request_ccb == NULL) { 1098 xpt_print(path, "xpt_scan_lun: can't allocate CCB, " 1099 "can't continue\n"); 1100 return; 1101 } 1102 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT); 1103 if (new_path == NULL) { 1104 xpt_print(path, "xpt_scan_lun: can't allocate path, " 1105 "can't continue\n"); 1106 free(request_ccb, M_CAMXPT); 1107 return; 1108 } 1109 status = xpt_compile_path(new_path, xpt_periph, 1110 path->bus->path_id, 1111 path->target->target_id, 1112 path->device->lun_id); 1113 1114 if (status != CAM_REQ_CMP) { 1115 xpt_print(path, "xpt_scan_lun: can't compile path, " 1116 "can't continue\n"); 1117 free(request_ccb, M_CAMXPT); 1118 free(new_path, M_CAMXPT); 1119 return; 1120 } 1121 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_NORMAL); 1122 request_ccb->ccb_h.cbfcnp = xptscandone; 1123 request_ccb->ccb_h.func_code = XPT_SCAN_LUN; 1124 request_ccb->crcn.flags = flags; 1125 } 1126 1127 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) { 1128 probe_softc *softc; 1129 1130 softc = (probe_softc *)old_periph->softc; 1131 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 1132 periph_links.tqe); 1133 } else { 1134 status = cam_periph_alloc(proberegister, NULL, probecleanup, 1135 probestart, "aprobe", 1136 CAM_PERIPH_BIO, 1137 request_ccb->ccb_h.path, NULL, 0, 1138 request_ccb); 1139 1140 if (status != CAM_REQ_CMP) { 1141 xpt_print(path, "xpt_scan_lun: cam_alloc_periph " 1142 "returned an error, can't continue probe\n"); 1143 request_ccb->ccb_h.status = status; 1144 xpt_done(request_ccb); 1145 } 1146 } 1147} 1148 1149static void 1150xptscandone(struct cam_periph *periph, union ccb *done_ccb) 1151{ 1152 xpt_release_path(done_ccb->ccb_h.path); 1153 free(done_ccb->ccb_h.path, M_CAMXPT); 1154 free(done_ccb, M_CAMXPT); 1155} 1156 1157static struct cam_ed * 1158ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id) 1159{ 1160 struct cam_path path; 1161 struct ata_quirk_entry *quirk; 1162 struct cam_ed *device; 1163 struct cam_ed *cur_device; 1164 1165 device = xpt_alloc_device(bus, target, lun_id); 1166 if (device == NULL) 1167 return (NULL); 1168 1169 /* 1170 * Take the default quirk entry until we have inquiry 1171 * data and can determine a better quirk to use. 1172 */ 1173 quirk = &ata_quirk_table[ata_quirk_table_size - 1]; 1174 device->quirk = (void *)quirk; 1175 device->mintags = 0; 1176 device->maxtags = 0; 1177 bzero(&device->inq_data, sizeof(device->inq_data)); 1178 device->inq_flags = 0; 1179 device->queue_flags = 0; 1180 device->serial_num = NULL; 1181 device->serial_num_len = 0; 1182 1183 /* 1184 * XXX should be limited by number of CCBs this bus can 1185 * do. 1186 */ 1187 bus->sim->max_ccbs += device->ccbq.devq_openings; 1188 /* Insertion sort into our target's device list */ 1189 cur_device = TAILQ_FIRST(&target->ed_entries); 1190 while (cur_device != NULL && cur_device->lun_id < lun_id) 1191 cur_device = TAILQ_NEXT(cur_device, links); 1192 if (cur_device != NULL) { 1193 TAILQ_INSERT_BEFORE(cur_device, device, links); 1194 } else { 1195 TAILQ_INSERT_TAIL(&target->ed_entries, device, links); 1196 } 1197 target->generation++; 1198 if (lun_id != CAM_LUN_WILDCARD) { 1199 xpt_compile_path(&path, 1200 NULL, 1201 bus->path_id, 1202 target->target_id, 1203 lun_id); 1204 ata_device_transport(&path); 1205 xpt_release_path(&path); 1206 } 1207 1208 return (device); 1209} 1210 1211static void 1212ata_device_transport(struct cam_path *path) 1213{ 1214 struct ccb_pathinq cpi; 1215 struct ccb_trans_settings cts; 1216 struct scsi_inquiry_data *inq_buf = NULL; 1217 struct ata_params *ident_buf = NULL; 1218 1219 /* Get transport information from the SIM */ 1220 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL); 1221 cpi.ccb_h.func_code = XPT_PATH_INQ; 1222 xpt_action((union ccb *)&cpi); 1223 1224 path->device->transport = cpi.transport; 1225 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) 1226 inq_buf = &path->device->inq_data; 1227 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0) 1228 ident_buf = &path->device->ident_data; 1229 if (path->device->protocol == PROTO_ATA) { 1230 path->device->protocol_version = ident_buf ? 1231 ata_version(ident_buf->version_major) : cpi.protocol_version; 1232 } else if (path->device->protocol == PROTO_SCSI) { 1233 path->device->protocol_version = inq_buf ? 1234 SID_ANSI_REV(inq_buf) : cpi.protocol_version; 1235 } 1236 path->device->transport_version = ident_buf ? 1237 ata_version(ident_buf->version_major) : cpi.transport_version; 1238 1239 /* Tell the controller what we think */ 1240 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); 1241 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 1242 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1243 cts.transport = path->device->transport; 1244 cts.transport_version = path->device->transport_version; 1245 cts.protocol = path->device->protocol; 1246 cts.protocol_version = path->device->protocol_version; 1247 cts.proto_specific.valid = 0; 1248 cts.xport_specific.valid = 0; 1249 xpt_action((union ccb *)&cts); 1250} 1251 1252static void 1253ata_action(union ccb *start_ccb) 1254{ 1255 1256 switch (start_ccb->ccb_h.func_code) { 1257 case XPT_SET_TRAN_SETTINGS: 1258 { 1259 ata_set_transfer_settings(&start_ccb->cts, 1260 start_ccb->ccb_h.path->device, 1261 /*async_update*/FALSE); 1262 break; 1263 } 1264 case XPT_SCAN_BUS: 1265 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb); 1266 break; 1267 case XPT_SCAN_LUN: 1268 ata_scan_lun(start_ccb->ccb_h.path->periph, 1269 start_ccb->ccb_h.path, start_ccb->crcn.flags, 1270 start_ccb); 1271 break; 1272 case XPT_GET_TRAN_SETTINGS: 1273 { 1274 struct cam_sim *sim; 1275 1276 sim = start_ccb->ccb_h.path->bus->sim; 1277 (*(sim->sim_action))(sim, start_ccb); 1278 break; 1279 } 1280 default: 1281 xpt_action_default(start_ccb); 1282 break; 1283 } 1284} 1285 1286static void 1287ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device, 1288 int async_update) 1289{ 1290 struct ccb_pathinq cpi; 1291 struct ccb_trans_settings cur_cts; 1292 struct ccb_trans_settings_scsi *scsi; 1293 struct ccb_trans_settings_scsi *cur_scsi; 1294 struct cam_sim *sim; 1295 struct scsi_inquiry_data *inq_data; 1296 1297 if (device == NULL) { 1298 cts->ccb_h.status = CAM_PATH_INVALID; 1299 xpt_done((union ccb *)cts); 1300 return; 1301 } 1302 1303 if (cts->protocol == PROTO_UNKNOWN 1304 || cts->protocol == PROTO_UNSPECIFIED) { 1305 cts->protocol = device->protocol; 1306 cts->protocol_version = device->protocol_version; 1307 } 1308 1309 if (cts->protocol_version == PROTO_VERSION_UNKNOWN 1310 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED) 1311 cts->protocol_version = device->protocol_version; 1312 1313 if (cts->protocol != device->protocol) { 1314 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n", 1315 cts->protocol, device->protocol); 1316 cts->protocol = device->protocol; 1317 } 1318 1319 if (cts->protocol_version > device->protocol_version) { 1320 if (bootverbose) { 1321 xpt_print(cts->ccb_h.path, "Down reving Protocol " 1322 "Version from %d to %d?\n", cts->protocol_version, 1323 device->protocol_version); 1324 } 1325 cts->protocol_version = device->protocol_version; 1326 } 1327 1328 if (cts->transport == XPORT_UNKNOWN 1329 || cts->transport == XPORT_UNSPECIFIED) { 1330 cts->transport = device->transport; 1331 cts->transport_version = device->transport_version; 1332 } 1333 1334 if (cts->transport_version == XPORT_VERSION_UNKNOWN 1335 || cts->transport_version == XPORT_VERSION_UNSPECIFIED) 1336 cts->transport_version = device->transport_version; 1337 1338 if (cts->transport != device->transport) { 1339 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n", 1340 cts->transport, device->transport); 1341 cts->transport = device->transport; 1342 } 1343 1344 if (cts->transport_version > device->transport_version) { 1345 if (bootverbose) { 1346 xpt_print(cts->ccb_h.path, "Down reving Transport " 1347 "Version from %d to %d?\n", cts->transport_version, 1348 device->transport_version); 1349 } 1350 cts->transport_version = device->transport_version; 1351 } 1352 1353 sim = cts->ccb_h.path->bus->sim; 1354 1355 /* 1356 * Nothing more of interest to do unless 1357 * this is a device connected via the 1358 * SCSI protocol. 1359 */ 1360 if (cts->protocol != PROTO_SCSI) { 1361 if (async_update == FALSE) 1362 (*(sim->sim_action))(sim, (union ccb *)cts); 1363 return; 1364 } 1365 1366 inq_data = &device->inq_data; 1367 scsi = &cts->proto_specific.scsi; 1368 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NORMAL); 1369 cpi.ccb_h.func_code = XPT_PATH_INQ; 1370 xpt_action((union ccb *)&cpi); 1371 1372 /* SCSI specific sanity checking */ 1373 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0 1374 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0 1375 || (device->queue_flags & SCP_QUEUE_DQUE) != 0 1376 || (device->mintags == 0)) { 1377 /* 1378 * Can't tag on hardware that doesn't support tags, 1379 * doesn't have it enabled, or has broken tag support. 1380 */ 1381 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1382 } 1383 1384 if (async_update == FALSE) { 1385 /* 1386 * Perform sanity checking against what the 1387 * controller and device can do. 1388 */ 1389 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NORMAL); 1390 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 1391 cur_cts.type = cts->type; 1392 xpt_action((union ccb *)&cur_cts); 1393 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1394 return; 1395 } 1396 cur_scsi = &cur_cts.proto_specific.scsi; 1397 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) { 1398 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1399 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB; 1400 } 1401 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0) 1402 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; 1403 } 1404 1405 if (cts->type == CTS_TYPE_CURRENT_SETTINGS 1406 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) { 1407 int device_tagenb; 1408 1409 /* 1410 * If we are transitioning from tags to no-tags or 1411 * vice-versa, we need to carefully freeze and restart 1412 * the queue so that we don't overlap tagged and non-tagged 1413 * commands. We also temporarily stop tags if there is 1414 * a change in transfer negotiation settings to allow 1415 * "tag-less" negotiation. 1416 */ 1417 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 1418 || (device->inq_flags & SID_CmdQue) != 0) 1419 device_tagenb = TRUE; 1420 else 1421 device_tagenb = FALSE; 1422 1423 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0 1424 && device_tagenb == FALSE) 1425 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0 1426 && device_tagenb == TRUE)) { 1427 1428 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) { 1429 /* 1430 * Delay change to use tags until after a 1431 * few commands have gone to this device so 1432 * the controller has time to perform transfer 1433 * negotiations without tagged messages getting 1434 * in the way. 1435 */ 1436 device->tag_delay_count = CAM_TAG_DELAY_COUNT; 1437 device->flags |= CAM_DEV_TAG_AFTER_COUNT; 1438 } else { 1439 xpt_stop_tags(cts->ccb_h.path); 1440 } 1441 } 1442 } 1443 if (async_update == FALSE) 1444 (*(sim->sim_action))(sim, (union ccb *)cts); 1445} 1446 1447/* 1448 * Handle any per-device event notifications that require action by the XPT. 1449 */ 1450static void 1451ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, 1452 struct cam_ed *device, void *async_arg) 1453{ 1454 cam_status status; 1455 struct cam_path newpath; 1456 1457 /* 1458 * We only need to handle events for real devices. 1459 */ 1460 if (target->target_id == CAM_TARGET_WILDCARD 1461 || device->lun_id == CAM_LUN_WILDCARD) 1462 return; 1463 1464 /* 1465 * We need our own path with wildcards expanded to 1466 * handle certain types of events. 1467 */ 1468 if ((async_code == AC_SENT_BDR) 1469 || (async_code == AC_BUS_RESET) 1470 || (async_code == AC_INQ_CHANGED)) 1471 status = xpt_compile_path(&newpath, NULL, 1472 bus->path_id, 1473 target->target_id, 1474 device->lun_id); 1475 else 1476 status = CAM_REQ_CMP_ERR; 1477 1478 if (status == CAM_REQ_CMP) { 1479 if (async_code == AC_INQ_CHANGED) { 1480 /* 1481 * We've sent a start unit command, or 1482 * something similar to a device that 1483 * may have caused its inquiry data to 1484 * change. So we re-scan the device to 1485 * refresh the inquiry data for it. 1486 */ 1487 ata_scan_lun(newpath.periph, &newpath, 1488 CAM_EXPECT_INQ_CHANGE, NULL); 1489 } 1490 xpt_release_path(&newpath); 1491 } else if (async_code == AC_LOST_DEVICE && 1492 (device->flags & CAM_DEV_UNCONFIGURED) == 0) { 1493 device->flags |= CAM_DEV_UNCONFIGURED; 1494 xpt_release_device(device); 1495 } else if (async_code == AC_TRANSFER_NEG) { 1496 struct ccb_trans_settings *settings; 1497 1498 settings = (struct ccb_trans_settings *)async_arg; 1499 ata_set_transfer_settings(settings, device, 1500 /*async_update*/TRUE); 1501 } 1502} 1503
|