diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-04-30 11:59:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-04-30 11:59:57 -0400 |
commit | 40caf5ea5a7d47f8a33e26b63ca81dea4b5109d2 (patch) | |
tree | 3f879353d5cb69d2dee707108e4aaeae075f5a0c /drivers/ieee1394/eth1394.c | |
parent | d6454706c382ab74e2ecad7803c434cc6bd30343 (diff) | |
parent | bcfd09ee48f77a4fe903dbc3757e7af931998ce1 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6: (56 commits)
ieee1394: remove garbage from Kconfig
ieee1394: more help in Kconfig
ieee1394: ohci1394: Fix mistake in printk message.
ieee1394: ohci1394: remove unnecessary rcvPhyPkt bit flipping in LinkControl register
ieee1394: ohci1394: fix cosmetic problem in error logging
ieee1394: eth1394: send async streams at S100 on 1394b buses
ieee1394: eth1394: fix error path in module_init
ieee1394: eth1394: correct return codes in hard_start_xmit
ieee1394: eth1394: hard_start_xmit is called in atomic context
ieee1394: eth1394: some conditions are unlikely
ieee1394: eth1394: clean up fragment_overlap
ieee1394: eth1394: don't use alloc_etherdev
ieee1394: eth1394: omit useless set_mac_address callback
ieee1394: eth1394: CONFIG_INET is always defined
ieee1394: eth1394: allow MTU bigger than 1500
ieee1394: unexport highlevel_host_reset
ieee1394: eth1394: contain host reset
ieee1394: eth1394: shorter error messages
ieee1394: eth1394: correct a memset argument
ieee1394: eth1394: refactor .probe and .update
...
Diffstat (limited to 'drivers/ieee1394/eth1394.c')
-rw-r--r-- | drivers/ieee1394/eth1394.c | 798 |
1 files changed, 357 insertions, 441 deletions
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c index a364003ba47f..2296d43a2414 100644 --- a/drivers/ieee1394/eth1394.c +++ b/drivers/ieee1394/eth1394.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * eth1394.c -- Ethernet driver for Linux IEEE-1394 Subsystem | 2 | * eth1394.c -- IPv4 driver for Linux IEEE-1394 Subsystem |
3 | * | 3 | * |
4 | * Copyright (C) 2001-2003 Ben Collins <bcollins@debian.org> | 4 | * Copyright (C) 2001-2003 Ben Collins <bcollins@debian.org> |
5 | * 2000 Bonin Franck <boninf@free.fr> | 5 | * 2000 Bonin Franck <boninf@free.fr> |
@@ -22,10 +22,9 @@ | |||
22 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 22 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | /* This driver intends to support RFC 2734, which describes a method for | 25 | /* |
26 | * transporting IPv4 datagrams over IEEE-1394 serial busses. This driver | 26 | * This driver intends to support RFC 2734, which describes a method for |
27 | * will ultimately support that method, but currently falls short in | 27 | * transporting IPv4 datagrams over IEEE-1394 serial busses. |
28 | * several areas. | ||
29 | * | 28 | * |
30 | * TODO: | 29 | * TODO: |
31 | * RFC 2734 related: | 30 | * RFC 2734 related: |
@@ -40,7 +39,6 @@ | |||
40 | * - Consider garbage collecting old partial datagrams after X amount of time | 39 | * - Consider garbage collecting old partial datagrams after X amount of time |
41 | */ | 40 | */ |
42 | 41 | ||
43 | |||
44 | #include <linux/module.h> | 42 | #include <linux/module.h> |
45 | 43 | ||
46 | #include <linux/kernel.h> | 44 | #include <linux/kernel.h> |
@@ -52,7 +50,6 @@ | |||
52 | 50 | ||
53 | #include <linux/netdevice.h> | 51 | #include <linux/netdevice.h> |
54 | #include <linux/inetdevice.h> | 52 | #include <linux/inetdevice.h> |
55 | #include <linux/etherdevice.h> | ||
56 | #include <linux/if_arp.h> | 53 | #include <linux/if_arp.h> |
57 | #include <linux/if_ether.h> | 54 | #include <linux/if_ether.h> |
58 | #include <linux/ip.h> | 55 | #include <linux/ip.h> |
@@ -84,10 +81,6 @@ | |||
84 | #define ETH1394_PRINT(level, dev_name, fmt, args...) \ | 81 | #define ETH1394_PRINT(level, dev_name, fmt, args...) \ |
85 | printk(level "%s: %s: " fmt, driver_name, dev_name, ## args) | 82 | printk(level "%s: %s: " fmt, driver_name, dev_name, ## args) |
86 | 83 | ||
87 | #define DEBUG(fmt, args...) \ | ||
88 | printk(KERN_ERR "%s:%s[%d]: " fmt "\n", driver_name, __FUNCTION__, __LINE__, ## args) | ||
89 | #define TRACE() printk(KERN_ERR "%s:%s[%d] ---- TRACE\n", driver_name, __FUNCTION__, __LINE__) | ||
90 | |||
91 | struct fragment_info { | 84 | struct fragment_info { |
92 | struct list_head list; | 85 | struct list_head list; |
93 | int offset; | 86 | int offset; |
@@ -105,9 +98,9 @@ struct partial_datagram { | |||
105 | }; | 98 | }; |
106 | 99 | ||
107 | struct pdg_list { | 100 | struct pdg_list { |
108 | struct list_head list; /* partial datagram list per node */ | 101 | struct list_head list; /* partial datagram list per node */ |
109 | unsigned int sz; /* partial datagram list size per node */ | 102 | unsigned int sz; /* partial datagram list size per node */ |
110 | spinlock_t lock; /* partial datagram lock */ | 103 | spinlock_t lock; /* partial datagram lock */ |
111 | }; | 104 | }; |
112 | 105 | ||
113 | struct eth1394_host_info { | 106 | struct eth1394_host_info { |
@@ -121,16 +114,14 @@ struct eth1394_node_ref { | |||
121 | }; | 114 | }; |
122 | 115 | ||
123 | struct eth1394_node_info { | 116 | struct eth1394_node_info { |
124 | u16 maxpayload; /* Max payload */ | 117 | u16 maxpayload; /* max payload */ |
125 | u8 sspd; /* Max speed */ | 118 | u8 sspd; /* max speed */ |
126 | u64 fifo; /* FIFO address */ | 119 | u64 fifo; /* FIFO address */ |
127 | struct pdg_list pdg; /* partial RX datagram lists */ | 120 | struct pdg_list pdg; /* partial RX datagram lists */ |
128 | int dgl; /* Outgoing datagram label */ | 121 | int dgl; /* outgoing datagram label */ |
129 | }; | 122 | }; |
130 | 123 | ||
131 | /* Our ieee1394 highlevel driver */ | 124 | static const char driver_name[] = "eth1394"; |
132 | #define ETH1394_DRIVER_NAME "eth1394" | ||
133 | static const char driver_name[] = ETH1394_DRIVER_NAME; | ||
134 | 125 | ||
135 | static struct kmem_cache *packet_task_cache; | 126 | static struct kmem_cache *packet_task_cache; |
136 | 127 | ||
@@ -138,18 +129,12 @@ static struct hpsb_highlevel eth1394_highlevel; | |||
138 | 129 | ||
139 | /* Use common.lf to determine header len */ | 130 | /* Use common.lf to determine header len */ |
140 | static const int hdr_type_len[] = { | 131 | static const int hdr_type_len[] = { |
141 | sizeof (struct eth1394_uf_hdr), | 132 | sizeof(struct eth1394_uf_hdr), |
142 | sizeof (struct eth1394_ff_hdr), | 133 | sizeof(struct eth1394_ff_hdr), |
143 | sizeof (struct eth1394_sf_hdr), | 134 | sizeof(struct eth1394_sf_hdr), |
144 | sizeof (struct eth1394_sf_hdr) | 135 | sizeof(struct eth1394_sf_hdr) |
145 | }; | 136 | }; |
146 | 137 | ||
147 | /* Change this to IEEE1394_SPEED_S100 to make testing easier */ | ||
148 | #define ETH1394_SPEED_DEF IEEE1394_SPEED_MAX | ||
149 | |||
150 | /* For now, this needs to be 1500, so that XP works with us */ | ||
151 | #define ETH1394_DATA_LEN ETH_DATA_LEN | ||
152 | |||
153 | static const u16 eth1394_speedto_maxpayload[] = { | 138 | static const u16 eth1394_speedto_maxpayload[] = { |
154 | /* S100, S200, S400, S800, S1600, S3200 */ | 139 | /* S100, S200, S400, S800, S1600, S3200 */ |
155 | 512, 1024, 2048, 4096, 4096, 4096 | 140 | 512, 1024, 2048, 4096, 4096, 4096 |
@@ -159,7 +144,8 @@ MODULE_AUTHOR("Ben Collins (bcollins@debian.org)"); | |||
159 | MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)"); | 144 | MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)"); |
160 | MODULE_LICENSE("GPL"); | 145 | MODULE_LICENSE("GPL"); |
161 | 146 | ||
162 | /* The max_partial_datagrams parameter is the maximum number of fragmented | 147 | /* |
148 | * The max_partial_datagrams parameter is the maximum number of fragmented | ||
163 | * datagrams per node that eth1394 will keep in memory. Providing an upper | 149 | * datagrams per node that eth1394 will keep in memory. Providing an upper |
164 | * bound allows us to limit the amount of memory that partial datagrams | 150 | * bound allows us to limit the amount of memory that partial datagrams |
165 | * consume in the event that some partial datagrams are never completed. | 151 | * consume in the event that some partial datagrams are never completed. |
@@ -179,10 +165,7 @@ static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr); | |||
179 | static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh); | 165 | static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh); |
180 | static void ether1394_header_cache_update(struct hh_cache *hh, | 166 | static void ether1394_header_cache_update(struct hh_cache *hh, |
181 | struct net_device *dev, | 167 | struct net_device *dev, |
182 | unsigned char * haddr); | 168 | unsigned char *haddr); |
183 | static int ether1394_mac_addr(struct net_device *dev, void *p); | ||
184 | |||
185 | static void purge_partial_datagram(struct list_head *old); | ||
186 | static int ether1394_tx(struct sk_buff *skb, struct net_device *dev); | 169 | static int ether1394_tx(struct sk_buff *skb, struct net_device *dev); |
187 | static void ether1394_iso(struct hpsb_iso *iso); | 170 | static void ether1394_iso(struct hpsb_iso *iso); |
188 | 171 | ||
@@ -190,9 +173,9 @@ static struct ethtool_ops ethtool_ops; | |||
190 | 173 | ||
191 | static int ether1394_write(struct hpsb_host *host, int srcid, int destid, | 174 | static int ether1394_write(struct hpsb_host *host, int srcid, int destid, |
192 | quadlet_t *data, u64 addr, size_t len, u16 flags); | 175 | quadlet_t *data, u64 addr, size_t len, u16 flags); |
193 | static void ether1394_add_host (struct hpsb_host *host); | 176 | static void ether1394_add_host(struct hpsb_host *host); |
194 | static void ether1394_remove_host (struct hpsb_host *host); | 177 | static void ether1394_remove_host(struct hpsb_host *host); |
195 | static void ether1394_host_reset (struct hpsb_host *host); | 178 | static void ether1394_host_reset(struct hpsb_host *host); |
196 | 179 | ||
197 | /* Function for incoming 1394 packets */ | 180 | /* Function for incoming 1394 packets */ |
198 | static struct hpsb_address_ops addr_ops = { | 181 | static struct hpsb_address_ops addr_ops = { |
@@ -207,89 +190,107 @@ static struct hpsb_highlevel eth1394_highlevel = { | |||
207 | .host_reset = ether1394_host_reset, | 190 | .host_reset = ether1394_host_reset, |
208 | }; | 191 | }; |
209 | 192 | ||
193 | static int ether1394_recv_init(struct eth1394_priv *priv) | ||
194 | { | ||
195 | unsigned int iso_buf_size; | ||
196 | |||
197 | /* FIXME: rawiso limits us to PAGE_SIZE */ | ||
198 | iso_buf_size = min((unsigned int)PAGE_SIZE, | ||
199 | 2 * (1U << (priv->host->csr.max_rec + 1))); | ||
200 | |||
201 | priv->iso = hpsb_iso_recv_init(priv->host, | ||
202 | ETHER1394_GASP_BUFFERS * iso_buf_size, | ||
203 | ETHER1394_GASP_BUFFERS, | ||
204 | priv->broadcast_channel, | ||
205 | HPSB_ISO_DMA_PACKET_PER_BUFFER, | ||
206 | 1, ether1394_iso); | ||
207 | if (priv->iso == NULL) { | ||
208 | ETH1394_PRINT_G(KERN_ERR, "Failed to allocate IR context\n"); | ||
209 | priv->bc_state = ETHER1394_BC_ERROR; | ||
210 | return -EAGAIN; | ||
211 | } | ||
212 | |||
213 | if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0) | ||
214 | priv->bc_state = ETHER1394_BC_STOPPED; | ||
215 | else | ||
216 | priv->bc_state = ETHER1394_BC_RUNNING; | ||
217 | return 0; | ||
218 | } | ||
210 | 219 | ||
211 | /* This is called after an "ifup" */ | 220 | /* This is called after an "ifup" */ |
212 | static int ether1394_open (struct net_device *dev) | 221 | static int ether1394_open(struct net_device *dev) |
213 | { | 222 | { |
214 | struct eth1394_priv *priv = netdev_priv(dev); | 223 | struct eth1394_priv *priv = netdev_priv(dev); |
215 | int ret = 0; | 224 | int ret; |
216 | 225 | ||
217 | /* Something bad happened, don't even try */ | ||
218 | if (priv->bc_state == ETHER1394_BC_ERROR) { | 226 | if (priv->bc_state == ETHER1394_BC_ERROR) { |
219 | /* we'll try again */ | 227 | ret = ether1394_recv_init(priv); |
220 | priv->iso = hpsb_iso_recv_init(priv->host, | 228 | if (ret) |
221 | ETHER1394_ISO_BUF_SIZE, | 229 | return ret; |
222 | ETHER1394_GASP_BUFFERS, | ||
223 | priv->broadcast_channel, | ||
224 | HPSB_ISO_DMA_PACKET_PER_BUFFER, | ||
225 | 1, ether1394_iso); | ||
226 | if (priv->iso == NULL) { | ||
227 | ETH1394_PRINT(KERN_ERR, dev->name, | ||
228 | "Could not allocate isochronous receive " | ||
229 | "context for the broadcast channel\n"); | ||
230 | priv->bc_state = ETHER1394_BC_ERROR; | ||
231 | ret = -EAGAIN; | ||
232 | } else { | ||
233 | if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0) | ||
234 | priv->bc_state = ETHER1394_BC_STOPPED; | ||
235 | else | ||
236 | priv->bc_state = ETHER1394_BC_RUNNING; | ||
237 | } | ||
238 | } | 230 | } |
239 | 231 | netif_start_queue(dev); | |
240 | if (ret) | ||
241 | return ret; | ||
242 | |||
243 | netif_start_queue (dev); | ||
244 | return 0; | 232 | return 0; |
245 | } | 233 | } |
246 | 234 | ||
247 | /* This is called after an "ifdown" */ | 235 | /* This is called after an "ifdown" */ |
248 | static int ether1394_stop (struct net_device *dev) | 236 | static int ether1394_stop(struct net_device *dev) |
249 | { | 237 | { |
250 | netif_stop_queue (dev); | 238 | netif_stop_queue(dev); |
251 | return 0; | 239 | return 0; |
252 | } | 240 | } |
253 | 241 | ||
254 | /* Return statistics to the caller */ | 242 | /* Return statistics to the caller */ |
255 | static struct net_device_stats *ether1394_stats (struct net_device *dev) | 243 | static struct net_device_stats *ether1394_stats(struct net_device *dev) |
256 | { | 244 | { |
257 | return &(((struct eth1394_priv *)netdev_priv(dev))->stats); | 245 | return &(((struct eth1394_priv *)netdev_priv(dev))->stats); |
258 | } | 246 | } |
259 | 247 | ||
260 | /* What to do if we timeout. I think a host reset is probably in order, so | 248 | /* FIXME: What to do if we timeout? I think a host reset is probably in order, |
261 | * that's what we do. Should we increment the stat counters too? */ | 249 | * so that's what we do. Should we increment the stat counters too? */ |
262 | static void ether1394_tx_timeout (struct net_device *dev) | 250 | static void ether1394_tx_timeout(struct net_device *dev) |
263 | { | 251 | { |
264 | ETH1394_PRINT (KERN_ERR, dev->name, "Timeout, resetting host %s\n", | 252 | struct hpsb_host *host = |
265 | ((struct eth1394_priv *)netdev_priv(dev))->host->driver->name); | 253 | ((struct eth1394_priv *)netdev_priv(dev))->host; |
266 | 254 | ||
267 | highlevel_host_reset (((struct eth1394_priv *)netdev_priv(dev))->host); | 255 | ETH1394_PRINT(KERN_ERR, dev->name, "Timeout, resetting host\n"); |
256 | ether1394_host_reset(host); | ||
257 | } | ||
268 | 258 | ||
269 | netif_wake_queue (dev); | 259 | static inline int ether1394_max_mtu(struct hpsb_host* host) |
260 | { | ||
261 | return (1 << (host->csr.max_rec + 1)) | ||
262 | - sizeof(union eth1394_hdr) - ETHER1394_GASP_OVERHEAD; | ||
270 | } | 263 | } |
271 | 264 | ||
272 | static int ether1394_change_mtu(struct net_device *dev, int new_mtu) | 265 | static int ether1394_change_mtu(struct net_device *dev, int new_mtu) |
273 | { | 266 | { |
274 | struct eth1394_priv *priv = netdev_priv(dev); | 267 | int max_mtu; |
275 | 268 | ||
276 | if ((new_mtu < 68) || | 269 | if (new_mtu < 68) |
277 | (new_mtu > min(ETH1394_DATA_LEN, | ||
278 | (int)((1 << (priv->host->csr.max_rec + 1)) - | ||
279 | (sizeof(union eth1394_hdr) + | ||
280 | ETHER1394_GASP_OVERHEAD))))) | ||
281 | return -EINVAL; | 270 | return -EINVAL; |
271 | |||
272 | max_mtu = ether1394_max_mtu( | ||
273 | ((struct eth1394_priv *)netdev_priv(dev))->host); | ||
274 | if (new_mtu > max_mtu) { | ||
275 | ETH1394_PRINT(KERN_INFO, dev->name, | ||
276 | "Local node constrains MTU to %d\n", max_mtu); | ||
277 | return -ERANGE; | ||
278 | } | ||
279 | |||
282 | dev->mtu = new_mtu; | 280 | dev->mtu = new_mtu; |
283 | return 0; | 281 | return 0; |
284 | } | 282 | } |
285 | 283 | ||
286 | static void purge_partial_datagram(struct list_head *old) | 284 | static void purge_partial_datagram(struct list_head *old) |
287 | { | 285 | { |
288 | struct partial_datagram *pd = list_entry(old, struct partial_datagram, list); | 286 | struct partial_datagram *pd; |
289 | struct list_head *lh, *n; | 287 | struct list_head *lh, *n; |
288 | struct fragment_info *fi; | ||
289 | |||
290 | pd = list_entry(old, struct partial_datagram, list); | ||
290 | 291 | ||
291 | list_for_each_safe(lh, n, &pd->frag_info) { | 292 | list_for_each_safe(lh, n, &pd->frag_info) { |
292 | struct fragment_info *fi = list_entry(lh, struct fragment_info, list); | 293 | fi = list_entry(lh, struct fragment_info, list); |
293 | list_del(lh); | 294 | list_del(lh); |
294 | kfree(fi); | 295 | kfree(fi); |
295 | } | 296 | } |
@@ -330,35 +331,26 @@ static struct eth1394_node_ref *eth1394_find_node_nodeid(struct list_head *inl, | |||
330 | nodeid_t nodeid) | 331 | nodeid_t nodeid) |
331 | { | 332 | { |
332 | struct eth1394_node_ref *node; | 333 | struct eth1394_node_ref *node; |
333 | list_for_each_entry(node, inl, list) { | 334 | |
335 | list_for_each_entry(node, inl, list) | ||
334 | if (node->ud->ne->nodeid == nodeid) | 336 | if (node->ud->ne->nodeid == nodeid) |
335 | return node; | 337 | return node; |
336 | } | ||
337 | 338 | ||
338 | return NULL; | 339 | return NULL; |
339 | } | 340 | } |
340 | 341 | ||
341 | static int eth1394_probe(struct device *dev) | 342 | static int eth1394_new_node(struct eth1394_host_info *hi, |
343 | struct unit_directory *ud) | ||
342 | { | 344 | { |
343 | struct unit_directory *ud; | ||
344 | struct eth1394_host_info *hi; | ||
345 | struct eth1394_priv *priv; | 345 | struct eth1394_priv *priv; |
346 | struct eth1394_node_ref *new_node; | 346 | struct eth1394_node_ref *new_node; |
347 | struct eth1394_node_info *node_info; | 347 | struct eth1394_node_info *node_info; |
348 | 348 | ||
349 | ud = container_of(dev, struct unit_directory, device); | 349 | new_node = kmalloc(sizeof(*new_node), GFP_KERNEL); |
350 | |||
351 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); | ||
352 | if (!hi) | ||
353 | return -ENOENT; | ||
354 | |||
355 | new_node = kmalloc(sizeof(*new_node), | ||
356 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | ||
357 | if (!new_node) | 350 | if (!new_node) |
358 | return -ENOMEM; | 351 | return -ENOMEM; |
359 | 352 | ||
360 | node_info = kmalloc(sizeof(*node_info), | 353 | node_info = kmalloc(sizeof(*node_info), GFP_KERNEL); |
361 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | ||
362 | if (!node_info) { | 354 | if (!node_info) { |
363 | kfree(new_node); | 355 | kfree(new_node); |
364 | return -ENOMEM; | 356 | return -ENOMEM; |
@@ -374,10 +366,22 @@ static int eth1394_probe(struct device *dev) | |||
374 | 366 | ||
375 | priv = netdev_priv(hi->dev); | 367 | priv = netdev_priv(hi->dev); |
376 | list_add_tail(&new_node->list, &priv->ip_node_list); | 368 | list_add_tail(&new_node->list, &priv->ip_node_list); |
377 | |||
378 | return 0; | 369 | return 0; |
379 | } | 370 | } |
380 | 371 | ||
372 | static int eth1394_probe(struct device *dev) | ||
373 | { | ||
374 | struct unit_directory *ud; | ||
375 | struct eth1394_host_info *hi; | ||
376 | |||
377 | ud = container_of(dev, struct unit_directory, device); | ||
378 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); | ||
379 | if (!hi) | ||
380 | return -ENOENT; | ||
381 | |||
382 | return eth1394_new_node(hi, ud); | ||
383 | } | ||
384 | |||
381 | static int eth1394_remove(struct device *dev) | 385 | static int eth1394_remove(struct device *dev) |
382 | { | 386 | { |
383 | struct unit_directory *ud; | 387 | struct unit_directory *ud; |
@@ -396,24 +400,23 @@ static int eth1394_remove(struct device *dev) | |||
396 | priv = netdev_priv(hi->dev); | 400 | priv = netdev_priv(hi->dev); |
397 | 401 | ||
398 | old_node = eth1394_find_node(&priv->ip_node_list, ud); | 402 | old_node = eth1394_find_node(&priv->ip_node_list, ud); |
403 | if (!old_node) | ||
404 | return 0; | ||
399 | 405 | ||
400 | if (old_node) { | 406 | list_del(&old_node->list); |
401 | list_del(&old_node->list); | 407 | kfree(old_node); |
402 | kfree(old_node); | ||
403 | 408 | ||
404 | node_info = (struct eth1394_node_info*)ud->device.driver_data; | 409 | node_info = (struct eth1394_node_info*)ud->device.driver_data; |
405 | 410 | ||
406 | spin_lock_irqsave(&node_info->pdg.lock, flags); | 411 | spin_lock_irqsave(&node_info->pdg.lock, flags); |
407 | /* The partial datagram list should be empty, but we'll just | 412 | /* The partial datagram list should be empty, but we'll just |
408 | * make sure anyway... */ | 413 | * make sure anyway... */ |
409 | list_for_each_safe(lh, n, &node_info->pdg.list) { | 414 | list_for_each_safe(lh, n, &node_info->pdg.list) |
410 | purge_partial_datagram(lh); | 415 | purge_partial_datagram(lh); |
411 | } | 416 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); |
412 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); | ||
413 | 417 | ||
414 | kfree(node_info); | 418 | kfree(node_info); |
415 | ud->device.driver_data = NULL; | 419 | ud->device.driver_data = NULL; |
416 | } | ||
417 | return 0; | 420 | return 0; |
418 | } | 421 | } |
419 | 422 | ||
@@ -422,44 +425,19 @@ static int eth1394_update(struct unit_directory *ud) | |||
422 | struct eth1394_host_info *hi; | 425 | struct eth1394_host_info *hi; |
423 | struct eth1394_priv *priv; | 426 | struct eth1394_priv *priv; |
424 | struct eth1394_node_ref *node; | 427 | struct eth1394_node_ref *node; |
425 | struct eth1394_node_info *node_info; | ||
426 | 428 | ||
427 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); | 429 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); |
428 | if (!hi) | 430 | if (!hi) |
429 | return -ENOENT; | 431 | return -ENOENT; |
430 | 432 | ||
431 | priv = netdev_priv(hi->dev); | 433 | priv = netdev_priv(hi->dev); |
432 | |||
433 | node = eth1394_find_node(&priv->ip_node_list, ud); | 434 | node = eth1394_find_node(&priv->ip_node_list, ud); |
435 | if (node) | ||
436 | return 0; | ||
434 | 437 | ||
435 | if (!node) { | 438 | return eth1394_new_node(hi, ud); |
436 | node = kmalloc(sizeof(*node), | ||
437 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | ||
438 | if (!node) | ||
439 | return -ENOMEM; | ||
440 | |||
441 | node_info = kmalloc(sizeof(*node_info), | ||
442 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | ||
443 | if (!node_info) { | ||
444 | kfree(node); | ||
445 | return -ENOMEM; | ||
446 | } | ||
447 | |||
448 | spin_lock_init(&node_info->pdg.lock); | ||
449 | INIT_LIST_HEAD(&node_info->pdg.list); | ||
450 | node_info->pdg.sz = 0; | ||
451 | |||
452 | ud->device.driver_data = node_info; | ||
453 | node->ud = ud; | ||
454 | |||
455 | priv = netdev_priv(hi->dev); | ||
456 | list_add_tail(&node->list, &priv->ip_node_list); | ||
457 | } | ||
458 | |||
459 | return 0; | ||
460 | } | 439 | } |
461 | 440 | ||
462 | |||
463 | static struct ieee1394_device_id eth1394_id_table[] = { | 441 | static struct ieee1394_device_id eth1394_id_table[] = { |
464 | { | 442 | { |
465 | .match_flags = (IEEE1394_MATCH_SPECIFIER_ID | | 443 | .match_flags = (IEEE1394_MATCH_SPECIFIER_ID | |
@@ -473,7 +451,7 @@ static struct ieee1394_device_id eth1394_id_table[] = { | |||
473 | MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table); | 451 | MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table); |
474 | 452 | ||
475 | static struct hpsb_protocol_driver eth1394_proto_driver = { | 453 | static struct hpsb_protocol_driver eth1394_proto_driver = { |
476 | .name = ETH1394_DRIVER_NAME, | 454 | .name = driver_name, |
477 | .id_table = eth1394_id_table, | 455 | .id_table = eth1394_id_table, |
478 | .update = eth1394_update, | 456 | .update = eth1394_update, |
479 | .driver = { | 457 | .driver = { |
@@ -482,47 +460,50 @@ static struct hpsb_protocol_driver eth1394_proto_driver = { | |||
482 | }, | 460 | }, |
483 | }; | 461 | }; |
484 | 462 | ||
485 | 463 | static void ether1394_reset_priv(struct net_device *dev, int set_mtu) | |
486 | static void ether1394_reset_priv (struct net_device *dev, int set_mtu) | ||
487 | { | 464 | { |
488 | unsigned long flags; | 465 | unsigned long flags; |
489 | int i; | 466 | int i; |
490 | struct eth1394_priv *priv = netdev_priv(dev); | 467 | struct eth1394_priv *priv = netdev_priv(dev); |
491 | struct hpsb_host *host = priv->host; | 468 | struct hpsb_host *host = priv->host; |
492 | u64 guid = get_unaligned((u64*)&(host->csr.rom->bus_info_data[3])); | 469 | u64 guid = get_unaligned((u64 *)&(host->csr.rom->bus_info_data[3])); |
493 | u16 maxpayload = 1 << (host->csr.max_rec + 1); | ||
494 | int max_speed = IEEE1394_SPEED_MAX; | 470 | int max_speed = IEEE1394_SPEED_MAX; |
495 | 471 | ||
496 | spin_lock_irqsave (&priv->lock, flags); | 472 | spin_lock_irqsave(&priv->lock, flags); |
497 | 473 | ||
498 | memset(priv->ud_list, 0, sizeof(struct node_entry*) * ALL_NODES); | 474 | memset(priv->ud_list, 0, sizeof(priv->ud_list)); |
499 | priv->bc_maxpayload = 512; | 475 | priv->bc_maxpayload = 512; |
500 | 476 | ||
501 | /* Determine speed limit */ | 477 | /* Determine speed limit */ |
502 | for (i = 0; i < host->node_count; i++) | 478 | /* FIXME: This is broken for nodes with link speed < PHY speed, |
479 | * and it is suboptimal for S200B...S800B hardware. | ||
480 | * The result of nodemgr's speed probe should be used somehow. */ | ||
481 | for (i = 0; i < host->node_count; i++) { | ||
482 | /* take care of S100B...S400B PHY ports */ | ||
483 | if (host->speed[i] == SELFID_SPEED_UNKNOWN) { | ||
484 | max_speed = IEEE1394_SPEED_100; | ||
485 | break; | ||
486 | } | ||
503 | if (max_speed > host->speed[i]) | 487 | if (max_speed > host->speed[i]) |
504 | max_speed = host->speed[i]; | 488 | max_speed = host->speed[i]; |
489 | } | ||
505 | priv->bc_sspd = max_speed; | 490 | priv->bc_sspd = max_speed; |
506 | 491 | ||
507 | /* We'll use our maxpayload as the default mtu */ | ||
508 | if (set_mtu) { | 492 | if (set_mtu) { |
509 | dev->mtu = min(ETH1394_DATA_LEN, | 493 | /* Use the RFC 2734 default 1500 octets or the maximum payload |
510 | (int)(maxpayload - | 494 | * as initial MTU */ |
511 | (sizeof(union eth1394_hdr) + | 495 | dev->mtu = min(1500, ether1394_max_mtu(host)); |
512 | ETHER1394_GASP_OVERHEAD))); | ||
513 | 496 | ||
514 | /* Set our hardware address while we're at it */ | 497 | /* Set our hardware address while we're at it */ |
515 | memcpy(dev->dev_addr, &guid, sizeof(u64)); | 498 | memcpy(dev->dev_addr, &guid, sizeof(u64)); |
516 | memset(dev->broadcast, 0xff, sizeof(u64)); | 499 | memset(dev->broadcast, 0xff, sizeof(u64)); |
517 | } | 500 | } |
518 | 501 | ||
519 | spin_unlock_irqrestore (&priv->lock, flags); | 502 | spin_unlock_irqrestore(&priv->lock, flags); |
520 | } | 503 | } |
521 | 504 | ||
522 | /* This function is called right before register_netdev */ | 505 | static void ether1394_init_dev(struct net_device *dev) |
523 | static void ether1394_init_dev (struct net_device *dev) | ||
524 | { | 506 | { |
525 | /* Our functions */ | ||
526 | dev->open = ether1394_open; | 507 | dev->open = ether1394_open; |
527 | dev->stop = ether1394_stop; | 508 | dev->stop = ether1394_stop; |
528 | dev->hard_start_xmit = ether1394_tx; | 509 | dev->hard_start_xmit = ether1394_tx; |
@@ -535,10 +516,9 @@ static void ether1394_init_dev (struct net_device *dev) | |||
535 | dev->hard_header_cache = ether1394_header_cache; | 516 | dev->hard_header_cache = ether1394_header_cache; |
536 | dev->header_cache_update= ether1394_header_cache_update; | 517 | dev->header_cache_update= ether1394_header_cache_update; |
537 | dev->hard_header_parse = ether1394_header_parse; | 518 | dev->hard_header_parse = ether1394_header_parse; |
538 | dev->set_mac_address = ether1394_mac_addr; | 519 | |
539 | SET_ETHTOOL_OPS(dev, ðtool_ops); | 520 | SET_ETHTOOL_OPS(dev, ðtool_ops); |
540 | 521 | ||
541 | /* Some constants */ | ||
542 | dev->watchdog_timeo = ETHER1394_TIMEOUT; | 522 | dev->watchdog_timeo = ETHER1394_TIMEOUT; |
543 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; | 523 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; |
544 | dev->features = NETIF_F_HIGHDMA; | 524 | dev->features = NETIF_F_HIGHDMA; |
@@ -546,7 +526,8 @@ static void ether1394_init_dev (struct net_device *dev) | |||
546 | dev->hard_header_len = ETH1394_HLEN; | 526 | dev->hard_header_len = ETH1394_HLEN; |
547 | dev->type = ARPHRD_IEEE1394; | 527 | dev->type = ARPHRD_IEEE1394; |
548 | 528 | ||
549 | ether1394_reset_priv (dev, 1); | 529 | /* FIXME: This value was copied from ether_setup(). Is it too much? */ |
530 | dev->tx_queue_len = 1000; | ||
550 | } | 531 | } |
551 | 532 | ||
552 | /* | 533 | /* |
@@ -554,34 +535,33 @@ static void ether1394_init_dev (struct net_device *dev) | |||
554 | * when the module is installed. This is where we add all of our ethernet | 535 | * when the module is installed. This is where we add all of our ethernet |
555 | * devices. One for each host. | 536 | * devices. One for each host. |
556 | */ | 537 | */ |
557 | static void ether1394_add_host (struct hpsb_host *host) | 538 | static void ether1394_add_host(struct hpsb_host *host) |
558 | { | 539 | { |
559 | struct eth1394_host_info *hi = NULL; | 540 | struct eth1394_host_info *hi = NULL; |
560 | struct net_device *dev = NULL; | 541 | struct net_device *dev = NULL; |
561 | struct eth1394_priv *priv; | 542 | struct eth1394_priv *priv; |
562 | u64 fifo_addr; | 543 | u64 fifo_addr; |
563 | 544 | ||
564 | if (!(host->config_roms & HPSB_CONFIG_ROM_ENTRY_IP1394)) | 545 | if (hpsb_config_rom_ip1394_add(host) != 0) { |
546 | ETH1394_PRINT_G(KERN_ERR, "Can't add IP-over-1394 ROM entry\n"); | ||
565 | return; | 547 | return; |
548 | } | ||
566 | 549 | ||
567 | fifo_addr = hpsb_allocate_and_register_addrspace( | 550 | fifo_addr = hpsb_allocate_and_register_addrspace( |
568 | ð1394_highlevel, host, &addr_ops, | 551 | ð1394_highlevel, host, &addr_ops, |
569 | ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN, | 552 | ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN, |
570 | CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE); | 553 | CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE); |
571 | if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) | 554 | if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) { |
572 | goto out; | 555 | ETH1394_PRINT_G(KERN_ERR, "Cannot register CSR space\n"); |
573 | 556 | hpsb_config_rom_ip1394_remove(host); | |
574 | /* We should really have our own alloc_hpsbdev() function in | 557 | return; |
575 | * net_init.c instead of calling the one for ethernet then hijacking | 558 | } |
576 | * it for ourselves. That way we'd be a real networking device. */ | ||
577 | dev = alloc_etherdev(sizeof (struct eth1394_priv)); | ||
578 | 559 | ||
560 | dev = alloc_netdev(sizeof(*priv), "eth%d", ether1394_init_dev); | ||
579 | if (dev == NULL) { | 561 | if (dev == NULL) { |
580 | ETH1394_PRINT_G (KERN_ERR, "Out of memory trying to allocate " | 562 | ETH1394_PRINT_G(KERN_ERR, "Out of memory\n"); |
581 | "etherdevice for IEEE 1394 device %s-%d\n", | ||
582 | host->driver->name, host->id); | ||
583 | goto out; | 563 | goto out; |
584 | } | 564 | } |
585 | 565 | ||
586 | SET_MODULE_OWNER(dev); | 566 | SET_MODULE_OWNER(dev); |
587 | #if 0 | 567 | #if 0 |
@@ -590,31 +570,26 @@ static void ether1394_add_host (struct hpsb_host *host) | |||
590 | #endif | 570 | #endif |
591 | 571 | ||
592 | priv = netdev_priv(dev); | 572 | priv = netdev_priv(dev); |
593 | |||
594 | INIT_LIST_HEAD(&priv->ip_node_list); | 573 | INIT_LIST_HEAD(&priv->ip_node_list); |
595 | |||
596 | spin_lock_init(&priv->lock); | 574 | spin_lock_init(&priv->lock); |
597 | priv->host = host; | 575 | priv->host = host; |
598 | priv->local_fifo = fifo_addr; | 576 | priv->local_fifo = fifo_addr; |
599 | 577 | ||
600 | hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi)); | 578 | hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi)); |
601 | |||
602 | if (hi == NULL) { | 579 | if (hi == NULL) { |
603 | ETH1394_PRINT_G (KERN_ERR, "Out of memory trying to create " | 580 | ETH1394_PRINT_G(KERN_ERR, "Out of memory\n"); |
604 | "hostinfo for IEEE 1394 device %s-%d\n", | ||
605 | host->driver->name, host->id); | ||
606 | goto out; | 581 | goto out; |
607 | } | 582 | } |
608 | 583 | ||
609 | ether1394_init_dev(dev); | 584 | ether1394_reset_priv(dev, 1); |
610 | 585 | ||
611 | if (register_netdev (dev)) { | 586 | if (register_netdev(dev)) { |
612 | ETH1394_PRINT (KERN_ERR, dev->name, "Error registering network driver\n"); | 587 | ETH1394_PRINT_G(KERN_ERR, "Cannot register the driver\n"); |
613 | goto out; | 588 | goto out; |
614 | } | 589 | } |
615 | 590 | ||
616 | ETH1394_PRINT (KERN_INFO, dev->name, "IEEE-1394 IPv4 over 1394 Ethernet (fw-host%d)\n", | 591 | ETH1394_PRINT(KERN_INFO, dev->name, "IPv4 over IEEE 1394 (fw-host%d)\n", |
617 | host->id); | 592 | host->id); |
618 | 593 | ||
619 | hi->host = host; | 594 | hi->host = host; |
620 | hi->dev = dev; | 595 | hi->dev = dev; |
@@ -623,61 +598,37 @@ static void ether1394_add_host (struct hpsb_host *host) | |||
623 | * be checked when the eth device is opened. */ | 598 | * be checked when the eth device is opened. */ |
624 | priv->broadcast_channel = host->csr.broadcast_channel & 0x3f; | 599 | priv->broadcast_channel = host->csr.broadcast_channel & 0x3f; |
625 | 600 | ||
626 | priv->iso = hpsb_iso_recv_init(host, | 601 | ether1394_recv_init(priv); |
627 | ETHER1394_ISO_BUF_SIZE, | ||
628 | ETHER1394_GASP_BUFFERS, | ||
629 | priv->broadcast_channel, | ||
630 | HPSB_ISO_DMA_PACKET_PER_BUFFER, | ||
631 | 1, ether1394_iso); | ||
632 | if (priv->iso == NULL) { | ||
633 | ETH1394_PRINT(KERN_ERR, dev->name, | ||
634 | "Could not allocate isochronous receive context " | ||
635 | "for the broadcast channel\n"); | ||
636 | priv->bc_state = ETHER1394_BC_ERROR; | ||
637 | } else { | ||
638 | if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0) | ||
639 | priv->bc_state = ETHER1394_BC_STOPPED; | ||
640 | else | ||
641 | priv->bc_state = ETHER1394_BC_RUNNING; | ||
642 | } | ||
643 | |||
644 | return; | 602 | return; |
645 | |||
646 | out: | 603 | out: |
647 | if (dev != NULL) | 604 | if (dev) |
648 | free_netdev(dev); | 605 | free_netdev(dev); |
649 | if (hi) | 606 | if (hi) |
650 | hpsb_destroy_hostinfo(ð1394_highlevel, host); | 607 | hpsb_destroy_hostinfo(ð1394_highlevel, host); |
651 | 608 | hpsb_unregister_addrspace(ð1394_highlevel, host, fifo_addr); | |
652 | return; | 609 | hpsb_config_rom_ip1394_remove(host); |
653 | } | 610 | } |
654 | 611 | ||
655 | /* Remove a card from our list */ | 612 | /* Remove a card from our list */ |
656 | static void ether1394_remove_host (struct hpsb_host *host) | 613 | static void ether1394_remove_host(struct hpsb_host *host) |
657 | { | 614 | { |
658 | struct eth1394_host_info *hi; | 615 | struct eth1394_host_info *hi; |
616 | struct eth1394_priv *priv; | ||
659 | 617 | ||
660 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); | 618 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
661 | if (hi != NULL) { | 619 | if (!hi) |
662 | struct eth1394_priv *priv = netdev_priv(hi->dev); | 620 | return; |
663 | 621 | priv = netdev_priv(hi->dev); | |
664 | hpsb_unregister_addrspace(ð1394_highlevel, host, | 622 | hpsb_unregister_addrspace(ð1394_highlevel, host, priv->local_fifo); |
665 | priv->local_fifo); | 623 | hpsb_config_rom_ip1394_remove(host); |
666 | 624 | if (priv->iso) | |
667 | if (priv->iso != NULL) | 625 | hpsb_iso_shutdown(priv->iso); |
668 | hpsb_iso_shutdown(priv->iso); | 626 | unregister_netdev(hi->dev); |
669 | 627 | free_netdev(hi->dev); | |
670 | if (hi->dev) { | ||
671 | unregister_netdev (hi->dev); | ||
672 | free_netdev(hi->dev); | ||
673 | } | ||
674 | } | ||
675 | |||
676 | return; | ||
677 | } | 628 | } |
678 | 629 | ||
679 | /* A reset has just arisen */ | 630 | /* A bus reset happened */ |
680 | static void ether1394_host_reset (struct hpsb_host *host) | 631 | static void ether1394_host_reset(struct hpsb_host *host) |
681 | { | 632 | { |
682 | struct eth1394_host_info *hi; | 633 | struct eth1394_host_info *hi; |
683 | struct eth1394_priv *priv; | 634 | struct eth1394_priv *priv; |
@@ -690,24 +641,23 @@ static void ether1394_host_reset (struct hpsb_host *host) | |||
690 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); | 641 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
691 | 642 | ||
692 | /* This can happen for hosts that we don't use */ | 643 | /* This can happen for hosts that we don't use */ |
693 | if (hi == NULL) | 644 | if (!hi) |
694 | return; | 645 | return; |
695 | 646 | ||
696 | dev = hi->dev; | 647 | dev = hi->dev; |
697 | priv = (struct eth1394_priv *)netdev_priv(dev); | 648 | priv = netdev_priv(dev); |
698 | 649 | ||
699 | /* Reset our private host data, but not our mtu */ | 650 | /* Reset our private host data, but not our MTU */ |
700 | netif_stop_queue (dev); | 651 | netif_stop_queue(dev); |
701 | ether1394_reset_priv (dev, 0); | 652 | ether1394_reset_priv(dev, 0); |
702 | 653 | ||
703 | list_for_each_entry(node, &priv->ip_node_list, list) { | 654 | list_for_each_entry(node, &priv->ip_node_list, list) { |
704 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; | 655 | node_info = node->ud->device.driver_data; |
705 | 656 | ||
706 | spin_lock_irqsave(&node_info->pdg.lock, flags); | 657 | spin_lock_irqsave(&node_info->pdg.lock, flags); |
707 | 658 | ||
708 | list_for_each_safe(lh, n, &node_info->pdg.list) { | 659 | list_for_each_safe(lh, n, &node_info->pdg.list) |
709 | purge_partial_datagram(lh); | 660 | purge_partial_datagram(lh); |
710 | } | ||
711 | 661 | ||
712 | INIT_LIST_HEAD(&(node_info->pdg.list)); | 662 | INIT_LIST_HEAD(&(node_info->pdg.list)); |
713 | node_info->pdg.sz = 0; | 663 | node_info->pdg.sz = 0; |
@@ -715,7 +665,7 @@ static void ether1394_host_reset (struct hpsb_host *host) | |||
715 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); | 665 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); |
716 | } | 666 | } |
717 | 667 | ||
718 | netif_wake_queue (dev); | 668 | netif_wake_queue(dev); |
719 | } | 669 | } |
720 | 670 | ||
721 | /****************************************** | 671 | /****************************************** |
@@ -723,7 +673,6 @@ static void ether1394_host_reset (struct hpsb_host *host) | |||
723 | ******************************************/ | 673 | ******************************************/ |
724 | /* These functions have been adapted from net/ethernet/eth.c */ | 674 | /* These functions have been adapted from net/ethernet/eth.c */ |
725 | 675 | ||
726 | |||
727 | /* Create a fake MAC header for an arbitrary protocol layer. | 676 | /* Create a fake MAC header for an arbitrary protocol layer. |
728 | * saddr=NULL means use device source address | 677 | * saddr=NULL means use device source address |
729 | * daddr=NULL means leave destination address (eg unresolved arp). */ | 678 | * daddr=NULL means leave destination address (eg unresolved arp). */ |
@@ -731,25 +680,24 @@ static int ether1394_header(struct sk_buff *skb, struct net_device *dev, | |||
731 | unsigned short type, void *daddr, void *saddr, | 680 | unsigned short type, void *daddr, void *saddr, |
732 | unsigned len) | 681 | unsigned len) |
733 | { | 682 | { |
734 | struct eth1394hdr *eth = (struct eth1394hdr *)skb_push(skb, ETH1394_HLEN); | 683 | struct eth1394hdr *eth = |
684 | (struct eth1394hdr *)skb_push(skb, ETH1394_HLEN); | ||
735 | 685 | ||
736 | eth->h_proto = htons(type); | 686 | eth->h_proto = htons(type); |
737 | 687 | ||
738 | if (dev->flags & (IFF_LOOPBACK|IFF_NOARP)) { | 688 | if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) { |
739 | memset(eth->h_dest, 0, dev->addr_len); | 689 | memset(eth->h_dest, 0, dev->addr_len); |
740 | return(dev->hard_header_len); | 690 | return dev->hard_header_len; |
741 | } | 691 | } |
742 | 692 | ||
743 | if (daddr) { | 693 | if (daddr) { |
744 | memcpy(eth->h_dest,daddr,dev->addr_len); | 694 | memcpy(eth->h_dest, daddr, dev->addr_len); |
745 | return dev->hard_header_len; | 695 | return dev->hard_header_len; |
746 | } | 696 | } |
747 | 697 | ||
748 | return -dev->hard_header_len; | 698 | return -dev->hard_header_len; |
749 | |||
750 | } | 699 | } |
751 | 700 | ||
752 | |||
753 | /* Rebuild the faked MAC header. This is called after an ARP | 701 | /* Rebuild the faked MAC header. This is called after an ARP |
754 | * (or in future other address resolution) has completed on this | 702 | * (or in future other address resolution) has completed on this |
755 | * sk_buff. We now let ARP fill in the other fields. | 703 | * sk_buff. We now let ARP fill in the other fields. |
@@ -760,38 +708,30 @@ static int ether1394_header(struct sk_buff *skb, struct net_device *dev, | |||
760 | static int ether1394_rebuild_header(struct sk_buff *skb) | 708 | static int ether1394_rebuild_header(struct sk_buff *skb) |
761 | { | 709 | { |
762 | struct eth1394hdr *eth = (struct eth1394hdr *)skb->data; | 710 | struct eth1394hdr *eth = (struct eth1394hdr *)skb->data; |
763 | struct net_device *dev = skb->dev; | ||
764 | 711 | ||
765 | switch (eth->h_proto) { | 712 | if (eth->h_proto == htons(ETH_P_IP)) |
766 | 713 | return arp_find((unsigned char *)ð->h_dest, skb); | |
767 | #ifdef CONFIG_INET | ||
768 | case __constant_htons(ETH_P_IP): | ||
769 | return arp_find((unsigned char*)ð->h_dest, skb); | ||
770 | #endif | ||
771 | default: | ||
772 | ETH1394_PRINT(KERN_DEBUG, dev->name, | ||
773 | "unable to resolve type %04x addresses.\n", | ||
774 | ntohs(eth->h_proto)); | ||
775 | break; | ||
776 | } | ||
777 | 714 | ||
715 | ETH1394_PRINT(KERN_DEBUG, skb->dev->name, | ||
716 | "unable to resolve type %04x addresses\n", | ||
717 | ntohs(eth->h_proto)); | ||
778 | return 0; | 718 | return 0; |
779 | } | 719 | } |
780 | 720 | ||
781 | static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr) | 721 | static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr) |
782 | { | 722 | { |
783 | struct net_device *dev = skb->dev; | 723 | struct net_device *dev = skb->dev; |
724 | |||
784 | memcpy(haddr, dev->dev_addr, ETH1394_ALEN); | 725 | memcpy(haddr, dev->dev_addr, ETH1394_ALEN); |
785 | return ETH1394_ALEN; | 726 | return ETH1394_ALEN; |
786 | } | 727 | } |
787 | 728 | ||
788 | |||
789 | static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh) | 729 | static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh) |
790 | { | 730 | { |
791 | unsigned short type = hh->hh_type; | 731 | unsigned short type = hh->hh_type; |
792 | struct eth1394hdr *eth = (struct eth1394hdr*)(((u8*)hh->hh_data) + | ||
793 | (16 - ETH1394_HLEN)); | ||
794 | struct net_device *dev = neigh->dev; | 732 | struct net_device *dev = neigh->dev; |
733 | struct eth1394hdr *eth = | ||
734 | (struct eth1394hdr *)((u8 *)hh->hh_data + 16 - ETH1394_HLEN); | ||
795 | 735 | ||
796 | if (type == htons(ETH_P_802_3)) | 736 | if (type == htons(ETH_P_802_3)) |
797 | return -1; | 737 | return -1; |
@@ -808,38 +748,25 @@ static void ether1394_header_cache_update(struct hh_cache *hh, | |||
808 | struct net_device *dev, | 748 | struct net_device *dev, |
809 | unsigned char * haddr) | 749 | unsigned char * haddr) |
810 | { | 750 | { |
811 | memcpy(((u8*)hh->hh_data) + (16 - ETH1394_HLEN), haddr, dev->addr_len); | 751 | memcpy((u8 *)hh->hh_data + 16 - ETH1394_HLEN, haddr, dev->addr_len); |
812 | } | 752 | } |
813 | 753 | ||
814 | static int ether1394_mac_addr(struct net_device *dev, void *p) | ||
815 | { | ||
816 | if (netif_running(dev)) | ||
817 | return -EBUSY; | ||
818 | |||
819 | /* Not going to allow setting the MAC address, we really need to use | ||
820 | * the real one supplied by the hardware */ | ||
821 | return -EINVAL; | ||
822 | } | ||
823 | |||
824 | |||
825 | |||
826 | /****************************************** | 754 | /****************************************** |
827 | * Datagram reception code | 755 | * Datagram reception code |
828 | ******************************************/ | 756 | ******************************************/ |
829 | 757 | ||
830 | /* Copied from net/ethernet/eth.c */ | 758 | /* Copied from net/ethernet/eth.c */ |
831 | static inline u16 ether1394_type_trans(struct sk_buff *skb, | 759 | static u16 ether1394_type_trans(struct sk_buff *skb, struct net_device *dev) |
832 | struct net_device *dev) | ||
833 | { | 760 | { |
834 | struct eth1394hdr *eth; | 761 | struct eth1394hdr *eth; |
835 | unsigned char *rawp; | 762 | unsigned char *rawp; |
836 | 763 | ||
837 | skb_reset_mac_header(skb); | 764 | skb_reset_mac_header(skb); |
838 | skb_pull (skb, ETH1394_HLEN); | 765 | skb_pull(skb, ETH1394_HLEN); |
839 | eth = eth1394_hdr(skb); | 766 | eth = eth1394_hdr(skb); |
840 | 767 | ||
841 | if (*eth->h_dest & 1) { | 768 | if (*eth->h_dest & 1) { |
842 | if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len)==0) | 769 | if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len) == 0) |
843 | skb->pkt_type = PACKET_BROADCAST; | 770 | skb->pkt_type = PACKET_BROADCAST; |
844 | #if 0 | 771 | #if 0 |
845 | else | 772 | else |
@@ -848,47 +775,45 @@ static inline u16 ether1394_type_trans(struct sk_buff *skb, | |||
848 | } else { | 775 | } else { |
849 | if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len)) | 776 | if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len)) |
850 | skb->pkt_type = PACKET_OTHERHOST; | 777 | skb->pkt_type = PACKET_OTHERHOST; |
851 | } | 778 | } |
852 | 779 | ||
853 | if (ntohs (eth->h_proto) >= 1536) | 780 | if (ntohs(eth->h_proto) >= 1536) |
854 | return eth->h_proto; | 781 | return eth->h_proto; |
855 | 782 | ||
856 | rawp = skb->data; | 783 | rawp = skb->data; |
857 | 784 | ||
858 | if (*(unsigned short *)rawp == 0xFFFF) | 785 | if (*(unsigned short *)rawp == 0xFFFF) |
859 | return htons (ETH_P_802_3); | 786 | return htons(ETH_P_802_3); |
860 | 787 | ||
861 | return htons (ETH_P_802_2); | 788 | return htons(ETH_P_802_2); |
862 | } | 789 | } |
863 | 790 | ||
864 | /* Parse an encapsulated IP1394 header into an ethernet frame packet. | 791 | /* Parse an encapsulated IP1394 header into an ethernet frame packet. |
865 | * We also perform ARP translation here, if need be. */ | 792 | * We also perform ARP translation here, if need be. */ |
866 | static inline u16 ether1394_parse_encap(struct sk_buff *skb, | 793 | static u16 ether1394_parse_encap(struct sk_buff *skb, struct net_device *dev, |
867 | struct net_device *dev, | 794 | nodeid_t srcid, nodeid_t destid, |
868 | nodeid_t srcid, nodeid_t destid, | 795 | u16 ether_type) |
869 | u16 ether_type) | ||
870 | { | 796 | { |
871 | struct eth1394_priv *priv = netdev_priv(dev); | 797 | struct eth1394_priv *priv = netdev_priv(dev); |
872 | u64 dest_hw; | 798 | u64 dest_hw; |
873 | unsigned short ret = 0; | 799 | unsigned short ret = 0; |
874 | 800 | ||
875 | /* Setup our hw addresses. We use these to build the | 801 | /* Setup our hw addresses. We use these to build the ethernet header. */ |
876 | * ethernet header. */ | ||
877 | if (destid == (LOCAL_BUS | ALL_NODES)) | 802 | if (destid == (LOCAL_BUS | ALL_NODES)) |
878 | dest_hw = ~0ULL; /* broadcast */ | 803 | dest_hw = ~0ULL; /* broadcast */ |
879 | else | 804 | else |
880 | dest_hw = cpu_to_be64((((u64)priv->host->csr.guid_hi) << 32) | | 805 | dest_hw = cpu_to_be64((u64)priv->host->csr.guid_hi << 32 | |
881 | priv->host->csr.guid_lo); | 806 | priv->host->csr.guid_lo); |
882 | 807 | ||
883 | /* If this is an ARP packet, convert it. First, we want to make | 808 | /* If this is an ARP packet, convert it. First, we want to make |
884 | * use of some of the fields, since they tell us a little bit | 809 | * use of some of the fields, since they tell us a little bit |
885 | * about the sending machine. */ | 810 | * about the sending machine. */ |
886 | if (ether_type == htons(ETH_P_ARP)) { | 811 | if (ether_type == htons(ETH_P_ARP)) { |
887 | struct eth1394_arp *arp1394 = (struct eth1394_arp*)skb->data; | 812 | struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data; |
888 | struct arphdr *arp = (struct arphdr *)skb->data; | 813 | struct arphdr *arp = (struct arphdr *)skb->data; |
889 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); | 814 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); |
890 | u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 | | 815 | u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 | |
891 | ntohl(arp1394->fifo_lo); | 816 | ntohl(arp1394->fifo_lo); |
892 | u8 max_rec = min(priv->host->csr.max_rec, | 817 | u8 max_rec = min(priv->host->csr.max_rec, |
893 | (u8)(arp1394->max_rec)); | 818 | (u8)(arp1394->max_rec)); |
894 | int sspd = arp1394->sspd; | 819 | int sspd = arp1394->sspd; |
@@ -902,16 +827,17 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb, | |||
902 | if (sspd > 5 || sspd < 0) | 827 | if (sspd > 5 || sspd < 0) |
903 | sspd = 0; | 828 | sspd = 0; |
904 | 829 | ||
905 | maxpayload = min(eth1394_speedto_maxpayload[sspd], (u16)(1 << (max_rec + 1))); | 830 | maxpayload = min(eth1394_speedto_maxpayload[sspd], |
831 | (u16)(1 << (max_rec + 1))); | ||
906 | 832 | ||
907 | guid = get_unaligned(&arp1394->s_uniq_id); | 833 | guid = get_unaligned(&arp1394->s_uniq_id); |
908 | node = eth1394_find_node_guid(&priv->ip_node_list, | 834 | node = eth1394_find_node_guid(&priv->ip_node_list, |
909 | be64_to_cpu(guid)); | 835 | be64_to_cpu(guid)); |
910 | if (!node) { | 836 | if (!node) |
911 | return 0; | 837 | return 0; |
912 | } | ||
913 | 838 | ||
914 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; | 839 | node_info = |
840 | (struct eth1394_node_info *)node->ud->device.driver_data; | ||
915 | 841 | ||
916 | /* Update our speed/payload/fifo_offset table */ | 842 | /* Update our speed/payload/fifo_offset table */ |
917 | node_info->maxpayload = maxpayload; | 843 | node_info->maxpayload = maxpayload; |
@@ -930,7 +856,7 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb, | |||
930 | 856 | ||
931 | arp->ar_hln = 8; | 857 | arp->ar_hln = 8; |
932 | arp_ptr += arp->ar_hln; /* skip over sender unique id */ | 858 | arp_ptr += arp->ar_hln; /* skip over sender unique id */ |
933 | *(u32*)arp_ptr = arp1394->sip; /* move sender IP addr */ | 859 | *(u32 *)arp_ptr = arp1394->sip; /* move sender IP addr */ |
934 | arp_ptr += arp->ar_pln; /* skip over sender IP addr */ | 860 | arp_ptr += arp->ar_pln; /* skip over sender IP addr */ |
935 | 861 | ||
936 | if (arp->ar_op == htons(ARPOP_REQUEST)) | 862 | if (arp->ar_op == htons(ARPOP_REQUEST)) |
@@ -947,65 +873,65 @@ static inline u16 ether1394_parse_encap(struct sk_buff *skb, | |||
947 | return ret; | 873 | return ret; |
948 | } | 874 | } |
949 | 875 | ||
950 | static inline int fragment_overlap(struct list_head *frag_list, int offset, int len) | 876 | static int fragment_overlap(struct list_head *frag_list, int offset, int len) |
951 | { | 877 | { |
952 | struct fragment_info *fi; | 878 | struct fragment_info *fi; |
879 | int end = offset + len; | ||
953 | 880 | ||
954 | list_for_each_entry(fi, frag_list, list) { | 881 | list_for_each_entry(fi, frag_list, list) |
955 | if ( ! ((offset > (fi->offset + fi->len - 1)) || | 882 | if (offset < fi->offset + fi->len && end > fi->offset) |
956 | ((offset + len - 1) < fi->offset))) | ||
957 | return 1; | 883 | return 1; |
958 | } | 884 | |
959 | return 0; | 885 | return 0; |
960 | } | 886 | } |
961 | 887 | ||
962 | static inline struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl) | 888 | static struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl) |
963 | { | 889 | { |
964 | struct partial_datagram *pd; | 890 | struct partial_datagram *pd; |
965 | 891 | ||
966 | list_for_each_entry(pd, pdgl, list) { | 892 | list_for_each_entry(pd, pdgl, list) |
967 | if (pd->dgl == dgl) | 893 | if (pd->dgl == dgl) |
968 | return &pd->list; | 894 | return &pd->list; |
969 | } | 895 | |
970 | return NULL; | 896 | return NULL; |
971 | } | 897 | } |
972 | 898 | ||
973 | /* Assumes that new fragment does not overlap any existing fragments */ | 899 | /* Assumes that new fragment does not overlap any existing fragments */ |
974 | static inline int new_fragment(struct list_head *frag_info, int offset, int len) | 900 | static int new_fragment(struct list_head *frag_info, int offset, int len) |
975 | { | 901 | { |
976 | struct list_head *lh; | 902 | struct list_head *lh; |
977 | struct fragment_info *fi, *fi2, *new; | 903 | struct fragment_info *fi, *fi2, *new; |
978 | 904 | ||
979 | list_for_each(lh, frag_info) { | 905 | list_for_each(lh, frag_info) { |
980 | fi = list_entry(lh, struct fragment_info, list); | 906 | fi = list_entry(lh, struct fragment_info, list); |
981 | if ((fi->offset + fi->len) == offset) { | 907 | if (fi->offset + fi->len == offset) { |
982 | /* The new fragment can be tacked on to the end */ | 908 | /* The new fragment can be tacked on to the end */ |
983 | fi->len += len; | 909 | fi->len += len; |
984 | /* Did the new fragment plug a hole? */ | 910 | /* Did the new fragment plug a hole? */ |
985 | fi2 = list_entry(lh->next, struct fragment_info, list); | 911 | fi2 = list_entry(lh->next, struct fragment_info, list); |
986 | if ((fi->offset + fi->len) == fi2->offset) { | 912 | if (fi->offset + fi->len == fi2->offset) { |
987 | /* glue fragments together */ | 913 | /* glue fragments together */ |
988 | fi->len += fi2->len; | 914 | fi->len += fi2->len; |
989 | list_del(lh->next); | 915 | list_del(lh->next); |
990 | kfree(fi2); | 916 | kfree(fi2); |
991 | } | 917 | } |
992 | return 0; | 918 | return 0; |
993 | } else if ((offset + len) == fi->offset) { | 919 | } else if (offset + len == fi->offset) { |
994 | /* The new fragment can be tacked on to the beginning */ | 920 | /* The new fragment can be tacked on to the beginning */ |
995 | fi->offset = offset; | 921 | fi->offset = offset; |
996 | fi->len += len; | 922 | fi->len += len; |
997 | /* Did the new fragment plug a hole? */ | 923 | /* Did the new fragment plug a hole? */ |
998 | fi2 = list_entry(lh->prev, struct fragment_info, list); | 924 | fi2 = list_entry(lh->prev, struct fragment_info, list); |
999 | if ((fi2->offset + fi2->len) == fi->offset) { | 925 | if (fi2->offset + fi2->len == fi->offset) { |
1000 | /* glue fragments together */ | 926 | /* glue fragments together */ |
1001 | fi2->len += fi->len; | 927 | fi2->len += fi->len; |
1002 | list_del(lh); | 928 | list_del(lh); |
1003 | kfree(fi); | 929 | kfree(fi); |
1004 | } | 930 | } |
1005 | return 0; | 931 | return 0; |
1006 | } else if (offset > (fi->offset + fi->len)) { | 932 | } else if (offset > fi->offset + fi->len) { |
1007 | break; | 933 | break; |
1008 | } else if ((offset + len) < fi->offset) { | 934 | } else if (offset + len < fi->offset) { |
1009 | lh = lh->prev; | 935 | lh = lh->prev; |
1010 | break; | 936 | break; |
1011 | } | 937 | } |
@@ -1019,14 +945,12 @@ static inline int new_fragment(struct list_head *frag_info, int offset, int len) | |||
1019 | new->len = len; | 945 | new->len = len; |
1020 | 946 | ||
1021 | list_add(&new->list, lh); | 947 | list_add(&new->list, lh); |
1022 | |||
1023 | return 0; | 948 | return 0; |
1024 | } | 949 | } |
1025 | 950 | ||
1026 | static inline int new_partial_datagram(struct net_device *dev, | 951 | static int new_partial_datagram(struct net_device *dev, struct list_head *pdgl, |
1027 | struct list_head *pdgl, int dgl, | 952 | int dgl, int dg_size, char *frag_buf, |
1028 | int dg_size, char *frag_buf, | 953 | int frag_off, int frag_len) |
1029 | int frag_off, int frag_len) | ||
1030 | { | 954 | { |
1031 | struct partial_datagram *new; | 955 | struct partial_datagram *new; |
1032 | 956 | ||
@@ -1059,33 +983,33 @@ static inline int new_partial_datagram(struct net_device *dev, | |||
1059 | memcpy(new->pbuf + frag_off, frag_buf, frag_len); | 983 | memcpy(new->pbuf + frag_off, frag_buf, frag_len); |
1060 | 984 | ||
1061 | list_add(&new->list, pdgl); | 985 | list_add(&new->list, pdgl); |
1062 | |||
1063 | return 0; | 986 | return 0; |
1064 | } | 987 | } |
1065 | 988 | ||
1066 | static inline int update_partial_datagram(struct list_head *pdgl, struct list_head *lh, | 989 | static int update_partial_datagram(struct list_head *pdgl, struct list_head *lh, |
1067 | char *frag_buf, int frag_off, int frag_len) | 990 | char *frag_buf, int frag_off, int frag_len) |
1068 | { | 991 | { |
1069 | struct partial_datagram *pd = list_entry(lh, struct partial_datagram, list); | 992 | struct partial_datagram *pd = |
993 | list_entry(lh, struct partial_datagram, list); | ||
1070 | 994 | ||
1071 | if (new_fragment(&pd->frag_info, frag_off, frag_len) < 0) { | 995 | if (new_fragment(&pd->frag_info, frag_off, frag_len) < 0) |
1072 | return -ENOMEM; | 996 | return -ENOMEM; |
1073 | } | ||
1074 | 997 | ||
1075 | memcpy(pd->pbuf + frag_off, frag_buf, frag_len); | 998 | memcpy(pd->pbuf + frag_off, frag_buf, frag_len); |
1076 | 999 | ||
1077 | /* Move list entry to beginnig of list so that oldest partial | 1000 | /* Move list entry to beginnig of list so that oldest partial |
1078 | * datagrams percolate to the end of the list */ | 1001 | * datagrams percolate to the end of the list */ |
1079 | list_move(lh, pdgl); | 1002 | list_move(lh, pdgl); |
1080 | |||
1081 | return 0; | 1003 | return 0; |
1082 | } | 1004 | } |
1083 | 1005 | ||
1084 | static inline int is_datagram_complete(struct list_head *lh, int dg_size) | 1006 | static int is_datagram_complete(struct list_head *lh, int dg_size) |
1085 | { | 1007 | { |
1086 | struct partial_datagram *pd = list_entry(lh, struct partial_datagram, list); | 1008 | struct partial_datagram *pd; |
1087 | struct fragment_info *fi = list_entry(pd->frag_info.next, | 1009 | struct fragment_info *fi; |
1088 | struct fragment_info, list); | 1010 | |
1011 | pd = list_entry(lh, struct partial_datagram, list); | ||
1012 | fi = list_entry(pd->frag_info.next, struct fragment_info, list); | ||
1089 | 1013 | ||
1090 | return (fi->len == dg_size); | 1014 | return (fi->len == dg_size); |
1091 | } | 1015 | } |
@@ -1108,7 +1032,7 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, | |||
1108 | if (!ud) { | 1032 | if (!ud) { |
1109 | struct eth1394_node_ref *node; | 1033 | struct eth1394_node_ref *node; |
1110 | node = eth1394_find_node_nodeid(&priv->ip_node_list, srcid); | 1034 | node = eth1394_find_node_nodeid(&priv->ip_node_list, srcid); |
1111 | if (!node) { | 1035 | if (unlikely(!node)) { |
1112 | HPSB_PRINT(KERN_ERR, "ether1394 rx: sender nodeid " | 1036 | HPSB_PRINT(KERN_ERR, "ether1394 rx: sender nodeid " |
1113 | "lookup failure: " NODE_BUS_FMT, | 1037 | "lookup failure: " NODE_BUS_FMT, |
1114 | NODE_BUS_ARGS(priv->host, srcid)); | 1038 | NODE_BUS_ARGS(priv->host, srcid)); |
@@ -1120,7 +1044,7 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, | |||
1120 | priv->ud_list[NODEID_TO_NODE(srcid)] = ud; | 1044 | priv->ud_list[NODEID_TO_NODE(srcid)] = ud; |
1121 | } | 1045 | } |
1122 | 1046 | ||
1123 | node_info = (struct eth1394_node_info*)ud->device.driver_data; | 1047 | node_info = (struct eth1394_node_info *)ud->device.driver_data; |
1124 | 1048 | ||
1125 | /* First, did we receive a fragmented or unfragmented datagram? */ | 1049 | /* First, did we receive a fragmented or unfragmented datagram? */ |
1126 | hdr->words.word1 = ntohs(hdr->words.word1); | 1050 | hdr->words.word1 = ntohs(hdr->words.word1); |
@@ -1133,13 +1057,14 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, | |||
1133 | * high level network layer. */ | 1057 | * high level network layer. */ |
1134 | 1058 | ||
1135 | skb = dev_alloc_skb(len + dev->hard_header_len + 15); | 1059 | skb = dev_alloc_skb(len + dev->hard_header_len + 15); |
1136 | if (!skb) { | 1060 | if (unlikely(!skb)) { |
1137 | HPSB_PRINT (KERN_ERR, "ether1394 rx: low on mem\n"); | 1061 | ETH1394_PRINT_G(KERN_ERR, "Out of memory\n"); |
1138 | priv->stats.rx_dropped++; | 1062 | priv->stats.rx_dropped++; |
1139 | return -1; | 1063 | return -1; |
1140 | } | 1064 | } |
1141 | skb_reserve(skb, (dev->hard_header_len + 15) & ~15); | 1065 | skb_reserve(skb, (dev->hard_header_len + 15) & ~15); |
1142 | memcpy(skb_put(skb, len - hdr_len), buf + hdr_len, len - hdr_len); | 1066 | memcpy(skb_put(skb, len - hdr_len), buf + hdr_len, |
1067 | len - hdr_len); | ||
1143 | ether_type = hdr->uf.ether_type; | 1068 | ether_type = hdr->uf.ether_type; |
1144 | } else { | 1069 | } else { |
1145 | /* A datagram fragment has been received, now the fun begins. */ | 1070 | /* A datagram fragment has been received, now the fun begins. */ |
@@ -1224,9 +1149,8 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, | |||
1224 | 1149 | ||
1225 | pd = list_entry(lh, struct partial_datagram, list); | 1150 | pd = list_entry(lh, struct partial_datagram, list); |
1226 | 1151 | ||
1227 | if (hdr->common.lf == ETH1394_HDR_LF_FF) { | 1152 | if (hdr->common.lf == ETH1394_HDR_LF_FF) |
1228 | pd->ether_type = ether_type; | 1153 | pd->ether_type = ether_type; |
1229 | } | ||
1230 | 1154 | ||
1231 | if (is_datagram_complete(lh, dg_size)) { | 1155 | if (is_datagram_complete(lh, dg_size)) { |
1232 | ether_type = pd->ether_type; | 1156 | ether_type = pd->ether_type; |
@@ -1253,8 +1177,8 @@ static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, | |||
1253 | skb->protocol = ether1394_parse_encap(skb, dev, srcid, destid, | 1177 | skb->protocol = ether1394_parse_encap(skb, dev, srcid, destid, |
1254 | ether_type); | 1178 | ether_type); |
1255 | 1179 | ||
1256 | |||
1257 | spin_lock_irqsave(&priv->lock, flags); | 1180 | spin_lock_irqsave(&priv->lock, flags); |
1181 | |||
1258 | if (!skb->protocol) { | 1182 | if (!skb->protocol) { |
1259 | priv->stats.rx_errors++; | 1183 | priv->stats.rx_errors++; |
1260 | priv->stats.rx_dropped++; | 1184 | priv->stats.rx_dropped++; |
@@ -1288,9 +1212,9 @@ static int ether1394_write(struct hpsb_host *host, int srcid, int destid, | |||
1288 | struct eth1394_host_info *hi; | 1212 | struct eth1394_host_info *hi; |
1289 | 1213 | ||
1290 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); | 1214 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
1291 | if (hi == NULL) { | 1215 | if (unlikely(!hi)) { |
1292 | ETH1394_PRINT_G(KERN_ERR, "Could not find net device for host %s\n", | 1216 | ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n", |
1293 | host->driver->name); | 1217 | host->id); |
1294 | return RCODE_ADDRESS_ERROR; | 1218 | return RCODE_ADDRESS_ERROR; |
1295 | } | 1219 | } |
1296 | 1220 | ||
@@ -1314,9 +1238,9 @@ static void ether1394_iso(struct hpsb_iso *iso) | |||
1314 | int nready; | 1238 | int nready; |
1315 | 1239 | ||
1316 | hi = hpsb_get_hostinfo(ð1394_highlevel, iso->host); | 1240 | hi = hpsb_get_hostinfo(ð1394_highlevel, iso->host); |
1317 | if (hi == NULL) { | 1241 | if (unlikely(!hi)) { |
1318 | ETH1394_PRINT_G(KERN_ERR, "Could not find net device for host %s\n", | 1242 | ETH1394_PRINT_G(KERN_ERR, "No net device at fw-host%d\n", |
1319 | iso->host->driver->name); | 1243 | iso->host->id); |
1320 | return; | 1244 | return; |
1321 | } | 1245 | } |
1322 | 1246 | ||
@@ -1326,20 +1250,20 @@ static void ether1394_iso(struct hpsb_iso *iso) | |||
1326 | for (i = 0; i < nready; i++) { | 1250 | for (i = 0; i < nready; i++) { |
1327 | struct hpsb_iso_packet_info *info = | 1251 | struct hpsb_iso_packet_info *info = |
1328 | &iso->infos[(iso->first_packet + i) % iso->buf_packets]; | 1252 | &iso->infos[(iso->first_packet + i) % iso->buf_packets]; |
1329 | data = (quadlet_t*) (iso->data_buf.kvirt + info->offset); | 1253 | data = (quadlet_t *)(iso->data_buf.kvirt + info->offset); |
1330 | 1254 | ||
1331 | /* skip over GASP header */ | 1255 | /* skip over GASP header */ |
1332 | buf = (char *)data + 8; | 1256 | buf = (char *)data + 8; |
1333 | len = info->len - 8; | 1257 | len = info->len - 8; |
1334 | 1258 | ||
1335 | specifier_id = (((be32_to_cpu(data[0]) & 0xffff) << 8) | | 1259 | specifier_id = (be32_to_cpu(data[0]) & 0xffff) << 8 | |
1336 | ((be32_to_cpu(data[1]) & 0xff000000) >> 24)); | 1260 | (be32_to_cpu(data[1]) & 0xff000000) >> 24; |
1337 | source_id = be32_to_cpu(data[0]) >> 16; | 1261 | source_id = be32_to_cpu(data[0]) >> 16; |
1338 | 1262 | ||
1339 | priv = netdev_priv(dev); | 1263 | priv = netdev_priv(dev); |
1340 | 1264 | ||
1341 | if (info->channel != (iso->host->csr.broadcast_channel & 0x3f) || | 1265 | if (info->channel != (iso->host->csr.broadcast_channel & 0x3f) |
1342 | specifier_id != ETHER1394_GASP_SPECIFIER_ID) { | 1266 | || specifier_id != ETHER1394_GASP_SPECIFIER_ID) { |
1343 | /* This packet is not for us */ | 1267 | /* This packet is not for us */ |
1344 | continue; | 1268 | continue; |
1345 | } | 1269 | } |
@@ -1367,35 +1291,31 @@ static void ether1394_iso(struct hpsb_iso *iso) | |||
1367 | * speed, and unicast FIFO address information between the sender_unique_id | 1291 | * speed, and unicast FIFO address information between the sender_unique_id |
1368 | * and the IP addresses. | 1292 | * and the IP addresses. |
1369 | */ | 1293 | */ |
1370 | static inline void ether1394_arp_to_1394arp(struct sk_buff *skb, | 1294 | static void ether1394_arp_to_1394arp(struct sk_buff *skb, |
1371 | struct net_device *dev) | 1295 | struct net_device *dev) |
1372 | { | 1296 | { |
1373 | struct eth1394_priv *priv = netdev_priv(dev); | 1297 | struct eth1394_priv *priv = netdev_priv(dev); |
1374 | |||
1375 | struct arphdr *arp = (struct arphdr *)skb->data; | 1298 | struct arphdr *arp = (struct arphdr *)skb->data; |
1376 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); | 1299 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); |
1377 | struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data; | 1300 | struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data; |
1378 | 1301 | ||
1379 | /* Believe it or not, all that need to happen is sender IP get moved | ||
1380 | * and set hw_addr_len, max_rec, sspd, fifo_hi and fifo_lo. */ | ||
1381 | arp1394->hw_addr_len = 16; | 1302 | arp1394->hw_addr_len = 16; |
1382 | arp1394->sip = *(u32*)(arp_ptr + ETH1394_ALEN); | 1303 | arp1394->sip = *(u32*)(arp_ptr + ETH1394_ALEN); |
1383 | arp1394->max_rec = priv->host->csr.max_rec; | 1304 | arp1394->max_rec = priv->host->csr.max_rec; |
1384 | arp1394->sspd = priv->host->csr.lnk_spd; | 1305 | arp1394->sspd = priv->host->csr.lnk_spd; |
1385 | arp1394->fifo_hi = htons (priv->local_fifo >> 32); | 1306 | arp1394->fifo_hi = htons(priv->local_fifo >> 32); |
1386 | arp1394->fifo_lo = htonl (priv->local_fifo & ~0x0); | 1307 | arp1394->fifo_lo = htonl(priv->local_fifo & ~0x0); |
1387 | |||
1388 | return; | ||
1389 | } | 1308 | } |
1390 | 1309 | ||
1391 | /* We need to encapsulate the standard header with our own. We use the | 1310 | /* We need to encapsulate the standard header with our own. We use the |
1392 | * ethernet header's proto for our own. */ | 1311 | * ethernet header's proto for our own. */ |
1393 | static inline unsigned int ether1394_encapsulate_prep(unsigned int max_payload, | 1312 | static unsigned int ether1394_encapsulate_prep(unsigned int max_payload, |
1394 | __be16 proto, | 1313 | __be16 proto, |
1395 | union eth1394_hdr *hdr, | 1314 | union eth1394_hdr *hdr, |
1396 | u16 dg_size, u16 dgl) | 1315 | u16 dg_size, u16 dgl) |
1397 | { | 1316 | { |
1398 | unsigned int adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_UF]; | 1317 | unsigned int adj_max_payload = |
1318 | max_payload - hdr_type_len[ETH1394_HDR_LF_UF]; | ||
1399 | 1319 | ||
1400 | /* Does it all fit in one packet? */ | 1320 | /* Does it all fit in one packet? */ |
1401 | if (dg_size <= adj_max_payload) { | 1321 | if (dg_size <= adj_max_payload) { |
@@ -1408,19 +1328,19 @@ static inline unsigned int ether1394_encapsulate_prep(unsigned int max_payload, | |||
1408 | hdr->ff.dgl = dgl; | 1328 | hdr->ff.dgl = dgl; |
1409 | adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF]; | 1329 | adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF]; |
1410 | } | 1330 | } |
1411 | return((dg_size + (adj_max_payload - 1)) / adj_max_payload); | 1331 | return (dg_size + adj_max_payload - 1) / adj_max_payload; |
1412 | } | 1332 | } |
1413 | 1333 | ||
1414 | static inline unsigned int ether1394_encapsulate(struct sk_buff *skb, | 1334 | static unsigned int ether1394_encapsulate(struct sk_buff *skb, |
1415 | unsigned int max_payload, | 1335 | unsigned int max_payload, |
1416 | union eth1394_hdr *hdr) | 1336 | union eth1394_hdr *hdr) |
1417 | { | 1337 | { |
1418 | union eth1394_hdr *bufhdr; | 1338 | union eth1394_hdr *bufhdr; |
1419 | int ftype = hdr->common.lf; | 1339 | int ftype = hdr->common.lf; |
1420 | int hdrsz = hdr_type_len[ftype]; | 1340 | int hdrsz = hdr_type_len[ftype]; |
1421 | unsigned int adj_max_payload = max_payload - hdrsz; | 1341 | unsigned int adj_max_payload = max_payload - hdrsz; |
1422 | 1342 | ||
1423 | switch(ftype) { | 1343 | switch (ftype) { |
1424 | case ETH1394_HDR_LF_UF: | 1344 | case ETH1394_HDR_LF_UF: |
1425 | bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz); | 1345 | bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz); |
1426 | bufhdr->words.word1 = htons(hdr->words.word1); | 1346 | bufhdr->words.word1 = htons(hdr->words.word1); |
@@ -1449,11 +1369,10 @@ static inline unsigned int ether1394_encapsulate(struct sk_buff *skb, | |||
1449 | bufhdr->words.word3 = htons(hdr->words.word3); | 1369 | bufhdr->words.word3 = htons(hdr->words.word3); |
1450 | bufhdr->words.word4 = 0; | 1370 | bufhdr->words.word4 = 0; |
1451 | } | 1371 | } |
1452 | |||
1453 | return min(max_payload, skb->len); | 1372 | return min(max_payload, skb->len); |
1454 | } | 1373 | } |
1455 | 1374 | ||
1456 | static inline struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host *host) | 1375 | static struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host *host) |
1457 | { | 1376 | { |
1458 | struct hpsb_packet *p; | 1377 | struct hpsb_packet *p; |
1459 | 1378 | ||
@@ -1466,61 +1385,57 @@ static inline struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host | |||
1466 | return p; | 1385 | return p; |
1467 | } | 1386 | } |
1468 | 1387 | ||
1469 | static inline int ether1394_prep_write_packet(struct hpsb_packet *p, | 1388 | static int ether1394_prep_write_packet(struct hpsb_packet *p, |
1470 | struct hpsb_host *host, | 1389 | struct hpsb_host *host, nodeid_t node, |
1471 | nodeid_t node, u64 addr, | 1390 | u64 addr, void *data, int tx_len) |
1472 | void * data, int tx_len) | ||
1473 | { | 1391 | { |
1474 | p->node_id = node; | 1392 | p->node_id = node; |
1475 | p->data = NULL; | 1393 | p->data = NULL; |
1476 | 1394 | ||
1477 | p->tcode = TCODE_WRITEB; | 1395 | p->tcode = TCODE_WRITEB; |
1478 | p->header[1] = (host->node_id << 16) | (addr >> 32); | 1396 | p->header[1] = host->node_id << 16 | addr >> 32; |
1479 | p->header[2] = addr & 0xffffffff; | 1397 | p->header[2] = addr & 0xffffffff; |
1480 | 1398 | ||
1481 | p->header_size = 16; | 1399 | p->header_size = 16; |
1482 | p->expect_response = 1; | 1400 | p->expect_response = 1; |
1483 | 1401 | ||
1484 | if (hpsb_get_tlabel(p)) { | 1402 | if (hpsb_get_tlabel(p)) { |
1485 | ETH1394_PRINT_G(KERN_ERR, "No more tlabels left while sending " | 1403 | ETH1394_PRINT_G(KERN_ERR, "Out of tlabels\n"); |
1486 | "to node " NODE_BUS_FMT "\n", NODE_BUS_ARGS(host, node)); | ||
1487 | return -1; | 1404 | return -1; |
1488 | } | 1405 | } |
1489 | p->header[0] = (p->node_id << 16) | (p->tlabel << 10) | 1406 | p->header[0] = |
1490 | | (1 << 8) | (TCODE_WRITEB << 4); | 1407 | p->node_id << 16 | p->tlabel << 10 | 1 << 8 | TCODE_WRITEB << 4; |
1491 | 1408 | ||
1492 | p->header[3] = tx_len << 16; | 1409 | p->header[3] = tx_len << 16; |
1493 | p->data_size = (tx_len + 3) & ~3; | 1410 | p->data_size = (tx_len + 3) & ~3; |
1494 | p->data = (quadlet_t*)data; | 1411 | p->data = data; |
1495 | 1412 | ||
1496 | return 0; | 1413 | return 0; |
1497 | } | 1414 | } |
1498 | 1415 | ||
1499 | static inline void ether1394_prep_gasp_packet(struct hpsb_packet *p, | 1416 | static void ether1394_prep_gasp_packet(struct hpsb_packet *p, |
1500 | struct eth1394_priv *priv, | 1417 | struct eth1394_priv *priv, |
1501 | struct sk_buff *skb, int length) | 1418 | struct sk_buff *skb, int length) |
1502 | { | 1419 | { |
1503 | p->header_size = 4; | 1420 | p->header_size = 4; |
1504 | p->tcode = TCODE_STREAM_DATA; | 1421 | p->tcode = TCODE_STREAM_DATA; |
1505 | 1422 | ||
1506 | p->header[0] = (length << 16) | (3 << 14) | 1423 | p->header[0] = length << 16 | 3 << 14 | priv->broadcast_channel << 8 | |
1507 | | ((priv->broadcast_channel) << 8) | 1424 | TCODE_STREAM_DATA << 4; |
1508 | | (TCODE_STREAM_DATA << 4); | ||
1509 | p->data_size = length; | 1425 | p->data_size = length; |
1510 | p->data = ((quadlet_t*)skb->data) - 2; | 1426 | p->data = (quadlet_t *)skb->data - 2; |
1511 | p->data[0] = cpu_to_be32((priv->host->node_id << 16) | | 1427 | p->data[0] = cpu_to_be32(priv->host->node_id << 16 | |
1512 | ETHER1394_GASP_SPECIFIER_ID_HI); | 1428 | ETHER1394_GASP_SPECIFIER_ID_HI); |
1513 | p->data[1] = cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) | | 1429 | p->data[1] = cpu_to_be32(ETHER1394_GASP_SPECIFIER_ID_LO << 24 | |
1514 | ETHER1394_GASP_VERSION); | 1430 | ETHER1394_GASP_VERSION); |
1515 | 1431 | ||
1516 | /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES) | ||
1517 | * prevents hpsb_send_packet() from setting the speed to an arbitrary | ||
1518 | * value based on packet->node_id if packet->node_id is not set. */ | ||
1519 | p->node_id = ALL_NODES; | ||
1520 | p->speed_code = priv->bc_sspd; | 1432 | p->speed_code = priv->bc_sspd; |
1433 | |||
1434 | /* prevent hpsb_send_packet() from overriding our speed code */ | ||
1435 | p->node_id = LOCAL_BUS | ALL_NODES; | ||
1521 | } | 1436 | } |
1522 | 1437 | ||
1523 | static inline void ether1394_free_packet(struct hpsb_packet *packet) | 1438 | static void ether1394_free_packet(struct hpsb_packet *packet) |
1524 | { | 1439 | { |
1525 | if (packet->tcode != TCODE_STREAM_DATA) | 1440 | if (packet->tcode != TCODE_STREAM_DATA) |
1526 | hpsb_free_tlabel(packet); | 1441 | hpsb_free_tlabel(packet); |
@@ -1539,7 +1454,7 @@ static int ether1394_send_packet(struct packet_task *ptask, unsigned int tx_len) | |||
1539 | return -1; | 1454 | return -1; |
1540 | 1455 | ||
1541 | if (ptask->tx_type == ETH1394_GASP) { | 1456 | if (ptask->tx_type == ETH1394_GASP) { |
1542 | int length = tx_len + (2 * sizeof(quadlet_t)); | 1457 | int length = tx_len + 2 * sizeof(quadlet_t); |
1543 | 1458 | ||
1544 | ether1394_prep_gasp_packet(packet, priv, ptask->skb, length); | 1459 | ether1394_prep_gasp_packet(packet, priv, ptask->skb, length); |
1545 | } else if (ether1394_prep_write_packet(packet, priv->host, | 1460 | } else if (ether1394_prep_write_packet(packet, priv->host, |
@@ -1562,13 +1477,11 @@ static int ether1394_send_packet(struct packet_task *ptask, unsigned int tx_len) | |||
1562 | return 0; | 1477 | return 0; |
1563 | } | 1478 | } |
1564 | 1479 | ||
1565 | |||
1566 | /* Task function to be run when a datagram transmission is completed */ | 1480 | /* Task function to be run when a datagram transmission is completed */ |
1567 | static inline void ether1394_dg_complete(struct packet_task *ptask, int fail) | 1481 | static void ether1394_dg_complete(struct packet_task *ptask, int fail) |
1568 | { | 1482 | { |
1569 | struct sk_buff *skb = ptask->skb; | 1483 | struct sk_buff *skb = ptask->skb; |
1570 | struct net_device *dev = skb->dev; | 1484 | struct eth1394_priv *priv = netdev_priv(skb->dev); |
1571 | struct eth1394_priv *priv = netdev_priv(dev); | ||
1572 | unsigned long flags; | 1485 | unsigned long flags; |
1573 | 1486 | ||
1574 | /* Statistics */ | 1487 | /* Statistics */ |
@@ -1586,7 +1499,6 @@ static inline void ether1394_dg_complete(struct packet_task *ptask, int fail) | |||
1586 | kmem_cache_free(packet_task_cache, ptask); | 1499 | kmem_cache_free(packet_task_cache, ptask); |
1587 | } | 1500 | } |
1588 | 1501 | ||
1589 | |||
1590 | /* Callback for when a packet has been sent and the status of that packet is | 1502 | /* Callback for when a packet has been sent and the status of that packet is |
1591 | * known */ | 1503 | * known */ |
1592 | static void ether1394_complete_cb(void *__ptask) | 1504 | static void ether1394_complete_cb(void *__ptask) |
@@ -1614,19 +1526,15 @@ static void ether1394_complete_cb(void *__ptask) | |||
1614 | } | 1526 | } |
1615 | } | 1527 | } |
1616 | 1528 | ||
1617 | |||
1618 | |||
1619 | /* Transmit a packet (called by kernel) */ | 1529 | /* Transmit a packet (called by kernel) */ |
1620 | static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | 1530 | static int ether1394_tx(struct sk_buff *skb, struct net_device *dev) |
1621 | { | 1531 | { |
1622 | gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; | ||
1623 | struct eth1394hdr *eth; | 1532 | struct eth1394hdr *eth; |
1624 | struct eth1394_priv *priv = netdev_priv(dev); | 1533 | struct eth1394_priv *priv = netdev_priv(dev); |
1625 | __be16 proto; | 1534 | __be16 proto; |
1626 | unsigned long flags; | 1535 | unsigned long flags; |
1627 | nodeid_t dest_node; | 1536 | nodeid_t dest_node; |
1628 | eth1394_tx_type tx_type; | 1537 | eth1394_tx_type tx_type; |
1629 | int ret = 0; | ||
1630 | unsigned int tx_len; | 1538 | unsigned int tx_len; |
1631 | unsigned int max_payload; | 1539 | unsigned int max_payload; |
1632 | u16 dg_size; | 1540 | u16 dg_size; |
@@ -1635,29 +1543,24 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1635 | struct eth1394_node_ref *node; | 1543 | struct eth1394_node_ref *node; |
1636 | struct eth1394_node_info *node_info = NULL; | 1544 | struct eth1394_node_info *node_info = NULL; |
1637 | 1545 | ||
1638 | ptask = kmem_cache_alloc(packet_task_cache, kmflags); | 1546 | ptask = kmem_cache_alloc(packet_task_cache, GFP_ATOMIC); |
1639 | if (ptask == NULL) { | 1547 | if (ptask == NULL) |
1640 | ret = -ENOMEM; | ||
1641 | goto fail; | 1548 | goto fail; |
1642 | } | ||
1643 | 1549 | ||
1644 | /* XXX Ignore this for now. Noticed that when MacOSX is the IRM, | 1550 | /* XXX Ignore this for now. Noticed that when MacOSX is the IRM, |
1645 | * it does not set our validity bit. We need to compensate for | 1551 | * it does not set our validity bit. We need to compensate for |
1646 | * that somewhere else, but not in eth1394. */ | 1552 | * that somewhere else, but not in eth1394. */ |
1647 | #if 0 | 1553 | #if 0 |
1648 | if ((priv->host->csr.broadcast_channel & 0xc0000000) != 0xc0000000) { | 1554 | if ((priv->host->csr.broadcast_channel & 0xc0000000) != 0xc0000000) |
1649 | ret = -EAGAIN; | ||
1650 | goto fail; | 1555 | goto fail; |
1651 | } | ||
1652 | #endif | 1556 | #endif |
1653 | 1557 | ||
1654 | if ((skb = skb_share_check (skb, kmflags)) == NULL) { | 1558 | skb = skb_share_check(skb, GFP_ATOMIC); |
1655 | ret = -ENOMEM; | 1559 | if (!skb) |
1656 | goto fail; | 1560 | goto fail; |
1657 | } | ||
1658 | 1561 | ||
1659 | /* Get rid of the fake eth1394 header, but save a pointer */ | 1562 | /* Get rid of the fake eth1394 header, but save a pointer */ |
1660 | eth = (struct eth1394hdr*)skb->data; | 1563 | eth = (struct eth1394hdr *)skb->data; |
1661 | skb_pull(skb, ETH1394_HLEN); | 1564 | skb_pull(skb, ETH1394_HLEN); |
1662 | 1565 | ||
1663 | proto = eth->h_proto; | 1566 | proto = eth->h_proto; |
@@ -1672,7 +1575,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1672 | tx_type = ETH1394_GASP; | 1575 | tx_type = ETH1394_GASP; |
1673 | dest_node = LOCAL_BUS | ALL_NODES; | 1576 | dest_node = LOCAL_BUS | ALL_NODES; |
1674 | max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD; | 1577 | max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD; |
1675 | BUG_ON(max_payload < (512 - ETHER1394_GASP_OVERHEAD)); | 1578 | BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD); |
1676 | dgl = priv->bc_dgl; | 1579 | dgl = priv->bc_dgl; |
1677 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) | 1580 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) |
1678 | priv->bc_dgl++; | 1581 | priv->bc_dgl++; |
@@ -1681,19 +1584,17 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1681 | 1584 | ||
1682 | node = eth1394_find_node_guid(&priv->ip_node_list, | 1585 | node = eth1394_find_node_guid(&priv->ip_node_list, |
1683 | be64_to_cpu(guid)); | 1586 | be64_to_cpu(guid)); |
1684 | if (!node) { | 1587 | if (!node) |
1685 | ret = -EAGAIN; | ||
1686 | goto fail; | 1588 | goto fail; |
1687 | } | 1589 | |
1688 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; | 1590 | node_info = |
1689 | if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) { | 1591 | (struct eth1394_node_info *)node->ud->device.driver_data; |
1690 | ret = -EAGAIN; | 1592 | if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) |
1691 | goto fail; | 1593 | goto fail; |
1692 | } | ||
1693 | 1594 | ||
1694 | dest_node = node->ud->ne->nodeid; | 1595 | dest_node = node->ud->ne->nodeid; |
1695 | max_payload = node_info->maxpayload; | 1596 | max_payload = node_info->maxpayload; |
1696 | BUG_ON(max_payload < (512 - ETHER1394_GASP_OVERHEAD)); | 1597 | BUG_ON(max_payload < 512 - ETHER1394_GASP_OVERHEAD); |
1697 | 1598 | ||
1698 | dgl = node_info->dgl; | 1599 | dgl = node_info->dgl; |
1699 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) | 1600 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) |
@@ -1703,7 +1604,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1703 | 1604 | ||
1704 | /* If this is an ARP packet, convert it */ | 1605 | /* If this is an ARP packet, convert it */ |
1705 | if (proto == htons(ETH_P_ARP)) | 1606 | if (proto == htons(ETH_P_ARP)) |
1706 | ether1394_arp_to_1394arp (skb, dev); | 1607 | ether1394_arp_to_1394arp(skb, dev); |
1707 | 1608 | ||
1708 | ptask->hdr.words.word1 = 0; | 1609 | ptask->hdr.words.word1 = 0; |
1709 | ptask->hdr.words.word2 = 0; | 1610 | ptask->hdr.words.word2 = 0; |
@@ -1726,9 +1627,8 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1726 | 1627 | ||
1727 | ptask->tx_type = tx_type; | 1628 | ptask->tx_type = tx_type; |
1728 | ptask->max_payload = max_payload; | 1629 | ptask->max_payload = max_payload; |
1729 | ptask->outstanding_pkts = ether1394_encapsulate_prep(max_payload, proto, | 1630 | ptask->outstanding_pkts = ether1394_encapsulate_prep(max_payload, |
1730 | &ptask->hdr, dg_size, | 1631 | proto, &ptask->hdr, dg_size, dgl); |
1731 | dgl); | ||
1732 | 1632 | ||
1733 | /* Add the encapsulation header to the fragment */ | 1633 | /* Add the encapsulation header to the fragment */ |
1734 | tx_len = ether1394_encapsulate(skb, max_payload, &ptask->hdr); | 1634 | tx_len = ether1394_encapsulate(skb, max_payload, &ptask->hdr); |
@@ -1737,7 +1637,7 @@ static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) | |||
1737 | goto fail; | 1637 | goto fail; |
1738 | 1638 | ||
1739 | netif_wake_queue(dev); | 1639 | netif_wake_queue(dev); |
1740 | return 0; | 1640 | return NETDEV_TX_OK; |
1741 | fail: | 1641 | fail: |
1742 | if (ptask) | 1642 | if (ptask) |
1743 | kmem_cache_free(packet_task_cache, ptask); | 1643 | kmem_cache_free(packet_task_cache, ptask); |
@@ -1745,40 +1645,56 @@ fail: | |||
1745 | if (skb != NULL) | 1645 | if (skb != NULL) |
1746 | dev_kfree_skb(skb); | 1646 | dev_kfree_skb(skb); |
1747 | 1647 | ||
1748 | spin_lock_irqsave (&priv->lock, flags); | 1648 | spin_lock_irqsave(&priv->lock, flags); |
1749 | priv->stats.tx_dropped++; | 1649 | priv->stats.tx_dropped++; |
1750 | priv->stats.tx_errors++; | 1650 | priv->stats.tx_errors++; |
1751 | spin_unlock_irqrestore (&priv->lock, flags); | 1651 | spin_unlock_irqrestore(&priv->lock, flags); |
1752 | 1652 | ||
1753 | if (netif_queue_stopped(dev)) | 1653 | if (netif_queue_stopped(dev)) |
1754 | netif_wake_queue(dev); | 1654 | netif_wake_queue(dev); |
1755 | 1655 | ||
1756 | return 0; /* returning non-zero causes serious problems */ | 1656 | /* |
1657 | * FIXME: According to a patch from 2003-02-26, "returning non-zero | ||
1658 | * causes serious problems" here, allegedly. Before that patch, | ||
1659 | * -ERRNO was returned which is not appropriate under Linux 2.6. | ||
1660 | * Perhaps more needs to be done? Stop the queue in serious | ||
1661 | * conditions and restart it elsewhere? | ||
1662 | */ | ||
1663 | /* return NETDEV_TX_BUSY; */ | ||
1664 | return NETDEV_TX_OK; | ||
1757 | } | 1665 | } |
1758 | 1666 | ||
1759 | static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | 1667 | static void ether1394_get_drvinfo(struct net_device *dev, |
1668 | struct ethtool_drvinfo *info) | ||
1760 | { | 1669 | { |
1761 | strcpy (info->driver, driver_name); | 1670 | strcpy(info->driver, driver_name); |
1762 | /* FIXME XXX provide sane businfo */ | 1671 | strcpy(info->bus_info, "ieee1394"); /* FIXME provide more detail? */ |
1763 | strcpy (info->bus_info, "ieee1394"); | ||
1764 | } | 1672 | } |
1765 | 1673 | ||
1766 | static struct ethtool_ops ethtool_ops = { | 1674 | static struct ethtool_ops ethtool_ops = { |
1767 | .get_drvinfo = ether1394_get_drvinfo | 1675 | .get_drvinfo = ether1394_get_drvinfo |
1768 | }; | 1676 | }; |
1769 | 1677 | ||
1770 | static int __init ether1394_init_module (void) | 1678 | static int __init ether1394_init_module(void) |
1771 | { | 1679 | { |
1772 | packet_task_cache = kmem_cache_create("packet_task", sizeof(struct packet_task), | 1680 | int err; |
1681 | |||
1682 | packet_task_cache = kmem_cache_create("packet_task", | ||
1683 | sizeof(struct packet_task), | ||
1773 | 0, 0, NULL, NULL); | 1684 | 0, 0, NULL, NULL); |
1685 | if (!packet_task_cache) | ||
1686 | return -ENOMEM; | ||
1774 | 1687 | ||
1775 | /* Register ourselves as a highlevel driver */ | ||
1776 | hpsb_register_highlevel(ð1394_highlevel); | 1688 | hpsb_register_highlevel(ð1394_highlevel); |
1777 | 1689 | err = hpsb_register_protocol(ð1394_proto_driver); | |
1778 | return hpsb_register_protocol(ð1394_proto_driver); | 1690 | if (err) { |
1691 | hpsb_unregister_highlevel(ð1394_highlevel); | ||
1692 | kmem_cache_destroy(packet_task_cache); | ||
1693 | } | ||
1694 | return err; | ||
1779 | } | 1695 | } |
1780 | 1696 | ||
1781 | static void __exit ether1394_exit_module (void) | 1697 | static void __exit ether1394_exit_module(void) |
1782 | { | 1698 | { |
1783 | hpsb_unregister_protocol(ð1394_proto_driver); | 1699 | hpsb_unregister_protocol(ð1394_proto_driver); |
1784 | hpsb_unregister_highlevel(ð1394_highlevel); | 1700 | hpsb_unregister_highlevel(ð1394_highlevel); |