Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 173659
b: refs/heads/master
c: 5868287
h: refs/heads/master
i:
  173657: fed5d6b
  173655: bcdf402
v: v3
  • Loading branch information
Robert Love authored and James Bottomley committed Dec 4, 2009
1 parent a0c92c4 commit 43de4f1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 47 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 07aac328342d6ca1725d901e1c5da8a1aa88f557
refs/heads/master: 5868287460b0fc243e828a0b856cd53d8bf45739
56 changes: 10 additions & 46 deletions trunk/drivers/scsi/libfc/fc_fcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
size_t len;
void *buf;
struct scatterlist *sg;
size_t remaining;
u32 nents;

fh = fc_frame_header_get(fp);
offset = ntohl(fh->fh_parm_offset);
Expand All @@ -347,55 +347,19 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
if (offset != fsp->xfer_len)
fsp->state |= FC_SRB_DISCONTIG;

crc = 0;
if (fr_flags(fp) & FCPHF_CRC_UNCHECKED)
crc = crc32(~0, (u8 *) fh, sizeof(*fh));

sg = scsi_sglist(sc);
remaining = len;

while (remaining > 0 && sg) {
size_t off;
void *page_addr;
size_t sg_bytes;

if (offset >= sg->length) {
offset -= sg->length;
sg = sg_next(sg);
continue;
}
sg_bytes = min(remaining, sg->length - offset);

/*
* The scatterlist item may be bigger than PAGE_SIZE,
* but we are limited to mapping PAGE_SIZE at a time.
*/
off = offset + sg->offset;
sg_bytes = min(sg_bytes, (size_t)
(PAGE_SIZE - (off & ~PAGE_MASK)));
page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT),
KM_SOFTIRQ0);
if (!page_addr)
break; /* XXX panic? */

if (fr_flags(fp) & FCPHF_CRC_UNCHECKED)
crc = crc32(crc, buf, sg_bytes);
memcpy((char *)page_addr + (off & ~PAGE_MASK), buf,
sg_bytes);

kunmap_atomic(page_addr, KM_SOFTIRQ0);
buf += sg_bytes;
offset += sg_bytes;
remaining -= sg_bytes;
copy_len += sg_bytes;
}
nents = scsi_sg_count(sc);

if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED)) {
copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents,
&offset, KM_SOFTIRQ0, NULL);
} else {
crc = crc32(~0, (u8 *) fh, sizeof(*fh));
copy_len = fc_copy_buffer_to_sglist(buf, len, sg, &nents,
&offset, KM_SOFTIRQ0, &crc);
buf = fc_frame_payload_get(fp, 0);
if (len % 4) {
if (len % 4)
crc = crc32(crc, buf + len, 4 - (len % 4));
len += 4 - (len % 4);
}

if (~crc != le32_to_cpu(fr_crc(fp))) {
crc_err:
Expand Down
60 changes: 60 additions & 0 deletions trunk/drivers/scsi/libfc/fc_libfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,63 @@ static void __exit libfc_exit(void)
fc_destroy_rport();
}
module_exit(libfc_exit);

/**
* fc_copy_buffer_to_sglist() - This routine copies the data of a buffer
* into a scatter-gather list (SG list).
*
* @buf: pointer to the data buffer.
* @len: the byte-length of the data buffer.
* @sg: pointer to the pointer of the SG list.
* @nents: pointer to the remaining number of entries in the SG list.
* @offset: pointer to the current offset in the SG list.
* @km_type: dedicated page table slot type for kmap_atomic.
* @crc: pointer to the 32-bit crc value.
* If crc is NULL, CRC is not calculated.
*/
u32 fc_copy_buffer_to_sglist(void *buf, size_t len,
struct scatterlist *sg,
u32 *nents, size_t *offset,
enum km_type km_type, u32 *crc)
{
size_t remaining = len;
u32 copy_len = 0;

while (remaining > 0 && sg) {
size_t off, sg_bytes;
void *page_addr;

if (*offset >= sg->length) {
/*
* Check for end and drop resources
* from the last iteration.
*/
if (!(*nents))
break;
--(*nents);
*offset -= sg->length;
sg = sg_next(sg);
continue;
}
sg_bytes = min(remaining, sg->length - *offset);

/*
* The scatterlist item may be bigger than PAGE_SIZE,
* but we are limited to mapping PAGE_SIZE at a time.
*/
off = *offset + sg->offset;
sg_bytes = min(sg_bytes,
(size_t)(PAGE_SIZE - (off & ~PAGE_MASK)));
page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT),
km_type);
if (crc)
*crc = crc32(*crc, buf, sg_bytes);
memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, sg_bytes);
kunmap_atomic(page_addr, km_type);
buf += sg_bytes;
*offset += sg_bytes;
remaining -= sg_bytes;
copy_len += sg_bytes;
}
return copy_len;
}
8 changes: 8 additions & 0 deletions trunk/drivers/scsi/libfc/fc_libfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ void fc_destroy_fcp(void);
*/
const char *fc_els_resp_type(struct fc_frame *);

/*
* Copies a buffer into an sg list
*/
u32 fc_copy_buffer_to_sglist(void *buf, size_t len,
struct scatterlist *sg,
u32 *nents, size_t *offset,
enum km_type km_type, u32 *crc);

#endif /* _FC_LIBFC_H_ */

0 comments on commit 43de4f1

Please sign in to comment.