| 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. * |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2006 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> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 26 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 27 | #include <scsi/scsi_device.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_tcq.h> |
| 30 | #include <scsi/scsi_transport_fc.h> |
| 31 | |
| 32 | #include "lpfc_hw.h" |
| 33 | #include "lpfc_sli.h" |
| 34 | #include "lpfc_disc.h" |
| 35 | #include "lpfc_scsi.h" |
| 36 | #include "lpfc.h" |
| 37 | #include "lpfc_logmsg.h" |
| 38 | #include "lpfc_version.h" |
| 39 | #include "lpfc_compat.h" |
| 40 | #include "lpfc_crtn.h" |
| 41 | |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 42 | #define LPFC_DEF_DEVLOSS_TMO 30 |
| 43 | #define LPFC_MIN_DEVLOSS_TMO 1 |
| 44 | #define LPFC_MAX_DEVLOSS_TMO 255 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | |
| 46 | static void |
| 47 | lpfc_jedec_to_ascii(int incr, char hdw[]) |
| 48 | { |
| 49 | int i, j; |
| 50 | for (i = 0; i < 8; i++) { |
| 51 | j = (incr & 0xf); |
| 52 | if (j <= 9) |
| 53 | hdw[7 - i] = 0x30 + j; |
| 54 | else |
| 55 | hdw[7 - i] = 0x61 + j - 10; |
| 56 | incr = (incr >> 4); |
| 57 | } |
| 58 | hdw[8] = 0; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | static ssize_t |
| 63 | lpfc_drvr_version_show(struct class_device *cdev, char *buf) |
| 64 | { |
| 65 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); |
| 66 | } |
| 67 | |
| 68 | static ssize_t |
| 69 | management_version_show(struct class_device *cdev, char *buf) |
| 70 | { |
| 71 | return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n"); |
| 72 | } |
| 73 | |
| 74 | static ssize_t |
| 75 | lpfc_info_show(struct class_device *cdev, char *buf) |
| 76 | { |
| 77 | struct Scsi_Host *host = class_to_shost(cdev); |
| 78 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); |
| 79 | } |
| 80 | |
| 81 | static ssize_t |
| 82 | lpfc_serialnum_show(struct class_device *cdev, char *buf) |
| 83 | { |
| 84 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 85 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
| 87 | } |
| 88 | |
| 89 | static ssize_t |
| 90 | lpfc_modeldesc_show(struct class_device *cdev, char *buf) |
| 91 | { |
| 92 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 93 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 94 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
| 95 | } |
| 96 | |
| 97 | static ssize_t |
| 98 | lpfc_modelname_show(struct class_device *cdev, char *buf) |
| 99 | { |
| 100 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 101 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
| 103 | } |
| 104 | |
| 105 | static ssize_t |
| 106 | lpfc_programtype_show(struct class_device *cdev, char *buf) |
| 107 | { |
| 108 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 109 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
| 111 | } |
| 112 | |
| 113 | static ssize_t |
| 114 | lpfc_portnum_show(struct class_device *cdev, char *buf) |
| 115 | { |
| 116 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 117 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
| 119 | } |
| 120 | |
| 121 | static ssize_t |
| 122 | lpfc_fwrev_show(struct class_device *cdev, char *buf) |
| 123 | { |
| 124 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 125 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 126 | char fwrev[32]; |
| 127 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
| 128 | return snprintf(buf, PAGE_SIZE, "%s\n",fwrev); |
| 129 | } |
| 130 | |
| 131 | static ssize_t |
| 132 | lpfc_hdw_show(struct class_device *cdev, char *buf) |
| 133 | { |
| 134 | char hdw[9]; |
| 135 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 136 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | lpfc_vpd_t *vp = &phba->vpd; |
| 138 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
| 139 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); |
| 140 | } |
| 141 | static ssize_t |
| 142 | lpfc_option_rom_version_show(struct class_device *cdev, char *buf) |
| 143 | { |
| 144 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 145 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); |
| 147 | } |
| 148 | static ssize_t |
| 149 | lpfc_state_show(struct class_device *cdev, char *buf) |
| 150 | { |
| 151 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 152 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 153 | int len = 0; |
| 154 | switch (phba->hba_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 155 | case LPFC_STATE_UNKNOWN: |
| 156 | case LPFC_WARM_START: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | case LPFC_INIT_START: |
| 158 | case LPFC_INIT_MBX_CMDS: |
| 159 | case LPFC_LINK_DOWN: |
| 160 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); |
| 161 | break; |
| 162 | case LPFC_LINK_UP: |
| 163 | case LPFC_LOCAL_CFG_LINK: |
| 164 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n"); |
| 165 | break; |
| 166 | case LPFC_FLOGI: |
| 167 | case LPFC_FABRIC_CFG_LINK: |
| 168 | case LPFC_NS_REG: |
| 169 | case LPFC_NS_QRY: |
| 170 | case LPFC_BUILD_DISC_LIST: |
| 171 | case LPFC_DISC_AUTH: |
| 172 | case LPFC_CLEAR_LA: |
| 173 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 174 | "Link Up - Discovery\n"); |
| 175 | break; |
| 176 | case LPFC_HBA_READY: |
| 177 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 178 | "Link Up - Ready:\n"); |
| 179 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 180 | if (phba->fc_flag & FC_PUBLIC_LOOP) |
| 181 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 182 | " Public Loop\n"); |
| 183 | else |
| 184 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 185 | " Private Loop\n"); |
| 186 | } else { |
| 187 | if (phba->fc_flag & FC_FABRIC) |
| 188 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 189 | " Fabric\n"); |
| 190 | else |
| 191 | len += snprintf(buf + len, PAGE_SIZE-len, |
| 192 | " Point-2-Point\n"); |
| 193 | } |
| 194 | } |
| 195 | return len; |
| 196 | } |
| 197 | |
| 198 | static ssize_t |
| 199 | lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) |
| 200 | { |
| 201 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 202 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt + |
| 204 | phba->fc_unmap_cnt); |
| 205 | } |
| 206 | |
| 207 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 208 | static int |
| 209 | lpfc_issue_lip(struct Scsi_Host *host) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 211 | struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | LPFC_MBOXQ_t *pmboxq; |
| 213 | int mbxstatus = MBXERR_ERROR; |
| 214 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
| 216 | (phba->hba_state != LPFC_HBA_READY)) |
| 217 | return -EPERM; |
| 218 | |
| 219 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 220 | |
| 221 | if (!pmboxq) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 225 | pmboxq->mb.mbxCommand = MBX_DOWN_LINK; |
| 226 | pmboxq->mb.mbxOwner = OWN_HOST; |
| 227 | |
James Smart | 33ccf8d | 2006-08-17 11:57:58 -0400 | [diff] [blame] | 228 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 229 | |
James Smart | 4db621e | 2006-07-06 15:49:49 -0400 | [diff] [blame] | 230 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) { |
| 231 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| 232 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, |
| 233 | phba->cfg_link_speed); |
| 234 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, |
| 235 | phba->fc_ratov * 2); |
| 236 | } |
| 237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | if (mbxstatus == MBX_TIMEOUT) |
| 239 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 240 | else |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 241 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | |
| 243 | if (mbxstatus == MBXERR_ERROR) |
| 244 | return -EIO; |
| 245 | |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 246 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | } |
| 248 | |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 249 | static int |
| 250 | lpfc_selective_reset(struct lpfc_hba *phba) |
| 251 | { |
| 252 | struct completion online_compl; |
| 253 | int status = 0; |
| 254 | |
| 255 | init_completion(&online_compl); |
| 256 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 257 | LPFC_EVT_OFFLINE); |
| 258 | wait_for_completion(&online_compl); |
| 259 | |
| 260 | if (status != 0) |
| 261 | return -EIO; |
| 262 | |
| 263 | init_completion(&online_compl); |
| 264 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 265 | LPFC_EVT_ONLINE); |
| 266 | wait_for_completion(&online_compl); |
| 267 | |
| 268 | if (status != 0) |
| 269 | return -EIO; |
| 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static ssize_t |
| 275 | lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count) |
| 276 | { |
| 277 | struct Scsi_Host *host = class_to_shost(cdev); |
| 278 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| 279 | int status = -EINVAL; |
| 280 | |
| 281 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) |
| 282 | status = lpfc_selective_reset(phba); |
| 283 | |
| 284 | if (status == 0) |
| 285 | return strlen(buf); |
| 286 | else |
| 287 | return status; |
| 288 | } |
| 289 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | static ssize_t |
| 291 | lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) |
| 292 | { |
| 293 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 294 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 295 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
| 296 | } |
| 297 | |
| 298 | static ssize_t |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 299 | lpfc_board_mode_show(struct class_device *cdev, char *buf) |
| 300 | { |
| 301 | struct Scsi_Host *host = class_to_shost(cdev); |
| 302 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| 303 | char * state; |
| 304 | |
| 305 | if (phba->hba_state == LPFC_HBA_ERROR) |
| 306 | state = "error"; |
| 307 | else if (phba->hba_state == LPFC_WARM_START) |
| 308 | state = "warm start"; |
| 309 | else if (phba->hba_state == LPFC_INIT_START) |
| 310 | state = "offline"; |
| 311 | else |
| 312 | state = "online"; |
| 313 | |
| 314 | return snprintf(buf, PAGE_SIZE, "%s\n", state); |
| 315 | } |
| 316 | |
| 317 | static ssize_t |
| 318 | lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count) |
| 319 | { |
| 320 | struct Scsi_Host *host = class_to_shost(cdev); |
| 321 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| 322 | struct completion online_compl; |
| 323 | int status=0; |
| 324 | |
| 325 | init_completion(&online_compl); |
| 326 | |
| 327 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) |
| 328 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 329 | LPFC_EVT_ONLINE); |
| 330 | else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) |
| 331 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 332 | LPFC_EVT_OFFLINE); |
| 333 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
| 334 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 335 | LPFC_EVT_WARM_START); |
| 336 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) |
| 337 | lpfc_workq_post_event(phba, &status, &online_compl, |
| 338 | LPFC_EVT_KILL); |
| 339 | else |
| 340 | return -EINVAL; |
| 341 | |
| 342 | wait_for_completion(&online_compl); |
| 343 | |
| 344 | if (!status) |
| 345 | return strlen(buf); |
| 346 | else |
| 347 | return -EIO; |
| 348 | } |
| 349 | |
| 350 | static ssize_t |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 351 | lpfc_poll_show(struct class_device *cdev, char *buf) |
| 352 | { |
| 353 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 354 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 355 | |
| 356 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); |
| 357 | } |
| 358 | |
| 359 | static ssize_t |
| 360 | lpfc_poll_store(struct class_device *cdev, const char *buf, |
| 361 | size_t count) |
| 362 | { |
| 363 | struct Scsi_Host *host = class_to_shost(cdev); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 364 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 365 | uint32_t creg_val; |
| 366 | uint32_t old_val; |
| 367 | int val=0; |
| 368 | |
| 369 | if (!isdigit(buf[0])) |
| 370 | return -EINVAL; |
| 371 | |
| 372 | if (sscanf(buf, "%i", &val) != 1) |
| 373 | return -EINVAL; |
| 374 | |
| 375 | if ((val & 0x3) != val) |
| 376 | return -EINVAL; |
| 377 | |
| 378 | spin_lock_irq(phba->host->host_lock); |
| 379 | |
| 380 | old_val = phba->cfg_poll; |
| 381 | |
| 382 | if (val & ENABLE_FCP_RING_POLLING) { |
| 383 | if ((val & DISABLE_FCP_RING_INT) && |
| 384 | !(old_val & DISABLE_FCP_RING_INT)) { |
| 385 | creg_val = readl(phba->HCregaddr); |
| 386 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
| 387 | writel(creg_val, phba->HCregaddr); |
| 388 | readl(phba->HCregaddr); /* flush */ |
| 389 | |
| 390 | lpfc_poll_start_timer(phba); |
| 391 | } |
| 392 | } else if (val != 0x0) { |
| 393 | spin_unlock_irq(phba->host->host_lock); |
| 394 | return -EINVAL; |
| 395 | } |
| 396 | |
| 397 | if (!(val & DISABLE_FCP_RING_INT) && |
| 398 | (old_val & DISABLE_FCP_RING_INT)) |
| 399 | { |
| 400 | spin_unlock_irq(phba->host->host_lock); |
| 401 | del_timer(&phba->fcp_poll_timer); |
| 402 | spin_lock_irq(phba->host->host_lock); |
| 403 | creg_val = readl(phba->HCregaddr); |
| 404 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
| 405 | writel(creg_val, phba->HCregaddr); |
| 406 | readl(phba->HCregaddr); /* flush */ |
| 407 | } |
| 408 | |
| 409 | phba->cfg_poll = val; |
| 410 | |
| 411 | spin_unlock_irq(phba->host->host_lock); |
| 412 | |
| 413 | return strlen(buf); |
| 414 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | |
| 416 | #define lpfc_param_show(attr) \ |
| 417 | static ssize_t \ |
| 418 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 419 | { \ |
| 420 | struct Scsi_Host *host = class_to_shost(cdev);\ |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 421 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | int val = 0;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 423 | val = phba->cfg_##attr;\ |
| 424 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
| 425 | phba->cfg_##attr);\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | } |
| 427 | |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 428 | #define lpfc_param_hex_show(attr) \ |
| 429 | static ssize_t \ |
| 430 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ |
| 431 | { \ |
| 432 | struct Scsi_Host *host = class_to_shost(cdev);\ |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 433 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 434 | int val = 0;\ |
| 435 | val = phba->cfg_##attr;\ |
| 436 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ |
| 437 | phba->cfg_##attr);\ |
| 438 | } |
| 439 | |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 440 | #define lpfc_param_init(attr, default, minval, maxval) \ |
| 441 | static int \ |
| 442 | lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ |
| 443 | { \ |
| 444 | if (val >= minval && val <= maxval) {\ |
| 445 | phba->cfg_##attr = val;\ |
| 446 | return 0;\ |
| 447 | }\ |
| 448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
| 449 | "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 450 | "allowed range is ["#minval", "#maxval"]\n", \ |
| 451 | phba->brd_no, val); \ |
| 452 | phba->cfg_##attr = default;\ |
| 453 | return -EINVAL;\ |
| 454 | } |
| 455 | |
| 456 | #define lpfc_param_set(attr, default, minval, maxval) \ |
| 457 | static int \ |
| 458 | lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ |
| 459 | { \ |
| 460 | if (val >= minval && val <= maxval) {\ |
| 461 | phba->cfg_##attr = val;\ |
| 462 | return 0;\ |
| 463 | }\ |
| 464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
| 465 | "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 466 | "allowed range is ["#minval", "#maxval"]\n", \ |
| 467 | phba->brd_no, val); \ |
| 468 | return -EINVAL;\ |
| 469 | } |
| 470 | |
| 471 | #define lpfc_param_store(attr) \ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | static ssize_t \ |
| 473 | lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ |
| 474 | { \ |
| 475 | struct Scsi_Host *host = class_to_shost(cdev);\ |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 476 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 477 | int val=0;\ |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 478 | if (!isdigit(buf[0]))\ |
| 479 | return -EINVAL;\ |
| 480 | if (sscanf(buf, "%i", &val) != 1)\ |
| 481 | return -EINVAL;\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 482 | if (lpfc_##attr##_set(phba, val) == 0) \ |
James.Smart@Emulex.Com | 755c0d0 | 2005-10-28 20:29:06 -0400 | [diff] [blame] | 483 | return strlen(buf);\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 484 | else \ |
| 485 | return -EINVAL;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | } |
| 487 | |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 488 | #define LPFC_ATTR(name, defval, minval, maxval, desc) \ |
| 489 | static int lpfc_##name = defval;\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | module_param(lpfc_##name, int, 0);\ |
| 491 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 492 | lpfc_param_init(name, defval, minval, maxval) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 493 | |
| 494 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ |
| 495 | static int lpfc_##name = defval;\ |
| 496 | module_param(lpfc_##name, int, 0);\ |
| 497 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 498 | lpfc_param_show(name)\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 499 | lpfc_param_init(name, defval, minval, maxval)\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 501 | |
| 502 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ |
| 503 | static int lpfc_##name = defval;\ |
| 504 | module_param(lpfc_##name, int, 0);\ |
| 505 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 506 | lpfc_param_show(name)\ |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 507 | lpfc_param_init(name, defval, minval, maxval)\ |
| 508 | lpfc_param_set(name, defval, minval, maxval)\ |
| 509 | lpfc_param_store(name)\ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 510 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 511 | lpfc_##name##_show, lpfc_##name##_store) |
| 512 | |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 513 | #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ |
| 514 | static int lpfc_##name = defval;\ |
| 515 | module_param(lpfc_##name, int, 0);\ |
| 516 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 517 | lpfc_param_hex_show(name)\ |
| 518 | lpfc_param_init(name, defval, minval, maxval)\ |
| 519 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
| 520 | |
| 521 | #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ |
| 522 | static int lpfc_##name = defval;\ |
| 523 | module_param(lpfc_##name, int, 0);\ |
| 524 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
| 525 | lpfc_param_hex_show(name)\ |
| 526 | lpfc_param_init(name, defval, minval, maxval)\ |
| 527 | lpfc_param_set(name, defval, minval, maxval)\ |
| 528 | lpfc_param_store(name)\ |
| 529 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
| 530 | lpfc_##name##_show, lpfc_##name##_store) |
| 531 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 532 | static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); |
| 533 | static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); |
| 534 | static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); |
| 535 | static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); |
| 536 | static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); |
| 537 | static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL); |
| 538 | static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); |
| 539 | static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); |
| 540 | static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); |
| 541 | static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO, |
| 542 | lpfc_option_rom_version_show, NULL); |
| 543 | static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO, |
| 544 | lpfc_num_discovered_ports_show, NULL); |
| 545 | static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
| 546 | static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, |
| 547 | NULL); |
| 548 | static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show, |
| 549 | NULL); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 550 | static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, |
| 551 | lpfc_board_mode_show, lpfc_board_mode_store); |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 552 | static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 553 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 554 | static int lpfc_poll = 0; |
| 555 | module_param(lpfc_poll, int, 0); |
| 556 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" |
| 557 | " 0 - none," |
| 558 | " 1 - poll with interrupts enabled" |
| 559 | " 3 - poll and disable FCP ring interrupts"); |
| 560 | |
| 561 | static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
| 562 | lpfc_poll_show, lpfc_poll_store); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 563 | |
| 564 | /* |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 565 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear |
| 566 | # until the timer expires. Value range is [0,255]. Default value is 30. |
| 567 | */ |
| 568 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
| 569 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; |
| 570 | module_param(lpfc_nodev_tmo, int, 0); |
| 571 | MODULE_PARM_DESC(lpfc_nodev_tmo, |
| 572 | "Seconds driver will hold I/O waiting " |
| 573 | "for a device to come back"); |
| 574 | static ssize_t |
| 575 | lpfc_nodev_tmo_show(struct class_device *cdev, char *buf) |
| 576 | { |
| 577 | struct Scsi_Host *host = class_to_shost(cdev); |
| 578 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| 579 | int val = 0; |
| 580 | val = phba->cfg_devloss_tmo; |
| 581 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 582 | phba->cfg_devloss_tmo); |
| 583 | } |
| 584 | |
| 585 | static int |
| 586 | lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val) |
| 587 | { |
| 588 | static int warned; |
| 589 | if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { |
| 590 | phba->cfg_nodev_tmo = phba->cfg_devloss_tmo; |
| 591 | if (!warned && val != LPFC_DEF_DEVLOSS_TMO) { |
| 592 | warned = 1; |
| 593 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 594 | "%d:0402 Ignoring nodev_tmo module " |
| 595 | "parameter because devloss_tmo is" |
| 596 | " set.\n", |
| 597 | phba->brd_no); |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
| 603 | phba->cfg_nodev_tmo = val; |
| 604 | phba->cfg_devloss_tmo = val; |
| 605 | return 0; |
| 606 | } |
| 607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 608 | "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, " |
| 609 | "allowed range is [%d, %d]\n", |
| 610 | phba->brd_no, val, |
| 611 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
| 612 | phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
| 613 | return -EINVAL; |
| 614 | } |
| 615 | |
| 616 | static int |
| 617 | lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val) |
| 618 | { |
| 619 | if (phba->dev_loss_tmo_changed || |
| 620 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { |
| 621 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 622 | "%d:0401 Ignoring change to nodev_tmo " |
| 623 | "because devloss_tmo is set.\n", |
| 624 | phba->brd_no); |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
| 629 | phba->cfg_nodev_tmo = val; |
| 630 | phba->cfg_devloss_tmo = val; |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 635 | "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, " |
| 636 | "allowed range is [%d, %d]\n", |
| 637 | phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO, |
| 638 | LPFC_MAX_DEVLOSS_TMO); |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | |
| 642 | lpfc_param_store(nodev_tmo) |
| 643 | |
| 644 | static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
| 645 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); |
| 646 | |
| 647 | /* |
| 648 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that |
| 649 | # disappear until the timer expires. Value range is [0,255]. Default |
| 650 | # value is 30. |
| 651 | */ |
| 652 | module_param(lpfc_devloss_tmo, int, 0); |
| 653 | MODULE_PARM_DESC(lpfc_devloss_tmo, |
| 654 | "Seconds driver will hold I/O waiting " |
| 655 | "for a device to come back"); |
| 656 | lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
| 657 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) |
| 658 | lpfc_param_show(devloss_tmo) |
| 659 | static int |
| 660 | lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val) |
| 661 | { |
| 662 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
| 663 | phba->cfg_nodev_tmo = val; |
| 664 | phba->cfg_devloss_tmo = val; |
| 665 | phba->dev_loss_tmo_changed = 1; |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 670 | "%d:0404 lpfc_devloss_tmo attribute cannot be set to" |
| 671 | " %d, allowed range is [%d, %d]\n", |
| 672 | phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO, |
| 673 | LPFC_MAX_DEVLOSS_TMO); |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
| 677 | lpfc_param_store(devloss_tmo) |
| 678 | static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
| 679 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); |
| 680 | |
| 681 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 682 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being |
| 683 | # deluged with LOTS of information. |
| 684 | # You can set a bit mask to record specific types of verbose messages: |
| 685 | # |
| 686 | # LOG_ELS 0x1 ELS events |
| 687 | # LOG_DISCOVERY 0x2 Link discovery events |
| 688 | # LOG_MBOX 0x4 Mailbox events |
| 689 | # LOG_INIT 0x8 Initialization events |
| 690 | # LOG_LINK_EVENT 0x10 Link events |
| 691 | # LOG_IP 0x20 IP traffic history |
| 692 | # LOG_FCP 0x40 FCP traffic history |
| 693 | # LOG_NODE 0x80 Node table events |
| 694 | # LOG_MISC 0x400 Miscellaneous events |
| 695 | # LOG_SLI 0x800 SLI events |
| 696 | # LOG_CHK_COND 0x1000 FCP Check condition flag |
| 697 | # LOG_LIBDFC 0x2000 LIBDFC events |
| 698 | # LOG_ALL_MSG 0xffff LOG all messages |
| 699 | */ |
James.Smart@Emulex.Com | 93a20f7 | 2005-10-28 20:29:32 -0400 | [diff] [blame] | 700 | LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 701 | |
| 702 | /* |
| 703 | # lun_queue_depth: This parameter is used to limit the number of outstanding |
| 704 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. |
| 705 | */ |
| 706 | LPFC_ATTR_R(lun_queue_depth, 30, 1, 128, |
| 707 | "Max number of FCP commands we can queue to a specific LUN"); |
| 708 | |
| 709 | /* |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 710 | # hba_queue_depth: This parameter is used to limit the number of outstanding |
| 711 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter |
| 712 | # value is greater than the maximum number of exchanges supported by the HBA, |
| 713 | # then maximum number of exchanges supported by the HBA is used to determine |
| 714 | # the hba_queue_depth. |
| 715 | */ |
| 716 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, |
| 717 | "Max number of FCP commands we can queue to a lpfc HBA"); |
| 718 | |
| 719 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | # Some disk devices have a "select ID" or "select Target" capability. |
| 721 | # From a protocol standpoint "select ID" usually means select the |
| 722 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative |
| 723 | # annex" which contains a table that maps a "select ID" (a number |
| 724 | # between 0 and 7F) to an ALPA. By default, for compatibility with |
| 725 | # older drivers, the lpfc driver scans this table from low ALPA to high |
| 726 | # ALPA. |
| 727 | # |
| 728 | # Turning on the scan-down variable (on = 1, off = 0) will |
| 729 | # cause the lpfc driver to use an inverted table, effectively |
| 730 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. |
| 731 | # |
| 732 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic |
| 733 | # and will not work across a fabric. Also this parameter will take |
| 734 | # effect only in the case when ALPA map is not available.) |
| 735 | */ |
| 736 | LPFC_ATTR_R(scan_down, 1, 0, 1, |
| 737 | "Start scanning for devices from highest ALPA to lowest"); |
| 738 | |
| 739 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | # lpfc_topology: link topology for init link |
| 741 | # 0x0 = attempt loop mode then point-to-point |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 742 | # 0x01 = internal loopback mode |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 743 | # 0x02 = attempt point-to-point mode only |
| 744 | # 0x04 = attempt loop mode only |
| 745 | # 0x06 = attempt point-to-point mode then loop |
| 746 | # Set point-to-point mode if you want to run as an N_Port. |
| 747 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. |
| 748 | # Default value is 0. |
| 749 | */ |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 750 | LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 751 | |
| 752 | /* |
| 753 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel |
| 754 | # connection. |
| 755 | # 0 = auto select (default) |
| 756 | # 1 = 1 Gigabaud |
| 757 | # 2 = 2 Gigabaud |
| 758 | # 4 = 4 Gigabaud |
| 759 | # Value range is [0,4]. Default value is 0. |
| 760 | */ |
| 761 | LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed"); |
| 762 | |
| 763 | /* |
| 764 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. |
| 765 | # Value range is [2,3]. Default value is 3. |
| 766 | */ |
| 767 | LPFC_ATTR_R(fcp_class, 3, 2, 3, |
| 768 | "Select Fibre Channel class of service for FCP sequences"); |
| 769 | |
| 770 | /* |
| 771 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range |
| 772 | # is [0,1]. Default value is 0. |
| 773 | */ |
| 774 | LPFC_ATTR_RW(use_adisc, 0, 0, 1, |
| 775 | "Use ADISC on rediscovery to authenticate FCP devices"); |
| 776 | |
| 777 | /* |
| 778 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value |
| 779 | # range is [0,1]. Default value is 0. |
| 780 | */ |
| 781 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); |
| 782 | |
| 783 | /* |
| 784 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing |
| 785 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take |
| 786 | # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay |
| 787 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
| 788 | # cr_delay is set to 0. |
| 789 | */ |
Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 790 | 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] | 791 | "interrupt response is generated"); |
| 792 | |
Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 793 | 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] | 794 | "interrupt response is generated"); |
| 795 | |
| 796 | /* |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 797 | # lpfc_multi_ring_support: Determines how many rings to spread available |
| 798 | # cmd/rsp IOCB entries across. |
| 799 | # Value range is [1,2]. Default value is 1. |
| 800 | */ |
| 801 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " |
| 802 | "SLI rings to spread IOCB entries across"); |
| 803 | |
| 804 | /* |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 805 | # lpfc_fdmi_on: controls FDMI support. |
| 806 | # 0 = no FDMI support |
| 807 | # 1 = support FDMI without attribute of hostname |
| 808 | # 2 = support FDMI with attribute of hostname |
| 809 | # Value range [0,2]. Default value is 0. |
| 810 | */ |
| 811 | LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); |
| 812 | |
| 813 | /* |
| 814 | # Specifies the maximum number of ELS cmds we can have outstanding (for |
| 815 | # discovery). Value range is [1,64]. Default value = 32. |
| 816 | */ |
Jamie Wellnitz | 8189fd1 | 2006-02-28 19:25:35 -0500 | [diff] [blame] | 817 | LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 818 | "during discovery"); |
| 819 | |
| 820 | /* |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 821 | # lpfc_max_luns: maximum allowed LUN. |
| 822 | # Value range is [0,65535]. Default value is 255. |
| 823 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | */ |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 825 | LPFC_ATTR_R(max_luns, 255, 0, 65535, |
| 826 | "Maximum allowed LUN"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 827 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 828 | /* |
| 829 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. |
| 830 | # Value range is [1,255], default value is 10. |
| 831 | */ |
| 832 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, |
| 833 | "Milliseconds driver will wait between polling FCP ring"); |
| 834 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 835 | struct class_device_attribute *lpfc_host_attrs[] = { |
| 836 | &class_device_attr_info, |
| 837 | &class_device_attr_serialnum, |
| 838 | &class_device_attr_modeldesc, |
| 839 | &class_device_attr_modelname, |
| 840 | &class_device_attr_programtype, |
| 841 | &class_device_attr_portnum, |
| 842 | &class_device_attr_fwrev, |
| 843 | &class_device_attr_hdw, |
| 844 | &class_device_attr_option_rom_version, |
| 845 | &class_device_attr_state, |
| 846 | &class_device_attr_num_discovered_ports, |
| 847 | &class_device_attr_lpfc_drvr_version, |
| 848 | &class_device_attr_lpfc_log_verbose, |
| 849 | &class_device_attr_lpfc_lun_queue_depth, |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 850 | &class_device_attr_lpfc_hba_queue_depth, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | &class_device_attr_lpfc_nodev_tmo, |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 852 | &class_device_attr_lpfc_devloss_tmo, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 853 | &class_device_attr_lpfc_fcp_class, |
| 854 | &class_device_attr_lpfc_use_adisc, |
| 855 | &class_device_attr_lpfc_ack0, |
| 856 | &class_device_attr_lpfc_topology, |
| 857 | &class_device_attr_lpfc_scan_down, |
| 858 | &class_device_attr_lpfc_link_speed, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 859 | &class_device_attr_lpfc_cr_delay, |
| 860 | &class_device_attr_lpfc_cr_count, |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 861 | &class_device_attr_lpfc_multi_ring_support, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 862 | &class_device_attr_lpfc_fdmi_on, |
| 863 | &class_device_attr_lpfc_max_luns, |
| 864 | &class_device_attr_nport_evt_cnt, |
| 865 | &class_device_attr_management_version, |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 866 | &class_device_attr_board_mode, |
James Smart | 40496f0 | 2006-07-06 15:50:22 -0400 | [diff] [blame] | 867 | &class_device_attr_issue_reset, |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 868 | &class_device_attr_lpfc_poll, |
| 869 | &class_device_attr_lpfc_poll_tmo, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | NULL, |
| 871 | }; |
| 872 | |
| 873 | static ssize_t |
| 874 | sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 875 | { |
| 876 | size_t buf_off; |
| 877 | struct Scsi_Host *host = class_to_shost(container_of(kobj, |
| 878 | struct class_device, kobj)); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 879 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 880 | |
| 881 | if ((off + count) > FF_REG_AREA_SIZE) |
| 882 | return -ERANGE; |
| 883 | |
| 884 | if (count == 0) return 0; |
| 885 | |
| 886 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 887 | return -EINVAL; |
| 888 | |
| 889 | spin_lock_irq(phba->host->host_lock); |
| 890 | |
| 891 | if (!(phba->fc_flag & FC_OFFLINE_MODE)) { |
| 892 | spin_unlock_irq(phba->host->host_lock); |
| 893 | return -EPERM; |
| 894 | } |
| 895 | |
| 896 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) |
| 897 | writel(*((uint32_t *)(buf + buf_off)), |
| 898 | phba->ctrl_regs_memmap_p + off + buf_off); |
| 899 | |
| 900 | spin_unlock_irq(phba->host->host_lock); |
| 901 | |
| 902 | return count; |
| 903 | } |
| 904 | |
| 905 | static ssize_t |
| 906 | sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 907 | { |
| 908 | size_t buf_off; |
| 909 | uint32_t * tmp_ptr; |
| 910 | struct Scsi_Host *host = class_to_shost(container_of(kobj, |
| 911 | struct class_device, kobj)); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 912 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 913 | |
| 914 | if (off > FF_REG_AREA_SIZE) |
| 915 | return -ERANGE; |
| 916 | |
| 917 | if ((off + count) > FF_REG_AREA_SIZE) |
| 918 | count = FF_REG_AREA_SIZE - off; |
| 919 | |
| 920 | if (count == 0) return 0; |
| 921 | |
| 922 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 923 | return -EINVAL; |
| 924 | |
| 925 | spin_lock_irq(phba->host->host_lock); |
| 926 | |
| 927 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { |
| 928 | tmp_ptr = (uint32_t *)(buf + buf_off); |
| 929 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); |
| 930 | } |
| 931 | |
| 932 | spin_unlock_irq(phba->host->host_lock); |
| 933 | |
| 934 | return count; |
| 935 | } |
| 936 | |
| 937 | static struct bin_attribute sysfs_ctlreg_attr = { |
| 938 | .attr = { |
| 939 | .name = "ctlreg", |
| 940 | .mode = S_IRUSR | S_IWUSR, |
| 941 | .owner = THIS_MODULE, |
| 942 | }, |
| 943 | .size = 256, |
| 944 | .read = sysfs_ctlreg_read, |
| 945 | .write = sysfs_ctlreg_write, |
| 946 | }; |
| 947 | |
| 948 | |
| 949 | static void |
| 950 | sysfs_mbox_idle (struct lpfc_hba * phba) |
| 951 | { |
| 952 | phba->sysfs_mbox.state = SMBOX_IDLE; |
| 953 | phba->sysfs_mbox.offset = 0; |
| 954 | |
| 955 | if (phba->sysfs_mbox.mbox) { |
| 956 | mempool_free(phba->sysfs_mbox.mbox, |
| 957 | phba->mbox_mem_pool); |
| 958 | phba->sysfs_mbox.mbox = NULL; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | static ssize_t |
| 963 | sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 964 | { |
| 965 | struct Scsi_Host * host = |
| 966 | class_to_shost(container_of(kobj, struct class_device, kobj)); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 967 | struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 968 | struct lpfcMboxq * mbox = NULL; |
| 969 | |
| 970 | if ((count + off) > MAILBOX_CMD_SIZE) |
| 971 | return -ERANGE; |
| 972 | |
| 973 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 974 | return -EINVAL; |
| 975 | |
| 976 | if (count == 0) |
| 977 | return 0; |
| 978 | |
| 979 | if (off == 0) { |
| 980 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 981 | if (!mbox) |
| 982 | return -ENOMEM; |
James Smart | fc6c12b | 2006-03-07 15:04:19 -0500 | [diff] [blame] | 983 | memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | spin_lock_irq(host->host_lock); |
| 987 | |
| 988 | if (off == 0) { |
| 989 | if (phba->sysfs_mbox.mbox) |
| 990 | mempool_free(mbox, phba->mbox_mem_pool); |
| 991 | else |
| 992 | phba->sysfs_mbox.mbox = mbox; |
| 993 | phba->sysfs_mbox.state = SMBOX_WRITING; |
| 994 | } else { |
| 995 | if (phba->sysfs_mbox.state != SMBOX_WRITING || |
| 996 | phba->sysfs_mbox.offset != off || |
| 997 | phba->sysfs_mbox.mbox == NULL ) { |
| 998 | sysfs_mbox_idle(phba); |
| 999 | spin_unlock_irq(host->host_lock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1000 | return -EAGAIN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, |
| 1005 | buf, count); |
| 1006 | |
| 1007 | phba->sysfs_mbox.offset = off + count; |
| 1008 | |
| 1009 | spin_unlock_irq(host->host_lock); |
| 1010 | |
| 1011 | return count; |
| 1012 | } |
| 1013 | |
| 1014 | static ssize_t |
| 1015 | sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count) |
| 1016 | { |
| 1017 | struct Scsi_Host *host = |
| 1018 | class_to_shost(container_of(kobj, struct class_device, |
| 1019 | kobj)); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1020 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1021 | int rc; |
| 1022 | |
| 1023 | if (off > sizeof(MAILBOX_t)) |
| 1024 | return -ERANGE; |
| 1025 | |
| 1026 | if ((count + off) > sizeof(MAILBOX_t)) |
| 1027 | count = sizeof(MAILBOX_t) - off; |
| 1028 | |
| 1029 | if (off % 4 || count % 4 || (unsigned long)buf % 4) |
| 1030 | return -EINVAL; |
| 1031 | |
| 1032 | if (off && count == 0) |
| 1033 | return 0; |
| 1034 | |
| 1035 | spin_lock_irq(phba->host->host_lock); |
| 1036 | |
| 1037 | if (off == 0 && |
| 1038 | phba->sysfs_mbox.state == SMBOX_WRITING && |
| 1039 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { |
| 1040 | |
| 1041 | switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { |
| 1042 | /* Offline only */ |
| 1043 | case MBX_WRITE_NV: |
| 1044 | case MBX_INIT_LINK: |
| 1045 | case MBX_DOWN_LINK: |
| 1046 | case MBX_CONFIG_LINK: |
| 1047 | case MBX_CONFIG_RING: |
| 1048 | case MBX_RESET_RING: |
| 1049 | case MBX_UNREG_LOGIN: |
| 1050 | case MBX_CLEAR_LA: |
| 1051 | case MBX_DUMP_CONTEXT: |
| 1052 | case MBX_RUN_DIAGS: |
| 1053 | case MBX_RESTART: |
| 1054 | case MBX_FLASH_WR_ULA: |
| 1055 | case MBX_SET_MASK: |
| 1056 | case MBX_SET_SLIM: |
| 1057 | case MBX_SET_DEBUG: |
| 1058 | if (!(phba->fc_flag & FC_OFFLINE_MODE)) { |
| 1059 | printk(KERN_WARNING "mbox_read:Command 0x%x " |
| 1060 | "is illegal in on-line state\n", |
| 1061 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1062 | sysfs_mbox_idle(phba); |
| 1063 | spin_unlock_irq(phba->host->host_lock); |
| 1064 | return -EPERM; |
| 1065 | } |
| 1066 | case MBX_LOAD_SM: |
| 1067 | case MBX_READ_NV: |
| 1068 | case MBX_READ_CONFIG: |
| 1069 | case MBX_READ_RCONFIG: |
| 1070 | case MBX_READ_STATUS: |
| 1071 | case MBX_READ_XRI: |
| 1072 | case MBX_READ_REV: |
| 1073 | case MBX_READ_LNK_STAT: |
| 1074 | case MBX_DUMP_MEMORY: |
| 1075 | case MBX_DOWN_LOAD: |
| 1076 | case MBX_UPDATE_CFG: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1077 | case MBX_KILL_BOARD: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1078 | case MBX_LOAD_AREA: |
| 1079 | case MBX_LOAD_EXP_ROM: |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1080 | case MBX_BEACON: |
| 1081 | case MBX_DEL_LD_ENTRY: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1082 | break; |
| 1083 | case MBX_READ_SPARM64: |
| 1084 | case MBX_READ_LA: |
| 1085 | case MBX_READ_LA64: |
| 1086 | case MBX_REG_LOGIN: |
| 1087 | case MBX_REG_LOGIN64: |
| 1088 | case MBX_CONFIG_PORT: |
| 1089 | case MBX_RUN_BIU_DIAG: |
| 1090 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", |
| 1091 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1092 | sysfs_mbox_idle(phba); |
| 1093 | spin_unlock_irq(phba->host->host_lock); |
| 1094 | return -EPERM; |
| 1095 | default: |
| 1096 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", |
| 1097 | phba->sysfs_mbox.mbox->mb.mbxCommand); |
| 1098 | sysfs_mbox_idle(phba); |
| 1099 | spin_unlock_irq(phba->host->host_lock); |
| 1100 | return -EPERM; |
| 1101 | } |
| 1102 | |
| 1103 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
| 1104 | (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ |
| 1105 | |
| 1106 | spin_unlock_irq(phba->host->host_lock); |
| 1107 | rc = lpfc_sli_issue_mbox (phba, |
| 1108 | phba->sysfs_mbox.mbox, |
| 1109 | MBX_POLL); |
| 1110 | spin_lock_irq(phba->host->host_lock); |
| 1111 | |
| 1112 | } else { |
| 1113 | spin_unlock_irq(phba->host->host_lock); |
| 1114 | rc = lpfc_sli_issue_mbox_wait (phba, |
| 1115 | phba->sysfs_mbox.mbox, |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1116 | lpfc_mbox_tmo_val(phba, |
| 1117 | phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1118 | spin_lock_irq(phba->host->host_lock); |
| 1119 | } |
| 1120 | |
| 1121 | if (rc != MBX_SUCCESS) { |
| 1122 | sysfs_mbox_idle(phba); |
| 1123 | spin_unlock_irq(host->host_lock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1124 | return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1125 | } |
| 1126 | phba->sysfs_mbox.state = SMBOX_READING; |
| 1127 | } |
| 1128 | else if (phba->sysfs_mbox.offset != off || |
| 1129 | phba->sysfs_mbox.state != SMBOX_READING) { |
| 1130 | printk(KERN_WARNING "mbox_read: Bad State\n"); |
| 1131 | sysfs_mbox_idle(phba); |
| 1132 | spin_unlock_irq(host->host_lock); |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 1133 | return -EAGAIN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); |
| 1137 | |
| 1138 | phba->sysfs_mbox.offset = off + count; |
| 1139 | |
| 1140 | if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t)) |
| 1141 | sysfs_mbox_idle(phba); |
| 1142 | |
| 1143 | spin_unlock_irq(phba->host->host_lock); |
| 1144 | |
| 1145 | return count; |
| 1146 | } |
| 1147 | |
| 1148 | static struct bin_attribute sysfs_mbox_attr = { |
| 1149 | .attr = { |
| 1150 | .name = "mbox", |
| 1151 | .mode = S_IRUSR | S_IWUSR, |
| 1152 | .owner = THIS_MODULE, |
| 1153 | }, |
| 1154 | .size = sizeof(MAILBOX_t), |
| 1155 | .read = sysfs_mbox_read, |
| 1156 | .write = sysfs_mbox_write, |
| 1157 | }; |
| 1158 | |
| 1159 | int |
| 1160 | lpfc_alloc_sysfs_attr(struct lpfc_hba *phba) |
| 1161 | { |
| 1162 | struct Scsi_Host *host = phba->host; |
| 1163 | int error; |
| 1164 | |
| 1165 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, |
| 1166 | &sysfs_ctlreg_attr); |
| 1167 | if (error) |
| 1168 | goto out; |
| 1169 | |
| 1170 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, |
| 1171 | &sysfs_mbox_attr); |
| 1172 | if (error) |
| 1173 | goto out_remove_ctlreg_attr; |
| 1174 | |
| 1175 | return 0; |
| 1176 | out_remove_ctlreg_attr: |
| 1177 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); |
| 1178 | out: |
| 1179 | return error; |
| 1180 | } |
| 1181 | |
| 1182 | void |
| 1183 | lpfc_free_sysfs_attr(struct lpfc_hba *phba) |
| 1184 | { |
| 1185 | struct Scsi_Host *host = phba->host; |
| 1186 | |
| 1187 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr); |
| 1188 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | /* |
| 1193 | * Dynamic FC Host Attributes Support |
| 1194 | */ |
| 1195 | |
| 1196 | static void |
| 1197 | lpfc_get_host_port_id(struct Scsi_Host *shost) |
| 1198 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1199 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1200 | /* note: fc_myDID already in cpu endianness */ |
| 1201 | fc_host_port_id(shost) = phba->fc_myDID; |
| 1202 | } |
| 1203 | |
| 1204 | static void |
| 1205 | lpfc_get_host_port_type(struct Scsi_Host *shost) |
| 1206 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1207 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1208 | |
| 1209 | spin_lock_irq(shost->host_lock); |
| 1210 | |
| 1211 | if (phba->hba_state == LPFC_HBA_READY) { |
| 1212 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1213 | if (phba->fc_flag & FC_PUBLIC_LOOP) |
| 1214 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
| 1215 | else |
| 1216 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; |
| 1217 | } else { |
| 1218 | if (phba->fc_flag & FC_FABRIC) |
| 1219 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
| 1220 | else |
| 1221 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; |
| 1222 | } |
| 1223 | } else |
| 1224 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; |
| 1225 | |
| 1226 | spin_unlock_irq(shost->host_lock); |
| 1227 | } |
| 1228 | |
| 1229 | static void |
| 1230 | lpfc_get_host_port_state(struct Scsi_Host *shost) |
| 1231 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1232 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | |
| 1234 | spin_lock_irq(shost->host_lock); |
| 1235 | |
| 1236 | if (phba->fc_flag & FC_OFFLINE_MODE) |
| 1237 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
| 1238 | else { |
| 1239 | switch (phba->hba_state) { |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1240 | case LPFC_STATE_UNKNOWN: |
| 1241 | case LPFC_WARM_START: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1242 | case LPFC_INIT_START: |
| 1243 | case LPFC_INIT_MBX_CMDS: |
| 1244 | case LPFC_LINK_DOWN: |
| 1245 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; |
| 1246 | break; |
| 1247 | case LPFC_LINK_UP: |
| 1248 | case LPFC_LOCAL_CFG_LINK: |
| 1249 | case LPFC_FLOGI: |
| 1250 | case LPFC_FABRIC_CFG_LINK: |
| 1251 | case LPFC_NS_REG: |
| 1252 | case LPFC_NS_QRY: |
| 1253 | case LPFC_BUILD_DISC_LIST: |
| 1254 | case LPFC_DISC_AUTH: |
| 1255 | case LPFC_CLEAR_LA: |
| 1256 | case LPFC_HBA_READY: |
| 1257 | /* Links up, beyond this port_type reports state */ |
| 1258 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; |
| 1259 | break; |
| 1260 | case LPFC_HBA_ERROR: |
| 1261 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; |
| 1262 | break; |
| 1263 | default: |
| 1264 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | spin_unlock_irq(shost->host_lock); |
| 1270 | } |
| 1271 | |
| 1272 | static void |
| 1273 | lpfc_get_host_speed(struct Scsi_Host *shost) |
| 1274 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1275 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1276 | |
| 1277 | spin_lock_irq(shost->host_lock); |
| 1278 | |
| 1279 | if (phba->hba_state == LPFC_HBA_READY) { |
| 1280 | switch(phba->fc_linkspeed) { |
| 1281 | case LA_1GHZ_LINK: |
| 1282 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; |
| 1283 | break; |
| 1284 | case LA_2GHZ_LINK: |
| 1285 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; |
| 1286 | break; |
| 1287 | case LA_4GHZ_LINK: |
| 1288 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; |
| 1289 | break; |
| 1290 | default: |
| 1291 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; |
| 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | spin_unlock_irq(shost->host_lock); |
| 1297 | } |
| 1298 | |
| 1299 | static void |
| 1300 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) |
| 1301 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1302 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1303 | u64 node_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | |
| 1305 | spin_lock_irq(shost->host_lock); |
| 1306 | |
| 1307 | if ((phba->fc_flag & FC_FABRIC) || |
| 1308 | ((phba->fc_topology == TOPOLOGY_LOOP) && |
| 1309 | (phba->fc_flag & FC_PUBLIC_LOOP))) |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1310 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | else |
| 1312 | /* fabric is local port if there is no F/FL_Port */ |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1313 | node_name = wwn_to_u64(phba->fc_nodename.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | |
| 1315 | spin_unlock_irq(shost->host_lock); |
| 1316 | |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1317 | fc_host_fabric_name(shost) = node_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1318 | } |
| 1319 | |
James Smart | ae36764 | 2006-08-18 17:46:53 -0400 | [diff] [blame] | 1320 | static void |
| 1321 | lpfc_get_host_symbolic_name (struct Scsi_Host *shost) |
| 1322 | { |
| 1323 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; |
| 1324 | |
| 1325 | spin_lock_irq(shost->host_lock); |
| 1326 | lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost)); |
| 1327 | spin_unlock_irq(shost->host_lock); |
| 1328 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1329 | |
| 1330 | static struct fc_host_statistics * |
| 1331 | lpfc_get_stats(struct Scsi_Host *shost) |
| 1332 | { |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1333 | struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1334 | struct lpfc_sli *psli = &phba->sli; |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 1335 | struct fc_host_statistics *hs = &phba->link_stats; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1336 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1337 | LPFC_MBOXQ_t *pmboxq; |
| 1338 | MAILBOX_t *pmb; |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1339 | unsigned long seconds; |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1340 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1341 | |
| 1342 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1343 | if (!pmboxq) |
| 1344 | return NULL; |
| 1345 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| 1346 | |
| 1347 | pmb = &pmboxq->mb; |
| 1348 | pmb->mbxCommand = MBX_READ_STATUS; |
| 1349 | pmb->mbxOwner = OWN_HOST; |
| 1350 | pmboxq->context1 = NULL; |
| 1351 | |
| 1352 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1353 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1354 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1355 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1356 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 1357 | |
| 1358 | if (rc != MBX_SUCCESS) { |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1359 | if (rc == MBX_TIMEOUT) |
| 1360 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 1361 | else |
| 1362 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | return NULL; |
| 1364 | } |
| 1365 | |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 1366 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
| 1367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
| 1369 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); |
| 1370 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; |
| 1371 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); |
| 1372 | |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1373 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1374 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
| 1375 | pmb->mbxOwner = OWN_HOST; |
| 1376 | pmboxq->context1 = NULL; |
| 1377 | |
| 1378 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1379 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1380 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1381 | else |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1382 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 1383 | |
| 1384 | if (rc != MBX_SUCCESS) { |
James.Smart@Emulex.Com | 433c357 | 2005-10-28 20:28:56 -0400 | [diff] [blame] | 1385 | if (rc == MBX_TIMEOUT) |
| 1386 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 1387 | else |
| 1388 | mempool_free( pmboxq, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | return NULL; |
| 1390 | } |
| 1391 | |
| 1392 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; |
| 1393 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; |
| 1394 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; |
| 1395 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; |
| 1396 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; |
| 1397 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; |
| 1398 | hs->error_frames = pmb->un.varRdLnk.crcCnt; |
| 1399 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1400 | hs->link_failure_count -= lso->link_failure_count; |
| 1401 | hs->loss_of_sync_count -= lso->loss_of_sync_count; |
| 1402 | hs->loss_of_signal_count -= lso->loss_of_signal_count; |
| 1403 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; |
| 1404 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; |
| 1405 | hs->invalid_crc_count -= lso->invalid_crc_count; |
| 1406 | hs->error_frames -= lso->error_frames; |
| 1407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1408 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
| 1409 | hs->lip_count = (phba->fc_eventTag >> 1); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1410 | hs->lip_count -= lso->link_events; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | hs->nos_count = -1; |
| 1412 | } else { |
| 1413 | hs->lip_count = -1; |
| 1414 | hs->nos_count = (phba->fc_eventTag >> 1); |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1415 | hs->nos_count -= lso->link_events; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | hs->dumped_frames = -1; |
| 1419 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1420 | seconds = get_seconds(); |
| 1421 | if (seconds < psli->stats_start) |
| 1422 | hs->seconds_since_last_reset = seconds + |
| 1423 | ((unsigned long)-1 - psli->stats_start); |
| 1424 | else |
| 1425 | hs->seconds_since_last_reset = seconds - psli->stats_start; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | |
| 1427 | return hs; |
| 1428 | } |
| 1429 | |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1430 | static void |
| 1431 | lpfc_reset_stats(struct Scsi_Host *shost) |
| 1432 | { |
| 1433 | struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; |
| 1434 | struct lpfc_sli *psli = &phba->sli; |
| 1435 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
| 1436 | LPFC_MBOXQ_t *pmboxq; |
| 1437 | MAILBOX_t *pmb; |
| 1438 | int rc = 0; |
| 1439 | |
| 1440 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1441 | if (!pmboxq) |
| 1442 | return; |
| 1443 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 1444 | |
| 1445 | pmb = &pmboxq->mb; |
| 1446 | pmb->mbxCommand = MBX_READ_STATUS; |
| 1447 | pmb->mbxOwner = OWN_HOST; |
| 1448 | pmb->un.varWords[0] = 0x1; /* reset request */ |
| 1449 | pmboxq->context1 = NULL; |
| 1450 | |
| 1451 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
| 1452 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| 1453 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 1454 | else |
| 1455 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 1456 | |
| 1457 | if (rc != MBX_SUCCESS) { |
| 1458 | if (rc == MBX_TIMEOUT) |
| 1459 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 1460 | else |
| 1461 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1462 | return; |
| 1463 | } |
| 1464 | |
| 1465 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 1466 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
| 1467 | pmb->mbxOwner = OWN_HOST; |
| 1468 | pmboxq->context1 = NULL; |
| 1469 | |
| 1470 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
| 1471 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
| 1472 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
| 1473 | else |
| 1474 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
| 1475 | |
| 1476 | if (rc != MBX_SUCCESS) { |
| 1477 | if (rc == MBX_TIMEOUT) |
| 1478 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 1479 | else |
| 1480 | mempool_free( pmboxq, phba->mbox_mem_pool); |
| 1481 | return; |
| 1482 | } |
| 1483 | |
| 1484 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; |
| 1485 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; |
| 1486 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; |
| 1487 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; |
| 1488 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; |
| 1489 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; |
| 1490 | lso->error_frames = pmb->un.varRdLnk.crcCnt; |
| 1491 | lso->link_events = (phba->fc_eventTag >> 1); |
| 1492 | |
| 1493 | psli->stats_start = get_seconds(); |
| 1494 | |
| 1495 | return; |
| 1496 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1497 | |
| 1498 | /* |
| 1499 | * The LPFC driver treats linkdown handling as target loss events so there |
| 1500 | * are no sysfs handlers for link_down_tmo. |
| 1501 | */ |
| 1502 | static void |
| 1503 | lpfc_get_starget_port_id(struct scsi_target *starget) |
| 1504 | { |
| 1505 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1506 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1507 | uint32_t did = -1; |
| 1508 | struct lpfc_nodelist *ndlp = NULL; |
| 1509 | |
| 1510 | spin_lock_irq(shost->host_lock); |
| 1511 | /* Search the mapped list for this target ID */ |
| 1512 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { |
| 1513 | if (starget->id == ndlp->nlp_sid) { |
| 1514 | did = ndlp->nlp_DID; |
| 1515 | break; |
| 1516 | } |
| 1517 | } |
| 1518 | spin_unlock_irq(shost->host_lock); |
| 1519 | |
| 1520 | fc_starget_port_id(starget) = did; |
| 1521 | } |
| 1522 | |
| 1523 | static void |
| 1524 | lpfc_get_starget_node_name(struct scsi_target *starget) |
| 1525 | { |
| 1526 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1527 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1528 | u64 node_name = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1529 | struct lpfc_nodelist *ndlp = NULL; |
| 1530 | |
| 1531 | spin_lock_irq(shost->host_lock); |
| 1532 | /* Search the mapped list for this target ID */ |
| 1533 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { |
| 1534 | if (starget->id == ndlp->nlp_sid) { |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1535 | node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1536 | break; |
| 1537 | } |
| 1538 | } |
| 1539 | spin_unlock_irq(shost->host_lock); |
| 1540 | |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1541 | fc_starget_node_name(starget) = node_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static void |
| 1545 | lpfc_get_starget_port_name(struct scsi_target *starget) |
| 1546 | { |
| 1547 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
Jamie Wellnitz | 7f0b5b1 | 2006-02-28 19:25:24 -0500 | [diff] [blame] | 1548 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1549 | u64 port_name = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1550 | struct lpfc_nodelist *ndlp = NULL; |
| 1551 | |
| 1552 | spin_lock_irq(shost->host_lock); |
| 1553 | /* Search the mapped list for this target ID */ |
| 1554 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { |
| 1555 | if (starget->id == ndlp->nlp_sid) { |
Andrew Morton | 68ce1eb | 2005-09-21 09:46:54 -0700 | [diff] [blame] | 1556 | port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | break; |
| 1558 | } |
| 1559 | } |
| 1560 | spin_unlock_irq(shost->host_lock); |
| 1561 | |
Andrew Vasquez | f631b4b | 2005-08-31 15:23:12 -0700 | [diff] [blame] | 1562 | fc_starget_port_name(starget) = port_name; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | static void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1566 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) |
| 1567 | { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | if (timeout) |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 1569 | rport->dev_loss_tmo = timeout; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1570 | else |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 1571 | rport->dev_loss_tmo = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
| 1576 | static ssize_t \ |
| 1577 | lpfc_show_rport_##field (struct class_device *cdev, char *buf) \ |
| 1578 | { \ |
| 1579 | struct fc_rport *rport = transport_class_to_rport(cdev); \ |
| 1580 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
| 1581 | return snprintf(buf, sz, format_string, \ |
| 1582 | (rdata->target) ? cast rdata->target->field : 0); \ |
| 1583 | } |
| 1584 | |
| 1585 | #define lpfc_rport_rd_attr(field, format_string, sz) \ |
| 1586 | lpfc_rport_show_function(field, format_string, sz, ) \ |
| 1587 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) |
| 1588 | |
| 1589 | |
| 1590 | struct fc_function_template lpfc_transport_functions = { |
| 1591 | /* fixed attributes the driver supports */ |
| 1592 | .show_host_node_name = 1, |
| 1593 | .show_host_port_name = 1, |
| 1594 | .show_host_supported_classes = 1, |
| 1595 | .show_host_supported_fc4s = 1, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1596 | .show_host_supported_speeds = 1, |
| 1597 | .show_host_maxframe_size = 1, |
| 1598 | |
| 1599 | /* dynamic attributes the driver supports */ |
| 1600 | .get_host_port_id = lpfc_get_host_port_id, |
| 1601 | .show_host_port_id = 1, |
| 1602 | |
| 1603 | .get_host_port_type = lpfc_get_host_port_type, |
| 1604 | .show_host_port_type = 1, |
| 1605 | |
| 1606 | .get_host_port_state = lpfc_get_host_port_state, |
| 1607 | .show_host_port_state = 1, |
| 1608 | |
| 1609 | /* active_fc4s is shown but doesn't change (thus no get function) */ |
| 1610 | .show_host_active_fc4s = 1, |
| 1611 | |
| 1612 | .get_host_speed = lpfc_get_host_speed, |
| 1613 | .show_host_speed = 1, |
| 1614 | |
| 1615 | .get_host_fabric_name = lpfc_get_host_fabric_name, |
| 1616 | .show_host_fabric_name = 1, |
| 1617 | |
James Smart | ae36764 | 2006-08-18 17:46:53 -0400 | [diff] [blame] | 1618 | .get_host_symbolic_name = lpfc_get_host_symbolic_name, |
| 1619 | .show_host_symbolic_name = 1, |
| 1620 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | /* |
| 1622 | * The LPFC driver treats linkdown handling as target loss events |
| 1623 | * so there are no sysfs handlers for link_down_tmo. |
| 1624 | */ |
| 1625 | |
| 1626 | .get_fc_host_stats = lpfc_get_stats, |
James Smart | 64ba881 | 2006-08-02 15:24:34 -0400 | [diff] [blame] | 1627 | .reset_fc_host_stats = lpfc_reset_stats, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1628 | |
| 1629 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), |
| 1630 | .show_rport_maxframe_size = 1, |
| 1631 | .show_rport_supported_classes = 1, |
| 1632 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1633 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
| 1634 | .show_rport_dev_loss_tmo = 1, |
| 1635 | |
| 1636 | .get_starget_port_id = lpfc_get_starget_port_id, |
| 1637 | .show_starget_port_id = 1, |
| 1638 | |
| 1639 | .get_starget_node_name = lpfc_get_starget_node_name, |
| 1640 | .show_starget_node_name = 1, |
| 1641 | |
| 1642 | .get_starget_port_name = lpfc_get_starget_port_name, |
| 1643 | .show_starget_port_name = 1, |
Andrew Vasquez | 91ca7b0 | 2005-10-27 16:03:37 -0700 | [diff] [blame] | 1644 | |
| 1645 | .issue_fc_host_lip = lpfc_issue_lip, |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 1646 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
| 1647 | .terminate_rport_io = lpfc_terminate_rport_io, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | }; |
| 1649 | |
| 1650 | void |
| 1651 | lpfc_get_cfgparam(struct lpfc_hba *phba) |
| 1652 | { |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1653 | lpfc_log_verbose_init(phba, lpfc_log_verbose); |
| 1654 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
| 1655 | lpfc_cr_count_init(phba, lpfc_cr_count); |
Jamie Wellnitz | cf5bf97 | 2006-02-28 22:33:08 -0500 | [diff] [blame] | 1656 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1657 | lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth); |
| 1658 | lpfc_fcp_class_init(phba, lpfc_fcp_class); |
| 1659 | lpfc_use_adisc_init(phba, lpfc_use_adisc); |
| 1660 | lpfc_ack0_init(phba, lpfc_ack0); |
| 1661 | lpfc_topology_init(phba, lpfc_topology); |
| 1662 | lpfc_scan_down_init(phba, lpfc_scan_down); |
James.Smart@Emulex.Com | 7bcbb75 | 2005-10-28 20:29:13 -0400 | [diff] [blame] | 1663 | lpfc_link_speed_init(phba, lpfc_link_speed); |
| 1664 | lpfc_fdmi_on_init(phba, lpfc_fdmi_on); |
| 1665 | lpfc_discovery_threads_init(phba, lpfc_discovery_threads); |
| 1666 | lpfc_max_luns_init(phba, lpfc_max_luns); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1667 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
James Smart | c01f320 | 2006-08-18 17:47:08 -0400 | [diff] [blame^] | 1668 | lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo); |
| 1669 | lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1670 | phba->cfg_poll = lpfc_poll; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1671 | |
| 1672 | /* |
| 1673 | * The total number of segments is the configuration value plus 2 |
| 1674 | * since the IOCB need a command and response bde. |
| 1675 | */ |
| 1676 | phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2; |
| 1677 | |
| 1678 | /* |
| 1679 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
| 1680 | * used to create the sg_dma_buf_pool must be dynamically calculated |
| 1681 | */ |
| 1682 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 1683 | sizeof(struct fcp_rsp) + |
| 1684 | (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64)); |
| 1685 | |
| 1686 | switch (phba->pcidev->device) { |
| 1687 | case PCI_DEVICE_ID_LP101: |
| 1688 | case PCI_DEVICE_ID_BSMB: |
| 1689 | case PCI_DEVICE_ID_ZSMB: |
| 1690 | phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH; |
| 1691 | break; |
| 1692 | case PCI_DEVICE_ID_RFLY: |
| 1693 | case PCI_DEVICE_ID_PFLY: |
| 1694 | case PCI_DEVICE_ID_BMID: |
| 1695 | case PCI_DEVICE_ID_ZMID: |
| 1696 | case PCI_DEVICE_ID_TFLY: |
| 1697 | phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH; |
| 1698 | break; |
| 1699 | default: |
| 1700 | phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH; |
| 1701 | } |
Jamie Wellnitz | b28485a | 2006-02-28 19:25:21 -0500 | [diff] [blame] | 1702 | |
| 1703 | if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth) |
| 1704 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
| 1705 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1706 | return; |
| 1707 | } |