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