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