qla_attr.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. static int qla24xx_vport_disable(struct fc_vport *, bool);
  12. /* SYSFS attributes --------------------------------------------------------- */
  13. static ssize_t
  14. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  15. struct bin_attribute *bin_attr,
  16. char *buf, loff_t off, size_t count)
  17. {
  18. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  19. struct device, kobj)));
  20. struct qla_hw_data *ha = vha->hw;
  21. if (ha->fw_dump_reading == 0)
  22. return 0;
  23. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  24. ha->fw_dump_len);
  25. }
  26. static ssize_t
  27. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  28. struct bin_attribute *bin_attr,
  29. char *buf, loff_t off, size_t count)
  30. {
  31. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  32. struct device, kobj)));
  33. struct qla_hw_data *ha = vha->hw;
  34. int reading;
  35. if (off != 0)
  36. return (0);
  37. reading = simple_strtol(buf, NULL, 10);
  38. switch (reading) {
  39. case 0:
  40. if (!ha->fw_dump_reading)
  41. break;
  42. qla_printk(KERN_INFO, ha,
  43. "Firmware dump cleared on (%ld).\n", vha->host_no);
  44. ha->fw_dump_reading = 0;
  45. ha->fw_dumped = 0;
  46. break;
  47. case 1:
  48. if (ha->fw_dumped && !ha->fw_dump_reading) {
  49. ha->fw_dump_reading = 1;
  50. qla_printk(KERN_INFO, ha,
  51. "Raw firmware dump ready for read on (%ld).\n",
  52. vha->host_no);
  53. }
  54. break;
  55. case 2:
  56. qla2x00_alloc_fw_dump(vha);
  57. break;
  58. case 3:
  59. qla2x00_system_error(vha);
  60. break;
  61. }
  62. return (count);
  63. }
  64. static struct bin_attribute sysfs_fw_dump_attr = {
  65. .attr = {
  66. .name = "fw_dump",
  67. .mode = S_IRUSR | S_IWUSR,
  68. },
  69. .size = 0,
  70. .read = qla2x00_sysfs_read_fw_dump,
  71. .write = qla2x00_sysfs_write_fw_dump,
  72. };
  73. static ssize_t
  74. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  75. struct bin_attribute *bin_attr,
  76. char *buf, loff_t off, size_t count)
  77. {
  78. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  79. struct device, kobj)));
  80. struct qla_hw_data *ha = vha->hw;
  81. if (!capable(CAP_SYS_ADMIN))
  82. return 0;
  83. if (IS_NOCACHE_VPD_TYPE(ha))
  84. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_nvram << 2,
  85. ha->nvram_size);
  86. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  87. ha->nvram_size);
  88. }
  89. static ssize_t
  90. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  91. struct bin_attribute *bin_attr,
  92. char *buf, loff_t off, size_t count)
  93. {
  94. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  95. struct device, kobj)));
  96. struct qla_hw_data *ha = vha->hw;
  97. uint16_t cnt;
  98. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  99. !ha->isp_ops->write_nvram)
  100. return 0;
  101. /* Checksum NVRAM. */
  102. if (IS_FWI2_CAPABLE(ha)) {
  103. uint32_t *iter;
  104. uint32_t chksum;
  105. iter = (uint32_t *)buf;
  106. chksum = 0;
  107. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  108. chksum += le32_to_cpu(*iter++);
  109. chksum = ~chksum + 1;
  110. *iter = cpu_to_le32(chksum);
  111. } else {
  112. uint8_t *iter;
  113. uint8_t chksum;
  114. iter = (uint8_t *)buf;
  115. chksum = 0;
  116. for (cnt = 0; cnt < count - 1; cnt++)
  117. chksum += *iter++;
  118. chksum = ~chksum + 1;
  119. *iter = chksum;
  120. }
  121. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  122. qla_printk(KERN_WARNING, ha,
  123. "HBA not online, failing NVRAM update.\n");
  124. return -EAGAIN;
  125. }
  126. /* Write NVRAM. */
  127. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  128. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  129. count);
  130. /* NVRAM settings take effect immediately. */
  131. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  132. qla2xxx_wake_dpc(vha);
  133. qla2x00_wait_for_chip_reset(vha);
  134. return (count);
  135. }
  136. static struct bin_attribute sysfs_nvram_attr = {
  137. .attr = {
  138. .name = "nvram",
  139. .mode = S_IRUSR | S_IWUSR,
  140. },
  141. .size = 512,
  142. .read = qla2x00_sysfs_read_nvram,
  143. .write = qla2x00_sysfs_write_nvram,
  144. };
  145. static ssize_t
  146. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  147. struct bin_attribute *bin_attr,
  148. char *buf, loff_t off, size_t count)
  149. {
  150. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  151. struct device, kobj)));
  152. struct qla_hw_data *ha = vha->hw;
  153. if (ha->optrom_state != QLA_SREADING)
  154. return 0;
  155. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  156. ha->optrom_region_size);
  157. }
  158. static ssize_t
  159. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  160. struct bin_attribute *bin_attr,
  161. char *buf, loff_t off, size_t count)
  162. {
  163. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  164. struct device, kobj)));
  165. struct qla_hw_data *ha = vha->hw;
  166. if (ha->optrom_state != QLA_SWRITING)
  167. return -EINVAL;
  168. if (off > ha->optrom_region_size)
  169. return -ERANGE;
  170. if (off + count > ha->optrom_region_size)
  171. count = ha->optrom_region_size - off;
  172. memcpy(&ha->optrom_buffer[off], buf, count);
  173. return count;
  174. }
  175. static struct bin_attribute sysfs_optrom_attr = {
  176. .attr = {
  177. .name = "optrom",
  178. .mode = S_IRUSR | S_IWUSR,
  179. },
  180. .size = 0,
  181. .read = qla2x00_sysfs_read_optrom,
  182. .write = qla2x00_sysfs_write_optrom,
  183. };
  184. static ssize_t
  185. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  186. struct bin_attribute *bin_attr,
  187. char *buf, loff_t off, size_t count)
  188. {
  189. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  190. struct device, kobj)));
  191. struct qla_hw_data *ha = vha->hw;
  192. uint32_t start = 0;
  193. uint32_t size = ha->optrom_size;
  194. int val, valid;
  195. if (off)
  196. return 0;
  197. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  198. return -EINVAL;
  199. if (start > ha->optrom_size)
  200. return -EINVAL;
  201. switch (val) {
  202. case 0:
  203. if (ha->optrom_state != QLA_SREADING &&
  204. ha->optrom_state != QLA_SWRITING)
  205. break;
  206. ha->optrom_state = QLA_SWAITING;
  207. DEBUG2(qla_printk(KERN_INFO, ha,
  208. "Freeing flash region allocation -- 0x%x bytes.\n",
  209. ha->optrom_region_size));
  210. vfree(ha->optrom_buffer);
  211. ha->optrom_buffer = NULL;
  212. break;
  213. case 1:
  214. if (ha->optrom_state != QLA_SWAITING)
  215. break;
  216. ha->optrom_region_start = start;
  217. ha->optrom_region_size = start + size > ha->optrom_size ?
  218. ha->optrom_size - start : size;
  219. ha->optrom_state = QLA_SREADING;
  220. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  221. if (ha->optrom_buffer == NULL) {
  222. qla_printk(KERN_WARNING, ha,
  223. "Unable to allocate memory for optrom retrieval "
  224. "(%x).\n", ha->optrom_region_size);
  225. ha->optrom_state = QLA_SWAITING;
  226. return count;
  227. }
  228. DEBUG2(qla_printk(KERN_INFO, ha,
  229. "Reading flash region -- 0x%x/0x%x.\n",
  230. ha->optrom_region_start, ha->optrom_region_size));
  231. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  232. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  233. ha->optrom_region_start, ha->optrom_region_size);
  234. break;
  235. case 2:
  236. if (ha->optrom_state != QLA_SWAITING)
  237. break;
  238. /*
  239. * We need to be more restrictive on which FLASH regions are
  240. * allowed to be updated via user-space. Regions accessible
  241. * via this method include:
  242. *
  243. * ISP21xx/ISP22xx/ISP23xx type boards:
  244. *
  245. * 0x000000 -> 0x020000 -- Boot code.
  246. *
  247. * ISP2322/ISP24xx type boards:
  248. *
  249. * 0x000000 -> 0x07ffff -- Boot code.
  250. * 0x080000 -> 0x0fffff -- Firmware.
  251. *
  252. * ISP25xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  257. */
  258. valid = 0;
  259. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  260. valid = 1;
  261. else if (start == (ha->flt_region_boot * 4) ||
  262. start == (ha->flt_region_fw * 4))
  263. valid = 1;
  264. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  265. valid = 1;
  266. if (!valid) {
  267. qla_printk(KERN_WARNING, ha,
  268. "Invalid start region 0x%x/0x%x.\n", start, size);
  269. return -EINVAL;
  270. }
  271. ha->optrom_region_start = start;
  272. ha->optrom_region_size = start + size > ha->optrom_size ?
  273. ha->optrom_size - start : size;
  274. ha->optrom_state = QLA_SWRITING;
  275. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  276. if (ha->optrom_buffer == NULL) {
  277. qla_printk(KERN_WARNING, ha,
  278. "Unable to allocate memory for optrom update "
  279. "(%x).\n", ha->optrom_region_size);
  280. ha->optrom_state = QLA_SWAITING;
  281. return count;
  282. }
  283. DEBUG2(qla_printk(KERN_INFO, ha,
  284. "Staging flash region write -- 0x%x/0x%x.\n",
  285. ha->optrom_region_start, ha->optrom_region_size));
  286. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  287. break;
  288. case 3:
  289. if (ha->optrom_state != QLA_SWRITING)
  290. break;
  291. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  292. qla_printk(KERN_WARNING, ha,
  293. "HBA not online, failing flash update.\n");
  294. return -EAGAIN;
  295. }
  296. DEBUG2(qla_printk(KERN_INFO, ha,
  297. "Writing flash region -- 0x%x/0x%x.\n",
  298. ha->optrom_region_start, ha->optrom_region_size));
  299. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  300. ha->optrom_region_start, ha->optrom_region_size);
  301. break;
  302. default:
  303. count = -EINVAL;
  304. }
  305. return count;
  306. }
  307. static struct bin_attribute sysfs_optrom_ctl_attr = {
  308. .attr = {
  309. .name = "optrom_ctl",
  310. .mode = S_IWUSR,
  311. },
  312. .size = 0,
  313. .write = qla2x00_sysfs_write_optrom_ctl,
  314. };
  315. static ssize_t
  316. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  317. struct bin_attribute *bin_attr,
  318. char *buf, loff_t off, size_t count)
  319. {
  320. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  321. struct device, kobj)));
  322. struct qla_hw_data *ha = vha->hw;
  323. if (!capable(CAP_SYS_ADMIN))
  324. return 0;
  325. if (IS_NOCACHE_VPD_TYPE(ha))
  326. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  327. ha->vpd_size);
  328. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  329. }
  330. static ssize_t
  331. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  332. struct bin_attribute *bin_attr,
  333. char *buf, loff_t off, size_t count)
  334. {
  335. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  336. struct device, kobj)));
  337. struct qla_hw_data *ha = vha->hw;
  338. uint8_t *tmp_data;
  339. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  340. !ha->isp_ops->write_nvram)
  341. return 0;
  342. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  343. qla_printk(KERN_WARNING, ha,
  344. "HBA not online, failing VPD update.\n");
  345. return -EAGAIN;
  346. }
  347. /* Write NVRAM. */
  348. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  349. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  350. /* Update flash version information for 4Gb & above. */
  351. if (!IS_FWI2_CAPABLE(ha))
  352. goto done;
  353. tmp_data = vmalloc(256);
  354. if (!tmp_data) {
  355. qla_printk(KERN_WARNING, ha,
  356. "Unable to allocate memory for VPD information update.\n");
  357. goto done;
  358. }
  359. ha->isp_ops->get_flash_version(vha, tmp_data);
  360. vfree(tmp_data);
  361. done:
  362. return count;
  363. }
  364. static struct bin_attribute sysfs_vpd_attr = {
  365. .attr = {
  366. .name = "vpd",
  367. .mode = S_IRUSR | S_IWUSR,
  368. },
  369. .size = 0,
  370. .read = qla2x00_sysfs_read_vpd,
  371. .write = qla2x00_sysfs_write_vpd,
  372. };
  373. static ssize_t
  374. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  375. struct bin_attribute *bin_attr,
  376. char *buf, loff_t off, size_t count)
  377. {
  378. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  379. struct device, kobj)));
  380. struct qla_hw_data *ha = vha->hw;
  381. uint16_t iter, addr, offset;
  382. int rval;
  383. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  384. return 0;
  385. if (ha->sfp_data)
  386. goto do_read;
  387. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  388. &ha->sfp_data_dma);
  389. if (!ha->sfp_data) {
  390. qla_printk(KERN_WARNING, ha,
  391. "Unable to allocate memory for SFP read-data.\n");
  392. return 0;
  393. }
  394. do_read:
  395. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  396. addr = 0xa0;
  397. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  398. iter++, offset += SFP_BLOCK_SIZE) {
  399. if (iter == 4) {
  400. /* Skip to next device address. */
  401. addr = 0xa2;
  402. offset = 0;
  403. }
  404. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  405. SFP_BLOCK_SIZE);
  406. if (rval != QLA_SUCCESS) {
  407. qla_printk(KERN_WARNING, ha,
  408. "Unable to read SFP data (%x/%x/%x).\n", rval,
  409. addr, offset);
  410. count = 0;
  411. break;
  412. }
  413. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  414. buf += SFP_BLOCK_SIZE;
  415. }
  416. return count;
  417. }
  418. static struct bin_attribute sysfs_sfp_attr = {
  419. .attr = {
  420. .name = "sfp",
  421. .mode = S_IRUSR | S_IWUSR,
  422. },
  423. .size = SFP_DEV_SIZE * 2,
  424. .read = qla2x00_sysfs_read_sfp,
  425. };
  426. static ssize_t
  427. qla2x00_sysfs_write_reset(struct kobject *kobj,
  428. struct bin_attribute *bin_attr,
  429. char *buf, loff_t off, size_t count)
  430. {
  431. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  432. struct device, kobj)));
  433. struct qla_hw_data *ha = vha->hw;
  434. int type;
  435. if (off != 0)
  436. return 0;
  437. type = simple_strtol(buf, NULL, 10);
  438. switch (type) {
  439. case 0x2025c:
  440. qla_printk(KERN_INFO, ha,
  441. "Issuing ISP reset on (%ld).\n", vha->host_no);
  442. scsi_block_requests(vha->host);
  443. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  444. qla2xxx_wake_dpc(vha);
  445. qla2x00_wait_for_chip_reset(vha);
  446. scsi_unblock_requests(vha->host);
  447. break;
  448. case 0x2025d:
  449. if (!IS_QLA81XX(ha))
  450. break;
  451. qla_printk(KERN_INFO, ha,
  452. "Issuing MPI reset on (%ld).\n", vha->host_no);
  453. /* Make sure FC side is not in reset */
  454. qla2x00_wait_for_hba_online(vha);
  455. /* Issue MPI reset */
  456. scsi_block_requests(vha->host);
  457. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  458. qla_printk(KERN_WARNING, ha,
  459. "MPI reset failed on (%ld).\n", vha->host_no);
  460. scsi_unblock_requests(vha->host);
  461. break;
  462. }
  463. return count;
  464. }
  465. static struct bin_attribute sysfs_reset_attr = {
  466. .attr = {
  467. .name = "reset",
  468. .mode = S_IWUSR,
  469. },
  470. .size = 0,
  471. .write = qla2x00_sysfs_write_reset,
  472. };
  473. static ssize_t
  474. qla2x00_sysfs_write_edc(struct kobject *kobj,
  475. struct bin_attribute *bin_attr,
  476. char *buf, loff_t off, size_t count)
  477. {
  478. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  479. struct device, kobj)));
  480. struct qla_hw_data *ha = vha->hw;
  481. uint16_t dev, adr, opt, len;
  482. int rval;
  483. ha->edc_data_len = 0;
  484. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  485. return 0;
  486. if (!ha->edc_data) {
  487. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  488. &ha->edc_data_dma);
  489. if (!ha->edc_data) {
  490. DEBUG2(qla_printk(KERN_INFO, ha,
  491. "Unable to allocate memory for EDC write.\n"));
  492. return 0;
  493. }
  494. }
  495. dev = le16_to_cpup((void *)&buf[0]);
  496. adr = le16_to_cpup((void *)&buf[2]);
  497. opt = le16_to_cpup((void *)&buf[4]);
  498. len = le16_to_cpup((void *)&buf[6]);
  499. if (!(opt & BIT_0))
  500. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  501. return -EINVAL;
  502. memcpy(ha->edc_data, &buf[8], len);
  503. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  504. ha->edc_data, len, opt);
  505. if (rval != QLA_SUCCESS) {
  506. DEBUG2(qla_printk(KERN_INFO, ha,
  507. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  508. rval, dev, adr, opt, len, *buf));
  509. return 0;
  510. }
  511. return count;
  512. }
  513. static struct bin_attribute sysfs_edc_attr = {
  514. .attr = {
  515. .name = "edc",
  516. .mode = S_IWUSR,
  517. },
  518. .size = 0,
  519. .write = qla2x00_sysfs_write_edc,
  520. };
  521. static ssize_t
  522. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  523. struct bin_attribute *bin_attr,
  524. char *buf, loff_t off, size_t count)
  525. {
  526. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  527. struct device, kobj)));
  528. struct qla_hw_data *ha = vha->hw;
  529. uint16_t dev, adr, opt, len;
  530. int rval;
  531. ha->edc_data_len = 0;
  532. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  533. return 0;
  534. if (!ha->edc_data) {
  535. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  536. &ha->edc_data_dma);
  537. if (!ha->edc_data) {
  538. DEBUG2(qla_printk(KERN_INFO, ha,
  539. "Unable to allocate memory for EDC status.\n"));
  540. return 0;
  541. }
  542. }
  543. dev = le16_to_cpup((void *)&buf[0]);
  544. adr = le16_to_cpup((void *)&buf[2]);
  545. opt = le16_to_cpup((void *)&buf[4]);
  546. len = le16_to_cpup((void *)&buf[6]);
  547. if (!(opt & BIT_0))
  548. if (len == 0 || len > DMA_POOL_SIZE)
  549. return -EINVAL;
  550. memset(ha->edc_data, 0, len);
  551. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  552. ha->edc_data, len, opt);
  553. if (rval != QLA_SUCCESS) {
  554. DEBUG2(qla_printk(KERN_INFO, ha,
  555. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  556. rval, dev, adr, opt, len));
  557. return 0;
  558. }
  559. ha->edc_data_len = len;
  560. return count;
  561. }
  562. static ssize_t
  563. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  564. struct bin_attribute *bin_attr,
  565. char *buf, loff_t off, size_t count)
  566. {
  567. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  568. struct device, kobj)));
  569. struct qla_hw_data *ha = vha->hw;
  570. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  571. return 0;
  572. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  573. return -EINVAL;
  574. memcpy(buf, ha->edc_data, ha->edc_data_len);
  575. return ha->edc_data_len;
  576. }
  577. static struct bin_attribute sysfs_edc_status_attr = {
  578. .attr = {
  579. .name = "edc_status",
  580. .mode = S_IRUSR | S_IWUSR,
  581. },
  582. .size = 0,
  583. .write = qla2x00_sysfs_write_edc_status,
  584. .read = qla2x00_sysfs_read_edc_status,
  585. };
  586. static struct sysfs_entry {
  587. char *name;
  588. struct bin_attribute *attr;
  589. int is4GBp_only;
  590. } bin_file_entries[] = {
  591. { "fw_dump", &sysfs_fw_dump_attr, },
  592. { "nvram", &sysfs_nvram_attr, },
  593. { "optrom", &sysfs_optrom_attr, },
  594. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  595. { "vpd", &sysfs_vpd_attr, 1 },
  596. { "sfp", &sysfs_sfp_attr, 1 },
  597. { "reset", &sysfs_reset_attr, },
  598. { "edc", &sysfs_edc_attr, 2 },
  599. { "edc_status", &sysfs_edc_status_attr, 2 },
  600. { NULL },
  601. };
  602. void
  603. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  604. {
  605. struct Scsi_Host *host = vha->host;
  606. struct sysfs_entry *iter;
  607. int ret;
  608. for (iter = bin_file_entries; iter->name; iter++) {
  609. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  610. continue;
  611. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  612. continue;
  613. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  614. iter->attr);
  615. if (ret)
  616. qla_printk(KERN_INFO, vha->hw,
  617. "Unable to create sysfs %s binary attribute "
  618. "(%d).\n", iter->name, ret);
  619. }
  620. }
  621. void
  622. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  623. {
  624. struct Scsi_Host *host = vha->host;
  625. struct sysfs_entry *iter;
  626. struct qla_hw_data *ha = vha->hw;
  627. for (iter = bin_file_entries; iter->name; iter++) {
  628. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  629. continue;
  630. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  631. continue;
  632. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  633. iter->attr);
  634. }
  635. if (ha->beacon_blink_led == 1)
  636. ha->isp_ops->beacon_off(vha);
  637. }
  638. /* Scsi_Host attributes. */
  639. static ssize_t
  640. qla2x00_drvr_version_show(struct device *dev,
  641. struct device_attribute *attr, char *buf)
  642. {
  643. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  644. }
  645. static ssize_t
  646. qla2x00_fw_version_show(struct device *dev,
  647. struct device_attribute *attr, char *buf)
  648. {
  649. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  650. struct qla_hw_data *ha = vha->hw;
  651. char fw_str[128];
  652. return snprintf(buf, PAGE_SIZE, "%s\n",
  653. ha->isp_ops->fw_version_str(vha, fw_str));
  654. }
  655. static ssize_t
  656. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  657. char *buf)
  658. {
  659. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  660. struct qla_hw_data *ha = vha->hw;
  661. uint32_t sn;
  662. if (IS_FWI2_CAPABLE(ha)) {
  663. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  664. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  665. }
  666. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  667. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  668. sn % 100000);
  669. }
  670. static ssize_t
  671. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  672. char *buf)
  673. {
  674. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  675. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  676. }
  677. static ssize_t
  678. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  679. char *buf)
  680. {
  681. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  682. struct qla_hw_data *ha = vha->hw;
  683. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  684. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  685. ha->product_id[3]);
  686. }
  687. static ssize_t
  688. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  689. char *buf)
  690. {
  691. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  692. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  693. }
  694. static ssize_t
  695. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  696. char *buf)
  697. {
  698. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  699. return snprintf(buf, PAGE_SIZE, "%s\n",
  700. vha->hw->model_desc ? vha->hw->model_desc : "");
  701. }
  702. static ssize_t
  703. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  704. char *buf)
  705. {
  706. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  707. char pci_info[30];
  708. return snprintf(buf, PAGE_SIZE, "%s\n",
  709. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  710. }
  711. static ssize_t
  712. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  713. char *buf)
  714. {
  715. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  716. struct qla_hw_data *ha = vha->hw;
  717. int len = 0;
  718. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  719. atomic_read(&vha->loop_state) == LOOP_DEAD)
  720. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  721. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  722. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  723. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  724. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  725. else {
  726. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  727. switch (ha->current_topology) {
  728. case ISP_CFG_NL:
  729. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  730. break;
  731. case ISP_CFG_FL:
  732. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  733. break;
  734. case ISP_CFG_N:
  735. len += snprintf(buf + len, PAGE_SIZE-len,
  736. "N_Port to N_Port\n");
  737. break;
  738. case ISP_CFG_F:
  739. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  740. break;
  741. default:
  742. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  743. break;
  744. }
  745. }
  746. return len;
  747. }
  748. static ssize_t
  749. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  750. char *buf)
  751. {
  752. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  753. int len = 0;
  754. switch (vha->hw->zio_mode) {
  755. case QLA_ZIO_MODE_6:
  756. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  757. break;
  758. case QLA_ZIO_DISABLED:
  759. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  760. break;
  761. }
  762. return len;
  763. }
  764. static ssize_t
  765. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  766. const char *buf, size_t count)
  767. {
  768. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  769. struct qla_hw_data *ha = vha->hw;
  770. int val = 0;
  771. uint16_t zio_mode;
  772. if (!IS_ZIO_SUPPORTED(ha))
  773. return -ENOTSUPP;
  774. if (sscanf(buf, "%d", &val) != 1)
  775. return -EINVAL;
  776. if (val)
  777. zio_mode = QLA_ZIO_MODE_6;
  778. else
  779. zio_mode = QLA_ZIO_DISABLED;
  780. /* Update per-hba values and queue a reset. */
  781. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  782. ha->zio_mode = zio_mode;
  783. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  784. }
  785. return strlen(buf);
  786. }
  787. static ssize_t
  788. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  793. }
  794. static ssize_t
  795. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  796. const char *buf, size_t count)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. int val = 0;
  800. uint16_t zio_timer;
  801. if (sscanf(buf, "%d", &val) != 1)
  802. return -EINVAL;
  803. if (val > 25500 || val < 100)
  804. return -ERANGE;
  805. zio_timer = (uint16_t)(val / 100);
  806. vha->hw->zio_timer = zio_timer;
  807. return strlen(buf);
  808. }
  809. static ssize_t
  810. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  811. char *buf)
  812. {
  813. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  814. int len = 0;
  815. if (vha->hw->beacon_blink_led)
  816. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  817. else
  818. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  819. return len;
  820. }
  821. static ssize_t
  822. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  823. const char *buf, size_t count)
  824. {
  825. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  826. struct qla_hw_data *ha = vha->hw;
  827. int val = 0;
  828. int rval;
  829. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  830. return -EPERM;
  831. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  832. qla_printk(KERN_WARNING, ha,
  833. "Abort ISP active -- ignoring beacon request.\n");
  834. return -EBUSY;
  835. }
  836. if (sscanf(buf, "%d", &val) != 1)
  837. return -EINVAL;
  838. if (val)
  839. rval = ha->isp_ops->beacon_on(vha);
  840. else
  841. rval = ha->isp_ops->beacon_off(vha);
  842. if (rval != QLA_SUCCESS)
  843. count = 0;
  844. return count;
  845. }
  846. static ssize_t
  847. qla2x00_optrom_bios_version_show(struct device *dev,
  848. struct device_attribute *attr, char *buf)
  849. {
  850. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  851. struct qla_hw_data *ha = vha->hw;
  852. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  853. ha->bios_revision[0]);
  854. }
  855. static ssize_t
  856. qla2x00_optrom_efi_version_show(struct device *dev,
  857. struct device_attribute *attr, char *buf)
  858. {
  859. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  860. struct qla_hw_data *ha = vha->hw;
  861. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  862. ha->efi_revision[0]);
  863. }
  864. static ssize_t
  865. qla2x00_optrom_fcode_version_show(struct device *dev,
  866. struct device_attribute *attr, char *buf)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  871. ha->fcode_revision[0]);
  872. }
  873. static ssize_t
  874. qla2x00_optrom_fw_version_show(struct device *dev,
  875. struct device_attribute *attr, char *buf)
  876. {
  877. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  878. struct qla_hw_data *ha = vha->hw;
  879. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  880. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  881. ha->fw_revision[3]);
  882. }
  883. static ssize_t
  884. qla2x00_total_isp_aborts_show(struct device *dev,
  885. struct device_attribute *attr, char *buf)
  886. {
  887. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  888. struct qla_hw_data *ha = vha->hw;
  889. return snprintf(buf, PAGE_SIZE, "%d\n",
  890. ha->qla_stats.total_isp_aborts);
  891. }
  892. static ssize_t
  893. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  894. char *buf)
  895. {
  896. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  897. struct qla_hw_data *ha = vha->hw;
  898. if (!IS_QLA81XX(ha))
  899. return snprintf(buf, PAGE_SIZE, "\n");
  900. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  901. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  902. ha->mpi_capabilities);
  903. }
  904. static ssize_t
  905. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  906. char *buf)
  907. {
  908. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  909. struct qla_hw_data *ha = vha->hw;
  910. if (!IS_QLA81XX(ha))
  911. return snprintf(buf, PAGE_SIZE, "\n");
  912. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  913. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  914. }
  915. static ssize_t
  916. qla2x00_flash_block_size_show(struct device *dev,
  917. struct device_attribute *attr, char *buf)
  918. {
  919. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  920. struct qla_hw_data *ha = vha->hw;
  921. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  922. }
  923. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  924. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  925. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  926. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  927. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  928. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  929. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  930. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  931. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  932. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  933. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  934. qla2x00_zio_timer_store);
  935. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  936. qla2x00_beacon_store);
  937. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  938. qla2x00_optrom_bios_version_show, NULL);
  939. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  940. qla2x00_optrom_efi_version_show, NULL);
  941. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  942. qla2x00_optrom_fcode_version_show, NULL);
  943. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  944. NULL);
  945. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  946. NULL);
  947. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  948. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  949. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  950. NULL);
  951. struct device_attribute *qla2x00_host_attrs[] = {
  952. &dev_attr_driver_version,
  953. &dev_attr_fw_version,
  954. &dev_attr_serial_num,
  955. &dev_attr_isp_name,
  956. &dev_attr_isp_id,
  957. &dev_attr_model_name,
  958. &dev_attr_model_desc,
  959. &dev_attr_pci_info,
  960. &dev_attr_link_state,
  961. &dev_attr_zio,
  962. &dev_attr_zio_timer,
  963. &dev_attr_beacon,
  964. &dev_attr_optrom_bios_version,
  965. &dev_attr_optrom_efi_version,
  966. &dev_attr_optrom_fcode_version,
  967. &dev_attr_optrom_fw_version,
  968. &dev_attr_total_isp_aborts,
  969. &dev_attr_mpi_version,
  970. &dev_attr_phy_version,
  971. &dev_attr_flash_block_size,
  972. NULL,
  973. };
  974. /* Host attributes. */
  975. static void
  976. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(shost);
  979. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  980. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  981. }
  982. static void
  983. qla2x00_get_host_speed(struct Scsi_Host *shost)
  984. {
  985. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  986. (shost_priv(shost)))->hw;
  987. u32 speed = FC_PORTSPEED_UNKNOWN;
  988. switch (ha->link_data_rate) {
  989. case PORT_SPEED_1GB:
  990. speed = FC_PORTSPEED_1GBIT;
  991. break;
  992. case PORT_SPEED_2GB:
  993. speed = FC_PORTSPEED_2GBIT;
  994. break;
  995. case PORT_SPEED_4GB:
  996. speed = FC_PORTSPEED_4GBIT;
  997. break;
  998. case PORT_SPEED_8GB:
  999. speed = FC_PORTSPEED_8GBIT;
  1000. break;
  1001. case PORT_SPEED_10GB:
  1002. speed = FC_PORTSPEED_10GBIT;
  1003. break;
  1004. }
  1005. fc_host_speed(shost) = speed;
  1006. }
  1007. static void
  1008. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1009. {
  1010. scsi_qla_host_t *vha = shost_priv(shost);
  1011. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1012. if (vha->vp_idx) {
  1013. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1014. return;
  1015. }
  1016. switch (vha->hw->current_topology) {
  1017. case ISP_CFG_NL:
  1018. port_type = FC_PORTTYPE_LPORT;
  1019. break;
  1020. case ISP_CFG_FL:
  1021. port_type = FC_PORTTYPE_NLPORT;
  1022. break;
  1023. case ISP_CFG_N:
  1024. port_type = FC_PORTTYPE_PTP;
  1025. break;
  1026. case ISP_CFG_F:
  1027. port_type = FC_PORTTYPE_NPORT;
  1028. break;
  1029. }
  1030. fc_host_port_type(shost) = port_type;
  1031. }
  1032. static void
  1033. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1034. {
  1035. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1036. scsi_qla_host_t *vha = shost_priv(host);
  1037. fc_port_t *fcport;
  1038. u64 node_name = 0;
  1039. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1040. if (fcport->rport &&
  1041. starget->id == fcport->rport->scsi_target_id) {
  1042. node_name = wwn_to_u64(fcport->node_name);
  1043. break;
  1044. }
  1045. }
  1046. fc_starget_node_name(starget) = node_name;
  1047. }
  1048. static void
  1049. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1050. {
  1051. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1052. scsi_qla_host_t *vha = shost_priv(host);
  1053. fc_port_t *fcport;
  1054. u64 port_name = 0;
  1055. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1056. if (fcport->rport &&
  1057. starget->id == fcport->rport->scsi_target_id) {
  1058. port_name = wwn_to_u64(fcport->port_name);
  1059. break;
  1060. }
  1061. }
  1062. fc_starget_port_name(starget) = port_name;
  1063. }
  1064. static void
  1065. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1066. {
  1067. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1068. scsi_qla_host_t *vha = shost_priv(host);
  1069. fc_port_t *fcport;
  1070. uint32_t port_id = ~0U;
  1071. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1072. if (fcport->rport &&
  1073. starget->id == fcport->rport->scsi_target_id) {
  1074. port_id = fcport->d_id.b.domain << 16 |
  1075. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1076. break;
  1077. }
  1078. }
  1079. fc_starget_port_id(starget) = port_id;
  1080. }
  1081. static void
  1082. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1083. {
  1084. if (timeout)
  1085. rport->dev_loss_tmo = timeout;
  1086. else
  1087. rport->dev_loss_tmo = 1;
  1088. }
  1089. static void
  1090. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1091. {
  1092. struct Scsi_Host *host = rport_to_shost(rport);
  1093. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1094. if (!fcport)
  1095. return;
  1096. qla2x00_abort_fcport_cmds(fcport);
  1097. /*
  1098. * Transport has effectively 'deleted' the rport, clear
  1099. * all local references.
  1100. */
  1101. spin_lock_irq(host->host_lock);
  1102. fcport->rport = NULL;
  1103. *((fc_port_t **)rport->dd_data) = NULL;
  1104. spin_unlock_irq(host->host_lock);
  1105. }
  1106. static void
  1107. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1108. {
  1109. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1110. if (!fcport)
  1111. return;
  1112. /*
  1113. * At this point all fcport's software-states are cleared. Perform any
  1114. * final cleanup of firmware resources (PCBs and XCBs).
  1115. */
  1116. if (fcport->loop_id != FC_NO_LOOP_ID)
  1117. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1118. fcport->loop_id, fcport->d_id.b.domain,
  1119. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1120. qla2x00_abort_fcport_cmds(fcport);
  1121. }
  1122. static int
  1123. qla2x00_issue_lip(struct Scsi_Host *shost)
  1124. {
  1125. scsi_qla_host_t *vha = shost_priv(shost);
  1126. qla2x00_loop_reset(vha);
  1127. return 0;
  1128. }
  1129. static struct fc_host_statistics *
  1130. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1131. {
  1132. scsi_qla_host_t *vha = shost_priv(shost);
  1133. struct qla_hw_data *ha = vha->hw;
  1134. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1135. int rval;
  1136. struct link_statistics *stats;
  1137. dma_addr_t stats_dma;
  1138. struct fc_host_statistics *pfc_host_stat;
  1139. pfc_host_stat = &ha->fc_host_stat;
  1140. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1141. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1142. if (stats == NULL) {
  1143. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1144. __func__, base_vha->host_no));
  1145. goto done;
  1146. }
  1147. memset(stats, 0, DMA_POOL_SIZE);
  1148. rval = QLA_FUNCTION_FAILED;
  1149. if (IS_FWI2_CAPABLE(ha)) {
  1150. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1151. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1152. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1153. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1154. !ha->dpc_active) {
  1155. /* Must be in a 'READY' state for statistics retrieval. */
  1156. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1157. stats, stats_dma);
  1158. }
  1159. if (rval != QLA_SUCCESS)
  1160. goto done_free;
  1161. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1162. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1163. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1164. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1165. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1166. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1167. if (IS_FWI2_CAPABLE(ha)) {
  1168. pfc_host_stat->lip_count = stats->lip_cnt;
  1169. pfc_host_stat->tx_frames = stats->tx_frames;
  1170. pfc_host_stat->rx_frames = stats->rx_frames;
  1171. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1172. pfc_host_stat->nos_count = stats->nos_rcvd;
  1173. }
  1174. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1175. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1176. done_free:
  1177. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1178. done:
  1179. return pfc_host_stat;
  1180. }
  1181. static void
  1182. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1183. {
  1184. scsi_qla_host_t *vha = shost_priv(shost);
  1185. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1186. }
  1187. static void
  1188. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1189. {
  1190. scsi_qla_host_t *vha = shost_priv(shost);
  1191. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1192. }
  1193. static void
  1194. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1195. {
  1196. scsi_qla_host_t *vha = shost_priv(shost);
  1197. u64 node_name;
  1198. if (vha->device_flags & SWITCH_FOUND)
  1199. node_name = wwn_to_u64(vha->fabric_node_name);
  1200. else
  1201. node_name = wwn_to_u64(vha->node_name);
  1202. fc_host_fabric_name(shost) = node_name;
  1203. }
  1204. static void
  1205. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1206. {
  1207. scsi_qla_host_t *vha = shost_priv(shost);
  1208. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1209. if (!base_vha->flags.online)
  1210. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1211. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1212. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1213. else
  1214. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1215. }
  1216. static int
  1217. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1218. {
  1219. int ret = 0;
  1220. int cnt = 0;
  1221. uint8_t qos = QLA_DEFAULT_QUE_QOS;
  1222. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1223. scsi_qla_host_t *vha = NULL;
  1224. struct qla_hw_data *ha = base_vha->hw;
  1225. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1226. if (ret) {
  1227. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1228. "status %x\n", ret));
  1229. return (ret);
  1230. }
  1231. vha = qla24xx_create_vhost(fc_vport);
  1232. if (vha == NULL) {
  1233. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1234. vha));
  1235. return FC_VPORT_FAILED;
  1236. }
  1237. if (disable) {
  1238. atomic_set(&vha->vp_state, VP_OFFLINE);
  1239. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1240. } else
  1241. atomic_set(&vha->vp_state, VP_FAILED);
  1242. /* ready to create vport */
  1243. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1244. vha->vp_idx);
  1245. /* initialized vport states */
  1246. atomic_set(&vha->loop_state, LOOP_DOWN);
  1247. vha->vp_err_state= VP_ERR_PORTDWN;
  1248. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1249. /* Check if physical ha port is Up */
  1250. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1251. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1252. /* Don't retry or attempt login of this virtual port */
  1253. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1254. base_vha->host_no));
  1255. atomic_set(&vha->loop_state, LOOP_DEAD);
  1256. if (!disable)
  1257. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1258. }
  1259. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  1260. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1261. vha->host_no, vha->vp_idx));
  1262. goto vport_create_failed_2;
  1263. }
  1264. /* initialize attributes */
  1265. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1266. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1267. fc_host_supported_classes(vha->host) =
  1268. fc_host_supported_classes(base_vha->host);
  1269. fc_host_supported_speeds(vha->host) =
  1270. fc_host_supported_speeds(base_vha->host);
  1271. qla24xx_vport_disable(fc_vport, disable);
  1272. /* Create a queue pair for the vport */
  1273. if (ha->mqenable) {
  1274. if (ha->npiv_info) {
  1275. for (; cnt < ha->nvram_npiv_size; cnt++) {
  1276. if (ha->npiv_info[cnt].port_name ==
  1277. vha->port_name &&
  1278. ha->npiv_info[cnt].node_name ==
  1279. vha->node_name) {
  1280. qos = ha->npiv_info[cnt].q_qos;
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. qla25xx_create_queues(vha, qos);
  1286. }
  1287. return 0;
  1288. vport_create_failed_2:
  1289. qla24xx_disable_vp(vha);
  1290. qla24xx_deallocate_vp_id(vha);
  1291. scsi_host_put(vha->host);
  1292. return FC_VPORT_FAILED;
  1293. }
  1294. static int
  1295. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1296. {
  1297. scsi_qla_host_t *vha = fc_vport->dd_data;
  1298. fc_port_t *fcport, *tfcport;
  1299. struct qla_hw_data *ha = vha->hw;
  1300. uint16_t id = vha->vp_idx;
  1301. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1302. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1303. msleep(1000);
  1304. qla24xx_disable_vp(vha);
  1305. fc_remove_host(vha->host);
  1306. scsi_remove_host(vha->host);
  1307. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1308. list_del(&fcport->list);
  1309. kfree(fcport);
  1310. fcport = NULL;
  1311. }
  1312. qla24xx_deallocate_vp_id(vha);
  1313. if (vha->timer_active) {
  1314. qla2x00_vp_stop_timer(vha);
  1315. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1316. "has stopped\n",
  1317. vha->host_no, vha->vp_idx, vha));
  1318. }
  1319. if (ha->mqenable) {
  1320. if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
  1321. qla_printk(KERN_WARNING, ha,
  1322. "Queue delete failed.\n");
  1323. }
  1324. scsi_host_put(vha->host);
  1325. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1326. return 0;
  1327. }
  1328. static int
  1329. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1330. {
  1331. scsi_qla_host_t *vha = fc_vport->dd_data;
  1332. if (disable)
  1333. qla24xx_disable_vp(vha);
  1334. else
  1335. qla24xx_enable_vp(vha);
  1336. return 0;
  1337. }
  1338. struct fc_function_template qla2xxx_transport_functions = {
  1339. .show_host_node_name = 1,
  1340. .show_host_port_name = 1,
  1341. .show_host_supported_classes = 1,
  1342. .show_host_supported_speeds = 1,
  1343. .get_host_port_id = qla2x00_get_host_port_id,
  1344. .show_host_port_id = 1,
  1345. .get_host_speed = qla2x00_get_host_speed,
  1346. .show_host_speed = 1,
  1347. .get_host_port_type = qla2x00_get_host_port_type,
  1348. .show_host_port_type = 1,
  1349. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1350. .show_host_symbolic_name = 1,
  1351. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1352. .show_host_system_hostname = 1,
  1353. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1354. .show_host_fabric_name = 1,
  1355. .get_host_port_state = qla2x00_get_host_port_state,
  1356. .show_host_port_state = 1,
  1357. .dd_fcrport_size = sizeof(struct fc_port *),
  1358. .show_rport_supported_classes = 1,
  1359. .get_starget_node_name = qla2x00_get_starget_node_name,
  1360. .show_starget_node_name = 1,
  1361. .get_starget_port_name = qla2x00_get_starget_port_name,
  1362. .show_starget_port_name = 1,
  1363. .get_starget_port_id = qla2x00_get_starget_port_id,
  1364. .show_starget_port_id = 1,
  1365. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1366. .show_rport_dev_loss_tmo = 1,
  1367. .issue_fc_host_lip = qla2x00_issue_lip,
  1368. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1369. .terminate_rport_io = qla2x00_terminate_rport_io,
  1370. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1371. .vport_create = qla24xx_vport_create,
  1372. .vport_disable = qla24xx_vport_disable,
  1373. .vport_delete = qla24xx_vport_delete,
  1374. };
  1375. struct fc_function_template qla2xxx_transport_vport_functions = {
  1376. .show_host_node_name = 1,
  1377. .show_host_port_name = 1,
  1378. .show_host_supported_classes = 1,
  1379. .get_host_port_id = qla2x00_get_host_port_id,
  1380. .show_host_port_id = 1,
  1381. .get_host_speed = qla2x00_get_host_speed,
  1382. .show_host_speed = 1,
  1383. .get_host_port_type = qla2x00_get_host_port_type,
  1384. .show_host_port_type = 1,
  1385. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1386. .show_host_symbolic_name = 1,
  1387. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1388. .show_host_system_hostname = 1,
  1389. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1390. .show_host_fabric_name = 1,
  1391. .get_host_port_state = qla2x00_get_host_port_state,
  1392. .show_host_port_state = 1,
  1393. .dd_fcrport_size = sizeof(struct fc_port *),
  1394. .show_rport_supported_classes = 1,
  1395. .get_starget_node_name = qla2x00_get_starget_node_name,
  1396. .show_starget_node_name = 1,
  1397. .get_starget_port_name = qla2x00_get_starget_port_name,
  1398. .show_starget_port_name = 1,
  1399. .get_starget_port_id = qla2x00_get_starget_port_id,
  1400. .show_starget_port_id = 1,
  1401. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1402. .show_rport_dev_loss_tmo = 1,
  1403. .issue_fc_host_lip = qla2x00_issue_lip,
  1404. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1405. .terminate_rport_io = qla2x00_terminate_rport_io,
  1406. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1407. };
  1408. void
  1409. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1410. {
  1411. struct qla_hw_data *ha = vha->hw;
  1412. u32 speed = FC_PORTSPEED_UNKNOWN;
  1413. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1414. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1415. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1416. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1417. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1418. if (IS_QLA81XX(ha))
  1419. speed = FC_PORTSPEED_10GBIT;
  1420. else if (IS_QLA25XX(ha))
  1421. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1422. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1423. else if (IS_QLA24XX_TYPE(ha))
  1424. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1425. FC_PORTSPEED_1GBIT;
  1426. else if (IS_QLA23XX(ha))
  1427. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1428. else
  1429. speed = FC_PORTSPEED_1GBIT;
  1430. fc_host_supported_speeds(vha->host) = speed;
  1431. }