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