Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] ipr: Support attaching SATA devices

Adds support to attach SATA devices to ipr SAS adapters.

Signed-off-by: Brian King <brking@us.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by

Brian King and committed by
James Bottomley
35a39691 d7694f8c

+681 -22
+1 -1
drivers/scsi/Kconfig
··· 1014 1014 1015 1015 config SCSI_IPR 1016 1016 tristate "IBM Power Linux RAID adapter support" 1017 - depends on PCI && SCSI 1017 + depends on PCI && SCSI && ATA 1018 1018 select FW_LOADER 1019 1019 ---help--- 1020 1020 This driver supports the IBM Power Linux family RAID adapters.
+665 -18
drivers/scsi/ipr.c
··· 70 70 #include <linux/firmware.h> 71 71 #include <linux/module.h> 72 72 #include <linux/moduleparam.h> 73 + #include <linux/libata.h> 73 74 #include <asm/io.h> 74 75 #include <asm/irq.h> 75 76 #include <asm/processor.h> ··· 79 78 #include <scsi/scsi_tcq.h> 80 79 #include <scsi/scsi_eh.h> 81 80 #include <scsi/scsi_cmnd.h> 81 + #include <scsi/scsi_transport.h> 82 82 #include "ipr.h" 83 83 84 84 /* ··· 201 199 "FFFA: Undefined device response recovered by the IOA"}, 202 200 {0x014A0000, 1, 1, 203 201 "FFF6: Device bus error, message or command phase"}, 202 + {0x014A8000, 0, 1, 203 + "FFFE: Task Management Function failed"}, 204 204 {0x015D0000, 0, 1, 205 205 "FFF6: Failure prediction threshold exceeded"}, 206 206 {0x015D9200, 0, 1, ··· 265 261 "Device bus status error"}, 266 262 {0x04448600, 0, 1, 267 263 "8157: IOA error requiring IOA reset to recover"}, 264 + {0x04448700, 0, 0, 265 + "ATA device status error"}, 268 266 {0x04490000, 0, 0, 269 267 "Message reject received from the device"}, 270 268 {0x04449200, 0, 1, ··· 279 273 "9082: IOA detected device error"}, 280 274 {0x044A0000, 1, 1, 281 275 "3110: Device bus error, message or command phase"}, 276 + {0x044A8000, 1, 1, 277 + "3110: SAS Command / Task Management Function failed"}, 282 278 {0x04670400, 0, 1, 283 279 "9091: Incorrect hardware configuration change has been detected"}, 284 280 {0x04678000, 0, 1, ··· 461 453 trace_entry->time = jiffies; 462 454 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0]; 463 455 trace_entry->type = type; 464 - trace_entry->cmd_index = ipr_cmd->cmd_index; 456 + trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command; 457 + trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff; 465 458 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle; 466 459 trace_entry->u.add_data = add_data; 467 460 } ··· 489 480 ioarcb->read_ioadl_len = 0; 490 481 ioasa->ioasc = 0; 491 482 ioasa->residual_data_len = 0; 483 + ioasa->u.gata.status = 0; 492 484 493 485 ipr_cmd->scsi_cmd = NULL; 486 + ipr_cmd->qc = NULL; 494 487 ipr_cmd->sense_buffer[0] = 0; 495 488 ipr_cmd->dma_use_sg = 0; 496 489 } ··· 637 626 } 638 627 639 628 /** 629 + * ipr_sata_eh_done - done function for aborted SATA commands 630 + * @ipr_cmd: ipr command struct 631 + * 632 + * This function is invoked for ops generated to SATA 633 + * devices which are being aborted. 634 + * 635 + * Return value: 636 + * none 637 + **/ 638 + static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd) 639 + { 640 + struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; 641 + struct ata_queued_cmd *qc = ipr_cmd->qc; 642 + struct ipr_sata_port *sata_port = qc->ap->private_data; 643 + 644 + qc->err_mask |= AC_ERR_OTHER; 645 + sata_port->ioasa.status |= ATA_BUSY; 646 + list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q); 647 + ata_qc_complete(qc); 648 + } 649 + 650 + /** 640 651 * ipr_scsi_eh_done - mid-layer done function for aborted ops 641 652 * @ipr_cmd: ipr command struct 642 653 * ··· 702 669 703 670 if (ipr_cmd->scsi_cmd) 704 671 ipr_cmd->done = ipr_scsi_eh_done; 672 + else if (ipr_cmd->qc) 673 + ipr_cmd->done = ipr_sata_eh_done; 705 674 706 675 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET); 707 676 del_timer(&ipr_cmd->timer); ··· 860 825 res->del_from_ml = 0; 861 826 res->resetting_device = 0; 862 827 res->sdev = NULL; 828 + res->sata_port = NULL; 863 829 } 864 830 865 831 /** ··· 1352 1316 int i; 1353 1317 1354 1318 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++) 1355 - if (ipr_error_table[i].ioasc == ioasc) 1319 + if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK)) 1356 1320 return i; 1357 1321 1358 1322 return 0; ··· 3087 3051 **/ 3088 3052 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth) 3089 3053 { 3054 + struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata; 3055 + struct ipr_resource_entry *res; 3056 + unsigned long lock_flags = 0; 3057 + 3058 + spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3059 + res = (struct ipr_resource_entry *)sdev->hostdata; 3060 + 3061 + if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN) 3062 + qdepth = IPR_MAX_CMD_PER_ATA_LUN; 3063 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3064 + 3090 3065 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 3091 3066 return sdev->queue_depth; 3092 3067 } ··· 3213 3166 } 3214 3167 3215 3168 /** 3169 + * ipr_find_starget - Find target based on bus/target. 3170 + * @starget: scsi target struct 3171 + * 3172 + * Return value: 3173 + * resource entry pointer if found / NULL if not found 3174 + **/ 3175 + static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget) 3176 + { 3177 + struct Scsi_Host *shost = dev_to_shost(&starget->dev); 3178 + struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata; 3179 + struct ipr_resource_entry *res; 3180 + 3181 + list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { 3182 + if ((res->cfgte.res_addr.bus == starget->channel) && 3183 + (res->cfgte.res_addr.target == starget->id) && 3184 + (res->cfgte.res_addr.lun == 0)) { 3185 + return res; 3186 + } 3187 + } 3188 + 3189 + return NULL; 3190 + } 3191 + 3192 + static struct ata_port_info sata_port_info; 3193 + 3194 + /** 3195 + * ipr_target_alloc - Prepare for commands to a SCSI target 3196 + * @starget: scsi target struct 3197 + * 3198 + * If the device is a SATA device, this function allocates an 3199 + * ATA port with libata, else it does nothing. 3200 + * 3201 + * Return value: 3202 + * 0 on success / non-0 on failure 3203 + **/ 3204 + static int ipr_target_alloc(struct scsi_target *starget) 3205 + { 3206 + struct Scsi_Host *shost = dev_to_shost(&starget->dev); 3207 + struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata; 3208 + struct ipr_sata_port *sata_port; 3209 + struct ata_port *ap; 3210 + struct ipr_resource_entry *res; 3211 + unsigned long lock_flags; 3212 + 3213 + spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3214 + res = ipr_find_starget(starget); 3215 + starget->hostdata = NULL; 3216 + 3217 + if (res && ipr_is_gata(res)) { 3218 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3219 + sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL); 3220 + if (!sata_port) 3221 + return -ENOMEM; 3222 + 3223 + ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost); 3224 + if (ap) { 3225 + spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3226 + sata_port->ioa_cfg = ioa_cfg; 3227 + sata_port->ap = ap; 3228 + sata_port->res = res; 3229 + 3230 + res->sata_port = sata_port; 3231 + ap->private_data = sata_port; 3232 + starget->hostdata = sata_port; 3233 + } else { 3234 + kfree(sata_port); 3235 + return -ENOMEM; 3236 + } 3237 + } 3238 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3239 + 3240 + return 0; 3241 + } 3242 + 3243 + /** 3244 + * ipr_target_destroy - Destroy a SCSI target 3245 + * @starget: scsi target struct 3246 + * 3247 + * If the device was a SATA device, this function frees the libata 3248 + * ATA port, else it does nothing. 3249 + * 3250 + **/ 3251 + static void ipr_target_destroy(struct scsi_target *starget) 3252 + { 3253 + struct ipr_sata_port *sata_port = starget->hostdata; 3254 + 3255 + if (sata_port) { 3256 + starget->hostdata = NULL; 3257 + ata_sas_port_destroy(sata_port->ap); 3258 + kfree(sata_port); 3259 + } 3260 + } 3261 + 3262 + /** 3263 + * ipr_find_sdev - Find device based on bus/target/lun. 3264 + * @sdev: scsi device struct 3265 + * 3266 + * Return value: 3267 + * resource entry pointer if found / NULL if not found 3268 + **/ 3269 + static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev) 3270 + { 3271 + struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata; 3272 + struct ipr_resource_entry *res; 3273 + 3274 + list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { 3275 + if ((res->cfgte.res_addr.bus == sdev->channel) && 3276 + (res->cfgte.res_addr.target == sdev->id) && 3277 + (res->cfgte.res_addr.lun == sdev->lun)) 3278 + return res; 3279 + } 3280 + 3281 + return NULL; 3282 + } 3283 + 3284 + /** 3216 3285 * ipr_slave_destroy - Unconfigure a SCSI device 3217 3286 * @sdev: scsi device struct 3218 3287 * ··· 3346 3183 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3347 3184 res = (struct ipr_resource_entry *) sdev->hostdata; 3348 3185 if (res) { 3186 + if (res->sata_port) 3187 + ata_port_disable(res->sata_port->ap); 3349 3188 sdev->hostdata = NULL; 3350 3189 res->sdev = NULL; 3190 + res->sata_port = NULL; 3351 3191 } 3352 3192 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3353 3193 } ··· 3385 3219 } 3386 3220 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)) 3387 3221 sdev->allow_restart = 1; 3388 - scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 3222 + if (ipr_is_gata(res) && res->sata_port) { 3223 + scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN); 3224 + ata_sas_slave_configure(sdev, res->sata_port->ap); 3225 + } else { 3226 + scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 3227 + } 3389 3228 } 3390 3229 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3391 3230 return 0; 3231 + } 3232 + 3233 + /** 3234 + * ipr_ata_slave_alloc - Prepare for commands to a SATA device 3235 + * @sdev: scsi device struct 3236 + * 3237 + * This function initializes an ATA port so that future commands 3238 + * sent through queuecommand will work. 3239 + * 3240 + * Return value: 3241 + * 0 on success 3242 + **/ 3243 + static int ipr_ata_slave_alloc(struct scsi_device *sdev) 3244 + { 3245 + struct ipr_sata_port *sata_port = NULL; 3246 + int rc = -ENXIO; 3247 + 3248 + ENTER; 3249 + if (sdev->sdev_target) 3250 + sata_port = sdev->sdev_target->hostdata; 3251 + if (sata_port) 3252 + rc = ata_sas_port_init(sata_port->ap); 3253 + if (rc) 3254 + ipr_slave_destroy(sdev); 3255 + 3256 + LEAVE; 3257 + return rc; 3392 3258 } 3393 3259 3394 3260 /** ··· 3446 3248 3447 3249 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3448 3250 3449 - list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { 3450 - if ((res->cfgte.res_addr.bus == sdev->channel) && 3451 - (res->cfgte.res_addr.target == sdev->id) && 3452 - (res->cfgte.res_addr.lun == sdev->lun)) { 3453 - res->sdev = sdev; 3454 - res->add_to_ml = 0; 3455 - res->in_erp = 0; 3456 - sdev->hostdata = res; 3457 - if (!ipr_is_naca_model(res)) 3458 - res->needs_sync_complete = 1; 3459 - rc = 0; 3460 - break; 3251 + res = ipr_find_sdev(sdev); 3252 + if (res) { 3253 + res->sdev = sdev; 3254 + res->add_to_ml = 0; 3255 + res->in_erp = 0; 3256 + sdev->hostdata = res; 3257 + if (!ipr_is_naca_model(res)) 3258 + res->needs_sync_complete = 1; 3259 + rc = 0; 3260 + if (ipr_is_gata(res)) { 3261 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3262 + return ipr_ata_slave_alloc(sdev); 3461 3263 } 3462 3264 } 3463 3265 ··· 3512 3314 * This function issues a device reset to the affected device. 3513 3315 * If the device is a SCSI device, a LUN reset will be sent 3514 3316 * to the device first. If that does not work, a target reset 3515 - * will be sent. 3317 + * will be sent. If the device is a SATA device, a PHY reset will 3318 + * be sent. 3516 3319 * 3517 3320 * Return value: 3518 3321 * 0 on success / non-zero on failure ··· 3524 3325 struct ipr_cmnd *ipr_cmd; 3525 3326 struct ipr_ioarcb *ioarcb; 3526 3327 struct ipr_cmd_pkt *cmd_pkt; 3328 + struct ipr_ioarcb_ata_regs *regs; 3527 3329 u32 ioasc; 3528 3330 3529 3331 ENTER; 3530 3332 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 3531 3333 ioarcb = &ipr_cmd->ioarcb; 3532 3334 cmd_pkt = &ioarcb->cmd_pkt; 3335 + regs = &ioarcb->add_data.u.regs; 3533 3336 3534 3337 ioarcb->res_handle = res->cfgte.res_handle; 3535 3338 cmd_pkt->request_type = IPR_RQTYPE_IOACMD; 3536 3339 cmd_pkt->cdb[0] = IPR_RESET_DEVICE; 3340 + if (ipr_is_gata(res)) { 3341 + cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET; 3342 + ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags)); 3343 + regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION; 3344 + } 3537 3345 3538 3346 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT); 3539 3347 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc); 3540 3348 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q); 3349 + if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) 3350 + memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata, 3351 + sizeof(struct ipr_ioasa_gata)); 3541 3352 3542 3353 LEAVE; 3543 3354 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0); 3355 + } 3356 + 3357 + /** 3358 + * ipr_sata_reset - Reset the SATA port 3359 + * @ap: SATA port to reset 3360 + * @classes: class of the attached device 3361 + * 3362 + * This function issues a SATA phy reset to the affected ATA port. 3363 + * 3364 + * Return value: 3365 + * 0 on success / non-zero on failure 3366 + **/ 3367 + static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes) 3368 + { 3369 + struct ipr_sata_port *sata_port = ap->private_data; 3370 + struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg; 3371 + struct ipr_resource_entry *res; 3372 + unsigned long lock_flags = 0; 3373 + int rc = -ENXIO; 3374 + 3375 + ENTER; 3376 + spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3377 + res = sata_port->res; 3378 + if (res) { 3379 + rc = ipr_device_reset(ioa_cfg, res); 3380 + switch(res->cfgte.proto) { 3381 + case IPR_PROTO_SATA: 3382 + case IPR_PROTO_SAS_STP: 3383 + *classes = ATA_DEV_ATA; 3384 + break; 3385 + case IPR_PROTO_SATA_ATAPI: 3386 + case IPR_PROTO_SAS_STP_ATAPI: 3387 + *classes = ATA_DEV_ATAPI; 3388 + break; 3389 + default: 3390 + *classes = ATA_DEV_UNKNOWN; 3391 + break; 3392 + }; 3393 + } 3394 + 3395 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3396 + LEAVE; 3397 + return rc; 3544 3398 } 3545 3399 3546 3400 /** ··· 3612 3360 struct ipr_cmnd *ipr_cmd; 3613 3361 struct ipr_ioa_cfg *ioa_cfg; 3614 3362 struct ipr_resource_entry *res; 3615 - int rc; 3363 + struct ata_port *ap; 3364 + int rc = 0; 3616 3365 3617 3366 ENTER; 3618 3367 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata; ··· 3641 3388 3642 3389 res->resetting_device = 1; 3643 3390 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n"); 3644 - rc = ipr_device_reset(ioa_cfg, res); 3391 + 3392 + if (ipr_is_gata(res) && res->sata_port) { 3393 + ap = res->sata_port->ap; 3394 + spin_unlock_irq(scsi_cmd->device->host->host_lock); 3395 + ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL); 3396 + spin_lock_irq(scsi_cmd->device->host->host_lock); 3397 + } else 3398 + rc = ipr_device_reset(ioa_cfg, res); 3645 3399 res->resetting_device = 0; 3646 3400 3647 3401 LEAVE; ··· 4560 4300 return 0; 4561 4301 } 4562 4302 4303 + if (ipr_is_gata(res) && res->sata_port) 4304 + return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap); 4305 + 4563 4306 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 4564 4307 ioarcb = &ipr_cmd->ioarcb; 4565 4308 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q); ··· 4608 4345 } 4609 4346 4610 4347 /** 4348 + * ipr_ioctl - IOCTL handler 4349 + * @sdev: scsi device struct 4350 + * @cmd: IOCTL cmd 4351 + * @arg: IOCTL arg 4352 + * 4353 + * Return value: 4354 + * 0 on success / other on failure 4355 + **/ 4356 + int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 4357 + { 4358 + struct ipr_resource_entry *res; 4359 + 4360 + res = (struct ipr_resource_entry *)sdev->hostdata; 4361 + if (res && ipr_is_gata(res)) 4362 + return ata_scsi_ioctl(sdev, cmd, arg); 4363 + 4364 + return -EINVAL; 4365 + } 4366 + 4367 + /** 4611 4368 * ipr_info - Get information about the card/driver 4612 4369 * @scsi_host: scsi host struct 4613 4370 * ··· 4649 4366 return buffer; 4650 4367 } 4651 4368 4369 + /** 4370 + * ipr_scsi_timed_out - Handle scsi command timeout 4371 + * @scsi_cmd: scsi command struct 4372 + * 4373 + * Return value: 4374 + * EH_NOT_HANDLED 4375 + **/ 4376 + enum scsi_eh_timer_return ipr_scsi_timed_out(struct scsi_cmnd *scsi_cmd) 4377 + { 4378 + struct ipr_ioa_cfg *ioa_cfg; 4379 + struct ipr_cmnd *ipr_cmd; 4380 + unsigned long flags; 4381 + 4382 + ENTER; 4383 + spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags); 4384 + ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata; 4385 + 4386 + list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) { 4387 + if (ipr_cmd->qc && ipr_cmd->qc->scsicmd == scsi_cmd) { 4388 + ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT; 4389 + ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED; 4390 + break; 4391 + } 4392 + } 4393 + 4394 + spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags); 4395 + LEAVE; 4396 + return EH_NOT_HANDLED; 4397 + } 4398 + 4399 + static struct scsi_transport_template ipr_transport_template = { 4400 + .eh_timed_out = ipr_scsi_timed_out 4401 + }; 4402 + 4652 4403 static struct scsi_host_template driver_template = { 4653 4404 .module = THIS_MODULE, 4654 4405 .name = "IPR", 4655 4406 .info = ipr_ioa_info, 4407 + .ioctl = ipr_ioctl, 4656 4408 .queuecommand = ipr_queuecommand, 4657 4409 .eh_abort_handler = ipr_eh_abort, 4658 4410 .eh_device_reset_handler = ipr_eh_dev_reset, ··· 4695 4377 .slave_alloc = ipr_slave_alloc, 4696 4378 .slave_configure = ipr_slave_configure, 4697 4379 .slave_destroy = ipr_slave_destroy, 4380 + .target_alloc = ipr_target_alloc, 4381 + .target_destroy = ipr_target_destroy, 4698 4382 .change_queue_depth = ipr_change_queue_depth, 4699 4383 .change_queue_type = ipr_change_queue_type, 4700 4384 .bios_param = ipr_biosparam, ··· 4709 4389 .shost_attrs = ipr_ioa_attrs, 4710 4390 .sdev_attrs = ipr_dev_attrs, 4711 4391 .proc_name = IPR_NAME 4392 + }; 4393 + 4394 + /** 4395 + * ipr_ata_phy_reset - libata phy_reset handler 4396 + * @ap: ata port to reset 4397 + * 4398 + **/ 4399 + static void ipr_ata_phy_reset(struct ata_port *ap) 4400 + { 4401 + unsigned long flags; 4402 + struct ipr_sata_port *sata_port = ap->private_data; 4403 + struct ipr_resource_entry *res = sata_port->res; 4404 + struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg; 4405 + int rc; 4406 + 4407 + ENTER; 4408 + spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 4409 + while(ioa_cfg->in_reset_reload) { 4410 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 4411 + wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 4412 + spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 4413 + } 4414 + 4415 + if (!ioa_cfg->allow_cmds) 4416 + goto out_unlock; 4417 + 4418 + rc = ipr_device_reset(ioa_cfg, res); 4419 + 4420 + if (rc) { 4421 + ap->ops->port_disable(ap); 4422 + goto out_unlock; 4423 + } 4424 + 4425 + switch(res->cfgte.proto) { 4426 + case IPR_PROTO_SATA: 4427 + case IPR_PROTO_SAS_STP: 4428 + ap->device[0].class = ATA_DEV_ATA; 4429 + break; 4430 + case IPR_PROTO_SATA_ATAPI: 4431 + case IPR_PROTO_SAS_STP_ATAPI: 4432 + ap->device[0].class = ATA_DEV_ATAPI; 4433 + break; 4434 + default: 4435 + ap->device[0].class = ATA_DEV_UNKNOWN; 4436 + ap->ops->port_disable(ap); 4437 + break; 4438 + }; 4439 + 4440 + out_unlock: 4441 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 4442 + LEAVE; 4443 + } 4444 + 4445 + /** 4446 + * ipr_ata_post_internal - Cleanup after an internal command 4447 + * @qc: ATA queued command 4448 + * 4449 + * Return value: 4450 + * none 4451 + **/ 4452 + static void ipr_ata_post_internal(struct ata_queued_cmd *qc) 4453 + { 4454 + struct ipr_sata_port *sata_port = qc->ap->private_data; 4455 + struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg; 4456 + struct ipr_cmnd *ipr_cmd; 4457 + unsigned long flags; 4458 + 4459 + spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 4460 + list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) { 4461 + if (ipr_cmd->qc == qc) { 4462 + ipr_device_reset(ioa_cfg, sata_port->res); 4463 + break; 4464 + } 4465 + } 4466 + spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 4467 + } 4468 + 4469 + /** 4470 + * ipr_tf_read - Read the current ATA taskfile for the ATA port 4471 + * @ap: ATA port 4472 + * @tf: destination ATA taskfile 4473 + * 4474 + * Return value: 4475 + * none 4476 + **/ 4477 + static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 4478 + { 4479 + struct ipr_sata_port *sata_port = ap->private_data; 4480 + struct ipr_ioasa_gata *g = &sata_port->ioasa; 4481 + 4482 + tf->feature = g->error; 4483 + tf->nsect = g->nsect; 4484 + tf->lbal = g->lbal; 4485 + tf->lbam = g->lbam; 4486 + tf->lbah = g->lbah; 4487 + tf->device = g->device; 4488 + tf->command = g->status; 4489 + tf->hob_nsect = g->hob_nsect; 4490 + tf->hob_lbal = g->hob_lbal; 4491 + tf->hob_lbam = g->hob_lbam; 4492 + tf->hob_lbah = g->hob_lbah; 4493 + tf->ctl = g->alt_status; 4494 + } 4495 + 4496 + /** 4497 + * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure 4498 + * @regs: destination 4499 + * @tf: source ATA taskfile 4500 + * 4501 + * Return value: 4502 + * none 4503 + **/ 4504 + static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs, 4505 + struct ata_taskfile *tf) 4506 + { 4507 + regs->feature = tf->feature; 4508 + regs->nsect = tf->nsect; 4509 + regs->lbal = tf->lbal; 4510 + regs->lbam = tf->lbam; 4511 + regs->lbah = tf->lbah; 4512 + regs->device = tf->device; 4513 + regs->command = tf->command; 4514 + regs->hob_feature = tf->hob_feature; 4515 + regs->hob_nsect = tf->hob_nsect; 4516 + regs->hob_lbal = tf->hob_lbal; 4517 + regs->hob_lbam = tf->hob_lbam; 4518 + regs->hob_lbah = tf->hob_lbah; 4519 + regs->ctl = tf->ctl; 4520 + } 4521 + 4522 + /** 4523 + * ipr_sata_done - done function for SATA commands 4524 + * @ipr_cmd: ipr command struct 4525 + * 4526 + * This function is invoked by the interrupt handler for 4527 + * ops generated by the SCSI mid-layer to SATA devices 4528 + * 4529 + * Return value: 4530 + * none 4531 + **/ 4532 + static void ipr_sata_done(struct ipr_cmnd *ipr_cmd) 4533 + { 4534 + struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; 4535 + struct ata_queued_cmd *qc = ipr_cmd->qc; 4536 + struct ipr_sata_port *sata_port = qc->ap->private_data; 4537 + struct ipr_resource_entry *res = sata_port->res; 4538 + u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc); 4539 + 4540 + memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata, 4541 + sizeof(struct ipr_ioasa_gata)); 4542 + ipr_dump_ioasa(ioa_cfg, ipr_cmd, res); 4543 + 4544 + if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET) 4545 + scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus, 4546 + res->cfgte.res_addr.target); 4547 + 4548 + if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR) 4549 + qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status); 4550 + else 4551 + qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status); 4552 + list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q); 4553 + ata_qc_complete(qc); 4554 + } 4555 + 4556 + /** 4557 + * ipr_build_ata_ioadl - Build an ATA scatter/gather list 4558 + * @ipr_cmd: ipr command struct 4559 + * @qc: ATA queued command 4560 + * 4561 + **/ 4562 + static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd, 4563 + struct ata_queued_cmd *qc) 4564 + { 4565 + u32 ioadl_flags = 0; 4566 + struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb; 4567 + struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl; 4568 + int len = qc->nbytes + qc->pad_len; 4569 + struct scatterlist *sg; 4570 + 4571 + if (len == 0) 4572 + return; 4573 + 4574 + if (qc->dma_dir == DMA_TO_DEVICE) { 4575 + ioadl_flags = IPR_IOADL_FLAGS_WRITE; 4576 + ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ; 4577 + ioarcb->write_data_transfer_length = cpu_to_be32(len); 4578 + ioarcb->write_ioadl_len = 4579 + cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg); 4580 + } else if (qc->dma_dir == DMA_FROM_DEVICE) { 4581 + ioadl_flags = IPR_IOADL_FLAGS_READ; 4582 + ioarcb->read_data_transfer_length = cpu_to_be32(len); 4583 + ioarcb->read_ioadl_len = 4584 + cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg); 4585 + } 4586 + 4587 + ata_for_each_sg(sg, qc) { 4588 + ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg)); 4589 + ioadl->address = cpu_to_be32(sg_dma_address(sg)); 4590 + if (ata_sg_is_last(sg, qc)) 4591 + ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST); 4592 + else 4593 + ioadl++; 4594 + } 4595 + } 4596 + 4597 + /** 4598 + * ipr_qc_issue - Issue a SATA qc to a device 4599 + * @qc: queued command 4600 + * 4601 + * Return value: 4602 + * 0 if success 4603 + **/ 4604 + static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc) 4605 + { 4606 + struct ata_port *ap = qc->ap; 4607 + struct ipr_sata_port *sata_port = ap->private_data; 4608 + struct ipr_resource_entry *res = sata_port->res; 4609 + struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg; 4610 + struct ipr_cmnd *ipr_cmd; 4611 + struct ipr_ioarcb *ioarcb; 4612 + struct ipr_ioarcb_ata_regs *regs; 4613 + 4614 + if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead)) 4615 + return -EIO; 4616 + 4617 + ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 4618 + ioarcb = &ipr_cmd->ioarcb; 4619 + regs = &ioarcb->add_data.u.regs; 4620 + 4621 + memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data)); 4622 + ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs)); 4623 + 4624 + list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q); 4625 + ipr_cmd->qc = qc; 4626 + ipr_cmd->done = ipr_sata_done; 4627 + ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle; 4628 + ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU; 4629 + ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC; 4630 + ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK; 4631 + ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem; 4632 + 4633 + ipr_build_ata_ioadl(ipr_cmd, qc); 4634 + regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION; 4635 + ipr_copy_sata_tf(regs, &qc->tf); 4636 + memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN); 4637 + ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr)); 4638 + 4639 + switch (qc->tf.protocol) { 4640 + case ATA_PROT_NODATA: 4641 + case ATA_PROT_PIO: 4642 + break; 4643 + 4644 + case ATA_PROT_DMA: 4645 + regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA; 4646 + break; 4647 + 4648 + case ATA_PROT_ATAPI: 4649 + case ATA_PROT_ATAPI_NODATA: 4650 + regs->flags |= IPR_ATA_FLAG_PACKET_CMD; 4651 + break; 4652 + 4653 + case ATA_PROT_ATAPI_DMA: 4654 + regs->flags |= IPR_ATA_FLAG_PACKET_CMD; 4655 + regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA; 4656 + break; 4657 + 4658 + default: 4659 + WARN_ON(1); 4660 + return -1; 4661 + } 4662 + 4663 + mb(); 4664 + writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr), 4665 + ioa_cfg->regs.ioarrin_reg); 4666 + return 0; 4667 + } 4668 + 4669 + /** 4670 + * ipr_ata_check_status - Return last ATA status 4671 + * @ap: ATA port 4672 + * 4673 + * Return value: 4674 + * ATA status 4675 + **/ 4676 + static u8 ipr_ata_check_status(struct ata_port *ap) 4677 + { 4678 + struct ipr_sata_port *sata_port = ap->private_data; 4679 + return sata_port->ioasa.status; 4680 + } 4681 + 4682 + /** 4683 + * ipr_ata_check_altstatus - Return last ATA altstatus 4684 + * @ap: ATA port 4685 + * 4686 + * Return value: 4687 + * Alt ATA status 4688 + **/ 4689 + static u8 ipr_ata_check_altstatus(struct ata_port *ap) 4690 + { 4691 + struct ipr_sata_port *sata_port = ap->private_data; 4692 + return sata_port->ioasa.alt_status; 4693 + } 4694 + 4695 + static struct ata_port_operations ipr_sata_ops = { 4696 + .port_disable = ata_port_disable, 4697 + .check_status = ipr_ata_check_status, 4698 + .check_altstatus = ipr_ata_check_altstatus, 4699 + .dev_select = ata_noop_dev_select, 4700 + .phy_reset = ipr_ata_phy_reset, 4701 + .post_internal_cmd = ipr_ata_post_internal, 4702 + .tf_read = ipr_tf_read, 4703 + .qc_prep = ata_noop_qc_prep, 4704 + .qc_issue = ipr_qc_issue, 4705 + .port_start = ata_sas_port_start, 4706 + .port_stop = ata_sas_port_stop 4707 + }; 4708 + 4709 + static struct ata_port_info sata_port_info = { 4710 + .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET | 4711 + ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA, 4712 + .pio_mask = 0x10, /* pio4 */ 4713 + .mwdma_mask = 0x07, 4714 + .udma_mask = 0x7f, /* udma0-6 */ 4715 + .port_ops = &ipr_sata_ops 4712 4716 }; 4713 4717 4714 4718 #ifdef CONFIG_PPC_PSERIES ··· 7018 6374 7019 6375 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata; 7020 6376 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg)); 6377 + host->transportt = &ipr_transport_template; 6378 + ata_host_init(&ioa_cfg->ata_host, &pdev->dev, 6379 + sata_port_info.flags, &ipr_sata_ops); 7021 6380 7022 6381 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id); 7023 6382
+15 -3
drivers/scsi/ipr.h
··· 28 28 29 29 #include <linux/types.h> 30 30 #include <linux/completion.h> 31 + #include <linux/libata.h> 31 32 #include <linux/list.h> 32 33 #include <linux/kref.h> 33 34 #include <scsi/scsi.h> ··· 37 36 /* 38 37 * Literals 39 38 */ 40 - #define IPR_DRIVER_VERSION "2.1.4" 41 - #define IPR_DRIVER_DATE "(August 2, 2006)" 39 + #define IPR_DRIVER_VERSION "2.2.0" 40 + #define IPR_DRIVER_DATE "(September 25, 2006)" 42 41 43 42 /* 44 43 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding ··· 850 849 u32 max_xfer_rate; 851 850 }; 852 851 852 + struct ipr_sata_port { 853 + struct ipr_ioa_cfg *ioa_cfg; 854 + struct ata_port *ap; 855 + struct ipr_resource_entry *res; 856 + struct ipr_ioasa_gata ioasa; 857 + }; 858 + 853 859 struct ipr_resource_entry { 854 860 struct ipr_config_table_entry cfgte; 855 861 u8 needs_sync_complete:1; ··· 866 858 u8 resetting_device:1; 867 859 868 860 struct scsi_device *sdev; 861 + struct ipr_sata_port *sata_port; 869 862 struct list_head queue; 870 863 }; 871 864 ··· 937 928 u32 time; 938 929 939 930 u8 op_code; 931 + u8 ata_op_code; 940 932 u8 type; 941 933 #define IPR_TRACE_START 0x00 942 934 #define IPR_TRACE_FINISH 0xff 943 - u16 cmd_index; 935 + u8 cmd_index; 944 936 945 937 __be32 res_handle; 946 938 union { ··· 1083 1073 1084 1074 struct ipr_cmnd *reset_cmd; 1085 1075 1076 + struct ata_host ata_host; 1086 1077 char ipr_cmd_label[8]; 1087 1078 #define IPR_CMD_LABEL "ipr_cmnd" 1088 1079 struct ipr_cmnd *ipr_cmnd_list[IPR_NUM_CMD_BLKS]; ··· 1096 1085 struct ipr_ioadl_desc ioadl[IPR_NUM_IOADL_ENTRIES]; 1097 1086 struct list_head queue; 1098 1087 struct scsi_cmnd *scsi_cmd; 1088 + struct ata_queued_cmd *qc; 1099 1089 struct completion completion; 1100 1090 struct timer_list timer; 1101 1091 void (*done) (struct ipr_cmnd *);