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