diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-27 15:35:51 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-27 15:35:51 -0500 |
commit | 7205649778ca4a110d6098f8defd7312f0bb7289 (patch) | |
tree | 1e056fcdf578a62e5639e0a2b5cb8cd393115491 /drivers | |
parent | 0b711cac8b9e604c93b32ca6e0b6b73261056d65 (diff) | |
parent | 4bb9ebc78097376b3734c6d3001a96aecac0f7bb (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6: (43 commits)
bnx2: Eliminate AER error messages on systems not supporting it
cnic: Fix big endian bug
xfrm6: Don't forget to propagate peer into ipsec route.
tg3: Use new VLAN code
bonding: update documentation - alternate configuration.
TCP: fix a bug that triggers large number of TCP RST by mistake
MAINTAINERS: remove Reinette Chatre as iwlwifi maintainer
rt2x00: add device id for windy31 usb device
mac80211: fix a crash in ieee80211_beacon_get_tim on change_interface
ipv6: Revert 'administrative down' address handling changes.
textsearch: doc - fix spelling in lib/textsearch.c.
USB NET KL5KUSB101: Fix mem leak in error path of kaweth_download_firmware()
pch_gbe: don't use flush_scheduled_work()
bnx2: Always set ETH_FLAG_TXVLAN
net: clear heap allocation for ethtool_get_regs()
ipv6: Always clone offlink routes.
dcbnl: make get_app handling symmetric for IEEE and CEE DCBx
tcp: fix bug in listening_get_next()
inetpeer: Use correct AVL tree base pointer in inet_getpeer().
GRO: fix merging a paged skb after non-paged skbs
...
Diffstat (limited to 'drivers')
31 files changed, 2397 insertions, 198 deletions
diff --git a/drivers/atm/idt77105.c b/drivers/atm/idt77105.c index bca9cb89a118..487a54739854 100644 --- a/drivers/atm/idt77105.c +++ b/drivers/atm/idt77105.c | |||
@@ -151,7 +151,7 @@ static int fetch_stats(struct atm_dev *dev,struct idt77105_stats __user *arg,int | |||
151 | spin_unlock_irqrestore(&idt77105_priv_lock, flags); | 151 | spin_unlock_irqrestore(&idt77105_priv_lock, flags); |
152 | if (arg == NULL) | 152 | if (arg == NULL) |
153 | return 0; | 153 | return 0; |
154 | return copy_to_user(arg, &PRIV(dev)->stats, | 154 | return copy_to_user(arg, &stats, |
155 | sizeof(struct idt77105_stats)) ? -EFAULT : 0; | 155 | sizeof(struct idt77105_stats)) ? -EFAULT : 0; |
156 | } | 156 | } |
157 | 157 | ||
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c index 949ed09c6361..a126e614601f 100644 --- a/drivers/bluetooth/ath3k.c +++ b/drivers/bluetooth/ath3k.c | |||
@@ -47,46 +47,40 @@ MODULE_DEVICE_TABLE(usb, ath3k_table); | |||
47 | #define USB_REQ_DFU_DNLOAD 1 | 47 | #define USB_REQ_DFU_DNLOAD 1 |
48 | #define BULK_SIZE 4096 | 48 | #define BULK_SIZE 4096 |
49 | 49 | ||
50 | struct ath3k_data { | 50 | static int ath3k_load_firmware(struct usb_device *udev, |
51 | struct usb_device *udev; | 51 | const struct firmware *firmware) |
52 | u8 *fw_data; | ||
53 | u32 fw_size; | ||
54 | u32 fw_sent; | ||
55 | }; | ||
56 | |||
57 | static int ath3k_load_firmware(struct ath3k_data *data, | ||
58 | unsigned char *firmware, | ||
59 | int count) | ||
60 | { | 52 | { |
61 | u8 *send_buf; | 53 | u8 *send_buf; |
62 | int err, pipe, len, size, sent = 0; | 54 | int err, pipe, len, size, sent = 0; |
55 | int count = firmware->size; | ||
63 | 56 | ||
64 | BT_DBG("ath3k %p udev %p", data, data->udev); | 57 | BT_DBG("udev %p", udev); |
65 | 58 | ||
66 | pipe = usb_sndctrlpipe(data->udev, 0); | 59 | pipe = usb_sndctrlpipe(udev, 0); |
67 | 60 | ||
68 | if ((usb_control_msg(data->udev, pipe, | 61 | send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC); |
62 | if (!send_buf) { | ||
63 | BT_ERR("Can't allocate memory chunk for firmware"); | ||
64 | return -ENOMEM; | ||
65 | } | ||
66 | |||
67 | memcpy(send_buf, firmware->data, 20); | ||
68 | if ((err = usb_control_msg(udev, pipe, | ||
69 | USB_REQ_DFU_DNLOAD, | 69 | USB_REQ_DFU_DNLOAD, |
70 | USB_TYPE_VENDOR, 0, 0, | 70 | USB_TYPE_VENDOR, 0, 0, |
71 | firmware, 20, USB_CTRL_SET_TIMEOUT)) < 0) { | 71 | send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) { |
72 | BT_ERR("Can't change to loading configuration err"); | 72 | BT_ERR("Can't change to loading configuration err"); |
73 | return -EBUSY; | 73 | goto error; |
74 | } | 74 | } |
75 | sent += 20; | 75 | sent += 20; |
76 | count -= 20; | 76 | count -= 20; |
77 | 77 | ||
78 | send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC); | ||
79 | if (!send_buf) { | ||
80 | BT_ERR("Can't allocate memory chunk for firmware"); | ||
81 | return -ENOMEM; | ||
82 | } | ||
83 | |||
84 | while (count) { | 78 | while (count) { |
85 | size = min_t(uint, count, BULK_SIZE); | 79 | size = min_t(uint, count, BULK_SIZE); |
86 | pipe = usb_sndbulkpipe(data->udev, 0x02); | 80 | pipe = usb_sndbulkpipe(udev, 0x02); |
87 | memcpy(send_buf, firmware + sent, size); | 81 | memcpy(send_buf, firmware->data + sent, size); |
88 | 82 | ||
89 | err = usb_bulk_msg(data->udev, pipe, send_buf, size, | 83 | err = usb_bulk_msg(udev, pipe, send_buf, size, |
90 | &len, 3000); | 84 | &len, 3000); |
91 | 85 | ||
92 | if (err || (len != size)) { | 86 | if (err || (len != size)) { |
@@ -112,57 +106,28 @@ static int ath3k_probe(struct usb_interface *intf, | |||
112 | { | 106 | { |
113 | const struct firmware *firmware; | 107 | const struct firmware *firmware; |
114 | struct usb_device *udev = interface_to_usbdev(intf); | 108 | struct usb_device *udev = interface_to_usbdev(intf); |
115 | struct ath3k_data *data; | ||
116 | int size; | ||
117 | 109 | ||
118 | BT_DBG("intf %p id %p", intf, id); | 110 | BT_DBG("intf %p id %p", intf, id); |
119 | 111 | ||
120 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) | 112 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) |
121 | return -ENODEV; | 113 | return -ENODEV; |
122 | 114 | ||
123 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
124 | if (!data) | ||
125 | return -ENOMEM; | ||
126 | |||
127 | data->udev = udev; | ||
128 | |||
129 | if (request_firmware(&firmware, "ath3k-1.fw", &udev->dev) < 0) { | 115 | if (request_firmware(&firmware, "ath3k-1.fw", &udev->dev) < 0) { |
130 | kfree(data); | ||
131 | return -EIO; | 116 | return -EIO; |
132 | } | 117 | } |
133 | 118 | ||
134 | size = max_t(uint, firmware->size, 4096); | 119 | if (ath3k_load_firmware(udev, firmware)) { |
135 | data->fw_data = kmalloc(size, GFP_KERNEL); | ||
136 | if (!data->fw_data) { | ||
137 | release_firmware(firmware); | 120 | release_firmware(firmware); |
138 | kfree(data); | ||
139 | return -ENOMEM; | ||
140 | } | ||
141 | |||
142 | memcpy(data->fw_data, firmware->data, firmware->size); | ||
143 | data->fw_size = firmware->size; | ||
144 | data->fw_sent = 0; | ||
145 | release_firmware(firmware); | ||
146 | |||
147 | usb_set_intfdata(intf, data); | ||
148 | if (ath3k_load_firmware(data, data->fw_data, data->fw_size)) { | ||
149 | usb_set_intfdata(intf, NULL); | ||
150 | kfree(data->fw_data); | ||
151 | kfree(data); | ||
152 | return -EIO; | 121 | return -EIO; |
153 | } | 122 | } |
123 | release_firmware(firmware); | ||
154 | 124 | ||
155 | return 0; | 125 | return 0; |
156 | } | 126 | } |
157 | 127 | ||
158 | static void ath3k_disconnect(struct usb_interface *intf) | 128 | static void ath3k_disconnect(struct usb_interface *intf) |
159 | { | 129 | { |
160 | struct ath3k_data *data = usb_get_intfdata(intf); | ||
161 | |||
162 | BT_DBG("ath3k_disconnect intf %p", intf); | 130 | BT_DBG("ath3k_disconnect intf %p", intf); |
163 | |||
164 | kfree(data->fw_data); | ||
165 | kfree(data); | ||
166 | } | 131 | } |
167 | 132 | ||
168 | static struct usb_driver ath3k_driver = { | 133 | static struct usb_driver ath3k_driver = { |
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c index df99edf3464a..0ba59d5aeb7f 100644 --- a/drivers/net/bnx2.c +++ b/drivers/net/bnx2.c | |||
@@ -7553,6 +7553,10 @@ bnx2_set_flags(struct net_device *dev, u32 data) | |||
7553 | !(data & ETH_FLAG_RXVLAN)) | 7553 | !(data & ETH_FLAG_RXVLAN)) |
7554 | return -EINVAL; | 7554 | return -EINVAL; |
7555 | 7555 | ||
7556 | /* TSO with VLAN tag won't work with current firmware */ | ||
7557 | if (!(data & ETH_FLAG_TXVLAN)) | ||
7558 | return -EINVAL; | ||
7559 | |||
7556 | rc = ethtool_op_set_flags(dev, data, ETH_FLAG_RXHASH | ETH_FLAG_RXVLAN | | 7560 | rc = ethtool_op_set_flags(dev, data, ETH_FLAG_RXHASH | ETH_FLAG_RXVLAN | |
7557 | ETH_FLAG_TXVLAN); | 7561 | ETH_FLAG_TXVLAN); |
7558 | if (rc) | 7562 | if (rc) |
@@ -7962,11 +7966,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev) | |||
7962 | 7966 | ||
7963 | /* AER (Advanced Error Reporting) hooks */ | 7967 | /* AER (Advanced Error Reporting) hooks */ |
7964 | err = pci_enable_pcie_error_reporting(pdev); | 7968 | err = pci_enable_pcie_error_reporting(pdev); |
7965 | if (err) { | 7969 | if (!err) |
7966 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting " | 7970 | bp->flags |= BNX2_FLAG_AER_ENABLED; |
7967 | "failed 0x%x\n", err); | ||
7968 | /* non-fatal, continue */ | ||
7969 | } | ||
7970 | 7971 | ||
7971 | } else { | 7972 | } else { |
7972 | bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX); | 7973 | bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX); |
@@ -8229,8 +8230,10 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev) | |||
8229 | return 0; | 8230 | return 0; |
8230 | 8231 | ||
8231 | err_out_unmap: | 8232 | err_out_unmap: |
8232 | if (bp->flags & BNX2_FLAG_PCIE) | 8233 | if (bp->flags & BNX2_FLAG_AER_ENABLED) { |
8233 | pci_disable_pcie_error_reporting(pdev); | 8234 | pci_disable_pcie_error_reporting(pdev); |
8235 | bp->flags &= ~BNX2_FLAG_AER_ENABLED; | ||
8236 | } | ||
8234 | 8237 | ||
8235 | if (bp->regview) { | 8238 | if (bp->regview) { |
8236 | iounmap(bp->regview); | 8239 | iounmap(bp->regview); |
@@ -8418,8 +8421,10 @@ bnx2_remove_one(struct pci_dev *pdev) | |||
8418 | 8421 | ||
8419 | kfree(bp->temp_stats_blk); | 8422 | kfree(bp->temp_stats_blk); |
8420 | 8423 | ||
8421 | if (bp->flags & BNX2_FLAG_PCIE) | 8424 | if (bp->flags & BNX2_FLAG_AER_ENABLED) { |
8422 | pci_disable_pcie_error_reporting(pdev); | 8425 | pci_disable_pcie_error_reporting(pdev); |
8426 | bp->flags &= ~BNX2_FLAG_AER_ENABLED; | ||
8427 | } | ||
8423 | 8428 | ||
8424 | free_netdev(dev); | 8429 | free_netdev(dev); |
8425 | 8430 | ||
@@ -8535,7 +8540,7 @@ static pci_ers_result_t bnx2_io_slot_reset(struct pci_dev *pdev) | |||
8535 | } | 8540 | } |
8536 | rtnl_unlock(); | 8541 | rtnl_unlock(); |
8537 | 8542 | ||
8538 | if (!(bp->flags & BNX2_FLAG_PCIE)) | 8543 | if (!(bp->flags & BNX2_FLAG_AER_ENABLED)) |
8539 | return result; | 8544 | return result; |
8540 | 8545 | ||
8541 | err = pci_cleanup_aer_uncorrect_error_status(pdev); | 8546 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h index 5488a2e82fe9..f459fb2f9add 100644 --- a/drivers/net/bnx2.h +++ b/drivers/net/bnx2.h | |||
@@ -6741,6 +6741,7 @@ struct bnx2 { | |||
6741 | #define BNX2_FLAG_JUMBO_BROKEN 0x00000800 | 6741 | #define BNX2_FLAG_JUMBO_BROKEN 0x00000800 |
6742 | #define BNX2_FLAG_CAN_KEEP_VLAN 0x00001000 | 6742 | #define BNX2_FLAG_CAN_KEEP_VLAN 0x00001000 |
6743 | #define BNX2_FLAG_BROKEN_STATS 0x00002000 | 6743 | #define BNX2_FLAG_BROKEN_STATS 0x00002000 |
6744 | #define BNX2_FLAG_AER_ENABLED 0x00004000 | ||
6744 | 6745 | ||
6745 | struct bnx2_napi bnx2_napi[BNX2_MAX_MSIX_VEC]; | 6746 | struct bnx2_napi bnx2_napi[BNX2_MAX_MSIX_VEC]; |
6746 | 6747 | ||
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 171782e2bb39..1024ae158227 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
@@ -2470,6 +2470,10 @@ int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct pac | |||
2470 | if (!(dev->flags & IFF_MASTER)) | 2470 | if (!(dev->flags & IFF_MASTER)) |
2471 | goto out; | 2471 | goto out; |
2472 | 2472 | ||
2473 | skb = skb_share_check(skb, GFP_ATOMIC); | ||
2474 | if (!skb) | ||
2475 | goto out; | ||
2476 | |||
2473 | if (!pskb_may_pull(skb, sizeof(struct lacpdu))) | 2477 | if (!pskb_may_pull(skb, sizeof(struct lacpdu))) |
2474 | goto out; | 2478 | goto out; |
2475 | 2479 | ||
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index f4e638c65129..5c6fba802f2b 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c | |||
@@ -326,6 +326,10 @@ static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct | |||
326 | goto out; | 326 | goto out; |
327 | } | 327 | } |
328 | 328 | ||
329 | skb = skb_share_check(skb, GFP_ATOMIC); | ||
330 | if (!skb) | ||
331 | goto out; | ||
332 | |||
329 | if (!pskb_may_pull(skb, arp_hdr_len(bond_dev))) | 333 | if (!pskb_may_pull(skb, arp_hdr_len(bond_dev))) |
330 | goto out; | 334 | goto out; |
331 | 335 | ||
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index b1025b85acf1..163e0b06eaa5 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -2733,6 +2733,10 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack | |||
2733 | if (!slave || !slave_do_arp_validate(bond, slave)) | 2733 | if (!slave || !slave_do_arp_validate(bond, slave)) |
2734 | goto out_unlock; | 2734 | goto out_unlock; |
2735 | 2735 | ||
2736 | skb = skb_share_check(skb, GFP_ATOMIC); | ||
2737 | if (!skb) | ||
2738 | goto out_unlock; | ||
2739 | |||
2736 | if (!pskb_may_pull(skb, arp_hdr_len(dev))) | 2740 | if (!pskb_may_pull(skb, arp_hdr_len(dev))) |
2737 | goto out_unlock; | 2741 | goto out_unlock; |
2738 | 2742 | ||
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index d5a9db60ade9..986195eaa57c 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig | |||
@@ -117,6 +117,8 @@ source "drivers/net/can/sja1000/Kconfig" | |||
117 | 117 | ||
118 | source "drivers/net/can/usb/Kconfig" | 118 | source "drivers/net/can/usb/Kconfig" |
119 | 119 | ||
120 | source "drivers/net/can/softing/Kconfig" | ||
121 | |||
120 | config CAN_DEBUG_DEVICES | 122 | config CAN_DEBUG_DEVICES |
121 | bool "CAN devices debugging messages" | 123 | bool "CAN devices debugging messages" |
122 | depends on CAN | 124 | depends on CAN |
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile index 07ca159ba3f9..53c82a71778e 100644 --- a/drivers/net/can/Makefile +++ b/drivers/net/can/Makefile | |||
@@ -9,6 +9,7 @@ obj-$(CONFIG_CAN_DEV) += can-dev.o | |||
9 | can-dev-y := dev.o | 9 | can-dev-y := dev.o |
10 | 10 | ||
11 | obj-y += usb/ | 11 | obj-y += usb/ |
12 | obj-y += softing/ | ||
12 | 13 | ||
13 | obj-$(CONFIG_CAN_SJA1000) += sja1000/ | 14 | obj-$(CONFIG_CAN_SJA1000) += sja1000/ |
14 | obj-$(CONFIG_CAN_MSCAN) += mscan/ | 15 | obj-$(CONFIG_CAN_MSCAN) += mscan/ |
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c index 7ef83d06f7ed..2532b9631538 100644 --- a/drivers/net/can/at91_can.c +++ b/drivers/net/can/at91_can.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * at91_can.c - CAN network driver for AT91 SoC CAN controller | 2 | * at91_can.c - CAN network driver for AT91 SoC CAN controller |
3 | * | 3 | * |
4 | * (C) 2007 by Hans J. Koch <hjk@hansjkoch.de> | 4 | * (C) 2007 by Hans J. Koch <hjk@hansjkoch.de> |
5 | * (C) 2008, 2009, 2010 by Marc Kleine-Budde <kernel@pengutronix.de> | 5 | * (C) 2008, 2009, 2010, 2011 by Marc Kleine-Budde <kernel@pengutronix.de> |
6 | * | 6 | * |
7 | * This software may be distributed under the terms of the GNU General | 7 | * This software may be distributed under the terms of the GNU General |
8 | * Public License ("GPL") version 2 as distributed in the 'COPYING' | 8 | * Public License ("GPL") version 2 as distributed in the 'COPYING' |
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/netdevice.h> | 31 | #include <linux/netdevice.h> |
32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/rtnetlink.h> | ||
33 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
34 | #include <linux/spinlock.h> | 35 | #include <linux/spinlock.h> |
35 | #include <linux/string.h> | 36 | #include <linux/string.h> |
@@ -40,22 +41,23 @@ | |||
40 | 41 | ||
41 | #include <mach/board.h> | 42 | #include <mach/board.h> |
42 | 43 | ||
43 | #define AT91_NAPI_WEIGHT 12 | 44 | #define AT91_NAPI_WEIGHT 11 |
44 | 45 | ||
45 | /* | 46 | /* |
46 | * RX/TX Mailbox split | 47 | * RX/TX Mailbox split |
47 | * don't dare to touch | 48 | * don't dare to touch |
48 | */ | 49 | */ |
49 | #define AT91_MB_RX_NUM 12 | 50 | #define AT91_MB_RX_NUM 11 |
50 | #define AT91_MB_TX_SHIFT 2 | 51 | #define AT91_MB_TX_SHIFT 2 |
51 | 52 | ||
52 | #define AT91_MB_RX_FIRST 0 | 53 | #define AT91_MB_RX_FIRST 1 |
53 | #define AT91_MB_RX_LAST (AT91_MB_RX_FIRST + AT91_MB_RX_NUM - 1) | 54 | #define AT91_MB_RX_LAST (AT91_MB_RX_FIRST + AT91_MB_RX_NUM - 1) |
54 | 55 | ||
55 | #define AT91_MB_RX_MASK(i) ((1 << (i)) - 1) | 56 | #define AT91_MB_RX_MASK(i) ((1 << (i)) - 1) |
56 | #define AT91_MB_RX_SPLIT 8 | 57 | #define AT91_MB_RX_SPLIT 8 |
57 | #define AT91_MB_RX_LOW_LAST (AT91_MB_RX_SPLIT - 1) | 58 | #define AT91_MB_RX_LOW_LAST (AT91_MB_RX_SPLIT - 1) |
58 | #define AT91_MB_RX_LOW_MASK (AT91_MB_RX_MASK(AT91_MB_RX_SPLIT)) | 59 | #define AT91_MB_RX_LOW_MASK (AT91_MB_RX_MASK(AT91_MB_RX_SPLIT) & \ |
60 | ~AT91_MB_RX_MASK(AT91_MB_RX_FIRST)) | ||
59 | 61 | ||
60 | #define AT91_MB_TX_NUM (1 << AT91_MB_TX_SHIFT) | 62 | #define AT91_MB_TX_NUM (1 << AT91_MB_TX_SHIFT) |
61 | #define AT91_MB_TX_FIRST (AT91_MB_RX_LAST + 1) | 63 | #define AT91_MB_TX_FIRST (AT91_MB_RX_LAST + 1) |
@@ -168,6 +170,8 @@ struct at91_priv { | |||
168 | 170 | ||
169 | struct clk *clk; | 171 | struct clk *clk; |
170 | struct at91_can_data *pdata; | 172 | struct at91_can_data *pdata; |
173 | |||
174 | canid_t mb0_id; | ||
171 | }; | 175 | }; |
172 | 176 | ||
173 | static struct can_bittiming_const at91_bittiming_const = { | 177 | static struct can_bittiming_const at91_bittiming_const = { |
@@ -220,6 +224,18 @@ static inline void set_mb_mode(const struct at91_priv *priv, unsigned int mb, | |||
220 | set_mb_mode_prio(priv, mb, mode, 0); | 224 | set_mb_mode_prio(priv, mb, mode, 0); |
221 | } | 225 | } |
222 | 226 | ||
227 | static inline u32 at91_can_id_to_reg_mid(canid_t can_id) | ||
228 | { | ||
229 | u32 reg_mid; | ||
230 | |||
231 | if (can_id & CAN_EFF_FLAG) | ||
232 | reg_mid = (can_id & CAN_EFF_MASK) | AT91_MID_MIDE; | ||
233 | else | ||
234 | reg_mid = (can_id & CAN_SFF_MASK) << 18; | ||
235 | |||
236 | return reg_mid; | ||
237 | } | ||
238 | |||
223 | /* | 239 | /* |
224 | * Swtich transceiver on or off | 240 | * Swtich transceiver on or off |
225 | */ | 241 | */ |
@@ -233,12 +249,22 @@ static void at91_setup_mailboxes(struct net_device *dev) | |||
233 | { | 249 | { |
234 | struct at91_priv *priv = netdev_priv(dev); | 250 | struct at91_priv *priv = netdev_priv(dev); |
235 | unsigned int i; | 251 | unsigned int i; |
252 | u32 reg_mid; | ||
236 | 253 | ||
237 | /* | 254 | /* |
238 | * The first 12 mailboxes are used as a reception FIFO. The | 255 | * Due to a chip bug (errata 50.2.6.3 & 50.3.5.3) the first |
239 | * last mailbox is configured with overwrite option. The | 256 | * mailbox is disabled. The next 11 mailboxes are used as a |
240 | * overwrite flag indicates a FIFO overflow. | 257 | * reception FIFO. The last mailbox is configured with |
258 | * overwrite option. The overwrite flag indicates a FIFO | ||
259 | * overflow. | ||
241 | */ | 260 | */ |
261 | reg_mid = at91_can_id_to_reg_mid(priv->mb0_id); | ||
262 | for (i = 0; i < AT91_MB_RX_FIRST; i++) { | ||
263 | set_mb_mode(priv, i, AT91_MB_MODE_DISABLED); | ||
264 | at91_write(priv, AT91_MID(i), reg_mid); | ||
265 | at91_write(priv, AT91_MCR(i), 0x0); /* clear dlc */ | ||
266 | } | ||
267 | |||
242 | for (i = AT91_MB_RX_FIRST; i < AT91_MB_RX_LAST; i++) | 268 | for (i = AT91_MB_RX_FIRST; i < AT91_MB_RX_LAST; i++) |
243 | set_mb_mode(priv, i, AT91_MB_MODE_RX); | 269 | set_mb_mode(priv, i, AT91_MB_MODE_RX); |
244 | set_mb_mode(priv, AT91_MB_RX_LAST, AT91_MB_MODE_RX_OVRWR); | 270 | set_mb_mode(priv, AT91_MB_RX_LAST, AT91_MB_MODE_RX_OVRWR); |
@@ -254,7 +280,8 @@ static void at91_setup_mailboxes(struct net_device *dev) | |||
254 | set_mb_mode_prio(priv, i, AT91_MB_MODE_TX, 0); | 280 | set_mb_mode_prio(priv, i, AT91_MB_MODE_TX, 0); |
255 | 281 | ||
256 | /* Reset tx and rx helper pointers */ | 282 | /* Reset tx and rx helper pointers */ |
257 | priv->tx_next = priv->tx_echo = priv->rx_next = 0; | 283 | priv->tx_next = priv->tx_echo = 0; |
284 | priv->rx_next = AT91_MB_RX_FIRST; | ||
258 | } | 285 | } |
259 | 286 | ||
260 | static int at91_set_bittiming(struct net_device *dev) | 287 | static int at91_set_bittiming(struct net_device *dev) |
@@ -372,12 +399,7 @@ static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
372 | netdev_err(dev, "BUG! TX buffer full when queue awake!\n"); | 399 | netdev_err(dev, "BUG! TX buffer full when queue awake!\n"); |
373 | return NETDEV_TX_BUSY; | 400 | return NETDEV_TX_BUSY; |
374 | } | 401 | } |
375 | 402 | reg_mid = at91_can_id_to_reg_mid(cf->can_id); | |
376 | if (cf->can_id & CAN_EFF_FLAG) | ||
377 | reg_mid = (cf->can_id & CAN_EFF_MASK) | AT91_MID_MIDE; | ||
378 | else | ||
379 | reg_mid = (cf->can_id & CAN_SFF_MASK) << 18; | ||
380 | |||
381 | reg_mcr = ((cf->can_id & CAN_RTR_FLAG) ? AT91_MCR_MRTR : 0) | | 403 | reg_mcr = ((cf->can_id & CAN_RTR_FLAG) ? AT91_MCR_MRTR : 0) | |
382 | (cf->can_dlc << 16) | AT91_MCR_MTCR; | 404 | (cf->can_dlc << 16) | AT91_MCR_MTCR; |
383 | 405 | ||
@@ -539,27 +561,31 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb) | |||
539 | * | 561 | * |
540 | * Theory of Operation: | 562 | * Theory of Operation: |
541 | * | 563 | * |
542 | * 12 of the 16 mailboxes on the chip are reserved for RX. we split | 564 | * 11 of the 16 mailboxes on the chip are reserved for RX. we split |
543 | * them into 2 groups. The lower group holds 8 and upper 4 mailboxes. | 565 | * them into 2 groups. The lower group holds 7 and upper 4 mailboxes. |
544 | * | 566 | * |
545 | * Like it or not, but the chip always saves a received CAN message | 567 | * Like it or not, but the chip always saves a received CAN message |
546 | * into the first free mailbox it finds (starting with the | 568 | * into the first free mailbox it finds (starting with the |
547 | * lowest). This makes it very difficult to read the messages in the | 569 | * lowest). This makes it very difficult to read the messages in the |
548 | * right order from the chip. This is how we work around that problem: | 570 | * right order from the chip. This is how we work around that problem: |
549 | * | 571 | * |
550 | * The first message goes into mb nr. 0 and issues an interrupt. All | 572 | * The first message goes into mb nr. 1 and issues an interrupt. All |
551 | * rx ints are disabled in the interrupt handler and a napi poll is | 573 | * rx ints are disabled in the interrupt handler and a napi poll is |
552 | * scheduled. We read the mailbox, but do _not_ reenable the mb (to | 574 | * scheduled. We read the mailbox, but do _not_ reenable the mb (to |
553 | * receive another message). | 575 | * receive another message). |
554 | * | 576 | * |
555 | * lower mbxs upper | 577 | * lower mbxs upper |
556 | * ______^______ __^__ | 578 | * ____^______ __^__ |
557 | * / \ / \ | 579 | * / \ / \ |
558 | * +-+-+-+-+-+-+-+-++-+-+-+-+ | 580 | * +-+-+-+-+-+-+-+-++-+-+-+-+ |
559 | * |x|x|x|x|x|x|x|x|| | | | | | 581 | * | |x|x|x|x|x|x|x|| | | | | |
560 | * +-+-+-+-+-+-+-+-++-+-+-+-+ | 582 | * +-+-+-+-+-+-+-+-++-+-+-+-+ |
561 | * 0 0 0 0 0 0 0 0 0 0 1 1 \ mail | 583 | * 0 0 0 0 0 0 0 0 0 0 1 1 \ mail |
562 | * 0 1 2 3 4 5 6 7 8 9 0 1 / box | 584 | * 0 1 2 3 4 5 6 7 8 9 0 1 / box |
585 | * ^ | ||
586 | * | | ||
587 | * \ | ||
588 | * unused, due to chip bug | ||
563 | * | 589 | * |
564 | * The variable priv->rx_next points to the next mailbox to read a | 590 | * The variable priv->rx_next points to the next mailbox to read a |
565 | * message from. As long we're in the lower mailboxes we just read the | 591 | * message from. As long we're in the lower mailboxes we just read the |
@@ -590,10 +616,10 @@ static int at91_poll_rx(struct net_device *dev, int quota) | |||
590 | "order of incoming frames cannot be guaranteed\n"); | 616 | "order of incoming frames cannot be guaranteed\n"); |
591 | 617 | ||
592 | again: | 618 | again: |
593 | for (mb = find_next_bit(addr, AT91_MB_RX_NUM, priv->rx_next); | 619 | for (mb = find_next_bit(addr, AT91_MB_RX_LAST + 1, priv->rx_next); |
594 | mb < AT91_MB_RX_NUM && quota > 0; | 620 | mb < AT91_MB_RX_LAST + 1 && quota > 0; |
595 | reg_sr = at91_read(priv, AT91_SR), | 621 | reg_sr = at91_read(priv, AT91_SR), |
596 | mb = find_next_bit(addr, AT91_MB_RX_NUM, ++priv->rx_next)) { | 622 | mb = find_next_bit(addr, AT91_MB_RX_LAST + 1, ++priv->rx_next)) { |
597 | at91_read_msg(dev, mb); | 623 | at91_read_msg(dev, mb); |
598 | 624 | ||
599 | /* reactivate mailboxes */ | 625 | /* reactivate mailboxes */ |
@@ -610,8 +636,8 @@ static int at91_poll_rx(struct net_device *dev, int quota) | |||
610 | 636 | ||
611 | /* upper group completed, look again in lower */ | 637 | /* upper group completed, look again in lower */ |
612 | if (priv->rx_next > AT91_MB_RX_LOW_LAST && | 638 | if (priv->rx_next > AT91_MB_RX_LOW_LAST && |
613 | quota > 0 && mb >= AT91_MB_RX_NUM) { | 639 | quota > 0 && mb > AT91_MB_RX_LAST) { |
614 | priv->rx_next = 0; | 640 | priv->rx_next = AT91_MB_RX_FIRST; |
615 | goto again; | 641 | goto again; |
616 | } | 642 | } |
617 | 643 | ||
@@ -1037,6 +1063,64 @@ static const struct net_device_ops at91_netdev_ops = { | |||
1037 | .ndo_start_xmit = at91_start_xmit, | 1063 | .ndo_start_xmit = at91_start_xmit, |
1038 | }; | 1064 | }; |
1039 | 1065 | ||
1066 | static ssize_t at91_sysfs_show_mb0_id(struct device *dev, | ||
1067 | struct device_attribute *attr, char *buf) | ||
1068 | { | ||
1069 | struct at91_priv *priv = netdev_priv(to_net_dev(dev)); | ||
1070 | |||
1071 | if (priv->mb0_id & CAN_EFF_FLAG) | ||
1072 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", priv->mb0_id); | ||
1073 | else | ||
1074 | return snprintf(buf, PAGE_SIZE, "0x%03x\n", priv->mb0_id); | ||
1075 | } | ||
1076 | |||
1077 | static ssize_t at91_sysfs_set_mb0_id(struct device *dev, | ||
1078 | struct device_attribute *attr, const char *buf, size_t count) | ||
1079 | { | ||
1080 | struct net_device *ndev = to_net_dev(dev); | ||
1081 | struct at91_priv *priv = netdev_priv(ndev); | ||
1082 | unsigned long can_id; | ||
1083 | ssize_t ret; | ||
1084 | int err; | ||
1085 | |||
1086 | rtnl_lock(); | ||
1087 | |||
1088 | if (ndev->flags & IFF_UP) { | ||
1089 | ret = -EBUSY; | ||
1090 | goto out; | ||
1091 | } | ||
1092 | |||
1093 | err = strict_strtoul(buf, 0, &can_id); | ||
1094 | if (err) { | ||
1095 | ret = err; | ||
1096 | goto out; | ||
1097 | } | ||
1098 | |||
1099 | if (can_id & CAN_EFF_FLAG) | ||
1100 | can_id &= CAN_EFF_MASK | CAN_EFF_FLAG; | ||
1101 | else | ||
1102 | can_id &= CAN_SFF_MASK; | ||
1103 | |||
1104 | priv->mb0_id = can_id; | ||
1105 | ret = count; | ||
1106 | |||
1107 | out: | ||
1108 | rtnl_unlock(); | ||
1109 | return ret; | ||
1110 | } | ||
1111 | |||
1112 | static DEVICE_ATTR(mb0_id, S_IWUGO | S_IRUGO, | ||
1113 | at91_sysfs_show_mb0_id, at91_sysfs_set_mb0_id); | ||
1114 | |||
1115 | static struct attribute *at91_sysfs_attrs[] = { | ||
1116 | &dev_attr_mb0_id.attr, | ||
1117 | NULL, | ||
1118 | }; | ||
1119 | |||
1120 | static struct attribute_group at91_sysfs_attr_group = { | ||
1121 | .attrs = at91_sysfs_attrs, | ||
1122 | }; | ||
1123 | |||
1040 | static int __devinit at91_can_probe(struct platform_device *pdev) | 1124 | static int __devinit at91_can_probe(struct platform_device *pdev) |
1041 | { | 1125 | { |
1042 | struct net_device *dev; | 1126 | struct net_device *dev; |
@@ -1082,6 +1166,7 @@ static int __devinit at91_can_probe(struct platform_device *pdev) | |||
1082 | dev->netdev_ops = &at91_netdev_ops; | 1166 | dev->netdev_ops = &at91_netdev_ops; |
1083 | dev->irq = irq; | 1167 | dev->irq = irq; |
1084 | dev->flags |= IFF_ECHO; | 1168 | dev->flags |= IFF_ECHO; |
1169 | dev->sysfs_groups[0] = &at91_sysfs_attr_group; | ||
1085 | 1170 | ||
1086 | priv = netdev_priv(dev); | 1171 | priv = netdev_priv(dev); |
1087 | priv->can.clock.freq = clk_get_rate(clk); | 1172 | priv->can.clock.freq = clk_get_rate(clk); |
@@ -1093,6 +1178,7 @@ static int __devinit at91_can_probe(struct platform_device *pdev) | |||
1093 | priv->dev = dev; | 1178 | priv->dev = dev; |
1094 | priv->clk = clk; | 1179 | priv->clk = clk; |
1095 | priv->pdata = pdev->dev.platform_data; | 1180 | priv->pdata = pdev->dev.platform_data; |
1181 | priv->mb0_id = 0x7ff; | ||
1096 | 1182 | ||
1097 | netif_napi_add(dev, &priv->napi, at91_poll, AT91_NAPI_WEIGHT); | 1183 | netif_napi_add(dev, &priv->napi, at91_poll, AT91_NAPI_WEIGHT); |
1098 | 1184 | ||
diff --git a/drivers/net/can/softing/Kconfig b/drivers/net/can/softing/Kconfig new file mode 100644 index 000000000000..92bd6bdde5e3 --- /dev/null +++ b/drivers/net/can/softing/Kconfig | |||
@@ -0,0 +1,30 @@ | |||
1 | config CAN_SOFTING | ||
2 | tristate "Softing Gmbh CAN generic support" | ||
3 | depends on CAN_DEV | ||
4 | ---help--- | ||
5 | Support for CAN cards from Softing Gmbh & some cards | ||
6 | from Vector Gmbh. | ||
7 | Softing Gmbh CAN cards come with 1 or 2 physical busses. | ||
8 | Those cards typically use Dual Port RAM to communicate | ||
9 | with the host CPU. The interface is then identical for PCI | ||
10 | and PCMCIA cards. This driver operates on a platform device, | ||
11 | which has been created by softing_cs or softing_pci driver. | ||
12 | Warning: | ||
13 | The API of the card does not allow fine control per bus, but | ||
14 | controls the 2 busses on the card together. | ||
15 | As such, some actions (start/stop/busoff recovery) on 1 bus | ||
16 | must bring down the other bus too temporarily. | ||
17 | |||
18 | config CAN_SOFTING_CS | ||
19 | tristate "Softing Gmbh CAN pcmcia cards" | ||
20 | depends on PCMCIA | ||
21 | select CAN_SOFTING | ||
22 | ---help--- | ||
23 | Support for PCMCIA cards from Softing Gmbh & some cards | ||
24 | from Vector Gmbh. | ||
25 | You need firmware for these, which you can get at | ||
26 | http://developer.berlios.de/projects/socketcan/ | ||
27 | This version of the driver is written against | ||
28 | firmware version 4.6 (softing-fw-4.6-binaries.tar.gz) | ||
29 | In order to use the card as CAN device, you need the Softing generic | ||
30 | support too. | ||
diff --git a/drivers/net/can/softing/Makefile b/drivers/net/can/softing/Makefile new file mode 100644 index 000000000000..c5e5016c742e --- /dev/null +++ b/drivers/net/can/softing/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | |||
2 | softing-y := softing_main.o softing_fw.o | ||
3 | obj-$(CONFIG_CAN_SOFTING) += softing.o | ||
4 | obj-$(CONFIG_CAN_SOFTING_CS) += softing_cs.o | ||
5 | |||
6 | ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG | ||
diff --git a/drivers/net/can/softing/softing.h b/drivers/net/can/softing/softing.h new file mode 100644 index 000000000000..7ec9f4db3d52 --- /dev/null +++ b/drivers/net/can/softing/softing.h | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * softing common interfaces | ||
3 | * | ||
4 | * by Kurt Van Dijck, 2008-2010 | ||
5 | */ | ||
6 | |||
7 | #include <linux/atomic.h> | ||
8 | #include <linux/netdevice.h> | ||
9 | #include <linux/ktime.h> | ||
10 | #include <linux/mutex.h> | ||
11 | #include <linux/spinlock.h> | ||
12 | #include <linux/can.h> | ||
13 | #include <linux/can/dev.h> | ||
14 | |||
15 | #include "softing_platform.h" | ||
16 | |||
17 | struct softing; | ||
18 | |||
19 | struct softing_priv { | ||
20 | struct can_priv can; /* must be the first member! */ | ||
21 | struct net_device *netdev; | ||
22 | struct softing *card; | ||
23 | struct { | ||
24 | int pending; | ||
25 | /* variables wich hold the circular buffer */ | ||
26 | int echo_put; | ||
27 | int echo_get; | ||
28 | } tx; | ||
29 | struct can_bittiming_const btr_const; | ||
30 | int index; | ||
31 | uint8_t output; | ||
32 | uint16_t chip; | ||
33 | }; | ||
34 | #define netdev2softing(netdev) ((struct softing_priv *)netdev_priv(netdev)) | ||
35 | |||
36 | struct softing { | ||
37 | const struct softing_platform_data *pdat; | ||
38 | struct platform_device *pdev; | ||
39 | struct net_device *net[2]; | ||
40 | spinlock_t spin; /* protect this structure & DPRAM access */ | ||
41 | ktime_t ts_ref; | ||
42 | ktime_t ts_overflow; /* timestamp overflow value, in ktime */ | ||
43 | |||
44 | struct { | ||
45 | /* indication of firmware status */ | ||
46 | int up; | ||
47 | /* protection of the 'up' variable */ | ||
48 | struct mutex lock; | ||
49 | } fw; | ||
50 | struct { | ||
51 | int nr; | ||
52 | int requested; | ||
53 | int svc_count; | ||
54 | unsigned int dpram_position; | ||
55 | } irq; | ||
56 | struct { | ||
57 | int pending; | ||
58 | int last_bus; | ||
59 | /* | ||
60 | * keep the bus that last tx'd a message, | ||
61 | * in order to let every netdev queue resume | ||
62 | */ | ||
63 | } tx; | ||
64 | __iomem uint8_t *dpram; | ||
65 | unsigned long dpram_phys; | ||
66 | unsigned long dpram_size; | ||
67 | struct { | ||
68 | uint16_t fw_version, hw_version, license, serial; | ||
69 | uint16_t chip[2]; | ||
70 | unsigned int freq; /* remote cpu's operating frequency */ | ||
71 | } id; | ||
72 | }; | ||
73 | |||
74 | extern int softing_default_output(struct net_device *netdev); | ||
75 | |||
76 | extern ktime_t softing_raw2ktime(struct softing *card, u32 raw); | ||
77 | |||
78 | extern int softing_chip_poweron(struct softing *card); | ||
79 | |||
80 | extern int softing_bootloader_command(struct softing *card, int16_t cmd, | ||
81 | const char *msg); | ||
82 | |||
83 | /* Load firmware after reset */ | ||
84 | extern int softing_load_fw(const char *file, struct softing *card, | ||
85 | __iomem uint8_t *virt, unsigned int size, int offset); | ||
86 | |||
87 | /* Load final application firmware after bootloader */ | ||
88 | extern int softing_load_app_fw(const char *file, struct softing *card); | ||
89 | |||
90 | /* | ||
91 | * enable or disable irq | ||
92 | * only called with fw.lock locked | ||
93 | */ | ||
94 | extern int softing_enable_irq(struct softing *card, int enable); | ||
95 | |||
96 | /* start/stop 1 bus on card */ | ||
97 | extern int softing_startstop(struct net_device *netdev, int up); | ||
98 | |||
99 | /* netif_rx() */ | ||
100 | extern int softing_netdev_rx(struct net_device *netdev, | ||
101 | const struct can_frame *msg, ktime_t ktime); | ||
102 | |||
103 | /* SOFTING DPRAM mappings */ | ||
104 | #define DPRAM_RX 0x0000 | ||
105 | #define DPRAM_RX_SIZE 32 | ||
106 | #define DPRAM_RX_CNT 16 | ||
107 | #define DPRAM_RX_RD 0x0201 /* uint8_t */ | ||
108 | #define DPRAM_RX_WR 0x0205 /* uint8_t */ | ||
109 | #define DPRAM_RX_LOST 0x0207 /* uint8_t */ | ||
110 | |||
111 | #define DPRAM_FCT_PARAM 0x0300 /* int16_t [20] */ | ||
112 | #define DPRAM_FCT_RESULT 0x0328 /* int16_t */ | ||
113 | #define DPRAM_FCT_HOST 0x032b /* uint16_t */ | ||
114 | |||
115 | #define DPRAM_INFO_BUSSTATE 0x0331 /* uint16_t */ | ||
116 | #define DPRAM_INFO_BUSSTATE2 0x0335 /* uint16_t */ | ||
117 | #define DPRAM_INFO_ERRSTATE 0x0339 /* uint16_t */ | ||
118 | #define DPRAM_INFO_ERRSTATE2 0x033d /* uint16_t */ | ||
119 | #define DPRAM_RESET 0x0341 /* uint16_t */ | ||
120 | #define DPRAM_CLR_RECV_FIFO 0x0345 /* uint16_t */ | ||
121 | #define DPRAM_RESET_TIME 0x034d /* uint16_t */ | ||
122 | #define DPRAM_TIME 0x0350 /* uint64_t */ | ||
123 | #define DPRAM_WR_START 0x0358 /* uint8_t */ | ||
124 | #define DPRAM_WR_END 0x0359 /* uint8_t */ | ||
125 | #define DPRAM_RESET_RX_FIFO 0x0361 /* uint16_t */ | ||
126 | #define DPRAM_RESET_TX_FIFO 0x0364 /* uint8_t */ | ||
127 | #define DPRAM_READ_FIFO_LEVEL 0x0365 /* uint8_t */ | ||
128 | #define DPRAM_RX_FIFO_LEVEL 0x0366 /* uint16_t */ | ||
129 | #define DPRAM_TX_FIFO_LEVEL 0x0366 /* uint16_t */ | ||
130 | |||
131 | #define DPRAM_TX 0x0400 /* uint16_t */ | ||
132 | #define DPRAM_TX_SIZE 16 | ||
133 | #define DPRAM_TX_CNT 32 | ||
134 | #define DPRAM_TX_RD 0x0601 /* uint8_t */ | ||
135 | #define DPRAM_TX_WR 0x0605 /* uint8_t */ | ||
136 | |||
137 | #define DPRAM_COMMAND 0x07e0 /* uint16_t */ | ||
138 | #define DPRAM_RECEIPT 0x07f0 /* uint16_t */ | ||
139 | #define DPRAM_IRQ_TOHOST 0x07fe /* uint8_t */ | ||
140 | #define DPRAM_IRQ_TOCARD 0x07ff /* uint8_t */ | ||
141 | |||
142 | #define DPRAM_V2_RESET 0x0e00 /* uint8_t */ | ||
143 | #define DPRAM_V2_IRQ_TOHOST 0x0e02 /* uint8_t */ | ||
144 | |||
145 | #define TXMAX (DPRAM_TX_CNT - 1) | ||
146 | |||
147 | /* DPRAM return codes */ | ||
148 | #define RES_NONE 0 | ||
149 | #define RES_OK 1 | ||
150 | #define RES_NOK 2 | ||
151 | #define RES_UNKNOWN 3 | ||
152 | /* DPRAM flags */ | ||
153 | #define CMD_TX 0x01 | ||
154 | #define CMD_ACK 0x02 | ||
155 | #define CMD_XTD 0x04 | ||
156 | #define CMD_RTR 0x08 | ||
157 | #define CMD_ERR 0x10 | ||
158 | #define CMD_BUS2 0x80 | ||
159 | |||
160 | /* returned fifo entry bus state masks */ | ||
161 | #define SF_MASK_BUSOFF 0x80 | ||
162 | #define SF_MASK_EPASSIVE 0x60 | ||
163 | |||
164 | /* bus states */ | ||
165 | #define STATE_BUSOFF 2 | ||
166 | #define STATE_EPASSIVE 1 | ||
167 | #define STATE_EACTIVE 0 | ||
diff --git a/drivers/net/can/softing/softing_cs.c b/drivers/net/can/softing/softing_cs.c new file mode 100644 index 000000000000..300fe75dd1a7 --- /dev/null +++ b/drivers/net/can/softing/softing_cs.c | |||
@@ -0,0 +1,359 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008-2010 | ||
3 | * | ||
4 | * - Kurt Van Dijck, EIA Electronics | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the version 2 of the GNU General Public License | ||
8 | * as published by the Free Software Foundation | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | |||
23 | #include <pcmcia/cistpl.h> | ||
24 | #include <pcmcia/ds.h> | ||
25 | |||
26 | #include "softing_platform.h" | ||
27 | |||
28 | static int softingcs_index; | ||
29 | static spinlock_t softingcs_index_lock; | ||
30 | |||
31 | static int softingcs_reset(struct platform_device *pdev, int v); | ||
32 | static int softingcs_enable_irq(struct platform_device *pdev, int v); | ||
33 | |||
34 | /* | ||
35 | * platform_data descriptions | ||
36 | */ | ||
37 | #define MHZ (1000*1000) | ||
38 | static const struct softing_platform_data softingcs_platform_data[] = { | ||
39 | { | ||
40 | .name = "CANcard", | ||
41 | .manf = 0x0168, .prod = 0x001, | ||
42 | .generation = 1, | ||
43 | .nbus = 2, | ||
44 | .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
45 | .dpram_size = 0x0800, | ||
46 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
47 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
48 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
49 | .reset = softingcs_reset, | ||
50 | .enable_irq = softingcs_enable_irq, | ||
51 | }, { | ||
52 | .name = "CANcard-NEC", | ||
53 | .manf = 0x0168, .prod = 0x002, | ||
54 | .generation = 1, | ||
55 | .nbus = 2, | ||
56 | .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
57 | .dpram_size = 0x0800, | ||
58 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
59 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
60 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
61 | .reset = softingcs_reset, | ||
62 | .enable_irq = softingcs_enable_irq, | ||
63 | }, { | ||
64 | .name = "CANcard-SJA", | ||
65 | .manf = 0x0168, .prod = 0x004, | ||
66 | .generation = 1, | ||
67 | .nbus = 2, | ||
68 | .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
69 | .dpram_size = 0x0800, | ||
70 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
71 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
72 | .app = {0x0010, 0x0d0000, fw_dir "cansja.bin",}, | ||
73 | .reset = softingcs_reset, | ||
74 | .enable_irq = softingcs_enable_irq, | ||
75 | }, { | ||
76 | .name = "CANcard-2", | ||
77 | .manf = 0x0168, .prod = 0x005, | ||
78 | .generation = 2, | ||
79 | .nbus = 2, | ||
80 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
81 | .dpram_size = 0x1000, | ||
82 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
83 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
84 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
85 | .reset = softingcs_reset, | ||
86 | .enable_irq = NULL, | ||
87 | }, { | ||
88 | .name = "Vector-CANcard", | ||
89 | .manf = 0x0168, .prod = 0x081, | ||
90 | .generation = 1, | ||
91 | .nbus = 2, | ||
92 | .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
93 | .dpram_size = 0x0800, | ||
94 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
95 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
96 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
97 | .reset = softingcs_reset, | ||
98 | .enable_irq = softingcs_enable_irq, | ||
99 | }, { | ||
100 | .name = "Vector-CANcard-SJA", | ||
101 | .manf = 0x0168, .prod = 0x084, | ||
102 | .generation = 1, | ||
103 | .nbus = 2, | ||
104 | .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
105 | .dpram_size = 0x0800, | ||
106 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
107 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
108 | .app = {0x0010, 0x0d0000, fw_dir "cansja.bin",}, | ||
109 | .reset = softingcs_reset, | ||
110 | .enable_irq = softingcs_enable_irq, | ||
111 | }, { | ||
112 | .name = "Vector-CANcard-2", | ||
113 | .manf = 0x0168, .prod = 0x085, | ||
114 | .generation = 2, | ||
115 | .nbus = 2, | ||
116 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
117 | .dpram_size = 0x1000, | ||
118 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
119 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
120 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
121 | .reset = softingcs_reset, | ||
122 | .enable_irq = NULL, | ||
123 | }, { | ||
124 | .name = "EDICcard-NEC", | ||
125 | .manf = 0x0168, .prod = 0x102, | ||
126 | .generation = 1, | ||
127 | .nbus = 2, | ||
128 | .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
129 | .dpram_size = 0x0800, | ||
130 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
131 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
132 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
133 | .reset = softingcs_reset, | ||
134 | .enable_irq = softingcs_enable_irq, | ||
135 | }, { | ||
136 | .name = "EDICcard-2", | ||
137 | .manf = 0x0168, .prod = 0x105, | ||
138 | .generation = 2, | ||
139 | .nbus = 2, | ||
140 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
141 | .dpram_size = 0x1000, | ||
142 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
143 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
144 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
145 | .reset = softingcs_reset, | ||
146 | .enable_irq = NULL, | ||
147 | }, { | ||
148 | 0, 0, | ||
149 | }, | ||
150 | }; | ||
151 | |||
152 | MODULE_FIRMWARE(fw_dir "bcard.bin"); | ||
153 | MODULE_FIRMWARE(fw_dir "ldcard.bin"); | ||
154 | MODULE_FIRMWARE(fw_dir "cancard.bin"); | ||
155 | MODULE_FIRMWARE(fw_dir "cansja.bin"); | ||
156 | |||
157 | MODULE_FIRMWARE(fw_dir "bcard2.bin"); | ||
158 | MODULE_FIRMWARE(fw_dir "ldcard2.bin"); | ||
159 | MODULE_FIRMWARE(fw_dir "cancrd2.bin"); | ||
160 | |||
161 | static __devinit const struct softing_platform_data | ||
162 | *softingcs_find_platform_data(unsigned int manf, unsigned int prod) | ||
163 | { | ||
164 | const struct softing_platform_data *lp; | ||
165 | |||
166 | for (lp = softingcs_platform_data; lp->manf; ++lp) { | ||
167 | if ((lp->manf == manf) && (lp->prod == prod)) | ||
168 | return lp; | ||
169 | } | ||
170 | return NULL; | ||
171 | } | ||
172 | |||
173 | /* | ||
174 | * platformdata callbacks | ||
175 | */ | ||
176 | static int softingcs_reset(struct platform_device *pdev, int v) | ||
177 | { | ||
178 | struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent); | ||
179 | |||
180 | dev_dbg(&pdev->dev, "pcmcia config [2] %02x\n", v ? 0 : 0x20); | ||
181 | return pcmcia_write_config_byte(pcmcia, 2, v ? 0 : 0x20); | ||
182 | } | ||
183 | |||
184 | static int softingcs_enable_irq(struct platform_device *pdev, int v) | ||
185 | { | ||
186 | struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent); | ||
187 | |||
188 | dev_dbg(&pdev->dev, "pcmcia config [0] %02x\n", v ? 0x60 : 0); | ||
189 | return pcmcia_write_config_byte(pcmcia, 0, v ? 0x60 : 0); | ||
190 | } | ||
191 | |||
192 | /* | ||
193 | * pcmcia check | ||
194 | */ | ||
195 | static __devinit int softingcs_probe_config(struct pcmcia_device *pcmcia, | ||
196 | void *priv_data) | ||
197 | { | ||
198 | struct softing_platform_data *pdat = priv_data; | ||
199 | struct resource *pres; | ||
200 | int memspeed = 0; | ||
201 | |||
202 | WARN_ON(!pdat); | ||
203 | pres = pcmcia->resource[PCMCIA_IOMEM_0]; | ||
204 | if (resource_size(pres) < 0x1000) | ||
205 | return -ERANGE; | ||
206 | |||
207 | pres->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE; | ||
208 | if (pdat->generation < 2) { | ||
209 | pres->flags |= WIN_USE_WAIT | WIN_DATA_WIDTH_8; | ||
210 | memspeed = 3; | ||
211 | } else { | ||
212 | pres->flags |= WIN_DATA_WIDTH_16; | ||
213 | } | ||
214 | return pcmcia_request_window(pcmcia, pres, memspeed); | ||
215 | } | ||
216 | |||
217 | static __devexit void softingcs_remove(struct pcmcia_device *pcmcia) | ||
218 | { | ||
219 | struct platform_device *pdev = pcmcia->priv; | ||
220 | |||
221 | /* free bits */ | ||
222 | platform_device_unregister(pdev); | ||
223 | /* release pcmcia stuff */ | ||
224 | pcmcia_disable_device(pcmcia); | ||
225 | } | ||
226 | |||
227 | /* | ||
228 | * platform_device wrapper | ||
229 | * pdev->resource has 2 entries: io & irq | ||
230 | */ | ||
231 | static void softingcs_pdev_release(struct device *dev) | ||
232 | { | ||
233 | struct platform_device *pdev = to_platform_device(dev); | ||
234 | kfree(pdev); | ||
235 | } | ||
236 | |||
237 | static __devinit int softingcs_probe(struct pcmcia_device *pcmcia) | ||
238 | { | ||
239 | int ret; | ||
240 | struct platform_device *pdev; | ||
241 | const struct softing_platform_data *pdat; | ||
242 | struct resource *pres; | ||
243 | struct dev { | ||
244 | struct platform_device pdev; | ||
245 | struct resource res[2]; | ||
246 | } *dev; | ||
247 | |||
248 | /* find matching platform_data */ | ||
249 | pdat = softingcs_find_platform_data(pcmcia->manf_id, pcmcia->card_id); | ||
250 | if (!pdat) | ||
251 | return -ENOTTY; | ||
252 | |||
253 | /* setup pcmcia device */ | ||
254 | pcmcia->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IOMEM | | ||
255 | CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC; | ||
256 | ret = pcmcia_loop_config(pcmcia, softingcs_probe_config, (void *)pdat); | ||
257 | if (ret) | ||
258 | goto pcmcia_failed; | ||
259 | |||
260 | ret = pcmcia_enable_device(pcmcia); | ||
261 | if (ret < 0) | ||
262 | goto pcmcia_failed; | ||
263 | |||
264 | pres = pcmcia->resource[PCMCIA_IOMEM_0]; | ||
265 | if (!pres) { | ||
266 | ret = -EBADF; | ||
267 | goto pcmcia_bad; | ||
268 | } | ||
269 | |||
270 | /* create softing platform device */ | ||
271 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
272 | if (!dev) { | ||
273 | ret = -ENOMEM; | ||
274 | goto mem_failed; | ||
275 | } | ||
276 | dev->pdev.resource = dev->res; | ||
277 | dev->pdev.num_resources = ARRAY_SIZE(dev->res); | ||
278 | dev->pdev.dev.release = softingcs_pdev_release; | ||
279 | |||
280 | pdev = &dev->pdev; | ||
281 | pdev->dev.platform_data = (void *)pdat; | ||
282 | pdev->dev.parent = &pcmcia->dev; | ||
283 | pcmcia->priv = pdev; | ||
284 | |||
285 | /* platform device resources */ | ||
286 | pdev->resource[0].flags = IORESOURCE_MEM; | ||
287 | pdev->resource[0].start = pres->start; | ||
288 | pdev->resource[0].end = pres->end; | ||
289 | |||
290 | pdev->resource[1].flags = IORESOURCE_IRQ; | ||
291 | pdev->resource[1].start = pcmcia->irq; | ||
292 | pdev->resource[1].end = pdev->resource[1].start; | ||
293 | |||
294 | /* platform device setup */ | ||
295 | spin_lock(&softingcs_index_lock); | ||
296 | pdev->id = softingcs_index++; | ||
297 | spin_unlock(&softingcs_index_lock); | ||
298 | pdev->name = "softing"; | ||
299 | dev_set_name(&pdev->dev, "softingcs.%i", pdev->id); | ||
300 | ret = platform_device_register(pdev); | ||
301 | if (ret < 0) | ||
302 | goto platform_failed; | ||
303 | |||
304 | dev_info(&pcmcia->dev, "created %s\n", dev_name(&pdev->dev)); | ||
305 | return 0; | ||
306 | |||
307 | platform_failed: | ||
308 | kfree(dev); | ||
309 | mem_failed: | ||
310 | pcmcia_bad: | ||
311 | pcmcia_failed: | ||
312 | pcmcia_disable_device(pcmcia); | ||
313 | pcmcia->priv = NULL; | ||
314 | return ret ?: -ENODEV; | ||
315 | } | ||
316 | |||
317 | static /*const*/ struct pcmcia_device_id softingcs_ids[] = { | ||
318 | /* softing */ | ||
319 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001), | ||
320 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002), | ||
321 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004), | ||
322 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005), | ||
323 | /* vector, manufacturer? */ | ||
324 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081), | ||
325 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084), | ||
326 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085), | ||
327 | /* EDIC */ | ||
328 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102), | ||
329 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105), | ||
330 | PCMCIA_DEVICE_NULL, | ||
331 | }; | ||
332 | |||
333 | MODULE_DEVICE_TABLE(pcmcia, softingcs_ids); | ||
334 | |||
335 | static struct pcmcia_driver softingcs_driver = { | ||
336 | .owner = THIS_MODULE, | ||
337 | .name = "softingcs", | ||
338 | .id_table = softingcs_ids, | ||
339 | .probe = softingcs_probe, | ||
340 | .remove = __devexit_p(softingcs_remove), | ||
341 | }; | ||
342 | |||
343 | static int __init softingcs_start(void) | ||
344 | { | ||
345 | spin_lock_init(&softingcs_index_lock); | ||
346 | return pcmcia_register_driver(&softingcs_driver); | ||
347 | } | ||
348 | |||
349 | static void __exit softingcs_stop(void) | ||
350 | { | ||
351 | pcmcia_unregister_driver(&softingcs_driver); | ||
352 | } | ||
353 | |||
354 | module_init(softingcs_start); | ||
355 | module_exit(softingcs_stop); | ||
356 | |||
357 | MODULE_DESCRIPTION("softing CANcard driver" | ||
358 | ", links PCMCIA card to softing driver"); | ||
359 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/net/can/softing/softing_fw.c b/drivers/net/can/softing/softing_fw.c new file mode 100644 index 000000000000..b520784fb197 --- /dev/null +++ b/drivers/net/can/softing/softing_fw.c | |||
@@ -0,0 +1,691 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008-2010 | ||
3 | * | ||
4 | * - Kurt Van Dijck, EIA Electronics | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the version 2 of the GNU General Public License | ||
8 | * as published by the Free Software Foundation | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/firmware.h> | ||
21 | #include <linux/sched.h> | ||
22 | #include <asm/div64.h> | ||
23 | |||
24 | #include "softing.h" | ||
25 | |||
26 | /* | ||
27 | * low level DPRAM command. | ||
28 | * Make sure that card->dpram[DPRAM_FCT_HOST] is preset | ||
29 | */ | ||
30 | static int _softing_fct_cmd(struct softing *card, int16_t cmd, uint16_t vector, | ||
31 | const char *msg) | ||
32 | { | ||
33 | int ret; | ||
34 | unsigned long stamp; | ||
35 | |||
36 | iowrite16(cmd, &card->dpram[DPRAM_FCT_PARAM]); | ||
37 | iowrite8(vector >> 8, &card->dpram[DPRAM_FCT_HOST + 1]); | ||
38 | iowrite8(vector, &card->dpram[DPRAM_FCT_HOST]); | ||
39 | /* be sure to flush this to the card */ | ||
40 | wmb(); | ||
41 | stamp = jiffies + 1 * HZ; | ||
42 | /* wait for card */ | ||
43 | do { | ||
44 | /* DPRAM_FCT_HOST is _not_ aligned */ | ||
45 | ret = ioread8(&card->dpram[DPRAM_FCT_HOST]) + | ||
46 | (ioread8(&card->dpram[DPRAM_FCT_HOST + 1]) << 8); | ||
47 | /* don't have any cached variables */ | ||
48 | rmb(); | ||
49 | if (ret == RES_OK) | ||
50 | /* read return-value now */ | ||
51 | return ioread16(&card->dpram[DPRAM_FCT_RESULT]); | ||
52 | |||
53 | if ((ret != vector) || time_after(jiffies, stamp)) | ||
54 | break; | ||
55 | /* process context => relax */ | ||
56 | usleep_range(500, 10000); | ||
57 | } while (1); | ||
58 | |||
59 | ret = (ret == RES_NONE) ? -ETIMEDOUT : -ECANCELED; | ||
60 | dev_alert(&card->pdev->dev, "firmware %s failed (%i)\n", msg, ret); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | static int softing_fct_cmd(struct softing *card, int16_t cmd, const char *msg) | ||
65 | { | ||
66 | int ret; | ||
67 | |||
68 | ret = _softing_fct_cmd(card, cmd, 0, msg); | ||
69 | if (ret > 0) { | ||
70 | dev_alert(&card->pdev->dev, "%s returned %u\n", msg, ret); | ||
71 | ret = -EIO; | ||
72 | } | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | int softing_bootloader_command(struct softing *card, int16_t cmd, | ||
77 | const char *msg) | ||
78 | { | ||
79 | int ret; | ||
80 | unsigned long stamp; | ||
81 | |||
82 | iowrite16(RES_NONE, &card->dpram[DPRAM_RECEIPT]); | ||
83 | iowrite16(cmd, &card->dpram[DPRAM_COMMAND]); | ||
84 | /* be sure to flush this to the card */ | ||
85 | wmb(); | ||
86 | stamp = jiffies + 3 * HZ; | ||
87 | /* wait for card */ | ||
88 | do { | ||
89 | ret = ioread16(&card->dpram[DPRAM_RECEIPT]); | ||
90 | /* don't have any cached variables */ | ||
91 | rmb(); | ||
92 | if (ret == RES_OK) | ||
93 | return 0; | ||
94 | if (time_after(jiffies, stamp)) | ||
95 | break; | ||
96 | /* process context => relax */ | ||
97 | usleep_range(500, 10000); | ||
98 | } while (!signal_pending(current)); | ||
99 | |||
100 | ret = (ret == RES_NONE) ? -ETIMEDOUT : -ECANCELED; | ||
101 | dev_alert(&card->pdev->dev, "bootloader %s failed (%i)\n", msg, ret); | ||
102 | return ret; | ||
103 | } | ||
104 | |||
105 | static int fw_parse(const uint8_t **pmem, uint16_t *ptype, uint32_t *paddr, | ||
106 | uint16_t *plen, const uint8_t **pdat) | ||
107 | { | ||
108 | uint16_t checksum[2]; | ||
109 | const uint8_t *mem; | ||
110 | const uint8_t *end; | ||
111 | |||
112 | /* | ||
113 | * firmware records are a binary, unaligned stream composed of: | ||
114 | * uint16_t type; | ||
115 | * uint32_t addr; | ||
116 | * uint16_t len; | ||
117 | * uint8_t dat[len]; | ||
118 | * uint16_t checksum; | ||
119 | * all values in little endian. | ||
120 | * We could define a struct for this, with __attribute__((packed)), | ||
121 | * but would that solve the alignment in _all_ cases (cfr. the | ||
122 | * struct itself may be an odd address)? | ||
123 | * | ||
124 | * I chose to use leXX_to_cpup() since this solves both | ||
125 | * endianness & alignment. | ||
126 | */ | ||
127 | mem = *pmem; | ||
128 | *ptype = le16_to_cpup((void *)&mem[0]); | ||
129 | *paddr = le32_to_cpup((void *)&mem[2]); | ||
130 | *plen = le16_to_cpup((void *)&mem[6]); | ||
131 | *pdat = &mem[8]; | ||
132 | /* verify checksum */ | ||
133 | end = &mem[8 + *plen]; | ||
134 | checksum[0] = le16_to_cpup((void *)end); | ||
135 | for (checksum[1] = 0; mem < end; ++mem) | ||
136 | checksum[1] += *mem; | ||
137 | if (checksum[0] != checksum[1]) | ||
138 | return -EINVAL; | ||
139 | /* increment */ | ||
140 | *pmem += 10 + *plen; | ||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | int softing_load_fw(const char *file, struct softing *card, | ||
145 | __iomem uint8_t *dpram, unsigned int size, int offset) | ||
146 | { | ||
147 | const struct firmware *fw; | ||
148 | int ret; | ||
149 | const uint8_t *mem, *end, *dat; | ||
150 | uint16_t type, len; | ||
151 | uint32_t addr; | ||
152 | uint8_t *buf = NULL; | ||
153 | int buflen = 0; | ||
154 | int8_t type_end = 0; | ||
155 | |||
156 | ret = request_firmware(&fw, file, &card->pdev->dev); | ||
157 | if (ret < 0) | ||
158 | return ret; | ||
159 | dev_dbg(&card->pdev->dev, "%s, firmware(%s) got %u bytes" | ||
160 | ", offset %c0x%04x\n", | ||
161 | card->pdat->name, file, (unsigned int)fw->size, | ||
162 | (offset >= 0) ? '+' : '-', (unsigned int)abs(offset)); | ||
163 | /* parse the firmware */ | ||
164 | mem = fw->data; | ||
165 | end = &mem[fw->size]; | ||
166 | /* look for header record */ | ||
167 | ret = fw_parse(&mem, &type, &addr, &len, &dat); | ||
168 | if (ret < 0) | ||
169 | goto failed; | ||
170 | if (type != 0xffff) | ||
171 | goto failed; | ||
172 | if (strncmp("Structured Binary Format, Softing GmbH" , dat, len)) { | ||
173 | ret = -EINVAL; | ||
174 | goto failed; | ||
175 | } | ||
176 | /* ok, we had a header */ | ||
177 | while (mem < end) { | ||
178 | ret = fw_parse(&mem, &type, &addr, &len, &dat); | ||
179 | if (ret < 0) | ||
180 | goto failed; | ||
181 | if (type == 3) { | ||
182 | /* start address, not used here */ | ||
183 | continue; | ||
184 | } else if (type == 1) { | ||
185 | /* eof */ | ||
186 | type_end = 1; | ||
187 | break; | ||
188 | } else if (type != 0) { | ||
189 | ret = -EINVAL; | ||
190 | goto failed; | ||
191 | } | ||
192 | |||
193 | if ((addr + len + offset) > size) | ||
194 | goto failed; | ||
195 | memcpy_toio(&dpram[addr + offset], dat, len); | ||
196 | /* be sure to flush caches from IO space */ | ||
197 | mb(); | ||
198 | if (len > buflen) { | ||
199 | /* align buflen */ | ||
200 | buflen = (len + (1024-1)) & ~(1024-1); | ||
201 | buf = krealloc(buf, buflen, GFP_KERNEL); | ||
202 | if (!buf) { | ||
203 | ret = -ENOMEM; | ||
204 | goto failed; | ||
205 | } | ||
206 | } | ||
207 | /* verify record data */ | ||
208 | memcpy_fromio(buf, &dpram[addr + offset], len); | ||
209 | if (memcmp(buf, dat, len)) { | ||
210 | /* is not ok */ | ||
211 | dev_alert(&card->pdev->dev, "DPRAM readback failed\n"); | ||
212 | ret = -EIO; | ||
213 | goto failed; | ||
214 | } | ||
215 | } | ||
216 | if (!type_end) | ||
217 | /* no end record seen */ | ||
218 | goto failed; | ||
219 | ret = 0; | ||
220 | failed: | ||
221 | kfree(buf); | ||
222 | release_firmware(fw); | ||
223 | if (ret < 0) | ||
224 | dev_info(&card->pdev->dev, "firmware %s failed\n", file); | ||
225 | return ret; | ||
226 | } | ||
227 | |||
228 | int softing_load_app_fw(const char *file, struct softing *card) | ||
229 | { | ||
230 | const struct firmware *fw; | ||
231 | const uint8_t *mem, *end, *dat; | ||
232 | int ret, j; | ||
233 | uint16_t type, len; | ||
234 | uint32_t addr, start_addr = 0; | ||
235 | unsigned int sum, rx_sum; | ||
236 | int8_t type_end = 0, type_entrypoint = 0; | ||
237 | |||
238 | ret = request_firmware(&fw, file, &card->pdev->dev); | ||
239 | if (ret) { | ||
240 | dev_alert(&card->pdev->dev, "request_firmware(%s) got %i\n", | ||
241 | file, ret); | ||
242 | return ret; | ||
243 | } | ||
244 | dev_dbg(&card->pdev->dev, "firmware(%s) got %lu bytes\n", | ||
245 | file, (unsigned long)fw->size); | ||
246 | /* parse the firmware */ | ||
247 | mem = fw->data; | ||
248 | end = &mem[fw->size]; | ||
249 | /* look for header record */ | ||
250 | ret = fw_parse(&mem, &type, &addr, &len, &dat); | ||
251 | if (ret) | ||
252 | goto failed; | ||
253 | ret = -EINVAL; | ||
254 | if (type != 0xffff) { | ||
255 | dev_alert(&card->pdev->dev, "firmware starts with type 0x%x\n", | ||
256 | type); | ||
257 | goto failed; | ||
258 | } | ||
259 | if (strncmp("Structured Binary Format, Softing GmbH", dat, len)) { | ||
260 | dev_alert(&card->pdev->dev, "firmware string '%.*s' fault\n", | ||
261 | len, dat); | ||
262 | goto failed; | ||
263 | } | ||
264 | /* ok, we had a header */ | ||
265 | while (mem < end) { | ||
266 | ret = fw_parse(&mem, &type, &addr, &len, &dat); | ||
267 | if (ret) | ||
268 | goto failed; | ||
269 | |||
270 | if (type == 3) { | ||
271 | /* start address */ | ||
272 | start_addr = addr; | ||
273 | type_entrypoint = 1; | ||
274 | continue; | ||
275 | } else if (type == 1) { | ||
276 | /* eof */ | ||
277 | type_end = 1; | ||
278 | break; | ||
279 | } else if (type != 0) { | ||
280 | dev_alert(&card->pdev->dev, | ||
281 | "unknown record type 0x%04x\n", type); | ||
282 | ret = -EINVAL; | ||
283 | goto failed; | ||
284 | } | ||
285 | |||
286 | /* regualar data */ | ||
287 | for (sum = 0, j = 0; j < len; ++j) | ||
288 | sum += dat[j]; | ||
289 | /* work in 16bit (target) */ | ||
290 | sum &= 0xffff; | ||
291 | |||
292 | memcpy_toio(&card->dpram[card->pdat->app.offs], dat, len); | ||
293 | iowrite32(card->pdat->app.offs + card->pdat->app.addr, | ||
294 | &card->dpram[DPRAM_COMMAND + 2]); | ||
295 | iowrite32(addr, &card->dpram[DPRAM_COMMAND + 6]); | ||
296 | iowrite16(len, &card->dpram[DPRAM_COMMAND + 10]); | ||
297 | iowrite8(1, &card->dpram[DPRAM_COMMAND + 12]); | ||
298 | ret = softing_bootloader_command(card, 1, "loading app."); | ||
299 | if (ret < 0) | ||
300 | goto failed; | ||
301 | /* verify checksum */ | ||
302 | rx_sum = ioread16(&card->dpram[DPRAM_RECEIPT + 2]); | ||
303 | if (rx_sum != sum) { | ||
304 | dev_alert(&card->pdev->dev, "SRAM seems to be damaged" | ||
305 | ", wanted 0x%04x, got 0x%04x\n", sum, rx_sum); | ||
306 | ret = -EIO; | ||
307 | goto failed; | ||
308 | } | ||
309 | } | ||
310 | if (!type_end || !type_entrypoint) | ||
311 | goto failed; | ||
312 | /* start application in card */ | ||
313 | iowrite32(start_addr, &card->dpram[DPRAM_COMMAND + 2]); | ||
314 | iowrite8(1, &card->dpram[DPRAM_COMMAND + 6]); | ||
315 | ret = softing_bootloader_command(card, 3, "start app."); | ||
316 | if (ret < 0) | ||
317 | goto failed; | ||
318 | ret = 0; | ||
319 | failed: | ||
320 | release_firmware(fw); | ||
321 | if (ret < 0) | ||
322 | dev_info(&card->pdev->dev, "firmware %s failed\n", file); | ||
323 | return ret; | ||
324 | } | ||
325 | |||
326 | static int softing_reset_chip(struct softing *card) | ||
327 | { | ||
328 | int ret; | ||
329 | |||
330 | do { | ||
331 | /* reset chip */ | ||
332 | iowrite8(0, &card->dpram[DPRAM_RESET_RX_FIFO]); | ||
333 | iowrite8(0, &card->dpram[DPRAM_RESET_RX_FIFO+1]); | ||
334 | iowrite8(1, &card->dpram[DPRAM_RESET]); | ||
335 | iowrite8(0, &card->dpram[DPRAM_RESET+1]); | ||
336 | |||
337 | ret = softing_fct_cmd(card, 0, "reset_can"); | ||
338 | if (!ret) | ||
339 | break; | ||
340 | if (signal_pending(current)) | ||
341 | /* don't wait any longer */ | ||
342 | break; | ||
343 | } while (1); | ||
344 | card->tx.pending = 0; | ||
345 | return ret; | ||
346 | } | ||
347 | |||
348 | int softing_chip_poweron(struct softing *card) | ||
349 | { | ||
350 | int ret; | ||
351 | /* sync */ | ||
352 | ret = _softing_fct_cmd(card, 99, 0x55, "sync-a"); | ||
353 | if (ret < 0) | ||
354 | goto failed; | ||
355 | |||
356 | ret = _softing_fct_cmd(card, 99, 0xaa, "sync-b"); | ||
357 | if (ret < 0) | ||
358 | goto failed; | ||
359 | |||
360 | ret = softing_reset_chip(card); | ||
361 | if (ret < 0) | ||
362 | goto failed; | ||
363 | /* get_serial */ | ||
364 | ret = softing_fct_cmd(card, 43, "get_serial_number"); | ||
365 | if (ret < 0) | ||
366 | goto failed; | ||
367 | card->id.serial = ioread32(&card->dpram[DPRAM_FCT_PARAM]); | ||
368 | /* get_version */ | ||
369 | ret = softing_fct_cmd(card, 12, "get_version"); | ||
370 | if (ret < 0) | ||
371 | goto failed; | ||
372 | card->id.fw_version = ioread16(&card->dpram[DPRAM_FCT_PARAM + 2]); | ||
373 | card->id.hw_version = ioread16(&card->dpram[DPRAM_FCT_PARAM + 4]); | ||
374 | card->id.license = ioread16(&card->dpram[DPRAM_FCT_PARAM + 6]); | ||
375 | card->id.chip[0] = ioread16(&card->dpram[DPRAM_FCT_PARAM + 8]); | ||
376 | card->id.chip[1] = ioread16(&card->dpram[DPRAM_FCT_PARAM + 10]); | ||
377 | return 0; | ||
378 | failed: | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static void softing_initialize_timestamp(struct softing *card) | ||
383 | { | ||
384 | uint64_t ovf; | ||
385 | |||
386 | card->ts_ref = ktime_get(); | ||
387 | |||
388 | /* 16MHz is the reference */ | ||
389 | ovf = 0x100000000ULL * 16; | ||
390 | do_div(ovf, card->pdat->freq ?: 16); | ||
391 | |||
392 | card->ts_overflow = ktime_add_us(ktime_set(0, 0), ovf); | ||
393 | } | ||
394 | |||
395 | ktime_t softing_raw2ktime(struct softing *card, u32 raw) | ||
396 | { | ||
397 | uint64_t rawl; | ||
398 | ktime_t now, real_offset; | ||
399 | ktime_t target; | ||
400 | ktime_t tmp; | ||
401 | |||
402 | now = ktime_get(); | ||
403 | real_offset = ktime_sub(ktime_get_real(), now); | ||
404 | |||
405 | /* find nsec from card */ | ||
406 | rawl = raw * 16; | ||
407 | do_div(rawl, card->pdat->freq ?: 16); | ||
408 | target = ktime_add_us(card->ts_ref, rawl); | ||
409 | /* test for overflows */ | ||
410 | tmp = ktime_add(target, card->ts_overflow); | ||
411 | while (unlikely(ktime_to_ns(tmp) > ktime_to_ns(now))) { | ||
412 | card->ts_ref = ktime_add(card->ts_ref, card->ts_overflow); | ||
413 | target = tmp; | ||
414 | tmp = ktime_add(target, card->ts_overflow); | ||
415 | } | ||
416 | return ktime_add(target, real_offset); | ||
417 | } | ||
418 | |||
419 | static inline int softing_error_reporting(struct net_device *netdev) | ||
420 | { | ||
421 | struct softing_priv *priv = netdev_priv(netdev); | ||
422 | |||
423 | return (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) | ||
424 | ? 1 : 0; | ||
425 | } | ||
426 | |||
427 | int softing_startstop(struct net_device *dev, int up) | ||
428 | { | ||
429 | int ret; | ||
430 | struct softing *card; | ||
431 | struct softing_priv *priv; | ||
432 | struct net_device *netdev; | ||
433 | int bus_bitmask_start; | ||
434 | int j, error_reporting; | ||
435 | struct can_frame msg; | ||
436 | const struct can_bittiming *bt; | ||
437 | |||
438 | priv = netdev_priv(dev); | ||
439 | card = priv->card; | ||
440 | |||
441 | if (!card->fw.up) | ||
442 | return -EIO; | ||
443 | |||
444 | ret = mutex_lock_interruptible(&card->fw.lock); | ||
445 | if (ret) | ||
446 | return ret; | ||
447 | |||
448 | bus_bitmask_start = 0; | ||
449 | if (dev && up) | ||
450 | /* prepare to start this bus as well */ | ||
451 | bus_bitmask_start |= (1 << priv->index); | ||
452 | /* bring netdevs down */ | ||
453 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
454 | netdev = card->net[j]; | ||
455 | if (!netdev) | ||
456 | continue; | ||
457 | priv = netdev_priv(netdev); | ||
458 | |||
459 | if (dev != netdev) | ||
460 | netif_stop_queue(netdev); | ||
461 | |||
462 | if (netif_running(netdev)) { | ||
463 | if (dev != netdev) | ||
464 | bus_bitmask_start |= (1 << j); | ||
465 | priv->tx.pending = 0; | ||
466 | priv->tx.echo_put = 0; | ||
467 | priv->tx.echo_get = 0; | ||
468 | /* | ||
469 | * this bus' may just have called open_candev() | ||
470 | * which is rather stupid to call close_candev() | ||
471 | * already | ||
472 | * but we may come here from busoff recovery too | ||
473 | * in which case the echo_skb _needs_ flushing too. | ||
474 | * just be sure to call open_candev() again | ||
475 | */ | ||
476 | close_candev(netdev); | ||
477 | } | ||
478 | priv->can.state = CAN_STATE_STOPPED; | ||
479 | } | ||
480 | card->tx.pending = 0; | ||
481 | |||
482 | softing_enable_irq(card, 0); | ||
483 | ret = softing_reset_chip(card); | ||
484 | if (ret) | ||
485 | goto failed; | ||
486 | if (!bus_bitmask_start) | ||
487 | /* no busses to be brought up */ | ||
488 | goto card_done; | ||
489 | |||
490 | if ((bus_bitmask_start & 1) && (bus_bitmask_start & 2) | ||
491 | && (softing_error_reporting(card->net[0]) | ||
492 | != softing_error_reporting(card->net[1]))) { | ||
493 | dev_alert(&card->pdev->dev, | ||
494 | "err_reporting flag differs for busses\n"); | ||
495 | goto invalid; | ||
496 | } | ||
497 | error_reporting = 0; | ||
498 | if (bus_bitmask_start & 1) { | ||
499 | netdev = card->net[0]; | ||
500 | priv = netdev_priv(netdev); | ||
501 | error_reporting += softing_error_reporting(netdev); | ||
502 | /* init chip 1 */ | ||
503 | bt = &priv->can.bittiming; | ||
504 | iowrite16(bt->brp, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
505 | iowrite16(bt->sjw, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
506 | iowrite16(bt->phase_seg1 + bt->prop_seg, | ||
507 | &card->dpram[DPRAM_FCT_PARAM + 6]); | ||
508 | iowrite16(bt->phase_seg2, &card->dpram[DPRAM_FCT_PARAM + 8]); | ||
509 | iowrite16((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) ? 1 : 0, | ||
510 | &card->dpram[DPRAM_FCT_PARAM + 10]); | ||
511 | ret = softing_fct_cmd(card, 1, "initialize_chip[0]"); | ||
512 | if (ret < 0) | ||
513 | goto failed; | ||
514 | /* set mode */ | ||
515 | iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
516 | iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
517 | ret = softing_fct_cmd(card, 3, "set_mode[0]"); | ||
518 | if (ret < 0) | ||
519 | goto failed; | ||
520 | /* set filter */ | ||
521 | /* 11bit id & mask */ | ||
522 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
523 | iowrite16(0x07ff, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
524 | /* 29bit id.lo & mask.lo & id.hi & mask.hi */ | ||
525 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 6]); | ||
526 | iowrite16(0xffff, &card->dpram[DPRAM_FCT_PARAM + 8]); | ||
527 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 10]); | ||
528 | iowrite16(0x1fff, &card->dpram[DPRAM_FCT_PARAM + 12]); | ||
529 | ret = softing_fct_cmd(card, 7, "set_filter[0]"); | ||
530 | if (ret < 0) | ||
531 | goto failed; | ||
532 | /* set output control */ | ||
533 | iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
534 | ret = softing_fct_cmd(card, 5, "set_output[0]"); | ||
535 | if (ret < 0) | ||
536 | goto failed; | ||
537 | } | ||
538 | if (bus_bitmask_start & 2) { | ||
539 | netdev = card->net[1]; | ||
540 | priv = netdev_priv(netdev); | ||
541 | error_reporting += softing_error_reporting(netdev); | ||
542 | /* init chip2 */ | ||
543 | bt = &priv->can.bittiming; | ||
544 | iowrite16(bt->brp, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
545 | iowrite16(bt->sjw, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
546 | iowrite16(bt->phase_seg1 + bt->prop_seg, | ||
547 | &card->dpram[DPRAM_FCT_PARAM + 6]); | ||
548 | iowrite16(bt->phase_seg2, &card->dpram[DPRAM_FCT_PARAM + 8]); | ||
549 | iowrite16((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) ? 1 : 0, | ||
550 | &card->dpram[DPRAM_FCT_PARAM + 10]); | ||
551 | ret = softing_fct_cmd(card, 2, "initialize_chip[1]"); | ||
552 | if (ret < 0) | ||
553 | goto failed; | ||
554 | /* set mode2 */ | ||
555 | iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
556 | iowrite16(0, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
557 | ret = softing_fct_cmd(card, 4, "set_mode[1]"); | ||
558 | if (ret < 0) | ||
559 | goto failed; | ||
560 | /* set filter2 */ | ||
561 | /* 11bit id & mask */ | ||
562 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
563 | iowrite16(0x07ff, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
564 | /* 29bit id.lo & mask.lo & id.hi & mask.hi */ | ||
565 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 6]); | ||
566 | iowrite16(0xffff, &card->dpram[DPRAM_FCT_PARAM + 8]); | ||
567 | iowrite16(0x0000, &card->dpram[DPRAM_FCT_PARAM + 10]); | ||
568 | iowrite16(0x1fff, &card->dpram[DPRAM_FCT_PARAM + 12]); | ||
569 | ret = softing_fct_cmd(card, 8, "set_filter[1]"); | ||
570 | if (ret < 0) | ||
571 | goto failed; | ||
572 | /* set output control2 */ | ||
573 | iowrite16(priv->output, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
574 | ret = softing_fct_cmd(card, 6, "set_output[1]"); | ||
575 | if (ret < 0) | ||
576 | goto failed; | ||
577 | } | ||
578 | /* enable_error_frame */ | ||
579 | /* | ||
580 | * Error reporting is switched off at the moment since | ||
581 | * the receiving of them is not yet 100% verified | ||
582 | * This should be enabled sooner or later | ||
583 | * | ||
584 | if (error_reporting) { | ||
585 | ret = softing_fct_cmd(card, 51, "enable_error_frame"); | ||
586 | if (ret < 0) | ||
587 | goto failed; | ||
588 | } | ||
589 | */ | ||
590 | /* initialize interface */ | ||
591 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 2]); | ||
592 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 4]); | ||
593 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 6]); | ||
594 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 8]); | ||
595 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 10]); | ||
596 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 12]); | ||
597 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 14]); | ||
598 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 16]); | ||
599 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 18]); | ||
600 | iowrite16(1, &card->dpram[DPRAM_FCT_PARAM + 20]); | ||
601 | ret = softing_fct_cmd(card, 17, "initialize_interface"); | ||
602 | if (ret < 0) | ||
603 | goto failed; | ||
604 | /* enable_fifo */ | ||
605 | ret = softing_fct_cmd(card, 36, "enable_fifo"); | ||
606 | if (ret < 0) | ||
607 | goto failed; | ||
608 | /* enable fifo tx ack */ | ||
609 | ret = softing_fct_cmd(card, 13, "fifo_tx_ack[0]"); | ||
610 | if (ret < 0) | ||
611 | goto failed; | ||
612 | /* enable fifo tx ack2 */ | ||
613 | ret = softing_fct_cmd(card, 14, "fifo_tx_ack[1]"); | ||
614 | if (ret < 0) | ||
615 | goto failed; | ||
616 | /* start_chip */ | ||
617 | ret = softing_fct_cmd(card, 11, "start_chip"); | ||
618 | if (ret < 0) | ||
619 | goto failed; | ||
620 | iowrite8(0, &card->dpram[DPRAM_INFO_BUSSTATE]); | ||
621 | iowrite8(0, &card->dpram[DPRAM_INFO_BUSSTATE2]); | ||
622 | if (card->pdat->generation < 2) { | ||
623 | iowrite8(0, &card->dpram[DPRAM_V2_IRQ_TOHOST]); | ||
624 | /* flush the DPRAM caches */ | ||
625 | wmb(); | ||
626 | } | ||
627 | |||
628 | softing_initialize_timestamp(card); | ||
629 | |||
630 | /* | ||
631 | * do socketcan notifications/status changes | ||
632 | * from here, no errors should occur, or the failed: part | ||
633 | * must be reviewed | ||
634 | */ | ||
635 | memset(&msg, 0, sizeof(msg)); | ||
636 | msg.can_id = CAN_ERR_FLAG | CAN_ERR_RESTARTED; | ||
637 | msg.can_dlc = CAN_ERR_DLC; | ||
638 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
639 | if (!(bus_bitmask_start & (1 << j))) | ||
640 | continue; | ||
641 | netdev = card->net[j]; | ||
642 | if (!netdev) | ||
643 | continue; | ||
644 | priv = netdev_priv(netdev); | ||
645 | priv->can.state = CAN_STATE_ERROR_ACTIVE; | ||
646 | open_candev(netdev); | ||
647 | if (dev != netdev) { | ||
648 | /* notify other busses on the restart */ | ||
649 | softing_netdev_rx(netdev, &msg, ktime_set(0, 0)); | ||
650 | ++priv->can.can_stats.restarts; | ||
651 | } | ||
652 | netif_wake_queue(netdev); | ||
653 | } | ||
654 | |||
655 | /* enable interrupts */ | ||
656 | ret = softing_enable_irq(card, 1); | ||
657 | if (ret) | ||
658 | goto failed; | ||
659 | card_done: | ||
660 | mutex_unlock(&card->fw.lock); | ||
661 | return 0; | ||
662 | invalid: | ||
663 | ret = -EINVAL; | ||
664 | failed: | ||
665 | softing_enable_irq(card, 0); | ||
666 | softing_reset_chip(card); | ||
667 | mutex_unlock(&card->fw.lock); | ||
668 | /* bring all other interfaces down */ | ||
669 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
670 | netdev = card->net[j]; | ||
671 | if (!netdev) | ||
672 | continue; | ||
673 | dev_close(netdev); | ||
674 | } | ||
675 | return ret; | ||
676 | } | ||
677 | |||
678 | int softing_default_output(struct net_device *netdev) | ||
679 | { | ||
680 | struct softing_priv *priv = netdev_priv(netdev); | ||
681 | struct softing *card = priv->card; | ||
682 | |||
683 | switch (priv->chip) { | ||
684 | case 1000: | ||
685 | return (card->pdat->generation < 2) ? 0xfb : 0xfa; | ||
686 | case 5: | ||
687 | return 0x60; | ||
688 | default: | ||
689 | return 0x40; | ||
690 | } | ||
691 | } | ||
diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c new file mode 100644 index 000000000000..5157e15e96eb --- /dev/null +++ b/drivers/net/can/softing/softing_main.c | |||
@@ -0,0 +1,893 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008-2010 | ||
3 | * | ||
4 | * - Kurt Van Dijck, EIA Electronics | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the version 2 of the GNU General Public License | ||
8 | * as published by the Free Software Foundation | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/version.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | |||
25 | #include "softing.h" | ||
26 | |||
27 | #define TX_ECHO_SKB_MAX (((TXMAX+1)/2)-1) | ||
28 | |||
29 | /* | ||
30 | * test is a specific CAN netdev | ||
31 | * is online (ie. up 'n running, not sleeping, not busoff | ||
32 | */ | ||
33 | static inline int canif_is_active(struct net_device *netdev) | ||
34 | { | ||
35 | struct can_priv *can = netdev_priv(netdev); | ||
36 | |||
37 | if (!netif_running(netdev)) | ||
38 | return 0; | ||
39 | return (can->state <= CAN_STATE_ERROR_PASSIVE); | ||
40 | } | ||
41 | |||
42 | /* reset DPRAM */ | ||
43 | static inline void softing_set_reset_dpram(struct softing *card) | ||
44 | { | ||
45 | if (card->pdat->generation >= 2) { | ||
46 | spin_lock_bh(&card->spin); | ||
47 | iowrite8(ioread8(&card->dpram[DPRAM_V2_RESET]) & ~1, | ||
48 | &card->dpram[DPRAM_V2_RESET]); | ||
49 | spin_unlock_bh(&card->spin); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | static inline void softing_clr_reset_dpram(struct softing *card) | ||
54 | { | ||
55 | if (card->pdat->generation >= 2) { | ||
56 | spin_lock_bh(&card->spin); | ||
57 | iowrite8(ioread8(&card->dpram[DPRAM_V2_RESET]) | 1, | ||
58 | &card->dpram[DPRAM_V2_RESET]); | ||
59 | spin_unlock_bh(&card->spin); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | /* trigger the tx queue-ing */ | ||
64 | static netdev_tx_t softing_netdev_start_xmit(struct sk_buff *skb, | ||
65 | struct net_device *dev) | ||
66 | { | ||
67 | struct softing_priv *priv = netdev_priv(dev); | ||
68 | struct softing *card = priv->card; | ||
69 | int ret; | ||
70 | uint8_t *ptr; | ||
71 | uint8_t fifo_wr, fifo_rd; | ||
72 | struct can_frame *cf = (struct can_frame *)skb->data; | ||
73 | uint8_t buf[DPRAM_TX_SIZE]; | ||
74 | |||
75 | if (can_dropped_invalid_skb(dev, skb)) | ||
76 | return NETDEV_TX_OK; | ||
77 | |||
78 | spin_lock(&card->spin); | ||
79 | |||
80 | ret = NETDEV_TX_BUSY; | ||
81 | if (!card->fw.up || | ||
82 | (card->tx.pending >= TXMAX) || | ||
83 | (priv->tx.pending >= TX_ECHO_SKB_MAX)) | ||
84 | goto xmit_done; | ||
85 | fifo_wr = ioread8(&card->dpram[DPRAM_TX_WR]); | ||
86 | fifo_rd = ioread8(&card->dpram[DPRAM_TX_RD]); | ||
87 | if (fifo_wr == fifo_rd) | ||
88 | /* fifo full */ | ||
89 | goto xmit_done; | ||
90 | memset(buf, 0, sizeof(buf)); | ||
91 | ptr = buf; | ||
92 | *ptr = CMD_TX; | ||
93 | if (cf->can_id & CAN_RTR_FLAG) | ||
94 | *ptr |= CMD_RTR; | ||
95 | if (cf->can_id & CAN_EFF_FLAG) | ||
96 | *ptr |= CMD_XTD; | ||
97 | if (priv->index) | ||
98 | *ptr |= CMD_BUS2; | ||
99 | ++ptr; | ||
100 | *ptr++ = cf->can_dlc; | ||
101 | *ptr++ = (cf->can_id >> 0); | ||
102 | *ptr++ = (cf->can_id >> 8); | ||
103 | if (cf->can_id & CAN_EFF_FLAG) { | ||
104 | *ptr++ = (cf->can_id >> 16); | ||
105 | *ptr++ = (cf->can_id >> 24); | ||
106 | } else { | ||
107 | /* increment 1, not 2 as you might think */ | ||
108 | ptr += 1; | ||
109 | } | ||
110 | if (!(cf->can_id & CAN_RTR_FLAG)) | ||
111 | memcpy(ptr, &cf->data[0], cf->can_dlc); | ||
112 | memcpy_toio(&card->dpram[DPRAM_TX + DPRAM_TX_SIZE * fifo_wr], | ||
113 | buf, DPRAM_TX_SIZE); | ||
114 | if (++fifo_wr >= DPRAM_TX_CNT) | ||
115 | fifo_wr = 0; | ||
116 | iowrite8(fifo_wr, &card->dpram[DPRAM_TX_WR]); | ||
117 | card->tx.last_bus = priv->index; | ||
118 | ++card->tx.pending; | ||
119 | ++priv->tx.pending; | ||
120 | can_put_echo_skb(skb, dev, priv->tx.echo_put); | ||
121 | ++priv->tx.echo_put; | ||
122 | if (priv->tx.echo_put >= TX_ECHO_SKB_MAX) | ||
123 | priv->tx.echo_put = 0; | ||
124 | /* can_put_echo_skb() saves the skb, safe to return TX_OK */ | ||
125 | ret = NETDEV_TX_OK; | ||
126 | xmit_done: | ||
127 | spin_unlock(&card->spin); | ||
128 | if (card->tx.pending >= TXMAX) { | ||
129 | int j; | ||
130 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
131 | if (card->net[j]) | ||
132 | netif_stop_queue(card->net[j]); | ||
133 | } | ||
134 | } | ||
135 | if (ret != NETDEV_TX_OK) | ||
136 | netif_stop_queue(dev); | ||
137 | |||
138 | return ret; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * shortcut for skb delivery | ||
143 | */ | ||
144 | int softing_netdev_rx(struct net_device *netdev, const struct can_frame *msg, | ||
145 | ktime_t ktime) | ||
146 | { | ||
147 | struct sk_buff *skb; | ||
148 | struct can_frame *cf; | ||
149 | |||
150 | skb = alloc_can_skb(netdev, &cf); | ||
151 | if (!skb) | ||
152 | return -ENOMEM; | ||
153 | memcpy(cf, msg, sizeof(*msg)); | ||
154 | skb->tstamp = ktime; | ||
155 | return netif_rx(skb); | ||
156 | } | ||
157 | |||
158 | /* | ||
159 | * softing_handle_1 | ||
160 | * pop 1 entry from the DPRAM queue, and process | ||
161 | */ | ||
162 | static int softing_handle_1(struct softing *card) | ||
163 | { | ||
164 | struct net_device *netdev; | ||
165 | struct softing_priv *priv; | ||
166 | ktime_t ktime; | ||
167 | struct can_frame msg; | ||
168 | int cnt = 0, lost_msg; | ||
169 | uint8_t fifo_rd, fifo_wr, cmd; | ||
170 | uint8_t *ptr; | ||
171 | uint32_t tmp_u32; | ||
172 | uint8_t buf[DPRAM_RX_SIZE]; | ||
173 | |||
174 | memset(&msg, 0, sizeof(msg)); | ||
175 | /* test for lost msgs */ | ||
176 | lost_msg = ioread8(&card->dpram[DPRAM_RX_LOST]); | ||
177 | if (lost_msg) { | ||
178 | int j; | ||
179 | /* reset condition */ | ||
180 | iowrite8(0, &card->dpram[DPRAM_RX_LOST]); | ||
181 | /* prepare msg */ | ||
182 | msg.can_id = CAN_ERR_FLAG | CAN_ERR_CRTL; | ||
183 | msg.can_dlc = CAN_ERR_DLC; | ||
184 | msg.data[1] = CAN_ERR_CRTL_RX_OVERFLOW; | ||
185 | /* | ||
186 | * service to all busses, we don't know which it was applicable | ||
187 | * but only service busses that are online | ||
188 | */ | ||
189 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
190 | netdev = card->net[j]; | ||
191 | if (!netdev) | ||
192 | continue; | ||
193 | if (!canif_is_active(netdev)) | ||
194 | /* a dead bus has no overflows */ | ||
195 | continue; | ||
196 | ++netdev->stats.rx_over_errors; | ||
197 | softing_netdev_rx(netdev, &msg, ktime_set(0, 0)); | ||
198 | } | ||
199 | /* prepare for other use */ | ||
200 | memset(&msg, 0, sizeof(msg)); | ||
201 | ++cnt; | ||
202 | } | ||
203 | |||
204 | fifo_rd = ioread8(&card->dpram[DPRAM_RX_RD]); | ||
205 | fifo_wr = ioread8(&card->dpram[DPRAM_RX_WR]); | ||
206 | |||
207 | if (++fifo_rd >= DPRAM_RX_CNT) | ||
208 | fifo_rd = 0; | ||
209 | if (fifo_wr == fifo_rd) | ||
210 | return cnt; | ||
211 | |||
212 | memcpy_fromio(buf, &card->dpram[DPRAM_RX + DPRAM_RX_SIZE*fifo_rd], | ||
213 | DPRAM_RX_SIZE); | ||
214 | mb(); | ||
215 | /* trigger dual port RAM */ | ||
216 | iowrite8(fifo_rd, &card->dpram[DPRAM_RX_RD]); | ||
217 | |||
218 | ptr = buf; | ||
219 | cmd = *ptr++; | ||
220 | if (cmd == 0xff) | ||
221 | /* not quite usefull, probably the card has got out */ | ||
222 | return 0; | ||
223 | netdev = card->net[0]; | ||
224 | if (cmd & CMD_BUS2) | ||
225 | netdev = card->net[1]; | ||
226 | priv = netdev_priv(netdev); | ||
227 | |||
228 | if (cmd & CMD_ERR) { | ||
229 | uint8_t can_state, state; | ||
230 | |||
231 | state = *ptr++; | ||
232 | |||
233 | msg.can_id = CAN_ERR_FLAG; | ||
234 | msg.can_dlc = CAN_ERR_DLC; | ||
235 | |||
236 | if (state & SF_MASK_BUSOFF) { | ||
237 | can_state = CAN_STATE_BUS_OFF; | ||
238 | msg.can_id |= CAN_ERR_BUSOFF; | ||
239 | state = STATE_BUSOFF; | ||
240 | } else if (state & SF_MASK_EPASSIVE) { | ||
241 | can_state = CAN_STATE_ERROR_PASSIVE; | ||
242 | msg.can_id |= CAN_ERR_CRTL; | ||
243 | msg.data[1] = CAN_ERR_CRTL_TX_PASSIVE; | ||
244 | state = STATE_EPASSIVE; | ||
245 | } else { | ||
246 | can_state = CAN_STATE_ERROR_ACTIVE; | ||
247 | msg.can_id |= CAN_ERR_CRTL; | ||
248 | state = STATE_EACTIVE; | ||
249 | } | ||
250 | /* update DPRAM */ | ||
251 | iowrite8(state, &card->dpram[priv->index ? | ||
252 | DPRAM_INFO_BUSSTATE2 : DPRAM_INFO_BUSSTATE]); | ||
253 | /* timestamp */ | ||
254 | tmp_u32 = le32_to_cpup((void *)ptr); | ||
255 | ptr += 4; | ||
256 | ktime = softing_raw2ktime(card, tmp_u32); | ||
257 | |||
258 | ++netdev->stats.rx_errors; | ||
259 | /* update internal status */ | ||
260 | if (can_state != priv->can.state) { | ||
261 | priv->can.state = can_state; | ||
262 | if (can_state == CAN_STATE_ERROR_PASSIVE) | ||
263 | ++priv->can.can_stats.error_passive; | ||
264 | else if (can_state == CAN_STATE_BUS_OFF) { | ||
265 | /* this calls can_close_cleanup() */ | ||
266 | can_bus_off(netdev); | ||
267 | netif_stop_queue(netdev); | ||
268 | } | ||
269 | /* trigger socketcan */ | ||
270 | softing_netdev_rx(netdev, &msg, ktime); | ||
271 | } | ||
272 | |||
273 | } else { | ||
274 | if (cmd & CMD_RTR) | ||
275 | msg.can_id |= CAN_RTR_FLAG; | ||
276 | msg.can_dlc = get_can_dlc(*ptr++); | ||
277 | if (cmd & CMD_XTD) { | ||
278 | msg.can_id |= CAN_EFF_FLAG; | ||
279 | msg.can_id |= le32_to_cpup((void *)ptr); | ||
280 | ptr += 4; | ||
281 | } else { | ||
282 | msg.can_id |= le16_to_cpup((void *)ptr); | ||
283 | ptr += 2; | ||
284 | } | ||
285 | /* timestamp */ | ||
286 | tmp_u32 = le32_to_cpup((void *)ptr); | ||
287 | ptr += 4; | ||
288 | ktime = softing_raw2ktime(card, tmp_u32); | ||
289 | if (!(msg.can_id & CAN_RTR_FLAG)) | ||
290 | memcpy(&msg.data[0], ptr, 8); | ||
291 | ptr += 8; | ||
292 | /* update socket */ | ||
293 | if (cmd & CMD_ACK) { | ||
294 | /* acknowledge, was tx msg */ | ||
295 | struct sk_buff *skb; | ||
296 | skb = priv->can.echo_skb[priv->tx.echo_get]; | ||
297 | if (skb) | ||
298 | skb->tstamp = ktime; | ||
299 | can_get_echo_skb(netdev, priv->tx.echo_get); | ||
300 | ++priv->tx.echo_get; | ||
301 | if (priv->tx.echo_get >= TX_ECHO_SKB_MAX) | ||
302 | priv->tx.echo_get = 0; | ||
303 | if (priv->tx.pending) | ||
304 | --priv->tx.pending; | ||
305 | if (card->tx.pending) | ||
306 | --card->tx.pending; | ||
307 | ++netdev->stats.tx_packets; | ||
308 | if (!(msg.can_id & CAN_RTR_FLAG)) | ||
309 | netdev->stats.tx_bytes += msg.can_dlc; | ||
310 | } else { | ||
311 | int ret; | ||
312 | |||
313 | ret = softing_netdev_rx(netdev, &msg, ktime); | ||
314 | if (ret == NET_RX_SUCCESS) { | ||
315 | ++netdev->stats.rx_packets; | ||
316 | if (!(msg.can_id & CAN_RTR_FLAG)) | ||
317 | netdev->stats.rx_bytes += msg.can_dlc; | ||
318 | } else { | ||
319 | ++netdev->stats.rx_dropped; | ||
320 | } | ||
321 | } | ||
322 | } | ||
323 | ++cnt; | ||
324 | return cnt; | ||
325 | } | ||
326 | |||
327 | /* | ||
328 | * real interrupt handler | ||
329 | */ | ||
330 | static irqreturn_t softing_irq_thread(int irq, void *dev_id) | ||
331 | { | ||
332 | struct softing *card = (struct softing *)dev_id; | ||
333 | struct net_device *netdev; | ||
334 | struct softing_priv *priv; | ||
335 | int j, offset, work_done; | ||
336 | |||
337 | work_done = 0; | ||
338 | spin_lock_bh(&card->spin); | ||
339 | while (softing_handle_1(card) > 0) { | ||
340 | ++card->irq.svc_count; | ||
341 | ++work_done; | ||
342 | } | ||
343 | spin_unlock_bh(&card->spin); | ||
344 | /* resume tx queue's */ | ||
345 | offset = card->tx.last_bus; | ||
346 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
347 | if (card->tx.pending >= TXMAX) | ||
348 | break; | ||
349 | netdev = card->net[(j + offset + 1) % card->pdat->nbus]; | ||
350 | if (!netdev) | ||
351 | continue; | ||
352 | priv = netdev_priv(netdev); | ||
353 | if (!canif_is_active(netdev)) | ||
354 | /* it makes no sense to wake dead busses */ | ||
355 | continue; | ||
356 | if (priv->tx.pending >= TX_ECHO_SKB_MAX) | ||
357 | continue; | ||
358 | ++work_done; | ||
359 | netif_wake_queue(netdev); | ||
360 | } | ||
361 | return work_done ? IRQ_HANDLED : IRQ_NONE; | ||
362 | } | ||
363 | |||
364 | /* | ||
365 | * interrupt routines: | ||
366 | * schedule the 'real interrupt handler' | ||
367 | */ | ||
368 | static irqreturn_t softing_irq_v2(int irq, void *dev_id) | ||
369 | { | ||
370 | struct softing *card = (struct softing *)dev_id; | ||
371 | uint8_t ir; | ||
372 | |||
373 | ir = ioread8(&card->dpram[DPRAM_V2_IRQ_TOHOST]); | ||
374 | iowrite8(0, &card->dpram[DPRAM_V2_IRQ_TOHOST]); | ||
375 | return (1 == ir) ? IRQ_WAKE_THREAD : IRQ_NONE; | ||
376 | } | ||
377 | |||
378 | static irqreturn_t softing_irq_v1(int irq, void *dev_id) | ||
379 | { | ||
380 | struct softing *card = (struct softing *)dev_id; | ||
381 | uint8_t ir; | ||
382 | |||
383 | ir = ioread8(&card->dpram[DPRAM_IRQ_TOHOST]); | ||
384 | iowrite8(0, &card->dpram[DPRAM_IRQ_TOHOST]); | ||
385 | return ir ? IRQ_WAKE_THREAD : IRQ_NONE; | ||
386 | } | ||
387 | |||
388 | /* | ||
389 | * netdev/candev inter-operability | ||
390 | */ | ||
391 | static int softing_netdev_open(struct net_device *ndev) | ||
392 | { | ||
393 | int ret; | ||
394 | |||
395 | /* check or determine and set bittime */ | ||
396 | ret = open_candev(ndev); | ||
397 | if (!ret) | ||
398 | ret = softing_startstop(ndev, 1); | ||
399 | return ret; | ||
400 | } | ||
401 | |||
402 | static int softing_netdev_stop(struct net_device *ndev) | ||
403 | { | ||
404 | int ret; | ||
405 | |||
406 | netif_stop_queue(ndev); | ||
407 | |||
408 | /* softing cycle does close_candev() */ | ||
409 | ret = softing_startstop(ndev, 0); | ||
410 | return ret; | ||
411 | } | ||
412 | |||
413 | static int softing_candev_set_mode(struct net_device *ndev, enum can_mode mode) | ||
414 | { | ||
415 | int ret; | ||
416 | |||
417 | switch (mode) { | ||
418 | case CAN_MODE_START: | ||
419 | /* softing_startstop does close_candev() */ | ||
420 | ret = softing_startstop(ndev, 1); | ||
421 | return ret; | ||
422 | case CAN_MODE_STOP: | ||
423 | case CAN_MODE_SLEEP: | ||
424 | return -EOPNOTSUPP; | ||
425 | } | ||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | /* | ||
430 | * Softing device management helpers | ||
431 | */ | ||
432 | int softing_enable_irq(struct softing *card, int enable) | ||
433 | { | ||
434 | int ret; | ||
435 | |||
436 | if (!card->irq.nr) { | ||
437 | return 0; | ||
438 | } else if (card->irq.requested && !enable) { | ||
439 | free_irq(card->irq.nr, card); | ||
440 | card->irq.requested = 0; | ||
441 | } else if (!card->irq.requested && enable) { | ||
442 | ret = request_threaded_irq(card->irq.nr, | ||
443 | (card->pdat->generation >= 2) ? | ||
444 | softing_irq_v2 : softing_irq_v1, | ||
445 | softing_irq_thread, IRQF_SHARED, | ||
446 | dev_name(&card->pdev->dev), card); | ||
447 | if (ret) { | ||
448 | dev_alert(&card->pdev->dev, | ||
449 | "request_threaded_irq(%u) failed\n", | ||
450 | card->irq.nr); | ||
451 | return ret; | ||
452 | } | ||
453 | card->irq.requested = 1; | ||
454 | } | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static void softing_card_shutdown(struct softing *card) | ||
459 | { | ||
460 | int fw_up = 0; | ||
461 | |||
462 | if (mutex_lock_interruptible(&card->fw.lock)) | ||
463 | /* return -ERESTARTSYS */; | ||
464 | fw_up = card->fw.up; | ||
465 | card->fw.up = 0; | ||
466 | |||
467 | if (card->irq.requested && card->irq.nr) { | ||
468 | free_irq(card->irq.nr, card); | ||
469 | card->irq.requested = 0; | ||
470 | } | ||
471 | if (fw_up) { | ||
472 | if (card->pdat->enable_irq) | ||
473 | card->pdat->enable_irq(card->pdev, 0); | ||
474 | softing_set_reset_dpram(card); | ||
475 | if (card->pdat->reset) | ||
476 | card->pdat->reset(card->pdev, 1); | ||
477 | } | ||
478 | mutex_unlock(&card->fw.lock); | ||
479 | } | ||
480 | |||
481 | static __devinit int softing_card_boot(struct softing *card) | ||
482 | { | ||
483 | int ret, j; | ||
484 | static const uint8_t stream[] = { | ||
485 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, }; | ||
486 | unsigned char back[sizeof(stream)]; | ||
487 | |||
488 | if (mutex_lock_interruptible(&card->fw.lock)) | ||
489 | return -ERESTARTSYS; | ||
490 | if (card->fw.up) { | ||
491 | mutex_unlock(&card->fw.lock); | ||
492 | return 0; | ||
493 | } | ||
494 | /* reset board */ | ||
495 | if (card->pdat->enable_irq) | ||
496 | card->pdat->enable_irq(card->pdev, 1); | ||
497 | /* boot card */ | ||
498 | softing_set_reset_dpram(card); | ||
499 | if (card->pdat->reset) | ||
500 | card->pdat->reset(card->pdev, 1); | ||
501 | for (j = 0; (j + sizeof(stream)) < card->dpram_size; | ||
502 | j += sizeof(stream)) { | ||
503 | |||
504 | memcpy_toio(&card->dpram[j], stream, sizeof(stream)); | ||
505 | /* flush IO cache */ | ||
506 | mb(); | ||
507 | memcpy_fromio(back, &card->dpram[j], sizeof(stream)); | ||
508 | |||
509 | if (!memcmp(back, stream, sizeof(stream))) | ||
510 | continue; | ||
511 | /* memory is not equal */ | ||
512 | dev_alert(&card->pdev->dev, "dpram failed at 0x%04x\n", j); | ||
513 | ret = -EIO; | ||
514 | goto failed; | ||
515 | } | ||
516 | wmb(); | ||
517 | /* load boot firmware */ | ||
518 | ret = softing_load_fw(card->pdat->boot.fw, card, card->dpram, | ||
519 | card->dpram_size, | ||
520 | card->pdat->boot.offs - card->pdat->boot.addr); | ||
521 | if (ret < 0) | ||
522 | goto failed; | ||
523 | /* load loader firmware */ | ||
524 | ret = softing_load_fw(card->pdat->load.fw, card, card->dpram, | ||
525 | card->dpram_size, | ||
526 | card->pdat->load.offs - card->pdat->load.addr); | ||
527 | if (ret < 0) | ||
528 | goto failed; | ||
529 | |||
530 | if (card->pdat->reset) | ||
531 | card->pdat->reset(card->pdev, 0); | ||
532 | softing_clr_reset_dpram(card); | ||
533 | ret = softing_bootloader_command(card, 0, "card boot"); | ||
534 | if (ret < 0) | ||
535 | goto failed; | ||
536 | ret = softing_load_app_fw(card->pdat->app.fw, card); | ||
537 | if (ret < 0) | ||
538 | goto failed; | ||
539 | |||
540 | ret = softing_chip_poweron(card); | ||
541 | if (ret < 0) | ||
542 | goto failed; | ||
543 | |||
544 | card->fw.up = 1; | ||
545 | mutex_unlock(&card->fw.lock); | ||
546 | return 0; | ||
547 | failed: | ||
548 | card->fw.up = 0; | ||
549 | if (card->pdat->enable_irq) | ||
550 | card->pdat->enable_irq(card->pdev, 0); | ||
551 | softing_set_reset_dpram(card); | ||
552 | if (card->pdat->reset) | ||
553 | card->pdat->reset(card->pdev, 1); | ||
554 | mutex_unlock(&card->fw.lock); | ||
555 | return ret; | ||
556 | } | ||
557 | |||
558 | /* | ||
559 | * netdev sysfs | ||
560 | */ | ||
561 | static ssize_t show_channel(struct device *dev, struct device_attribute *attr, | ||
562 | char *buf) | ||
563 | { | ||
564 | struct net_device *ndev = to_net_dev(dev); | ||
565 | struct softing_priv *priv = netdev2softing(ndev); | ||
566 | |||
567 | return sprintf(buf, "%i\n", priv->index); | ||
568 | } | ||
569 | |||
570 | static ssize_t show_chip(struct device *dev, struct device_attribute *attr, | ||
571 | char *buf) | ||
572 | { | ||
573 | struct net_device *ndev = to_net_dev(dev); | ||
574 | struct softing_priv *priv = netdev2softing(ndev); | ||
575 | |||
576 | return sprintf(buf, "%i\n", priv->chip); | ||
577 | } | ||
578 | |||
579 | static ssize_t show_output(struct device *dev, struct device_attribute *attr, | ||
580 | char *buf) | ||
581 | { | ||
582 | struct net_device *ndev = to_net_dev(dev); | ||
583 | struct softing_priv *priv = netdev2softing(ndev); | ||
584 | |||
585 | return sprintf(buf, "0x%02x\n", priv->output); | ||
586 | } | ||
587 | |||
588 | static ssize_t store_output(struct device *dev, struct device_attribute *attr, | ||
589 | const char *buf, size_t count) | ||
590 | { | ||
591 | struct net_device *ndev = to_net_dev(dev); | ||
592 | struct softing_priv *priv = netdev2softing(ndev); | ||
593 | struct softing *card = priv->card; | ||
594 | unsigned long val; | ||
595 | int ret; | ||
596 | |||
597 | ret = strict_strtoul(buf, 0, &val); | ||
598 | if (ret < 0) | ||
599 | return ret; | ||
600 | val &= 0xFF; | ||
601 | |||
602 | ret = mutex_lock_interruptible(&card->fw.lock); | ||
603 | if (ret) | ||
604 | return -ERESTARTSYS; | ||
605 | if (netif_running(ndev)) { | ||
606 | mutex_unlock(&card->fw.lock); | ||
607 | return -EBUSY; | ||
608 | } | ||
609 | priv->output = val; | ||
610 | mutex_unlock(&card->fw.lock); | ||
611 | return count; | ||
612 | } | ||
613 | |||
614 | static const DEVICE_ATTR(channel, S_IRUGO, show_channel, NULL); | ||
615 | static const DEVICE_ATTR(chip, S_IRUGO, show_chip, NULL); | ||
616 | static const DEVICE_ATTR(output, S_IRUGO | S_IWUSR, show_output, store_output); | ||
617 | |||
618 | static const struct attribute *const netdev_sysfs_attrs[] = { | ||
619 | &dev_attr_channel.attr, | ||
620 | &dev_attr_chip.attr, | ||
621 | &dev_attr_output.attr, | ||
622 | NULL, | ||
623 | }; | ||
624 | static const struct attribute_group netdev_sysfs_group = { | ||
625 | .name = NULL, | ||
626 | .attrs = (struct attribute **)netdev_sysfs_attrs, | ||
627 | }; | ||
628 | |||
629 | static const struct net_device_ops softing_netdev_ops = { | ||
630 | .ndo_open = softing_netdev_open, | ||
631 | .ndo_stop = softing_netdev_stop, | ||
632 | .ndo_start_xmit = softing_netdev_start_xmit, | ||
633 | }; | ||
634 | |||
635 | static const struct can_bittiming_const softing_btr_const = { | ||
636 | .tseg1_min = 1, | ||
637 | .tseg1_max = 16, | ||
638 | .tseg2_min = 1, | ||
639 | .tseg2_max = 8, | ||
640 | .sjw_max = 4, /* overruled */ | ||
641 | .brp_min = 1, | ||
642 | .brp_max = 32, /* overruled */ | ||
643 | .brp_inc = 1, | ||
644 | }; | ||
645 | |||
646 | |||
647 | static __devinit struct net_device *softing_netdev_create(struct softing *card, | ||
648 | uint16_t chip_id) | ||
649 | { | ||
650 | struct net_device *netdev; | ||
651 | struct softing_priv *priv; | ||
652 | |||
653 | netdev = alloc_candev(sizeof(*priv), TX_ECHO_SKB_MAX); | ||
654 | if (!netdev) { | ||
655 | dev_alert(&card->pdev->dev, "alloc_candev failed\n"); | ||
656 | return NULL; | ||
657 | } | ||
658 | priv = netdev_priv(netdev); | ||
659 | priv->netdev = netdev; | ||
660 | priv->card = card; | ||
661 | memcpy(&priv->btr_const, &softing_btr_const, sizeof(priv->btr_const)); | ||
662 | priv->btr_const.brp_max = card->pdat->max_brp; | ||
663 | priv->btr_const.sjw_max = card->pdat->max_sjw; | ||
664 | priv->can.bittiming_const = &priv->btr_const; | ||
665 | priv->can.clock.freq = 8000000; | ||
666 | priv->chip = chip_id; | ||
667 | priv->output = softing_default_output(netdev); | ||
668 | SET_NETDEV_DEV(netdev, &card->pdev->dev); | ||
669 | |||
670 | netdev->flags |= IFF_ECHO; | ||
671 | netdev->netdev_ops = &softing_netdev_ops; | ||
672 | priv->can.do_set_mode = softing_candev_set_mode; | ||
673 | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; | ||
674 | |||
675 | return netdev; | ||
676 | } | ||
677 | |||
678 | static __devinit int softing_netdev_register(struct net_device *netdev) | ||
679 | { | ||
680 | int ret; | ||
681 | |||
682 | netdev->sysfs_groups[0] = &netdev_sysfs_group; | ||
683 | ret = register_candev(netdev); | ||
684 | if (ret) { | ||
685 | dev_alert(&netdev->dev, "register failed\n"); | ||
686 | return ret; | ||
687 | } | ||
688 | return 0; | ||
689 | } | ||
690 | |||
691 | static void softing_netdev_cleanup(struct net_device *netdev) | ||
692 | { | ||
693 | unregister_candev(netdev); | ||
694 | free_candev(netdev); | ||
695 | } | ||
696 | |||
697 | /* | ||
698 | * sysfs for Platform device | ||
699 | */ | ||
700 | #define DEV_ATTR_RO(name, member) \ | ||
701 | static ssize_t show_##name(struct device *dev, \ | ||
702 | struct device_attribute *attr, char *buf) \ | ||
703 | { \ | ||
704 | struct softing *card = platform_get_drvdata(to_platform_device(dev)); \ | ||
705 | return sprintf(buf, "%u\n", card->member); \ | ||
706 | } \ | ||
707 | static DEVICE_ATTR(name, 0444, show_##name, NULL) | ||
708 | |||
709 | #define DEV_ATTR_RO_STR(name, member) \ | ||
710 | static ssize_t show_##name(struct device *dev, \ | ||
711 | struct device_attribute *attr, char *buf) \ | ||
712 | { \ | ||
713 | struct softing *card = platform_get_drvdata(to_platform_device(dev)); \ | ||
714 | return sprintf(buf, "%s\n", card->member); \ | ||
715 | } \ | ||
716 | static DEVICE_ATTR(name, 0444, show_##name, NULL) | ||
717 | |||
718 | DEV_ATTR_RO(serial, id.serial); | ||
719 | DEV_ATTR_RO_STR(firmware, pdat->app.fw); | ||
720 | DEV_ATTR_RO(firmware_version, id.fw_version); | ||
721 | DEV_ATTR_RO_STR(hardware, pdat->name); | ||
722 | DEV_ATTR_RO(hardware_version, id.hw_version); | ||
723 | DEV_ATTR_RO(license, id.license); | ||
724 | DEV_ATTR_RO(frequency, id.freq); | ||
725 | DEV_ATTR_RO(txpending, tx.pending); | ||
726 | |||
727 | static struct attribute *softing_pdev_attrs[] = { | ||
728 | &dev_attr_serial.attr, | ||
729 | &dev_attr_firmware.attr, | ||
730 | &dev_attr_firmware_version.attr, | ||
731 | &dev_attr_hardware.attr, | ||
732 | &dev_attr_hardware_version.attr, | ||
733 | &dev_attr_license.attr, | ||
734 | &dev_attr_frequency.attr, | ||
735 | &dev_attr_txpending.attr, | ||
736 | NULL, | ||
737 | }; | ||
738 | |||
739 | static const struct attribute_group softing_pdev_group = { | ||
740 | .name = NULL, | ||
741 | .attrs = softing_pdev_attrs, | ||
742 | }; | ||
743 | |||
744 | /* | ||
745 | * platform driver | ||
746 | */ | ||
747 | static __devexit int softing_pdev_remove(struct platform_device *pdev) | ||
748 | { | ||
749 | struct softing *card = platform_get_drvdata(pdev); | ||
750 | int j; | ||
751 | |||
752 | /* first, disable card*/ | ||
753 | softing_card_shutdown(card); | ||
754 | |||
755 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
756 | if (!card->net[j]) | ||
757 | continue; | ||
758 | softing_netdev_cleanup(card->net[j]); | ||
759 | card->net[j] = NULL; | ||
760 | } | ||
761 | sysfs_remove_group(&pdev->dev.kobj, &softing_pdev_group); | ||
762 | |||
763 | iounmap(card->dpram); | ||
764 | kfree(card); | ||
765 | return 0; | ||
766 | } | ||
767 | |||
768 | static __devinit int softing_pdev_probe(struct platform_device *pdev) | ||
769 | { | ||
770 | const struct softing_platform_data *pdat = pdev->dev.platform_data; | ||
771 | struct softing *card; | ||
772 | struct net_device *netdev; | ||
773 | struct softing_priv *priv; | ||
774 | struct resource *pres; | ||
775 | int ret; | ||
776 | int j; | ||
777 | |||
778 | if (!pdat) { | ||
779 | dev_warn(&pdev->dev, "no platform data\n"); | ||
780 | return -EINVAL; | ||
781 | } | ||
782 | if (pdat->nbus > ARRAY_SIZE(card->net)) { | ||
783 | dev_warn(&pdev->dev, "%u nets??\n", pdat->nbus); | ||
784 | return -EINVAL; | ||
785 | } | ||
786 | |||
787 | card = kzalloc(sizeof(*card), GFP_KERNEL); | ||
788 | if (!card) | ||
789 | return -ENOMEM; | ||
790 | card->pdat = pdat; | ||
791 | card->pdev = pdev; | ||
792 | platform_set_drvdata(pdev, card); | ||
793 | mutex_init(&card->fw.lock); | ||
794 | spin_lock_init(&card->spin); | ||
795 | |||
796 | ret = -EINVAL; | ||
797 | pres = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
798 | if (!pres) | ||
799 | goto platform_resource_failed;; | ||
800 | card->dpram_phys = pres->start; | ||
801 | card->dpram_size = pres->end - pres->start + 1; | ||
802 | card->dpram = ioremap_nocache(card->dpram_phys, card->dpram_size); | ||
803 | if (!card->dpram) { | ||
804 | dev_alert(&card->pdev->dev, "dpram ioremap failed\n"); | ||
805 | goto ioremap_failed; | ||
806 | } | ||
807 | |||
808 | pres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
809 | if (pres) | ||
810 | card->irq.nr = pres->start; | ||
811 | |||
812 | /* reset card */ | ||
813 | ret = softing_card_boot(card); | ||
814 | if (ret < 0) { | ||
815 | dev_alert(&pdev->dev, "failed to boot\n"); | ||
816 | goto boot_failed; | ||
817 | } | ||
818 | |||
819 | /* only now, the chip's are known */ | ||
820 | card->id.freq = card->pdat->freq; | ||
821 | |||
822 | ret = sysfs_create_group(&pdev->dev.kobj, &softing_pdev_group); | ||
823 | if (ret < 0) { | ||
824 | dev_alert(&card->pdev->dev, "sysfs failed\n"); | ||
825 | goto sysfs_failed; | ||
826 | } | ||
827 | |||
828 | ret = -ENOMEM; | ||
829 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
830 | card->net[j] = netdev = | ||
831 | softing_netdev_create(card, card->id.chip[j]); | ||
832 | if (!netdev) { | ||
833 | dev_alert(&pdev->dev, "failed to make can[%i]", j); | ||
834 | goto netdev_failed; | ||
835 | } | ||
836 | priv = netdev_priv(card->net[j]); | ||
837 | priv->index = j; | ||
838 | ret = softing_netdev_register(netdev); | ||
839 | if (ret) { | ||
840 | free_candev(netdev); | ||
841 | card->net[j] = NULL; | ||
842 | dev_alert(&card->pdev->dev, | ||
843 | "failed to register can[%i]\n", j); | ||
844 | goto netdev_failed; | ||
845 | } | ||
846 | } | ||
847 | dev_info(&card->pdev->dev, "%s ready.\n", card->pdat->name); | ||
848 | return 0; | ||
849 | |||
850 | netdev_failed: | ||
851 | for (j = 0; j < ARRAY_SIZE(card->net); ++j) { | ||
852 | if (!card->net[j]) | ||
853 | continue; | ||
854 | softing_netdev_cleanup(card->net[j]); | ||
855 | } | ||
856 | sysfs_remove_group(&pdev->dev.kobj, &softing_pdev_group); | ||
857 | sysfs_failed: | ||
858 | softing_card_shutdown(card); | ||
859 | boot_failed: | ||
860 | iounmap(card->dpram); | ||
861 | ioremap_failed: | ||
862 | platform_resource_failed: | ||
863 | kfree(card); | ||
864 | return ret; | ||
865 | } | ||
866 | |||
867 | static struct platform_driver softing_driver = { | ||
868 | .driver = { | ||
869 | .name = "softing", | ||
870 | .owner = THIS_MODULE, | ||
871 | }, | ||
872 | .probe = softing_pdev_probe, | ||
873 | .remove = __devexit_p(softing_pdev_remove), | ||
874 | }; | ||
875 | |||
876 | MODULE_ALIAS("platform:softing"); | ||
877 | |||
878 | static int __init softing_start(void) | ||
879 | { | ||
880 | return platform_driver_register(&softing_driver); | ||
881 | } | ||
882 | |||
883 | static void __exit softing_stop(void) | ||
884 | { | ||
885 | platform_driver_unregister(&softing_driver); | ||
886 | } | ||
887 | |||
888 | module_init(softing_start); | ||
889 | module_exit(softing_stop); | ||
890 | |||
891 | MODULE_DESCRIPTION("Softing DPRAM CAN driver"); | ||
892 | MODULE_AUTHOR("Kurt Van Dijck <kurt.van.dijck@eia.be>"); | ||
893 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/net/can/softing/softing_platform.h b/drivers/net/can/softing/softing_platform.h new file mode 100644 index 000000000000..ebbf69815623 --- /dev/null +++ b/drivers/net/can/softing/softing_platform.h | |||
@@ -0,0 +1,40 @@ | |||
1 | |||
2 | #include <linux/platform_device.h> | ||
3 | |||
4 | #ifndef _SOFTING_DEVICE_H_ | ||
5 | #define _SOFTING_DEVICE_H_ | ||
6 | |||
7 | /* softing firmware directory prefix */ | ||
8 | #define fw_dir "softing-4.6/" | ||
9 | |||
10 | struct softing_platform_data { | ||
11 | unsigned int manf; | ||
12 | unsigned int prod; | ||
13 | /* | ||
14 | * generation | ||
15 | * 1st with NEC or SJA1000 | ||
16 | * 8bit, exclusive interrupt, ... | ||
17 | * 2nd only SJA1000 | ||
18 | * 16bit, shared interrupt | ||
19 | */ | ||
20 | int generation; | ||
21 | int nbus; /* # busses on device */ | ||
22 | unsigned int freq; /* operating frequency in Hz */ | ||
23 | unsigned int max_brp; | ||
24 | unsigned int max_sjw; | ||
25 | unsigned long dpram_size; | ||
26 | const char *name; | ||
27 | struct { | ||
28 | unsigned long offs; | ||
29 | unsigned long addr; | ||
30 | const char *fw; | ||
31 | } boot, load, app; | ||
32 | /* | ||
33 | * reset() function | ||
34 | * bring pdev in or out of reset, depending on value | ||
35 | */ | ||
36 | int (*reset)(struct platform_device *pdev, int value); | ||
37 | int (*enable_irq)(struct platform_device *pdev, int value); | ||
38 | }; | ||
39 | |||
40 | #endif | ||
diff --git a/drivers/net/cnic.c b/drivers/net/cnic.c index 263a2944566f..7ff170cbc7dc 100644 --- a/drivers/net/cnic.c +++ b/drivers/net/cnic.c | |||
@@ -699,13 +699,13 @@ static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma) | |||
699 | static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma) | 699 | static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma) |
700 | { | 700 | { |
701 | int i; | 701 | int i; |
702 | u32 *page_table = dma->pgtbl; | 702 | __le32 *page_table = (__le32 *) dma->pgtbl; |
703 | 703 | ||
704 | for (i = 0; i < dma->num_pages; i++) { | 704 | for (i = 0; i < dma->num_pages; i++) { |
705 | /* Each entry needs to be in big endian format. */ | 705 | /* Each entry needs to be in big endian format. */ |
706 | *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32); | 706 | *page_table = cpu_to_le32((u64) dma->pg_map_arr[i] >> 32); |
707 | page_table++; | 707 | page_table++; |
708 | *page_table = (u32) dma->pg_map_arr[i]; | 708 | *page_table = cpu_to_le32(dma->pg_map_arr[i] & 0xffffffff); |
709 | page_table++; | 709 | page_table++; |
710 | } | 710 | } |
711 | } | 711 | } |
@@ -713,13 +713,13 @@ static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma) | |||
713 | static void cnic_setup_page_tbl_le(struct cnic_dev *dev, struct cnic_dma *dma) | 713 | static void cnic_setup_page_tbl_le(struct cnic_dev *dev, struct cnic_dma *dma) |
714 | { | 714 | { |
715 | int i; | 715 | int i; |
716 | u32 *page_table = dma->pgtbl; | 716 | __le32 *page_table = (__le32 *) dma->pgtbl; |
717 | 717 | ||
718 | for (i = 0; i < dma->num_pages; i++) { | 718 | for (i = 0; i < dma->num_pages; i++) { |
719 | /* Each entry needs to be in little endian format. */ | 719 | /* Each entry needs to be in little endian format. */ |
720 | *page_table = dma->pg_map_arr[i] & 0xffffffff; | 720 | *page_table = cpu_to_le32(dma->pg_map_arr[i] & 0xffffffff); |
721 | page_table++; | 721 | page_table++; |
722 | *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32); | 722 | *page_table = cpu_to_le32((u64) dma->pg_map_arr[i] >> 32); |
723 | page_table++; | 723 | page_table++; |
724 | } | 724 | } |
725 | } | 725 | } |
diff --git a/drivers/net/cxgb4/cxgb4_main.c b/drivers/net/cxgb4/cxgb4_main.c index 059c1eec8c3f..ec35d458102c 100644 --- a/drivers/net/cxgb4/cxgb4_main.c +++ b/drivers/net/cxgb4/cxgb4_main.c | |||
@@ -2710,6 +2710,8 @@ static int cxgb_open(struct net_device *dev) | |||
2710 | struct port_info *pi = netdev_priv(dev); | 2710 | struct port_info *pi = netdev_priv(dev); |
2711 | struct adapter *adapter = pi->adapter; | 2711 | struct adapter *adapter = pi->adapter; |
2712 | 2712 | ||
2713 | netif_carrier_off(dev); | ||
2714 | |||
2713 | if (!(adapter->flags & FULL_INIT_DONE)) { | 2715 | if (!(adapter->flags & FULL_INIT_DONE)) { |
2714 | err = cxgb_up(adapter); | 2716 | err = cxgb_up(adapter); |
2715 | if (err < 0) | 2717 | if (err < 0) |
@@ -3661,7 +3663,6 @@ static int __devinit init_one(struct pci_dev *pdev, | |||
3661 | pi->xact_addr_filt = -1; | 3663 | pi->xact_addr_filt = -1; |
3662 | pi->rx_offload = RX_CSO; | 3664 | pi->rx_offload = RX_CSO; |
3663 | pi->port_id = i; | 3665 | pi->port_id = i; |
3664 | netif_carrier_off(netdev); | ||
3665 | netdev->irq = pdev->irq; | 3666 | netdev->irq = pdev->irq; |
3666 | 3667 | ||
3667 | netdev->features |= NETIF_F_SG | TSO_FLAGS; | 3668 | netdev->features |= NETIF_F_SG | TSO_FLAGS; |
diff --git a/drivers/net/pch_gbe/pch_gbe_main.c b/drivers/net/pch_gbe/pch_gbe_main.c index d7355306a738..1bf12339441b 100644 --- a/drivers/net/pch_gbe/pch_gbe_main.c +++ b/drivers/net/pch_gbe/pch_gbe_main.c | |||
@@ -2247,7 +2247,7 @@ static void pch_gbe_remove(struct pci_dev *pdev) | |||
2247 | struct net_device *netdev = pci_get_drvdata(pdev); | 2247 | struct net_device *netdev = pci_get_drvdata(pdev); |
2248 | struct pch_gbe_adapter *adapter = netdev_priv(netdev); | 2248 | struct pch_gbe_adapter *adapter = netdev_priv(netdev); |
2249 | 2249 | ||
2250 | flush_scheduled_work(); | 2250 | cancel_work_sync(&adapter->reset_task); |
2251 | unregister_netdev(netdev); | 2251 | unregister_netdev(netdev); |
2252 | 2252 | ||
2253 | pch_gbe_hal_phy_hw_reset(&adapter->hw); | 2253 | pch_gbe_hal_phy_hw_reset(&adapter->hw); |
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 7841a8f69998..93b32d366611 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
@@ -60,12 +60,6 @@ | |||
60 | #define BAR_0 0 | 60 | #define BAR_0 0 |
61 | #define BAR_2 2 | 61 | #define BAR_2 2 |
62 | 62 | ||
63 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | ||
64 | #define TG3_VLAN_TAG_USED 1 | ||
65 | #else | ||
66 | #define TG3_VLAN_TAG_USED 0 | ||
67 | #endif | ||
68 | |||
69 | #include "tg3.h" | 63 | #include "tg3.h" |
70 | 64 | ||
71 | #define DRV_MODULE_NAME "tg3" | 65 | #define DRV_MODULE_NAME "tg3" |
@@ -134,9 +128,6 @@ | |||
134 | TG3_TX_RING_SIZE) | 128 | TG3_TX_RING_SIZE) |
135 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) | 129 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
136 | 130 | ||
137 | #define TG3_RX_DMA_ALIGN 16 | ||
138 | #define TG3_RX_HEADROOM ALIGN(VLAN_HLEN, TG3_RX_DMA_ALIGN) | ||
139 | |||
140 | #define TG3_DMA_BYTE_ENAB 64 | 131 | #define TG3_DMA_BYTE_ENAB 64 |
141 | 132 | ||
142 | #define TG3_RX_STD_DMA_SZ 1536 | 133 | #define TG3_RX_STD_DMA_SZ 1536 |
@@ -4722,8 +4713,6 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget) | |||
4722 | struct sk_buff *skb; | 4713 | struct sk_buff *skb; |
4723 | dma_addr_t dma_addr; | 4714 | dma_addr_t dma_addr; |
4724 | u32 opaque_key, desc_idx, *post_ptr; | 4715 | u32 opaque_key, desc_idx, *post_ptr; |
4725 | bool hw_vlan __maybe_unused = false; | ||
4726 | u16 vtag __maybe_unused = 0; | ||
4727 | 4716 | ||
4728 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | 4717 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
4729 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | 4718 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
@@ -4782,12 +4771,12 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget) | |||
4782 | tg3_recycle_rx(tnapi, tpr, opaque_key, | 4771 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
4783 | desc_idx, *post_ptr); | 4772 | desc_idx, *post_ptr); |
4784 | 4773 | ||
4785 | copy_skb = netdev_alloc_skb(tp->dev, len + VLAN_HLEN + | 4774 | copy_skb = netdev_alloc_skb(tp->dev, len + |
4786 | TG3_RAW_IP_ALIGN); | 4775 | TG3_RAW_IP_ALIGN); |
4787 | if (copy_skb == NULL) | 4776 | if (copy_skb == NULL) |
4788 | goto drop_it_no_recycle; | 4777 | goto drop_it_no_recycle; |
4789 | 4778 | ||
4790 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN + VLAN_HLEN); | 4779 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN); |
4791 | skb_put(copy_skb, len); | 4780 | skb_put(copy_skb, len); |
4792 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); | 4781 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
4793 | skb_copy_from_linear_data(skb, copy_skb->data, len); | 4782 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
@@ -4814,30 +4803,11 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget) | |||
4814 | } | 4803 | } |
4815 | 4804 | ||
4816 | if (desc->type_flags & RXD_FLAG_VLAN && | 4805 | if (desc->type_flags & RXD_FLAG_VLAN && |
4817 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) { | 4806 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
4818 | vtag = desc->err_vlan & RXD_VLAN_MASK; | 4807 | __vlan_hwaccel_put_tag(skb, |
4819 | #if TG3_VLAN_TAG_USED | 4808 | desc->err_vlan & RXD_VLAN_MASK); |
4820 | if (tp->vlgrp) | ||
4821 | hw_vlan = true; | ||
4822 | else | ||
4823 | #endif | ||
4824 | { | ||
4825 | struct vlan_ethhdr *ve = (struct vlan_ethhdr *) | ||
4826 | __skb_push(skb, VLAN_HLEN); | ||
4827 | |||
4828 | memmove(ve, skb->data + VLAN_HLEN, | ||
4829 | ETH_ALEN * 2); | ||
4830 | ve->h_vlan_proto = htons(ETH_P_8021Q); | ||
4831 | ve->h_vlan_TCI = htons(vtag); | ||
4832 | } | ||
4833 | } | ||
4834 | 4809 | ||
4835 | #if TG3_VLAN_TAG_USED | 4810 | napi_gro_receive(&tnapi->napi, skb); |
4836 | if (hw_vlan) | ||
4837 | vlan_gro_receive(&tnapi->napi, tp->vlgrp, vtag, skb); | ||
4838 | else | ||
4839 | #endif | ||
4840 | napi_gro_receive(&tnapi->napi, skb); | ||
4841 | 4811 | ||
4842 | received++; | 4812 | received++; |
4843 | budget--; | 4813 | budget--; |
@@ -5740,11 +5710,9 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, | |||
5740 | base_flags |= TXD_FLAG_TCPUDP_CSUM; | 5710 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
5741 | } | 5711 | } |
5742 | 5712 | ||
5743 | #if TG3_VLAN_TAG_USED | ||
5744 | if (vlan_tx_tag_present(skb)) | 5713 | if (vlan_tx_tag_present(skb)) |
5745 | base_flags |= (TXD_FLAG_VLAN | | 5714 | base_flags |= (TXD_FLAG_VLAN | |
5746 | (vlan_tx_tag_get(skb) << 16)); | 5715 | (vlan_tx_tag_get(skb) << 16)); |
5747 | #endif | ||
5748 | 5716 | ||
5749 | len = skb_headlen(skb); | 5717 | len = skb_headlen(skb); |
5750 | 5718 | ||
@@ -5986,11 +5954,10 @@ static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb, | |||
5986 | } | 5954 | } |
5987 | } | 5955 | } |
5988 | } | 5956 | } |
5989 | #if TG3_VLAN_TAG_USED | 5957 | |
5990 | if (vlan_tx_tag_present(skb)) | 5958 | if (vlan_tx_tag_present(skb)) |
5991 | base_flags |= (TXD_FLAG_VLAN | | 5959 | base_flags |= (TXD_FLAG_VLAN | |
5992 | (vlan_tx_tag_get(skb) << 16)); | 5960 | (vlan_tx_tag_get(skb) << 16)); |
5993 | #endif | ||
5994 | 5961 | ||
5995 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && | 5962 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
5996 | !mss && skb->len > VLAN_ETH_FRAME_LEN) | 5963 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
@@ -9532,17 +9499,10 @@ static void __tg3_set_rx_mode(struct net_device *dev) | |||
9532 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | | 9499 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
9533 | RX_MODE_KEEP_VLAN_TAG); | 9500 | RX_MODE_KEEP_VLAN_TAG); |
9534 | 9501 | ||
9502 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) | ||
9535 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG | 9503 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
9536 | * flag clear. | 9504 | * flag clear. |
9537 | */ | 9505 | */ |
9538 | #if TG3_VLAN_TAG_USED | ||
9539 | if (!tp->vlgrp && | ||
9540 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | ||
9541 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; | ||
9542 | #else | ||
9543 | /* By definition, VLAN is disabled always in this | ||
9544 | * case. | ||
9545 | */ | ||
9546 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | 9506 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
9547 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; | 9507 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
9548 | #endif | 9508 | #endif |
@@ -11230,31 +11190,6 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | |||
11230 | return -EOPNOTSUPP; | 11190 | return -EOPNOTSUPP; |
11231 | } | 11191 | } |
11232 | 11192 | ||
11233 | #if TG3_VLAN_TAG_USED | ||
11234 | static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) | ||
11235 | { | ||
11236 | struct tg3 *tp = netdev_priv(dev); | ||
11237 | |||
11238 | if (!netif_running(dev)) { | ||
11239 | tp->vlgrp = grp; | ||
11240 | return; | ||
11241 | } | ||
11242 | |||
11243 | tg3_netif_stop(tp); | ||
11244 | |||
11245 | tg3_full_lock(tp, 0); | ||
11246 | |||
11247 | tp->vlgrp = grp; | ||
11248 | |||
11249 | /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ | ||
11250 | __tg3_set_rx_mode(dev); | ||
11251 | |||
11252 | tg3_netif_start(tp); | ||
11253 | |||
11254 | tg3_full_unlock(tp); | ||
11255 | } | ||
11256 | #endif | ||
11257 | |||
11258 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) | 11193 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11259 | { | 11194 | { |
11260 | struct tg3 *tp = netdev_priv(dev); | 11195 | struct tg3 *tp = netdev_priv(dev); |
@@ -13066,9 +13001,7 @@ static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); | |||
13066 | 13001 | ||
13067 | static void inline vlan_features_add(struct net_device *dev, unsigned long flags) | 13002 | static void inline vlan_features_add(struct net_device *dev, unsigned long flags) |
13068 | { | 13003 | { |
13069 | #if TG3_VLAN_TAG_USED | ||
13070 | dev->vlan_features |= flags; | 13004 | dev->vlan_features |= flags; |
13071 | #endif | ||
13072 | } | 13005 | } |
13073 | 13006 | ||
13074 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) | 13007 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
@@ -13861,11 +13794,11 @@ static int __devinit tg3_get_invariants(struct tg3 *tp) | |||
13861 | else | 13794 | else |
13862 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; | 13795 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; |
13863 | 13796 | ||
13864 | tp->rx_offset = NET_IP_ALIGN + TG3_RX_HEADROOM; | 13797 | tp->rx_offset = NET_IP_ALIGN; |
13865 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; | 13798 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
13866 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && | 13799 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
13867 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) { | 13800 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) { |
13868 | tp->rx_offset -= NET_IP_ALIGN; | 13801 | tp->rx_offset = 0; |
13869 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | 13802 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
13870 | tp->rx_copy_thresh = ~(u16)0; | 13803 | tp->rx_copy_thresh = ~(u16)0; |
13871 | #endif | 13804 | #endif |
@@ -14629,9 +14562,6 @@ static const struct net_device_ops tg3_netdev_ops = { | |||
14629 | .ndo_do_ioctl = tg3_ioctl, | 14562 | .ndo_do_ioctl = tg3_ioctl, |
14630 | .ndo_tx_timeout = tg3_tx_timeout, | 14563 | .ndo_tx_timeout = tg3_tx_timeout, |
14631 | .ndo_change_mtu = tg3_change_mtu, | 14564 | .ndo_change_mtu = tg3_change_mtu, |
14632 | #if TG3_VLAN_TAG_USED | ||
14633 | .ndo_vlan_rx_register = tg3_vlan_rx_register, | ||
14634 | #endif | ||
14635 | #ifdef CONFIG_NET_POLL_CONTROLLER | 14565 | #ifdef CONFIG_NET_POLL_CONTROLLER |
14636 | .ndo_poll_controller = tg3_poll_controller, | 14566 | .ndo_poll_controller = tg3_poll_controller, |
14637 | #endif | 14567 | #endif |
@@ -14648,9 +14578,6 @@ static const struct net_device_ops tg3_netdev_ops_dma_bug = { | |||
14648 | .ndo_do_ioctl = tg3_ioctl, | 14578 | .ndo_do_ioctl = tg3_ioctl, |
14649 | .ndo_tx_timeout = tg3_tx_timeout, | 14579 | .ndo_tx_timeout = tg3_tx_timeout, |
14650 | .ndo_change_mtu = tg3_change_mtu, | 14580 | .ndo_change_mtu = tg3_change_mtu, |
14651 | #if TG3_VLAN_TAG_USED | ||
14652 | .ndo_vlan_rx_register = tg3_vlan_rx_register, | ||
14653 | #endif | ||
14654 | #ifdef CONFIG_NET_POLL_CONTROLLER | 14581 | #ifdef CONFIG_NET_POLL_CONTROLLER |
14655 | .ndo_poll_controller = tg3_poll_controller, | 14582 | .ndo_poll_controller = tg3_poll_controller, |
14656 | #endif | 14583 | #endif |
@@ -14700,9 +14627,7 @@ static int __devinit tg3_init_one(struct pci_dev *pdev, | |||
14700 | 14627 | ||
14701 | SET_NETDEV_DEV(dev, &pdev->dev); | 14628 | SET_NETDEV_DEV(dev, &pdev->dev); |
14702 | 14629 | ||
14703 | #if TG3_VLAN_TAG_USED | ||
14704 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; | 14630 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
14705 | #endif | ||
14706 | 14631 | ||
14707 | tp = netdev_priv(dev); | 14632 | tp = netdev_priv(dev); |
14708 | tp->pdev = pdev; | 14633 | tp->pdev = pdev; |
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h index d62c8d937c82..f528243e1a4f 100644 --- a/drivers/net/tg3.h +++ b/drivers/net/tg3.h | |||
@@ -2808,9 +2808,6 @@ struct tg3 { | |||
2808 | u32 rx_std_max_post; | 2808 | u32 rx_std_max_post; |
2809 | u32 rx_offset; | 2809 | u32 rx_offset; |
2810 | u32 rx_pkt_map_sz; | 2810 | u32 rx_pkt_map_sz; |
2811 | #if TG3_VLAN_TAG_USED | ||
2812 | struct vlan_group *vlgrp; | ||
2813 | #endif | ||
2814 | 2811 | ||
2815 | 2812 | ||
2816 | /* begin "everything else" cacheline(s) section */ | 2813 | /* begin "everything else" cacheline(s) section */ |
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c index 5e98643a4a21..7dc84971f26f 100644 --- a/drivers/net/usb/kaweth.c +++ b/drivers/net/usb/kaweth.c | |||
@@ -406,6 +406,7 @@ static int kaweth_download_firmware(struct kaweth_device *kaweth, | |||
406 | 406 | ||
407 | if (fw->size > KAWETH_FIRMWARE_BUF_SIZE) { | 407 | if (fw->size > KAWETH_FIRMWARE_BUF_SIZE) { |
408 | err("Firmware too big: %zu", fw->size); | 408 | err("Firmware too big: %zu", fw->size); |
409 | release_firmware(fw); | ||
409 | return -ENOSPC; | 410 | return -ENOSPC; |
410 | } | 411 | } |
411 | data_len = fw->size; | 412 | data_len = fw->size; |
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c index 1afb8bb85756..9f01e50d5cda 100644 --- a/drivers/net/wireless/ath/ath9k/hw.c +++ b/drivers/net/wireless/ath/ath9k/hw.c | |||
@@ -369,6 +369,9 @@ static void ath9k_hw_init_config(struct ath_hw *ah) | |||
369 | else | 369 | else |
370 | ah->config.ht_enable = 0; | 370 | ah->config.ht_enable = 0; |
371 | 371 | ||
372 | /* PAPRD needs some more work to be enabled */ | ||
373 | ah->config.paprd_disable = 1; | ||
374 | |||
372 | ah->config.rx_intr_mitigation = true; | 375 | ah->config.rx_intr_mitigation = true; |
373 | ah->config.pcieSerDesWrite = true; | 376 | ah->config.pcieSerDesWrite = true; |
374 | 377 | ||
@@ -1933,7 +1936,8 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah) | |||
1933 | pCap->rx_status_len = sizeof(struct ar9003_rxs); | 1936 | pCap->rx_status_len = sizeof(struct ar9003_rxs); |
1934 | pCap->tx_desc_len = sizeof(struct ar9003_txc); | 1937 | pCap->tx_desc_len = sizeof(struct ar9003_txc); |
1935 | pCap->txs_len = sizeof(struct ar9003_txs); | 1938 | pCap->txs_len = sizeof(struct ar9003_txs); |
1936 | if (ah->eep_ops->get_eeprom(ah, EEP_PAPRD)) | 1939 | if (!ah->config.paprd_disable && |
1940 | ah->eep_ops->get_eeprom(ah, EEP_PAPRD)) | ||
1937 | pCap->hw_caps |= ATH9K_HW_CAP_PAPRD; | 1941 | pCap->hw_caps |= ATH9K_HW_CAP_PAPRD; |
1938 | } else { | 1942 | } else { |
1939 | pCap->tx_desc_len = sizeof(struct ath_desc); | 1943 | pCap->tx_desc_len = sizeof(struct ath_desc); |
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h index 5a3dfec45e96..ea9fde670646 100644 --- a/drivers/net/wireless/ath/ath9k/hw.h +++ b/drivers/net/wireless/ath/ath9k/hw.h | |||
@@ -225,6 +225,7 @@ struct ath9k_ops_config { | |||
225 | u32 pcie_waen; | 225 | u32 pcie_waen; |
226 | u8 analog_shiftreg; | 226 | u8 analog_shiftreg; |
227 | u8 ht_enable; | 227 | u8 ht_enable; |
228 | u8 paprd_disable; | ||
228 | u32 ofdm_trig_low; | 229 | u32 ofdm_trig_low; |
229 | u32 ofdm_trig_high; | 230 | u32 ofdm_trig_high; |
230 | u32 cck_trig_high; | 231 | u32 cck_trig_high; |
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c index f90a6ca94a76..c79c97be6cd4 100644 --- a/drivers/net/wireless/ath/ath9k/main.c +++ b/drivers/net/wireless/ath/ath9k/main.c | |||
@@ -592,14 +592,12 @@ void ath9k_tasklet(unsigned long data) | |||
592 | u32 status = sc->intrstatus; | 592 | u32 status = sc->intrstatus; |
593 | u32 rxmask; | 593 | u32 rxmask; |
594 | 594 | ||
595 | ath9k_ps_wakeup(sc); | ||
596 | |||
597 | if (status & ATH9K_INT_FATAL) { | 595 | if (status & ATH9K_INT_FATAL) { |
598 | ath_reset(sc, true); | 596 | ath_reset(sc, true); |
599 | ath9k_ps_restore(sc); | ||
600 | return; | 597 | return; |
601 | } | 598 | } |
602 | 599 | ||
600 | ath9k_ps_wakeup(sc); | ||
603 | spin_lock(&sc->sc_pcu_lock); | 601 | spin_lock(&sc->sc_pcu_lock); |
604 | 602 | ||
605 | if (!ath9k_hw_check_alive(ah)) | 603 | if (!ath9k_hw_check_alive(ah)) |
@@ -969,6 +967,7 @@ int ath_reset(struct ath_softc *sc, bool retry_tx) | |||
969 | /* Stop ANI */ | 967 | /* Stop ANI */ |
970 | del_timer_sync(&common->ani.timer); | 968 | del_timer_sync(&common->ani.timer); |
971 | 969 | ||
970 | ath9k_ps_wakeup(sc); | ||
972 | spin_lock_bh(&sc->sc_pcu_lock); | 971 | spin_lock_bh(&sc->sc_pcu_lock); |
973 | 972 | ||
974 | ieee80211_stop_queues(hw); | 973 | ieee80211_stop_queues(hw); |
@@ -1015,6 +1014,7 @@ int ath_reset(struct ath_softc *sc, bool retry_tx) | |||
1015 | 1014 | ||
1016 | /* Start ANI */ | 1015 | /* Start ANI */ |
1017 | ath_start_ani(common); | 1016 | ath_start_ani(common); |
1017 | ath9k_ps_restore(sc); | ||
1018 | 1018 | ||
1019 | return r; | 1019 | return r; |
1020 | } | 1020 | } |
@@ -1701,7 +1701,9 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed) | |||
1701 | skip_chan_change: | 1701 | skip_chan_change: |
1702 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | 1702 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
1703 | sc->config.txpowlimit = 2 * conf->power_level; | 1703 | sc->config.txpowlimit = 2 * conf->power_level; |
1704 | ath9k_ps_wakeup(sc); | ||
1704 | ath_update_txpow(sc); | 1705 | ath_update_txpow(sc); |
1706 | ath9k_ps_restore(sc); | ||
1705 | } | 1707 | } |
1706 | 1708 | ||
1707 | spin_lock_bh(&sc->wiphy_lock); | 1709 | spin_lock_bh(&sc->wiphy_lock); |
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c index 332d1feb5c18..33a37edbaf79 100644 --- a/drivers/net/wireless/ath/ath9k/xmit.c +++ b/drivers/net/wireless/ath/ath9k/xmit.c | |||
@@ -2113,9 +2113,7 @@ static void ath_tx_complete_poll_work(struct work_struct *work) | |||
2113 | if (needreset) { | 2113 | if (needreset) { |
2114 | ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET, | 2114 | ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET, |
2115 | "tx hung, resetting the chip\n"); | 2115 | "tx hung, resetting the chip\n"); |
2116 | ath9k_ps_wakeup(sc); | ||
2117 | ath_reset(sc, true); | 2116 | ath_reset(sc, true); |
2118 | ath9k_ps_restore(sc); | ||
2119 | } | 2117 | } |
2120 | 2118 | ||
2121 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, | 2119 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, |
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c index 3f1e5f1bf847..91a9f5253469 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965.c +++ b/drivers/net/wireless/iwlwifi/iwl-4965.c | |||
@@ -2624,6 +2624,7 @@ struct iwl_cfg iwl4965_agn_cfg = { | |||
2624 | .fw_name_pre = IWL4965_FW_PRE, | 2624 | .fw_name_pre = IWL4965_FW_PRE, |
2625 | .ucode_api_max = IWL4965_UCODE_API_MAX, | 2625 | .ucode_api_max = IWL4965_UCODE_API_MAX, |
2626 | .ucode_api_min = IWL4965_UCODE_API_MIN, | 2626 | .ucode_api_min = IWL4965_UCODE_API_MIN, |
2627 | .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, | ||
2627 | .valid_tx_ant = ANT_AB, | 2628 | .valid_tx_ant = ANT_AB, |
2628 | .valid_rx_ant = ANT_ABC, | 2629 | .valid_rx_ant = ANT_ABC, |
2629 | .eeprom_ver = EEPROM_4965_EEPROM_VERSION, | 2630 | .eeprom_ver = EEPROM_4965_EEPROM_VERSION, |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-agn-eeprom.c index 14ceb4df72f6..27b5a3eec9dc 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-eeprom.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-eeprom.c | |||
@@ -152,11 +152,14 @@ int iwl_eeprom_check_sku(struct iwl_priv *priv) | |||
152 | 152 | ||
153 | eeprom_sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP); | 153 | eeprom_sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP); |
154 | 154 | ||
155 | priv->cfg->sku = ((eeprom_sku & EEPROM_SKU_CAP_BAND_SELECTION) >> | 155 | if (!priv->cfg->sku) { |
156 | /* not using sku overwrite */ | ||
157 | priv->cfg->sku = | ||
158 | ((eeprom_sku & EEPROM_SKU_CAP_BAND_SELECTION) >> | ||
156 | EEPROM_SKU_CAP_BAND_POS); | 159 | EEPROM_SKU_CAP_BAND_POS); |
157 | if (eeprom_sku & EEPROM_SKU_CAP_11N_ENABLE) | 160 | if (eeprom_sku & EEPROM_SKU_CAP_11N_ENABLE) |
158 | priv->cfg->sku |= IWL_SKU_N; | 161 | priv->cfg->sku |= IWL_SKU_N; |
159 | 162 | } | |
160 | if (!priv->cfg->sku) { | 163 | if (!priv->cfg->sku) { |
161 | IWL_ERR(priv, "Invalid device sku\n"); | 164 | IWL_ERR(priv, "Invalid device sku\n"); |
162 | return -EINVAL; | 165 | return -EINVAL; |
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c index 0b4e8590cbb7..029be3c6c030 100644 --- a/drivers/net/wireless/rt2x00/rt73usb.c +++ b/drivers/net/wireless/rt2x00/rt73usb.c | |||
@@ -2446,6 +2446,7 @@ static struct usb_device_id rt73usb_device_table[] = { | |||
2446 | { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) }, | 2446 | { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) }, |
2447 | { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) }, | 2447 | { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) }, |
2448 | { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) }, | 2448 | { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) }, |
2449 | { USB_DEVICE(0x0812, 0x3101), USB_DEVICE_DATA(&rt73usb_ops) }, | ||
2449 | /* Qcom */ | 2450 | /* Qcom */ |
2450 | { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) }, | 2451 | { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) }, |
2451 | { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) }, | 2452 | { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) }, |
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c index 0fa36aa6701a..1758d4463247 100644 --- a/drivers/net/wireless/rtlwifi/pci.c +++ b/drivers/net/wireless/rtlwifi/pci.c | |||
@@ -619,6 +619,13 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw) | |||
619 | struct sk_buff *uskb = NULL; | 619 | struct sk_buff *uskb = NULL; |
620 | u8 *pdata; | 620 | u8 *pdata; |
621 | uskb = dev_alloc_skb(skb->len + 128); | 621 | uskb = dev_alloc_skb(skb->len + 128); |
622 | if (!uskb) { | ||
623 | RT_TRACE(rtlpriv, | ||
624 | (COMP_INTR | COMP_RECV), | ||
625 | DBG_EMERG, | ||
626 | ("can't alloc rx skb\n")); | ||
627 | goto done; | ||
628 | } | ||
622 | memcpy(IEEE80211_SKB_RXCB(uskb), | 629 | memcpy(IEEE80211_SKB_RXCB(uskb), |
623 | &rx_status, | 630 | &rx_status, |
624 | sizeof(rx_status)); | 631 | sizeof(rx_status)); |
@@ -641,7 +648,7 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw) | |||
641 | new_skb = dev_alloc_skb(rtlpci->rxbuffersize); | 648 | new_skb = dev_alloc_skb(rtlpci->rxbuffersize); |
642 | if (unlikely(!new_skb)) { | 649 | if (unlikely(!new_skb)) { |
643 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV), | 650 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV), |
644 | DBG_DMESG, | 651 | DBG_EMERG, |
645 | ("can't alloc skb for rx\n")); | 652 | ("can't alloc skb for rx\n")); |
646 | goto done; | 653 | goto done; |
647 | } | 654 | } |
@@ -1066,9 +1073,9 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw) | |||
1066 | struct sk_buff *skb = | 1073 | struct sk_buff *skb = |
1067 | dev_alloc_skb(rtlpci->rxbuffersize); | 1074 | dev_alloc_skb(rtlpci->rxbuffersize); |
1068 | u32 bufferaddress; | 1075 | u32 bufferaddress; |
1069 | entry = &rtlpci->rx_ring[rx_queue_idx].desc[i]; | ||
1070 | if (!skb) | 1076 | if (!skb) |
1071 | return 0; | 1077 | return 0; |
1078 | entry = &rtlpci->rx_ring[rx_queue_idx].desc[i]; | ||
1072 | 1079 | ||
1073 | /*skb->dev = dev; */ | 1080 | /*skb->dev = dev; */ |
1074 | 1081 | ||