Problems with UTP on Linux (sg driver)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with UTP on Linux (sg driver)

Jump to solution
1,657 Views
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?

0 Kudos
1 Solution
1,004 Views
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!

View solution in original post

0 Kudos
3 Replies
1,005 Views
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 Kudos
1,008 Views
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 Kudos
1,007 Views
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 Kudos