zfcp_fsf.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  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 & ZFCP_FSF_TIMER_INT_MASK;
  451. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  452. (u16)FSF_STATUS_READS_RECOM);
  453. if (fc_host_permanent_port_name(shost) == -1)
  454. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  455. switch (bottom->fc_topology) {
  456. case FSF_TOPO_P2P:
  457. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  458. adapter->peer_wwpn = plogi->fl_wwpn;
  459. adapter->peer_wwnn = plogi->fl_wwnn;
  460. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  461. break;
  462. case FSF_TOPO_FABRIC:
  463. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  464. break;
  465. case FSF_TOPO_AL:
  466. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  467. /* fall through */
  468. default:
  469. dev_err(&adapter->ccw_device->dev,
  470. "Unknown or unsupported arbitrated loop "
  471. "fibre channel topology detected\n");
  472. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  473. return -EIO;
  474. }
  475. return 0;
  476. }
  477. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  478. {
  479. struct zfcp_adapter *adapter = req->adapter;
  480. struct fsf_qtcb *qtcb = req->qtcb;
  481. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  482. struct Scsi_Host *shost = adapter->scsi_host;
  483. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  484. return;
  485. adapter->fsf_lic_version = bottom->lic_version;
  486. adapter->adapter_features = bottom->adapter_features;
  487. adapter->connection_features = bottom->connection_features;
  488. adapter->peer_wwpn = 0;
  489. adapter->peer_wwnn = 0;
  490. adapter->peer_d_id = 0;
  491. switch (qtcb->header.fsf_status) {
  492. case FSF_GOOD:
  493. if (zfcp_fsf_exchange_config_evaluate(req))
  494. return;
  495. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  496. dev_err(&adapter->ccw_device->dev,
  497. "FCP adapter maximum QTCB size (%d bytes) "
  498. "is too small\n",
  499. bottom->max_qtcb_size);
  500. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  501. return;
  502. }
  503. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  504. &adapter->status);
  505. break;
  506. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  507. fc_host_node_name(shost) = 0;
  508. fc_host_port_name(shost) = 0;
  509. fc_host_port_id(shost) = 0;
  510. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  511. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  512. adapter->hydra_version = 0;
  513. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  514. &adapter->status);
  515. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  516. &qtcb->header.fsf_status_qual.link_down_info);
  517. break;
  518. default:
  519. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  520. return;
  521. }
  522. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  523. adapter->hardware_version = bottom->hardware_version;
  524. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. EBCASC(fc_host_serial_number(shost),
  527. min(FC_SERIAL_NUMBER_SIZE, 17));
  528. }
  529. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  530. dev_err(&adapter->ccw_device->dev,
  531. "The FCP adapter only supports newer "
  532. "control block versions\n");
  533. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  534. return;
  535. }
  536. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  537. dev_err(&adapter->ccw_device->dev,
  538. "The FCP adapter only supports older "
  539. "control block versions\n");
  540. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  541. }
  542. }
  543. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  544. {
  545. struct zfcp_adapter *adapter = req->adapter;
  546. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  547. struct Scsi_Host *shost = adapter->scsi_host;
  548. if (req->data)
  549. memcpy(req->data, bottom, sizeof(*bottom));
  550. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  551. fc_host_permanent_port_name(shost) = bottom->wwpn;
  552. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  553. } else
  554. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  555. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  556. fc_host_supported_speeds(shost) = bottom->supported_speed;
  557. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  558. FC_FC4_LIST_SIZE);
  559. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  560. FC_FC4_LIST_SIZE);
  561. }
  562. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  563. {
  564. struct fsf_qtcb *qtcb = req->qtcb;
  565. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  566. return;
  567. switch (qtcb->header.fsf_status) {
  568. case FSF_GOOD:
  569. zfcp_fsf_exchange_port_evaluate(req);
  570. break;
  571. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  574. &qtcb->header.fsf_status_qual.link_down_info);
  575. break;
  576. }
  577. }
  578. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  579. {
  580. struct zfcp_fsf_req *req;
  581. if (likely(pool))
  582. req = mempool_alloc(pool, GFP_ATOMIC);
  583. else
  584. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  585. if (unlikely(!req))
  586. return NULL;
  587. memset(req, 0, sizeof(*req));
  588. req->pool = pool;
  589. return req;
  590. }
  591. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  592. {
  593. struct fsf_qtcb *qtcb;
  594. if (likely(pool))
  595. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  596. else
  597. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  598. if (unlikely(!qtcb))
  599. return NULL;
  600. memset(qtcb, 0, sizeof(*qtcb));
  601. return qtcb;
  602. }
  603. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  604. u32 fsf_cmd, u32 sbtype,
  605. mempool_t *pool)
  606. {
  607. struct zfcp_adapter *adapter = qdio->adapter;
  608. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  609. if (unlikely(!req))
  610. return ERR_PTR(-ENOMEM);
  611. if (adapter->req_no == 0)
  612. adapter->req_no++;
  613. INIT_LIST_HEAD(&req->list);
  614. init_timer(&req->timer);
  615. init_completion(&req->completion);
  616. req->adapter = adapter;
  617. req->fsf_command = fsf_cmd;
  618. req->req_id = adapter->req_no;
  619. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  620. if (likely(pool))
  621. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  622. else
  623. req->qtcb = zfcp_qtcb_alloc(NULL);
  624. if (unlikely(!req->qtcb)) {
  625. zfcp_fsf_req_free(req);
  626. return ERR_PTR(-ENOMEM);
  627. }
  628. req->seq_no = adapter->fsf_req_seq_no;
  629. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  630. req->qtcb->prefix.req_id = req->req_id;
  631. req->qtcb->prefix.ulp_info = 26;
  632. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  633. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  634. req->qtcb->header.req_handle = req->req_id;
  635. req->qtcb->header.fsf_command = req->fsf_command;
  636. }
  637. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  638. req->qtcb, sizeof(struct fsf_qtcb));
  639. return req;
  640. }
  641. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  642. {
  643. struct zfcp_adapter *adapter = req->adapter;
  644. struct zfcp_qdio *qdio = adapter->qdio;
  645. int with_qtcb = (req->qtcb != NULL);
  646. int req_id = req->req_id;
  647. zfcp_reqlist_add(adapter->req_list, req);
  648. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  649. req->issued = get_clock();
  650. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  651. del_timer(&req->timer);
  652. /* lookup request again, list might have changed */
  653. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  654. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  655. return -EIO;
  656. }
  657. /* Don't increase for unsolicited status */
  658. if (with_qtcb)
  659. adapter->fsf_req_seq_no++;
  660. adapter->req_no++;
  661. return 0;
  662. }
  663. /**
  664. * zfcp_fsf_status_read - send status read request
  665. * @adapter: pointer to struct zfcp_adapter
  666. * @req_flags: request flags
  667. * Returns: 0 on success, ERROR otherwise
  668. */
  669. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  670. {
  671. struct zfcp_adapter *adapter = qdio->adapter;
  672. struct zfcp_fsf_req *req;
  673. struct fsf_status_read_buffer *sr_buf;
  674. int retval = -EIO;
  675. spin_lock_bh(&qdio->req_q_lock);
  676. if (zfcp_qdio_sbal_get(qdio))
  677. goto out;
  678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  679. adapter->pool.status_read_req);
  680. if (IS_ERR(req)) {
  681. retval = PTR_ERR(req);
  682. goto out;
  683. }
  684. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  685. if (!sr_buf) {
  686. retval = -ENOMEM;
  687. goto failed_buf;
  688. }
  689. memset(sr_buf, 0, sizeof(*sr_buf));
  690. req->data = sr_buf;
  691. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  692. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  693. retval = zfcp_fsf_req_send(req);
  694. if (retval)
  695. goto failed_req_send;
  696. goto out;
  697. failed_req_send:
  698. mempool_free(sr_buf, adapter->pool.status_read_data);
  699. failed_buf:
  700. zfcp_fsf_req_free(req);
  701. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  702. out:
  703. spin_unlock_bh(&qdio->req_q_lock);
  704. return retval;
  705. }
  706. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  707. {
  708. struct zfcp_unit *unit = req->data;
  709. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  710. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  711. return;
  712. switch (req->qtcb->header.fsf_status) {
  713. case FSF_PORT_HANDLE_NOT_VALID:
  714. if (fsq->word[0] == fsq->word[1]) {
  715. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  716. "fsafch1", req);
  717. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  718. }
  719. break;
  720. case FSF_LUN_HANDLE_NOT_VALID:
  721. if (fsq->word[0] == fsq->word[1]) {
  722. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  723. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  724. }
  725. break;
  726. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  727. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  728. break;
  729. case FSF_PORT_BOXED:
  730. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  731. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  732. break;
  733. case FSF_LUN_BOXED:
  734. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  735. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  736. break;
  737. case FSF_ADAPTER_STATUS_AVAILABLE:
  738. switch (fsq->word[0]) {
  739. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  740. zfcp_fc_test_link(unit->port);
  741. /* fall through */
  742. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  743. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  744. break;
  745. }
  746. break;
  747. case FSF_GOOD:
  748. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  749. break;
  750. }
  751. }
  752. /**
  753. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  754. * @old_req_id: unsigned long
  755. * @unit: pointer to struct zfcp_unit
  756. * Returns: pointer to struct zfcp_fsf_req
  757. */
  758. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  759. struct zfcp_unit *unit)
  760. {
  761. struct zfcp_fsf_req *req = NULL;
  762. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  763. spin_lock_bh(&qdio->req_q_lock);
  764. if (zfcp_qdio_sbal_get(qdio))
  765. goto out;
  766. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  767. SBAL_FLAGS0_TYPE_READ,
  768. qdio->adapter->pool.scsi_abort);
  769. if (IS_ERR(req)) {
  770. req = NULL;
  771. goto out;
  772. }
  773. if (unlikely(!(atomic_read(&unit->status) &
  774. ZFCP_STATUS_COMMON_UNBLOCKED)))
  775. goto out_error_free;
  776. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  777. req->data = unit;
  778. req->handler = zfcp_fsf_abort_fcp_command_handler;
  779. req->qtcb->header.lun_handle = unit->handle;
  780. req->qtcb->header.port_handle = unit->port->handle;
  781. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  782. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  783. if (!zfcp_fsf_req_send(req))
  784. goto out;
  785. out_error_free:
  786. zfcp_fsf_req_free(req);
  787. req = NULL;
  788. out:
  789. spin_unlock_bh(&qdio->req_q_lock);
  790. return req;
  791. }
  792. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  793. {
  794. struct zfcp_adapter *adapter = req->adapter;
  795. struct zfcp_fsf_ct_els *ct = req->data;
  796. struct fsf_qtcb_header *header = &req->qtcb->header;
  797. ct->status = -EINVAL;
  798. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  799. goto skip_fsfstatus;
  800. switch (header->fsf_status) {
  801. case FSF_GOOD:
  802. zfcp_dbf_san_ct_response(req);
  803. ct->status = 0;
  804. break;
  805. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  806. zfcp_fsf_class_not_supp(req);
  807. break;
  808. case FSF_ADAPTER_STATUS_AVAILABLE:
  809. switch (header->fsf_status_qual.word[0]){
  810. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  811. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  812. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  813. break;
  814. }
  815. break;
  816. case FSF_ACCESS_DENIED:
  817. break;
  818. case FSF_PORT_BOXED:
  819. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  820. break;
  821. case FSF_PORT_HANDLE_NOT_VALID:
  822. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  823. /* fall through */
  824. case FSF_GENERIC_COMMAND_REJECTED:
  825. case FSF_PAYLOAD_SIZE_MISMATCH:
  826. case FSF_REQUEST_SIZE_TOO_LARGE:
  827. case FSF_RESPONSE_SIZE_TOO_LARGE:
  828. case FSF_SBAL_MISMATCH:
  829. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  830. break;
  831. }
  832. skip_fsfstatus:
  833. if (ct->handler)
  834. ct->handler(ct->handler_data);
  835. }
  836. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  837. struct zfcp_qdio_req *q_req,
  838. struct scatterlist *sg_req,
  839. struct scatterlist *sg_resp)
  840. {
  841. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  842. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  843. zfcp_qdio_set_sbale_last(qdio, q_req);
  844. }
  845. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  846. struct scatterlist *sg_req,
  847. struct scatterlist *sg_resp)
  848. {
  849. struct zfcp_adapter *adapter = req->adapter;
  850. u32 feat = adapter->adapter_features;
  851. int bytes;
  852. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  853. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  854. !zfcp_qdio_sg_one_sbale(sg_resp))
  855. return -EOPNOTSUPP;
  856. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  857. sg_req, sg_resp);
  858. return 0;
  859. }
  860. /* use single, unchained SBAL if it can hold the request */
  861. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  862. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  863. sg_req, sg_resp);
  864. return 0;
  865. }
  866. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
  867. if (bytes <= 0)
  868. return -EIO;
  869. req->qtcb->bottom.support.req_buf_length = bytes;
  870. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  871. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  872. sg_resp);
  873. req->qtcb->bottom.support.resp_buf_length = bytes;
  874. if (bytes <= 0)
  875. return -EIO;
  876. return 0;
  877. }
  878. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  879. struct scatterlist *sg_req,
  880. struct scatterlist *sg_resp,
  881. unsigned int timeout)
  882. {
  883. int ret;
  884. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  885. if (ret)
  886. return ret;
  887. /* common settings for ct/gs and els requests */
  888. if (timeout > 255)
  889. timeout = 255; /* max value accepted by hardware */
  890. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  891. req->qtcb->bottom.support.timeout = timeout;
  892. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  893. return 0;
  894. }
  895. /**
  896. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  897. * @ct: pointer to struct zfcp_send_ct with data for request
  898. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  899. */
  900. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  901. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  902. unsigned int timeout)
  903. {
  904. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  905. struct zfcp_fsf_req *req;
  906. int ret = -EIO;
  907. spin_lock_bh(&qdio->req_q_lock);
  908. if (zfcp_qdio_sbal_get(qdio))
  909. goto out;
  910. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  911. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  912. if (IS_ERR(req)) {
  913. ret = PTR_ERR(req);
  914. goto out;
  915. }
  916. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  917. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  918. if (ret)
  919. goto failed_send;
  920. req->handler = zfcp_fsf_send_ct_handler;
  921. req->qtcb->header.port_handle = wka_port->handle;
  922. req->data = ct;
  923. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  924. ret = zfcp_fsf_req_send(req);
  925. if (ret)
  926. goto failed_send;
  927. goto out;
  928. failed_send:
  929. zfcp_fsf_req_free(req);
  930. out:
  931. spin_unlock_bh(&qdio->req_q_lock);
  932. return ret;
  933. }
  934. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  935. {
  936. struct zfcp_fsf_ct_els *send_els = req->data;
  937. struct zfcp_port *port = send_els->port;
  938. struct fsf_qtcb_header *header = &req->qtcb->header;
  939. send_els->status = -EINVAL;
  940. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  941. goto skip_fsfstatus;
  942. switch (header->fsf_status) {
  943. case FSF_GOOD:
  944. zfcp_dbf_san_els_response(req);
  945. send_els->status = 0;
  946. break;
  947. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  948. zfcp_fsf_class_not_supp(req);
  949. break;
  950. case FSF_ADAPTER_STATUS_AVAILABLE:
  951. switch (header->fsf_status_qual.word[0]){
  952. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  953. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  954. case FSF_SQ_RETRY_IF_POSSIBLE:
  955. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  956. break;
  957. }
  958. break;
  959. case FSF_ELS_COMMAND_REJECTED:
  960. case FSF_PAYLOAD_SIZE_MISMATCH:
  961. case FSF_REQUEST_SIZE_TOO_LARGE:
  962. case FSF_RESPONSE_SIZE_TOO_LARGE:
  963. break;
  964. case FSF_ACCESS_DENIED:
  965. if (port)
  966. zfcp_fsf_access_denied_port(req, port);
  967. break;
  968. case FSF_SBAL_MISMATCH:
  969. /* should never occure, avoided in zfcp_fsf_send_els */
  970. /* fall through */
  971. default:
  972. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  973. break;
  974. }
  975. skip_fsfstatus:
  976. if (send_els->handler)
  977. send_els->handler(send_els->handler_data);
  978. }
  979. /**
  980. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  981. * @els: pointer to struct zfcp_send_els with data for the command
  982. */
  983. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  984. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  985. {
  986. struct zfcp_fsf_req *req;
  987. struct zfcp_qdio *qdio = adapter->qdio;
  988. int ret = -EIO;
  989. spin_lock_bh(&qdio->req_q_lock);
  990. if (zfcp_qdio_sbal_get(qdio))
  991. goto out;
  992. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  993. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  994. if (IS_ERR(req)) {
  995. ret = PTR_ERR(req);
  996. goto out;
  997. }
  998. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  999. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1000. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1001. if (ret)
  1002. goto failed_send;
  1003. hton24(req->qtcb->bottom.support.d_id, d_id);
  1004. req->handler = zfcp_fsf_send_els_handler;
  1005. req->data = els;
  1006. zfcp_dbf_san_els_request(req);
  1007. ret = zfcp_fsf_req_send(req);
  1008. if (ret)
  1009. goto failed_send;
  1010. goto out;
  1011. failed_send:
  1012. zfcp_fsf_req_free(req);
  1013. out:
  1014. spin_unlock_bh(&qdio->req_q_lock);
  1015. return ret;
  1016. }
  1017. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1018. {
  1019. struct zfcp_fsf_req *req;
  1020. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1021. int retval = -EIO;
  1022. spin_lock_bh(&qdio->req_q_lock);
  1023. if (zfcp_qdio_sbal_get(qdio))
  1024. goto out;
  1025. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1026. SBAL_FLAGS0_TYPE_READ,
  1027. qdio->adapter->pool.erp_req);
  1028. if (IS_ERR(req)) {
  1029. retval = PTR_ERR(req);
  1030. goto out;
  1031. }
  1032. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1033. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1034. req->qtcb->bottom.config.feature_selection =
  1035. FSF_FEATURE_CFDC |
  1036. FSF_FEATURE_LUN_SHARING |
  1037. FSF_FEATURE_NOTIFICATION_LOST |
  1038. FSF_FEATURE_UPDATE_ALERT;
  1039. req->erp_action = erp_action;
  1040. req->handler = zfcp_fsf_exchange_config_data_handler;
  1041. erp_action->fsf_req_id = req->req_id;
  1042. zfcp_fsf_start_erp_timer(req);
  1043. retval = zfcp_fsf_req_send(req);
  1044. if (retval) {
  1045. zfcp_fsf_req_free(req);
  1046. erp_action->fsf_req_id = 0;
  1047. }
  1048. out:
  1049. spin_unlock_bh(&qdio->req_q_lock);
  1050. return retval;
  1051. }
  1052. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1053. struct fsf_qtcb_bottom_config *data)
  1054. {
  1055. struct zfcp_fsf_req *req = NULL;
  1056. int retval = -EIO;
  1057. spin_lock_bh(&qdio->req_q_lock);
  1058. if (zfcp_qdio_sbal_get(qdio))
  1059. goto out_unlock;
  1060. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1061. SBAL_FLAGS0_TYPE_READ, NULL);
  1062. if (IS_ERR(req)) {
  1063. retval = PTR_ERR(req);
  1064. goto out_unlock;
  1065. }
  1066. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1067. req->handler = zfcp_fsf_exchange_config_data_handler;
  1068. req->qtcb->bottom.config.feature_selection =
  1069. FSF_FEATURE_CFDC |
  1070. FSF_FEATURE_LUN_SHARING |
  1071. FSF_FEATURE_NOTIFICATION_LOST |
  1072. FSF_FEATURE_UPDATE_ALERT;
  1073. if (data)
  1074. req->data = data;
  1075. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1076. retval = zfcp_fsf_req_send(req);
  1077. spin_unlock_bh(&qdio->req_q_lock);
  1078. if (!retval)
  1079. wait_for_completion(&req->completion);
  1080. zfcp_fsf_req_free(req);
  1081. return retval;
  1082. out_unlock:
  1083. spin_unlock_bh(&qdio->req_q_lock);
  1084. return retval;
  1085. }
  1086. /**
  1087. * zfcp_fsf_exchange_port_data - request information about local port
  1088. * @erp_action: ERP action for the adapter for which port data is requested
  1089. * Returns: 0 on success, error otherwise
  1090. */
  1091. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1092. {
  1093. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1094. struct zfcp_fsf_req *req;
  1095. int retval = -EIO;
  1096. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1097. return -EOPNOTSUPP;
  1098. spin_lock_bh(&qdio->req_q_lock);
  1099. if (zfcp_qdio_sbal_get(qdio))
  1100. goto out;
  1101. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1102. SBAL_FLAGS0_TYPE_READ,
  1103. qdio->adapter->pool.erp_req);
  1104. if (IS_ERR(req)) {
  1105. retval = PTR_ERR(req);
  1106. goto out;
  1107. }
  1108. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1109. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1110. req->handler = zfcp_fsf_exchange_port_data_handler;
  1111. req->erp_action = erp_action;
  1112. erp_action->fsf_req_id = req->req_id;
  1113. zfcp_fsf_start_erp_timer(req);
  1114. retval = zfcp_fsf_req_send(req);
  1115. if (retval) {
  1116. zfcp_fsf_req_free(req);
  1117. erp_action->fsf_req_id = 0;
  1118. }
  1119. out:
  1120. spin_unlock_bh(&qdio->req_q_lock);
  1121. return retval;
  1122. }
  1123. /**
  1124. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1125. * @qdio: pointer to struct zfcp_qdio
  1126. * @data: pointer to struct fsf_qtcb_bottom_port
  1127. * Returns: 0 on success, error otherwise
  1128. */
  1129. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1130. struct fsf_qtcb_bottom_port *data)
  1131. {
  1132. struct zfcp_fsf_req *req = NULL;
  1133. int retval = -EIO;
  1134. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1135. return -EOPNOTSUPP;
  1136. spin_lock_bh(&qdio->req_q_lock);
  1137. if (zfcp_qdio_sbal_get(qdio))
  1138. goto out_unlock;
  1139. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1140. SBAL_FLAGS0_TYPE_READ, NULL);
  1141. if (IS_ERR(req)) {
  1142. retval = PTR_ERR(req);
  1143. goto out_unlock;
  1144. }
  1145. if (data)
  1146. req->data = data;
  1147. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1148. req->handler = zfcp_fsf_exchange_port_data_handler;
  1149. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1150. retval = zfcp_fsf_req_send(req);
  1151. spin_unlock_bh(&qdio->req_q_lock);
  1152. if (!retval)
  1153. wait_for_completion(&req->completion);
  1154. zfcp_fsf_req_free(req);
  1155. return retval;
  1156. out_unlock:
  1157. spin_unlock_bh(&qdio->req_q_lock);
  1158. return retval;
  1159. }
  1160. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1161. {
  1162. struct zfcp_port *port = req->data;
  1163. struct fsf_qtcb_header *header = &req->qtcb->header;
  1164. struct fc_els_flogi *plogi;
  1165. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1166. goto out;
  1167. switch (header->fsf_status) {
  1168. case FSF_PORT_ALREADY_OPEN:
  1169. break;
  1170. case FSF_ACCESS_DENIED:
  1171. zfcp_fsf_access_denied_port(req, port);
  1172. break;
  1173. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1174. dev_warn(&req->adapter->ccw_device->dev,
  1175. "Not enough FCP adapter resources to open "
  1176. "remote port 0x%016Lx\n",
  1177. (unsigned long long)port->wwpn);
  1178. zfcp_erp_port_failed(port, "fsoph_1", req);
  1179. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1180. break;
  1181. case FSF_ADAPTER_STATUS_AVAILABLE:
  1182. switch (header->fsf_status_qual.word[0]) {
  1183. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1184. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1185. case FSF_SQ_NO_RETRY_POSSIBLE:
  1186. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1187. break;
  1188. }
  1189. break;
  1190. case FSF_GOOD:
  1191. port->handle = header->port_handle;
  1192. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1193. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1194. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1195. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1196. &port->status);
  1197. /* check whether D_ID has changed during open */
  1198. /*
  1199. * FIXME: This check is not airtight, as the FCP channel does
  1200. * not monitor closures of target port connections caused on
  1201. * the remote side. Thus, they might miss out on invalidating
  1202. * locally cached WWPNs (and other N_Port parameters) of gone
  1203. * target ports. So, our heroic attempt to make things safe
  1204. * could be undermined by 'open port' response data tagged with
  1205. * obsolete WWPNs. Another reason to monitor potential
  1206. * connection closures ourself at least (by interpreting
  1207. * incoming ELS' and unsolicited status). It just crosses my
  1208. * mind that one should be able to cross-check by means of
  1209. * another GID_PN straight after a port has been opened.
  1210. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1211. */
  1212. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1213. if (req->qtcb->bottom.support.els1_length >=
  1214. FSF_PLOGI_MIN_LEN)
  1215. zfcp_fc_plogi_evaluate(port, plogi);
  1216. break;
  1217. case FSF_UNKNOWN_OP_SUBTYPE:
  1218. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1219. break;
  1220. }
  1221. out:
  1222. put_device(&port->dev);
  1223. }
  1224. /**
  1225. * zfcp_fsf_open_port - create and send open port request
  1226. * @erp_action: pointer to struct zfcp_erp_action
  1227. * Returns: 0 on success, error otherwise
  1228. */
  1229. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1230. {
  1231. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1232. struct zfcp_port *port = erp_action->port;
  1233. struct zfcp_fsf_req *req;
  1234. int retval = -EIO;
  1235. spin_lock_bh(&qdio->req_q_lock);
  1236. if (zfcp_qdio_sbal_get(qdio))
  1237. goto out;
  1238. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1239. SBAL_FLAGS0_TYPE_READ,
  1240. qdio->adapter->pool.erp_req);
  1241. if (IS_ERR(req)) {
  1242. retval = PTR_ERR(req);
  1243. goto out;
  1244. }
  1245. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1246. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1247. req->handler = zfcp_fsf_open_port_handler;
  1248. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1249. req->data = port;
  1250. req->erp_action = erp_action;
  1251. erp_action->fsf_req_id = req->req_id;
  1252. get_device(&port->dev);
  1253. zfcp_fsf_start_erp_timer(req);
  1254. retval = zfcp_fsf_req_send(req);
  1255. if (retval) {
  1256. zfcp_fsf_req_free(req);
  1257. erp_action->fsf_req_id = 0;
  1258. put_device(&port->dev);
  1259. }
  1260. out:
  1261. spin_unlock_bh(&qdio->req_q_lock);
  1262. return retval;
  1263. }
  1264. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1265. {
  1266. struct zfcp_port *port = req->data;
  1267. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1268. return;
  1269. switch (req->qtcb->header.fsf_status) {
  1270. case FSF_PORT_HANDLE_NOT_VALID:
  1271. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1272. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1273. break;
  1274. case FSF_ADAPTER_STATUS_AVAILABLE:
  1275. break;
  1276. case FSF_GOOD:
  1277. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1278. ZFCP_STATUS_COMMON_OPEN,
  1279. ZFCP_CLEAR);
  1280. break;
  1281. }
  1282. }
  1283. /**
  1284. * zfcp_fsf_close_port - create and send close port request
  1285. * @erp_action: pointer to struct zfcp_erp_action
  1286. * Returns: 0 on success, error otherwise
  1287. */
  1288. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1289. {
  1290. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1291. struct zfcp_fsf_req *req;
  1292. int retval = -EIO;
  1293. spin_lock_bh(&qdio->req_q_lock);
  1294. if (zfcp_qdio_sbal_get(qdio))
  1295. goto out;
  1296. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1297. SBAL_FLAGS0_TYPE_READ,
  1298. qdio->adapter->pool.erp_req);
  1299. if (IS_ERR(req)) {
  1300. retval = PTR_ERR(req);
  1301. goto out;
  1302. }
  1303. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1304. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1305. req->handler = zfcp_fsf_close_port_handler;
  1306. req->data = erp_action->port;
  1307. req->erp_action = erp_action;
  1308. req->qtcb->header.port_handle = erp_action->port->handle;
  1309. erp_action->fsf_req_id = req->req_id;
  1310. zfcp_fsf_start_erp_timer(req);
  1311. retval = zfcp_fsf_req_send(req);
  1312. if (retval) {
  1313. zfcp_fsf_req_free(req);
  1314. erp_action->fsf_req_id = 0;
  1315. }
  1316. out:
  1317. spin_unlock_bh(&qdio->req_q_lock);
  1318. return retval;
  1319. }
  1320. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1321. {
  1322. struct zfcp_fc_wka_port *wka_port = req->data;
  1323. struct fsf_qtcb_header *header = &req->qtcb->header;
  1324. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1325. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1326. goto out;
  1327. }
  1328. switch (header->fsf_status) {
  1329. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1330. dev_warn(&req->adapter->ccw_device->dev,
  1331. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1332. /* fall through */
  1333. case FSF_ADAPTER_STATUS_AVAILABLE:
  1334. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1335. /* fall through */
  1336. case FSF_ACCESS_DENIED:
  1337. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1338. break;
  1339. case FSF_GOOD:
  1340. wka_port->handle = header->port_handle;
  1341. /* fall through */
  1342. case FSF_PORT_ALREADY_OPEN:
  1343. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1344. }
  1345. out:
  1346. wake_up(&wka_port->completion_wq);
  1347. }
  1348. /**
  1349. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1350. * @wka_port: pointer to struct zfcp_fc_wka_port
  1351. * Returns: 0 on success, error otherwise
  1352. */
  1353. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1354. {
  1355. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1356. struct zfcp_fsf_req *req;
  1357. int retval = -EIO;
  1358. spin_lock_bh(&qdio->req_q_lock);
  1359. if (zfcp_qdio_sbal_get(qdio))
  1360. goto out;
  1361. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1362. SBAL_FLAGS0_TYPE_READ,
  1363. qdio->adapter->pool.erp_req);
  1364. if (unlikely(IS_ERR(req))) {
  1365. retval = PTR_ERR(req);
  1366. goto out;
  1367. }
  1368. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1369. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1370. req->handler = zfcp_fsf_open_wka_port_handler;
  1371. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1372. req->data = wka_port;
  1373. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1374. retval = zfcp_fsf_req_send(req);
  1375. if (retval)
  1376. zfcp_fsf_req_free(req);
  1377. out:
  1378. spin_unlock_bh(&qdio->req_q_lock);
  1379. return retval;
  1380. }
  1381. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1382. {
  1383. struct zfcp_fc_wka_port *wka_port = req->data;
  1384. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1385. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1386. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1387. }
  1388. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1389. wake_up(&wka_port->completion_wq);
  1390. }
  1391. /**
  1392. * zfcp_fsf_close_wka_port - create and send close wka port request
  1393. * @wka_port: WKA port to open
  1394. * Returns: 0 on success, error otherwise
  1395. */
  1396. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1397. {
  1398. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1399. struct zfcp_fsf_req *req;
  1400. int retval = -EIO;
  1401. spin_lock_bh(&qdio->req_q_lock);
  1402. if (zfcp_qdio_sbal_get(qdio))
  1403. goto out;
  1404. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1405. SBAL_FLAGS0_TYPE_READ,
  1406. qdio->adapter->pool.erp_req);
  1407. if (unlikely(IS_ERR(req))) {
  1408. retval = PTR_ERR(req);
  1409. goto out;
  1410. }
  1411. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1412. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1413. req->handler = zfcp_fsf_close_wka_port_handler;
  1414. req->data = wka_port;
  1415. req->qtcb->header.port_handle = wka_port->handle;
  1416. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1417. retval = zfcp_fsf_req_send(req);
  1418. if (retval)
  1419. zfcp_fsf_req_free(req);
  1420. out:
  1421. spin_unlock_bh(&qdio->req_q_lock);
  1422. return retval;
  1423. }
  1424. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1425. {
  1426. struct zfcp_port *port = req->data;
  1427. struct fsf_qtcb_header *header = &req->qtcb->header;
  1428. struct zfcp_unit *unit;
  1429. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1430. return;
  1431. switch (header->fsf_status) {
  1432. case FSF_PORT_HANDLE_NOT_VALID:
  1433. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1434. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1435. break;
  1436. case FSF_ACCESS_DENIED:
  1437. zfcp_fsf_access_denied_port(req, port);
  1438. break;
  1439. case FSF_PORT_BOXED:
  1440. /* can't use generic zfcp_erp_modify_port_status because
  1441. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1442. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1443. read_lock(&port->unit_list_lock);
  1444. list_for_each_entry(unit, &port->unit_list, list)
  1445. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1446. &unit->status);
  1447. read_unlock(&port->unit_list_lock);
  1448. zfcp_erp_port_boxed(port, "fscpph2", req);
  1449. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1450. break;
  1451. case FSF_ADAPTER_STATUS_AVAILABLE:
  1452. switch (header->fsf_status_qual.word[0]) {
  1453. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1454. /* fall through */
  1455. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1456. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1457. break;
  1458. }
  1459. break;
  1460. case FSF_GOOD:
  1461. /* can't use generic zfcp_erp_modify_port_status because
  1462. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1463. */
  1464. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1465. read_lock(&port->unit_list_lock);
  1466. list_for_each_entry(unit, &port->unit_list, list)
  1467. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1468. &unit->status);
  1469. read_unlock(&port->unit_list_lock);
  1470. break;
  1471. }
  1472. }
  1473. /**
  1474. * zfcp_fsf_close_physical_port - close physical port
  1475. * @erp_action: pointer to struct zfcp_erp_action
  1476. * Returns: 0 on success
  1477. */
  1478. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1479. {
  1480. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1481. struct zfcp_fsf_req *req;
  1482. int retval = -EIO;
  1483. spin_lock_bh(&qdio->req_q_lock);
  1484. if (zfcp_qdio_sbal_get(qdio))
  1485. goto out;
  1486. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1487. SBAL_FLAGS0_TYPE_READ,
  1488. qdio->adapter->pool.erp_req);
  1489. if (IS_ERR(req)) {
  1490. retval = PTR_ERR(req);
  1491. goto out;
  1492. }
  1493. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1494. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1495. req->data = erp_action->port;
  1496. req->qtcb->header.port_handle = erp_action->port->handle;
  1497. req->erp_action = erp_action;
  1498. req->handler = zfcp_fsf_close_physical_port_handler;
  1499. erp_action->fsf_req_id = req->req_id;
  1500. zfcp_fsf_start_erp_timer(req);
  1501. retval = zfcp_fsf_req_send(req);
  1502. if (retval) {
  1503. zfcp_fsf_req_free(req);
  1504. erp_action->fsf_req_id = 0;
  1505. }
  1506. out:
  1507. spin_unlock_bh(&qdio->req_q_lock);
  1508. return retval;
  1509. }
  1510. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1511. {
  1512. struct zfcp_adapter *adapter = req->adapter;
  1513. struct zfcp_unit *unit = req->data;
  1514. struct fsf_qtcb_header *header = &req->qtcb->header;
  1515. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1516. struct fsf_queue_designator *queue_designator =
  1517. &header->fsf_status_qual.fsf_queue_designator;
  1518. int exclusive, readwrite;
  1519. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1520. return;
  1521. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1522. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1523. ZFCP_STATUS_UNIT_SHARED |
  1524. ZFCP_STATUS_UNIT_READONLY,
  1525. &unit->status);
  1526. switch (header->fsf_status) {
  1527. case FSF_PORT_HANDLE_NOT_VALID:
  1528. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1529. /* fall through */
  1530. case FSF_LUN_ALREADY_OPEN:
  1531. break;
  1532. case FSF_ACCESS_DENIED:
  1533. zfcp_fsf_access_denied_unit(req, unit);
  1534. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1535. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1536. break;
  1537. case FSF_PORT_BOXED:
  1538. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1539. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1540. break;
  1541. case FSF_LUN_SHARING_VIOLATION:
  1542. if (header->fsf_status_qual.word[0])
  1543. dev_warn(&adapter->ccw_device->dev,
  1544. "LUN 0x%Lx on port 0x%Lx is already in "
  1545. "use by CSS%d, MIF Image ID %x\n",
  1546. (unsigned long long)unit->fcp_lun,
  1547. (unsigned long long)unit->port->wwpn,
  1548. queue_designator->cssid,
  1549. queue_designator->hla);
  1550. else
  1551. zfcp_act_eval_err(adapter,
  1552. header->fsf_status_qual.word[2]);
  1553. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1554. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1555. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1556. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1557. break;
  1558. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1559. dev_warn(&adapter->ccw_device->dev,
  1560. "No handle is available for LUN "
  1561. "0x%016Lx on port 0x%016Lx\n",
  1562. (unsigned long long)unit->fcp_lun,
  1563. (unsigned long long)unit->port->wwpn);
  1564. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1565. /* fall through */
  1566. case FSF_INVALID_COMMAND_OPTION:
  1567. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1568. break;
  1569. case FSF_ADAPTER_STATUS_AVAILABLE:
  1570. switch (header->fsf_status_qual.word[0]) {
  1571. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1572. zfcp_fc_test_link(unit->port);
  1573. /* fall through */
  1574. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1575. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1576. break;
  1577. }
  1578. break;
  1579. case FSF_GOOD:
  1580. unit->handle = header->lun_handle;
  1581. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1582. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1583. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1584. !zfcp_ccw_priv_sch(adapter)) {
  1585. exclusive = (bottom->lun_access_info &
  1586. FSF_UNIT_ACCESS_EXCLUSIVE);
  1587. readwrite = (bottom->lun_access_info &
  1588. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1589. if (!exclusive)
  1590. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1591. &unit->status);
  1592. if (!readwrite) {
  1593. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1594. &unit->status);
  1595. dev_info(&adapter->ccw_device->dev,
  1596. "SCSI device at LUN 0x%016Lx on port "
  1597. "0x%016Lx opened read-only\n",
  1598. (unsigned long long)unit->fcp_lun,
  1599. (unsigned long long)unit->port->wwpn);
  1600. }
  1601. if (exclusive && !readwrite) {
  1602. dev_err(&adapter->ccw_device->dev,
  1603. "Exclusive read-only access not "
  1604. "supported (unit 0x%016Lx, "
  1605. "port 0x%016Lx)\n",
  1606. (unsigned long long)unit->fcp_lun,
  1607. (unsigned long long)unit->port->wwpn);
  1608. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1609. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1610. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1611. } else if (!exclusive && readwrite) {
  1612. dev_err(&adapter->ccw_device->dev,
  1613. "Shared read-write access not "
  1614. "supported (unit 0x%016Lx, port "
  1615. "0x%016Lx)\n",
  1616. (unsigned long long)unit->fcp_lun,
  1617. (unsigned long long)unit->port->wwpn);
  1618. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1619. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1620. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1621. }
  1622. }
  1623. break;
  1624. }
  1625. }
  1626. /**
  1627. * zfcp_fsf_open_unit - open unit
  1628. * @erp_action: pointer to struct zfcp_erp_action
  1629. * Returns: 0 on success, error otherwise
  1630. */
  1631. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1632. {
  1633. struct zfcp_adapter *adapter = erp_action->adapter;
  1634. struct zfcp_qdio *qdio = adapter->qdio;
  1635. struct zfcp_fsf_req *req;
  1636. int retval = -EIO;
  1637. spin_lock_bh(&qdio->req_q_lock);
  1638. if (zfcp_qdio_sbal_get(qdio))
  1639. goto out;
  1640. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1641. SBAL_FLAGS0_TYPE_READ,
  1642. adapter->pool.erp_req);
  1643. if (IS_ERR(req)) {
  1644. retval = PTR_ERR(req);
  1645. goto out;
  1646. }
  1647. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1648. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1649. req->qtcb->header.port_handle = erp_action->port->handle;
  1650. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1651. req->handler = zfcp_fsf_open_unit_handler;
  1652. req->data = erp_action->unit;
  1653. req->erp_action = erp_action;
  1654. erp_action->fsf_req_id = req->req_id;
  1655. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1656. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1657. zfcp_fsf_start_erp_timer(req);
  1658. retval = zfcp_fsf_req_send(req);
  1659. if (retval) {
  1660. zfcp_fsf_req_free(req);
  1661. erp_action->fsf_req_id = 0;
  1662. }
  1663. out:
  1664. spin_unlock_bh(&qdio->req_q_lock);
  1665. return retval;
  1666. }
  1667. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1668. {
  1669. struct zfcp_unit *unit = req->data;
  1670. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1671. return;
  1672. switch (req->qtcb->header.fsf_status) {
  1673. case FSF_PORT_HANDLE_NOT_VALID:
  1674. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1675. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1676. break;
  1677. case FSF_LUN_HANDLE_NOT_VALID:
  1678. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1679. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1680. break;
  1681. case FSF_PORT_BOXED:
  1682. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1684. break;
  1685. case FSF_ADAPTER_STATUS_AVAILABLE:
  1686. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1687. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1688. zfcp_fc_test_link(unit->port);
  1689. /* fall through */
  1690. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1691. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1692. break;
  1693. }
  1694. break;
  1695. case FSF_GOOD:
  1696. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1697. break;
  1698. }
  1699. }
  1700. /**
  1701. * zfcp_fsf_close_unit - close zfcp unit
  1702. * @erp_action: pointer to struct zfcp_unit
  1703. * Returns: 0 on success, error otherwise
  1704. */
  1705. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1706. {
  1707. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1708. struct zfcp_fsf_req *req;
  1709. int retval = -EIO;
  1710. spin_lock_bh(&qdio->req_q_lock);
  1711. if (zfcp_qdio_sbal_get(qdio))
  1712. goto out;
  1713. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1714. SBAL_FLAGS0_TYPE_READ,
  1715. qdio->adapter->pool.erp_req);
  1716. if (IS_ERR(req)) {
  1717. retval = PTR_ERR(req);
  1718. goto out;
  1719. }
  1720. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1721. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1722. req->qtcb->header.port_handle = erp_action->port->handle;
  1723. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1724. req->handler = zfcp_fsf_close_unit_handler;
  1725. req->data = erp_action->unit;
  1726. req->erp_action = erp_action;
  1727. erp_action->fsf_req_id = req->req_id;
  1728. zfcp_fsf_start_erp_timer(req);
  1729. retval = zfcp_fsf_req_send(req);
  1730. if (retval) {
  1731. zfcp_fsf_req_free(req);
  1732. erp_action->fsf_req_id = 0;
  1733. }
  1734. out:
  1735. spin_unlock_bh(&qdio->req_q_lock);
  1736. return retval;
  1737. }
  1738. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1739. {
  1740. lat_rec->sum += lat;
  1741. lat_rec->min = min(lat_rec->min, lat);
  1742. lat_rec->max = max(lat_rec->max, lat);
  1743. }
  1744. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1745. {
  1746. struct fsf_qual_latency_info *lat_in;
  1747. struct latency_cont *lat = NULL;
  1748. struct zfcp_unit *unit = req->unit;
  1749. struct zfcp_blk_drv_data blktrc;
  1750. int ticks = req->adapter->timer_ticks;
  1751. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1752. blktrc.flags = 0;
  1753. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1754. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1755. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1756. blktrc.inb_usage = 0;
  1757. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1758. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1759. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1760. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1761. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1762. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1763. switch (req->qtcb->bottom.io.data_direction) {
  1764. case FSF_DATADIR_READ:
  1765. lat = &unit->latencies.read;
  1766. break;
  1767. case FSF_DATADIR_WRITE:
  1768. lat = &unit->latencies.write;
  1769. break;
  1770. case FSF_DATADIR_CMND:
  1771. lat = &unit->latencies.cmd;
  1772. break;
  1773. }
  1774. if (lat) {
  1775. spin_lock(&unit->latencies.lock);
  1776. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1777. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1778. lat->counter++;
  1779. spin_unlock(&unit->latencies.lock);
  1780. }
  1781. }
  1782. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1783. sizeof(blktrc));
  1784. }
  1785. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1786. {
  1787. struct scsi_cmnd *scpnt;
  1788. struct fcp_resp_with_ext *fcp_rsp;
  1789. unsigned long flags;
  1790. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1791. scpnt = req->data;
  1792. if (unlikely(!scpnt)) {
  1793. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1794. return;
  1795. }
  1796. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1797. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1798. goto skip_fsfstatus;
  1799. }
  1800. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1801. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1802. skip_fsfstatus:
  1803. zfcp_fsf_req_trace(req, scpnt);
  1804. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1805. scpnt->host_scribble = NULL;
  1806. (scpnt->scsi_done) (scpnt);
  1807. /*
  1808. * We must hold this lock until scsi_done has been called.
  1809. * Otherwise we may call scsi_done after abort regarding this
  1810. * command has completed.
  1811. * Note: scsi_done must not block!
  1812. */
  1813. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1814. }
  1815. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1816. {
  1817. struct fcp_resp_with_ext *fcp_rsp;
  1818. struct fcp_resp_rsp_info *rsp_info;
  1819. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1820. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1821. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1822. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1823. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1824. }
  1825. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1826. {
  1827. struct zfcp_unit *unit;
  1828. struct fsf_qtcb_header *header = &req->qtcb->header;
  1829. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1830. unit = req->data;
  1831. else
  1832. unit = req->unit;
  1833. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1834. goto skip_fsfstatus;
  1835. switch (header->fsf_status) {
  1836. case FSF_HANDLE_MISMATCH:
  1837. case FSF_PORT_HANDLE_NOT_VALID:
  1838. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1839. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1840. break;
  1841. case FSF_FCPLUN_NOT_VALID:
  1842. case FSF_LUN_HANDLE_NOT_VALID:
  1843. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1844. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1845. break;
  1846. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1847. zfcp_fsf_class_not_supp(req);
  1848. break;
  1849. case FSF_ACCESS_DENIED:
  1850. zfcp_fsf_access_denied_unit(req, unit);
  1851. break;
  1852. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1853. dev_err(&req->adapter->ccw_device->dev,
  1854. "Incorrect direction %d, unit 0x%016Lx on port "
  1855. "0x%016Lx closed\n",
  1856. req->qtcb->bottom.io.data_direction,
  1857. (unsigned long long)unit->fcp_lun,
  1858. (unsigned long long)unit->port->wwpn);
  1859. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1860. req);
  1861. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1862. break;
  1863. case FSF_CMND_LENGTH_NOT_VALID:
  1864. dev_err(&req->adapter->ccw_device->dev,
  1865. "Incorrect CDB length %d, unit 0x%016Lx on "
  1866. "port 0x%016Lx closed\n",
  1867. req->qtcb->bottom.io.fcp_cmnd_length,
  1868. (unsigned long long)unit->fcp_lun,
  1869. (unsigned long long)unit->port->wwpn);
  1870. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1871. req);
  1872. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1873. break;
  1874. case FSF_PORT_BOXED:
  1875. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1876. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1877. break;
  1878. case FSF_LUN_BOXED:
  1879. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1880. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1881. break;
  1882. case FSF_ADAPTER_STATUS_AVAILABLE:
  1883. if (header->fsf_status_qual.word[0] ==
  1884. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1885. zfcp_fc_test_link(unit->port);
  1886. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1887. break;
  1888. }
  1889. skip_fsfstatus:
  1890. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1891. zfcp_fsf_send_fcp_ctm_handler(req);
  1892. else {
  1893. zfcp_fsf_send_fcp_command_task_handler(req);
  1894. req->unit = NULL;
  1895. put_device(&unit->dev);
  1896. }
  1897. }
  1898. /**
  1899. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1900. * @unit: unit where command is sent to
  1901. * @scsi_cmnd: scsi command to be sent
  1902. */
  1903. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1904. struct scsi_cmnd *scsi_cmnd)
  1905. {
  1906. struct zfcp_fsf_req *req;
  1907. struct fcp_cmnd *fcp_cmnd;
  1908. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1909. int real_bytes, retval = -EIO;
  1910. struct zfcp_adapter *adapter = unit->port->adapter;
  1911. struct zfcp_qdio *qdio = adapter->qdio;
  1912. if (unlikely(!(atomic_read(&unit->status) &
  1913. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1914. return -EBUSY;
  1915. spin_lock(&qdio->req_q_lock);
  1916. if (atomic_read(&qdio->req_q_free) <= 0) {
  1917. atomic_inc(&qdio->req_q_full);
  1918. goto out;
  1919. }
  1920. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1921. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1922. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1923. sbtype, adapter->pool.scsi_req);
  1924. if (IS_ERR(req)) {
  1925. retval = PTR_ERR(req);
  1926. goto out;
  1927. }
  1928. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1929. req->unit = unit;
  1930. req->data = scsi_cmnd;
  1931. req->handler = zfcp_fsf_send_fcp_command_handler;
  1932. req->qtcb->header.lun_handle = unit->handle;
  1933. req->qtcb->header.port_handle = unit->port->handle;
  1934. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1935. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1936. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1937. /*
  1938. * set depending on data direction:
  1939. * data direction bits in SBALE (SB Type)
  1940. * data direction bits in QTCB
  1941. */
  1942. switch (scsi_cmnd->sc_data_direction) {
  1943. case DMA_NONE:
  1944. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1945. break;
  1946. case DMA_FROM_DEVICE:
  1947. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1948. break;
  1949. case DMA_TO_DEVICE:
  1950. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1951. break;
  1952. case DMA_BIDIRECTIONAL:
  1953. goto failed_scsi_cmnd;
  1954. }
  1955. get_device(&unit->dev);
  1956. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1957. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1958. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1959. scsi_sglist(scsi_cmnd));
  1960. if (unlikely(real_bytes < 0))
  1961. goto failed_scsi_cmnd;
  1962. retval = zfcp_fsf_req_send(req);
  1963. if (unlikely(retval))
  1964. goto failed_scsi_cmnd;
  1965. goto out;
  1966. failed_scsi_cmnd:
  1967. put_device(&unit->dev);
  1968. zfcp_fsf_req_free(req);
  1969. scsi_cmnd->host_scribble = NULL;
  1970. out:
  1971. spin_unlock(&qdio->req_q_lock);
  1972. return retval;
  1973. }
  1974. /**
  1975. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1976. * @unit: pointer to struct zfcp_unit
  1977. * @tm_flags: unsigned byte for task management flags
  1978. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1979. */
  1980. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  1981. {
  1982. struct zfcp_fsf_req *req = NULL;
  1983. struct fcp_cmnd *fcp_cmnd;
  1984. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  1985. if (unlikely(!(atomic_read(&unit->status) &
  1986. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1987. return NULL;
  1988. spin_lock_bh(&qdio->req_q_lock);
  1989. if (zfcp_qdio_sbal_get(qdio))
  1990. goto out;
  1991. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1992. SBAL_FLAGS0_TYPE_WRITE,
  1993. qdio->adapter->pool.scsi_req);
  1994. if (IS_ERR(req)) {
  1995. req = NULL;
  1996. goto out;
  1997. }
  1998. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  1999. req->data = unit;
  2000. req->handler = zfcp_fsf_send_fcp_command_handler;
  2001. req->qtcb->header.lun_handle = unit->handle;
  2002. req->qtcb->header.port_handle = unit->port->handle;
  2003. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2004. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2005. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2006. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2007. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2008. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2009. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2010. if (!zfcp_fsf_req_send(req))
  2011. goto out;
  2012. zfcp_fsf_req_free(req);
  2013. req = NULL;
  2014. out:
  2015. spin_unlock_bh(&qdio->req_q_lock);
  2016. return req;
  2017. }
  2018. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2019. {
  2020. }
  2021. /**
  2022. * zfcp_fsf_control_file - control file upload/download
  2023. * @adapter: pointer to struct zfcp_adapter
  2024. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2025. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2026. */
  2027. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2028. struct zfcp_fsf_cfdc *fsf_cfdc)
  2029. {
  2030. struct zfcp_qdio *qdio = adapter->qdio;
  2031. struct zfcp_fsf_req *req = NULL;
  2032. struct fsf_qtcb_bottom_support *bottom;
  2033. int direction, retval = -EIO, bytes;
  2034. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2035. return ERR_PTR(-EOPNOTSUPP);
  2036. switch (fsf_cfdc->command) {
  2037. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2038. direction = SBAL_FLAGS0_TYPE_WRITE;
  2039. break;
  2040. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2041. direction = SBAL_FLAGS0_TYPE_READ;
  2042. break;
  2043. default:
  2044. return ERR_PTR(-EINVAL);
  2045. }
  2046. spin_lock_bh(&qdio->req_q_lock);
  2047. if (zfcp_qdio_sbal_get(qdio))
  2048. goto out;
  2049. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2050. if (IS_ERR(req)) {
  2051. retval = -EPERM;
  2052. goto out;
  2053. }
  2054. req->handler = zfcp_fsf_control_file_handler;
  2055. bottom = &req->qtcb->bottom.support;
  2056. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2057. bottom->option = fsf_cfdc->option;
  2058. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2059. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2060. zfcp_fsf_req_free(req);
  2061. goto out;
  2062. }
  2063. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2064. retval = zfcp_fsf_req_send(req);
  2065. out:
  2066. spin_unlock_bh(&qdio->req_q_lock);
  2067. if (!retval) {
  2068. wait_for_completion(&req->completion);
  2069. return req;
  2070. }
  2071. return ERR_PTR(retval);
  2072. }
  2073. /**
  2074. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2075. * @adapter: pointer to struct zfcp_adapter
  2076. * @sbal_idx: response queue index of SBAL to be processed
  2077. */
  2078. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2079. {
  2080. struct zfcp_adapter *adapter = qdio->adapter;
  2081. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2082. struct qdio_buffer_element *sbale;
  2083. struct zfcp_fsf_req *fsf_req;
  2084. unsigned long req_id;
  2085. int idx;
  2086. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2087. sbale = &sbal->element[idx];
  2088. req_id = (unsigned long) sbale->addr;
  2089. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2090. if (!fsf_req)
  2091. /*
  2092. * Unknown request means that we have potentially memory
  2093. * corruption and must stop the machine immediately.
  2094. */
  2095. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2096. req_id, dev_name(&adapter->ccw_device->dev));
  2097. fsf_req->qdio_req.sbal_response = sbal_idx;
  2098. zfcp_fsf_req_complete(fsf_req);
  2099. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2100. break;
  2101. }
  2102. }