diff options
Diffstat (limited to 'drivers/staging/gdm724x')
-rw-r--r-- | drivers/staging/gdm724x/gdm_endian.c | 24 | ||||
-rw-r--r-- | drivers/staging/gdm724x/gdm_endian.h | 15 | ||||
-rw-r--r-- | drivers/staging/gdm724x/gdm_lte.c | 53 | ||||
-rw-r--r-- | drivers/staging/gdm724x/hci_packet.h | 46 |
4 files changed, 71 insertions, 67 deletions
diff --git a/drivers/staging/gdm724x/gdm_endian.c b/drivers/staging/gdm724x/gdm_endian.c index d7144e7afa32..d0b43e20ec06 100644 --- a/drivers/staging/gdm724x/gdm_endian.c +++ b/drivers/staging/gdm724x/gdm_endian.c @@ -22,34 +22,34 @@ void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian) ed->dev_ed = ENDIANNESS_LITTLE; } -u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) +__dev16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) { if (ed->dev_ed == ENDIANNESS_LITTLE) - return cpu_to_le16(x); + return (__force __dev16)cpu_to_le16(x); else - return cpu_to_be16(x); + return (__force __dev16)cpu_to_be16(x); } -u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x) +u16 gdm_dev16_to_cpu(struct gdm_endian *ed, __dev16 x) { if (ed->dev_ed == ENDIANNESS_LITTLE) - return le16_to_cpu(x); + return le16_to_cpu((__force __le16)x); else - return be16_to_cpu(x); + return be16_to_cpu((__force __be16)x); } -u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x) +__dev32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x) { if (ed->dev_ed == ENDIANNESS_LITTLE) - return cpu_to_le32(x); + return (__force __dev32)cpu_to_le32(x); else - return cpu_to_be32(x); + return (__force __dev32)cpu_to_be32(x); } -u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x) +u32 gdm_dev32_to_cpu(struct gdm_endian *ed, __dev32 x) { if (ed->dev_ed == ENDIANNESS_LITTLE) - return le32_to_cpu(x); + return le32_to_cpu((__force __le32)x); else - return be32_to_cpu(x); + return be32_to_cpu((__force __be32)x); } diff --git a/drivers/staging/gdm724x/gdm_endian.h b/drivers/staging/gdm724x/gdm_endian.h index 6177870830e5..a785f30bb369 100644 --- a/drivers/staging/gdm724x/gdm_endian.h +++ b/drivers/staging/gdm724x/gdm_endian.h @@ -16,6 +16,13 @@ #include <linux/types.h> +/* + * For data in "device-endian" byte order (device endianness is model + * dependent). Analogous to __leXX or __beXX. + */ +typedef __u32 __bitwise __dev32; +typedef __u16 __bitwise __dev16; + enum { ENDIANNESS_MIN = 0, ENDIANNESS_UNKNOWN, @@ -30,9 +37,9 @@ struct gdm_endian { }; void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian); -u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x); -u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x); -u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x); -u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x); +__dev16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x); +u16 gdm_dev16_to_cpu(struct gdm_endian *ed, __dev16 x); +__dev32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x); +u32 gdm_dev32_to_cpu(struct gdm_endian *ed, __dev32 x); #endif /*__GDM_ENDIAN_H__*/ diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c index e72dfa9699f3..a3e046c3f65c 100644 --- a/drivers/staging/gdm724x/gdm_lte.c +++ b/drivers/staging/gdm724x/gdm_lte.c @@ -198,7 +198,7 @@ static int icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len) memset(&pseudo_header, 0, sizeof(pseudo_header)); memcpy(&pseudo_header.ph.ph_src, &ipv6->saddr.in6_u.u6_addr8, 16); memcpy(&pseudo_header.ph.ph_dst, &ipv6->daddr.in6_u.u6_addr8, 16); - pseudo_header.ph.ph_len = ipv6->payload_len; + pseudo_header.ph.ph_len = be16_to_cpu(ipv6->payload_len); pseudo_header.ph.ph_nxt = ipv6->nexthdr; w = (u16 *)&pseudo_header; @@ -560,13 +560,13 @@ void gdm_lte_event_exit(void) } } -static u8 find_dev_index(u32 nic_type) +static int find_dev_index(u32 nic_type) { u8 index; index = (u8)(nic_type & 0x0000000f); - if (index > MAX_NIC_TYPE) - index = 0; + if (index >= MAX_NIC_TYPE) + return -EINVAL; return index; } @@ -688,28 +688,24 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len) struct net_device *dev; struct multi_sdu *multi_sdu = (struct multi_sdu *)buf; struct sdu *sdu = NULL; + struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev); u8 *data = (u8 *)multi_sdu->data; u16 i = 0; u16 num_packet; u16 hci_len; u16 cmd_evt; u32 nic_type; - u8 index; + int index; - hci_len = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), - multi_sdu->len); - num_packet = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), - multi_sdu->num_packet); + hci_len = gdm_dev16_to_cpu(endian, multi_sdu->len); + num_packet = gdm_dev16_to_cpu(endian, multi_sdu->num_packet); for (i = 0; i < num_packet; i++) { sdu = (struct sdu *)data; - cmd_evt = gdm_dev16_to_cpu(phy_dev-> - get_endian(phy_dev->priv_dev), sdu->cmd_evt); - hci_len = gdm_dev16_to_cpu(phy_dev-> - get_endian(phy_dev->priv_dev), sdu->len); - nic_type = gdm_dev32_to_cpu(phy_dev-> - get_endian(phy_dev->priv_dev), sdu->nic_type); + cmd_evt = gdm_dev16_to_cpu(endian, sdu->cmd_evt); + hci_len = gdm_dev16_to_cpu(endian, sdu->len); + nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type); if (cmd_evt != LTE_RX_SDU) { pr_err("rx sdu wrong hci %04x\n", cmd_evt); @@ -721,13 +717,13 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len) } index = find_dev_index(nic_type); - if (index < MAX_NIC_TYPE) { - dev = phy_dev->dev[index]; - gdm_lte_netif_rx(dev, (char *)sdu->data, - (int)(hci_len - 12), nic_type); - } else { + if (index < 0) { pr_err("rx sdu invalid nic_type :%x\n", nic_type); + return; } + dev = phy_dev->dev[index]; + gdm_lte_netif_rx(dev, (char *)sdu->data, + (int)(hci_len - 12), nic_type); data += ((hci_len + 3) & 0xfffc) + HCI_HEADER_SIZE; } @@ -761,18 +757,18 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len) { struct hci_packet *hci = (struct hci_packet *)buf; struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf; + struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev); struct sdu *sdu; struct net_device *dev; int ret = 0; u16 cmd_evt; u32 nic_type; - u8 index; + int index; if (!len) return ret; - cmd_evt = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), - hci->cmd_evt); + cmd_evt = gdm_dev16_to_cpu(endian, hci->cmd_evt); dev = phy_dev->dev[0]; if (!dev) @@ -781,9 +777,10 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len) switch (cmd_evt) { case LTE_RX_SDU: sdu = (struct sdu *)hci->data; - nic_type = gdm_dev32_to_cpu(phy_dev-> - get_endian(phy_dev->priv_dev), sdu->nic_type); + nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type); index = find_dev_index(nic_type); + if (index < 0) + return index; dev = phy_dev->dev[index]; gdm_lte_netif_rx(dev, hci->data, len, nic_type); break; @@ -797,10 +794,10 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len) break; case LTE_PDN_TABLE_IND: pdn_table = (struct hci_pdn_table_ind *)buf; - nic_type = gdm_dev32_to_cpu(phy_dev-> - get_endian(phy_dev->priv_dev), - pdn_table->nic_type); + nic_type = gdm_dev32_to_cpu(endian, pdn_table->nic_type); index = find_dev_index(nic_type); + if (index < 0) + return index; dev = phy_dev->dev[index]; gdm_lte_pdn_table(dev, buf, len); /* Fall through */ diff --git a/drivers/staging/gdm724x/hci_packet.h b/drivers/staging/gdm724x/hci_packet.h index 4644f84038c9..22ce8b9477b6 100644 --- a/drivers/staging/gdm724x/hci_packet.h +++ b/drivers/staging/gdm724x/hci_packet.h @@ -36,8 +36,8 @@ #define NIC_TYPE_F_VLAN 0x00100000 struct hci_packet { - u16 cmd_evt; - u16 len; + __dev16 cmd_evt; + __dev16 len; u8 data[0]; } __packed; @@ -48,45 +48,45 @@ struct tlv { } __packed; struct sdu_header { - u16 cmd_evt; - u16 len; - u32 dftEpsId; - u32 bearer_ID; - u32 nic_type; + __dev16 cmd_evt; + __dev16 len; + __dev32 dftEpsId; + __dev32 bearer_ID; + __dev32 nic_type; } __packed; struct sdu { - u16 cmd_evt; - u16 len; - u32 dft_eps_ID; - u32 bearer_ID; - u32 nic_type; + __dev16 cmd_evt; + __dev16 len; + __dev32 dft_eps_ID; + __dev32 bearer_ID; + __dev32 nic_type; u8 data[0]; } __packed; struct multi_sdu { - u16 cmd_evt; - u16 len; - u16 num_packet; - u16 reserved; + __dev16 cmd_evt; + __dev16 len; + __dev16 num_packet; + __dev16 reserved; u8 data[0]; } __packed; struct hci_pdn_table_ind { - u16 cmd_evt; - u16 len; + __dev16 cmd_evt; + __dev16 len; u8 activate; - u32 dft_eps_id; - u32 nic_type; + __dev32 dft_eps_id; + __dev32 nic_type; u8 pdn_type; u8 ipv4_addr[4]; u8 ipv6_intf_id[8]; } __packed; struct hci_connect_ind { - u16 cmd_evt; - u16 len; - u32 connect; + __dev16 cmd_evt; + __dev16 len; + __dev32 connect; } __packed; #endif /* _HCI_PACKET_H_ */ |