zfcp_fsf.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  22. "fsrth_1", NULL);
  23. }
  24. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  25. unsigned long timeout)
  26. {
  27. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  29. fsf_req->timer.expires = jiffies + timeout;
  30. add_timer(&fsf_req->timer);
  31. }
  32. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  33. {
  34. BUG_ON(!fsf_req->erp_action);
  35. fsf_req->timer.function = zfcp_erp_timeout_handler;
  36. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  37. fsf_req->timer.expires = jiffies + 30 * HZ;
  38. add_timer(&fsf_req->timer);
  39. }
  40. /* association between FSF command and FSF QTCB type */
  41. static u32 fsf_qtcb_type[] = {
  42. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  43. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  52. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  53. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = table >> 16;
  59. u16 rule = table & 0xffff;
  60. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  61. if (subtable && subtable < ARRAY_SIZE(act_type))
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied according to ACT rule type %s, "
  64. "rule %d\n", act_type[subtable], rule);
  65. }
  66. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  67. struct zfcp_port *port)
  68. {
  69. struct fsf_qtcb_header *header = &req->qtcb->header;
  70. dev_warn(&req->adapter->ccw_device->dev,
  71. "Access denied to port 0x%016Lx\n",
  72. (unsigned long long)port->wwpn);
  73. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  75. zfcp_erp_port_access_denied(port, "fspad_1", req);
  76. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  77. }
  78. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  79. struct zfcp_unit *unit)
  80. {
  81. struct fsf_qtcb_header *header = &req->qtcb->header;
  82. dev_warn(&req->adapter->ccw_device->dev,
  83. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  84. (unsigned long long)unit->fcp_lun,
  85. (unsigned long long)unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  94. "operational because of an unsupported FC class\n");
  95. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  96. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  97. }
  98. /**
  99. * zfcp_fsf_req_free - free memory used by fsf request
  100. * @fsf_req: pointer to struct zfcp_fsf_req
  101. */
  102. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  103. {
  104. if (likely(req->pool)) {
  105. if (likely(req->qtcb))
  106. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  107. mempool_free(req, req->pool);
  108. return;
  109. }
  110. if (likely(req->qtcb))
  111. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  112. kfree(req);
  113. }
  114. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  115. {
  116. unsigned long flags;
  117. struct fsf_status_read_buffer *sr_buf = req->data;
  118. struct zfcp_adapter *adapter = req->adapter;
  119. struct zfcp_port *port;
  120. int d_id = ntoh24(sr_buf->d_id);
  121. read_lock_irqsave(&adapter->port_list_lock, flags);
  122. list_for_each_entry(port, &adapter->port_list, list)
  123. if (port->d_id == d_id) {
  124. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  125. break;
  126. }
  127. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  128. }
  129. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  130. struct fsf_link_down_info *link_down)
  131. {
  132. struct zfcp_adapter *adapter = req->adapter;
  133. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  134. return;
  135. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  136. zfcp_scsi_schedule_rports_block(adapter);
  137. if (!link_down)
  138. goto out;
  139. switch (link_down->error_code) {
  140. case FSF_PSQ_LINK_NO_LIGHT:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "There is no light signal from the local "
  143. "fibre channel cable\n");
  144. break;
  145. case FSF_PSQ_LINK_WRAP_PLUG:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "There is a wrap plug instead of a fibre "
  148. "channel cable\n");
  149. break;
  150. case FSF_PSQ_LINK_NO_FCP:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The adjacent fibre channel node does not "
  153. "support FCP\n");
  154. break;
  155. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The FCP device is suspended because of a "
  158. "firmware update\n");
  159. break;
  160. case FSF_PSQ_LINK_INVALID_WWPN:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The FCP device detected a WWPN that is "
  163. "duplicate or not valid\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The fibre channel fabric does not support NPIV\n");
  168. break;
  169. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "The FCP adapter cannot support more NPIV ports\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent switch cannot support "
  176. "more NPIV ports\n");
  177. break;
  178. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP adapter could not log in to the "
  181. "fibre channel fabric\n");
  182. break;
  183. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The WWPN assignment file on the FCP adapter "
  186. "has been damaged\n");
  187. break;
  188. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The mode table on the FCP adapter "
  191. "has been damaged\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "All NPIV ports on the FCP adapter have "
  196. "been assigned\n");
  197. break;
  198. default:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The link between the FCP adapter and "
  201. "the FC fabric is down\n");
  202. }
  203. out:
  204. zfcp_erp_adapter_failed(adapter, id, req);
  205. }
  206. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  207. {
  208. struct fsf_status_read_buffer *sr_buf = req->data;
  209. struct fsf_link_down_info *ldi =
  210. (struct fsf_link_down_info *) &sr_buf->payload;
  211. switch (sr_buf->status_subtype) {
  212. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  213. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  214. break;
  215. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  216. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  217. break;
  218. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  219. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  220. };
  221. }
  222. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  223. {
  224. struct zfcp_adapter *adapter = req->adapter;
  225. struct fsf_status_read_buffer *sr_buf = req->data;
  226. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  227. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  228. mempool_free(sr_buf, adapter->pool.status_read_data);
  229. zfcp_fsf_req_free(req);
  230. return;
  231. }
  232. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  233. switch (sr_buf->status_type) {
  234. case FSF_STATUS_READ_PORT_CLOSED:
  235. zfcp_fsf_status_read_port_closed(req);
  236. break;
  237. case FSF_STATUS_READ_INCOMING_ELS:
  238. zfcp_fc_incoming_els(req);
  239. break;
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. break;
  242. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  243. dev_warn(&adapter->ccw_device->dev,
  244. "The error threshold for checksum statistics "
  245. "has been exceeded\n");
  246. zfcp_dbf_hba_berr(adapter->dbf, req);
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. zfcp_fsf_status_read_link_down(req);
  250. break;
  251. case FSF_STATUS_READ_LINK_UP:
  252. dev_info(&adapter->ccw_device->dev,
  253. "The local link has been restored\n");
  254. /* All ports should be marked as ready to run again */
  255. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  256. ZFCP_STATUS_COMMON_RUNNING,
  257. ZFCP_SET);
  258. zfcp_erp_adapter_reopen(adapter,
  259. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  260. ZFCP_STATUS_COMMON_ERP_FAILED,
  261. "fssrh_2", req);
  262. break;
  263. case FSF_STATUS_READ_NOTIFICATION_LOST:
  264. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  265. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  266. req);
  267. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  268. queue_work(adapter->work_queue, &adapter->scan_work);
  269. break;
  270. case FSF_STATUS_READ_CFDC_UPDATED:
  271. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  272. break;
  273. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  274. adapter->adapter_features = sr_buf->payload.word[0];
  275. break;
  276. }
  277. mempool_free(sr_buf, adapter->pool.status_read_data);
  278. zfcp_fsf_req_free(req);
  279. atomic_inc(&adapter->stat_miss);
  280. queue_work(adapter->work_queue, &adapter->stat_work);
  281. }
  282. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  283. {
  284. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  285. case FSF_SQ_FCP_RSP_AVAILABLE:
  286. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  287. case FSF_SQ_NO_RETRY_POSSIBLE:
  288. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  289. return;
  290. case FSF_SQ_COMMAND_ABORTED:
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. return;
  328. }
  329. switch (qtcb->prefix.prot_status) {
  330. case FSF_PROT_GOOD:
  331. case FSF_PROT_FSF_STATUS_PRESENTED:
  332. return;
  333. case FSF_PROT_QTCB_VERSION_ERROR:
  334. dev_err(&adapter->ccw_device->dev,
  335. "QTCB version 0x%x not supported by FCP adapter "
  336. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  337. psq->word[0], psq->word[1]);
  338. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  339. break;
  340. case FSF_PROT_ERROR_STATE:
  341. case FSF_PROT_SEQ_NUMB_ERROR:
  342. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  344. break;
  345. case FSF_PROT_UNSUPP_QTCB_TYPE:
  346. dev_err(&adapter->ccw_device->dev,
  347. "The QTCB type is not supported by the FCP adapter\n");
  348. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  349. break;
  350. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  351. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  352. &adapter->status);
  353. break;
  354. case FSF_PROT_DUPLICATE_REQUEST_ID:
  355. dev_err(&adapter->ccw_device->dev,
  356. "0x%Lx is an ambiguous request identifier\n",
  357. (unsigned long long)qtcb->bottom.support.req_handle);
  358. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  359. break;
  360. case FSF_PROT_LINK_DOWN:
  361. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  362. &psq->link_down_info);
  363. /* go through reopen to flush pending requests */
  364. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  365. break;
  366. case FSF_PROT_REEST_QUEUE:
  367. /* All ports should be marked as ready to run again */
  368. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  369. ZFCP_STATUS_COMMON_RUNNING,
  370. ZFCP_SET);
  371. zfcp_erp_adapter_reopen(adapter,
  372. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  373. ZFCP_STATUS_COMMON_ERP_FAILED,
  374. "fspse_8", req);
  375. break;
  376. default:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%x is not a valid transfer protocol status\n",
  379. qtcb->prefix.prot_status);
  380. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  381. }
  382. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. }
  384. /**
  385. * zfcp_fsf_req_complete - process completion of a FSF request
  386. * @fsf_req: The FSF request that has been completed.
  387. *
  388. * When a request has been completed either from the FCP adapter,
  389. * or it has been dismissed due to a queue shutdown, this function
  390. * is called to process the completion status and trigger further
  391. * events related to the FSF request.
  392. */
  393. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  394. {
  395. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  396. zfcp_fsf_status_read_handler(req);
  397. return;
  398. }
  399. del_timer(&req->timer);
  400. zfcp_fsf_protstatus_eval(req);
  401. zfcp_fsf_fsfstatus_eval(req);
  402. req->handler(req);
  403. if (req->erp_action)
  404. zfcp_erp_notify(req->erp_action, 0);
  405. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  406. zfcp_fsf_req_free(req);
  407. else
  408. complete(&req->completion);
  409. }
  410. /**
  411. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  412. * @adapter: pointer to struct zfcp_adapter
  413. *
  414. * Never ever call this without shutting down the adapter first.
  415. * Otherwise the adapter would continue using and corrupting s390 storage.
  416. * Included BUG_ON() call to ensure this is done.
  417. * ERP is supposed to be the only user of this function.
  418. */
  419. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  420. {
  421. struct zfcp_fsf_req *req, *tmp;
  422. LIST_HEAD(remove_queue);
  423. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  424. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  425. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  426. list_del(&req->list);
  427. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  428. zfcp_fsf_req_complete(req);
  429. }
  430. }
  431. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  432. {
  433. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  434. struct zfcp_adapter *adapter = req->adapter;
  435. struct Scsi_Host *shost = adapter->scsi_host;
  436. struct fc_els_flogi *nsp, *plogi;
  437. /* adjust pointers for missing command code */
  438. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  439. - sizeof(u32));
  440. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  441. - sizeof(u32));
  442. if (req->data)
  443. memcpy(req->data, bottom, sizeof(*bottom));
  444. fc_host_port_name(shost) = nsp->fl_wwpn;
  445. fc_host_node_name(shost) = nsp->fl_wwnn;
  446. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  447. fc_host_speed(shost) = bottom->fc_link_speed;
  448. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  449. adapter->hydra_version = bottom->adapter_type;
  450. adapter->timer_ticks = bottom->timer_interval;
  451. if (fc_host_permanent_port_name(shost) == -1)
  452. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  453. switch (bottom->fc_topology) {
  454. case FSF_TOPO_P2P:
  455. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  456. adapter->peer_wwpn = plogi->fl_wwpn;
  457. adapter->peer_wwnn = plogi->fl_wwnn;
  458. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  459. break;
  460. case FSF_TOPO_FABRIC:
  461. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  462. break;
  463. case FSF_TOPO_AL:
  464. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  465. /* fall through */
  466. default:
  467. dev_err(&adapter->ccw_device->dev,
  468. "Unknown or unsupported arbitrated loop "
  469. "fibre channel topology detected\n");
  470. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  471. return -EIO;
  472. }
  473. return 0;
  474. }
  475. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  476. {
  477. struct zfcp_adapter *adapter = req->adapter;
  478. struct fsf_qtcb *qtcb = req->qtcb;
  479. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  480. struct Scsi_Host *shost = adapter->scsi_host;
  481. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  482. return;
  483. adapter->fsf_lic_version = bottom->lic_version;
  484. adapter->adapter_features = bottom->adapter_features;
  485. adapter->connection_features = bottom->connection_features;
  486. adapter->peer_wwpn = 0;
  487. adapter->peer_wwnn = 0;
  488. adapter->peer_d_id = 0;
  489. switch (qtcb->header.fsf_status) {
  490. case FSF_GOOD:
  491. if (zfcp_fsf_exchange_config_evaluate(req))
  492. return;
  493. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  494. dev_err(&adapter->ccw_device->dev,
  495. "FCP adapter maximum QTCB size (%d bytes) "
  496. "is too small\n",
  497. bottom->max_qtcb_size);
  498. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  499. return;
  500. }
  501. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  502. &adapter->status);
  503. break;
  504. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  505. fc_host_node_name(shost) = 0;
  506. fc_host_port_name(shost) = 0;
  507. fc_host_port_id(shost) = 0;
  508. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  509. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  510. adapter->hydra_version = 0;
  511. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  512. &adapter->status);
  513. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  514. &qtcb->header.fsf_status_qual.link_down_info);
  515. break;
  516. default:
  517. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  518. return;
  519. }
  520. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  521. adapter->hardware_version = bottom->hardware_version;
  522. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  523. min(FC_SERIAL_NUMBER_SIZE, 17));
  524. EBCASC(fc_host_serial_number(shost),
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. }
  527. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  528. dev_err(&adapter->ccw_device->dev,
  529. "The FCP adapter only supports newer "
  530. "control block versions\n");
  531. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  532. return;
  533. }
  534. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  535. dev_err(&adapter->ccw_device->dev,
  536. "The FCP adapter only supports older "
  537. "control block versions\n");
  538. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  539. }
  540. }
  541. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  542. {
  543. struct zfcp_adapter *adapter = req->adapter;
  544. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  545. struct Scsi_Host *shost = adapter->scsi_host;
  546. if (req->data)
  547. memcpy(req->data, bottom, sizeof(*bottom));
  548. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  549. fc_host_permanent_port_name(shost) = bottom->wwpn;
  550. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  551. } else
  552. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  553. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  554. fc_host_supported_speeds(shost) = bottom->supported_speed;
  555. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  556. FC_FC4_LIST_SIZE);
  557. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  558. FC_FC4_LIST_SIZE);
  559. }
  560. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  561. {
  562. struct fsf_qtcb *qtcb = req->qtcb;
  563. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  564. return;
  565. switch (qtcb->header.fsf_status) {
  566. case FSF_GOOD:
  567. zfcp_fsf_exchange_port_evaluate(req);
  568. break;
  569. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  572. &qtcb->header.fsf_status_qual.link_down_info);
  573. break;
  574. }
  575. }
  576. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  577. {
  578. struct zfcp_fsf_req *req;
  579. if (likely(pool))
  580. req = mempool_alloc(pool, GFP_ATOMIC);
  581. else
  582. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  583. if (unlikely(!req))
  584. return NULL;
  585. memset(req, 0, sizeof(*req));
  586. req->pool = pool;
  587. return req;
  588. }
  589. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  590. {
  591. struct fsf_qtcb *qtcb;
  592. if (likely(pool))
  593. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  594. else
  595. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  596. if (unlikely(!qtcb))
  597. return NULL;
  598. memset(qtcb, 0, sizeof(*qtcb));
  599. return qtcb;
  600. }
  601. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  602. u32 fsf_cmd, u32 sbtype,
  603. mempool_t *pool)
  604. {
  605. struct zfcp_adapter *adapter = qdio->adapter;
  606. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  607. if (unlikely(!req))
  608. return ERR_PTR(-ENOMEM);
  609. if (adapter->req_no == 0)
  610. adapter->req_no++;
  611. INIT_LIST_HEAD(&req->list);
  612. init_timer(&req->timer);
  613. init_completion(&req->completion);
  614. req->adapter = adapter;
  615. req->fsf_command = fsf_cmd;
  616. req->req_id = adapter->req_no;
  617. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  618. if (likely(pool))
  619. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  620. else
  621. req->qtcb = zfcp_qtcb_alloc(NULL);
  622. if (unlikely(!req->qtcb)) {
  623. zfcp_fsf_req_free(req);
  624. return ERR_PTR(-ENOMEM);
  625. }
  626. req->seq_no = adapter->fsf_req_seq_no;
  627. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  628. req->qtcb->prefix.req_id = req->req_id;
  629. req->qtcb->prefix.ulp_info = 26;
  630. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  631. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  632. req->qtcb->header.req_handle = req->req_id;
  633. req->qtcb->header.fsf_command = req->fsf_command;
  634. }
  635. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  636. req->qtcb, sizeof(struct fsf_qtcb));
  637. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  638. zfcp_fsf_req_free(req);
  639. return ERR_PTR(-EIO);
  640. }
  641. return req;
  642. }
  643. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  644. {
  645. struct zfcp_adapter *adapter = req->adapter;
  646. struct zfcp_qdio *qdio = adapter->qdio;
  647. int with_qtcb = (req->qtcb != NULL);
  648. int req_id = req->req_id;
  649. zfcp_reqlist_add(adapter->req_list, req);
  650. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  651. req->issued = get_clock();
  652. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  653. del_timer(&req->timer);
  654. /* lookup request again, list might have changed */
  655. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  656. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  657. return -EIO;
  658. }
  659. /* Don't increase for unsolicited status */
  660. if (with_qtcb)
  661. adapter->fsf_req_seq_no++;
  662. adapter->req_no++;
  663. return 0;
  664. }
  665. /**
  666. * zfcp_fsf_status_read - send status read request
  667. * @adapter: pointer to struct zfcp_adapter
  668. * @req_flags: request flags
  669. * Returns: 0 on success, ERROR otherwise
  670. */
  671. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  672. {
  673. struct zfcp_adapter *adapter = qdio->adapter;
  674. struct zfcp_fsf_req *req;
  675. struct fsf_status_read_buffer *sr_buf;
  676. int retval = -EIO;
  677. spin_lock_bh(&qdio->req_q_lock);
  678. if (zfcp_qdio_sbal_get(qdio))
  679. goto out;
  680. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  681. adapter->pool.status_read_req);
  682. if (IS_ERR(req)) {
  683. retval = PTR_ERR(req);
  684. goto out;
  685. }
  686. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  687. if (!sr_buf) {
  688. retval = -ENOMEM;
  689. goto failed_buf;
  690. }
  691. memset(sr_buf, 0, sizeof(*sr_buf));
  692. req->data = sr_buf;
  693. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  694. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  695. retval = zfcp_fsf_req_send(req);
  696. if (retval)
  697. goto failed_req_send;
  698. goto out;
  699. failed_req_send:
  700. mempool_free(sr_buf, adapter->pool.status_read_data);
  701. failed_buf:
  702. zfcp_fsf_req_free(req);
  703. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  704. out:
  705. spin_unlock_bh(&qdio->req_q_lock);
  706. return retval;
  707. }
  708. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  709. {
  710. struct zfcp_unit *unit = req->data;
  711. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  712. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  713. return;
  714. switch (req->qtcb->header.fsf_status) {
  715. case FSF_PORT_HANDLE_NOT_VALID:
  716. if (fsq->word[0] == fsq->word[1]) {
  717. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  718. "fsafch1", req);
  719. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  720. }
  721. break;
  722. case FSF_LUN_HANDLE_NOT_VALID:
  723. if (fsq->word[0] == fsq->word[1]) {
  724. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  725. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  726. }
  727. break;
  728. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  729. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  730. break;
  731. case FSF_PORT_BOXED:
  732. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  733. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  734. break;
  735. case FSF_LUN_BOXED:
  736. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  737. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  738. break;
  739. case FSF_ADAPTER_STATUS_AVAILABLE:
  740. switch (fsq->word[0]) {
  741. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  742. zfcp_fc_test_link(unit->port);
  743. /* fall through */
  744. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  745. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  746. break;
  747. }
  748. break;
  749. case FSF_GOOD:
  750. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  751. break;
  752. }
  753. }
  754. /**
  755. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  756. * @old_req_id: unsigned long
  757. * @unit: pointer to struct zfcp_unit
  758. * Returns: pointer to struct zfcp_fsf_req
  759. */
  760. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  761. struct zfcp_unit *unit)
  762. {
  763. struct zfcp_fsf_req *req = NULL;
  764. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  765. spin_lock_bh(&qdio->req_q_lock);
  766. if (zfcp_qdio_sbal_get(qdio))
  767. goto out;
  768. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  769. SBAL_FLAGS0_TYPE_READ,
  770. qdio->adapter->pool.scsi_abort);
  771. if (IS_ERR(req)) {
  772. req = NULL;
  773. goto out;
  774. }
  775. if (unlikely(!(atomic_read(&unit->status) &
  776. ZFCP_STATUS_COMMON_UNBLOCKED)))
  777. goto out_error_free;
  778. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  779. req->data = unit;
  780. req->handler = zfcp_fsf_abort_fcp_command_handler;
  781. req->qtcb->header.lun_handle = unit->handle;
  782. req->qtcb->header.port_handle = unit->port->handle;
  783. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  784. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  785. if (!zfcp_fsf_req_send(req))
  786. goto out;
  787. out_error_free:
  788. zfcp_fsf_req_free(req);
  789. req = NULL;
  790. out:
  791. spin_unlock_bh(&qdio->req_q_lock);
  792. return req;
  793. }
  794. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  795. {
  796. struct zfcp_adapter *adapter = req->adapter;
  797. struct zfcp_fsf_ct_els *ct = req->data;
  798. struct fsf_qtcb_header *header = &req->qtcb->header;
  799. ct->status = -EINVAL;
  800. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  801. goto skip_fsfstatus;
  802. switch (header->fsf_status) {
  803. case FSF_GOOD:
  804. zfcp_dbf_san_ct_response(req);
  805. ct->status = 0;
  806. break;
  807. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  808. zfcp_fsf_class_not_supp(req);
  809. break;
  810. case FSF_ADAPTER_STATUS_AVAILABLE:
  811. switch (header->fsf_status_qual.word[0]){
  812. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  813. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  814. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  815. break;
  816. }
  817. break;
  818. case FSF_ACCESS_DENIED:
  819. break;
  820. case FSF_PORT_BOXED:
  821. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  822. break;
  823. case FSF_PORT_HANDLE_NOT_VALID:
  824. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  825. /* fall through */
  826. case FSF_GENERIC_COMMAND_REJECTED:
  827. case FSF_PAYLOAD_SIZE_MISMATCH:
  828. case FSF_REQUEST_SIZE_TOO_LARGE:
  829. case FSF_RESPONSE_SIZE_TOO_LARGE:
  830. case FSF_SBAL_MISMATCH:
  831. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  832. break;
  833. }
  834. skip_fsfstatus:
  835. if (ct->handler)
  836. ct->handler(ct->handler_data);
  837. }
  838. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  839. struct zfcp_qdio_req *q_req,
  840. struct scatterlist *sg_req,
  841. struct scatterlist *sg_resp)
  842. {
  843. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  844. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  845. zfcp_qdio_set_sbale_last(qdio, q_req);
  846. }
  847. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  848. struct scatterlist *sg_req,
  849. struct scatterlist *sg_resp,
  850. int max_sbals)
  851. {
  852. struct zfcp_adapter *adapter = req->adapter;
  853. u32 feat = adapter->adapter_features;
  854. int bytes;
  855. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  856. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  857. !zfcp_qdio_sg_one_sbale(sg_resp))
  858. return -EOPNOTSUPP;
  859. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  860. sg_req, sg_resp);
  861. return 0;
  862. }
  863. /* use single, unchained SBAL if it can hold the request */
  864. if (zfcp_qdio_sg_one_sbale(sg_req) || zfcp_qdio_sg_one_sbale(sg_resp)) {
  865. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  866. sg_req, sg_resp);
  867. return 0;
  868. }
  869. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  870. sg_req, max_sbals);
  871. if (bytes <= 0)
  872. return -EIO;
  873. req->qtcb->bottom.support.req_buf_length = bytes;
  874. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  875. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  876. sg_resp, max_sbals);
  877. req->qtcb->bottom.support.resp_buf_length = bytes;
  878. if (bytes <= 0)
  879. return -EIO;
  880. return 0;
  881. }
  882. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  883. struct scatterlist *sg_req,
  884. struct scatterlist *sg_resp,
  885. int max_sbals, unsigned int timeout)
  886. {
  887. int ret;
  888. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  889. if (ret)
  890. return ret;
  891. /* common settings for ct/gs and els requests */
  892. if (timeout > 255)
  893. timeout = 255; /* max value accepted by hardware */
  894. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  895. req->qtcb->bottom.support.timeout = timeout;
  896. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  897. return 0;
  898. }
  899. /**
  900. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  901. * @ct: pointer to struct zfcp_send_ct with data for request
  902. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  903. */
  904. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  905. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  906. unsigned int timeout)
  907. {
  908. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  909. struct zfcp_fsf_req *req;
  910. int ret = -EIO;
  911. spin_lock_bh(&qdio->req_q_lock);
  912. if (zfcp_qdio_sbal_get(qdio))
  913. goto out;
  914. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  915. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  916. if (IS_ERR(req)) {
  917. ret = PTR_ERR(req);
  918. goto out;
  919. }
  920. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  921. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  922. ZFCP_FSF_MAX_SBALS_PER_REQ, timeout);
  923. if (ret)
  924. goto failed_send;
  925. req->handler = zfcp_fsf_send_ct_handler;
  926. req->qtcb->header.port_handle = wka_port->handle;
  927. req->data = ct;
  928. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  929. ret = zfcp_fsf_req_send(req);
  930. if (ret)
  931. goto failed_send;
  932. goto out;
  933. failed_send:
  934. zfcp_fsf_req_free(req);
  935. out:
  936. spin_unlock_bh(&qdio->req_q_lock);
  937. return ret;
  938. }
  939. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  940. {
  941. struct zfcp_fsf_ct_els *send_els = req->data;
  942. struct zfcp_port *port = send_els->port;
  943. struct fsf_qtcb_header *header = &req->qtcb->header;
  944. send_els->status = -EINVAL;
  945. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  946. goto skip_fsfstatus;
  947. switch (header->fsf_status) {
  948. case FSF_GOOD:
  949. zfcp_dbf_san_els_response(req);
  950. send_els->status = 0;
  951. break;
  952. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  953. zfcp_fsf_class_not_supp(req);
  954. break;
  955. case FSF_ADAPTER_STATUS_AVAILABLE:
  956. switch (header->fsf_status_qual.word[0]){
  957. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  958. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  959. case FSF_SQ_RETRY_IF_POSSIBLE:
  960. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  961. break;
  962. }
  963. break;
  964. case FSF_ELS_COMMAND_REJECTED:
  965. case FSF_PAYLOAD_SIZE_MISMATCH:
  966. case FSF_REQUEST_SIZE_TOO_LARGE:
  967. case FSF_RESPONSE_SIZE_TOO_LARGE:
  968. break;
  969. case FSF_ACCESS_DENIED:
  970. if (port)
  971. zfcp_fsf_access_denied_port(req, port);
  972. break;
  973. case FSF_SBAL_MISMATCH:
  974. /* should never occure, avoided in zfcp_fsf_send_els */
  975. /* fall through */
  976. default:
  977. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  978. break;
  979. }
  980. skip_fsfstatus:
  981. if (send_els->handler)
  982. send_els->handler(send_els->handler_data);
  983. }
  984. /**
  985. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  986. * @els: pointer to struct zfcp_send_els with data for the command
  987. */
  988. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  989. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  990. {
  991. struct zfcp_fsf_req *req;
  992. struct zfcp_qdio *qdio = adapter->qdio;
  993. int ret = -EIO;
  994. spin_lock_bh(&qdio->req_q_lock);
  995. if (zfcp_qdio_sbal_get(qdio))
  996. goto out;
  997. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  998. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  999. if (IS_ERR(req)) {
  1000. ret = PTR_ERR(req);
  1001. goto out;
  1002. }
  1003. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1004. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
  1005. if (ret)
  1006. goto failed_send;
  1007. hton24(req->qtcb->bottom.support.d_id, d_id);
  1008. req->handler = zfcp_fsf_send_els_handler;
  1009. req->data = els;
  1010. zfcp_dbf_san_els_request(req);
  1011. ret = zfcp_fsf_req_send(req);
  1012. if (ret)
  1013. goto failed_send;
  1014. goto out;
  1015. failed_send:
  1016. zfcp_fsf_req_free(req);
  1017. out:
  1018. spin_unlock_bh(&qdio->req_q_lock);
  1019. return ret;
  1020. }
  1021. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1022. {
  1023. struct zfcp_fsf_req *req;
  1024. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1025. int retval = -EIO;
  1026. spin_lock_bh(&qdio->req_q_lock);
  1027. if (zfcp_qdio_sbal_get(qdio))
  1028. goto out;
  1029. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1030. SBAL_FLAGS0_TYPE_READ,
  1031. qdio->adapter->pool.erp_req);
  1032. if (IS_ERR(req)) {
  1033. retval = PTR_ERR(req);
  1034. goto out;
  1035. }
  1036. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1037. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1038. req->qtcb->bottom.config.feature_selection =
  1039. FSF_FEATURE_CFDC |
  1040. FSF_FEATURE_LUN_SHARING |
  1041. FSF_FEATURE_NOTIFICATION_LOST |
  1042. FSF_FEATURE_UPDATE_ALERT;
  1043. req->erp_action = erp_action;
  1044. req->handler = zfcp_fsf_exchange_config_data_handler;
  1045. erp_action->fsf_req_id = req->req_id;
  1046. zfcp_fsf_start_erp_timer(req);
  1047. retval = zfcp_fsf_req_send(req);
  1048. if (retval) {
  1049. zfcp_fsf_req_free(req);
  1050. erp_action->fsf_req_id = 0;
  1051. }
  1052. out:
  1053. spin_unlock_bh(&qdio->req_q_lock);
  1054. return retval;
  1055. }
  1056. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1057. struct fsf_qtcb_bottom_config *data)
  1058. {
  1059. struct zfcp_fsf_req *req = NULL;
  1060. int retval = -EIO;
  1061. spin_lock_bh(&qdio->req_q_lock);
  1062. if (zfcp_qdio_sbal_get(qdio))
  1063. goto out_unlock;
  1064. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1065. SBAL_FLAGS0_TYPE_READ, NULL);
  1066. if (IS_ERR(req)) {
  1067. retval = PTR_ERR(req);
  1068. goto out_unlock;
  1069. }
  1070. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1071. req->handler = zfcp_fsf_exchange_config_data_handler;
  1072. req->qtcb->bottom.config.feature_selection =
  1073. FSF_FEATURE_CFDC |
  1074. FSF_FEATURE_LUN_SHARING |
  1075. FSF_FEATURE_NOTIFICATION_LOST |
  1076. FSF_FEATURE_UPDATE_ALERT;
  1077. if (data)
  1078. req->data = data;
  1079. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1080. retval = zfcp_fsf_req_send(req);
  1081. spin_unlock_bh(&qdio->req_q_lock);
  1082. if (!retval)
  1083. wait_for_completion(&req->completion);
  1084. zfcp_fsf_req_free(req);
  1085. return retval;
  1086. out_unlock:
  1087. spin_unlock_bh(&qdio->req_q_lock);
  1088. return retval;
  1089. }
  1090. /**
  1091. * zfcp_fsf_exchange_port_data - request information about local port
  1092. * @erp_action: ERP action for the adapter for which port data is requested
  1093. * Returns: 0 on success, error otherwise
  1094. */
  1095. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1096. {
  1097. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1098. struct zfcp_fsf_req *req;
  1099. int retval = -EIO;
  1100. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1101. return -EOPNOTSUPP;
  1102. spin_lock_bh(&qdio->req_q_lock);
  1103. if (zfcp_qdio_sbal_get(qdio))
  1104. goto out;
  1105. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1106. SBAL_FLAGS0_TYPE_READ,
  1107. qdio->adapter->pool.erp_req);
  1108. if (IS_ERR(req)) {
  1109. retval = PTR_ERR(req);
  1110. goto out;
  1111. }
  1112. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1113. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1114. req->handler = zfcp_fsf_exchange_port_data_handler;
  1115. req->erp_action = erp_action;
  1116. erp_action->fsf_req_id = req->req_id;
  1117. zfcp_fsf_start_erp_timer(req);
  1118. retval = zfcp_fsf_req_send(req);
  1119. if (retval) {
  1120. zfcp_fsf_req_free(req);
  1121. erp_action->fsf_req_id = 0;
  1122. }
  1123. out:
  1124. spin_unlock_bh(&qdio->req_q_lock);
  1125. return retval;
  1126. }
  1127. /**
  1128. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1129. * @qdio: pointer to struct zfcp_qdio
  1130. * @data: pointer to struct fsf_qtcb_bottom_port
  1131. * Returns: 0 on success, error otherwise
  1132. */
  1133. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1134. struct fsf_qtcb_bottom_port *data)
  1135. {
  1136. struct zfcp_fsf_req *req = NULL;
  1137. int retval = -EIO;
  1138. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1139. return -EOPNOTSUPP;
  1140. spin_lock_bh(&qdio->req_q_lock);
  1141. if (zfcp_qdio_sbal_get(qdio))
  1142. goto out_unlock;
  1143. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1144. SBAL_FLAGS0_TYPE_READ, NULL);
  1145. if (IS_ERR(req)) {
  1146. retval = PTR_ERR(req);
  1147. goto out_unlock;
  1148. }
  1149. if (data)
  1150. req->data = data;
  1151. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1152. req->handler = zfcp_fsf_exchange_port_data_handler;
  1153. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1154. retval = zfcp_fsf_req_send(req);
  1155. spin_unlock_bh(&qdio->req_q_lock);
  1156. if (!retval)
  1157. wait_for_completion(&req->completion);
  1158. zfcp_fsf_req_free(req);
  1159. return retval;
  1160. out_unlock:
  1161. spin_unlock_bh(&qdio->req_q_lock);
  1162. return retval;
  1163. }
  1164. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1165. {
  1166. struct zfcp_port *port = req->data;
  1167. struct fsf_qtcb_header *header = &req->qtcb->header;
  1168. struct fc_els_flogi *plogi;
  1169. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1170. goto out;
  1171. switch (header->fsf_status) {
  1172. case FSF_PORT_ALREADY_OPEN:
  1173. break;
  1174. case FSF_ACCESS_DENIED:
  1175. zfcp_fsf_access_denied_port(req, port);
  1176. break;
  1177. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1178. dev_warn(&req->adapter->ccw_device->dev,
  1179. "Not enough FCP adapter resources to open "
  1180. "remote port 0x%016Lx\n",
  1181. (unsigned long long)port->wwpn);
  1182. zfcp_erp_port_failed(port, "fsoph_1", req);
  1183. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1184. break;
  1185. case FSF_ADAPTER_STATUS_AVAILABLE:
  1186. switch (header->fsf_status_qual.word[0]) {
  1187. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1188. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1189. case FSF_SQ_NO_RETRY_POSSIBLE:
  1190. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1191. break;
  1192. }
  1193. break;
  1194. case FSF_GOOD:
  1195. port->handle = header->port_handle;
  1196. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1197. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1198. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1199. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1200. &port->status);
  1201. /* check whether D_ID has changed during open */
  1202. /*
  1203. * FIXME: This check is not airtight, as the FCP channel does
  1204. * not monitor closures of target port connections caused on
  1205. * the remote side. Thus, they might miss out on invalidating
  1206. * locally cached WWPNs (and other N_Port parameters) of gone
  1207. * target ports. So, our heroic attempt to make things safe
  1208. * could be undermined by 'open port' response data tagged with
  1209. * obsolete WWPNs. Another reason to monitor potential
  1210. * connection closures ourself at least (by interpreting
  1211. * incoming ELS' and unsolicited status). It just crosses my
  1212. * mind that one should be able to cross-check by means of
  1213. * another GID_PN straight after a port has been opened.
  1214. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1215. */
  1216. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1217. if (req->qtcb->bottom.support.els1_length >=
  1218. FSF_PLOGI_MIN_LEN)
  1219. zfcp_fc_plogi_evaluate(port, plogi);
  1220. break;
  1221. case FSF_UNKNOWN_OP_SUBTYPE:
  1222. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1223. break;
  1224. }
  1225. out:
  1226. put_device(&port->dev);
  1227. }
  1228. /**
  1229. * zfcp_fsf_open_port - create and send open port request
  1230. * @erp_action: pointer to struct zfcp_erp_action
  1231. * Returns: 0 on success, error otherwise
  1232. */
  1233. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1234. {
  1235. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1236. struct zfcp_port *port = erp_action->port;
  1237. struct zfcp_fsf_req *req;
  1238. int retval = -EIO;
  1239. spin_lock_bh(&qdio->req_q_lock);
  1240. if (zfcp_qdio_sbal_get(qdio))
  1241. goto out;
  1242. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1243. SBAL_FLAGS0_TYPE_READ,
  1244. qdio->adapter->pool.erp_req);
  1245. if (IS_ERR(req)) {
  1246. retval = PTR_ERR(req);
  1247. goto out;
  1248. }
  1249. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1250. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1251. req->handler = zfcp_fsf_open_port_handler;
  1252. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1253. req->data = port;
  1254. req->erp_action = erp_action;
  1255. erp_action->fsf_req_id = req->req_id;
  1256. get_device(&port->dev);
  1257. zfcp_fsf_start_erp_timer(req);
  1258. retval = zfcp_fsf_req_send(req);
  1259. if (retval) {
  1260. zfcp_fsf_req_free(req);
  1261. erp_action->fsf_req_id = 0;
  1262. put_device(&port->dev);
  1263. }
  1264. out:
  1265. spin_unlock_bh(&qdio->req_q_lock);
  1266. return retval;
  1267. }
  1268. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1269. {
  1270. struct zfcp_port *port = req->data;
  1271. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1272. return;
  1273. switch (req->qtcb->header.fsf_status) {
  1274. case FSF_PORT_HANDLE_NOT_VALID:
  1275. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1276. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1277. break;
  1278. case FSF_ADAPTER_STATUS_AVAILABLE:
  1279. break;
  1280. case FSF_GOOD:
  1281. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1282. ZFCP_STATUS_COMMON_OPEN,
  1283. ZFCP_CLEAR);
  1284. break;
  1285. }
  1286. }
  1287. /**
  1288. * zfcp_fsf_close_port - create and send close port request
  1289. * @erp_action: pointer to struct zfcp_erp_action
  1290. * Returns: 0 on success, error otherwise
  1291. */
  1292. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1293. {
  1294. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1295. struct zfcp_fsf_req *req;
  1296. int retval = -EIO;
  1297. spin_lock_bh(&qdio->req_q_lock);
  1298. if (zfcp_qdio_sbal_get(qdio))
  1299. goto out;
  1300. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1301. SBAL_FLAGS0_TYPE_READ,
  1302. qdio->adapter->pool.erp_req);
  1303. if (IS_ERR(req)) {
  1304. retval = PTR_ERR(req);
  1305. goto out;
  1306. }
  1307. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1308. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1309. req->handler = zfcp_fsf_close_port_handler;
  1310. req->data = erp_action->port;
  1311. req->erp_action = erp_action;
  1312. req->qtcb->header.port_handle = erp_action->port->handle;
  1313. erp_action->fsf_req_id = req->req_id;
  1314. zfcp_fsf_start_erp_timer(req);
  1315. retval = zfcp_fsf_req_send(req);
  1316. if (retval) {
  1317. zfcp_fsf_req_free(req);
  1318. erp_action->fsf_req_id = 0;
  1319. }
  1320. out:
  1321. spin_unlock_bh(&qdio->req_q_lock);
  1322. return retval;
  1323. }
  1324. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1325. {
  1326. struct zfcp_fc_wka_port *wka_port = req->data;
  1327. struct fsf_qtcb_header *header = &req->qtcb->header;
  1328. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1329. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1330. goto out;
  1331. }
  1332. switch (header->fsf_status) {
  1333. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1334. dev_warn(&req->adapter->ccw_device->dev,
  1335. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1336. /* fall through */
  1337. case FSF_ADAPTER_STATUS_AVAILABLE:
  1338. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1339. /* fall through */
  1340. case FSF_ACCESS_DENIED:
  1341. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1342. break;
  1343. case FSF_GOOD:
  1344. wka_port->handle = header->port_handle;
  1345. /* fall through */
  1346. case FSF_PORT_ALREADY_OPEN:
  1347. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1348. }
  1349. out:
  1350. wake_up(&wka_port->completion_wq);
  1351. }
  1352. /**
  1353. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1354. * @wka_port: pointer to struct zfcp_fc_wka_port
  1355. * Returns: 0 on success, error otherwise
  1356. */
  1357. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1358. {
  1359. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1360. struct zfcp_fsf_req *req;
  1361. int retval = -EIO;
  1362. spin_lock_bh(&qdio->req_q_lock);
  1363. if (zfcp_qdio_sbal_get(qdio))
  1364. goto out;
  1365. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1366. SBAL_FLAGS0_TYPE_READ,
  1367. qdio->adapter->pool.erp_req);
  1368. if (unlikely(IS_ERR(req))) {
  1369. retval = PTR_ERR(req);
  1370. goto out;
  1371. }
  1372. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1373. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1374. req->handler = zfcp_fsf_open_wka_port_handler;
  1375. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1376. req->data = wka_port;
  1377. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1378. retval = zfcp_fsf_req_send(req);
  1379. if (retval)
  1380. zfcp_fsf_req_free(req);
  1381. out:
  1382. spin_unlock_bh(&qdio->req_q_lock);
  1383. return retval;
  1384. }
  1385. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1386. {
  1387. struct zfcp_fc_wka_port *wka_port = req->data;
  1388. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1389. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1390. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1391. }
  1392. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1393. wake_up(&wka_port->completion_wq);
  1394. }
  1395. /**
  1396. * zfcp_fsf_close_wka_port - create and send close wka port request
  1397. * @wka_port: WKA port to open
  1398. * Returns: 0 on success, error otherwise
  1399. */
  1400. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1401. {
  1402. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1403. struct zfcp_fsf_req *req;
  1404. int retval = -EIO;
  1405. spin_lock_bh(&qdio->req_q_lock);
  1406. if (zfcp_qdio_sbal_get(qdio))
  1407. goto out;
  1408. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1409. SBAL_FLAGS0_TYPE_READ,
  1410. qdio->adapter->pool.erp_req);
  1411. if (unlikely(IS_ERR(req))) {
  1412. retval = PTR_ERR(req);
  1413. goto out;
  1414. }
  1415. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1416. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1417. req->handler = zfcp_fsf_close_wka_port_handler;
  1418. req->data = wka_port;
  1419. req->qtcb->header.port_handle = wka_port->handle;
  1420. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1421. retval = zfcp_fsf_req_send(req);
  1422. if (retval)
  1423. zfcp_fsf_req_free(req);
  1424. out:
  1425. spin_unlock_bh(&qdio->req_q_lock);
  1426. return retval;
  1427. }
  1428. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1429. {
  1430. struct zfcp_port *port = req->data;
  1431. struct fsf_qtcb_header *header = &req->qtcb->header;
  1432. struct zfcp_unit *unit;
  1433. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1434. return;
  1435. switch (header->fsf_status) {
  1436. case FSF_PORT_HANDLE_NOT_VALID:
  1437. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1438. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1439. break;
  1440. case FSF_ACCESS_DENIED:
  1441. zfcp_fsf_access_denied_port(req, port);
  1442. break;
  1443. case FSF_PORT_BOXED:
  1444. /* can't use generic zfcp_erp_modify_port_status because
  1445. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1446. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1447. read_lock(&port->unit_list_lock);
  1448. list_for_each_entry(unit, &port->unit_list, list)
  1449. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1450. &unit->status);
  1451. read_unlock(&port->unit_list_lock);
  1452. zfcp_erp_port_boxed(port, "fscpph2", req);
  1453. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1454. break;
  1455. case FSF_ADAPTER_STATUS_AVAILABLE:
  1456. switch (header->fsf_status_qual.word[0]) {
  1457. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1458. /* fall through */
  1459. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1460. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1461. break;
  1462. }
  1463. break;
  1464. case FSF_GOOD:
  1465. /* can't use generic zfcp_erp_modify_port_status because
  1466. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1467. */
  1468. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1469. read_lock(&port->unit_list_lock);
  1470. list_for_each_entry(unit, &port->unit_list, list)
  1471. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1472. &unit->status);
  1473. read_unlock(&port->unit_list_lock);
  1474. break;
  1475. }
  1476. }
  1477. /**
  1478. * zfcp_fsf_close_physical_port - close physical port
  1479. * @erp_action: pointer to struct zfcp_erp_action
  1480. * Returns: 0 on success
  1481. */
  1482. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1483. {
  1484. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1485. struct zfcp_fsf_req *req;
  1486. int retval = -EIO;
  1487. spin_lock_bh(&qdio->req_q_lock);
  1488. if (zfcp_qdio_sbal_get(qdio))
  1489. goto out;
  1490. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1491. SBAL_FLAGS0_TYPE_READ,
  1492. qdio->adapter->pool.erp_req);
  1493. if (IS_ERR(req)) {
  1494. retval = PTR_ERR(req);
  1495. goto out;
  1496. }
  1497. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1498. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1499. req->data = erp_action->port;
  1500. req->qtcb->header.port_handle = erp_action->port->handle;
  1501. req->erp_action = erp_action;
  1502. req->handler = zfcp_fsf_close_physical_port_handler;
  1503. erp_action->fsf_req_id = req->req_id;
  1504. zfcp_fsf_start_erp_timer(req);
  1505. retval = zfcp_fsf_req_send(req);
  1506. if (retval) {
  1507. zfcp_fsf_req_free(req);
  1508. erp_action->fsf_req_id = 0;
  1509. }
  1510. out:
  1511. spin_unlock_bh(&qdio->req_q_lock);
  1512. return retval;
  1513. }
  1514. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1515. {
  1516. struct zfcp_adapter *adapter = req->adapter;
  1517. struct zfcp_unit *unit = req->data;
  1518. struct fsf_qtcb_header *header = &req->qtcb->header;
  1519. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1520. struct fsf_queue_designator *queue_designator =
  1521. &header->fsf_status_qual.fsf_queue_designator;
  1522. int exclusive, readwrite;
  1523. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1524. return;
  1525. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1526. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1527. ZFCP_STATUS_UNIT_SHARED |
  1528. ZFCP_STATUS_UNIT_READONLY,
  1529. &unit->status);
  1530. switch (header->fsf_status) {
  1531. case FSF_PORT_HANDLE_NOT_VALID:
  1532. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1533. /* fall through */
  1534. case FSF_LUN_ALREADY_OPEN:
  1535. break;
  1536. case FSF_ACCESS_DENIED:
  1537. zfcp_fsf_access_denied_unit(req, unit);
  1538. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1539. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1540. break;
  1541. case FSF_PORT_BOXED:
  1542. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1543. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1544. break;
  1545. case FSF_LUN_SHARING_VIOLATION:
  1546. if (header->fsf_status_qual.word[0])
  1547. dev_warn(&adapter->ccw_device->dev,
  1548. "LUN 0x%Lx on port 0x%Lx is already in "
  1549. "use by CSS%d, MIF Image ID %x\n",
  1550. (unsigned long long)unit->fcp_lun,
  1551. (unsigned long long)unit->port->wwpn,
  1552. queue_designator->cssid,
  1553. queue_designator->hla);
  1554. else
  1555. zfcp_act_eval_err(adapter,
  1556. header->fsf_status_qual.word[2]);
  1557. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1558. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1559. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1560. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1561. break;
  1562. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1563. dev_warn(&adapter->ccw_device->dev,
  1564. "No handle is available for LUN "
  1565. "0x%016Lx on port 0x%016Lx\n",
  1566. (unsigned long long)unit->fcp_lun,
  1567. (unsigned long long)unit->port->wwpn);
  1568. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1569. /* fall through */
  1570. case FSF_INVALID_COMMAND_OPTION:
  1571. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1572. break;
  1573. case FSF_ADAPTER_STATUS_AVAILABLE:
  1574. switch (header->fsf_status_qual.word[0]) {
  1575. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1576. zfcp_fc_test_link(unit->port);
  1577. /* fall through */
  1578. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1579. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1580. break;
  1581. }
  1582. break;
  1583. case FSF_GOOD:
  1584. unit->handle = header->lun_handle;
  1585. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1586. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1587. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1588. !zfcp_ccw_priv_sch(adapter)) {
  1589. exclusive = (bottom->lun_access_info &
  1590. FSF_UNIT_ACCESS_EXCLUSIVE);
  1591. readwrite = (bottom->lun_access_info &
  1592. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1593. if (!exclusive)
  1594. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1595. &unit->status);
  1596. if (!readwrite) {
  1597. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1598. &unit->status);
  1599. dev_info(&adapter->ccw_device->dev,
  1600. "SCSI device at LUN 0x%016Lx on port "
  1601. "0x%016Lx opened read-only\n",
  1602. (unsigned long long)unit->fcp_lun,
  1603. (unsigned long long)unit->port->wwpn);
  1604. }
  1605. if (exclusive && !readwrite) {
  1606. dev_err(&adapter->ccw_device->dev,
  1607. "Exclusive read-only access not "
  1608. "supported (unit 0x%016Lx, "
  1609. "port 0x%016Lx)\n",
  1610. (unsigned long long)unit->fcp_lun,
  1611. (unsigned long long)unit->port->wwpn);
  1612. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1613. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1614. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1615. } else if (!exclusive && readwrite) {
  1616. dev_err(&adapter->ccw_device->dev,
  1617. "Shared read-write access not "
  1618. "supported (unit 0x%016Lx, port "
  1619. "0x%016Lx)\n",
  1620. (unsigned long long)unit->fcp_lun,
  1621. (unsigned long long)unit->port->wwpn);
  1622. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1623. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1624. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1625. }
  1626. }
  1627. break;
  1628. }
  1629. }
  1630. /**
  1631. * zfcp_fsf_open_unit - open unit
  1632. * @erp_action: pointer to struct zfcp_erp_action
  1633. * Returns: 0 on success, error otherwise
  1634. */
  1635. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1636. {
  1637. struct zfcp_adapter *adapter = erp_action->adapter;
  1638. struct zfcp_qdio *qdio = adapter->qdio;
  1639. struct zfcp_fsf_req *req;
  1640. int retval = -EIO;
  1641. spin_lock_bh(&qdio->req_q_lock);
  1642. if (zfcp_qdio_sbal_get(qdio))
  1643. goto out;
  1644. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1645. SBAL_FLAGS0_TYPE_READ,
  1646. adapter->pool.erp_req);
  1647. if (IS_ERR(req)) {
  1648. retval = PTR_ERR(req);
  1649. goto out;
  1650. }
  1651. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1652. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1653. req->qtcb->header.port_handle = erp_action->port->handle;
  1654. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1655. req->handler = zfcp_fsf_open_unit_handler;
  1656. req->data = erp_action->unit;
  1657. req->erp_action = erp_action;
  1658. erp_action->fsf_req_id = req->req_id;
  1659. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1660. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1661. zfcp_fsf_start_erp_timer(req);
  1662. retval = zfcp_fsf_req_send(req);
  1663. if (retval) {
  1664. zfcp_fsf_req_free(req);
  1665. erp_action->fsf_req_id = 0;
  1666. }
  1667. out:
  1668. spin_unlock_bh(&qdio->req_q_lock);
  1669. return retval;
  1670. }
  1671. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1672. {
  1673. struct zfcp_unit *unit = req->data;
  1674. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1675. return;
  1676. switch (req->qtcb->header.fsf_status) {
  1677. case FSF_PORT_HANDLE_NOT_VALID:
  1678. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1679. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1680. break;
  1681. case FSF_LUN_HANDLE_NOT_VALID:
  1682. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1684. break;
  1685. case FSF_PORT_BOXED:
  1686. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1687. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1688. break;
  1689. case FSF_ADAPTER_STATUS_AVAILABLE:
  1690. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1691. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1692. zfcp_fc_test_link(unit->port);
  1693. /* fall through */
  1694. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1695. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1696. break;
  1697. }
  1698. break;
  1699. case FSF_GOOD:
  1700. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1701. break;
  1702. }
  1703. }
  1704. /**
  1705. * zfcp_fsf_close_unit - close zfcp unit
  1706. * @erp_action: pointer to struct zfcp_unit
  1707. * Returns: 0 on success, error otherwise
  1708. */
  1709. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1710. {
  1711. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1712. struct zfcp_fsf_req *req;
  1713. int retval = -EIO;
  1714. spin_lock_bh(&qdio->req_q_lock);
  1715. if (zfcp_qdio_sbal_get(qdio))
  1716. goto out;
  1717. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1718. SBAL_FLAGS0_TYPE_READ,
  1719. qdio->adapter->pool.erp_req);
  1720. if (IS_ERR(req)) {
  1721. retval = PTR_ERR(req);
  1722. goto out;
  1723. }
  1724. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1725. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1726. req->qtcb->header.port_handle = erp_action->port->handle;
  1727. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1728. req->handler = zfcp_fsf_close_unit_handler;
  1729. req->data = erp_action->unit;
  1730. req->erp_action = erp_action;
  1731. erp_action->fsf_req_id = req->req_id;
  1732. zfcp_fsf_start_erp_timer(req);
  1733. retval = zfcp_fsf_req_send(req);
  1734. if (retval) {
  1735. zfcp_fsf_req_free(req);
  1736. erp_action->fsf_req_id = 0;
  1737. }
  1738. out:
  1739. spin_unlock_bh(&qdio->req_q_lock);
  1740. return retval;
  1741. }
  1742. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1743. {
  1744. lat_rec->sum += lat;
  1745. lat_rec->min = min(lat_rec->min, lat);
  1746. lat_rec->max = max(lat_rec->max, lat);
  1747. }
  1748. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1749. {
  1750. struct fsf_qual_latency_info *lat_in;
  1751. struct latency_cont *lat = NULL;
  1752. struct zfcp_unit *unit = req->unit;
  1753. struct zfcp_blk_drv_data blktrc;
  1754. int ticks = req->adapter->timer_ticks;
  1755. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1756. blktrc.flags = 0;
  1757. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1758. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1759. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1760. blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
  1761. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1762. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1763. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1764. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1765. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1766. switch (req->qtcb->bottom.io.data_direction) {
  1767. case FSF_DATADIR_READ:
  1768. lat = &unit->latencies.read;
  1769. break;
  1770. case FSF_DATADIR_WRITE:
  1771. lat = &unit->latencies.write;
  1772. break;
  1773. case FSF_DATADIR_CMND:
  1774. lat = &unit->latencies.cmd;
  1775. break;
  1776. }
  1777. if (lat) {
  1778. spin_lock(&unit->latencies.lock);
  1779. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1780. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1781. lat->counter++;
  1782. spin_unlock(&unit->latencies.lock);
  1783. }
  1784. }
  1785. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1786. sizeof(blktrc));
  1787. }
  1788. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1789. {
  1790. struct scsi_cmnd *scpnt;
  1791. struct fcp_resp_with_ext *fcp_rsp;
  1792. unsigned long flags;
  1793. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1794. scpnt = req->data;
  1795. if (unlikely(!scpnt)) {
  1796. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1797. return;
  1798. }
  1799. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1800. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1801. goto skip_fsfstatus;
  1802. }
  1803. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1804. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1805. zfcp_fsf_req_trace(req, scpnt);
  1806. skip_fsfstatus:
  1807. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1808. scpnt->host_scribble = NULL;
  1809. (scpnt->scsi_done) (scpnt);
  1810. /*
  1811. * We must hold this lock until scsi_done has been called.
  1812. * Otherwise we may call scsi_done after abort regarding this
  1813. * command has completed.
  1814. * Note: scsi_done must not block!
  1815. */
  1816. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1817. }
  1818. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1819. {
  1820. struct fcp_resp_with_ext *fcp_rsp;
  1821. struct fcp_resp_rsp_info *rsp_info;
  1822. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1823. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1824. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1825. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1826. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1827. }
  1828. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1829. {
  1830. struct zfcp_unit *unit;
  1831. struct fsf_qtcb_header *header = &req->qtcb->header;
  1832. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1833. unit = req->data;
  1834. else
  1835. unit = req->unit;
  1836. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1837. goto skip_fsfstatus;
  1838. switch (header->fsf_status) {
  1839. case FSF_HANDLE_MISMATCH:
  1840. case FSF_PORT_HANDLE_NOT_VALID:
  1841. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1842. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1843. break;
  1844. case FSF_FCPLUN_NOT_VALID:
  1845. case FSF_LUN_HANDLE_NOT_VALID:
  1846. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1847. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1848. break;
  1849. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1850. zfcp_fsf_class_not_supp(req);
  1851. break;
  1852. case FSF_ACCESS_DENIED:
  1853. zfcp_fsf_access_denied_unit(req, unit);
  1854. break;
  1855. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1856. dev_err(&req->adapter->ccw_device->dev,
  1857. "Incorrect direction %d, unit 0x%016Lx on port "
  1858. "0x%016Lx closed\n",
  1859. req->qtcb->bottom.io.data_direction,
  1860. (unsigned long long)unit->fcp_lun,
  1861. (unsigned long long)unit->port->wwpn);
  1862. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1863. req);
  1864. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1865. break;
  1866. case FSF_CMND_LENGTH_NOT_VALID:
  1867. dev_err(&req->adapter->ccw_device->dev,
  1868. "Incorrect CDB length %d, unit 0x%016Lx on "
  1869. "port 0x%016Lx closed\n",
  1870. req->qtcb->bottom.io.fcp_cmnd_length,
  1871. (unsigned long long)unit->fcp_lun,
  1872. (unsigned long long)unit->port->wwpn);
  1873. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1874. req);
  1875. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1876. break;
  1877. case FSF_PORT_BOXED:
  1878. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1879. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1880. break;
  1881. case FSF_LUN_BOXED:
  1882. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1883. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1884. break;
  1885. case FSF_ADAPTER_STATUS_AVAILABLE:
  1886. if (header->fsf_status_qual.word[0] ==
  1887. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1888. zfcp_fc_test_link(unit->port);
  1889. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1890. break;
  1891. }
  1892. skip_fsfstatus:
  1893. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1894. zfcp_fsf_send_fcp_ctm_handler(req);
  1895. else {
  1896. zfcp_fsf_send_fcp_command_task_handler(req);
  1897. req->unit = NULL;
  1898. put_device(&unit->dev);
  1899. }
  1900. }
  1901. /**
  1902. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1903. * @unit: unit where command is sent to
  1904. * @scsi_cmnd: scsi command to be sent
  1905. */
  1906. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1907. struct scsi_cmnd *scsi_cmnd)
  1908. {
  1909. struct zfcp_fsf_req *req;
  1910. struct fcp_cmnd *fcp_cmnd;
  1911. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1912. int real_bytes, retval = -EIO;
  1913. struct zfcp_adapter *adapter = unit->port->adapter;
  1914. struct zfcp_qdio *qdio = adapter->qdio;
  1915. if (unlikely(!(atomic_read(&unit->status) &
  1916. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1917. return -EBUSY;
  1918. spin_lock(&qdio->req_q_lock);
  1919. if (atomic_read(&qdio->req_q.count) <= 0) {
  1920. atomic_inc(&qdio->req_q_full);
  1921. goto out;
  1922. }
  1923. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1924. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1925. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1926. sbtype, adapter->pool.scsi_req);
  1927. if (IS_ERR(req)) {
  1928. retval = PTR_ERR(req);
  1929. goto out;
  1930. }
  1931. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1932. req->unit = unit;
  1933. req->data = scsi_cmnd;
  1934. req->handler = zfcp_fsf_send_fcp_command_handler;
  1935. req->qtcb->header.lun_handle = unit->handle;
  1936. req->qtcb->header.port_handle = unit->port->handle;
  1937. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1938. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1939. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1940. /*
  1941. * set depending on data direction:
  1942. * data direction bits in SBALE (SB Type)
  1943. * data direction bits in QTCB
  1944. */
  1945. switch (scsi_cmnd->sc_data_direction) {
  1946. case DMA_NONE:
  1947. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1948. break;
  1949. case DMA_FROM_DEVICE:
  1950. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1951. break;
  1952. case DMA_TO_DEVICE:
  1953. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1954. break;
  1955. case DMA_BIDIRECTIONAL:
  1956. goto failed_scsi_cmnd;
  1957. }
  1958. get_device(&unit->dev);
  1959. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1960. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1961. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1962. scsi_sglist(scsi_cmnd),
  1963. ZFCP_FSF_MAX_SBALS_PER_REQ);
  1964. if (unlikely(real_bytes < 0)) {
  1965. if (req->qdio_req.sbal_number >= ZFCP_FSF_MAX_SBALS_PER_REQ) {
  1966. dev_err(&adapter->ccw_device->dev,
  1967. "Oversize data package, unit 0x%016Lx "
  1968. "on port 0x%016Lx closed\n",
  1969. (unsigned long long)unit->fcp_lun,
  1970. (unsigned long long)unit->port->wwpn);
  1971. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  1972. retval = -EINVAL;
  1973. }
  1974. goto failed_scsi_cmnd;
  1975. }
  1976. retval = zfcp_fsf_req_send(req);
  1977. if (unlikely(retval))
  1978. goto failed_scsi_cmnd;
  1979. goto out;
  1980. failed_scsi_cmnd:
  1981. put_device(&unit->dev);
  1982. zfcp_fsf_req_free(req);
  1983. scsi_cmnd->host_scribble = NULL;
  1984. out:
  1985. spin_unlock(&qdio->req_q_lock);
  1986. return retval;
  1987. }
  1988. /**
  1989. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1990. * @unit: pointer to struct zfcp_unit
  1991. * @tm_flags: unsigned byte for task management flags
  1992. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1993. */
  1994. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  1995. {
  1996. struct zfcp_fsf_req *req = NULL;
  1997. struct fcp_cmnd *fcp_cmnd;
  1998. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  1999. if (unlikely(!(atomic_read(&unit->status) &
  2000. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2001. return NULL;
  2002. spin_lock_bh(&qdio->req_q_lock);
  2003. if (zfcp_qdio_sbal_get(qdio))
  2004. goto out;
  2005. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2006. SBAL_FLAGS0_TYPE_WRITE,
  2007. qdio->adapter->pool.scsi_req);
  2008. if (IS_ERR(req)) {
  2009. req = NULL;
  2010. goto out;
  2011. }
  2012. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2013. req->data = unit;
  2014. req->handler = zfcp_fsf_send_fcp_command_handler;
  2015. req->qtcb->header.lun_handle = unit->handle;
  2016. req->qtcb->header.port_handle = unit->port->handle;
  2017. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2018. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2019. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2020. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2021. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2022. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2023. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2024. if (!zfcp_fsf_req_send(req))
  2025. goto out;
  2026. zfcp_fsf_req_free(req);
  2027. req = NULL;
  2028. out:
  2029. spin_unlock_bh(&qdio->req_q_lock);
  2030. return req;
  2031. }
  2032. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2033. {
  2034. }
  2035. /**
  2036. * zfcp_fsf_control_file - control file upload/download
  2037. * @adapter: pointer to struct zfcp_adapter
  2038. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2039. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2040. */
  2041. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2042. struct zfcp_fsf_cfdc *fsf_cfdc)
  2043. {
  2044. struct zfcp_qdio *qdio = adapter->qdio;
  2045. struct zfcp_fsf_req *req = NULL;
  2046. struct fsf_qtcb_bottom_support *bottom;
  2047. int direction, retval = -EIO, bytes;
  2048. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2049. return ERR_PTR(-EOPNOTSUPP);
  2050. switch (fsf_cfdc->command) {
  2051. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2052. direction = SBAL_FLAGS0_TYPE_WRITE;
  2053. break;
  2054. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2055. direction = SBAL_FLAGS0_TYPE_READ;
  2056. break;
  2057. default:
  2058. return ERR_PTR(-EINVAL);
  2059. }
  2060. spin_lock_bh(&qdio->req_q_lock);
  2061. if (zfcp_qdio_sbal_get(qdio))
  2062. goto out;
  2063. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2064. if (IS_ERR(req)) {
  2065. retval = -EPERM;
  2066. goto out;
  2067. }
  2068. req->handler = zfcp_fsf_control_file_handler;
  2069. bottom = &req->qtcb->bottom.support;
  2070. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2071. bottom->option = fsf_cfdc->option;
  2072. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  2073. fsf_cfdc->sg,
  2074. ZFCP_FSF_MAX_SBALS_PER_REQ);
  2075. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2076. zfcp_fsf_req_free(req);
  2077. goto out;
  2078. }
  2079. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2080. retval = zfcp_fsf_req_send(req);
  2081. out:
  2082. spin_unlock_bh(&qdio->req_q_lock);
  2083. if (!retval) {
  2084. wait_for_completion(&req->completion);
  2085. return req;
  2086. }
  2087. return ERR_PTR(retval);
  2088. }
  2089. /**
  2090. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2091. * @adapter: pointer to struct zfcp_adapter
  2092. * @sbal_idx: response queue index of SBAL to be processed
  2093. */
  2094. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2095. {
  2096. struct zfcp_adapter *adapter = qdio->adapter;
  2097. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2098. struct qdio_buffer_element *sbale;
  2099. struct zfcp_fsf_req *fsf_req;
  2100. unsigned long req_id;
  2101. int idx;
  2102. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2103. sbale = &sbal->element[idx];
  2104. req_id = (unsigned long) sbale->addr;
  2105. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2106. if (!fsf_req)
  2107. /*
  2108. * Unknown request means that we have potentially memory
  2109. * corruption and must stop the machine immediately.
  2110. */
  2111. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2112. req_id, dev_name(&adapter->ccw_device->dev));
  2113. fsf_req->qdio_req.sbal_response = sbal_idx;
  2114. fsf_req->qdio_req.qdio_inb_usage =
  2115. atomic_read(&qdio->resp_q.count);
  2116. zfcp_fsf_req_complete(fsf_req);
  2117. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2118. break;
  2119. }
  2120. }