aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-10-09 11:16:14 -0400
committerJeff Garzik <jgarzik@pobox.com>2005-10-09 11:16:14 -0400
commitc4052da6f0c01a0b059d125d72bb934d0980b798 (patch)
treead50a17e4d14b8f6f1773158d956d424575d1712 /drivers/scsi/libata-core.c
parentcedc9a478d8c6265879dc3839ef3d4849a709184 (diff)
parent3d3467f0fdf61a421361c00cf84fcf0f1a6dc1e8 (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c433
1 files changed, 259 insertions, 174 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 943b44c3c16f..9aa93087d495 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -48,6 +48,7 @@
48#include <linux/completion.h> 48#include <linux/completion.h>
49#include <linux/suspend.h> 49#include <linux/suspend.h>
50#include <linux/workqueue.h> 50#include <linux/workqueue.h>
51#include <linux/jiffies.h>
51#include <scsi/scsi.h> 52#include <scsi/scsi.h>
52#include "scsi.h" 53#include "scsi.h"
53#include "scsi_priv.h" 54#include "scsi_priv.h"
@@ -62,6 +63,7 @@
62static unsigned int ata_busy_sleep (struct ata_port *ap, 63static unsigned int ata_busy_sleep (struct ata_port *ap,
63 unsigned long tmout_pat, 64 unsigned long tmout_pat,
64 unsigned long tmout); 65 unsigned long tmout);
66static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
65static void ata_set_mode(struct ata_port *ap); 67static void ata_set_mode(struct ata_port *ap);
66static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); 68static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev);
67static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift); 69static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift);
@@ -69,7 +71,6 @@ static int fgb(u32 bitmap);
69static int ata_choose_xfer_mode(struct ata_port *ap, 71static int ata_choose_xfer_mode(struct ata_port *ap,
70 u8 *xfer_mode_out, 72 u8 *xfer_mode_out,
71 unsigned int *xfer_shift_out); 73 unsigned int *xfer_shift_out);
72static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat);
73static void __ata_qc_complete(struct ata_queued_cmd *qc); 74static void __ata_qc_complete(struct ata_queued_cmd *qc);
74 75
75static unsigned int ata_unique_id = 1; 76static unsigned int ata_unique_id = 1;
@@ -1131,7 +1132,7 @@ static inline void ata_dump_id(struct ata_device *dev)
1131static void ata_dev_identify(struct ata_port *ap, unsigned int device) 1132static void ata_dev_identify(struct ata_port *ap, unsigned int device)
1132{ 1133{
1133 struct ata_device *dev = &ap->device[device]; 1134 struct ata_device *dev = &ap->device[device];
1134 unsigned int i; 1135 unsigned int major_version;
1135 u16 tmp; 1136 u16 tmp;
1136 unsigned long xfer_modes; 1137 unsigned long xfer_modes;
1137 u8 status; 1138 u8 status;
@@ -1229,9 +1230,9 @@ retry:
1229 * common ATA, ATAPI feature tests 1230 * common ATA, ATAPI feature tests
1230 */ 1231 */
1231 1232
1232 /* we require LBA and DMA support (bits 8 & 9 of word 49) */ 1233 /* we require DMA support (bits 8 of word 49) */
1233 if (!ata_id_has_dma(dev->id) || !ata_id_has_lba(dev->id)) { 1234 if (!ata_id_has_dma(dev->id)) {
1234 printk(KERN_DEBUG "ata%u: no dma/lba\n", ap->id); 1235 printk(KERN_DEBUG "ata%u: no dma\n", ap->id);
1235 goto err_out_nosup; 1236 goto err_out_nosup;
1236 } 1237 }
1237 1238
@@ -1251,32 +1252,69 @@ retry:
1251 if (!ata_id_is_ata(dev->id)) /* sanity check */ 1252 if (!ata_id_is_ata(dev->id)) /* sanity check */
1252 goto err_out_nosup; 1253 goto err_out_nosup;
1253 1254
1255 /* get major version */
1254 tmp = dev->id[ATA_ID_MAJOR_VER]; 1256 tmp = dev->id[ATA_ID_MAJOR_VER];
1255 for (i = 14; i >= 1; i--) 1257 for (major_version = 14; major_version >= 1; major_version--)
1256 if (tmp & (1 << i)) 1258 if (tmp & (1 << major_version))
1257 break; 1259 break;
1258 1260
1259 /* we require at least ATA-3 */ 1261 /*
1260 if (i < 3) { 1262 * The exact sequence expected by certain pre-ATA4 drives is:
1261 printk(KERN_DEBUG "ata%u: no ATA-3\n", ap->id); 1263 * SRST RESET
1262 goto err_out_nosup; 1264 * IDENTIFY
1263 } 1265 * INITIALIZE DEVICE PARAMETERS
1266 * anything else..
1267 * Some drives were very specific about that exact sequence.
1268 */
1269 if (major_version < 4 || (!ata_id_has_lba(dev->id)))
1270 ata_dev_init_params(ap, dev);
1271
1272 if (ata_id_has_lba(dev->id)) {
1273 dev->flags |= ATA_DFLAG_LBA;
1274
1275 if (ata_id_has_lba48(dev->id)) {
1276 dev->flags |= ATA_DFLAG_LBA48;
1277 dev->n_sectors = ata_id_u64(dev->id, 100);
1278 } else {
1279 dev->n_sectors = ata_id_u32(dev->id, 60);
1280 }
1281
1282 /* print device info to dmesg */
1283 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors:%s\n",
1284 ap->id, device,
1285 major_version,
1286 ata_mode_string(xfer_modes),
1287 (unsigned long long)dev->n_sectors,
1288 dev->flags & ATA_DFLAG_LBA48 ? " LBA48" : " LBA");
1289 } else {
1290 /* CHS */
1291
1292 /* Default translation */
1293 dev->cylinders = dev->id[1];
1294 dev->heads = dev->id[3];
1295 dev->sectors = dev->id[6];
1296 dev->n_sectors = dev->cylinders * dev->heads * dev->sectors;
1297
1298 if (ata_id_current_chs_valid(dev->id)) {
1299 /* Current CHS translation is valid. */
1300 dev->cylinders = dev->id[54];
1301 dev->heads = dev->id[55];
1302 dev->sectors = dev->id[56];
1303
1304 dev->n_sectors = ata_id_u32(dev->id, 57);
1305 }
1306
1307 /* print device info to dmesg */
1308 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors: CHS %d/%d/%d\n",
1309 ap->id, device,
1310 major_version,
1311 ata_mode_string(xfer_modes),
1312 (unsigned long long)dev->n_sectors,
1313 (int)dev->cylinders, (int)dev->heads, (int)dev->sectors);
1264 1314
1265 if (ata_id_has_lba48(dev->id)) {
1266 dev->flags |= ATA_DFLAG_LBA48;
1267 dev->n_sectors = ata_id_u64(dev->id, 100);
1268 } else {
1269 dev->n_sectors = ata_id_u32(dev->id, 60);
1270 } 1315 }
1271 1316
1272 ap->host->max_cmd_len = 16; 1317 ap->host->max_cmd_len = 16;
1273
1274 /* print device info to dmesg */
1275 printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors:%s\n",
1276 ap->id, device,
1277 ata_mode_string(xfer_modes),
1278 (unsigned long long)dev->n_sectors,
1279 dev->flags & ATA_DFLAG_LBA48 ? " lba48" : "");
1280 } 1318 }
1281 1319
1282 /* ATAPI-specific feature tests */ 1320 /* ATAPI-specific feature tests */
@@ -2144,6 +2182,54 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
2144} 2182}
2145 2183
2146/** 2184/**
2185 * ata_dev_init_params - Issue INIT DEV PARAMS command
2186 * @ap: Port associated with device @dev
2187 * @dev: Device to which command will be sent
2188 *
2189 * LOCKING:
2190 */
2191
2192static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev)
2193{
2194 DECLARE_COMPLETION(wait);
2195 struct ata_queued_cmd *qc;
2196 int rc;
2197 unsigned long flags;
2198 u16 sectors = dev->id[6];
2199 u16 heads = dev->id[3];
2200
2201 /* Number of sectors per track 1-255. Number of heads 1-16 */
2202 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16)
2203 return;
2204
2205 /* set up init dev params taskfile */
2206 DPRINTK("init dev params \n");
2207
2208 qc = ata_qc_new_init(ap, dev);
2209 BUG_ON(qc == NULL);
2210
2211 qc->tf.command = ATA_CMD_INIT_DEV_PARAMS;
2212 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
2213 qc->tf.protocol = ATA_PROT_NODATA;
2214 qc->tf.nsect = sectors;
2215 qc->tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
2216
2217 qc->waiting = &wait;
2218 qc->complete_fn = ata_qc_complete_noop;
2219
2220 spin_lock_irqsave(&ap->host_set->lock, flags);
2221 rc = ata_qc_issue(qc);
2222 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2223
2224 if (rc)
2225 ata_port_disable(ap);
2226 else
2227 wait_for_completion(&wait);
2228
2229 DPRINTK("EXIT\n");
2230}
2231
2232/**
2147 * ata_sg_clean - Unmap DMA memory associated with command 2233 * ata_sg_clean - Unmap DMA memory associated with command
2148 * @qc: Command containing DMA memory to be released 2234 * @qc: Command containing DMA memory to be released
2149 * 2235 *
@@ -2507,20 +2593,20 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
2507static unsigned long ata_pio_poll(struct ata_port *ap) 2593static unsigned long ata_pio_poll(struct ata_port *ap)
2508{ 2594{
2509 u8 status; 2595 u8 status;
2510 unsigned int poll_state = PIO_ST_UNKNOWN; 2596 unsigned int poll_state = HSM_ST_UNKNOWN;
2511 unsigned int reg_state = PIO_ST_UNKNOWN; 2597 unsigned int reg_state = HSM_ST_UNKNOWN;
2512 const unsigned int tmout_state = PIO_ST_TMOUT; 2598 const unsigned int tmout_state = HSM_ST_TMOUT;
2513 2599
2514 switch (ap->pio_task_state) { 2600 switch (ap->hsm_task_state) {
2515 case PIO_ST: 2601 case HSM_ST:
2516 case PIO_ST_POLL: 2602 case HSM_ST_POLL:
2517 poll_state = PIO_ST_POLL; 2603 poll_state = HSM_ST_POLL;
2518 reg_state = PIO_ST; 2604 reg_state = HSM_ST;
2519 break; 2605 break;
2520 case PIO_ST_LAST: 2606 case HSM_ST_LAST:
2521 case PIO_ST_LAST_POLL: 2607 case HSM_ST_LAST_POLL:
2522 poll_state = PIO_ST_LAST_POLL; 2608 poll_state = HSM_ST_LAST_POLL;
2523 reg_state = PIO_ST_LAST; 2609 reg_state = HSM_ST_LAST;
2524 break; 2610 break;
2525 default: 2611 default:
2526 BUG(); 2612 BUG();
@@ -2530,14 +2616,14 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2530 status = ata_chk_status(ap); 2616 status = ata_chk_status(ap);
2531 if (status & ATA_BUSY) { 2617 if (status & ATA_BUSY) {
2532 if (time_after(jiffies, ap->pio_task_timeout)) { 2618 if (time_after(jiffies, ap->pio_task_timeout)) {
2533 ap->pio_task_state = tmout_state; 2619 ap->hsm_task_state = tmout_state;
2534 return 0; 2620 return 0;
2535 } 2621 }
2536 ap->pio_task_state = poll_state; 2622 ap->hsm_task_state = poll_state;
2537 return ATA_SHORT_PAUSE; 2623 return ATA_SHORT_PAUSE;
2538 } 2624 }
2539 2625
2540 ap->pio_task_state = reg_state; 2626 ap->hsm_task_state = reg_state;
2541 return 0; 2627 return 0;
2542} 2628}
2543 2629
@@ -2562,14 +2648,14 @@ static int ata_pio_complete (struct ata_port *ap)
2562 * we enter, BSY will be cleared in a chk-status or two. If not, 2648 * we enter, BSY will be cleared in a chk-status or two. If not,
2563 * the drive is probably seeking or something. Snooze for a couple 2649 * the drive is probably seeking or something. Snooze for a couple
2564 * msecs, then chk-status again. If still busy, fall back to 2650 * msecs, then chk-status again. If still busy, fall back to
2565 * PIO_ST_POLL state. 2651 * HSM_ST_POLL state.
2566 */ 2652 */
2567 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); 2653 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
2568 if (drv_stat & (ATA_BUSY | ATA_DRQ)) { 2654 if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
2569 msleep(2); 2655 msleep(2);
2570 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); 2656 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
2571 if (drv_stat & (ATA_BUSY | ATA_DRQ)) { 2657 if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
2572 ap->pio_task_state = PIO_ST_LAST_POLL; 2658 ap->hsm_task_state = HSM_ST_LAST_POLL;
2573 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 2659 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
2574 return 0; 2660 return 0;
2575 } 2661 }
@@ -2577,14 +2663,14 @@ static int ata_pio_complete (struct ata_port *ap)
2577 2663
2578 drv_stat = ata_wait_idle(ap); 2664 drv_stat = ata_wait_idle(ap);
2579 if (!ata_ok(drv_stat)) { 2665 if (!ata_ok(drv_stat)) {
2580 ap->pio_task_state = PIO_ST_ERR; 2666 ap->hsm_task_state = HSM_ST_ERR;
2581 return 0; 2667 return 0;
2582 } 2668 }
2583 2669
2584 qc = ata_qc_from_tag(ap, ap->active_tag); 2670 qc = ata_qc_from_tag(ap, ap->active_tag);
2585 assert(qc != NULL); 2671 assert(qc != NULL);
2586 2672
2587 ap->pio_task_state = PIO_ST_IDLE; 2673 ap->hsm_task_state = HSM_ST_IDLE;
2588 2674
2589 ata_poll_qc_complete(qc, drv_stat); 2675 ata_poll_qc_complete(qc, drv_stat);
2590 2676
@@ -2744,7 +2830,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
2744 unsigned char *buf; 2830 unsigned char *buf;
2745 2831
2746 if (qc->cursect == (qc->nsect - 1)) 2832 if (qc->cursect == (qc->nsect - 1))
2747 ap->pio_task_state = PIO_ST_LAST; 2833 ap->hsm_task_state = HSM_ST_LAST;
2748 2834
2749 page = sg[qc->cursg].page; 2835 page = sg[qc->cursg].page;
2750 offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; 2836 offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE;
@@ -2794,7 +2880,7 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
2794 unsigned int offset, count; 2880 unsigned int offset, count;
2795 2881
2796 if (qc->curbytes + bytes >= qc->nbytes) 2882 if (qc->curbytes + bytes >= qc->nbytes)
2797 ap->pio_task_state = PIO_ST_LAST; 2883 ap->hsm_task_state = HSM_ST_LAST;
2798 2884
2799next_sg: 2885next_sg:
2800 if (unlikely(qc->cursg >= qc->n_elem)) { 2886 if (unlikely(qc->cursg >= qc->n_elem)) {
@@ -2816,7 +2902,7 @@ next_sg:
2816 for (i = 0; i < words; i++) 2902 for (i = 0; i < words; i++)
2817 ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); 2903 ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write);
2818 2904
2819 ap->pio_task_state = PIO_ST_LAST; 2905 ap->hsm_task_state = HSM_ST_LAST;
2820 return; 2906 return;
2821 } 2907 }
2822 2908
@@ -2897,7 +2983,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
2897err_out: 2983err_out:
2898 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", 2984 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n",
2899 ap->id, dev->devno); 2985 ap->id, dev->devno);
2900 ap->pio_task_state = PIO_ST_ERR; 2986 ap->hsm_task_state = HSM_ST_ERR;
2901} 2987}
2902 2988
2903/** 2989/**
@@ -2919,14 +3005,14 @@ static void ata_pio_block(struct ata_port *ap)
2919 * a chk-status or two. If not, the drive is probably seeking 3005 * a chk-status or two. If not, the drive is probably seeking
2920 * or something. Snooze for a couple msecs, then 3006 * or something. Snooze for a couple msecs, then
2921 * chk-status again. If still busy, fall back to 3007 * chk-status again. If still busy, fall back to
2922 * PIO_ST_POLL state. 3008 * HSM_ST_POLL state.
2923 */ 3009 */
2924 status = ata_busy_wait(ap, ATA_BUSY, 5); 3010 status = ata_busy_wait(ap, ATA_BUSY, 5);
2925 if (status & ATA_BUSY) { 3011 if (status & ATA_BUSY) {
2926 msleep(2); 3012 msleep(2);
2927 status = ata_busy_wait(ap, ATA_BUSY, 10); 3013 status = ata_busy_wait(ap, ATA_BUSY, 10);
2928 if (status & ATA_BUSY) { 3014 if (status & ATA_BUSY) {
2929 ap->pio_task_state = PIO_ST_POLL; 3015 ap->hsm_task_state = HSM_ST_POLL;
2930 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 3016 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
2931 return; 3017 return;
2932 } 3018 }
@@ -2938,7 +3024,7 @@ static void ata_pio_block(struct ata_port *ap)
2938 if (is_atapi_taskfile(&qc->tf)) { 3024 if (is_atapi_taskfile(&qc->tf)) {
2939 /* no more data to transfer or unsupported ATAPI command */ 3025 /* no more data to transfer or unsupported ATAPI command */
2940 if ((status & ATA_DRQ) == 0) { 3026 if ((status & ATA_DRQ) == 0) {
2941 ap->pio_task_state = PIO_ST_LAST; 3027 ap->hsm_task_state = HSM_ST_LAST;
2942 return; 3028 return;
2943 } 3029 }
2944 3030
@@ -2946,7 +3032,7 @@ static void ata_pio_block(struct ata_port *ap)
2946 } else { 3032 } else {
2947 /* handle BSY=0, DRQ=0 as error */ 3033 /* handle BSY=0, DRQ=0 as error */
2948 if ((status & ATA_DRQ) == 0) { 3034 if ((status & ATA_DRQ) == 0) {
2949 ap->pio_task_state = PIO_ST_ERR; 3035 ap->hsm_task_state = HSM_ST_ERR;
2950 return; 3036 return;
2951 } 3037 }
2952 3038
@@ -2966,7 +3052,7 @@ static void ata_pio_error(struct ata_port *ap)
2966 printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n", 3052 printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n",
2967 ap->id, drv_stat); 3053 ap->id, drv_stat);
2968 3054
2969 ap->pio_task_state = PIO_ST_IDLE; 3055 ap->hsm_task_state = HSM_ST_IDLE;
2970 3056
2971 ata_poll_qc_complete(qc, drv_stat | ATA_ERR); 3057 ata_poll_qc_complete(qc, drv_stat | ATA_ERR);
2972} 3058}
@@ -2981,25 +3067,25 @@ fsm_start:
2981 timeout = 0; 3067 timeout = 0;
2982 qc_completed = 0; 3068 qc_completed = 0;
2983 3069
2984 switch (ap->pio_task_state) { 3070 switch (ap->hsm_task_state) {
2985 case PIO_ST_IDLE: 3071 case HSM_ST_IDLE:
2986 return; 3072 return;
2987 3073
2988 case PIO_ST: 3074 case HSM_ST:
2989 ata_pio_block(ap); 3075 ata_pio_block(ap);
2990 break; 3076 break;
2991 3077
2992 case PIO_ST_LAST: 3078 case HSM_ST_LAST:
2993 qc_completed = ata_pio_complete(ap); 3079 qc_completed = ata_pio_complete(ap);
2994 break; 3080 break;
2995 3081
2996 case PIO_ST_POLL: 3082 case HSM_ST_POLL:
2997 case PIO_ST_LAST_POLL: 3083 case HSM_ST_LAST_POLL:
2998 timeout = ata_pio_poll(ap); 3084 timeout = ata_pio_poll(ap);
2999 break; 3085 break;
3000 3086
3001 case PIO_ST_TMOUT: 3087 case HSM_ST_TMOUT:
3002 case PIO_ST_ERR: 3088 case HSM_ST_ERR:
3003 ata_pio_error(ap); 3089 ata_pio_error(ap);
3004 return; 3090 return;
3005 } 3091 }
@@ -3010,52 +3096,6 @@ fsm_start:
3010 goto fsm_start; 3096 goto fsm_start;
3011} 3097}
3012 3098
3013static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
3014 struct scsi_cmnd *cmd)
3015{
3016 DECLARE_COMPLETION(wait);
3017 struct ata_queued_cmd *qc;
3018 unsigned long flags;
3019 int rc;
3020
3021 DPRINTK("ATAPI request sense\n");
3022
3023 qc = ata_qc_new_init(ap, dev);
3024 BUG_ON(qc == NULL);
3025
3026 /* FIXME: is this needed? */
3027 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
3028
3029 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
3030 qc->dma_dir = DMA_FROM_DEVICE;
3031
3032 memset(&qc->cdb, 0, ap->cdb_len);
3033 qc->cdb[0] = REQUEST_SENSE;
3034 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE;
3035
3036 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
3037 qc->tf.command = ATA_CMD_PACKET;
3038
3039 qc->tf.protocol = ATA_PROT_ATAPI;
3040 qc->tf.lbam = (8 * 1024) & 0xff;
3041 qc->tf.lbah = (8 * 1024) >> 8;
3042 qc->nbytes = SCSI_SENSE_BUFFERSIZE;
3043
3044 qc->waiting = &wait;
3045 qc->complete_fn = ata_qc_complete_noop;
3046
3047 spin_lock_irqsave(&ap->host_set->lock, flags);
3048 rc = ata_qc_issue(qc);
3049 spin_unlock_irqrestore(&ap->host_set->lock, flags);
3050
3051 if (rc)
3052 ata_port_disable(ap);
3053 else
3054 wait_for_completion(&wait);
3055
3056 DPRINTK("EXIT\n");
3057}
3058
3059/** 3099/**
3060 * ata_qc_timeout - Handle timeout of queued command 3100 * ata_qc_timeout - Handle timeout of queued command
3061 * @qc: Command that timed out 3101 * @qc: Command that timed out
@@ -3173,14 +3213,14 @@ void ata_eng_timeout(struct ata_port *ap)
3173 DPRINTK("ENTER\n"); 3213 DPRINTK("ENTER\n");
3174 3214
3175 qc = ata_qc_from_tag(ap, ap->active_tag); 3215 qc = ata_qc_from_tag(ap, ap->active_tag);
3176 if (!qc) { 3216 if (qc)
3217 ata_qc_timeout(qc);
3218 else {
3177 printk(KERN_ERR "ata%u: BUG: timeout without command\n", 3219 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
3178 ap->id); 3220 ap->id);
3179 goto out; 3221 goto out;
3180 } 3222 }
3181 3223
3182 ata_qc_timeout(qc);
3183
3184out: 3224out:
3185 DPRINTK("EXIT\n"); 3225 DPRINTK("EXIT\n");
3186} 3226}
@@ -3238,14 +3278,18 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
3238 3278
3239 ata_tf_init(ap, &qc->tf, dev->devno); 3279 ata_tf_init(ap, &qc->tf, dev->devno);
3240 3280
3241 if (dev->flags & ATA_DFLAG_LBA48) 3281 if (dev->flags & ATA_DFLAG_LBA) {
3242 qc->tf.flags |= ATA_TFLAG_LBA48; 3282 qc->tf.flags |= ATA_TFLAG_LBA;
3283
3284 if (dev->flags & ATA_DFLAG_LBA48)
3285 qc->tf.flags |= ATA_TFLAG_LBA48;
3286 }
3243 } 3287 }
3244 3288
3245 return qc; 3289 return qc;
3246} 3290}
3247 3291
3248static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) 3292int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat)
3249{ 3293{
3250 return 0; 3294 return 0;
3251} 3295}
@@ -3442,7 +3486,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3442 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ 3486 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */
3443 ata_qc_set_polling(qc); 3487 ata_qc_set_polling(qc);
3444 ata_tf_to_host_nolock(ap, &qc->tf); 3488 ata_tf_to_host_nolock(ap, &qc->tf);
3445 ap->pio_task_state = PIO_ST; 3489 ap->hsm_task_state = HSM_ST;
3446 queue_work(ata_wq, &ap->pio_task); 3490 queue_work(ata_wq, &ap->pio_task);
3447 break; 3491 break;
3448 3492
@@ -3668,7 +3712,7 @@ u8 ata_bmdma_status(struct ata_port *ap)
3668 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; 3712 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
3669 host_stat = readb(mmio + ATA_DMA_STATUS); 3713 host_stat = readb(mmio + ATA_DMA_STATUS);
3670 } else 3714 } else
3671 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 3715 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
3672 return host_stat; 3716 return host_stat;
3673} 3717}
3674 3718
@@ -3888,7 +3932,7 @@ static void atapi_packet_task(void *_data)
3888 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); 3932 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
3889 3933
3890 /* PIO commands are handled by polling */ 3934 /* PIO commands are handled by polling */
3891 ap->pio_task_state = PIO_ST; 3935 ap->hsm_task_state = HSM_ST;
3892 queue_work(ata_wq, &ap->pio_task); 3936 queue_work(ata_wq, &ap->pio_task);
3893 } 3937 }
3894 3938
@@ -4202,7 +4246,7 @@ int ata_device_add(struct ata_probe_ent *ent)
4202 for (i = 0; i < count; i++) { 4246 for (i = 0; i < count; i++) {
4203 struct ata_port *ap = host_set->ports[i]; 4247 struct ata_port *ap = host_set->ports[i];
4204 4248
4205 scsi_scan_host(ap->host); 4249 ata_scsi_scan_host(ap);
4206 } 4250 }
4207 4251
4208 dev_set_drvdata(dev, host_set); 4252 dev_set_drvdata(dev, host_set);
@@ -4362,85 +4406,87 @@ void ata_pci_host_stop (struct ata_host_set *host_set)
4362 * ata_pci_init_native_mode - Initialize native-mode driver 4406 * ata_pci_init_native_mode - Initialize native-mode driver
4363 * @pdev: pci device to be initialized 4407 * @pdev: pci device to be initialized
4364 * @port: array[2] of pointers to port info structures. 4408 * @port: array[2] of pointers to port info structures.
4409 * @ports: bitmap of ports present
4365 * 4410 *
4366 * Utility function which allocates and initializes an 4411 * Utility function which allocates and initializes an
4367 * ata_probe_ent structure for a standard dual-port 4412 * ata_probe_ent structure for a standard dual-port
4368 * PIO-based IDE controller. The returned ata_probe_ent 4413 * PIO-based IDE controller. The returned ata_probe_ent
4369 * structure can be passed to ata_device_add(). The returned 4414 * structure can be passed to ata_device_add(). The returned
4370 * ata_probe_ent structure should then be freed with kfree(). 4415 * ata_probe_ent structure should then be freed with kfree().
4416 *
4417 * The caller need only pass the address of the primary port, the
4418 * secondary will be deduced automatically. If the device has non
4419 * standard secondary port mappings this function can be called twice,
4420 * once for each interface.
4371 */ 4421 */
4372 4422
4373struct ata_probe_ent * 4423struct ata_probe_ent *
4374ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) 4424ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports)
4375{ 4425{
4376 struct ata_probe_ent *probe_ent = 4426 struct ata_probe_ent *probe_ent =
4377 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 4427 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
4428 int p = 0;
4429
4378 if (!probe_ent) 4430 if (!probe_ent)
4379 return NULL; 4431 return NULL;
4380 4432
4381 probe_ent->n_ports = 2;
4382 probe_ent->irq = pdev->irq; 4433 probe_ent->irq = pdev->irq;
4383 probe_ent->irq_flags = SA_SHIRQ; 4434 probe_ent->irq_flags = SA_SHIRQ;
4384 4435
4385 probe_ent->port[0].cmd_addr = pci_resource_start(pdev, 0); 4436 if (ports & ATA_PORT_PRIMARY) {
4386 probe_ent->port[0].altstatus_addr = 4437 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
4387 probe_ent->port[0].ctl_addr = 4438 probe_ent->port[p].altstatus_addr =
4388 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 4439 probe_ent->port[p].ctl_addr =
4389 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); 4440 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
4390 4441 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4);
4391 probe_ent->port[1].cmd_addr = pci_resource_start(pdev, 2); 4442 ata_std_ports(&probe_ent->port[p]);
4392 probe_ent->port[1].altstatus_addr = 4443 p++;
4393 probe_ent->port[1].ctl_addr = 4444 }
4394 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
4395 probe_ent->port[1].bmdma_addr = pci_resource_start(pdev, 4) + 8;
4396 4445
4397 ata_std_ports(&probe_ent->port[0]); 4446 if (ports & ATA_PORT_SECONDARY) {
4398 ata_std_ports(&probe_ent->port[1]); 4447 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2);
4448 probe_ent->port[p].altstatus_addr =
4449 probe_ent->port[p].ctl_addr =
4450 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
4451 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8;
4452 ata_std_ports(&probe_ent->port[p]);
4453 p++;
4454 }
4399 4455
4456 probe_ent->n_ports = p;
4400 return probe_ent; 4457 return probe_ent;
4401} 4458}
4402 4459
4403static struct ata_probe_ent * 4460static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info **port, int port_num)
4404ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
4405 struct ata_probe_ent **ppe2)
4406{ 4461{
4407 struct ata_probe_ent *probe_ent, *probe_ent2; 4462 struct ata_probe_ent *probe_ent;
4408 4463
4409 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 4464 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
4410 if (!probe_ent) 4465 if (!probe_ent)
4411 return NULL; 4466 return NULL;
4412 probe_ent2 = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[1]);
4413 if (!probe_ent2) {
4414 kfree(probe_ent);
4415 return NULL;
4416 }
4417 4467
4418 probe_ent->n_ports = 1; 4468
4419 probe_ent->irq = 14;
4420
4421 probe_ent->hard_port_no = 0;
4422 probe_ent->legacy_mode = 1; 4469 probe_ent->legacy_mode = 1;
4423 4470 probe_ent->n_ports = 1;
4424 probe_ent2->n_ports = 1; 4471 probe_ent->hard_port_no = port_num;
4425 probe_ent2->irq = 15; 4472
4426 4473 switch(port_num)
4427 probe_ent2->hard_port_no = 1; 4474 {
4428 probe_ent2->legacy_mode = 1; 4475 case 0:
4429 4476 probe_ent->irq = 14;
4430 probe_ent->port[0].cmd_addr = 0x1f0; 4477 probe_ent->port[0].cmd_addr = 0x1f0;
4431 probe_ent->port[0].altstatus_addr = 4478 probe_ent->port[0].altstatus_addr =
4432 probe_ent->port[0].ctl_addr = 0x3f6; 4479 probe_ent->port[0].ctl_addr = 0x3f6;
4433 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); 4480 break;
4434 4481 case 1:
4435 probe_ent2->port[0].cmd_addr = 0x170; 4482 probe_ent->irq = 15;
4436 probe_ent2->port[0].altstatus_addr = 4483 probe_ent->port[0].cmd_addr = 0x170;
4437 probe_ent2->port[0].ctl_addr = 0x376; 4484 probe_ent->port[0].altstatus_addr =
4438 probe_ent2->port[0].bmdma_addr = pci_resource_start(pdev, 4)+8; 4485 probe_ent->port[0].ctl_addr = 0x376;
4439 4486 break;
4487 }
4488 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4) + 8 * port_num;
4440 ata_std_ports(&probe_ent->port[0]); 4489 ata_std_ports(&probe_ent->port[0]);
4441 ata_std_ports(&probe_ent2->port[0]);
4442
4443 *ppe2 = probe_ent2;
4444 return probe_ent; 4490 return probe_ent;
4445} 4491}
4446 4492
@@ -4469,7 +4515,7 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
4469int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, 4515int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4470 unsigned int n_ports) 4516 unsigned int n_ports)
4471{ 4517{
4472 struct ata_probe_ent *probe_ent, *probe_ent2 = NULL; 4518 struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL;
4473 struct ata_port_info *port[2]; 4519 struct ata_port_info *port[2];
4474 u8 tmp8, mask; 4520 u8 tmp8, mask;
4475 unsigned int legacy_mode = 0; 4521 unsigned int legacy_mode = 0;
@@ -4486,7 +4532,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4486 4532
4487 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 4533 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0
4488 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { 4534 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
4489 /* TODO: support transitioning to native mode? */ 4535 /* TODO: What if one channel is in native mode ... */
4490 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); 4536 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
4491 mask = (1 << 2) | (1 << 0); 4537 mask = (1 << 2) | (1 << 0);
4492 if ((tmp8 & mask) != mask) 4538 if ((tmp8 & mask) != mask)
@@ -4494,11 +4540,20 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4494 } 4540 }
4495 4541
4496 /* FIXME... */ 4542 /* FIXME... */
4497 if ((!legacy_mode) && (n_ports > 1)) { 4543 if ((!legacy_mode) && (n_ports > 2)) {
4498 printk(KERN_ERR "ata: BUG: native mode, n_ports > 1\n"); 4544 printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n");
4499 return -EINVAL; 4545 n_ports = 2;
4546 /* For now */
4500 } 4547 }
4501 4548
4549 /* FIXME: Really for ATA it isn't safe because the device may be
4550 multi-purpose and we want to leave it alone if it was already
4551 enabled. Secondly for shared use as Arjan says we want refcounting
4552
4553 Checking dev->is_enabled is insufficient as this is not set at
4554 boot for the primary video which is BIOS enabled
4555 */
4556
4502 rc = pci_enable_device(pdev); 4557 rc = pci_enable_device(pdev);
4503 if (rc) 4558 if (rc)
4504 return rc; 4559 return rc;
@@ -4509,6 +4564,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4509 goto err_out; 4564 goto err_out;
4510 } 4565 }
4511 4566
4567 /* FIXME: Should use platform specific mappers for legacy port ranges */
4512 if (legacy_mode) { 4568 if (legacy_mode) {
4513 if (!request_region(0x1f0, 8, "libata")) { 4569 if (!request_region(0x1f0, 8, "libata")) {
4514 struct resource *conflict, res; 4570 struct resource *conflict, res;
@@ -4553,10 +4609,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4553 goto err_out_regions; 4609 goto err_out_regions;
4554 4610
4555 if (legacy_mode) { 4611 if (legacy_mode) {
4556 probe_ent = ata_pci_init_legacy_mode(pdev, port, &probe_ent2); 4612 if (legacy_mode & (1 << 0))
4557 } else 4613 probe_ent = ata_pci_init_legacy_port(pdev, port, 0);
4558 probe_ent = ata_pci_init_native_mode(pdev, port); 4614 if (legacy_mode & (1 << 1))
4559 if (!probe_ent) { 4615 probe_ent2 = ata_pci_init_legacy_port(pdev, port, 1);
4616 } else {
4617 if (n_ports == 2)
4618 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
4619 else
4620 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY);
4621 }
4622 if (!probe_ent && !probe_ent2) {
4560 rc = -ENOMEM; 4623 rc = -ENOMEM;
4561 goto err_out_regions; 4624 goto err_out_regions;
4562 } 4625 }
@@ -4668,6 +4731,27 @@ static void __exit ata_exit(void)
4668module_init(ata_init); 4731module_init(ata_init);
4669module_exit(ata_exit); 4732module_exit(ata_exit);
4670 4733
4734static unsigned long ratelimit_time;
4735static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED;
4736
4737int ata_ratelimit(void)
4738{
4739 int rc;
4740 unsigned long flags;
4741
4742 spin_lock_irqsave(&ata_ratelimit_lock, flags);
4743
4744 if (time_after(jiffies, ratelimit_time)) {
4745 rc = 1;
4746 ratelimit_time = jiffies + (HZ/5);
4747 } else
4748 rc = 0;
4749
4750 spin_unlock_irqrestore(&ata_ratelimit_lock, flags);
4751
4752 return rc;
4753}
4754
4671/* 4755/*
4672 * libata is essentially a library of internal helper functions for 4756 * libata is essentially a library of internal helper functions for
4673 * low-level ATA host controller drivers. As such, the API/ABI is 4757 * low-level ATA host controller drivers. As such, the API/ABI is
@@ -4709,6 +4793,7 @@ EXPORT_SYMBOL_GPL(sata_phy_reset);
4709EXPORT_SYMBOL_GPL(__sata_phy_reset); 4793EXPORT_SYMBOL_GPL(__sata_phy_reset);
4710EXPORT_SYMBOL_GPL(ata_bus_reset); 4794EXPORT_SYMBOL_GPL(ata_bus_reset);
4711EXPORT_SYMBOL_GPL(ata_port_disable); 4795EXPORT_SYMBOL_GPL(ata_port_disable);
4796EXPORT_SYMBOL_GPL(ata_ratelimit);
4712EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 4797EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
4713EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 4798EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
4714EXPORT_SYMBOL_GPL(ata_scsi_error); 4799EXPORT_SYMBOL_GPL(ata_scsi_error);