Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * eth1394.c -- Ethernet driver for Linux IEEE-1394 Subsystem |
| 3 | * |
| 4 | * Copyright (C) 2001-2003 Ben Collins <bcollins@debian.org> |
| 5 | * 2000 Bonin Franck <boninf@free.fr> |
| 6 | * 2003 Steve Kinneberg <kinnebergsteve@acmsystems.com> |
| 7 | * |
| 8 | * Mainly based on work by Emanuel Pirker and Andreas E. Bombe |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software Foundation, |
| 22 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | */ |
| 24 | |
| 25 | /* This driver intends to support RFC 2734, which describes a method for |
| 26 | * transporting IPv4 datagrams over IEEE-1394 serial busses. This driver |
| 27 | * will ultimately support that method, but currently falls short in |
| 28 | * several areas. |
| 29 | * |
| 30 | * TODO: |
| 31 | * RFC 2734 related: |
| 32 | * - Add MCAP. Limited Multicast exists only to 224.0.0.1 and 224.0.0.2. |
| 33 | * |
| 34 | * Non-RFC 2734 related: |
| 35 | * - Handle fragmented skb's coming from the networking layer. |
| 36 | * - Move generic GASP reception to core 1394 code |
| 37 | * - Convert kmalloc/kfree for link fragments to use kmem_cache_* instead |
| 38 | * - Stability improvements |
| 39 | * - Performance enhancements |
| 40 | * - Consider garbage collecting old partial datagrams after X amount of time |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | #include <linux/module.h> |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/kernel.h> |
| 47 | #include <linux/slab.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/types.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/init.h> |
| 52 | |
| 53 | #include <linux/netdevice.h> |
| 54 | #include <linux/inetdevice.h> |
| 55 | #include <linux/etherdevice.h> |
| 56 | #include <linux/if_arp.h> |
| 57 | #include <linux/if_ether.h> |
| 58 | #include <linux/ip.h> |
| 59 | #include <linux/in.h> |
| 60 | #include <linux/tcp.h> |
| 61 | #include <linux/skbuff.h> |
| 62 | #include <linux/bitops.h> |
| 63 | #include <linux/ethtool.h> |
| 64 | #include <asm/uaccess.h> |
| 65 | #include <asm/delay.h> |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 66 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <net/arp.h> |
| 68 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 69 | #include "config_roms.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #include "csr1212.h" |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 71 | #include "eth1394.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include "highlevel.h" |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 73 | #include "ieee1394.h" |
| 74 | #include "ieee1394_core.h" |
| 75 | #include "ieee1394_hotplug.h" |
| 76 | #include "ieee1394_transactions.h" |
| 77 | #include "ieee1394_types.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include "iso.h" |
| 79 | #include "nodemgr.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | #define ETH1394_PRINT_G(level, fmt, args...) \ |
| 82 | printk(level "%s: " fmt, driver_name, ## args) |
| 83 | |
| 84 | #define ETH1394_PRINT(level, dev_name, fmt, args...) \ |
| 85 | printk(level "%s: %s: " fmt, driver_name, dev_name, ## args) |
| 86 | |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct fragment_info { |
| 92 | struct list_head list; |
| 93 | int offset; |
| 94 | int len; |
| 95 | }; |
| 96 | |
| 97 | struct partial_datagram { |
| 98 | struct list_head list; |
| 99 | u16 dgl; |
| 100 | u16 dg_size; |
| 101 | u16 ether_type; |
| 102 | struct sk_buff *skb; |
| 103 | char *pbuf; |
| 104 | struct list_head frag_info; |
| 105 | }; |
| 106 | |
| 107 | struct pdg_list { |
| 108 | struct list_head list; /* partial datagram list per node */ |
| 109 | unsigned int sz; /* partial datagram list size per node */ |
| 110 | spinlock_t lock; /* partial datagram lock */ |
| 111 | }; |
| 112 | |
| 113 | struct eth1394_host_info { |
| 114 | struct hpsb_host *host; |
| 115 | struct net_device *dev; |
| 116 | }; |
| 117 | |
| 118 | struct eth1394_node_ref { |
| 119 | struct unit_directory *ud; |
| 120 | struct list_head list; |
| 121 | }; |
| 122 | |
| 123 | struct eth1394_node_info { |
| 124 | u16 maxpayload; /* Max payload */ |
| 125 | u8 sspd; /* Max speed */ |
| 126 | u64 fifo; /* FIFO address */ |
| 127 | struct pdg_list pdg; /* partial RX datagram lists */ |
| 128 | int dgl; /* Outgoing datagram label */ |
| 129 | }; |
| 130 | |
| 131 | /* Our ieee1394 highlevel driver */ |
| 132 | #define ETH1394_DRIVER_NAME "eth1394" |
| 133 | static const char driver_name[] = ETH1394_DRIVER_NAME; |
| 134 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 135 | static struct kmem_cache *packet_task_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | static struct hpsb_highlevel eth1394_highlevel; |
| 138 | |
| 139 | /* Use common.lf to determine header len */ |
| 140 | static const int hdr_type_len[] = { |
| 141 | sizeof (struct eth1394_uf_hdr), |
| 142 | sizeof (struct eth1394_ff_hdr), |
| 143 | sizeof (struct eth1394_sf_hdr), |
| 144 | sizeof (struct eth1394_sf_hdr) |
| 145 | }; |
| 146 | |
| 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[] = { |
| 154 | /* S100, S200, S400, S800, S1600, S3200 */ |
| 155 | 512, 1024, 2048, 4096, 4096, 4096 |
| 156 | }; |
| 157 | |
| 158 | MODULE_AUTHOR("Ben Collins (bcollins@debian.org)"); |
| 159 | MODULE_DESCRIPTION("IEEE 1394 IPv4 Driver (IPv4-over-1394 as per RFC 2734)"); |
| 160 | MODULE_LICENSE("GPL"); |
| 161 | |
| 162 | /* The max_partial_datagrams parameter is the maximum number of fragmented |
| 163 | * 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 |
| 165 | * consume in the event that some partial datagrams are never completed. |
| 166 | */ |
| 167 | static int max_partial_datagrams = 25; |
| 168 | module_param(max_partial_datagrams, int, S_IRUGO | S_IWUSR); |
| 169 | MODULE_PARM_DESC(max_partial_datagrams, |
| 170 | "Maximum number of partially received fragmented datagrams " |
| 171 | "(default = 25)."); |
| 172 | |
| 173 | |
| 174 | static int ether1394_header(struct sk_buff *skb, struct net_device *dev, |
| 175 | unsigned short type, void *daddr, void *saddr, |
| 176 | unsigned len); |
| 177 | static int ether1394_rebuild_header(struct sk_buff *skb); |
| 178 | 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); |
| 180 | static void ether1394_header_cache_update(struct hh_cache *hh, |
| 181 | struct net_device *dev, |
| 182 | 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); |
| 187 | static void ether1394_iso(struct hpsb_iso *iso); |
| 188 | |
| 189 | static struct ethtool_ops ethtool_ops; |
| 190 | |
| 191 | static int ether1394_write(struct hpsb_host *host, int srcid, int destid, |
| 192 | quadlet_t *data, u64 addr, size_t len, u16 flags); |
| 193 | static void ether1394_add_host (struct hpsb_host *host); |
| 194 | static void ether1394_remove_host (struct hpsb_host *host); |
| 195 | static void ether1394_host_reset (struct hpsb_host *host); |
| 196 | |
| 197 | /* Function for incoming 1394 packets */ |
| 198 | static struct hpsb_address_ops addr_ops = { |
| 199 | .write = ether1394_write, |
| 200 | }; |
| 201 | |
| 202 | /* Ieee1394 highlevel driver functions */ |
| 203 | static struct hpsb_highlevel eth1394_highlevel = { |
| 204 | .name = driver_name, |
| 205 | .add_host = ether1394_add_host, |
| 206 | .remove_host = ether1394_remove_host, |
| 207 | .host_reset = ether1394_host_reset, |
| 208 | }; |
| 209 | |
| 210 | |
Jean Delvare | 09d7a96 | 2007-04-01 10:06:33 +0200 | [diff] [blame^] | 211 | static int ether1394_recv_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
| 213 | struct eth1394_priv *priv = netdev_priv(dev); |
Jean Delvare | 09d7a96 | 2007-04-01 10:06:33 +0200 | [diff] [blame^] | 214 | |
| 215 | priv->iso = hpsb_iso_recv_init(priv->host, |
| 216 | ETHER1394_ISO_BUF_SIZE, |
| 217 | ETHER1394_GASP_BUFFERS, |
| 218 | priv->broadcast_channel, |
| 219 | HPSB_ISO_DMA_PACKET_PER_BUFFER, |
| 220 | 1, ether1394_iso); |
| 221 | if (priv->iso == NULL) { |
| 222 | ETH1394_PRINT(KERN_ERR, dev->name, |
| 223 | "Could not allocate isochronous receive " |
| 224 | "context for the broadcast channel\n"); |
| 225 | priv->bc_state = ETHER1394_BC_ERROR; |
| 226 | return -EAGAIN; |
| 227 | } |
| 228 | |
| 229 | if (hpsb_iso_recv_start(priv->iso, -1, (1 << 3), -1) < 0) |
| 230 | priv->bc_state = ETHER1394_BC_STOPPED; |
| 231 | else |
| 232 | priv->bc_state = ETHER1394_BC_RUNNING; |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | /* This is called after an "ifup" */ |
| 237 | static int ether1394_open(struct net_device *dev) |
| 238 | { |
| 239 | struct eth1394_priv *priv = netdev_priv(dev); |
| 240 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* Something bad happened, don't even try */ |
| 243 | if (priv->bc_state == ETHER1394_BC_ERROR) { |
| 244 | /* we'll try again */ |
Jean Delvare | 09d7a96 | 2007-04-01 10:06:33 +0200 | [diff] [blame^] | 245 | ret = ether1394_recv_init(dev); |
| 246 | if (ret) |
| 247 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | netif_start_queue (dev); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* This is called after an "ifdown" */ |
| 255 | static int ether1394_stop (struct net_device *dev) |
| 256 | { |
| 257 | netif_stop_queue (dev); |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | /* Return statistics to the caller */ |
| 262 | static struct net_device_stats *ether1394_stats (struct net_device *dev) |
| 263 | { |
| 264 | return &(((struct eth1394_priv *)netdev_priv(dev))->stats); |
| 265 | } |
| 266 | |
| 267 | /* What to do if we timeout. I think a host reset is probably in order, so |
| 268 | * that's what we do. Should we increment the stat counters too? */ |
| 269 | static void ether1394_tx_timeout (struct net_device *dev) |
| 270 | { |
| 271 | ETH1394_PRINT (KERN_ERR, dev->name, "Timeout, resetting host %s\n", |
| 272 | ((struct eth1394_priv *)netdev_priv(dev))->host->driver->name); |
| 273 | |
| 274 | highlevel_host_reset (((struct eth1394_priv *)netdev_priv(dev))->host); |
| 275 | |
| 276 | netif_wake_queue (dev); |
| 277 | } |
| 278 | |
| 279 | static int ether1394_change_mtu(struct net_device *dev, int new_mtu) |
| 280 | { |
| 281 | struct eth1394_priv *priv = netdev_priv(dev); |
| 282 | |
| 283 | if ((new_mtu < 68) || |
| 284 | (new_mtu > min(ETH1394_DATA_LEN, |
| 285 | (int)((1 << (priv->host->csr.max_rec + 1)) - |
| 286 | (sizeof(union eth1394_hdr) + |
| 287 | ETHER1394_GASP_OVERHEAD))))) |
| 288 | return -EINVAL; |
| 289 | dev->mtu = new_mtu; |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static void purge_partial_datagram(struct list_head *old) |
| 294 | { |
| 295 | struct partial_datagram *pd = list_entry(old, struct partial_datagram, list); |
| 296 | struct list_head *lh, *n; |
| 297 | |
| 298 | list_for_each_safe(lh, n, &pd->frag_info) { |
| 299 | struct fragment_info *fi = list_entry(lh, struct fragment_info, list); |
| 300 | list_del(lh); |
| 301 | kfree(fi); |
| 302 | } |
| 303 | list_del(old); |
| 304 | kfree_skb(pd->skb); |
| 305 | kfree(pd); |
| 306 | } |
| 307 | |
| 308 | /****************************************** |
| 309 | * 1394 bus activity functions |
| 310 | ******************************************/ |
| 311 | |
| 312 | static struct eth1394_node_ref *eth1394_find_node(struct list_head *inl, |
| 313 | struct unit_directory *ud) |
| 314 | { |
| 315 | struct eth1394_node_ref *node; |
| 316 | |
| 317 | list_for_each_entry(node, inl, list) |
| 318 | if (node->ud == ud) |
| 319 | return node; |
| 320 | |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | static struct eth1394_node_ref *eth1394_find_node_guid(struct list_head *inl, |
| 325 | u64 guid) |
| 326 | { |
| 327 | struct eth1394_node_ref *node; |
| 328 | |
| 329 | list_for_each_entry(node, inl, list) |
| 330 | if (node->ud->ne->guid == guid) |
| 331 | return node; |
| 332 | |
| 333 | return NULL; |
| 334 | } |
| 335 | |
| 336 | static struct eth1394_node_ref *eth1394_find_node_nodeid(struct list_head *inl, |
| 337 | nodeid_t nodeid) |
| 338 | { |
| 339 | struct eth1394_node_ref *node; |
| 340 | list_for_each_entry(node, inl, list) { |
| 341 | if (node->ud->ne->nodeid == nodeid) |
| 342 | return node; |
| 343 | } |
| 344 | |
| 345 | return NULL; |
| 346 | } |
| 347 | |
| 348 | static int eth1394_probe(struct device *dev) |
| 349 | { |
| 350 | struct unit_directory *ud; |
| 351 | struct eth1394_host_info *hi; |
| 352 | struct eth1394_priv *priv; |
| 353 | struct eth1394_node_ref *new_node; |
| 354 | struct eth1394_node_info *node_info; |
| 355 | |
| 356 | ud = container_of(dev, struct unit_directory, device); |
| 357 | |
| 358 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); |
| 359 | if (!hi) |
| 360 | return -ENOENT; |
| 361 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 362 | new_node = kmalloc(sizeof(*new_node), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
| 364 | if (!new_node) |
| 365 | return -ENOMEM; |
| 366 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 367 | node_info = kmalloc(sizeof(*node_info), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
| 369 | if (!node_info) { |
| 370 | kfree(new_node); |
| 371 | return -ENOMEM; |
| 372 | } |
| 373 | |
| 374 | spin_lock_init(&node_info->pdg.lock); |
| 375 | INIT_LIST_HEAD(&node_info->pdg.list); |
| 376 | node_info->pdg.sz = 0; |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 377 | node_info->fifo = CSR1212_INVALID_ADDR_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | ud->device.driver_data = node_info; |
| 380 | new_node->ud = ud; |
| 381 | |
| 382 | priv = netdev_priv(hi->dev); |
| 383 | list_add_tail(&new_node->list, &priv->ip_node_list); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static int eth1394_remove(struct device *dev) |
| 389 | { |
| 390 | struct unit_directory *ud; |
| 391 | struct eth1394_host_info *hi; |
| 392 | struct eth1394_priv *priv; |
| 393 | struct eth1394_node_ref *old_node; |
| 394 | struct eth1394_node_info *node_info; |
| 395 | struct list_head *lh, *n; |
| 396 | unsigned long flags; |
| 397 | |
| 398 | ud = container_of(dev, struct unit_directory, device); |
| 399 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); |
| 400 | if (!hi) |
| 401 | return -ENOENT; |
| 402 | |
| 403 | priv = netdev_priv(hi->dev); |
| 404 | |
| 405 | old_node = eth1394_find_node(&priv->ip_node_list, ud); |
| 406 | |
| 407 | if (old_node) { |
| 408 | list_del(&old_node->list); |
| 409 | kfree(old_node); |
| 410 | |
| 411 | node_info = (struct eth1394_node_info*)ud->device.driver_data; |
| 412 | |
| 413 | spin_lock_irqsave(&node_info->pdg.lock, flags); |
| 414 | /* The partial datagram list should be empty, but we'll just |
| 415 | * make sure anyway... */ |
| 416 | list_for_each_safe(lh, n, &node_info->pdg.list) { |
| 417 | purge_partial_datagram(lh); |
| 418 | } |
| 419 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); |
| 420 | |
| 421 | kfree(node_info); |
| 422 | ud->device.driver_data = NULL; |
| 423 | } |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | static int eth1394_update(struct unit_directory *ud) |
| 428 | { |
| 429 | struct eth1394_host_info *hi; |
| 430 | struct eth1394_priv *priv; |
| 431 | struct eth1394_node_ref *node; |
| 432 | struct eth1394_node_info *node_info; |
| 433 | |
| 434 | hi = hpsb_get_hostinfo(ð1394_highlevel, ud->ne->host); |
| 435 | if (!hi) |
| 436 | return -ENOENT; |
| 437 | |
| 438 | priv = netdev_priv(hi->dev); |
| 439 | |
| 440 | node = eth1394_find_node(&priv->ip_node_list, ud); |
| 441 | |
| 442 | if (!node) { |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 443 | node = kmalloc(sizeof(*node), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
| 445 | if (!node) |
| 446 | return -ENOMEM; |
| 447 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 448 | node_info = kmalloc(sizeof(*node_info), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
| 450 | if (!node_info) { |
| 451 | kfree(node); |
| 452 | return -ENOMEM; |
| 453 | } |
| 454 | |
| 455 | spin_lock_init(&node_info->pdg.lock); |
| 456 | INIT_LIST_HEAD(&node_info->pdg.list); |
| 457 | node_info->pdg.sz = 0; |
| 458 | |
| 459 | ud->device.driver_data = node_info; |
| 460 | node->ud = ud; |
| 461 | |
| 462 | priv = netdev_priv(hi->dev); |
| 463 | list_add_tail(&node->list, &priv->ip_node_list); |
| 464 | } |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | static struct ieee1394_device_id eth1394_id_table[] = { |
| 471 | { |
| 472 | .match_flags = (IEEE1394_MATCH_SPECIFIER_ID | |
| 473 | IEEE1394_MATCH_VERSION), |
| 474 | .specifier_id = ETHER1394_GASP_SPECIFIER_ID, |
| 475 | .version = ETHER1394_GASP_VERSION, |
| 476 | }, |
| 477 | {} |
| 478 | }; |
| 479 | |
| 480 | MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table); |
| 481 | |
| 482 | static struct hpsb_protocol_driver eth1394_proto_driver = { |
Ben Collins | ed30c26 | 2006-11-23 13:59:48 -0500 | [diff] [blame] | 483 | .name = ETH1394_DRIVER_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | .id_table = eth1394_id_table, |
| 485 | .update = eth1394_update, |
| 486 | .driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | .probe = eth1394_probe, |
| 488 | .remove = eth1394_remove, |
| 489 | }, |
| 490 | }; |
| 491 | |
| 492 | |
| 493 | static void ether1394_reset_priv (struct net_device *dev, int set_mtu) |
| 494 | { |
| 495 | unsigned long flags; |
| 496 | int i; |
| 497 | struct eth1394_priv *priv = netdev_priv(dev); |
| 498 | struct hpsb_host *host = priv->host; |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 499 | u64 guid = get_unaligned((u64*)&(host->csr.rom->bus_info_data[3])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | u16 maxpayload = 1 << (host->csr.max_rec + 1); |
| 501 | int max_speed = IEEE1394_SPEED_MAX; |
| 502 | |
| 503 | spin_lock_irqsave (&priv->lock, flags); |
| 504 | |
| 505 | memset(priv->ud_list, 0, sizeof(struct node_entry*) * ALL_NODES); |
| 506 | priv->bc_maxpayload = 512; |
| 507 | |
| 508 | /* Determine speed limit */ |
| 509 | for (i = 0; i < host->node_count; i++) |
Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 510 | if (max_speed > host->speed[i]) |
| 511 | max_speed = host->speed[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | priv->bc_sspd = max_speed; |
| 513 | |
| 514 | /* We'll use our maxpayload as the default mtu */ |
| 515 | if (set_mtu) { |
| 516 | dev->mtu = min(ETH1394_DATA_LEN, |
| 517 | (int)(maxpayload - |
| 518 | (sizeof(union eth1394_hdr) + |
| 519 | ETHER1394_GASP_OVERHEAD))); |
| 520 | |
| 521 | /* Set our hardware address while we're at it */ |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 522 | memcpy(dev->dev_addr, &guid, sizeof(u64)); |
| 523 | memset(dev->broadcast, 0xff, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | spin_unlock_irqrestore (&priv->lock, flags); |
| 527 | } |
| 528 | |
| 529 | /* This function is called right before register_netdev */ |
| 530 | static void ether1394_init_dev (struct net_device *dev) |
| 531 | { |
| 532 | /* Our functions */ |
| 533 | dev->open = ether1394_open; |
| 534 | dev->stop = ether1394_stop; |
| 535 | dev->hard_start_xmit = ether1394_tx; |
| 536 | dev->get_stats = ether1394_stats; |
| 537 | dev->tx_timeout = ether1394_tx_timeout; |
| 538 | dev->change_mtu = ether1394_change_mtu; |
| 539 | |
| 540 | dev->hard_header = ether1394_header; |
| 541 | dev->rebuild_header = ether1394_rebuild_header; |
| 542 | dev->hard_header_cache = ether1394_header_cache; |
| 543 | dev->header_cache_update= ether1394_header_cache_update; |
| 544 | dev->hard_header_parse = ether1394_header_parse; |
| 545 | dev->set_mac_address = ether1394_mac_addr; |
| 546 | SET_ETHTOOL_OPS(dev, ðtool_ops); |
| 547 | |
| 548 | /* Some constants */ |
| 549 | dev->watchdog_timeo = ETHER1394_TIMEOUT; |
| 550 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; |
| 551 | dev->features = NETIF_F_HIGHDMA; |
| 552 | dev->addr_len = ETH1394_ALEN; |
| 553 | dev->hard_header_len = ETH1394_HLEN; |
| 554 | dev->type = ARPHRD_IEEE1394; |
| 555 | |
| 556 | ether1394_reset_priv (dev, 1); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * This function is called every time a card is found. It is generally called |
| 561 | * when the module is installed. This is where we add all of our ethernet |
| 562 | * devices. One for each host. |
| 563 | */ |
| 564 | static void ether1394_add_host (struct hpsb_host *host) |
| 565 | { |
| 566 | struct eth1394_host_info *hi = NULL; |
| 567 | struct net_device *dev = NULL; |
| 568 | struct eth1394_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | u64 fifo_addr; |
| 570 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 571 | if (hpsb_config_rom_ip1394_add(host) != 0) { |
| 572 | ETH1394_PRINT_G(KERN_ERR, "Can't add IP-over-1394 ROM entry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return; |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 574 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 576 | fifo_addr = hpsb_allocate_and_register_addrspace( |
| 577 | ð1394_highlevel, host, &addr_ops, |
| 578 | ETHER1394_REGION_ADDR_LEN, ETHER1394_REGION_ADDR_LEN, |
| 579 | CSR1212_INVALID_ADDR_SPACE, CSR1212_INVALID_ADDR_SPACE); |
Stefan Richter | 157188c | 2007-02-10 23:56:38 +0100 | [diff] [blame] | 580 | if (fifo_addr == CSR1212_INVALID_ADDR_SPACE) { |
| 581 | ETH1394_PRINT_G(KERN_ERR, "Cannot register CSR space\n"); |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 582 | hpsb_config_rom_ip1394_remove(host); |
Stefan Richter | 157188c | 2007-02-10 23:56:38 +0100 | [diff] [blame] | 583 | return; |
| 584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | /* We should really have our own alloc_hpsbdev() function in |
| 587 | * net_init.c instead of calling the one for ethernet then hijacking |
| 588 | * it for ourselves. That way we'd be a real networking device. */ |
| 589 | dev = alloc_etherdev(sizeof (struct eth1394_priv)); |
| 590 | |
| 591 | if (dev == NULL) { |
| 592 | ETH1394_PRINT_G (KERN_ERR, "Out of memory trying to allocate " |
| 593 | "etherdevice for IEEE 1394 device %s-%d\n", |
| 594 | host->driver->name, host->id); |
| 595 | goto out; |
| 596 | } |
| 597 | |
| 598 | SET_MODULE_OWNER(dev); |
Stefan Richter | 7a9eeb2 | 2007-03-20 22:43:22 +0100 | [diff] [blame] | 599 | #if 0 |
| 600 | /* FIXME - Is this the correct parent device anyway? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | SET_NETDEV_DEV(dev, &host->device); |
Stefan Richter | 7a9eeb2 | 2007-03-20 22:43:22 +0100 | [diff] [blame] | 602 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | priv = netdev_priv(dev); |
| 605 | |
| 606 | INIT_LIST_HEAD(&priv->ip_node_list); |
| 607 | |
| 608 | spin_lock_init(&priv->lock); |
| 609 | priv->host = host; |
| 610 | priv->local_fifo = fifo_addr; |
| 611 | |
| 612 | hi = hpsb_create_hostinfo(ð1394_highlevel, host, sizeof(*hi)); |
| 613 | |
| 614 | if (hi == NULL) { |
| 615 | ETH1394_PRINT_G (KERN_ERR, "Out of memory trying to create " |
| 616 | "hostinfo for IEEE 1394 device %s-%d\n", |
| 617 | host->driver->name, host->id); |
| 618 | goto out; |
| 619 | } |
| 620 | |
| 621 | ether1394_init_dev(dev); |
| 622 | |
| 623 | if (register_netdev (dev)) { |
| 624 | ETH1394_PRINT (KERN_ERR, dev->name, "Error registering network driver\n"); |
| 625 | goto out; |
| 626 | } |
| 627 | |
| 628 | ETH1394_PRINT (KERN_INFO, dev->name, "IEEE-1394 IPv4 over 1394 Ethernet (fw-host%d)\n", |
| 629 | host->id); |
| 630 | |
| 631 | hi->host = host; |
| 632 | hi->dev = dev; |
| 633 | |
| 634 | /* Ignore validity in hopes that it will be set in the future. It'll |
| 635 | * be checked when the eth device is opened. */ |
| 636 | priv->broadcast_channel = host->csr.broadcast_channel & 0x3f; |
| 637 | |
Jean Delvare | 09d7a96 | 2007-04-01 10:06:33 +0200 | [diff] [blame^] | 638 | ether1394_recv_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | out: |
Stefan Richter | 157188c | 2007-02-10 23:56:38 +0100 | [diff] [blame] | 641 | if (dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | free_netdev(dev); |
| 643 | if (hi) |
| 644 | hpsb_destroy_hostinfo(ð1394_highlevel, host); |
Stefan Richter | 157188c | 2007-02-10 23:56:38 +0100 | [diff] [blame] | 645 | hpsb_unregister_addrspace(ð1394_highlevel, host, fifo_addr); |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 646 | hpsb_config_rom_ip1394_remove(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* Remove a card from our list */ |
| 650 | static void ether1394_remove_host (struct hpsb_host *host) |
| 651 | { |
| 652 | struct eth1394_host_info *hi; |
Stefan Richter | 2cd556a | 2007-02-10 23:57:57 +0100 | [diff] [blame] | 653 | struct eth1394_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
Stefan Richter | 2cd556a | 2007-02-10 23:57:57 +0100 | [diff] [blame] | 656 | if (!hi) |
| 657 | return; |
| 658 | priv = netdev_priv(hi->dev); |
| 659 | hpsb_unregister_addrspace(ð1394_highlevel, host, priv->local_fifo); |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 660 | hpsb_config_rom_ip1394_remove(host); |
Stefan Richter | 2cd556a | 2007-02-10 23:57:57 +0100 | [diff] [blame] | 661 | if (priv->iso) |
| 662 | hpsb_iso_shutdown(priv->iso); |
| 663 | unregister_netdev(hi->dev); |
| 664 | free_netdev(hi->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* A reset has just arisen */ |
| 668 | static void ether1394_host_reset (struct hpsb_host *host) |
| 669 | { |
| 670 | struct eth1394_host_info *hi; |
| 671 | struct eth1394_priv *priv; |
| 672 | struct net_device *dev; |
| 673 | struct list_head *lh, *n; |
| 674 | struct eth1394_node_ref *node; |
| 675 | struct eth1394_node_info *node_info; |
| 676 | unsigned long flags; |
| 677 | |
| 678 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
| 679 | |
| 680 | /* This can happen for hosts that we don't use */ |
Stefan Richter | 2cd556a | 2007-02-10 23:57:57 +0100 | [diff] [blame] | 681 | if (!hi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | return; |
| 683 | |
| 684 | dev = hi->dev; |
Ben Collins | 1934b8b | 2005-07-09 20:01:23 -0400 | [diff] [blame] | 685 | priv = (struct eth1394_priv *)netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | /* Reset our private host data, but not our mtu */ |
| 688 | netif_stop_queue (dev); |
| 689 | ether1394_reset_priv (dev, 0); |
| 690 | |
| 691 | list_for_each_entry(node, &priv->ip_node_list, list) { |
| 692 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; |
| 693 | |
| 694 | spin_lock_irqsave(&node_info->pdg.lock, flags); |
| 695 | |
| 696 | list_for_each_safe(lh, n, &node_info->pdg.list) { |
| 697 | purge_partial_datagram(lh); |
| 698 | } |
| 699 | |
| 700 | INIT_LIST_HEAD(&(node_info->pdg.list)); |
| 701 | node_info->pdg.sz = 0; |
| 702 | |
| 703 | spin_unlock_irqrestore(&node_info->pdg.lock, flags); |
| 704 | } |
| 705 | |
| 706 | netif_wake_queue (dev); |
| 707 | } |
| 708 | |
| 709 | /****************************************** |
| 710 | * HW Header net device functions |
| 711 | ******************************************/ |
| 712 | /* These functions have been adapted from net/ethernet/eth.c */ |
| 713 | |
| 714 | |
| 715 | /* Create a fake MAC header for an arbitrary protocol layer. |
| 716 | * saddr=NULL means use device source address |
| 717 | * daddr=NULL means leave destination address (eg unresolved arp). */ |
| 718 | static int ether1394_header(struct sk_buff *skb, struct net_device *dev, |
| 719 | unsigned short type, void *daddr, void *saddr, |
| 720 | unsigned len) |
| 721 | { |
| 722 | struct eth1394hdr *eth = (struct eth1394hdr *)skb_push(skb, ETH1394_HLEN); |
| 723 | |
| 724 | eth->h_proto = htons(type); |
| 725 | |
| 726 | if (dev->flags & (IFF_LOOPBACK|IFF_NOARP)) { |
| 727 | memset(eth->h_dest, 0, dev->addr_len); |
| 728 | return(dev->hard_header_len); |
| 729 | } |
| 730 | |
| 731 | if (daddr) { |
| 732 | memcpy(eth->h_dest,daddr,dev->addr_len); |
| 733 | return dev->hard_header_len; |
| 734 | } |
| 735 | |
| 736 | return -dev->hard_header_len; |
| 737 | |
| 738 | } |
| 739 | |
| 740 | |
| 741 | /* Rebuild the faked MAC header. This is called after an ARP |
| 742 | * (or in future other address resolution) has completed on this |
| 743 | * sk_buff. We now let ARP fill in the other fields. |
| 744 | * |
| 745 | * This routine CANNOT use cached dst->neigh! |
| 746 | * Really, it is used only when dst->neigh is wrong. |
| 747 | */ |
| 748 | static int ether1394_rebuild_header(struct sk_buff *skb) |
| 749 | { |
| 750 | struct eth1394hdr *eth = (struct eth1394hdr *)skb->data; |
| 751 | struct net_device *dev = skb->dev; |
| 752 | |
| 753 | switch (eth->h_proto) { |
| 754 | |
| 755 | #ifdef CONFIG_INET |
| 756 | case __constant_htons(ETH_P_IP): |
| 757 | return arp_find((unsigned char*)ð->h_dest, skb); |
| 758 | #endif |
| 759 | default: |
| 760 | ETH1394_PRINT(KERN_DEBUG, dev->name, |
| 761 | "unable to resolve type %04x addresses.\n", |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 762 | ntohs(eth->h_proto)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | break; |
| 764 | } |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static int ether1394_header_parse(struct sk_buff *skb, unsigned char *haddr) |
| 770 | { |
| 771 | struct net_device *dev = skb->dev; |
| 772 | memcpy(haddr, dev->dev_addr, ETH1394_ALEN); |
| 773 | return ETH1394_ALEN; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | static int ether1394_header_cache(struct neighbour *neigh, struct hh_cache *hh) |
| 778 | { |
| 779 | unsigned short type = hh->hh_type; |
| 780 | struct eth1394hdr *eth = (struct eth1394hdr*)(((u8*)hh->hh_data) + |
| 781 | (16 - ETH1394_HLEN)); |
| 782 | struct net_device *dev = neigh->dev; |
| 783 | |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 784 | if (type == htons(ETH_P_802_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | eth->h_proto = type; |
| 788 | memcpy(eth->h_dest, neigh->ha, dev->addr_len); |
| 789 | |
| 790 | hh->hh_len = ETH1394_HLEN; |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | /* Called by Address Resolution module to notify changes in address. */ |
| 795 | static void ether1394_header_cache_update(struct hh_cache *hh, |
| 796 | struct net_device *dev, |
| 797 | unsigned char * haddr) |
| 798 | { |
| 799 | memcpy(((u8*)hh->hh_data) + (16 - ETH1394_HLEN), haddr, dev->addr_len); |
| 800 | } |
| 801 | |
| 802 | static int ether1394_mac_addr(struct net_device *dev, void *p) |
| 803 | { |
| 804 | if (netif_running(dev)) |
| 805 | return -EBUSY; |
| 806 | |
| 807 | /* Not going to allow setting the MAC address, we really need to use |
| 808 | * the real one supplied by the hardware */ |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | |
| 814 | /****************************************** |
| 815 | * Datagram reception code |
| 816 | ******************************************/ |
| 817 | |
| 818 | /* Copied from net/ethernet/eth.c */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 819 | static u16 ether1394_type_trans(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
| 821 | struct eth1394hdr *eth; |
| 822 | unsigned char *rawp; |
| 823 | |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 824 | skb_reset_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | skb_pull (skb, ETH1394_HLEN); |
| 826 | eth = eth1394_hdr(skb); |
| 827 | |
| 828 | if (*eth->h_dest & 1) { |
| 829 | if (memcmp(eth->h_dest, dev->broadcast, dev->addr_len)==0) |
| 830 | skb->pkt_type = PACKET_BROADCAST; |
| 831 | #if 0 |
| 832 | else |
| 833 | skb->pkt_type = PACKET_MULTICAST; |
| 834 | #endif |
| 835 | } else { |
| 836 | if (memcmp(eth->h_dest, dev->dev_addr, dev->addr_len)) |
| 837 | skb->pkt_type = PACKET_OTHERHOST; |
| 838 | } |
| 839 | |
| 840 | if (ntohs (eth->h_proto) >= 1536) |
| 841 | return eth->h_proto; |
| 842 | |
| 843 | rawp = skb->data; |
| 844 | |
| 845 | if (*(unsigned short *)rawp == 0xFFFF) |
| 846 | return htons (ETH_P_802_3); |
| 847 | |
| 848 | return htons (ETH_P_802_2); |
| 849 | } |
| 850 | |
| 851 | /* Parse an encapsulated IP1394 header into an ethernet frame packet. |
| 852 | * We also perform ARP translation here, if need be. */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 853 | static u16 ether1394_parse_encap(struct sk_buff *skb, struct net_device *dev, |
| 854 | nodeid_t srcid, nodeid_t destid, |
| 855 | u16 ether_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | { |
| 857 | struct eth1394_priv *priv = netdev_priv(dev); |
| 858 | u64 dest_hw; |
| 859 | unsigned short ret = 0; |
| 860 | |
| 861 | /* Setup our hw addresses. We use these to build the |
| 862 | * ethernet header. */ |
| 863 | if (destid == (LOCAL_BUS | ALL_NODES)) |
| 864 | dest_hw = ~0ULL; /* broadcast */ |
| 865 | else |
| 866 | dest_hw = cpu_to_be64((((u64)priv->host->csr.guid_hi) << 32) | |
| 867 | priv->host->csr.guid_lo); |
| 868 | |
| 869 | /* If this is an ARP packet, convert it. First, we want to make |
| 870 | * use of some of the fields, since they tell us a little bit |
| 871 | * about the sending machine. */ |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 872 | if (ether_type == htons(ETH_P_ARP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | struct eth1394_arp *arp1394 = (struct eth1394_arp*)skb->data; |
| 874 | struct arphdr *arp = (struct arphdr *)skb->data; |
| 875 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); |
| 876 | u64 fifo_addr = (u64)ntohs(arp1394->fifo_hi) << 32 | |
| 877 | ntohl(arp1394->fifo_lo); |
| 878 | u8 max_rec = min(priv->host->csr.max_rec, |
| 879 | (u8)(arp1394->max_rec)); |
| 880 | int sspd = arp1394->sspd; |
| 881 | u16 maxpayload; |
| 882 | struct eth1394_node_ref *node; |
| 883 | struct eth1394_node_info *node_info; |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 884 | __be64 guid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | /* Sanity check. MacOSX seems to be sending us 131 in this |
| 887 | * field (atleast on my Panther G5). Not sure why. */ |
| 888 | if (sspd > 5 || sspd < 0) |
| 889 | sspd = 0; |
| 890 | |
| 891 | maxpayload = min(eth1394_speedto_maxpayload[sspd], (u16)(1 << (max_rec + 1))); |
| 892 | |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 893 | guid = get_unaligned(&arp1394->s_uniq_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | node = eth1394_find_node_guid(&priv->ip_node_list, |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 895 | be64_to_cpu(guid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | if (!node) { |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; |
| 901 | |
| 902 | /* Update our speed/payload/fifo_offset table */ |
| 903 | node_info->maxpayload = maxpayload; |
| 904 | node_info->sspd = sspd; |
| 905 | node_info->fifo = fifo_addr; |
| 906 | |
| 907 | /* Now that we're done with the 1394 specific stuff, we'll |
| 908 | * need to alter some of the data. Believe it or not, all |
| 909 | * that needs to be done is sender_IP_address needs to be |
| 910 | * moved, the destination hardware address get stuffed |
| 911 | * in and the hardware address length set to 8. |
| 912 | * |
| 913 | * IMPORTANT: The code below overwrites 1394 specific data |
| 914 | * needed above so keep the munging of the data for the |
| 915 | * higher level IP stack last. */ |
| 916 | |
| 917 | arp->ar_hln = 8; |
| 918 | arp_ptr += arp->ar_hln; /* skip over sender unique id */ |
| 919 | *(u32*)arp_ptr = arp1394->sip; /* move sender IP addr */ |
| 920 | arp_ptr += arp->ar_pln; /* skip over sender IP addr */ |
| 921 | |
Ben Collins | 02f4213 | 2006-06-12 18:15:11 -0400 | [diff] [blame] | 922 | if (arp->ar_op == htons(ARPOP_REQUEST)) |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 923 | memset(arp_ptr, 0, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | else |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 925 | memcpy(arp_ptr, dev->dev_addr, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /* Now add the ethernet header. */ |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 929 | if (dev->hard_header(skb, dev, ntohs(ether_type), &dest_hw, NULL, |
| 930 | skb->len) >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | ret = ether1394_type_trans(skb, dev); |
| 932 | |
| 933 | return ret; |
| 934 | } |
| 935 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 936 | static int fragment_overlap(struct list_head *frag_list, int offset, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | { |
| 938 | struct fragment_info *fi; |
| 939 | |
| 940 | list_for_each_entry(fi, frag_list, list) { |
| 941 | if ( ! ((offset > (fi->offset + fi->len - 1)) || |
| 942 | ((offset + len - 1) < fi->offset))) |
| 943 | return 1; |
| 944 | } |
| 945 | return 0; |
| 946 | } |
| 947 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 948 | static struct list_head *find_partial_datagram(struct list_head *pdgl, int dgl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | { |
| 950 | struct partial_datagram *pd; |
| 951 | |
| 952 | list_for_each_entry(pd, pdgl, list) { |
| 953 | if (pd->dgl == dgl) |
| 954 | return &pd->list; |
| 955 | } |
| 956 | return NULL; |
| 957 | } |
| 958 | |
| 959 | /* Assumes that new fragment does not overlap any existing fragments */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 960 | static int new_fragment(struct list_head *frag_info, int offset, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
| 962 | struct list_head *lh; |
| 963 | struct fragment_info *fi, *fi2, *new; |
| 964 | |
| 965 | list_for_each(lh, frag_info) { |
| 966 | fi = list_entry(lh, struct fragment_info, list); |
| 967 | if ((fi->offset + fi->len) == offset) { |
| 968 | /* The new fragment can be tacked on to the end */ |
| 969 | fi->len += len; |
| 970 | /* Did the new fragment plug a hole? */ |
| 971 | fi2 = list_entry(lh->next, struct fragment_info, list); |
| 972 | if ((fi->offset + fi->len) == fi2->offset) { |
| 973 | /* glue fragments together */ |
| 974 | fi->len += fi2->len; |
| 975 | list_del(lh->next); |
| 976 | kfree(fi2); |
| 977 | } |
| 978 | return 0; |
| 979 | } else if ((offset + len) == fi->offset) { |
| 980 | /* The new fragment can be tacked on to the beginning */ |
| 981 | fi->offset = offset; |
| 982 | fi->len += len; |
| 983 | /* Did the new fragment plug a hole? */ |
| 984 | fi2 = list_entry(lh->prev, struct fragment_info, list); |
| 985 | if ((fi2->offset + fi2->len) == fi->offset) { |
| 986 | /* glue fragments together */ |
| 987 | fi2->len += fi->len; |
| 988 | list_del(lh); |
| 989 | kfree(fi); |
| 990 | } |
| 991 | return 0; |
| 992 | } else if (offset > (fi->offset + fi->len)) { |
| 993 | break; |
| 994 | } else if ((offset + len) < fi->offset) { |
| 995 | lh = lh->prev; |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 1000 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | if (!new) |
| 1002 | return -ENOMEM; |
| 1003 | |
| 1004 | new->offset = offset; |
| 1005 | new->len = len; |
| 1006 | |
| 1007 | list_add(&new->list, lh); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1012 | static int new_partial_datagram(struct net_device *dev, struct list_head *pdgl, |
| 1013 | int dgl, int dg_size, char *frag_buf, |
| 1014 | int frag_off, int frag_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | { |
| 1016 | struct partial_datagram *new; |
| 1017 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 1018 | new = kmalloc(sizeof(*new), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | if (!new) |
| 1020 | return -ENOMEM; |
| 1021 | |
| 1022 | INIT_LIST_HEAD(&new->frag_info); |
| 1023 | |
| 1024 | if (new_fragment(&new->frag_info, frag_off, frag_len) < 0) { |
| 1025 | kfree(new); |
| 1026 | return -ENOMEM; |
| 1027 | } |
| 1028 | |
| 1029 | new->dgl = dgl; |
| 1030 | new->dg_size = dg_size; |
| 1031 | |
| 1032 | new->skb = dev_alloc_skb(dg_size + dev->hard_header_len + 15); |
| 1033 | if (!new->skb) { |
| 1034 | struct fragment_info *fi = list_entry(new->frag_info.next, |
| 1035 | struct fragment_info, |
| 1036 | list); |
| 1037 | kfree(fi); |
| 1038 | kfree(new); |
| 1039 | return -ENOMEM; |
| 1040 | } |
| 1041 | |
| 1042 | skb_reserve(new->skb, (dev->hard_header_len + 15) & ~15); |
| 1043 | new->pbuf = skb_put(new->skb, dg_size); |
| 1044 | memcpy(new->pbuf + frag_off, frag_buf, frag_len); |
| 1045 | |
| 1046 | list_add(&new->list, pdgl); |
| 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1051 | static int update_partial_datagram(struct list_head *pdgl, struct list_head *lh, |
| 1052 | char *frag_buf, int frag_off, int frag_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | { |
| 1054 | struct partial_datagram *pd = list_entry(lh, struct partial_datagram, list); |
| 1055 | |
| 1056 | if (new_fragment(&pd->frag_info, frag_off, frag_len) < 0) { |
| 1057 | return -ENOMEM; |
| 1058 | } |
| 1059 | |
| 1060 | memcpy(pd->pbuf + frag_off, frag_buf, frag_len); |
| 1061 | |
| 1062 | /* Move list entry to beginnig of list so that oldest partial |
| 1063 | * datagrams percolate to the end of the list */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 1064 | list_move(lh, pdgl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1069 | static int is_datagram_complete(struct list_head *lh, int dg_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | { |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1071 | struct partial_datagram *pd; |
| 1072 | struct fragment_info *fi; |
| 1073 | |
| 1074 | pd = list_entry(lh, struct partial_datagram, list); |
| 1075 | fi = list_entry(pd->frag_info.next, struct fragment_info, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
| 1077 | return (fi->len == dg_size); |
| 1078 | } |
| 1079 | |
| 1080 | /* Packet reception. We convert the IP1394 encapsulation header to an |
| 1081 | * ethernet header, and fill it with some of our other fields. This is |
| 1082 | * an incoming packet from the 1394 bus. */ |
| 1083 | static int ether1394_data_handler(struct net_device *dev, int srcid, int destid, |
| 1084 | char *buf, int len) |
| 1085 | { |
| 1086 | struct sk_buff *skb; |
| 1087 | unsigned long flags; |
| 1088 | struct eth1394_priv *priv = netdev_priv(dev); |
| 1089 | union eth1394_hdr *hdr = (union eth1394_hdr *)buf; |
| 1090 | u16 ether_type = 0; /* initialized to clear warning */ |
| 1091 | int hdr_len; |
| 1092 | struct unit_directory *ud = priv->ud_list[NODEID_TO_NODE(srcid)]; |
| 1093 | struct eth1394_node_info *node_info; |
| 1094 | |
| 1095 | if (!ud) { |
| 1096 | struct eth1394_node_ref *node; |
| 1097 | node = eth1394_find_node_nodeid(&priv->ip_node_list, srcid); |
| 1098 | if (!node) { |
| 1099 | HPSB_PRINT(KERN_ERR, "ether1394 rx: sender nodeid " |
| 1100 | "lookup failure: " NODE_BUS_FMT, |
| 1101 | NODE_BUS_ARGS(priv->host, srcid)); |
| 1102 | priv->stats.rx_dropped++; |
| 1103 | return -1; |
| 1104 | } |
| 1105 | ud = node->ud; |
| 1106 | |
| 1107 | priv->ud_list[NODEID_TO_NODE(srcid)] = ud; |
| 1108 | } |
| 1109 | |
| 1110 | node_info = (struct eth1394_node_info*)ud->device.driver_data; |
| 1111 | |
| 1112 | /* First, did we receive a fragmented or unfragmented datagram? */ |
| 1113 | hdr->words.word1 = ntohs(hdr->words.word1); |
| 1114 | |
| 1115 | hdr_len = hdr_type_len[hdr->common.lf]; |
| 1116 | |
| 1117 | if (hdr->common.lf == ETH1394_HDR_LF_UF) { |
| 1118 | /* An unfragmented datagram has been received by the ieee1394 |
| 1119 | * bus. Build an skbuff around it so we can pass it to the |
| 1120 | * high level network layer. */ |
| 1121 | |
| 1122 | skb = dev_alloc_skb(len + dev->hard_header_len + 15); |
| 1123 | if (!skb) { |
| 1124 | HPSB_PRINT (KERN_ERR, "ether1394 rx: low on mem\n"); |
| 1125 | priv->stats.rx_dropped++; |
| 1126 | return -1; |
| 1127 | } |
| 1128 | skb_reserve(skb, (dev->hard_header_len + 15) & ~15); |
| 1129 | memcpy(skb_put(skb, len - hdr_len), buf + hdr_len, len - hdr_len); |
| 1130 | ether_type = hdr->uf.ether_type; |
| 1131 | } else { |
| 1132 | /* A datagram fragment has been received, now the fun begins. */ |
| 1133 | |
| 1134 | struct list_head *pdgl, *lh; |
| 1135 | struct partial_datagram *pd; |
| 1136 | int fg_off; |
| 1137 | int fg_len = len - hdr_len; |
| 1138 | int dg_size; |
| 1139 | int dgl; |
| 1140 | int retval; |
| 1141 | struct pdg_list *pdg = &(node_info->pdg); |
| 1142 | |
| 1143 | hdr->words.word3 = ntohs(hdr->words.word3); |
| 1144 | /* The 4th header word is reserved so no need to do ntohs() */ |
| 1145 | |
| 1146 | if (hdr->common.lf == ETH1394_HDR_LF_FF) { |
| 1147 | ether_type = hdr->ff.ether_type; |
| 1148 | dgl = hdr->ff.dgl; |
| 1149 | dg_size = hdr->ff.dg_size + 1; |
| 1150 | fg_off = 0; |
| 1151 | } else { |
| 1152 | hdr->words.word2 = ntohs(hdr->words.word2); |
| 1153 | dgl = hdr->sf.dgl; |
| 1154 | dg_size = hdr->sf.dg_size + 1; |
| 1155 | fg_off = hdr->sf.fg_off; |
| 1156 | } |
| 1157 | spin_lock_irqsave(&pdg->lock, flags); |
| 1158 | |
| 1159 | pdgl = &(pdg->list); |
| 1160 | lh = find_partial_datagram(pdgl, dgl); |
| 1161 | |
| 1162 | if (lh == NULL) { |
| 1163 | while (pdg->sz >= max_partial_datagrams) { |
| 1164 | /* remove the oldest */ |
| 1165 | purge_partial_datagram(pdgl->prev); |
| 1166 | pdg->sz--; |
| 1167 | } |
| 1168 | |
| 1169 | retval = new_partial_datagram(dev, pdgl, dgl, dg_size, |
| 1170 | buf + hdr_len, fg_off, |
| 1171 | fg_len); |
| 1172 | if (retval < 0) { |
| 1173 | spin_unlock_irqrestore(&pdg->lock, flags); |
| 1174 | goto bad_proto; |
| 1175 | } |
| 1176 | pdg->sz++; |
| 1177 | lh = find_partial_datagram(pdgl, dgl); |
| 1178 | } else { |
| 1179 | struct partial_datagram *pd; |
| 1180 | |
| 1181 | pd = list_entry(lh, struct partial_datagram, list); |
| 1182 | |
| 1183 | if (fragment_overlap(&pd->frag_info, fg_off, fg_len)) { |
| 1184 | /* Overlapping fragments, obliterate old |
| 1185 | * datagram and start new one. */ |
| 1186 | purge_partial_datagram(lh); |
| 1187 | retval = new_partial_datagram(dev, pdgl, dgl, |
| 1188 | dg_size, |
| 1189 | buf + hdr_len, |
| 1190 | fg_off, fg_len); |
| 1191 | if (retval < 0) { |
| 1192 | pdg->sz--; |
| 1193 | spin_unlock_irqrestore(&pdg->lock, flags); |
| 1194 | goto bad_proto; |
| 1195 | } |
| 1196 | } else { |
| 1197 | retval = update_partial_datagram(pdgl, lh, |
| 1198 | buf + hdr_len, |
| 1199 | fg_off, fg_len); |
| 1200 | if (retval < 0) { |
| 1201 | /* Couldn't save off fragment anyway |
| 1202 | * so might as well obliterate the |
| 1203 | * datagram now. */ |
| 1204 | purge_partial_datagram(lh); |
| 1205 | pdg->sz--; |
| 1206 | spin_unlock_irqrestore(&pdg->lock, flags); |
| 1207 | goto bad_proto; |
| 1208 | } |
| 1209 | } /* fragment overlap */ |
| 1210 | } /* new datagram or add to existing one */ |
| 1211 | |
| 1212 | pd = list_entry(lh, struct partial_datagram, list); |
| 1213 | |
| 1214 | if (hdr->common.lf == ETH1394_HDR_LF_FF) { |
| 1215 | pd->ether_type = ether_type; |
| 1216 | } |
| 1217 | |
| 1218 | if (is_datagram_complete(lh, dg_size)) { |
| 1219 | ether_type = pd->ether_type; |
| 1220 | pdg->sz--; |
| 1221 | skb = skb_get(pd->skb); |
| 1222 | purge_partial_datagram(lh); |
| 1223 | spin_unlock_irqrestore(&pdg->lock, flags); |
| 1224 | } else { |
| 1225 | /* Datagram is not complete, we're done for the |
| 1226 | * moment. */ |
| 1227 | spin_unlock_irqrestore(&pdg->lock, flags); |
| 1228 | return 0; |
| 1229 | } |
| 1230 | } /* unframgented datagram or fragmented one */ |
| 1231 | |
| 1232 | /* Write metadata, and then pass to the receive level */ |
| 1233 | skb->dev = dev; |
| 1234 | skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */ |
| 1235 | |
| 1236 | /* Parse the encapsulation header. This actually does the job of |
| 1237 | * converting to an ethernet frame header, aswell as arp |
| 1238 | * conversion if needed. ARP conversion is easier in this |
| 1239 | * direction, since we are using ethernet as our backend. */ |
| 1240 | skb->protocol = ether1394_parse_encap(skb, dev, srcid, destid, |
| 1241 | ether_type); |
| 1242 | |
| 1243 | |
| 1244 | spin_lock_irqsave(&priv->lock, flags); |
| 1245 | if (!skb->protocol) { |
| 1246 | priv->stats.rx_errors++; |
| 1247 | priv->stats.rx_dropped++; |
| 1248 | dev_kfree_skb_any(skb); |
| 1249 | goto bad_proto; |
| 1250 | } |
| 1251 | |
| 1252 | if (netif_rx(skb) == NET_RX_DROP) { |
| 1253 | priv->stats.rx_errors++; |
| 1254 | priv->stats.rx_dropped++; |
| 1255 | goto bad_proto; |
| 1256 | } |
| 1257 | |
| 1258 | /* Statistics */ |
| 1259 | priv->stats.rx_packets++; |
| 1260 | priv->stats.rx_bytes += skb->len; |
| 1261 | |
| 1262 | bad_proto: |
| 1263 | if (netif_queue_stopped(dev)) |
| 1264 | netif_wake_queue(dev); |
| 1265 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1266 | |
| 1267 | dev->last_rx = jiffies; |
| 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | static int ether1394_write(struct hpsb_host *host, int srcid, int destid, |
| 1273 | quadlet_t *data, u64 addr, size_t len, u16 flags) |
| 1274 | { |
| 1275 | struct eth1394_host_info *hi; |
| 1276 | |
| 1277 | hi = hpsb_get_hostinfo(ð1394_highlevel, host); |
| 1278 | if (hi == NULL) { |
| 1279 | ETH1394_PRINT_G(KERN_ERR, "Could not find net device for host %s\n", |
| 1280 | host->driver->name); |
| 1281 | return RCODE_ADDRESS_ERROR; |
| 1282 | } |
| 1283 | |
| 1284 | if (ether1394_data_handler(hi->dev, srcid, destid, (char*)data, len)) |
| 1285 | return RCODE_ADDRESS_ERROR; |
| 1286 | else |
| 1287 | return RCODE_COMPLETE; |
| 1288 | } |
| 1289 | |
| 1290 | static void ether1394_iso(struct hpsb_iso *iso) |
| 1291 | { |
| 1292 | quadlet_t *data; |
| 1293 | char *buf; |
| 1294 | struct eth1394_host_info *hi; |
| 1295 | struct net_device *dev; |
| 1296 | struct eth1394_priv *priv; |
| 1297 | unsigned int len; |
| 1298 | u32 specifier_id; |
| 1299 | u16 source_id; |
| 1300 | int i; |
| 1301 | int nready; |
| 1302 | |
| 1303 | hi = hpsb_get_hostinfo(ð1394_highlevel, iso->host); |
| 1304 | if (hi == NULL) { |
| 1305 | ETH1394_PRINT_G(KERN_ERR, "Could not find net device for host %s\n", |
| 1306 | iso->host->driver->name); |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | dev = hi->dev; |
| 1311 | |
| 1312 | nready = hpsb_iso_n_ready(iso); |
| 1313 | for (i = 0; i < nready; i++) { |
| 1314 | struct hpsb_iso_packet_info *info = |
| 1315 | &iso->infos[(iso->first_packet + i) % iso->buf_packets]; |
| 1316 | data = (quadlet_t*) (iso->data_buf.kvirt + info->offset); |
| 1317 | |
| 1318 | /* skip over GASP header */ |
| 1319 | buf = (char *)data + 8; |
| 1320 | len = info->len - 8; |
| 1321 | |
| 1322 | specifier_id = (((be32_to_cpu(data[0]) & 0xffff) << 8) | |
| 1323 | ((be32_to_cpu(data[1]) & 0xff000000) >> 24)); |
| 1324 | source_id = be32_to_cpu(data[0]) >> 16; |
| 1325 | |
| 1326 | priv = netdev_priv(dev); |
| 1327 | |
| 1328 | if (info->channel != (iso->host->csr.broadcast_channel & 0x3f) || |
| 1329 | specifier_id != ETHER1394_GASP_SPECIFIER_ID) { |
| 1330 | /* This packet is not for us */ |
| 1331 | continue; |
| 1332 | } |
| 1333 | ether1394_data_handler(dev, source_id, LOCAL_BUS | ALL_NODES, |
| 1334 | buf, len); |
| 1335 | } |
| 1336 | |
| 1337 | hpsb_iso_recv_release_packets(iso, i); |
| 1338 | |
| 1339 | dev->last_rx = jiffies; |
| 1340 | } |
| 1341 | |
| 1342 | /****************************************** |
| 1343 | * Datagram transmission code |
| 1344 | ******************************************/ |
| 1345 | |
| 1346 | /* Convert a standard ARP packet to 1394 ARP. The first 8 bytes (the entire |
| 1347 | * arphdr) is the same format as the ip1394 header, so they overlap. The rest |
| 1348 | * needs to be munged a bit. The remainder of the arphdr is formatted based |
| 1349 | * on hwaddr len and ipaddr len. We know what they'll be, so it's easy to |
| 1350 | * judge. |
| 1351 | * |
| 1352 | * Now that the EUI is used for the hardware address all we need to do to make |
| 1353 | * this work for 1394 is to insert 2 quadlets that contain max_rec size, |
| 1354 | * speed, and unicast FIFO address information between the sender_unique_id |
| 1355 | * and the IP addresses. |
| 1356 | */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1357 | static void ether1394_arp_to_1394arp(struct sk_buff *skb, |
| 1358 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
| 1360 | struct eth1394_priv *priv = netdev_priv(dev); |
| 1361 | |
| 1362 | struct arphdr *arp = (struct arphdr *)skb->data; |
| 1363 | unsigned char *arp_ptr = (unsigned char *)(arp + 1); |
| 1364 | struct eth1394_arp *arp1394 = (struct eth1394_arp *)skb->data; |
| 1365 | |
| 1366 | /* Believe it or not, all that need to happen is sender IP get moved |
| 1367 | * and set hw_addr_len, max_rec, sspd, fifo_hi and fifo_lo. */ |
| 1368 | arp1394->hw_addr_len = 16; |
| 1369 | arp1394->sip = *(u32*)(arp_ptr + ETH1394_ALEN); |
| 1370 | arp1394->max_rec = priv->host->csr.max_rec; |
| 1371 | arp1394->sspd = priv->host->csr.lnk_spd; |
| 1372 | arp1394->fifo_hi = htons (priv->local_fifo >> 32); |
| 1373 | arp1394->fifo_lo = htonl (priv->local_fifo & ~0x0); |
| 1374 | |
| 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | /* We need to encapsulate the standard header with our own. We use the |
| 1379 | * ethernet header's proto for our own. */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1380 | static unsigned int ether1394_encapsulate_prep(unsigned int max_payload, |
| 1381 | __be16 proto, |
| 1382 | union eth1394_hdr *hdr, |
| 1383 | u16 dg_size, u16 dgl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | { |
| 1385 | unsigned int adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_UF]; |
| 1386 | |
| 1387 | /* Does it all fit in one packet? */ |
| 1388 | if (dg_size <= adj_max_payload) { |
| 1389 | hdr->uf.lf = ETH1394_HDR_LF_UF; |
| 1390 | hdr->uf.ether_type = proto; |
| 1391 | } else { |
| 1392 | hdr->ff.lf = ETH1394_HDR_LF_FF; |
| 1393 | hdr->ff.ether_type = proto; |
| 1394 | hdr->ff.dg_size = dg_size - 1; |
| 1395 | hdr->ff.dgl = dgl; |
| 1396 | adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF]; |
| 1397 | } |
| 1398 | return((dg_size + (adj_max_payload - 1)) / adj_max_payload); |
| 1399 | } |
| 1400 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1401 | static unsigned int ether1394_encapsulate(struct sk_buff *skb, |
| 1402 | unsigned int max_payload, |
| 1403 | union eth1394_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
| 1405 | union eth1394_hdr *bufhdr; |
| 1406 | int ftype = hdr->common.lf; |
| 1407 | int hdrsz = hdr_type_len[ftype]; |
| 1408 | unsigned int adj_max_payload = max_payload - hdrsz; |
| 1409 | |
| 1410 | switch(ftype) { |
| 1411 | case ETH1394_HDR_LF_UF: |
| 1412 | bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz); |
| 1413 | bufhdr->words.word1 = htons(hdr->words.word1); |
| 1414 | bufhdr->words.word2 = hdr->words.word2; |
| 1415 | break; |
| 1416 | |
| 1417 | case ETH1394_HDR_LF_FF: |
| 1418 | bufhdr = (union eth1394_hdr *)skb_push(skb, hdrsz); |
| 1419 | bufhdr->words.word1 = htons(hdr->words.word1); |
| 1420 | bufhdr->words.word2 = hdr->words.word2; |
| 1421 | bufhdr->words.word3 = htons(hdr->words.word3); |
| 1422 | bufhdr->words.word4 = 0; |
| 1423 | |
| 1424 | /* Set frag type here for future interior fragments */ |
| 1425 | hdr->common.lf = ETH1394_HDR_LF_IF; |
| 1426 | hdr->sf.fg_off = 0; |
| 1427 | break; |
| 1428 | |
| 1429 | default: |
| 1430 | hdr->sf.fg_off += adj_max_payload; |
| 1431 | bufhdr = (union eth1394_hdr *)skb_pull(skb, adj_max_payload); |
| 1432 | if (max_payload >= skb->len) |
| 1433 | hdr->common.lf = ETH1394_HDR_LF_LF; |
| 1434 | bufhdr->words.word1 = htons(hdr->words.word1); |
| 1435 | bufhdr->words.word2 = htons(hdr->words.word2); |
| 1436 | bufhdr->words.word3 = htons(hdr->words.word3); |
| 1437 | bufhdr->words.word4 = 0; |
| 1438 | } |
| 1439 | |
| 1440 | return min(max_payload, skb->len); |
| 1441 | } |
| 1442 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1443 | static struct hpsb_packet *ether1394_alloc_common_packet(struct hpsb_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
| 1445 | struct hpsb_packet *p; |
| 1446 | |
| 1447 | p = hpsb_alloc_packet(0); |
| 1448 | if (p) { |
| 1449 | p->host = host; |
| 1450 | p->generation = get_hpsb_generation(host); |
| 1451 | p->type = hpsb_async; |
| 1452 | } |
| 1453 | return p; |
| 1454 | } |
| 1455 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1456 | static int ether1394_prep_write_packet(struct hpsb_packet *p, |
| 1457 | struct hpsb_host *host, nodeid_t node, |
| 1458 | u64 addr, void * data, int tx_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
| 1460 | p->node_id = node; |
| 1461 | p->data = NULL; |
| 1462 | |
| 1463 | p->tcode = TCODE_WRITEB; |
| 1464 | p->header[1] = (host->node_id << 16) | (addr >> 32); |
| 1465 | p->header[2] = addr & 0xffffffff; |
| 1466 | |
| 1467 | p->header_size = 16; |
| 1468 | p->expect_response = 1; |
| 1469 | |
| 1470 | if (hpsb_get_tlabel(p)) { |
| 1471 | ETH1394_PRINT_G(KERN_ERR, "No more tlabels left while sending " |
| 1472 | "to node " NODE_BUS_FMT "\n", NODE_BUS_ARGS(host, node)); |
| 1473 | return -1; |
| 1474 | } |
| 1475 | p->header[0] = (p->node_id << 16) | (p->tlabel << 10) |
| 1476 | | (1 << 8) | (TCODE_WRITEB << 4); |
| 1477 | |
| 1478 | p->header[3] = tx_len << 16; |
| 1479 | p->data_size = (tx_len + 3) & ~3; |
| 1480 | p->data = (quadlet_t*)data; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1485 | static void ether1394_prep_gasp_packet(struct hpsb_packet *p, |
| 1486 | struct eth1394_priv *priv, |
| 1487 | struct sk_buff *skb, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | { |
| 1489 | p->header_size = 4; |
| 1490 | p->tcode = TCODE_STREAM_DATA; |
| 1491 | |
| 1492 | p->header[0] = (length << 16) | (3 << 14) |
| 1493 | | ((priv->broadcast_channel) << 8) |
| 1494 | | (TCODE_STREAM_DATA << 4); |
| 1495 | p->data_size = length; |
| 1496 | p->data = ((quadlet_t*)skb->data) - 2; |
| 1497 | p->data[0] = cpu_to_be32((priv->host->node_id << 16) | |
| 1498 | ETHER1394_GASP_SPECIFIER_ID_HI); |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 1499 | p->data[1] = cpu_to_be32((ETHER1394_GASP_SPECIFIER_ID_LO << 24) | |
| 1500 | ETHER1394_GASP_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
| 1502 | /* Setting the node id to ALL_NODES (not LOCAL_BUS | ALL_NODES) |
| 1503 | * prevents hpsb_send_packet() from setting the speed to an arbitrary |
| 1504 | * value based on packet->node_id if packet->node_id is not set. */ |
| 1505 | p->node_id = ALL_NODES; |
| 1506 | p->speed_code = priv->bc_sspd; |
| 1507 | } |
| 1508 | |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1509 | static void ether1394_free_packet(struct hpsb_packet *packet) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | { |
| 1511 | if (packet->tcode != TCODE_STREAM_DATA) |
| 1512 | hpsb_free_tlabel(packet); |
| 1513 | hpsb_free_packet(packet); |
| 1514 | } |
| 1515 | |
| 1516 | static void ether1394_complete_cb(void *__ptask); |
| 1517 | |
| 1518 | static int ether1394_send_packet(struct packet_task *ptask, unsigned int tx_len) |
| 1519 | { |
| 1520 | struct eth1394_priv *priv = ptask->priv; |
| 1521 | struct hpsb_packet *packet = NULL; |
| 1522 | |
| 1523 | packet = ether1394_alloc_common_packet(priv->host); |
| 1524 | if (!packet) |
| 1525 | return -1; |
| 1526 | |
| 1527 | if (ptask->tx_type == ETH1394_GASP) { |
| 1528 | int length = tx_len + (2 * sizeof(quadlet_t)); |
| 1529 | |
| 1530 | ether1394_prep_gasp_packet(packet, priv, ptask->skb, length); |
| 1531 | } else if (ether1394_prep_write_packet(packet, priv->host, |
| 1532 | ptask->dest_node, |
| 1533 | ptask->addr, ptask->skb->data, |
| 1534 | tx_len)) { |
| 1535 | hpsb_free_packet(packet); |
| 1536 | return -1; |
| 1537 | } |
| 1538 | |
| 1539 | ptask->packet = packet; |
| 1540 | hpsb_set_packet_complete_task(ptask->packet, ether1394_complete_cb, |
| 1541 | ptask); |
| 1542 | |
| 1543 | if (hpsb_send_packet(packet) < 0) { |
| 1544 | ether1394_free_packet(packet); |
| 1545 | return -1; |
| 1546 | } |
| 1547 | |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | /* Task function to be run when a datagram transmission is completed */ |
Stefan Richter | e00f04a | 2007-03-18 12:23:11 +0100 | [diff] [blame] | 1553 | static void ether1394_dg_complete(struct packet_task *ptask, int fail) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | { |
| 1555 | struct sk_buff *skb = ptask->skb; |
| 1556 | struct net_device *dev = skb->dev; |
| 1557 | struct eth1394_priv *priv = netdev_priv(dev); |
| 1558 | unsigned long flags; |
| 1559 | |
| 1560 | /* Statistics */ |
| 1561 | spin_lock_irqsave(&priv->lock, flags); |
| 1562 | if (fail) { |
| 1563 | priv->stats.tx_dropped++; |
| 1564 | priv->stats.tx_errors++; |
| 1565 | } else { |
| 1566 | priv->stats.tx_bytes += skb->len; |
| 1567 | priv->stats.tx_packets++; |
| 1568 | } |
| 1569 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1570 | |
| 1571 | dev_kfree_skb_any(skb); |
| 1572 | kmem_cache_free(packet_task_cache, ptask); |
| 1573 | } |
| 1574 | |
| 1575 | |
| 1576 | /* Callback for when a packet has been sent and the status of that packet is |
| 1577 | * known */ |
| 1578 | static void ether1394_complete_cb(void *__ptask) |
| 1579 | { |
| 1580 | struct packet_task *ptask = (struct packet_task *)__ptask; |
| 1581 | struct hpsb_packet *packet = ptask->packet; |
| 1582 | int fail = 0; |
| 1583 | |
| 1584 | if (packet->tcode != TCODE_STREAM_DATA) |
| 1585 | fail = hpsb_packet_success(packet); |
| 1586 | |
| 1587 | ether1394_free_packet(packet); |
| 1588 | |
| 1589 | ptask->outstanding_pkts--; |
| 1590 | if (ptask->outstanding_pkts > 0 && !fail) { |
| 1591 | int tx_len; |
| 1592 | |
| 1593 | /* Add the encapsulation header to the fragment */ |
| 1594 | tx_len = ether1394_encapsulate(ptask->skb, ptask->max_payload, |
| 1595 | &ptask->hdr); |
| 1596 | if (ether1394_send_packet(ptask, tx_len)) |
| 1597 | ether1394_dg_complete(ptask, 1); |
| 1598 | } else { |
| 1599 | ether1394_dg_complete(ptask, fail); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | /* Transmit a packet (called by kernel) */ |
| 1606 | static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) |
| 1607 | { |
Al Viro | b4e3ca1 | 2005-10-21 03:22:34 -0400 | [diff] [blame] | 1608 | gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | struct eth1394hdr *eth; |
| 1610 | struct eth1394_priv *priv = netdev_priv(dev); |
Ben Collins | 02f4213 | 2006-06-12 18:15:11 -0400 | [diff] [blame] | 1611 | __be16 proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | unsigned long flags; |
| 1613 | nodeid_t dest_node; |
| 1614 | eth1394_tx_type tx_type; |
| 1615 | int ret = 0; |
| 1616 | unsigned int tx_len; |
| 1617 | unsigned int max_payload; |
| 1618 | u16 dg_size; |
| 1619 | u16 dgl; |
| 1620 | struct packet_task *ptask; |
| 1621 | struct eth1394_node_ref *node; |
| 1622 | struct eth1394_node_info *node_info = NULL; |
| 1623 | |
| 1624 | ptask = kmem_cache_alloc(packet_task_cache, kmflags); |
| 1625 | if (ptask == NULL) { |
| 1626 | ret = -ENOMEM; |
| 1627 | goto fail; |
| 1628 | } |
| 1629 | |
| 1630 | /* XXX Ignore this for now. Noticed that when MacOSX is the IRM, |
| 1631 | * it does not set our validity bit. We need to compensate for |
| 1632 | * that somewhere else, but not in eth1394. */ |
| 1633 | #if 0 |
| 1634 | if ((priv->host->csr.broadcast_channel & 0xc0000000) != 0xc0000000) { |
| 1635 | ret = -EAGAIN; |
| 1636 | goto fail; |
| 1637 | } |
| 1638 | #endif |
| 1639 | |
| 1640 | if ((skb = skb_share_check (skb, kmflags)) == NULL) { |
| 1641 | ret = -ENOMEM; |
| 1642 | goto fail; |
| 1643 | } |
| 1644 | |
| 1645 | /* Get rid of the fake eth1394 header, but save a pointer */ |
| 1646 | eth = (struct eth1394hdr*)skb->data; |
| 1647 | skb_pull(skb, ETH1394_HLEN); |
| 1648 | |
| 1649 | proto = eth->h_proto; |
| 1650 | dg_size = skb->len; |
| 1651 | |
| 1652 | /* Set the transmission type for the packet. ARP packets and IP |
| 1653 | * broadcast packets are sent via GASP. */ |
| 1654 | if (memcmp(eth->h_dest, dev->broadcast, ETH1394_ALEN) == 0 || |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 1655 | proto == htons(ETH_P_ARP) || |
| 1656 | (proto == htons(ETH_P_IP) && |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1657 | IN_MULTICAST(ntohl(ip_hdr(skb)->daddr)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | tx_type = ETH1394_GASP; |
| 1659 | dest_node = LOCAL_BUS | ALL_NODES; |
| 1660 | max_payload = priv->bc_maxpayload - ETHER1394_GASP_OVERHEAD; |
| 1661 | BUG_ON(max_payload < (512 - ETHER1394_GASP_OVERHEAD)); |
| 1662 | dgl = priv->bc_dgl; |
| 1663 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) |
| 1664 | priv->bc_dgl++; |
| 1665 | } else { |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 1666 | __be64 guid = get_unaligned((u64 *)eth->h_dest); |
| 1667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | node = eth1394_find_node_guid(&priv->ip_node_list, |
David S. Miller | c20e394 | 2006-10-29 16:14:55 -0800 | [diff] [blame] | 1669 | be64_to_cpu(guid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | if (!node) { |
| 1671 | ret = -EAGAIN; |
| 1672 | goto fail; |
| 1673 | } |
| 1674 | node_info = (struct eth1394_node_info*)node->ud->device.driver_data; |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 1675 | if (node_info->fifo == CSR1212_INVALID_ADDR_SPACE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | ret = -EAGAIN; |
| 1677 | goto fail; |
| 1678 | } |
| 1679 | |
| 1680 | dest_node = node->ud->ne->nodeid; |
| 1681 | max_payload = node_info->maxpayload; |
| 1682 | BUG_ON(max_payload < (512 - ETHER1394_GASP_OVERHEAD)); |
| 1683 | |
| 1684 | dgl = node_info->dgl; |
| 1685 | if (max_payload < dg_size + hdr_type_len[ETH1394_HDR_LF_UF]) |
| 1686 | node_info->dgl++; |
| 1687 | tx_type = ETH1394_WRREQ; |
| 1688 | } |
| 1689 | |
| 1690 | /* If this is an ARP packet, convert it */ |
Ben Collins | 7136b80 | 2006-06-12 18:16:25 -0400 | [diff] [blame] | 1691 | if (proto == htons(ETH_P_ARP)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | ether1394_arp_to_1394arp (skb, dev); |
| 1693 | |
| 1694 | ptask->hdr.words.word1 = 0; |
| 1695 | ptask->hdr.words.word2 = 0; |
| 1696 | ptask->hdr.words.word3 = 0; |
| 1697 | ptask->hdr.words.word4 = 0; |
| 1698 | ptask->skb = skb; |
| 1699 | ptask->priv = priv; |
| 1700 | ptask->tx_type = tx_type; |
| 1701 | |
| 1702 | if (tx_type != ETH1394_GASP) { |
| 1703 | u64 addr; |
| 1704 | |
| 1705 | spin_lock_irqsave(&priv->lock, flags); |
| 1706 | addr = node_info->fifo; |
| 1707 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1708 | |
| 1709 | ptask->addr = addr; |
| 1710 | ptask->dest_node = dest_node; |
| 1711 | } |
| 1712 | |
| 1713 | ptask->tx_type = tx_type; |
| 1714 | ptask->max_payload = max_payload; |
| 1715 | ptask->outstanding_pkts = ether1394_encapsulate_prep(max_payload, proto, |
| 1716 | &ptask->hdr, dg_size, |
| 1717 | dgl); |
| 1718 | |
| 1719 | /* Add the encapsulation header to the fragment */ |
| 1720 | tx_len = ether1394_encapsulate(skb, max_payload, &ptask->hdr); |
| 1721 | dev->trans_start = jiffies; |
| 1722 | if (ether1394_send_packet(ptask, tx_len)) |
| 1723 | goto fail; |
| 1724 | |
| 1725 | netif_wake_queue(dev); |
| 1726 | return 0; |
| 1727 | fail: |
| 1728 | if (ptask) |
| 1729 | kmem_cache_free(packet_task_cache, ptask); |
| 1730 | |
| 1731 | if (skb != NULL) |
| 1732 | dev_kfree_skb(skb); |
| 1733 | |
| 1734 | spin_lock_irqsave (&priv->lock, flags); |
| 1735 | priv->stats.tx_dropped++; |
| 1736 | priv->stats.tx_errors++; |
| 1737 | spin_unlock_irqrestore (&priv->lock, flags); |
| 1738 | |
| 1739 | if (netif_queue_stopped(dev)) |
| 1740 | netif_wake_queue(dev); |
| 1741 | |
| 1742 | return 0; /* returning non-zero causes serious problems */ |
| 1743 | } |
| 1744 | |
| 1745 | static void ether1394_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 1746 | { |
| 1747 | strcpy (info->driver, driver_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | /* FIXME XXX provide sane businfo */ |
| 1749 | strcpy (info->bus_info, "ieee1394"); |
| 1750 | } |
| 1751 | |
| 1752 | static struct ethtool_ops ethtool_ops = { |
| 1753 | .get_drvinfo = ether1394_get_drvinfo |
| 1754 | }; |
| 1755 | |
| 1756 | static int __init ether1394_init_module (void) |
| 1757 | { |
| 1758 | packet_task_cache = kmem_cache_create("packet_task", sizeof(struct packet_task), |
| 1759 | 0, 0, NULL, NULL); |
| 1760 | |
| 1761 | /* Register ourselves as a highlevel driver */ |
| 1762 | hpsb_register_highlevel(ð1394_highlevel); |
| 1763 | |
| 1764 | return hpsb_register_protocol(ð1394_proto_driver); |
| 1765 | } |
| 1766 | |
| 1767 | static void __exit ether1394_exit_module (void) |
| 1768 | { |
| 1769 | hpsb_unregister_protocol(ð1394_proto_driver); |
| 1770 | hpsb_unregister_highlevel(ð1394_highlevel); |
| 1771 | kmem_cache_destroy(packet_task_cache); |
| 1772 | } |
| 1773 | |
| 1774 | module_init(ether1394_init_module); |
| 1775 | module_exit(ether1394_exit_module); |