| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2 |  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 3 |  * All rights reserved | 
 | 4 |  * www.brocade.com | 
 | 5 |  * | 
 | 6 |  * Linux driver for Brocade Fibre Channel Host Bus Adapter. | 
 | 7 |  * | 
 | 8 |  * This program is free software; you can redistribute it and/or modify it | 
 | 9 |  * under the terms of the GNU General Public License (GPL) Version 2 as | 
 | 10 |  * published by the Free Software Foundation | 
 | 11 |  * | 
 | 12 |  * This program is distributed in the hope that it will be useful, but | 
 | 13 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 14 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
 | 15 |  * General Public License for more details. | 
 | 16 |  */ | 
 | 17 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 18 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 19 |  *  bfa_attr.c Linux driver configuration interface module. | 
 | 20 |  */ | 
 | 21 |  | 
 | 22 | #include "bfad_drv.h" | 
 | 23 | #include "bfad_im.h" | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 24 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 25 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 26 |  * FC transport template entry, get SCSI target port ID. | 
 | 27 |  */ | 
| Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 28 | static void | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 29 | bfad_im_get_starget_port_id(struct scsi_target *starget) | 
 | 30 | { | 
 | 31 | 	struct Scsi_Host *shost; | 
 | 32 | 	struct bfad_im_port_s *im_port; | 
 | 33 | 	struct bfad_s         *bfad; | 
 | 34 | 	struct bfad_itnim_s   *itnim = NULL; | 
 | 35 | 	u32        fc_id = -1; | 
 | 36 | 	unsigned long   flags; | 
 | 37 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 38 | 	shost = dev_to_shost(starget->dev.parent); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 39 | 	im_port = (struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 40 | 	bfad = im_port->bfad; | 
 | 41 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 42 |  | 
| Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 43 | 	itnim = bfad_get_itnim(im_port, starget->id); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 44 | 	if (itnim) | 
 | 45 | 		fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim); | 
 | 46 |  | 
 | 47 | 	fc_starget_port_id(starget) = fc_id; | 
 | 48 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 49 | } | 
 | 50 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 51 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 52 |  * FC transport template entry, get SCSI target nwwn. | 
 | 53 |  */ | 
| Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 54 | static void | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 55 | bfad_im_get_starget_node_name(struct scsi_target *starget) | 
 | 56 | { | 
 | 57 | 	struct Scsi_Host *shost; | 
 | 58 | 	struct bfad_im_port_s *im_port; | 
 | 59 | 	struct bfad_s         *bfad; | 
 | 60 | 	struct bfad_itnim_s   *itnim = NULL; | 
 | 61 | 	u64             node_name = 0; | 
 | 62 | 	unsigned long   flags; | 
 | 63 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 64 | 	shost = dev_to_shost(starget->dev.parent); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 65 | 	im_port = (struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 66 | 	bfad = im_port->bfad; | 
 | 67 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 68 |  | 
| Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 69 | 	itnim = bfad_get_itnim(im_port, starget->id); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 70 | 	if (itnim) | 
 | 71 | 		node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim); | 
 | 72 |  | 
| Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 73 | 	fc_starget_node_name(starget) = cpu_to_be64(node_name); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 74 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 75 | } | 
 | 76 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 77 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 78 |  * FC transport template entry, get SCSI target pwwn. | 
 | 79 |  */ | 
| Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 80 | static void | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 81 | bfad_im_get_starget_port_name(struct scsi_target *starget) | 
 | 82 | { | 
 | 83 | 	struct Scsi_Host *shost; | 
 | 84 | 	struct bfad_im_port_s *im_port; | 
 | 85 | 	struct bfad_s         *bfad; | 
 | 86 | 	struct bfad_itnim_s   *itnim = NULL; | 
 | 87 | 	u64             port_name = 0; | 
 | 88 | 	unsigned long   flags; | 
 | 89 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 90 | 	shost = dev_to_shost(starget->dev.parent); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 91 | 	im_port = (struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 92 | 	bfad = im_port->bfad; | 
 | 93 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 94 |  | 
| Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 95 | 	itnim = bfad_get_itnim(im_port, starget->id); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 96 | 	if (itnim) | 
 | 97 | 		port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim); | 
 | 98 |  | 
| Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 99 | 	fc_starget_port_name(starget) = cpu_to_be64(port_name); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 100 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 101 | } | 
 | 102 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 103 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 104 |  * FC transport template entry, get SCSI host port ID. | 
 | 105 |  */ | 
| Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 106 | static void | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 107 | bfad_im_get_host_port_id(struct Scsi_Host *shost) | 
 | 108 | { | 
 | 109 | 	struct bfad_im_port_s *im_port = | 
 | 110 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 111 | 	struct bfad_port_s    *port = im_port->port; | 
 | 112 |  | 
 | 113 | 	fc_host_port_id(shost) = | 
| Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 114 | 			bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port)); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 115 | } | 
 | 116 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 117 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 118 |  * FC transport template entry, get SCSI host port type. | 
 | 119 |  */ | 
 | 120 | static void | 
 | 121 | bfad_im_get_host_port_type(struct Scsi_Host *shost) | 
 | 122 | { | 
 | 123 | 	struct bfad_im_port_s *im_port = | 
 | 124 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 125 | 	struct bfad_s         *bfad = im_port->bfad; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 126 | 	struct bfa_lport_attr_s port_attr; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 127 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 128 | 	bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 129 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 130 | 	switch (port_attr.port_type) { | 
 | 131 | 	case BFA_PORT_TYPE_NPORT: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 132 | 		fc_host_port_type(shost) = FC_PORTTYPE_NPORT; | 
 | 133 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 134 | 	case BFA_PORT_TYPE_NLPORT: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 135 | 		fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; | 
 | 136 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 137 | 	case BFA_PORT_TYPE_P2P: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 138 | 		fc_host_port_type(shost) = FC_PORTTYPE_PTP; | 
 | 139 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 140 | 	case BFA_PORT_TYPE_LPORT: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 141 | 		fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | 
 | 142 | 		break; | 
 | 143 | 	default: | 
 | 144 | 		fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | 
 | 145 | 		break; | 
 | 146 | 	} | 
 | 147 | } | 
 | 148 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 149 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 150 |  * FC transport template entry, get SCSI host port state. | 
 | 151 |  */ | 
 | 152 | static void | 
 | 153 | bfad_im_get_host_port_state(struct Scsi_Host *shost) | 
 | 154 | { | 
 | 155 | 	struct bfad_im_port_s *im_port = | 
 | 156 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 157 | 	struct bfad_s         *bfad = im_port->bfad; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 158 | 	struct bfa_port_attr_s attr; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 159 |  | 
| Krishna Gudipati | 1c8a4c3 | 2010-03-05 19:37:37 -0800 | [diff] [blame] | 160 | 	bfa_fcport_get_attr(&bfad->bfa, &attr); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 161 |  | 
 | 162 | 	switch (attr.port_state) { | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 163 | 	case BFA_PORT_ST_LINKDOWN: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 164 | 		fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | 
 | 165 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 166 | 	case BFA_PORT_ST_LINKUP: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 167 | 		fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | 
 | 168 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 169 | 	case BFA_PORT_ST_DISABLED: | 
 | 170 | 	case BFA_PORT_ST_STOPPED: | 
 | 171 | 	case BFA_PORT_ST_IOCDOWN: | 
 | 172 | 	case BFA_PORT_ST_IOCDIS: | 
 | 173 | 		fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | 
 | 174 | 		break; | 
 | 175 | 	case BFA_PORT_ST_UNINIT: | 
 | 176 | 	case BFA_PORT_ST_ENABLING_QWAIT: | 
 | 177 | 	case BFA_PORT_ST_ENABLING: | 
 | 178 | 	case BFA_PORT_ST_DISABLING_QWAIT: | 
 | 179 | 	case BFA_PORT_ST_DISABLING: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 180 | 	default: | 
 | 181 | 		fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | 
 | 182 | 		break; | 
 | 183 | 	} | 
 | 184 | } | 
 | 185 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 186 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 187 |  * FC transport template entry, get SCSI host active fc4s. | 
 | 188 |  */ | 
 | 189 | static void | 
 | 190 | bfad_im_get_host_active_fc4s(struct Scsi_Host *shost) | 
 | 191 | { | 
 | 192 | 	struct bfad_im_port_s *im_port = | 
 | 193 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 194 | 	struct bfad_port_s    *port = im_port->port; | 
 | 195 |  | 
 | 196 | 	memset(fc_host_active_fc4s(shost), 0, | 
 | 197 | 	       sizeof(fc_host_active_fc4s(shost))); | 
 | 198 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 199 | 	if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM) | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 200 | 		fc_host_active_fc4s(shost)[2] = 1; | 
 | 201 |  | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 202 | 	fc_host_active_fc4s(shost)[7] = 1; | 
 | 203 | } | 
 | 204 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 205 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 206 |  * FC transport template entry, get SCSI host link speed. | 
 | 207 |  */ | 
 | 208 | static void | 
 | 209 | bfad_im_get_host_speed(struct Scsi_Host *shost) | 
 | 210 | { | 
 | 211 | 	struct bfad_im_port_s *im_port = | 
 | 212 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 213 | 	struct bfad_s         *bfad = im_port->bfad; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 214 | 	struct bfa_port_attr_s attr; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 215 |  | 
| Krishna Gudipati | 1c8a4c3 | 2010-03-05 19:37:37 -0800 | [diff] [blame] | 216 | 	bfa_fcport_get_attr(&bfad->bfa, &attr); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 217 | 	switch (attr.speed) { | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 218 | 	case BFA_PORT_SPEED_10GBPS: | 
 | 219 | 		fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | 
 | 220 | 		break; | 
| Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 221 | 	case BFA_PORT_SPEED_16GBPS: | 
 | 222 | 		fc_host_speed(shost) = FC_PORTSPEED_16GBIT; | 
 | 223 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 224 | 	case BFA_PORT_SPEED_8GBPS: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 225 | 		fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | 
 | 226 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 227 | 	case BFA_PORT_SPEED_4GBPS: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 228 | 		fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | 
 | 229 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 230 | 	case BFA_PORT_SPEED_2GBPS: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 231 | 		fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | 
 | 232 | 		break; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 233 | 	case BFA_PORT_SPEED_1GBPS: | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 234 | 		fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | 
 | 235 | 		break; | 
 | 236 | 	default: | 
 | 237 | 		fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | 
 | 238 | 		break; | 
 | 239 | 	} | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 240 | } | 
 | 241 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 242 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 243 |  * FC transport template entry, get SCSI host port type. | 
 | 244 |  */ | 
 | 245 | static void | 
 | 246 | bfad_im_get_host_fabric_name(struct Scsi_Host *shost) | 
 | 247 | { | 
 | 248 | 	struct bfad_im_port_s *im_port = | 
 | 249 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 250 | 	struct bfad_port_s    *port = im_port->port; | 
 | 251 | 	wwn_t           fabric_nwwn = 0; | 
 | 252 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 253 | 	fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 254 |  | 
| Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 255 | 	fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 256 |  | 
 | 257 | } | 
 | 258 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 259 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 260 |  * FC transport template entry, get BFAD statistics. | 
 | 261 |  */ | 
 | 262 | static struct fc_host_statistics * | 
 | 263 | bfad_im_get_stats(struct Scsi_Host *shost) | 
 | 264 | { | 
 | 265 | 	struct bfad_im_port_s *im_port = | 
 | 266 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 267 | 	struct bfad_s         *bfad = im_port->bfad; | 
 | 268 | 	struct bfad_hal_comp fcomp; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 269 | 	union bfa_port_stats_u *fcstats; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 270 | 	struct fc_host_statistics *hstats; | 
 | 271 | 	bfa_status_t    rc; | 
 | 272 | 	unsigned long   flags; | 
 | 273 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 274 | 	fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL); | 
 | 275 | 	if (fcstats == NULL) | 
 | 276 | 		return NULL; | 
 | 277 |  | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 278 | 	hstats = &bfad->link_stats; | 
 | 279 | 	init_completion(&fcomp.comp); | 
 | 280 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 281 | 	memset(hstats, 0, sizeof(struct fc_host_statistics)); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 282 | 	rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa), | 
 | 283 | 				fcstats, bfad_hcb_comp, &fcomp); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 284 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 285 | 	if (rc != BFA_STATUS_OK) | 
 | 286 | 		return NULL; | 
 | 287 |  | 
 | 288 | 	wait_for_completion(&fcomp.comp); | 
 | 289 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 290 | 	/* Fill the fc_host_statistics structure */ | 
 | 291 | 	hstats->seconds_since_last_reset = fcstats->fc.secs_reset; | 
 | 292 | 	hstats->tx_frames = fcstats->fc.tx_frames; | 
 | 293 | 	hstats->tx_words  = fcstats->fc.tx_words; | 
 | 294 | 	hstats->rx_frames = fcstats->fc.rx_frames; | 
 | 295 | 	hstats->rx_words  = fcstats->fc.rx_words; | 
 | 296 | 	hstats->lip_count = fcstats->fc.lip_count; | 
 | 297 | 	hstats->nos_count = fcstats->fc.nos_count; | 
 | 298 | 	hstats->error_frames = fcstats->fc.error_frames; | 
 | 299 | 	hstats->dumped_frames = fcstats->fc.dropped_frames; | 
 | 300 | 	hstats->link_failure_count = fcstats->fc.link_failures; | 
 | 301 | 	hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs; | 
 | 302 | 	hstats->loss_of_signal_count = fcstats->fc.loss_of_signals; | 
 | 303 | 	hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs; | 
 | 304 | 	hstats->invalid_crc_count = fcstats->fc.invalid_crcs; | 
 | 305 |  | 
 | 306 | 	kfree(fcstats); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 307 | 	return hstats; | 
 | 308 | } | 
 | 309 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 310 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 311 |  * FC transport template entry, reset BFAD statistics. | 
 | 312 |  */ | 
 | 313 | static void | 
 | 314 | bfad_im_reset_stats(struct Scsi_Host *shost) | 
 | 315 | { | 
 | 316 | 	struct bfad_im_port_s *im_port = | 
 | 317 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 318 | 	struct bfad_s         *bfad = im_port->bfad; | 
 | 319 | 	struct bfad_hal_comp fcomp; | 
 | 320 | 	unsigned long   flags; | 
 | 321 | 	bfa_status_t    rc; | 
 | 322 |  | 
 | 323 | 	init_completion(&fcomp.comp); | 
 | 324 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
| Krishna Gudipati | ca8b432 | 2010-03-05 19:38:07 -0800 | [diff] [blame] | 325 | 	rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp, | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 326 | 					&fcomp); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 327 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 328 |  | 
 | 329 | 	if (rc != BFA_STATUS_OK) | 
 | 330 | 		return; | 
 | 331 |  | 
 | 332 | 	wait_for_completion(&fcomp.comp); | 
 | 333 |  | 
 | 334 | 	return; | 
 | 335 | } | 
 | 336 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 337 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 338 |  * FC transport template entry, get rport loss timeout. | 
 | 339 |  */ | 
 | 340 | static void | 
 | 341 | bfad_im_get_rport_loss_tmo(struct fc_rport *rport) | 
 | 342 | { | 
 | 343 | 	struct bfad_itnim_data_s *itnim_data = rport->dd_data; | 
 | 344 | 	struct bfad_itnim_s   *itnim = itnim_data->itnim; | 
 | 345 | 	struct bfad_s         *bfad = itnim->im->bfad; | 
 | 346 | 	unsigned long   flags; | 
 | 347 |  | 
 | 348 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 349 | 	rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa); | 
 | 350 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 351 | } | 
 | 352 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 353 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 354 |  * FC transport template entry, set rport loss timeout. | 
 | 355 |  */ | 
 | 356 | static void | 
 | 357 | bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) | 
 | 358 | { | 
 | 359 | 	struct bfad_itnim_data_s *itnim_data = rport->dd_data; | 
 | 360 | 	struct bfad_itnim_s   *itnim = itnim_data->itnim; | 
 | 361 | 	struct bfad_s         *bfad = itnim->im->bfad; | 
 | 362 | 	unsigned long   flags; | 
 | 363 |  | 
 | 364 | 	if (timeout > 0) { | 
 | 365 | 		spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 366 | 		bfa_fcpim_path_tov_set(&bfad->bfa, timeout); | 
 | 367 | 		rport->dev_loss_tmo = bfa_fcpim_path_tov_get(&bfad->bfa); | 
 | 368 | 		spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 369 | 	} | 
 | 370 |  | 
 | 371 | } | 
 | 372 |  | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 373 | static int | 
 | 374 | bfad_im_vport_create(struct fc_vport *fc_vport, bool disable) | 
 | 375 | { | 
 | 376 | 	char *vname = fc_vport->symbolic_name; | 
 | 377 | 	struct Scsi_Host *shost = fc_vport->shost; | 
 | 378 | 	struct bfad_im_port_s *im_port = | 
 | 379 | 		(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 380 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 381 | 	struct bfa_lport_cfg_s port_cfg; | 
 | 382 | 	struct bfad_vport_s *vp; | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 383 | 	int status = 0, rc; | 
 | 384 | 	unsigned long flags; | 
 | 385 |  | 
 | 386 | 	memset(&port_cfg, 0, sizeof(port_cfg)); | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 387 | 	u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn); | 
 | 388 | 	u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 389 | 	if (strlen(vname) > 0) | 
 | 390 | 		strcpy((char *)&port_cfg.sym_name, vname); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 391 | 	port_cfg.roles = BFA_LPORT_ROLE_FCP_IM; | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 392 |  | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 393 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 394 | 	list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) { | 
 | 395 | 		if (port_cfg.pwwn == | 
 | 396 | 				vp->fcs_vport.lport.port_cfg.pwwn) { | 
 | 397 | 			port_cfg.preboot_vp = | 
 | 398 | 				vp->fcs_vport.lport.port_cfg.preboot_vp; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 399 | 			break; | 
 | 400 | 		} | 
 | 401 | 	} | 
 | 402 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 403 |  | 
 | 404 | 	rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 405 | 	if (rc == BFA_STATUS_OK) { | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 406 | 		struct bfad_vport_s *vport; | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 407 | 		struct bfa_fcs_vport_s *fcs_vport; | 
 | 408 | 		struct Scsi_Host *vshost; | 
 | 409 |  | 
 | 410 | 		spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 411 | 		fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, | 
 | 412 | 					port_cfg.pwwn); | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 413 | 		spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 414 | 		if (fcs_vport == NULL) | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 415 | 			return VPCERR_BAD_WWN; | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 416 |  | 
 | 417 | 		fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); | 
 | 418 | 		if (disable) { | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 419 | 			spin_lock_irqsave(&bfad->bfad_lock, flags); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 420 | 			bfa_fcs_vport_stop(fcs_vport); | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 421 | 			spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 422 | 			fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); | 
 | 423 | 		} | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 424 |  | 
 | 425 | 		vport = fcs_vport->vport_drv; | 
 | 426 | 		vshost = vport->drv_port.im_port->shost; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 427 | 		fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn); | 
 | 428 | 		fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn); | 
| Krishna Gudipati | 6192bd7 | 2012-05-11 17:49:59 -0700 | [diff] [blame] | 429 | 		fc_host_supported_classes(vshost) = FC_COS_CLASS3; | 
 | 430 |  | 
 | 431 | 		memset(fc_host_supported_fc4s(vshost), 0, | 
 | 432 | 			sizeof(fc_host_supported_fc4s(vshost))); | 
 | 433 |  | 
 | 434 | 		/* For FCP type 0x08 */ | 
 | 435 | 		if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM) | 
 | 436 | 			fc_host_supported_fc4s(vshost)[2] = 1; | 
 | 437 |  | 
 | 438 | 		/* For fibre channel services type 0x20 */ | 
 | 439 | 		fc_host_supported_fc4s(vshost)[7] = 1; | 
 | 440 |  | 
 | 441 | 		fc_host_supported_speeds(vshost) = | 
 | 442 | 				bfad_im_supported_speeds(&bfad->bfa); | 
 | 443 | 		fc_host_maxframe_size(vshost) = | 
 | 444 | 				bfa_fcport_get_maxfrsize(&bfad->bfa); | 
 | 445 |  | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 446 | 		fc_vport->dd_data = vport; | 
 | 447 | 		vport->drv_port.im_port->fc_vport = fc_vport; | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 448 | 	} else if (rc == BFA_STATUS_INVALID_WWN) | 
 | 449 | 		return VPCERR_BAD_WWN; | 
 | 450 | 	else if (rc == BFA_STATUS_VPORT_EXISTS) | 
 | 451 | 		return VPCERR_BAD_WWN; | 
 | 452 | 	else if (rc == BFA_STATUS_VPORT_MAX) | 
 | 453 | 		return VPCERR_NO_FABRIC_SUPP; | 
 | 454 | 	else if (rc == BFA_STATUS_VPORT_WWN_BP) | 
 | 455 | 		return VPCERR_BAD_WWN; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 456 | 	else | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 457 | 		return FC_VPORT_FAILED; | 
 | 458 |  | 
 | 459 | 	return status; | 
 | 460 | } | 
 | 461 |  | 
| Krishna Gudipati | acea241 | 2012-03-13 17:37:26 -0700 | [diff] [blame] | 462 | int | 
 | 463 | bfad_im_issue_fc_host_lip(struct Scsi_Host *shost) | 
 | 464 | { | 
 | 465 | 	struct bfad_im_port_s *im_port = | 
 | 466 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 467 | 	struct bfad_s *bfad = im_port->bfad; | 
 | 468 | 	struct bfad_hal_comp fcomp; | 
 | 469 | 	unsigned long flags; | 
 | 470 | 	uint32_t status; | 
 | 471 |  | 
 | 472 | 	init_completion(&fcomp.comp); | 
 | 473 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 474 | 	status = bfa_port_disable(&bfad->bfa.modules.port, | 
 | 475 | 					bfad_hcb_comp, &fcomp); | 
 | 476 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 477 |  | 
 | 478 | 	if (status != BFA_STATUS_OK) | 
 | 479 | 		return -EIO; | 
 | 480 |  | 
 | 481 | 	wait_for_completion(&fcomp.comp); | 
 | 482 | 	if (fcomp.status != BFA_STATUS_OK) | 
 | 483 | 		return -EIO; | 
 | 484 |  | 
 | 485 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 486 | 	status = bfa_port_enable(&bfad->bfa.modules.port, | 
 | 487 | 					bfad_hcb_comp, &fcomp); | 
 | 488 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 489 | 	if (status != BFA_STATUS_OK) | 
 | 490 | 		return -EIO; | 
 | 491 |  | 
 | 492 | 	wait_for_completion(&fcomp.comp); | 
 | 493 | 	if (fcomp.status != BFA_STATUS_OK) | 
 | 494 | 		return -EIO; | 
 | 495 |  | 
 | 496 | 	return 0; | 
 | 497 | } | 
 | 498 |  | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 499 | static int | 
 | 500 | bfad_im_vport_delete(struct fc_vport *fc_vport) | 
 | 501 | { | 
 | 502 | 	struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data; | 
 | 503 | 	struct bfad_im_port_s *im_port = | 
 | 504 | 			(struct bfad_im_port_s *) vport->drv_port.im_port; | 
 | 505 | 	struct bfad_s *bfad = im_port->bfad; | 
 | 506 | 	struct bfad_port_s *port; | 
 | 507 | 	struct bfa_fcs_vport_s *fcs_vport; | 
 | 508 | 	struct Scsi_Host *vshost; | 
 | 509 | 	wwn_t   pwwn; | 
 | 510 | 	int rc; | 
 | 511 | 	unsigned long flags; | 
 | 512 | 	struct completion fcomp; | 
 | 513 |  | 
| Krishna Gudipati | ff179e0 | 2012-03-13 17:40:31 -0700 | [diff] [blame] | 514 | 	if (im_port->flags & BFAD_PORT_DELETE) { | 
 | 515 | 		bfad_scsi_host_free(bfad, im_port); | 
 | 516 | 		list_del(&vport->list_entry); | 
| Krishna Gudipati | 17c201b | 2012-04-09 18:40:01 -0700 | [diff] [blame] | 517 | 		kfree(vport); | 
| Krishna Gudipati | ff179e0 | 2012-03-13 17:40:31 -0700 | [diff] [blame] | 518 | 		return 0; | 
 | 519 | 	} | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 520 |  | 
 | 521 | 	port = im_port->port; | 
 | 522 |  | 
 | 523 | 	vshost = vport->drv_port.im_port->shost; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 524 | 	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 525 |  | 
 | 526 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 527 | 	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); | 
 | 528 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 529 |  | 
 | 530 | 	if (fcs_vport == NULL) | 
 | 531 | 		return VPCERR_BAD_WWN; | 
 | 532 |  | 
 | 533 | 	vport->drv_port.flags |= BFAD_PORT_DELETE; | 
 | 534 |  | 
 | 535 | 	vport->comp_del = &fcomp; | 
 | 536 | 	init_completion(vport->comp_del); | 
 | 537 |  | 
 | 538 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 539 | 	rc = bfa_fcs_vport_delete(&vport->fcs_vport); | 
 | 540 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 541 |  | 
| Jing Huang | c54d557 | 2010-07-08 20:01:49 -0700 | [diff] [blame] | 542 | 	if (rc == BFA_STATUS_PBC) { | 
 | 543 | 		vport->drv_port.flags &= ~BFAD_PORT_DELETE; | 
 | 544 | 		vport->comp_del = NULL; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 545 | 		return -1; | 
| Jing Huang | c54d557 | 2010-07-08 20:01:49 -0700 | [diff] [blame] | 546 | 	} | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 547 |  | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 548 | 	wait_for_completion(vport->comp_del); | 
 | 549 |  | 
| Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 550 | 	bfad_scsi_host_free(bfad, im_port); | 
| Krishna Gudipati | 5b7db7a | 2011-12-20 18:58:32 -0800 | [diff] [blame] | 551 | 	list_del(&vport->list_entry); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 552 | 	kfree(vport); | 
 | 553 |  | 
 | 554 | 	return 0; | 
 | 555 | } | 
 | 556 |  | 
 | 557 | static int | 
 | 558 | bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable) | 
 | 559 | { | 
 | 560 | 	struct bfad_vport_s *vport; | 
 | 561 | 	struct bfad_s *bfad; | 
 | 562 | 	struct bfa_fcs_vport_s *fcs_vport; | 
 | 563 | 	struct Scsi_Host *vshost; | 
 | 564 | 	wwn_t   pwwn; | 
 | 565 | 	unsigned long flags; | 
 | 566 |  | 
 | 567 | 	vport = (struct bfad_vport_s *)fc_vport->dd_data; | 
 | 568 | 	bfad = vport->drv_port.bfad; | 
 | 569 | 	vshost = vport->drv_port.im_port->shost; | 
| Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 570 | 	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 571 |  | 
 | 572 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 573 | 	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); | 
 | 574 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 575 |  | 
 | 576 | 	if (fcs_vport == NULL) | 
 | 577 | 		return VPCERR_BAD_WWN; | 
 | 578 |  | 
 | 579 | 	if (disable) { | 
 | 580 | 		bfa_fcs_vport_stop(fcs_vport); | 
 | 581 | 		fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); | 
 | 582 | 	} else { | 
 | 583 | 		bfa_fcs_vport_start(fcs_vport); | 
 | 584 | 		fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); | 
 | 585 | 	} | 
 | 586 |  | 
 | 587 | 	return 0; | 
 | 588 | } | 
 | 589 |  | 
| Krishna Gudipati | ebfe839 | 2012-08-22 19:50:20 -0700 | [diff] [blame] | 590 | void | 
 | 591 | bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport) | 
 | 592 | { | 
 | 593 | 	struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data; | 
 | 594 | 	struct bfad_im_port_s *im_port = | 
 | 595 | 			(struct bfad_im_port_s *)vport->drv_port.im_port; | 
 | 596 | 	struct bfad_s *bfad = im_port->bfad; | 
 | 597 | 	struct Scsi_Host *vshost = vport->drv_port.im_port->shost; | 
 | 598 | 	char *sym_name = fc_vport->symbolic_name; | 
 | 599 | 	struct bfa_fcs_vport_s *fcs_vport; | 
 | 600 | 	wwn_t	pwwn; | 
 | 601 | 	unsigned long flags; | 
 | 602 |  | 
 | 603 | 	u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); | 
 | 604 |  | 
 | 605 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 606 | 	fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); | 
 | 607 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 608 |  | 
 | 609 | 	if (fcs_vport == NULL) | 
 | 610 | 		return; | 
 | 611 |  | 
 | 612 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
 | 613 | 	if (strlen(sym_name) > 0) { | 
 | 614 | 		strcpy(fcs_vport->lport.port_cfg.sym_name.symname, sym_name); | 
 | 615 | 		bfa_fcs_lport_ns_util_send_rspn_id( | 
 | 616 | 			BFA_FCS_GET_NS_FROM_PORT((&fcs_vport->lport)), NULL); | 
 | 617 | 	} | 
 | 618 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 619 | } | 
 | 620 |  | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 621 | struct fc_function_template bfad_im_fc_function_template = { | 
 | 622 |  | 
 | 623 | 	/* Target dynamic attributes */ | 
 | 624 | 	.get_starget_port_id = bfad_im_get_starget_port_id, | 
 | 625 | 	.show_starget_port_id = 1, | 
 | 626 | 	.get_starget_node_name = bfad_im_get_starget_node_name, | 
 | 627 | 	.show_starget_node_name = 1, | 
 | 628 | 	.get_starget_port_name = bfad_im_get_starget_port_name, | 
 | 629 | 	.show_starget_port_name = 1, | 
 | 630 |  | 
 | 631 | 	/* Host dynamic attribute */ | 
 | 632 | 	.get_host_port_id = bfad_im_get_host_port_id, | 
 | 633 | 	.show_host_port_id = 1, | 
 | 634 |  | 
 | 635 | 	/* Host fixed attributes */ | 
 | 636 | 	.show_host_node_name = 1, | 
 | 637 | 	.show_host_port_name = 1, | 
 | 638 | 	.show_host_supported_classes = 1, | 
 | 639 | 	.show_host_supported_fc4s = 1, | 
 | 640 | 	.show_host_supported_speeds = 1, | 
 | 641 | 	.show_host_maxframe_size = 1, | 
 | 642 |  | 
 | 643 | 	/* More host dynamic attributes */ | 
 | 644 | 	.show_host_port_type = 1, | 
 | 645 | 	.get_host_port_type = bfad_im_get_host_port_type, | 
 | 646 | 	.show_host_port_state = 1, | 
 | 647 | 	.get_host_port_state = bfad_im_get_host_port_state, | 
 | 648 | 	.show_host_active_fc4s = 1, | 
 | 649 | 	.get_host_active_fc4s = bfad_im_get_host_active_fc4s, | 
 | 650 | 	.show_host_speed = 1, | 
 | 651 | 	.get_host_speed = bfad_im_get_host_speed, | 
 | 652 | 	.show_host_fabric_name = 1, | 
 | 653 | 	.get_host_fabric_name = bfad_im_get_host_fabric_name, | 
 | 654 |  | 
 | 655 | 	.show_host_symbolic_name = 1, | 
 | 656 |  | 
 | 657 | 	/* Statistics */ | 
 | 658 | 	.get_fc_host_stats = bfad_im_get_stats, | 
 | 659 | 	.reset_fc_host_stats = bfad_im_reset_stats, | 
 | 660 |  | 
 | 661 | 	/* Allocation length for host specific data */ | 
 | 662 | 	.dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), | 
 | 663 |  | 
 | 664 | 	/* Remote port fixed attributes */ | 
 | 665 | 	.show_rport_maxframe_size = 1, | 
 | 666 | 	.show_rport_supported_classes = 1, | 
 | 667 | 	.show_rport_dev_loss_tmo = 1, | 
 | 668 | 	.get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo, | 
 | 669 | 	.set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, | 
| Krishna Gudipati | acea241 | 2012-03-13 17:37:26 -0700 | [diff] [blame] | 670 | 	.issue_fc_host_lip = bfad_im_issue_fc_host_lip, | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 671 | 	.vport_create = bfad_im_vport_create, | 
 | 672 | 	.vport_delete = bfad_im_vport_delete, | 
 | 673 | 	.vport_disable = bfad_im_vport_disable, | 
| Krishna Gudipati | ebfe839 | 2012-08-22 19:50:20 -0700 | [diff] [blame] | 674 | 	.set_vport_symbolic_name = bfad_im_vport_set_symbolic_name, | 
| Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 675 | 	.bsg_request = bfad_im_bsg_request, | 
 | 676 | 	.bsg_timeout = bfad_im_bsg_timeout, | 
| Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 677 | }; | 
 | 678 |  | 
 | 679 | struct fc_function_template bfad_im_vport_fc_function_template = { | 
 | 680 |  | 
 | 681 | 	/* Target dynamic attributes */ | 
 | 682 | 	.get_starget_port_id = bfad_im_get_starget_port_id, | 
 | 683 | 	.show_starget_port_id = 1, | 
 | 684 | 	.get_starget_node_name = bfad_im_get_starget_node_name, | 
 | 685 | 	.show_starget_node_name = 1, | 
 | 686 | 	.get_starget_port_name = bfad_im_get_starget_port_name, | 
 | 687 | 	.show_starget_port_name = 1, | 
 | 688 |  | 
 | 689 | 	/* Host dynamic attribute */ | 
 | 690 | 	.get_host_port_id = bfad_im_get_host_port_id, | 
 | 691 | 	.show_host_port_id = 1, | 
 | 692 |  | 
 | 693 | 	/* Host fixed attributes */ | 
 | 694 | 	.show_host_node_name = 1, | 
 | 695 | 	.show_host_port_name = 1, | 
 | 696 | 	.show_host_supported_classes = 1, | 
 | 697 | 	.show_host_supported_fc4s = 1, | 
 | 698 | 	.show_host_supported_speeds = 1, | 
 | 699 | 	.show_host_maxframe_size = 1, | 
 | 700 |  | 
 | 701 | 	/* More host dynamic attributes */ | 
 | 702 | 	.show_host_port_type = 1, | 
 | 703 | 	.get_host_port_type = bfad_im_get_host_port_type, | 
 | 704 | 	.show_host_port_state = 1, | 
 | 705 | 	.get_host_port_state = bfad_im_get_host_port_state, | 
 | 706 | 	.show_host_active_fc4s = 1, | 
 | 707 | 	.get_host_active_fc4s = bfad_im_get_host_active_fc4s, | 
 | 708 | 	.show_host_speed = 1, | 
 | 709 | 	.get_host_speed = bfad_im_get_host_speed, | 
 | 710 | 	.show_host_fabric_name = 1, | 
 | 711 | 	.get_host_fabric_name = bfad_im_get_host_fabric_name, | 
 | 712 |  | 
 | 713 | 	.show_host_symbolic_name = 1, | 
 | 714 |  | 
 | 715 | 	/* Statistics */ | 
 | 716 | 	.get_fc_host_stats = bfad_im_get_stats, | 
 | 717 | 	.reset_fc_host_stats = bfad_im_reset_stats, | 
 | 718 |  | 
 | 719 | 	/* Allocation length for host specific data */ | 
 | 720 | 	.dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), | 
 | 721 |  | 
 | 722 | 	/* Remote port fixed attributes */ | 
 | 723 | 	.show_rport_maxframe_size = 1, | 
 | 724 | 	.show_rport_supported_classes = 1, | 
 | 725 | 	.show_rport_dev_loss_tmo = 1, | 
 | 726 | 	.get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo, | 
 | 727 | 	.set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 728 | }; | 
 | 729 |  | 
| Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 730 | /* | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 731 |  *  Scsi_Host_attrs SCSI host attributes | 
 | 732 |  */ | 
 | 733 | static ssize_t | 
 | 734 | bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr, | 
 | 735 | 			 char *buf) | 
 | 736 | { | 
 | 737 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 738 | 	struct bfad_im_port_s *im_port = | 
 | 739 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 740 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 741 | 	char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 742 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 743 | 	bfa_get_adapter_serial_num(&bfad->bfa, serial_num); | 
 | 744 | 	return snprintf(buf, PAGE_SIZE, "%s\n", serial_num); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 745 | } | 
 | 746 |  | 
 | 747 | static ssize_t | 
 | 748 | bfad_im_model_show(struct device *dev, struct device_attribute *attr, | 
 | 749 | 			char *buf) | 
 | 750 | { | 
 | 751 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 752 | 	struct bfad_im_port_s *im_port = | 
 | 753 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 754 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 755 | 	char model[BFA_ADAPTER_MODEL_NAME_LEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 756 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 757 | 	bfa_get_adapter_model(&bfad->bfa, model); | 
 | 758 | 	return snprintf(buf, PAGE_SIZE, "%s\n", model); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 759 | } | 
 | 760 |  | 
 | 761 | static ssize_t | 
 | 762 | bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr, | 
 | 763 | 				 char *buf) | 
 | 764 | { | 
 | 765 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 766 | 	struct bfad_im_port_s *im_port = | 
 | 767 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 768 | 	struct bfad_s *bfad = im_port->bfad; | 
 | 769 | 	char model[BFA_ADAPTER_MODEL_NAME_LEN]; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 770 | 	char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN]; | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 771 | 	int nports = 0; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 772 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 773 | 	bfa_get_adapter_model(&bfad->bfa, model); | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 774 | 	nports = bfa_get_nports(&bfad->bfa); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 775 | 	if (!strcmp(model, "Brocade-425")) | 
 | 776 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 777 | 			"Brocade 4Gbps PCIe dual port FC HBA"); | 
 | 778 | 	else if (!strcmp(model, "Brocade-825")) | 
 | 779 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 780 | 			"Brocade 8Gbps PCIe dual port FC HBA"); | 
 | 781 | 	else if (!strcmp(model, "Brocade-42B")) | 
 | 782 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 783 | 			"Brocade 4Gbps PCIe dual port FC HBA for HP"); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 784 | 	else if (!strcmp(model, "Brocade-82B")) | 
 | 785 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 786 | 			"Brocade 8Gbps PCIe dual port FC HBA for HP"); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 787 | 	else if (!strcmp(model, "Brocade-1010")) | 
 | 788 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 789 | 			"Brocade 10Gbps single port CNA"); | 
 | 790 | 	else if (!strcmp(model, "Brocade-1020")) | 
 | 791 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 792 | 			"Brocade 10Gbps dual port CNA"); | 
 | 793 | 	else if (!strcmp(model, "Brocade-1007")) | 
 | 794 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 795 | 			"Brocade 10Gbps CNA for IBM Blade Center"); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 796 | 	else if (!strcmp(model, "Brocade-415")) | 
 | 797 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 798 | 			"Brocade 4Gbps PCIe single port FC HBA"); | 
 | 799 | 	else if (!strcmp(model, "Brocade-815")) | 
 | 800 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 801 | 			"Brocade 8Gbps PCIe single port FC HBA"); | 
 | 802 | 	else if (!strcmp(model, "Brocade-41B")) | 
 | 803 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 804 | 			"Brocade 4Gbps PCIe single port FC HBA for HP"); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 805 | 	else if (!strcmp(model, "Brocade-81B")) | 
 | 806 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 807 | 			"Brocade 8Gbps PCIe single port FC HBA for HP"); | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 808 | 	else if (!strcmp(model, "Brocade-804")) | 
 | 809 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 810 | 			"Brocade 8Gbps FC HBA for HP Bladesystem C-class"); | 
| Krishna Gudipati | 9d8ad78 | 2012-04-09 18:40:43 -0700 | [diff] [blame] | 811 | 	else if (!strcmp(model, "Brocade-1741")) | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 812 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 813 | 			"Brocade 10Gbps CNA for Dell M-Series Blade Servers"); | 
| Krishna Gudipati | 9d8ad78 | 2012-04-09 18:40:43 -0700 | [diff] [blame] | 814 | 	else if (strstr(model, "Brocade-1860")) { | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 815 | 		if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 816 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 817 | 				"Brocade 10Gbps single port CNA"); | 
 | 818 | 		else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 819 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 820 | 				"Brocade 16Gbps PCIe single port FC HBA"); | 
 | 821 | 		else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 822 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 823 | 				"Brocade 10Gbps dual port CNA"); | 
 | 824 | 		else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 825 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 826 | 				"Brocade 16Gbps PCIe dual port FC HBA"); | 
| Krishna Gudipati | 6dca60a | 2012-08-22 19:51:35 -0700 | [diff] [blame] | 827 | 	} else if (!strcmp(model, "Brocade-1867")) { | 
 | 828 | 		if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 829 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 830 | 				"Brocade 16Gbps PCIe single port FC HBA for IBM"); | 
 | 831 | 		else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) | 
 | 832 | 			snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 833 | 				"Brocade 16Gbps PCIe dual port FC HBA for IBM"); | 
| Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 834 | 	} else | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 835 | 		snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, | 
 | 836 | 			"Invalid Model"); | 
 | 837 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 838 | 	return snprintf(buf, PAGE_SIZE, "%s\n", model_descr); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 839 | } | 
 | 840 |  | 
 | 841 | static ssize_t | 
 | 842 | bfad_im_node_name_show(struct device *dev, struct device_attribute *attr, | 
 | 843 | 				 char *buf) | 
 | 844 | { | 
 | 845 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 846 | 	struct bfad_im_port_s *im_port = | 
 | 847 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 848 | 	struct bfad_port_s    *port = im_port->port; | 
 | 849 | 	u64        nwwn; | 
 | 850 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 851 | 	nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port); | 
| Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 852 | 	return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn)); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 853 | } | 
 | 854 |  | 
 | 855 | static ssize_t | 
 | 856 | bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr, | 
 | 857 | 				 char *buf) | 
 | 858 | { | 
 | 859 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 860 | 	struct bfad_im_port_s *im_port = | 
 | 861 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 862 | 	struct bfad_s *bfad = im_port->bfad; | 
 | 863 | 	struct bfa_lport_attr_s port_attr; | 
 | 864 | 	char symname[BFA_SYMNAME_MAXLEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 865 |  | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 866 | 	bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); | 
 | 867 | 	strncpy(symname, port_attr.port_cfg.sym_name.symname, | 
 | 868 | 			BFA_SYMNAME_MAXLEN); | 
 | 869 | 	return snprintf(buf, PAGE_SIZE, "%s\n", symname); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 870 | } | 
 | 871 |  | 
 | 872 | static ssize_t | 
 | 873 | bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr, | 
 | 874 | 				char *buf) | 
 | 875 | { | 
 | 876 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 877 | 	struct bfad_im_port_s *im_port = | 
 | 878 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 879 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 880 | 	char hw_ver[BFA_VERSION_LEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 881 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 882 | 	bfa_get_pci_chip_rev(&bfad->bfa, hw_ver); | 
 | 883 | 	return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 884 | } | 
 | 885 |  | 
 | 886 | static ssize_t | 
 | 887 | bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr, | 
 | 888 | 				char *buf) | 
 | 889 | { | 
 | 890 | 	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION); | 
 | 891 | } | 
 | 892 |  | 
 | 893 | static ssize_t | 
 | 894 | bfad_im_optionrom_version_show(struct device *dev, | 
 | 895 | 			 struct device_attribute *attr, char *buf) | 
 | 896 | { | 
 | 897 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 898 | 	struct bfad_im_port_s *im_port = | 
 | 899 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 900 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 901 | 	char optrom_ver[BFA_VERSION_LEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 902 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 903 | 	bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver); | 
 | 904 | 	return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 905 | } | 
 | 906 |  | 
 | 907 | static ssize_t | 
 | 908 | bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr, | 
 | 909 | 				 char *buf) | 
 | 910 | { | 
 | 911 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 912 | 	struct bfad_im_port_s *im_port = | 
 | 913 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 914 | 	struct bfad_s *bfad = im_port->bfad; | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 915 | 	char fw_ver[BFA_VERSION_LEN]; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 916 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 917 | 	bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver); | 
 | 918 | 	return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 919 | } | 
 | 920 |  | 
 | 921 | static ssize_t | 
 | 922 | bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr, | 
 | 923 | 				char *buf) | 
 | 924 | { | 
 | 925 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 926 | 	struct bfad_im_port_s *im_port = | 
 | 927 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 928 | 	struct bfad_s *bfad = im_port->bfad; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 929 |  | 
| Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 930 | 	return snprintf(buf, PAGE_SIZE, "%d\n", | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 931 | 			bfa_get_nports(&bfad->bfa)); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 932 | } | 
 | 933 |  | 
 | 934 | static ssize_t | 
 | 935 | bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr, | 
 | 936 | 				char *buf) | 
 | 937 | { | 
 | 938 | 	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME); | 
 | 939 | } | 
 | 940 |  | 
 | 941 | static ssize_t | 
 | 942 | bfad_im_num_of_discovered_ports_show(struct device *dev, | 
 | 943 | 			struct device_attribute *attr, char *buf) | 
 | 944 | { | 
 | 945 | 	struct Scsi_Host *shost = class_to_shost(dev); | 
 | 946 | 	struct bfad_im_port_s *im_port = | 
 | 947 | 			(struct bfad_im_port_s *) shost->hostdata[0]; | 
 | 948 | 	struct bfad_port_s    *port = im_port->port; | 
 | 949 | 	struct bfad_s         *bfad = im_port->bfad; | 
 | 950 | 	int        nrports = 2048; | 
| Krishna Gudipati | ee1a4a4 | 2012-08-22 19:50:43 -0700 | [diff] [blame] | 951 | 	struct bfa_rport_qualifier_s *rports = NULL; | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 952 | 	unsigned long   flags; | 
 | 953 |  | 
| Krishna Gudipati | ee1a4a4 | 2012-08-22 19:50:43 -0700 | [diff] [blame] | 954 | 	rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports, | 
 | 955 | 			 GFP_ATOMIC); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 956 | 	if (rports == NULL) | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 957 | 		return snprintf(buf, PAGE_SIZE, "Failed\n"); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 958 |  | 
 | 959 | 	spin_lock_irqsave(&bfad->bfad_lock, flags); | 
| Krishna Gudipati | ee1a4a4 | 2012-08-22 19:50:43 -0700 | [diff] [blame] | 960 | 	bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports); | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 961 | 	spin_unlock_irqrestore(&bfad->bfad_lock, flags); | 
 | 962 | 	kfree(rports); | 
 | 963 |  | 
 | 964 | 	return snprintf(buf, PAGE_SIZE, "%d\n", nrports); | 
 | 965 | } | 
 | 966 |  | 
 | 967 | static          DEVICE_ATTR(serial_number, S_IRUGO, | 
 | 968 | 				bfad_im_serial_num_show, NULL); | 
 | 969 | static          DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL); | 
 | 970 | static          DEVICE_ATTR(model_description, S_IRUGO, | 
 | 971 | 				bfad_im_model_desc_show, NULL); | 
 | 972 | static          DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL); | 
 | 973 | static          DEVICE_ATTR(symbolic_name, S_IRUGO, | 
 | 974 | 				bfad_im_symbolic_name_show, NULL); | 
 | 975 | static          DEVICE_ATTR(hardware_version, S_IRUGO, | 
 | 976 | 				bfad_im_hw_version_show, NULL); | 
 | 977 | static          DEVICE_ATTR(driver_version, S_IRUGO, | 
 | 978 | 				bfad_im_drv_version_show, NULL); | 
 | 979 | static          DEVICE_ATTR(option_rom_version, S_IRUGO, | 
 | 980 | 				bfad_im_optionrom_version_show, NULL); | 
 | 981 | static          DEVICE_ATTR(firmware_version, S_IRUGO, | 
 | 982 | 				bfad_im_fw_version_show, NULL); | 
 | 983 | static          DEVICE_ATTR(number_of_ports, S_IRUGO, | 
 | 984 | 				bfad_im_num_of_ports_show, NULL); | 
 | 985 | static          DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL); | 
 | 986 | static          DEVICE_ATTR(number_of_discovered_ports, S_IRUGO, | 
 | 987 | 				bfad_im_num_of_discovered_ports_show, NULL); | 
 | 988 |  | 
 | 989 | struct device_attribute *bfad_im_host_attrs[] = { | 
 | 990 | 	&dev_attr_serial_number, | 
 | 991 | 	&dev_attr_model, | 
 | 992 | 	&dev_attr_model_description, | 
 | 993 | 	&dev_attr_node_name, | 
 | 994 | 	&dev_attr_symbolic_name, | 
 | 995 | 	&dev_attr_hardware_version, | 
 | 996 | 	&dev_attr_driver_version, | 
 | 997 | 	&dev_attr_option_rom_version, | 
 | 998 | 	&dev_attr_firmware_version, | 
 | 999 | 	&dev_attr_number_of_ports, | 
 | 1000 | 	&dev_attr_driver_name, | 
 | 1001 | 	&dev_attr_number_of_discovered_ports, | 
 | 1002 | 	NULL, | 
 | 1003 | }; | 
 | 1004 |  | 
 | 1005 | struct device_attribute *bfad_im_vport_attrs[] = { | 
| Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1006 | 	&dev_attr_serial_number, | 
 | 1007 | 	&dev_attr_model, | 
 | 1008 | 	&dev_attr_model_description, | 
 | 1009 | 	&dev_attr_node_name, | 
 | 1010 | 	&dev_attr_symbolic_name, | 
 | 1011 | 	&dev_attr_hardware_version, | 
 | 1012 | 	&dev_attr_driver_version, | 
 | 1013 | 	&dev_attr_option_rom_version, | 
 | 1014 | 	&dev_attr_firmware_version, | 
 | 1015 | 	&dev_attr_number_of_ports, | 
 | 1016 | 	&dev_attr_driver_name, | 
 | 1017 | 	&dev_attr_number_of_discovered_ports, | 
 | 1018 | 	NULL, | 
| Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1019 | }; | 
 | 1020 |  | 
 | 1021 |  |