[PATCH 2/9] NetEffect 10Gb RNIC Driver: main kernel driver c file

2006-10-26 Thread Glenn Grundstrom
Kernel driver patch 2 of 9.

Signed-off-by: Glenn Grundstrom [EMAIL PROTECTED]

==

diff -ruNp old/drivers/infiniband/hw/nes/nes.c
new/drivers/infiniband/hw/nes/nes.c
--- old/drivers/infiniband/hw/nes/nes.c 1969-12-31 18:00:00.0
-0600
+++ new/drivers/infiniband/hw/nes/nes.c 2006-10-25 10:15:49.0
-0500
@@ -0,0 +1,653 @@
+/*
+ * Copyright (c) 2006 NetEffect, Inc. All rights reserved.
+ * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/etherdevice.h
+#include linux/ethtool.h
+#include linux/mii.h
+#include linux/if_vlan.h
+#include linux/crc32.h
+#include linux/in.h
+#include linux/init.h
+#include linux/if_arp.h
+#include asm/io.h
+#include asm/irq.h
+#include asm/byteorder.h
+
+#include rdma/ib_smi.h
+#include rdma/ib_verbs.h
+#include rdma/ib_pack.h
+#include rdma/iw_cm.h
+
+#include nes.h
+
+MODULE_AUTHOR(NetEffect);
+MODULE_DESCRIPTION(NetEffect RNIC Low-level iWARP Driver);
+MODULE_LICENSE(Dual BSD/GPL);
+MODULE_VERSION(DRV_VERSION);
+
+int max_mtu = ETH_DATA_LEN;
+
+
+/* Interoperability */
+int mpa_version = 1;
+module_param(mpa_version, int, 0);
+MODULE_PARM_DESC(mpa_version, MPA version to be used int MPA Req/Resp
(0 or 1));
+
+/* Interoperability */
+int disable_mpa_crc = 0;
+module_param(disable_mpa_crc, int, 0);
+MODULE_PARM_DESC(disable_mpa_crc, Disable checking of MPA CRC);
+
+
+unsigned int send_first = 0;
+module_param(send_first, int, 0);
+MODULE_PARM_DESC(send_first, Send RDMA Message First on Active
Connection);
+
+
+LIST_HEAD(nes_adapter_list);
+LIST_HEAD(nes_dev_list);
+
+static int nes_device_event(struct notifier_block *notifier, unsigned
long event, void *ptr);
+static int nes_inetaddr_event(struct notifier_block *notifier, unsigned
long event, void *ptr);
+static void nes_print_macaddr(struct net_device *netdev);
+static irqreturn_t nes_interrupt(int, void *, struct pt_regs *);
+static int __devinit nes_probe(struct pci_dev *, const struct
pci_device_id *);
+static int nes_suspend(struct pci_dev *, pm_message_t);
+static int nes_resume(struct pci_dev *);
+static void __devexit nes_remove(struct pci_dev *);
+static int __init nes_init_module(void);
+static void __exit nes_exit_module(void);
+
+extern  struct nes_dev  *nes_ifs[];
+
+// _the_ function interface handle to nes_tcpip module
+struct nes_stack_ops *stack_ops_p;
+
+static struct pci_device_id nes_pci_table[] = {
+   {PCI_VENDOR_ID_NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE010,
PCI_ANY_ID, PCI_ANY_ID},
+   {0}
+};
+
+MODULE_DEVICE_TABLE(pci, nes_pci_table);
+
+
+static struct notifier_block nes_dev_notifier = {
+   notifier_call:  nes_device_event
+};
+
+static struct notifier_block nes_inetaddr_notifier = {
+   notifier_call:  nes_inetaddr_event
+};
+
+
+/**
+ * nes_device_event
+ * 
+ * @param notifier
+ * @param event
+ * @param ptr
+ * 
+ * @return int
+ */
+static int nes_device_event(struct notifier_block *notifier,
+   unsigned long
event, void *ptr)
+{
+   struct net_device  *netdev = (struct  net_device *)ptr;
+   struct nes_dev *nesdev;
+
+   dprintk(nes_device_event: notifier %p event=%ld netdev=%p,
interface name = %s.\n,
+   notifier, event, netdev, netdev-name);
+
+   list_for_each_entry(nesdev, nes_dev_list, list) {
+   dprintk(Nesdev list entry = 0x%p.\n, nesdev);
+   if (nesdev-netdev == netdev) {
+   switch (event) {
+ 

Re: [PATCH 2/9] NetEffect 10Gb RNIC Driver: main kernel driver c file

2006-10-26 Thread Roland Dreier
  +static int nes_device_event(struct notifier_block *notifier, unsigned
  long event, void *ptr);
  +static int nes_inetaddr_event(struct notifier_block *notifier, unsigned
  long event, void *ptr);
  +static void nes_print_macaddr(struct net_device *netdev);
  +static irqreturn_t nes_interrupt(int, void *, struct pt_regs *);
  +static int __devinit nes_probe(struct pci_dev *, const struct
  pci_device_id *);
  +static int nes_suspend(struct pci_dev *, pm_message_t);
  +static int nes_resume(struct pci_dev *);
  +static void __devexit nes_remove(struct pci_dev *);
  +static int __init nes_init_module(void);
  +static void __exit nes_exit_module(void);

Some of these declarations are already unneeded (eg at least
nes_init_module and nes_exit_module), and it would be good to
rearrange your code so that the rest can be removed too.

  +// _the_ function interface handle to nes_tcpip module

We prefer /* */ style comments

  +static struct notifier_block nes_dev_notifier = {
  +notifier_call:  nes_device_event
  +};

Standard C syntax (rather than gcc extension is preferred), like:

static struct notifier_block nes_dev_notifier = {
.notifier_call = nes_device_event
};

  +/**
  + * nes_device_event
  + * 
  + * @param notifier
  + * @param event
  + * @param ptr
  + * 
  + * @return int
  + */

There's no point to comments like this.  I can read the function
declaration just fine, so save the screen real estate unless you have
something more to say.

  +unsigned long reg0_start, reg0_flags, reg0_len;
  +unsigned long reg1_start, reg1_flags, reg1_len;

PCI bars are type resource_size_t, which can be bigger than long...

  +assert(pcidev != NULL);
  +assert(ent != NULL);

BUG_ON() is more idiomatic.  But this looks kind of useless anyway --
you'll get a nice enough oops if they are NULL.

  +/* Enable PCI device */
  +ret = pci_enable_device(pcidev);

This isn't major, but comments like this just waste screen space.  I
mean, someone who can't guess what pci_enable_device() does is
probably not going to be helped by the comment either.

  +/* pci tweaks */
  +pci_write_config_word(pcidev, 0x000c, 0xfc10);
  +pci_write_config_dword(pcidev, 0x0048, 0x00480007);

Looks rather magic and fragile.  Register 0xc is the cacheline size
and latency, right?  Why are you tweaking that?

And I assume 0x48 is somewhere in a capability structure.  It's much
better to use pci_find_capability() in that case.  That way when the
hardware guys tell you they have to rearrange the PCI header in the
next rev of the chip, you don't have to touch the chip.  However this
tweaking probably needs to be justified too.

  +/**
  + * nes_suspend - power management
  + */
  +static int nes_suspend(struct pci_dev *pcidev, pm_message_t state)
  +{
  +dprintk(pcidev=%p\n, pcidev);
  +
  +return (0);
  +}
  

Umm, just don't have suspend/resume methods if you don't support it.

  +nes_adapter_free(nesdev-nesadapter);
  +
  +dprintk(nes_remove: calling iounmap.\n);
  +/* Unmap adapter PA space */
  +iounmap(nesdev-regs);
  +
  +/* Unregister with OpenFabrics */
  +if (nesdev-of_device_registered) {
  +dprintk(nes_remove: calling nes_unregister_device.\n);
  +nes_unregister_device(nesdev);
  +}

You can still have upper layers calling into you until
ib_unregister_device() returns, so it looks bogus to do things like
iounmap before then.  I think your cleanup needs to be reordered.

And I don't think you're unregistering with OpenFabrics -- you're just
unregistering with the RDMA midlayer.

  +return (pci_module_init(nes_pci_driver));

Just use pci_register_driver().
 - R.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html