diff options
author | Dhananjay Phadke <dhananjay@netxen.com> | 2009-10-13 01:31:45 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-13 14:48:25 -0400 |
commit | 70f9cf8951e5253cfef821f8dcb92f6fc3af50c6 (patch) | |
tree | 8ed392633d7064b79ed14bc0bfc0acad3c2adca6 /drivers/net/netxen | |
parent | f03b0ebd8e7132bd9adb41348070813feb280300 (diff) |
netxen: add sysfs entries for diag tools
Add sysfs entries to enable register and memory access
for diagnostic tools.
Signed-off-by: Narender Kumar <narender.kumar@qlogic.com>
Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/netxen')
-rw-r--r-- | drivers/net/netxen/netxen_nic.h | 1 | ||||
-rw-r--r-- | drivers/net/netxen/netxen_nic_main.c | 187 |
2 files changed, 188 insertions, 0 deletions
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h index 1047609ef51b..1bdb8f4a3c86 100644 --- a/drivers/net/netxen/netxen_nic.h +++ b/drivers/net/netxen/netxen_nic.h | |||
@@ -1089,6 +1089,7 @@ typedef struct { | |||
1089 | #define NETXEN_NIC_MSIX_ENABLED 0x04 | 1089 | #define NETXEN_NIC_MSIX_ENABLED 0x04 |
1090 | #define NETXEN_NIC_LRO_ENABLED 0x08 | 1090 | #define NETXEN_NIC_LRO_ENABLED 0x08 |
1091 | #define NETXEN_NIC_BRIDGE_ENABLED 0X10 | 1091 | #define NETXEN_NIC_BRIDGE_ENABLED 0X10 |
1092 | #define NETXEN_NIC_DIAG_ENABLED 0x20 | ||
1092 | #define NETXEN_IS_MSI_FAMILY(adapter) \ | 1093 | #define NETXEN_IS_MSI_FAMILY(adapter) \ |
1093 | ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED)) | 1094 | ((adapter)->flags & (NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED)) |
1094 | 1095 | ||
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c index 38529ee55be9..ecbadc5e2899 100644 --- a/drivers/net/netxen/netxen_nic_main.c +++ b/drivers/net/netxen/netxen_nic_main.c | |||
@@ -73,6 +73,8 @@ static void netxen_nic_poll_controller(struct net_device *netdev); | |||
73 | 73 | ||
74 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); | 74 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); |
75 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); | 75 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); |
76 | static void netxen_create_diag_entries(struct netxen_adapter *adapter); | ||
77 | static void netxen_remove_diag_entries(struct netxen_adapter *adapter); | ||
76 | 78 | ||
77 | static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); | 79 | static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter); |
78 | static int netxen_can_start_firmware(struct netxen_adapter *adapter); | 80 | static int netxen_can_start_firmware(struct netxen_adapter *adapter); |
@@ -1307,6 +1309,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1307 | break; | 1309 | break; |
1308 | } | 1310 | } |
1309 | 1311 | ||
1312 | netxen_create_diag_entries(adapter); | ||
1313 | |||
1310 | return 0; | 1314 | return 0; |
1311 | 1315 | ||
1312 | err_out_disable_msi: | 1316 | err_out_disable_msi: |
@@ -1359,6 +1363,8 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev) | |||
1359 | 1363 | ||
1360 | netxen_teardown_intr(adapter); | 1364 | netxen_teardown_intr(adapter); |
1361 | 1365 | ||
1366 | netxen_remove_diag_entries(adapter); | ||
1367 | |||
1362 | netxen_cleanup_pci_map(adapter); | 1368 | netxen_cleanup_pci_map(adapter); |
1363 | 1369 | ||
1364 | netxen_release_firmware(adapter); | 1370 | netxen_release_firmware(adapter); |
@@ -2331,6 +2337,160 @@ static struct device_attribute dev_attr_bridged_mode = { | |||
2331 | .store = netxen_store_bridged_mode, | 2337 | .store = netxen_store_bridged_mode, |
2332 | }; | 2338 | }; |
2333 | 2339 | ||
2340 | static ssize_t | ||
2341 | netxen_store_diag_mode(struct device *dev, | ||
2342 | struct device_attribute *attr, const char *buf, size_t len) | ||
2343 | { | ||
2344 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2345 | unsigned long new; | ||
2346 | |||
2347 | if (strict_strtoul(buf, 2, &new)) | ||
2348 | return -EINVAL; | ||
2349 | |||
2350 | if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2351 | adapter->flags ^= NETXEN_NIC_DIAG_ENABLED; | ||
2352 | |||
2353 | return len; | ||
2354 | } | ||
2355 | |||
2356 | static ssize_t | ||
2357 | netxen_show_diag_mode(struct device *dev, | ||
2358 | struct device_attribute *attr, char *buf) | ||
2359 | { | ||
2360 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2361 | |||
2362 | return sprintf(buf, "%d\n", | ||
2363 | !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)); | ||
2364 | } | ||
2365 | |||
2366 | static struct device_attribute dev_attr_diag_mode = { | ||
2367 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, | ||
2368 | .show = netxen_show_diag_mode, | ||
2369 | .store = netxen_store_diag_mode, | ||
2370 | }; | ||
2371 | |||
2372 | static int | ||
2373 | netxen_sysfs_validate_crb(struct netxen_adapter *adapter, | ||
2374 | loff_t offset, size_t size) | ||
2375 | { | ||
2376 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2377 | return -EIO; | ||
2378 | |||
2379 | if ((size != 4) || (offset & 0x3)) | ||
2380 | return -EINVAL; | ||
2381 | |||
2382 | if (offset < NETXEN_PCI_CRBSPACE) | ||
2383 | return -EINVAL; | ||
2384 | |||
2385 | return 0; | ||
2386 | } | ||
2387 | |||
2388 | static ssize_t | ||
2389 | netxen_sysfs_read_crb(struct kobject *kobj, struct bin_attribute *attr, | ||
2390 | char *buf, loff_t offset, size_t size) | ||
2391 | { | ||
2392 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2393 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2394 | u32 data; | ||
2395 | int ret; | ||
2396 | |||
2397 | ret = netxen_sysfs_validate_crb(adapter, offset, size); | ||
2398 | if (ret != 0) | ||
2399 | return ret; | ||
2400 | |||
2401 | data = NXRD32(adapter, offset); | ||
2402 | memcpy(buf, &data, size); | ||
2403 | return size; | ||
2404 | } | ||
2405 | |||
2406 | static ssize_t | ||
2407 | netxen_sysfs_write_crb(struct kobject *kobj, struct bin_attribute *attr, | ||
2408 | char *buf, loff_t offset, size_t size) | ||
2409 | { | ||
2410 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2411 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2412 | u32 data; | ||
2413 | int ret; | ||
2414 | |||
2415 | ret = netxen_sysfs_validate_crb(adapter, offset, size); | ||
2416 | if (ret != 0) | ||
2417 | return ret; | ||
2418 | |||
2419 | memcpy(&data, buf, size); | ||
2420 | NXWR32(adapter, offset, data); | ||
2421 | return size; | ||
2422 | } | ||
2423 | |||
2424 | static int | ||
2425 | netxen_sysfs_validate_mem(struct netxen_adapter *adapter, | ||
2426 | loff_t offset, size_t size) | ||
2427 | { | ||
2428 | if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED)) | ||
2429 | return -EIO; | ||
2430 | |||
2431 | if ((size != 8) || (offset & 0x7)) | ||
2432 | return -EIO; | ||
2433 | |||
2434 | return 0; | ||
2435 | } | ||
2436 | |||
2437 | static ssize_t | ||
2438 | netxen_sysfs_read_mem(struct kobject *kobj, struct bin_attribute *attr, | ||
2439 | char *buf, loff_t offset, size_t size) | ||
2440 | { | ||
2441 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2442 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2443 | u64 data; | ||
2444 | int ret; | ||
2445 | |||
2446 | ret = netxen_sysfs_validate_mem(adapter, offset, size); | ||
2447 | if (ret != 0) | ||
2448 | return ret; | ||
2449 | |||
2450 | if (adapter->pci_mem_read(adapter, offset, &data)) | ||
2451 | return -EIO; | ||
2452 | |||
2453 | memcpy(buf, &data, size); | ||
2454 | |||
2455 | return size; | ||
2456 | } | ||
2457 | |||
2458 | ssize_t netxen_sysfs_write_mem(struct kobject *kobj, | ||
2459 | struct bin_attribute *attr, char *buf, | ||
2460 | loff_t offset, size_t size) | ||
2461 | { | ||
2462 | struct device *dev = container_of(kobj, struct device, kobj); | ||
2463 | struct netxen_adapter *adapter = dev_get_drvdata(dev); | ||
2464 | u64 data; | ||
2465 | int ret; | ||
2466 | |||
2467 | ret = netxen_sysfs_validate_mem(adapter, offset, size); | ||
2468 | if (ret != 0) | ||
2469 | return ret; | ||
2470 | |||
2471 | memcpy(&data, buf, size); | ||
2472 | |||
2473 | if (adapter->pci_mem_write(adapter, offset, data)) | ||
2474 | return -EIO; | ||
2475 | |||
2476 | return size; | ||
2477 | } | ||
2478 | |||
2479 | |||
2480 | static struct bin_attribute bin_attr_crb = { | ||
2481 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, | ||
2482 | .size = 0, | ||
2483 | .read = netxen_sysfs_read_crb, | ||
2484 | .write = netxen_sysfs_write_crb, | ||
2485 | }; | ||
2486 | |||
2487 | static struct bin_attribute bin_attr_mem = { | ||
2488 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, | ||
2489 | .size = 0, | ||
2490 | .read = netxen_sysfs_read_mem, | ||
2491 | .write = netxen_sysfs_write_mem, | ||
2492 | }; | ||
2493 | |||
2334 | static void | 2494 | static void |
2335 | netxen_create_sysfs_entries(struct netxen_adapter *adapter) | 2495 | netxen_create_sysfs_entries(struct netxen_adapter *adapter) |
2336 | { | 2496 | { |
@@ -2356,6 +2516,33 @@ netxen_remove_sysfs_entries(struct netxen_adapter *adapter) | |||
2356 | device_remove_file(dev, &dev_attr_bridged_mode); | 2516 | device_remove_file(dev, &dev_attr_bridged_mode); |
2357 | } | 2517 | } |
2358 | 2518 | ||
2519 | static void | ||
2520 | netxen_create_diag_entries(struct netxen_adapter *adapter) | ||
2521 | { | ||
2522 | struct pci_dev *pdev = adapter->pdev; | ||
2523 | struct device *dev; | ||
2524 | |||
2525 | dev = &pdev->dev; | ||
2526 | if (device_create_file(dev, &dev_attr_diag_mode)) | ||
2527 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); | ||
2528 | if (device_create_bin_file(dev, &bin_attr_crb)) | ||
2529 | dev_info(dev, "failed to create crb sysfs entry\n"); | ||
2530 | if (device_create_bin_file(dev, &bin_attr_mem)) | ||
2531 | dev_info(dev, "failed to create mem sysfs entry\n"); | ||
2532 | } | ||
2533 | |||
2534 | |||
2535 | static void | ||
2536 | netxen_remove_diag_entries(struct netxen_adapter *adapter) | ||
2537 | { | ||
2538 | struct pci_dev *pdev = adapter->pdev; | ||
2539 | struct device *dev = &pdev->dev; | ||
2540 | |||
2541 | device_remove_file(dev, &dev_attr_diag_mode); | ||
2542 | device_remove_bin_file(dev, &bin_attr_crb); | ||
2543 | device_remove_bin_file(dev, &bin_attr_mem); | ||
2544 | } | ||
2545 | |||
2359 | #ifdef CONFIG_INET | 2546 | #ifdef CONFIG_INET |
2360 | 2547 | ||
2361 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) | 2548 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) |