qla_attr.c 56 KB

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