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