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