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); |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 429 | fc_vport->dd_data = vport; |
| 430 | vport->drv_port.im_port->fc_vport = fc_vport; |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 431 | } else if (rc == BFA_STATUS_INVALID_WWN) |
| 432 | return VPCERR_BAD_WWN; |
| 433 | else if (rc == BFA_STATUS_VPORT_EXISTS) |
| 434 | return VPCERR_BAD_WWN; |
| 435 | else if (rc == BFA_STATUS_VPORT_MAX) |
| 436 | return VPCERR_NO_FABRIC_SUPP; |
| 437 | else if (rc == BFA_STATUS_VPORT_WWN_BP) |
| 438 | return VPCERR_BAD_WWN; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 439 | else |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 440 | return FC_VPORT_FAILED; |
| 441 | |
| 442 | return status; |
| 443 | } |
| 444 | |
| 445 | static int |
| 446 | bfad_im_vport_delete(struct fc_vport *fc_vport) |
| 447 | { |
| 448 | struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data; |
| 449 | struct bfad_im_port_s *im_port = |
| 450 | (struct bfad_im_port_s *) vport->drv_port.im_port; |
| 451 | struct bfad_s *bfad = im_port->bfad; |
| 452 | struct bfad_port_s *port; |
| 453 | struct bfa_fcs_vport_s *fcs_vport; |
| 454 | struct Scsi_Host *vshost; |
| 455 | wwn_t pwwn; |
| 456 | int rc; |
| 457 | unsigned long flags; |
| 458 | struct completion fcomp; |
| 459 | |
| 460 | if (im_port->flags & BFAD_PORT_DELETE) |
| 461 | goto free_scsi_host; |
| 462 | |
| 463 | port = im_port->port; |
| 464 | |
| 465 | vshost = vport->drv_port.im_port->shost; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 466 | u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 467 | |
| 468 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 469 | fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); |
| 470 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 471 | |
| 472 | if (fcs_vport == NULL) |
| 473 | return VPCERR_BAD_WWN; |
| 474 | |
| 475 | vport->drv_port.flags |= BFAD_PORT_DELETE; |
| 476 | |
| 477 | vport->comp_del = &fcomp; |
| 478 | init_completion(vport->comp_del); |
| 479 | |
| 480 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 481 | rc = bfa_fcs_vport_delete(&vport->fcs_vport); |
| 482 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 483 | |
Jing Huang | c54d557 | 2010-07-08 20:01:49 -0700 | [diff] [blame] | 484 | if (rc == BFA_STATUS_PBC) { |
| 485 | vport->drv_port.flags &= ~BFAD_PORT_DELETE; |
| 486 | vport->comp_del = NULL; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 487 | return -1; |
Jing Huang | c54d557 | 2010-07-08 20:01:49 -0700 | [diff] [blame] | 488 | } |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 489 | |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 490 | wait_for_completion(vport->comp_del); |
| 491 | |
| 492 | free_scsi_host: |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 493 | bfad_scsi_host_free(bfad, im_port); |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 494 | |
| 495 | kfree(vport); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int |
| 501 | bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable) |
| 502 | { |
| 503 | struct bfad_vport_s *vport; |
| 504 | struct bfad_s *bfad; |
| 505 | struct bfa_fcs_vport_s *fcs_vport; |
| 506 | struct Scsi_Host *vshost; |
| 507 | wwn_t pwwn; |
| 508 | unsigned long flags; |
| 509 | |
| 510 | vport = (struct bfad_vport_s *)fc_vport->dd_data; |
| 511 | bfad = vport->drv_port.bfad; |
| 512 | vshost = vport->drv_port.im_port->shost; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 513 | u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 514 | |
| 515 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 516 | fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); |
| 517 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 518 | |
| 519 | if (fcs_vport == NULL) |
| 520 | return VPCERR_BAD_WWN; |
| 521 | |
| 522 | if (disable) { |
| 523 | bfa_fcs_vport_stop(fcs_vport); |
| 524 | fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); |
| 525 | } else { |
| 526 | bfa_fcs_vport_start(fcs_vport); |
| 527 | fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 533 | struct fc_function_template bfad_im_fc_function_template = { |
| 534 | |
| 535 | /* Target dynamic attributes */ |
| 536 | .get_starget_port_id = bfad_im_get_starget_port_id, |
| 537 | .show_starget_port_id = 1, |
| 538 | .get_starget_node_name = bfad_im_get_starget_node_name, |
| 539 | .show_starget_node_name = 1, |
| 540 | .get_starget_port_name = bfad_im_get_starget_port_name, |
| 541 | .show_starget_port_name = 1, |
| 542 | |
| 543 | /* Host dynamic attribute */ |
| 544 | .get_host_port_id = bfad_im_get_host_port_id, |
| 545 | .show_host_port_id = 1, |
| 546 | |
| 547 | /* Host fixed attributes */ |
| 548 | .show_host_node_name = 1, |
| 549 | .show_host_port_name = 1, |
| 550 | .show_host_supported_classes = 1, |
| 551 | .show_host_supported_fc4s = 1, |
| 552 | .show_host_supported_speeds = 1, |
| 553 | .show_host_maxframe_size = 1, |
| 554 | |
| 555 | /* More host dynamic attributes */ |
| 556 | .show_host_port_type = 1, |
| 557 | .get_host_port_type = bfad_im_get_host_port_type, |
| 558 | .show_host_port_state = 1, |
| 559 | .get_host_port_state = bfad_im_get_host_port_state, |
| 560 | .show_host_active_fc4s = 1, |
| 561 | .get_host_active_fc4s = bfad_im_get_host_active_fc4s, |
| 562 | .show_host_speed = 1, |
| 563 | .get_host_speed = bfad_im_get_host_speed, |
| 564 | .show_host_fabric_name = 1, |
| 565 | .get_host_fabric_name = bfad_im_get_host_fabric_name, |
| 566 | |
| 567 | .show_host_symbolic_name = 1, |
| 568 | |
| 569 | /* Statistics */ |
| 570 | .get_fc_host_stats = bfad_im_get_stats, |
| 571 | .reset_fc_host_stats = bfad_im_reset_stats, |
| 572 | |
| 573 | /* Allocation length for host specific data */ |
| 574 | .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), |
| 575 | |
| 576 | /* Remote port fixed attributes */ |
| 577 | .show_rport_maxframe_size = 1, |
| 578 | .show_rport_supported_classes = 1, |
| 579 | .show_rport_dev_loss_tmo = 1, |
| 580 | .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo, |
| 581 | .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 582 | |
| 583 | .vport_create = bfad_im_vport_create, |
| 584 | .vport_delete = bfad_im_vport_delete, |
| 585 | .vport_disable = bfad_im_vport_disable, |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 586 | .bsg_request = bfad_im_bsg_request, |
| 587 | .bsg_timeout = bfad_im_bsg_timeout, |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 588 | }; |
| 589 | |
| 590 | struct fc_function_template bfad_im_vport_fc_function_template = { |
| 591 | |
| 592 | /* Target dynamic attributes */ |
| 593 | .get_starget_port_id = bfad_im_get_starget_port_id, |
| 594 | .show_starget_port_id = 1, |
| 595 | .get_starget_node_name = bfad_im_get_starget_node_name, |
| 596 | .show_starget_node_name = 1, |
| 597 | .get_starget_port_name = bfad_im_get_starget_port_name, |
| 598 | .show_starget_port_name = 1, |
| 599 | |
| 600 | /* Host dynamic attribute */ |
| 601 | .get_host_port_id = bfad_im_get_host_port_id, |
| 602 | .show_host_port_id = 1, |
| 603 | |
| 604 | /* Host fixed attributes */ |
| 605 | .show_host_node_name = 1, |
| 606 | .show_host_port_name = 1, |
| 607 | .show_host_supported_classes = 1, |
| 608 | .show_host_supported_fc4s = 1, |
| 609 | .show_host_supported_speeds = 1, |
| 610 | .show_host_maxframe_size = 1, |
| 611 | |
| 612 | /* More host dynamic attributes */ |
| 613 | .show_host_port_type = 1, |
| 614 | .get_host_port_type = bfad_im_get_host_port_type, |
| 615 | .show_host_port_state = 1, |
| 616 | .get_host_port_state = bfad_im_get_host_port_state, |
| 617 | .show_host_active_fc4s = 1, |
| 618 | .get_host_active_fc4s = bfad_im_get_host_active_fc4s, |
| 619 | .show_host_speed = 1, |
| 620 | .get_host_speed = bfad_im_get_host_speed, |
| 621 | .show_host_fabric_name = 1, |
| 622 | .get_host_fabric_name = bfad_im_get_host_fabric_name, |
| 623 | |
| 624 | .show_host_symbolic_name = 1, |
| 625 | |
| 626 | /* Statistics */ |
| 627 | .get_fc_host_stats = bfad_im_get_stats, |
| 628 | .reset_fc_host_stats = bfad_im_reset_stats, |
| 629 | |
| 630 | /* Allocation length for host specific data */ |
| 631 | .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), |
| 632 | |
| 633 | /* Remote port fixed attributes */ |
| 634 | .show_rport_maxframe_size = 1, |
| 635 | .show_rport_supported_classes = 1, |
| 636 | .show_rport_dev_loss_tmo = 1, |
| 637 | .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo, |
| 638 | .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 639 | }; |
| 640 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 641 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 642 | * Scsi_Host_attrs SCSI host attributes |
| 643 | */ |
| 644 | static ssize_t |
| 645 | bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr, |
| 646 | char *buf) |
| 647 | { |
| 648 | struct Scsi_Host *shost = class_to_shost(dev); |
| 649 | struct bfad_im_port_s *im_port = |
| 650 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 651 | struct bfad_s *bfad = im_port->bfad; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 652 | char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 653 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 654 | bfa_get_adapter_serial_num(&bfad->bfa, serial_num); |
| 655 | return snprintf(buf, PAGE_SIZE, "%s\n", serial_num); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | static ssize_t |
| 659 | bfad_im_model_show(struct device *dev, struct device_attribute *attr, |
| 660 | char *buf) |
| 661 | { |
| 662 | struct Scsi_Host *shost = class_to_shost(dev); |
| 663 | struct bfad_im_port_s *im_port = |
| 664 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 665 | struct bfad_s *bfad = im_port->bfad; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 666 | char model[BFA_ADAPTER_MODEL_NAME_LEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 667 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 668 | bfa_get_adapter_model(&bfad->bfa, model); |
| 669 | return snprintf(buf, PAGE_SIZE, "%s\n", model); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static ssize_t |
| 673 | bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr, |
| 674 | char *buf) |
| 675 | { |
| 676 | struct Scsi_Host *shost = class_to_shost(dev); |
| 677 | struct bfad_im_port_s *im_port = |
| 678 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 679 | struct bfad_s *bfad = im_port->bfad; |
| 680 | char model[BFA_ADAPTER_MODEL_NAME_LEN]; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 681 | char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN]; |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 682 | int nports = 0; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 683 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 684 | bfa_get_adapter_model(&bfad->bfa, model); |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 685 | nports = bfa_get_nports(&bfad->bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 686 | if (!strcmp(model, "Brocade-425")) |
| 687 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 688 | "Brocade 4Gbps PCIe dual port FC HBA"); |
| 689 | else if (!strcmp(model, "Brocade-825")) |
| 690 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 691 | "Brocade 8Gbps PCIe dual port FC HBA"); |
| 692 | else if (!strcmp(model, "Brocade-42B")) |
| 693 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 694 | "Brocade 4Gbps PCIe dual port FC HBA for HP"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 695 | else if (!strcmp(model, "Brocade-82B")) |
| 696 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 697 | "Brocade 8Gbps PCIe dual port FC HBA for HP"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 698 | else if (!strcmp(model, "Brocade-1010")) |
| 699 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 700 | "Brocade 10Gbps single port CNA"); |
| 701 | else if (!strcmp(model, "Brocade-1020")) |
| 702 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 703 | "Brocade 10Gbps dual port CNA"); |
| 704 | else if (!strcmp(model, "Brocade-1007")) |
| 705 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 706 | "Brocade 10Gbps CNA for IBM Blade Center"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 707 | else if (!strcmp(model, "Brocade-415")) |
| 708 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 709 | "Brocade 4Gbps PCIe single port FC HBA"); |
| 710 | else if (!strcmp(model, "Brocade-815")) |
| 711 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 712 | "Brocade 8Gbps PCIe single port FC HBA"); |
| 713 | else if (!strcmp(model, "Brocade-41B")) |
| 714 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 715 | "Brocade 4Gbps PCIe single port FC HBA for HP"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 716 | else if (!strcmp(model, "Brocade-81B")) |
| 717 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 718 | "Brocade 8Gbps PCIe single port FC HBA for HP"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 719 | else if (!strcmp(model, "Brocade-804")) |
| 720 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 721 | "Brocade 8Gbps FC HBA for HP Bladesystem C-class"); |
| 722 | else if (!strcmp(model, "Brocade-902") || |
| 723 | !strcmp(model, "Brocade-1741")) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 724 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 725 | "Brocade 10Gbps CNA for Dell M-Series Blade Servers"); |
| 726 | else if (strstr(model, "Brocade-1560")) { |
| 727 | if (nports == 1) |
| 728 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 729 | "Brocade 16Gbps PCIe single port FC HBA"); |
| 730 | else |
| 731 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 732 | "Brocade 16Gbps PCIe dual port FC HBA"); |
| 733 | } else if (strstr(model, "Brocade-1710")) { |
| 734 | if (nports == 1) |
| 735 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 736 | "Brocade 10Gbps single port CNA"); |
| 737 | else |
| 738 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 739 | "Brocade 10Gbps dual port CNA"); |
| 740 | } else if (strstr(model, "Brocade-1860")) { |
| 741 | if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc)) |
| 742 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 743 | "Brocade 10Gbps single port CNA"); |
| 744 | else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) |
| 745 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 746 | "Brocade 16Gbps PCIe single port FC HBA"); |
| 747 | else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc)) |
| 748 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 749 | "Brocade 10Gbps dual port CNA"); |
| 750 | else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) |
| 751 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 752 | "Brocade 16Gbps PCIe dual port FC HBA"); |
| 753 | } else |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 754 | snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, |
| 755 | "Invalid Model"); |
| 756 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 757 | return snprintf(buf, PAGE_SIZE, "%s\n", model_descr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static ssize_t |
| 761 | bfad_im_node_name_show(struct device *dev, struct device_attribute *attr, |
| 762 | char *buf) |
| 763 | { |
| 764 | struct Scsi_Host *shost = class_to_shost(dev); |
| 765 | struct bfad_im_port_s *im_port = |
| 766 | (struct bfad_im_port_s *) shost->hostdata[0]; |
| 767 | struct bfad_port_s *port = im_port->port; |
| 768 | u64 nwwn; |
| 769 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 770 | nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 771 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static ssize_t |
| 775 | bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr, |
| 776 | char *buf) |
| 777 | { |
| 778 | struct Scsi_Host *shost = class_to_shost(dev); |
| 779 | struct bfad_im_port_s *im_port = |
| 780 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 781 | struct bfad_s *bfad = im_port->bfad; |
| 782 | struct bfa_lport_attr_s port_attr; |
| 783 | char symname[BFA_SYMNAME_MAXLEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 784 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 785 | bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); |
| 786 | strncpy(symname, port_attr.port_cfg.sym_name.symname, |
| 787 | BFA_SYMNAME_MAXLEN); |
| 788 | return snprintf(buf, PAGE_SIZE, "%s\n", symname); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static ssize_t |
| 792 | bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr, |
| 793 | char *buf) |
| 794 | { |
| 795 | struct Scsi_Host *shost = class_to_shost(dev); |
| 796 | struct bfad_im_port_s *im_port = |
| 797 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 798 | struct bfad_s *bfad = im_port->bfad; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 799 | char hw_ver[BFA_VERSION_LEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 800 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 801 | bfa_get_pci_chip_rev(&bfad->bfa, hw_ver); |
| 802 | return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static ssize_t |
| 806 | bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr, |
| 807 | char *buf) |
| 808 | { |
| 809 | return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION); |
| 810 | } |
| 811 | |
| 812 | static ssize_t |
| 813 | bfad_im_optionrom_version_show(struct device *dev, |
| 814 | struct device_attribute *attr, char *buf) |
| 815 | { |
| 816 | struct Scsi_Host *shost = class_to_shost(dev); |
| 817 | struct bfad_im_port_s *im_port = |
| 818 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 819 | struct bfad_s *bfad = im_port->bfad; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 820 | char optrom_ver[BFA_VERSION_LEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 821 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 822 | bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver); |
| 823 | return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | static ssize_t |
| 827 | bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr, |
| 828 | char *buf) |
| 829 | { |
| 830 | struct Scsi_Host *shost = class_to_shost(dev); |
| 831 | struct bfad_im_port_s *im_port = |
| 832 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 833 | struct bfad_s *bfad = im_port->bfad; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 834 | char fw_ver[BFA_VERSION_LEN]; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 835 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 836 | bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver); |
| 837 | return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static ssize_t |
| 841 | bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr, |
| 842 | char *buf) |
| 843 | { |
| 844 | struct Scsi_Host *shost = class_to_shost(dev); |
| 845 | struct bfad_im_port_s *im_port = |
| 846 | (struct bfad_im_port_s *) shost->hostdata[0]; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 847 | struct bfad_s *bfad = im_port->bfad; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 848 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 849 | return snprintf(buf, PAGE_SIZE, "%d\n", |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 850 | bfa_get_nports(&bfad->bfa)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static ssize_t |
| 854 | bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr, |
| 855 | char *buf) |
| 856 | { |
| 857 | return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME); |
| 858 | } |
| 859 | |
| 860 | static ssize_t |
| 861 | bfad_im_num_of_discovered_ports_show(struct device *dev, |
| 862 | struct device_attribute *attr, char *buf) |
| 863 | { |
| 864 | struct Scsi_Host *shost = class_to_shost(dev); |
| 865 | struct bfad_im_port_s *im_port = |
| 866 | (struct bfad_im_port_s *) shost->hostdata[0]; |
| 867 | struct bfad_port_s *port = im_port->port; |
| 868 | struct bfad_s *bfad = im_port->bfad; |
| 869 | int nrports = 2048; |
| 870 | wwn_t *rports = NULL; |
| 871 | unsigned long flags; |
| 872 | |
| 873 | rports = kzalloc(sizeof(wwn_t) * nrports , GFP_ATOMIC); |
| 874 | if (rports == NULL) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 875 | return snprintf(buf, PAGE_SIZE, "Failed\n"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 876 | |
| 877 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 878 | bfa_fcs_lport_get_rports(port->fcs_port, rports, &nrports); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 879 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 880 | kfree(rports); |
| 881 | |
| 882 | return snprintf(buf, PAGE_SIZE, "%d\n", nrports); |
| 883 | } |
| 884 | |
| 885 | static DEVICE_ATTR(serial_number, S_IRUGO, |
| 886 | bfad_im_serial_num_show, NULL); |
| 887 | static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL); |
| 888 | static DEVICE_ATTR(model_description, S_IRUGO, |
| 889 | bfad_im_model_desc_show, NULL); |
| 890 | static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL); |
| 891 | static DEVICE_ATTR(symbolic_name, S_IRUGO, |
| 892 | bfad_im_symbolic_name_show, NULL); |
| 893 | static DEVICE_ATTR(hardware_version, S_IRUGO, |
| 894 | bfad_im_hw_version_show, NULL); |
| 895 | static DEVICE_ATTR(driver_version, S_IRUGO, |
| 896 | bfad_im_drv_version_show, NULL); |
| 897 | static DEVICE_ATTR(option_rom_version, S_IRUGO, |
| 898 | bfad_im_optionrom_version_show, NULL); |
| 899 | static DEVICE_ATTR(firmware_version, S_IRUGO, |
| 900 | bfad_im_fw_version_show, NULL); |
| 901 | static DEVICE_ATTR(number_of_ports, S_IRUGO, |
| 902 | bfad_im_num_of_ports_show, NULL); |
| 903 | static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL); |
| 904 | static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO, |
| 905 | bfad_im_num_of_discovered_ports_show, NULL); |
| 906 | |
| 907 | struct device_attribute *bfad_im_host_attrs[] = { |
| 908 | &dev_attr_serial_number, |
| 909 | &dev_attr_model, |
| 910 | &dev_attr_model_description, |
| 911 | &dev_attr_node_name, |
| 912 | &dev_attr_symbolic_name, |
| 913 | &dev_attr_hardware_version, |
| 914 | &dev_attr_driver_version, |
| 915 | &dev_attr_option_rom_version, |
| 916 | &dev_attr_firmware_version, |
| 917 | &dev_attr_number_of_ports, |
| 918 | &dev_attr_driver_name, |
| 919 | &dev_attr_number_of_discovered_ports, |
| 920 | NULL, |
| 921 | }; |
| 922 | |
| 923 | struct device_attribute *bfad_im_vport_attrs[] = { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 924 | &dev_attr_serial_number, |
| 925 | &dev_attr_model, |
| 926 | &dev_attr_model_description, |
| 927 | &dev_attr_node_name, |
| 928 | &dev_attr_symbolic_name, |
| 929 | &dev_attr_hardware_version, |
| 930 | &dev_attr_driver_version, |
| 931 | &dev_attr_option_rom_version, |
| 932 | &dev_attr_firmware_version, |
| 933 | &dev_attr_number_of_ports, |
| 934 | &dev_attr_driver_name, |
| 935 | &dev_attr_number_of_discovered_ports, |
| 936 | NULL, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 937 | }; |
| 938 | |
| 939 | |