Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
92494144 | 4 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
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. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/ctype.h> |
46fa311e | 23 | #include <linux/delay.h> |
dea3101e | 24 | #include <linux/pci.h> |
25 | #include <linux/interrupt.h> | |
0d878419 | 26 | #include <linux/aer.h> |
5a0e3ad6 | 27 | #include <linux/gfp.h> |
ecc30990 | 28 | #include <linux/kernel.h> |
dea3101e | 29 | |
91886523 | 30 | #include <scsi/scsi.h> |
dea3101e | 31 | #include <scsi/scsi_device.h> |
32 | #include <scsi/scsi_host.h> | |
33 | #include <scsi/scsi_tcq.h> | |
34 | #include <scsi/scsi_transport_fc.h> | |
6a9c52cf | 35 | #include <scsi/fc/fc_fs.h> |
dea3101e | 36 | |
da0436e9 | 37 | #include "lpfc_hw4.h" |
dea3101e | 38 | #include "lpfc_hw.h" |
39 | #include "lpfc_sli.h" | |
da0436e9 | 40 | #include "lpfc_sli4.h" |
ea2151b4 | 41 | #include "lpfc_nl.h" |
dea3101e | 42 | #include "lpfc_disc.h" |
43 | #include "lpfc_scsi.h" | |
44 | #include "lpfc.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_version.h" | |
47 | #include "lpfc_compat.h" | |
48 | #include "lpfc_crtn.h" | |
92d7f7b0 | 49 | #include "lpfc_vport.h" |
dea3101e | 50 | |
c01f3208 JS |
51 | #define LPFC_DEF_DEVLOSS_TMO 30 |
52 | #define LPFC_MIN_DEVLOSS_TMO 1 | |
53 | #define LPFC_MAX_DEVLOSS_TMO 255 | |
dea3101e | 54 | |
e59058c4 | 55 | /** |
3621a710 | 56 | * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules |
e59058c4 JS |
57 | * @incr: integer to convert. |
58 | * @hdw: ascii string holding converted integer plus a string terminator. | |
59 | * | |
60 | * Description: | |
61 | * JEDEC Joint Electron Device Engineering Council. | |
62 | * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii | |
63 | * character string. The string is then terminated with a NULL in byte 9. | |
64 | * Hex 0-9 becomes ascii '0' to '9'. | |
65 | * Hex a-f becomes ascii '=' to 'B' capital B. | |
66 | * | |
67 | * Notes: | |
68 | * Coded for 32 bit integers only. | |
69 | **/ | |
dea3101e | 70 | static void |
71 | lpfc_jedec_to_ascii(int incr, char hdw[]) | |
72 | { | |
73 | int i, j; | |
74 | for (i = 0; i < 8; i++) { | |
75 | j = (incr & 0xf); | |
76 | if (j <= 9) | |
77 | hdw[7 - i] = 0x30 + j; | |
78 | else | |
79 | hdw[7 - i] = 0x61 + j - 10; | |
80 | incr = (incr >> 4); | |
81 | } | |
82 | hdw[8] = 0; | |
83 | return; | |
84 | } | |
85 | ||
e59058c4 | 86 | /** |
3621a710 | 87 | * lpfc_drvr_version_show - Return the Emulex driver string with version number |
e59058c4 JS |
88 | * @dev: class unused variable. |
89 | * @attr: device attribute, not used. | |
90 | * @buf: on return contains the module description text. | |
91 | * | |
92 | * Returns: size of formatted string. | |
93 | **/ | |
dea3101e | 94 | static ssize_t |
ee959b00 TJ |
95 | lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, |
96 | char *buf) | |
dea3101e | 97 | { |
98 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | |
99 | } | |
100 | ||
45ed1190 JS |
101 | /** |
102 | * lpfc_enable_fip_show - Return the fip mode of the HBA | |
103 | * @dev: class unused variable. | |
104 | * @attr: device attribute, not used. | |
105 | * @buf: on return contains the module description text. | |
106 | * | |
107 | * Returns: size of formatted string. | |
108 | **/ | |
109 | static ssize_t | |
110 | lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr, | |
111 | char *buf) | |
112 | { | |
113 | struct Scsi_Host *shost = class_to_shost(dev); | |
114 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
115 | struct lpfc_hba *phba = vport->phba; | |
116 | ||
117 | if (phba->hba_flag & HBA_FIP_SUPPORT) | |
118 | return snprintf(buf, PAGE_SIZE, "1\n"); | |
119 | else | |
120 | return snprintf(buf, PAGE_SIZE, "0\n"); | |
121 | } | |
122 | ||
81301a9b JS |
123 | static ssize_t |
124 | lpfc_bg_info_show(struct device *dev, struct device_attribute *attr, | |
125 | char *buf) | |
126 | { | |
127 | struct Scsi_Host *shost = class_to_shost(dev); | |
128 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
129 | struct lpfc_hba *phba = vport->phba; | |
130 | ||
131 | if (phba->cfg_enable_bg) | |
132 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
133 | return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n"); | |
134 | else | |
135 | return snprintf(buf, PAGE_SIZE, | |
136 | "BlockGuard Not Supported\n"); | |
137 | else | |
138 | return snprintf(buf, PAGE_SIZE, | |
139 | "BlockGuard Disabled\n"); | |
140 | } | |
141 | ||
142 | static ssize_t | |
143 | lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr, | |
144 | char *buf) | |
145 | { | |
146 | struct Scsi_Host *shost = class_to_shost(dev); | |
147 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
148 | struct lpfc_hba *phba = vport->phba; | |
149 | ||
87b5c328 JS |
150 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
151 | (unsigned long long)phba->bg_guard_err_cnt); | |
81301a9b JS |
152 | } |
153 | ||
154 | static ssize_t | |
155 | lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr, | |
156 | char *buf) | |
157 | { | |
158 | struct Scsi_Host *shost = class_to_shost(dev); | |
159 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
160 | struct lpfc_hba *phba = vport->phba; | |
161 | ||
87b5c328 JS |
162 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
163 | (unsigned long long)phba->bg_apptag_err_cnt); | |
81301a9b JS |
164 | } |
165 | ||
166 | static ssize_t | |
167 | lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr, | |
168 | char *buf) | |
169 | { | |
170 | struct Scsi_Host *shost = class_to_shost(dev); | |
171 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
172 | struct lpfc_hba *phba = vport->phba; | |
173 | ||
87b5c328 JS |
174 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
175 | (unsigned long long)phba->bg_reftag_err_cnt); | |
81301a9b JS |
176 | } |
177 | ||
e59058c4 | 178 | /** |
3621a710 | 179 | * lpfc_info_show - Return some pci info about the host in ascii |
e59058c4 JS |
180 | * @dev: class converted to a Scsi_host structure. |
181 | * @attr: device attribute, not used. | |
182 | * @buf: on return contains the formatted text from lpfc_info(). | |
183 | * | |
184 | * Returns: size of formatted string. | |
185 | **/ | |
dea3101e | 186 | static ssize_t |
ee959b00 TJ |
187 | lpfc_info_show(struct device *dev, struct device_attribute *attr, |
188 | char *buf) | |
dea3101e | 189 | { |
ee959b00 | 190 | struct Scsi_Host *host = class_to_shost(dev); |
2e0fef85 | 191 | |
dea3101e | 192 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); |
193 | } | |
194 | ||
e59058c4 | 195 | /** |
3621a710 | 196 | * lpfc_serialnum_show - Return the hba serial number in ascii |
e59058c4 JS |
197 | * @dev: class converted to a Scsi_host structure. |
198 | * @attr: device attribute, not used. | |
199 | * @buf: on return contains the formatted text serial number. | |
200 | * | |
201 | * Returns: size of formatted string. | |
202 | **/ | |
dea3101e | 203 | static ssize_t |
ee959b00 TJ |
204 | lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, |
205 | char *buf) | |
dea3101e | 206 | { |
ee959b00 | 207 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
208 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
209 | struct lpfc_hba *phba = vport->phba; | |
210 | ||
dea3101e | 211 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
212 | } | |
213 | ||
e59058c4 | 214 | /** |
3621a710 | 215 | * lpfc_temp_sensor_show - Return the temperature sensor level |
e59058c4 JS |
216 | * @dev: class converted to a Scsi_host structure. |
217 | * @attr: device attribute, not used. | |
218 | * @buf: on return contains the formatted support level. | |
219 | * | |
220 | * Description: | |
221 | * Returns a number indicating the temperature sensor level currently | |
222 | * supported, zero or one in ascii. | |
223 | * | |
224 | * Returns: size of formatted string. | |
225 | **/ | |
57127f15 | 226 | static ssize_t |
ee959b00 TJ |
227 | lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, |
228 | char *buf) | |
57127f15 | 229 | { |
ee959b00 | 230 | struct Scsi_Host *shost = class_to_shost(dev); |
57127f15 JS |
231 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
232 | struct lpfc_hba *phba = vport->phba; | |
233 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); | |
234 | } | |
235 | ||
e59058c4 | 236 | /** |
3621a710 | 237 | * lpfc_modeldesc_show - Return the model description of the hba |
e59058c4 JS |
238 | * @dev: class converted to a Scsi_host structure. |
239 | * @attr: device attribute, not used. | |
240 | * @buf: on return contains the scsi vpd model description. | |
241 | * | |
242 | * Returns: size of formatted string. | |
243 | **/ | |
dea3101e | 244 | static ssize_t |
ee959b00 TJ |
245 | lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, |
246 | char *buf) | |
dea3101e | 247 | { |
ee959b00 | 248 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
249 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
250 | struct lpfc_hba *phba = vport->phba; | |
251 | ||
dea3101e | 252 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
253 | } | |
254 | ||
e59058c4 | 255 | /** |
3621a710 | 256 | * lpfc_modelname_show - Return the model name of the hba |
e59058c4 JS |
257 | * @dev: class converted to a Scsi_host structure. |
258 | * @attr: device attribute, not used. | |
259 | * @buf: on return contains the scsi vpd model name. | |
260 | * | |
261 | * Returns: size of formatted string. | |
262 | **/ | |
dea3101e | 263 | static ssize_t |
ee959b00 TJ |
264 | lpfc_modelname_show(struct device *dev, struct device_attribute *attr, |
265 | char *buf) | |
dea3101e | 266 | { |
ee959b00 | 267 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
268 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
269 | struct lpfc_hba *phba = vport->phba; | |
270 | ||
dea3101e | 271 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
272 | } | |
273 | ||
e59058c4 | 274 | /** |
3621a710 | 275 | * lpfc_programtype_show - Return the program type of the hba |
e59058c4 JS |
276 | * @dev: class converted to a Scsi_host structure. |
277 | * @attr: device attribute, not used. | |
278 | * @buf: on return contains the scsi vpd program type. | |
279 | * | |
280 | * Returns: size of formatted string. | |
281 | **/ | |
dea3101e | 282 | static ssize_t |
ee959b00 TJ |
283 | lpfc_programtype_show(struct device *dev, struct device_attribute *attr, |
284 | char *buf) | |
dea3101e | 285 | { |
ee959b00 | 286 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
287 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
288 | struct lpfc_hba *phba = vport->phba; | |
289 | ||
dea3101e | 290 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
291 | } | |
292 | ||
84774a4d | 293 | /** |
3621a710 | 294 | * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag |
84774a4d JS |
295 | * @dev: class converted to a Scsi_host structure. |
296 | * @attr: device attribute, not used. | |
297 | * @buf: on return contains the Menlo Maintenance sli flag. | |
298 | * | |
299 | * Returns: size of formatted string. | |
300 | **/ | |
301 | static ssize_t | |
302 | lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) | |
303 | { | |
304 | struct Scsi_Host *shost = class_to_shost(dev); | |
305 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
306 | struct lpfc_hba *phba = vport->phba; | |
307 | ||
308 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
309 | (phba->sli.sli_flag & LPFC_MENLO_MAINT)); | |
310 | } | |
311 | ||
e59058c4 | 312 | /** |
3621a710 | 313 | * lpfc_vportnum_show - Return the port number in ascii of the hba |
e59058c4 JS |
314 | * @dev: class converted to a Scsi_host structure. |
315 | * @attr: device attribute, not used. | |
316 | * @buf: on return contains scsi vpd program type. | |
317 | * | |
318 | * Returns: size of formatted string. | |
319 | **/ | |
dea3101e | 320 | static ssize_t |
ee959b00 TJ |
321 | lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, |
322 | char *buf) | |
dea3101e | 323 | { |
ee959b00 | 324 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
325 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
326 | struct lpfc_hba *phba = vport->phba; | |
327 | ||
dea3101e | 328 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
329 | } | |
330 | ||
e59058c4 | 331 | /** |
3621a710 | 332 | * lpfc_fwrev_show - Return the firmware rev running in the hba |
e59058c4 JS |
333 | * @dev: class converted to a Scsi_host structure. |
334 | * @attr: device attribute, not used. | |
335 | * @buf: on return contains the scsi vpd program type. | |
336 | * | |
337 | * Returns: size of formatted string. | |
338 | **/ | |
dea3101e | 339 | static ssize_t |
ee959b00 TJ |
340 | lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, |
341 | char *buf) | |
dea3101e | 342 | { |
ee959b00 | 343 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
344 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
345 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 346 | char fwrev[32]; |
2e0fef85 | 347 | |
dea3101e | 348 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
92d7f7b0 | 349 | return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); |
dea3101e | 350 | } |
351 | ||
e59058c4 | 352 | /** |
3621a710 | 353 | * lpfc_hdw_show - Return the jedec information about the hba |
e59058c4 JS |
354 | * @dev: class converted to a Scsi_host structure. |
355 | * @attr: device attribute, not used. | |
356 | * @buf: on return contains the scsi vpd program type. | |
357 | * | |
358 | * Returns: size of formatted string. | |
359 | **/ | |
dea3101e | 360 | static ssize_t |
ee959b00 | 361 | lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) |
dea3101e | 362 | { |
363 | char hdw[9]; | |
ee959b00 | 364 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
365 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
366 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 367 | lpfc_vpd_t *vp = &phba->vpd; |
2e0fef85 | 368 | |
dea3101e | 369 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
370 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | |
371 | } | |
e59058c4 JS |
372 | |
373 | /** | |
3621a710 | 374 | * lpfc_option_rom_version_show - Return the adapter ROM FCode version |
e59058c4 JS |
375 | * @dev: class converted to a Scsi_host structure. |
376 | * @attr: device attribute, not used. | |
377 | * @buf: on return contains the ROM and FCode ascii strings. | |
378 | * | |
379 | * Returns: size of formatted string. | |
380 | **/ | |
dea3101e | 381 | static ssize_t |
ee959b00 TJ |
382 | lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, |
383 | char *buf) | |
dea3101e | 384 | { |
ee959b00 | 385 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
386 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
387 | struct lpfc_hba *phba = vport->phba; | |
388 | ||
dea3101e | 389 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); |
390 | } | |
e59058c4 JS |
391 | |
392 | /** | |
3621a710 | 393 | * lpfc_state_show - Return the link state of the port |
e59058c4 JS |
394 | * @dev: class converted to a Scsi_host structure. |
395 | * @attr: device attribute, not used. | |
396 | * @buf: on return contains text describing the state of the link. | |
397 | * | |
398 | * Notes: | |
399 | * The switch statement has no default so zero will be returned. | |
400 | * | |
401 | * Returns: size of formatted string. | |
402 | **/ | |
dea3101e | 403 | static ssize_t |
bbd1ae41 HR |
404 | lpfc_link_state_show(struct device *dev, struct device_attribute *attr, |
405 | char *buf) | |
dea3101e | 406 | { |
ee959b00 | 407 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
408 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
409 | struct lpfc_hba *phba = vport->phba; | |
410 | int len = 0; | |
411 | ||
412 | switch (phba->link_state) { | |
413 | case LPFC_LINK_UNKNOWN: | |
41415862 | 414 | case LPFC_WARM_START: |
dea3101e | 415 | case LPFC_INIT_START: |
416 | case LPFC_INIT_MBX_CMDS: | |
417 | case LPFC_LINK_DOWN: | |
2e0fef85 | 418 | case LPFC_HBA_ERROR: |
a0c87cbd JS |
419 | if (phba->hba_flag & LINK_DISABLED) |
420 | len += snprintf(buf + len, PAGE_SIZE-len, | |
421 | "Link Down - User disabled\n"); | |
422 | else | |
423 | len += snprintf(buf + len, PAGE_SIZE-len, | |
424 | "Link Down\n"); | |
dea3101e | 425 | break; |
426 | case LPFC_LINK_UP: | |
dea3101e | 427 | case LPFC_CLEAR_LA: |
dea3101e | 428 | case LPFC_HBA_READY: |
a8adb832 | 429 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); |
2e0fef85 JS |
430 | |
431 | switch (vport->port_state) { | |
2e0fef85 JS |
432 | case LPFC_LOCAL_CFG_LINK: |
433 | len += snprintf(buf + len, PAGE_SIZE-len, | |
92d7f7b0 | 434 | "Configuring Link\n"); |
2e0fef85 | 435 | break; |
92d7f7b0 | 436 | case LPFC_FDISC: |
2e0fef85 JS |
437 | case LPFC_FLOGI: |
438 | case LPFC_FABRIC_CFG_LINK: | |
439 | case LPFC_NS_REG: | |
440 | case LPFC_NS_QRY: | |
441 | case LPFC_BUILD_DISC_LIST: | |
442 | case LPFC_DISC_AUTH: | |
443 | len += snprintf(buf + len, PAGE_SIZE - len, | |
444 | "Discovery\n"); | |
445 | break; | |
446 | case LPFC_VPORT_READY: | |
447 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); | |
448 | break; | |
449 | ||
92d7f7b0 JS |
450 | case LPFC_VPORT_FAILED: |
451 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); | |
452 | break; | |
453 | ||
454 | case LPFC_VPORT_UNKNOWN: | |
2e0fef85 JS |
455 | len += snprintf(buf + len, PAGE_SIZE - len, |
456 | "Unknown\n"); | |
457 | break; | |
458 | } | |
84774a4d JS |
459 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
460 | len += snprintf(buf + len, PAGE_SIZE-len, | |
461 | " Menlo Maint Mode\n"); | |
76a95d75 | 462 | else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 463 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e | 464 | len += snprintf(buf + len, PAGE_SIZE-len, |
465 | " Public Loop\n"); | |
466 | else | |
467 | len += snprintf(buf + len, PAGE_SIZE-len, | |
468 | " Private Loop\n"); | |
469 | } else { | |
2e0fef85 | 470 | if (vport->fc_flag & FC_FABRIC) |
dea3101e | 471 | len += snprintf(buf + len, PAGE_SIZE-len, |
472 | " Fabric\n"); | |
473 | else | |
474 | len += snprintf(buf + len, PAGE_SIZE-len, | |
475 | " Point-2-Point\n"); | |
476 | } | |
477 | } | |
2e0fef85 | 478 | |
dea3101e | 479 | return len; |
480 | } | |
481 | ||
84d1b006 JS |
482 | /** |
483 | * lpfc_link_state_store - Transition the link_state on an HBA port | |
484 | * @dev: class device that is converted into a Scsi_host. | |
485 | * @attr: device attribute, not used. | |
486 | * @buf: one or more lpfc_polling_flags values. | |
487 | * @count: not used. | |
488 | * | |
489 | * Returns: | |
490 | * -EINVAL if the buffer is not "up" or "down" | |
491 | * return from link state change function if non-zero | |
492 | * length of the buf on success | |
493 | **/ | |
494 | static ssize_t | |
495 | lpfc_link_state_store(struct device *dev, struct device_attribute *attr, | |
496 | const char *buf, size_t count) | |
497 | { | |
498 | struct Scsi_Host *shost = class_to_shost(dev); | |
499 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
500 | struct lpfc_hba *phba = vport->phba; | |
501 | ||
502 | int status = -EINVAL; | |
503 | ||
504 | if ((strncmp(buf, "up", sizeof("up") - 1) == 0) && | |
505 | (phba->link_state == LPFC_LINK_DOWN)) | |
6e7288d9 | 506 | status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
84d1b006 JS |
507 | else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) && |
508 | (phba->link_state >= LPFC_LINK_UP)) | |
6e7288d9 | 509 | status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT); |
84d1b006 JS |
510 | |
511 | if (status == 0) | |
512 | return strlen(buf); | |
513 | else | |
514 | return status; | |
515 | } | |
516 | ||
e59058c4 | 517 | /** |
3621a710 | 518 | * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports |
e59058c4 JS |
519 | * @dev: class device that is converted into a Scsi_host. |
520 | * @attr: device attribute, not used. | |
521 | * @buf: on return contains the sum of fc mapped and unmapped. | |
522 | * | |
523 | * Description: | |
524 | * Returns the ascii text number of the sum of the fc mapped and unmapped | |
525 | * vport counts. | |
526 | * | |
527 | * Returns: size of formatted string. | |
528 | **/ | |
dea3101e | 529 | static ssize_t |
ee959b00 TJ |
530 | lpfc_num_discovered_ports_show(struct device *dev, |
531 | struct device_attribute *attr, char *buf) | |
dea3101e | 532 | { |
ee959b00 | 533 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
534 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
535 | ||
536 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
537 | vport->fc_map_cnt + vport->fc_unmap_cnt); | |
dea3101e | 538 | } |
539 | ||
e59058c4 | 540 | /** |
3621a710 | 541 | * lpfc_issue_lip - Misnomer, name carried over from long ago |
e59058c4 JS |
542 | * @shost: Scsi_Host pointer. |
543 | * | |
544 | * Description: | |
545 | * Bring the link down gracefully then re-init the link. The firmware will | |
546 | * re-init the fiber channel interface as required. Does not issue a LIP. | |
547 | * | |
548 | * Returns: | |
549 | * -EPERM port offline or management commands are being blocked | |
550 | * -ENOMEM cannot allocate memory for the mailbox command | |
551 | * -EIO error sending the mailbox command | |
552 | * zero for success | |
553 | **/ | |
91ca7b01 | 554 | static int |
2e0fef85 | 555 | lpfc_issue_lip(struct Scsi_Host *shost) |
dea3101e | 556 | { |
2e0fef85 JS |
557 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
558 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 559 | LPFC_MBOXQ_t *pmboxq; |
560 | int mbxstatus = MBXERR_ERROR; | |
561 | ||
2e0fef85 | 562 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
83108bd3 | 563 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) |
dea3101e | 564 | return -EPERM; |
565 | ||
566 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
567 | ||
568 | if (!pmboxq) | |
569 | return -ENOMEM; | |
570 | ||
571 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
04c68496 JS |
572 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; |
573 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
4db621e0 | 574 | |
33ccf8d1 | 575 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
dea3101e | 576 | |
04c68496 JS |
577 | if ((mbxstatus == MBX_SUCCESS) && |
578 | (pmboxq->u.mb.mbxStatus == 0 || | |
579 | pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) { | |
4db621e0 JS |
580 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
581 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, | |
582 | phba->cfg_link_speed); | |
583 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
584 | phba->fc_ratov * 2); | |
dcf2a4e0 JS |
585 | if ((mbxstatus == MBX_SUCCESS) && |
586 | (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
587 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
588 | "2859 SLI authentication is required " | |
589 | "for INIT_LINK but has not done yet\n"); | |
4db621e0 JS |
590 | } |
591 | ||
5b8bd0c9 | 592 | lpfc_set_loopback_flag(phba); |
858c9f6c | 593 | if (mbxstatus != MBX_TIMEOUT) |
433c3579 | 594 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 595 | |
596 | if (mbxstatus == MBXERR_ERROR) | |
597 | return -EIO; | |
598 | ||
91ca7b01 | 599 | return 0; |
dea3101e | 600 | } |
601 | ||
e59058c4 | 602 | /** |
3621a710 | 603 | * lpfc_do_offline - Issues a mailbox command to bring the link down |
e59058c4 JS |
604 | * @phba: lpfc_hba pointer. |
605 | * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. | |
606 | * | |
607 | * Notes: | |
608 | * Assumes any error from lpfc_do_offline() will be negative. | |
609 | * Can wait up to 5 seconds for the port ring buffers count | |
610 | * to reach zero, prints a warning if it is not zero and continues. | |
3621a710 | 611 | * lpfc_workq_post_event() returns a non-zero return code if call fails. |
e59058c4 JS |
612 | * |
613 | * Returns: | |
614 | * -EIO error posting the event | |
615 | * zero for success | |
616 | **/ | |
40496f07 | 617 | static int |
46fa311e | 618 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) |
40496f07 JS |
619 | { |
620 | struct completion online_compl; | |
46fa311e JS |
621 | struct lpfc_sli_ring *pring; |
622 | struct lpfc_sli *psli; | |
40496f07 | 623 | int status = 0; |
46fa311e JS |
624 | int cnt = 0; |
625 | int i; | |
fedd3b7b | 626 | int rc; |
40496f07 JS |
627 | |
628 | init_completion(&online_compl); | |
fedd3b7b | 629 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
46fa311e | 630 | LPFC_EVT_OFFLINE_PREP); |
fedd3b7b JS |
631 | if (rc == 0) |
632 | return -ENOMEM; | |
633 | ||
46fa311e JS |
634 | wait_for_completion(&online_compl); |
635 | ||
636 | if (status != 0) | |
637 | return -EIO; | |
638 | ||
639 | psli = &phba->sli; | |
640 | ||
09372820 JS |
641 | /* Wait a little for things to settle down, but not |
642 | * long enough for dev loss timeout to expire. | |
643 | */ | |
46fa311e JS |
644 | for (i = 0; i < psli->num_rings; i++) { |
645 | pring = &psli->ring[i]; | |
46fa311e JS |
646 | while (pring->txcmplq_cnt) { |
647 | msleep(10); | |
09372820 | 648 | if (cnt++ > 500) { /* 5 secs */ |
46fa311e JS |
649 | lpfc_printf_log(phba, |
650 | KERN_WARNING, LOG_INIT, | |
e8b62011 JS |
651 | "0466 Outstanding IO when " |
652 | "bringing Adapter offline\n"); | |
46fa311e JS |
653 | break; |
654 | } | |
655 | } | |
656 | } | |
657 | ||
658 | init_completion(&online_compl); | |
fedd3b7b JS |
659 | rc = lpfc_workq_post_event(phba, &status, &online_compl, type); |
660 | if (rc == 0) | |
661 | return -ENOMEM; | |
662 | ||
40496f07 JS |
663 | wait_for_completion(&online_compl); |
664 | ||
665 | if (status != 0) | |
666 | return -EIO; | |
667 | ||
46fa311e JS |
668 | return 0; |
669 | } | |
670 | ||
e59058c4 | 671 | /** |
3621a710 | 672 | * lpfc_selective_reset - Offline then onlines the port |
e59058c4 JS |
673 | * @phba: lpfc_hba pointer. |
674 | * | |
675 | * Description: | |
676 | * If the port is configured to allow a reset then the hba is brought | |
677 | * offline then online. | |
678 | * | |
679 | * Notes: | |
680 | * Assumes any error from lpfc_do_offline() will be negative. | |
ab56dc2e | 681 | * Do not make this function static. |
e59058c4 JS |
682 | * |
683 | * Returns: | |
684 | * lpfc_do_offline() return code if not zero | |
685 | * -EIO reset not configured or error posting the event | |
686 | * zero for success | |
687 | **/ | |
7f86059a | 688 | int |
46fa311e JS |
689 | lpfc_selective_reset(struct lpfc_hba *phba) |
690 | { | |
691 | struct completion online_compl; | |
692 | int status = 0; | |
fedd3b7b | 693 | int rc; |
46fa311e | 694 | |
13815c83 JS |
695 | if (!phba->cfg_enable_hba_reset) |
696 | return -EIO; | |
697 | ||
46fa311e JS |
698 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
699 | ||
700 | if (status != 0) | |
701 | return status; | |
702 | ||
40496f07 | 703 | init_completion(&online_compl); |
fedd3b7b | 704 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
40496f07 | 705 | LPFC_EVT_ONLINE); |
fedd3b7b JS |
706 | if (rc == 0) |
707 | return -ENOMEM; | |
708 | ||
40496f07 JS |
709 | wait_for_completion(&online_compl); |
710 | ||
711 | if (status != 0) | |
712 | return -EIO; | |
713 | ||
714 | return 0; | |
715 | } | |
716 | ||
e59058c4 | 717 | /** |
3621a710 | 718 | * lpfc_issue_reset - Selectively resets an adapter |
e59058c4 JS |
719 | * @dev: class device that is converted into a Scsi_host. |
720 | * @attr: device attribute, not used. | |
721 | * @buf: containing the string "selective". | |
722 | * @count: unused variable. | |
723 | * | |
724 | * Description: | |
725 | * If the buf contains the string "selective" then lpfc_selective_reset() | |
726 | * is called to perform the reset. | |
727 | * | |
728 | * Notes: | |
729 | * Assumes any error from lpfc_selective_reset() will be negative. | |
730 | * If lpfc_selective_reset() returns zero then the length of the buffer | |
af901ca1 | 731 | * is returned which indicates success |
e59058c4 JS |
732 | * |
733 | * Returns: | |
734 | * -EINVAL if the buffer does not contain the string "selective" | |
735 | * length of buf if lpfc-selective_reset() if the call succeeds | |
736 | * return value of lpfc_selective_reset() if the call fails | |
737 | **/ | |
40496f07 | 738 | static ssize_t |
ee959b00 TJ |
739 | lpfc_issue_reset(struct device *dev, struct device_attribute *attr, |
740 | const char *buf, size_t count) | |
40496f07 | 741 | { |
ee959b00 | 742 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
743 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
744 | struct lpfc_hba *phba = vport->phba; | |
745 | ||
40496f07 JS |
746 | int status = -EINVAL; |
747 | ||
748 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) | |
7f86059a | 749 | status = phba->lpfc_selective_reset(phba); |
40496f07 JS |
750 | |
751 | if (status == 0) | |
752 | return strlen(buf); | |
753 | else | |
754 | return status; | |
755 | } | |
756 | ||
c0c11512 JS |
757 | /** |
758 | * lpfc_sli4_fw_dump_request - Request firmware to perform a firmware dump | |
759 | * @phba: lpfc_hba pointer. | |
760 | * | |
761 | * Description: | |
762 | * Request SLI4 interface type-2 device to perform a dump of firmware dump | |
763 | * object into it's /dbg directory of the flash file system. | |
764 | * | |
765 | * Returns: | |
766 | * zero for success | |
767 | **/ | |
768 | static ssize_t | |
769 | lpfc_sli4_fw_dump_request(struct lpfc_hba *phba) | |
770 | { | |
771 | struct completion online_compl; | |
772 | uint32_t reg_val; | |
773 | int status = 0; | |
774 | int rc; | |
775 | ||
776 | if (!phba->cfg_enable_hba_reset) | |
777 | return -EIO; | |
778 | ||
779 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
780 | ||
781 | if (status != 0) | |
782 | return status; | |
783 | ||
784 | /* wait for the device to be quiesced before firmware reset */ | |
785 | msleep(100); | |
786 | ||
787 | reg_val = readl(phba->sli4_hba.conf_regs_memmap_p + | |
788 | LPFC_CTL_PDEV_CTL_OFFSET); | |
789 | reg_val |= LPFC_FW_DUMP_REQUEST; | |
790 | writel(reg_val, phba->sli4_hba.conf_regs_memmap_p + | |
791 | LPFC_CTL_PDEV_CTL_OFFSET); | |
792 | /* flush */ | |
793 | readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); | |
794 | ||
795 | /* delay driver action following IF_TYPE_2 reset */ | |
796 | msleep(100); | |
797 | ||
798 | init_completion(&online_compl); | |
799 | rc = lpfc_workq_post_event(phba, &status, &online_compl, | |
800 | LPFC_EVT_ONLINE); | |
801 | if (rc == 0) | |
802 | return -ENOMEM; | |
803 | ||
804 | wait_for_completion(&online_compl); | |
805 | ||
806 | if (status != 0) | |
807 | return -EIO; | |
808 | ||
809 | return 0; | |
810 | } | |
811 | ||
e59058c4 | 812 | /** |
3621a710 | 813 | * lpfc_nport_evt_cnt_show - Return the number of nport events |
e59058c4 JS |
814 | * @dev: class device that is converted into a Scsi_host. |
815 | * @attr: device attribute, not used. | |
816 | * @buf: on return contains the ascii number of nport events. | |
817 | * | |
818 | * Returns: size of formatted string. | |
819 | **/ | |
dea3101e | 820 | static ssize_t |
ee959b00 TJ |
821 | lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, |
822 | char *buf) | |
dea3101e | 823 | { |
ee959b00 | 824 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
825 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
826 | struct lpfc_hba *phba = vport->phba; | |
827 | ||
dea3101e | 828 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
829 | } | |
830 | ||
e59058c4 | 831 | /** |
3621a710 | 832 | * lpfc_board_mode_show - Return the state of the board |
e59058c4 JS |
833 | * @dev: class device that is converted into a Scsi_host. |
834 | * @attr: device attribute, not used. | |
835 | * @buf: on return contains the state of the adapter. | |
836 | * | |
837 | * Returns: size of formatted string. | |
838 | **/ | |
41415862 | 839 | static ssize_t |
ee959b00 TJ |
840 | lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, |
841 | char *buf) | |
41415862 | 842 | { |
ee959b00 | 843 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
844 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
845 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
846 | char * state; |
847 | ||
2e0fef85 | 848 | if (phba->link_state == LPFC_HBA_ERROR) |
41415862 | 849 | state = "error"; |
2e0fef85 | 850 | else if (phba->link_state == LPFC_WARM_START) |
41415862 | 851 | state = "warm start"; |
2e0fef85 | 852 | else if (phba->link_state == LPFC_INIT_START) |
41415862 JW |
853 | state = "offline"; |
854 | else | |
855 | state = "online"; | |
856 | ||
857 | return snprintf(buf, PAGE_SIZE, "%s\n", state); | |
858 | } | |
859 | ||
e59058c4 | 860 | /** |
3621a710 | 861 | * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state |
e59058c4 JS |
862 | * @dev: class device that is converted into a Scsi_host. |
863 | * @attr: device attribute, not used. | |
864 | * @buf: containing one of the strings "online", "offline", "warm" or "error". | |
865 | * @count: unused variable. | |
866 | * | |
867 | * Returns: | |
868 | * -EACCES if enable hba reset not enabled | |
869 | * -EINVAL if the buffer does not contain a valid string (see above) | |
870 | * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails | |
871 | * buf length greater than zero indicates success | |
872 | **/ | |
41415862 | 873 | static ssize_t |
ee959b00 TJ |
874 | lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, |
875 | const char *buf, size_t count) | |
41415862 | 876 | { |
ee959b00 | 877 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
878 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
879 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
880 | struct completion online_compl; |
881 | int status=0; | |
fedd3b7b | 882 | int rc; |
41415862 | 883 | |
13815c83 JS |
884 | if (!phba->cfg_enable_hba_reset) |
885 | return -EACCES; | |
41415862 JW |
886 | init_completion(&online_compl); |
887 | ||
46fa311e | 888 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { |
fedd3b7b | 889 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
41415862 | 890 | LPFC_EVT_ONLINE); |
fedd3b7b JS |
891 | if (rc == 0) |
892 | return -ENOMEM; | |
46fa311e JS |
893 | wait_for_completion(&online_compl); |
894 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) | |
895 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
41415862 | 896 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
6a9c52cf JS |
897 | if (phba->sli_rev == LPFC_SLI_REV4) |
898 | return -EINVAL; | |
899 | else | |
900 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); | |
46fa311e | 901 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) |
6a9c52cf JS |
902 | if (phba->sli_rev == LPFC_SLI_REV4) |
903 | return -EINVAL; | |
904 | else | |
905 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); | |
c0c11512 JS |
906 | else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0) |
907 | if ((phba->sli_rev < LPFC_SLI_REV4) || | |
908 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
909 | LPFC_SLI_INTF_IF_TYPE_2)) | |
910 | return -EPERM; | |
911 | else | |
912 | status = lpfc_sli4_fw_dump_request(phba); | |
41415862 JW |
913 | else |
914 | return -EINVAL; | |
915 | ||
41415862 JW |
916 | if (!status) |
917 | return strlen(buf); | |
918 | else | |
919 | return -EIO; | |
920 | } | |
921 | ||
e59058c4 | 922 | /** |
3621a710 | 923 | * lpfc_get_hba_info - Return various bits of informaton about the adapter |
e59058c4 | 924 | * @phba: pointer to the adapter structure. |
3621a710 JS |
925 | * @mxri: max xri count. |
926 | * @axri: available xri count. | |
927 | * @mrpi: max rpi count. | |
928 | * @arpi: available rpi count. | |
929 | * @mvpi: max vpi count. | |
930 | * @avpi: available vpi count. | |
e59058c4 JS |
931 | * |
932 | * Description: | |
933 | * If an integer pointer for an count is not null then the value for the | |
934 | * count is returned. | |
935 | * | |
936 | * Returns: | |
937 | * zero on error | |
938 | * one for success | |
939 | **/ | |
311464ec | 940 | static int |
858c9f6c JS |
941 | lpfc_get_hba_info(struct lpfc_hba *phba, |
942 | uint32_t *mxri, uint32_t *axri, | |
943 | uint32_t *mrpi, uint32_t *arpi, | |
944 | uint32_t *mvpi, uint32_t *avpi) | |
92d7f7b0 | 945 | { |
04c68496 | 946 | struct lpfc_mbx_read_config *rd_config; |
92d7f7b0 JS |
947 | LPFC_MBOXQ_t *pmboxq; |
948 | MAILBOX_t *pmb; | |
949 | int rc = 0; | |
15672319 | 950 | uint32_t max_vpi; |
92d7f7b0 JS |
951 | |
952 | /* | |
953 | * prevent udev from issuing mailbox commands until the port is | |
954 | * configured. | |
955 | */ | |
956 | if (phba->link_state < LPFC_LINK_DOWN || | |
957 | !phba->mbox_mem_pool || | |
f4b4c68f | 958 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 JS |
959 | return 0; |
960 | ||
961 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
962 | return 0; | |
963 | ||
964 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
965 | if (!pmboxq) | |
966 | return 0; | |
967 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
968 | ||
04c68496 | 969 | pmb = &pmboxq->u.mb; |
92d7f7b0 JS |
970 | pmb->mbxCommand = MBX_READ_CONFIG; |
971 | pmb->mbxOwner = OWN_HOST; | |
972 | pmboxq->context1 = NULL; | |
973 | ||
75baf696 | 974 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
92d7f7b0 JS |
975 | rc = MBX_NOT_FINISHED; |
976 | else | |
977 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
978 | ||
979 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 980 | if (rc != MBX_TIMEOUT) |
92d7f7b0 JS |
981 | mempool_free(pmboxq, phba->mbox_mem_pool); |
982 | return 0; | |
983 | } | |
984 | ||
da0436e9 JS |
985 | if (phba->sli_rev == LPFC_SLI_REV4) { |
986 | rd_config = &pmboxq->u.mqe.un.rd_config; | |
987 | if (mrpi) | |
988 | *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
989 | if (arpi) | |
990 | *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - | |
991 | phba->sli4_hba.max_cfg_param.rpi_used; | |
992 | if (mxri) | |
993 | *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
994 | if (axri) | |
995 | *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - | |
996 | phba->sli4_hba.max_cfg_param.xri_used; | |
15672319 JS |
997 | |
998 | /* Account for differences with SLI-3. Get vpi count from | |
999 | * mailbox data and subtract one for max vpi value. | |
1000 | */ | |
1001 | max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? | |
1002 | (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; | |
1003 | ||
da0436e9 | 1004 | if (mvpi) |
15672319 | 1005 | *mvpi = max_vpi; |
da0436e9 | 1006 | if (avpi) |
15672319 | 1007 | *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; |
da0436e9 JS |
1008 | } else { |
1009 | if (mrpi) | |
1010 | *mrpi = pmb->un.varRdConfig.max_rpi; | |
1011 | if (arpi) | |
1012 | *arpi = pmb->un.varRdConfig.avail_rpi; | |
1013 | if (mxri) | |
1014 | *mxri = pmb->un.varRdConfig.max_xri; | |
1015 | if (axri) | |
1016 | *axri = pmb->un.varRdConfig.avail_xri; | |
1017 | if (mvpi) | |
1018 | *mvpi = pmb->un.varRdConfig.max_vpi; | |
1019 | if (avpi) | |
1020 | *avpi = pmb->un.varRdConfig.avail_vpi; | |
1021 | } | |
92d7f7b0 JS |
1022 | |
1023 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1024 | return 1; | |
1025 | } | |
1026 | ||
e59058c4 | 1027 | /** |
3621a710 | 1028 | * lpfc_max_rpi_show - Return maximum rpi |
e59058c4 JS |
1029 | * @dev: class device that is converted into a Scsi_host. |
1030 | * @attr: device attribute, not used. | |
1031 | * @buf: on return contains the maximum rpi count in decimal or "Unknown". | |
1032 | * | |
1033 | * Description: | |
1034 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1035 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1036 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1037 | * must check for "Unknown" in the buffer to detect a failure. | |
1038 | * | |
1039 | * Returns: size of formatted string. | |
1040 | **/ | |
92d7f7b0 | 1041 | static ssize_t |
ee959b00 TJ |
1042 | lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, |
1043 | char *buf) | |
92d7f7b0 | 1044 | { |
ee959b00 | 1045 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1046 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1047 | struct lpfc_hba *phba = vport->phba; | |
1048 | uint32_t cnt; | |
1049 | ||
858c9f6c | 1050 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) |
92d7f7b0 JS |
1051 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1052 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1053 | } | |
1054 | ||
e59058c4 | 1055 | /** |
3621a710 | 1056 | * lpfc_used_rpi_show - Return maximum rpi minus available rpi |
e59058c4 JS |
1057 | * @dev: class device that is converted into a Scsi_host. |
1058 | * @attr: device attribute, not used. | |
1059 | * @buf: containing the used rpi count in decimal or "Unknown". | |
1060 | * | |
1061 | * Description: | |
1062 | * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. | |
1063 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1064 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1065 | * must check for "Unknown" in the buffer to detect a failure. | |
1066 | * | |
1067 | * Returns: size of formatted string. | |
1068 | **/ | |
92d7f7b0 | 1069 | static ssize_t |
ee959b00 TJ |
1070 | lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, |
1071 | char *buf) | |
92d7f7b0 | 1072 | { |
ee959b00 | 1073 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1074 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1075 | struct lpfc_hba *phba = vport->phba; | |
1076 | uint32_t cnt, acnt; | |
1077 | ||
858c9f6c | 1078 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) |
92d7f7b0 JS |
1079 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1080 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1081 | } | |
1082 | ||
e59058c4 | 1083 | /** |
3621a710 | 1084 | * lpfc_max_xri_show - Return maximum xri |
e59058c4 JS |
1085 | * @dev: class device that is converted into a Scsi_host. |
1086 | * @attr: device attribute, not used. | |
1087 | * @buf: on return contains the maximum xri count in decimal or "Unknown". | |
1088 | * | |
1089 | * Description: | |
1090 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1091 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1092 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1093 | * must check for "Unknown" in the buffer to detect a failure. | |
1094 | * | |
1095 | * Returns: size of formatted string. | |
1096 | **/ | |
92d7f7b0 | 1097 | static ssize_t |
ee959b00 TJ |
1098 | lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, |
1099 | char *buf) | |
92d7f7b0 | 1100 | { |
ee959b00 | 1101 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1102 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1103 | struct lpfc_hba *phba = vport->phba; | |
1104 | uint32_t cnt; | |
1105 | ||
858c9f6c | 1106 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) |
92d7f7b0 JS |
1107 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1108 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1109 | } | |
1110 | ||
e59058c4 | 1111 | /** |
3621a710 | 1112 | * lpfc_used_xri_show - Return maximum xpi minus the available xpi |
e59058c4 JS |
1113 | * @dev: class device that is converted into a Scsi_host. |
1114 | * @attr: device attribute, not used. | |
1115 | * @buf: on return contains the used xri count in decimal or "Unknown". | |
1116 | * | |
1117 | * Description: | |
1118 | * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. | |
1119 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1120 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1121 | * must check for "Unknown" in the buffer to detect a failure. | |
1122 | * | |
1123 | * Returns: size of formatted string. | |
1124 | **/ | |
92d7f7b0 | 1125 | static ssize_t |
ee959b00 TJ |
1126 | lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, |
1127 | char *buf) | |
92d7f7b0 | 1128 | { |
ee959b00 | 1129 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1130 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1131 | struct lpfc_hba *phba = vport->phba; | |
1132 | uint32_t cnt, acnt; | |
1133 | ||
858c9f6c JS |
1134 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) |
1135 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | |
1136 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1137 | } | |
1138 | ||
e59058c4 | 1139 | /** |
3621a710 | 1140 | * lpfc_max_vpi_show - Return maximum vpi |
e59058c4 JS |
1141 | * @dev: class device that is converted into a Scsi_host. |
1142 | * @attr: device attribute, not used. | |
1143 | * @buf: on return contains the maximum vpi count in decimal or "Unknown". | |
1144 | * | |
1145 | * Description: | |
1146 | * Calls lpfc_get_hba_info() asking for just the mvpi count. | |
1147 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1148 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1149 | * must check for "Unknown" in the buffer to detect a failure. | |
1150 | * | |
1151 | * Returns: size of formatted string. | |
1152 | **/ | |
858c9f6c | 1153 | static ssize_t |
ee959b00 TJ |
1154 | lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, |
1155 | char *buf) | |
858c9f6c | 1156 | { |
ee959b00 | 1157 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1158 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1159 | struct lpfc_hba *phba = vport->phba; | |
1160 | uint32_t cnt; | |
1161 | ||
1162 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) | |
1163 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | |
1164 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1165 | } | |
1166 | ||
e59058c4 | 1167 | /** |
3621a710 | 1168 | * lpfc_used_vpi_show - Return maximum vpi minus the available vpi |
e59058c4 JS |
1169 | * @dev: class device that is converted into a Scsi_host. |
1170 | * @attr: device attribute, not used. | |
1171 | * @buf: on return contains the used vpi count in decimal or "Unknown". | |
1172 | * | |
1173 | * Description: | |
1174 | * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. | |
1175 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1176 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1177 | * must check for "Unknown" in the buffer to detect a failure. | |
1178 | * | |
1179 | * Returns: size of formatted string. | |
1180 | **/ | |
858c9f6c | 1181 | static ssize_t |
ee959b00 TJ |
1182 | lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, |
1183 | char *buf) | |
858c9f6c | 1184 | { |
ee959b00 | 1185 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1186 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1187 | struct lpfc_hba *phba = vport->phba; | |
1188 | uint32_t cnt, acnt; | |
1189 | ||
1190 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) | |
92d7f7b0 JS |
1191 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1192 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1193 | } | |
1194 | ||
e59058c4 | 1195 | /** |
3621a710 | 1196 | * lpfc_npiv_info_show - Return text about NPIV support for the adapter |
e59058c4 JS |
1197 | * @dev: class device that is converted into a Scsi_host. |
1198 | * @attr: device attribute, not used. | |
1199 | * @buf: text that must be interpreted to determine if npiv is supported. | |
1200 | * | |
1201 | * Description: | |
1202 | * Buffer will contain text indicating npiv is not suppoerted on the port, | |
1203 | * the port is an NPIV physical port, or it is an npiv virtual port with | |
1204 | * the id of the vport. | |
1205 | * | |
1206 | * Returns: size of formatted string. | |
1207 | **/ | |
92d7f7b0 | 1208 | static ssize_t |
ee959b00 TJ |
1209 | lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, |
1210 | char *buf) | |
92d7f7b0 | 1211 | { |
ee959b00 | 1212 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1213 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1214 | struct lpfc_hba *phba = vport->phba; | |
1215 | ||
1216 | if (!(phba->max_vpi)) | |
1217 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); | |
1218 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
1219 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); | |
1220 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); | |
1221 | } | |
1222 | ||
e59058c4 | 1223 | /** |
3621a710 | 1224 | * lpfc_poll_show - Return text about poll support for the adapter |
e59058c4 JS |
1225 | * @dev: class device that is converted into a Scsi_host. |
1226 | * @attr: device attribute, not used. | |
1227 | * @buf: on return contains the cfg_poll in hex. | |
1228 | * | |
1229 | * Notes: | |
1230 | * cfg_poll should be a lpfc_polling_flags type. | |
1231 | * | |
1232 | * Returns: size of formatted string. | |
1233 | **/ | |
875fbdfe | 1234 | static ssize_t |
ee959b00 TJ |
1235 | lpfc_poll_show(struct device *dev, struct device_attribute *attr, |
1236 | char *buf) | |
875fbdfe | 1237 | { |
ee959b00 | 1238 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1239 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1240 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1241 | |
1242 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); | |
1243 | } | |
1244 | ||
e59058c4 | 1245 | /** |
3621a710 | 1246 | * lpfc_poll_store - Set the value of cfg_poll for the adapter |
e59058c4 JS |
1247 | * @dev: class device that is converted into a Scsi_host. |
1248 | * @attr: device attribute, not used. | |
1249 | * @buf: one or more lpfc_polling_flags values. | |
1250 | * @count: not used. | |
1251 | * | |
1252 | * Notes: | |
1253 | * buf contents converted to integer and checked for a valid value. | |
1254 | * | |
1255 | * Returns: | |
1256 | * -EINVAL if the buffer connot be converted or is out of range | |
1257 | * length of the buf on success | |
1258 | **/ | |
875fbdfe | 1259 | static ssize_t |
ee959b00 TJ |
1260 | lpfc_poll_store(struct device *dev, struct device_attribute *attr, |
1261 | const char *buf, size_t count) | |
875fbdfe | 1262 | { |
ee959b00 | 1263 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1264 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1265 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1266 | uint32_t creg_val; |
1267 | uint32_t old_val; | |
1268 | int val=0; | |
1269 | ||
1270 | if (!isdigit(buf[0])) | |
1271 | return -EINVAL; | |
1272 | ||
1273 | if (sscanf(buf, "%i", &val) != 1) | |
1274 | return -EINVAL; | |
1275 | ||
1276 | if ((val & 0x3) != val) | |
1277 | return -EINVAL; | |
1278 | ||
45ed1190 JS |
1279 | if (phba->sli_rev == LPFC_SLI_REV4) |
1280 | val = 0; | |
1281 | ||
2e0fef85 | 1282 | spin_lock_irq(&phba->hbalock); |
875fbdfe JSEC |
1283 | |
1284 | old_val = phba->cfg_poll; | |
1285 | ||
1286 | if (val & ENABLE_FCP_RING_POLLING) { | |
1287 | if ((val & DISABLE_FCP_RING_INT) && | |
1288 | !(old_val & DISABLE_FCP_RING_INT)) { | |
9940b97b JS |
1289 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1290 | spin_unlock_irq(&phba->hbalock); | |
1291 | return -EINVAL; | |
1292 | } | |
875fbdfe JSEC |
1293 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
1294 | writel(creg_val, phba->HCregaddr); | |
1295 | readl(phba->HCregaddr); /* flush */ | |
1296 | ||
1297 | lpfc_poll_start_timer(phba); | |
1298 | } | |
1299 | } else if (val != 0x0) { | |
2e0fef85 | 1300 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1301 | return -EINVAL; |
1302 | } | |
1303 | ||
1304 | if (!(val & DISABLE_FCP_RING_INT) && | |
1305 | (old_val & DISABLE_FCP_RING_INT)) | |
1306 | { | |
2e0fef85 | 1307 | spin_unlock_irq(&phba->hbalock); |
875fbdfe | 1308 | del_timer(&phba->fcp_poll_timer); |
2e0fef85 | 1309 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
1310 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1311 | spin_unlock_irq(&phba->hbalock); | |
1312 | return -EINVAL; | |
1313 | } | |
875fbdfe JSEC |
1314 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
1315 | writel(creg_val, phba->HCregaddr); | |
1316 | readl(phba->HCregaddr); /* flush */ | |
1317 | } | |
1318 | ||
1319 | phba->cfg_poll = val; | |
1320 | ||
2e0fef85 | 1321 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1322 | |
1323 | return strlen(buf); | |
1324 | } | |
dea3101e | 1325 | |
bc73905a JS |
1326 | /** |
1327 | * lpfc_fips_level_show - Return the current FIPS level for the HBA | |
1328 | * @dev: class unused variable. | |
1329 | * @attr: device attribute, not used. | |
1330 | * @buf: on return contains the module description text. | |
1331 | * | |
1332 | * Returns: size of formatted string. | |
1333 | **/ | |
1334 | static ssize_t | |
1335 | lpfc_fips_level_show(struct device *dev, struct device_attribute *attr, | |
1336 | char *buf) | |
1337 | { | |
1338 | struct Scsi_Host *shost = class_to_shost(dev); | |
1339 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1340 | struct lpfc_hba *phba = vport->phba; | |
1341 | ||
1342 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level); | |
1343 | } | |
1344 | ||
1345 | /** | |
1346 | * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA | |
1347 | * @dev: class unused variable. | |
1348 | * @attr: device attribute, not used. | |
1349 | * @buf: on return contains the module description text. | |
1350 | * | |
1351 | * Returns: size of formatted string. | |
1352 | **/ | |
1353 | static ssize_t | |
1354 | lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr, | |
1355 | char *buf) | |
1356 | { | |
1357 | struct Scsi_Host *shost = class_to_shost(dev); | |
1358 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1359 | struct lpfc_hba *phba = vport->phba; | |
1360 | ||
1361 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev); | |
1362 | } | |
1363 | ||
ab56dc2e JS |
1364 | /** |
1365 | * lpfc_dss_show - Return the current state of dss and the configured state | |
1366 | * @dev: class converted to a Scsi_host structure. | |
1367 | * @attr: device attribute, not used. | |
1368 | * @buf: on return contains the formatted text. | |
1369 | * | |
1370 | * Returns: size of formatted string. | |
1371 | **/ | |
1372 | static ssize_t | |
1373 | lpfc_dss_show(struct device *dev, struct device_attribute *attr, | |
1374 | char *buf) | |
1375 | { | |
1376 | struct Scsi_Host *shost = class_to_shost(dev); | |
1377 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1378 | struct lpfc_hba *phba = vport->phba; | |
1379 | ||
1380 | return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n", | |
1381 | (phba->cfg_enable_dss) ? "Enabled" : "Disabled", | |
1382 | (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ? | |
1383 | "" : "Not "); | |
1384 | } | |
1385 | ||
912e3acd JS |
1386 | /** |
1387 | * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions | |
1388 | * @dev: class converted to a Scsi_host structure. | |
1389 | * @attr: device attribute, not used. | |
1390 | * @buf: on return contains the formatted support level. | |
1391 | * | |
1392 | * Description: | |
1393 | * Returns the maximum number of virtual functions a physical function can | |
1394 | * support, 0 will be returned if called on virtual function. | |
1395 | * | |
1396 | * Returns: size of formatted string. | |
1397 | **/ | |
1398 | static ssize_t | |
1399 | lpfc_sriov_hw_max_virtfn_show(struct device *dev, | |
1400 | struct device_attribute *attr, | |
1401 | char *buf) | |
1402 | { | |
1403 | struct Scsi_Host *shost = class_to_shost(dev); | |
1404 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1405 | struct lpfc_hba *phba = vport->phba; | |
1406 | struct pci_dev *pdev = phba->pcidev; | |
1407 | union lpfc_sli4_cfg_shdr *shdr; | |
1408 | uint32_t shdr_status, shdr_add_status; | |
1409 | LPFC_MBOXQ_t *mboxq; | |
1410 | struct lpfc_mbx_get_prof_cfg *get_prof_cfg; | |
1411 | struct lpfc_rsrc_desc_pcie *desc; | |
1412 | uint32_t max_nr_virtfn; | |
1413 | uint32_t desc_count; | |
1414 | int length, rc, i; | |
1415 | ||
1416 | if ((phba->sli_rev < LPFC_SLI_REV4) || | |
1417 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
1418 | LPFC_SLI_INTF_IF_TYPE_2)) | |
1419 | return -EPERM; | |
1420 | ||
1421 | if (!pdev->is_physfn) | |
1422 | return snprintf(buf, PAGE_SIZE, "%d\n", 0); | |
1423 | ||
1424 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1425 | if (!mboxq) | |
1426 | return -ENOMEM; | |
1427 | ||
1428 | /* get the maximum number of virtfn support by physfn */ | |
1429 | length = (sizeof(struct lpfc_mbx_get_prof_cfg) - | |
1430 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
1431 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
1432 | LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG, | |
1433 | length, LPFC_SLI4_MBX_EMBED); | |
1434 | shdr = (union lpfc_sli4_cfg_shdr *) | |
1435 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
1436 | bf_set(lpfc_mbox_hdr_pf_num, &shdr->request, | |
1437 | phba->sli4_hba.iov.pf_number + 1); | |
1438 | ||
1439 | get_prof_cfg = &mboxq->u.mqe.un.get_prof_cfg; | |
1440 | bf_set(lpfc_mbx_get_prof_cfg_prof_tp, &get_prof_cfg->u.request, | |
1441 | LPFC_CFG_TYPE_CURRENT_ACTIVE); | |
1442 | ||
1443 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, | |
1444 | lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG)); | |
1445 | ||
1446 | if (rc != MBX_TIMEOUT) { | |
1447 | /* check return status */ | |
1448 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
1449 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
1450 | &shdr->response); | |
1451 | if (shdr_status || shdr_add_status || rc) | |
1452 | goto error_out; | |
1453 | ||
1454 | } else | |
1455 | goto error_out; | |
1456 | ||
1457 | desc_count = get_prof_cfg->u.response.prof_cfg.rsrc_desc_count; | |
1458 | ||
1459 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { | |
1460 | desc = (struct lpfc_rsrc_desc_pcie *) | |
1461 | &get_prof_cfg->u.response.prof_cfg.desc[i]; | |
1462 | if (LPFC_RSRC_DESC_TYPE_PCIE == | |
1463 | bf_get(lpfc_rsrc_desc_pcie_type, desc)) { | |
1464 | max_nr_virtfn = bf_get(lpfc_rsrc_desc_pcie_nr_virtfn, | |
1465 | desc); | |
1466 | break; | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | if (i < LPFC_RSRC_DESC_MAX_NUM) { | |
1471 | if (rc != MBX_TIMEOUT) | |
1472 | mempool_free(mboxq, phba->mbox_mem_pool); | |
1473 | return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn); | |
1474 | } | |
1475 | ||
1476 | error_out: | |
1477 | if (rc != MBX_TIMEOUT) | |
1478 | mempool_free(mboxq, phba->mbox_mem_pool); | |
1479 | return -EIO; | |
1480 | } | |
1481 | ||
e59058c4 | 1482 | /** |
3621a710 | 1483 | * lpfc_param_show - Return a cfg attribute value in decimal |
e59058c4 JS |
1484 | * |
1485 | * Description: | |
1486 | * Macro that given an attr e.g. hba_queue_depth expands | |
1487 | * into a function with the name lpfc_hba_queue_depth_show. | |
1488 | * | |
1489 | * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. | |
1490 | * @dev: class device that is converted into a Scsi_host. | |
1491 | * @attr: device attribute, not used. | |
1492 | * @buf: on return contains the attribute value in decimal. | |
1493 | * | |
1494 | * Returns: size of formatted string. | |
1495 | **/ | |
dea3101e | 1496 | #define lpfc_param_show(attr) \ |
1497 | static ssize_t \ | |
ee959b00 TJ |
1498 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1499 | char *buf) \ | |
dea3101e | 1500 | { \ |
ee959b00 | 1501 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1502 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1503 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 1504 | uint val = 0;\ |
7bcbb752 JSEC |
1505 | val = phba->cfg_##attr;\ |
1506 | return snprintf(buf, PAGE_SIZE, "%d\n",\ | |
1507 | phba->cfg_##attr);\ | |
1508 | } | |
1509 | ||
e59058c4 | 1510 | /** |
3621a710 | 1511 | * lpfc_param_hex_show - Return a cfg attribute value in hex |
e59058c4 JS |
1512 | * |
1513 | * Description: | |
1514 | * Macro that given an attr e.g. hba_queue_depth expands | |
1515 | * into a function with the name lpfc_hba_queue_depth_show | |
1516 | * | |
1517 | * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. | |
1518 | * @dev: class device that is converted into a Scsi_host. | |
1519 | * @attr: device attribute, not used. | |
3621a710 | 1520 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
1521 | * |
1522 | * Returns: size of formatted string. | |
1523 | **/ | |
93a20f74 JSEC |
1524 | #define lpfc_param_hex_show(attr) \ |
1525 | static ssize_t \ | |
ee959b00 TJ |
1526 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1527 | char *buf) \ | |
93a20f74 | 1528 | { \ |
ee959b00 | 1529 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1530 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1531 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 1532 | uint val = 0;\ |
93a20f74 JSEC |
1533 | val = phba->cfg_##attr;\ |
1534 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ | |
1535 | phba->cfg_##attr);\ | |
1536 | } | |
1537 | ||
e59058c4 | 1538 | /** |
b595076a | 1539 | * lpfc_param_init - Initializes a cfg attribute |
e59058c4 JS |
1540 | * |
1541 | * Description: | |
1542 | * Macro that given an attr e.g. hba_queue_depth expands | |
1543 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1544 | * takes a default argument, a minimum and maximum argument. | |
1545 | * | |
1546 | * lpfc_##attr##_init: Initializes an attribute. | |
1547 | * @phba: pointer the the adapter structure. | |
1548 | * @val: integer attribute value. | |
1549 | * | |
1550 | * Validates the min and max values then sets the adapter config field | |
1551 | * accordingly, or uses the default if out of range and prints an error message. | |
1552 | * | |
1553 | * Returns: | |
1554 | * zero on success | |
1555 | * -EINVAL if default used | |
1556 | **/ | |
7bcbb752 JSEC |
1557 | #define lpfc_param_init(attr, default, minval, maxval) \ |
1558 | static int \ | |
84d1b006 | 1559 | lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \ |
7bcbb752 JSEC |
1560 | { \ |
1561 | if (val >= minval && val <= maxval) {\ | |
1562 | phba->cfg_##attr = val;\ | |
1563 | return 0;\ | |
dea3101e | 1564 | }\ |
7bcbb752 | 1565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
e8b62011 JS |
1566 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
1567 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1568 | phba->cfg_##attr = default;\ |
1569 | return -EINVAL;\ | |
dea3101e | 1570 | } |
1571 | ||
e59058c4 | 1572 | /** |
3621a710 | 1573 | * lpfc_param_set - Set a cfg attribute value |
e59058c4 JS |
1574 | * |
1575 | * Description: | |
1576 | * Macro that given an attr e.g. hba_queue_depth expands | |
1577 | * into a function with the name lpfc_hba_queue_depth_set | |
1578 | * | |
1579 | * lpfc_##attr##_set: Sets an attribute value. | |
1580 | * @phba: pointer the the adapter structure. | |
1581 | * @val: integer attribute value. | |
1582 | * | |
1583 | * Description: | |
1584 | * Validates the min and max values then sets the | |
1585 | * adapter config field if in the valid range. prints error message | |
1586 | * and does not set the parameter if invalid. | |
1587 | * | |
1588 | * Returns: | |
1589 | * zero on success | |
1590 | * -EINVAL if val is invalid | |
1591 | **/ | |
7bcbb752 JSEC |
1592 | #define lpfc_param_set(attr, default, minval, maxval) \ |
1593 | static int \ | |
84d1b006 | 1594 | lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \ |
7bcbb752 JSEC |
1595 | { \ |
1596 | if (val >= minval && val <= maxval) {\ | |
1597 | phba->cfg_##attr = val;\ | |
1598 | return 0;\ | |
1599 | }\ | |
1600 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | |
e8b62011 JS |
1601 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
1602 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1603 | return -EINVAL;\ |
1604 | } | |
1605 | ||
e59058c4 | 1606 | /** |
3621a710 | 1607 | * lpfc_param_store - Set a vport attribute value |
e59058c4 JS |
1608 | * |
1609 | * Description: | |
1610 | * Macro that given an attr e.g. hba_queue_depth expands | |
1611 | * into a function with the name lpfc_hba_queue_depth_store. | |
1612 | * | |
1613 | * lpfc_##attr##_store: Set an sttribute value. | |
1614 | * @dev: class device that is converted into a Scsi_host. | |
1615 | * @attr: device attribute, not used. | |
1616 | * @buf: contains the attribute value in ascii. | |
1617 | * @count: not used. | |
1618 | * | |
1619 | * Description: | |
1620 | * Convert the ascii text number to an integer, then | |
1621 | * use the lpfc_##attr##_set function to set the value. | |
1622 | * | |
1623 | * Returns: | |
1624 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
1625 | * length of buffer upon success. | |
1626 | **/ | |
7bcbb752 | 1627 | #define lpfc_param_store(attr) \ |
dea3101e | 1628 | static ssize_t \ |
ee959b00 TJ |
1629 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
1630 | const char *buf, size_t count) \ | |
dea3101e | 1631 | { \ |
ee959b00 | 1632 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1633 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1634 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 1635 | uint val = 0;\ |
93a20f74 JSEC |
1636 | if (!isdigit(buf[0]))\ |
1637 | return -EINVAL;\ | |
1638 | if (sscanf(buf, "%i", &val) != 1)\ | |
1639 | return -EINVAL;\ | |
7bcbb752 | 1640 | if (lpfc_##attr##_set(phba, val) == 0) \ |
755c0d06 | 1641 | return strlen(buf);\ |
7bcbb752 JSEC |
1642 | else \ |
1643 | return -EINVAL;\ | |
dea3101e | 1644 | } |
1645 | ||
e59058c4 | 1646 | /** |
3621a710 | 1647 | * lpfc_vport_param_show - Return decimal formatted cfg attribute value |
e59058c4 JS |
1648 | * |
1649 | * Description: | |
1650 | * Macro that given an attr e.g. hba_queue_depth expands | |
1651 | * into a function with the name lpfc_hba_queue_depth_show | |
1652 | * | |
1653 | * lpfc_##attr##_show: prints the attribute value in decimal. | |
1654 | * @dev: class device that is converted into a Scsi_host. | |
1655 | * @attr: device attribute, not used. | |
1656 | * @buf: on return contains the attribute value in decimal. | |
1657 | * | |
1658 | * Returns: length of formatted string. | |
1659 | **/ | |
3de2a653 JS |
1660 | #define lpfc_vport_param_show(attr) \ |
1661 | static ssize_t \ | |
ee959b00 TJ |
1662 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1663 | char *buf) \ | |
3de2a653 | 1664 | { \ |
ee959b00 | 1665 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 1666 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
84d1b006 | 1667 | uint val = 0;\ |
3de2a653 JS |
1668 | val = vport->cfg_##attr;\ |
1669 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ | |
1670 | } | |
1671 | ||
e59058c4 | 1672 | /** |
3621a710 | 1673 | * lpfc_vport_param_hex_show - Return hex formatted attribute value |
e59058c4 JS |
1674 | * |
1675 | * Description: | |
1676 | * Macro that given an attr e.g. | |
1677 | * hba_queue_depth expands into a function with the name | |
1678 | * lpfc_hba_queue_depth_show | |
1679 | * | |
3621a710 | 1680 | * lpfc_##attr##_show: prints the attribute value in hexadecimal. |
e59058c4 JS |
1681 | * @dev: class device that is converted into a Scsi_host. |
1682 | * @attr: device attribute, not used. | |
3621a710 | 1683 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
1684 | * |
1685 | * Returns: length of formatted string. | |
1686 | **/ | |
3de2a653 JS |
1687 | #define lpfc_vport_param_hex_show(attr) \ |
1688 | static ssize_t \ | |
ee959b00 TJ |
1689 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1690 | char *buf) \ | |
3de2a653 | 1691 | { \ |
ee959b00 | 1692 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 1693 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
84d1b006 | 1694 | uint val = 0;\ |
3de2a653 JS |
1695 | val = vport->cfg_##attr;\ |
1696 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ | |
1697 | } | |
1698 | ||
e59058c4 | 1699 | /** |
3621a710 | 1700 | * lpfc_vport_param_init - Initialize a vport cfg attribute |
e59058c4 JS |
1701 | * |
1702 | * Description: | |
1703 | * Macro that given an attr e.g. hba_queue_depth expands | |
1704 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1705 | * takes a default argument, a minimum and maximum argument. | |
1706 | * | |
1707 | * lpfc_##attr##_init: validates the min and max values then sets the | |
1708 | * adapter config field accordingly, or uses the default if out of range | |
1709 | * and prints an error message. | |
1710 | * @phba: pointer the the adapter structure. | |
1711 | * @val: integer attribute value. | |
1712 | * | |
1713 | * Returns: | |
1714 | * zero on success | |
1715 | * -EINVAL if default used | |
1716 | **/ | |
3de2a653 JS |
1717 | #define lpfc_vport_param_init(attr, default, minval, maxval) \ |
1718 | static int \ | |
84d1b006 | 1719 | lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \ |
3de2a653 JS |
1720 | { \ |
1721 | if (val >= minval && val <= maxval) {\ | |
1722 | vport->cfg_##attr = val;\ | |
1723 | return 0;\ | |
1724 | }\ | |
e8b62011 | 1725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 1726 | "0423 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 1727 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
1728 | vport->cfg_##attr = default;\ |
1729 | return -EINVAL;\ | |
1730 | } | |
1731 | ||
e59058c4 | 1732 | /** |
3621a710 | 1733 | * lpfc_vport_param_set - Set a vport cfg attribute |
e59058c4 JS |
1734 | * |
1735 | * Description: | |
1736 | * Macro that given an attr e.g. hba_queue_depth expands | |
1737 | * into a function with the name lpfc_hba_queue_depth_set | |
1738 | * | |
1739 | * lpfc_##attr##_set: validates the min and max values then sets the | |
1740 | * adapter config field if in the valid range. prints error message | |
1741 | * and does not set the parameter if invalid. | |
1742 | * @phba: pointer the the adapter structure. | |
1743 | * @val: integer attribute value. | |
1744 | * | |
1745 | * Returns: | |
1746 | * zero on success | |
1747 | * -EINVAL if val is invalid | |
1748 | **/ | |
3de2a653 JS |
1749 | #define lpfc_vport_param_set(attr, default, minval, maxval) \ |
1750 | static int \ | |
84d1b006 | 1751 | lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \ |
3de2a653 JS |
1752 | { \ |
1753 | if (val >= minval && val <= maxval) {\ | |
1754 | vport->cfg_##attr = val;\ | |
1755 | return 0;\ | |
1756 | }\ | |
e8b62011 | 1757 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 1758 | "0424 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 1759 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
1760 | return -EINVAL;\ |
1761 | } | |
1762 | ||
e59058c4 | 1763 | /** |
3621a710 | 1764 | * lpfc_vport_param_store - Set a vport attribute |
e59058c4 JS |
1765 | * |
1766 | * Description: | |
1767 | * Macro that given an attr e.g. hba_queue_depth | |
1768 | * expands into a function with the name lpfc_hba_queue_depth_store | |
1769 | * | |
1770 | * lpfc_##attr##_store: convert the ascii text number to an integer, then | |
1771 | * use the lpfc_##attr##_set function to set the value. | |
1772 | * @cdev: class device that is converted into a Scsi_host. | |
1773 | * @buf: contains the attribute value in decimal. | |
1774 | * @count: not used. | |
1775 | * | |
1776 | * Returns: | |
1777 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
1778 | * length of buffer upon success. | |
1779 | **/ | |
3de2a653 JS |
1780 | #define lpfc_vport_param_store(attr) \ |
1781 | static ssize_t \ | |
ee959b00 TJ |
1782 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
1783 | const char *buf, size_t count) \ | |
3de2a653 | 1784 | { \ |
ee959b00 | 1785 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 1786 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
84d1b006 | 1787 | uint val = 0;\ |
3de2a653 JS |
1788 | if (!isdigit(buf[0]))\ |
1789 | return -EINVAL;\ | |
1790 | if (sscanf(buf, "%i", &val) != 1)\ | |
1791 | return -EINVAL;\ | |
1792 | if (lpfc_##attr##_set(vport, val) == 0) \ | |
1793 | return strlen(buf);\ | |
1794 | else \ | |
1795 | return -EINVAL;\ | |
1796 | } | |
1797 | ||
1798 | ||
7bcbb752 | 1799 | #define LPFC_ATTR(name, defval, minval, maxval, desc) \ |
84d1b006 | 1800 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1801 | module_param(lpfc_##name, uint, S_IRUGO);\ |
dea3101e | 1802 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
7bcbb752 | 1803 | lpfc_param_init(name, defval, minval, maxval) |
dea3101e | 1804 | |
1805 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1806 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1807 | module_param(lpfc_##name, uint, S_IRUGO);\ |
dea3101e | 1808 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1809 | lpfc_param_show(name)\ | |
7bcbb752 | 1810 | lpfc_param_init(name, defval, minval, maxval)\ |
ee959b00 | 1811 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
dea3101e | 1812 | |
1813 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1814 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1815 | module_param(lpfc_##name, uint, S_IRUGO);\ |
dea3101e | 1816 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1817 | lpfc_param_show(name)\ | |
7bcbb752 JSEC |
1818 | lpfc_param_init(name, defval, minval, maxval)\ |
1819 | lpfc_param_set(name, defval, minval, maxval)\ | |
1820 | lpfc_param_store(name)\ | |
ee959b00 TJ |
1821 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1822 | lpfc_##name##_show, lpfc_##name##_store) | |
dea3101e | 1823 | |
93a20f74 | 1824 | #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ |
84d1b006 | 1825 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1826 | module_param(lpfc_##name, uint, S_IRUGO);\ |
93a20f74 JSEC |
1827 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1828 | lpfc_param_hex_show(name)\ | |
1829 | lpfc_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1830 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
93a20f74 JSEC |
1831 | |
1832 | #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1833 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1834 | module_param(lpfc_##name, uint, S_IRUGO);\ |
93a20f74 JSEC |
1835 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1836 | lpfc_param_hex_show(name)\ | |
1837 | lpfc_param_init(name, defval, minval, maxval)\ | |
1838 | lpfc_param_set(name, defval, minval, maxval)\ | |
1839 | lpfc_param_store(name)\ | |
ee959b00 TJ |
1840 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1841 | lpfc_##name##_show, lpfc_##name##_store) | |
93a20f74 | 1842 | |
3de2a653 | 1843 | #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ |
84d1b006 | 1844 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1845 | module_param(lpfc_##name, uint, S_IRUGO);\ |
3de2a653 JS |
1846 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1847 | lpfc_vport_param_init(name, defval, minval, maxval) | |
1848 | ||
1849 | #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1850 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1851 | module_param(lpfc_##name, uint, S_IRUGO);\ |
3de2a653 JS |
1852 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1853 | lpfc_vport_param_show(name)\ | |
1854 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1855 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
3de2a653 JS |
1856 | |
1857 | #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1858 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1859 | module_param(lpfc_##name, uint, S_IRUGO);\ |
3de2a653 JS |
1860 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1861 | lpfc_vport_param_show(name)\ | |
1862 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
1863 | lpfc_vport_param_set(name, defval, minval, maxval)\ | |
1864 | lpfc_vport_param_store(name)\ | |
ee959b00 TJ |
1865 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1866 | lpfc_##name##_show, lpfc_##name##_store) | |
3de2a653 JS |
1867 | |
1868 | #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1869 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1870 | module_param(lpfc_##name, uint, S_IRUGO);\ |
3de2a653 JS |
1871 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1872 | lpfc_vport_param_hex_show(name)\ | |
1873 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1874 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
3de2a653 JS |
1875 | |
1876 | #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | |
84d1b006 | 1877 | static uint lpfc_##name = defval;\ |
ab56dc2e | 1878 | module_param(lpfc_##name, uint, S_IRUGO);\ |
3de2a653 JS |
1879 | MODULE_PARM_DESC(lpfc_##name, desc);\ |
1880 | lpfc_vport_param_hex_show(name)\ | |
1881 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
1882 | lpfc_vport_param_set(name, defval, minval, maxval)\ | |
1883 | lpfc_vport_param_store(name)\ | |
ee959b00 TJ |
1884 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1885 | lpfc_##name##_show, lpfc_##name##_store) | |
1886 | ||
81301a9b JS |
1887 | static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL); |
1888 | static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL); | |
1889 | static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL); | |
1890 | static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL); | |
ee959b00 TJ |
1891 | static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); |
1892 | static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | |
1893 | static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | |
1894 | static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | |
1895 | static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | |
1896 | static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); | |
1897 | static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | |
1898 | static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | |
84d1b006 JS |
1899 | static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show, |
1900 | lpfc_link_state_store); | |
ee959b00 TJ |
1901 | static DEVICE_ATTR(option_rom_version, S_IRUGO, |
1902 | lpfc_option_rom_version_show, NULL); | |
1903 | static DEVICE_ATTR(num_discovered_ports, S_IRUGO, | |
1904 | lpfc_num_discovered_ports_show, NULL); | |
84774a4d | 1905 | static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); |
ee959b00 TJ |
1906 | static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
1907 | static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); | |
45ed1190 | 1908 | static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL); |
ee959b00 TJ |
1909 | static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, |
1910 | lpfc_board_mode_show, lpfc_board_mode_store); | |
1911 | static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); | |
1912 | static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); | |
1913 | static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); | |
1914 | static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); | |
1915 | static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); | |
1916 | static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); | |
1917 | static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); | |
1918 | static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); | |
1919 | static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); | |
bc73905a JS |
1920 | static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL); |
1921 | static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL); | |
ab56dc2e | 1922 | static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL); |
912e3acd JS |
1923 | static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO, |
1924 | lpfc_sriov_hw_max_virtfn_show, NULL); | |
c3f28afa | 1925 | |
a12e07bc | 1926 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; |
c3f28afa | 1927 | |
e59058c4 | 1928 | /** |
3621a710 | 1929 | * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid |
e59058c4 JS |
1930 | * @dev: class device that is converted into a Scsi_host. |
1931 | * @attr: device attribute, not used. | |
1932 | * @buf: containing the string lpfc_soft_wwn_key. | |
1933 | * @count: must be size of lpfc_soft_wwn_key. | |
1934 | * | |
1935 | * Returns: | |
1936 | * -EINVAL if the buffer does not contain lpfc_soft_wwn_key | |
1937 | * length of buf indicates success | |
1938 | **/ | |
c3f28afa | 1939 | static ssize_t |
ee959b00 TJ |
1940 | lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, |
1941 | const char *buf, size_t count) | |
c3f28afa | 1942 | { |
ee959b00 | 1943 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1944 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1945 | struct lpfc_hba *phba = vport->phba; | |
c3f28afa JS |
1946 | unsigned int cnt = count; |
1947 | ||
1948 | /* | |
1949 | * We're doing a simple sanity check for soft_wwpn setting. | |
1950 | * We require that the user write a specific key to enable | |
1951 | * the soft_wwpn attribute to be settable. Once the attribute | |
1952 | * is written, the enable key resets. If further updates are | |
1953 | * desired, the key must be written again to re-enable the | |
1954 | * attribute. | |
1955 | * | |
1956 | * The "key" is not secret - it is a hardcoded string shown | |
1957 | * here. The intent is to protect against the random user or | |
1958 | * application that is just writing attributes. | |
1959 | */ | |
1960 | ||
1961 | /* count may include a LF at end of string */ | |
1962 | if (buf[cnt-1] == '\n') | |
1963 | cnt--; | |
1964 | ||
a12e07bc JS |
1965 | if ((cnt != strlen(lpfc_soft_wwn_key)) || |
1966 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) | |
c3f28afa JS |
1967 | return -EINVAL; |
1968 | ||
a12e07bc | 1969 | phba->soft_wwn_enable = 1; |
c3f28afa JS |
1970 | return count; |
1971 | } | |
ee959b00 TJ |
1972 | static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, |
1973 | lpfc_soft_wwn_enable_store); | |
c3f28afa | 1974 | |
e59058c4 | 1975 | /** |
3621a710 | 1976 | * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter |
e59058c4 JS |
1977 | * @dev: class device that is converted into a Scsi_host. |
1978 | * @attr: device attribute, not used. | |
3621a710 | 1979 | * @buf: on return contains the wwpn in hexadecimal. |
e59058c4 JS |
1980 | * |
1981 | * Returns: size of formatted string. | |
1982 | **/ | |
c3f28afa | 1983 | static ssize_t |
ee959b00 TJ |
1984 | lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, |
1985 | char *buf) | |
c3f28afa | 1986 | { |
ee959b00 | 1987 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1988 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1989 | struct lpfc_hba *phba = vport->phba; | |
1990 | ||
afc071e6 RD |
1991 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
1992 | (unsigned long long)phba->cfg_soft_wwpn); | |
c3f28afa JS |
1993 | } |
1994 | ||
e59058c4 | 1995 | /** |
3621a710 | 1996 | * lpfc_soft_wwpn_store - Set the ww port name of the adapter |
e59058c4 JS |
1997 | * @dev class device that is converted into a Scsi_host. |
1998 | * @attr: device attribute, not used. | |
3621a710 | 1999 | * @buf: contains the wwpn in hexadecimal. |
e59058c4 JS |
2000 | * @count: number of wwpn bytes in buf |
2001 | * | |
2002 | * Returns: | |
2003 | * -EACCES hba reset not enabled, adapter over temp | |
2004 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid | |
2005 | * -EIO error taking adapter offline or online | |
2006 | * value of count on success | |
2007 | **/ | |
c3f28afa | 2008 | static ssize_t |
ee959b00 TJ |
2009 | lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, |
2010 | const char *buf, size_t count) | |
c3f28afa | 2011 | { |
ee959b00 | 2012 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
2013 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2014 | struct lpfc_hba *phba = vport->phba; | |
c3f28afa JS |
2015 | struct completion online_compl; |
2016 | int stat1=0, stat2=0; | |
2017 | unsigned int i, j, cnt=count; | |
2018 | u8 wwpn[8]; | |
fedd3b7b | 2019 | int rc; |
c3f28afa | 2020 | |
13815c83 JS |
2021 | if (!phba->cfg_enable_hba_reset) |
2022 | return -EACCES; | |
7af67051 JS |
2023 | spin_lock_irq(&phba->hbalock); |
2024 | if (phba->over_temp_state == HBA_OVER_TEMP) { | |
2025 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 2026 | return -EACCES; |
7af67051 JS |
2027 | } |
2028 | spin_unlock_irq(&phba->hbalock); | |
c3f28afa JS |
2029 | /* count may include a LF at end of string */ |
2030 | if (buf[cnt-1] == '\n') | |
2031 | cnt--; | |
2032 | ||
a12e07bc | 2033 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || |
c3f28afa JS |
2034 | ((cnt == 17) && (*buf++ != 'x')) || |
2035 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
2036 | return -EINVAL; | |
2037 | ||
a12e07bc | 2038 | phba->soft_wwn_enable = 0; |
c3f28afa JS |
2039 | |
2040 | memset(wwpn, 0, sizeof(wwpn)); | |
2041 | ||
2042 | /* Validate and store the new name */ | |
2043 | for (i=0, j=0; i < 16; i++) { | |
ecc30990 AS |
2044 | int value; |
2045 | ||
2046 | value = hex_to_bin(*buf++); | |
2047 | if (value >= 0) | |
2048 | j = (j << 4) | value; | |
c3f28afa JS |
2049 | else |
2050 | return -EINVAL; | |
2051 | if (i % 2) { | |
2052 | wwpn[i/2] = j & 0xff; | |
2053 | j = 0; | |
2054 | } | |
2055 | } | |
2056 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); | |
2e0fef85 | 2057 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; |
a12e07bc | 2058 | if (phba->cfg_soft_wwnn) |
2e0fef85 | 2059 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; |
c3f28afa JS |
2060 | |
2061 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2062 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); | |
2063 | ||
46fa311e | 2064 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
c3f28afa JS |
2065 | if (stat1) |
2066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
2067 | "0463 lpfc_soft_wwpn attribute set failed to " |
2068 | "reinit adapter - %d\n", stat1); | |
c3f28afa | 2069 | init_completion(&online_compl); |
fedd3b7b JS |
2070 | rc = lpfc_workq_post_event(phba, &stat2, &online_compl, |
2071 | LPFC_EVT_ONLINE); | |
2072 | if (rc == 0) | |
2073 | return -ENOMEM; | |
2074 | ||
c3f28afa JS |
2075 | wait_for_completion(&online_compl); |
2076 | if (stat2) | |
2077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
2078 | "0464 lpfc_soft_wwpn attribute set failed to " |
2079 | "reinit adapter - %d\n", stat2); | |
c3f28afa JS |
2080 | return (stat1 || stat2) ? -EIO : count; |
2081 | } | |
ee959b00 TJ |
2082 | static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ |
2083 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); | |
c3f28afa | 2084 | |
e59058c4 | 2085 | /** |
3621a710 | 2086 | * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter |
e59058c4 JS |
2087 | * @dev: class device that is converted into a Scsi_host. |
2088 | * @attr: device attribute, not used. | |
3621a710 | 2089 | * @buf: on return contains the wwnn in hexadecimal. |
e59058c4 JS |
2090 | * |
2091 | * Returns: size of formatted string. | |
2092 | **/ | |
a12e07bc | 2093 | static ssize_t |
ee959b00 TJ |
2094 | lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, |
2095 | char *buf) | |
a12e07bc | 2096 | { |
ee959b00 | 2097 | struct Scsi_Host *shost = class_to_shost(dev); |
51ef4c26 | 2098 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
a12e07bc JS |
2099 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
2100 | (unsigned long long)phba->cfg_soft_wwnn); | |
2101 | } | |
2102 | ||
e59058c4 | 2103 | /** |
3621a710 | 2104 | * lpfc_soft_wwnn_store - sets the ww node name of the adapter |
e59058c4 | 2105 | * @cdev: class device that is converted into a Scsi_host. |
3621a710 | 2106 | * @buf: contains the ww node name in hexadecimal. |
e59058c4 JS |
2107 | * @count: number of wwnn bytes in buf. |
2108 | * | |
2109 | * Returns: | |
2110 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid | |
2111 | * value of count on success | |
2112 | **/ | |
a12e07bc | 2113 | static ssize_t |
ee959b00 TJ |
2114 | lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, |
2115 | const char *buf, size_t count) | |
a12e07bc | 2116 | { |
ee959b00 | 2117 | struct Scsi_Host *shost = class_to_shost(dev); |
51ef4c26 | 2118 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
a12e07bc JS |
2119 | unsigned int i, j, cnt=count; |
2120 | u8 wwnn[8]; | |
2121 | ||
2122 | /* count may include a LF at end of string */ | |
2123 | if (buf[cnt-1] == '\n') | |
2124 | cnt--; | |
2125 | ||
2126 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || | |
2127 | ((cnt == 17) && (*buf++ != 'x')) || | |
2128 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
2129 | return -EINVAL; | |
2130 | ||
2131 | /* | |
2132 | * Allow wwnn to be set many times, as long as the enable is set. | |
2133 | * However, once the wwpn is set, everything locks. | |
2134 | */ | |
2135 | ||
2136 | memset(wwnn, 0, sizeof(wwnn)); | |
2137 | ||
2138 | /* Validate and store the new name */ | |
2139 | for (i=0, j=0; i < 16; i++) { | |
ecc30990 AS |
2140 | int value; |
2141 | ||
2142 | value = hex_to_bin(*buf++); | |
2143 | if (value >= 0) | |
2144 | j = (j << 4) | value; | |
a12e07bc JS |
2145 | else |
2146 | return -EINVAL; | |
2147 | if (i % 2) { | |
2148 | wwnn[i/2] = j & 0xff; | |
2149 | j = 0; | |
2150 | } | |
2151 | } | |
2152 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); | |
2153 | ||
2154 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2155 | "lpfc%d: soft_wwnn set. Value will take effect upon " | |
2156 | "setting of the soft_wwpn\n", phba->brd_no); | |
2157 | ||
2158 | return count; | |
2159 | } | |
ee959b00 TJ |
2160 | static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\ |
2161 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); | |
a12e07bc | 2162 | |
c3f28afa | 2163 | |
875fbdfe | 2164 | static int lpfc_poll = 0; |
ab56dc2e | 2165 | module_param(lpfc_poll, int, S_IRUGO); |
875fbdfe JSEC |
2166 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" |
2167 | " 0 - none," | |
2168 | " 1 - poll with interrupts enabled" | |
2169 | " 3 - poll and disable FCP ring interrupts"); | |
2170 | ||
ee959b00 TJ |
2171 | static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
2172 | lpfc_poll_show, lpfc_poll_store); | |
dea3101e | 2173 | |
92d7f7b0 | 2174 | int lpfc_sli_mode = 0; |
ab56dc2e | 2175 | module_param(lpfc_sli_mode, int, S_IRUGO); |
92d7f7b0 JS |
2176 | MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" |
2177 | " 0 - auto (SLI-3 if supported)," | |
2178 | " 2 - select SLI-2 even on SLI-3 capable HBAs," | |
2179 | " 3 - select SLI-3"); | |
2180 | ||
15672319 | 2181 | int lpfc_enable_npiv = 1; |
ab56dc2e | 2182 | module_param(lpfc_enable_npiv, int, S_IRUGO); |
7ee5d43e JS |
2183 | MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); |
2184 | lpfc_param_show(enable_npiv); | |
4b40c59e | 2185 | lpfc_param_init(enable_npiv, 1, 0, 1); |
15672319 | 2186 | static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL); |
92d7f7b0 | 2187 | |
19ca7609 | 2188 | int lpfc_enable_rrq; |
ab56dc2e | 2189 | module_param(lpfc_enable_rrq, int, S_IRUGO); |
19ca7609 JS |
2190 | MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality"); |
2191 | lpfc_param_show(enable_rrq); | |
2192 | lpfc_param_init(enable_rrq, 0, 0, 1); | |
2193 | static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL); | |
2194 | ||
84d1b006 JS |
2195 | /* |
2196 | # lpfc_suppress_link_up: Bring link up at initialization | |
2197 | # 0x0 = bring link up (issue MBX_INIT_LINK) | |
2198 | # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK) | |
2199 | # 0x2 = never bring up link | |
2200 | # Default value is 0. | |
2201 | */ | |
e40a02c1 JS |
2202 | LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK, |
2203 | LPFC_DELAY_INIT_LINK_INDEFINITELY, | |
2204 | "Suppress Link Up at initialization"); | |
2a9bf3d0 JS |
2205 | /* |
2206 | # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS | |
2207 | # 1 - (1024) | |
2208 | # 2 - (2048) | |
2209 | # 3 - (3072) | |
2210 | # 4 - (4096) | |
2211 | # 5 - (5120) | |
2212 | */ | |
2213 | static ssize_t | |
2214 | lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
2215 | { | |
2216 | struct Scsi_Host *shost = class_to_shost(dev); | |
2217 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
2218 | ||
2219 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max); | |
2220 | } | |
2221 | ||
2222 | static DEVICE_ATTR(iocb_hw, S_IRUGO, | |
2223 | lpfc_iocb_hw_show, NULL); | |
2224 | static ssize_t | |
2225 | lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
2226 | { | |
2227 | struct Scsi_Host *shost = class_to_shost(dev); | |
2228 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
2229 | ||
2230 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2231 | phba->sli.ring[LPFC_ELS_RING].txq_max); | |
2232 | } | |
2233 | ||
2234 | static DEVICE_ATTR(txq_hw, S_IRUGO, | |
2235 | lpfc_txq_hw_show, NULL); | |
2236 | static ssize_t | |
2237 | lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr, | |
2238 | char *buf) | |
2239 | { | |
2240 | struct Scsi_Host *shost = class_to_shost(dev); | |
2241 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
2242 | ||
2243 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
2244 | phba->sli.ring[LPFC_ELS_RING].txcmplq_max); | |
2245 | } | |
2246 | ||
2247 | static DEVICE_ATTR(txcmplq_hw, S_IRUGO, | |
2248 | lpfc_txcmplq_hw_show, NULL); | |
2249 | ||
2250 | int lpfc_iocb_cnt = 2; | |
ab56dc2e | 2251 | module_param(lpfc_iocb_cnt, int, S_IRUGO); |
2a9bf3d0 JS |
2252 | MODULE_PARM_DESC(lpfc_iocb_cnt, |
2253 | "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); | |
2254 | lpfc_param_show(iocb_cnt); | |
2255 | lpfc_param_init(iocb_cnt, 2, 1, 5); | |
2256 | static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO, | |
2257 | lpfc_iocb_cnt_show, NULL); | |
84d1b006 | 2258 | |
c01f3208 JS |
2259 | /* |
2260 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | |
2261 | # until the timer expires. Value range is [0,255]. Default value is 30. | |
2262 | */ | |
2263 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | |
2264 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; | |
2265 | module_param(lpfc_nodev_tmo, int, 0); | |
2266 | MODULE_PARM_DESC(lpfc_nodev_tmo, | |
2267 | "Seconds driver will hold I/O waiting " | |
2268 | "for a device to come back"); | |
e59058c4 JS |
2269 | |
2270 | /** | |
3621a710 | 2271 | * lpfc_nodev_tmo_show - Return the hba dev loss timeout value |
e59058c4 JS |
2272 | * @dev: class converted to a Scsi_host structure. |
2273 | * @attr: device attribute, not used. | |
2274 | * @buf: on return contains the dev loss timeout in decimal. | |
2275 | * | |
2276 | * Returns: size of formatted string. | |
2277 | **/ | |
c01f3208 | 2278 | static ssize_t |
ee959b00 TJ |
2279 | lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, |
2280 | char *buf) | |
c01f3208 | 2281 | { |
ee959b00 | 2282 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 | 2283 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
e40a02c1 | 2284 | |
3de2a653 | 2285 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); |
c01f3208 JS |
2286 | } |
2287 | ||
e59058c4 | 2288 | /** |
3621a710 | 2289 | * lpfc_nodev_tmo_init - Set the hba nodev timeout value |
e59058c4 JS |
2290 | * @vport: lpfc vport structure pointer. |
2291 | * @val: contains the nodev timeout value. | |
2292 | * | |
2293 | * Description: | |
2294 | * If the devloss tmo is already set then nodev tmo is set to devloss tmo, | |
2295 | * a kernel error message is printed and zero is returned. | |
2296 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
2297 | * Otherwise nodev tmo is set to the default value. | |
2298 | * | |
2299 | * Returns: | |
2300 | * zero if already set or if val is in range | |
2301 | * -EINVAL val out of range | |
2302 | **/ | |
c01f3208 | 2303 | static int |
3de2a653 JS |
2304 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) |
2305 | { | |
2306 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { | |
2307 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; | |
2308 | if (val != LPFC_DEF_DEVLOSS_TMO) | |
e8b62011 | 2309 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 2310 | "0407 Ignoring nodev_tmo module " |
e8b62011 JS |
2311 | "parameter because devloss_tmo is " |
2312 | "set.\n"); | |
c01f3208 JS |
2313 | return 0; |
2314 | } | |
2315 | ||
2316 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
2317 | vport->cfg_nodev_tmo = val; |
2318 | vport->cfg_devloss_tmo = val; | |
c01f3208 JS |
2319 | return 0; |
2320 | } | |
e8b62011 JS |
2321 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2322 | "0400 lpfc_nodev_tmo attribute cannot be set to" | |
2323 | " %d, allowed range is [%d, %d]\n", | |
2324 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
3de2a653 | 2325 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
c01f3208 JS |
2326 | return -EINVAL; |
2327 | } | |
2328 | ||
e59058c4 | 2329 | /** |
3621a710 | 2330 | * lpfc_update_rport_devloss_tmo - Update dev loss tmo value |
e59058c4 JS |
2331 | * @vport: lpfc vport structure pointer. |
2332 | * | |
2333 | * Description: | |
2334 | * Update all the ndlp's dev loss tmo with the vport devloss tmo value. | |
2335 | **/ | |
7054a606 | 2336 | static void |
3de2a653 | 2337 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) |
7054a606 | 2338 | { |
858c9f6c | 2339 | struct Scsi_Host *shost; |
7054a606 JS |
2340 | struct lpfc_nodelist *ndlp; |
2341 | ||
51ef4c26 JS |
2342 | shost = lpfc_shost_from_vport(vport); |
2343 | spin_lock_irq(shost->host_lock); | |
2344 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) | |
e47c9093 | 2345 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) |
51ef4c26 JS |
2346 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
2347 | spin_unlock_irq(shost->host_lock); | |
7054a606 JS |
2348 | } |
2349 | ||
e59058c4 | 2350 | /** |
3621a710 | 2351 | * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values |
e59058c4 JS |
2352 | * @vport: lpfc vport structure pointer. |
2353 | * @val: contains the tmo value. | |
2354 | * | |
2355 | * Description: | |
2356 | * If the devloss tmo is already set or the vport dev loss tmo has changed | |
2357 | * then a kernel error message is printed and zero is returned. | |
2358 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
2359 | * Otherwise nodev tmo is set to the default value. | |
2360 | * | |
2361 | * Returns: | |
2362 | * zero if already set or if val is in range | |
2363 | * -EINVAL val out of range | |
2364 | **/ | |
c01f3208 | 2365 | static int |
3de2a653 | 2366 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 | 2367 | { |
3de2a653 JS |
2368 | if (vport->dev_loss_tmo_changed || |
2369 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { | |
e8b62011 JS |
2370 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2371 | "0401 Ignoring change to nodev_tmo " | |
2372 | "because devloss_tmo is set.\n"); | |
c01f3208 JS |
2373 | return 0; |
2374 | } | |
c01f3208 | 2375 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
3de2a653 JS |
2376 | vport->cfg_nodev_tmo = val; |
2377 | vport->cfg_devloss_tmo = val; | |
0af5d708 MC |
2378 | /* |
2379 | * For compat: set the fc_host dev loss so new rports | |
2380 | * will get the value. | |
2381 | */ | |
2382 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; | |
3de2a653 | 2383 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
2384 | return 0; |
2385 | } | |
e8b62011 JS |
2386 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2387 | "0403 lpfc_nodev_tmo attribute cannot be set to" | |
2388 | "%d, allowed range is [%d, %d]\n", | |
2389 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
2390 | return -EINVAL; |
2391 | } | |
2392 | ||
3de2a653 | 2393 | lpfc_vport_param_store(nodev_tmo) |
c01f3208 | 2394 | |
ee959b00 TJ |
2395 | static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
2396 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); | |
c01f3208 JS |
2397 | |
2398 | /* | |
2399 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that | |
2400 | # disappear until the timer expires. Value range is [0,255]. Default | |
2401 | # value is 30. | |
2402 | */ | |
ab56dc2e | 2403 | module_param(lpfc_devloss_tmo, int, S_IRUGO); |
c01f3208 JS |
2404 | MODULE_PARM_DESC(lpfc_devloss_tmo, |
2405 | "Seconds driver will hold I/O waiting " | |
2406 | "for a device to come back"); | |
3de2a653 JS |
2407 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
2408 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) | |
2409 | lpfc_vport_param_show(devloss_tmo) | |
e59058c4 JS |
2410 | |
2411 | /** | |
3621a710 | 2412 | * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit |
e59058c4 JS |
2413 | * @vport: lpfc vport structure pointer. |
2414 | * @val: contains the tmo value. | |
2415 | * | |
2416 | * Description: | |
2417 | * If val is in a valid range then set the vport nodev tmo, | |
2418 | * devloss tmo, also set the vport dev loss tmo changed flag. | |
2419 | * Else a kernel error message is printed. | |
2420 | * | |
2421 | * Returns: | |
2422 | * zero if val is in range | |
2423 | * -EINVAL val out of range | |
2424 | **/ | |
c01f3208 | 2425 | static int |
3de2a653 | 2426 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 JS |
2427 | { |
2428 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
2429 | vport->cfg_nodev_tmo = val; |
2430 | vport->cfg_devloss_tmo = val; | |
2431 | vport->dev_loss_tmo_changed = 1; | |
0af5d708 | 2432 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; |
3de2a653 | 2433 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
2434 | return 0; |
2435 | } | |
2436 | ||
e8b62011 JS |
2437 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2438 | "0404 lpfc_devloss_tmo attribute cannot be set to" | |
2439 | " %d, allowed range is [%d, %d]\n", | |
2440 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
2441 | return -EINVAL; |
2442 | } | |
2443 | ||
3de2a653 | 2444 | lpfc_vport_param_store(devloss_tmo) |
ee959b00 TJ |
2445 | static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
2446 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); | |
c01f3208 | 2447 | |
dea3101e | 2448 | /* |
2449 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | |
2450 | # deluged with LOTS of information. | |
2451 | # You can set a bit mask to record specific types of verbose messages: | |
f4b4c68f | 2452 | # See lpfc_logmsh.h for definitions. |
dea3101e | 2453 | */ |
f4b4c68f | 2454 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, |
e8b62011 | 2455 | "Verbose logging bit-mask"); |
dea3101e | 2456 | |
7ee5d43e JS |
2457 | /* |
2458 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters | |
2459 | # objects that have been registered with the nameserver after login. | |
2460 | */ | |
2461 | LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1, | |
2462 | "Deregister nameserver objects before LOGO"); | |
2463 | ||
dea3101e | 2464 | /* |
2465 | # lun_queue_depth: This parameter is used to limit the number of outstanding | |
2466 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. | |
2467 | */ | |
3de2a653 JS |
2468 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128, |
2469 | "Max number of FCP commands we can queue to a specific LUN"); | |
dea3101e | 2470 | |
7dc517df JS |
2471 | /* |
2472 | # tgt_queue_depth: This parameter is used to limit the number of outstanding | |
2473 | # commands per target port. Value range is [10,65535]. Default value is 65535. | |
2474 | */ | |
2475 | LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535, | |
2476 | "Max number of FCP commands we can queue to a specific target port"); | |
2477 | ||
b28485ac JW |
2478 | /* |
2479 | # hba_queue_depth: This parameter is used to limit the number of outstanding | |
2480 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter | |
2481 | # value is greater than the maximum number of exchanges supported by the HBA, | |
2482 | # then maximum number of exchanges supported by the HBA is used to determine | |
2483 | # the hba_queue_depth. | |
2484 | */ | |
2485 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, | |
2486 | "Max number of FCP commands we can queue to a lpfc HBA"); | |
2487 | ||
92d7f7b0 JS |
2488 | /* |
2489 | # peer_port_login: This parameter allows/prevents logins | |
2490 | # between peer ports hosted on the same physical port. | |
2491 | # When this parameter is set 0 peer ports of same physical port | |
2492 | # are not allowed to login to each other. | |
2493 | # When this parameter is set 1 peer ports of same physical port | |
2494 | # are allowed to login to each other. | |
2495 | # Default value of this parameter is 0. | |
2496 | */ | |
3de2a653 JS |
2497 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, |
2498 | "Allow peer ports on the same physical port to login to each " | |
2499 | "other."); | |
92d7f7b0 JS |
2500 | |
2501 | /* | |
3de2a653 | 2502 | # restrict_login: This parameter allows/prevents logins |
92d7f7b0 JS |
2503 | # between Virtual Ports and remote initiators. |
2504 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from | |
2505 | # other initiators and will attempt to PLOGI all remote ports. | |
2506 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from | |
2507 | # remote ports and will not attempt to PLOGI to other initiators. | |
2508 | # This parameter does not restrict to the physical port. | |
2509 | # This parameter does not restrict logins to Fabric resident remote ports. | |
2510 | # Default value of this parameter is 1. | |
2511 | */ | |
3de2a653 | 2512 | static int lpfc_restrict_login = 1; |
ab56dc2e | 2513 | module_param(lpfc_restrict_login, int, S_IRUGO); |
3de2a653 JS |
2514 | MODULE_PARM_DESC(lpfc_restrict_login, |
2515 | "Restrict virtual ports login to remote initiators."); | |
2516 | lpfc_vport_param_show(restrict_login); | |
2517 | ||
e59058c4 | 2518 | /** |
3621a710 | 2519 | * lpfc_restrict_login_init - Set the vport restrict login flag |
e59058c4 JS |
2520 | * @vport: lpfc vport structure pointer. |
2521 | * @val: contains the restrict login value. | |
2522 | * | |
2523 | * Description: | |
2524 | * If val is not in a valid range then log a kernel error message and set | |
2525 | * the vport restrict login to one. | |
2526 | * If the port type is physical clear the restrict login flag and return. | |
2527 | * Else set the restrict login flag to val. | |
2528 | * | |
2529 | * Returns: | |
2530 | * zero if val is in range | |
2531 | * -EINVAL val out of range | |
2532 | **/ | |
3de2a653 JS |
2533 | static int |
2534 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) | |
2535 | { | |
2536 | if (val < 0 || val > 1) { | |
e8b62011 | 2537 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 2538 | "0422 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
2539 | "be set to %d, allowed range is [0, 1]\n", |
2540 | val); | |
3de2a653 JS |
2541 | vport->cfg_restrict_login = 1; |
2542 | return -EINVAL; | |
2543 | } | |
2544 | if (vport->port_type == LPFC_PHYSICAL_PORT) { | |
2545 | vport->cfg_restrict_login = 0; | |
2546 | return 0; | |
2547 | } | |
2548 | vport->cfg_restrict_login = val; | |
2549 | return 0; | |
2550 | } | |
2551 | ||
e59058c4 | 2552 | /** |
3621a710 | 2553 | * lpfc_restrict_login_set - Set the vport restrict login flag |
e59058c4 JS |
2554 | * @vport: lpfc vport structure pointer. |
2555 | * @val: contains the restrict login value. | |
2556 | * | |
2557 | * Description: | |
2558 | * If val is not in a valid range then log a kernel error message and set | |
2559 | * the vport restrict login to one. | |
2560 | * If the port type is physical and the val is not zero log a kernel | |
2561 | * error message, clear the restrict login flag and return zero. | |
2562 | * Else set the restrict login flag to val. | |
2563 | * | |
2564 | * Returns: | |
2565 | * zero if val is in range | |
2566 | * -EINVAL val out of range | |
2567 | **/ | |
3de2a653 JS |
2568 | static int |
2569 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) | |
2570 | { | |
2571 | if (val < 0 || val > 1) { | |
e8b62011 | 2572 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 2573 | "0425 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
2574 | "be set to %d, allowed range is [0, 1]\n", |
2575 | val); | |
3de2a653 JS |
2576 | vport->cfg_restrict_login = 1; |
2577 | return -EINVAL; | |
2578 | } | |
2579 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { | |
e8b62011 JS |
2580 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2581 | "0468 lpfc_restrict_login must be 0 for " | |
2582 | "Physical ports.\n"); | |
3de2a653 JS |
2583 | vport->cfg_restrict_login = 0; |
2584 | return 0; | |
2585 | } | |
2586 | vport->cfg_restrict_login = val; | |
2587 | return 0; | |
2588 | } | |
2589 | lpfc_vport_param_store(restrict_login); | |
ee959b00 TJ |
2590 | static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, |
2591 | lpfc_restrict_login_show, lpfc_restrict_login_store); | |
92d7f7b0 | 2592 | |
dea3101e | 2593 | /* |
2594 | # Some disk devices have a "select ID" or "select Target" capability. | |
2595 | # From a protocol standpoint "select ID" usually means select the | |
2596 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative | |
2597 | # annex" which contains a table that maps a "select ID" (a number | |
2598 | # between 0 and 7F) to an ALPA. By default, for compatibility with | |
2599 | # older drivers, the lpfc driver scans this table from low ALPA to high | |
2600 | # ALPA. | |
2601 | # | |
2602 | # Turning on the scan-down variable (on = 1, off = 0) will | |
2603 | # cause the lpfc driver to use an inverted table, effectively | |
2604 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | |
2605 | # | |
2606 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | |
2607 | # and will not work across a fabric. Also this parameter will take | |
2608 | # effect only in the case when ALPA map is not available.) | |
2609 | */ | |
3de2a653 JS |
2610 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, |
2611 | "Start scanning for devices from highest ALPA to lowest"); | |
dea3101e | 2612 | |
dea3101e | 2613 | /* |
2614 | # lpfc_topology: link topology for init link | |
2615 | # 0x0 = attempt loop mode then point-to-point | |
367c2713 | 2616 | # 0x01 = internal loopback mode |
dea3101e | 2617 | # 0x02 = attempt point-to-point mode only |
2618 | # 0x04 = attempt loop mode only | |
2619 | # 0x06 = attempt point-to-point mode then loop | |
2620 | # Set point-to-point mode if you want to run as an N_Port. | |
2621 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | |
2622 | # Default value is 0. | |
2623 | */ | |
e59058c4 JS |
2624 | |
2625 | /** | |
3621a710 | 2626 | * lpfc_topology_set - Set the adapters topology field |
e59058c4 JS |
2627 | * @phba: lpfc_hba pointer. |
2628 | * @val: topology value. | |
2629 | * | |
2630 | * Description: | |
2631 | * If val is in a valid range then set the adapter's topology field and | |
2632 | * issue a lip; if the lip fails reset the topology to the old value. | |
2633 | * | |
2634 | * If the value is not in range log a kernel error message and return an error. | |
2635 | * | |
2636 | * Returns: | |
2637 | * zero if val is in range and lip okay | |
2638 | * non-zero return value from lpfc_issue_lip() | |
2639 | * -EINVAL val out of range | |
2640 | **/ | |
a257bf90 JS |
2641 | static ssize_t |
2642 | lpfc_topology_store(struct device *dev, struct device_attribute *attr, | |
2643 | const char *buf, size_t count) | |
83108bd3 | 2644 | { |
a257bf90 JS |
2645 | struct Scsi_Host *shost = class_to_shost(dev); |
2646 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2647 | struct lpfc_hba *phba = vport->phba; | |
2648 | int val = 0; | |
2649 | int nolip = 0; | |
2650 | const char *val_buf = buf; | |
83108bd3 JS |
2651 | int err; |
2652 | uint32_t prev_val; | |
a257bf90 JS |
2653 | |
2654 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { | |
2655 | nolip = 1; | |
2656 | val_buf = &buf[strlen("nolip ")]; | |
2657 | } | |
2658 | ||
2659 | if (!isdigit(val_buf[0])) | |
2660 | return -EINVAL; | |
2661 | if (sscanf(val_buf, "%i", &val) != 1) | |
2662 | return -EINVAL; | |
2663 | ||
83108bd3 JS |
2664 | if (val >= 0 && val <= 6) { |
2665 | prev_val = phba->cfg_topology; | |
2666 | phba->cfg_topology = val; | |
a257bf90 JS |
2667 | if (nolip) |
2668 | return strlen(buf); | |
2669 | ||
83108bd3 | 2670 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 2671 | if (err) { |
83108bd3 | 2672 | phba->cfg_topology = prev_val; |
a257bf90 JS |
2673 | return -EINVAL; |
2674 | } else | |
2675 | return strlen(buf); | |
83108bd3 JS |
2676 | } |
2677 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2678 | "%d:0467 lpfc_topology attribute cannot be set to %d, " | |
2679 | "allowed range is [0, 6]\n", | |
2680 | phba->brd_no, val); | |
2681 | return -EINVAL; | |
2682 | } | |
2683 | static int lpfc_topology = 0; | |
ab56dc2e | 2684 | module_param(lpfc_topology, int, S_IRUGO); |
83108bd3 JS |
2685 | MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology"); |
2686 | lpfc_param_show(topology) | |
2687 | lpfc_param_init(topology, 0, 0, 6) | |
ee959b00 | 2688 | static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, |
83108bd3 | 2689 | lpfc_topology_show, lpfc_topology_store); |
dea3101e | 2690 | |
21e9a0a5 JS |
2691 | /** |
2692 | * lpfc_static_vport_show: Read callback function for | |
2693 | * lpfc_static_vport sysfs file. | |
2694 | * @dev: Pointer to class device object. | |
2695 | * @attr: device attribute structure. | |
2696 | * @buf: Data buffer. | |
2697 | * | |
2698 | * This function is the read call back function for | |
2699 | * lpfc_static_vport sysfs file. The lpfc_static_vport | |
2700 | * sysfs file report the mageability of the vport. | |
2701 | **/ | |
2702 | static ssize_t | |
2703 | lpfc_static_vport_show(struct device *dev, struct device_attribute *attr, | |
2704 | char *buf) | |
2705 | { | |
2706 | struct Scsi_Host *shost = class_to_shost(dev); | |
2707 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2708 | if (vport->vport_flag & STATIC_VPORT) | |
2709 | sprintf(buf, "1\n"); | |
2710 | else | |
2711 | sprintf(buf, "0\n"); | |
2712 | ||
2713 | return strlen(buf); | |
2714 | } | |
2715 | ||
2716 | /* | |
2717 | * Sysfs attribute to control the statistical data collection. | |
2718 | */ | |
2719 | static DEVICE_ATTR(lpfc_static_vport, S_IRUGO, | |
2720 | lpfc_static_vport_show, NULL); | |
ea2151b4 JS |
2721 | |
2722 | /** | |
3621a710 | 2723 | * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
2724 | * @dev: Pointer to class device. |
2725 | * @buf: Data buffer. | |
2726 | * @count: Size of the data buffer. | |
2727 | * | |
2728 | * This function get called when an user write to the lpfc_stat_data_ctrl | |
2729 | * sysfs file. This function parse the command written to the sysfs file | |
2730 | * and take appropriate action. These commands are used for controlling | |
2731 | * driver statistical data collection. | |
2732 | * Following are the command this function handles. | |
2733 | * | |
2734 | * setbucket <bucket_type> <base> <step> | |
2735 | * = Set the latency buckets. | |
2736 | * destroybucket = destroy all the buckets. | |
2737 | * start = start data collection | |
2738 | * stop = stop data collection | |
2739 | * reset = reset the collected data | |
2740 | **/ | |
2741 | static ssize_t | |
2742 | lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, | |
2743 | const char *buf, size_t count) | |
2744 | { | |
2745 | struct Scsi_Host *shost = class_to_shost(dev); | |
2746 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2747 | struct lpfc_hba *phba = vport->phba; | |
2748 | #define LPFC_MAX_DATA_CTRL_LEN 1024 | |
2749 | static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; | |
2750 | unsigned long i; | |
2751 | char *str_ptr, *token; | |
2752 | struct lpfc_vport **vports; | |
2753 | struct Scsi_Host *v_shost; | |
2754 | char *bucket_type_str, *base_str, *step_str; | |
2755 | unsigned long base, step, bucket_type; | |
2756 | ||
2757 | if (!strncmp(buf, "setbucket", strlen("setbucket"))) { | |
a257bf90 | 2758 | if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1)) |
ea2151b4 JS |
2759 | return -EINVAL; |
2760 | ||
2761 | strcpy(bucket_data, buf); | |
2762 | str_ptr = &bucket_data[0]; | |
2763 | /* Ignore this token - this is command token */ | |
2764 | token = strsep(&str_ptr, "\t "); | |
2765 | if (!token) | |
2766 | return -EINVAL; | |
2767 | ||
2768 | bucket_type_str = strsep(&str_ptr, "\t "); | |
2769 | if (!bucket_type_str) | |
2770 | return -EINVAL; | |
2771 | ||
2772 | if (!strncmp(bucket_type_str, "linear", strlen("linear"))) | |
2773 | bucket_type = LPFC_LINEAR_BUCKET; | |
2774 | else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) | |
2775 | bucket_type = LPFC_POWER2_BUCKET; | |
2776 | else | |
2777 | return -EINVAL; | |
2778 | ||
2779 | base_str = strsep(&str_ptr, "\t "); | |
2780 | if (!base_str) | |
2781 | return -EINVAL; | |
2782 | base = simple_strtoul(base_str, NULL, 0); | |
2783 | ||
2784 | step_str = strsep(&str_ptr, "\t "); | |
2785 | if (!step_str) | |
2786 | return -EINVAL; | |
2787 | step = simple_strtoul(step_str, NULL, 0); | |
2788 | if (!step) | |
2789 | return -EINVAL; | |
2790 | ||
2791 | /* Block the data collection for every vport */ | |
2792 | vports = lpfc_create_vport_work_array(phba); | |
2793 | if (vports == NULL) | |
2794 | return -ENOMEM; | |
2795 | ||
f4b4c68f | 2796 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
2797 | v_shost = lpfc_shost_from_vport(vports[i]); |
2798 | spin_lock_irq(v_shost->host_lock); | |
2799 | /* Block and reset data collection */ | |
2800 | vports[i]->stat_data_blocked = 1; | |
2801 | if (vports[i]->stat_data_enabled) | |
2802 | lpfc_vport_reset_stat_data(vports[i]); | |
2803 | spin_unlock_irq(v_shost->host_lock); | |
2804 | } | |
2805 | ||
2806 | /* Set the bucket attributes */ | |
2807 | phba->bucket_type = bucket_type; | |
2808 | phba->bucket_base = base; | |
2809 | phba->bucket_step = step; | |
2810 | ||
f4b4c68f | 2811 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
2812 | v_shost = lpfc_shost_from_vport(vports[i]); |
2813 | ||
2814 | /* Unblock data collection */ | |
2815 | spin_lock_irq(v_shost->host_lock); | |
2816 | vports[i]->stat_data_blocked = 0; | |
2817 | spin_unlock_irq(v_shost->host_lock); | |
2818 | } | |
2819 | lpfc_destroy_vport_work_array(phba, vports); | |
2820 | return strlen(buf); | |
2821 | } | |
2822 | ||
2823 | if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { | |
2824 | vports = lpfc_create_vport_work_array(phba); | |
2825 | if (vports == NULL) | |
2826 | return -ENOMEM; | |
2827 | ||
f4b4c68f | 2828 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
2829 | v_shost = lpfc_shost_from_vport(vports[i]); |
2830 | spin_lock_irq(shost->host_lock); | |
2831 | vports[i]->stat_data_blocked = 1; | |
2832 | lpfc_free_bucket(vport); | |
2833 | vport->stat_data_enabled = 0; | |
2834 | vports[i]->stat_data_blocked = 0; | |
2835 | spin_unlock_irq(shost->host_lock); | |
2836 | } | |
2837 | lpfc_destroy_vport_work_array(phba, vports); | |
2838 | phba->bucket_type = LPFC_NO_BUCKET; | |
2839 | phba->bucket_base = 0; | |
2840 | phba->bucket_step = 0; | |
2841 | return strlen(buf); | |
2842 | } | |
2843 | ||
2844 | if (!strncmp(buf, "start", strlen("start"))) { | |
2845 | /* If no buckets configured return error */ | |
2846 | if (phba->bucket_type == LPFC_NO_BUCKET) | |
2847 | return -EINVAL; | |
2848 | spin_lock_irq(shost->host_lock); | |
2849 | if (vport->stat_data_enabled) { | |
2850 | spin_unlock_irq(shost->host_lock); | |
2851 | return strlen(buf); | |
2852 | } | |
2853 | lpfc_alloc_bucket(vport); | |
2854 | vport->stat_data_enabled = 1; | |
2855 | spin_unlock_irq(shost->host_lock); | |
2856 | return strlen(buf); | |
2857 | } | |
2858 | ||
2859 | if (!strncmp(buf, "stop", strlen("stop"))) { | |
2860 | spin_lock_irq(shost->host_lock); | |
2861 | if (vport->stat_data_enabled == 0) { | |
2862 | spin_unlock_irq(shost->host_lock); | |
2863 | return strlen(buf); | |
2864 | } | |
2865 | lpfc_free_bucket(vport); | |
2866 | vport->stat_data_enabled = 0; | |
2867 | spin_unlock_irq(shost->host_lock); | |
2868 | return strlen(buf); | |
2869 | } | |
2870 | ||
2871 | if (!strncmp(buf, "reset", strlen("reset"))) { | |
2872 | if ((phba->bucket_type == LPFC_NO_BUCKET) | |
2873 | || !vport->stat_data_enabled) | |
2874 | return strlen(buf); | |
2875 | spin_lock_irq(shost->host_lock); | |
2876 | vport->stat_data_blocked = 1; | |
2877 | lpfc_vport_reset_stat_data(vport); | |
2878 | vport->stat_data_blocked = 0; | |
2879 | spin_unlock_irq(shost->host_lock); | |
2880 | return strlen(buf); | |
2881 | } | |
2882 | return -EINVAL; | |
2883 | } | |
2884 | ||
2885 | ||
2886 | /** | |
3621a710 | 2887 | * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
2888 | * @dev: Pointer to class device object. |
2889 | * @buf: Data buffer. | |
2890 | * | |
2891 | * This function is the read call back function for | |
2892 | * lpfc_stat_data_ctrl sysfs file. This function report the | |
2893 | * current statistical data collection state. | |
2894 | **/ | |
2895 | static ssize_t | |
2896 | lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, | |
2897 | char *buf) | |
2898 | { | |
2899 | struct Scsi_Host *shost = class_to_shost(dev); | |
2900 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2901 | struct lpfc_hba *phba = vport->phba; | |
2902 | int index = 0; | |
2903 | int i; | |
2904 | char *bucket_type; | |
2905 | unsigned long bucket_value; | |
2906 | ||
2907 | switch (phba->bucket_type) { | |
2908 | case LPFC_LINEAR_BUCKET: | |
2909 | bucket_type = "linear"; | |
2910 | break; | |
2911 | case LPFC_POWER2_BUCKET: | |
2912 | bucket_type = "power2"; | |
2913 | break; | |
2914 | default: | |
2915 | bucket_type = "No Bucket"; | |
2916 | break; | |
2917 | } | |
2918 | ||
2919 | sprintf(&buf[index], "Statistical Data enabled :%d, " | |
2920 | "blocked :%d, Bucket type :%s, Bucket base :%d," | |
2921 | " Bucket step :%d\nLatency Ranges :", | |
2922 | vport->stat_data_enabled, vport->stat_data_blocked, | |
2923 | bucket_type, phba->bucket_base, phba->bucket_step); | |
2924 | index = strlen(buf); | |
2925 | if (phba->bucket_type != LPFC_NO_BUCKET) { | |
2926 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
2927 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) | |
2928 | bucket_value = phba->bucket_base + | |
2929 | phba->bucket_step * i; | |
2930 | else | |
2931 | bucket_value = phba->bucket_base + | |
2932 | (1 << i) * phba->bucket_step; | |
2933 | ||
2934 | if (index + 10 > PAGE_SIZE) | |
2935 | break; | |
2936 | sprintf(&buf[index], "%08ld ", bucket_value); | |
2937 | index = strlen(buf); | |
2938 | } | |
2939 | } | |
2940 | sprintf(&buf[index], "\n"); | |
2941 | return strlen(buf); | |
2942 | } | |
2943 | ||
2944 | /* | |
2945 | * Sysfs attribute to control the statistical data collection. | |
2946 | */ | |
2947 | static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR, | |
2948 | lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store); | |
2949 | ||
2950 | /* | |
2951 | * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. | |
2952 | */ | |
2953 | ||
2954 | /* | |
2955 | * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN | |
2956 | * for each target. | |
2957 | */ | |
2958 | #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) | |
2959 | #define MAX_STAT_DATA_SIZE_PER_TARGET \ | |
2960 | STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) | |
2961 | ||
2962 | ||
2963 | /** | |
3621a710 | 2964 | * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute |
2c3c8bea | 2965 | * @filp: sysfs file |
ea2151b4 JS |
2966 | * @kobj: Pointer to the kernel object |
2967 | * @bin_attr: Attribute object | |
2968 | * @buff: Buffer pointer | |
2969 | * @off: File offset | |
2970 | * @count: Buffer size | |
2971 | * | |
2972 | * This function is the read call back function for lpfc_drvr_stat_data | |
2973 | * sysfs file. This function export the statistical data to user | |
2974 | * applications. | |
2975 | **/ | |
2976 | static ssize_t | |
2c3c8bea CW |
2977 | sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj, |
2978 | struct bin_attribute *bin_attr, | |
ea2151b4 JS |
2979 | char *buf, loff_t off, size_t count) |
2980 | { | |
2981 | struct device *dev = container_of(kobj, struct device, | |
2982 | kobj); | |
2983 | struct Scsi_Host *shost = class_to_shost(dev); | |
2984 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2985 | struct lpfc_hba *phba = vport->phba; | |
2986 | int i = 0, index = 0; | |
2987 | unsigned long nport_index; | |
2988 | struct lpfc_nodelist *ndlp = NULL; | |
2989 | nport_index = (unsigned long)off / | |
2990 | MAX_STAT_DATA_SIZE_PER_TARGET; | |
2991 | ||
2992 | if (!vport->stat_data_enabled || vport->stat_data_blocked | |
2993 | || (phba->bucket_type == LPFC_NO_BUCKET)) | |
2994 | return 0; | |
2995 | ||
2996 | spin_lock_irq(shost->host_lock); | |
2997 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
2998 | if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) | |
2999 | continue; | |
3000 | ||
3001 | if (nport_index > 0) { | |
3002 | nport_index--; | |
3003 | continue; | |
3004 | } | |
3005 | ||
3006 | if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) | |
3007 | > count) | |
3008 | break; | |
3009 | ||
3010 | if (!ndlp->lat_data) | |
3011 | continue; | |
3012 | ||
3013 | /* Print the WWN */ | |
3014 | sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", | |
3015 | ndlp->nlp_portname.u.wwn[0], | |
3016 | ndlp->nlp_portname.u.wwn[1], | |
3017 | ndlp->nlp_portname.u.wwn[2], | |
3018 | ndlp->nlp_portname.u.wwn[3], | |
3019 | ndlp->nlp_portname.u.wwn[4], | |
3020 | ndlp->nlp_portname.u.wwn[5], | |
3021 | ndlp->nlp_portname.u.wwn[6], | |
3022 | ndlp->nlp_portname.u.wwn[7]); | |
3023 | ||
3024 | index = strlen(buf); | |
3025 | ||
3026 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
3027 | sprintf(&buf[index], "%010u,", | |
3028 | ndlp->lat_data[i].cmd_count); | |
3029 | index = strlen(buf); | |
3030 | } | |
3031 | sprintf(&buf[index], "\n"); | |
3032 | index = strlen(buf); | |
3033 | } | |
3034 | spin_unlock_irq(shost->host_lock); | |
3035 | return index; | |
3036 | } | |
3037 | ||
3038 | static struct bin_attribute sysfs_drvr_stat_data_attr = { | |
3039 | .attr = { | |
3040 | .name = "lpfc_drvr_stat_data", | |
3041 | .mode = S_IRUSR, | |
ea2151b4 JS |
3042 | }, |
3043 | .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, | |
3044 | .read = sysfs_drvr_stat_data_read, | |
3045 | .write = NULL, | |
3046 | }; | |
3047 | ||
dea3101e | 3048 | /* |
3049 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | |
3050 | # connection. | |
76a95d75 | 3051 | # Value range is [0,16]. Default value is 0. |
dea3101e | 3052 | */ |
e59058c4 | 3053 | /** |
3621a710 | 3054 | * lpfc_link_speed_set - Set the adapters link speed |
e59058c4 JS |
3055 | * @phba: lpfc_hba pointer. |
3056 | * @val: link speed value. | |
3057 | * | |
3058 | * Description: | |
3059 | * If val is in a valid range then set the adapter's link speed field and | |
3060 | * issue a lip; if the lip fails reset the link speed to the old value. | |
3061 | * | |
3062 | * Notes: | |
3063 | * If the value is not in range log a kernel error message and return an error. | |
3064 | * | |
3065 | * Returns: | |
3066 | * zero if val is in range and lip okay. | |
3067 | * non-zero return value from lpfc_issue_lip() | |
3068 | * -EINVAL val out of range | |
3069 | **/ | |
a257bf90 JS |
3070 | static ssize_t |
3071 | lpfc_link_speed_store(struct device *dev, struct device_attribute *attr, | |
3072 | const char *buf, size_t count) | |
83108bd3 | 3073 | { |
a257bf90 JS |
3074 | struct Scsi_Host *shost = class_to_shost(dev); |
3075 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3076 | struct lpfc_hba *phba = vport->phba; | |
76a95d75 | 3077 | int val = LPFC_USER_LINK_SPEED_AUTO; |
a257bf90 JS |
3078 | int nolip = 0; |
3079 | const char *val_buf = buf; | |
83108bd3 JS |
3080 | int err; |
3081 | uint32_t prev_val; | |
3082 | ||
a257bf90 JS |
3083 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { |
3084 | nolip = 1; | |
3085 | val_buf = &buf[strlen("nolip ")]; | |
3086 | } | |
3087 | ||
3088 | if (!isdigit(val_buf[0])) | |
3089 | return -EINVAL; | |
3090 | if (sscanf(val_buf, "%i", &val) != 1) | |
3091 | return -EINVAL; | |
3092 | ||
76a95d75 JS |
3093 | if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || |
3094 | ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || | |
3095 | ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || | |
3096 | ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || | |
3097 | ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) || | |
3098 | ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) { | |
3099 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3100 | "2879 lpfc_link_speed attribute cannot be set " | |
3101 | "to %d. Speed is not supported by this port.\n", | |
3102 | val); | |
83108bd3 | 3103 | return -EINVAL; |
76a95d75 JS |
3104 | } |
3105 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && | |
3106 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
3107 | prev_val = phba->cfg_link_speed; |
3108 | phba->cfg_link_speed = val; | |
a257bf90 JS |
3109 | if (nolip) |
3110 | return strlen(buf); | |
3111 | ||
83108bd3 | 3112 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 3113 | if (err) { |
83108bd3 | 3114 | phba->cfg_link_speed = prev_val; |
a257bf90 JS |
3115 | return -EINVAL; |
3116 | } else | |
3117 | return strlen(buf); | |
83108bd3 | 3118 | } |
83108bd3 | 3119 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
76a95d75 JS |
3120 | "0469 lpfc_link_speed attribute cannot be set to %d, " |
3121 | "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val); | |
83108bd3 JS |
3122 | return -EINVAL; |
3123 | } | |
3124 | ||
3125 | static int lpfc_link_speed = 0; | |
ab56dc2e | 3126 | module_param(lpfc_link_speed, int, S_IRUGO); |
83108bd3 JS |
3127 | MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); |
3128 | lpfc_param_show(link_speed) | |
e59058c4 JS |
3129 | |
3130 | /** | |
3621a710 | 3131 | * lpfc_link_speed_init - Set the adapters link speed |
e59058c4 JS |
3132 | * @phba: lpfc_hba pointer. |
3133 | * @val: link speed value. | |
3134 | * | |
3135 | * Description: | |
3136 | * If val is in a valid range then set the adapter's link speed field. | |
3137 | * | |
3138 | * Notes: | |
3139 | * If the value is not in range log a kernel error message, clear the link | |
3140 | * speed and return an error. | |
3141 | * | |
3142 | * Returns: | |
3143 | * zero if val saved. | |
3144 | * -EINVAL val out of range | |
3145 | **/ | |
83108bd3 JS |
3146 | static int |
3147 | lpfc_link_speed_init(struct lpfc_hba *phba, int val) | |
3148 | { | |
76a95d75 JS |
3149 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && |
3150 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
3151 | phba->cfg_link_speed = val; |
3152 | return 0; | |
3153 | } | |
3154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 3155 | "0405 lpfc_link_speed attribute cannot " |
83108bd3 JS |
3156 | "be set to %d, allowed values are " |
3157 | "["LPFC_LINK_SPEED_STRING"]\n", val); | |
76a95d75 | 3158 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
83108bd3 JS |
3159 | return -EINVAL; |
3160 | } | |
3161 | ||
ee959b00 | 3162 | static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, |
76a95d75 | 3163 | lpfc_link_speed_show, lpfc_link_speed_store); |
dea3101e | 3164 | |
0d878419 JS |
3165 | /* |
3166 | # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER) | |
3167 | # 0 = aer disabled or not supported | |
3168 | # 1 = aer supported and enabled (default) | |
3169 | # Value range is [0,1]. Default value is 1. | |
3170 | */ | |
3171 | ||
3172 | /** | |
3173 | * lpfc_aer_support_store - Set the adapter for aer support | |
3174 | * | |
3175 | * @dev: class device that is converted into a Scsi_host. | |
3176 | * @attr: device attribute, not used. | |
912e3acd | 3177 | * @buf: containing enable or disable aer flag. |
0d878419 JS |
3178 | * @count: unused variable. |
3179 | * | |
3180 | * Description: | |
3181 | * If the val is 1 and currently the device's AER capability was not | |
3182 | * enabled, invoke the kernel's enable AER helper routine, trying to | |
3183 | * enable the device's AER capability. If the helper routine enabling | |
3184 | * AER returns success, update the device's cfg_aer_support flag to | |
3185 | * indicate AER is supported by the device; otherwise, if the device | |
3186 | * AER capability is already enabled to support AER, then do nothing. | |
3187 | * | |
3188 | * If the val is 0 and currently the device's AER support was enabled, | |
3189 | * invoke the kernel's disable AER helper routine. After that, update | |
3190 | * the device's cfg_aer_support flag to indicate AER is not supported | |
3191 | * by the device; otherwise, if the device AER capability is already | |
3192 | * disabled from supporting AER, then do nothing. | |
3193 | * | |
3194 | * Returns: | |
3195 | * length of the buf on success if val is in range the intended mode | |
3196 | * is supported. | |
3197 | * -EINVAL if val out of range or intended mode is not supported. | |
3198 | **/ | |
3199 | static ssize_t | |
3200 | lpfc_aer_support_store(struct device *dev, struct device_attribute *attr, | |
3201 | const char *buf, size_t count) | |
3202 | { | |
3203 | struct Scsi_Host *shost = class_to_shost(dev); | |
3204 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
3205 | struct lpfc_hba *phba = vport->phba; | |
3206 | int val = 0, rc = -EINVAL; | |
3207 | ||
3208 | if (!isdigit(buf[0])) | |
3209 | return -EINVAL; | |
3210 | if (sscanf(buf, "%i", &val) != 1) | |
3211 | return -EINVAL; | |
3212 | ||
3213 | switch (val) { | |
3214 | case 0: | |
3215 | if (phba->hba_flag & HBA_AER_ENABLED) { | |
3216 | rc = pci_disable_pcie_error_reporting(phba->pcidev); | |
3217 | if (!rc) { | |
3218 | spin_lock_irq(&phba->hbalock); | |
3219 | phba->hba_flag &= ~HBA_AER_ENABLED; | |
3220 | spin_unlock_irq(&phba->hbalock); | |
3221 | phba->cfg_aer_support = 0; | |
3222 | rc = strlen(buf); | |
3223 | } else | |
891478a2 JS |
3224 | rc = -EPERM; |
3225 | } else { | |
0d878419 | 3226 | phba->cfg_aer_support = 0; |
891478a2 JS |
3227 | rc = strlen(buf); |
3228 | } | |
0d878419 JS |
3229 | break; |
3230 | case 1: | |
3231 | if (!(phba->hba_flag & HBA_AER_ENABLED)) { | |
3232 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
3233 | if (!rc) { | |
3234 | spin_lock_irq(&phba->hbalock); | |
3235 | phba->hba_flag |= HBA_AER_ENABLED; | |
3236 | spin_unlock_irq(&phba->hbalock); | |
3237 | phba->cfg_aer_support = 1; | |
3238 | rc = strlen(buf); | |
3239 | } else | |
891478a2 JS |
3240 | rc = -EPERM; |
3241 | } else { | |
0d878419 | 3242 | phba->cfg_aer_support = 1; |
891478a2 JS |
3243 | rc = strlen(buf); |
3244 | } | |
0d878419 JS |
3245 | break; |
3246 | default: | |
3247 | rc = -EINVAL; | |
3248 | break; | |
3249 | } | |
3250 | return rc; | |
3251 | } | |
3252 | ||
3253 | static int lpfc_aer_support = 1; | |
ab56dc2e | 3254 | module_param(lpfc_aer_support, int, S_IRUGO); |
0d878419 JS |
3255 | MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support"); |
3256 | lpfc_param_show(aer_support) | |
3257 | ||
3258 | /** | |
3259 | * lpfc_aer_support_init - Set the initial adapters aer support flag | |
3260 | * @phba: lpfc_hba pointer. | |
912e3acd | 3261 | * @val: enable aer or disable aer flag. |
0d878419 JS |
3262 | * |
3263 | * Description: | |
3264 | * If val is in a valid range [0,1], then set the adapter's initial | |
3265 | * cfg_aer_support field. It will be up to the driver's probe_one | |
3266 | * routine to determine whether the device's AER support can be set | |
3267 | * or not. | |
3268 | * | |
3269 | * Notes: | |
3270 | * If the value is not in range log a kernel error message, and | |
3271 | * choose the default value of setting AER support and return. | |
3272 | * | |
3273 | * Returns: | |
3274 | * zero if val saved. | |
3275 | * -EINVAL val out of range | |
3276 | **/ | |
3277 | static int | |
3278 | lpfc_aer_support_init(struct lpfc_hba *phba, int val) | |
3279 | { | |
3280 | if (val == 0 || val == 1) { | |
3281 | phba->cfg_aer_support = val; | |
3282 | return 0; | |
3283 | } | |
3284 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3285 | "2712 lpfc_aer_support attribute value %d out " | |
3286 | "of range, allowed values are 0|1, setting it " | |
3287 | "to default value of 1\n", val); | |
891478a2 | 3288 | /* By default, try to enable AER on a device */ |
0d878419 JS |
3289 | phba->cfg_aer_support = 1; |
3290 | return -EINVAL; | |
3291 | } | |
3292 | ||
3293 | static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR, | |
3294 | lpfc_aer_support_show, lpfc_aer_support_store); | |
3295 | ||
3296 | /** | |
3297 | * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device | |
3298 | * @dev: class device that is converted into a Scsi_host. | |
3299 | * @attr: device attribute, not used. | |
912e3acd | 3300 | * @buf: containing flag 1 for aer cleanup state. |
0d878419 JS |
3301 | * @count: unused variable. |
3302 | * | |
3303 | * Description: | |
3304 | * If the @buf contains 1 and the device currently has the AER support | |
3305 | * enabled, then invokes the kernel AER helper routine | |
3306 | * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable | |
3307 | * error status register. | |
3308 | * | |
3309 | * Notes: | |
3310 | * | |
3311 | * Returns: | |
3312 | * -EINVAL if the buf does not contain the 1 or the device is not currently | |
3313 | * enabled with the AER support. | |
3314 | **/ | |
3315 | static ssize_t | |
3316 | lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr, | |
3317 | const char *buf, size_t count) | |
3318 | { | |
3319 | struct Scsi_Host *shost = class_to_shost(dev); | |
3320 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3321 | struct lpfc_hba *phba = vport->phba; | |
3322 | int val, rc = -1; | |
3323 | ||
3324 | if (!isdigit(buf[0])) | |
3325 | return -EINVAL; | |
3326 | if (sscanf(buf, "%i", &val) != 1) | |
3327 | return -EINVAL; | |
891478a2 JS |
3328 | if (val != 1) |
3329 | return -EINVAL; | |
0d878419 | 3330 | |
891478a2 | 3331 | if (phba->hba_flag & HBA_AER_ENABLED) |
0d878419 JS |
3332 | rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev); |
3333 | ||
3334 | if (rc == 0) | |
3335 | return strlen(buf); | |
3336 | else | |
891478a2 | 3337 | return -EPERM; |
0d878419 JS |
3338 | } |
3339 | ||
3340 | static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL, | |
3341 | lpfc_aer_cleanup_state); | |
3342 | ||
912e3acd JS |
3343 | /** |
3344 | * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions | |
3345 | * | |
3346 | * @dev: class device that is converted into a Scsi_host. | |
3347 | * @attr: device attribute, not used. | |
3348 | * @buf: containing the string the number of vfs to be enabled. | |
3349 | * @count: unused variable. | |
3350 | * | |
3351 | * Description: | |
3352 | * When this api is called either through user sysfs, the driver shall | |
3353 | * try to enable or disable SR-IOV virtual functions according to the | |
3354 | * following: | |
3355 | * | |
3356 | * If zero virtual function has been enabled to the physical function, | |
3357 | * the driver shall invoke the pci enable virtual function api trying | |
3358 | * to enable the virtual functions. If the nr_vfn provided is greater | |
3359 | * than the maximum supported, the maximum virtual function number will | |
3360 | * be used for invoking the api; otherwise, the nr_vfn provided shall | |
3361 | * be used for invoking the api. If the api call returned success, the | |
3362 | * actual number of virtual functions enabled will be set to the driver | |
3363 | * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver | |
3364 | * cfg_sriov_nr_virtfn remains zero. | |
3365 | * | |
3366 | * If none-zero virtual functions have already been enabled to the | |
3367 | * physical function, as reflected by the driver's cfg_sriov_nr_virtfn, | |
3368 | * -EINVAL will be returned and the driver does nothing; | |
3369 | * | |
3370 | * If the nr_vfn provided is zero and none-zero virtual functions have | |
3371 | * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the | |
3372 | * disabling virtual function api shall be invoded to disable all the | |
3373 | * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to | |
3374 | * zero. Otherwise, if zero virtual function has been enabled, do | |
3375 | * nothing. | |
3376 | * | |
3377 | * Returns: | |
3378 | * length of the buf on success if val is in range the intended mode | |
3379 | * is supported. | |
3380 | * -EINVAL if val out of range or intended mode is not supported. | |
3381 | **/ | |
3382 | static ssize_t | |
3383 | lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr, | |
3384 | const char *buf, size_t count) | |
3385 | { | |
3386 | struct Scsi_Host *shost = class_to_shost(dev); | |
3387 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
3388 | struct lpfc_hba *phba = vport->phba; | |
3389 | struct pci_dev *pdev = phba->pcidev; | |
3390 | int val = 0, rc = -EINVAL; | |
3391 | ||
3392 | /* Sanity check on user data */ | |
3393 | if (!isdigit(buf[0])) | |
3394 | return -EINVAL; | |
3395 | if (sscanf(buf, "%i", &val) != 1) | |
3396 | return -EINVAL; | |
3397 | if (val < 0) | |
3398 | return -EINVAL; | |
3399 | ||
3400 | /* Request disabling virtual functions */ | |
3401 | if (val == 0) { | |
3402 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
3403 | pci_disable_sriov(pdev); | |
3404 | phba->cfg_sriov_nr_virtfn = 0; | |
3405 | } | |
3406 | return strlen(buf); | |
3407 | } | |
3408 | ||
3409 | /* Request enabling virtual functions */ | |
3410 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
3411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3412 | "3018 There are %d virtual functions " | |
3413 | "enabled on physical function.\n", | |
3414 | phba->cfg_sriov_nr_virtfn); | |
3415 | return -EEXIST; | |
3416 | } | |
3417 | ||
3418 | if (val <= LPFC_MAX_VFN_PER_PFN) | |
3419 | phba->cfg_sriov_nr_virtfn = val; | |
3420 | else { | |
3421 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3422 | "3019 Enabling %d virtual functions is not " | |
3423 | "allowed.\n", val); | |
3424 | return -EINVAL; | |
3425 | } | |
3426 | ||
3427 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn); | |
3428 | if (rc) { | |
3429 | phba->cfg_sriov_nr_virtfn = 0; | |
3430 | rc = -EPERM; | |
3431 | } else | |
3432 | rc = strlen(buf); | |
3433 | ||
3434 | return rc; | |
3435 | } | |
3436 | ||
3437 | static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN; | |
3438 | module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR); | |
3439 | MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn"); | |
3440 | lpfc_param_show(sriov_nr_virtfn) | |
3441 | ||
3442 | /** | |
3443 | * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable | |
3444 | * @phba: lpfc_hba pointer. | |
3445 | * @val: link speed value. | |
3446 | * | |
3447 | * Description: | |
3448 | * If val is in a valid range [0,255], then set the adapter's initial | |
3449 | * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum | |
3450 | * number shall be used instead. It will be up to the driver's probe_one | |
3451 | * routine to determine whether the device's SR-IOV is supported or not. | |
3452 | * | |
3453 | * Returns: | |
3454 | * zero if val saved. | |
3455 | * -EINVAL val out of range | |
3456 | **/ | |
3457 | static int | |
3458 | lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val) | |
3459 | { | |
3460 | if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) { | |
3461 | phba->cfg_sriov_nr_virtfn = val; | |
3462 | return 0; | |
3463 | } | |
3464 | ||
3465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3466 | "3017 Enabling %d virtual functions is not " | |
3467 | "allowed.\n", val); | |
3468 | return -EINVAL; | |
3469 | } | |
3470 | static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR, | |
3471 | lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store); | |
3472 | ||
dea3101e | 3473 | /* |
3474 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. | |
3475 | # Value range is [2,3]. Default value is 3. | |
3476 | */ | |
3de2a653 JS |
3477 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, |
3478 | "Select Fibre Channel class of service for FCP sequences"); | |
dea3101e | 3479 | |
3480 | /* | |
3481 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | |
3482 | # is [0,1]. Default value is 0. | |
3483 | */ | |
3de2a653 JS |
3484 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, |
3485 | "Use ADISC on rediscovery to authenticate FCP devices"); | |
dea3101e | 3486 | |
977b5a0a JS |
3487 | /* |
3488 | # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue | |
3489 | # depth. Default value is 0. When the value of this parameter is zero the | |
3490 | # SCSI command completion time is not used for controlling I/O queue depth. When | |
3491 | # the parameter is set to a non-zero value, the I/O queue depth is controlled | |
3492 | # to limit the I/O completion time to the parameter value. | |
3493 | # The value is set in milliseconds. | |
3494 | */ | |
3495 | static int lpfc_max_scsicmpl_time; | |
ab56dc2e | 3496 | module_param(lpfc_max_scsicmpl_time, int, S_IRUGO); |
977b5a0a JS |
3497 | MODULE_PARM_DESC(lpfc_max_scsicmpl_time, |
3498 | "Use command completion time to control queue depth"); | |
3499 | lpfc_vport_param_show(max_scsicmpl_time); | |
3500 | lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000); | |
3501 | static int | |
3502 | lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) | |
3503 | { | |
3504 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
3505 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
3506 | ||
3507 | if (val == vport->cfg_max_scsicmpl_time) | |
3508 | return 0; | |
3509 | if ((val < 0) || (val > 60000)) | |
3510 | return -EINVAL; | |
3511 | vport->cfg_max_scsicmpl_time = val; | |
3512 | ||
3513 | spin_lock_irq(shost->host_lock); | |
3514 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
3515 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
3516 | continue; | |
3517 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | |
3518 | continue; | |
7dc517df | 3519 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
977b5a0a JS |
3520 | } |
3521 | spin_unlock_irq(shost->host_lock); | |
3522 | return 0; | |
3523 | } | |
3524 | lpfc_vport_param_store(max_scsicmpl_time); | |
3525 | static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR, | |
3526 | lpfc_max_scsicmpl_time_show, | |
3527 | lpfc_max_scsicmpl_time_store); | |
3528 | ||
dea3101e | 3529 | /* |
3530 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | |
3531 | # range is [0,1]. Default value is 0. | |
3532 | */ | |
3533 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | |
3534 | ||
3535 | /* | |
3536 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | |
3537 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | |
7054a606 | 3538 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay |
dea3101e | 3539 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
3540 | # cr_delay is set to 0. | |
3541 | */ | |
8189fd19 | 3542 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " |
dea3101e | 3543 | "interrupt response is generated"); |
3544 | ||
8189fd19 | 3545 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " |
dea3101e | 3546 | "interrupt response is generated"); |
3547 | ||
cf5bf97e JW |
3548 | /* |
3549 | # lpfc_multi_ring_support: Determines how many rings to spread available | |
3550 | # cmd/rsp IOCB entries across. | |
3551 | # Value range is [1,2]. Default value is 1. | |
3552 | */ | |
3553 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " | |
3554 | "SLI rings to spread IOCB entries across"); | |
3555 | ||
a4bc3379 JS |
3556 | /* |
3557 | # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this | |
3558 | # identifies what rctl value to configure the additional ring for. | |
3559 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). | |
3560 | */ | |
6a9c52cf | 3561 | LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1, |
a4bc3379 JS |
3562 | 255, "Identifies RCTL for additional ring configuration"); |
3563 | ||
3564 | /* | |
3565 | # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this | |
3566 | # identifies what type value to configure the additional ring for. | |
3567 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). | |
3568 | */ | |
6a9c52cf | 3569 | LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1, |
a4bc3379 JS |
3570 | 255, "Identifies TYPE for additional ring configuration"); |
3571 | ||
dea3101e | 3572 | /* |
3573 | # lpfc_fdmi_on: controls FDMI support. | |
3574 | # 0 = no FDMI support | |
3575 | # 1 = support FDMI without attribute of hostname | |
3576 | # 2 = support FDMI with attribute of hostname | |
3577 | # Value range [0,2]. Default value is 0. | |
3578 | */ | |
3de2a653 | 3579 | LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); |
dea3101e | 3580 | |
3581 | /* | |
3582 | # Specifies the maximum number of ELS cmds we can have outstanding (for | |
3583 | # discovery). Value range is [1,64]. Default value = 32. | |
3584 | */ | |
3de2a653 | 3585 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
dea3101e | 3586 | "during discovery"); |
3587 | ||
3588 | /* | |
65a29c16 JS |
3589 | # lpfc_max_luns: maximum allowed LUN. |
3590 | # Value range is [0,65535]. Default value is 255. | |
3591 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. | |
dea3101e | 3592 | */ |
3de2a653 | 3593 | LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN"); |
dea3101e | 3594 | |
875fbdfe JSEC |
3595 | /* |
3596 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. | |
3597 | # Value range is [1,255], default value is 10. | |
3598 | */ | |
3599 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, | |
3600 | "Milliseconds driver will wait between polling FCP ring"); | |
3601 | ||
4ff43246 JS |
3602 | /* |
3603 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that | |
3604 | # support this feature | |
8605c46c | 3605 | # 0 = MSI disabled |
4ff43246 | 3606 | # 1 = MSI enabled |
8605c46c GK |
3607 | # 2 = MSI-X enabled (default) |
3608 | # Value range is [0,2]. Default value is 2. | |
4ff43246 | 3609 | */ |
8605c46c | 3610 | LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " |
db2378e0 | 3611 | "MSI-X (2), if possible"); |
4ff43246 | 3612 | |
da0436e9 JS |
3613 | /* |
3614 | # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second | |
3615 | # | |
3616 | # Value range is [636,651042]. Default value is 10000. | |
3617 | */ | |
3618 | LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST, | |
3619 | "Set the maximum number of fast-path FCP interrupts per second"); | |
3620 | ||
3621 | /* | |
3622 | # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues | |
3623 | # | |
3624 | # Value range is [1,31]. Default value is 4. | |
3625 | */ | |
3626 | LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX, | |
3627 | "Set the number of fast-path FCP work queues, if possible"); | |
3628 | ||
3629 | /* | |
3630 | # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues | |
3631 | # | |
3632 | # Value range is [1,7]. Default value is 1. | |
3633 | */ | |
3634 | LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX, | |
3635 | "Set the number of fast-path FCP event queues, if possible"); | |
3636 | ||
13815c83 JS |
3637 | /* |
3638 | # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. | |
3639 | # 0 = HBA resets disabled | |
3640 | # 1 = HBA resets enabled (default) | |
3641 | # Value range is [0,1]. Default value is 1. | |
3642 | */ | |
3643 | LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); | |
c3f28afa | 3644 | |
13815c83 | 3645 | /* |
eb7a339e | 3646 | # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer.. |
13815c83 JS |
3647 | # 0 = HBA Heartbeat disabled |
3648 | # 1 = HBA Heartbeat enabled (default) | |
3649 | # Value range is [0,1]. Default value is 1. | |
3650 | */ | |
eb7a339e | 3651 | LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat."); |
92d7f7b0 | 3652 | |
81301a9b JS |
3653 | /* |
3654 | # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF) | |
3655 | # 0 = BlockGuard disabled (default) | |
3656 | # 1 = BlockGuard enabled | |
3657 | # Value range is [0,1]. Default value is 0. | |
3658 | */ | |
3659 | LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support"); | |
3660 | ||
81301a9b JS |
3661 | /* |
3662 | # lpfc_prot_mask: i | |
3663 | # - Bit mask of host protection capabilities used to register with the | |
3664 | # SCSI mid-layer | |
3665 | # - Only meaningful if BG is turned on (lpfc_enable_bg=1). | |
3666 | # - Allows you to ultimately specify which profiles to use | |
3667 | # - Default will result in registering capabilities for all profiles. | |
3668 | # | |
3669 | */ | |
bc73905a | 3670 | unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION; |
81301a9b | 3671 | |
ab56dc2e | 3672 | module_param(lpfc_prot_mask, uint, S_IRUGO); |
81301a9b JS |
3673 | MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask"); |
3674 | ||
3675 | /* | |
3676 | # lpfc_prot_guard: i | |
3677 | # - Bit mask of protection guard types to register with the SCSI mid-layer | |
3678 | # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC | |
3679 | # - Allows you to ultimately specify which profiles to use | |
3680 | # - Default will result in registering capabilities for all guard types | |
3681 | # | |
3682 | */ | |
3683 | unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP; | |
ab56dc2e | 3684 | module_param(lpfc_prot_guard, byte, S_IRUGO); |
81301a9b JS |
3685 | MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type"); |
3686 | ||
92494144 JS |
3687 | /* |
3688 | * Delay initial NPort discovery when Clean Address bit is cleared in | |
3689 | * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed. | |
3690 | * This parameter can have value 0 or 1. | |
3691 | * When this parameter is set to 0, no delay is added to the initial | |
3692 | * discovery. | |
3693 | * When this parameter is set to non-zero value, initial Nport discovery is | |
3694 | * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC | |
3695 | * accept and FCID/Fabric name/Fabric portname is changed. | |
3696 | * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion | |
3697 | * when Clean Address bit is cleared in FLOGI/FDISC | |
3698 | * accept and FCID/Fabric name/Fabric portname is changed. | |
3699 | * Default value is 0. | |
3700 | */ | |
3701 | int lpfc_delay_discovery; | |
ab56dc2e | 3702 | module_param(lpfc_delay_discovery, int, S_IRUGO); |
92494144 JS |
3703 | MODULE_PARM_DESC(lpfc_delay_discovery, |
3704 | "Delay NPort discovery when Clean Address bit is cleared. " | |
3705 | "Allowed values: 0,1."); | |
81301a9b | 3706 | |
83108bd3 | 3707 | /* |
3621a710 | 3708 | * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count |
83108bd3 JS |
3709 | * This value can be set to values between 64 and 256. The default value is |
3710 | * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer | |
3711 | * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). | |
3712 | */ | |
3713 | LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, | |
3714 | LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); | |
3715 | ||
81301a9b JS |
3716 | LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT, |
3717 | LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT, | |
3718 | "Max Protection Scatter Gather Segment Count"); | |
3719 | ||
ee959b00 | 3720 | struct device_attribute *lpfc_hba_attrs[] = { |
81301a9b JS |
3721 | &dev_attr_bg_info, |
3722 | &dev_attr_bg_guard_err, | |
3723 | &dev_attr_bg_apptag_err, | |
3724 | &dev_attr_bg_reftag_err, | |
ee959b00 TJ |
3725 | &dev_attr_info, |
3726 | &dev_attr_serialnum, | |
3727 | &dev_attr_modeldesc, | |
3728 | &dev_attr_modelname, | |
3729 | &dev_attr_programtype, | |
3730 | &dev_attr_portnum, | |
3731 | &dev_attr_fwrev, | |
3732 | &dev_attr_hdw, | |
3733 | &dev_attr_option_rom_version, | |
bbd1ae41 | 3734 | &dev_attr_link_state, |
ee959b00 | 3735 | &dev_attr_num_discovered_ports, |
84774a4d | 3736 | &dev_attr_menlo_mgmt_mode, |
ee959b00 | 3737 | &dev_attr_lpfc_drvr_version, |
45ed1190 | 3738 | &dev_attr_lpfc_enable_fip, |
ee959b00 TJ |
3739 | &dev_attr_lpfc_temp_sensor, |
3740 | &dev_attr_lpfc_log_verbose, | |
3741 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 3742 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
3743 | &dev_attr_lpfc_hba_queue_depth, |
3744 | &dev_attr_lpfc_peer_port_login, | |
3745 | &dev_attr_lpfc_nodev_tmo, | |
3746 | &dev_attr_lpfc_devloss_tmo, | |
3747 | &dev_attr_lpfc_fcp_class, | |
3748 | &dev_attr_lpfc_use_adisc, | |
3749 | &dev_attr_lpfc_ack0, | |
3750 | &dev_attr_lpfc_topology, | |
3751 | &dev_attr_lpfc_scan_down, | |
3752 | &dev_attr_lpfc_link_speed, | |
3753 | &dev_attr_lpfc_cr_delay, | |
3754 | &dev_attr_lpfc_cr_count, | |
3755 | &dev_attr_lpfc_multi_ring_support, | |
3756 | &dev_attr_lpfc_multi_ring_rctl, | |
3757 | &dev_attr_lpfc_multi_ring_type, | |
3758 | &dev_attr_lpfc_fdmi_on, | |
3759 | &dev_attr_lpfc_max_luns, | |
3760 | &dev_attr_lpfc_enable_npiv, | |
19ca7609 | 3761 | &dev_attr_lpfc_enable_rrq, |
ee959b00 TJ |
3762 | &dev_attr_nport_evt_cnt, |
3763 | &dev_attr_board_mode, | |
3764 | &dev_attr_max_vpi, | |
3765 | &dev_attr_used_vpi, | |
3766 | &dev_attr_max_rpi, | |
3767 | &dev_attr_used_rpi, | |
3768 | &dev_attr_max_xri, | |
3769 | &dev_attr_used_xri, | |
3770 | &dev_attr_npiv_info, | |
3771 | &dev_attr_issue_reset, | |
3772 | &dev_attr_lpfc_poll, | |
3773 | &dev_attr_lpfc_poll_tmo, | |
3774 | &dev_attr_lpfc_use_msi, | |
da0436e9 JS |
3775 | &dev_attr_lpfc_fcp_imax, |
3776 | &dev_attr_lpfc_fcp_wq_count, | |
3777 | &dev_attr_lpfc_fcp_eq_count, | |
81301a9b | 3778 | &dev_attr_lpfc_enable_bg, |
ee959b00 TJ |
3779 | &dev_attr_lpfc_soft_wwnn, |
3780 | &dev_attr_lpfc_soft_wwpn, | |
3781 | &dev_attr_lpfc_soft_wwn_enable, | |
3782 | &dev_attr_lpfc_enable_hba_reset, | |
3783 | &dev_attr_lpfc_enable_hba_heartbeat, | |
3784 | &dev_attr_lpfc_sg_seg_cnt, | |
977b5a0a | 3785 | &dev_attr_lpfc_max_scsicmpl_time, |
ea2151b4 | 3786 | &dev_attr_lpfc_stat_data_ctrl, |
81301a9b | 3787 | &dev_attr_lpfc_prot_sg_seg_cnt, |
0d878419 JS |
3788 | &dev_attr_lpfc_aer_support, |
3789 | &dev_attr_lpfc_aer_state_cleanup, | |
912e3acd | 3790 | &dev_attr_lpfc_sriov_nr_virtfn, |
84d1b006 | 3791 | &dev_attr_lpfc_suppress_link_up, |
2a9bf3d0 JS |
3792 | &dev_attr_lpfc_iocb_cnt, |
3793 | &dev_attr_iocb_hw, | |
3794 | &dev_attr_txq_hw, | |
3795 | &dev_attr_txcmplq_hw, | |
bc73905a JS |
3796 | &dev_attr_lpfc_fips_level, |
3797 | &dev_attr_lpfc_fips_rev, | |
ab56dc2e | 3798 | &dev_attr_lpfc_dss, |
912e3acd | 3799 | &dev_attr_lpfc_sriov_hw_max_virtfn, |
dea3101e | 3800 | NULL, |
3801 | }; | |
3802 | ||
ee959b00 TJ |
3803 | struct device_attribute *lpfc_vport_attrs[] = { |
3804 | &dev_attr_info, | |
bbd1ae41 | 3805 | &dev_attr_link_state, |
ee959b00 TJ |
3806 | &dev_attr_num_discovered_ports, |
3807 | &dev_attr_lpfc_drvr_version, | |
3808 | &dev_attr_lpfc_log_verbose, | |
3809 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 3810 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
3811 | &dev_attr_lpfc_nodev_tmo, |
3812 | &dev_attr_lpfc_devloss_tmo, | |
3813 | &dev_attr_lpfc_hba_queue_depth, | |
3814 | &dev_attr_lpfc_peer_port_login, | |
3815 | &dev_attr_lpfc_restrict_login, | |
3816 | &dev_attr_lpfc_fcp_class, | |
3817 | &dev_attr_lpfc_use_adisc, | |
3818 | &dev_attr_lpfc_fdmi_on, | |
3819 | &dev_attr_lpfc_max_luns, | |
3820 | &dev_attr_nport_evt_cnt, | |
3821 | &dev_attr_npiv_info, | |
3822 | &dev_attr_lpfc_enable_da_id, | |
ea2151b4 JS |
3823 | &dev_attr_lpfc_max_scsicmpl_time, |
3824 | &dev_attr_lpfc_stat_data_ctrl, | |
21e9a0a5 | 3825 | &dev_attr_lpfc_static_vport, |
bc73905a JS |
3826 | &dev_attr_lpfc_fips_level, |
3827 | &dev_attr_lpfc_fips_rev, | |
3de2a653 JS |
3828 | NULL, |
3829 | }; | |
3830 | ||
e59058c4 | 3831 | /** |
3621a710 | 3832 | * sysfs_ctlreg_write - Write method for writing to ctlreg |
2c3c8bea | 3833 | * @filp: open sysfs file |
e59058c4 JS |
3834 | * @kobj: kernel kobject that contains the kernel class device. |
3835 | * @bin_attr: kernel attributes passed to us. | |
3836 | * @buf: contains the data to be written to the adapter IOREG space. | |
3837 | * @off: offset into buffer to beginning of data. | |
3838 | * @count: bytes to transfer. | |
3839 | * | |
3840 | * Description: | |
3841 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
3842 | * Uses the adapter io control registers to send buf contents to the adapter. | |
3843 | * | |
3844 | * Returns: | |
3845 | * -ERANGE off and count combo out of range | |
3846 | * -EINVAL off, count or buff address invalid | |
3847 | * -EPERM adapter is offline | |
3848 | * value of count, buf contents written | |
3849 | **/ | |
dea3101e | 3850 | static ssize_t |
2c3c8bea CW |
3851 | sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, |
3852 | struct bin_attribute *bin_attr, | |
91a69029 | 3853 | char *buf, loff_t off, size_t count) |
dea3101e | 3854 | { |
3855 | size_t buf_off; | |
ee959b00 TJ |
3856 | struct device *dev = container_of(kobj, struct device, kobj); |
3857 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
3858 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3859 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3860 | |
f1126688 JS |
3861 | if (phba->sli_rev >= LPFC_SLI_REV4) |
3862 | return -EPERM; | |
3863 | ||
dea3101e | 3864 | if ((off + count) > FF_REG_AREA_SIZE) |
3865 | return -ERANGE; | |
3866 | ||
3867 | if (count == 0) return 0; | |
3868 | ||
3869 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
3870 | return -EINVAL; | |
3871 | ||
2e0fef85 | 3872 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
dea3101e | 3873 | return -EPERM; |
3874 | } | |
3875 | ||
2e0fef85 | 3876 | spin_lock_irq(&phba->hbalock); |
dea3101e | 3877 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) |
3878 | writel(*((uint32_t *)(buf + buf_off)), | |
3879 | phba->ctrl_regs_memmap_p + off + buf_off); | |
3880 | ||
2e0fef85 | 3881 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3882 | |
3883 | return count; | |
3884 | } | |
3885 | ||
e59058c4 | 3886 | /** |
3621a710 | 3887 | * sysfs_ctlreg_read - Read method for reading from ctlreg |
2c3c8bea | 3888 | * @filp: open sysfs file |
e59058c4 JS |
3889 | * @kobj: kernel kobject that contains the kernel class device. |
3890 | * @bin_attr: kernel attributes passed to us. | |
af901ca1 | 3891 | * @buf: if successful contains the data from the adapter IOREG space. |
e59058c4 JS |
3892 | * @off: offset into buffer to beginning of data. |
3893 | * @count: bytes to transfer. | |
3894 | * | |
3895 | * Description: | |
3896 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
3897 | * Uses the adapter io control registers to read data into buf. | |
3898 | * | |
3899 | * Returns: | |
3900 | * -ERANGE off and count combo out of range | |
3901 | * -EINVAL off, count or buff address invalid | |
3902 | * value of count, buf contents read | |
3903 | **/ | |
dea3101e | 3904 | static ssize_t |
2c3c8bea CW |
3905 | sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, |
3906 | struct bin_attribute *bin_attr, | |
91a69029 | 3907 | char *buf, loff_t off, size_t count) |
dea3101e | 3908 | { |
3909 | size_t buf_off; | |
3910 | uint32_t * tmp_ptr; | |
ee959b00 TJ |
3911 | struct device *dev = container_of(kobj, struct device, kobj); |
3912 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
3913 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3914 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3915 | |
f1126688 JS |
3916 | if (phba->sli_rev >= LPFC_SLI_REV4) |
3917 | return -EPERM; | |
3918 | ||
dea3101e | 3919 | if (off > FF_REG_AREA_SIZE) |
3920 | return -ERANGE; | |
3921 | ||
3922 | if ((off + count) > FF_REG_AREA_SIZE) | |
3923 | count = FF_REG_AREA_SIZE - off; | |
3924 | ||
3925 | if (count == 0) return 0; | |
3926 | ||
3927 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
3928 | return -EINVAL; | |
3929 | ||
2e0fef85 | 3930 | spin_lock_irq(&phba->hbalock); |
dea3101e | 3931 | |
3932 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | |
3933 | tmp_ptr = (uint32_t *)(buf + buf_off); | |
3934 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | |
3935 | } | |
3936 | ||
2e0fef85 | 3937 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3938 | |
3939 | return count; | |
3940 | } | |
3941 | ||
3942 | static struct bin_attribute sysfs_ctlreg_attr = { | |
3943 | .attr = { | |
3944 | .name = "ctlreg", | |
3945 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 3946 | }, |
3947 | .size = 256, | |
3948 | .read = sysfs_ctlreg_read, | |
3949 | .write = sysfs_ctlreg_write, | |
3950 | }; | |
3951 | ||
e59058c4 | 3952 | /** |
3621a710 | 3953 | * sysfs_mbox_idle - frees the sysfs mailbox |
e59058c4 JS |
3954 | * @phba: lpfc_hba pointer |
3955 | **/ | |
dea3101e | 3956 | static void |
2e0fef85 | 3957 | sysfs_mbox_idle(struct lpfc_hba *phba) |
dea3101e | 3958 | { |
3959 | phba->sysfs_mbox.state = SMBOX_IDLE; | |
3960 | phba->sysfs_mbox.offset = 0; | |
3961 | ||
3962 | if (phba->sysfs_mbox.mbox) { | |
3963 | mempool_free(phba->sysfs_mbox.mbox, | |
3964 | phba->mbox_mem_pool); | |
3965 | phba->sysfs_mbox.mbox = NULL; | |
3966 | } | |
3967 | } | |
3968 | ||
e59058c4 | 3969 | /** |
3621a710 | 3970 | * sysfs_mbox_write - Write method for writing information via mbox |
2c3c8bea | 3971 | * @filp: open sysfs file |
e59058c4 JS |
3972 | * @kobj: kernel kobject that contains the kernel class device. |
3973 | * @bin_attr: kernel attributes passed to us. | |
3974 | * @buf: contains the data to be written to sysfs mbox. | |
3975 | * @off: offset into buffer to beginning of data. | |
3976 | * @count: bytes to transfer. | |
3977 | * | |
3978 | * Description: | |
3979 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | |
3980 | * Uses the sysfs mbox to send buf contents to the adapter. | |
3981 | * | |
3982 | * Returns: | |
3983 | * -ERANGE off and count combo out of range | |
3984 | * -EINVAL off, count or buff address invalid | |
3985 | * zero if count is zero | |
3986 | * -EPERM adapter is offline | |
3987 | * -ENOMEM failed to allocate memory for the mail box | |
3988 | * -EAGAIN offset, state or mbox is NULL | |
3989 | * count number of bytes transferred | |
3990 | **/ | |
dea3101e | 3991 | static ssize_t |
2c3c8bea CW |
3992 | sysfs_mbox_write(struct file *filp, struct kobject *kobj, |
3993 | struct bin_attribute *bin_attr, | |
91a69029 | 3994 | char *buf, loff_t off, size_t count) |
dea3101e | 3995 | { |
ee959b00 TJ |
3996 | struct device *dev = container_of(kobj, struct device, kobj); |
3997 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
3998 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3999 | struct lpfc_hba *phba = vport->phba; | |
4000 | struct lpfcMboxq *mbox = NULL; | |
dea3101e | 4001 | |
4002 | if ((count + off) > MAILBOX_CMD_SIZE) | |
4003 | return -ERANGE; | |
4004 | ||
4005 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
4006 | return -EINVAL; | |
4007 | ||
4008 | if (count == 0) | |
4009 | return 0; | |
4010 | ||
4011 | if (off == 0) { | |
4012 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4013 | if (!mbox) | |
4014 | return -ENOMEM; | |
fc6c12bc | 4015 | memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e | 4016 | } |
4017 | ||
2e0fef85 | 4018 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4019 | |
4020 | if (off == 0) { | |
4021 | if (phba->sysfs_mbox.mbox) | |
4022 | mempool_free(mbox, phba->mbox_mem_pool); | |
4023 | else | |
4024 | phba->sysfs_mbox.mbox = mbox; | |
4025 | phba->sysfs_mbox.state = SMBOX_WRITING; | |
4026 | } else { | |
4027 | if (phba->sysfs_mbox.state != SMBOX_WRITING || | |
4028 | phba->sysfs_mbox.offset != off || | |
92d7f7b0 | 4029 | phba->sysfs_mbox.mbox == NULL) { |
dea3101e | 4030 | sysfs_mbox_idle(phba); |
2e0fef85 | 4031 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 4032 | return -EAGAIN; |
dea3101e | 4033 | } |
4034 | } | |
4035 | ||
04c68496 | 4036 | memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off, |
dea3101e | 4037 | buf, count); |
4038 | ||
4039 | phba->sysfs_mbox.offset = off + count; | |
4040 | ||
2e0fef85 | 4041 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4042 | |
4043 | return count; | |
4044 | } | |
4045 | ||
e59058c4 | 4046 | /** |
3621a710 | 4047 | * sysfs_mbox_read - Read method for reading information via mbox |
2c3c8bea | 4048 | * @filp: open sysfs file |
e59058c4 JS |
4049 | * @kobj: kernel kobject that contains the kernel class device. |
4050 | * @bin_attr: kernel attributes passed to us. | |
4051 | * @buf: contains the data to be read from sysfs mbox. | |
4052 | * @off: offset into buffer to beginning of data. | |
4053 | * @count: bytes to transfer. | |
4054 | * | |
4055 | * Description: | |
4056 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | |
4057 | * Uses the sysfs mbox to receive data from to the adapter. | |
4058 | * | |
4059 | * Returns: | |
4060 | * -ERANGE off greater than mailbox command size | |
4061 | * -EINVAL off, count or buff address invalid | |
4062 | * zero if off and count are zero | |
4063 | * -EACCES adapter over temp | |
4064 | * -EPERM garbage can value to catch a multitude of errors | |
4065 | * -EAGAIN management IO not permitted, state or off error | |
4066 | * -ETIME mailbox timeout | |
4067 | * -ENODEV mailbox error | |
4068 | * count number of bytes transferred | |
4069 | **/ | |
dea3101e | 4070 | static ssize_t |
2c3c8bea CW |
4071 | sysfs_mbox_read(struct file *filp, struct kobject *kobj, |
4072 | struct bin_attribute *bin_attr, | |
91a69029 | 4073 | char *buf, loff_t off, size_t count) |
dea3101e | 4074 | { |
ee959b00 TJ |
4075 | struct device *dev = container_of(kobj, struct device, kobj); |
4076 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
4077 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4078 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4079 | int rc; |
04c68496 | 4080 | MAILBOX_t *pmb; |
dea3101e | 4081 | |
1dcb58e5 | 4082 | if (off > MAILBOX_CMD_SIZE) |
dea3101e | 4083 | return -ERANGE; |
4084 | ||
1dcb58e5 JS |
4085 | if ((count + off) > MAILBOX_CMD_SIZE) |
4086 | count = MAILBOX_CMD_SIZE - off; | |
dea3101e | 4087 | |
4088 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
4089 | return -EINVAL; | |
4090 | ||
4091 | if (off && count == 0) | |
4092 | return 0; | |
4093 | ||
2e0fef85 | 4094 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4095 | |
7af67051 JS |
4096 | if (phba->over_temp_state == HBA_OVER_TEMP) { |
4097 | sysfs_mbox_idle(phba); | |
4098 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 4099 | return -EACCES; |
7af67051 JS |
4100 | } |
4101 | ||
dea3101e | 4102 | if (off == 0 && |
4103 | phba->sysfs_mbox.state == SMBOX_WRITING && | |
4104 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { | |
04c68496 JS |
4105 | pmb = &phba->sysfs_mbox.mbox->u.mb; |
4106 | switch (pmb->mbxCommand) { | |
dea3101e | 4107 | /* Offline only */ |
dea3101e | 4108 | case MBX_INIT_LINK: |
4109 | case MBX_DOWN_LINK: | |
4110 | case MBX_CONFIG_LINK: | |
4111 | case MBX_CONFIG_RING: | |
4112 | case MBX_RESET_RING: | |
4113 | case MBX_UNREG_LOGIN: | |
4114 | case MBX_CLEAR_LA: | |
4115 | case MBX_DUMP_CONTEXT: | |
4116 | case MBX_RUN_DIAGS: | |
4117 | case MBX_RESTART: | |
dea3101e | 4118 | case MBX_SET_MASK: |
dea3101e | 4119 | case MBX_SET_DEBUG: |
2e0fef85 | 4120 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
dea3101e | 4121 | printk(KERN_WARNING "mbox_read:Command 0x%x " |
4122 | "is illegal in on-line state\n", | |
04c68496 | 4123 | pmb->mbxCommand); |
dea3101e | 4124 | sysfs_mbox_idle(phba); |
2e0fef85 | 4125 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4126 | return -EPERM; |
4127 | } | |
a8adb832 JS |
4128 | case MBX_WRITE_NV: |
4129 | case MBX_WRITE_VPARMS: | |
dea3101e | 4130 | case MBX_LOAD_SM: |
4131 | case MBX_READ_NV: | |
4132 | case MBX_READ_CONFIG: | |
4133 | case MBX_READ_RCONFIG: | |
4134 | case MBX_READ_STATUS: | |
4135 | case MBX_READ_XRI: | |
4136 | case MBX_READ_REV: | |
4137 | case MBX_READ_LNK_STAT: | |
4138 | case MBX_DUMP_MEMORY: | |
4139 | case MBX_DOWN_LOAD: | |
4140 | case MBX_UPDATE_CFG: | |
41415862 | 4141 | case MBX_KILL_BOARD: |
dea3101e | 4142 | case MBX_LOAD_AREA: |
4143 | case MBX_LOAD_EXP_ROM: | |
41415862 JW |
4144 | case MBX_BEACON: |
4145 | case MBX_DEL_LD_ENTRY: | |
09372820 JS |
4146 | case MBX_SET_VARIABLE: |
4147 | case MBX_WRITE_WWN: | |
84774a4d JS |
4148 | case MBX_PORT_CAPABILITIES: |
4149 | case MBX_PORT_IOV_CONTROL: | |
dea3101e | 4150 | break; |
dcf2a4e0 JS |
4151 | case MBX_SECURITY_MGMT: |
4152 | case MBX_AUTH_PORT: | |
5989b8d4 JS |
4153 | if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) { |
4154 | printk(KERN_WARNING "mbox_read:Command 0x%x " | |
4155 | "is not permitted\n", pmb->mbxCommand); | |
4156 | sysfs_mbox_idle(phba); | |
4157 | spin_unlock_irq(&phba->hbalock); | |
dcf2a4e0 | 4158 | return -EPERM; |
5989b8d4 | 4159 | } |
dcf2a4e0 | 4160 | break; |
dea3101e | 4161 | case MBX_READ_SPARM64: |
76a95d75 | 4162 | case MBX_READ_TOPOLOGY: |
dea3101e | 4163 | case MBX_REG_LOGIN: |
4164 | case MBX_REG_LOGIN64: | |
4165 | case MBX_CONFIG_PORT: | |
4166 | case MBX_RUN_BIU_DIAG: | |
4167 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", | |
04c68496 | 4168 | pmb->mbxCommand); |
dea3101e | 4169 | sysfs_mbox_idle(phba); |
2e0fef85 | 4170 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4171 | return -EPERM; |
4172 | default: | |
4173 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", | |
04c68496 | 4174 | pmb->mbxCommand); |
dea3101e | 4175 | sysfs_mbox_idle(phba); |
2e0fef85 | 4176 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4177 | return -EPERM; |
4178 | } | |
4179 | ||
09372820 | 4180 | /* If HBA encountered an error attention, allow only DUMP |
1b32f6aa | 4181 | * or RESTART mailbox commands until the HBA is restarted. |
09372820 | 4182 | */ |
d7c255b2 | 4183 | if (phba->pport->stopped && |
04c68496 JS |
4184 | pmb->mbxCommand != MBX_DUMP_MEMORY && |
4185 | pmb->mbxCommand != MBX_RESTART && | |
4186 | pmb->mbxCommand != MBX_WRITE_VPARMS && | |
4187 | pmb->mbxCommand != MBX_WRITE_WWN) | |
d7c255b2 JS |
4188 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
4189 | "1259 mbox: Issued mailbox cmd " | |
4190 | "0x%x while in stopped state.\n", | |
04c68496 | 4191 | pmb->mbxCommand); |
09372820 | 4192 | |
92d7f7b0 JS |
4193 | phba->sysfs_mbox.mbox->vport = vport; |
4194 | ||
58da1ffb JS |
4195 | /* Don't allow mailbox commands to be sent when blocked |
4196 | * or when in the middle of discovery | |
4197 | */ | |
495a714c | 4198 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { |
46fa311e | 4199 | sysfs_mbox_idle(phba); |
2e0fef85 | 4200 | spin_unlock_irq(&phba->hbalock); |
46fa311e JS |
4201 | return -EAGAIN; |
4202 | } | |
4203 | ||
2e0fef85 | 4204 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 4205 | (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) { |
dea3101e | 4206 | |
2e0fef85 | 4207 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4208 | rc = lpfc_sli_issue_mbox (phba, |
4209 | phba->sysfs_mbox.mbox, | |
4210 | MBX_POLL); | |
2e0fef85 | 4211 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4212 | |
4213 | } else { | |
2e0fef85 | 4214 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4215 | rc = lpfc_sli_issue_mbox_wait (phba, |
4216 | phba->sysfs_mbox.mbox, | |
04c68496 | 4217 | lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ); |
2e0fef85 | 4218 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4219 | } |
4220 | ||
4221 | if (rc != MBX_SUCCESS) { | |
1dcb58e5 | 4222 | if (rc == MBX_TIMEOUT) { |
1dcb58e5 JS |
4223 | phba->sysfs_mbox.mbox = NULL; |
4224 | } | |
dea3101e | 4225 | sysfs_mbox_idle(phba); |
2e0fef85 | 4226 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 4227 | return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
dea3101e | 4228 | } |
4229 | phba->sysfs_mbox.state = SMBOX_READING; | |
4230 | } | |
4231 | else if (phba->sysfs_mbox.offset != off || | |
4232 | phba->sysfs_mbox.state != SMBOX_READING) { | |
4233 | printk(KERN_WARNING "mbox_read: Bad State\n"); | |
4234 | sysfs_mbox_idle(phba); | |
2e0fef85 | 4235 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 4236 | return -EAGAIN; |
dea3101e | 4237 | } |
4238 | ||
04c68496 | 4239 | memcpy(buf, (uint8_t *) &pmb + off, count); |
dea3101e | 4240 | |
4241 | phba->sysfs_mbox.offset = off + count; | |
4242 | ||
1dcb58e5 | 4243 | if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) |
dea3101e | 4244 | sysfs_mbox_idle(phba); |
4245 | ||
2e0fef85 | 4246 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4247 | |
4248 | return count; | |
4249 | } | |
4250 | ||
4251 | static struct bin_attribute sysfs_mbox_attr = { | |
4252 | .attr = { | |
4253 | .name = "mbox", | |
4254 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 4255 | }, |
c0c11512 | 4256 | .size = MAILBOX_SYSFS_MAX, |
dea3101e | 4257 | .read = sysfs_mbox_read, |
4258 | .write = sysfs_mbox_write, | |
4259 | }; | |
4260 | ||
e59058c4 | 4261 | /** |
3621a710 | 4262 | * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries |
e59058c4 JS |
4263 | * @vport: address of lpfc vport structure. |
4264 | * | |
4265 | * Return codes: | |
4266 | * zero on success | |
4267 | * error return code from sysfs_create_bin_file() | |
4268 | **/ | |
dea3101e | 4269 | int |
2e0fef85 | 4270 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 4271 | { |
2e0fef85 | 4272 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 4273 | int error; |
4274 | ||
ee959b00 | 4275 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d JS |
4276 | &sysfs_drvr_stat_data_attr); |
4277 | ||
4278 | /* Virtual ports do not need ctrl_reg and mbox */ | |
4279 | if (error || vport->port_type == LPFC_NPIV_PORT) | |
dea3101e | 4280 | goto out; |
4281 | ||
ee959b00 | 4282 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 4283 | &sysfs_ctlreg_attr); |
dea3101e | 4284 | if (error) |
eada272d | 4285 | goto out_remove_stat_attr; |
dea3101e | 4286 | |
ea2151b4 | 4287 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 4288 | &sysfs_mbox_attr); |
ea2151b4 | 4289 | if (error) |
eada272d | 4290 | goto out_remove_ctlreg_attr; |
ea2151b4 | 4291 | |
dea3101e | 4292 | return 0; |
4293 | out_remove_ctlreg_attr: | |
ee959b00 | 4294 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); |
eada272d JS |
4295 | out_remove_stat_attr: |
4296 | sysfs_remove_bin_file(&shost->shost_dev.kobj, | |
4297 | &sysfs_drvr_stat_data_attr); | |
dea3101e | 4298 | out: |
4299 | return error; | |
4300 | } | |
4301 | ||
e59058c4 | 4302 | /** |
3621a710 | 4303 | * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries |
e59058c4 JS |
4304 | * @vport: address of lpfc vport structure. |
4305 | **/ | |
dea3101e | 4306 | void |
2e0fef85 | 4307 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 4308 | { |
2e0fef85 | 4309 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
ea2151b4 JS |
4310 | sysfs_remove_bin_file(&shost->shost_dev.kobj, |
4311 | &sysfs_drvr_stat_data_attr); | |
eada272d JS |
4312 | /* Virtual ports do not need ctrl_reg and mbox */ |
4313 | if (vport->port_type == LPFC_NPIV_PORT) | |
4314 | return; | |
ee959b00 TJ |
4315 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); |
4316 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | |
dea3101e | 4317 | } |
4318 | ||
4319 | ||
4320 | /* | |
4321 | * Dynamic FC Host Attributes Support | |
4322 | */ | |
4323 | ||
e59058c4 | 4324 | /** |
3621a710 | 4325 | * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id |
e59058c4 JS |
4326 | * @shost: kernel scsi host pointer. |
4327 | **/ | |
dea3101e | 4328 | static void |
4329 | lpfc_get_host_port_id(struct Scsi_Host *shost) | |
4330 | { | |
2e0fef85 JS |
4331 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4332 | ||
dea3101e | 4333 | /* note: fc_myDID already in cpu endianness */ |
2e0fef85 | 4334 | fc_host_port_id(shost) = vport->fc_myDID; |
dea3101e | 4335 | } |
4336 | ||
e59058c4 | 4337 | /** |
3621a710 | 4338 | * lpfc_get_host_port_type - Set the value of the scsi host port type |
e59058c4 JS |
4339 | * @shost: kernel scsi host pointer. |
4340 | **/ | |
dea3101e | 4341 | static void |
4342 | lpfc_get_host_port_type(struct Scsi_Host *shost) | |
4343 | { | |
2e0fef85 JS |
4344 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4345 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4346 | |
4347 | spin_lock_irq(shost->host_lock); | |
4348 | ||
92d7f7b0 JS |
4349 | if (vport->port_type == LPFC_NPIV_PORT) { |
4350 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
4351 | } else if (lpfc_is_link_up(phba)) { | |
76a95d75 | 4352 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 4353 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e | 4354 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
4355 | else | |
4356 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | |
4357 | } else { | |
2e0fef85 | 4358 | if (vport->fc_flag & FC_FABRIC) |
dea3101e | 4359 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
4360 | else | |
4361 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | |
4362 | } | |
4363 | } else | |
4364 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
4365 | ||
4366 | spin_unlock_irq(shost->host_lock); | |
4367 | } | |
4368 | ||
e59058c4 | 4369 | /** |
3621a710 | 4370 | * lpfc_get_host_port_state - Set the value of the scsi host port state |
e59058c4 JS |
4371 | * @shost: kernel scsi host pointer. |
4372 | **/ | |
dea3101e | 4373 | static void |
4374 | lpfc_get_host_port_state(struct Scsi_Host *shost) | |
4375 | { | |
2e0fef85 JS |
4376 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4377 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4378 | |
4379 | spin_lock_irq(shost->host_lock); | |
4380 | ||
2e0fef85 | 4381 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 4382 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
4383 | else { | |
2e0fef85 JS |
4384 | switch (phba->link_state) { |
4385 | case LPFC_LINK_UNKNOWN: | |
dea3101e | 4386 | case LPFC_LINK_DOWN: |
4387 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
4388 | break; | |
4389 | case LPFC_LINK_UP: | |
dea3101e | 4390 | case LPFC_CLEAR_LA: |
4391 | case LPFC_HBA_READY: | |
4392 | /* Links up, beyond this port_type reports state */ | |
4393 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
4394 | break; | |
4395 | case LPFC_HBA_ERROR: | |
4396 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
4397 | break; | |
4398 | default: | |
4399 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
4400 | break; | |
4401 | } | |
4402 | } | |
4403 | ||
4404 | spin_unlock_irq(shost->host_lock); | |
4405 | } | |
4406 | ||
e59058c4 | 4407 | /** |
3621a710 | 4408 | * lpfc_get_host_speed - Set the value of the scsi host speed |
e59058c4 JS |
4409 | * @shost: kernel scsi host pointer. |
4410 | **/ | |
dea3101e | 4411 | static void |
4412 | lpfc_get_host_speed(struct Scsi_Host *shost) | |
4413 | { | |
2e0fef85 JS |
4414 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4415 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 4416 | |
4417 | spin_lock_irq(shost->host_lock); | |
4418 | ||
2e0fef85 | 4419 | if (lpfc_is_link_up(phba)) { |
dea3101e | 4420 | switch(phba->fc_linkspeed) { |
76a95d75 JS |
4421 | case LPFC_LINK_SPEED_1GHZ: |
4422 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
dea3101e | 4423 | break; |
76a95d75 JS |
4424 | case LPFC_LINK_SPEED_2GHZ: |
4425 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
dea3101e | 4426 | break; |
76a95d75 JS |
4427 | case LPFC_LINK_SPEED_4GHZ: |
4428 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
dea3101e | 4429 | break; |
76a95d75 JS |
4430 | case LPFC_LINK_SPEED_8GHZ: |
4431 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | |
b87eab38 | 4432 | break; |
76a95d75 JS |
4433 | case LPFC_LINK_SPEED_10GHZ: |
4434 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | |
f4b4c68f | 4435 | break; |
76a95d75 JS |
4436 | case LPFC_LINK_SPEED_16GHZ: |
4437 | fc_host_speed(shost) = FC_PORTSPEED_16GBIT; | |
4438 | break; | |
4439 | default: | |
4440 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e | 4441 | break; |
4442 | } | |
09372820 JS |
4443 | } else |
4444 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e | 4445 | |
4446 | spin_unlock_irq(shost->host_lock); | |
4447 | } | |
4448 | ||
e59058c4 | 4449 | /** |
3621a710 | 4450 | * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name |
e59058c4 JS |
4451 | * @shost: kernel scsi host pointer. |
4452 | **/ | |
dea3101e | 4453 | static void |
4454 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |
4455 | { | |
2e0fef85 JS |
4456 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4457 | struct lpfc_hba *phba = vport->phba; | |
f631b4be | 4458 | u64 node_name; |
dea3101e | 4459 | |
4460 | spin_lock_irq(shost->host_lock); | |
4461 | ||
2e0fef85 | 4462 | if ((vport->fc_flag & FC_FABRIC) || |
76a95d75 | 4463 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && |
2e0fef85 | 4464 | (vport->fc_flag & FC_PUBLIC_LOOP))) |
68ce1eb5 | 4465 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
dea3101e | 4466 | else |
4467 | /* fabric is local port if there is no F/FL_Port */ | |
09372820 | 4468 | node_name = 0; |
dea3101e | 4469 | |
4470 | spin_unlock_irq(shost->host_lock); | |
4471 | ||
f631b4be | 4472 | fc_host_fabric_name(shost) = node_name; |
dea3101e | 4473 | } |
4474 | ||
e59058c4 | 4475 | /** |
3621a710 | 4476 | * lpfc_get_stats - Return statistical information about the adapter |
e59058c4 JS |
4477 | * @shost: kernel scsi host pointer. |
4478 | * | |
4479 | * Notes: | |
4480 | * NULL on error for link down, no mbox pool, sli2 active, | |
4481 | * management not allowed, memory allocation error, or mbox error. | |
4482 | * | |
4483 | * Returns: | |
4484 | * NULL for error | |
4485 | * address of the adapter host statistics | |
4486 | **/ | |
dea3101e | 4487 | static struct fc_host_statistics * |
4488 | lpfc_get_stats(struct Scsi_Host *shost) | |
4489 | { | |
2e0fef85 JS |
4490 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4491 | struct lpfc_hba *phba = vport->phba; | |
4492 | struct lpfc_sli *psli = &phba->sli; | |
f888ba3c | 4493 | struct fc_host_statistics *hs = &phba->link_stats; |
64ba8818 | 4494 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
dea3101e | 4495 | LPFC_MBOXQ_t *pmboxq; |
4496 | MAILBOX_t *pmb; | |
64ba8818 | 4497 | unsigned long seconds; |
433c3579 | 4498 | int rc = 0; |
dea3101e | 4499 | |
92d7f7b0 JS |
4500 | /* |
4501 | * prevent udev from issuing mailbox commands until the port is | |
4502 | * configured. | |
4503 | */ | |
2e0fef85 JS |
4504 | if (phba->link_state < LPFC_LINK_DOWN || |
4505 | !phba->mbox_mem_pool || | |
f4b4c68f | 4506 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 | 4507 | return NULL; |
2e0fef85 JS |
4508 | |
4509 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
46fa311e JS |
4510 | return NULL; |
4511 | ||
dea3101e | 4512 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4513 | if (!pmboxq) | |
4514 | return NULL; | |
4515 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
4516 | ||
04c68496 | 4517 | pmb = &pmboxq->u.mb; |
dea3101e | 4518 | pmb->mbxCommand = MBX_READ_STATUS; |
4519 | pmb->mbxOwner = OWN_HOST; | |
4520 | pmboxq->context1 = NULL; | |
92d7f7b0 | 4521 | pmboxq->vport = vport; |
dea3101e | 4522 | |
75baf696 | 4523 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 4524 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 4525 | else |
dea3101e | 4526 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
4527 | ||
4528 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 4529 | if (rc != MBX_TIMEOUT) |
433c3579 | 4530 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 4531 | return NULL; |
4532 | } | |
4533 | ||
f888ba3c JSEC |
4534 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
4535 | ||
dea3101e | 4536 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
4537 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); | |
4538 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; | |
4539 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); | |
4540 | ||
433c3579 | 4541 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e | 4542 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
4543 | pmb->mbxOwner = OWN_HOST; | |
4544 | pmboxq->context1 = NULL; | |
92d7f7b0 | 4545 | pmboxq->vport = vport; |
dea3101e | 4546 | |
75baf696 | 4547 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 4548 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 4549 | else |
dea3101e | 4550 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
4551 | ||
4552 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 4553 | if (rc != MBX_TIMEOUT) |
92d7f7b0 | 4554 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 4555 | return NULL; |
4556 | } | |
4557 | ||
4558 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
4559 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
4560 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
4561 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
4562 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
4563 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
4564 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | |
4565 | ||
64ba8818 JS |
4566 | hs->link_failure_count -= lso->link_failure_count; |
4567 | hs->loss_of_sync_count -= lso->loss_of_sync_count; | |
4568 | hs->loss_of_signal_count -= lso->loss_of_signal_count; | |
4569 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; | |
4570 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; | |
4571 | hs->invalid_crc_count -= lso->invalid_crc_count; | |
4572 | hs->error_frames -= lso->error_frames; | |
4573 | ||
76a95d75 | 4574 | if (phba->hba_flag & HBA_FCOE_MODE) { |
4d9ab994 JS |
4575 | hs->lip_count = -1; |
4576 | hs->nos_count = (phba->link_events >> 1); | |
4577 | hs->nos_count -= lso->link_events; | |
76a95d75 | 4578 | } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
dea3101e | 4579 | hs->lip_count = (phba->fc_eventTag >> 1); |
64ba8818 | 4580 | hs->lip_count -= lso->link_events; |
dea3101e | 4581 | hs->nos_count = -1; |
4582 | } else { | |
4583 | hs->lip_count = -1; | |
4584 | hs->nos_count = (phba->fc_eventTag >> 1); | |
64ba8818 | 4585 | hs->nos_count -= lso->link_events; |
dea3101e | 4586 | } |
4587 | ||
4588 | hs->dumped_frames = -1; | |
4589 | ||
64ba8818 JS |
4590 | seconds = get_seconds(); |
4591 | if (seconds < psli->stats_start) | |
4592 | hs->seconds_since_last_reset = seconds + | |
4593 | ((unsigned long)-1 - psli->stats_start); | |
4594 | else | |
4595 | hs->seconds_since_last_reset = seconds - psli->stats_start; | |
dea3101e | 4596 | |
1dcb58e5 JS |
4597 | mempool_free(pmboxq, phba->mbox_mem_pool); |
4598 | ||
dea3101e | 4599 | return hs; |
4600 | } | |
4601 | ||
e59058c4 | 4602 | /** |
3621a710 | 4603 | * lpfc_reset_stats - Copy the adapter link stats information |
e59058c4 JS |
4604 | * @shost: kernel scsi host pointer. |
4605 | **/ | |
64ba8818 JS |
4606 | static void |
4607 | lpfc_reset_stats(struct Scsi_Host *shost) | |
4608 | { | |
2e0fef85 JS |
4609 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
4610 | struct lpfc_hba *phba = vport->phba; | |
4611 | struct lpfc_sli *psli = &phba->sli; | |
4612 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; | |
64ba8818 JS |
4613 | LPFC_MBOXQ_t *pmboxq; |
4614 | MAILBOX_t *pmb; | |
4615 | int rc = 0; | |
4616 | ||
2e0fef85 | 4617 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
46fa311e JS |
4618 | return; |
4619 | ||
64ba8818 JS |
4620 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4621 | if (!pmboxq) | |
4622 | return; | |
4623 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
4624 | ||
04c68496 | 4625 | pmb = &pmboxq->u.mb; |
64ba8818 JS |
4626 | pmb->mbxCommand = MBX_READ_STATUS; |
4627 | pmb->mbxOwner = OWN_HOST; | |
4628 | pmb->un.varWords[0] = 0x1; /* reset request */ | |
4629 | pmboxq->context1 = NULL; | |
92d7f7b0 | 4630 | pmboxq->vport = vport; |
64ba8818 | 4631 | |
2e0fef85 | 4632 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 4633 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
4634 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
4635 | else | |
4636 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
4637 | ||
4638 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 4639 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
4640 | mempool_free(pmboxq, phba->mbox_mem_pool); |
4641 | return; | |
4642 | } | |
4643 | ||
4644 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
4645 | pmb->mbxCommand = MBX_READ_LNK_STAT; | |
4646 | pmb->mbxOwner = OWN_HOST; | |
4647 | pmboxq->context1 = NULL; | |
92d7f7b0 | 4648 | pmboxq->vport = vport; |
64ba8818 | 4649 | |
2e0fef85 | 4650 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 4651 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
4652 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
4653 | else | |
4654 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
4655 | ||
4656 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 4657 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
4658 | mempool_free( pmboxq, phba->mbox_mem_pool); |
4659 | return; | |
4660 | } | |
4661 | ||
4662 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
4663 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
4664 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
4665 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
4666 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
4667 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
4668 | lso->error_frames = pmb->un.varRdLnk.crcCnt; | |
76a95d75 | 4669 | if (phba->hba_flag & HBA_FCOE_MODE) |
4d9ab994 JS |
4670 | lso->link_events = (phba->link_events >> 1); |
4671 | else | |
4672 | lso->link_events = (phba->fc_eventTag >> 1); | |
64ba8818 JS |
4673 | |
4674 | psli->stats_start = get_seconds(); | |
4675 | ||
1dcb58e5 JS |
4676 | mempool_free(pmboxq, phba->mbox_mem_pool); |
4677 | ||
64ba8818 JS |
4678 | return; |
4679 | } | |
dea3101e | 4680 | |
4681 | /* | |
4682 | * The LPFC driver treats linkdown handling as target loss events so there | |
4683 | * are no sysfs handlers for link_down_tmo. | |
4684 | */ | |
685f0bf7 | 4685 | |
e59058c4 | 4686 | /** |
3621a710 | 4687 | * lpfc_get_node_by_target - Return the nodelist for a target |
e59058c4 JS |
4688 | * @starget: kernel scsi target pointer. |
4689 | * | |
4690 | * Returns: | |
4691 | * address of the node list if found | |
4692 | * NULL target not found | |
4693 | **/ | |
685f0bf7 JS |
4694 | static struct lpfc_nodelist * |
4695 | lpfc_get_node_by_target(struct scsi_target *starget) | |
dea3101e | 4696 | { |
2e0fef85 JS |
4697 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
4698 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
685f0bf7 | 4699 | struct lpfc_nodelist *ndlp; |
dea3101e | 4700 | |
4701 | spin_lock_irq(shost->host_lock); | |
685f0bf7 | 4702 | /* Search for this, mapped, target ID */ |
2e0fef85 | 4703 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
4704 | if (NLP_CHK_NODE_ACT(ndlp) && |
4705 | ndlp->nlp_state == NLP_STE_MAPPED_NODE && | |
685f0bf7 JS |
4706 | starget->id == ndlp->nlp_sid) { |
4707 | spin_unlock_irq(shost->host_lock); | |
4708 | return ndlp; | |
dea3101e | 4709 | } |
4710 | } | |
4711 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 JS |
4712 | return NULL; |
4713 | } | |
dea3101e | 4714 | |
e59058c4 | 4715 | /** |
3621a710 | 4716 | * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1 |
e59058c4 JS |
4717 | * @starget: kernel scsi target pointer. |
4718 | **/ | |
685f0bf7 JS |
4719 | static void |
4720 | lpfc_get_starget_port_id(struct scsi_target *starget) | |
4721 | { | |
4722 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | |
4723 | ||
4724 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; | |
dea3101e | 4725 | } |
4726 | ||
e59058c4 | 4727 | /** |
3621a710 | 4728 | * lpfc_get_starget_node_name - Set the target node name |
e59058c4 JS |
4729 | * @starget: kernel scsi target pointer. |
4730 | * | |
4731 | * Description: Set the target node name to the ndlp node name wwn or zero. | |
4732 | **/ | |
dea3101e | 4733 | static void |
4734 | lpfc_get_starget_node_name(struct scsi_target *starget) | |
4735 | { | |
685f0bf7 | 4736 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 4737 | |
685f0bf7 JS |
4738 | fc_starget_node_name(starget) = |
4739 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; | |
dea3101e | 4740 | } |
4741 | ||
e59058c4 | 4742 | /** |
3621a710 | 4743 | * lpfc_get_starget_port_name - Set the target port name |
e59058c4 JS |
4744 | * @starget: kernel scsi target pointer. |
4745 | * | |
4746 | * Description: set the target port name to the ndlp port name wwn or zero. | |
4747 | **/ | |
dea3101e | 4748 | static void |
4749 | lpfc_get_starget_port_name(struct scsi_target *starget) | |
4750 | { | |
685f0bf7 | 4751 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 4752 | |
685f0bf7 JS |
4753 | fc_starget_port_name(starget) = |
4754 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; | |
dea3101e | 4755 | } |
4756 | ||
e59058c4 | 4757 | /** |
3621a710 | 4758 | * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo |
e59058c4 JS |
4759 | * @rport: fc rport address. |
4760 | * @timeout: new value for dev loss tmo. | |
4761 | * | |
4762 | * Description: | |
4763 | * If timeout is non zero set the dev_loss_tmo to timeout, else set | |
4764 | * dev_loss_tmo to one. | |
4765 | **/ | |
dea3101e | 4766 | static void |
4767 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
4768 | { | |
dea3101e | 4769 | if (timeout) |
c01f3208 | 4770 | rport->dev_loss_tmo = timeout; |
dea3101e | 4771 | else |
c01f3208 | 4772 | rport->dev_loss_tmo = 1; |
dea3101e | 4773 | } |
4774 | ||
e59058c4 | 4775 | /** |
3621a710 | 4776 | * lpfc_rport_show_function - Return rport target information |
e59058c4 JS |
4777 | * |
4778 | * Description: | |
4779 | * Macro that uses field to generate a function with the name lpfc_show_rport_ | |
4780 | * | |
4781 | * lpfc_show_rport_##field: returns the bytes formatted in buf | |
4782 | * @cdev: class converted to an fc_rport. | |
4783 | * @buf: on return contains the target_field or zero. | |
4784 | * | |
4785 | * Returns: size of formatted string. | |
4786 | **/ | |
dea3101e | 4787 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
4788 | static ssize_t \ | |
ee959b00 TJ |
4789 | lpfc_show_rport_##field (struct device *dev, \ |
4790 | struct device_attribute *attr, \ | |
4791 | char *buf) \ | |
dea3101e | 4792 | { \ |
ee959b00 | 4793 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
dea3101e | 4794 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
4795 | return snprintf(buf, sz, format_string, \ | |
4796 | (rdata->target) ? cast rdata->target->field : 0); \ | |
4797 | } | |
4798 | ||
4799 | #define lpfc_rport_rd_attr(field, format_string, sz) \ | |
4800 | lpfc_rport_show_function(field, format_string, sz, ) \ | |
4801 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | |
4802 | ||
eada272d | 4803 | /** |
3621a710 | 4804 | * lpfc_set_vport_symbolic_name - Set the vport's symbolic name |
eada272d JS |
4805 | * @fc_vport: The fc_vport who's symbolic name has been changed. |
4806 | * | |
4807 | * Description: | |
4808 | * This function is called by the transport after the @fc_vport's symbolic name | |
4809 | * has been changed. This function re-registers the symbolic name with the | |
25985edc | 4810 | * switch to propagate the change into the fabric if the vport is active. |
eada272d JS |
4811 | **/ |
4812 | static void | |
4813 | lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport) | |
4814 | { | |
4815 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; | |
4816 | ||
4817 | if (vport->port_state == LPFC_VPORT_READY) | |
4818 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); | |
4819 | } | |
dea3101e | 4820 | |
f4b4c68f JS |
4821 | /** |
4822 | * lpfc_hba_log_verbose_init - Set hba's log verbose level | |
4823 | * @phba: Pointer to lpfc_hba struct. | |
4824 | * | |
4825 | * This function is called by the lpfc_get_cfgparam() routine to set the | |
4826 | * module lpfc_log_verbose into the @phba cfg_log_verbose for use with | |
70f23fd6 | 4827 | * log message according to the module's lpfc_log_verbose parameter setting |
f4b4c68f JS |
4828 | * before hba port or vport created. |
4829 | **/ | |
4830 | static void | |
4831 | lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose) | |
4832 | { | |
4833 | phba->cfg_log_verbose = verbose; | |
4834 | } | |
4835 | ||
dea3101e | 4836 | struct fc_function_template lpfc_transport_functions = { |
4837 | /* fixed attributes the driver supports */ | |
4838 | .show_host_node_name = 1, | |
4839 | .show_host_port_name = 1, | |
4840 | .show_host_supported_classes = 1, | |
4841 | .show_host_supported_fc4s = 1, | |
dea3101e | 4842 | .show_host_supported_speeds = 1, |
4843 | .show_host_maxframe_size = 1, | |
eada272d | 4844 | .show_host_symbolic_name = 1, |
dea3101e | 4845 | |
4846 | /* dynamic attributes the driver supports */ | |
4847 | .get_host_port_id = lpfc_get_host_port_id, | |
4848 | .show_host_port_id = 1, | |
4849 | ||
4850 | .get_host_port_type = lpfc_get_host_port_type, | |
4851 | .show_host_port_type = 1, | |
4852 | ||
4853 | .get_host_port_state = lpfc_get_host_port_state, | |
4854 | .show_host_port_state = 1, | |
4855 | ||
4856 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
4857 | .show_host_active_fc4s = 1, | |
4858 | ||
4859 | .get_host_speed = lpfc_get_host_speed, | |
4860 | .show_host_speed = 1, | |
4861 | ||
4862 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
4863 | .show_host_fabric_name = 1, | |
4864 | ||
4865 | /* | |
4866 | * The LPFC driver treats linkdown handling as target loss events | |
4867 | * so there are no sysfs handlers for link_down_tmo. | |
4868 | */ | |
4869 | ||
4870 | .get_fc_host_stats = lpfc_get_stats, | |
64ba8818 | 4871 | .reset_fc_host_stats = lpfc_reset_stats, |
dea3101e | 4872 | |
4873 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
4874 | .show_rport_maxframe_size = 1, | |
4875 | .show_rport_supported_classes = 1, | |
4876 | ||
dea3101e | 4877 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
4878 | .show_rport_dev_loss_tmo = 1, | |
4879 | ||
4880 | .get_starget_port_id = lpfc_get_starget_port_id, | |
4881 | .show_starget_port_id = 1, | |
4882 | ||
4883 | .get_starget_node_name = lpfc_get_starget_node_name, | |
4884 | .show_starget_node_name = 1, | |
4885 | ||
4886 | .get_starget_port_name = lpfc_get_starget_port_name, | |
4887 | .show_starget_port_name = 1, | |
91ca7b01 AV |
4888 | |
4889 | .issue_fc_host_lip = lpfc_issue_lip, | |
c01f3208 JS |
4890 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
4891 | .terminate_rport_io = lpfc_terminate_rport_io, | |
92d7f7b0 | 4892 | |
92d7f7b0 | 4893 | .dd_fcvport_size = sizeof(struct lpfc_vport *), |
eada272d JS |
4894 | |
4895 | .vport_disable = lpfc_vport_disable, | |
4896 | ||
4897 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
f1c3b0fc JS |
4898 | |
4899 | .bsg_request = lpfc_bsg_request, | |
4900 | .bsg_timeout = lpfc_bsg_timeout, | |
92d7f7b0 JS |
4901 | }; |
4902 | ||
98c9ea5c JS |
4903 | struct fc_function_template lpfc_vport_transport_functions = { |
4904 | /* fixed attributes the driver supports */ | |
4905 | .show_host_node_name = 1, | |
4906 | .show_host_port_name = 1, | |
4907 | .show_host_supported_classes = 1, | |
4908 | .show_host_supported_fc4s = 1, | |
4909 | .show_host_supported_speeds = 1, | |
4910 | .show_host_maxframe_size = 1, | |
eada272d | 4911 | .show_host_symbolic_name = 1, |
98c9ea5c JS |
4912 | |
4913 | /* dynamic attributes the driver supports */ | |
4914 | .get_host_port_id = lpfc_get_host_port_id, | |
4915 | .show_host_port_id = 1, | |
4916 | ||
4917 | .get_host_port_type = lpfc_get_host_port_type, | |
4918 | .show_host_port_type = 1, | |
4919 | ||
4920 | .get_host_port_state = lpfc_get_host_port_state, | |
4921 | .show_host_port_state = 1, | |
4922 | ||
4923 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
4924 | .show_host_active_fc4s = 1, | |
4925 | ||
4926 | .get_host_speed = lpfc_get_host_speed, | |
4927 | .show_host_speed = 1, | |
4928 | ||
4929 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
4930 | .show_host_fabric_name = 1, | |
4931 | ||
4932 | /* | |
4933 | * The LPFC driver treats linkdown handling as target loss events | |
4934 | * so there are no sysfs handlers for link_down_tmo. | |
4935 | */ | |
4936 | ||
4937 | .get_fc_host_stats = lpfc_get_stats, | |
4938 | .reset_fc_host_stats = lpfc_reset_stats, | |
4939 | ||
4940 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
4941 | .show_rport_maxframe_size = 1, | |
4942 | .show_rport_supported_classes = 1, | |
4943 | ||
4944 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | |
4945 | .show_rport_dev_loss_tmo = 1, | |
4946 | ||
4947 | .get_starget_port_id = lpfc_get_starget_port_id, | |
4948 | .show_starget_port_id = 1, | |
4949 | ||
4950 | .get_starget_node_name = lpfc_get_starget_node_name, | |
4951 | .show_starget_node_name = 1, | |
4952 | ||
4953 | .get_starget_port_name = lpfc_get_starget_port_name, | |
4954 | .show_starget_port_name = 1, | |
4955 | ||
4956 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | |
4957 | .terminate_rport_io = lpfc_terminate_rport_io, | |
4958 | ||
4959 | .vport_disable = lpfc_vport_disable, | |
eada272d JS |
4960 | |
4961 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
98c9ea5c JS |
4962 | }; |
4963 | ||
e59058c4 | 4964 | /** |
3621a710 | 4965 | * lpfc_get_cfgparam - Used during probe_one to init the adapter structure |
e59058c4 JS |
4966 | * @phba: lpfc_hba pointer. |
4967 | **/ | |
dea3101e | 4968 | void |
4969 | lpfc_get_cfgparam(struct lpfc_hba *phba) | |
4970 | { | |
7bcbb752 JSEC |
4971 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
4972 | lpfc_cr_count_init(phba, lpfc_cr_count); | |
cf5bf97e | 4973 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
a4bc3379 JS |
4974 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); |
4975 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); | |
7bcbb752 JSEC |
4976 | lpfc_ack0_init(phba, lpfc_ack0); |
4977 | lpfc_topology_init(phba, lpfc_topology); | |
7bcbb752 | 4978 | lpfc_link_speed_init(phba, lpfc_link_speed); |
875fbdfe | 4979 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
78b2d852 | 4980 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); |
19ca7609 | 4981 | lpfc_enable_rrq_init(phba, lpfc_enable_rrq); |
4ff43246 | 4982 | lpfc_use_msi_init(phba, lpfc_use_msi); |
da0436e9 JS |
4983 | lpfc_fcp_imax_init(phba, lpfc_fcp_imax); |
4984 | lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count); | |
4985 | lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count); | |
13815c83 JS |
4986 | lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); |
4987 | lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); | |
81301a9b | 4988 | lpfc_enable_bg_init(phba, lpfc_enable_bg); |
45ed1190 JS |
4989 | if (phba->sli_rev == LPFC_SLI_REV4) |
4990 | phba->cfg_poll = 0; | |
4991 | else | |
875fbdfe | 4992 | phba->cfg_poll = lpfc_poll; |
a12e07bc | 4993 | phba->cfg_soft_wwnn = 0L; |
c3f28afa | 4994 | phba->cfg_soft_wwpn = 0L; |
83108bd3 | 4995 | lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); |
81301a9b | 4996 | lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt); |
7054a606 | 4997 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
6fb120a7 | 4998 | lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); |
0d878419 | 4999 | lpfc_aer_support_init(phba, lpfc_aer_support); |
912e3acd | 5000 | lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn); |
84d1b006 | 5001 | lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); |
2a9bf3d0 | 5002 | lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); |
ab56dc2e | 5003 | phba->cfg_enable_dss = 1; |
3de2a653 JS |
5004 | return; |
5005 | } | |
b28485ac | 5006 | |
e59058c4 | 5007 | /** |
3621a710 | 5008 | * lpfc_get_vport_cfgparam - Used during port create, init the vport structure |
e59058c4 JS |
5009 | * @vport: lpfc_vport pointer. |
5010 | **/ | |
3de2a653 JS |
5011 | void |
5012 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) | |
5013 | { | |
e8b62011 | 5014 | lpfc_log_verbose_init(vport, lpfc_log_verbose); |
3de2a653 | 5015 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); |
7dc517df | 5016 | lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth); |
3de2a653 JS |
5017 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); |
5018 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); | |
5019 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); | |
5020 | lpfc_restrict_login_init(vport, lpfc_restrict_login); | |
5021 | lpfc_fcp_class_init(vport, lpfc_fcp_class); | |
5022 | lpfc_use_adisc_init(vport, lpfc_use_adisc); | |
977b5a0a | 5023 | lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); |
3de2a653 JS |
5024 | lpfc_fdmi_on_init(vport, lpfc_fdmi_on); |
5025 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); | |
5026 | lpfc_max_luns_init(vport, lpfc_max_luns); | |
5027 | lpfc_scan_down_init(vport, lpfc_scan_down); | |
7ee5d43e | 5028 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); |
dea3101e | 5029 | return; |
5030 | } |