25 #include <linux/sched.h>
54 if (scsi_sg_count(srb) == 0) {
55 if (*offset >= scsi_bufflen(srb))
57 cnt =
min(buflen, scsi_bufflen(srb) - *offset);
59 memcpy((
unsigned char *) scsi_sglist(srb) + *offset,
62 memcpy(buffer, (
unsigned char *) scsi_sglist(srb) +
83 while (cnt < buflen && *index < scsi_sg_count(srb)) {
90 if (sglen > buflen - cnt) {
107 unsigned int plen =
min(sglen, (
unsigned int)
109 unsigned char *
ptr =
kmap(page);
112 memcpy(ptr + poff, buffer + cnt, plen);
114 memcpy(buffer + cnt, ptr + poff, plen);
139 if (buflen < scsi_bufflen(srb))
140 scsi_set_resid(srb, scsi_bufflen(srb) - buflen);
150 if (buflen < scsi_bufflen(srb))
151 scsi_set_resid(srb, scsi_bufflen(srb) - buflen);
180 RTSX_DEBUGP(
"-- transport indicates error, resetting\n");
215 val |= (
u32)(cmd_type & 0x03) << 30;
216 val |= (
u32)(reg_addr & 0x3FFF) << 16;
217 val |= (
u32)mask << 8;
233 val |= (
u32)(chip->
ci * 4) & 0x00FFFFFF;
259 rtsx->
done = &trans_done;
261 init_completion(&trans_done);
266 val |= (
u32)(chip->
ci * 4) & 0x00FFFFFF;
275 &trans_done, timeout *
HZ / 1000);
300 static inline void rtsx_add_sg_tbl(
311 temp_opt = option & (~
SG_END);
316 val = ((
u64)addr << 32) | ((
u64)temp_len << 12) | temp_opt;
326 static int rtsx_transfer_sglist_adma_partial(
struct rtsx_chip *chip,
u8 card,
334 int sg_cnt,
i, resid;
340 if ((sg ==
NULL) || (num_sg <= 0) || !offset || !index)
362 rtsx->
done = &trans_done;
379 for (i = 0; i < *
index; i++)
381 for (i = *index; i < sg_cnt; i++) {
390 (
unsigned int)addr, len);
391 RTSX_DEBUGP(
"*index = %d, *offset = %d\n", *index, *offset);
395 if ((len - *offset) > resid) {
405 if ((i == (sg_cnt - 1)) || !resid)
410 rtsx_add_sg_tbl(chip, (
u32)addr, (
u32)len, option);
420 val |= (
u32)(dir & 0x01) << 29;
425 init_completion(&trans_done);
433 &trans_done, timeout *
HZ / 1000);
435 RTSX_DEBUGP(
"Timeout (%s %d)\n", __func__, __LINE__);
452 init_completion(&trans_done);
455 &trans_done, timeout *
HZ / 1000);
457 RTSX_DEBUGP(
"Timeout (%s %d)\n", __func__, __LINE__);
485 static int rtsx_transfer_sglist_adma(
struct rtsx_chip *chip,
u8 card,
497 if ((sg ==
NULL) || (num_sg <= 0))
519 rtsx->
done = &trans_done;
526 buf_cnt =
dma_map_sg(&(rtsx->
pci->dev), sg, num_sg, dma_dir);
540 for (j = 0; j < sg_cnt; j++) {
546 (
unsigned int)addr, len);
548 if (j == (sg_cnt - 1))
553 rtsx_add_sg_tbl(chip, (
u32)addr, (
u32)len, option);
560 val |= (
u32)(dir & 0x01) << 29;
565 init_completion(&trans_done);
573 &trans_done, timeout *
HZ / 1000);
575 RTSX_DEBUGP(
"Timeout (%s %d)\n", __func__, __LINE__);
595 init_completion(&trans_done);
598 &trans_done, timeout *
HZ / 1000);
600 RTSX_DEBUGP(
"Timeout (%s %d)\n", __func__, __LINE__);
628 static int rtsx_transfer_buf(
struct rtsx_chip *chip,
u8 card,
void *
buf,
size_t len,
639 if ((buf ==
NULL) || (len <= 0))
662 val |= (
u32)(dir & 0x01) << 29;
663 val |= (
u32)(len & 0x00FFFFFF);
668 rtsx->
done = &trans_done;
670 init_completion(&trans_done);
682 &trans_done, timeout *
HZ / 1000);
684 RTSX_DEBUGP(
"Timeout (%s %d)\n", __func__, __LINE__);
710 void *buf,
size_t len,
int use_sg,
unsigned int *index,
721 err = rtsx_transfer_sglist_adma_partial(chip, card,
723 index, offset, (
int)len, dma_dir, timeout);
725 err = rtsx_transfer_buf(chip, card,
726 buf, len, dma_dir, timeout);
752 err = rtsx_transfer_sglist_adma(chip, card,
754 use_sg, dma_dir, timeout);
756 err = rtsx_transfer_buf(chip, card, buf, len, dma_dir, timeout);