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