Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
| 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 | |
| 18 | #include <linux/uaccess.h> |
| 19 | #include "bfad_drv.h" |
| 20 | #include "bfad_im.h" |
| 21 | #include "bfad_bsg.h" |
| 22 | |
| 23 | BFA_TRC_FILE(LDRV, BSG); |
| 24 | |
| 25 | /* bfad_im_bsg_get_kobject - increment the bfa refcnt */ |
| 26 | static void |
| 27 | bfad_im_bsg_get_kobject(struct fc_bsg_job *job) |
| 28 | { |
| 29 | struct Scsi_Host *shost = job->shost; |
| 30 | unsigned long flags; |
| 31 | |
| 32 | spin_lock_irqsave(shost->host_lock, flags); |
| 33 | __module_get(shost->dma_dev->driver->owner); |
| 34 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 35 | } |
| 36 | |
| 37 | /* bfad_im_bsg_put_kobject - decrement the bfa refcnt */ |
| 38 | static void |
| 39 | bfad_im_bsg_put_kobject(struct fc_bsg_job *job) |
| 40 | { |
| 41 | struct Scsi_Host *shost = job->shost; |
| 42 | unsigned long flags; |
| 43 | |
| 44 | spin_lock_irqsave(shost->host_lock, flags); |
| 45 | module_put(shost->dma_dev->driver->owner); |
| 46 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 47 | } |
| 48 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 49 | int |
| 50 | bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd) |
| 51 | { |
| 52 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 53 | int rc = 0; |
| 54 | unsigned long flags; |
| 55 | |
| 56 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 57 | /* If IOC is not in disabled state - return */ |
| 58 | if (!bfa_ioc_is_disabled(&bfad->bfa.ioc)) { |
| 59 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 60 | iocmd->status = BFA_STATUS_IOC_FAILURE; |
| 61 | return rc; |
| 62 | } |
| 63 | |
| 64 | init_completion(&bfad->enable_comp); |
| 65 | bfa_iocfc_enable(&bfad->bfa); |
| 66 | iocmd->status = BFA_STATUS_OK; |
| 67 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 68 | wait_for_completion(&bfad->enable_comp); |
| 69 | |
| 70 | return rc; |
| 71 | } |
| 72 | |
| 73 | int |
| 74 | bfad_iocmd_ioc_disable(struct bfad_s *bfad, void *cmd) |
| 75 | { |
| 76 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 77 | int rc = 0; |
| 78 | unsigned long flags; |
| 79 | |
| 80 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 81 | if (bfad->disable_active) { |
| 82 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 83 | return EBUSY; |
| 84 | } |
| 85 | |
| 86 | bfad->disable_active = BFA_TRUE; |
| 87 | init_completion(&bfad->disable_comp); |
| 88 | bfa_iocfc_disable(&bfad->bfa); |
| 89 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 90 | |
| 91 | wait_for_completion(&bfad->disable_comp); |
| 92 | bfad->disable_active = BFA_FALSE; |
| 93 | iocmd->status = BFA_STATUS_OK; |
| 94 | |
| 95 | return rc; |
| 96 | } |
| 97 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 98 | static int |
| 99 | bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd) |
| 100 | { |
| 101 | int i; |
| 102 | struct bfa_bsg_ioc_info_s *iocmd = (struct bfa_bsg_ioc_info_s *)cmd; |
| 103 | struct bfad_im_port_s *im_port; |
| 104 | struct bfa_port_attr_s pattr; |
| 105 | unsigned long flags; |
| 106 | |
| 107 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 108 | bfa_fcport_get_attr(&bfad->bfa, &pattr); |
| 109 | iocmd->nwwn = pattr.nwwn; |
| 110 | iocmd->pwwn = pattr.pwwn; |
| 111 | iocmd->ioc_type = bfa_get_type(&bfad->bfa); |
| 112 | iocmd->mac = bfa_get_mac(&bfad->bfa); |
| 113 | iocmd->factory_mac = bfa_get_mfg_mac(&bfad->bfa); |
| 114 | bfa_get_adapter_serial_num(&bfad->bfa, iocmd->serialnum); |
| 115 | iocmd->factorynwwn = pattr.factorynwwn; |
| 116 | iocmd->factorypwwn = pattr.factorypwwn; |
| 117 | im_port = bfad->pport.im_port; |
| 118 | iocmd->host = im_port->shost->host_no; |
| 119 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 120 | |
| 121 | strcpy(iocmd->name, bfad->adapter_name); |
| 122 | strcpy(iocmd->port_name, bfad->port_name); |
| 123 | strcpy(iocmd->hwpath, bfad->pci_name); |
| 124 | |
| 125 | /* set adapter hw path */ |
| 126 | strcpy(iocmd->adapter_hwpath, bfad->pci_name); |
| 127 | i = strlen(iocmd->adapter_hwpath) - 1; |
| 128 | while (iocmd->adapter_hwpath[i] != '.') |
| 129 | i--; |
| 130 | iocmd->adapter_hwpath[i] = '\0'; |
| 131 | iocmd->status = BFA_STATUS_OK; |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int |
| 136 | bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd) |
| 137 | { |
| 138 | struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd; |
| 139 | unsigned long flags; |
| 140 | |
| 141 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 142 | bfa_ioc_get_attr(&bfad->bfa.ioc, &iocmd->ioc_attr); |
| 143 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 144 | |
| 145 | /* fill in driver attr info */ |
| 146 | strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME); |
| 147 | strncpy(iocmd->ioc_attr.driver_attr.driver_ver, |
| 148 | BFAD_DRIVER_VERSION, BFA_VERSION_LEN); |
| 149 | strcpy(iocmd->ioc_attr.driver_attr.fw_ver, |
| 150 | iocmd->ioc_attr.adapter_attr.fw_ver); |
| 151 | strcpy(iocmd->ioc_attr.driver_attr.bios_ver, |
| 152 | iocmd->ioc_attr.adapter_attr.optrom_ver); |
| 153 | |
| 154 | /* copy chip rev info first otherwise it will be overwritten */ |
| 155 | memcpy(bfad->pci_attr.chip_rev, iocmd->ioc_attr.pci_attr.chip_rev, |
| 156 | sizeof(bfad->pci_attr.chip_rev)); |
| 157 | memcpy(&iocmd->ioc_attr.pci_attr, &bfad->pci_attr, |
| 158 | sizeof(struct bfa_ioc_pci_attr_s)); |
| 159 | |
| 160 | iocmd->status = BFA_STATUS_OK; |
| 161 | return 0; |
| 162 | } |
| 163 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 164 | int |
| 165 | bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd) |
| 166 | { |
| 167 | struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd; |
| 168 | |
| 169 | bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats); |
| 170 | iocmd->status = BFA_STATUS_OK; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | int |
| 175 | bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd, |
| 176 | unsigned int payload_len) |
| 177 | { |
| 178 | struct bfa_bsg_ioc_fwstats_s *iocmd = |
| 179 | (struct bfa_bsg_ioc_fwstats_s *)cmd; |
| 180 | void *iocmd_bufptr; |
| 181 | unsigned long flags; |
| 182 | |
| 183 | if (bfad_chk_iocmd_sz(payload_len, |
| 184 | sizeof(struct bfa_bsg_ioc_fwstats_s), |
| 185 | sizeof(struct bfa_fw_stats_s)) != BFA_STATUS_OK) { |
| 186 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 187 | goto out; |
| 188 | } |
| 189 | |
| 190 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_ioc_fwstats_s); |
| 191 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 192 | iocmd->status = bfa_ioc_fw_stats_get(&bfad->bfa.ioc, iocmd_bufptr); |
| 193 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 194 | |
| 195 | if (iocmd->status != BFA_STATUS_OK) { |
| 196 | bfa_trc(bfad, iocmd->status); |
| 197 | goto out; |
| 198 | } |
| 199 | out: |
| 200 | bfa_trc(bfad, 0x6666); |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int |
| 205 | bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd) |
| 206 | { |
| 207 | struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd; |
| 208 | |
| 209 | iocmd->status = BFA_STATUS_OK; |
| 210 | bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr); |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | int |
| 216 | bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd) |
| 217 | { |
| 218 | struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd; |
| 219 | unsigned long flags; |
| 220 | |
| 221 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 222 | iocmd->status = bfa_iocfc_israttr_set(&bfad->bfa, &iocmd->attr); |
| 223 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | int |
| 229 | bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd) |
| 230 | { |
| 231 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 232 | struct bfad_hal_comp fcomp; |
| 233 | unsigned long flags; |
| 234 | |
| 235 | init_completion(&fcomp.comp); |
| 236 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 237 | iocmd->status = bfa_port_enable(&bfad->bfa.modules.port, |
| 238 | bfad_hcb_comp, &fcomp); |
| 239 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 240 | if (iocmd->status != BFA_STATUS_OK) { |
| 241 | bfa_trc(bfad, iocmd->status); |
| 242 | return 0; |
| 243 | } |
| 244 | wait_for_completion(&fcomp.comp); |
| 245 | iocmd->status = fcomp.status; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | int |
| 250 | bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd) |
| 251 | { |
| 252 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 253 | struct bfad_hal_comp fcomp; |
| 254 | unsigned long flags; |
| 255 | |
| 256 | init_completion(&fcomp.comp); |
| 257 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 258 | iocmd->status = bfa_port_disable(&bfad->bfa.modules.port, |
| 259 | bfad_hcb_comp, &fcomp); |
| 260 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 261 | |
| 262 | if (iocmd->status != BFA_STATUS_OK) { |
| 263 | bfa_trc(bfad, iocmd->status); |
| 264 | return 0; |
| 265 | } |
| 266 | wait_for_completion(&fcomp.comp); |
| 267 | iocmd->status = fcomp.status; |
| 268 | return 0; |
| 269 | } |
| 270 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 271 | static int |
| 272 | bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd) |
| 273 | { |
| 274 | struct bfa_bsg_port_attr_s *iocmd = (struct bfa_bsg_port_attr_s *)cmd; |
| 275 | struct bfa_lport_attr_s port_attr; |
| 276 | unsigned long flags; |
| 277 | |
| 278 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 279 | bfa_fcport_get_attr(&bfad->bfa, &iocmd->attr); |
| 280 | bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); |
| 281 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 282 | |
| 283 | if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE) |
| 284 | iocmd->attr.pid = port_attr.pid; |
| 285 | else |
| 286 | iocmd->attr.pid = 0; |
| 287 | |
| 288 | iocmd->attr.port_type = port_attr.port_type; |
| 289 | iocmd->attr.loopback = port_attr.loopback; |
| 290 | iocmd->attr.authfail = port_attr.authfail; |
| 291 | strncpy(iocmd->attr.port_symname.symname, |
| 292 | port_attr.port_cfg.sym_name.symname, |
| 293 | sizeof(port_attr.port_cfg.sym_name.symname)); |
| 294 | |
| 295 | iocmd->status = BFA_STATUS_OK; |
| 296 | return 0; |
| 297 | } |
| 298 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 299 | int |
| 300 | bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd, |
| 301 | unsigned int payload_len) |
| 302 | { |
| 303 | struct bfa_bsg_port_stats_s *iocmd = (struct bfa_bsg_port_stats_s *)cmd; |
| 304 | struct bfad_hal_comp fcomp; |
| 305 | void *iocmd_bufptr; |
| 306 | unsigned long flags; |
| 307 | |
| 308 | if (bfad_chk_iocmd_sz(payload_len, |
| 309 | sizeof(struct bfa_bsg_port_stats_s), |
| 310 | sizeof(union bfa_port_stats_u)) != BFA_STATUS_OK) { |
| 311 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s); |
| 316 | |
| 317 | init_completion(&fcomp.comp); |
| 318 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 319 | iocmd->status = bfa_port_get_stats(&bfad->bfa.modules.port, |
| 320 | iocmd_bufptr, bfad_hcb_comp, &fcomp); |
| 321 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 322 | if (iocmd->status != BFA_STATUS_OK) { |
| 323 | bfa_trc(bfad, iocmd->status); |
| 324 | goto out; |
| 325 | } |
| 326 | |
| 327 | wait_for_completion(&fcomp.comp); |
| 328 | iocmd->status = fcomp.status; |
| 329 | out: |
| 330 | return 0; |
| 331 | } |
| 332 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 333 | static int |
| 334 | bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd) |
| 335 | { |
| 336 | struct bfa_fcs_lport_s *fcs_port; |
| 337 | struct bfa_bsg_lport_attr_s *iocmd = (struct bfa_bsg_lport_attr_s *)cmd; |
| 338 | unsigned long flags; |
| 339 | |
| 340 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 341 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 342 | iocmd->vf_id, iocmd->pwwn); |
| 343 | if (fcs_port == NULL) { |
| 344 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 345 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 346 | goto out; |
| 347 | } |
| 348 | |
| 349 | bfa_fcs_lport_get_attr(fcs_port, &iocmd->port_attr); |
| 350 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 351 | iocmd->status = BFA_STATUS_OK; |
| 352 | out: |
| 353 | return 0; |
| 354 | } |
| 355 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 356 | int |
| 357 | bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd) |
| 358 | { |
| 359 | struct bfa_fcs_lport_s *fcs_port; |
| 360 | struct bfa_bsg_lport_stats_s *iocmd = |
| 361 | (struct bfa_bsg_lport_stats_s *)cmd; |
| 362 | unsigned long flags; |
| 363 | |
| 364 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 365 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 366 | iocmd->vf_id, iocmd->pwwn); |
| 367 | if (fcs_port == NULL) { |
| 368 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 369 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 370 | goto out; |
| 371 | } |
| 372 | |
| 373 | bfa_fcs_lport_get_stats(fcs_port, &iocmd->port_stats); |
| 374 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 375 | iocmd->status = BFA_STATUS_OK; |
| 376 | out: |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | int |
| 381 | bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd) |
| 382 | { |
| 383 | struct bfa_fcs_lport_s *fcs_port; |
| 384 | struct bfa_bsg_lport_iostats_s *iocmd = |
| 385 | (struct bfa_bsg_lport_iostats_s *)cmd; |
| 386 | unsigned long flags; |
| 387 | |
| 388 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 389 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 390 | iocmd->vf_id, iocmd->pwwn); |
| 391 | if (fcs_port == NULL) { |
| 392 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 393 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 394 | goto out; |
| 395 | } |
| 396 | |
| 397 | bfa_fcpim_port_iostats(&bfad->bfa, &iocmd->iostats, |
| 398 | fcs_port->lp_tag); |
| 399 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 400 | iocmd->status = BFA_STATUS_OK; |
| 401 | out: |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | int |
| 406 | bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd, |
| 407 | unsigned int payload_len) |
| 408 | { |
| 409 | struct bfa_bsg_lport_get_rports_s *iocmd = |
| 410 | (struct bfa_bsg_lport_get_rports_s *)cmd; |
| 411 | struct bfa_fcs_lport_s *fcs_port; |
| 412 | unsigned long flags; |
| 413 | void *iocmd_bufptr; |
| 414 | |
| 415 | if (iocmd->nrports == 0) |
| 416 | return EINVAL; |
| 417 | |
| 418 | if (bfad_chk_iocmd_sz(payload_len, |
| 419 | sizeof(struct bfa_bsg_lport_get_rports_s), |
| 420 | sizeof(wwn_t) * iocmd->nrports) != BFA_STATUS_OK) { |
| 421 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | iocmd_bufptr = (char *)iocmd + |
| 426 | sizeof(struct bfa_bsg_lport_get_rports_s); |
| 427 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 428 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 429 | iocmd->vf_id, iocmd->pwwn); |
| 430 | if (fcs_port == NULL) { |
| 431 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 432 | bfa_trc(bfad, 0); |
| 433 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 434 | goto out; |
| 435 | } |
| 436 | |
| 437 | bfa_fcs_lport_get_rports(fcs_port, (wwn_t *)iocmd_bufptr, |
| 438 | &iocmd->nrports); |
| 439 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 440 | iocmd->status = BFA_STATUS_OK; |
| 441 | out: |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | int |
| 446 | bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd) |
| 447 | { |
| 448 | struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd; |
| 449 | struct bfa_fcs_lport_s *fcs_port; |
| 450 | struct bfa_fcs_rport_s *fcs_rport; |
| 451 | unsigned long flags; |
| 452 | |
| 453 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 454 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 455 | iocmd->vf_id, iocmd->pwwn); |
| 456 | if (fcs_port == NULL) { |
| 457 | bfa_trc(bfad, 0); |
| 458 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 459 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 460 | goto out; |
| 461 | } |
| 462 | |
| 463 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); |
| 464 | if (fcs_rport == NULL) { |
| 465 | bfa_trc(bfad, 0); |
| 466 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 467 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 468 | goto out; |
| 469 | } |
| 470 | |
| 471 | bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr); |
| 472 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 473 | iocmd->status = BFA_STATUS_OK; |
| 474 | out: |
| 475 | return 0; |
| 476 | } |
| 477 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 478 | static int |
| 479 | bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd) |
| 480 | { |
| 481 | struct bfa_bsg_rport_scsi_addr_s *iocmd = |
| 482 | (struct bfa_bsg_rport_scsi_addr_s *)cmd; |
| 483 | struct bfa_fcs_lport_s *fcs_port; |
| 484 | struct bfa_fcs_itnim_s *fcs_itnim; |
| 485 | struct bfad_itnim_s *drv_itnim; |
| 486 | unsigned long flags; |
| 487 | |
| 488 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 489 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 490 | iocmd->vf_id, iocmd->pwwn); |
| 491 | if (fcs_port == NULL) { |
| 492 | bfa_trc(bfad, 0); |
| 493 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 494 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 495 | goto out; |
| 496 | } |
| 497 | |
| 498 | fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); |
| 499 | if (fcs_itnim == NULL) { |
| 500 | bfa_trc(bfad, 0); |
| 501 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 502 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 503 | goto out; |
| 504 | } |
| 505 | |
| 506 | drv_itnim = fcs_itnim->itnim_drv; |
| 507 | |
| 508 | if (drv_itnim && drv_itnim->im_port) |
| 509 | iocmd->host = drv_itnim->im_port->shost->host_no; |
| 510 | else { |
| 511 | bfa_trc(bfad, 0); |
| 512 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 513 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 514 | goto out; |
| 515 | } |
| 516 | |
| 517 | iocmd->target = drv_itnim->scsi_tgt_id; |
| 518 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 519 | |
| 520 | iocmd->bus = 0; |
| 521 | iocmd->lun = 0; |
| 522 | iocmd->status = BFA_STATUS_OK; |
| 523 | out: |
| 524 | return 0; |
| 525 | } |
| 526 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 527 | int |
| 528 | bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd) |
| 529 | { |
| 530 | struct bfa_bsg_rport_stats_s *iocmd = |
| 531 | (struct bfa_bsg_rport_stats_s *)cmd; |
| 532 | struct bfa_fcs_lport_s *fcs_port; |
| 533 | struct bfa_fcs_rport_s *fcs_rport; |
| 534 | unsigned long flags; |
| 535 | |
| 536 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 537 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 538 | iocmd->vf_id, iocmd->pwwn); |
| 539 | if (fcs_port == NULL) { |
| 540 | bfa_trc(bfad, 0); |
| 541 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 542 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 543 | goto out; |
| 544 | } |
| 545 | |
| 546 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); |
| 547 | if (fcs_rport == NULL) { |
| 548 | bfa_trc(bfad, 0); |
| 549 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 550 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 551 | goto out; |
| 552 | } |
| 553 | |
| 554 | memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats, |
| 555 | sizeof(struct bfa_rport_stats_s)); |
| 556 | memcpy((void *)&iocmd->stats.hal_stats, |
| 557 | (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats), |
| 558 | sizeof(struct bfa_rport_hal_stats_s)); |
| 559 | |
| 560 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 561 | iocmd->status = BFA_STATUS_OK; |
| 562 | out: |
| 563 | return 0; |
| 564 | } |
| 565 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 566 | static int |
| 567 | bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd, |
| 568 | unsigned int payload_len) |
| 569 | { |
| 570 | struct bfa_bsg_fabric_get_lports_s *iocmd = |
| 571 | (struct bfa_bsg_fabric_get_lports_s *)cmd; |
| 572 | bfa_fcs_vf_t *fcs_vf; |
| 573 | uint32_t nports = iocmd->nports; |
| 574 | unsigned long flags; |
| 575 | void *iocmd_bufptr; |
| 576 | |
| 577 | if (nports == 0) { |
| 578 | iocmd->status = BFA_STATUS_EINVAL; |
| 579 | goto out; |
| 580 | } |
| 581 | |
| 582 | if (bfad_chk_iocmd_sz(payload_len, |
| 583 | sizeof(struct bfa_bsg_fabric_get_lports_s), |
| 584 | sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) { |
| 585 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 586 | goto out; |
| 587 | } |
| 588 | |
| 589 | iocmd_bufptr = (char *)iocmd + |
| 590 | sizeof(struct bfa_bsg_fabric_get_lports_s); |
| 591 | |
| 592 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 593 | fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id); |
| 594 | if (fcs_vf == NULL) { |
| 595 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 596 | iocmd->status = BFA_STATUS_UNKNOWN_VFID; |
| 597 | goto out; |
| 598 | } |
| 599 | bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports); |
| 600 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 601 | |
| 602 | iocmd->nports = nports; |
| 603 | iocmd->status = BFA_STATUS_OK; |
| 604 | out: |
| 605 | return 0; |
| 606 | } |
| 607 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 608 | int |
| 609 | bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd) |
| 610 | { |
| 611 | struct bfa_bsg_fcpim_modstats_s *iocmd = |
| 612 | (struct bfa_bsg_fcpim_modstats_s *)cmd; |
| 613 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); |
| 614 | struct list_head *qe, *qen; |
| 615 | struct bfa_itnim_s *itnim; |
| 616 | unsigned long flags; |
| 617 | |
| 618 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 619 | /* accumulate IO stats from itnim */ |
| 620 | memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s)); |
| 621 | list_for_each_safe(qe, qen, &fcpim->itnim_q) { |
| 622 | itnim = (struct bfa_itnim_s *) qe; |
| 623 | bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats)); |
| 624 | } |
| 625 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 626 | iocmd->status = BFA_STATUS_OK; |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | int |
| 631 | bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd) |
| 632 | { |
| 633 | struct bfa_bsg_fcpim_del_itn_stats_s *iocmd = |
| 634 | (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd; |
| 635 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); |
| 636 | unsigned long flags; |
| 637 | |
| 638 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 639 | memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats, |
| 640 | sizeof(struct bfa_fcpim_del_itn_stats_s)); |
| 641 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 642 | |
| 643 | iocmd->status = BFA_STATUS_OK; |
| 644 | return 0; |
| 645 | } |
| 646 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 647 | static int |
| 648 | bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd) |
| 649 | { |
| 650 | struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd; |
| 651 | struct bfa_fcs_lport_s *fcs_port; |
| 652 | unsigned long flags; |
| 653 | |
| 654 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 655 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 656 | iocmd->vf_id, iocmd->lpwwn); |
| 657 | if (!fcs_port) |
| 658 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 659 | else |
| 660 | iocmd->status = bfa_fcs_itnim_attr_get(fcs_port, |
| 661 | iocmd->rpwwn, &iocmd->attr); |
| 662 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 663 | return 0; |
| 664 | } |
| 665 | |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 666 | static int |
| 667 | bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd) |
| 668 | { |
| 669 | struct bfa_bsg_itnim_iostats_s *iocmd = |
| 670 | (struct bfa_bsg_itnim_iostats_s *)cmd; |
| 671 | struct bfa_fcs_lport_s *fcs_port; |
| 672 | struct bfa_fcs_itnim_s *itnim; |
| 673 | unsigned long flags; |
| 674 | |
| 675 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 676 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 677 | iocmd->vf_id, iocmd->lpwwn); |
| 678 | if (!fcs_port) { |
| 679 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 680 | bfa_trc(bfad, 0); |
| 681 | } else { |
| 682 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); |
| 683 | if (itnim == NULL) |
| 684 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 685 | else { |
| 686 | iocmd->status = BFA_STATUS_OK; |
| 687 | memcpy((void *)&iocmd->iostats, (void *) |
| 688 | &(bfa_fcs_itnim_get_halitn(itnim)->stats), |
| 689 | sizeof(struct bfa_itnim_iostats_s)); |
| 690 | } |
| 691 | } |
| 692 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | static int |
| 697 | bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd) |
| 698 | { |
| 699 | struct bfa_bsg_itnim_itnstats_s *iocmd = |
| 700 | (struct bfa_bsg_itnim_itnstats_s *)cmd; |
| 701 | struct bfa_fcs_lport_s *fcs_port; |
| 702 | struct bfa_fcs_itnim_s *itnim; |
| 703 | unsigned long flags; |
| 704 | |
| 705 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 706 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, |
| 707 | iocmd->vf_id, iocmd->lpwwn); |
| 708 | if (!fcs_port) { |
| 709 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; |
| 710 | bfa_trc(bfad, 0); |
| 711 | } else { |
| 712 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); |
| 713 | if (itnim == NULL) |
| 714 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; |
| 715 | else { |
| 716 | iocmd->status = BFA_STATUS_OK; |
| 717 | bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn, |
| 718 | &iocmd->itnstats); |
| 719 | } |
| 720 | } |
| 721 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | int |
| 726 | bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd) |
| 727 | { |
| 728 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 729 | unsigned long flags; |
| 730 | |
| 731 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 732 | iocmd->status = bfa_fcport_enable(&bfad->bfa); |
| 733 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | int |
| 739 | bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd) |
| 740 | { |
| 741 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 742 | unsigned long flags; |
| 743 | |
| 744 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 745 | iocmd->status = bfa_fcport_disable(&bfad->bfa); |
| 746 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 751 | int |
| 752 | bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd) |
| 753 | { |
| 754 | struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd; |
| 755 | struct bfad_hal_comp fcomp; |
| 756 | unsigned long flags; |
| 757 | |
| 758 | init_completion(&fcomp.comp); |
| 759 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 760 | iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk, |
| 761 | &iocmd->pcifn_cfg, |
| 762 | bfad_hcb_comp, &fcomp); |
| 763 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 764 | if (iocmd->status != BFA_STATUS_OK) |
| 765 | goto out; |
| 766 | |
| 767 | wait_for_completion(&fcomp.comp); |
| 768 | iocmd->status = fcomp.status; |
| 769 | out: |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | int |
| 774 | bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd) |
| 775 | { |
| 776 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; |
| 777 | struct bfad_hal_comp fcomp; |
| 778 | unsigned long flags; |
| 779 | |
| 780 | init_completion(&fcomp.comp); |
| 781 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 782 | iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk, |
| 783 | &iocmd->pcifn_id, iocmd->port, |
| 784 | iocmd->pcifn_class, iocmd->bandwidth, |
| 785 | bfad_hcb_comp, &fcomp); |
| 786 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 787 | if (iocmd->status != BFA_STATUS_OK) |
| 788 | goto out; |
| 789 | |
| 790 | wait_for_completion(&fcomp.comp); |
| 791 | iocmd->status = fcomp.status; |
| 792 | out: |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | int |
| 797 | bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd) |
| 798 | { |
| 799 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; |
| 800 | struct bfad_hal_comp fcomp; |
| 801 | unsigned long flags; |
| 802 | |
| 803 | init_completion(&fcomp.comp); |
| 804 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 805 | iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk, |
| 806 | iocmd->pcifn_id, |
| 807 | bfad_hcb_comp, &fcomp); |
| 808 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 809 | if (iocmd->status != BFA_STATUS_OK) |
| 810 | goto out; |
| 811 | |
| 812 | wait_for_completion(&fcomp.comp); |
| 813 | iocmd->status = fcomp.status; |
| 814 | out: |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | int |
| 819 | bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd) |
| 820 | { |
| 821 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; |
| 822 | struct bfad_hal_comp fcomp; |
| 823 | unsigned long flags; |
| 824 | |
| 825 | init_completion(&fcomp.comp); |
| 826 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 827 | iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk, |
| 828 | iocmd->pcifn_id, iocmd->bandwidth, |
| 829 | bfad_hcb_comp, &fcomp); |
| 830 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 831 | bfa_trc(bfad, iocmd->status); |
| 832 | if (iocmd->status != BFA_STATUS_OK) |
| 833 | goto out; |
| 834 | |
| 835 | wait_for_completion(&fcomp.comp); |
| 836 | iocmd->status = fcomp.status; |
| 837 | bfa_trc(bfad, iocmd->status); |
| 838 | out: |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | int |
| 843 | bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd) |
| 844 | { |
| 845 | struct bfa_bsg_adapter_cfg_mode_s *iocmd = |
| 846 | (struct bfa_bsg_adapter_cfg_mode_s *)cmd; |
| 847 | struct bfad_hal_comp fcomp; |
| 848 | unsigned long flags = 0; |
| 849 | |
| 850 | init_completion(&fcomp.comp); |
| 851 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 852 | iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk, |
| 853 | iocmd->cfg.mode, iocmd->cfg.max_pf, |
| 854 | iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp); |
| 855 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 856 | if (iocmd->status != BFA_STATUS_OK) |
| 857 | goto out; |
| 858 | |
| 859 | wait_for_completion(&fcomp.comp); |
| 860 | iocmd->status = fcomp.status; |
| 861 | out: |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | int |
| 866 | bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd) |
| 867 | { |
| 868 | struct bfa_bsg_port_cfg_mode_s *iocmd = |
| 869 | (struct bfa_bsg_port_cfg_mode_s *)cmd; |
| 870 | struct bfad_hal_comp fcomp; |
| 871 | unsigned long flags = 0; |
| 872 | |
| 873 | init_completion(&fcomp.comp); |
| 874 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 875 | iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk, |
| 876 | iocmd->instance, iocmd->cfg.mode, |
| 877 | iocmd->cfg.max_pf, iocmd->cfg.max_vf, |
| 878 | bfad_hcb_comp, &fcomp); |
| 879 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 880 | if (iocmd->status != BFA_STATUS_OK) |
| 881 | goto out; |
| 882 | |
| 883 | wait_for_completion(&fcomp.comp); |
| 884 | iocmd->status = fcomp.status; |
| 885 | out: |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | int |
| 890 | bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd) |
| 891 | { |
| 892 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; |
| 893 | struct bfad_hal_comp fcomp; |
| 894 | unsigned long flags; |
| 895 | |
| 896 | init_completion(&fcomp.comp); |
| 897 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 898 | if (cmd == IOCMD_FLASH_ENABLE_OPTROM) |
| 899 | iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk, |
| 900 | bfad_hcb_comp, &fcomp); |
| 901 | else |
| 902 | iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk, |
| 903 | bfad_hcb_comp, &fcomp); |
| 904 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 905 | |
| 906 | if (iocmd->status != BFA_STATUS_OK) |
| 907 | goto out; |
| 908 | |
| 909 | wait_for_completion(&fcomp.comp); |
| 910 | iocmd->status = fcomp.status; |
| 911 | out: |
| 912 | return 0; |
| 913 | } |
| 914 | |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame] | 915 | int |
| 916 | bfad_iocmd_faa_enable(struct bfad_s *bfad, void *cmd) |
| 917 | { |
| 918 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 919 | unsigned long flags; |
| 920 | struct bfad_hal_comp fcomp; |
| 921 | |
| 922 | init_completion(&fcomp.comp); |
| 923 | iocmd->status = BFA_STATUS_OK; |
| 924 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 925 | iocmd->status = bfa_faa_enable(&bfad->bfa, bfad_hcb_comp, &fcomp); |
| 926 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 927 | |
| 928 | if (iocmd->status != BFA_STATUS_OK) |
| 929 | goto out; |
| 930 | |
| 931 | wait_for_completion(&fcomp.comp); |
| 932 | iocmd->status = fcomp.status; |
| 933 | out: |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | int |
| 938 | bfad_iocmd_faa_disable(struct bfad_s *bfad, void *cmd) |
| 939 | { |
| 940 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 941 | unsigned long flags; |
| 942 | struct bfad_hal_comp fcomp; |
| 943 | |
| 944 | init_completion(&fcomp.comp); |
| 945 | iocmd->status = BFA_STATUS_OK; |
| 946 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 947 | iocmd->status = bfa_faa_disable(&bfad->bfa, bfad_hcb_comp, &fcomp); |
| 948 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 949 | |
| 950 | if (iocmd->status != BFA_STATUS_OK) |
| 951 | goto out; |
| 952 | |
| 953 | wait_for_completion(&fcomp.comp); |
| 954 | iocmd->status = fcomp.status; |
| 955 | out: |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | int |
| 960 | bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd) |
| 961 | { |
| 962 | struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd; |
| 963 | struct bfad_hal_comp fcomp; |
| 964 | unsigned long flags; |
| 965 | |
| 966 | init_completion(&fcomp.comp); |
| 967 | iocmd->status = BFA_STATUS_OK; |
| 968 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 969 | iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr, |
| 970 | bfad_hcb_comp, &fcomp); |
| 971 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 972 | |
| 973 | if (iocmd->status != BFA_STATUS_OK) |
| 974 | goto out; |
| 975 | |
| 976 | wait_for_completion(&fcomp.comp); |
| 977 | iocmd->status = fcomp.status; |
| 978 | out: |
| 979 | return 0; |
| 980 | } |
| 981 | |
Krishna Gudipati | 148d610 | 2011-06-24 20:25:36 -0700 | [diff] [blame] | 982 | int |
| 983 | bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len) |
| 984 | { |
| 985 | struct bfa_bsg_cee_attr_s *iocmd = |
| 986 | (struct bfa_bsg_cee_attr_s *)cmd; |
| 987 | void *iocmd_bufptr; |
| 988 | struct bfad_hal_comp cee_comp; |
| 989 | unsigned long flags; |
| 990 | |
| 991 | if (bfad_chk_iocmd_sz(payload_len, |
| 992 | sizeof(struct bfa_bsg_cee_attr_s), |
| 993 | sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) { |
| 994 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s); |
| 999 | |
| 1000 | cee_comp.status = 0; |
| 1001 | init_completion(&cee_comp.comp); |
| 1002 | mutex_lock(&bfad_mutex); |
| 1003 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1004 | iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr, |
| 1005 | bfad_hcb_comp, &cee_comp); |
| 1006 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1007 | if (iocmd->status != BFA_STATUS_OK) { |
| 1008 | mutex_unlock(&bfad_mutex); |
| 1009 | bfa_trc(bfad, 0x5555); |
| 1010 | goto out; |
| 1011 | } |
| 1012 | wait_for_completion(&cee_comp.comp); |
| 1013 | mutex_unlock(&bfad_mutex); |
| 1014 | out: |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
| 1018 | int |
| 1019 | bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd, |
| 1020 | unsigned int payload_len) |
| 1021 | { |
| 1022 | struct bfa_bsg_cee_stats_s *iocmd = |
| 1023 | (struct bfa_bsg_cee_stats_s *)cmd; |
| 1024 | void *iocmd_bufptr; |
| 1025 | struct bfad_hal_comp cee_comp; |
| 1026 | unsigned long flags; |
| 1027 | |
| 1028 | if (bfad_chk_iocmd_sz(payload_len, |
| 1029 | sizeof(struct bfa_bsg_cee_stats_s), |
| 1030 | sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) { |
| 1031 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s); |
| 1036 | |
| 1037 | cee_comp.status = 0; |
| 1038 | init_completion(&cee_comp.comp); |
| 1039 | mutex_lock(&bfad_mutex); |
| 1040 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1041 | iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr, |
| 1042 | bfad_hcb_comp, &cee_comp); |
| 1043 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1044 | if (iocmd->status != BFA_STATUS_OK) { |
| 1045 | mutex_unlock(&bfad_mutex); |
| 1046 | bfa_trc(bfad, 0x5555); |
| 1047 | goto out; |
| 1048 | } |
| 1049 | wait_for_completion(&cee_comp.comp); |
| 1050 | mutex_unlock(&bfad_mutex); |
| 1051 | out: |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | int |
| 1056 | bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd) |
| 1057 | { |
| 1058 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; |
| 1059 | unsigned long flags; |
| 1060 | |
| 1061 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1062 | iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL); |
| 1063 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1064 | if (iocmd->status != BFA_STATUS_OK) |
| 1065 | bfa_trc(bfad, 0x5555); |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame^] | 1069 | int |
| 1070 | bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd) |
| 1071 | { |
| 1072 | struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd; |
| 1073 | struct bfad_hal_comp fcomp; |
| 1074 | unsigned long flags; |
| 1075 | |
| 1076 | init_completion(&fcomp.comp); |
| 1077 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1078 | iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media, |
| 1079 | bfad_hcb_comp, &fcomp); |
| 1080 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1081 | bfa_trc(bfad, iocmd->status); |
| 1082 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) |
| 1083 | goto out; |
| 1084 | |
| 1085 | wait_for_completion(&fcomp.comp); |
| 1086 | iocmd->status = fcomp.status; |
| 1087 | out: |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | int |
| 1092 | bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd) |
| 1093 | { |
| 1094 | struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd; |
| 1095 | struct bfad_hal_comp fcomp; |
| 1096 | unsigned long flags; |
| 1097 | |
| 1098 | init_completion(&fcomp.comp); |
| 1099 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1100 | iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed, |
| 1101 | bfad_hcb_comp, &fcomp); |
| 1102 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1103 | bfa_trc(bfad, iocmd->status); |
| 1104 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) |
| 1105 | goto out; |
| 1106 | wait_for_completion(&fcomp.comp); |
| 1107 | iocmd->status = fcomp.status; |
| 1108 | out: |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1112 | static int |
| 1113 | bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd, |
| 1114 | unsigned int payload_len) |
| 1115 | { |
| 1116 | int rc = EINVAL; |
| 1117 | |
| 1118 | switch (cmd) { |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1119 | case IOCMD_IOC_ENABLE: |
| 1120 | rc = bfad_iocmd_ioc_enable(bfad, iocmd); |
| 1121 | break; |
| 1122 | case IOCMD_IOC_DISABLE: |
| 1123 | rc = bfad_iocmd_ioc_disable(bfad, iocmd); |
| 1124 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1125 | case IOCMD_IOC_GET_INFO: |
| 1126 | rc = bfad_iocmd_ioc_get_info(bfad, iocmd); |
| 1127 | break; |
| 1128 | case IOCMD_IOC_GET_ATTR: |
| 1129 | rc = bfad_iocmd_ioc_get_attr(bfad, iocmd); |
| 1130 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1131 | case IOCMD_IOC_GET_STATS: |
| 1132 | rc = bfad_iocmd_ioc_get_stats(bfad, iocmd); |
| 1133 | break; |
| 1134 | case IOCMD_IOC_GET_FWSTATS: |
| 1135 | rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len); |
| 1136 | break; |
| 1137 | case IOCMD_IOCFC_GET_ATTR: |
| 1138 | rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd); |
| 1139 | break; |
| 1140 | case IOCMD_IOCFC_SET_INTR: |
| 1141 | rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd); |
| 1142 | break; |
| 1143 | case IOCMD_PORT_ENABLE: |
| 1144 | rc = bfad_iocmd_port_enable(bfad, iocmd); |
| 1145 | break; |
| 1146 | case IOCMD_PORT_DISABLE: |
| 1147 | rc = bfad_iocmd_port_disable(bfad, iocmd); |
| 1148 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1149 | case IOCMD_PORT_GET_ATTR: |
| 1150 | rc = bfad_iocmd_port_get_attr(bfad, iocmd); |
| 1151 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1152 | case IOCMD_PORT_GET_STATS: |
| 1153 | rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len); |
| 1154 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1155 | case IOCMD_LPORT_GET_ATTR: |
| 1156 | rc = bfad_iocmd_lport_get_attr(bfad, iocmd); |
| 1157 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1158 | case IOCMD_LPORT_GET_STATS: |
| 1159 | rc = bfad_iocmd_lport_get_stats(bfad, iocmd); |
| 1160 | break; |
| 1161 | case IOCMD_LPORT_GET_IOSTATS: |
| 1162 | rc = bfad_iocmd_lport_get_iostats(bfad, iocmd); |
| 1163 | break; |
| 1164 | case IOCMD_LPORT_GET_RPORTS: |
| 1165 | rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len); |
| 1166 | break; |
| 1167 | case IOCMD_RPORT_GET_ATTR: |
| 1168 | rc = bfad_iocmd_rport_get_attr(bfad, iocmd); |
| 1169 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1170 | case IOCMD_RPORT_GET_ADDR: |
| 1171 | rc = bfad_iocmd_rport_get_addr(bfad, iocmd); |
| 1172 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1173 | case IOCMD_RPORT_GET_STATS: |
| 1174 | rc = bfad_iocmd_rport_get_stats(bfad, iocmd); |
| 1175 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1176 | case IOCMD_FABRIC_GET_LPORTS: |
| 1177 | rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len); |
| 1178 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1179 | case IOCMD_FCPIM_MODSTATS: |
| 1180 | rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd); |
| 1181 | break; |
| 1182 | case IOCMD_FCPIM_DEL_ITN_STATS: |
| 1183 | rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd); |
| 1184 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1185 | case IOCMD_ITNIM_GET_ATTR: |
| 1186 | rc = bfad_iocmd_itnim_get_attr(bfad, iocmd); |
| 1187 | break; |
Krishna Gudipati | 6013806 | 2011-06-24 20:25:15 -0700 | [diff] [blame] | 1188 | case IOCMD_ITNIM_GET_IOSTATS: |
| 1189 | rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd); |
| 1190 | break; |
| 1191 | case IOCMD_ITNIM_GET_ITNSTATS: |
| 1192 | rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd); |
| 1193 | break; |
| 1194 | case IOCMD_FCPORT_ENABLE: |
| 1195 | rc = bfad_iocmd_fcport_enable(bfad, iocmd); |
| 1196 | break; |
| 1197 | case IOCMD_FCPORT_DISABLE: |
| 1198 | rc = bfad_iocmd_fcport_disable(bfad, iocmd); |
| 1199 | break; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 1200 | case IOCMD_IOC_PCIFN_CFG: |
| 1201 | rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd); |
| 1202 | break; |
| 1203 | case IOCMD_PCIFN_CREATE: |
| 1204 | rc = bfad_iocmd_pcifn_create(bfad, iocmd); |
| 1205 | break; |
| 1206 | case IOCMD_PCIFN_DELETE: |
| 1207 | rc = bfad_iocmd_pcifn_delete(bfad, iocmd); |
| 1208 | break; |
| 1209 | case IOCMD_PCIFN_BW: |
| 1210 | rc = bfad_iocmd_pcifn_bw(bfad, iocmd); |
| 1211 | break; |
| 1212 | case IOCMD_ADAPTER_CFG_MODE: |
| 1213 | rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd); |
| 1214 | break; |
| 1215 | case IOCMD_PORT_CFG_MODE: |
| 1216 | rc = bfad_iocmd_port_cfg_mode(bfad, iocmd); |
| 1217 | break; |
| 1218 | case IOCMD_FLASH_ENABLE_OPTROM: |
| 1219 | case IOCMD_FLASH_DISABLE_OPTROM: |
| 1220 | rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd); |
| 1221 | break; |
Krishna Gudipati | a714134 | 2011-06-24 20:23:19 -0700 | [diff] [blame] | 1222 | case IOCMD_FAA_ENABLE: |
| 1223 | rc = bfad_iocmd_faa_enable(bfad, iocmd); |
| 1224 | break; |
| 1225 | case IOCMD_FAA_DISABLE: |
| 1226 | rc = bfad_iocmd_faa_disable(bfad, iocmd); |
| 1227 | break; |
| 1228 | case IOCMD_FAA_QUERY: |
| 1229 | rc = bfad_iocmd_faa_query(bfad, iocmd); |
| 1230 | break; |
Krishna Gudipati | 148d610 | 2011-06-24 20:25:36 -0700 | [diff] [blame] | 1231 | case IOCMD_CEE_GET_ATTR: |
| 1232 | rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len); |
| 1233 | break; |
| 1234 | case IOCMD_CEE_GET_STATS: |
| 1235 | rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len); |
| 1236 | break; |
| 1237 | case IOCMD_CEE_RESET_STATS: |
| 1238 | rc = bfad_iocmd_cee_reset_stats(bfad, iocmd); |
| 1239 | break; |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame^] | 1240 | case IOCMD_SFP_MEDIA: |
| 1241 | rc = bfad_iocmd_sfp_media(bfad, iocmd); |
| 1242 | break; |
| 1243 | case IOCMD_SFP_SPEED: |
| 1244 | rc = bfad_iocmd_sfp_speed(bfad, iocmd); |
| 1245 | break; |
Krishna Gudipati | b85daaf | 2011-06-13 15:55:11 -0700 | [diff] [blame] | 1246 | default: |
| 1247 | rc = EINVAL; |
| 1248 | break; |
| 1249 | } |
| 1250 | return -rc; |
| 1251 | } |
| 1252 | |
| 1253 | static int |
| 1254 | bfad_im_bsg_vendor_request(struct fc_bsg_job *job) |
| 1255 | { |
| 1256 | uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0]; |
| 1257 | struct bfad_im_port_s *im_port = |
| 1258 | (struct bfad_im_port_s *) job->shost->hostdata[0]; |
| 1259 | struct bfad_s *bfad = im_port->bfad; |
| 1260 | void *payload_kbuf; |
| 1261 | int rc = -EINVAL; |
| 1262 | |
| 1263 | /* Allocate a temp buffer to hold the passed in user space command */ |
| 1264 | payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); |
| 1265 | if (!payload_kbuf) { |
| 1266 | rc = -ENOMEM; |
| 1267 | goto out; |
| 1268 | } |
| 1269 | |
| 1270 | /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */ |
| 1271 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 1272 | job->request_payload.sg_cnt, payload_kbuf, |
| 1273 | job->request_payload.payload_len); |
| 1274 | |
| 1275 | /* Invoke IOCMD handler - to handle all the vendor command requests */ |
| 1276 | rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf, |
| 1277 | job->request_payload.payload_len); |
| 1278 | if (rc != BFA_STATUS_OK) |
| 1279 | goto error; |
| 1280 | |
| 1281 | /* Copy the response data to the job->reply_payload sg_list */ |
| 1282 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 1283 | job->reply_payload.sg_cnt, |
| 1284 | payload_kbuf, |
| 1285 | job->reply_payload.payload_len); |
| 1286 | |
| 1287 | /* free the command buffer */ |
| 1288 | kfree(payload_kbuf); |
| 1289 | |
| 1290 | /* Fill the BSG job reply data */ |
| 1291 | job->reply_len = job->reply_payload.payload_len; |
| 1292 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; |
| 1293 | job->reply->result = rc; |
| 1294 | |
| 1295 | job->job_done(job); |
| 1296 | return rc; |
| 1297 | error: |
| 1298 | /* free the command buffer */ |
| 1299 | kfree(payload_kbuf); |
| 1300 | out: |
| 1301 | job->reply->result = rc; |
| 1302 | job->reply_len = sizeof(uint32_t); |
| 1303 | job->reply->reply_payload_rcv_len = 0; |
| 1304 | return rc; |
| 1305 | } |
| 1306 | |
| 1307 | /* FC passthru call backs */ |
| 1308 | u64 |
| 1309 | bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid) |
| 1310 | { |
| 1311 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; |
| 1312 | struct bfa_sge_s *sge; |
| 1313 | u64 addr; |
| 1314 | |
| 1315 | sge = drv_fcxp->req_sge + sgeid; |
| 1316 | addr = (u64)(size_t) sge->sg_addr; |
| 1317 | return addr; |
| 1318 | } |
| 1319 | |
| 1320 | u32 |
| 1321 | bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid) |
| 1322 | { |
| 1323 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; |
| 1324 | struct bfa_sge_s *sge; |
| 1325 | |
| 1326 | sge = drv_fcxp->req_sge + sgeid; |
| 1327 | return sge->sg_len; |
| 1328 | } |
| 1329 | |
| 1330 | u64 |
| 1331 | bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid) |
| 1332 | { |
| 1333 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; |
| 1334 | struct bfa_sge_s *sge; |
| 1335 | u64 addr; |
| 1336 | |
| 1337 | sge = drv_fcxp->rsp_sge + sgeid; |
| 1338 | addr = (u64)(size_t) sge->sg_addr; |
| 1339 | return addr; |
| 1340 | } |
| 1341 | |
| 1342 | u32 |
| 1343 | bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid) |
| 1344 | { |
| 1345 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; |
| 1346 | struct bfa_sge_s *sge; |
| 1347 | |
| 1348 | sge = drv_fcxp->rsp_sge + sgeid; |
| 1349 | return sge->sg_len; |
| 1350 | } |
| 1351 | |
| 1352 | void |
| 1353 | bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg, |
| 1354 | bfa_status_t req_status, u32 rsp_len, u32 resid_len, |
| 1355 | struct fchs_s *rsp_fchs) |
| 1356 | { |
| 1357 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; |
| 1358 | |
| 1359 | drv_fcxp->req_status = req_status; |
| 1360 | drv_fcxp->rsp_len = rsp_len; |
| 1361 | |
| 1362 | /* bfa_fcxp will be automatically freed by BFA */ |
| 1363 | drv_fcxp->bfa_fcxp = NULL; |
| 1364 | complete(&drv_fcxp->comp); |
| 1365 | } |
| 1366 | |
| 1367 | struct bfad_buf_info * |
| 1368 | bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf, |
| 1369 | uint32_t payload_len, uint32_t *num_sgles) |
| 1370 | { |
| 1371 | struct bfad_buf_info *buf_base, *buf_info; |
| 1372 | struct bfa_sge_s *sg_table; |
| 1373 | int sge_num = 1; |
| 1374 | |
| 1375 | buf_base = kzalloc((sizeof(struct bfad_buf_info) + |
| 1376 | sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL); |
| 1377 | if (!buf_base) |
| 1378 | return NULL; |
| 1379 | |
| 1380 | sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) + |
| 1381 | (sizeof(struct bfad_buf_info) * sge_num)); |
| 1382 | |
| 1383 | /* Allocate dma coherent memory */ |
| 1384 | buf_info = buf_base; |
| 1385 | buf_info->size = payload_len; |
| 1386 | buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size, |
| 1387 | &buf_info->phys, GFP_KERNEL); |
| 1388 | if (!buf_info->virt) |
| 1389 | goto out_free_mem; |
| 1390 | |
| 1391 | /* copy the linear bsg buffer to buf_info */ |
| 1392 | memset(buf_info->virt, 0, buf_info->size); |
| 1393 | memcpy(buf_info->virt, payload_kbuf, buf_info->size); |
| 1394 | |
| 1395 | /* |
| 1396 | * Setup SG table |
| 1397 | */ |
| 1398 | sg_table->sg_len = buf_info->size; |
| 1399 | sg_table->sg_addr = (void *)(size_t) buf_info->phys; |
| 1400 | |
| 1401 | *num_sgles = sge_num; |
| 1402 | |
| 1403 | return buf_base; |
| 1404 | |
| 1405 | out_free_mem: |
| 1406 | kfree(buf_base); |
| 1407 | return NULL; |
| 1408 | } |
| 1409 | |
| 1410 | void |
| 1411 | bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base, |
| 1412 | uint32_t num_sgles) |
| 1413 | { |
| 1414 | int i; |
| 1415 | struct bfad_buf_info *buf_info = buf_base; |
| 1416 | |
| 1417 | if (buf_base) { |
| 1418 | for (i = 0; i < num_sgles; buf_info++, i++) { |
| 1419 | if (buf_info->virt != NULL) |
| 1420 | dma_free_coherent(&bfad->pcidev->dev, |
| 1421 | buf_info->size, buf_info->virt, |
| 1422 | buf_info->phys); |
| 1423 | } |
| 1424 | kfree(buf_base); |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | int |
| 1429 | bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp, |
| 1430 | bfa_bsg_fcpt_t *bsg_fcpt) |
| 1431 | { |
| 1432 | struct bfa_fcxp_s *hal_fcxp; |
| 1433 | struct bfad_s *bfad = drv_fcxp->port->bfad; |
| 1434 | unsigned long flags; |
| 1435 | uint8_t lp_tag; |
| 1436 | |
| 1437 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1438 | |
| 1439 | /* Allocate bfa_fcxp structure */ |
| 1440 | hal_fcxp = bfa_fcxp_alloc(drv_fcxp, &bfad->bfa, |
| 1441 | drv_fcxp->num_req_sgles, |
| 1442 | drv_fcxp->num_rsp_sgles, |
| 1443 | bfad_fcxp_get_req_sgaddr_cb, |
| 1444 | bfad_fcxp_get_req_sglen_cb, |
| 1445 | bfad_fcxp_get_rsp_sgaddr_cb, |
| 1446 | bfad_fcxp_get_rsp_sglen_cb); |
| 1447 | if (!hal_fcxp) { |
| 1448 | bfa_trc(bfad, 0); |
| 1449 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1450 | return BFA_STATUS_ENOMEM; |
| 1451 | } |
| 1452 | |
| 1453 | drv_fcxp->bfa_fcxp = hal_fcxp; |
| 1454 | |
| 1455 | lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id); |
| 1456 | |
| 1457 | bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag, |
| 1458 | bsg_fcpt->cts, bsg_fcpt->cos, |
| 1459 | job->request_payload.payload_len, |
| 1460 | &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad, |
| 1461 | job->reply_payload.payload_len, bsg_fcpt->tsecs); |
| 1462 | |
| 1463 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1464 | |
| 1465 | return BFA_STATUS_OK; |
| 1466 | } |
| 1467 | |
| 1468 | int |
| 1469 | bfad_im_bsg_els_ct_request(struct fc_bsg_job *job) |
| 1470 | { |
| 1471 | struct bfa_bsg_data *bsg_data; |
| 1472 | struct bfad_im_port_s *im_port = |
| 1473 | (struct bfad_im_port_s *) job->shost->hostdata[0]; |
| 1474 | struct bfad_s *bfad = im_port->bfad; |
| 1475 | bfa_bsg_fcpt_t *bsg_fcpt; |
| 1476 | struct bfad_fcxp *drv_fcxp; |
| 1477 | struct bfa_fcs_lport_s *fcs_port; |
| 1478 | struct bfa_fcs_rport_s *fcs_rport; |
| 1479 | uint32_t command_type = job->request->msgcode; |
| 1480 | unsigned long flags; |
| 1481 | struct bfad_buf_info *rsp_buf_info; |
| 1482 | void *req_kbuf = NULL, *rsp_kbuf = NULL; |
| 1483 | int rc = -EINVAL; |
| 1484 | |
| 1485 | job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */ |
| 1486 | job->reply->reply_payload_rcv_len = 0; |
| 1487 | |
| 1488 | /* Get the payload passed in from userspace */ |
| 1489 | bsg_data = (struct bfa_bsg_data *) (((char *)job->request) + |
| 1490 | sizeof(struct fc_bsg_request)); |
| 1491 | if (bsg_data == NULL) |
| 1492 | goto out; |
| 1493 | |
| 1494 | /* |
| 1495 | * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload |
| 1496 | * buffer of size bsg_data->payload_len |
| 1497 | */ |
| 1498 | bsg_fcpt = (struct bfa_bsg_fcpt_s *) |
| 1499 | kzalloc(bsg_data->payload_len, GFP_KERNEL); |
| 1500 | if (!bsg_fcpt) |
| 1501 | goto out; |
| 1502 | |
| 1503 | if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload, |
| 1504 | bsg_data->payload_len)) { |
| 1505 | kfree(bsg_fcpt); |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL); |
| 1510 | if (drv_fcxp == NULL) { |
| 1511 | rc = -ENOMEM; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
| 1515 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1516 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id, |
| 1517 | bsg_fcpt->lpwwn); |
| 1518 | if (fcs_port == NULL) { |
| 1519 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN; |
| 1520 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1521 | goto out_free_mem; |
| 1522 | } |
| 1523 | |
| 1524 | /* Check if the port is online before sending FC Passthru cmd */ |
| 1525 | if (!bfa_fcs_lport_is_online(fcs_port)) { |
| 1526 | bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE; |
| 1527 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1528 | goto out_free_mem; |
| 1529 | } |
| 1530 | |
| 1531 | drv_fcxp->port = fcs_port->bfad_port; |
| 1532 | |
| 1533 | if (drv_fcxp->port->bfad == 0) |
| 1534 | drv_fcxp->port->bfad = bfad; |
| 1535 | |
| 1536 | /* Fetch the bfa_rport - if nexus needed */ |
| 1537 | if (command_type == FC_BSG_HST_ELS_NOLOGIN || |
| 1538 | command_type == FC_BSG_HST_CT) { |
| 1539 | /* BSG HST commands: no nexus needed */ |
| 1540 | drv_fcxp->bfa_rport = NULL; |
| 1541 | |
| 1542 | } else if (command_type == FC_BSG_RPT_ELS || |
| 1543 | command_type == FC_BSG_RPT_CT) { |
| 1544 | /* BSG RPT commands: nexus needed */ |
| 1545 | fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port, |
| 1546 | bsg_fcpt->dpwwn); |
| 1547 | if (fcs_rport == NULL) { |
| 1548 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN; |
| 1549 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1550 | goto out_free_mem; |
| 1551 | } |
| 1552 | |
| 1553 | drv_fcxp->bfa_rport = fcs_rport->bfa_rport; |
| 1554 | |
| 1555 | } else { /* Unknown BSG msgcode; return -EINVAL */ |
| 1556 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1557 | goto out_free_mem; |
| 1558 | } |
| 1559 | |
| 1560 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1561 | |
| 1562 | /* allocate memory for req / rsp buffers */ |
| 1563 | req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); |
| 1564 | if (!req_kbuf) { |
| 1565 | printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n", |
| 1566 | bfad->pci_name); |
| 1567 | rc = -ENOMEM; |
| 1568 | goto out_free_mem; |
| 1569 | } |
| 1570 | |
| 1571 | rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL); |
| 1572 | if (!rsp_kbuf) { |
| 1573 | printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n", |
| 1574 | bfad->pci_name); |
| 1575 | rc = -ENOMEM; |
| 1576 | goto out_free_mem; |
| 1577 | } |
| 1578 | |
| 1579 | /* map req sg - copy the sg_list passed in to the linear buffer */ |
| 1580 | sg_copy_to_buffer(job->request_payload.sg_list, |
| 1581 | job->request_payload.sg_cnt, req_kbuf, |
| 1582 | job->request_payload.payload_len); |
| 1583 | |
| 1584 | drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf, |
| 1585 | job->request_payload.payload_len, |
| 1586 | &drv_fcxp->num_req_sgles); |
| 1587 | if (!drv_fcxp->reqbuf_info) { |
| 1588 | printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n", |
| 1589 | bfad->pci_name); |
| 1590 | rc = -ENOMEM; |
| 1591 | goto out_free_mem; |
| 1592 | } |
| 1593 | |
| 1594 | drv_fcxp->req_sge = (struct bfa_sge_s *) |
| 1595 | (((uint8_t *)drv_fcxp->reqbuf_info) + |
| 1596 | (sizeof(struct bfad_buf_info) * |
| 1597 | drv_fcxp->num_req_sgles)); |
| 1598 | |
| 1599 | /* map rsp sg */ |
| 1600 | drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf, |
| 1601 | job->reply_payload.payload_len, |
| 1602 | &drv_fcxp->num_rsp_sgles); |
| 1603 | if (!drv_fcxp->rspbuf_info) { |
| 1604 | printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n", |
| 1605 | bfad->pci_name); |
| 1606 | rc = -ENOMEM; |
| 1607 | goto out_free_mem; |
| 1608 | } |
| 1609 | |
| 1610 | rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info; |
| 1611 | drv_fcxp->rsp_sge = (struct bfa_sge_s *) |
| 1612 | (((uint8_t *)drv_fcxp->rspbuf_info) + |
| 1613 | (sizeof(struct bfad_buf_info) * |
| 1614 | drv_fcxp->num_rsp_sgles)); |
| 1615 | |
| 1616 | /* fcxp send */ |
| 1617 | init_completion(&drv_fcxp->comp); |
| 1618 | rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt); |
| 1619 | if (rc == BFA_STATUS_OK) { |
| 1620 | wait_for_completion(&drv_fcxp->comp); |
| 1621 | bsg_fcpt->status = drv_fcxp->req_status; |
| 1622 | } else { |
| 1623 | bsg_fcpt->status = rc; |
| 1624 | goto out_free_mem; |
| 1625 | } |
| 1626 | |
| 1627 | /* fill the job->reply data */ |
| 1628 | if (drv_fcxp->req_status == BFA_STATUS_OK) { |
| 1629 | job->reply_len = drv_fcxp->rsp_len; |
| 1630 | job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len; |
| 1631 | job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; |
| 1632 | } else { |
| 1633 | job->reply->reply_payload_rcv_len = |
| 1634 | sizeof(struct fc_bsg_ctels_reply); |
| 1635 | job->reply_len = sizeof(uint32_t); |
| 1636 | job->reply->reply_data.ctels_reply.status = |
| 1637 | FC_CTELS_STATUS_REJECT; |
| 1638 | } |
| 1639 | |
| 1640 | /* Copy the response data to the reply_payload sg list */ |
| 1641 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 1642 | job->reply_payload.sg_cnt, |
| 1643 | (uint8_t *)rsp_buf_info->virt, |
| 1644 | job->reply_payload.payload_len); |
| 1645 | |
| 1646 | out_free_mem: |
| 1647 | bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info, |
| 1648 | drv_fcxp->num_rsp_sgles); |
| 1649 | bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info, |
| 1650 | drv_fcxp->num_req_sgles); |
| 1651 | kfree(req_kbuf); |
| 1652 | kfree(rsp_kbuf); |
| 1653 | |
| 1654 | /* Need a copy to user op */ |
| 1655 | if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt, |
| 1656 | bsg_data->payload_len)) |
| 1657 | rc = -EIO; |
| 1658 | |
| 1659 | kfree(bsg_fcpt); |
| 1660 | kfree(drv_fcxp); |
| 1661 | out: |
| 1662 | job->reply->result = rc; |
| 1663 | |
| 1664 | if (rc == BFA_STATUS_OK) |
| 1665 | job->job_done(job); |
| 1666 | |
| 1667 | return rc; |
| 1668 | } |
| 1669 | |
| 1670 | int |
| 1671 | bfad_im_bsg_request(struct fc_bsg_job *job) |
| 1672 | { |
| 1673 | uint32_t rc = BFA_STATUS_OK; |
| 1674 | |
| 1675 | /* Increment the bfa module refcnt - if bsg request is in service */ |
| 1676 | bfad_im_bsg_get_kobject(job); |
| 1677 | |
| 1678 | switch (job->request->msgcode) { |
| 1679 | case FC_BSG_HST_VENDOR: |
| 1680 | /* Process BSG HST Vendor requests */ |
| 1681 | rc = bfad_im_bsg_vendor_request(job); |
| 1682 | break; |
| 1683 | case FC_BSG_HST_ELS_NOLOGIN: |
| 1684 | case FC_BSG_RPT_ELS: |
| 1685 | case FC_BSG_HST_CT: |
| 1686 | case FC_BSG_RPT_CT: |
| 1687 | /* Process BSG ELS/CT commands */ |
| 1688 | rc = bfad_im_bsg_els_ct_request(job); |
| 1689 | break; |
| 1690 | default: |
| 1691 | job->reply->result = rc = -EINVAL; |
| 1692 | job->reply->reply_payload_rcv_len = 0; |
| 1693 | break; |
| 1694 | } |
| 1695 | |
| 1696 | /* Decrement the bfa module refcnt - on completion of bsg request */ |
| 1697 | bfad_im_bsg_put_kobject(job); |
| 1698 | |
| 1699 | return rc; |
| 1700 | } |
| 1701 | |
| 1702 | int |
| 1703 | bfad_im_bsg_timeout(struct fc_bsg_job *job) |
| 1704 | { |
| 1705 | /* Don't complete the BSG job request - return -EAGAIN |
| 1706 | * to reset bsg job timeout : for ELS/CT pass thru we |
| 1707 | * already have timer to track the request. |
| 1708 | */ |
| 1709 | return -EAGAIN; |
| 1710 | } |