qla_attr.c 52 KB

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