Problems with UTP on Linux (sg driver)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems with UTP on Linux (sg driver)

跳至解决方案
2,854 次查看
magnustherning
Contributor II

I've been looking into UTP and am currently trying to experiment with an implementation in Linux.  With a few hints from the source code of Mfg tool and documents in various versions of Mfg tool I've put together the following code to generate a poll command:

struct __attribute__ (( packed )) utp_cmd
{
     uint8_t oc;
     uint8_t cmd;
     uint32_t tag;
     uint64_t lparam;
     uint8_t res[2];
};
struct utp_cmd poll =
{
     .oc = 0xf0,
     .cmd = 0x00,
     .tag = 0x1,
     .lparam = 0,
};

I then put together the data to pass to sg like this:

uint8_t sbuf[128];
struct sg_io_hdr scsi_hdr = {
    .interface_id = 'S',
    .timeout = 2000,

    .cmdp = (unsigned char *)&poll,
    .cmd_len = sizeof(struct utp_cmd),

    .sbp = sbuf,
    .mx_sb_len = 128,

    .dxfer_direction = SG_DXFER_TO_DEV,
};

Then I pass it all off to sg like this:

int res = ioctl(dev, SG_IO, &scsi_hdr);

This fails though though with the rather cryptic error "Bad address" (errno set to 14).  Anyone who's encountered this and solved it already?

标记 (4)
0 项奖励
回复
1 解答
2,201 次查看
CommunityBot
Community Manager
This an automatic process.

We are marking this post as solved, due to the either low activity or any reply marked as correct.

If you have additional questions, please create a new post and reference to this closed post.

NXP Community!

在原帖中查看解决方案

0 项奖励
回复
3 回复数
2,202 次查看
CommunityBot
Community Manager
This an automatic process.

We are marking this post as solved, due to the either low activity or any reply marked as correct.

If you have additional questions, please create a new post and reference to this closed post.

NXP Community!
0 项奖励
回复
2,205 次查看
igorpadykov
NXP Employee
NXP Employee

Hi Magnus

frankly speaking I never heard about such efforts.

Best regards

chip

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
2,204 次查看
magnustherning
Contributor II

I find it very unfortunate that Freescale cares so little for software developers that it only provide tools for legacy OSs :smileywink:

Kidding aside.  The issue above was solved after a bit of wider searching online.  The error message, "Bad address", is particularly misgiving since the issue actually is one of missing permissions.  For raw access to the SCSI device one needs CAP_SYS_RAWIO (see e.g. http://lwn.net/Articles/542327/).  So I got it all working when running my code as root.  I now have non-IO command in UTP working, and I'm about to add command with IO.  All using the sgutils library via Haskell :smileygrin:.

0 项奖励
回复