| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/ctype.h> |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 23 | #include <linux/delay.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/pci.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 28 | #include <scsi/scsi_device.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_tcq.h> |
| 31 | #include <scsi/scsi_transport_fc.h> |
| 32 | |
| 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
| 35 | #include "lpfc_disc.h" |
| 36 | #include "lpfc_scsi.h" |
| 37 | #include "lpfc.h" |
| 38 | #include "lpfc_logmsg.h" |
| 39 | #include "lpfc_version.h" |
| 40 | #include "lpfc_compat.h" |
| 41 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 42 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 44 | #define LPFC_DEF_DEVLOSS_TMO 30 |
| 45 | #define LPFC_MIN_DEVLOSS_TMO 1 |
| 46 | #define LPFC_MAX_DEVLOSS_TMO 255 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | |
| 48 | static void |
| 49 | lpfc_jedec_to_ascii(int incr, char hdw[]) |
| 50 | { |
| 51 | int i, j; |
| 52 | for (i = 0; i < 8; i++) { |
| 53 | j = (incr & 0xf); |
| 54 | if (j <= 9) |
| 55 | hdw[7 - i] = 0x30 + j; |
| 56 | else |
| 57 | hdw[7 - i] = 0x61 + j - 10; |
| 58 | incr = (incr >> 4); |
| 59 | } |
| 60 | hdw[8] = 0; |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | static ssize_t |
| 65 | lpfc_drvr_version_show(struct class_device *cdev, char *buf) |
| 66 | { |
| 67 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); |
| 68 | } |
| 69 | |
| 70 | static ssize_t |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 71 | lpfc_info_show(struct class_device *cdev, char *buf) |
| 72 | { |
| 73 | struct Scsi_Host *host = class_to_shost(cdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 74 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 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 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 81 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 82 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 83 | struct lpfc_hba *phba = vport->phba; |
| 84 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 85 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
| 86 | } |
| 87 | |
| 88 | static ssize_t |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 89 | lpfc_temp_sensor_show(struct class_device *cdev, char *buf) |
| 90 | { |
| 91 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 92 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 93 | struct lpfc_hba *phba = vport->phba; |
| 94 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); |
| 95 | } |
| 96 | |
| 97 | static ssize_t |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 98 | lpfc_modeldesc_show(struct class_device *cdev, char *buf) |
| 99 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 100 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 101 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 102 | struct lpfc_hba *phba = vport->phba; |
| 103 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 104 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
| 105 | } |
| 106 | |
| 107 | static ssize_t |
| 108 | lpfc_modelname_show(struct class_device *cdev, char *buf) |
| 109 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 110 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 111 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 112 | struct lpfc_hba *phba = vport->phba; |
| 113 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
| 115 | } |
| 116 | |
| 117 | static ssize_t |
| 118 | lpfc_programtype_show(struct class_device *cdev, char *buf) |
| 119 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 120 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 121 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 122 | struct lpfc_hba *phba = vport->phba; |
| 123 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 124 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
| 125 | } |
| 126 | |
| 127 | static ssize_t |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 128 | lpfc_vportnum_show(struct class_device *cdev, char *buf) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 129 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 130 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 131 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 132 | struct lpfc_hba *phba = vport->phba; |
| 133 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 134 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
| 135 | } |
| 136 | |
| 137 | static ssize_t |
| 138 | lpfc_fwrev_show(struct class_device *cdev, char *buf) |
| 139 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 140 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 141 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 142 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | char fwrev[32]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 144 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 145 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 146 | return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static ssize_t |
| 150 | lpfc_hdw_show(struct class_device *cdev, char *buf) |
| 151 | { |
| 152 | char hdw[9]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 153 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 154 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 155 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 156 | lpfc_vpd_t *vp = &phba->vpd; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 157 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
| 159 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); |
| 160 | } |
| 161 | static ssize_t |
| 162 | lpfc_option_rom_version_show(struct class_device *cdev, char *buf) |
| 163 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 164 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 165 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 166 | struct lpfc_hba *phba = vport->phba; |
| 167 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); |
| 169 | } |
| 170 | static ssize_t |
| 171 | lpfc_state_show(struct class_device *cdev, char *buf) |
| 172 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 173 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 174 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 175 | struct lpfc_hba *phba = vport->phba; |
| 176 | int len = 0; |
| 177 | |
| 178 | switch (phba->link_state) { |
| 179 | case LPFC_LINK_UNKNOWN: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 180 | case LPFC_WARM_START: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 181 | case LPFC_INIT_START: |
| 182 | case LPFC_INIT_MBX_CMDS: |
| 183 | case LPFC_LINK_DOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 184 | case LPFC_HBA_ERROR: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); |
| 186 | break; |
| 187 | case LPFC_LINK_UP: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 188 | case LPFC_CLEAR_LA: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 189 | case LPFC_HBA_READY: |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 190 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 191 | |
| 192 | switch (vport->port_state) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 193 | case LPFC_LOCAL_CFG_LINK: |
| 194 | len += snprintf(buf + len, PAGE_SIZE-len, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 195 | "Configuring Link\n"); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 196 | break; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 197 | case LPFC_FDISC: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 198 | case LPFC_FLOGI: |
| 199 | case LPFC_FABRIC_CFG_LINK: |
| 200 | case LPFC_NS_REG: |
| 201 | case LPFC_NS_QRY: |
| 202 | case LPFC_BUILD_DISC_LIST: |
| 203 | case LPFC_DISC_AUTH: |
| 204 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 205 | "Discovery\n"); |
| 206 | break; |
| 207 | case LPFC_VPORT_READY: |
| 208 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); |
| 209 | break; |
| 210 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 211 | case LPFC_VPORT_FAILED: |
| 212 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); |
| 213 | break; |
| 214 | |
| 215 | case LPFC_VPORT_UNKNOWN: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 216 | len += snprintf(buf + len, PAGE_SIZE - len, |
| 217 | "Unknown\n"); |
| 218 | break; |
| 219 | } |
| 220 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 221 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 222 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 223 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 224 | " Public Loop\n"); |
| 225 | else |
| 226 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 227 | " Private Loop\n"); |
| 228 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 229 | if (vport->fc_flag & FC_FABRIC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 230 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 231 | " Fabric\n"); |
| 232 | else |
| 233 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 234 | " Point-2-Point\n"); |
| 235 | } |
| 236 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | return len; |
| 239 | } |
| 240 | |
| 241 | static ssize_t |
| 242 | lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) |
| 243 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 244 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 245 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 246 | |
| 247 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 248 | vport->fc_map_cnt + vport->fc_unmap_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 252 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 253 | lpfc_issue_lip(struct Scsi_Host *shost) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 254 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 255 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 256 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 257 | LPFC_MBOXQ_t *pmboxq; |
| 258 | int mbxstatus = MBXERR_ERROR; |
| 259 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 260 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
| 261 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) || |
| 262 | (vport->port_state != LPFC_VPORT_READY)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 263 | return -EPERM; |
| 264 | |
| 265 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 266 | |
| 267 | if (!pmboxq) |
| 268 | return -ENOMEM; |
| 269 | |
| 270 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 271 | pmboxq->mb.mbxCommand = MBX_DOWN_LINK; |
| 272 | pmboxq->mb.mbxOwner = OWN_HOST; |
| 273 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 274 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 275 | |
James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 276 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) { |
| 277 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| 278 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, |
| 279 | phba->cfg_link_speed); |
| 280 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, |
| 281 | phba->fc_ratov * 2); |
| 282 | } |
| 283 | |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 284 | lpfc_set_loopback_flag(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 285 | if (mbxstatus != MBX_TIMEOUT) |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 286 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | |
| 288 | if (mbxstatus == MBXERR_ERROR) |
| 289 | return -EIO; |
| 290 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 291 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 292 | } |
| 293 | |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 294 | static int |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 295 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) |
| 296 | { |
| 297 | struct completion online_compl; |
| 298 | struct lpfc_sli_ring *pring; |
| 299 | struct lpfc_sli *psli; |
| 300 | int status = 0; |
| 301 | int cnt = 0; |
| 302 | int i; |
| 303 | |
| 304 | init_completion(&online_compl); |
| 305 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 306 | LPFC_EVT_OFFLINE_PREP); |
| 307 | wait_for_completion(&online_compl); |
| 308 | |
| 309 | if (status != 0) |
| 310 | return -EIO; |
| 311 | |
| 312 | psli = &phba->sli; |
| 313 | |
| 314 | for (i = 0; i < psli->num_rings; i++) { |
| 315 | pring = &psli->ring[i]; |
| 316 | /* The linkdown event takes 30 seconds to timeout. */ |
| 317 | while (pring->txcmplq_cnt) { |
| 318 | msleep(10); |
| 319 | if (cnt++ > 3000) { |
| 320 | lpfc_printf_log(phba, |
| 321 | KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 322 | "0466 Outstanding IO when " |
| 323 | "bringing Adapter offline\n"); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 324 | break; |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | init_completion(&online_compl); |
| 330 | lpfc_workq_post_event(phba, &status, &online_compl, type); |
| 331 | wait_for_completion(&online_compl); |
| 332 | |
| 333 | if (status != 0) |
| 334 | return -EIO; |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 340 | lpfc_selective_reset(struct lpfc_hba *phba) |
| 341 | { |
| 342 | struct completion online_compl; |
| 343 | int status = 0; |
| 344 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 345 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 346 | |
| 347 | if (status != 0) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 348 | return status; |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 349 | |
| 350 | init_completion(&online_compl); |
| 351 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 352 | LPFC_EVT_ONLINE); |
| 353 | wait_for_completion(&online_compl); |
| 354 | |
| 355 | if (status != 0) |
| 356 | return -EIO; |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static ssize_t |
| 362 | lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count) |
| 363 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 364 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 365 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 366 | struct lpfc_hba *phba = vport->phba; |
| 367 | |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 368 | int status = -EINVAL; |
| 369 | |
| 370 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) |
| 371 | status = lpfc_selective_reset(phba); |
| 372 | |
| 373 | if (status == 0) |
| 374 | return strlen(buf); |
| 375 | else |
| 376 | return status; |
| 377 | } |
| 378 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 379 | static ssize_t |
| 380 | lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) |
| 381 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 382 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 383 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 384 | struct lpfc_hba *phba = vport->phba; |
| 385 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 386 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
| 387 | } |
| 388 | |
| 389 | static ssize_t |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 390 | lpfc_board_mode_show(struct class_device *cdev, char *buf) |
| 391 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 392 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 393 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 394 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 395 | char * state; |
| 396 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 397 | if (phba->link_state == LPFC_HBA_ERROR) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 398 | state = "error"; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 399 | else if (phba->link_state == LPFC_WARM_START) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 400 | state = "warm start"; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 401 | else if (phba->link_state == LPFC_INIT_START) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 402 | state = "offline"; |
| 403 | else |
| 404 | state = "online"; |
| 405 | |
| 406 | return snprintf(buf, PAGE_SIZE, "%s\n", state); |
| 407 | } |
| 408 | |
| 409 | static ssize_t |
| 410 | lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count) |
| 411 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 413 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 414 | struct lpfc_hba *phba = vport->phba; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 415 | struct completion online_compl; |
| 416 | int status=0; |
| 417 | |
| 418 | init_completion(&online_compl); |
| 419 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 420 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 421 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 422 | LPFC_EVT_ONLINE); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 423 | wait_for_completion(&online_compl); |
| 424 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) |
| 425 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 426 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 427 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); |
| 428 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) |
| 429 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 430 | else |
| 431 | return -EINVAL; |
| 432 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 433 | if (!status) |
| 434 | return strlen(buf); |
| 435 | else |
| 436 | return -EIO; |
| 437 | } |
| 438 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 439 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 440 | lpfc_get_hba_info(struct lpfc_hba *phba, |
| 441 | uint32_t *mxri, uint32_t *axri, |
| 442 | uint32_t *mrpi, uint32_t *arpi, |
| 443 | uint32_t *mvpi, uint32_t *avpi) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 444 | { |
| 445 | struct lpfc_sli *psli = &phba->sli; |
| 446 | LPFC_MBOXQ_t *pmboxq; |
| 447 | MAILBOX_t *pmb; |
| 448 | int rc = 0; |
| 449 | |
| 450 | /* |
| 451 | * prevent udev from issuing mailbox commands until the port is |
| 452 | * configured. |
| 453 | */ |
| 454 | if (phba->link_state < LPFC_LINK_DOWN || |
| 455 | !phba->mbox_mem_pool || |
| 456 | (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) |
| 457 | return 0; |
| 458 | |
| 459 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
| 460 | return 0; |
| 461 | |
| 462 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 463 | if (!pmboxq) |
| 464 | return 0; |
| 465 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| 466 | |
| 467 | pmb = &pmboxq->mb; |
| 468 | pmb->mbxCommand = MBX_READ_CONFIG; |
| 469 | pmb->mbxOwner = OWN_HOST; |
| 470 | pmboxq->context1 = NULL; |
| 471 | |
| 472 | if ((phba->pport->fc_flag & FC_OFFLINE_MODE) || |
| 473 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| 474 | rc = MBX_NOT_FINISHED; |
| 475 | else |
| 476 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 477 | |
| 478 | if (rc != MBX_SUCCESS) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 479 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 480 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | if (mrpi) |
| 485 | *mrpi = pmb->un.varRdConfig.max_rpi; |
| 486 | if (arpi) |
| 487 | *arpi = pmb->un.varRdConfig.avail_rpi; |
| 488 | if (mxri) |
| 489 | *mxri = pmb->un.varRdConfig.max_xri; |
| 490 | if (axri) |
| 491 | *axri = pmb->un.varRdConfig.avail_xri; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 492 | if (mvpi) |
| 493 | *mvpi = pmb->un.varRdConfig.max_vpi; |
| 494 | if (avpi) |
| 495 | *avpi = pmb->un.varRdConfig.avail_vpi; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 496 | |
| 497 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 498 | return 1; |
| 499 | } |
| 500 | |
| 501 | static ssize_t |
| 502 | lpfc_max_rpi_show(struct class_device *cdev, char *buf) |
| 503 | { |
| 504 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 505 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 506 | struct lpfc_hba *phba = vport->phba; |
| 507 | uint32_t cnt; |
| 508 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 509 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 510 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
| 511 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 512 | } |
| 513 | |
| 514 | static ssize_t |
| 515 | lpfc_used_rpi_show(struct class_device *cdev, char *buf) |
| 516 | { |
| 517 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 518 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 519 | struct lpfc_hba *phba = vport->phba; |
| 520 | uint32_t cnt, acnt; |
| 521 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 522 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 523 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
| 524 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 525 | } |
| 526 | |
| 527 | static ssize_t |
| 528 | lpfc_max_xri_show(struct class_device *cdev, char *buf) |
| 529 | { |
| 530 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 531 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 532 | struct lpfc_hba *phba = vport->phba; |
| 533 | uint32_t cnt; |
| 534 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 535 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 536 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
| 537 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 538 | } |
| 539 | |
| 540 | static ssize_t |
| 541 | lpfc_used_xri_show(struct class_device *cdev, char *buf) |
| 542 | { |
| 543 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 544 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 545 | struct lpfc_hba *phba = vport->phba; |
| 546 | uint32_t cnt, acnt; |
| 547 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 548 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) |
| 549 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
| 550 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 551 | } |
| 552 | |
| 553 | static ssize_t |
| 554 | lpfc_max_vpi_show(struct class_device *cdev, char *buf) |
| 555 | { |
| 556 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 557 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 558 | struct lpfc_hba *phba = vport->phba; |
| 559 | uint32_t cnt; |
| 560 | |
| 561 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) |
| 562 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
| 563 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 564 | } |
| 565 | |
| 566 | static ssize_t |
| 567 | lpfc_used_vpi_show(struct class_device *cdev, char *buf) |
| 568 | { |
| 569 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 570 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 571 | struct lpfc_hba *phba = vport->phba; |
| 572 | uint32_t cnt, acnt; |
| 573 | |
| 574 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 575 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
| 576 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); |
| 577 | } |
| 578 | |
| 579 | static ssize_t |
| 580 | lpfc_npiv_info_show(struct class_device *cdev, char *buf) |
| 581 | { |
| 582 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 583 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 584 | struct lpfc_hba *phba = vport->phba; |
| 585 | |
| 586 | if (!(phba->max_vpi)) |
| 587 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); |
| 588 | if (vport->port_type == LPFC_PHYSICAL_PORT) |
| 589 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); |
| 590 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); |
| 591 | } |
| 592 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 593 | static ssize_t |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 594 | lpfc_poll_show(struct class_device *cdev, char *buf) |
| 595 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 596 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 597 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 598 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 599 | |
| 600 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); |
| 601 | } |
| 602 | |
| 603 | static ssize_t |
| 604 | lpfc_poll_store(struct class_device *cdev, const char *buf, |
| 605 | size_t count) |
| 606 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 607 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 608 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 609 | struct lpfc_hba *phba = vport->phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 610 | uint32_t creg_val; |
| 611 | uint32_t old_val; |
| 612 | int val=0; |
| 613 | |
| 614 | if (!isdigit(buf[0])) |
| 615 | return -EINVAL; |
| 616 | |
| 617 | if (sscanf(buf, "%i", &val) != 1) |
| 618 | return -EINVAL; |
| 619 | |
| 620 | if ((val & 0x3) != val) |
| 621 | return -EINVAL; |
| 622 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 623 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 624 | |
| 625 | old_val = phba->cfg_poll; |
| 626 | |
| 627 | if (val & ENABLE_FCP_RING_POLLING) { |
| 628 | if ((val & DISABLE_FCP_RING_INT) && |
| 629 | !(old_val & DISABLE_FCP_RING_INT)) { |
| 630 | creg_val = readl(phba->HCregaddr); |
| 631 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 632 | writel(creg_val, phba->HCregaddr); |
| 633 | readl(phba->HCregaddr); /* flush */ |
| 634 | |
| 635 | lpfc_poll_start_timer(phba); |
| 636 | } |
| 637 | } else if (val != 0x0) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 638 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 639 | return -EINVAL; |
| 640 | } |
| 641 | |
| 642 | if (!(val & DISABLE_FCP_RING_INT) && |
| 643 | (old_val & DISABLE_FCP_RING_INT)) |
| 644 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 645 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 646 | del_timer(&phba->fcp_poll_timer); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 647 | spin_lock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 648 | creg_val = readl(phba->HCregaddr); |
| 649 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 650 | writel(creg_val, phba->HCregaddr); |
| 651 | readl(phba->HCregaddr); /* flush */ |
| 652 | } |
| 653 | |
| 654 | phba->cfg_poll = val; |
| 655 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 656 | spin_unlock_irq(&phba->hbalock); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 657 | |
| 658 | return strlen(buf); |
| 659 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 660 | |
| 661 | #define lpfc_param_show(attr) \ |
| 662 | static ssize_t \ |
| 663 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 664 | { \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 665 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 666 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 667 | struct lpfc_hba *phba = vport->phba;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 668 | int val = 0;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 669 | val = phba->cfg_##attr;\ |
| 670 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
| 671 | phba->cfg_##attr);\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 672 | } |
| 673 | |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 674 | #define lpfc_param_hex_show(attr) \ |
| 675 | static ssize_t \ |
| 676 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 677 | { \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 678 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 679 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 680 | struct lpfc_hba *phba = vport->phba;\ |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 681 | int val = 0;\ |
| 682 | val = phba->cfg_##attr;\ |
| 683 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ |
| 684 | phba->cfg_##attr);\ |
| 685 | } |
| 686 | |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 687 | #define lpfc_param_init(attr, default, minval, maxval) \ |
| 688 | static int \ |
| 689 | lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ |
| 690 | { \ |
| 691 | if (val >= minval && val <= maxval) {\ |
| 692 | phba->cfg_##attr = val;\ |
| 693 | return 0;\ |
| 694 | }\ |
| 695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 696 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 697 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 698 | phba->cfg_##attr = default;\ |
| 699 | return -EINVAL;\ |
| 700 | } |
| 701 | |
| 702 | #define lpfc_param_set(attr, default, minval, maxval) \ |
| 703 | static int \ |
| 704 | lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ |
| 705 | { \ |
| 706 | if (val >= minval && val <= maxval) {\ |
| 707 | phba->cfg_##attr = val;\ |
| 708 | return 0;\ |
| 709 | }\ |
| 710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 711 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 712 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 713 | return -EINVAL;\ |
| 714 | } |
| 715 | |
| 716 | #define lpfc_param_store(attr) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 717 | static ssize_t \ |
| 718 | lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ |
| 719 | { \ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 720 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 721 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 722 | struct lpfc_hba *phba = vport->phba;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 723 | int val=0;\ |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 724 | if (!isdigit(buf[0]))\ |
| 725 | return -EINVAL;\ |
| 726 | if (sscanf(buf, "%i", &val) != 1)\ |
| 727 | return -EINVAL;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 728 | if (lpfc_##attr##_set(phba, val) == 0) \ |
James.Smart@Emulex.Com | 755c0d0 | 2005-10-28 20:29:06 -0400 | [diff] [blame] | 729 | return strlen(buf);\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 730 | else \ |
| 731 | return -EINVAL;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 732 | } |
| 733 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 734 | #define lpfc_vport_param_show(attr) \ |
| 735 | static ssize_t \ |
| 736 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 737 | { \ |
| 738 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 739 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 740 | int val = 0;\ |
| 741 | val = vport->cfg_##attr;\ |
| 742 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ |
| 743 | } |
| 744 | |
| 745 | #define lpfc_vport_param_hex_show(attr) \ |
| 746 | static ssize_t \ |
| 747 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 748 | { \ |
| 749 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 750 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 751 | int val = 0;\ |
| 752 | val = vport->cfg_##attr;\ |
| 753 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ |
| 754 | } |
| 755 | |
| 756 | #define lpfc_vport_param_init(attr, default, minval, maxval) \ |
| 757 | static int \ |
| 758 | lpfc_##attr##_init(struct lpfc_vport *vport, int val) \ |
| 759 | { \ |
| 760 | if (val >= minval && val <= maxval) {\ |
| 761 | vport->cfg_##attr = val;\ |
| 762 | return 0;\ |
| 763 | }\ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 764 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
| 765 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 766 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 767 | vport->cfg_##attr = default;\ |
| 768 | return -EINVAL;\ |
| 769 | } |
| 770 | |
| 771 | #define lpfc_vport_param_set(attr, default, minval, maxval) \ |
| 772 | static int \ |
| 773 | lpfc_##attr##_set(struct lpfc_vport *vport, int val) \ |
| 774 | { \ |
| 775 | if (val >= minval && val <= maxval) {\ |
| 776 | vport->cfg_##attr = val;\ |
| 777 | return 0;\ |
| 778 | }\ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 779 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
| 780 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 781 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 782 | return -EINVAL;\ |
| 783 | } |
| 784 | |
| 785 | #define lpfc_vport_param_store(attr) \ |
| 786 | static ssize_t \ |
| 787 | lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ |
| 788 | { \ |
| 789 | struct Scsi_Host *shost = class_to_shost(cdev);\ |
| 790 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
| 791 | int val=0;\ |
| 792 | if (!isdigit(buf[0]))\ |
| 793 | return -EINVAL;\ |
| 794 | if (sscanf(buf, "%i", &val) != 1)\ |
| 795 | return -EINVAL;\ |
| 796 | if (lpfc_##attr##_set(vport, val) == 0) \ |
| 797 | return strlen(buf);\ |
| 798 | else \ |
| 799 | return -EINVAL;\ |
| 800 | } |
| 801 | |
| 802 | |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 803 | #define LPFC_ATTR(name, defval, minval, maxval, desc) \ |
| 804 | static int lpfc_##name = defval;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | module_param(lpfc_##name, int, 0);\ |
| 806 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 807 | lpfc_param_init(name, defval, minval, maxval) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 808 | |
| 809 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ |
| 810 | static int lpfc_##name = defval;\ |
| 811 | module_param(lpfc_##name, int, 0);\ |
| 812 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 813 | lpfc_param_show(name)\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 814 | lpfc_param_init(name, defval, minval, maxval)\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 815 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 816 | |
| 817 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ |
| 818 | static int lpfc_##name = defval;\ |
| 819 | module_param(lpfc_##name, int, 0);\ |
| 820 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 821 | lpfc_param_show(name)\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 822 | lpfc_param_init(name, defval, minval, maxval)\ |
| 823 | lpfc_param_set(name, defval, minval, maxval)\ |
| 824 | lpfc_param_store(name)\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 826 | lpfc_##name##_show, lpfc_##name##_store) |
| 827 | |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 828 | #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ |
| 829 | static int lpfc_##name = defval;\ |
| 830 | module_param(lpfc_##name, int, 0);\ |
| 831 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 832 | lpfc_param_hex_show(name)\ |
| 833 | lpfc_param_init(name, defval, minval, maxval)\ |
| 834 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 835 | |
| 836 | #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ |
| 837 | static int lpfc_##name = defval;\ |
| 838 | module_param(lpfc_##name, int, 0);\ |
| 839 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 840 | lpfc_param_hex_show(name)\ |
| 841 | lpfc_param_init(name, defval, minval, maxval)\ |
| 842 | lpfc_param_set(name, defval, minval, maxval)\ |
| 843 | lpfc_param_store(name)\ |
| 844 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 845 | lpfc_##name##_show, lpfc_##name##_store) |
| 846 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 847 | #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ |
| 848 | static int lpfc_##name = defval;\ |
| 849 | module_param(lpfc_##name, int, 0);\ |
| 850 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 851 | lpfc_vport_param_init(name, defval, minval, maxval) |
| 852 | |
| 853 | #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ |
| 854 | static int lpfc_##name = defval;\ |
| 855 | module_param(lpfc_##name, int, 0);\ |
| 856 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 857 | lpfc_vport_param_show(name)\ |
| 858 | lpfc_vport_param_init(name, defval, minval, maxval)\ |
| 859 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 860 | |
| 861 | #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ |
| 862 | static int lpfc_##name = defval;\ |
| 863 | module_param(lpfc_##name, int, 0);\ |
| 864 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 865 | lpfc_vport_param_show(name)\ |
| 866 | lpfc_vport_param_init(name, defval, minval, maxval)\ |
| 867 | lpfc_vport_param_set(name, defval, minval, maxval)\ |
| 868 | lpfc_vport_param_store(name)\ |
| 869 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 870 | lpfc_##name##_show, lpfc_##name##_store) |
| 871 | |
| 872 | #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ |
| 873 | static int lpfc_##name = defval;\ |
| 874 | module_param(lpfc_##name, int, 0);\ |
| 875 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 876 | lpfc_vport_param_hex_show(name)\ |
| 877 | lpfc_vport_param_init(name, defval, minval, maxval)\ |
| 878 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 879 | |
| 880 | #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ |
| 881 | static int lpfc_##name = defval;\ |
| 882 | module_param(lpfc_##name, int, 0);\ |
| 883 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 884 | lpfc_vport_param_hex_show(name)\ |
| 885 | lpfc_vport_param_init(name, defval, minval, maxval)\ |
| 886 | lpfc_vport_param_set(name, defval, minval, maxval)\ |
| 887 | lpfc_vport_param_store(name)\ |
| 888 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 889 | lpfc_##name##_show, lpfc_##name##_store) |
| 890 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 891 | static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); |
| 892 | static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); |
| 893 | static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); |
| 894 | static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); |
| 895 | static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 896 | static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 897 | static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); |
| 898 | static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); |
| 899 | static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); |
| 900 | static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO, |
| 901 | lpfc_option_rom_version_show, NULL); |
| 902 | static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO, |
| 903 | lpfc_num_discovered_ports_show, NULL); |
| 904 | static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
| 905 | static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, |
| 906 | NULL); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 907 | static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, |
| 908 | lpfc_board_mode_show, lpfc_board_mode_store); |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 909 | static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 910 | static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); |
| 911 | static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); |
| 912 | static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); |
| 913 | static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); |
| 914 | static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); |
| 915 | static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); |
| 916 | static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 917 | static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, |
| 918 | NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 919 | |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 920 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 921 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 922 | |
| 923 | static ssize_t |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 924 | lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf, |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 925 | size_t count) |
| 926 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 927 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 928 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 929 | struct lpfc_hba *phba = vport->phba; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 930 | unsigned int cnt = count; |
| 931 | |
| 932 | /* |
| 933 | * We're doing a simple sanity check for soft_wwpn setting. |
| 934 | * We require that the user write a specific key to enable |
| 935 | * the soft_wwpn attribute to be settable. Once the attribute |
| 936 | * is written, the enable key resets. If further updates are |
| 937 | * desired, the key must be written again to re-enable the |
| 938 | * attribute. |
| 939 | * |
| 940 | * The "key" is not secret - it is a hardcoded string shown |
| 941 | * here. The intent is to protect against the random user or |
| 942 | * application that is just writing attributes. |
| 943 | */ |
| 944 | |
| 945 | /* count may include a LF at end of string */ |
| 946 | if (buf[cnt-1] == '\n') |
| 947 | cnt--; |
| 948 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 949 | if ((cnt != strlen(lpfc_soft_wwn_key)) || |
| 950 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 951 | return -EINVAL; |
| 952 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 953 | phba->soft_wwn_enable = 1; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 954 | return count; |
| 955 | } |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 956 | static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, |
| 957 | lpfc_soft_wwn_enable_store); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 958 | |
| 959 | static ssize_t |
| 960 | lpfc_soft_wwpn_show(struct class_device *cdev, char *buf) |
| 961 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 962 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 963 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 964 | struct lpfc_hba *phba = vport->phba; |
| 965 | |
Randy Dunlap | afc071e | 2006-10-23 21:47:13 -0700 | [diff] [blame] | 966 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
| 967 | (unsigned long long)phba->cfg_soft_wwpn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | |
| 971 | static ssize_t |
| 972 | lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count) |
| 973 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 974 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 975 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 976 | struct lpfc_hba *phba = vport->phba; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 977 | struct completion online_compl; |
| 978 | int stat1=0, stat2=0; |
| 979 | unsigned int i, j, cnt=count; |
| 980 | u8 wwpn[8]; |
| 981 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame^] | 982 | spin_lock_irq(&phba->hbalock); |
| 983 | if (phba->over_temp_state == HBA_OVER_TEMP) { |
| 984 | spin_unlock_irq(&phba->hbalock); |
| 985 | return -EPERM; |
| 986 | } |
| 987 | spin_unlock_irq(&phba->hbalock); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 988 | /* count may include a LF at end of string */ |
| 989 | if (buf[cnt-1] == '\n') |
| 990 | cnt--; |
| 991 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 992 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 993 | ((cnt == 17) && (*buf++ != 'x')) || |
| 994 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) |
| 995 | return -EINVAL; |
| 996 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 997 | phba->soft_wwn_enable = 0; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 998 | |
| 999 | memset(wwpn, 0, sizeof(wwpn)); |
| 1000 | |
| 1001 | /* Validate and store the new name */ |
| 1002 | for (i=0, j=0; i < 16; i++) { |
| 1003 | if ((*buf >= 'a') && (*buf <= 'f')) |
| 1004 | j = ((j << 4) | ((*buf++ -'a') + 10)); |
| 1005 | else if ((*buf >= 'A') && (*buf <= 'F')) |
| 1006 | j = ((j << 4) | ((*buf++ -'A') + 10)); |
| 1007 | else if ((*buf >= '0') && (*buf <= '9')) |
| 1008 | j = ((j << 4) | (*buf++ -'0')); |
| 1009 | else |
| 1010 | return -EINVAL; |
| 1011 | if (i % 2) { |
| 1012 | wwpn[i/2] = j & 0xff; |
| 1013 | j = 0; |
| 1014 | } |
| 1015 | } |
| 1016 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1017 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1018 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1019 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1020 | |
| 1021 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, |
| 1022 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); |
| 1023 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1024 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1025 | if (stat1) |
| 1026 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1027 | "0463 lpfc_soft_wwpn attribute set failed to " |
| 1028 | "reinit adapter - %d\n", stat1); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1029 | init_completion(&online_compl); |
| 1030 | lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE); |
| 1031 | wait_for_completion(&online_compl); |
| 1032 | if (stat2) |
| 1033 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1034 | "0464 lpfc_soft_wwpn attribute set failed to " |
| 1035 | "reinit adapter - %d\n", stat2); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1036 | return (stat1 || stat2) ? -EIO : count; |
| 1037 | } |
| 1038 | static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ |
| 1039 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); |
| 1040 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1041 | static ssize_t |
| 1042 | lpfc_soft_wwnn_show(struct class_device *cdev, char *buf) |
| 1043 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1044 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1045 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1046 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
| 1047 | (unsigned long long)phba->cfg_soft_wwnn); |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | static ssize_t |
| 1052 | lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count) |
| 1053 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1054 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1055 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1056 | unsigned int i, j, cnt=count; |
| 1057 | u8 wwnn[8]; |
| 1058 | |
| 1059 | /* count may include a LF at end of string */ |
| 1060 | if (buf[cnt-1] == '\n') |
| 1061 | cnt--; |
| 1062 | |
| 1063 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || |
| 1064 | ((cnt == 17) && (*buf++ != 'x')) || |
| 1065 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) |
| 1066 | return -EINVAL; |
| 1067 | |
| 1068 | /* |
| 1069 | * Allow wwnn to be set many times, as long as the enable is set. |
| 1070 | * However, once the wwpn is set, everything locks. |
| 1071 | */ |
| 1072 | |
| 1073 | memset(wwnn, 0, sizeof(wwnn)); |
| 1074 | |
| 1075 | /* Validate and store the new name */ |
| 1076 | for (i=0, j=0; i < 16; i++) { |
| 1077 | if ((*buf >= 'a') && (*buf <= 'f')) |
| 1078 | j = ((j << 4) | ((*buf++ -'a') + 10)); |
| 1079 | else if ((*buf >= 'A') && (*buf <= 'F')) |
| 1080 | j = ((j << 4) | ((*buf++ -'A') + 10)); |
| 1081 | else if ((*buf >= '0') && (*buf <= '9')) |
| 1082 | j = ((j << 4) | (*buf++ -'0')); |
| 1083 | else |
| 1084 | return -EINVAL; |
| 1085 | if (i % 2) { |
| 1086 | wwnn[i/2] = j & 0xff; |
| 1087 | j = 0; |
| 1088 | } |
| 1089 | } |
| 1090 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); |
| 1091 | |
| 1092 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, |
| 1093 | "lpfc%d: soft_wwnn set. Value will take effect upon " |
| 1094 | "setting of the soft_wwpn\n", phba->brd_no); |
| 1095 | |
| 1096 | return count; |
| 1097 | } |
| 1098 | static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\ |
| 1099 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); |
| 1100 | |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1101 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1102 | static int lpfc_poll = 0; |
| 1103 | module_param(lpfc_poll, int, 0); |
| 1104 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" |
| 1105 | " 0 - none," |
| 1106 | " 1 - poll with interrupts enabled" |
| 1107 | " 3 - poll and disable FCP ring interrupts"); |
| 1108 | |
| 1109 | static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
| 1110 | lpfc_poll_show, lpfc_poll_store); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1111 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1112 | int lpfc_sli_mode = 0; |
| 1113 | module_param(lpfc_sli_mode, int, 0); |
| 1114 | MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" |
| 1115 | " 0 - auto (SLI-3 if supported)," |
| 1116 | " 2 - select SLI-2 even on SLI-3 capable HBAs," |
| 1117 | " 3 - select SLI-3"); |
| 1118 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1119 | int lpfc_enable_npiv = 0; |
| 1120 | module_param(lpfc_enable_npiv, int, 0); |
| 1121 | MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); |
| 1122 | lpfc_param_show(enable_npiv); |
| 1123 | lpfc_param_init(enable_npiv, 0, 0, 1); |
| 1124 | static CLASS_DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, |
| 1125 | lpfc_enable_npiv_show, NULL); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1126 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1127 | /* |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1128 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear |
| 1129 | # until the timer expires. Value range is [0,255]. Default value is 30. |
| 1130 | */ |
| 1131 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
| 1132 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; |
| 1133 | module_param(lpfc_nodev_tmo, int, 0); |
| 1134 | MODULE_PARM_DESC(lpfc_nodev_tmo, |
| 1135 | "Seconds driver will hold I/O waiting " |
| 1136 | "for a device to come back"); |
| 1137 | static ssize_t |
| 1138 | lpfc_nodev_tmo_show(struct class_device *cdev, char *buf) |
| 1139 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1140 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1141 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1142 | int val = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1143 | val = vport->cfg_devloss_tmo; |
| 1144 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | static int |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1148 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1149 | { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1150 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { |
| 1151 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; |
| 1152 | if (val != LPFC_DEF_DEVLOSS_TMO) |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1154 | "0402 Ignoring nodev_tmo module " |
| 1155 | "parameter because devloss_tmo is " |
| 1156 | "set.\n"); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1157 | return 0; |
| 1158 | } |
| 1159 | |
| 1160 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1161 | vport->cfg_nodev_tmo = val; |
| 1162 | vport->cfg_devloss_tmo = val; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1163 | return 0; |
| 1164 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1165 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1166 | "0400 lpfc_nodev_tmo attribute cannot be set to" |
| 1167 | " %d, allowed range is [%d, %d]\n", |
| 1168 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1169 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1170 | return -EINVAL; |
| 1171 | } |
| 1172 | |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1173 | static void |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1174 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1175 | { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1176 | struct Scsi_Host *shost; |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1177 | struct lpfc_nodelist *ndlp; |
| 1178 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1179 | shost = lpfc_shost_from_vport(vport); |
| 1180 | spin_lock_irq(shost->host_lock); |
| 1181 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) |
| 1182 | if (ndlp->rport) |
| 1183 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
| 1184 | spin_unlock_irq(shost->host_lock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1187 | static int |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1188 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1189 | { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1190 | if (vport->dev_loss_tmo_changed || |
| 1191 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1192 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1193 | "0401 Ignoring change to nodev_tmo " |
| 1194 | "because devloss_tmo is set.\n"); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1197 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1198 | vport->cfg_nodev_tmo = val; |
| 1199 | vport->cfg_devloss_tmo = val; |
| 1200 | lpfc_update_rport_devloss_tmo(vport); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1203 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1204 | "0403 lpfc_nodev_tmo attribute cannot be set to" |
| 1205 | "%d, allowed range is [%d, %d]\n", |
| 1206 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1207 | return -EINVAL; |
| 1208 | } |
| 1209 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1210 | lpfc_vport_param_store(nodev_tmo) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1211 | |
| 1212 | static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
| 1213 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); |
| 1214 | |
| 1215 | /* |
| 1216 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that |
| 1217 | # disappear until the timer expires. Value range is [0,255]. Default |
| 1218 | # value is 30. |
| 1219 | */ |
| 1220 | module_param(lpfc_devloss_tmo, int, 0); |
| 1221 | MODULE_PARM_DESC(lpfc_devloss_tmo, |
| 1222 | "Seconds driver will hold I/O waiting " |
| 1223 | "for a device to come back"); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1224 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
| 1225 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) |
| 1226 | lpfc_vport_param_show(devloss_tmo) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1227 | static int |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1228 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1229 | { |
| 1230 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1231 | vport->cfg_nodev_tmo = val; |
| 1232 | vport->cfg_devloss_tmo = val; |
| 1233 | vport->dev_loss_tmo_changed = 1; |
| 1234 | lpfc_update_rport_devloss_tmo(vport); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1235 | return 0; |
| 1236 | } |
| 1237 | |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1238 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1239 | "0404 lpfc_devloss_tmo attribute cannot be set to" |
| 1240 | " %d, allowed range is [%d, %d]\n", |
| 1241 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1242 | return -EINVAL; |
| 1243 | } |
| 1244 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1245 | lpfc_vport_param_store(devloss_tmo) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1246 | static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
| 1247 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); |
| 1248 | |
| 1249 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1250 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being |
| 1251 | # deluged with LOTS of information. |
| 1252 | # You can set a bit mask to record specific types of verbose messages: |
| 1253 | # |
| 1254 | # LOG_ELS 0x1 ELS events |
| 1255 | # LOG_DISCOVERY 0x2 Link discovery events |
| 1256 | # LOG_MBOX 0x4 Mailbox events |
| 1257 | # LOG_INIT 0x8 Initialization events |
| 1258 | # LOG_LINK_EVENT 0x10 Link events |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | # LOG_FCP 0x40 FCP traffic history |
| 1260 | # LOG_NODE 0x80 Node table events |
| 1261 | # LOG_MISC 0x400 Miscellaneous events |
| 1262 | # LOG_SLI 0x800 SLI events |
James Smart | c774395 | 2006-12-02 13:34:42 -0500 | [diff] [blame] | 1263 | # LOG_FCP_ERROR 0x1000 Only log FCP errors |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1264 | # LOG_LIBDFC 0x2000 LIBDFC events |
| 1265 | # LOG_ALL_MSG 0xffff LOG all messages |
| 1266 | */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1267 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, |
| 1268 | "Verbose logging bit-mask"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | |
| 1270 | /* |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1271 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters |
| 1272 | # objects that have been registered with the nameserver after login. |
| 1273 | */ |
| 1274 | LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1, |
| 1275 | "Deregister nameserver objects before LOGO"); |
| 1276 | |
| 1277 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1278 | # lun_queue_depth: This parameter is used to limit the number of outstanding |
| 1279 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. |
| 1280 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1281 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128, |
| 1282 | "Max number of FCP commands we can queue to a specific LUN"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | |
| 1284 | /* |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 1285 | # hba_queue_depth: This parameter is used to limit the number of outstanding |
| 1286 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter |
| 1287 | # value is greater than the maximum number of exchanges supported by the HBA, |
| 1288 | # then maximum number of exchanges supported by the HBA is used to determine |
| 1289 | # the hba_queue_depth. |
| 1290 | */ |
| 1291 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, |
| 1292 | "Max number of FCP commands we can queue to a lpfc HBA"); |
| 1293 | |
| 1294 | /* |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1295 | # peer_port_login: This parameter allows/prevents logins |
| 1296 | # between peer ports hosted on the same physical port. |
| 1297 | # When this parameter is set 0 peer ports of same physical port |
| 1298 | # are not allowed to login to each other. |
| 1299 | # When this parameter is set 1 peer ports of same physical port |
| 1300 | # are allowed to login to each other. |
| 1301 | # Default value of this parameter is 0. |
| 1302 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1303 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, |
| 1304 | "Allow peer ports on the same physical port to login to each " |
| 1305 | "other."); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1306 | |
| 1307 | /* |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1308 | # restrict_login: This parameter allows/prevents logins |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1309 | # between Virtual Ports and remote initiators. |
| 1310 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from |
| 1311 | # other initiators and will attempt to PLOGI all remote ports. |
| 1312 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from |
| 1313 | # remote ports and will not attempt to PLOGI to other initiators. |
| 1314 | # This parameter does not restrict to the physical port. |
| 1315 | # This parameter does not restrict logins to Fabric resident remote ports. |
| 1316 | # Default value of this parameter is 1. |
| 1317 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1318 | static int lpfc_restrict_login = 1; |
| 1319 | module_param(lpfc_restrict_login, int, 0); |
| 1320 | MODULE_PARM_DESC(lpfc_restrict_login, |
| 1321 | "Restrict virtual ports login to remote initiators."); |
| 1322 | lpfc_vport_param_show(restrict_login); |
| 1323 | |
| 1324 | static int |
| 1325 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) |
| 1326 | { |
| 1327 | if (val < 0 || val > 1) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1328 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1329 | "0449 lpfc_restrict_login attribute cannot " |
| 1330 | "be set to %d, allowed range is [0, 1]\n", |
| 1331 | val); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1332 | vport->cfg_restrict_login = 1; |
| 1333 | return -EINVAL; |
| 1334 | } |
| 1335 | if (vport->port_type == LPFC_PHYSICAL_PORT) { |
| 1336 | vport->cfg_restrict_login = 0; |
| 1337 | return 0; |
| 1338 | } |
| 1339 | vport->cfg_restrict_login = val; |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | static int |
| 1344 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) |
| 1345 | { |
| 1346 | if (val < 0 || val > 1) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1347 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1348 | "0450 lpfc_restrict_login attribute cannot " |
| 1349 | "be set to %d, allowed range is [0, 1]\n", |
| 1350 | val); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1351 | vport->cfg_restrict_login = 1; |
| 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1355 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1356 | "0468 lpfc_restrict_login must be 0 for " |
| 1357 | "Physical ports.\n"); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1358 | vport->cfg_restrict_login = 0; |
| 1359 | return 0; |
| 1360 | } |
| 1361 | vport->cfg_restrict_login = val; |
| 1362 | return 0; |
| 1363 | } |
| 1364 | lpfc_vport_param_store(restrict_login); |
| 1365 | static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, |
| 1366 | lpfc_restrict_login_show, lpfc_restrict_login_store); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1367 | |
| 1368 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | # Some disk devices have a "select ID" or "select Target" capability. |
| 1370 | # From a protocol standpoint "select ID" usually means select the |
| 1371 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative |
| 1372 | # annex" which contains a table that maps a "select ID" (a number |
| 1373 | # between 0 and 7F) to an ALPA. By default, for compatibility with |
| 1374 | # older drivers, the lpfc driver scans this table from low ALPA to high |
| 1375 | # ALPA. |
| 1376 | # |
| 1377 | # Turning on the scan-down variable (on = 1, off = 0) will |
| 1378 | # cause the lpfc driver to use an inverted table, effectively |
| 1379 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. |
| 1380 | # |
| 1381 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic |
| 1382 | # and will not work across a fabric. Also this parameter will take |
| 1383 | # effect only in the case when ALPA map is not available.) |
| 1384 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1385 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, |
| 1386 | "Start scanning for devices from highest ALPA to lowest"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1387 | |
| 1388 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | # lpfc_topology: link topology for init link |
| 1390 | # 0x0 = attempt loop mode then point-to-point |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 1391 | # 0x01 = internal loopback mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1392 | # 0x02 = attempt point-to-point mode only |
| 1393 | # 0x04 = attempt loop mode only |
| 1394 | # 0x06 = attempt point-to-point mode then loop |
| 1395 | # Set point-to-point mode if you want to run as an N_Port. |
| 1396 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. |
| 1397 | # Default value is 0. |
| 1398 | */ |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 1399 | LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1400 | |
| 1401 | /* |
| 1402 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel |
| 1403 | # connection. |
| 1404 | # 0 = auto select (default) |
| 1405 | # 1 = 1 Gigabaud |
| 1406 | # 2 = 2 Gigabaud |
| 1407 | # 4 = 4 Gigabaud |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1408 | # 8 = 8 Gigabaud |
| 1409 | # Value range is [0,8]. Default value is 0. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1410 | */ |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1411 | LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1412 | |
| 1413 | /* |
| 1414 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. |
| 1415 | # Value range is [2,3]. Default value is 3. |
| 1416 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1417 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, |
| 1418 | "Select Fibre Channel class of service for FCP sequences"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | |
| 1420 | /* |
| 1421 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range |
| 1422 | # is [0,1]. Default value is 0. |
| 1423 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1424 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, |
| 1425 | "Use ADISC on rediscovery to authenticate FCP devices"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | |
| 1427 | /* |
| 1428 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value |
| 1429 | # range is [0,1]. Default value is 0. |
| 1430 | */ |
| 1431 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); |
| 1432 | |
| 1433 | /* |
| 1434 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing |
| 1435 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1436 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1437 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
| 1438 | # cr_delay is set to 0. |
| 1439 | */ |
Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 1440 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1441 | "interrupt response is generated"); |
| 1442 | |
Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 1443 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1444 | "interrupt response is generated"); |
| 1445 | |
| 1446 | /* |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1447 | # lpfc_multi_ring_support: Determines how many rings to spread available |
| 1448 | # cmd/rsp IOCB entries across. |
| 1449 | # Value range is [1,2]. Default value is 1. |
| 1450 | */ |
| 1451 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " |
| 1452 | "SLI rings to spread IOCB entries across"); |
| 1453 | |
| 1454 | /* |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1455 | # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this |
| 1456 | # identifies what rctl value to configure the additional ring for. |
| 1457 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). |
| 1458 | */ |
| 1459 | LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1, |
| 1460 | 255, "Identifies RCTL for additional ring configuration"); |
| 1461 | |
| 1462 | /* |
| 1463 | # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this |
| 1464 | # identifies what type value to configure the additional ring for. |
| 1465 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). |
| 1466 | */ |
| 1467 | LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1, |
| 1468 | 255, "Identifies TYPE for additional ring configuration"); |
| 1469 | |
| 1470 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1471 | # lpfc_fdmi_on: controls FDMI support. |
| 1472 | # 0 = no FDMI support |
| 1473 | # 1 = support FDMI without attribute of hostname |
| 1474 | # 2 = support FDMI with attribute of hostname |
| 1475 | # Value range [0,2]. Default value is 0. |
| 1476 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1477 | LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1478 | |
| 1479 | /* |
| 1480 | # Specifies the maximum number of ELS cmds we can have outstanding (for |
| 1481 | # discovery). Value range is [1,64]. Default value = 32. |
| 1482 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1483 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1484 | "during discovery"); |
| 1485 | |
| 1486 | /* |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 1487 | # lpfc_max_luns: maximum allowed LUN. |
| 1488 | # Value range is [0,65535]. Default value is 255. |
| 1489 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1490 | */ |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1491 | LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1493 | /* |
| 1494 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. |
| 1495 | # Value range is [1,255], default value is 10. |
| 1496 | */ |
| 1497 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, |
| 1498 | "Milliseconds driver will wait between polling FCP ring"); |
| 1499 | |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 1500 | /* |
| 1501 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that |
| 1502 | # support this feature |
| 1503 | # 0 = MSI disabled (default) |
| 1504 | # 1 = MSI enabled |
| 1505 | # Value range is [0,1]. Default value is 0. |
| 1506 | */ |
| 1507 | LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible"); |
| 1508 | |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1509 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1511 | struct class_device_attribute *lpfc_hba_attrs[] = { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1512 | &class_device_attr_info, |
| 1513 | &class_device_attr_serialnum, |
| 1514 | &class_device_attr_modeldesc, |
| 1515 | &class_device_attr_modelname, |
| 1516 | &class_device_attr_programtype, |
| 1517 | &class_device_attr_portnum, |
| 1518 | &class_device_attr_fwrev, |
| 1519 | &class_device_attr_hdw, |
| 1520 | &class_device_attr_option_rom_version, |
| 1521 | &class_device_attr_state, |
| 1522 | &class_device_attr_num_discovered_ports, |
| 1523 | &class_device_attr_lpfc_drvr_version, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1524 | &class_device_attr_lpfc_temp_sensor, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1525 | &class_device_attr_lpfc_log_verbose, |
| 1526 | &class_device_attr_lpfc_lun_queue_depth, |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 1527 | &class_device_attr_lpfc_hba_queue_depth, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1528 | &class_device_attr_lpfc_peer_port_login, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1529 | &class_device_attr_lpfc_nodev_tmo, |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 1530 | &class_device_attr_lpfc_devloss_tmo, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1531 | &class_device_attr_lpfc_fcp_class, |
| 1532 | &class_device_attr_lpfc_use_adisc, |
| 1533 | &class_device_attr_lpfc_ack0, |
| 1534 | &class_device_attr_lpfc_topology, |
| 1535 | &class_device_attr_lpfc_scan_down, |
| 1536 | &class_device_attr_lpfc_link_speed, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1537 | &class_device_attr_lpfc_cr_delay, |
| 1538 | &class_device_attr_lpfc_cr_count, |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1539 | &class_device_attr_lpfc_multi_ring_support, |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 1540 | &class_device_attr_lpfc_multi_ring_rctl, |
| 1541 | &class_device_attr_lpfc_multi_ring_type, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | &class_device_attr_lpfc_fdmi_on, |
| 1543 | &class_device_attr_lpfc_max_luns, |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1544 | &class_device_attr_lpfc_enable_npiv, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1545 | &class_device_attr_nport_evt_cnt, |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1546 | &class_device_attr_board_mode, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1547 | &class_device_attr_max_vpi, |
| 1548 | &class_device_attr_used_vpi, |
| 1549 | &class_device_attr_max_rpi, |
| 1550 | &class_device_attr_used_rpi, |
| 1551 | &class_device_attr_max_xri, |
| 1552 | &class_device_attr_used_xri, |
| 1553 | &class_device_attr_npiv_info, |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 1554 | &class_device_attr_issue_reset, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1555 | &class_device_attr_lpfc_poll, |
| 1556 | &class_device_attr_lpfc_poll_tmo, |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 1557 | &class_device_attr_lpfc_use_msi, |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1558 | &class_device_attr_lpfc_soft_wwnn, |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 1559 | &class_device_attr_lpfc_soft_wwpn, |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 1560 | &class_device_attr_lpfc_soft_wwn_enable, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1561 | NULL, |
| 1562 | }; |
| 1563 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1564 | struct class_device_attribute *lpfc_vport_attrs[] = { |
| 1565 | &class_device_attr_info, |
| 1566 | &class_device_attr_state, |
| 1567 | &class_device_attr_num_discovered_ports, |
| 1568 | &class_device_attr_lpfc_drvr_version, |
| 1569 | |
| 1570 | &class_device_attr_lpfc_log_verbose, |
| 1571 | &class_device_attr_lpfc_lun_queue_depth, |
| 1572 | &class_device_attr_lpfc_nodev_tmo, |
| 1573 | &class_device_attr_lpfc_devloss_tmo, |
| 1574 | &class_device_attr_lpfc_hba_queue_depth, |
| 1575 | &class_device_attr_lpfc_peer_port_login, |
| 1576 | &class_device_attr_lpfc_restrict_login, |
| 1577 | &class_device_attr_lpfc_fcp_class, |
| 1578 | &class_device_attr_lpfc_use_adisc, |
| 1579 | &class_device_attr_lpfc_fdmi_on, |
| 1580 | &class_device_attr_lpfc_max_luns, |
| 1581 | &class_device_attr_nport_evt_cnt, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1582 | &class_device_attr_npiv_info, |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 1583 | &class_device_attr_lpfc_enable_da_id, |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1584 | NULL, |
| 1585 | }; |
| 1586 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1587 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1588 | sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 1589 | char *buf, loff_t off, size_t count) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | { |
| 1591 | size_t buf_off; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1592 | struct class_device *cdev = container_of(kobj, struct class_device, |
| 1593 | kobj); |
| 1594 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1595 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1596 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1597 | |
| 1598 | if ((off + count) > FF_REG_AREA_SIZE) |
| 1599 | return -ERANGE; |
| 1600 | |
| 1601 | if (count == 0) return 0; |
| 1602 | |
| 1603 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 1604 | return -EINVAL; |
| 1605 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1606 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1607 | return -EPERM; |
| 1608 | } |
| 1609 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1610 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1611 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) |
| 1612 | writel(*((uint32_t *)(buf + buf_off)), |
| 1613 | phba->ctrl_regs_memmap_p + off + buf_off); |
| 1614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1615 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1616 | |
| 1617 | return count; |
| 1618 | } |
| 1619 | |
| 1620 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1621 | sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 1622 | char *buf, loff_t off, size_t count) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1623 | { |
| 1624 | size_t buf_off; |
| 1625 | uint32_t * tmp_ptr; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1626 | struct class_device *cdev = container_of(kobj, struct class_device, |
| 1627 | kobj); |
| 1628 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1629 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1630 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | |
| 1632 | if (off > FF_REG_AREA_SIZE) |
| 1633 | return -ERANGE; |
| 1634 | |
| 1635 | if ((off + count) > FF_REG_AREA_SIZE) |
| 1636 | count = FF_REG_AREA_SIZE - off; |
| 1637 | |
| 1638 | if (count == 0) return 0; |
| 1639 | |
| 1640 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 1641 | return -EINVAL; |
| 1642 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1643 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1644 | |
| 1645 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { |
| 1646 | tmp_ptr = (uint32_t *)(buf + buf_off); |
| 1647 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); |
| 1648 | } |
| 1649 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1650 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1651 | |
| 1652 | return count; |
| 1653 | } |
| 1654 | |
| 1655 | static struct bin_attribute sysfs_ctlreg_attr = { |
| 1656 | .attr = { |
| 1657 | .name = "ctlreg", |
| 1658 | .mode = S_IRUSR | S_IWUSR, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1659 | }, |
| 1660 | .size = 256, |
| 1661 | .read = sysfs_ctlreg_read, |
| 1662 | .write = sysfs_ctlreg_write, |
| 1663 | }; |
| 1664 | |
| 1665 | |
| 1666 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1667 | sysfs_mbox_idle(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | { |
| 1669 | phba->sysfs_mbox.state = SMBOX_IDLE; |
| 1670 | phba->sysfs_mbox.offset = 0; |
| 1671 | |
| 1672 | if (phba->sysfs_mbox.mbox) { |
| 1673 | mempool_free(phba->sysfs_mbox.mbox, |
| 1674 | phba->mbox_mem_pool); |
| 1675 | phba->sysfs_mbox.mbox = NULL; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1680 | sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 1681 | char *buf, loff_t off, size_t count) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1682 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1683 | struct class_device *cdev = container_of(kobj, struct class_device, |
| 1684 | kobj); |
| 1685 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1686 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1687 | struct lpfc_hba *phba = vport->phba; |
| 1688 | struct lpfcMboxq *mbox = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1689 | |
| 1690 | if ((count + off) > MAILBOX_CMD_SIZE) |
| 1691 | return -ERANGE; |
| 1692 | |
| 1693 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 1694 | return -EINVAL; |
| 1695 | |
| 1696 | if (count == 0) |
| 1697 | return 0; |
| 1698 | |
| 1699 | if (off == 0) { |
| 1700 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1701 | if (!mbox) |
| 1702 | return -ENOMEM; |
James Smart | fc6c12b | 2006-03-07 15:04:19 -0500 | [diff] [blame] | 1703 | memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1704 | } |
| 1705 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1706 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1707 | |
| 1708 | if (off == 0) { |
| 1709 | if (phba->sysfs_mbox.mbox) |
| 1710 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1711 | else |
| 1712 | phba->sysfs_mbox.mbox = mbox; |
| 1713 | phba->sysfs_mbox.state = SMBOX_WRITING; |
| 1714 | } else { |
| 1715 | if (phba->sysfs_mbox.state != SMBOX_WRITING || |
| 1716 | phba->sysfs_mbox.offset != off || |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1717 | phba->sysfs_mbox.mbox == NULL) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1718 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1719 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1720 | return -EAGAIN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, |
| 1725 | buf, count); |
| 1726 | |
| 1727 | phba->sysfs_mbox.offset = off + count; |
| 1728 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1729 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | |
| 1731 | return count; |
| 1732 | } |
| 1733 | |
| 1734 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1735 | sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 1736 | char *buf, loff_t off, size_t count) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | struct class_device *cdev = container_of(kobj, struct class_device, |
| 1739 | kobj); |
| 1740 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 1741 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1742 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | int rc; |
| 1744 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1745 | if (off > MAILBOX_CMD_SIZE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | return -ERANGE; |
| 1747 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1748 | if ((count + off) > MAILBOX_CMD_SIZE) |
| 1749 | count = MAILBOX_CMD_SIZE - off; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | |
| 1751 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 1752 | return -EINVAL; |
| 1753 | |
| 1754 | if (off && count == 0) |
| 1755 | return 0; |
| 1756 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1757 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame^] | 1759 | if (phba->over_temp_state == HBA_OVER_TEMP) { |
| 1760 | sysfs_mbox_idle(phba); |
| 1761 | spin_unlock_irq(&phba->hbalock); |
| 1762 | return -EPERM; |
| 1763 | } |
| 1764 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1765 | if (off == 0 && |
| 1766 | phba->sysfs_mbox.state == SMBOX_WRITING && |
| 1767 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { |
| 1768 | |
| 1769 | switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { |
| 1770 | /* Offline only */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1771 | case MBX_INIT_LINK: |
| 1772 | case MBX_DOWN_LINK: |
| 1773 | case MBX_CONFIG_LINK: |
| 1774 | case MBX_CONFIG_RING: |
| 1775 | case MBX_RESET_RING: |
| 1776 | case MBX_UNREG_LOGIN: |
| 1777 | case MBX_CLEAR_LA: |
| 1778 | case MBX_DUMP_CONTEXT: |
| 1779 | case MBX_RUN_DIAGS: |
| 1780 | case MBX_RESTART: |
| 1781 | case MBX_FLASH_WR_ULA: |
| 1782 | case MBX_SET_MASK: |
| 1783 | case MBX_SET_SLIM: |
| 1784 | case MBX_SET_DEBUG: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1785 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | printk(KERN_WARNING "mbox_read:Command 0x%x " |
| 1787 | "is illegal in on-line state\n", |
| 1788 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1789 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1790 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | return -EPERM; |
| 1792 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1793 | case MBX_WRITE_NV: |
| 1794 | case MBX_WRITE_VPARMS: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | case MBX_LOAD_SM: |
| 1796 | case MBX_READ_NV: |
| 1797 | case MBX_READ_CONFIG: |
| 1798 | case MBX_READ_RCONFIG: |
| 1799 | case MBX_READ_STATUS: |
| 1800 | case MBX_READ_XRI: |
| 1801 | case MBX_READ_REV: |
| 1802 | case MBX_READ_LNK_STAT: |
| 1803 | case MBX_DUMP_MEMORY: |
| 1804 | case MBX_DOWN_LOAD: |
| 1805 | case MBX_UPDATE_CFG: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1806 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1807 | case MBX_LOAD_AREA: |
| 1808 | case MBX_LOAD_EXP_ROM: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1809 | case MBX_BEACON: |
| 1810 | case MBX_DEL_LD_ENTRY: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | break; |
| 1812 | case MBX_READ_SPARM64: |
| 1813 | case MBX_READ_LA: |
| 1814 | case MBX_READ_LA64: |
| 1815 | case MBX_REG_LOGIN: |
| 1816 | case MBX_REG_LOGIN64: |
| 1817 | case MBX_CONFIG_PORT: |
| 1818 | case MBX_RUN_BIU_DIAG: |
| 1819 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", |
| 1820 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1821 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1822 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | return -EPERM; |
| 1824 | default: |
| 1825 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", |
| 1826 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1827 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1828 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1829 | return -EPERM; |
| 1830 | } |
| 1831 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1832 | phba->sysfs_mbox.mbox->vport = vport; |
| 1833 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1834 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1835 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | spin_unlock_irq(&phba->hbalock); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1837 | return -EAGAIN; |
| 1838 | } |
| 1839 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1840 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ |
| 1842 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1843 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1844 | rc = lpfc_sli_issue_mbox (phba, |
| 1845 | phba->sysfs_mbox.mbox, |
| 1846 | MBX_POLL); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1847 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1848 | |
| 1849 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1850 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1851 | rc = lpfc_sli_issue_mbox_wait (phba, |
| 1852 | phba->sysfs_mbox.mbox, |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1853 | lpfc_mbox_tmo_val(phba, |
| 1854 | phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1855 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | if (rc != MBX_SUCCESS) { |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1859 | if (rc == MBX_TIMEOUT) { |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1860 | phba->sysfs_mbox.mbox = NULL; |
| 1861 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1862 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1863 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1864 | return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1865 | } |
| 1866 | phba->sysfs_mbox.state = SMBOX_READING; |
| 1867 | } |
| 1868 | else if (phba->sysfs_mbox.offset != off || |
| 1869 | phba->sysfs_mbox.state != SMBOX_READING) { |
| 1870 | printk(KERN_WARNING "mbox_read: Bad State\n"); |
| 1871 | sysfs_mbox_idle(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1872 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1873 | return -EAGAIN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); |
| 1877 | |
| 1878 | phba->sysfs_mbox.offset = off + count; |
| 1879 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1880 | if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1881 | sysfs_mbox_idle(phba); |
| 1882 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1883 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1884 | |
| 1885 | return count; |
| 1886 | } |
| 1887 | |
| 1888 | static struct bin_attribute sysfs_mbox_attr = { |
| 1889 | .attr = { |
| 1890 | .name = "mbox", |
| 1891 | .mode = S_IRUSR | S_IWUSR, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1892 | }, |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1893 | .size = MAILBOX_CMD_SIZE, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1894 | .read = sysfs_mbox_read, |
| 1895 | .write = sysfs_mbox_write, |
| 1896 | }; |
| 1897 | |
| 1898 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1899 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1900 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1901 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1902 | int error; |
| 1903 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1904 | error = sysfs_create_bin_file(&shost->shost_classdev.kobj, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1905 | &sysfs_ctlreg_attr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1906 | if (error) |
| 1907 | goto out; |
| 1908 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1909 | error = sysfs_create_bin_file(&shost->shost_classdev.kobj, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1910 | &sysfs_mbox_attr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1911 | if (error) |
| 1912 | goto out_remove_ctlreg_attr; |
| 1913 | |
| 1914 | return 0; |
| 1915 | out_remove_ctlreg_attr: |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1916 | sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1917 | out: |
| 1918 | return error; |
| 1919 | } |
| 1920 | |
| 1921 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1922 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1923 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1924 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1925 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1926 | sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr); |
| 1927 | sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | |
| 1931 | /* |
| 1932 | * Dynamic FC Host Attributes Support |
| 1933 | */ |
| 1934 | |
| 1935 | static void |
| 1936 | lpfc_get_host_port_id(struct Scsi_Host *shost) |
| 1937 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1938 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1939 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1940 | /* note: fc_myDID already in cpu endianness */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1941 | fc_host_port_id(shost) = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | static void |
| 1945 | lpfc_get_host_port_type(struct Scsi_Host *shost) |
| 1946 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1947 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1948 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1949 | |
| 1950 | spin_lock_irq(shost->host_lock); |
| 1951 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1952 | if (vport->port_type == LPFC_NPIV_PORT) { |
| 1953 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; |
| 1954 | } else if (lpfc_is_link_up(phba)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1955 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1956 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
| 1958 | else |
| 1959 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; |
| 1960 | } else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | if (vport->fc_flag & FC_FABRIC) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1962 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 1963 | else |
| 1964 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
| 1965 | } |
| 1966 | } else |
| 1967 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
| 1968 | |
| 1969 | spin_unlock_irq(shost->host_lock); |
| 1970 | } |
| 1971 | |
| 1972 | static void |
| 1973 | lpfc_get_host_port_state(struct Scsi_Host *shost) |
| 1974 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1975 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 1976 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | |
| 1978 | spin_lock_irq(shost->host_lock); |
| 1979 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1980 | if (vport->fc_flag & FC_OFFLINE_MODE) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1981 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
| 1982 | else { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1983 | switch (phba->link_state) { |
| 1984 | case LPFC_LINK_UNKNOWN: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1985 | case LPFC_LINK_DOWN: |
| 1986 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; |
| 1987 | break; |
| 1988 | case LPFC_LINK_UP: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1989 | case LPFC_CLEAR_LA: |
| 1990 | case LPFC_HBA_READY: |
| 1991 | /* Links up, beyond this port_type reports state */ |
| 1992 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 1993 | break; |
| 1994 | case LPFC_HBA_ERROR: |
| 1995 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; |
| 1996 | break; |
| 1997 | default: |
| 1998 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
| 1999 | break; |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | spin_unlock_irq(shost->host_lock); |
| 2004 | } |
| 2005 | |
| 2006 | static void |
| 2007 | lpfc_get_host_speed(struct Scsi_Host *shost) |
| 2008 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2009 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2010 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2011 | |
| 2012 | spin_lock_irq(shost->host_lock); |
| 2013 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2014 | if (lpfc_is_link_up(phba)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2015 | switch(phba->fc_linkspeed) { |
| 2016 | case LA_1GHZ_LINK: |
| 2017 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; |
| 2018 | break; |
| 2019 | case LA_2GHZ_LINK: |
| 2020 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; |
| 2021 | break; |
| 2022 | case LA_4GHZ_LINK: |
| 2023 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; |
| 2024 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2025 | case LA_8GHZ_LINK: |
| 2026 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; |
| 2027 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | default: |
| 2029 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
| 2030 | break; |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | spin_unlock_irq(shost->host_lock); |
| 2035 | } |
| 2036 | |
| 2037 | static void |
| 2038 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) |
| 2039 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2040 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2041 | struct lpfc_hba *phba = vport->phba; |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 2042 | u64 node_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | |
| 2044 | spin_lock_irq(shost->host_lock); |
| 2045 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2046 | if ((vport->fc_flag & FC_FABRIC) || |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2047 | ((phba->fc_topology == TOPOLOGY_LOOP) && |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2048 | (vport->fc_flag & FC_PUBLIC_LOOP))) |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 2049 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2050 | else |
| 2051 | /* fabric is local port if there is no F/FL_Port */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2052 | node_name = wwn_to_u64(vport->fc_nodename.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2053 | |
| 2054 | spin_unlock_irq(shost->host_lock); |
| 2055 | |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 2056 | fc_host_fabric_name(shost) = node_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2057 | } |
| 2058 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2059 | static struct fc_host_statistics * |
| 2060 | lpfc_get_stats(struct Scsi_Host *shost) |
| 2061 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2062 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2063 | struct lpfc_hba *phba = vport->phba; |
| 2064 | struct lpfc_sli *psli = &phba->sli; |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 2065 | struct fc_host_statistics *hs = &phba->link_stats; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2066 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2067 | LPFC_MBOXQ_t *pmboxq; |
| 2068 | MAILBOX_t *pmb; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2069 | unsigned long seconds; |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2070 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2071 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2072 | /* |
| 2073 | * prevent udev from issuing mailbox commands until the port is |
| 2074 | * configured. |
| 2075 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2076 | if (phba->link_state < LPFC_LINK_DOWN || |
| 2077 | !phba->mbox_mem_pool || |
| 2078 | (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2079 | return NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2080 | |
| 2081 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2082 | return NULL; |
| 2083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2084 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2085 | if (!pmboxq) |
| 2086 | return NULL; |
| 2087 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| 2088 | |
| 2089 | pmb = &pmboxq->mb; |
| 2090 | pmb->mbxCommand = MBX_READ_STATUS; |
| 2091 | pmb->mbxOwner = OWN_HOST; |
| 2092 | pmboxq->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2093 | pmboxq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2094 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2095 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2096 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2098 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 2100 | |
| 2101 | if (rc != MBX_SUCCESS) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2102 | if (rc != MBX_TIMEOUT) |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2103 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | return NULL; |
| 2105 | } |
| 2106 | |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 2107 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
| 2108 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2109 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
| 2110 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); |
| 2111 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; |
| 2112 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); |
| 2113 | |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2114 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2115 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
| 2116 | pmb->mbxOwner = OWN_HOST; |
| 2117 | pmboxq->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2118 | pmboxq->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2120 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2121 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 2123 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 2125 | |
| 2126 | if (rc != MBX_SUCCESS) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2127 | if (rc != MBX_TIMEOUT) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2128 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | return NULL; |
| 2130 | } |
| 2131 | |
| 2132 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; |
| 2133 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; |
| 2134 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; |
| 2135 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; |
| 2136 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; |
| 2137 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; |
| 2138 | hs->error_frames = pmb->un.varRdLnk.crcCnt; |
| 2139 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2140 | hs->link_failure_count -= lso->link_failure_count; |
| 2141 | hs->loss_of_sync_count -= lso->loss_of_sync_count; |
| 2142 | hs->loss_of_signal_count -= lso->loss_of_signal_count; |
| 2143 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; |
| 2144 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; |
| 2145 | hs->invalid_crc_count -= lso->invalid_crc_count; |
| 2146 | hs->error_frames -= lso->error_frames; |
| 2147 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 2149 | hs->lip_count = (phba->fc_eventTag >> 1); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2150 | hs->lip_count -= lso->link_events; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2151 | hs->nos_count = -1; |
| 2152 | } else { |
| 2153 | hs->lip_count = -1; |
| 2154 | hs->nos_count = (phba->fc_eventTag >> 1); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2155 | hs->nos_count -= lso->link_events; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | hs->dumped_frames = -1; |
| 2159 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2160 | seconds = get_seconds(); |
| 2161 | if (seconds < psli->stats_start) |
| 2162 | hs->seconds_since_last_reset = seconds + |
| 2163 | ((unsigned long)-1 - psli->stats_start); |
| 2164 | else |
| 2165 | hs->seconds_since_last_reset = seconds - psli->stats_start; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2166 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2167 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 2168 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2169 | return hs; |
| 2170 | } |
| 2171 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2172 | static void |
| 2173 | lpfc_reset_stats(struct Scsi_Host *shost) |
| 2174 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2175 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2176 | struct lpfc_hba *phba = vport->phba; |
| 2177 | struct lpfc_sli *psli = &phba->sli; |
| 2178 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2179 | LPFC_MBOXQ_t *pmboxq; |
| 2180 | MAILBOX_t *pmb; |
| 2181 | int rc = 0; |
| 2182 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2183 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 2184 | return; |
| 2185 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2186 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2187 | if (!pmboxq) |
| 2188 | return; |
| 2189 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 2190 | |
| 2191 | pmb = &pmboxq->mb; |
| 2192 | pmb->mbxCommand = MBX_READ_STATUS; |
| 2193 | pmb->mbxOwner = OWN_HOST; |
| 2194 | pmb->un.varWords[0] = 0x1; /* reset request */ |
| 2195 | pmboxq->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2196 | pmboxq->vport = vport; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2197 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2198 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2199 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| 2200 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 2201 | else |
| 2202 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 2203 | |
| 2204 | if (rc != MBX_SUCCESS) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2205 | if (rc != MBX_TIMEOUT) |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2206 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 2207 | return; |
| 2208 | } |
| 2209 | |
| 2210 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 2211 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
| 2212 | pmb->mbxOwner = OWN_HOST; |
| 2213 | pmboxq->context1 = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2214 | pmboxq->vport = vport; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2215 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2216 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2217 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| 2218 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 2219 | else |
| 2220 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 2221 | |
| 2222 | if (rc != MBX_SUCCESS) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2223 | if (rc != MBX_TIMEOUT) |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2224 | mempool_free( pmboxq, phba->mbox_mem_pool); |
| 2225 | return; |
| 2226 | } |
| 2227 | |
| 2228 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; |
| 2229 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; |
| 2230 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; |
| 2231 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; |
| 2232 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; |
| 2233 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; |
| 2234 | lso->error_frames = pmb->un.varRdLnk.crcCnt; |
| 2235 | lso->link_events = (phba->fc_eventTag >> 1); |
| 2236 | |
| 2237 | psli->stats_start = get_seconds(); |
| 2238 | |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2239 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 2240 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2241 | return; |
| 2242 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2243 | |
| 2244 | /* |
| 2245 | * The LPFC driver treats linkdown handling as target loss events so there |
| 2246 | * are no sysfs handlers for link_down_tmo. |
| 2247 | */ |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2248 | |
| 2249 | static struct lpfc_nodelist * |
| 2250 | lpfc_get_node_by_target(struct scsi_target *starget) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2252 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2253 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2254 | struct lpfc_nodelist *ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2255 | |
| 2256 | spin_lock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2257 | /* Search for this, mapped, target ID */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2258 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2259 | if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && |
| 2260 | starget->id == ndlp->nlp_sid) { |
| 2261 | spin_unlock_irq(shost->host_lock); |
| 2262 | return ndlp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2263 | } |
| 2264 | } |
| 2265 | spin_unlock_irq(shost->host_lock); |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2266 | return NULL; |
| 2267 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2268 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2269 | static void |
| 2270 | lpfc_get_starget_port_id(struct scsi_target *starget) |
| 2271 | { |
| 2272 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
| 2273 | |
| 2274 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | static void |
| 2278 | lpfc_get_starget_node_name(struct scsi_target *starget) |
| 2279 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2280 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2281 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2282 | fc_starget_node_name(starget) = |
| 2283 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | static void |
| 2287 | lpfc_get_starget_port_name(struct scsi_target *starget) |
| 2288 | { |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2289 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2290 | |
James Smart | 685f0bf | 2007-04-25 09:53:08 -0400 | [diff] [blame] | 2291 | fc_starget_port_name(starget) = |
| 2292 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | static void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2296 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) |
| 2297 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2298 | if (timeout) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2299 | rport->dev_loss_tmo = timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | else |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2301 | rport->dev_loss_tmo = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | |
| 2305 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
| 2306 | static ssize_t \ |
| 2307 | lpfc_show_rport_##field (struct class_device *cdev, char *buf) \ |
| 2308 | { \ |
| 2309 | struct fc_rport *rport = transport_class_to_rport(cdev); \ |
| 2310 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
| 2311 | return snprintf(buf, sz, format_string, \ |
| 2312 | (rdata->target) ? cast rdata->target->field : 0); \ |
| 2313 | } |
| 2314 | |
| 2315 | #define lpfc_rport_rd_attr(field, format_string, sz) \ |
| 2316 | lpfc_rport_show_function(field, format_string, sz, ) \ |
| 2317 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) |
| 2318 | |
| 2319 | |
| 2320 | struct fc_function_template lpfc_transport_functions = { |
| 2321 | /* fixed attributes the driver supports */ |
| 2322 | .show_host_node_name = 1, |
| 2323 | .show_host_port_name = 1, |
| 2324 | .show_host_supported_classes = 1, |
| 2325 | .show_host_supported_fc4s = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2326 | .show_host_supported_speeds = 1, |
| 2327 | .show_host_maxframe_size = 1, |
| 2328 | |
| 2329 | /* dynamic attributes the driver supports */ |
| 2330 | .get_host_port_id = lpfc_get_host_port_id, |
| 2331 | .show_host_port_id = 1, |
| 2332 | |
| 2333 | .get_host_port_type = lpfc_get_host_port_type, |
| 2334 | .show_host_port_type = 1, |
| 2335 | |
| 2336 | .get_host_port_state = lpfc_get_host_port_state, |
| 2337 | .show_host_port_state = 1, |
| 2338 | |
| 2339 | /* active_fc4s is shown but doesn't change (thus no get function) */ |
| 2340 | .show_host_active_fc4s = 1, |
| 2341 | |
| 2342 | .get_host_speed = lpfc_get_host_speed, |
| 2343 | .show_host_speed = 1, |
| 2344 | |
| 2345 | .get_host_fabric_name = lpfc_get_host_fabric_name, |
| 2346 | .show_host_fabric_name = 1, |
| 2347 | |
| 2348 | /* |
| 2349 | * The LPFC driver treats linkdown handling as target loss events |
| 2350 | * so there are no sysfs handlers for link_down_tmo. |
| 2351 | */ |
| 2352 | |
| 2353 | .get_fc_host_stats = lpfc_get_stats, |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 2354 | .reset_fc_host_stats = lpfc_reset_stats, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | |
| 2356 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), |
| 2357 | .show_rport_maxframe_size = 1, |
| 2358 | .show_rport_supported_classes = 1, |
| 2359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
| 2361 | .show_rport_dev_loss_tmo = 1, |
| 2362 | |
| 2363 | .get_starget_port_id = lpfc_get_starget_port_id, |
| 2364 | .show_starget_port_id = 1, |
| 2365 | |
| 2366 | .get_starget_node_name = lpfc_get_starget_node_name, |
| 2367 | .show_starget_node_name = 1, |
| 2368 | |
| 2369 | .get_starget_port_name = lpfc_get_starget_port_name, |
| 2370 | .show_starget_port_name = 1, |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 2371 | |
| 2372 | .issue_fc_host_lip = lpfc_issue_lip, |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame] | 2373 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
| 2374 | .terminate_rport_io = lpfc_terminate_rport_io, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2375 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2376 | .dd_fcvport_size = sizeof(struct lpfc_vport *), |
| 2377 | }; |
| 2378 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2379 | struct fc_function_template lpfc_vport_transport_functions = { |
| 2380 | /* fixed attributes the driver supports */ |
| 2381 | .show_host_node_name = 1, |
| 2382 | .show_host_port_name = 1, |
| 2383 | .show_host_supported_classes = 1, |
| 2384 | .show_host_supported_fc4s = 1, |
| 2385 | .show_host_supported_speeds = 1, |
| 2386 | .show_host_maxframe_size = 1, |
| 2387 | |
| 2388 | /* dynamic attributes the driver supports */ |
| 2389 | .get_host_port_id = lpfc_get_host_port_id, |
| 2390 | .show_host_port_id = 1, |
| 2391 | |
| 2392 | .get_host_port_type = lpfc_get_host_port_type, |
| 2393 | .show_host_port_type = 1, |
| 2394 | |
| 2395 | .get_host_port_state = lpfc_get_host_port_state, |
| 2396 | .show_host_port_state = 1, |
| 2397 | |
| 2398 | /* active_fc4s is shown but doesn't change (thus no get function) */ |
| 2399 | .show_host_active_fc4s = 1, |
| 2400 | |
| 2401 | .get_host_speed = lpfc_get_host_speed, |
| 2402 | .show_host_speed = 1, |
| 2403 | |
| 2404 | .get_host_fabric_name = lpfc_get_host_fabric_name, |
| 2405 | .show_host_fabric_name = 1, |
| 2406 | |
| 2407 | /* |
| 2408 | * The LPFC driver treats linkdown handling as target loss events |
| 2409 | * so there are no sysfs handlers for link_down_tmo. |
| 2410 | */ |
| 2411 | |
| 2412 | .get_fc_host_stats = lpfc_get_stats, |
| 2413 | .reset_fc_host_stats = lpfc_reset_stats, |
| 2414 | |
| 2415 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), |
| 2416 | .show_rport_maxframe_size = 1, |
| 2417 | .show_rport_supported_classes = 1, |
| 2418 | |
| 2419 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
| 2420 | .show_rport_dev_loss_tmo = 1, |
| 2421 | |
| 2422 | .get_starget_port_id = lpfc_get_starget_port_id, |
| 2423 | .show_starget_port_id = 1, |
| 2424 | |
| 2425 | .get_starget_node_name = lpfc_get_starget_node_name, |
| 2426 | .show_starget_node_name = 1, |
| 2427 | |
| 2428 | .get_starget_port_name = lpfc_get_starget_port_name, |
| 2429 | .show_starget_port_name = 1, |
| 2430 | |
| 2431 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
| 2432 | .terminate_rport_io = lpfc_terminate_rport_io, |
| 2433 | |
| 2434 | .vport_disable = lpfc_vport_disable, |
| 2435 | }; |
| 2436 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | void |
| 2438 | lpfc_get_cfgparam(struct lpfc_hba *phba) |
| 2439 | { |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 2440 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
| 2441 | lpfc_cr_count_init(phba, lpfc_cr_count); |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 2442 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 2443 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); |
| 2444 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 2445 | lpfc_ack0_init(phba, lpfc_ack0); |
| 2446 | lpfc_topology_init(phba, lpfc_topology); |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 2447 | lpfc_link_speed_init(phba, lpfc_link_speed); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2448 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 2449 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2450 | lpfc_use_msi_init(phba, lpfc_use_msi); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2451 | phba->cfg_poll = lpfc_poll; |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 2452 | phba->cfg_soft_wwnn = 0L; |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 2453 | phba->cfg_soft_wwpn = 0L; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | /* |
| 2455 | * The total number of segments is the configuration value plus 2 |
| 2456 | * since the IOCB need a command and response bde. |
| 2457 | */ |
| 2458 | phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | /* |
| 2460 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 2461 | * used to create the sg_dma_buf_pool must be dynamically calculated |
| 2462 | */ |
| 2463 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 2464 | sizeof(struct fcp_rsp) + |
| 2465 | (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64)); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 2466 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2467 | return; |
| 2468 | } |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 2469 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2470 | void |
| 2471 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) |
| 2472 | { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2473 | lpfc_log_verbose_init(vport, lpfc_log_verbose); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2474 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); |
| 2475 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); |
| 2476 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); |
| 2477 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); |
| 2478 | lpfc_restrict_login_init(vport, lpfc_restrict_login); |
| 2479 | lpfc_fcp_class_init(vport, lpfc_fcp_class); |
| 2480 | lpfc_use_adisc_init(vport, lpfc_use_adisc); |
| 2481 | lpfc_fdmi_on_init(vport, lpfc_fdmi_on); |
| 2482 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); |
| 2483 | lpfc_max_luns_init(vport, lpfc_max_luns); |
| 2484 | lpfc_scan_down_init(vport, lpfc_scan_down); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 2485 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2486 | return; |
| 2487 | } |