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