[Open-FCoE] [PATCH V2 05/13] fcoe: move FIP controller from fcoe_port to fcoe_interface

Joe Eykholt jeykholt at cisco.com
Thu Jul 9 18:34:45 UTC 2009


Chris Leech wrote:
> There is only one FIP state per net_device, so the FIP controller needs to be
> moved from the per-SCSI-host fcoe_port to the per-net_device fcoe_interface
> structure.
> 
> Also changed fcoe_from_ctlr() from a preprocessor macro to an inline function
> around container_of(), to get type checking on the use of the return value.

That change is OK with me, but container_of() already casts the result
to the appropriate type, so it's not really necessary.  If it didn't,
we would want to fix container_of().

> Signed-off-by: Chris Leech <christopher.leech at intel.com>
> ---
> 
>  drivers/scsi/fcoe/fcoe.c |   83 +++++++++++++++++++++-------------------------
>  drivers/scsi/fcoe/fcoe.h |    7 +++-
>  2 files changed, 42 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
> index 4db55d2..e898c5d 100644
> --- a/drivers/scsi/fcoe/fcoe.c
> +++ b/drivers/scsi/fcoe/fcoe.c
> @@ -147,11 +147,9 @@ static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
>  			 struct net_device *orig_dev)
>  {
>  	struct fcoe_interface *fcoe;
> -	struct fcoe_port *port;
>  
>  	fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type);
> -	port = fcoe->priv;
> -	fcoe_ctlr_recv(&port->ctlr, skb);
> +	fcoe_ctlr_recv(&fcoe->ctlr, skb);
>  	return 0;
>  }
>  
> @@ -162,7 +160,7 @@ static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
>   */
>  static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
>  {
> -	skb->dev = fcoe_from_ctlr(fip)->fcoe->real_dev;
> +	skb->dev = fcoe_from_ctlr(fip)->real_dev;
>  	dev_queue_xmit(skb);
>  }
>  
> @@ -178,11 +176,8 @@ static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
>  static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
>  {
>  	struct fcoe_interface *fcoe;
> -	struct fcoe_port *port;
> -
> -	port = fcoe_from_ctlr(fip);
> -	fcoe = port->fcoe;
>  
> +	fcoe = fcoe_from_ctlr(fip);
>  	rtnl_lock();
>  	if (!is_zero_ether_addr(old))
>  		dev_unicast_delete(fcoe->real_dev, old);
> @@ -239,10 +234,10 @@ void fcoe_netdev_cleanup(struct fcoe_port *port)
>  	rtnl_lock();
>  	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
>  	dev_unicast_delete(fcoe->real_dev, flogi_maddr);
> -	if (!is_zero_ether_addr(port->ctlr.data_src_addr))
> -		dev_unicast_delete(fcoe->real_dev, port->ctlr.data_src_addr);
> -	if (port->ctlr.spma)
> -		dev_unicast_delete(fcoe->real_dev, port->ctlr.ctl_src_addr);
> +	if (!is_zero_ether_addr(fcoe->ctlr.data_src_addr))
> +		dev_unicast_delete(fcoe->real_dev, fcoe->ctlr.data_src_addr);
> +	if (fcoe->ctlr.spma)
> +		dev_unicast_delete(fcoe->real_dev, fcoe->ctlr.ctl_src_addr);
>  	dev_mc_delete(fcoe->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
>  	rtnl_unlock();
>  }
> @@ -280,7 +275,7 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
>  	/* Setup lport private data to point to fcoe softc */
>  	port = lport_priv(lp);
>  	fcoe = port->fcoe;
> -	port->ctlr.lp = lp;
> +	fcoe->ctlr.lp = lp;
>  	fcoe->real_dev = netdev;
>  	fcoe->phys_dev = netdev;
>  
> @@ -338,17 +333,17 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
>  	rcu_read_lock();
>  	for_each_dev_addr(netdev, ha) {
>  		if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
> -		    (is_valid_ether_addr(port->ctlr.ctl_src_addr))) {
> -			memcpy(port->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
> -			port->ctlr.spma = 1;
> +		    (is_valid_ether_addr(fcoe->ctlr.ctl_src_addr))) {
> +			memcpy(fcoe->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
> +			fcoe->ctlr.spma = 1;
>  			break;
>  		}
>  	}
>  	rcu_read_unlock();
>  
>  	/* setup Source Mac Address */
> -	if (!port->ctlr.spma)
> -		memcpy(port->ctlr.ctl_src_addr, fcoe->real_dev->dev_addr,
> +	if (!fcoe->ctlr.spma)
> +		memcpy(fcoe->ctlr.ctl_src_addr, fcoe->real_dev->dev_addr,
>  		       fcoe->real_dev->addr_len);
>  
>  	wwnn = fcoe_wwn_from_mac(fcoe->real_dev->dev_addr, 1, 0);
> @@ -365,8 +360,8 @@ static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
>  	rtnl_lock();
>  	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
>  	dev_unicast_add(fcoe->real_dev, flogi_maddr);
> -	if (port->ctlr.spma)
> -		dev_unicast_add(fcoe->real_dev, port->ctlr.ctl_src_addr);
> +	if (fcoe->ctlr.spma)
> +		dev_unicast_add(fcoe->real_dev, fcoe->ctlr.ctl_src_addr);
>  	dev_mc_add(fcoe->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
>  	rtnl_unlock();
>  
> @@ -529,7 +524,7 @@ static void fcoe_if_destroy(struct fc_lport *lport)
>  	fcoe_netdev_cleanup(port);
>  
>  	/* tear-down the FCoE controller */
> -	fcoe_ctlr_destroy(&port->ctlr);
> +	fcoe_ctlr_destroy(&fcoe->ctlr);
>  
>  	/* Free queued packets for the per-CPU receive threads */
>  	fcoe_percpu_clean(lport);
> @@ -654,9 +649,9 @@ static struct fc_lport *fcoe_if_create(struct net_device *netdev,
>  	/*
>  	 * Initialize FIP.
>  	 */
> -	fcoe_ctlr_init(&port->ctlr);
> -	port->ctlr.send = fcoe_fip_send;
> -	port->ctlr.update_mac = fcoe_update_src_mac;
> +	fcoe_ctlr_init(&fcoe->ctlr);
> +	fcoe->ctlr.send = fcoe_fip_send;
> +	fcoe->ctlr.update_mac = fcoe_update_src_mac;
>  
>  	/* configure lport network properties */
>  	rc = fcoe_netdev_config(lport, netdev);
> @@ -706,7 +701,7 @@ static struct fc_lport *fcoe_if_create(struct net_device *netdev,
>  	fc_fabric_login(lport);
>  
>  	if (!fcoe_link_ok(lport))
> -		fcoe_ctlr_link_up(&port->ctlr);
> +		fcoe_ctlr_link_up(&fcoe->ctlr);
>  
>  	dev_hold(netdev);
>  
> @@ -921,15 +916,13 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
>  	struct fc_lport *lp;
>  	struct fcoe_rcv_info *fr;
>  	struct fcoe_interface *fcoe;
> -	struct fcoe_port *port;
>  	struct fc_frame_header *fh;
>  	struct fcoe_percpu_s *fps;
>  	unsigned short oxid;
>  	unsigned int cpu = 0;
>  
>  	fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type);
> -	port = fcoe->priv;
> -	lp = port->ctlr.lp;
> +	lp = fcoe->ctlr.lp;
>  	if (unlikely(lp == NULL)) {
>  		FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
>  		goto err2;
> @@ -1130,13 +1123,13 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
>  	unsigned int hlen;		/* header length implies the version */
>  	unsigned int tlen;		/* trailer length */
>  	unsigned int elen;		/* eth header, may include vlan */
> -	struct fcoe_port *port;
> +	struct fcoe_port *port = lport_priv(lp);
> +	struct fcoe_interface *fcoe = port->fcoe;
>  	u8 sof, eof;
>  	struct fcoe_hdr *hp;
>  
>  	WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
>  
> -	port = lport_priv(lp);
>  	fh = fc_frame_header_get(fp);
>  	skb = fp_skb(fp);
>  	wlen = skb->len / FCOE_WORD_TO_BYTE;
> @@ -1147,7 +1140,7 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
>  	}
>  
>  	if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
> -	    fcoe_ctlr_els_send(&port->ctlr, skb))
> +	    fcoe_ctlr_els_send(&fcoe->ctlr, skb))
>  		return 0;
>  
>  	sof = fr_sof(fp);
> @@ -1198,21 +1191,21 @@ int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
>  	skb_reset_network_header(skb);
>  	skb->mac_len = elen;
>  	skb->protocol = htons(ETH_P_FCOE);
> -	skb->dev = port->fcoe->real_dev;
> +	skb->dev = fcoe->real_dev;
>  
>  	/* fill up mac and fcoe headers */
>  	eh = eth_hdr(skb);
>  	eh->h_proto = htons(ETH_P_FCOE);
> -	if (port->ctlr.map_dest)
> +	if (fcoe->ctlr.map_dest)
>  		fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
>  	else
>  		/* insert GW address */
> -		memcpy(eh->h_dest, port->ctlr.dest_addr, ETH_ALEN);
> +		memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN);
>  
> -	if (unlikely(port->ctlr.flogi_oxid != FC_XID_UNKNOWN))
> -		memcpy(eh->h_source, port->ctlr.ctl_src_addr, ETH_ALEN);
> +	if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN))
> +		memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN);
>  	else
> -		memcpy(eh->h_source, port->ctlr.data_src_addr, ETH_ALEN);
> +		memcpy(eh->h_source, fcoe->ctlr.data_src_addr, ETH_ALEN);
>  
>  	hp = (struct fcoe_hdr *)(eh + 1);
>  	memset(hp, 0, sizeof(*hp));
> @@ -1377,8 +1370,8 @@ int fcoe_percpu_receive_thread(void *arg)
>  			}
>  			fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
>  		}
> -		if (unlikely(port->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
> -		    fcoe_ctlr_recv_flogi(&port->ctlr, fp, mac)) {
> +		if (unlikely(port->fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
> +		    fcoe_ctlr_recv_flogi(&port->fcoe->ctlr, fp, mac)) {
>  			fc_frame_free(fp);
>  			continue;
>  		}
> @@ -1477,7 +1470,6 @@ static int fcoe_device_notification(struct notifier_block *notifier,
>  	struct fc_lport *lp = NULL;
>  	struct net_device *real_dev = ptr;
>  	struct fcoe_interface *fcoe;
> -	struct fcoe_port *port = NULL;
>  	struct fcoe_dev_stats *stats;
>  	u32 link_possible = 1;
>  	u32 mfs;
> @@ -1485,9 +1477,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
>  
>  	read_lock(&fcoe_hostlist_lock);
>  	list_for_each_entry(fcoe, &fcoe_hostlist, list) {
> -		port = fcoe->priv;
>  		if (fcoe->real_dev == real_dev) {
> -			lp = port->ctlr.lp;
> +			lp = fcoe->ctlr.lp;
>  			break;
>  		}
>  	}
> @@ -1519,8 +1510,8 @@ static int fcoe_device_notification(struct notifier_block *notifier,
>  				"from netdev netlink\n", event);
>  	}
>  	if (link_possible && !fcoe_link_ok(lp))
> -		fcoe_ctlr_link_up(&port->ctlr);
> -	else if (fcoe_ctlr_link_down(&port->ctlr)) {
> +		fcoe_ctlr_link_up(&fcoe->ctlr);
> +	else if (fcoe_ctlr_link_down(&fcoe->ctlr)) {
>  		stats = fc_lport_get_stats(lp);
>  		stats->LinkFailureCount++;
>  		fcoe_clean_pending_queue(lp);
> @@ -1837,7 +1828,7 @@ struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
>  	fcoe = fcoe_hostlist_lookup_port(netdev);
>  	read_unlock(&fcoe_hostlist_lock);
>  
> -	return (fcoe) ? fcoe->priv->ctlr.lp : NULL;
> +	return (fcoe) ? fcoe->ctlr.lp : NULL;
>  }
>  
>  /**
> @@ -1938,7 +1929,7 @@ static void __exit fcoe_exit(void)
>  
>  	/* releases the associated fcoe hosts */
>  	list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list)
> -		fcoe_if_destroy(fcoe->priv->ctlr.lp);
> +		fcoe_if_destroy(fcoe->ctlr.lp);
>  
>  	unregister_hotcpu_notifier(&fcoe_cpu_notifier);
>  
> diff --git a/drivers/scsi/fcoe/fcoe.h b/drivers/scsi/fcoe/fcoe.h
> index abcb76e..d351b04 100644
> --- a/drivers/scsi/fcoe/fcoe.h
> +++ b/drivers/scsi/fcoe/fcoe.h
> @@ -86,6 +86,7 @@ struct fcoe_interface {
>  	struct net_device *phys_dev;		/* device with ethtool_ops */
>  	struct packet_type  fcoe_packet_type;
>  	struct packet_type  fip_packet_type;
> +	struct fcoe_ctlr ctlr;
>  };
>  
>  /*
> @@ -98,10 +99,12 @@ struct fcoe_port {
>  	struct sk_buff_head fcoe_pending_queue;
>  	u8	fcoe_pending_queue_active;
>  	struct timer_list timer;		/* queue timer */
> -	struct fcoe_ctlr ctlr;
>  };
>  
> -#define fcoe_from_ctlr(fip) container_of(fip, struct fcoe_port, ctlr)
> +static inline struct fcoe_interface *fcoe_from_ctlr(struct fcoe_ctlr *fip)
> +{
> +	return container_of(fip, struct fcoe_interface, ctlr);
> +}
>  
>  static inline struct net_device *fcoe_netdev(const struct fc_lport *lp)
>  {
> 
> _______________________________________________
> devel mailing list
> devel at open-fcoe.org
> http://www.open-fcoe.org/mailman/listinfo/devel




More information about the devel mailing list