* ks7010 endianness question
@ 2017-04-19 3:34 Tobin C. Harding
2017-04-19 4:02 ` Tobin C. Harding
0 siblings, 1 reply; 3+ messages in thread
From: Tobin C. Harding @ 2017-04-19 3:34 UTC (permalink / raw)
To: Wolfram Sang; +Cc: devel, linux-wireless
Hi Wolfram,
May I please ask you with an ks7010 driver endianness question?
Comments on the hostif_hdr data structure (ks_hostif.h) state that the
target uses little endian byte order.
/*
* HOST-MAC I/F data structure
* Byte alignmet Little Endian
*/
struct hostif_hdr {
u16 size;
u16 event;
} __packed;
On the rx data path this header is unpacked using get_WORD()
void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
unsigned int size)
{
DPRINTK(4, "\n");
devio_rec_ind(priv, p, size);
priv->rxp = p;
priv->rx_size = size;
if (get_WORD(priv) == priv->rx_size) { /* length check !! */
hostif_event_check(priv); /* event check */
}
}
get_WORD() inverts the byte order
static inline u16 get_WORD(struct ks_wlan_private *priv)
{
u16 data;
data = (get_BYTE(priv) & 0xff);
data |= ((get_BYTE(priv) << 8) & 0xff00);
return data;
}
Am I missing something? It seems that this code will only work if the
host and the target have differing endianness. It seems unlikely that
the driver was tested solely on a big-endian machine, is the comment
wrong - is the target actually big-endian?
Off topic, I watched your 2014 Fosdem talk on adding device support to
the kernel without adding code. It was very educational.
thanks for your time,
Tobin.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ks7010 endianness question
2017-04-19 3:34 ks7010 endianness question Tobin C. Harding
@ 2017-04-19 4:02 ` Tobin C. Harding
2017-04-19 6:56 ` Wolfram Sang
0 siblings, 1 reply; 3+ messages in thread
From: Tobin C. Harding @ 2017-04-19 4:02 UTC (permalink / raw)
To: Wolfram Sang; +Cc: devel, linux-wireless
On Wed, Apr 19, 2017 at 01:34:46PM +1000, Tobin C. Harding wrote:
> Hi Wolfram,
>
> May I please ask you with an ks7010 driver endianness question?
>
> Comments on the hostif_hdr data structure (ks_hostif.h) state that the
> target uses little endian byte order.
>
> /*
> * HOST-MAC I/F data structure
> * Byte alignmet Little Endian
> */
>
> struct hostif_hdr {
> u16 size;
> u16 event;
> } __packed;
>
> On the rx data path this header is unpacked using get_WORD()
>
> void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
> unsigned int size)
> {
> DPRINTK(4, "\n");
>
> devio_rec_ind(priv, p, size);
>
> priv->rxp = p;
> priv->rx_size = size;
>
> if (get_WORD(priv) == priv->rx_size) { /* length check !! */
> hostif_event_check(priv); /* event check */
> }
> }
>
> get_WORD() inverts the byte order
>
> static inline u16 get_WORD(struct ks_wlan_private *priv)
> {
> u16 data;
>
> data = (get_BYTE(priv) & 0xff);
> data |= ((get_BYTE(priv) << 8) & 0xff00);
> return data;
> }
>
> Am I missing something? It seems that this code will only work if the
> host and the target have differing endianness. It seems unlikely that
> the driver was tested solely on a big-endian machine, is the comment
> wrong - is the target actually big-endian?
Further investigation suggests that the target is actually using
network byte order (implying that the comment is wrong).
static void hostif_data_indication(struct ks_wlan_private *priv)
{
...
auth_type = get_WORD(priv); /* AuthType */
get_WORD(priv); /* Reserve Area */
eth_hdr = (struct ether_hdr *)(priv->rxp);
eth_proto = ntohs(eth_hdr->h_proto);
...
I think we can call this question resolved. Remove the comment and
change the hostif_hdr description to
struct hostif_hdr {
__be16 size;
__be16 event;
} __packed;
Are you happy with this?
thanks,
Tobin.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ks7010 endianness question
2017-04-19 4:02 ` Tobin C. Harding
@ 2017-04-19 6:56 ` Wolfram Sang
0 siblings, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2017-04-19 6:56 UTC (permalink / raw)
To: Tobin C. Harding; +Cc: devel, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 245 bytes --]
> I think we can call this question resolved. Remove the comment and
> change the hostif_hdr description to
>
> struct hostif_hdr {
> __be16 size;
> __be16 event;
> } __packed;
>
> Are you happy with this?
Yes, I trust you.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-19 6:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-19 3:34 ks7010 endianness question Tobin C. Harding
2017-04-19 4:02 ` Tobin C. Harding
2017-04-19 6:56 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).