17725ccfdSJing Huang /* 2a36c61f9SKrishna Gudipati * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. 37725ccfdSJing Huang * All rights reserved 47725ccfdSJing Huang * www.brocade.com 57725ccfdSJing Huang * 67725ccfdSJing Huang * Linux driver for Brocade Fibre Channel Host Bus Adapter. 77725ccfdSJing Huang * 87725ccfdSJing Huang * This program is free software; you can redistribute it and/or modify it 97725ccfdSJing Huang * under the terms of the GNU General Public License (GPL) Version 2 as 107725ccfdSJing Huang * published by the Free Software Foundation 117725ccfdSJing Huang * 127725ccfdSJing Huang * This program is distributed in the hope that it will be useful, but 137725ccfdSJing Huang * WITHOUT ANY WARRANTY; without even the implied warranty of 147725ccfdSJing Huang * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 157725ccfdSJing Huang * General Public License for more details. 167725ccfdSJing Huang */ 177725ccfdSJing Huang 185fbe25c7SJing Huang /* 197725ccfdSJing Huang * bfa_attr.c Linux driver configuration interface module. 207725ccfdSJing Huang */ 217725ccfdSJing Huang 227725ccfdSJing Huang #include "bfad_drv.h" 237725ccfdSJing Huang #include "bfad_im.h" 247725ccfdSJing Huang 255fbe25c7SJing Huang /* 267725ccfdSJing Huang * FC transport template entry, get SCSI target port ID. 277725ccfdSJing Huang */ 2852f94b6fSMaggie static void 297725ccfdSJing Huang bfad_im_get_starget_port_id(struct scsi_target *starget) 307725ccfdSJing Huang { 317725ccfdSJing Huang struct Scsi_Host *shost; 327725ccfdSJing Huang struct bfad_im_port_s *im_port; 337725ccfdSJing Huang struct bfad_s *bfad; 347725ccfdSJing Huang struct bfad_itnim_s *itnim = NULL; 357725ccfdSJing Huang u32 fc_id = -1; 367725ccfdSJing Huang unsigned long flags; 377725ccfdSJing Huang 38a36c61f9SKrishna Gudipati shost = dev_to_shost(starget->dev.parent); 397725ccfdSJing Huang im_port = (struct bfad_im_port_s *) shost->hostdata[0]; 407725ccfdSJing Huang bfad = im_port->bfad; 417725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 427725ccfdSJing Huang 43f16a1750SMaggie Zhang itnim = bfad_get_itnim(im_port, starget->id); 447725ccfdSJing Huang if (itnim) 457725ccfdSJing Huang fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim); 467725ccfdSJing Huang 477725ccfdSJing Huang fc_starget_port_id(starget) = fc_id; 487725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 497725ccfdSJing Huang } 507725ccfdSJing Huang 515fbe25c7SJing Huang /* 527725ccfdSJing Huang * FC transport template entry, get SCSI target nwwn. 537725ccfdSJing Huang */ 5452f94b6fSMaggie static void 557725ccfdSJing Huang bfad_im_get_starget_node_name(struct scsi_target *starget) 567725ccfdSJing Huang { 577725ccfdSJing Huang struct Scsi_Host *shost; 587725ccfdSJing Huang struct bfad_im_port_s *im_port; 597725ccfdSJing Huang struct bfad_s *bfad; 607725ccfdSJing Huang struct bfad_itnim_s *itnim = NULL; 617725ccfdSJing Huang u64 node_name = 0; 627725ccfdSJing Huang unsigned long flags; 637725ccfdSJing Huang 64a36c61f9SKrishna Gudipati shost = dev_to_shost(starget->dev.parent); 657725ccfdSJing Huang im_port = (struct bfad_im_port_s *) shost->hostdata[0]; 667725ccfdSJing Huang bfad = im_port->bfad; 677725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 687725ccfdSJing Huang 69f16a1750SMaggie Zhang itnim = bfad_get_itnim(im_port, starget->id); 707725ccfdSJing Huang if (itnim) 717725ccfdSJing Huang node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim); 727725ccfdSJing Huang 73ba816ea8SJing Huang fc_starget_node_name(starget) = cpu_to_be64(node_name); 747725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 757725ccfdSJing Huang } 767725ccfdSJing Huang 775fbe25c7SJing Huang /* 787725ccfdSJing Huang * FC transport template entry, get SCSI target pwwn. 797725ccfdSJing Huang */ 8052f94b6fSMaggie static void 817725ccfdSJing Huang bfad_im_get_starget_port_name(struct scsi_target *starget) 827725ccfdSJing Huang { 837725ccfdSJing Huang struct Scsi_Host *shost; 847725ccfdSJing Huang struct bfad_im_port_s *im_port; 857725ccfdSJing Huang struct bfad_s *bfad; 867725ccfdSJing Huang struct bfad_itnim_s *itnim = NULL; 877725ccfdSJing Huang u64 port_name = 0; 887725ccfdSJing Huang unsigned long flags; 897725ccfdSJing Huang 90a36c61f9SKrishna Gudipati shost = dev_to_shost(starget->dev.parent); 917725ccfdSJing Huang im_port = (struct bfad_im_port_s *) shost->hostdata[0]; 927725ccfdSJing Huang bfad = im_port->bfad; 937725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 947725ccfdSJing Huang 95f16a1750SMaggie Zhang itnim = bfad_get_itnim(im_port, starget->id); 967725ccfdSJing Huang if (itnim) 977725ccfdSJing Huang port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim); 987725ccfdSJing Huang 99ba816ea8SJing Huang fc_starget_port_name(starget) = cpu_to_be64(port_name); 1007725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 1017725ccfdSJing Huang } 1027725ccfdSJing Huang 1035fbe25c7SJing Huang /* 1047725ccfdSJing Huang * FC transport template entry, get SCSI host port ID. 1057725ccfdSJing Huang */ 10652f94b6fSMaggie static void 1077725ccfdSJing Huang bfad_im_get_host_port_id(struct Scsi_Host *shost) 1087725ccfdSJing Huang { 1097725ccfdSJing Huang struct bfad_im_port_s *im_port = 1107725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 1117725ccfdSJing Huang struct bfad_port_s *port = im_port->port; 1127725ccfdSJing Huang 1137725ccfdSJing Huang fc_host_port_id(shost) = 114f16a1750SMaggie Zhang bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port)); 1157725ccfdSJing Huang } 1167725ccfdSJing Huang 1175fbe25c7SJing Huang /* 1187725ccfdSJing Huang * FC transport template entry, get SCSI host port type. 1197725ccfdSJing Huang */ 1207725ccfdSJing Huang static void 1217725ccfdSJing Huang bfad_im_get_host_port_type(struct Scsi_Host *shost) 1227725ccfdSJing Huang { 1237725ccfdSJing Huang struct bfad_im_port_s *im_port = 1247725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 1257725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 126a36c61f9SKrishna Gudipati struct bfa_lport_attr_s port_attr; 1277725ccfdSJing Huang 128a36c61f9SKrishna Gudipati bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); 1297725ccfdSJing Huang 130a36c61f9SKrishna Gudipati switch (port_attr.port_type) { 131a36c61f9SKrishna Gudipati case BFA_PORT_TYPE_NPORT: 1327725ccfdSJing Huang fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 1337725ccfdSJing Huang break; 134a36c61f9SKrishna Gudipati case BFA_PORT_TYPE_NLPORT: 1357725ccfdSJing Huang fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 1367725ccfdSJing Huang break; 137a36c61f9SKrishna Gudipati case BFA_PORT_TYPE_P2P: 1387725ccfdSJing Huang fc_host_port_type(shost) = FC_PORTTYPE_PTP; 1397725ccfdSJing Huang break; 140a36c61f9SKrishna Gudipati case BFA_PORT_TYPE_LPORT: 1417725ccfdSJing Huang fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 1427725ccfdSJing Huang break; 1437725ccfdSJing Huang default: 1447725ccfdSJing Huang fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 1457725ccfdSJing Huang break; 1467725ccfdSJing Huang } 1477725ccfdSJing Huang } 1487725ccfdSJing Huang 1495fbe25c7SJing Huang /* 1507725ccfdSJing Huang * FC transport template entry, get SCSI host port state. 1517725ccfdSJing Huang */ 1527725ccfdSJing Huang static void 1537725ccfdSJing Huang bfad_im_get_host_port_state(struct Scsi_Host *shost) 1547725ccfdSJing Huang { 1557725ccfdSJing Huang struct bfad_im_port_s *im_port = 1567725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 1577725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 158a36c61f9SKrishna Gudipati struct bfa_port_attr_s attr; 1597725ccfdSJing Huang 1601c8a4c37SKrishna Gudipati bfa_fcport_get_attr(&bfad->bfa, &attr); 1617725ccfdSJing Huang 1627725ccfdSJing Huang switch (attr.port_state) { 163a36c61f9SKrishna Gudipati case BFA_PORT_ST_LINKDOWN: 1647725ccfdSJing Huang fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 1657725ccfdSJing Huang break; 166a36c61f9SKrishna Gudipati case BFA_PORT_ST_LINKUP: 1677725ccfdSJing Huang fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 1687725ccfdSJing Huang break; 169a36c61f9SKrishna Gudipati case BFA_PORT_ST_DISABLED: 170a36c61f9SKrishna Gudipati case BFA_PORT_ST_STOPPED: 171a36c61f9SKrishna Gudipati case BFA_PORT_ST_IOCDOWN: 172a36c61f9SKrishna Gudipati case BFA_PORT_ST_IOCDIS: 173a36c61f9SKrishna Gudipati fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 174a36c61f9SKrishna Gudipati break; 175a36c61f9SKrishna Gudipati case BFA_PORT_ST_UNINIT: 176a36c61f9SKrishna Gudipati case BFA_PORT_ST_ENABLING_QWAIT: 177a36c61f9SKrishna Gudipati case BFA_PORT_ST_ENABLING: 178a36c61f9SKrishna Gudipati case BFA_PORT_ST_DISABLING_QWAIT: 179a36c61f9SKrishna Gudipati case BFA_PORT_ST_DISABLING: 1807725ccfdSJing Huang default: 1817725ccfdSJing Huang fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 1827725ccfdSJing Huang break; 1837725ccfdSJing Huang } 1847725ccfdSJing Huang } 1857725ccfdSJing Huang 1865fbe25c7SJing Huang /* 1877725ccfdSJing Huang * FC transport template entry, get SCSI host active fc4s. 1887725ccfdSJing Huang */ 1897725ccfdSJing Huang static void 1907725ccfdSJing Huang bfad_im_get_host_active_fc4s(struct Scsi_Host *shost) 1917725ccfdSJing Huang { 1927725ccfdSJing Huang struct bfad_im_port_s *im_port = 1937725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 1947725ccfdSJing Huang struct bfad_port_s *port = im_port->port; 1957725ccfdSJing Huang 1967725ccfdSJing Huang memset(fc_host_active_fc4s(shost), 0, 1977725ccfdSJing Huang sizeof(fc_host_active_fc4s(shost))); 1987725ccfdSJing Huang 199a36c61f9SKrishna Gudipati if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM) 2007725ccfdSJing Huang fc_host_active_fc4s(shost)[2] = 1; 2017725ccfdSJing Huang 2027725ccfdSJing Huang fc_host_active_fc4s(shost)[7] = 1; 2037725ccfdSJing Huang } 2047725ccfdSJing Huang 2055fbe25c7SJing Huang /* 2067725ccfdSJing Huang * FC transport template entry, get SCSI host link speed. 2077725ccfdSJing Huang */ 2087725ccfdSJing Huang static void 2097725ccfdSJing Huang bfad_im_get_host_speed(struct Scsi_Host *shost) 2107725ccfdSJing Huang { 2117725ccfdSJing Huang struct bfad_im_port_s *im_port = 2127725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 2137725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 214a36c61f9SKrishna Gudipati struct bfa_port_attr_s attr; 2157725ccfdSJing Huang 2161c8a4c37SKrishna Gudipati bfa_fcport_get_attr(&bfad->bfa, &attr); 2177725ccfdSJing Huang switch (attr.speed) { 218a36c61f9SKrishna Gudipati case BFA_PORT_SPEED_10GBPS: 219a36c61f9SKrishna Gudipati fc_host_speed(shost) = FC_PORTSPEED_10GBIT; 220a36c61f9SKrishna Gudipati break; 2218b070b4aSKrishna Gudipati case BFA_PORT_SPEED_16GBPS: 2228b070b4aSKrishna Gudipati fc_host_speed(shost) = FC_PORTSPEED_16GBIT; 2238b070b4aSKrishna Gudipati break; 224a36c61f9SKrishna Gudipati case BFA_PORT_SPEED_8GBPS: 2257725ccfdSJing Huang fc_host_speed(shost) = FC_PORTSPEED_8GBIT; 2267725ccfdSJing Huang break; 227a36c61f9SKrishna Gudipati case BFA_PORT_SPEED_4GBPS: 2287725ccfdSJing Huang fc_host_speed(shost) = FC_PORTSPEED_4GBIT; 2297725ccfdSJing Huang break; 230a36c61f9SKrishna Gudipati case BFA_PORT_SPEED_2GBPS: 2317725ccfdSJing Huang fc_host_speed(shost) = FC_PORTSPEED_2GBIT; 2327725ccfdSJing Huang break; 233a36c61f9SKrishna Gudipati case BFA_PORT_SPEED_1GBPS: 2347725ccfdSJing Huang fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 2357725ccfdSJing Huang break; 2367725ccfdSJing Huang default: 2377725ccfdSJing Huang fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 2387725ccfdSJing Huang break; 2397725ccfdSJing Huang } 2407725ccfdSJing Huang } 2417725ccfdSJing Huang 2425fbe25c7SJing Huang /* 2437725ccfdSJing Huang * FC transport template entry, get SCSI host port type. 2447725ccfdSJing Huang */ 2457725ccfdSJing Huang static void 2467725ccfdSJing Huang bfad_im_get_host_fabric_name(struct Scsi_Host *shost) 2477725ccfdSJing Huang { 2487725ccfdSJing Huang struct bfad_im_port_s *im_port = 2497725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 2507725ccfdSJing Huang struct bfad_port_s *port = im_port->port; 2517725ccfdSJing Huang wwn_t fabric_nwwn = 0; 2527725ccfdSJing Huang 253a36c61f9SKrishna Gudipati fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port); 2547725ccfdSJing Huang 255ba816ea8SJing Huang fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn); 2567725ccfdSJing Huang 2577725ccfdSJing Huang } 2587725ccfdSJing Huang 2595fbe25c7SJing Huang /* 2607725ccfdSJing Huang * FC transport template entry, get BFAD statistics. 2617725ccfdSJing Huang */ 2627725ccfdSJing Huang static struct fc_host_statistics * 2637725ccfdSJing Huang bfad_im_get_stats(struct Scsi_Host *shost) 2647725ccfdSJing Huang { 2657725ccfdSJing Huang struct bfad_im_port_s *im_port = 2667725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 2677725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 2687725ccfdSJing Huang struct bfad_hal_comp fcomp; 269a36c61f9SKrishna Gudipati union bfa_port_stats_u *fcstats; 2707725ccfdSJing Huang struct fc_host_statistics *hstats; 2717725ccfdSJing Huang bfa_status_t rc; 2727725ccfdSJing Huang unsigned long flags; 2737725ccfdSJing Huang 274a36c61f9SKrishna Gudipati fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL); 275a36c61f9SKrishna Gudipati if (fcstats == NULL) 276a36c61f9SKrishna Gudipati return NULL; 277a36c61f9SKrishna Gudipati 2787725ccfdSJing Huang hstats = &bfad->link_stats; 2797725ccfdSJing Huang init_completion(&fcomp.comp); 2807725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 2817725ccfdSJing Huang memset(hstats, 0, sizeof(struct fc_host_statistics)); 282ca8b4327SKrishna Gudipati rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa), 283a36c61f9SKrishna Gudipati fcstats, bfad_hcb_comp, &fcomp); 2847725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 2857725ccfdSJing Huang if (rc != BFA_STATUS_OK) 2867725ccfdSJing Huang return NULL; 2877725ccfdSJing Huang 2887725ccfdSJing Huang wait_for_completion(&fcomp.comp); 2897725ccfdSJing Huang 290a36c61f9SKrishna Gudipati /* Fill the fc_host_statistics structure */ 291a36c61f9SKrishna Gudipati hstats->seconds_since_last_reset = fcstats->fc.secs_reset; 292a36c61f9SKrishna Gudipati hstats->tx_frames = fcstats->fc.tx_frames; 293a36c61f9SKrishna Gudipati hstats->tx_words = fcstats->fc.tx_words; 294a36c61f9SKrishna Gudipati hstats->rx_frames = fcstats->fc.rx_frames; 295a36c61f9SKrishna Gudipati hstats->rx_words = fcstats->fc.rx_words; 296a36c61f9SKrishna Gudipati hstats->lip_count = fcstats->fc.lip_count; 297a36c61f9SKrishna Gudipati hstats->nos_count = fcstats->fc.nos_count; 298a36c61f9SKrishna Gudipati hstats->error_frames = fcstats->fc.error_frames; 299a36c61f9SKrishna Gudipati hstats->dumped_frames = fcstats->fc.dropped_frames; 300a36c61f9SKrishna Gudipati hstats->link_failure_count = fcstats->fc.link_failures; 301a36c61f9SKrishna Gudipati hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs; 302a36c61f9SKrishna Gudipati hstats->loss_of_signal_count = fcstats->fc.loss_of_signals; 303a36c61f9SKrishna Gudipati hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs; 304a36c61f9SKrishna Gudipati hstats->invalid_crc_count = fcstats->fc.invalid_crcs; 305a36c61f9SKrishna Gudipati 306a36c61f9SKrishna Gudipati kfree(fcstats); 3077725ccfdSJing Huang return hstats; 3087725ccfdSJing Huang } 3097725ccfdSJing Huang 3105fbe25c7SJing Huang /* 3117725ccfdSJing Huang * FC transport template entry, reset BFAD statistics. 3127725ccfdSJing Huang */ 3137725ccfdSJing Huang static void 3147725ccfdSJing Huang bfad_im_reset_stats(struct Scsi_Host *shost) 3157725ccfdSJing Huang { 3167725ccfdSJing Huang struct bfad_im_port_s *im_port = 3177725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 3187725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 3197725ccfdSJing Huang struct bfad_hal_comp fcomp; 3207725ccfdSJing Huang unsigned long flags; 3217725ccfdSJing Huang bfa_status_t rc; 3227725ccfdSJing Huang 3237725ccfdSJing Huang init_completion(&fcomp.comp); 3247725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 325ca8b4327SKrishna Gudipati rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp, 326ca8b4327SKrishna Gudipati &fcomp); 3277725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 3287725ccfdSJing Huang 3297725ccfdSJing Huang if (rc != BFA_STATUS_OK) 3307725ccfdSJing Huang return; 3317725ccfdSJing Huang 3327725ccfdSJing Huang wait_for_completion(&fcomp.comp); 3337725ccfdSJing Huang 3347725ccfdSJing Huang return; 3357725ccfdSJing Huang } 3367725ccfdSJing Huang 3375fbe25c7SJing Huang /* 3387725ccfdSJing Huang * FC transport template entry, set rport loss timeout. 3394dde5069SVijaya Mohan Guvva * Update dev_loss_tmo based on the value pushed down by the stack 3404dde5069SVijaya Mohan Guvva * In case it is lesser than path_tov of driver, set it to path_tov + 1 3414dde5069SVijaya Mohan Guvva * to ensure that the driver times out before the application 3427725ccfdSJing Huang */ 3437725ccfdSJing Huang static void 3447725ccfdSJing Huang bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout) 3457725ccfdSJing Huang { 3467725ccfdSJing Huang struct bfad_itnim_data_s *itnim_data = rport->dd_data; 3477725ccfdSJing Huang struct bfad_itnim_s *itnim = itnim_data->itnim; 3487725ccfdSJing Huang struct bfad_s *bfad = itnim->im->bfad; 3494dde5069SVijaya Mohan Guvva uint16_t path_tov = bfa_fcpim_path_tov_get(&bfad->bfa); 3507725ccfdSJing Huang 3514dde5069SVijaya Mohan Guvva rport->dev_loss_tmo = timeout; 3524dde5069SVijaya Mohan Guvva if (timeout < path_tov) 3534dde5069SVijaya Mohan Guvva rport->dev_loss_tmo = path_tov + 1; 3547725ccfdSJing Huang } 3557725ccfdSJing Huang 356b504293fSJing Huang static int 357b504293fSJing Huang bfad_im_vport_create(struct fc_vport *fc_vport, bool disable) 358b504293fSJing Huang { 359b504293fSJing Huang char *vname = fc_vport->symbolic_name; 360b504293fSJing Huang struct Scsi_Host *shost = fc_vport->shost; 361b504293fSJing Huang struct bfad_im_port_s *im_port = 362b504293fSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 363b504293fSJing Huang struct bfad_s *bfad = im_port->bfad; 364a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s port_cfg; 365a36c61f9SKrishna Gudipati struct bfad_vport_s *vp; 366b504293fSJing Huang int status = 0, rc; 367b504293fSJing Huang unsigned long flags; 368b504293fSJing Huang 369b504293fSJing Huang memset(&port_cfg, 0, sizeof(port_cfg)); 370d9883548SJing Huang u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn); 371d9883548SJing Huang u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn); 372b504293fSJing Huang if (strlen(vname) > 0) 373b504293fSJing Huang strcpy((char *)&port_cfg.sym_name, vname); 374a36c61f9SKrishna Gudipati port_cfg.roles = BFA_LPORT_ROLE_FCP_IM; 375b504293fSJing Huang 376d9883548SJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 377a36c61f9SKrishna Gudipati list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) { 378a36c61f9SKrishna Gudipati if (port_cfg.pwwn == 379a36c61f9SKrishna Gudipati vp->fcs_vport.lport.port_cfg.pwwn) { 380a36c61f9SKrishna Gudipati port_cfg.preboot_vp = 381a36c61f9SKrishna Gudipati vp->fcs_vport.lport.port_cfg.preboot_vp; 382d9883548SJing Huang break; 383d9883548SJing Huang } 384d9883548SJing Huang } 385d9883548SJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 386d9883548SJing Huang 387d9883548SJing Huang rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev); 388b504293fSJing Huang if (rc == BFA_STATUS_OK) { 389b504293fSJing Huang struct bfad_vport_s *vport; 390b504293fSJing Huang struct bfa_fcs_vport_s *fcs_vport; 391b504293fSJing Huang struct Scsi_Host *vshost; 392b504293fSJing Huang 393b504293fSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 394b504293fSJing Huang fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, 395b504293fSJing Huang port_cfg.pwwn); 396b504293fSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 397d9883548SJing Huang if (fcs_vport == NULL) 398b504293fSJing Huang return VPCERR_BAD_WWN; 399b504293fSJing Huang 400b504293fSJing Huang fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); 401b504293fSJing Huang if (disable) { 402d9883548SJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 403b504293fSJing Huang bfa_fcs_vport_stop(fcs_vport); 404d9883548SJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 405b504293fSJing Huang fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); 406b504293fSJing Huang } 407b504293fSJing Huang 408b504293fSJing Huang vport = fcs_vport->vport_drv; 409b504293fSJing Huang vshost = vport->drv_port.im_port->shost; 410b504293fSJing Huang fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn); 411b504293fSJing Huang fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn); 4126192bd7cSKrishna Gudipati fc_host_supported_classes(vshost) = FC_COS_CLASS3; 4136192bd7cSKrishna Gudipati 4146192bd7cSKrishna Gudipati memset(fc_host_supported_fc4s(vshost), 0, 4156192bd7cSKrishna Gudipati sizeof(fc_host_supported_fc4s(vshost))); 4166192bd7cSKrishna Gudipati 4176192bd7cSKrishna Gudipati /* For FCP type 0x08 */ 4186192bd7cSKrishna Gudipati if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM) 4196192bd7cSKrishna Gudipati fc_host_supported_fc4s(vshost)[2] = 1; 4206192bd7cSKrishna Gudipati 4216192bd7cSKrishna Gudipati /* For fibre channel services type 0x20 */ 4226192bd7cSKrishna Gudipati fc_host_supported_fc4s(vshost)[7] = 1; 4236192bd7cSKrishna Gudipati 4246192bd7cSKrishna Gudipati fc_host_supported_speeds(vshost) = 4256192bd7cSKrishna Gudipati bfad_im_supported_speeds(&bfad->bfa); 4266192bd7cSKrishna Gudipati fc_host_maxframe_size(vshost) = 4276192bd7cSKrishna Gudipati bfa_fcport_get_maxfrsize(&bfad->bfa); 4286192bd7cSKrishna Gudipati 429b504293fSJing Huang fc_vport->dd_data = vport; 430b504293fSJing Huang vport->drv_port.im_port->fc_vport = fc_vport; 431b504293fSJing Huang } else if (rc == BFA_STATUS_INVALID_WWN) 432b504293fSJing Huang return VPCERR_BAD_WWN; 433b504293fSJing Huang else if (rc == BFA_STATUS_VPORT_EXISTS) 434b504293fSJing Huang return VPCERR_BAD_WWN; 435b504293fSJing Huang else if (rc == BFA_STATUS_VPORT_MAX) 436b504293fSJing Huang return VPCERR_NO_FABRIC_SUPP; 437b504293fSJing Huang else if (rc == BFA_STATUS_VPORT_WWN_BP) 438b504293fSJing Huang return VPCERR_BAD_WWN; 439b504293fSJing Huang else 440b504293fSJing Huang return FC_VPORT_FAILED; 441b504293fSJing Huang 442b504293fSJing Huang return status; 443b504293fSJing Huang } 444b504293fSJing Huang 445acea2415SKrishna Gudipati int 446acea2415SKrishna Gudipati bfad_im_issue_fc_host_lip(struct Scsi_Host *shost) 447acea2415SKrishna Gudipati { 448acea2415SKrishna Gudipati struct bfad_im_port_s *im_port = 449acea2415SKrishna Gudipati (struct bfad_im_port_s *) shost->hostdata[0]; 450acea2415SKrishna Gudipati struct bfad_s *bfad = im_port->bfad; 451acea2415SKrishna Gudipati struct bfad_hal_comp fcomp; 452acea2415SKrishna Gudipati unsigned long flags; 453acea2415SKrishna Gudipati uint32_t status; 454acea2415SKrishna Gudipati 455acea2415SKrishna Gudipati init_completion(&fcomp.comp); 456acea2415SKrishna Gudipati spin_lock_irqsave(&bfad->bfad_lock, flags); 457acea2415SKrishna Gudipati status = bfa_port_disable(&bfad->bfa.modules.port, 458acea2415SKrishna Gudipati bfad_hcb_comp, &fcomp); 459acea2415SKrishna Gudipati spin_unlock_irqrestore(&bfad->bfad_lock, flags); 460acea2415SKrishna Gudipati 461acea2415SKrishna Gudipati if (status != BFA_STATUS_OK) 462acea2415SKrishna Gudipati return -EIO; 463acea2415SKrishna Gudipati 464acea2415SKrishna Gudipati wait_for_completion(&fcomp.comp); 465acea2415SKrishna Gudipati if (fcomp.status != BFA_STATUS_OK) 466acea2415SKrishna Gudipati return -EIO; 467acea2415SKrishna Gudipati 468acea2415SKrishna Gudipati spin_lock_irqsave(&bfad->bfad_lock, flags); 469acea2415SKrishna Gudipati status = bfa_port_enable(&bfad->bfa.modules.port, 470acea2415SKrishna Gudipati bfad_hcb_comp, &fcomp); 471acea2415SKrishna Gudipati spin_unlock_irqrestore(&bfad->bfad_lock, flags); 472acea2415SKrishna Gudipati if (status != BFA_STATUS_OK) 473acea2415SKrishna Gudipati return -EIO; 474acea2415SKrishna Gudipati 475acea2415SKrishna Gudipati wait_for_completion(&fcomp.comp); 476acea2415SKrishna Gudipati if (fcomp.status != BFA_STATUS_OK) 477acea2415SKrishna Gudipati return -EIO; 478acea2415SKrishna Gudipati 479acea2415SKrishna Gudipati return 0; 480acea2415SKrishna Gudipati } 481acea2415SKrishna Gudipati 482b504293fSJing Huang static int 483b504293fSJing Huang bfad_im_vport_delete(struct fc_vport *fc_vport) 484b504293fSJing Huang { 485b504293fSJing Huang struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data; 486b504293fSJing Huang struct bfad_im_port_s *im_port = 487b504293fSJing Huang (struct bfad_im_port_s *) vport->drv_port.im_port; 488b504293fSJing Huang struct bfad_s *bfad = im_port->bfad; 489b504293fSJing Huang struct bfad_port_s *port; 490b504293fSJing Huang struct bfa_fcs_vport_s *fcs_vport; 491b504293fSJing Huang struct Scsi_Host *vshost; 492b504293fSJing Huang wwn_t pwwn; 493b504293fSJing Huang int rc; 494b504293fSJing Huang unsigned long flags; 495b504293fSJing Huang struct completion fcomp; 496b504293fSJing Huang 497ff179e0fSKrishna Gudipati if (im_port->flags & BFAD_PORT_DELETE) { 498ff179e0fSKrishna Gudipati bfad_scsi_host_free(bfad, im_port); 499ff179e0fSKrishna Gudipati list_del(&vport->list_entry); 50017c201b3SKrishna Gudipati kfree(vport); 501ff179e0fSKrishna Gudipati return 0; 502ff179e0fSKrishna Gudipati } 503b504293fSJing Huang 504b504293fSJing Huang port = im_port->port; 505b504293fSJing Huang 506b504293fSJing Huang vshost = vport->drv_port.im_port->shost; 507d9883548SJing Huang u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); 508b504293fSJing Huang 509b504293fSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 510b504293fSJing Huang fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); 511b504293fSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 512b504293fSJing Huang 513b504293fSJing Huang if (fcs_vport == NULL) 514b504293fSJing Huang return VPCERR_BAD_WWN; 515b504293fSJing Huang 516b504293fSJing Huang vport->drv_port.flags |= BFAD_PORT_DELETE; 517b504293fSJing Huang 518b504293fSJing Huang vport->comp_del = &fcomp; 519b504293fSJing Huang init_completion(vport->comp_del); 520b504293fSJing Huang 521b504293fSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 522b504293fSJing Huang rc = bfa_fcs_vport_delete(&vport->fcs_vport); 523b504293fSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 524b504293fSJing Huang 525c54d557cSJing Huang if (rc == BFA_STATUS_PBC) { 526c54d557cSJing Huang vport->drv_port.flags &= ~BFAD_PORT_DELETE; 527c54d557cSJing Huang vport->comp_del = NULL; 528d9883548SJing Huang return -1; 529c54d557cSJing Huang } 530d9883548SJing Huang 531b504293fSJing Huang wait_for_completion(vport->comp_del); 532b504293fSJing Huang 533f16a1750SMaggie Zhang bfad_scsi_host_free(bfad, im_port); 5345b7db7afSKrishna Gudipati list_del(&vport->list_entry); 535b504293fSJing Huang kfree(vport); 536b504293fSJing Huang 537b504293fSJing Huang return 0; 538b504293fSJing Huang } 539b504293fSJing Huang 540b504293fSJing Huang static int 541b504293fSJing Huang bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable) 542b504293fSJing Huang { 543b504293fSJing Huang struct bfad_vport_s *vport; 544b504293fSJing Huang struct bfad_s *bfad; 545b504293fSJing Huang struct bfa_fcs_vport_s *fcs_vport; 546b504293fSJing Huang struct Scsi_Host *vshost; 547b504293fSJing Huang wwn_t pwwn; 548b504293fSJing Huang unsigned long flags; 549b504293fSJing Huang 550b504293fSJing Huang vport = (struct bfad_vport_s *)fc_vport->dd_data; 551b504293fSJing Huang bfad = vport->drv_port.bfad; 552b504293fSJing Huang vshost = vport->drv_port.im_port->shost; 553d9883548SJing Huang u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); 554b504293fSJing Huang 555b504293fSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 556b504293fSJing Huang fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); 557b504293fSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 558b504293fSJing Huang 559b504293fSJing Huang if (fcs_vport == NULL) 560b504293fSJing Huang return VPCERR_BAD_WWN; 561b504293fSJing Huang 562b504293fSJing Huang if (disable) { 563b504293fSJing Huang bfa_fcs_vport_stop(fcs_vport); 564b504293fSJing Huang fc_vport_set_state(fc_vport, FC_VPORT_DISABLED); 565b504293fSJing Huang } else { 566b504293fSJing Huang bfa_fcs_vport_start(fcs_vport); 567b504293fSJing Huang fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); 568b504293fSJing Huang } 569b504293fSJing Huang 570b504293fSJing Huang return 0; 571b504293fSJing Huang } 572b504293fSJing Huang 573ebfe8392SKrishna Gudipati void 574ebfe8392SKrishna Gudipati bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport) 575ebfe8392SKrishna Gudipati { 576ebfe8392SKrishna Gudipati struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data; 577ebfe8392SKrishna Gudipati struct bfad_im_port_s *im_port = 578ebfe8392SKrishna Gudipati (struct bfad_im_port_s *)vport->drv_port.im_port; 579ebfe8392SKrishna Gudipati struct bfad_s *bfad = im_port->bfad; 580ebfe8392SKrishna Gudipati struct Scsi_Host *vshost = vport->drv_port.im_port->shost; 581ebfe8392SKrishna Gudipati char *sym_name = fc_vport->symbolic_name; 582ebfe8392SKrishna Gudipati struct bfa_fcs_vport_s *fcs_vport; 583ebfe8392SKrishna Gudipati wwn_t pwwn; 584ebfe8392SKrishna Gudipati unsigned long flags; 585ebfe8392SKrishna Gudipati 586ebfe8392SKrishna Gudipati u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn); 587ebfe8392SKrishna Gudipati 588ebfe8392SKrishna Gudipati spin_lock_irqsave(&bfad->bfad_lock, flags); 589ebfe8392SKrishna Gudipati fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn); 590ebfe8392SKrishna Gudipati spin_unlock_irqrestore(&bfad->bfad_lock, flags); 591ebfe8392SKrishna Gudipati 592ebfe8392SKrishna Gudipati if (fcs_vport == NULL) 593ebfe8392SKrishna Gudipati return; 594ebfe8392SKrishna Gudipati 595ebfe8392SKrishna Gudipati spin_lock_irqsave(&bfad->bfad_lock, flags); 59622a08538SVijaya Mohan Guvva if (strlen(sym_name) > 0) 59722a08538SVijaya Mohan Guvva bfa_fcs_lport_set_symname(&fcs_vport->lport, sym_name); 598ebfe8392SKrishna Gudipati spin_unlock_irqrestore(&bfad->bfad_lock, flags); 599ebfe8392SKrishna Gudipati } 600ebfe8392SKrishna Gudipati 6017725ccfdSJing Huang struct fc_function_template bfad_im_fc_function_template = { 6027725ccfdSJing Huang 6037725ccfdSJing Huang /* Target dynamic attributes */ 6047725ccfdSJing Huang .get_starget_port_id = bfad_im_get_starget_port_id, 6057725ccfdSJing Huang .show_starget_port_id = 1, 6067725ccfdSJing Huang .get_starget_node_name = bfad_im_get_starget_node_name, 6077725ccfdSJing Huang .show_starget_node_name = 1, 6087725ccfdSJing Huang .get_starget_port_name = bfad_im_get_starget_port_name, 6097725ccfdSJing Huang .show_starget_port_name = 1, 6107725ccfdSJing Huang 6117725ccfdSJing Huang /* Host dynamic attribute */ 6127725ccfdSJing Huang .get_host_port_id = bfad_im_get_host_port_id, 6137725ccfdSJing Huang .show_host_port_id = 1, 6147725ccfdSJing Huang 6157725ccfdSJing Huang /* Host fixed attributes */ 6167725ccfdSJing Huang .show_host_node_name = 1, 6177725ccfdSJing Huang .show_host_port_name = 1, 6187725ccfdSJing Huang .show_host_supported_classes = 1, 6197725ccfdSJing Huang .show_host_supported_fc4s = 1, 6207725ccfdSJing Huang .show_host_supported_speeds = 1, 6217725ccfdSJing Huang .show_host_maxframe_size = 1, 6227725ccfdSJing Huang 6237725ccfdSJing Huang /* More host dynamic attributes */ 6247725ccfdSJing Huang .show_host_port_type = 1, 6257725ccfdSJing Huang .get_host_port_type = bfad_im_get_host_port_type, 6267725ccfdSJing Huang .show_host_port_state = 1, 6277725ccfdSJing Huang .get_host_port_state = bfad_im_get_host_port_state, 6287725ccfdSJing Huang .show_host_active_fc4s = 1, 6297725ccfdSJing Huang .get_host_active_fc4s = bfad_im_get_host_active_fc4s, 6307725ccfdSJing Huang .show_host_speed = 1, 6317725ccfdSJing Huang .get_host_speed = bfad_im_get_host_speed, 6327725ccfdSJing Huang .show_host_fabric_name = 1, 6337725ccfdSJing Huang .get_host_fabric_name = bfad_im_get_host_fabric_name, 6347725ccfdSJing Huang 6357725ccfdSJing Huang .show_host_symbolic_name = 1, 6367725ccfdSJing Huang 6377725ccfdSJing Huang /* Statistics */ 6387725ccfdSJing Huang .get_fc_host_stats = bfad_im_get_stats, 6397725ccfdSJing Huang .reset_fc_host_stats = bfad_im_reset_stats, 6407725ccfdSJing Huang 6417725ccfdSJing Huang /* Allocation length for host specific data */ 6427725ccfdSJing Huang .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), 6437725ccfdSJing Huang 6447725ccfdSJing Huang /* Remote port fixed attributes */ 6457725ccfdSJing Huang .show_rport_maxframe_size = 1, 6467725ccfdSJing Huang .show_rport_supported_classes = 1, 6477725ccfdSJing Huang .show_rport_dev_loss_tmo = 1, 6487725ccfdSJing Huang .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, 649acea2415SKrishna Gudipati .issue_fc_host_lip = bfad_im_issue_fc_host_lip, 650b504293fSJing Huang .vport_create = bfad_im_vport_create, 651b504293fSJing Huang .vport_delete = bfad_im_vport_delete, 652b504293fSJing Huang .vport_disable = bfad_im_vport_disable, 653ebfe8392SKrishna Gudipati .set_vport_symbolic_name = bfad_im_vport_set_symbolic_name, 654b85daafeSKrishna Gudipati .bsg_request = bfad_im_bsg_request, 655b85daafeSKrishna Gudipati .bsg_timeout = bfad_im_bsg_timeout, 656b504293fSJing Huang }; 657b504293fSJing Huang 658b504293fSJing Huang struct fc_function_template bfad_im_vport_fc_function_template = { 659b504293fSJing Huang 660b504293fSJing Huang /* Target dynamic attributes */ 661b504293fSJing Huang .get_starget_port_id = bfad_im_get_starget_port_id, 662b504293fSJing Huang .show_starget_port_id = 1, 663b504293fSJing Huang .get_starget_node_name = bfad_im_get_starget_node_name, 664b504293fSJing Huang .show_starget_node_name = 1, 665b504293fSJing Huang .get_starget_port_name = bfad_im_get_starget_port_name, 666b504293fSJing Huang .show_starget_port_name = 1, 667b504293fSJing Huang 668b504293fSJing Huang /* Host dynamic attribute */ 669b504293fSJing Huang .get_host_port_id = bfad_im_get_host_port_id, 670b504293fSJing Huang .show_host_port_id = 1, 671b504293fSJing Huang 672b504293fSJing Huang /* Host fixed attributes */ 673b504293fSJing Huang .show_host_node_name = 1, 674b504293fSJing Huang .show_host_port_name = 1, 675b504293fSJing Huang .show_host_supported_classes = 1, 676b504293fSJing Huang .show_host_supported_fc4s = 1, 677b504293fSJing Huang .show_host_supported_speeds = 1, 678b504293fSJing Huang .show_host_maxframe_size = 1, 679b504293fSJing Huang 680b504293fSJing Huang /* More host dynamic attributes */ 681b504293fSJing Huang .show_host_port_type = 1, 682b504293fSJing Huang .get_host_port_type = bfad_im_get_host_port_type, 683b504293fSJing Huang .show_host_port_state = 1, 684b504293fSJing Huang .get_host_port_state = bfad_im_get_host_port_state, 685b504293fSJing Huang .show_host_active_fc4s = 1, 686b504293fSJing Huang .get_host_active_fc4s = bfad_im_get_host_active_fc4s, 687b504293fSJing Huang .show_host_speed = 1, 688b504293fSJing Huang .get_host_speed = bfad_im_get_host_speed, 689b504293fSJing Huang .show_host_fabric_name = 1, 690b504293fSJing Huang .get_host_fabric_name = bfad_im_get_host_fabric_name, 691b504293fSJing Huang 692b504293fSJing Huang .show_host_symbolic_name = 1, 693b504293fSJing Huang 694b504293fSJing Huang /* Statistics */ 695b504293fSJing Huang .get_fc_host_stats = bfad_im_get_stats, 696b504293fSJing Huang .reset_fc_host_stats = bfad_im_reset_stats, 697b504293fSJing Huang 698b504293fSJing Huang /* Allocation length for host specific data */ 699b504293fSJing Huang .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *), 700b504293fSJing Huang 701b504293fSJing Huang /* Remote port fixed attributes */ 702b504293fSJing Huang .show_rport_maxframe_size = 1, 703b504293fSJing Huang .show_rport_supported_classes = 1, 704b504293fSJing Huang .show_rport_dev_loss_tmo = 1, 705b504293fSJing Huang .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, 7067725ccfdSJing Huang }; 7077725ccfdSJing Huang 7085fbe25c7SJing Huang /* 7097725ccfdSJing Huang * Scsi_Host_attrs SCSI host attributes 7107725ccfdSJing Huang */ 7117725ccfdSJing Huang static ssize_t 7127725ccfdSJing Huang bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr, 7137725ccfdSJing Huang char *buf) 7147725ccfdSJing Huang { 7157725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 7167725ccfdSJing Huang struct bfad_im_port_s *im_port = 7177725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 7187725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 7190a4b1fc0SKrishna Gudipati char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; 7207725ccfdSJing Huang 7210a4b1fc0SKrishna Gudipati bfa_get_adapter_serial_num(&bfad->bfa, serial_num); 7220a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", serial_num); 7237725ccfdSJing Huang } 7247725ccfdSJing Huang 7257725ccfdSJing Huang static ssize_t 7267725ccfdSJing Huang bfad_im_model_show(struct device *dev, struct device_attribute *attr, 7277725ccfdSJing Huang char *buf) 7287725ccfdSJing Huang { 7297725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 7307725ccfdSJing Huang struct bfad_im_port_s *im_port = 7317725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 7327725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 7330a4b1fc0SKrishna Gudipati char model[BFA_ADAPTER_MODEL_NAME_LEN]; 7347725ccfdSJing Huang 7350a4b1fc0SKrishna Gudipati bfa_get_adapter_model(&bfad->bfa, model); 7360a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", model); 7377725ccfdSJing Huang } 7387725ccfdSJing Huang 7397725ccfdSJing Huang static ssize_t 7407725ccfdSJing Huang bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr, 7417725ccfdSJing Huang char *buf) 7427725ccfdSJing Huang { 7437725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 7447725ccfdSJing Huang struct bfad_im_port_s *im_port = 7457725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 7467725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 747a36c61f9SKrishna Gudipati char model[BFA_ADAPTER_MODEL_NAME_LEN]; 7480a4b1fc0SKrishna Gudipati char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN]; 74975332a70SKrishna Gudipati int nports = 0; 7507725ccfdSJing Huang 751a36c61f9SKrishna Gudipati bfa_get_adapter_model(&bfad->bfa, model); 75275332a70SKrishna Gudipati nports = bfa_get_nports(&bfad->bfa); 753a36c61f9SKrishna Gudipati if (!strcmp(model, "Brocade-425")) 754a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 755a36c61f9SKrishna Gudipati "Brocade 4Gbps PCIe dual port FC HBA"); 756a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-825")) 757a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 758a36c61f9SKrishna Gudipati "Brocade 8Gbps PCIe dual port FC HBA"); 759a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-42B")) 760a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 76175332a70SKrishna Gudipati "Brocade 4Gbps PCIe dual port FC HBA for HP"); 762a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-82B")) 763a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 76475332a70SKrishna Gudipati "Brocade 8Gbps PCIe dual port FC HBA for HP"); 765a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-1010")) 766a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 767a36c61f9SKrishna Gudipati "Brocade 10Gbps single port CNA"); 768a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-1020")) 769a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 770a36c61f9SKrishna Gudipati "Brocade 10Gbps dual port CNA"); 771a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-1007")) 772a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 77375332a70SKrishna Gudipati "Brocade 10Gbps CNA for IBM Blade Center"); 774a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-415")) 775a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 776a36c61f9SKrishna Gudipati "Brocade 4Gbps PCIe single port FC HBA"); 777a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-815")) 778a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 779a36c61f9SKrishna Gudipati "Brocade 8Gbps PCIe single port FC HBA"); 780a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-41B")) 781a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 78275332a70SKrishna Gudipati "Brocade 4Gbps PCIe single port FC HBA for HP"); 783a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-81B")) 784a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 78575332a70SKrishna Gudipati "Brocade 8Gbps PCIe single port FC HBA for HP"); 786a36c61f9SKrishna Gudipati else if (!strcmp(model, "Brocade-804")) 787a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 78875332a70SKrishna Gudipati "Brocade 8Gbps FC HBA for HP Bladesystem C-class"); 7899d8ad782SKrishna Gudipati else if (!strcmp(model, "Brocade-1741")) 790a36c61f9SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 79175332a70SKrishna Gudipati "Brocade 10Gbps CNA for Dell M-Series Blade Servers"); 7929d8ad782SKrishna Gudipati else if (strstr(model, "Brocade-1860")) { 79375332a70SKrishna Gudipati if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc)) 79475332a70SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 79575332a70SKrishna Gudipati "Brocade 10Gbps single port CNA"); 79675332a70SKrishna Gudipati else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) 79775332a70SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 79875332a70SKrishna Gudipati "Brocade 16Gbps PCIe single port FC HBA"); 79975332a70SKrishna Gudipati else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc)) 80075332a70SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 80175332a70SKrishna Gudipati "Brocade 10Gbps dual port CNA"); 80275332a70SKrishna Gudipati else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) 80375332a70SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 80475332a70SKrishna Gudipati "Brocade 16Gbps PCIe dual port FC HBA"); 8056dca60a3SKrishna Gudipati } else if (!strcmp(model, "Brocade-1867")) { 8066dca60a3SKrishna Gudipati if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) 8076dca60a3SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 8086dca60a3SKrishna Gudipati "Brocade 16Gbps PCIe single port FC HBA for IBM"); 8096dca60a3SKrishna Gudipati else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc)) 8106dca60a3SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 8116dca60a3SKrishna Gudipati "Brocade 16Gbps PCIe dual port FC HBA for IBM"); 81275332a70SKrishna Gudipati } else 81375332a70SKrishna Gudipati snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN, 814a36c61f9SKrishna Gudipati "Invalid Model"); 815a36c61f9SKrishna Gudipati 8160a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", model_descr); 8177725ccfdSJing Huang } 8187725ccfdSJing Huang 8197725ccfdSJing Huang static ssize_t 8207725ccfdSJing Huang bfad_im_node_name_show(struct device *dev, struct device_attribute *attr, 8217725ccfdSJing Huang char *buf) 8227725ccfdSJing Huang { 8237725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 8247725ccfdSJing Huang struct bfad_im_port_s *im_port = 8257725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 8267725ccfdSJing Huang struct bfad_port_s *port = im_port->port; 8277725ccfdSJing Huang u64 nwwn; 8287725ccfdSJing Huang 829a36c61f9SKrishna Gudipati nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port); 830ba816ea8SJing Huang return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn)); 8317725ccfdSJing Huang } 8327725ccfdSJing Huang 8337725ccfdSJing Huang static ssize_t 8347725ccfdSJing Huang bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr, 8357725ccfdSJing Huang char *buf) 8367725ccfdSJing Huang { 8377725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 8387725ccfdSJing Huang struct bfad_im_port_s *im_port = 8397725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 8407725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 841a36c61f9SKrishna Gudipati struct bfa_lport_attr_s port_attr; 842a36c61f9SKrishna Gudipati char symname[BFA_SYMNAME_MAXLEN]; 8437725ccfdSJing Huang 844a36c61f9SKrishna Gudipati bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); 845a36c61f9SKrishna Gudipati strncpy(symname, port_attr.port_cfg.sym_name.symname, 846a36c61f9SKrishna Gudipati BFA_SYMNAME_MAXLEN); 847a36c61f9SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", symname); 8487725ccfdSJing Huang } 8497725ccfdSJing Huang 8507725ccfdSJing Huang static ssize_t 8517725ccfdSJing Huang bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr, 8527725ccfdSJing Huang char *buf) 8537725ccfdSJing Huang { 8547725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 8557725ccfdSJing Huang struct bfad_im_port_s *im_port = 8567725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 8577725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 8580a4b1fc0SKrishna Gudipati char hw_ver[BFA_VERSION_LEN]; 8597725ccfdSJing Huang 8600a4b1fc0SKrishna Gudipati bfa_get_pci_chip_rev(&bfad->bfa, hw_ver); 8610a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver); 8627725ccfdSJing Huang } 8637725ccfdSJing Huang 8647725ccfdSJing Huang static ssize_t 8657725ccfdSJing Huang bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr, 8667725ccfdSJing Huang char *buf) 8677725ccfdSJing Huang { 8687725ccfdSJing Huang return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION); 8697725ccfdSJing Huang } 8707725ccfdSJing Huang 8717725ccfdSJing Huang static ssize_t 8727725ccfdSJing Huang bfad_im_optionrom_version_show(struct device *dev, 8737725ccfdSJing Huang struct device_attribute *attr, char *buf) 8747725ccfdSJing Huang { 8757725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 8767725ccfdSJing Huang struct bfad_im_port_s *im_port = 8777725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 8787725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 8790a4b1fc0SKrishna Gudipati char optrom_ver[BFA_VERSION_LEN]; 8807725ccfdSJing Huang 8810a4b1fc0SKrishna Gudipati bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver); 8820a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver); 8837725ccfdSJing Huang } 8847725ccfdSJing Huang 8857725ccfdSJing Huang static ssize_t 8867725ccfdSJing Huang bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr, 8877725ccfdSJing Huang char *buf) 8887725ccfdSJing Huang { 8897725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 8907725ccfdSJing Huang struct bfad_im_port_s *im_port = 8917725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 8927725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 8930a4b1fc0SKrishna Gudipati char fw_ver[BFA_VERSION_LEN]; 8947725ccfdSJing Huang 8950a4b1fc0SKrishna Gudipati bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver); 8960a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver); 8977725ccfdSJing Huang } 8987725ccfdSJing Huang 8997725ccfdSJing Huang static ssize_t 9007725ccfdSJing Huang bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr, 9017725ccfdSJing Huang char *buf) 9027725ccfdSJing Huang { 9037725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 9047725ccfdSJing Huang struct bfad_im_port_s *im_port = 9057725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 9067725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 9077725ccfdSJing Huang 9080a4b1fc0SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "%d\n", 9090a4b1fc0SKrishna Gudipati bfa_get_nports(&bfad->bfa)); 9107725ccfdSJing Huang } 9117725ccfdSJing Huang 9127725ccfdSJing Huang static ssize_t 9137725ccfdSJing Huang bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr, 9147725ccfdSJing Huang char *buf) 9157725ccfdSJing Huang { 9167725ccfdSJing Huang return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME); 9177725ccfdSJing Huang } 9187725ccfdSJing Huang 9197725ccfdSJing Huang static ssize_t 9207725ccfdSJing Huang bfad_im_num_of_discovered_ports_show(struct device *dev, 9217725ccfdSJing Huang struct device_attribute *attr, char *buf) 9227725ccfdSJing Huang { 9237725ccfdSJing Huang struct Scsi_Host *shost = class_to_shost(dev); 9247725ccfdSJing Huang struct bfad_im_port_s *im_port = 9257725ccfdSJing Huang (struct bfad_im_port_s *) shost->hostdata[0]; 9267725ccfdSJing Huang struct bfad_port_s *port = im_port->port; 9277725ccfdSJing Huang struct bfad_s *bfad = im_port->bfad; 9287725ccfdSJing Huang int nrports = 2048; 929ee1a4a42SKrishna Gudipati struct bfa_rport_qualifier_s *rports = NULL; 9307725ccfdSJing Huang unsigned long flags; 9317725ccfdSJing Huang 932ee1a4a42SKrishna Gudipati rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports, 933ee1a4a42SKrishna Gudipati GFP_ATOMIC); 9347725ccfdSJing Huang if (rports == NULL) 935a36c61f9SKrishna Gudipati return snprintf(buf, PAGE_SIZE, "Failed\n"); 9367725ccfdSJing Huang 9377725ccfdSJing Huang spin_lock_irqsave(&bfad->bfad_lock, flags); 938ee1a4a42SKrishna Gudipati bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports); 9397725ccfdSJing Huang spin_unlock_irqrestore(&bfad->bfad_lock, flags); 9407725ccfdSJing Huang kfree(rports); 9417725ccfdSJing Huang 9427725ccfdSJing Huang return snprintf(buf, PAGE_SIZE, "%d\n", nrports); 9437725ccfdSJing Huang } 9447725ccfdSJing Huang 9457725ccfdSJing Huang static DEVICE_ATTR(serial_number, S_IRUGO, 9467725ccfdSJing Huang bfad_im_serial_num_show, NULL); 9477725ccfdSJing Huang static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL); 9487725ccfdSJing Huang static DEVICE_ATTR(model_description, S_IRUGO, 9497725ccfdSJing Huang bfad_im_model_desc_show, NULL); 9507725ccfdSJing Huang static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL); 9517725ccfdSJing Huang static DEVICE_ATTR(symbolic_name, S_IRUGO, 9527725ccfdSJing Huang bfad_im_symbolic_name_show, NULL); 9537725ccfdSJing Huang static DEVICE_ATTR(hardware_version, S_IRUGO, 9547725ccfdSJing Huang bfad_im_hw_version_show, NULL); 9557725ccfdSJing Huang static DEVICE_ATTR(driver_version, S_IRUGO, 9567725ccfdSJing Huang bfad_im_drv_version_show, NULL); 9577725ccfdSJing Huang static DEVICE_ATTR(option_rom_version, S_IRUGO, 9587725ccfdSJing Huang bfad_im_optionrom_version_show, NULL); 9597725ccfdSJing Huang static DEVICE_ATTR(firmware_version, S_IRUGO, 9607725ccfdSJing Huang bfad_im_fw_version_show, NULL); 9617725ccfdSJing Huang static DEVICE_ATTR(number_of_ports, S_IRUGO, 9627725ccfdSJing Huang bfad_im_num_of_ports_show, NULL); 9637725ccfdSJing Huang static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL); 9647725ccfdSJing Huang static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO, 9657725ccfdSJing Huang bfad_im_num_of_discovered_ports_show, NULL); 9667725ccfdSJing Huang 9677725ccfdSJing Huang struct device_attribute *bfad_im_host_attrs[] = { 9687725ccfdSJing Huang &dev_attr_serial_number, 9697725ccfdSJing Huang &dev_attr_model, 9707725ccfdSJing Huang &dev_attr_model_description, 9717725ccfdSJing Huang &dev_attr_node_name, 9727725ccfdSJing Huang &dev_attr_symbolic_name, 9737725ccfdSJing Huang &dev_attr_hardware_version, 9747725ccfdSJing Huang &dev_attr_driver_version, 9757725ccfdSJing Huang &dev_attr_option_rom_version, 9767725ccfdSJing Huang &dev_attr_firmware_version, 9777725ccfdSJing Huang &dev_attr_number_of_ports, 9787725ccfdSJing Huang &dev_attr_driver_name, 9797725ccfdSJing Huang &dev_attr_number_of_discovered_ports, 9807725ccfdSJing Huang NULL, 9817725ccfdSJing Huang }; 9827725ccfdSJing Huang 9837725ccfdSJing Huang struct device_attribute *bfad_im_vport_attrs[] = { 9847725ccfdSJing Huang &dev_attr_serial_number, 9857725ccfdSJing Huang &dev_attr_model, 9867725ccfdSJing Huang &dev_attr_model_description, 9877725ccfdSJing Huang &dev_attr_node_name, 9887725ccfdSJing Huang &dev_attr_symbolic_name, 9897725ccfdSJing Huang &dev_attr_hardware_version, 9907725ccfdSJing Huang &dev_attr_driver_version, 9917725ccfdSJing Huang &dev_attr_option_rom_version, 9927725ccfdSJing Huang &dev_attr_firmware_version, 9937725ccfdSJing Huang &dev_attr_number_of_ports, 9947725ccfdSJing Huang &dev_attr_driver_name, 9957725ccfdSJing Huang &dev_attr_number_of_discovered_ports, 9967725ccfdSJing Huang NULL, 9977725ccfdSJing Huang }; 9987725ccfdSJing Huang 9997725ccfdSJing Huang 1000