diff options
| author | Bhanu Prakash Gollapudi <bprakash@broadcom.com> | 2011-08-04 20:38:49 -0400 |
|---|---|---|
| committer | James Bottomley <JBottomley@Parallels.com> | 2011-08-27 10:35:46 -0400 |
| commit | d834895c41d34b64a1923fa631e6a64f763ed31c (patch) | |
| tree | 94a3311fed06686b4e327c894fdd1dce78b69cd9 /drivers/scsi/fcoe | |
| parent | 3f8744d147375aca902de7a9f2632a89872565f4 (diff) | |
[SCSI] fcoe: Move common functions to fcoe_transport library
Export fcoe_get_wwn, fcoe_validate_vport_create and fcoe_wwn_to_str so that all
LLDs can use these common function.
Signed-off-by: Bhanu Prakash Gollapudi <bprakash@broadcom.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/fcoe')
| -rw-r--r-- | drivers/scsi/fcoe/fcoe.c | 66 | ||||
| -rw-r--r-- | drivers/scsi/fcoe/fcoe.h | 10 | ||||
| -rw-r--r-- | drivers/scsi/fcoe/fcoe_transport.c | 72 |
3 files changed, 73 insertions, 75 deletions
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c index ba710e350ac5..c30fa27402d9 100644 --- a/drivers/scsi/fcoe/fcoe.c +++ b/drivers/scsi/fcoe/fcoe.c | |||
| @@ -138,7 +138,6 @@ static int fcoe_vport_create(struct fc_vport *, bool disabled); | |||
| 138 | static int fcoe_vport_disable(struct fc_vport *, bool disable); | 138 | static int fcoe_vport_disable(struct fc_vport *, bool disable); |
| 139 | static void fcoe_set_vport_symbolic_name(struct fc_vport *); | 139 | static void fcoe_set_vport_symbolic_name(struct fc_vport *); |
| 140 | static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); | 140 | static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); |
| 141 | static int fcoe_validate_vport_create(struct fc_vport *); | ||
| 142 | 141 | ||
| 143 | static struct libfc_function_template fcoe_libfc_fcn_templ = { | 142 | static struct libfc_function_template fcoe_libfc_fcn_templ = { |
| 144 | .frame_send = fcoe_xmit, | 143 | .frame_send = fcoe_xmit, |
| @@ -577,23 +576,6 @@ static int fcoe_lport_config(struct fc_lport *lport) | |||
| 577 | } | 576 | } |
| 578 | 577 | ||
| 579 | /** | 578 | /** |
| 580 | * fcoe_get_wwn() - Get the world wide name from LLD if it supports it | ||
| 581 | * @netdev: the associated net device | ||
| 582 | * @wwn: the output WWN | ||
| 583 | * @type: the type of WWN (WWPN or WWNN) | ||
| 584 | * | ||
| 585 | * Returns: 0 for success | ||
| 586 | */ | ||
| 587 | static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) | ||
| 588 | { | ||
| 589 | const struct net_device_ops *ops = netdev->netdev_ops; | ||
| 590 | |||
| 591 | if (ops->ndo_fcoe_get_wwn) | ||
| 592 | return ops->ndo_fcoe_get_wwn(netdev, wwn, type); | ||
| 593 | return -EINVAL; | ||
| 594 | } | ||
| 595 | |||
| 596 | /** | ||
| 597 | * fcoe_netdev_features_change - Updates the lport's offload flags based | 579 | * fcoe_netdev_features_change - Updates the lport's offload flags based |
| 598 | * on the LLD netdev's FCoE feature flags | 580 | * on the LLD netdev's FCoE feature flags |
| 599 | */ | 581 | */ |
| @@ -2444,7 +2426,7 @@ static int fcoe_vport_create(struct fc_vport *vport, bool disabled) | |||
| 2444 | 2426 | ||
| 2445 | rc = fcoe_validate_vport_create(vport); | 2427 | rc = fcoe_validate_vport_create(vport); |
| 2446 | if (rc) { | 2428 | if (rc) { |
| 2447 | wwn_to_str(vport->port_name, buf, sizeof(buf)); | 2429 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); |
| 2448 | printk(KERN_ERR "fcoe: Failed to create vport, " | 2430 | printk(KERN_ERR "fcoe: Failed to create vport, " |
| 2449 | "WWPN (0x%s) already exists\n", | 2431 | "WWPN (0x%s) already exists\n", |
| 2450 | buf); | 2432 | buf); |
| @@ -2596,49 +2578,3 @@ static void fcoe_set_port_id(struct fc_lport *lport, | |||
| 2596 | if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) | 2578 | if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) |
| 2597 | fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); | 2579 | fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); |
| 2598 | } | 2580 | } |
| 2599 | |||
| 2600 | /** | ||
| 2601 | * fcoe_validate_vport_create() - Validate a vport before creating it | ||
| 2602 | * @vport: NPIV port to be created | ||
| 2603 | * | ||
| 2604 | * This routine is meant to add validation for a vport before creating it | ||
| 2605 | * via fcoe_vport_create(). | ||
| 2606 | * Current validations are: | ||
| 2607 | * - WWPN supplied is unique for given lport | ||
| 2608 | * | ||
| 2609 | * | ||
| 2610 | */ | ||
| 2611 | static int fcoe_validate_vport_create(struct fc_vport *vport) | ||
| 2612 | { | ||
| 2613 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
| 2614 | struct fc_lport *n_port = shost_priv(shost); | ||
| 2615 | struct fc_lport *vn_port; | ||
| 2616 | int rc = 0; | ||
| 2617 | char buf[32]; | ||
| 2618 | |||
| 2619 | mutex_lock(&n_port->lp_mutex); | ||
| 2620 | |||
| 2621 | wwn_to_str(vport->port_name, buf, sizeof(buf)); | ||
| 2622 | /* Check if the wwpn is not same as that of the lport */ | ||
| 2623 | if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) { | ||
| 2624 | FCOE_DBG("vport WWPN 0x%s is same as that of the " | ||
| 2625 | "base port WWPN\n", buf); | ||
| 2626 | rc = -EINVAL; | ||
| 2627 | goto out; | ||
| 2628 | } | ||
| 2629 | |||
| 2630 | /* Check if there is any existing vport with same wwpn */ | ||
| 2631 | list_for_each_entry(vn_port, &n_port->vports, list) { | ||
| 2632 | if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) { | ||
| 2633 | FCOE_DBG("vport with given WWPN 0x%s already " | ||
| 2634 | "exists\n", buf); | ||
| 2635 | rc = -EINVAL; | ||
| 2636 | break; | ||
| 2637 | } | ||
| 2638 | } | ||
| 2639 | |||
| 2640 | out: | ||
| 2641 | mutex_unlock(&n_port->lp_mutex); | ||
| 2642 | |||
| 2643 | return rc; | ||
| 2644 | } | ||
diff --git a/drivers/scsi/fcoe/fcoe.h b/drivers/scsi/fcoe/fcoe.h index c4a93993c0cf..408a6fd78fb4 100644 --- a/drivers/scsi/fcoe/fcoe.h +++ b/drivers/scsi/fcoe/fcoe.h | |||
| @@ -99,14 +99,4 @@ static inline struct net_device *fcoe_netdev(const struct fc_lport *lport) | |||
| 99 | ((struct fcoe_port *)lport_priv(lport))->priv)->netdev; | 99 | ((struct fcoe_port *)lport_priv(lport))->priv)->netdev; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | static inline void wwn_to_str(u64 wwn, char *buf, int len) | ||
| 103 | { | ||
| 104 | u8 wwpn[8]; | ||
| 105 | |||
| 106 | u64_to_wwn(wwn, wwpn); | ||
| 107 | snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x", | ||
| 108 | wwpn[0], wwpn[1], wwpn[2], wwpn[3], | ||
| 109 | wwpn[4], wwpn[5], wwpn[6], wwpn[7]); | ||
| 110 | } | ||
| 111 | |||
| 112 | #endif /* _FCOE_H_ */ | 102 | #endif /* _FCOE_H_ */ |
diff --git a/drivers/scsi/fcoe/fcoe_transport.c b/drivers/scsi/fcoe/fcoe_transport.c index 41068e8748e7..50c8c4a530aa 100644 --- a/drivers/scsi/fcoe/fcoe_transport.c +++ b/drivers/scsi/fcoe/fcoe_transport.c | |||
| @@ -83,6 +83,78 @@ static struct notifier_block libfcoe_notifier = { | |||
| 83 | .notifier_call = libfcoe_device_notification, | 83 | .notifier_call = libfcoe_device_notification, |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | void fcoe_wwn_to_str(u64 wwn, char *buf, int len) | ||
| 87 | { | ||
| 88 | u8 wwpn[8]; | ||
| 89 | |||
| 90 | u64_to_wwn(wwn, wwpn); | ||
| 91 | snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x", | ||
| 92 | wwpn[0], wwpn[1], wwpn[2], wwpn[3], | ||
| 93 | wwpn[4], wwpn[5], wwpn[6], wwpn[7]); | ||
| 94 | } | ||
| 95 | EXPORT_SYMBOL_GPL(fcoe_wwn_to_str); | ||
| 96 | |||
| 97 | /** | ||
| 98 | * fcoe_validate_vport_create() - Validate a vport before creating it | ||
| 99 | * @vport: NPIV port to be created | ||
| 100 | * | ||
| 101 | * This routine is meant to add validation for a vport before creating it | ||
| 102 | * via fcoe_vport_create(). | ||
| 103 | * Current validations are: | ||
| 104 | * - WWPN supplied is unique for given lport | ||
| 105 | */ | ||
| 106 | int fcoe_validate_vport_create(struct fc_vport *vport) | ||
| 107 | { | ||
| 108 | struct Scsi_Host *shost = vport_to_shost(vport); | ||
| 109 | struct fc_lport *n_port = shost_priv(shost); | ||
| 110 | struct fc_lport *vn_port; | ||
| 111 | int rc = 0; | ||
| 112 | char buf[32]; | ||
| 113 | |||
| 114 | mutex_lock(&n_port->lp_mutex); | ||
| 115 | |||
| 116 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); | ||
| 117 | /* Check if the wwpn is not same as that of the lport */ | ||
| 118 | if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) { | ||
| 119 | LIBFCOE_TRANSPORT_DBG("vport WWPN 0x%s is same as that of the " | ||
| 120 | "base port WWPN\n", buf); | ||
| 121 | rc = -EINVAL; | ||
| 122 | goto out; | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Check if there is any existing vport with same wwpn */ | ||
| 126 | list_for_each_entry(vn_port, &n_port->vports, list) { | ||
| 127 | if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) { | ||
| 128 | LIBFCOE_TRANSPORT_DBG("vport with given WWPN 0x%s " | ||
| 129 | "already exists\n", buf); | ||
| 130 | rc = -EINVAL; | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | out: | ||
| 135 | mutex_unlock(&n_port->lp_mutex); | ||
| 136 | return rc; | ||
| 137 | } | ||
| 138 | EXPORT_SYMBOL_GPL(fcoe_validate_vport_create); | ||
| 139 | |||
| 140 | /** | ||
| 141 | * fcoe_get_wwn() - Get the world wide name from LLD if it supports it | ||
| 142 | * @netdev: the associated net device | ||
| 143 | * @wwn: the output WWN | ||
| 144 | * @type: the type of WWN (WWPN or WWNN) | ||
| 145 | * | ||
| 146 | * Returns: 0 for success | ||
| 147 | */ | ||
| 148 | int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) | ||
| 149 | { | ||
| 150 | const struct net_device_ops *ops = netdev->netdev_ops; | ||
| 151 | |||
| 152 | if (ops->ndo_fcoe_get_wwn) | ||
| 153 | return ops->ndo_fcoe_get_wwn(netdev, wwn, type); | ||
| 154 | return -EINVAL; | ||
| 155 | } | ||
| 156 | EXPORT_SYMBOL_GPL(fcoe_get_wwn); | ||
| 157 | |||
| 86 | /** | 158 | /** |
| 87 | * fcoe_fc_crc() - Calculates the CRC for a given frame | 159 | * fcoe_fc_crc() - Calculates the CRC for a given frame |
| 88 | * @fp: The frame to be checksumed | 160 | * @fp: The frame to be checksumed |
