1 /******************************************************************* 2 * This file is part of the Emulex Linux Device Driver for * 3 * Fibre Channel Host Bus Adapters. * 4 * Copyright (C) 2004-2005 Emulex. All rights reserved. * 5 * EMULEX and SLI are trademarks of Emulex. * 6 * www.emulex.com * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 8 * * 9 * This program is free software; you can redistribute it and/or * 10 * modify it under the terms of version 2 of the GNU General * 11 * Public License as published by the Free Software Foundation. * 12 * This program is distributed in the hope that it will be useful. * 13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 17 * TO BE LEGALLY INVALID. See the GNU General Public License for * 18 * more details, a copy of which can be found in the file COPYING * 19 * included with this package. * 20 *******************************************************************/ 21 22 #include <linux/ctype.h> 23 #include <linux/pci.h> 24 #include <linux/interrupt.h> 25 26 #include <scsi/scsi.h> 27 #include <scsi/scsi_device.h> 28 #include <scsi/scsi_host.h> 29 #include <scsi/scsi_tcq.h> 30 #include <scsi/scsi_transport_fc.h> 31 32 #include "lpfc_hw.h" 33 #include "lpfc_sli.h" 34 #include "lpfc_disc.h" 35 #include "lpfc_scsi.h" 36 #include "lpfc.h" 37 #include "lpfc_logmsg.h" 38 #include "lpfc_version.h" 39 #include "lpfc_compat.h" 40 #include "lpfc_crtn.h" 41 42 43 static void 44 lpfc_jedec_to_ascii(int incr, char hdw[]) 45 { 46 int i, j; 47 for (i = 0; i < 8; i++) { 48 j = (incr & 0xf); 49 if (j <= 9) 50 hdw[7 - i] = 0x30 + j; 51 else 52 hdw[7 - i] = 0x61 + j - 10; 53 incr = (incr >> 4); 54 } 55 hdw[8] = 0; 56 return; 57 } 58 59 static ssize_t 60 lpfc_drvr_version_show(struct class_device *cdev, char *buf) 61 { 62 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); 63 } 64 65 static ssize_t 66 management_version_show(struct class_device *cdev, char *buf) 67 { 68 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n"); 69 } 70 71 static ssize_t 72 lpfc_info_show(struct class_device *cdev, char *buf) 73 { 74 struct Scsi_Host *host = class_to_shost(cdev); 75 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 76 } 77 78 static ssize_t 79 lpfc_serialnum_show(struct class_device *cdev, char *buf) 80 { 81 struct Scsi_Host *host = class_to_shost(cdev); 82 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 83 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 84 } 85 86 static ssize_t 87 lpfc_modeldesc_show(struct class_device *cdev, char *buf) 88 { 89 struct Scsi_Host *host = class_to_shost(cdev); 90 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 91 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 92 } 93 94 static ssize_t 95 lpfc_modelname_show(struct class_device *cdev, char *buf) 96 { 97 struct Scsi_Host *host = class_to_shost(cdev); 98 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 99 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 100 } 101 102 static ssize_t 103 lpfc_programtype_show(struct class_device *cdev, char *buf) 104 { 105 struct Scsi_Host *host = class_to_shost(cdev); 106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 107 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 108 } 109 110 static ssize_t 111 lpfc_portnum_show(struct class_device *cdev, char *buf) 112 { 113 struct Scsi_Host *host = class_to_shost(cdev); 114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 115 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 116 } 117 118 static ssize_t 119 lpfc_fwrev_show(struct class_device *cdev, char *buf) 120 { 121 struct Scsi_Host *host = class_to_shost(cdev); 122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 123 char fwrev[32]; 124 lpfc_decode_firmware_rev(phba, fwrev, 1); 125 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev); 126 } 127 128 static ssize_t 129 lpfc_hdw_show(struct class_device *cdev, char *buf) 130 { 131 char hdw[9]; 132 struct Scsi_Host *host = class_to_shost(cdev); 133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 134 lpfc_vpd_t *vp = &phba->vpd; 135 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 136 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 137 } 138 static ssize_t 139 lpfc_option_rom_version_show(struct class_device *cdev, char *buf) 140 { 141 struct Scsi_Host *host = class_to_shost(cdev); 142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 143 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 144 } 145 static ssize_t 146 lpfc_state_show(struct class_device *cdev, char *buf) 147 { 148 struct Scsi_Host *host = class_to_shost(cdev); 149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 150 int len = 0; 151 switch (phba->hba_state) { 152 case LPFC_INIT_START: 153 case LPFC_INIT_MBX_CMDS: 154 case LPFC_LINK_DOWN: 155 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); 156 break; 157 case LPFC_LINK_UP: 158 case LPFC_LOCAL_CFG_LINK: 159 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n"); 160 break; 161 case LPFC_FLOGI: 162 case LPFC_FABRIC_CFG_LINK: 163 case LPFC_NS_REG: 164 case LPFC_NS_QRY: 165 case LPFC_BUILD_DISC_LIST: 166 case LPFC_DISC_AUTH: 167 case LPFC_CLEAR_LA: 168 len += snprintf(buf + len, PAGE_SIZE-len, 169 "Link Up - Discovery\n"); 170 break; 171 case LPFC_HBA_READY: 172 len += snprintf(buf + len, PAGE_SIZE-len, 173 "Link Up - Ready:\n"); 174 if (phba->fc_topology == TOPOLOGY_LOOP) { 175 if (phba->fc_flag & FC_PUBLIC_LOOP) 176 len += snprintf(buf + len, PAGE_SIZE-len, 177 " Public Loop\n"); 178 else 179 len += snprintf(buf + len, PAGE_SIZE-len, 180 " Private Loop\n"); 181 } else { 182 if (phba->fc_flag & FC_FABRIC) 183 len += snprintf(buf + len, PAGE_SIZE-len, 184 " Fabric\n"); 185 else 186 len += snprintf(buf + len, PAGE_SIZE-len, 187 " Point-2-Point\n"); 188 } 189 } 190 return len; 191 } 192 193 static ssize_t 194 lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) 195 { 196 struct Scsi_Host *host = class_to_shost(cdev); 197 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 198 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt + 199 phba->fc_unmap_cnt); 200 } 201 202 203 static int 204 lpfc_issue_lip(struct Scsi_Host *host) 205 { 206 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0]; 207 LPFC_MBOXQ_t *pmboxq; 208 int mbxstatus = MBXERR_ERROR; 209 210 if ((phba->fc_flag & FC_OFFLINE_MODE) || 211 (phba->hba_state != LPFC_HBA_READY)) 212 return -EPERM; 213 214 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 215 216 if (!pmboxq) 217 return -ENOMEM; 218 219 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 220 lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed); 221 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 222 223 if (mbxstatus == MBX_TIMEOUT) 224 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 225 else 226 mempool_free(pmboxq, phba->mbox_mem_pool); 227 228 if (mbxstatus == MBXERR_ERROR) 229 return -EIO; 230 231 return 0; 232 } 233 234 static ssize_t 235 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) 236 { 237 struct Scsi_Host *host = class_to_shost(cdev); 238 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 239 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 240 } 241 242 static ssize_t 243 lpfc_board_online_show(struct class_device *cdev, char *buf) 244 { 245 struct Scsi_Host *host = class_to_shost(cdev); 246 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 247 248 if (phba->fc_flag & FC_OFFLINE_MODE) 249 return snprintf(buf, PAGE_SIZE, "0\n"); 250 else 251 return snprintf(buf, PAGE_SIZE, "1\n"); 252 } 253 254 static ssize_t 255 lpfc_board_online_store(struct class_device *cdev, const char *buf, 256 size_t count) 257 { 258 struct Scsi_Host *host = class_to_shost(cdev); 259 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 260 struct completion online_compl; 261 int val=0, status=0; 262 263 if (sscanf(buf, "%d", &val) != 1) 264 return -EINVAL; 265 266 init_completion(&online_compl); 267 268 if (val) 269 lpfc_workq_post_event(phba, &status, &online_compl, 270 LPFC_EVT_ONLINE); 271 else 272 lpfc_workq_post_event(phba, &status, &online_compl, 273 LPFC_EVT_OFFLINE); 274 wait_for_completion(&online_compl); 275 if (!status) 276 return strlen(buf); 277 else 278 return -EIO; 279 } 280 281 282 #define lpfc_param_show(attr) \ 283 static ssize_t \ 284 lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 285 { \ 286 struct Scsi_Host *host = class_to_shost(cdev);\ 287 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\ 288 int val = 0;\ 289 val = phba->cfg_##attr;\ 290 return snprintf(buf, PAGE_SIZE, "%d\n",\ 291 phba->cfg_##attr);\ 292 } 293 294 #define lpfc_param_hex_show(attr) \ 295 static ssize_t \ 296 lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 297 { \ 298 struct Scsi_Host *host = class_to_shost(cdev);\ 299 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\ 300 int val = 0;\ 301 val = phba->cfg_##attr;\ 302 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 303 phba->cfg_##attr);\ 304 } 305 306 #define lpfc_param_init(attr, default, minval, maxval) \ 307 static int \ 308 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ 309 { \ 310 if (val >= minval && val <= maxval) {\ 311 phba->cfg_##attr = val;\ 312 return 0;\ 313 }\ 314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 315 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\ 316 "allowed range is ["#minval", "#maxval"]\n", \ 317 phba->brd_no, val); \ 318 phba->cfg_##attr = default;\ 319 return -EINVAL;\ 320 } 321 322 #define lpfc_param_set(attr, default, minval, maxval) \ 323 static int \ 324 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ 325 { \ 326 if (val >= minval && val <= maxval) {\ 327 phba->cfg_##attr = val;\ 328 return 0;\ 329 }\ 330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ 331 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\ 332 "allowed range is ["#minval", "#maxval"]\n", \ 333 phba->brd_no, val); \ 334 return -EINVAL;\ 335 } 336 337 #define lpfc_param_store(attr) \ 338 static ssize_t \ 339 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ 340 { \ 341 struct Scsi_Host *host = class_to_shost(cdev);\ 342 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\ 343 int val=0;\ 344 if (!isdigit(buf[0]))\ 345 return -EINVAL;\ 346 if (sscanf(buf, "%i", &val) != 1)\ 347 return -EINVAL;\ 348 if (lpfc_##attr##_set(phba, val) == 0) \ 349 return strlen(buf);\ 350 else \ 351 return -EINVAL;\ 352 } 353 354 #define LPFC_ATTR(name, defval, minval, maxval, desc) \ 355 static int lpfc_##name = defval;\ 356 module_param(lpfc_##name, int, 0);\ 357 MODULE_PARM_DESC(lpfc_##name, desc);\ 358 lpfc_param_init(name, defval, minval, maxval) 359 360 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ 361 static int lpfc_##name = defval;\ 362 module_param(lpfc_##name, int, 0);\ 363 MODULE_PARM_DESC(lpfc_##name, desc);\ 364 lpfc_param_show(name)\ 365 lpfc_param_init(name, defval, minval, maxval)\ 366 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 367 368 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ 369 static int lpfc_##name = defval;\ 370 module_param(lpfc_##name, int, 0);\ 371 MODULE_PARM_DESC(lpfc_##name, desc);\ 372 lpfc_param_show(name)\ 373 lpfc_param_init(name, defval, minval, maxval)\ 374 lpfc_param_set(name, defval, minval, maxval)\ 375 lpfc_param_store(name)\ 376 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 377 lpfc_##name##_show, lpfc_##name##_store) 378 379 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 380 static int lpfc_##name = defval;\ 381 module_param(lpfc_##name, int, 0);\ 382 MODULE_PARM_DESC(lpfc_##name, desc);\ 383 lpfc_param_hex_show(name)\ 384 lpfc_param_init(name, defval, minval, maxval)\ 385 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 386 387 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 388 static int lpfc_##name = defval;\ 389 module_param(lpfc_##name, int, 0);\ 390 MODULE_PARM_DESC(lpfc_##name, desc);\ 391 lpfc_param_hex_show(name)\ 392 lpfc_param_init(name, defval, minval, maxval)\ 393 lpfc_param_set(name, defval, minval, maxval)\ 394 lpfc_param_store(name)\ 395 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ 396 lpfc_##name##_show, lpfc_##name##_store) 397 398 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); 399 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); 400 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); 401 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); 402 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); 403 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL); 404 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 405 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 406 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); 407 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO, 408 lpfc_option_rom_version_show, NULL); 409 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO, 410 lpfc_num_discovered_ports_show, NULL); 411 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); 412 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, 413 NULL); 414 static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show, 415 NULL); 416 static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR, 417 lpfc_board_online_show, lpfc_board_online_store); 418 419 420 /* 421 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being 422 # deluged with LOTS of information. 423 # You can set a bit mask to record specific types of verbose messages: 424 # 425 # LOG_ELS 0x1 ELS events 426 # LOG_DISCOVERY 0x2 Link discovery events 427 # LOG_MBOX 0x4 Mailbox events 428 # LOG_INIT 0x8 Initialization events 429 # LOG_LINK_EVENT 0x10 Link events 430 # LOG_IP 0x20 IP traffic history 431 # LOG_FCP 0x40 FCP traffic history 432 # LOG_NODE 0x80 Node table events 433 # LOG_MISC 0x400 Miscellaneous events 434 # LOG_SLI 0x800 SLI events 435 # LOG_CHK_COND 0x1000 FCP Check condition flag 436 # LOG_LIBDFC 0x2000 LIBDFC events 437 # LOG_ALL_MSG 0xffff LOG all messages 438 */ 439 LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask"); 440 441 /* 442 # lun_queue_depth: This parameter is used to limit the number of outstanding 443 # commands per FCP LUN. Value range is [1,128]. Default value is 30. 444 */ 445 LPFC_ATTR_R(lun_queue_depth, 30, 1, 128, 446 "Max number of FCP commands we can queue to a specific LUN"); 447 448 /* 449 # Some disk devices have a "select ID" or "select Target" capability. 450 # From a protocol standpoint "select ID" usually means select the 451 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative 452 # annex" which contains a table that maps a "select ID" (a number 453 # between 0 and 7F) to an ALPA. By default, for compatibility with 454 # older drivers, the lpfc driver scans this table from low ALPA to high 455 # ALPA. 456 # 457 # Turning on the scan-down variable (on = 1, off = 0) will 458 # cause the lpfc driver to use an inverted table, effectively 459 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. 460 # 461 # (Note: This "select ID" functionality is a LOOP ONLY characteristic 462 # and will not work across a fabric. Also this parameter will take 463 # effect only in the case when ALPA map is not available.) 464 */ 465 LPFC_ATTR_R(scan_down, 1, 0, 1, 466 "Start scanning for devices from highest ALPA to lowest"); 467 468 /* 469 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear 470 # until the timer expires. Value range is [0,255]. Default value is 30. 471 # NOTE: this MUST be less then the SCSI Layer command timeout - 1. 472 */ 473 LPFC_ATTR_RW(nodev_tmo, 30, 0, 255, 474 "Seconds driver will hold I/O waiting for a device to come back"); 475 476 /* 477 # lpfc_topology: link topology for init link 478 # 0x0 = attempt loop mode then point-to-point 479 # 0x02 = attempt point-to-point mode only 480 # 0x04 = attempt loop mode only 481 # 0x06 = attempt point-to-point mode then loop 482 # Set point-to-point mode if you want to run as an N_Port. 483 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. 484 # Default value is 0. 485 */ 486 LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology"); 487 488 /* 489 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel 490 # connection. 491 # 0 = auto select (default) 492 # 1 = 1 Gigabaud 493 # 2 = 2 Gigabaud 494 # 4 = 4 Gigabaud 495 # Value range is [0,4]. Default value is 0. 496 */ 497 LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed"); 498 499 /* 500 # lpfc_fcp_class: Determines FC class to use for the FCP protocol. 501 # Value range is [2,3]. Default value is 3. 502 */ 503 LPFC_ATTR_R(fcp_class, 3, 2, 3, 504 "Select Fibre Channel class of service for FCP sequences"); 505 506 /* 507 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range 508 # is [0,1]. Default value is 0. 509 */ 510 LPFC_ATTR_RW(use_adisc, 0, 0, 1, 511 "Use ADISC on rediscovery to authenticate FCP devices"); 512 513 /* 514 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value 515 # range is [0,1]. Default value is 0. 516 */ 517 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); 518 519 /* 520 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing 521 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take 522 # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay 523 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if 524 # cr_delay is set to 0. 525 */ 526 LPFC_ATTR(cr_delay, 0, 0, 63, "A count of milliseconds after which an" 527 "interrupt response is generated"); 528 529 LPFC_ATTR(cr_count, 1, 1, 255, "A count of I/O completions after which an" 530 "interrupt response is generated"); 531 532 /* 533 # lpfc_fdmi_on: controls FDMI support. 534 # 0 = no FDMI support 535 # 1 = support FDMI without attribute of hostname 536 # 2 = support FDMI with attribute of hostname 537 # Value range [0,2]. Default value is 0. 538 */ 539 LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); 540 541 /* 542 # Specifies the maximum number of ELS cmds we can have outstanding (for 543 # discovery). Value range is [1,64]. Default value = 32. 544 */ 545 LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands" 546 "during discovery"); 547 548 /* 549 # lpfc_max_luns: maximum number of LUNs per target driver will support 550 # Value range is [1,32768]. Default value is 256. 551 # NOTE: The SCSI layer will scan each target for this many luns 552 */ 553 LPFC_ATTR_R(max_luns, 256, 1, 32768, 554 "Maximum number of LUNs per target driver will support"); 555 556 struct class_device_attribute *lpfc_host_attrs[] = { 557 &class_device_attr_info, 558 &class_device_attr_serialnum, 559 &class_device_attr_modeldesc, 560 &class_device_attr_modelname, 561 &class_device_attr_programtype, 562 &class_device_attr_portnum, 563 &class_device_attr_fwrev, 564 &class_device_attr_hdw, 565 &class_device_attr_option_rom_version, 566 &class_device_attr_state, 567 &class_device_attr_num_discovered_ports, 568 &class_device_attr_lpfc_drvr_version, 569 &class_device_attr_lpfc_log_verbose, 570 &class_device_attr_lpfc_lun_queue_depth, 571 &class_device_attr_lpfc_nodev_tmo, 572 &class_device_attr_lpfc_fcp_class, 573 &class_device_attr_lpfc_use_adisc, 574 &class_device_attr_lpfc_ack0, 575 &class_device_attr_lpfc_topology, 576 &class_device_attr_lpfc_scan_down, 577 &class_device_attr_lpfc_link_speed, 578 &class_device_attr_lpfc_fdmi_on, 579 &class_device_attr_lpfc_max_luns, 580 &class_device_attr_nport_evt_cnt, 581 &class_device_attr_management_version, 582 &class_device_attr_board_online, 583 NULL, 584 }; 585 586 static ssize_t 587 sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 588 { 589 size_t buf_off; 590 struct Scsi_Host *host = class_to_shost(container_of(kobj, 591 struct class_device, kobj)); 592 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 593 594 if ((off + count) > FF_REG_AREA_SIZE) 595 return -ERANGE; 596 597 if (count == 0) return 0; 598 599 if (off % 4 || count % 4 || (unsigned long)buf % 4) 600 return -EINVAL; 601 602 spin_lock_irq(phba->host->host_lock); 603 604 if (!(phba->fc_flag & FC_OFFLINE_MODE)) { 605 spin_unlock_irq(phba->host->host_lock); 606 return -EPERM; 607 } 608 609 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) 610 writel(*((uint32_t *)(buf + buf_off)), 611 phba->ctrl_regs_memmap_p + off + buf_off); 612 613 spin_unlock_irq(phba->host->host_lock); 614 615 return count; 616 } 617 618 static ssize_t 619 sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 620 { 621 size_t buf_off; 622 uint32_t * tmp_ptr; 623 struct Scsi_Host *host = class_to_shost(container_of(kobj, 624 struct class_device, kobj)); 625 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 626 627 if (off > FF_REG_AREA_SIZE) 628 return -ERANGE; 629 630 if ((off + count) > FF_REG_AREA_SIZE) 631 count = FF_REG_AREA_SIZE - off; 632 633 if (count == 0) return 0; 634 635 if (off % 4 || count % 4 || (unsigned long)buf % 4) 636 return -EINVAL; 637 638 spin_lock_irq(phba->host->host_lock); 639 640 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { 641 tmp_ptr = (uint32_t *)(buf + buf_off); 642 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); 643 } 644 645 spin_unlock_irq(phba->host->host_lock); 646 647 return count; 648 } 649 650 static struct bin_attribute sysfs_ctlreg_attr = { 651 .attr = { 652 .name = "ctlreg", 653 .mode = S_IRUSR | S_IWUSR, 654 .owner = THIS_MODULE, 655 }, 656 .size = 256, 657 .read = sysfs_ctlreg_read, 658 .write = sysfs_ctlreg_write, 659 }; 660 661 662 static void 663 sysfs_mbox_idle (struct lpfc_hba * phba) 664 { 665 phba->sysfs_mbox.state = SMBOX_IDLE; 666 phba->sysfs_mbox.offset = 0; 667 668 if (phba->sysfs_mbox.mbox) { 669 mempool_free(phba->sysfs_mbox.mbox, 670 phba->mbox_mem_pool); 671 phba->sysfs_mbox.mbox = NULL; 672 } 673 } 674 675 static ssize_t 676 sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 677 { 678 struct Scsi_Host * host = 679 class_to_shost(container_of(kobj, struct class_device, kobj)); 680 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0]; 681 struct lpfcMboxq * mbox = NULL; 682 683 if ((count + off) > MAILBOX_CMD_SIZE) 684 return -ERANGE; 685 686 if (off % 4 || count % 4 || (unsigned long)buf % 4) 687 return -EINVAL; 688 689 if (count == 0) 690 return 0; 691 692 if (off == 0) { 693 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 694 if (!mbox) 695 return -ENOMEM; 696 697 } 698 699 spin_lock_irq(host->host_lock); 700 701 if (off == 0) { 702 if (phba->sysfs_mbox.mbox) 703 mempool_free(mbox, phba->mbox_mem_pool); 704 else 705 phba->sysfs_mbox.mbox = mbox; 706 phba->sysfs_mbox.state = SMBOX_WRITING; 707 } else { 708 if (phba->sysfs_mbox.state != SMBOX_WRITING || 709 phba->sysfs_mbox.offset != off || 710 phba->sysfs_mbox.mbox == NULL ) { 711 sysfs_mbox_idle(phba); 712 spin_unlock_irq(host->host_lock); 713 return -EINVAL; 714 } 715 } 716 717 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, 718 buf, count); 719 720 phba->sysfs_mbox.offset = off + count; 721 722 spin_unlock_irq(host->host_lock); 723 724 return count; 725 } 726 727 static ssize_t 728 sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 729 { 730 struct Scsi_Host *host = 731 class_to_shost(container_of(kobj, struct class_device, 732 kobj)); 733 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; 734 int rc; 735 736 if (off > sizeof(MAILBOX_t)) 737 return -ERANGE; 738 739 if ((count + off) > sizeof(MAILBOX_t)) 740 count = sizeof(MAILBOX_t) - off; 741 742 if (off % 4 || count % 4 || (unsigned long)buf % 4) 743 return -EINVAL; 744 745 if (off && count == 0) 746 return 0; 747 748 spin_lock_irq(phba->host->host_lock); 749 750 if (off == 0 && 751 phba->sysfs_mbox.state == SMBOX_WRITING && 752 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { 753 754 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { 755 /* Offline only */ 756 case MBX_WRITE_NV: 757 case MBX_INIT_LINK: 758 case MBX_DOWN_LINK: 759 case MBX_CONFIG_LINK: 760 case MBX_CONFIG_RING: 761 case MBX_RESET_RING: 762 case MBX_UNREG_LOGIN: 763 case MBX_CLEAR_LA: 764 case MBX_DUMP_CONTEXT: 765 case MBX_RUN_DIAGS: 766 case MBX_RESTART: 767 case MBX_FLASH_WR_ULA: 768 case MBX_SET_MASK: 769 case MBX_SET_SLIM: 770 case MBX_SET_DEBUG: 771 if (!(phba->fc_flag & FC_OFFLINE_MODE)) { 772 printk(KERN_WARNING "mbox_read:Command 0x%x " 773 "is illegal in on-line state\n", 774 phba->sysfs_mbox.mbox->mb.mbxCommand); 775 sysfs_mbox_idle(phba); 776 spin_unlock_irq(phba->host->host_lock); 777 return -EPERM; 778 } 779 case MBX_LOAD_SM: 780 case MBX_READ_NV: 781 case MBX_READ_CONFIG: 782 case MBX_READ_RCONFIG: 783 case MBX_READ_STATUS: 784 case MBX_READ_XRI: 785 case MBX_READ_REV: 786 case MBX_READ_LNK_STAT: 787 case MBX_DUMP_MEMORY: 788 case MBX_DOWN_LOAD: 789 case MBX_UPDATE_CFG: 790 case MBX_LOAD_AREA: 791 case MBX_LOAD_EXP_ROM: 792 break; 793 case MBX_READ_SPARM64: 794 case MBX_READ_LA: 795 case MBX_READ_LA64: 796 case MBX_REG_LOGIN: 797 case MBX_REG_LOGIN64: 798 case MBX_CONFIG_PORT: 799 case MBX_RUN_BIU_DIAG: 800 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", 801 phba->sysfs_mbox.mbox->mb.mbxCommand); 802 sysfs_mbox_idle(phba); 803 spin_unlock_irq(phba->host->host_lock); 804 return -EPERM; 805 default: 806 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", 807 phba->sysfs_mbox.mbox->mb.mbxCommand); 808 sysfs_mbox_idle(phba); 809 spin_unlock_irq(phba->host->host_lock); 810 return -EPERM; 811 } 812 813 if ((phba->fc_flag & FC_OFFLINE_MODE) || 814 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ 815 816 spin_unlock_irq(phba->host->host_lock); 817 rc = lpfc_sli_issue_mbox (phba, 818 phba->sysfs_mbox.mbox, 819 MBX_POLL); 820 spin_lock_irq(phba->host->host_lock); 821 822 } else { 823 spin_unlock_irq(phba->host->host_lock); 824 rc = lpfc_sli_issue_mbox_wait (phba, 825 phba->sysfs_mbox.mbox, 826 phba->fc_ratov * 2); 827 spin_lock_irq(phba->host->host_lock); 828 } 829 830 if (rc != MBX_SUCCESS) { 831 sysfs_mbox_idle(phba); 832 spin_unlock_irq(host->host_lock); 833 return -ENODEV; 834 } 835 phba->sysfs_mbox.state = SMBOX_READING; 836 } 837 else if (phba->sysfs_mbox.offset != off || 838 phba->sysfs_mbox.state != SMBOX_READING) { 839 printk(KERN_WARNING "mbox_read: Bad State\n"); 840 sysfs_mbox_idle(phba); 841 spin_unlock_irq(host->host_lock); 842 return -EINVAL; 843 } 844 845 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); 846 847 phba->sysfs_mbox.offset = off + count; 848 849 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t)) 850 sysfs_mbox_idle(phba); 851 852 spin_unlock_irq(phba->host->host_lock); 853 854 return count; 855 } 856 857 static struct bin_attribute sysfs_mbox_attr = { 858 .attr = { 859 .name = "mbox", 860 .mode = S_IRUSR | S_IWUSR, 861 .owner = THIS_MODULE, 862 }, 863 .size = sizeof(MAILBOX_t), 864 .read = sysfs_mbox_read, 865 .write = sysfs_mbox_write, 866 }; 867 868 int 869 lpfc_alloc_sysfs_attr(struct lpfc_hba *phba) 870 { 871 struct Scsi_Host *host = phba->host; 872 int error; 873 874 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 875 &sysfs_ctlreg_attr); 876 if (error) 877 goto out; 878 879 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 880 &sysfs_mbox_attr); 881 if (error) 882 goto out_remove_ctlreg_attr; 883 884 return 0; 885 out_remove_ctlreg_attr: 886 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 887 out: 888 return error; 889 } 890 891 void 892 lpfc_free_sysfs_attr(struct lpfc_hba *phba) 893 { 894 struct Scsi_Host *host = phba->host; 895 896 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr); 897 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 898 } 899 900 901 /* 902 * Dynamic FC Host Attributes Support 903 */ 904 905 static void 906 lpfc_get_host_port_id(struct Scsi_Host *shost) 907 { 908 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; 909 /* note: fc_myDID already in cpu endianness */ 910 fc_host_port_id(shost) = phba->fc_myDID; 911 } 912 913 static void 914 lpfc_get_host_port_type(struct Scsi_Host *shost) 915 { 916 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; 917 918 spin_lock_irq(shost->host_lock); 919 920 if (phba->hba_state == LPFC_HBA_READY) { 921 if (phba->fc_topology == TOPOLOGY_LOOP) { 922 if (phba->fc_flag & FC_PUBLIC_LOOP) 923 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 924 else 925 fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 926 } else { 927 if (phba->fc_flag & FC_FABRIC) 928 fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 929 else 930 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 931 } 932 } else 933 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 934 935 spin_unlock_irq(shost->host_lock); 936 } 937 938 static void 939 lpfc_get_host_port_state(struct Scsi_Host *shost) 940 { 941 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; 942 943 spin_lock_irq(shost->host_lock); 944 945 if (phba->fc_flag & FC_OFFLINE_MODE) 946 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 947 else { 948 switch (phba->hba_state) { 949 case LPFC_INIT_START: 950 case LPFC_INIT_MBX_CMDS: 951 case LPFC_LINK_DOWN: 952 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 953 break; 954 case LPFC_LINK_UP: 955 case LPFC_LOCAL_CFG_LINK: 956 case LPFC_FLOGI: 957 case LPFC_FABRIC_CFG_LINK: 958 case LPFC_NS_REG: 959 case LPFC_NS_QRY: 960 case LPFC_BUILD_DISC_LIST: 961 case LPFC_DISC_AUTH: 962 case LPFC_CLEAR_LA: 963 case LPFC_HBA_READY: 964 /* Links up, beyond this port_type reports state */ 965 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 966 break; 967 case LPFC_HBA_ERROR: 968 fc_host_port_state(shost) = FC_PORTSTATE_ERROR; 969 break; 970 default: 971 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 972 break; 973 } 974 } 975 976 spin_unlock_irq(shost->host_lock); 977 } 978 979 static void 980 lpfc_get_host_speed(struct Scsi_Host *shost) 981 { 982 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; 983 984 spin_lock_irq(shost->host_lock); 985 986 if (phba->hba_state == LPFC_HBA_READY) { 987 switch(phba->fc_linkspeed) { 988 case LA_1GHZ_LINK: 989 fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 990 break; 991 case LA_2GHZ_LINK: 992 fc_host_speed(shost) = FC_PORTSPEED_2GBIT; 993 break; 994 case LA_4GHZ_LINK: 995 fc_host_speed(shost) = FC_PORTSPEED_4GBIT; 996 break; 997 default: 998 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 999 break; 1000 } 1001 } 1002 1003 spin_unlock_irq(shost->host_lock); 1004 } 1005 1006 static void 1007 lpfc_get_host_fabric_name (struct Scsi_Host *shost) 1008 { 1009 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; 1010 u64 node_name; 1011 1012 spin_lock_irq(shost->host_lock); 1013 1014 if ((phba->fc_flag & FC_FABRIC) || 1015 ((phba->fc_topology == TOPOLOGY_LOOP) && 1016 (phba->fc_flag & FC_PUBLIC_LOOP))) 1017 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); 1018 else 1019 /* fabric is local port if there is no F/FL_Port */ 1020 node_name = wwn_to_u64(phba->fc_nodename.u.wwn); 1021 1022 spin_unlock_irq(shost->host_lock); 1023 1024 fc_host_fabric_name(shost) = node_name; 1025 } 1026 1027 1028 static struct fc_host_statistics * 1029 lpfc_get_stats(struct Scsi_Host *shost) 1030 { 1031 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0]; 1032 struct lpfc_sli *psli = &phba->sli; 1033 struct fc_host_statistics *hs = &phba->link_stats; 1034 LPFC_MBOXQ_t *pmboxq; 1035 MAILBOX_t *pmb; 1036 int rc = 0; 1037 1038 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1039 if (!pmboxq) 1040 return NULL; 1041 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 1042 1043 pmb = &pmboxq->mb; 1044 pmb->mbxCommand = MBX_READ_STATUS; 1045 pmb->mbxOwner = OWN_HOST; 1046 pmboxq->context1 = NULL; 1047 1048 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1049 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1050 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1051 else 1052 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 1053 1054 if (rc != MBX_SUCCESS) { 1055 if (rc == MBX_TIMEOUT) 1056 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1057 else 1058 mempool_free(pmboxq, phba->mbox_mem_pool); 1059 return NULL; 1060 } 1061 1062 memset(hs, 0, sizeof (struct fc_host_statistics)); 1063 1064 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; 1065 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); 1066 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; 1067 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); 1068 1069 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); 1070 pmb->mbxCommand = MBX_READ_LNK_STAT; 1071 pmb->mbxOwner = OWN_HOST; 1072 pmboxq->context1 = NULL; 1073 1074 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1075 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1076 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1077 else 1078 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 1079 1080 if (rc != MBX_SUCCESS) { 1081 if (rc == MBX_TIMEOUT) 1082 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1083 else 1084 mempool_free( pmboxq, phba->mbox_mem_pool); 1085 return NULL; 1086 } 1087 1088 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; 1089 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; 1090 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; 1091 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; 1092 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; 1093 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; 1094 hs->error_frames = pmb->un.varRdLnk.crcCnt; 1095 1096 if (phba->fc_topology == TOPOLOGY_LOOP) { 1097 hs->lip_count = (phba->fc_eventTag >> 1); 1098 hs->nos_count = -1; 1099 } else { 1100 hs->lip_count = -1; 1101 hs->nos_count = (phba->fc_eventTag >> 1); 1102 } 1103 1104 hs->dumped_frames = -1; 1105 1106 /* FIX ME */ 1107 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/ 1108 1109 return hs; 1110 } 1111 1112 1113 /* 1114 * The LPFC driver treats linkdown handling as target loss events so there 1115 * are no sysfs handlers for link_down_tmo. 1116 */ 1117 static void 1118 lpfc_get_starget_port_id(struct scsi_target *starget) 1119 { 1120 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1121 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; 1122 uint32_t did = -1; 1123 struct lpfc_nodelist *ndlp = NULL; 1124 1125 spin_lock_irq(shost->host_lock); 1126 /* Search the mapped list for this target ID */ 1127 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1128 if (starget->id == ndlp->nlp_sid) { 1129 did = ndlp->nlp_DID; 1130 break; 1131 } 1132 } 1133 spin_unlock_irq(shost->host_lock); 1134 1135 fc_starget_port_id(starget) = did; 1136 } 1137 1138 static void 1139 lpfc_get_starget_node_name(struct scsi_target *starget) 1140 { 1141 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1142 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; 1143 u64 node_name = 0; 1144 struct lpfc_nodelist *ndlp = NULL; 1145 1146 spin_lock_irq(shost->host_lock); 1147 /* Search the mapped list for this target ID */ 1148 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1149 if (starget->id == ndlp->nlp_sid) { 1150 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); 1151 break; 1152 } 1153 } 1154 spin_unlock_irq(shost->host_lock); 1155 1156 fc_starget_node_name(starget) = node_name; 1157 } 1158 1159 static void 1160 lpfc_get_starget_port_name(struct scsi_target *starget) 1161 { 1162 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1163 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; 1164 u64 port_name = 0; 1165 struct lpfc_nodelist *ndlp = NULL; 1166 1167 spin_lock_irq(shost->host_lock); 1168 /* Search the mapped list for this target ID */ 1169 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1170 if (starget->id == ndlp->nlp_sid) { 1171 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); 1172 break; 1173 } 1174 } 1175 spin_unlock_irq(shost->host_lock); 1176 1177 fc_starget_port_name(starget) = port_name; 1178 } 1179 1180 static void 1181 lpfc_get_rport_loss_tmo(struct fc_rport *rport) 1182 { 1183 /* 1184 * Return the driver's global value for device loss timeout plus 1185 * five seconds to allow the driver's nodev timer to run. 1186 */ 1187 rport->dev_loss_tmo = lpfc_nodev_tmo + 5; 1188 } 1189 1190 static void 1191 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) 1192 { 1193 /* 1194 * The driver doesn't have a per-target timeout setting. Set 1195 * this value globally. lpfc_nodev_tmo should be greater then 0. 1196 */ 1197 if (timeout) 1198 lpfc_nodev_tmo = timeout; 1199 else 1200 lpfc_nodev_tmo = 1; 1201 rport->dev_loss_tmo = lpfc_nodev_tmo + 5; 1202 } 1203 1204 1205 #define lpfc_rport_show_function(field, format_string, sz, cast) \ 1206 static ssize_t \ 1207 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \ 1208 { \ 1209 struct fc_rport *rport = transport_class_to_rport(cdev); \ 1210 struct lpfc_rport_data *rdata = rport->hostdata; \ 1211 return snprintf(buf, sz, format_string, \ 1212 (rdata->target) ? cast rdata->target->field : 0); \ 1213 } 1214 1215 #define lpfc_rport_rd_attr(field, format_string, sz) \ 1216 lpfc_rport_show_function(field, format_string, sz, ) \ 1217 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) 1218 1219 1220 struct fc_function_template lpfc_transport_functions = { 1221 /* fixed attributes the driver supports */ 1222 .show_host_node_name = 1, 1223 .show_host_port_name = 1, 1224 .show_host_supported_classes = 1, 1225 .show_host_supported_fc4s = 1, 1226 .show_host_symbolic_name = 1, 1227 .show_host_supported_speeds = 1, 1228 .show_host_maxframe_size = 1, 1229 1230 /* dynamic attributes the driver supports */ 1231 .get_host_port_id = lpfc_get_host_port_id, 1232 .show_host_port_id = 1, 1233 1234 .get_host_port_type = lpfc_get_host_port_type, 1235 .show_host_port_type = 1, 1236 1237 .get_host_port_state = lpfc_get_host_port_state, 1238 .show_host_port_state = 1, 1239 1240 /* active_fc4s is shown but doesn't change (thus no get function) */ 1241 .show_host_active_fc4s = 1, 1242 1243 .get_host_speed = lpfc_get_host_speed, 1244 .show_host_speed = 1, 1245 1246 .get_host_fabric_name = lpfc_get_host_fabric_name, 1247 .show_host_fabric_name = 1, 1248 1249 /* 1250 * The LPFC driver treats linkdown handling as target loss events 1251 * so there are no sysfs handlers for link_down_tmo. 1252 */ 1253 1254 .get_fc_host_stats = lpfc_get_stats, 1255 1256 /* the LPFC driver doesn't support resetting stats yet */ 1257 1258 .dd_fcrport_size = sizeof(struct lpfc_rport_data), 1259 .show_rport_maxframe_size = 1, 1260 .show_rport_supported_classes = 1, 1261 1262 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo, 1263 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, 1264 .show_rport_dev_loss_tmo = 1, 1265 1266 .get_starget_port_id = lpfc_get_starget_port_id, 1267 .show_starget_port_id = 1, 1268 1269 .get_starget_node_name = lpfc_get_starget_node_name, 1270 .show_starget_node_name = 1, 1271 1272 .get_starget_port_name = lpfc_get_starget_port_name, 1273 .show_starget_port_name = 1, 1274 1275 .issue_fc_host_lip = lpfc_issue_lip, 1276 }; 1277 1278 void 1279 lpfc_get_cfgparam(struct lpfc_hba *phba) 1280 { 1281 lpfc_log_verbose_init(phba, lpfc_log_verbose); 1282 lpfc_cr_delay_init(phba, lpfc_cr_delay); 1283 lpfc_cr_count_init(phba, lpfc_cr_count); 1284 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth); 1285 lpfc_fcp_class_init(phba, lpfc_fcp_class); 1286 lpfc_use_adisc_init(phba, lpfc_use_adisc); 1287 lpfc_ack0_init(phba, lpfc_ack0); 1288 lpfc_topology_init(phba, lpfc_topology); 1289 lpfc_scan_down_init(phba, lpfc_scan_down); 1290 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo); 1291 lpfc_link_speed_init(phba, lpfc_link_speed); 1292 lpfc_fdmi_on_init(phba, lpfc_fdmi_on); 1293 lpfc_discovery_threads_init(phba, lpfc_discovery_threads); 1294 lpfc_max_luns_init(phba, lpfc_max_luns); 1295 1296 /* 1297 * The total number of segments is the configuration value plus 2 1298 * since the IOCB need a command and response bde. 1299 */ 1300 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2; 1301 1302 /* 1303 * Since the sg_tablesize is module parameter, the sg_dma_buf_size 1304 * used to create the sg_dma_buf_pool must be dynamically calculated 1305 */ 1306 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + 1307 sizeof(struct fcp_rsp) + 1308 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64)); 1309 1310 switch (phba->pcidev->device) { 1311 case PCI_DEVICE_ID_LP101: 1312 case PCI_DEVICE_ID_BSMB: 1313 case PCI_DEVICE_ID_ZSMB: 1314 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH; 1315 break; 1316 case PCI_DEVICE_ID_RFLY: 1317 case PCI_DEVICE_ID_PFLY: 1318 case PCI_DEVICE_ID_BMID: 1319 case PCI_DEVICE_ID_ZMID: 1320 case PCI_DEVICE_ID_TFLY: 1321 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH; 1322 break; 1323 default: 1324 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH; 1325 } 1326 return; 1327 } 1328